Disallow exports between decorator & class body

For stage 2 decorators
This commit is contained in:
Peeyush Kushwaha 2017-06-17 18:12:14 +05:30
parent 9c639743dd
commit b5e23835ce
10 changed files with 6 additions and 379 deletions

View File

@ -157,6 +157,10 @@ export default class StatementParser extends ExpressionParser {
}
parseDecorators(allowExport?: boolean): void {
if (this.hasPlugin("decorators-stage-2")) {
allowExport = false;
}
while (this.match(tt.at)) {
const decorator = this.parseDecorator();
this.state.decorators.push(decorator);

View File

@ -1,116 +0,0 @@
{
"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": []
}
}

View File

@ -1,3 +1,4 @@
{
"sourceType": "module"
"sourceType": "module",
"throws": "Leading decorators must be attached to a class declaration (2:0)"
}

View File

@ -1,7 +0,0 @@
@ParentDecorator
export default class ParentClass {
makeNestedClass() {
class NestedClass {
}
}
}

View File

@ -1,240 +0,0 @@
{
"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": []
}
}

View File

@ -1,3 +0,0 @@
{
"sourceType": "module"
}

View File

@ -1,2 +0,0 @@
@foo
export default function f(){};

View File

@ -1,4 +0,0 @@
{
"throws": "You can only use decorators on an export when exporting a class (2:0)",
"sourceType": "module"
}

View File

@ -1,2 +0,0 @@
@foo
export default 0;

View File

@ -1,4 +0,0 @@
{
"throws": "You can only use decorators on an export when exporting a class (2:0)",
"sourceType": "module"
}