From cec8bc035411101f531045857b38e3686f35560d Mon Sep 17 00:00:00 2001 From: Andrew Levine Date: Thu, 5 Jan 2017 15:07:40 -0600 Subject: [PATCH] Add some test coverage for decorators stage-0 plugin (#250) --- README.md | 2 +- .../class-decorator-call-expr/actual.js | 2 + .../class-decorator-call-expr/expected.json | 154 +++++++++++++ .../decorators/class-decorator/actual.js | 4 + .../decorators/class-decorator/expected.json | 117 ++++++++++ .../computed-member-expr-on-prop/actual.js | 3 + .../expected.json | 205 +++++++++++++++++ .../computed-member-expr-on-prop/options.json | 3 + .../computed-member-expression/actual.js | 6 + .../computed-member-expression/expected.json | 208 ++++++++++++++++++ 10 files changed, 703 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/experimental/decorators/class-decorator-call-expr/actual.js create mode 100644 test/fixtures/experimental/decorators/class-decorator-call-expr/expected.json create mode 100644 test/fixtures/experimental/decorators/class-decorator/actual.js create mode 100644 test/fixtures/experimental/decorators/class-decorator/expected.json create mode 100644 test/fixtures/experimental/decorators/computed-member-expr-on-prop/actual.js create mode 100644 test/fixtures/experimental/decorators/computed-member-expr-on-prop/expected.json create mode 100644 test/fixtures/experimental/decorators/computed-member-expr-on-prop/options.json create mode 100644 test/fixtures/experimental/decorators/computed-member-expression/actual.js create mode 100644 test/fixtures/experimental/decorators/computed-member-expression/expected.json diff --git a/README.md b/README.md index 2303cc5398..68c136a851 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ require("babylon").parse("code", { - `flow` - `doExpressions` - `objectRestSpread` - - `decorators` + - `decorators` (Based on an outdated version of the Decorators proposal. Will be removed in a future version of `Babylon`) - `classProperties` - `exportExtensions` - `asyncGenerators` diff --git a/test/fixtures/experimental/decorators/class-decorator-call-expr/actual.js b/test/fixtures/experimental/decorators/class-decorator-call-expr/actual.js new file mode 100644 index 0000000000..8f69136200 --- /dev/null +++ b/test/fixtures/experimental/decorators/class-decorator-call-expr/actual.js @@ -0,0 +1,2 @@ +@foo('bar') +class Foo {} diff --git a/test/fixtures/experimental/decorators/class-decorator-call-expr/expected.json b/test/fixtures/experimental/decorators/class-decorator-call-expr/expected.json new file mode 100644 index 0000000000..291ef173cc --- /dev/null +++ b/test/fixtures/experimental/decorators/class-decorator-call-expr/expected.json @@ -0,0 +1,154 @@ +{ + "type": "File", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ClassDeclaration", + "start": 12, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "decorators": [ + { + "type": "Decorator", + "start": 0, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "expression": { + "type": "CallExpression", + "start": 1, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "callee": { + "type": "Identifier", + "start": 1, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 4 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "arguments": [ + { + "type": "StringLiteral", + "start": 5, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "extra": { + "rawValue": "bar", + "raw": "'bar'" + }, + "value": "bar" + } + ] + } + } + ], + "id": { + "type": "Identifier", + "start": 18, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 22, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "body": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/decorators/class-decorator/actual.js b/test/fixtures/experimental/decorators/class-decorator/actual.js new file mode 100644 index 0000000000..b1d1c0dd75 --- /dev/null +++ b/test/fixtures/experimental/decorators/class-decorator/actual.js @@ -0,0 +1,4 @@ +@abc +class Foo { + +} diff --git a/test/fixtures/experimental/decorators/class-decorator/expected.json b/test/fixtures/experimental/decorators/class-decorator/expected.json new file mode 100644 index 0000000000..8299bdd639 --- /dev/null +++ b/test/fixtures/experimental/decorators/class-decorator/expected.json @@ -0,0 +1,117 @@ +{ + "type": "File", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ClassDeclaration", + "start": 5, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "decorators": [ + { + "type": "Decorator", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "expression": { + "type": "Identifier", + "start": 1, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 4 + }, + "identifierName": "abc" + }, + "name": "abc" + } + } + ], + "id": { + "type": "Identifier", + "start": 11, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 15, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/decorators/computed-member-expr-on-prop/actual.js b/test/fixtures/experimental/decorators/computed-member-expr-on-prop/actual.js new file mode 100644 index 0000000000..a7c918a617 --- /dev/null +++ b/test/fixtures/experimental/decorators/computed-member-expr-on-prop/actual.js @@ -0,0 +1,3 @@ +class Foo { + @foo[bar] a = 1; +} diff --git a/test/fixtures/experimental/decorators/computed-member-expr-on-prop/expected.json b/test/fixtures/experimental/decorators/computed-member-expr-on-prop/expected.json new file mode 100644 index 0000000000..184415bff7 --- /dev/null +++ b/test/fixtures/experimental/decorators/computed-member-expr-on-prop/expected.json @@ -0,0 +1,205 @@ +{ + "type": "File", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 10, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ClassProperty", + "start": 24, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "decorators": [ + { + "type": "Decorator", + "start": 14, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "expression": { + "type": "MemberExpression", + "start": 15, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "object": { + "type": "Identifier", + "start": 15, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "property": { + "type": "Identifier", + "start": 19, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 10 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "computed": true + } + } + ], + "computed": false, + "key": { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 13 + }, + "identifierName": "a" + }, + "name": "a" + }, + "static": false, + "value": { + "type": "NumericLiteral", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/decorators/computed-member-expr-on-prop/options.json b/test/fixtures/experimental/decorators/computed-member-expr-on-prop/options.json new file mode 100644 index 0000000000..49038f416f --- /dev/null +++ b/test/fixtures/experimental/decorators/computed-member-expr-on-prop/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["decorators", "classProperties"] +} diff --git a/test/fixtures/experimental/decorators/computed-member-expression/actual.js b/test/fixtures/experimental/decorators/computed-member-expression/actual.js new file mode 100644 index 0000000000..f261291097 --- /dev/null +++ b/test/fixtures/experimental/decorators/computed-member-expression/actual.js @@ -0,0 +1,6 @@ +class Foo { + @bar[bizz] + abc() { + + } +} diff --git a/test/fixtures/experimental/decorators/computed-member-expression/expected.json b/test/fixtures/experimental/decorators/computed-member-expression/expected.json new file mode 100644 index 0000000000..d0c4947e9b --- /dev/null +++ b/test/fixtures/experimental/decorators/computed-member-expression/expected.json @@ -0,0 +1,208 @@ +{ + "type": "File", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 10, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 27, + "end": 39, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 5, + "column": 3 + } + }, + "decorators": [ + { + "type": "Decorator", + "start": 14, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "expression": { + "type": "MemberExpression", + "start": 15, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "object": { + "type": "Identifier", + "start": 15, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "property": { + "type": "Identifier", + "start": 19, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "bizz" + }, + "name": "bizz" + }, + "computed": true + } + } + ], + "computed": false, + "key": { + "type": "Identifier", + "start": 27, + "end": 30, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 5 + }, + "identifierName": "abc" + }, + "name": "abc" + }, + "static": false, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 33, + "end": 39, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 5, + "column": 3 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file