Skip to content

Commit cc9d4b3

Browse files
PajnJamesHenry
authored andcommitted
Fix: Add missing typeAnnotation to class properties (fixes eslint#190) (eslint#191)
1 parent 215a012 commit cc9d4b3

6 files changed

+93
-15
lines changed

lib/ast-converter.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,8 @@ module.exports = function(ast, extra) {
10821082
accessibility: getTSNodeAccessibility(node),
10831083
decorators: (node.decorators) ? node.decorators.map(function(d) {
10841084
return convertChild(d.expression);
1085-
}) : []
1085+
}) : [],
1086+
typeAnnotation: (node.type) ? convertTypeAnnotation(node.type) : null
10861087
});
10871088
break;
10881089

tests/fixtures/typescript/basics/class-with-accessibility-modifiers.result.js

+71-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,41 @@ module.exports = {
9090
"computed": false,
9191
"static": false,
9292
"accessibility": "private",
93-
"decorators": []
93+
"decorators": [],
94+
"typeAnnotation": {
95+
"loc": {
96+
"end": {
97+
"column": 22,
98+
"line": 2
99+
},
100+
"start": {
101+
"column": 16,
102+
"line": 2
103+
}
104+
},
105+
"range": [
106+
28,
107+
34
108+
],
109+
"type": "TypeAnnotation",
110+
"typeAnnotation": {
111+
"loc": {
112+
"end": {
113+
"column": 22,
114+
"line": 2
115+
},
116+
"start": {
117+
"column": 16,
118+
"line": 2
119+
}
120+
},
121+
"range": [
122+
28,
123+
34
124+
],
125+
"type": "TSStringKeyword"
126+
}
127+
}
94128
},
95129
{
96130
"type": "ClassProperty",
@@ -130,7 +164,42 @@ module.exports = {
130164
"computed": false,
131165
"static": true,
132166
"accessibility": "public",
133-
"decorators": []
167+
"decorators": [],
168+
"typeAnnotation": {
169+
"loc": {
170+
"end": {
171+
"column": 28,
172+
"line": 3
173+
},
174+
"start": {
175+
"column": 22,
176+
"line": 3
177+
}
178+
},
179+
"range": [
180+
58,
181+
64
182+
],
183+
"type": "TypeAnnotation",
184+
"typeAnnotation": {
185+
"loc": {
186+
"end": {
187+
"column": 28,
188+
"line": 3
189+
},
190+
"start": {
191+
"column": 22,
192+
"line": 3
193+
}
194+
},
195+
"range": [
196+
58,
197+
64
198+
],
199+
"type": "TSNumberKeyword"
200+
}
201+
}
202+
134203
},
135204
{
136205
"type": "MethodDefinition",

tests/fixtures/typescript/decorators/property-decorators/property-decorator-factory-instance-member.result.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ module.exports = {
127127
},
128128
"arguments": []
129129
}
130-
]
130+
],
131+
"typeAnnotation": null
131132
},
132133
{
133134
"type": "ClassProperty",
@@ -239,7 +240,8 @@ module.exports = {
239240
},
240241
"arguments": []
241242
}
242-
]
243+
],
244+
"typeAnnotation": null
243245
}
244246
],
245247
"range": [
@@ -643,4 +645,4 @@ module.exports = {
643645
}
644646
}
645647
]
646-
};
648+
};

tests/fixtures/typescript/decorators/property-decorators/property-decorator-factory-static-member.result.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ module.exports = {
147147
}
148148
]
149149
}
150-
]
150+
],
151+
"typeAnnotation": null
151152
},
152153
{
153154
"type": "ClassProperty",
@@ -244,7 +245,8 @@ module.exports = {
244245
}
245246
]
246247
}
247-
]
248+
],
249+
"typeAnnotation": null
248250
}
249251
],
250252
"range": [
@@ -630,4 +632,4 @@ module.exports = {
630632
}
631633
}
632634
]
633-
};
635+
};

tests/fixtures/typescript/decorators/property-decorators/property-decorator-instance-member.result.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ module.exports = {
109109
},
110110
"name": "foo"
111111
}
112-
]
112+
],
113+
"typeAnnotation": null
113114
},
114115
{
115116
"type": "ClassProperty",
@@ -168,7 +169,8 @@ module.exports = {
168169
},
169170
"name": "bar"
170171
}
171-
]
172+
],
173+
"typeAnnotation": null
172174
}
173175
],
174176
"range": [
@@ -410,4 +412,4 @@ module.exports = {
410412
}
411413
}
412414
]
413-
};
415+
};

tests/fixtures/typescript/decorators/property-decorators/property-decorator-static-member.result.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ module.exports = {
109109
},
110110
"name": "baz"
111111
}
112-
]
112+
],
113+
"typeAnnotation": null
113114
},
114115
{
115116
"type": "ClassProperty",
@@ -168,7 +169,8 @@ module.exports = {
168169
},
169170
"name": "qux"
170171
}
171-
]
172+
],
173+
"typeAnnotation": null
172174
}
173175
],
174176
"range": [
@@ -446,4 +448,4 @@ module.exports = {
446448
}
447449
}
448450
]
449-
};
451+
};

0 commit comments

Comments
 (0)