Disallow in object literals, params, class props
And add tests to reflect the same
This commit is contained in:
parent
162bc905a6
commit
9c639743dd
@ -847,8 +847,16 @@ export default class ExpressionParser extends LValParser {
|
||||
if (this.eat(tt.braceR)) break;
|
||||
}
|
||||
|
||||
while (this.match(tt.at)) {
|
||||
decorators.push(this.parseDecorator());
|
||||
if (this.match(tt.at)) {
|
||||
if (this.hasPlugin("decorators-stage-2")) {
|
||||
this.raise(this.state.start, "decorators-stage-2 disallows object literal property decorators");
|
||||
} else {
|
||||
// we needn't check if decorators (stage 0) plugin is enabled since it's checked by
|
||||
// the call to this.parseDecorator
|
||||
while (this.match(tt.at)) {
|
||||
decorators.push(this.parseDecorator());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let prop = this.startNode(), isGenerator = false, isAsync = false, startPos, startLoc;
|
||||
|
||||
@ -187,6 +187,9 @@ export default class LValParser extends NodeUtils {
|
||||
break;
|
||||
} else {
|
||||
const decorators = [];
|
||||
if (this.match(tt.at) && this.hasPlugin("decorators-stage-2")) {
|
||||
this.raise(this.state.start, "Stage 2 decorators cannot be used to decorate parameters");
|
||||
}
|
||||
while (this.match(tt.at)) {
|
||||
decorators.push(this.parseDecorator());
|
||||
}
|
||||
|
||||
@ -709,6 +709,10 @@ export default class StatementParser extends ExpressionParser {
|
||||
}
|
||||
|
||||
this.parseClassMember(classBody, member, state);
|
||||
|
||||
if (this.hasPlugin("decorators-stage-2") && member.kind != "method" && member.decorators && member.decorators.length > 0) {
|
||||
this.raise(member.start, "Stage 2 decorators may only be used with a class or a class method");
|
||||
}
|
||||
}
|
||||
|
||||
if (decorators.length) {
|
||||
@ -776,6 +780,7 @@ export default class StatementParser extends ExpressionParser {
|
||||
if (!methodOrProp.computed && methodOrProp.static && (methodOrProp.key.name === "prototype" || methodOrProp.key.value === "prototype")) {
|
||||
this.raise(methodOrProp.key.start, "Classes may not have static property named prototype");
|
||||
}
|
||||
|
||||
if (this.isClassMethod()) {
|
||||
// a normal method
|
||||
if (this.isNonstaticConstructor(method)) {
|
||||
|
||||
2
test/fixtures/experimental/decorators-stage-2/class-decorator-call-expr/actual.js
vendored
Normal file
2
test/fixtures/experimental/decorators-stage-2/class-decorator-call-expr/actual.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
@foo('bar')
|
||||
class Foo {}
|
||||
154
test/fixtures/experimental/decorators-stage-2/class-decorator-call-expr/expected.json
vendored
Normal file
154
test/fixtures/experimental/decorators-stage-2/class-decorator-call-expr/expected.json
vendored
Normal file
@ -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": []
|
||||
}
|
||||
}
|
||||
4
test/fixtures/experimental/decorators-stage-2/class-decorator/actual.js
vendored
Normal file
4
test/fixtures/experimental/decorators-stage-2/class-decorator/actual.js
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
@abc
|
||||
class Foo {
|
||||
|
||||
}
|
||||
117
test/fixtures/experimental/decorators-stage-2/class-decorator/expected.json
vendored
Normal file
117
test/fixtures/experimental/decorators-stage-2/class-decorator/expected.json
vendored
Normal file
@ -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": []
|
||||
}
|
||||
}
|
||||
3
test/fixtures/experimental/decorators-stage-2/class-method-parameter/actual.js
vendored
Normal file
3
test/fixtures/experimental/decorators-stage-2/class-method-parameter/actual.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
class Foo {
|
||||
constructor(@foo x) {}
|
||||
}
|
||||
3
test/fixtures/experimental/decorators-stage-2/class-method-parameter/options.json
vendored
Normal file
3
test/fixtures/experimental/decorators-stage-2/class-method-parameter/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "Stage 2 decorators cannot be used to decorate parameters (2:14)"
|
||||
}
|
||||
3
test/fixtures/experimental/decorators-stage-2/computed-member-expr-on-prop/actual.js
vendored
Normal file
3
test/fixtures/experimental/decorators-stage-2/computed-member-expr-on-prop/actual.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
class Foo {
|
||||
@foo[bar] a = 1;
|
||||
}
|
||||
4
test/fixtures/experimental/decorators-stage-2/computed-member-expr-on-prop/options.json
vendored
Normal file
4
test/fixtures/experimental/decorators-stage-2/computed-member-expr-on-prop/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": ["decorators-stage-2", "classProperties"],
|
||||
"throws": "Unexpected token (2:12)"
|
||||
}
|
||||
6
test/fixtures/experimental/decorators-stage-2/computed-member-expression/actual.js
vendored
Normal file
6
test/fixtures/experimental/decorators-stage-2/computed-member-expression/actual.js
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
class Foo {
|
||||
@bar[bizz]
|
||||
abc() {
|
||||
|
||||
}
|
||||
}
|
||||
4
test/fixtures/experimental/decorators-stage-2/computed-member-expression/options.json
vendored
Normal file
4
test/fixtures/experimental/decorators-stage-2/computed-member-expression/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": ["decorators-stage-2", "classProperties"],
|
||||
"throws": "Stage 2 decorators may only be used with a class or a class method (2:6)"
|
||||
}
|
||||
2
test/fixtures/experimental/decorators-stage-2/export-decorators-on-class/actual.js
vendored
Normal file
2
test/fixtures/experimental/decorators-stage-2/export-decorators-on-class/actual.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
@foo
|
||||
export default class {}
|
||||
116
test/fixtures/experimental/decorators-stage-2/export-decorators-on-class/expected.json
vendored
Normal file
116
test/fixtures/experimental/decorators-stage-2/export-decorators-on-class/expected.json
vendored
Normal file
@ -0,0 +1,116 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 28,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 23
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 28,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 23
|
||||
}
|
||||
},
|
||||
"sourceType": "module",
|
||||
"body": [
|
||||
{
|
||||
"type": "ExportDefaultDeclaration",
|
||||
"start": 5,
|
||||
"end": 28,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 23
|
||||
}
|
||||
},
|
||||
"declaration": {
|
||||
"type": "ClassDeclaration",
|
||||
"start": 20,
|
||||
"end": 28,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 15
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 23
|
||||
}
|
||||
},
|
||||
"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": "foo"
|
||||
},
|
||||
"name": "foo"
|
||||
}
|
||||
}
|
||||
],
|
||||
"id": null,
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start": 26,
|
||||
"end": 28,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 21
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 23
|
||||
}
|
||||
},
|
||||
"body": []
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
3
test/fixtures/experimental/decorators-stage-2/export-decorators-on-class/options.json
vendored
Normal file
3
test/fixtures/experimental/decorators-stage-2/export-decorators-on-class/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"sourceType": "module"
|
||||
}
|
||||
7
test/fixtures/experimental/decorators-stage-2/export-default-with-nested-class/actual.js
vendored
Normal file
7
test/fixtures/experimental/decorators-stage-2/export-default-with-nested-class/actual.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
@ParentDecorator
|
||||
export default class ParentClass {
|
||||
makeNestedClass() {
|
||||
class NestedClass {
|
||||
}
|
||||
}
|
||||
}
|
||||
240
test/fixtures/experimental/decorators-stage-2/export-default-with-nested-class/expected.json
vendored
Normal file
240
test/fixtures/experimental/decorators-stage-2/export-default-with-nested-class/expected.json
vendored
Normal file
@ -0,0 +1,240 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 109,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 7,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 109,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 7,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"sourceType": "module",
|
||||
"body": [
|
||||
{
|
||||
"type": "ExportDefaultDeclaration",
|
||||
"start": 17,
|
||||
"end": 109,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 7,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"declaration": {
|
||||
"type": "ClassDeclaration",
|
||||
"start": 32,
|
||||
"end": 109,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 15
|
||||
},
|
||||
"end": {
|
||||
"line": 7,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"decorators": [
|
||||
{
|
||||
"type": "Decorator",
|
||||
"start": 0,
|
||||
"end": 16,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 16
|
||||
}
|
||||
},
|
||||
"expression": {
|
||||
"type": "Identifier",
|
||||
"start": 1,
|
||||
"end": 16,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 16
|
||||
},
|
||||
"identifierName": "ParentDecorator"
|
||||
},
|
||||
"name": "ParentDecorator"
|
||||
}
|
||||
}
|
||||
],
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 38,
|
||||
"end": 49,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 21
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 32
|
||||
},
|
||||
"identifierName": "ParentClass"
|
||||
},
|
||||
"name": "ParentClass"
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start": 50,
|
||||
"end": 109,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 33
|
||||
},
|
||||
"end": {
|
||||
"line": 7,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassMethod",
|
||||
"start": 54,
|
||||
"end": 107,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"static": false,
|
||||
"computed": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start": 54,
|
||||
"end": 69,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 17
|
||||
},
|
||||
"identifierName": "makeNestedClass"
|
||||
},
|
||||
"name": "makeNestedClass"
|
||||
},
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"expression": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start": 72,
|
||||
"end": 107,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 20
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"start": 78,
|
||||
"end": 103,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 4
|
||||
},
|
||||
"end": {
|
||||
"line": 5,
|
||||
"column": 5
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 84,
|
||||
"end": 95,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 10
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 21
|
||||
},
|
||||
"identifierName": "NestedClass"
|
||||
},
|
||||
"name": "NestedClass"
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start": 96,
|
||||
"end": 103,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 22
|
||||
},
|
||||
"end": {
|
||||
"line": 5,
|
||||
"column": 5
|
||||
}
|
||||
},
|
||||
"body": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
3
test/fixtures/experimental/decorators-stage-2/export-default-with-nested-class/options.json
vendored
Normal file
3
test/fixtures/experimental/decorators-stage-2/export-default-with-nested-class/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"sourceType": "module"
|
||||
}
|
||||
1
test/fixtures/experimental/decorators-stage-2/function-parameters/actual.js
vendored
Normal file
1
test/fixtures/experimental/decorators-stage-2/function-parameters/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
function func(@foo x) {}
|
||||
3
test/fixtures/experimental/decorators-stage-2/function-parameters/options.json
vendored
Normal file
3
test/fixtures/experimental/decorators-stage-2/function-parameters/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "Stage 2 decorators cannot be used to decorate parameters (1:14)"
|
||||
}
|
||||
4
test/fixtures/experimental/decorators-stage-2/no-constructor-decorators/actual.js
vendored
Normal file
4
test/fixtures/experimental/decorators-stage-2/no-constructor-decorators/actual.js
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
class Foo {
|
||||
@abc
|
||||
constructor(){}
|
||||
}
|
||||
3
test/fixtures/experimental/decorators-stage-2/no-constructor-decorators/options.json
vendored
Normal file
3
test/fixtures/experimental/decorators-stage-2/no-constructor-decorators/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "You can't attach decorators to a class constructor (3:2)"
|
||||
}
|
||||
2
test/fixtures/experimental/decorators-stage-2/no-export-decorators-without-class/actual.js
vendored
Normal file
2
test/fixtures/experimental/decorators-stage-2/no-export-decorators-without-class/actual.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
@foo
|
||||
export default function f(){};
|
||||
@ -0,0 +1,4 @@
|
||||
{
|
||||
"throws": "You can only use decorators on an export when exporting a class (2:0)",
|
||||
"sourceType": "module"
|
||||
}
|
||||
2
test/fixtures/experimental/decorators-stage-2/no-export-decorators/actual.js
vendored
Normal file
2
test/fixtures/experimental/decorators-stage-2/no-export-decorators/actual.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
@foo
|
||||
export default 0;
|
||||
4
test/fixtures/experimental/decorators-stage-2/no-export-decorators/options.json
vendored
Normal file
4
test/fixtures/experimental/decorators-stage-2/no-export-decorators/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"throws": "You can only use decorators on an export when exporting a class (2:0)",
|
||||
"sourceType": "module"
|
||||
}
|
||||
4
test/fixtures/experimental/decorators-stage-2/no-semi/actual.js
vendored
Normal file
4
test/fixtures/experimental/decorators-stage-2/no-semi/actual.js
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
class A {
|
||||
@a;
|
||||
m(){}
|
||||
}
|
||||
3
test/fixtures/experimental/decorators-stage-2/no-semi/options.json
vendored
Normal file
3
test/fixtures/experimental/decorators-stage-2/no-semi/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "Decorators must not be followed by a semicolon (2:5)"
|
||||
}
|
||||
3
test/fixtures/experimental/decorators-stage-2/object-method-parameter/actual.js
vendored
Normal file
3
test/fixtures/experimental/decorators-stage-2/object-method-parameter/actual.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
var obj = {
|
||||
method(@foo x) {}
|
||||
};
|
||||
3
test/fixtures/experimental/decorators-stage-2/object-method-parameter/options.json
vendored
Normal file
3
test/fixtures/experimental/decorators-stage-2/object-method-parameter/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "Stage 2 decorators cannot be used to decorate parameters (2:9)"
|
||||
}
|
||||
@ -1,175 +0,0 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 31,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 31,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"sourceType": "script",
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"start": 0,
|
||||
"end": 31,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 6,
|
||||
"end": 7,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 6
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 7
|
||||
},
|
||||
"identifierName": "A"
|
||||
},
|
||||
"name": "A"
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start": 8,
|
||||
"end": 31,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 8
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassProperty",
|
||||
"start": 17,
|
||||
"end": 29,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 7
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 19
|
||||
}
|
||||
},
|
||||
"decorators": [
|
||||
{
|
||||
"type": "Decorator",
|
||||
"start": 12,
|
||||
"end": 16,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 6
|
||||
}
|
||||
},
|
||||
"expression": {
|
||||
"type": "Identifier",
|
||||
"start": 13,
|
||||
"end": 16,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 3
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 6
|
||||
},
|
||||
"identifierName": "dec"
|
||||
},
|
||||
"name": "dec"
|
||||
}
|
||||
}
|
||||
],
|
||||
"static": false,
|
||||
"computed": true,
|
||||
"key": {
|
||||
"type": "StringLiteral",
|
||||
"start": 18,
|
||||
"end": 24,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 8
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 14
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"rawValue": "name",
|
||||
"raw": "'name'"
|
||||
},
|
||||
"value": "name"
|
||||
},
|
||||
"value": {
|
||||
"type": "NumericLiteral",
|
||||
"start": 28,
|
||||
"end": 29,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 18
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 19
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"rawValue": 0,
|
||||
"raw": "0"
|
||||
},
|
||||
"value": 0
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
@ -1,3 +1,4 @@
|
||||
{
|
||||
"plugins": ["classProperties", "decorators-stage-2"]
|
||||
"plugins": ["classProperties", "decorators-stage-2"],
|
||||
"throws": "Stage 2 decorators may only be used with a class or a class method (2:7)"
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user