diff --git a/lib/convert.js b/lib/convert.js index 5564eae..3eee332 100644 --- a/lib/convert.js +++ b/lib/convert.js @@ -1104,6 +1104,8 @@ module.exports = function convert(config) { loc: nodeUtils.getLoc(node, ast), accessibility: nodeUtils.getTSNodeAccessibility(node), isReadonly: nodeUtils.hasModifier(SyntaxKind.ReadonlyKeyword, node), + static: nodeUtils.hasModifier(SyntaxKind.StaticKeyword, node), + export: nodeUtils.hasModifier(SyntaxKind.ExportKeyword, node), parameter: result }; } diff --git a/tests/fixtures/typescript/basics/class-with-export-parameter-properties.result.js b/tests/fixtures/typescript/basics/class-with-export-parameter-properties.result.js new file mode 100644 index 0000000..0bbff21 --- /dev/null +++ b/tests/fixtures/typescript/basics/class-with-export-parameter-properties.result.js @@ -0,0 +1,467 @@ +module.exports = { + "type": "Program", + "range": [ + 0, + 56 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "body": [ + { + "type": "ClassDeclaration", + "range": [ + 0, + 56 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "range": [ + 6, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "name": "Foo" + }, + "body": { + "type": "ClassBody", + "body": [ + { + "type": "MethodDefinition", + "range": [ + 16, + 54 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 4, + "column": 5 + } + }, + "key": { + "type": "Identifier", + "name": "constructor", + "range": [ + 16, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 15 + } + } + }, + "value": { + "type": "FunctionExpression", + "id": null, + "params": [ + { + "type": "TSParameterProperty", + "range": [ + 28, + 44 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 32 + } + }, + "accessibility": null, + "isReadonly": false, + "static": false, + "export": true, + "parameter": { + "type": "Identifier", + "range": [ + 35, + 36 + ], + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "name": "a", + "typeAnnotation": { + "type": "TypeAnnotation", + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 32 + } + }, + "range": [ + 38, + 44 + ], + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 38, + 44 + ], + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 32 + } + } + } + } + }, + "decorators": [] + } + ], + "generator": false, + "expression": false, + "async": false, + "body": { + "type": "BlockStatement", + "range": [ + 46, + 54 + ], + "loc": { + "start": { + "line": 2, + "column": 34 + }, + "end": { + "line": 4, + "column": 5 + } + }, + "body": [] + }, + "range": [ + 27, + 54 + ], + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 4, + "column": 5 + } + } + }, + "computed": false, + "accessibility": null, + "static": false, + "kind": "constructor" + } + ], + "range": [ + 10, + 56 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 5, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "decorators": [] + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "class", + "range": [ + 0, + 5 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + } + }, + { + "type": "Identifier", + "value": "Foo", + "range": [ + 6, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 10, + 11 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + } + }, + { + "type": "Identifier", + "value": "constructor", + "range": [ + 16, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 27, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + { + "type": "Keyword", + "value": "export", + "range": [ + 28, + 34 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 22 + } + } + }, + { + "type": "Identifier", + "value": "a", + "range": [ + 35, + 36 + ], + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 25 + } + } + }, + { + "type": "Identifier", + "value": "string", + "range": [ + 38, + 44 + ], + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 32 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 44, + 45 + ], + "loc": { + "start": { + "line": 2, + "column": 32 + }, + "end": { + "line": 2, + "column": 33 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 46, + 47 + ], + "loc": { + "start": { + "line": 2, + "column": 34 + }, + "end": { + "line": 2, + "column": 35 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 53, + 54 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 55, + 56 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + } + } + ] +}; diff --git a/tests/fixtures/typescript/basics/class-with-export-parameter-properties.src.ts b/tests/fixtures/typescript/basics/class-with-export-parameter-properties.src.ts new file mode 100644 index 0000000..f1befb2 --- /dev/null +++ b/tests/fixtures/typescript/basics/class-with-export-parameter-properties.src.ts @@ -0,0 +1,6 @@ +class Foo { + constructor(export a: string) { + + } +} + 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 index 464b490..2d64e5f 100644 --- a/tests/fixtures/typescript/basics/class-with-private-parameter-properties.result.js +++ b/tests/fixtures/typescript/basics/class-with-private-parameter-properties.result.js @@ -114,6 +114,8 @@ module.exports = { "decorators": [], "accessibility": "private", "isReadonly": false, + "static": false, + "export": false, "parameter": { "type": "Identifier", "range": [ @@ -186,6 +188,8 @@ module.exports = { "decorators": [], "accessibility": "private", "isReadonly": true, + "static": false, + "export": false, "parameter": { "type": "Identifier", "range": [ @@ -258,6 +262,8 @@ module.exports = { "decorators": [], "accessibility": "private", "isReadonly": false, + "static": false, + "export": false, "parameter": { "left": { "type": "Identifier", @@ -366,6 +372,8 @@ module.exports = { "decorators": [], "accessibility": "private", "isReadonly": true, + "static": false, + "export": false, "parameter": { "left": { "type": "Identifier", @@ -1128,4 +1136,4 @@ module.exports = { "value": "}" } ], -}; \ 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 index 412dc9a..31a388e 100644 --- a/tests/fixtures/typescript/basics/class-with-protected-parameter-properties.result.js +++ b/tests/fixtures/typescript/basics/class-with-protected-parameter-properties.result.js @@ -144,6 +144,8 @@ module.exports = { "decorators": [], "accessibility": "protected", "isReadonly": false, + "static": false, + "export": false, "parameter": { "type": "Identifier", "range": [ @@ -216,6 +218,8 @@ module.exports = { "decorators": [], "accessibility": "protected", "isReadonly": true, + "static": false, + "export": false, "parameter": { "type": "Identifier", "range": [ @@ -288,6 +292,8 @@ module.exports = { "decorators": [], "accessibility": "protected", "isReadonly": false, + "static": false, + "export": false, "parameter": { "type": "AssignmentPattern", "range": [ @@ -396,6 +402,8 @@ module.exports = { "decorators": [], "accessibility": "protected", "isReadonly": true, + "static": false, + "export": false, "parameter": { "type": "AssignmentPattern", "range": [ @@ -1128,4 +1136,4 @@ module.exports = { "value": "}" } ], -}; \ 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 index 777e252..a29e488 100644 --- a/tests/fixtures/typescript/basics/class-with-public-parameter-properties.result.js +++ b/tests/fixtures/typescript/basics/class-with-public-parameter-properties.result.js @@ -144,6 +144,8 @@ module.exports = { "decorators": [], "accessibility": "public", "isReadonly": false, + "static": false, + "export": false, "parameter": { "type": "Identifier", "range": [ @@ -216,6 +218,8 @@ module.exports = { "decorators": [], "accessibility": "public", "isReadonly": true, + "static": false, + "export": false, "parameter": { "type": "Identifier", "range": [ @@ -288,6 +292,8 @@ module.exports = { "decorators": [], "accessibility": "public", "isReadonly": false, + "static": false, + "export": false, "parameter": { "type": "AssignmentPattern", "range": [ @@ -396,6 +402,8 @@ module.exports = { "decorators": [], "accessibility": "public", "isReadonly": true, + "static": false, + "export": false, "parameter": { "type": "AssignmentPattern", "range": [ @@ -1128,4 +1136,4 @@ module.exports = { "value": "}" } ] -}; \ 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 index 862b587..9823df6 100644 --- a/tests/fixtures/typescript/basics/class-with-readonly-parameter-properties.result.js +++ b/tests/fixtures/typescript/basics/class-with-readonly-parameter-properties.result.js @@ -144,6 +144,8 @@ module.exports = { "decorators": [], "accessibility": null, "isReadonly": true, + "static": false, + "export": false, "parameter": { "type": "Identifier", "range": [ @@ -216,6 +218,8 @@ module.exports = { "decorators": [], "accessibility": null, "isReadonly": true, + "static": false, + "export": false, "parameter": { "type": "AssignmentPattern", "range": [ @@ -696,4 +700,4 @@ module.exports = { "value": "}" } ] -}; \ No newline at end of file +}; diff --git a/tests/fixtures/typescript/basics/class-with-static-parameter-properties.result.js b/tests/fixtures/typescript/basics/class-with-static-parameter-properties.result.js new file mode 100644 index 0000000..d5c7807 --- /dev/null +++ b/tests/fixtures/typescript/basics/class-with-static-parameter-properties.result.js @@ -0,0 +1,467 @@ +module.exports = { + "type": "Program", + "range": [ + 0, + 56 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "body": [ + { + "type": "ClassDeclaration", + "range": [ + 0, + 56 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "range": [ + 6, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "name": "Foo" + }, + "body": { + "type": "ClassBody", + "body": [ + { + "type": "MethodDefinition", + "range": [ + 16, + 54 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 4, + "column": 5 + } + }, + "key": { + "type": "Identifier", + "name": "constructor", + "range": [ + 16, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 15 + } + } + }, + "value": { + "type": "FunctionExpression", + "id": null, + "params": [ + { + "type": "TSParameterProperty", + "range": [ + 28, + 44 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 32 + } + }, + "accessibility": null, + "isReadonly": false, + "static": true, + "export": false, + "parameter": { + "type": "Identifier", + "range": [ + 35, + 36 + ], + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "name": "a", + "typeAnnotation": { + "type": "TypeAnnotation", + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 32 + } + }, + "range": [ + 38, + 44 + ], + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 38, + 44 + ], + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 32 + } + } + } + } + }, + "decorators": [] + } + ], + "generator": false, + "expression": false, + "async": false, + "body": { + "type": "BlockStatement", + "range": [ + 46, + 54 + ], + "loc": { + "start": { + "line": 2, + "column": 34 + }, + "end": { + "line": 4, + "column": 5 + } + }, + "body": [] + }, + "range": [ + 27, + 54 + ], + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 4, + "column": 5 + } + } + }, + "computed": false, + "accessibility": null, + "static": false, + "kind": "constructor" + } + ], + "range": [ + 10, + 56 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 5, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "decorators": [] + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "class", + "range": [ + 0, + 5 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + } + }, + { + "type": "Identifier", + "value": "Foo", + "range": [ + 6, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 10, + 11 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + } + }, + { + "type": "Identifier", + "value": "constructor", + "range": [ + 16, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 27, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + { + "type": "Keyword", + "value": "static", + "range": [ + 28, + 34 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 22 + } + } + }, + { + "type": "Identifier", + "value": "a", + "range": [ + 35, + 36 + ], + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 25 + } + } + }, + { + "type": "Identifier", + "value": "string", + "range": [ + 38, + 44 + ], + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 32 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 44, + 45 + ], + "loc": { + "start": { + "line": 2, + "column": 32 + }, + "end": { + "line": 2, + "column": 33 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 46, + 47 + ], + "loc": { + "start": { + "line": 2, + "column": 34 + }, + "end": { + "line": 2, + "column": 35 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 53, + 54 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 55, + 56 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + } + } + ] +}; diff --git a/tests/fixtures/typescript/basics/class-with-static-parameter-properties.src.ts b/tests/fixtures/typescript/basics/class-with-static-parameter-properties.src.ts new file mode 100644 index 0000000..b113775 --- /dev/null +++ b/tests/fixtures/typescript/basics/class-with-static-parameter-properties.src.ts @@ -0,0 +1,7 @@ +class Foo { + constructor(static a: string) { + + } +} + + diff --git a/tests/fixtures/typescript/basics/interface-with-construct-signature-with-parameter-accessibility.result.js b/tests/fixtures/typescript/basics/interface-with-construct-signature-with-parameter-accessibility.result.js index bbf54d5..cd7f56c 100644 --- a/tests/fixtures/typescript/basics/interface-with-construct-signature-with-parameter-accessibility.result.js +++ b/tests/fixtures/typescript/basics/interface-with-construct-signature-with-parameter-accessibility.result.js @@ -71,6 +71,8 @@ module.exports = { }, "accessibility": "public", "isReadonly": false, + "static": false, + "export": false, "parameter": { "type": "Identifier", "range": [ @@ -108,6 +110,8 @@ module.exports = { }, "accessibility": "private", "isReadonly": false, + "static": false, + "export": false, "parameter": { "type": "Identifier", "range": [ @@ -403,4 +407,4 @@ module.exports = { } } ] -}; \ No newline at end of file +};