Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Commit eaeb9b4

Browse files
committed
Fix: Missing parameter properties info in constructors (fixes #143)
1 parent 76c33f8 commit eaeb9b4

9 files changed

+4133
-2
lines changed

lib/ast-converter.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -1172,10 +1172,27 @@ module.exports = function(ast, extra) {
11721172
id: null,
11731173
params: node.parameters.map(function(param) {
11741174
var convertedParam = convertChild(param);
1175-
convertedParam.decorators = (param.decorators) ? param.decorators.map(function(d) {
1175+
var decorators = (param.decorators) ? param.decorators.map(function(d) {
11761176
return convertChild(d.expression);
11771177
}) : [];
1178-
return convertedParam;
1178+
1179+
if (param.modifiers) {
1180+
return {
1181+
type: "TSParameterProperty",
1182+
range: [param.getStart(), param.end],
1183+
loc: getLoc(param, ast),
1184+
accessibility: getTSNodeAccessibility(param),
1185+
isReadonly: param.modifiers.filter(function(modifier) {
1186+
return modifier.kind === SyntaxKind.ReadonlyKeyword;
1187+
}).length > 0,
1188+
parameter: convertedParam,
1189+
decorators: decorators
1190+
};
1191+
}
1192+
1193+
return assign(convertedParam, {
1194+
decorators: decorators
1195+
});
11791196
}),
11801197
generator: false,
11811198
expression: false,

tests/fixtures/typescript/basics/class-with-private-parameter-properties.result.js

+1,131
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Foo {
2+
constructor(private firstName: string,
3+
private readonly lastName: string,
4+
private age: number = 30,
5+
private readonly student: boolean = false) {}
6+
}

tests/fixtures/typescript/basics/class-with-protected-parameter-properties.result.js

+1,131
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Foo {
2+
constructor(protected firstName: string,
3+
protected readonly lastName: string,
4+
protected age: number = 30,
5+
protected readonly student: boolean = false) {}
6+
}

tests/fixtures/typescript/basics/class-with-public-parameter-properties.result.js

+1,131
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Foo {
2+
constructor(public firstName: string,
3+
public readonly lastName: string,
4+
public age: number = 30,
5+
public readonly student: boolean = false) {}
6+
}

0 commit comments

Comments
 (0)