From e7da8dde80e786474dc66adad40d0f16fc2bc80e Mon Sep 17 00:00:00 2001 From: James Henry Date: Sun, 28 Aug 2016 20:31:03 +0100 Subject: [PATCH] New: Add accessor decorators to AST (fixes #63) --- ...ecorator-factory-instance-member.result.js | 645 ++++++++++++++ ...r-decorator-factory-instance-member.src.ts | 4 + ...-decorator-factory-static-member.result.js | 793 ++++++++++++++++++ ...sor-decorator-factory-static-member.src.ts | 4 + ...cessor-decorator-instance-member.result.js | 553 ++++++++++++ .../accessor-decorator-instance-member.src.ts | 4 + ...accessor-decorator-static-member.result.js | 663 +++++++++++++++ .../accessor-decorator-static-member.src.ts | 6 + 8 files changed, 2672 insertions(+) create mode 100644 tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-factory-instance-member.result.js create mode 100644 tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-factory-instance-member.src.ts create mode 100644 tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-factory-static-member.result.js create mode 100644 tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-factory-static-member.src.ts create mode 100644 tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-instance-member.result.js create mode 100644 tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-instance-member.src.ts create mode 100644 tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-static-member.result.js create mode 100644 tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-static-member.src.ts diff --git a/tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-factory-instance-member.result.js b/tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-factory-instance-member.result.js new file mode 100644 index 0000000..59c6570 --- /dev/null +++ b/tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-factory-instance-member.result.js @@ -0,0 +1,645 @@ +module.exports = { + "type": "Program", + "range": [ + 0, + 72 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassDeclaration", + "range": [ + 0, + 72 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "range": [ + 6, + 11 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "name": "Point" + }, + "body": { + "type": "ClassBody", + "body": [ + { + "type": "MethodDefinition", + "range": [ + 18, + 70 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "key": { + "type": "Identifier", + "range": [ + 47, + 48 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "name": "x" + }, + "value": { + "type": "FunctionExpression", + "id": null, + "generator": false, + "expression": false, + "body": { + "type": "BlockStatement", + "range": [ + 51, + 70 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "body": [ + { + "type": "ReturnStatement", + "range": [ + 53, + 68 + ], + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 29 + } + }, + "argument": { + "type": "MemberExpression", + "range": [ + 60, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "object": { + "type": "ThisExpression", + "range": [ + 60, + 64 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 25 + } + } + }, + "property": { + "type": "Identifier", + "range": [ + 65, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "name": "_x" + }, + "computed": false + } + } + ] + }, + "range": [ + 48, + 70 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "params": [] + }, + "computed": false, + "static": false, + "kind": "get", + "decorators": [ + { + "type": "CallExpression", + "range": [ + 19, + 38 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "callee": { + "type": "Identifier", + "range": [ + 19, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "name": "configurable" + }, + "arguments": [ + { + "type": "Literal", + "range": [ + 32, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "value": false, + "raw": "false" + } + ] + } + ] + } + ], + "range": [ + 12, + 72 + ], + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 4, + "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": "Point", + "range": [ + 6, + 11 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 11 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 12, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": "@", + "range": [ + 18, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + } + }, + { + "type": "Identifier", + "value": "configurable", + "range": [ + 19, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 31, + 32 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 18 + } + } + }, + { + "type": "Boolean", + "value": "false", + "range": [ + 32, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 23 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 37, + 38 + ], + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 24 + } + } + }, + { + "type": "Identifier", + "value": "get", + "range": [ + 43, + 46 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 7 + } + } + }, + { + "type": "Identifier", + "value": "x", + "range": [ + 47, + 48 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 48, + 49 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 49, + 50 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 51, + 52 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 13 + } + } + }, + { + "type": "Keyword", + "value": "return", + "range": [ + 53, + 59 + ], + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 20 + } + } + }, + { + "type": "Keyword", + "value": "this", + "range": [ + 60, + 64 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 64, + 65 + ], + "loc": { + "start": { + "line": 3, + "column": 25 + }, + "end": { + "line": 3, + "column": 26 + } + } + }, + { + "type": "Identifier", + "value": "_x", + "range": [ + 65, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 28 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 67, + 68 + ], + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 3, + "column": 29 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 69, + 70 + ], + "loc": { + "start": { + "line": 3, + "column": 30 + }, + "end": { + "line": 3, + "column": 31 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 71, + 72 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + } + } + ] +}; diff --git a/tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-factory-instance-member.src.ts b/tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-factory-instance-member.src.ts new file mode 100644 index 0000000..24f2b53 --- /dev/null +++ b/tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-factory-instance-member.src.ts @@ -0,0 +1,4 @@ +class Point { + @configurable(false) + get x() { return this._x; } +} \ No newline at end of file diff --git a/tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-factory-static-member.result.js b/tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-factory-static-member.result.js new file mode 100644 index 0000000..410be52 --- /dev/null +++ b/tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-factory-static-member.result.js @@ -0,0 +1,793 @@ +module.exports = { + "type": "Program", + "range": [ + 0, + 82 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassDeclaration", + "range": [ + 0, + 82 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "range": [ + 6, + 11 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "name": "Other" + }, + "body": { + "type": "ClassBody", + "body": [ + { + "type": "MethodDefinition", + "range": [ + 18, + 80 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 3, + "column": 42 + } + }, + "key": { + "type": "Identifier", + "range": [ + 53, + 56 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "name": "bar" + }, + "value": { + "type": "FunctionExpression", + "id": null, + "generator": false, + "expression": false, + "body": { + "type": "BlockStatement", + "range": [ + 59, + 80 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 42 + } + }, + "body": [ + { + "type": "ReturnStatement", + "range": [ + 61, + 78 + ], + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 40 + } + }, + "argument": { + "type": "MemberExpression", + "range": [ + 68, + 77 + ], + "loc": { + "start": { + "line": 3, + "column": 30 + }, + "end": { + "line": 3, + "column": 39 + } + }, + "object": { + "type": "ThisExpression", + "range": [ + 68, + 72 + ], + "loc": { + "start": { + "line": 3, + "column": 30 + }, + "end": { + "line": 3, + "column": 34 + } + } + }, + "property": { + "type": "Identifier", + "range": [ + 73, + 77 + ], + "loc": { + "start": { + "line": 3, + "column": 35 + }, + "end": { + "line": 3, + "column": 39 + } + }, + "name": "_bar" + }, + "computed": false + } + } + ] + }, + "range": [ + 56, + 80 + ], + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 42 + } + }, + "params": [] + }, + "computed": false, + "static": true, + "kind": "get", + "decorators": [ + { + "type": "CallExpression", + "range": [ + 19, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "callee": { + "type": "Identifier", + "range": [ + 19, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "name": "foo" + }, + "arguments": [ + { + "type": "ObjectExpression", + "range": [ + 23, + 36 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "properties": [ + { + "type": "Property", + "range": [ + 25, + 34 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "key": { + "type": "Identifier", + "range": [ + 25, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "name": "baz" + }, + "value": { + "type": "Literal", + "range": [ + 30, + 34 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "value": true, + "raw": "true" + }, + "computed": false, + "method": false, + "shorthand": false, + "kind": "init" + } + ] + } + ] + } + ] + } + ], + "range": [ + 12, + 82 + ], + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 4, + "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": "Other", + "range": [ + 6, + 11 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 11 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 12, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": "@", + "range": [ + 18, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + } + }, + { + "type": "Identifier", + "value": "foo", + "range": [ + 19, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 22, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 23, + 24 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + { + "type": "Identifier", + "value": "baz", + "range": [ + 25, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 28, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + } + } + }, + { + "type": "Boolean", + "value": "true", + "range": [ + 30, + 34 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 35, + 36 + ], + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 22 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 23 + } + } + }, + { + "type": "Keyword", + "value": "static", + "range": [ + 42, + 48 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 10 + } + } + }, + { + "type": "Identifier", + "value": "get", + "range": [ + 49, + 52 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 14 + } + } + }, + { + "type": "Identifier", + "value": "bar", + "range": [ + 53, + 56 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 18 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 56, + 57 + ], + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 57, + 58 + ], + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 59, + 60 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 22 + } + } + }, + { + "type": "Keyword", + "value": "return", + "range": [ + 61, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 29 + } + } + }, + { + "type": "Keyword", + "value": "this", + "range": [ + 68, + 72 + ], + "loc": { + "start": { + "line": 3, + "column": 30 + }, + "end": { + "line": 3, + "column": 34 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 72, + 73 + ], + "loc": { + "start": { + "line": 3, + "column": 34 + }, + "end": { + "line": 3, + "column": 35 + } + } + }, + { + "type": "Identifier", + "value": "_bar", + "range": [ + 73, + 77 + ], + "loc": { + "start": { + "line": 3, + "column": 35 + }, + "end": { + "line": 3, + "column": 39 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 77, + 78 + ], + "loc": { + "start": { + "line": 3, + "column": 39 + }, + "end": { + "line": 3, + "column": 40 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 79, + 80 + ], + "loc": { + "start": { + "line": 3, + "column": 41 + }, + "end": { + "line": 3, + "column": 42 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 81, + 82 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + } + } + ] +}; diff --git a/tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-factory-static-member.src.ts b/tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-factory-static-member.src.ts new file mode 100644 index 0000000..f48e710 --- /dev/null +++ b/tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-factory-static-member.src.ts @@ -0,0 +1,4 @@ +class Other { + @foo({ baz: true }) + static get bar() { return this._bar; } +} \ No newline at end of file diff --git a/tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-instance-member.result.js b/tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-instance-member.result.js new file mode 100644 index 0000000..ef73cf1 --- /dev/null +++ b/tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-instance-member.result.js @@ -0,0 +1,553 @@ +module.exports = { + "type": "Program", + "range": [ + 0, + 55 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassDeclaration", + "range": [ + 0, + 55 + ], + "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": "P" + }, + "body": { + "type": "ClassBody", + "body": [ + { + "type": "MethodDefinition", + "range": [ + 14, + 53 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "key": { + "type": "Identifier", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "name": "z" + }, + "value": { + "type": "FunctionExpression", + "id": null, + "generator": false, + "expression": false, + "body": { + "type": "BlockStatement", + "range": [ + 34, + 53 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "body": [ + { + "type": "ReturnStatement", + "range": [ + 36, + 51 + ], + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 29 + } + }, + "argument": { + "type": "MemberExpression", + "range": [ + 43, + 50 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "object": { + "type": "ThisExpression", + "range": [ + 43, + 47 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 25 + } + } + }, + "property": { + "type": "Identifier", + "range": [ + 48, + 50 + ], + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "name": "_z" + }, + "computed": false + } + } + ] + }, + "range": [ + 31, + 53 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "params": [] + }, + "computed": false, + "static": false, + "kind": "get", + "decorators": [ + { + "type": "Identifier", + "range": [ + 15, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "name": "hidden" + } + ] + } + ], + "range": [ + 8, + 55 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "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": "P", + "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": "hidden", + "range": [ + 15, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + { + "type": "Identifier", + "value": "get", + "range": [ + 26, + 29 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 7 + } + } + }, + { + "type": "Identifier", + "value": "z", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 31, + 32 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 32, + 33 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 34, + 35 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 13 + } + } + }, + { + "type": "Keyword", + "value": "return", + "range": [ + 36, + 42 + ], + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 20 + } + } + }, + { + "type": "Keyword", + "value": "this", + "range": [ + 43, + 47 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 47, + 48 + ], + "loc": { + "start": { + "line": 3, + "column": 25 + }, + "end": { + "line": 3, + "column": 26 + } + } + }, + { + "type": "Identifier", + "value": "_z", + "range": [ + 48, + 50 + ], + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 28 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 50, + 51 + ], + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 3, + "column": 29 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 52, + 53 + ], + "loc": { + "start": { + "line": 3, + "column": 30 + }, + "end": { + "line": 3, + "column": 31 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 54, + 55 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + } + } + ] +}; diff --git a/tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-instance-member.src.ts b/tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-instance-member.src.ts new file mode 100644 index 0000000..4cea728 --- /dev/null +++ b/tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-instance-member.src.ts @@ -0,0 +1,4 @@ +class P { + @hidden + get z() { return this._z; } +} \ No newline at end of file diff --git a/tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-static-member.result.js b/tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-static-member.result.js new file mode 100644 index 0000000..1bf4490 --- /dev/null +++ b/tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-static-member.result.js @@ -0,0 +1,663 @@ +module.exports = { + "type": "Program", + "range": [ + 0, + 78 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "body": [ + { + "type": "ClassDeclaration", + "range": [ + 0, + 78 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "range": [ + 6, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "name": "User" + }, + "body": { + "type": "ClassBody", + "body": [ + { + "type": "MethodDefinition", + "range": [ + 17, + 76 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 + } + }, + "key": { + "type": "Identifier", + "range": [ + 43, + 44 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "name": "y" + }, + "value": { + "type": "FunctionExpression", + "id": null, + "generator": false, + "expression": false, + "body": { + "type": "BlockStatement", + "range": [ + 48, + 76 + ], + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 5, + "column": 5 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "range": [ + 58, + 70 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 20 + } + }, + "expression": { + "type": "AssignmentExpression", + "range": [ + 58, + 69 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 19 + } + }, + "operator": "=", + "left": { + "type": "MemberExpression", + "range": [ + 58, + 65 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 15 + } + }, + "object": { + "type": "ThisExpression", + "range": [ + 58, + 62 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 12 + } + } + }, + "property": { + "type": "Identifier", + "range": [ + 63, + 65 + ], + "loc": { + "start": { + "line": 4, + "column": 13 + }, + "end": { + "line": 4, + "column": 15 + } + }, + "name": "_y" + }, + "computed": false + }, + "right": { + "type": "Identifier", + "range": [ + 68, + 69 + ], + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 19 + } + }, + "name": "a" + } + } + } + ] + }, + "range": [ + 44, + 76 + ], + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 5, + "column": 5 + } + }, + "params": [ + { + "type": "Identifier", + "range": [ + 45, + 46 + ], + "loc": { + "start": { + "line": 3, + "column": 17 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "name": "a", + "decorators": [] + } + ] + }, + "computed": false, + "static": true, + "kind": "set", + "decorators": [ + { + "type": "Identifier", + "range": [ + 18, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "name": "adminonly" + } + ] + } + ], + "range": [ + 11, + 78 + ], + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 6, + "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": "User", + "range": [ + 6, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 11, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": "@", + "range": [ + 17, + 18 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + } + }, + { + "type": "Identifier", + "value": "adminonly", + "range": [ + 18, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + { + "type": "Keyword", + "value": "static", + "range": [ + 32, + 38 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 10 + } + } + }, + { + "type": "Identifier", + "value": "set", + "range": [ + 39, + 42 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 14 + } + } + }, + { + "type": "Identifier", + "value": "y", + "range": [ + 43, + 44 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 44, + 45 + ], + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 17 + } + } + }, + { + "type": "Identifier", + "value": "a", + "range": [ + 45, + 46 + ], + "loc": { + "start": { + "line": 3, + "column": 17 + }, + "end": { + "line": 3, + "column": 18 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 46, + 47 + ], + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 48, + 49 + ], + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 21 + } + } + }, + { + "type": "Keyword", + "value": "this", + "range": [ + 58, + 62 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 62, + 63 + ], + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 13 + } + } + }, + { + "type": "Identifier", + "value": "_y", + "range": [ + 63, + 65 + ], + "loc": { + "start": { + "line": 4, + "column": 13 + }, + "end": { + "line": 4, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 66, + 67 + ], + "loc": { + "start": { + "line": 4, + "column": 16 + }, + "end": { + "line": 4, + "column": 17 + } + } + }, + { + "type": "Identifier", + "value": "a", + "range": [ + 68, + 69 + ], + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 69, + 70 + ], + "loc": { + "start": { + "line": 4, + "column": 19 + }, + "end": { + "line": 4, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 75, + 76 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 77, + 78 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + } + } + ] +}; diff --git a/tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-static-member.src.ts b/tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-static-member.src.ts new file mode 100644 index 0000000..f9b2964 --- /dev/null +++ b/tests/fixtures/typescript/decorators/accessor-decorators/accessor-decorator-static-member.src.ts @@ -0,0 +1,6 @@ +class User { + @adminonly + static set y(a) { + this._y = a; + } +} \ No newline at end of file