Merge pull request #590 from peey/decorators-followup

Follow-up on Decorators PR
This commit is contained in:
Henry Zhu
2017-06-27 15:34:44 -04:00
committed by GitHub
9 changed files with 839 additions and 12 deletions

View File

@@ -0,0 +1,6 @@
@outer({
store: @inner class Foo {}
})
class Bar {
}

View File

@@ -0,0 +1,269 @@
{
"type": "File",
"start": 0,
"end": 57,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 6,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 57,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 6,
"column": 1
}
},
"sourceType": "script",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 57,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 6,
"column": 1
}
},
"decorators": [
{
"type": "Decorator",
"start": 0,
"end": 40,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 2
}
},
"expression": {
"type": "CallExpression",
"start": 1,
"end": 40,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 3,
"column": 2
}
},
"callee": {
"type": "Identifier",
"start": 1,
"end": 6,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 6
},
"identifierName": "outer"
},
"name": "outer"
},
"arguments": [
{
"type": "ObjectExpression",
"start": 7,
"end": 39,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 3,
"column": 1
}
},
"properties": [
{
"type": "ObjectProperty",
"start": 11,
"end": 37,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 28
}
},
"method": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 11,
"end": 16,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 7
},
"identifierName": "store"
},
"name": "store"
},
"shorthand": false,
"value": {
"type": "ClassExpression",
"start": 18,
"end": 37,
"loc": {
"start": {
"line": 2,
"column": 9
},
"end": {
"line": 2,
"column": 28
}
},
"decorators": [
{
"type": "Decorator",
"start": 18,
"end": 24,
"loc": {
"start": {
"line": 2,
"column": 9
},
"end": {
"line": 2,
"column": 15
}
},
"expression": {
"type": "Identifier",
"start": 19,
"end": 24,
"loc": {
"start": {
"line": 2,
"column": 10
},
"end": {
"line": 2,
"column": 15
},
"identifierName": "inner"
},
"name": "inner"
}
}
],
"id": {
"type": "Identifier",
"start": 31,
"end": 34,
"loc": {
"start": {
"line": 2,
"column": 22
},
"end": {
"line": 2,
"column": 25
},
"identifierName": "Foo"
},
"name": "Foo"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 35,
"end": 37,
"loc": {
"start": {
"line": 2,
"column": 26
},
"end": {
"line": 2,
"column": 28
}
},
"body": []
}
}
}
]
}
]
}
}
],
"id": {
"type": "Identifier",
"start": 47,
"end": 50,
"loc": {
"start": {
"line": 4,
"column": 6
},
"end": {
"line": 4,
"column": 9
},
"identifierName": "Bar"
},
"name": "Bar"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 51,
"end": 57,
"loc": {
"start": {
"line": 4,
"column": 10
},
"end": {
"line": 6,
"column": 1
}
},
"body": []
}
}
],
"directives": []
}
}

View File

@@ -0,0 +1,9 @@
class Bar{
@outer(
@classDec class {
@inner
innerMethod() {}
}
)
outerMethod() {}
}

View File

@@ -0,0 +1,351 @@
{
"type": "File",
"start": 0,
"end": 112,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 9,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 112,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 9,
"column": 1
}
},
"sourceType": "script",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 112,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 9,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 9,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 9
},
"identifierName": "Bar"
},
"name": "Bar"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 9,
"end": 112,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 9,
"column": 1
}
},
"body": [
{
"type": "ClassMethod",
"start": 13,
"end": 110,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 8,
"column": 18
}
},
"decorators": [
{
"type": "Decorator",
"start": 13,
"end": 91,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 7,
"column": 3
}
},
"expression": {
"type": "CallExpression",
"start": 14,
"end": 91,
"loc": {
"start": {
"line": 2,
"column": 3
},
"end": {
"line": 7,
"column": 3
}
},
"callee": {
"type": "Identifier",
"start": 14,
"end": 19,
"loc": {
"start": {
"line": 2,
"column": 3
},
"end": {
"line": 2,
"column": 8
},
"identifierName": "outer"
},
"name": "outer"
},
"arguments": [
{
"type": "ClassExpression",
"start": 25,
"end": 87,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 6,
"column": 5
}
},
"decorators": [
{
"type": "Decorator",
"start": 25,
"end": 34,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 13
}
},
"expression": {
"type": "Identifier",
"start": 26,
"end": 34,
"loc": {
"start": {
"line": 3,
"column": 5
},
"end": {
"line": 3,
"column": 13
},
"identifierName": "classDec"
},
"name": "classDec"
}
}
],
"id": null,
"superClass": null,
"body": {
"type": "ClassBody",
"start": 41,
"end": 87,
"loc": {
"start": {
"line": 3,
"column": 20
},
"end": {
"line": 6,
"column": 5
}
},
"body": [
{
"type": "ClassMethod",
"start": 50,
"end": 80,
"loc": {
"start": {
"line": 4,
"column": 6
},
"end": {
"line": 5,
"column": 22
}
},
"decorators": [
{
"type": "Decorator",
"start": 50,
"end": 56,
"loc": {
"start": {
"line": 4,
"column": 6
},
"end": {
"line": 4,
"column": 12
}
},
"expression": {
"type": "Identifier",
"start": 51,
"end": 56,
"loc": {
"start": {
"line": 4,
"column": 7
},
"end": {
"line": 4,
"column": 12
},
"identifierName": "inner"
},
"name": "inner"
}
}
],
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 64,
"end": 75,
"loc": {
"start": {
"line": 5,
"column": 6
},
"end": {
"line": 5,
"column": 17
},
"identifierName": "innerMethod"
},
"name": "innerMethod"
},
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 78,
"end": 80,
"loc": {
"start": {
"line": 5,
"column": 20
},
"end": {
"line": 5,
"column": 22
}
},
"body": [],
"directives": []
}
}
]
}
}
]
}
}
],
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 94,
"end": 105,
"loc": {
"start": {
"line": 8,
"column": 2
},
"end": {
"line": 8,
"column": 13
},
"identifierName": "outerMethod"
},
"name": "outerMethod"
},
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 108,
"end": 110,
"loc": {
"start": {
"line": 8,
"column": 16
},
"end": {
"line": 8,
"column": 18
}
},
"body": [],
"directives": []
}
}
]
}
}
],
"directives": []
}
}

View File

@@ -1,4 +1,4 @@
{
"sourceType": "module",
"throws": "Leading decorators must be attached to a class declaration (2:0)"
"throws": "Using the export keyword between a decorator and a class is not allowed. Please use `export @dec class` instead (2:0)"
}

View File

@@ -0,0 +1,4 @@
class Foo {
@dec
static bar() {}
}

View File

@@ -0,0 +1,175 @@
{
"type": "File",
"start": 0,
"end": 38,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 38,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"sourceType": "script",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 38,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"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": 38,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 4,
"column": 1
}
},
"body": [
{
"type": "ClassMethod",
"start": 14,
"end": 36,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 3,
"column": 17
}
},
"decorators": [
{
"type": "Decorator",
"start": 14,
"end": 18,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 6
}
},
"expression": {
"type": "Identifier",
"start": 15,
"end": 18,
"loc": {
"start": {
"line": 2,
"column": 3
},
"end": {
"line": 2,
"column": 6
},
"identifierName": "dec"
},
"name": "dec"
}
}
],
"static": true,
"computed": false,
"key": {
"type": "Identifier",
"start": 28,
"end": 31,
"loc": {
"start": {
"line": 3,
"column": 9
},
"end": {
"line": 3,
"column": 12
},
"identifierName": "bar"
},
"name": "bar"
},
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 34,
"end": 36,
"loc": {
"start": {
"line": 3,
"column": 15
},
"end": {
"line": 3,
"column": 17
}
},
"body": [],
"directives": []
}
}
]
}
}
],
"directives": []
}
}