Skip to content

Commit

Permalink
fix(parser): dedupe some code
Browse files Browse the repository at this point in the history
  • Loading branch information
KFlash committed Aug 3, 2019
1 parent 6dfba9c commit 21e4449
Showing 1 changed file with 18 additions and 30 deletions.
48 changes: 18 additions & 30 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,12 @@ export function parseStatementListItem(
report(parser, Errors.InvalidImportExportSloppy, 'export');
// ImportDeclaration
case Token.ImportKeyword:
const expr = parseIdentifier(parser, context, 0);
nextToken(parser, context);
switch (parser.token) {
case Token.LeftParen:
return parseImportCallDeclaration(parser, context, start, line, column);
case Token.Period:
return parseImportMetaDeclaration(parser, context, expr, start, line, column);
return parseImportMetaDeclaration(parser, context, start, line, column);
default:
report(parser, Errors.InvalidImportExportSloppy, 'import');
}
Expand Down Expand Up @@ -736,11 +736,7 @@ export function parseExpressionOrLabelledStatement(

expr = parseMemberOrUpdateExpression(parser, context, expr, 0, 0, 0, start, line, column);

/** parseAssignmentExpression
*
* https://tc39.github.io/ecma262/#prod-AssignmentExpression
*
* AssignmentExpression :
/** AssignmentExpression :
* 1. ConditionalExpression
* 2. LeftHandSideExpression = AssignmentExpression
*
Expand Down Expand Up @@ -1115,11 +1111,8 @@ export function parseAsyncArrowOrAsyncFunctionDeclaration(
*/
if (parser.token === Token.Comma) expr = parseSequenceExpression(parser, context, 0, start, line, column, expr);

/** parseAssignmentExpression
*
* https://tc39.github.io/ecma262/#prod-AssignmentExpression
/** AssignmentExpression :
*
* AssignmentExpression :
* 1. ConditionalExpression
* 2. LeftHandSideExpression = AssignmentExpression
*
Expand Down Expand Up @@ -2459,18 +2452,8 @@ function parseImportDeclaration(
case Token.LeftParen:
return parseImportCallDeclaration(parser, context, start, line, column);
case Token.Period:
if (context & Context.OptionsNext && parser.token === Token.Period) {
return parseImportMetaDeclaration(
parser,
context,
finishNode(parser, context, start, line, column, {
type: 'Identifier',
name: 'import'
}),
start,
line,
column
);
if (context & Context.OptionsNext) {
return parseImportMetaDeclaration(parser, context, start, line, column);
}
default:
report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.token & Token.Type]);
Expand Down Expand Up @@ -2627,12 +2610,21 @@ function parseImportSpecifierOrNamedImports(
export function parseImportMetaDeclaration(
parser: ParserState,
context: Context,
meta: ESTree.Identifier,
start: number,
line: number,
column: number
): ESTree.ExpressionStatement {
let expr: ESTree.Expression = parseImportMetaExpression(parser, context, meta, start, line, column);
let expr: ESTree.Expression = parseImportMetaExpression(
parser,
context,
finishNode(parser, context, start, line, column, {
type: 'Identifier',
name: 'import'
}),
start,
line,
column
);

/** MemberExpression :
* 1. PrimaryExpression
Expand All @@ -2654,11 +2646,7 @@ export function parseImportMetaDeclaration(
*/
expr = parseMemberOrUpdateExpression(parser, context, expr, 0, 0, 0, start, line, column);

/** parseAssignmentExpression
*
* https://tc39.github.io/ecma262/#prod-AssignmentExpression
*
* AssignmentExpression :
/** AssignmentExpression :
* 1. ConditionalExpression
* 2. LeftHandSideExpression = AssignmentExpression
*/
Expand Down

0 comments on commit 21e4449

Please sign in to comment.