From 34f04444bfda219da04ffe350eecae6d50074e2b Mon Sep 17 00:00:00 2001 From: weirdpattern Date: Tue, 21 Feb 2017 22:30:31 -0600 Subject: [PATCH] Fix: Missing parameter properties info in constructors (fixes #143) --- lib/ast-converter.js | 21 +- ...ith-private-parameter-properties.result.js | 1131 +++++++++++++++++ ...s-with-private-parameter-properties.src.ts | 6 + ...h-protected-parameter-properties.result.js | 1131 +++++++++++++++++ ...with-protected-parameter-properties.src.ts | 6 + ...with-public-parameter-properties.result.js | 1131 +++++++++++++++++ ...ss-with-public-parameter-properties.src.ts | 6 + ...th-readonly-parameter-properties.result.js | 699 ++++++++++ ...-with-readonly-parameter-properties.src.ts | 4 + 9 files changed, 4133 insertions(+), 2 deletions(-) create mode 100644 tests/fixtures/typescript/basics/class-with-private-parameter-properties.result.js create mode 100644 tests/fixtures/typescript/basics/class-with-private-parameter-properties.src.ts create mode 100644 tests/fixtures/typescript/basics/class-with-protected-parameter-properties.result.js create mode 100644 tests/fixtures/typescript/basics/class-with-protected-parameter-properties.src.ts create mode 100644 tests/fixtures/typescript/basics/class-with-public-parameter-properties.result.js create mode 100644 tests/fixtures/typescript/basics/class-with-public-parameter-properties.src.ts create mode 100644 tests/fixtures/typescript/basics/class-with-readonly-parameter-properties.result.js create mode 100644 tests/fixtures/typescript/basics/class-with-readonly-parameter-properties.src.ts diff --git a/lib/ast-converter.js b/lib/ast-converter.js index fd8b72f..6785838 100644 --- a/lib/ast-converter.js +++ b/lib/ast-converter.js @@ -1187,10 +1187,27 @@ module.exports = function(ast, extra) { id: null, params: node.parameters.map(function(param) { var convertedParam = convertChild(param); - convertedParam.decorators = (param.decorators) ? param.decorators.map(function(d) { + var decorators = (param.decorators) ? param.decorators.map(function(d) { return convertChild(d.expression); }) : []; - return convertedParam; + + if (param.modifiers) { + return { + type: "TSParameterProperty", + range: [param.getStart(), param.end], + loc: getLoc(param, ast), + accessibility: getTSNodeAccessibility(param), + isReadonly: param.modifiers.some(function(modifier) { + return modifier.kind === SyntaxKind.ReadonlyKeyword; + }), + parameter: convertedParam, + decorators: decorators + }; + } + + return assign(convertedParam, { + decorators: decorators + }); }), generator: false, expression: false, diff --git a/tests/fixtures/typescript/basics/class-with-private-parameter-properties.result.js b/tests/fixtures/typescript/basics/class-with-private-parameter-properties.result.js new file mode 100644 index 0000000..464b490 --- /dev/null +++ b/tests/fixtures/typescript/basics/class-with-private-parameter-properties.result.js @@ -0,0 +1,1131 @@ +module.exports = { + "type": "Program", + "range": [ + 0, + 203 + ], + "loc": { + "end": { + "line": 6, + "column": 1 + }, + "start": { + "line": 1, + "column": 0 + } + }, + "body": [ + { + "body": { + "body": [ + { + "type": "MethodDefinition", + "kind": "constructor", + "range": [ + 14, + 201 + ], + "loc": { + "end": { + "line": 5, + "column": 59 + }, + "start": { + "line": 2, + "column": 2 + } + }, + "accessibility": null, + "computed": false, + "key": { + "type": "Identifier", + "range": [ + 14, + 25 + ], + "loc": { + "end": { + "line": 2, + "column": 13 + }, + "start": { + "line": 2, + "column": 2 + } + }, + "name": "constructor" + }, + "static": false, + "value": { + "type": "FunctionExpression", + "range": [ + 25, + 201 + ], + "loc": { + "end": { + "line": 5, + "column": 59 + }, + "start": { + "line": 2, + "column": 13 + } + }, + "async": false, + "body": { + "type": "BlockStatement", + "range": [ + 199, + 201 + ], + "loc": { + "end": { + "line": 5, + "column": 59 + }, + "start": { + "line": 5, + "column": 57 + } + }, + "body": [] + }, + "expression": false, + "generator": false, + "id": null, + "params": [ + { + "type": "TSParameterProperty", + "range": [ + 26, + 51 + ], + "loc": { + "end": { + "line": 2, + "column": 39 + }, + "start": { + "line": 2, + "column": 14 + } + }, + "decorators": [], + "accessibility": "private", + "isReadonly": false, + "parameter": { + "type": "Identifier", + "range": [ + 34, + 43 + ], + "loc": { + "end": { + "line": 2, + "column": 31 + }, + "start": { + "line": 2, + "column": 22 + } + }, + "name": "firstName", + "typeAnnotation": { + "type": "TypeAnnotation", + "range": [ + 45, + 51 + ], + "loc": { + "end": { + "line": 2, + "column": 39 + }, + "start": { + "line": 2, + "column": 33 + } + }, + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 45, + 51 + ], + "loc": { + "end": { + "line": 2, + "column": 39 + }, + "start": { + "line": 2, + "column": 33 + } + } + } + } + } + }, + { + "type": "TSParameterProperty", + "range": [ + 67, + 100 + ], + "loc": { + "end": { + "line": 3, + "column": 47 + }, + "start": { + "line": 3, + "column": 14 + } + }, + "decorators": [], + "accessibility": "private", + "isReadonly": true, + "parameter": { + "type": "Identifier", + "range": [ + 84, + 92 + ], + "loc": { + "end": { + "line": 3, + "column": 39 + }, + "start": { + "line": 3, + "column": 31 + } + }, + "name": "lastName", + "typeAnnotation": { + "type": "TypeAnnotation", + "range": [ + 94, + 100 + ], + "loc": { + "end": { + "line": 3, + "column": 47 + }, + "start": { + "line": 3, + "column": 41 + } + }, + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 94, + 100 + ], + "loc": { + "end": { + "line": 3, + "column": 47 + }, + "start": { + "line": 3, + "column": 41 + } + } + } + } + } + }, + { + "type": "TSParameterProperty", + "range": [ + 116, + 140 + ], + "loc": { + "end": { + "line": 4, + "column": 38 + }, + "start": { + "line": 4, + "column": 14 + } + }, + "decorators": [], + "accessibility": "private", + "isReadonly": false, + "parameter": { + "left": { + "type": "Identifier", + "range": [ + 124, + 127 + ], + "loc": { + "end": { + "line": 4, + "column": 25 + }, + "start": { + "line": 4, + "column": 22 + } + }, + "name": "age", + "typeAnnotation": { + "type": "TypeAnnotation", + "range": [ + 129, + 135 + ], + "loc": { + "end": { + "line": 4, + "column": 33 + }, + "start": { + "line": 4, + "column": 27 + } + }, + "typeAnnotation": { + "type": "TSNumberKeyword", + "range": [ + 129, + 135 + ], + "loc": { + "end": { + "line": 4, + "column": 33 + }, + "start": { + "line": 4, + "column": 27 + } + } + } + } + }, + "type": "AssignmentPattern", + "range": [ + 116, + 140 + ], + "loc": { + "end": { + "line": 4, + "column": 38 + }, + "start": { + "line": 4, + "column": 14 + } + }, + "right": { + "loc": { + "end": { + "line": 4, + "column": 38 + }, + "start": { + "line": 4, + "column": 36 + } + }, + "range": [ + 138, + 140 + ], + "raw": "30", + "type": "Literal", + "value": 30 + } + } + }, + { + "type": "TSParameterProperty", + "range": [ + 156, + 197 + ], + "loc": { + "end": { + "line": 5, + "column": 55 + }, + "start": { + "line": 5, + "column": 14 + } + }, + "decorators": [], + "accessibility": "private", + "isReadonly": true, + "parameter": { + "left": { + "type": "Identifier", + "range": [ + 173, + 180 + ], + "loc": { + "end": { + "line": 5, + "column": 38 + }, + "start": { + "line": 5, + "column": 31 + } + }, + "name": "student", + "typeAnnotation": { + "type": "TypeAnnotation", + "range": [ + 182, + 189 + ], + "loc": { + "end": { + "line": 5, + "column": 47 + }, + "start": { + "line": 5, + "column": 40 + } + }, + "typeAnnotation": { + "type": "TSBooleanKeyword", + "range": [ + 182, + 189 + ], + "loc": { + "end": { + "line": 5, + "column": 47 + }, + "start": { + "line": 5, + "column": 40 + } + } + } + } + }, + "type": "AssignmentPattern", + "range": [ + 156, + 197 + ], + "loc": { + "end": { + "line": 5, + "column": 55 + }, + "start": { + "line": 5, + "column": 14 + } + }, + "right": { + "type": "Literal", + "range": [ + 192, + 197 + ], + "loc": { + "end": { + "line": 5, + "column": 55 + }, + "start": { + "line": 5, + "column": 50 + } + }, + "raw": "false", + "value": false + } + } + } + ] + } + } + ], + "loc": { + "end": { + "line": 6, + "column": 1 + }, + "start": { + "line": 1, + "column": 10 + } + }, + "range": [ + 10, + 203 + ], + "type": "ClassBody" + }, + "decorators": [], + "id": { + "loc": { + "end": { + "line": 1, + "column": 9 + }, + "start": { + "line": 1, + "column": 6 + } + }, + "name": "Foo", + "range": [ + 6, + 9 + ], + "type": "Identifier" + }, + "implements": [], + "loc": { + "end": { + "line": 6, + "column": 1 + }, + "start": { + "line": 1, + "column": 0 + } + }, + "range": [ + 0, + 203 + ], + "superClass": null, + "type": "ClassDeclaration" + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "range": [ + 0, + 5 + ], + "loc": { + "end": { + "line": 1, + "column": 5 + }, + "start": { + "line": 1, + "column": 0 + } + }, + "value": "class" + }, + { + "type": "Identifier", + "range": [ + 6, + 9 + ], + "loc": { + "end": { + "line": 1, + "column": 9 + }, + "start": { + "line": 1, + "column": 6 + } + }, + "value": "Foo" + }, + { + "type": "Punctuator", + "range": [ + 10, + 11 + ], + "loc": { + "end": { + "line": 1, + "column": 11 + }, + "start": { + "line": 1, + "column": 10 + } + }, + "value": "{" + }, + { + "type": "Identifier", + "range": [ + 14, + 25 + ], + "loc": { + "end": { + "line": 2, + "column": 13 + }, + "start": { + "line": 2, + "column": 2 + } + }, + "value": "constructor" + }, + { + "type": "Punctuator", + "range": [ + 25, + 26 + ], + "loc": { + "end": { + "line": 2, + "column": 14 + }, + "start": { + "line": 2, + "column": 13 + } + }, + "value": "(" + }, + { + "type": "Keyword", + "range": [ + 26, + 33 + ], + "loc": { + "end": { + "line": 2, + "column": 21 + }, + "start": { + "line": 2, + "column": 14 + } + }, + "value": "private" + }, + { + "type": "Identifier", + "range": [ + 34, + 43 + ], + "loc": { + "end": { + "line": 2, + "column": 31 + }, + "start": { + "line": 2, + "column": 22 + } + }, + "value": "firstName" + }, + { + "type": "Punctuator", + "range": [ + 43, + 44 + ], + "loc": { + "end": { + "line": 2, + "column": 32 + }, + "start": { + "line": 2, + "column": 31 + } + }, + "value": ":" + }, + { + "type": "Identifier", + "range": [ + 45, + 51 + ], + "loc": { + "end": { + "line": 2, + "column": 39 + }, + "start": { + "line": 2, + "column": 33 + } + }, + "value": "string" + }, + { + "type": "Punctuator", + "range": [ + 51, + 52 + ], + "loc": { + "end": { + "line": 2, + "column": 40 + }, + "start": { + "line": 2, + "column": 39 + } + }, + "value": "," + }, + { + "type": "Keyword", + "range": [ + 67, + 74 + ], + "loc": { + "end": { + "line": 3, + "column": 21 + }, + "start": { + "line": 3, + "column": 14 + } + }, + "value": "private" + }, + { + "type": "Identifier", + "range": [ + 75, + 83 + ], + "loc": { + "end": { + "line": 3, + "column": 30 + }, + "start": { + "line": 3, + "column": 22 + } + }, + "value": "readonly" + }, + { + "type": "Identifier", + "range": [ + 84, + 92 + ], + "loc": { + "end": { + "line": 3, + "column": 39 + }, + "start": { + "line": 3, + "column": 31 + } + }, + "value": "lastName" + }, + { + "type": "Punctuator", + "range": [ + 92, + 93 + ], + "loc": { + "end": { + "line": 3, + "column": 40 + }, + "start": { + "line": 3, + "column": 39 + } + }, + "value": ":" + }, + { + "type": "Identifier", + "range": [ + 94, + 100 + ], + "loc": { + "end": { + "line": 3, + "column": 47 + }, + "start": { + "line": 3, + "column": 41 + } + }, + "value": "string" + }, + { + "type": "Punctuator", + "range": [ + 100, + 101 + ], + "loc": { + "end": { + "line": 3, + "column": 48 + }, + "start": { + "line": 3, + "column": 47 + } + }, + "value": "," + }, + { + "type": "Keyword", + "range": [ + 116, + 123 + ], + "loc": { + "end": { + "line": 4, + "column": 21 + }, + "start": { + "line": 4, + "column": 14 + } + }, + "value": "private" + }, + { + "type": "Identifier", + "range": [ + 124, + 127 + ], + "loc": { + "end": { + "line": 4, + "column": 25 + }, + "start": { + "line": 4, + "column": 22 + } + }, + "value": "age" + }, + { + "type": "Punctuator", + "range": [ + 127, + 128 + ], + "loc": { + "end": { + "line": 4, + "column": 26 + }, + "start": { + "line": 4, + "column": 25 + } + }, + "value": ":" + }, + { + "type": "Identifier", + "range": [ + 129, + 135 + ], + "loc": { + "end": { + "line": 4, + "column": 33 + }, + "start": { + "line": 4, + "column": 27 + } + }, + "value": "number" + }, + { + "type": "Punctuator", + "range": [ + 136, + 137 + ], + "loc": { + "end": { + "line": 4, + "column": 35 + }, + "start": { + "line": 4, + "column": 34 + } + }, + "value": "=" + }, + { + "type": "Numeric", + "range": [ + 138, + 140 + ], + "loc": { + "end": { + "line": 4, + "column": 38 + }, + "start": { + "line": 4, + "column": 36 + } + }, + "value": "30" + }, + { + "type": "Punctuator", + "range": [ + 140, + 141 + ], + "loc": { + "end": { + "line": 4, + "column": 39 + }, + "start": { + "line": 4, + "column": 38 + } + }, + "value": "," + }, + { + "type": "Keyword", + "range": [ + 156, + 163 + ], + "loc": { + "end": { + "line": 5, + "column": 21 + }, + "start": { + "line": 5, + "column": 14 + } + }, + "value": "private" + }, + { + "type": "Identifier", + "range": [ + 164, + 172 + ], + "loc": { + "end": { + "line": 5, + "column": 30 + }, + "start": { + "line": 5, + "column": 22 + } + }, + "value": "readonly" + }, + { + "type": "Identifier", + "range": [ + 173, + 180 + ], + "loc": { + "end": { + "line": 5, + "column": 38 + }, + "start": { + "line": 5, + "column": 31 + } + }, + "value": "student" + }, + { + "type": "Punctuator", + "range": [ + 180, + 181 + ], + "loc": { + "end": { + "line": 5, + "column": 39 + }, + "start": { + "line": 5, + "column": 38 + } + }, + "value": ":" + }, + { + "type": "Identifier", + "range": [ + 182, + 189 + ], + "loc": { + "end": { + "line": 5, + "column": 47 + }, + "start": { + "line": 5, + "column": 40 + } + }, + "value": "boolean" + }, + { + "type": "Punctuator", + "range": [ + 190, + 191 + ], + "loc": { + "end": { + "line": 5, + "column": 49 + }, + "start": { + "line": 5, + "column": 48 + } + }, + "value": "=" + }, + { + "type": "Boolean", + "range": [ + 192, + 197 + ], + "loc": { + "end": { + "line": 5, + "column": 55 + }, + "start": { + "line": 5, + "column": 50 + } + }, + "value": "false" + }, + { + "type": "Punctuator", + "range": [ + 197, + 198 + ], + "loc": { + "end": { + "line": 5, + "column": 56 + }, + "start": { + "line": 5, + "column": 55 + } + }, + "value": ")" + }, + { + "type": "Punctuator", + "range": [ + 199, + 200 + ], + "loc": { + "end": { + "line": 5, + "column": 58 + }, + "start": { + "line": 5, + "column": 57 + } + }, + "value": "{" + }, + { + "type": "Punctuator", + "range": [ + 200, + 201 + ], + "loc": { + "end": { + "line": 5, + "column": 59 + }, + "start": { + "line": 5, + "column": 58 + } + }, + "value": "}" + }, + { + "type": "Punctuator", + "range": [ + 202, + 203 + ], + "loc": { + "end": { + "line": 6, + "column": 1 + }, + "start": { + "line": 6, + "column": 0 + } + }, + "value": "}" + } + ], +}; \ No newline at end of file diff --git a/tests/fixtures/typescript/basics/class-with-private-parameter-properties.src.ts b/tests/fixtures/typescript/basics/class-with-private-parameter-properties.src.ts new file mode 100644 index 0000000..f806c1e --- /dev/null +++ b/tests/fixtures/typescript/basics/class-with-private-parameter-properties.src.ts @@ -0,0 +1,6 @@ +class Foo { + constructor(private firstName: string, + private readonly lastName: string, + private age: number = 30, + private readonly student: boolean = false) {} +} \ No newline at end of file diff --git a/tests/fixtures/typescript/basics/class-with-protected-parameter-properties.result.js b/tests/fixtures/typescript/basics/class-with-protected-parameter-properties.result.js new file mode 100644 index 0000000..412dc9a --- /dev/null +++ b/tests/fixtures/typescript/basics/class-with-protected-parameter-properties.result.js @@ -0,0 +1,1131 @@ +module.exports = { + "type": "Program", + "range": [ + 0, + 211 + ], + "loc": { + "end": { + "line": 6, + "column": 1 + }, + "start": { + "line": 1, + "column": 0 + } + }, + "body": [ + { + "type": "ClassDeclaration", + "range": [ + 0, + 211 + ], + "loc": { + "end": { + "line": 6, + "column": 1 + }, + "start": { + "line": 1, + "column": 0 + } + }, + "body": { + "type": "ClassBody", + "range": [ + 10, + 211 + ], + "loc": { + "end": { + "line": 6, + "column": 1 + }, + "start": { + "line": 1, + "column": 10 + } + }, + "body": [ + { + "type": "MethodDefinition", + "range": [ + 14, + 209 + ], + "loc": { + "end": { + "line": 5, + "column": 61 + }, + "start": { + "line": 2, + "column": 2 + } + }, + "kind": "constructor", + "accessibility": null, + "computed": false, + "key": { + "type": "Identifier", + "range": [ + 14, + 25 + ], + "loc": { + "end": { + "line": 2, + "column": 13 + }, + "start": { + "line": 2, + "column": 2 + } + }, + "name": "constructor" + }, + "static": false, + "value": { + "type": "FunctionExpression", + "range": [ + 25, + 209 + ], + "loc": { + "end": { + "line": 5, + "column": 61 + }, + "start": { + "line": 2, + "column": 13 + } + }, + "async": false, + "body": { + "type": "BlockStatement", + "range": [ + 207, + 209 + ], + "loc": { + "end": { + "line": 5, + "column": 61 + }, + "start": { + "line": 5, + "column": 59 + } + }, + "body": [] + }, + "expression": false, + "generator": false, + "id": null, + "params": [ + { + "type": "TSParameterProperty", + "range": [ + 26, + 53 + ], + "loc": { + "end": { + "line": 2, + "column": 41 + }, + "start": { + "line": 2, + "column": 14 + } + }, + "decorators": [], + "accessibility": "protected", + "isReadonly": false, + "parameter": { + "type": "Identifier", + "range": [ + 36, + 45 + ], + "loc": { + "end": { + "line": 2, + "column": 33 + }, + "start": { + "line": 2, + "column": 24 + } + }, + "name": "firstName", + "typeAnnotation": { + "type": "TypeAnnotation", + "range": [ + 47, + 53 + ], + "loc": { + "end": { + "line": 2, + "column": 41 + }, + "start": { + "line": 2, + "column": 35 + } + }, + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 47, + 53 + ], + "loc": { + "end": { + "line": 2, + "column": 41 + }, + "start": { + "line": 2, + "column": 35 + } + } + } + } + } + }, + { + "type": "TSParameterProperty", + "range": [ + 69, + 104 + ], + "loc": { + "end": { + "line": 3, + "column": 49 + }, + "start": { + "line": 3, + "column": 14 + } + }, + "decorators": [], + "accessibility": "protected", + "isReadonly": true, + "parameter": { + "type": "Identifier", + "range": [ + 88, + 96 + ], + "loc": { + "end": { + "line": 3, + "column": 41 + }, + "start": { + "line": 3, + "column": 33 + } + }, + "name": "lastName", + "typeAnnotation": { + "type": "TypeAnnotation", + "range": [ + 98, + 104 + ], + "loc": { + "end": { + "line": 3, + "column": 49 + }, + "start": { + "line": 3, + "column": 43 + } + }, + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 98, + 104 + ], + "loc": { + "end": { + "line": 3, + "column": 49 + }, + "start": { + "line": 3, + "column": 43 + } + } + } + } + } + }, + { + "type": "TSParameterProperty", + "range": [ + 120, + 146 + ], + "loc": { + "end": { + "line": 4, + "column": 40 + }, + "start": { + "line": 4, + "column": 14 + } + }, + "decorators": [], + "accessibility": "protected", + "isReadonly": false, + "parameter": { + "type": "AssignmentPattern", + "range": [ + 120, + 146 + ], + "loc": { + "end": { + "line": 4, + "column": 40 + }, + "start": { + "line": 4, + "column": 14 + } + }, + "left": { + "type": "Identifier", + "range": [ + 130, + 133 + ], + "loc": { + "end": { + "line": 4, + "column": 27 + }, + "start": { + "line": 4, + "column": 24 + } + }, + "name": "age", + "typeAnnotation": { + "type": "TypeAnnotation", + "range": [ + 135, + 141 + ], + "loc": { + "end": { + "line": 4, + "column": 35 + }, + "start": { + "line": 4, + "column": 29 + } + }, + "typeAnnotation": { + "type": "TSNumberKeyword", + "range": [ + 135, + 141 + ], + "loc": { + "end": { + "line": 4, + "column": 35 + }, + "start": { + "line": 4, + "column": 29 + } + } + } + } + }, + "right": { + "type": "Literal", + "range": [ + 144, + 146 + ], + "loc": { + "end": { + "line": 4, + "column": 40 + }, + "start": { + "line": 4, + "column": 38 + } + }, + "raw": "30", + "value": 30 + } + } + }, + { + "type": "TSParameterProperty", + "range": [ + 162, + 205 + ], + "loc": { + "end": { + "line": 5, + "column": 57 + }, + "start": { + "line": 5, + "column": 14 + } + }, + "decorators": [], + "accessibility": "protected", + "isReadonly": true, + "parameter": { + "type": "AssignmentPattern", + "range": [ + 162, + 205 + ], + "loc": { + "end": { + "line": 5, + "column": 57 + }, + "start": { + "line": 5, + "column": 14 + } + }, + "left": { + "type": "Identifier", + "range": [ + 181, + 188 + ], + "loc": { + "end": { + "line": 5, + "column": 40 + }, + "start": { + "line": 5, + "column": 33 + } + }, + "name": "student", + "typeAnnotation": { + "type": "TypeAnnotation", + "range": [ + 190, + 197 + ], + "loc": { + "end": { + "line": 5, + "column": 49 + }, + "start": { + "line": 5, + "column": 42 + } + }, + "typeAnnotation": { + "type": "TSBooleanKeyword", + "range": [ + 190, + 197 + ], + "loc": { + "end": { + "line": 5, + "column": 49 + }, + "start": { + "line": 5, + "column": 42 + } + } + } + } + }, + "right": { + "type": "Literal", + "range": [ + 200, + 205 + ], + "loc": { + "end": { + "line": 5, + "column": 57 + }, + "start": { + "line": 5, + "column": 52 + } + }, + "raw": "false", + "value": false + } + } + } + ] + } + } + ] + }, + "decorators": [], + "id": { + "type": "Identifier", + "range": [ + 6, + 9 + ], + "loc": { + "end": { + "line": 1, + "column": 9 + }, + "start": { + "line": 1, + "column": 6 + } + }, + "name": "Foo", + }, + "implements": [], + "superClass": null, + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "range": [ + 0, + 5 + ], + "loc": { + "end": { + "line": 1, + "column": 5 + }, + "start": { + "line": 1, + "column": 0 + } + }, + "value": "class" + }, + { + "type": "Identifier", + "range": [ + 6, + 9 + ], + "loc": { + "end": { + "line": 1, + "column": 9 + }, + "start": { + "line": 1, + "column": 6 + } + }, + "value": "Foo" + }, + { + "type": "Punctuator", + "range": [ + 10, + 11 + ], + "loc": { + "end": { + "line": 1, + "column": 11 + }, + "start": { + "line": 1, + "column": 10 + } + }, + "value": "{" + }, + { + "type": "Identifier", + "range": [ + 14, + 25 + ], + "loc": { + "end": { + "line": 2, + "column": 13 + }, + "start": { + "line": 2, + "column": 2 + } + }, + "value": "constructor" + }, + { + "type": "Punctuator", + "range": [ + 25, + 26 + ], + "loc": { + "end": { + "line": 2, + "column": 14 + }, + "start": { + "line": 2, + "column": 13 + } + }, + "value": "(" + }, + { + "type": "Keyword", + "range": [ + 26, + 35 + ], + "loc": { + "end": { + "line": 2, + "column": 23 + }, + "start": { + "line": 2, + "column": 14 + } + }, + "value": "protected" + }, + { + "type": "Identifier", + "range": [ + 36, + 45 + ], + "loc": { + "end": { + "line": 2, + "column": 33 + }, + "start": { + "line": 2, + "column": 24 + } + }, + "value": "firstName" + }, + { + "type": "Punctuator", + "range": [ + 45, + 46 + ], + "loc": { + "end": { + "line": 2, + "column": 34 + }, + "start": { + "line": 2, + "column": 33 + } + }, + "value": ":" + }, + { + "type": "Identifier", + "range": [ + 47, + 53 + ], + "loc": { + "end": { + "line": 2, + "column": 41 + }, + "start": { + "line": 2, + "column": 35 + } + }, + "value": "string" + }, + { + "type": "Punctuator", + "range": [ + 53, + 54 + ], + "loc": { + "end": { + "line": 2, + "column": 42 + }, + "start": { + "line": 2, + "column": 41 + } + }, + "value": "," + }, + { + "type": "Keyword", + "range": [ + 69, + 78 + ], + "loc": { + "end": { + "line": 3, + "column": 23 + }, + "start": { + "line": 3, + "column": 14 + } + }, + "value": "protected" + }, + { + "type": "Identifier", + "range": [ + 79, + 87 + ], + "loc": { + "end": { + "line": 3, + "column": 32 + }, + "start": { + "line": 3, + "column": 24 + } + }, + "value": "readonly" + }, + { + "type": "Identifier", + "range": [ + 88, + 96 + ], + "loc": { + "end": { + "line": 3, + "column": 41 + }, + "start": { + "line": 3, + "column": 33 + } + }, + "value": "lastName" + }, + { + "type": "Punctuator", + "range": [ + 96, + 97 + ], + "loc": { + "end": { + "line": 3, + "column": 42 + }, + "start": { + "line": 3, + "column": 41 + } + }, + "value": ":" + }, + { + "type": "Identifier", + "range": [ + 98, + 104 + ], + "loc": { + "end": { + "line": 3, + "column": 49 + }, + "start": { + "line": 3, + "column": 43 + } + }, + "value": "string" + }, + { + "type": "Punctuator", + "range": [ + 104, + 105 + ], + "loc": { + "end": { + "line": 3, + "column": 50 + }, + "start": { + "line": 3, + "column": 49 + } + }, + "value": "," + }, + { + "type": "Keyword", + "range": [ + 120, + 129 + ], + "loc": { + "end": { + "line": 4, + "column": 23 + }, + "start": { + "line": 4, + "column": 14 + } + }, + "value": "protected" + }, + { + "type": "Identifier", + "range": [ + 130, + 133 + ], + "loc": { + "end": { + "line": 4, + "column": 27 + }, + "start": { + "line": 4, + "column": 24 + } + }, + "value": "age" + }, + { + "loc": { + "end": { + "line": 4, + "column": 28 + }, + "start": { + "line": 4, + "column": 27 + } + }, + "range": [ + 133, + 134 + ], + "type": "Punctuator", + "value": ":" + }, + { + "type": "Identifier", + "range": [ + 135, + 141 + ], + "loc": { + "end": { + "line": 4, + "column": 35 + }, + "start": { + "line": 4, + "column": 29 + } + }, + "value": "number" + }, + { + "type": "Punctuator", + "range": [ + 142, + 143 + ], + "loc": { + "end": { + "line": 4, + "column": 37 + }, + "start": { + "line": 4, + "column": 36 + } + }, + "value": "=" + }, + { + "type": "Numeric", + "range": [ + 144, + 146 + ], + "loc": { + "end": { + "line": 4, + "column": 40 + }, + "start": { + "line": 4, + "column": 38 + } + }, + "value": "30" + }, + { + "type": "Punctuator", + "range": [ + 146, + 147 + ], + "loc": { + "end": { + "line": 4, + "column": 41 + }, + "start": { + "line": 4, + "column": 40 + } + }, + "value": "," + }, + { + "type": "Keyword", + "range": [ + 162, + 171 + ], + "loc": { + "end": { + "line": 5, + "column": 23 + }, + "start": { + "line": 5, + "column": 14 + } + }, + "value": "protected" + }, + { + "type": "Identifier", + "range": [ + 172, + 180 + ], + "loc": { + "end": { + "line": 5, + "column": 32 + }, + "start": { + "line": 5, + "column": 24 + } + }, + "value": "readonly" + }, + { + "type": "Identifier", + "range": [ + 181, + 188 + ], + "loc": { + "end": { + "line": 5, + "column": 40 + }, + "start": { + "line": 5, + "column": 33 + } + }, + "value": "student" + }, + { + "type": "Punctuator", + "range": [ + 188, + 189 + ], + "loc": { + "end": { + "line": 5, + "column": 41 + }, + "start": { + "line": 5, + "column": 40 + } + }, + "value": ":" + }, + { + "type": "Identifier", + "range": [ + 190, + 197 + ], + "loc": { + "end": { + "line": 5, + "column": 49 + }, + "start": { + "line": 5, + "column": 42 + } + }, + "value": "boolean" + }, + { + "type": "Punctuator", + "range": [ + 198, + 199 + ], + "loc": { + "end": { + "line": 5, + "column": 51 + }, + "start": { + "line": 5, + "column": 50 + } + }, + "value": "=" + }, + { + "type": "Boolean", + "range": [ + 200, + 205 + ], + "loc": { + "end": { + "line": 5, + "column": 57 + }, + "start": { + "line": 5, + "column": 52 + } + }, + "value": "false" + }, + { + "type": "Punctuator", + "range": [ + 205, + 206 + ], + "loc": { + "end": { + "line": 5, + "column": 58 + }, + "start": { + "line": 5, + "column": 57 + } + }, + "value": ")" + }, + { + "type": "Punctuator", + "range": [ + 207, + 208 + ], + "loc": { + "end": { + "line": 5, + "column": 60 + }, + "start": { + "line": 5, + "column": 59 + } + }, + "value": "{" + }, + { + "type": "Punctuator", + "range": [ + 208, + 209 + ], + "loc": { + "end": { + "line": 5, + "column": 61 + }, + "start": { + "line": 5, + "column": 60 + } + }, + "value": "}" + }, + { + "type": "Punctuator", + "range": [ + 210, + 211 + ], + "loc": { + "end": { + "line": 6, + "column": 1 + }, + "start": { + "line": 6, + "column": 0 + } + }, + "value": "}" + } + ], +}; \ No newline at end of file diff --git a/tests/fixtures/typescript/basics/class-with-protected-parameter-properties.src.ts b/tests/fixtures/typescript/basics/class-with-protected-parameter-properties.src.ts new file mode 100644 index 0000000..1abd344 --- /dev/null +++ b/tests/fixtures/typescript/basics/class-with-protected-parameter-properties.src.ts @@ -0,0 +1,6 @@ +class Foo { + constructor(protected firstName: string, + protected readonly lastName: string, + protected age: number = 30, + protected readonly student: boolean = false) {} +} \ No newline at end of file diff --git a/tests/fixtures/typescript/basics/class-with-public-parameter-properties.result.js b/tests/fixtures/typescript/basics/class-with-public-parameter-properties.result.js new file mode 100644 index 0000000..777e252 --- /dev/null +++ b/tests/fixtures/typescript/basics/class-with-public-parameter-properties.result.js @@ -0,0 +1,1131 @@ +module.exports = { + "type": "Program", + "range": [ + 0, + 199 + ], + "loc": { + "end": { + "line": 6, + "column": 1 + }, + "start": { + "line": 1, + "column": 0 + } + }, + "body": [ + { + "type": "ClassDeclaration", + "range": [ + 0, + 199 + ], + "loc": { + "end": { + "line": 6, + "column": 1 + }, + "start": { + "line": 1, + "column": 0 + } + }, + "body": { + "type": "ClassBody", + "range": [ + 10, + 199 + ], + "loc": { + "end": { + "line": 6, + "column": 1 + }, + "start": { + "line": 1, + "column": 10 + } + }, + "body": [ + { + "type": "MethodDefinition", + "range": [ + 14, + 197 + ], + "loc": { + "end": { + "line": 5, + "column": 58 + }, + "start": { + "line": 2, + "column": 2 + } + }, + "kind": "constructor", + "accessibility": null, + "computed": false, + "key": { + "type": "Identifier", + "range": [ + 14, + 25 + ], + "loc": { + "end": { + "line": 2, + "column": 13 + }, + "start": { + "line": 2, + "column": 2 + } + }, + "name": "constructor" + }, + "static": false, + "value": { + "type": "FunctionExpression", + "range": [ + 25, + 197 + ], + "loc": { + "end": { + "line": 5, + "column": 58 + }, + "start": { + "line": 2, + "column": 13 + } + }, + "async": false, + "body": { + "type": "BlockStatement", + "range": [ + 195, + 197 + ], + "loc": { + "end": { + "line": 5, + "column": 58 + }, + "start": { + "line": 5, + "column": 56 + } + }, + "body": [] + }, + "expression": false, + "generator": false, + "id": null, + "params": [ + { + "type": "TSParameterProperty", + "range": [ + 26, + 50 + ], + "loc": { + "end": { + "line": 2, + "column": 38 + }, + "start": { + "line": 2, + "column": 14 + } + }, + "decorators": [], + "accessibility": "public", + "isReadonly": false, + "parameter": { + "type": "Identifier", + "range": [ + 33, + 42 + ], + "loc": { + "end": { + "line": 2, + "column": 30 + }, + "start": { + "line": 2, + "column": 21 + } + }, + "name": "firstName", + "typeAnnotation": { + "type": "TypeAnnotation", + "range": [ + 44, + 50 + ], + "loc": { + "end": { + "line": 2, + "column": 38 + }, + "start": { + "line": 2, + "column": 32 + } + }, + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 44, + 50 + ], + "loc": { + "end": { + "line": 2, + "column": 38 + }, + "start": { + "line": 2, + "column": 32 + } + } + } + } + }, + }, + { + "type": "TSParameterProperty", + "range": [ + 66, + 98 + ], + "loc": { + "end": { + "line": 3, + "column": 46 + }, + "start": { + "line": 3, + "column": 14 + } + }, + "decorators": [], + "accessibility": "public", + "isReadonly": true, + "parameter": { + "type": "Identifier", + "range": [ + 82, + 90 + ], + "loc": { + "end": { + "line": 3, + "column": 38 + }, + "start": { + "line": 3, + "column": 30 + } + }, + "name": "lastName", + "typeAnnotation": { + "type": "TypeAnnotation", + "range": [ + 92, + 98 + ], + "loc": { + "end": { + "line": 3, + "column": 46 + }, + "start": { + "line": 3, + "column": 40 + } + }, + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 92, + 98 + ], + "loc": { + "end": { + "line": 3, + "column": 46 + }, + "start": { + "line": 3, + "column": 40 + } + } + } + } + }, + }, + { + "type": "TSParameterProperty", + "range": [ + 114, + 137 + ], + "loc": { + "end": { + "line": 4, + "column": 37 + }, + "start": { + "line": 4, + "column": 14 + } + }, + "decorators": [], + "accessibility": "public", + "isReadonly": false, + "parameter": { + "type": "AssignmentPattern", + "range": [ + 114, + 137 + ], + "loc": { + "end": { + "line": 4, + "column": 37 + }, + "start": { + "line": 4, + "column": 14 + } + }, + "left": { + "type": "Identifier", + "range": [ + 121, + 124 + ], + "loc": { + "end": { + "line": 4, + "column": 24 + }, + "start": { + "line": 4, + "column": 21 + } + }, + "name": "age", + "typeAnnotation": { + "type": "TypeAnnotation", + "range": [ + 126, + 132 + ], + "loc": { + "end": { + "line": 4, + "column": 32 + }, + "start": { + "line": 4, + "column": 26 + } + }, + "typeAnnotation": { + "type": "TSNumberKeyword", + "range": [ + 126, + 132 + ], + "loc": { + "end": { + "line": 4, + "column": 32 + }, + "start": { + "line": 4, + "column": 26 + } + } + } + } + }, + "right": { + "type": "Literal", + "range": [ + 135, + 137 + ], + "loc": { + "end": { + "line": 4, + "column": 37 + }, + "start": { + "line": 4, + "column": 35 + } + }, + "raw": "30", + "value": 30 + } + }, + }, + { + "type": "TSParameterProperty", + "range": [ + 153, + 193 + ], + "loc": { + "end": { + "line": 5, + "column": 54 + }, + "start": { + "line": 5, + "column": 14 + } + }, + "decorators": [], + "accessibility": "public", + "isReadonly": true, + "parameter": { + "type": "AssignmentPattern", + "range": [ + 153, + 193 + ], + "loc": { + "end": { + "line": 5, + "column": 54 + }, + "start": { + "line": 5, + "column": 14 + } + }, + "left": { + "type": "Identifier", + "range": [ + 169, + 176 + ], + "loc": { + "end": { + "line": 5, + "column": 37 + }, + "start": { + "line": 5, + "column": 30 + } + }, + "name": "student", + "typeAnnotation": { + "type": "TypeAnnotation", + "range": [ + 178, + 185 + ], + "loc": { + "end": { + "line": 5, + "column": 46 + }, + "start": { + "line": 5, + "column": 39 + } + }, + "typeAnnotation": { + "type": "TSBooleanKeyword", + "range": [ + 178, + 185 + ], + "loc": { + "end": { + "line": 5, + "column": 46 + }, + "start": { + "line": 5, + "column": 39 + } + } + } + } + }, + "right": { + "type": "Literal", + "range": [ + 188, + 193 + ], + "loc": { + "end": { + "line": 5, + "column": 54 + }, + "start": { + "line": 5, + "column": 49 + } + }, + "raw": "false", + "value": false + } + } + } + ] + } + } + ] + }, + "decorators": [], + "id": { + "type": "Identifier", + "range": [ + 6, + 9 + ], + "loc": { + "end": { + "line": 1, + "column": 9 + }, + "start": { + "line": 1, + "column": 6 + } + }, + "name": "Foo" + }, + "implements": [], + "superClass": null + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "range": [ + 0, + 5 + ], + "loc": { + "end": { + "line": 1, + "column": 5 + }, + "start": { + "line": 1, + "column": 0 + } + }, + "value": "class" + }, + { + "type": "Identifier", + "range": [ + 6, + 9 + ], + "loc": { + "end": { + "line": 1, + "column": 9 + }, + "start": { + "line": 1, + "column": 6 + } + }, + "value": "Foo" + }, + { + "type": "Punctuator", + "range": [ + 10, + 11 + ], + "loc": { + "end": { + "line": 1, + "column": 11 + }, + "start": { + "line": 1, + "column": 10 + } + }, + "value": "{" + }, + { + "type": "Identifier", + "range": [ + 14, + 25 + ], + "loc": { + "end": { + "line": 2, + "column": 13 + }, + "start": { + "line": 2, + "column": 2 + } + }, + "value": "constructor" + }, + { + "type": "Punctuator", + "range": [ + 25, + 26 + ], + "loc": { + "end": { + "line": 2, + "column": 14 + }, + "start": { + "line": 2, + "column": 13 + } + }, + "value": "(" + }, + { + "type": "Keyword", + "range": [ + 26, + 32 + ], + "loc": { + "end": { + "line": 2, + "column": 20 + }, + "start": { + "line": 2, + "column": 14 + } + }, + "value": "public" + }, + { + "type": "Identifier", + "range": [ + 33, + 42 + ], + "loc": { + "end": { + "line": 2, + "column": 30 + }, + "start": { + "line": 2, + "column": 21 + } + }, + "value": "firstName" + }, + { + "type": "Punctuator", + "range": [ + 42, + 43 + ], + "loc": { + "end": { + "line": 2, + "column": 31 + }, + "start": { + "line": 2, + "column": 30 + } + }, + "value": ":" + }, + { + "type": "Identifier", + "range": [ + 44, + 50 + ], + "loc": { + "end": { + "line": 2, + "column": 38 + }, + "start": { + "line": 2, + "column": 32 + } + }, + "value": "string" + }, + { + "type": "Punctuator", + "range": [ + 50, + 51 + ], + "loc": { + "end": { + "line": 2, + "column": 39 + }, + "start": { + "line": 2, + "column": 38 + } + }, + "value": "," + }, + { + "type": "Keyword", + "range": [ + 66, + 72 + ], + "loc": { + "end": { + "line": 3, + "column": 20 + }, + "start": { + "line": 3, + "column": 14 + } + }, + "value": "public" + }, + { + "type": "Identifier", + "range": [ + 73, + 81 + ], + "loc": { + "end": { + "line": 3, + "column": 29 + }, + "start": { + "line": 3, + "column": 21 + } + }, + "value": "readonly" + }, + { + "type": "Identifier", + "range": [ + 82, + 90 + ], + "loc": { + "end": { + "line": 3, + "column": 38 + }, + "start": { + "line": 3, + "column": 30 + } + }, + "value": "lastName" + }, + { + "type": "Punctuator", + "range": [ + 90, + 91 + ], + "loc": { + "end": { + "line": 3, + "column": 39 + }, + "start": { + "line": 3, + "column": 38 + } + }, + "value": ":" + }, + { + "type": "Identifier", + "range": [ + 92, + 98 + ], + "loc": { + "end": { + "line": 3, + "column": 46 + }, + "start": { + "line": 3, + "column": 40 + } + }, + "value": "string" + }, + { + "type": "Punctuator", + "range": [ + 98, + 99 + ], + "loc": { + "end": { + "line": 3, + "column": 47 + }, + "start": { + "line": 3, + "column": 46 + } + }, + "value": "," + }, + { + "type": "Keyword", + "range": [ + 114, + 120 + ], + "loc": { + "end": { + "line": 4, + "column": 20 + }, + "start": { + "line": 4, + "column": 14 + } + }, + "value": "public" + }, + { + "type": "Identifier", + "range": [ + 121, + 124 + ], + "loc": { + "end": { + "line": 4, + "column": 24 + }, + "start": { + "line": 4, + "column": 21 + } + }, + "value": "age" + }, + { + "type": "Punctuator", + "range": [ + 124, + 125 + ], + "loc": { + "end": { + "line": 4, + "column": 25 + }, + "start": { + "line": 4, + "column": 24 + } + }, + "value": ":" + }, + { + "type": "Identifier", + "range": [ + 126, + 132 + ], + "loc": { + "end": { + "line": 4, + "column": 32 + }, + "start": { + "line": 4, + "column": 26 + } + }, + "value": "number" + }, + { + "type": "Punctuator", + "range": [ + 133, + 134 + ], + "loc": { + "end": { + "line": 4, + "column": 34 + }, + "start": { + "line": 4, + "column": 33 + } + }, + "value": "=" + }, + { + "type": "Numeric", + "range": [ + 135, + 137 + ], + "loc": { + "end": { + "line": 4, + "column": 37 + }, + "start": { + "line": 4, + "column": 35 + } + }, + "value": "30" + }, + { + "type": "Punctuator", + "range": [ + 137, + 138 + ], + "loc": { + "end": { + "line": 4, + "column": 38 + }, + "start": { + "line": 4, + "column": 37 + } + }, + "value": "," + }, + { + "type": "Keyword", + "range": [ + 153, + 159 + ], + "loc": { + "end": { + "line": 5, + "column": 20 + }, + "start": { + "line": 5, + "column": 14 + } + }, + "value": "public" + }, + { + "type": "Identifier", + "range": [ + 160, + 168 + ], + "loc": { + "end": { + "line": 5, + "column": 29 + }, + "start": { + "line": 5, + "column": 21 + } + }, + "value": "readonly" + }, + { + "type": "Identifier", + "range": [ + 169, + 176 + ], + "loc": { + "end": { + "line": 5, + "column": 37 + }, + "start": { + "line": 5, + "column": 30 + } + }, + "value": "student" + }, + { + "type": "Punctuator", + "range": [ + 176, + 177 + ], + "loc": { + "end": { + "line": 5, + "column": 38 + }, + "start": { + "line": 5, + "column": 37 + } + }, + "value": ":" + }, + { + "type": "Identifier", + "range": [ + 178, + 185 + ], + "loc": { + "end": { + "line": 5, + "column": 46 + }, + "start": { + "line": 5, + "column": 39 + } + }, + "value": "boolean" + }, + { + "type": "Punctuator", + "range": [ + 186, + 187 + ], + "loc": { + "end": { + "line": 5, + "column": 48 + }, + "start": { + "line": 5, + "column": 47 + } + }, + "value": "=" + }, + { + "type": "Boolean", + "range": [ + 188, + 193 + ], + "loc": { + "end": { + "line": 5, + "column": 54 + }, + "start": { + "line": 5, + "column": 49 + } + }, + "value": "false" + }, + { + "type": "Punctuator", + "range": [ + 193, + 194 + ], + "loc": { + "end": { + "line": 5, + "column": 55 + }, + "start": { + "line": 5, + "column": 54 + } + }, + "value": ")" + }, + { + "type": "Punctuator", + "range": [ + 195, + 196 + ], + "loc": { + "end": { + "line": 5, + "column": 57 + }, + "start": { + "line": 5, + "column": 56 + } + }, + "value": "{" + }, + { + "type": "Punctuator", + "range": [ + 196, + 197 + ], + "loc": { + "end": { + "line": 5, + "column": 58 + }, + "start": { + "line": 5, + "column": 57 + } + }, + "value": "}" + }, + { + "type": "Punctuator", + "range": [ + 198, + 199 + ], + "loc": { + "end": { + "line": 6, + "column": 1 + }, + "start": { + "line": 6, + "column": 0 + } + }, + "value": "}" + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/typescript/basics/class-with-public-parameter-properties.src.ts b/tests/fixtures/typescript/basics/class-with-public-parameter-properties.src.ts new file mode 100644 index 0000000..cf2ee5a --- /dev/null +++ b/tests/fixtures/typescript/basics/class-with-public-parameter-properties.src.ts @@ -0,0 +1,6 @@ +class Foo { + constructor(public firstName: string, + public readonly lastName: string, + public age: number = 30, + public readonly student: boolean = false) {} +} \ No newline at end of file diff --git a/tests/fixtures/typescript/basics/class-with-readonly-parameter-properties.result.js b/tests/fixtures/typescript/basics/class-with-readonly-parameter-properties.result.js new file mode 100644 index 0000000..862b587 --- /dev/null +++ b/tests/fixtures/typescript/basics/class-with-readonly-parameter-properties.result.js @@ -0,0 +1,699 @@ +module.exports = { + "type": "Program", + "range": [ + 0, + 109 + ], + "loc": { + "end": { + "line": 4, + "column": 1 + }, + "start": { + "line": 1, + "column": 0 + } + }, + "body": [ + { + "type": "ClassDeclaration", + "range": [ + 0, + 109 + ], + "loc": { + "end": { + "line": 4, + "column": 1 + }, + "start": { + "line": 1, + "column": 0 + } + }, + "body": { + "type": "ClassBody", + "range": [ + 10, + 109 + ], + "loc": { + "end": { + "line": 4, + "column": 1 + }, + "start": { + "line": 1, + "column": 10 + } + }, + "body": [ + { + "type": "MethodDefinition", + "range": [ + 14, + 107 + ], + "loc": { + "end": { + "line": 3, + "column": 53 + }, + "start": { + "line": 2, + "column": 2 + } + }, + "kind": "constructor", + "accessibility": null, + "computed": false, + "key": { + "type": "Identifier", + "range": [ + 14, + 25 + ], + "loc": { + "end": { + "line": 2, + "column": 13 + }, + "start": { + "line": 2, + "column": 2 + } + }, + "name": "constructor" + }, + "static": false, + "value": { + "type": "FunctionExpression", + "range": [ + 25, + 107 + ], + "loc": { + "end": { + "line": 3, + "column": 53 + }, + "start": { + "line": 2, + "column": 13 + } + }, + "async": false, + "body": { + "type": "BlockStatement", + "range": [ + 105, + 107 + ], + "loc": { + "end": { + "line": 3, + "column": 53 + }, + "start": { + "line": 3, + "column": 51 + } + }, + "body": [] + }, + "expression": false, + "generator": false, + "id": null, + "params": [ + { + "type": "TSParameterProperty", + "range": [ + 26, + 52 + ], + "loc": { + "end": { + "line": 2, + "column": 40 + }, + "start": { + "line": 2, + "column": 14 + } + }, + "decorators": [], + "accessibility": null, + "isReadonly": true, + "parameter": { + "type": "Identifier", + "range": [ + 35, + 44 + ], + "loc": { + "end": { + "line": 2, + "column": 32 + }, + "start": { + "line": 2, + "column": 23 + } + }, + "name": "firstName", + "typeAnnotation": { + "type": "TypeAnnotation", + "range": [ + 46, + 52 + ], + "loc": { + "end": { + "line": 2, + "column": 40 + }, + "start": { + "line": 2, + "column": 34 + } + }, + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 46, + 52 + ], + "loc": { + "end": { + "line": 2, + "column": 40 + }, + "start": { + "line": 2, + "column": 34 + } + } + } + } + } + }, + { + "type": "TSParameterProperty", + "range": [ + 68, + 103 + ], + "loc": { + "end": { + "line": 3, + "column": 49 + }, + "start": { + "line": 3, + "column": 14 + } + }, + "decorators": [], + "accessibility": null, + "isReadonly": true, + "parameter": { + "type": "AssignmentPattern", + "range": [ + 68, + 103 + ], + "loc": { + "end": { + "line": 3, + "column": 49 + }, + "start": { + "line": 3, + "column": 14 + } + }, + "left": { + "type": "Identifier", + "range": [ + 77, + 85 + ], + "loc": { + "end": { + "line": 3, + "column": 31 + }, + "start": { + "line": 3, + "column": 23 + } + }, + "name": "lastName", + "typeAnnotation": { + "type": "TypeAnnotation", + "range": [ + 87, + 93 + ], + "loc": { + "end": { + "line": 3, + "column": 39 + }, + "start": { + "line": 3, + "column": 33 + } + }, + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 87, + 93 + ], + "loc": { + "end": { + "line": 3, + "column": 39 + }, + "start": { + "line": 3, + "column": 33 + } + } + } + } + }, + "right": { + "type": "Literal", + "range": [ + 96, + 103 + ], + "loc": { + "end": { + "line": 3, + "column": 49 + }, + "start": { + "line": 3, + "column": 42 + } + }, + "raw": "'Smith'", + "value": "Smith" + }, + } + } + ] + } + } + ] + }, + "decorators": [], + "id": { + "type": "Identifier", + "range": [ + 6, + 9 + ], + "loc": { + "end": { + "line": 1, + "column": 9 + }, + "start": { + "line": 1, + "column": 6 + } + }, + "name": "Foo" + }, + "implements": [], + "superClass": null + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "range": [ + 0, + 5 + ], + "loc": { + "end": { + "line": 1, + "column": 5 + }, + "start": { + "line": 1, + "column": 0 + } + }, + "value": "class" + }, + { + "type": "Identifier", + "range": [ + 6, + 9 + ], + "loc": { + "end": { + "line": 1, + "column": 9 + }, + "start": { + "line": 1, + "column": 6 + } + }, + "value": "Foo" + }, + { + "type": "Punctuator", + "range": [ + 10, + 11 + ], + "loc": { + "end": { + "line": 1, + "column": 11 + }, + "start": { + "line": 1, + "column": 10 + } + }, + "value": "{" + }, + { + "type": "Identifier", + "range": [ + 14, + 25 + ], + "loc": { + "end": { + "line": 2, + "column": 13 + }, + "start": { + "line": 2, + "column": 2 + } + }, + "value": "constructor" + }, + { + "type": "Punctuator", + "range": [ + 25, + 26 + ], + "loc": { + "end": { + "line": 2, + "column": 14 + }, + "start": { + "line": 2, + "column": 13 + } + }, + "value": "(" + }, + { + "type": "Identifier", + "range": [ + 26, + 34 + ], + "loc": { + "end": { + "line": 2, + "column": 22 + }, + "start": { + "line": 2, + "column": 14 + } + }, + "value": "readonly" + }, + { + "type": "Identifier", + "range": [ + 35, + 44 + ], + "loc": { + "end": { + "line": 2, + "column": 32 + }, + "start": { + "line": 2, + "column": 23 + } + }, + "value": "firstName" + }, + { + "type": "Punctuator", + "range": [ + 44, + 45 + ], + "loc": { + "end": { + "line": 2, + "column": 33 + }, + "start": { + "line": 2, + "column": 32 + } + }, + "value": ":" + }, + { + "type": "Identifier", + "range": [ + 46, + 52 + ], + "loc": { + "end": { + "line": 2, + "column": 40 + }, + "start": { + "line": 2, + "column": 34 + } + }, + "value": "string" + }, + { + "type": "Punctuator", + "range": [ + 52, + 53 + ], + "loc": { + "end": { + "line": 2, + "column": 41 + }, + "start": { + "line": 2, + "column": 40 + } + }, + "value": "," + }, + { + "type": "Identifier", + "range": [ + 68, + 76 + ], + "loc": { + "end": { + "line": 3, + "column": 22 + }, + "start": { + "line": 3, + "column": 14 + } + }, + "value": "readonly" + }, + { + "type": "Identifier", + "range": [ + 77, + 85 + ], + "loc": { + "end": { + "line": 3, + "column": 31 + }, + "start": { + "line": 3, + "column": 23 + } + }, + "value": "lastName" + }, + { + "type": "Punctuator", + "range": [ + 85, + 86 + ], + "loc": { + "end": { + "line": 3, + "column": 32 + }, + "start": { + "line": 3, + "column": 31 + } + }, + "value": ":" + }, + { + "type": "Identifier", + "range": [ + 87, + 93 + ], + "loc": { + "end": { + "line": 3, + "column": 39 + }, + "start": { + "line": 3, + "column": 33 + } + }, + "value": "string" + }, + { + "type": "Punctuator", + "range": [ + 94, + 95 + ], + "loc": { + "end": { + "line": 3, + "column": 41 + }, + "start": { + "line": 3, + "column": 40 + } + }, + "value": "=" + }, + { + "type": "String", + "range": [ + 96, + 103 + ], + "loc": { + "end": { + "line": 3, + "column": 49 + }, + "start": { + "line": 3, + "column": 42 + } + }, + "value": "'Smith'" + }, + { + "type": "Punctuator", + "range": [ + 103, + 104 + ], + "loc": { + "end": { + "line": 3, + "column": 50 + }, + "start": { + "line": 3, + "column": 49 + } + }, + "value": ")" + }, + { + "type": "Punctuator", + "range": [ + 105, + 106 + ], + "loc": { + "end": { + "line": 3, + "column": 52 + }, + "start": { + "line": 3, + "column": 51 + } + }, + "value": "{" + }, + { + "type": "Punctuator", + "range": [ + 106, + 107 + ], + "loc": { + "end": { + "line": 3, + "column": 53 + }, + "start": { + "line": 3, + "column": 52 + } + }, + "value": "}" + }, + { + "type": "Punctuator", + "range": [ + 108, + 109 + ], + "loc": { + "end": { + "line": 4, + "column": 1 + }, + "start": { + "line": 4, + "column": 0 + } + }, + "value": "}" + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/typescript/basics/class-with-readonly-parameter-properties.src.ts b/tests/fixtures/typescript/basics/class-with-readonly-parameter-properties.src.ts new file mode 100644 index 0000000..2525c67 --- /dev/null +++ b/tests/fixtures/typescript/basics/class-with-readonly-parameter-properties.src.ts @@ -0,0 +1,4 @@ +class Foo { + constructor(readonly firstName: string, + readonly lastName: string = 'Smith') {} +} \ No newline at end of file