Skip to content

Commit

Permalink
fix #38, use code from esprima-net
Browse files Browse the repository at this point in the history
  • Loading branch information
jogibear9988 committed Jan 6, 2024
1 parent 90cf526 commit b1245fa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"esparse": "./bin/esparse.js",
"esvalidate": "./bin/esvalidate.js"
},
"version": "6.0.1",
"version": "6.0.2",
"files": [
"bin",
"dist/esprima.js",
Expand Down
2 changes: 1 addition & 1 deletion src/esprima.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export { Syntax } from './syntax';
export { Visitor } from './visitor'

// Sync with *.json manifests.
export const version = '6.0.1';
export const version = '6.0.2';

export default {
parse, parseModule, parseScript, tokenize, Syntax, version
Expand Down
18 changes: 12 additions & 6 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1342,21 +1342,27 @@ export class Parser {
this.expectKeyword('import');
this.expect("(");

var previousIsAssignmentTarget = this.context.isAssignmentTarget;
this.context.isAssignmentTarget = true;

const source = this.parseAssignmentExpression();

let attributes: Node.Expression | null = null;
if (this.match(",")) {
this.nextToken();
attributes = this.parseObjectInitializer();
if (!this.match(")"))
attributes = this.parseAssignmentExpression();
}

if (!this.match(")") && this.config.tolerant) {
this.tolerateUnexpectedToken(this.nextToken());
} else {
this.expect(")");
if (this.match(";")) {
this.context.isAssignmentTarget = previousIsAssignmentTarget;

if (!this.match(")")) {
if (this.match(",")) {
this.nextToken();
}
this.expect(")");
} else {
this.nextToken();
}
return this.finalize(node, new Node.ImportExpression(source, attributes));
}
Expand Down
10 changes: 9 additions & 1 deletion test/esprima-next.issue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,12 @@ test('esprima-next - #36 - fixes after changes', () => {
`;
let ast = parseModule(code);
expect(ast).not.toBeNull();
});
});

test('esprima-next - #38 - Error with await import and the following statement on the same line', () => {
let code = `async function load (i) {
let c = await import(i,); console.log(c);
}`;
let ast = parseModule(code, { loc: true, range:true, tokens:true });
expect(ast).not.toBeNull();
});

0 comments on commit b1245fa

Please sign in to comment.