Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dynamic import paren ranges #157

Merged
merged 4 commits into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chompfile.toml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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