Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Commit

Permalink
parse parameter decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
shuhei committed Mar 24, 2016
1 parent 6b14e4c commit 066229f
Show file tree
Hide file tree
Showing 8 changed files with 1,107 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/parser/lval.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,14 @@ pp.parseBindingList = function (close, allowEmpty, allowTrailingComma) {
this.expect(close);
break;
} else {
let decorators = [];
while (this.match(tt.at)) {
decorators.push(this.parseDecorator());
}
let left = this.parseMaybeDefault();
if (decorators.length) {
left.decorators = decorators;
}
this.parseAssignableListItemTypes(left);
elts.push(this.parseMaybeDefault(null, null, left));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function func(@foo() x, @bar({ a: 123 }) @baz() y) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,335 @@
{
"type": "File",
"start": 0,
"end": 53,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 53
}
},
"program": {
"type": "Program",
"start": 0,
"end": 53,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 53
}
},
"sourceType": "script",
"body": [
{
"type": "FunctionDeclaration",
"start": 0,
"end": 53,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 53
}
},
"id": {
"type": "Identifier",
"start": 9,
"end": 13,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 13
}
},
"name": "func"
},
"generator": false,
"expression": false,
"params": [
{
"type": "Identifier",
"start": 21,
"end": 22,
"loc": {
"start": {
"line": 1,
"column": 21
},
"end": {
"line": 1,
"column": 22
}
},
"name": "x",
"decorators": [
{
"type": "Decorator",
"start": 14,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 20
}
},
"expression": {
"type": "CallExpression",
"start": 15,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 20
}
},
"callee": {
"type": "Identifier",
"start": 15,
"end": 18,
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 18
}
},
"name": "foo"
},
"arguments": []
}
}
]
},
{
"type": "Identifier",
"start": 48,
"end": 49,
"loc": {
"start": {
"line": 1,
"column": 48
},
"end": {
"line": 1,
"column": 49
}
},
"name": "y",
"decorators": [
{
"type": "Decorator",
"start": 24,
"end": 40,
"loc": {
"start": {
"line": 1,
"column": 24
},
"end": {
"line": 1,
"column": 40
}
},
"expression": {
"type": "CallExpression",
"start": 25,
"end": 40,
"loc": {
"start": {
"line": 1,
"column": 25
},
"end": {
"line": 1,
"column": 40
}
},
"callee": {
"type": "Identifier",
"start": 25,
"end": 28,
"loc": {
"start": {
"line": 1,
"column": 25
},
"end": {
"line": 1,
"column": 28
}
},
"name": "bar"
},
"arguments": [
{
"type": "ObjectExpression",
"start": 29,
"end": 39,
"loc": {
"start": {
"line": 1,
"column": 29
},
"end": {
"line": 1,
"column": 39
}
},
"properties": [
{
"type": "ObjectProperty",
"start": 31,
"end": 37,
"loc": {
"start": {
"line": 1,
"column": 31
},
"end": {
"line": 1,
"column": 37
}
},
"method": false,
"shorthand": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 31,
"end": 32,
"loc": {
"start": {
"line": 1,
"column": 31
},
"end": {
"line": 1,
"column": 32
}
},
"name": "a"
},
"value": {
"type": "NumericLiteral",
"start": 34,
"end": 37,
"loc": {
"start": {
"line": 1,
"column": 34
},
"end": {
"line": 1,
"column": 37
}
},
"extra": {
"rawValue": 123,
"raw": "123"
},
"value": 123
}
}
]
}
]
}
},
{
"type": "Decorator",
"start": 41,
"end": 47,
"loc": {
"start": {
"line": 1,
"column": 41
},
"end": {
"line": 1,
"column": 47
}
},
"expression": {
"type": "CallExpression",
"start": 42,
"end": 47,
"loc": {
"start": {
"line": 1,
"column": 42
},
"end": {
"line": 1,
"column": 47
}
},
"callee": {
"type": "Identifier",
"start": 42,
"end": 45,
"loc": {
"start": {
"line": 1,
"column": 42
},
"end": {
"line": 1,
"column": 45
}
},
"name": "baz"
},
"arguments": []
}
}
]
}
],
"body": {
"type": "BlockStatement",
"start": 51,
"end": 53,
"loc": {
"start": {
"line": 1,
"column": 51
},
"end": {
"line": 1,
"column": 53
}
},
"body": [],
"directives": []
}
}
],
"directives": []
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const func = function (@foo() x, @bar({ a: 123 }) @baz() y) {};
Loading

0 comments on commit 066229f

Please sign in to comment.