Add some test coverage for decorators stage-0 plugin (#250)

This commit is contained in:
Andrew Levine 2017-01-05 15:07:40 -06:00 committed by Daniel Tschinder
parent 3267e5f365
commit cec8bc0354
10 changed files with 703 additions and 1 deletions

View File

@ -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`

View File

@ -0,0 +1,2 @@
@foo('bar')
class Foo {}

View 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": []
}
}

View File

@ -0,0 +1,4 @@
@abc
class Foo {
}

View 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": []
}
}

View File

@ -0,0 +1,3 @@
class Foo {
@foo[bar] a = 1;
}

View File

@ -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": []
}
}

View File

@ -0,0 +1,3 @@
{
"plugins": ["decorators", "classProperties"]
}

View File

@ -0,0 +1,6 @@
class Foo {
@bar[bizz]
abc() {
}
}

View File

@ -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": []
}
}