Skip to content

Commit

Permalink
fix(estree): fix the estree interface for BigIntLiteral, cleanup RegE…
Browse files Browse the repository at this point in the history
…xpLiteral
  • Loading branch information
3cp committed Sep 21, 2020
1 parent 46f60b4 commit 100c9ad
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
17 changes: 11 additions & 6 deletions src/estree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export type Node =
| PrivateName
| Program
| Property
| RegExpLiteral
| RestElement
| ReturnStatement
| SequenceExpression
Expand Down Expand Up @@ -185,7 +186,7 @@ export type LeftHandSideExpression =
| MemberExpression
| PrimaryExpression
| TaggedTemplateExpression;
export type LiteralExpression = BigIntLiteral | Literal | TemplateLiteral;
export type LiteralExpression = Literal | TemplateLiteral;
export type ObjectLiteralElementLike = MethodDefinition | Property | RestElement | SpreadElement;
export type Parameter = AssignmentPattern | RestElement | ArrayPattern | ObjectPattern | Identifier;
export type PrimaryExpression =
Expand Down Expand Up @@ -311,11 +312,8 @@ export interface AwaitExpression extends _Node {
argument: Expression;
}

export interface BigIntLiteral extends _Node {
type: 'BigIntLiteral';
value: number | null;
export interface BigIntLiteral extends Literal {
bigint: string;
raw?: string;
}

export interface BinaryExpression extends _Node {
Expand Down Expand Up @@ -615,7 +613,7 @@ export interface LabeledStatement extends _Node {

export interface Literal extends _Node {
type: 'Literal';
value: boolean | number | string | null;
value: boolean | number | string | null | RegExp | bigint;
raw?: string;
}

Expand Down Expand Up @@ -683,6 +681,13 @@ export interface Property extends _Node {
kind: 'init' | 'get' | 'set';
}

export interface RegExpLiteral extends Literal {
regex: {
pattern: string;
flags: string;
};
}

export interface RestElement extends _Node {
type: 'RestElement';
argument: BindingPattern | Identifier | Expression | PropertyName;
Expand Down
10 changes: 5 additions & 5 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4403,13 +4403,13 @@ export function parseBigIntLiteral(
column,
context & Context.OptionsRaw
? {
type: 'BigIntLiteral',
type: 'Literal',
value: tokenValue,
bigint: tokenRaw,
raw: tokenRaw
}
: {
type: 'BigIntLiteral',
type: 'Literal',
value: tokenValue,
bigint: tokenRaw
}
Expand Down Expand Up @@ -7780,21 +7780,21 @@ export function parseRegExpLiteral(
start: number,
line: number,
column: number
): ESTree.Literal {
): ESTree.RegExpLiteral {
const { tokenRaw, tokenRegExp, tokenValue } = parser;
nextToken(parser, context);
parser.assignable = AssignmentKind.CannotAssign;
return context & Context.OptionsRaw
? finishNode(parser, context, start, line, column, {
type: 'Literal',
value: tokenValue,
regex: tokenRegExp,
regex: tokenRegExp as { pattern: string; flags: string },
raw: tokenRaw
})
: finishNode(parser, context, start, line, column, {
type: 'Literal',
value: tokenValue,
regex: tokenRegExp
regex: tokenRegExp as { pattern: string; flags: string }
});
}

Expand Down
6 changes: 3 additions & 3 deletions test/parser/expressions/bigint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ describe('Expressions - BigInt', () => {
{
type: 'ExpressionStatement',
expression: {
type: 'BigIntLiteral',
type: 'Literal',
value: BigInt(1),
bigint: '1n',
start: 0,
Expand Down Expand Up @@ -181,15 +181,15 @@ describe('Expressions - BigInt', () => {
expression: {
type: 'BinaryExpression',
left: {
type: 'BigIntLiteral',
type: 'Literal',
value: BigInt(1),
bigint: '1n',
start: 0,
end: 2,
range: [0, 2]
},
right: {
type: 'BigIntLiteral',
type: 'Literal',
value: BigInt(2333333),
bigint: '2333333n',
start: 5,
Expand Down

0 comments on commit 100c9ad

Please sign in to comment.