Skip to content

Commit

Permalink
fix: dynamic import paren ranges (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Sep 10, 2023
1 parent d44ad4a commit 842c16c
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion chompfile.toml
Expand Up @@ -52,7 +52,7 @@ dep = 'src/lexer.ts'
# even when we set "source-maps = false", so for now we have ejected the
# template to its raw "run" command, and added an "rm" step.
run = '''
node ./node_modules/@swc/cli/bin/swc.js $DEP -o $TARGET --no-swcrc -C jsc.parser.syntax=typescript -C jsc.parser.importAssertions=true -C jsc.parser.topLevelAwait=true -C jsc.parser.importMeta=true -C jsc.parser.privateMethod=true -C jsc.parser.dynamicImport=true -C jsc.target=es2016 -C jsc.experimental.keepImportAssertions=true
node ./node_modules/@swc/cli/bin/swc.js $DEP -o $TARGET --no-swcrc -C jsc.parser.syntax=typescript -C jsc.parser.importAssertions=true -C jsc.parser.topLevelAwait=true -C jsc.parser.importMeta=true -C jsc.parser.privateMethod=true -C jsc.parser.dynamicImport=true -C jsc.target=es2016 -C jsc.experimental.keepImportAttributes=true
'''

[[task]]
Expand Down
2 changes: 1 addition & 1 deletion lib/lexer.asm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/lexer.emcc.asm.js

Large diffs are not rendered by default.

Binary file modified lib/lexer.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -29,7 +29,7 @@
"@types/node": "^18.7.1",
"kleur": "^2.0.2",
"mocha": "^5.2.0",
"terser": "^5.14.2",
"terser": "^5.19.4",
"typescript": "^4.7.4"
},
"files": [
Expand Down
2 changes: 1 addition & 1 deletion src/lexer.c
Expand Up @@ -129,7 +129,7 @@ bool parse () {
if (openTokenDepth == 0)
return syntaxError(), false;
openTokenDepth--;
if (dynamicImportStackDepth > 0 && dynamicImportStack[dynamicImportStackDepth - 1]->dynamic == openTokenStack[openTokenDepth].pos) {
if (dynamicImportStackDepth > 0 && openTokenStack[openTokenDepth].token == ImportParen) {
Import* cur_dynamic_import = dynamicImportStack[dynamicImportStackDepth - 1];
if (cur_dynamic_import->end == 0)
cur_dynamic_import->end = pos;
Expand Down
7 changes: 7 additions & 0 deletions test/_unit.cjs
Expand Up @@ -39,6 +39,13 @@ function assertExportIs(source, actual, expected) {
suite('Lexer', () => {
beforeEach(async () => await init);

test(`Dynamic import expression range`, () => {
const source = `import(("asdf")) aaaa`;
const [[impt]] = parse(source);
assert.strictEqual(source.slice(impt.ss, impt.se), 'import(("asdf"))');
assert.strictEqual(source.slice(impt.s, impt.e), '("asdf")');
});

test(`Simple export destructuring`, () => {
const source = `
export const{URI,Utils,...Another}=LIB
Expand Down

0 comments on commit 842c16c

Please sign in to comment.