Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add AST spec on optional chain [skip ci] #11729

Merged
merged 1 commit into from Jul 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 34 additions & 6 deletions packages/babel-parser/ast/spec.md
Expand Up @@ -77,9 +77,11 @@ These are the core @babel/parser (babylon) AST node types.
- [SpreadElement](#spreadelement)
- [ArgumentPlaceholder](#argumentplaceholder)
- [MemberExpression](#memberexpression)
- [OptionalMemberExpression](#optionalmemberexpression)
- [BindExpression](#bindexpression)
- [ConditionalExpression](#conditionalexpression)
- [CallExpression](#callexpression)
- [OptionalCallExpression](#optionalcallexpression)
- [NewExpression](#newexpression)
- [SequenceExpression](#sequenceexpression)
- [ParenthesizedExpression](#parenthesizedexpression)
Expand Down Expand Up @@ -176,17 +178,16 @@ interface Identifier <: Expression, Pattern {

An identifier. Note that an identifier may be an expression or a destructuring pattern.


# PrivateName

```js
interface PrivateName <: Expression, Pattern {
interface PrivateName <: Node {
type: "PrivateName";
id: Identifier;
}
```
A Private Name Identifier.

A Private Name Identifier.

# Literals

Expand Down Expand Up @@ -817,12 +818,12 @@ An update (increment or decrement) operator token.
interface BinaryExpression <: Expression {
type: "BinaryExpression";
operator: BinaryOperator;
left: Expression;
left: Expression | PrivateName;
right: Expression;
}
```

A binary operator expression.
A binary operator expression. When `operator` is `in`, the `left` can be a `PrivateName`.

#### BinaryOperator

Expand Down Expand Up @@ -912,13 +913,27 @@ interface ArgumentPlaceholder <: Node {
interface MemberExpression <: Expression, Pattern {
type: "MemberExpression";
object: Expression | Super;
property: Expression;
property: Expression | PrivateName;
computed: boolean;
}
```

A member expression. If `computed` is `true`, the node corresponds to a computed (`a[b]`) member expression and `property` is an `Expression`. If `computed` is `false`, the node corresponds to a static (`a.b`) member expression and `property` is an `Identifier` or a `PrivateName`.

### OptionalMemberExpression

```js
interface OptionalMemberExpression <: Expression {
type: "OptionalMemberExpression";
object: Expression;
property: Expression | PrivateName;
computed: boolean;
optional: boolean;
}
```

An optional member expression is a part of the optional chain. When `optional` is `true`, it is the starting element of the optional chain. i.e. In `a?.b.c`, `?.b` is an optional member expression with `optional: true`, `.c` is an optional member expression. See this [gist](https://gist.github.com/JLHwung/567fb29fa2b82bbe164ad9067ff3290f) for more AST examples.

### BindExpression

```js
Expand Down Expand Up @@ -1004,6 +1019,19 @@ interface CallExpression <: Expression {

A function or method call expression. When the `callee` is `Import`, the `arguments` must have only one `Expression` element.

## OptionalCallExpression

```js
interface OptionalCallExpression <: Expression {
type: "OptionalCallExpression";
callee: Expression;
arguments: [ Expression | SpreadElement ];
optional: boolean;
}
```

An optional call expression is a part of the optional chain. When `optional` is `true`, it is the starting element of the optional chain. i.e. In `f?.()()`, `?.()` is an optional call expression with `optional: true`, `()` is an optional call expression with `optional: false`. See this [gist](https://gist.github.com/JLHwung/567fb29fa2b82bbe164ad9067ff3290f) for more AST examples.

## NewExpression

```js
Expand Down