Update decorators parsing (#7719)
* Update decorators parsing
This commit introduces three changes:
1) Class properties can be decorated
2) Decorators can contain arbitrary expressions, using @(...)
3) The Decorator node type has a new property, "arguments". This
makes it possible do distinguish @dec() and @(dec()), which have
different behaviors because @(dec()) is equivalent to @(dec())().
* Rename Decorator#expression to Decorator#callee
* Add test for @dec()()
This commit is contained in:
@@ -584,12 +584,13 @@ Aliases: `Flow`, `FlowPredicate`
|
||||
|
||||
### decorator
|
||||
```javascript
|
||||
t.decorator(expression)
|
||||
t.decorator(callee, arguments)
|
||||
```
|
||||
|
||||
See also `t.isDecorator(node, opts)` and `t.assertDecorator(node, opts)`.
|
||||
|
||||
- `expression`: `Expression` (required)
|
||||
- `callee`: `Expression` (required)
|
||||
- `arguments`: `Array<Expression | SpreadElement>` (default: `null`)
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -135,11 +135,18 @@ defineType("Import", {
|
||||
});
|
||||
|
||||
defineType("Decorator", {
|
||||
visitor: ["expression"],
|
||||
visitor: ["callee", "arguments"],
|
||||
fields: {
|
||||
expression: {
|
||||
callee: {
|
||||
validate: assertNodeType("Expression"),
|
||||
},
|
||||
arguments: {
|
||||
optional: true,
|
||||
validate: chain(
|
||||
assertValueType("array"),
|
||||
assertEach(assertNodeType("Expression", "SpreadElement")),
|
||||
),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user