This repository was archived by the owner on Jan 19, 2019. It is now read-only.
File tree 4 files changed +217
-1
lines changed
fixtures/typescript/basics
4 files changed +217
-1
lines changed Original file line number Diff line number Diff line change @@ -118,6 +118,7 @@ module.exports = {
118
118
TSModuleDeclaration : "TSModuleDeclaration" ,
119
119
TSNamespaceFunctionDeclaration : "TSNamespaceFunctionDeclaration" ,
120
120
TSNonNullExpression : "TSNonNullExpression" ,
121
+ TSNullKeyword : "TSNullKeyword" ,
121
122
TSNumberKeyword : "TSNumberKeyword" ,
122
123
TSParameterProperty : "TSParameterProperty" ,
123
124
TSPropertySignature : "TSPropertySignature" ,
Original file line number Diff line number Diff line change @@ -85,12 +85,22 @@ module.exports = function convert(config) {
85
85
*/
86
86
function convertTypeAnnotation ( child ) {
87
87
const annotation = convertChild ( child ) ;
88
- return {
88
+ const converted = {
89
89
type : AST_NODE_TYPES . TypeAnnotation ,
90
90
loc : annotation . loc ,
91
91
range : annotation . range ,
92
92
typeAnnotation : annotation
93
93
} ;
94
+ /**
95
+ * A typeAnnotation of "null" will be interpreted as a Literal within convertChild(),
96
+ * so we simply post-process it to work around that
97
+ */
98
+ if ( child . kind === SyntaxKind . NullKeyword ) {
99
+ converted . typeAnnotation . type = AST_NODE_TYPES . TSNullKeyword ;
100
+ delete converted . typeAnnotation . value ;
101
+ delete converted . typeAnnotation . raw ;
102
+ }
103
+ return converted ;
94
104
}
95
105
96
106
/**
Original file line number Diff line number Diff line change
1
+ let x : null ;
2
+ let y : undefined ;
Original file line number Diff line number Diff line change @@ -15659,6 +15659,209 @@ Object {
15659
15659
}
15660
15660
`;
15661
15661
15662
+ exports[`typescript fixtures/basics/null-and-undefined-type-annotations.src 1`] = `
15663
+ Object {
15664
+ "body": Array [
15665
+ Object {
15666
+ "declarations": Array [
15667
+ Object {
15668
+ "id": Object {
15669
+ "loc": Object {
15670
+ "end": Object {
15671
+ "column": 5,
15672
+ "line": 1,
15673
+ },
15674
+ "start": Object {
15675
+ "column": 4,
15676
+ "line": 1,
15677
+ },
15678
+ },
15679
+ "name": "x",
15680
+ "range": Array [
15681
+ 4,
15682
+ 5,
15683
+ ],
15684
+ "type": "Identifier",
15685
+ "typeAnnotation": Object {
15686
+ "loc": Object {
15687
+ "end": Object {
15688
+ "column": 11,
15689
+ "line": 1,
15690
+ },
15691
+ "start": Object {
15692
+ "column": 7,
15693
+ "line": 1,
15694
+ },
15695
+ },
15696
+ "range": Array [
15697
+ 7,
15698
+ 11,
15699
+ ],
15700
+ "type": "TypeAnnotation",
15701
+ "typeAnnotation": Object {
15702
+ "loc": Object {
15703
+ "end": Object {
15704
+ "column": 11,
15705
+ "line": 1,
15706
+ },
15707
+ "start": Object {
15708
+ "column": 7,
15709
+ "line": 1,
15710
+ },
15711
+ },
15712
+ "range": Array [
15713
+ 7,
15714
+ 11,
15715
+ ],
15716
+ "type": "TSNullKeyword",
15717
+ },
15718
+ },
15719
+ },
15720
+ "init": null,
15721
+ "loc": Object {
15722
+ "end": Object {
15723
+ "column": 11,
15724
+ "line": 1,
15725
+ },
15726
+ "start": Object {
15727
+ "column": 4,
15728
+ "line": 1,
15729
+ },
15730
+ },
15731
+ "range": Array [
15732
+ 4,
15733
+ 11,
15734
+ ],
15735
+ "type": "VariableDeclarator",
15736
+ },
15737
+ ],
15738
+ "kind": "let",
15739
+ "loc": Object {
15740
+ "end": Object {
15741
+ "column": 12,
15742
+ "line": 1,
15743
+ },
15744
+ "start": Object {
15745
+ "column": 0,
15746
+ "line": 1,
15747
+ },
15748
+ },
15749
+ "range": Array [
15750
+ 0,
15751
+ 12,
15752
+ ],
15753
+ "type": "VariableDeclaration",
15754
+ },
15755
+ Object {
15756
+ "declarations": Array [
15757
+ Object {
15758
+ "id": Object {
15759
+ "loc": Object {
15760
+ "end": Object {
15761
+ "column": 5,
15762
+ "line": 2,
15763
+ },
15764
+ "start": Object {
15765
+ "column": 4,
15766
+ "line": 2,
15767
+ },
15768
+ },
15769
+ "name": "y",
15770
+ "range": Array [
15771
+ 17,
15772
+ 18,
15773
+ ],
15774
+ "type": "Identifier",
15775
+ "typeAnnotation": Object {
15776
+ "loc": Object {
15777
+ "end": Object {
15778
+ "column": 16,
15779
+ "line": 2,
15780
+ },
15781
+ "start": Object {
15782
+ "column": 7,
15783
+ "line": 2,
15784
+ },
15785
+ },
15786
+ "range": Array [
15787
+ 20,
15788
+ 29,
15789
+ ],
15790
+ "type": "TypeAnnotation",
15791
+ "typeAnnotation": Object {
15792
+ "loc": Object {
15793
+ "end": Object {
15794
+ "column": 16,
15795
+ "line": 2,
15796
+ },
15797
+ "start": Object {
15798
+ "column": 7,
15799
+ "line": 2,
15800
+ },
15801
+ },
15802
+ "range": Array [
15803
+ 20,
15804
+ 29,
15805
+ ],
15806
+ "type": "TSUndefinedKeyword",
15807
+ },
15808
+ },
15809
+ },
15810
+ "init": null,
15811
+ "loc": Object {
15812
+ "end": Object {
15813
+ "column": 16,
15814
+ "line": 2,
15815
+ },
15816
+ "start": Object {
15817
+ "column": 4,
15818
+ "line": 2,
15819
+ },
15820
+ },
15821
+ "range": Array [
15822
+ 17,
15823
+ 29,
15824
+ ],
15825
+ "type": "VariableDeclarator",
15826
+ },
15827
+ ],
15828
+ "kind": "let",
15829
+ "loc": Object {
15830
+ "end": Object {
15831
+ "column": 17,
15832
+ "line": 2,
15833
+ },
15834
+ "start": Object {
15835
+ "column": 0,
15836
+ "line": 2,
15837
+ },
15838
+ },
15839
+ "range": Array [
15840
+ 13,
15841
+ 30,
15842
+ ],
15843
+ "type": "VariableDeclaration",
15844
+ },
15845
+ ],
15846
+ "loc": Object {
15847
+ "end": Object {
15848
+ "column": 17,
15849
+ "line": 2,
15850
+ },
15851
+ "start": Object {
15852
+ "column": 0,
15853
+ "line": 1,
15854
+ },
15855
+ },
15856
+ "range": Array [
15857
+ 0,
15858
+ 30,
15859
+ ],
15860
+ "sourceType": "script",
15861
+ "type": "Program",
15862
+ }
15863
+ `;
15864
+
15662
15865
exports[`typescript fixtures/basics/type-alias-declaration.src 1`] = `
15663
15866
Object {
15664
15867
"body": Array [
You can’t perform that action at this time.
0 commit comments