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: ignore dynamic import for hasModulesyntax #164

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -176,6 +176,15 @@ const [,,, hasModuleSyntax] = parse(`
hasModuleSyntax === true;
```

Dynamic imports are ignored since they can be used in Non-ESM files.

```js
const [,,, hasModuleSyntax] = parse(`
import('./foo.js')
`);
hasModuleSyntax === false;
```

### Environment Support

Node.js 10+, and [all browsers with Web Assembly support](https://caniuse.com/#feat=wasm).
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.
3 changes: 2 additions & 1 deletion src/lexer.h
Expand Up @@ -123,7 +123,8 @@ void addImport (const char16_t* statement_start, const char16_t* start, const ch
import->dynamic = dynamic;
import->safe = dynamic == STANDARD_IMPORT;
import->next = NULL;
hasModuleSyntax = true;
if (dynamic == IMPORT_META || dynamic == STANDARD_IMPORT)
hasModuleSyntax = true;
}

void addExport (const char16_t* start, const char16_t* end, const char16_t* local_start, const char16_t* local_end) {
Expand Down
3 changes: 2 additions & 1 deletion test/_unit.cjs
Expand Up @@ -1399,7 +1399,8 @@ function x() {
})
test('hasModuleSyntax import3', () => {
const [,,, hasModuleSyntax] = parse('import("./foo")')
assert.strictEqual(hasModuleSyntax, true)
// dynamic imports can be used in non-ESM files as well
assert.strictEqual(hasModuleSyntax, false)
})
test('hasModuleSyntax import4', () => {
const [,,, hasModuleSyntax] = parse('import.meta.url')
Expand Down