Skip to content

Commit

Permalink
fix(parser): fixed import call implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
KFlash committed May 28, 2019
1 parent 66fe1b0 commit cb09a9c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ export const enum Errors {
InvalidNestedStatement,
UnknownLabel,
InvalidImportTail,
ImportNotOneArg
ImportNotOneArg,
InvalidImportNew
}

/*@internal*/
Expand Down Expand Up @@ -326,7 +327,8 @@ export const errorMessages: {
[Errors.InvalidNestedStatement]: 'continue statement must be nested within an iteration statement',
[Errors.UnknownLabel]: "Undefined label '%0'",
[Errors.InvalidImportTail]: 'Trailing comma is disallowed inside import(...) arguments',
[Errors.ImportNotOneArg]: 'import() requires exactly one argument'
[Errors.ImportNotOneArg]: 'import() requires exactly one argument',
[Errors.InvalidImportNew]: 'Cannot use new with import(...)'
};

export class ParseError extends SyntaxError {
Expand Down
16 changes: 9 additions & 7 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2810,16 +2810,18 @@ function parseImportCallExpression(

nextToken(parser, context);

if (parser.token === Token.Period || parser.token === Token.RightBracket)
if (parser.token !== Token.LeftParen)
report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.token & Token.Type]);

if (inNewExpression) report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.token & Token.Type]);
if (inNewExpression) report(parser, Errors.InvalidImportNew);

let expr: ESTree.ImportExpression = { type: 'Import' };

parser.assignable = AssignmentKind.CannotAssign;

expr = parseMemberOrUpdateExpression(parser, context, expr as any, inNewExpression, /* isDynamicImport */ 1);
const expr = parseMemberOrUpdateExpression(
parser,
context,
{ type: 'Import' } as any,
inNewExpression,
/* isDynamicImport */ 1
);

parser.assignable = AssignmentKind.CannotAssign;

Expand Down

0 comments on commit cb09a9c

Please sign in to comment.