Ensure takeDecorators is called on exported class (#358)

This commit is contained in:
Brian Ng 2017-02-22 09:22:38 -06:00 committed by Daniel Tschinder
parent 94eda1254e
commit ad8d520406
4 changed files with 251 additions and 1 deletions

View File

@ -76,7 +76,6 @@ pp.parseStatement = function (declaration, topLevel) {
case tt._class: case tt._class:
if (!declaration) this.unexpected(); if (!declaration) this.unexpected();
this.takeDecorators(node);
return this.parseClass(node, true); return this.parseClass(node, true);
case tt._if: return this.parseIfStatement(node); case tt._if: return this.parseIfStatement(node);
@ -618,6 +617,7 @@ pp.parseFunctionParams = function (node) {
pp.parseClass = function (node, isStatement, optionalId) { pp.parseClass = function (node, isStatement, optionalId) {
this.next(); this.next();
this.takeDecorators(node);
this.parseClassId(node, isStatement, optionalId); this.parseClassId(node, isStatement, optionalId);
this.parseClassSuper(node); this.parseClassSuper(node);
this.parseClassBody(node); this.parseClassBody(node);

View File

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

View 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
}
},
"id": {
"type": "Identifier",
"start": 38,
"end": 49,
"loc": {
"start": {
"line": 2,
"column": 21
},
"end": {
"line": 2,
"column": 32
},
"identifierName": "ParentClass"
},
"name": "ParentClass"
},
"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"
}
}
],
"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
}
},
"computed": false,
"key": {
"type": "Identifier",
"start": 54,
"end": 69,
"loc": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 17
},
"identifierName": "makeNestedClass"
},
"name": "makeNestedClass"
},
"static": false,
"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

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