Skip to content

Commit

Permalink
fix: rename CoalesceExpression
Browse files Browse the repository at this point in the history
The Estree spec extends the LogicalExpression node type by adding
the '??' operator value to it:
https://github.com/estree/estree/blob/master/es2020.md#logicalexpression
  • Loading branch information
davidbonnet committed Jul 18, 2020
1 parent 83fcc51 commit 2256168
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 26 deletions.
10 changes: 0 additions & 10 deletions src/estree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export type ArgumentExpression =
| SpreadElement
| BinaryExpression
| LogicalExpression
| CoalesceExpression
| SequenceExpression;

export type CommentType = 'Line' | 'Block' | 'HTMLOpen' | 'HTMLClose';
Expand Down Expand Up @@ -104,7 +103,6 @@ export type Node =
| LabeledStatement
| Literal
| LogicalExpression
| CoalesceExpression
| MemberExpression
| MetaProperty
| MethodDefinition
Expand Down Expand Up @@ -161,7 +159,6 @@ export type Expression =
| JSXOpeningFragment
| JSXSpreadChild
| LogicalExpression
| CoalesceExpression
| NewExpression
| RestElement
| SequenceExpression
Expand Down Expand Up @@ -622,13 +619,6 @@ export interface Literal extends _Node {
raw?: string;
}

export interface CoalesceExpression extends _Node {
type: 'CoalesceExpression';
operator: string;
left: Expression;
right: Expression;
}

export interface LogicalExpression extends _Node {
type: 'LogicalExpression';
operator: string;
Expand Down
2 changes: 1 addition & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3416,7 +3416,7 @@ export function parseBinaryExpression(
nextToken(parser, context | Context.AllowRegExp);

left = finishNode(parser, context, start, line, column, {
type: t & Token.IsLogical ? 'LogicalExpression' : t & Token.IsCoalesc ? 'CoalesceExpression' : 'BinaryExpression',
type: t & Token.IsLogical || t & Token.IsCoalesc ? 'LogicalExpression' : 'BinaryExpression',
left,
right: parseBinaryExpression(
parser,
Expand Down
2 changes: 1 addition & 1 deletion test/parser/miscellaneous/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ describe('Expressions - API', () => {
{
type: 'ExpressionStatement',
expression: {
type: 'CoalesceExpression',
type: 'LogicalExpression',
left: {
type: 'Identifier',
name: 'a',
Expand Down
28 changes: 14 additions & 14 deletions test/parser/next/nullCoalescing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ describe('Next - Nullish Coalescing', () => {
type: 'Literal',
value: 3
},
type: 'CoalesceExpression'
type: 'LogicalExpression'
},
property: {
name: 'x',
Expand Down Expand Up @@ -187,7 +187,7 @@ describe('Next - Nullish Coalescing', () => {
type: 'Literal',
value: 3
},
type: 'CoalesceExpression'
type: 'LogicalExpression'
},
type: 'ExpressionStatement'
}
Expand All @@ -212,7 +212,7 @@ describe('Next - Nullish Coalescing', () => {
type: 'Literal',
value: 3
},
type: 'CoalesceExpression'
type: 'LogicalExpression'
},
type: 'ExpressionStatement'
}
Expand Down Expand Up @@ -245,7 +245,7 @@ describe('Next - Nullish Coalescing', () => {
type: 'Literal',
value: 3
},
type: 'CoalesceExpression'
type: 'LogicalExpression'
},
type: 'ExpressionStatement'
}
Expand Down Expand Up @@ -278,7 +278,7 @@ describe('Next - Nullish Coalescing', () => {
type: 'Literal',
value: 3
},
type: 'CoalesceExpression'
type: 'LogicalExpression'
},
type: 'ExpressionStatement'
}
Expand Down Expand Up @@ -311,7 +311,7 @@ describe('Next - Nullish Coalescing', () => {
},
type: 'LogicalExpression'
},
type: 'CoalesceExpression'
type: 'LogicalExpression'
},
type: 'ExpressionStatement'
}
Expand Down Expand Up @@ -339,14 +339,14 @@ describe('Next - Nullish Coalescing', () => {
name: 'b',
type: 'Identifier'
},
type: 'CoalesceExpression'
type: 'LogicalExpression'
},
operator: '??',
right: {
name: 'c',
type: 'Identifier'
},
type: 'CoalesceExpression'
type: 'LogicalExpression'
},
type: 'ExpressionStatement'
}
Expand All @@ -371,7 +371,7 @@ describe('Next - Nullish Coalescing', () => {
type: 'Literal',
value: 1
},
type: 'CoalesceExpression'
type: 'LogicalExpression'
},
type: 'ExpressionStatement'
}
Expand All @@ -397,14 +397,14 @@ describe('Next - Nullish Coalescing', () => {
name: 'b',
type: 'Identifier'
},
type: 'CoalesceExpression'
type: 'LogicalExpression'
},
operator: '??',
right: {
name: 'c',
type: 'Identifier'
},
type: 'CoalesceExpression'
type: 'LogicalExpression'
},
type: 'ExpressionStatement'
}
Expand Down Expand Up @@ -437,7 +437,7 @@ describe('Next - Nullish Coalescing', () => {
},
type: 'LogicalExpression'
},
type: 'CoalesceExpression'
type: 'LogicalExpression'
},
type: 'ExpressionStatement'
}
Expand Down Expand Up @@ -470,7 +470,7 @@ describe('Next - Nullish Coalescing', () => {
name: 'c',
type: 'Identifier'
},
type: 'CoalesceExpression'
type: 'LogicalExpression'
},
type: 'ExpressionStatement'
}
Expand Down Expand Up @@ -503,7 +503,7 @@ describe('Next - Nullish Coalescing', () => {
name: 'c',
type: 'Identifier'
},
type: 'CoalesceExpression'
type: 'LogicalExpression'
},
type: 'ExpressionStatement'
}
Expand Down

0 comments on commit 2256168

Please sign in to comment.