From 208c153114fcda5df5196d01503aecf41e0bf7cc Mon Sep 17 00:00:00 2001 From: James Henry Date: Mon, 22 Aug 2016 21:44:09 +0100 Subject: [PATCH] New: Add method decorators to AST (fixes #65) --- lib/ast-converter.js | 5 +- .../export-default-anonymous-class.result.js | 1 + .../class-accessor-properties.result.js | 2 + .../class-computed-static-method.result.js | 1 + .../class-method-named-prototype.result.js | 1 + .../class-method-named-static.result.js | 1 + .../classes/class-one-method-super.result.js | 1 + .../classes/class-one-method.result.js | 1 + ...ss-static-method-named-prototype.result.js | 1 + ...class-static-method-named-static.result.js | 1 + .../classes/class-static-method.result.js | 1 + ...-methods-and-accessor-properties.result.js | 3 + ...lass-two-computed-static-methods.result.js | 2 + ...two-methods-computed-constructor.result.js | 2 + .../classes/class-two-methods-semi.result.js | 2 + .../class-two-methods-three-semi.result.js | 2 + .../class-two-methods-two-semi.result.js | 2 + .../classes/class-two-methods.result.js | 2 + ...ecorator-factory-instance-member.result.js | 465 +++++++++++++++++ ...d-decorator-factory-instance-member.src.ts | 4 + ...-decorator-factory-static-member.result.js | 483 ++++++++++++++++++ ...hod-decorator-factory-static-member.src.ts | 4 + ...method-decorator-instance-member.result.js | 373 ++++++++++++++ .../method-decorator-instance-member.src.ts | 4 + .../method-decorator-static-member.result.js | 391 ++++++++++++++ .../method-decorator-static-member.src.ts | 4 + 26 files changed, 1758 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/typescript/decorators/method-decorators/method-decorator-factory-instance-member.result.js create mode 100644 tests/fixtures/typescript/decorators/method-decorators/method-decorator-factory-instance-member.src.ts create mode 100644 tests/fixtures/typescript/decorators/method-decorators/method-decorator-factory-static-member.result.js create mode 100644 tests/fixtures/typescript/decorators/method-decorators/method-decorator-factory-static-member.src.ts create mode 100644 tests/fixtures/typescript/decorators/method-decorators/method-decorator-instance-member.result.js create mode 100644 tests/fixtures/typescript/decorators/method-decorators/method-decorator-instance-member.src.ts create mode 100644 tests/fixtures/typescript/decorators/method-decorators/method-decorator-static-member.result.js create mode 100644 tests/fixtures/typescript/decorators/method-decorators/method-decorator-static-member.src.ts diff --git a/lib/ast-converter.js b/lib/ast-converter.js index 528b180..3e664ee 100644 --- a/lib/ast-converter.js +++ b/lib/ast-converter.js @@ -993,7 +993,10 @@ module.exports = function(ast, extra) { value: method, computed: methodNameIsComputed, static: Boolean(node.flags & ts.NodeFlags.Static), - kind: "method" + kind: "method", + decorators: (node.decorators) ? node.decorators.map(function(d) { + return convertChild(d.expression); + }) : [] }); } diff --git a/tests/fixtures/attach-comments/export-default-anonymous-class.result.js b/tests/fixtures/attach-comments/export-default-anonymous-class.result.js index 0e4c7d9..035cd83 100644 --- a/tests/fixtures/attach-comments/export-default-anonymous-class.result.js +++ b/tests/fixtures/attach-comments/export-default-anonymous-class.result.js @@ -72,6 +72,7 @@ module.exports = { }, "kind": "method", "computed": false, + "decorators": [], "range": [ 103, 119 diff --git a/tests/fixtures/ecma-features/classes/class-accessor-properties.result.js b/tests/fixtures/ecma-features/classes/class-accessor-properties.result.js index b607f3b..f0f7cbc 100644 --- a/tests/fixtures/ecma-features/classes/class-accessor-properties.result.js +++ b/tests/fixtures/ecma-features/classes/class-accessor-properties.result.js @@ -85,6 +85,7 @@ module.exports = { 18 ], "computed": false, + "decorators": [], "key": { "type": "Identifier", "loc": { @@ -162,6 +163,7 @@ module.exports = { 29 ], "computed": false, + "decorators": [], "key": { "type": "Identifier", "loc": { diff --git a/tests/fixtures/ecma-features/classes/class-computed-static-method.result.js b/tests/fixtures/ecma-features/classes/class-computed-static-method.result.js index ac3cf9a..c26bbfc 100644 --- a/tests/fixtures/ecma-features/classes/class-computed-static-method.result.js +++ b/tests/fixtures/ecma-features/classes/class-computed-static-method.result.js @@ -85,6 +85,7 @@ module.exports = { 23 ], "computed": true, + "decorators": [], "key": { "type": "Identifier", "loc": { diff --git a/tests/fixtures/ecma-features/classes/class-method-named-prototype.result.js b/tests/fixtures/ecma-features/classes/class-method-named-prototype.result.js index 1abfdcb..14fb1a3 100644 --- a/tests/fixtures/ecma-features/classes/class-method-named-prototype.result.js +++ b/tests/fixtures/ecma-features/classes/class-method-named-prototype.result.js @@ -85,6 +85,7 @@ module.exports = { 22 ], "computed": false, + "decorators": [], "key": { "type": "Identifier", "loc": { diff --git a/tests/fixtures/ecma-features/classes/class-method-named-static.result.js b/tests/fixtures/ecma-features/classes/class-method-named-static.result.js index d0f8e1a..935429a 100644 --- a/tests/fixtures/ecma-features/classes/class-method-named-static.result.js +++ b/tests/fixtures/ecma-features/classes/class-method-named-static.result.js @@ -85,6 +85,7 @@ module.exports = { 19 ], "computed": false, + "decorators": [], "key": { "type": "Identifier", "loc": { diff --git a/tests/fixtures/ecma-features/classes/class-one-method-super.result.js b/tests/fixtures/ecma-features/classes/class-one-method-super.result.js index 245ba91..867cd1a 100644 --- a/tests/fixtures/ecma-features/classes/class-one-method-super.result.js +++ b/tests/fixtures/ecma-features/classes/class-one-method-super.result.js @@ -85,6 +85,7 @@ module.exports = { 41 ], "computed": false, + "decorators": [], "key": { "type": "Identifier", "loc": { diff --git a/tests/fixtures/ecma-features/classes/class-one-method.result.js b/tests/fixtures/ecma-features/classes/class-one-method.result.js index 12380f6..d328f63 100644 --- a/tests/fixtures/ecma-features/classes/class-one-method.result.js +++ b/tests/fixtures/ecma-features/classes/class-one-method.result.js @@ -85,6 +85,7 @@ module.exports = { 19 ], "computed": false, + "decorators": [], "key": { "type": "Identifier", "loc": { diff --git a/tests/fixtures/ecma-features/classes/class-static-method-named-prototype.result.js b/tests/fixtures/ecma-features/classes/class-static-method-named-prototype.result.js index f8d53e4..520fce1 100644 --- a/tests/fixtures/ecma-features/classes/class-static-method-named-prototype.result.js +++ b/tests/fixtures/ecma-features/classes/class-static-method-named-prototype.result.js @@ -85,6 +85,7 @@ module.exports = { 33 ], "computed": true, + "decorators": [], "key": { "type": "Literal", "loc": { diff --git a/tests/fixtures/ecma-features/classes/class-static-method-named-static.result.js b/tests/fixtures/ecma-features/classes/class-static-method-named-static.result.js index 75491db..d208df8 100644 --- a/tests/fixtures/ecma-features/classes/class-static-method-named-static.result.js +++ b/tests/fixtures/ecma-features/classes/class-static-method-named-static.result.js @@ -85,6 +85,7 @@ module.exports = { 26 ], "computed": false, + "decorators": [], "key": { "type": "Identifier", "loc": { diff --git a/tests/fixtures/ecma-features/classes/class-static-method.result.js b/tests/fixtures/ecma-features/classes/class-static-method.result.js index d4bfefd..368b27a 100644 --- a/tests/fixtures/ecma-features/classes/class-static-method.result.js +++ b/tests/fixtures/ecma-features/classes/class-static-method.result.js @@ -85,6 +85,7 @@ module.exports = { 21 ], "computed": false, + "decorators": [], "key": { "type": "Identifier", "loc": { diff --git a/tests/fixtures/ecma-features/classes/class-static-methods-and-accessor-properties.result.js b/tests/fixtures/ecma-features/classes/class-static-methods-and-accessor-properties.result.js index e321241..cc4556a 100644 --- a/tests/fixtures/ecma-features/classes/class-static-methods-and-accessor-properties.result.js +++ b/tests/fixtures/ecma-features/classes/class-static-methods-and-accessor-properties.result.js @@ -85,6 +85,7 @@ module.exports = { 21 ], "computed": false, + "decorators": [], "key": { "type": "Identifier", "loc": { @@ -162,6 +163,7 @@ module.exports = { 38 ], "computed": false, + "decorators": [], "key": { "type": "Identifier", "loc": { @@ -239,6 +241,7 @@ module.exports = { 56 ], "computed": false, + "decorators": [], "key": { "type": "Identifier", "loc": { diff --git a/tests/fixtures/ecma-features/classes/class-two-computed-static-methods.result.js b/tests/fixtures/ecma-features/classes/class-two-computed-static-methods.result.js index 51cc0a6..83c7099 100644 --- a/tests/fixtures/ecma-features/classes/class-two-computed-static-methods.result.js +++ b/tests/fixtures/ecma-features/classes/class-two-computed-static-methods.result.js @@ -85,6 +85,7 @@ module.exports = { 22 ], "computed": true, + "decorators": [], "key": { "type": "Identifier", "loc": { @@ -162,6 +163,7 @@ module.exports = { 37 ], "computed": true, + "decorators": [], "key": { "type": "Identifier", "loc": { diff --git a/tests/fixtures/ecma-features/classes/class-two-methods-computed-constructor.result.js b/tests/fixtures/ecma-features/classes/class-two-methods-computed-constructor.result.js index 6d5ce4e..9f6309f 100644 --- a/tests/fixtures/ecma-features/classes/class-two-methods-computed-constructor.result.js +++ b/tests/fixtures/ecma-features/classes/class-two-methods-computed-constructor.result.js @@ -85,6 +85,7 @@ module.exports = { 26 ], "computed": false, + "decorators": [], "key": { "type": "Literal", "loc": { @@ -163,6 +164,7 @@ module.exports = { 46 ], "computed": true, + "decorators": [], "key": { "type": "Literal", "loc": { diff --git a/tests/fixtures/ecma-features/classes/class-two-methods-semi.result.js b/tests/fixtures/ecma-features/classes/class-two-methods-semi.result.js index d0a2c12..3780003 100644 --- a/tests/fixtures/ecma-features/classes/class-two-methods-semi.result.js +++ b/tests/fixtures/ecma-features/classes/class-two-methods-semi.result.js @@ -85,6 +85,7 @@ module.exports = { 14 ], "computed": false, + "decorators": [], "key": { "type": "Identifier", "loc": { @@ -162,6 +163,7 @@ module.exports = { 20 ], "computed": false, + "decorators": [], "key": { "type": "Identifier", "loc": { diff --git a/tests/fixtures/ecma-features/classes/class-two-methods-three-semi.result.js b/tests/fixtures/ecma-features/classes/class-two-methods-three-semi.result.js index 76e07a5..72029d9 100644 --- a/tests/fixtures/ecma-features/classes/class-two-methods-three-semi.result.js +++ b/tests/fixtures/ecma-features/classes/class-two-methods-three-semi.result.js @@ -85,6 +85,7 @@ module.exports = { 15 ], "computed": false, + "decorators": [], "key": { "type": "Identifier", "loc": { @@ -162,6 +163,7 @@ module.exports = { 21 ], "computed": false, + "decorators": [], "key": { "type": "Identifier", "loc": { diff --git a/tests/fixtures/ecma-features/classes/class-two-methods-two-semi.result.js b/tests/fixtures/ecma-features/classes/class-two-methods-two-semi.result.js index 01735f7..3dd0d8b 100644 --- a/tests/fixtures/ecma-features/classes/class-two-methods-two-semi.result.js +++ b/tests/fixtures/ecma-features/classes/class-two-methods-two-semi.result.js @@ -85,6 +85,7 @@ module.exports = { 14 ], "computed": false, + "decorators": [], "key": { "type": "Identifier", "loc": { @@ -162,6 +163,7 @@ module.exports = { 20 ], "computed": false, + "decorators": [], "key": { "type": "Identifier", "loc": { diff --git a/tests/fixtures/ecma-features/classes/class-two-methods.result.js b/tests/fixtures/ecma-features/classes/class-two-methods.result.js index 2ea4519..c545cd5 100644 --- a/tests/fixtures/ecma-features/classes/class-two-methods.result.js +++ b/tests/fixtures/ecma-features/classes/class-two-methods.result.js @@ -85,6 +85,7 @@ module.exports = { 14 ], "computed": false, + "decorators": [], "key": { "type": "Identifier", "loc": { @@ -162,6 +163,7 @@ module.exports = { 19 ], "computed": false, + "decorators": [], "key": { "type": "Identifier", "loc": { diff --git a/tests/fixtures/typescript/decorators/method-decorators/method-decorator-factory-instance-member.result.js b/tests/fixtures/typescript/decorators/method-decorators/method-decorator-factory-instance-member.result.js new file mode 100644 index 0000000..2811d90 --- /dev/null +++ b/tests/fixtures/typescript/decorators/method-decorators/method-decorator-factory-instance-member.result.js @@ -0,0 +1,465 @@ +module.exports = { + "type": "Program", + "range": [ + 0, + 56 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassDeclaration", + "range": [ + 0, + 56 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "name": "B" + }, + "body": { + "type": "ClassBody", + "body": [ + { + "type": "MethodDefinition", + "range": [ + 14, + 54 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 3, + "column": 23 + } + }, + "key": { + "type": "Identifier", + "range": [ + 35, + 49 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "name": "instanceMethod" + }, + "value": { + "type": "FunctionExpression", + "id": null, + "params": [], + "generator": false, + "expression": false, + "body": { + "type": "BlockStatement", + "range": [ + 52, + 54 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 23 + } + }, + "body": [] + }, + "range": [ + 49, + 54 + ], + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 23 + } + } + }, + "computed": false, + "static": false, + "kind": "method", + "decorators": [ + { + "arguments": [ + { + "loc": { + "end": { + "column": 19, + "line": 2 + }, + "start": { + "column": 14, + "line": 2 + } + }, + "range": [ + 24, + 29 + ], + "raw": "false", + "type": "Literal", + "value": false + } + ], + "callee": { + "loc": { + "end": { + "column": 13, + "line": 2 + }, + "start": { + "column": 5, + "line": 2 + } + }, + "name": "readonly", + "range": [ + 15, + 23 + ], + "type": "Identifier" + }, + "loc": { + "end": { + "column": 20, + "line": 2 + }, + "start": { + "column": 5, + "line": 2 + } + }, + "range": [ + 15, + 30 + ], + "type": "CallExpression" + } + ] + } + ], + "range": [ + 8, + 56 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + } + }, + "superClass": null, + "implements": [] + } + ], + "sourceType": "script", + "tokens": [ + { + "loc": { + "end": { + "column": 5, + "line": 1 + }, + "start": { + "column": 0, + "line": 1 + } + }, + "range": [ + 0, + 5 + ], + "type": "Keyword", + "value": "class" + }, + { + "loc": { + "end": { + "column": 7, + "line": 1 + }, + "start": { + "column": 6, + "line": 1 + } + }, + "range": [ + 6, + 7 + ], + "type": "Identifier", + "value": "B" + }, + { + "loc": { + "end": { + "column": 9, + "line": 1 + }, + "start": { + "column": 8, + "line": 1 + } + }, + "range": [ + 8, + 9 + ], + "type": "Punctuator", + "value": "{" + }, + { + "loc": { + "end": { + "column": 5, + "line": 2 + }, + "start": { + "column": 4, + "line": 2 + } + }, + "range": [ + 14, + 15 + ], + "type": "Punctuator", + "value": "@" + }, + { + "loc": { + "end": { + "column": 13, + "line": 2 + }, + "start": { + "column": 5, + "line": 2 + } + }, + "range": [ + 15, + 23 + ], + "type": "Identifier", + "value": "readonly" + }, + { + "loc": { + "end": { + "column": 14, + "line": 2 + }, + "start": { + "column": 13, + "line": 2 + } + }, + "range": [ + 23, + 24 + ], + "type": "Punctuator", + "value": "(" + }, + { + "loc": { + "end": { + "column": 19, + "line": 2 + }, + "start": { + "column": 14, + "line": 2 + } + }, + "range": [ + 24, + 29 + ], + "type": "Boolean", + "value": "false" + }, + { + "loc": { + "end": { + "column": 20, + "line": 2 + }, + "start": { + "column": 19, + "line": 2 + } + }, + "range": [ + 29, + 30 + ], + "type": "Punctuator", + "value": ")" + }, + { + "loc": { + "end": { + "column": 18, + "line": 3 + }, + "start": { + "column": 4, + "line": 3 + } + }, + "range": [ + 35, + 49 + ], + "type": "Identifier", + "value": "instanceMethod" + }, + { + "loc": { + "end": { + "column": 19, + "line": 3 + }, + "start": { + "column": 18, + "line": 3 + } + }, + "range": [ + 49, + 50 + ], + "type": "Punctuator", + "value": "(" + }, + { + "loc": { + "end": { + "column": 20, + "line": 3 + }, + "start": { + "column": 19, + "line": 3 + } + }, + "range": [ + 50, + 51 + ], + "type": "Punctuator", + "value": ")" + }, + { + "loc": { + "end": { + "column": 22, + "line": 3 + }, + "start": { + "column": 21, + "line": 3 + } + }, + "range": [ + 52, + 53 + ], + "type": "Punctuator", + "value": "{" + }, + { + "loc": { + "end": { + "column": 23, + "line": 3 + }, + "start": { + "column": 22, + "line": 3 + } + }, + "range": [ + 53, + 54 + ], + "type": "Punctuator", + "value": "}" + }, + { + "loc": { + "end": { + "column": 1, + "line": 4 + }, + "start": { + "column": 0, + "line": 4 + } + }, + "range": [ + 55, + 56 + ], + "type": "Punctuator", + "value": "}" + } + ] +}; diff --git a/tests/fixtures/typescript/decorators/method-decorators/method-decorator-factory-instance-member.src.ts b/tests/fixtures/typescript/decorators/method-decorators/method-decorator-factory-instance-member.src.ts new file mode 100644 index 0000000..cb089fb --- /dev/null +++ b/tests/fixtures/typescript/decorators/method-decorators/method-decorator-factory-instance-member.src.ts @@ -0,0 +1,4 @@ +class B { + @readonly(false) + instanceMethod() {} +} diff --git a/tests/fixtures/typescript/decorators/method-decorators/method-decorator-factory-static-member.result.js b/tests/fixtures/typescript/decorators/method-decorators/method-decorator-factory-static-member.result.js new file mode 100644 index 0000000..75861aa --- /dev/null +++ b/tests/fixtures/typescript/decorators/method-decorators/method-decorator-factory-static-member.result.js @@ -0,0 +1,483 @@ +module.exports = { + "type": "Program", + "range": [ + 0, + 56 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassDeclaration", + "range": [ + 0, + 56 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "name": "C" + }, + "body": { + "type": "ClassBody", + "body": [ + { + "type": "MethodDefinition", + "range": [ + 14, + 54 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "key": { + "type": "Identifier", + "range": [ + 37, + 49 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 23 + } + }, + "name": "staticMethod" + }, + "value": { + "type": "FunctionExpression", + "id": null, + "params": [], + "generator": false, + "expression": false, + "body": { + "type": "BlockStatement", + "range": [ + 52, + 54 + ], + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "body": [] + }, + "range": [ + 49, + 54 + ], + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 28 + } + } + }, + "computed": false, + "static": true, + "kind": "method", + "decorators": [ + { + "arguments": [ + { + "loc": { + "end": { + "column": 14, + "line": 2 + }, + "start": { + "column": 9, + "line": 2 + } + }, + "range": [ + 19, + 24 + ], + "raw": "false", + "type": "Literal", + "value": false + } + ], + "callee": { + "loc": { + "end": { + "column": 8, + "line": 2 + }, + "start": { + "column": 5, + "line": 2 + } + }, + "name": "Foo", + "range": [ + 15, + 18 + ], + "type": "Identifier" + }, + "loc": { + "end": { + "column": 15, + "line": 2 + }, + "start": { + "column": 5, + "line": 2 + } + }, + "range": [ + 15, + 25 + ], + "type": "CallExpression" + } + ] + } + ], + "range": [ + 8, + 56 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + } + }, + "superClass": null, + "implements": [] + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "class", + "range": [ + 0, + 5 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + } + }, + { + "type": "Identifier", + "value": "C", + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 8, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + } + }, + { + "type": "Punctuator", + "value": "@", + "range": [ + 14, + 15 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + } + }, + { + "type": "Identifier", + "value": "Foo", + "range": [ + 15, + 18 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 18, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 + } + } + }, + { + "loc": { + "end": { + "column": 14, + "line": 2 + }, + "start": { + "column": 9, + "line": 2 + } + }, + "range": [ + 19, + 24 + ], + "type": "Boolean", + "value": "false" + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 24, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + } + } + }, + { + "type": "Keyword", + "value": "static", + "range": [ + 30, + 36 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 10 + } + } + }, + { + "type": "Identifier", + "value": "staticMethod", + "range": [ + 37, + 49 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 23 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 49, + 50 + ], + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 50, + 51 + ], + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 52, + 53 + ], + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 27 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 53, + 54 + ], + "loc": { + "start": { + "line": 3, + "column": 27 + }, + "end": { + "line": 3, + "column": 28 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 55, + 56 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + } + } + ] +}; diff --git a/tests/fixtures/typescript/decorators/method-decorators/method-decorator-factory-static-member.src.ts b/tests/fixtures/typescript/decorators/method-decorators/method-decorator-factory-static-member.src.ts new file mode 100644 index 0000000..735541f --- /dev/null +++ b/tests/fixtures/typescript/decorators/method-decorators/method-decorator-factory-static-member.src.ts @@ -0,0 +1,4 @@ +class C { + @Foo(false) + static staticMethod() {} +} diff --git a/tests/fixtures/typescript/decorators/method-decorators/method-decorator-instance-member.result.js b/tests/fixtures/typescript/decorators/method-decorators/method-decorator-instance-member.result.js new file mode 100644 index 0000000..b91dd2b --- /dev/null +++ b/tests/fixtures/typescript/decorators/method-decorators/method-decorator-instance-member.result.js @@ -0,0 +1,373 @@ +module.exports = { + "type": "Program", + "range": [ + 0, + 49 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassDeclaration", + "range": [ + 0, + 49 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "name": "A" + }, + "body": { + "type": "ClassBody", + "body": [ + { + "type": "MethodDefinition", + "range": [ + 14, + 47 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 3, + "column": 23 + } + }, + "key": { + "type": "Identifier", + "range": [ + 28, + 42 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "name": "instanceMethod" + }, + "value": { + "type": "FunctionExpression", + "id": null, + "params": [], + "generator": false, + "expression": false, + "body": { + "type": "BlockStatement", + "range": [ + 45, + 47 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 23 + } + }, + "body": [] + }, + "range": [ + 42, + 47 + ], + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 23 + } + } + }, + "computed": false, + "static": false, + "kind": "method", + "decorators": [ + { + "loc": { + "end": { + "column": 13, + "line": 2 + }, + "start": { + "column": 5, + "line": 2 + } + }, + "name": "readonly", + "range": [ + 15, + 23 + ], + "type": "Identifier" + } + ] + } + ], + "range": [ + 8, + 49 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + } + }, + "superClass": null, + "implements": [] + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "class", + "range": [ + 0, + 5 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + } + }, + { + "type": "Identifier", + "value": "A", + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 8, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + } + }, + { + "type": "Punctuator", + "value": "@", + "range": [ + 14, + 15 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + } + }, + { + "type": "Identifier", + "value": "readonly", + "range": [ + 15, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 13 + } + } + }, + { + "type": "Identifier", + "value": "instanceMethod", + "range": [ + 28, + 42 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 18 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 42, + 43 + ], + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 43, + 44 + ], + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 45, + 46 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 22 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 46, + 47 + ], + "loc": { + "start": { + "line": 3, + "column": 22 + }, + "end": { + "line": 3, + "column": 23 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 48, + 49 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + } + } + ] +}; diff --git a/tests/fixtures/typescript/decorators/method-decorators/method-decorator-instance-member.src.ts b/tests/fixtures/typescript/decorators/method-decorators/method-decorator-instance-member.src.ts new file mode 100644 index 0000000..4993bde --- /dev/null +++ b/tests/fixtures/typescript/decorators/method-decorators/method-decorator-instance-member.src.ts @@ -0,0 +1,4 @@ +class A { + @readonly + instanceMethod() {} +} diff --git a/tests/fixtures/typescript/decorators/method-decorators/method-decorator-static-member.result.js b/tests/fixtures/typescript/decorators/method-decorators/method-decorator-static-member.result.js new file mode 100644 index 0000000..1b3250a --- /dev/null +++ b/tests/fixtures/typescript/decorators/method-decorators/method-decorator-static-member.result.js @@ -0,0 +1,391 @@ +module.exports = { + "type": "Program", + "range": [ + 0, + 49 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassDeclaration", + "range": [ + 0, + 49 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "name": "D" + }, + "body": { + "type": "ClassBody", + "body": [ + { + "type": "MethodDefinition", + "range": [ + 14, + 47 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "key": { + "type": "Identifier", + "range": [ + 30, + 42 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 23 + } + }, + "name": "staticMethod" + }, + "value": { + "type": "FunctionExpression", + "id": null, + "params": [], + "generator": false, + "expression": false, + "body": { + "type": "BlockStatement", + "range": [ + 45, + 47 + ], + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "body": [] + }, + "range": [ + 42, + 47 + ], + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 28 + } + } + }, + "computed": false, + "static": true, + "kind": "method", + "decorators": [ + { + "loc": { + "end": { + "column": 8, + "line": 2 + }, + "start": { + "column": 5, + "line": 2 + } + }, + "name": "Foo", + "range": [ + 15, + 18 + ], + "type": "Identifier" + } + ] + } + ], + "range": [ + 8, + 49 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + } + }, + "superClass": null, + "implements": [] + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "class", + "range": [ + 0, + 5 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + } + }, + { + "type": "Identifier", + "value": "D", + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 8, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + } + }, + { + "type": "Punctuator", + "value": "@", + "range": [ + 14, + 15 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + } + }, + { + "type": "Identifier", + "value": "Foo", + "range": [ + 15, + 18 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 8 + } + } + }, + { + "type": "Keyword", + "value": "static", + "range": [ + 23, + 29 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 10 + } + } + }, + { + "type": "Identifier", + "value": "staticMethod", + "range": [ + 30, + 42 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 23 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 42, + 43 + ], + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 43, + 44 + ], + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 45, + 46 + ], + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 27 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 46, + 47 + ], + "loc": { + "start": { + "line": 3, + "column": 27 + }, + "end": { + "line": 3, + "column": 28 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 48, + 49 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + } + } + ] +}; diff --git a/tests/fixtures/typescript/decorators/method-decorators/method-decorator-static-member.src.ts b/tests/fixtures/typescript/decorators/method-decorators/method-decorator-static-member.src.ts new file mode 100644 index 0000000..59fc47f --- /dev/null +++ b/tests/fixtures/typescript/decorators/method-decorators/method-decorator-static-member.src.ts @@ -0,0 +1,4 @@ +class D { + @Foo + static staticMethod() {} +}