Skip to content
Closed
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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ import { init, parse } from 'es-module-lexer';
source.slice(imports[3].a, imports[3].se - 1);

// For non-string dynamic import expressions:
// - n will be undefined
// - n will be undefined, except for a lone template literal: import(`./a/${x}.js`)
// reports n as a glob with each ${...} collapsed to "*" (e.g. "./a/*.js")
// - a is currently -1 even if there is an import attribute
// - e is currently the character before the closing )

Expand Down Expand Up @@ -218,6 +219,8 @@ To handle escape sequences in specifier strings, the `.n` field of imported spec

For dynamic import expressions, this field will be empty if not a valid JS string.

When the entire dynamic import argument is a single template literal, `.n` is reported as a glob: each `${...}` substitution is collapsed to a single `*` (for example `` import(`./locales/${locale}.js`) `` yields `./locales/*.js`). A template concatenated with anything else, or any other expression, still resolves to `undefined`.

### Facade Detection

Facade modules that only use import / export syntax can be detected via the third return value:
Expand Down
16 changes: 8 additions & 8 deletions bench/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Promise.resolve().then(async () => {
{
const start = process.hrtime.bigint();
var { parse } = await import('../dist/lexer.asm.js');
console.log(`> ${c.bold.green(Math.round(Number(process.hrtime.bigint() - start) / 1e6) + 'ms')}`);
console.log(`> ${c.bold().green(Math.round(Number(process.hrtime.bigint() - start) / 1e6) + 'ms')}`);
}

doRun();
Expand All @@ -46,7 +46,7 @@ Promise.resolve().then(async () => {
const start = process.hrtime.bigint();
var { parse, init } = await import('../dist/lexer.js');
await init;
console.log(`> ${c.bold.green(Math.round(Number(process.hrtime.bigint() - start) / 1e6) + 'ms')}`);
console.log(`> ${c.bold().green(Math.round(Number(process.hrtime.bigint() - start) / 1e6) + 'ms')}`);
}

doRun();
Expand All @@ -61,22 +61,22 @@ Promise.resolve().then(async () => {
totalSize += size;
total += timeRun(code);
});
console.log(c.bold.cyan(`test/samples/*.js (${Math.round(totalSize / 1e3)} KiB)`));
console.log(`> ${c.bold.green(total + 'ms')}`);
console.log(c.bold().cyan(`test/samples/*.js (${Math.round(totalSize / 1e3)} KiB)`));
console.log(`> ${c.bold().green(total + 'ms')}`);
gc();
}

console.log(`\nWarm Runs (average of ${n} runs)`);
files.forEach(({ file, code, size }) => {
console.log(c.bold.cyan(`${file} (${Math.round(size / 1e3)} KiB)`));
console.log(c.bold().cyan(`${file} (${Math.round(size / 1e3)} KiB)`));

let total = 0;
for (let i = 0; i < n; i++) {
total += timeRun(code);
gc();
}

console.log(`> ${c.bold.green((total / n) + 'ms')}`);
console.log(`> ${c.bold().green((total / n) + 'ms')}`);
});

console.log(`\nWarm Runs, All Samples (average of ${n} runs)`);
Expand All @@ -87,8 +87,8 @@ Promise.resolve().then(async () => {
total += timeRun(code);
});
}
console.log(c.bold.cyan(`test/samples/*.js (${Math.round(totalSize / 1e3)} KiB)`));
console.log(`> ${c.bold.green((total / n) + 'ms')}`);
console.log(c.bold().cyan(`test/samples/*.js (${Math.round(totalSize / 1e3)} KiB)`));
console.log(`> ${c.bold().green((total / n) + 'ms')}`);
}
}
});
4 changes: 3 additions & 1 deletion chompfile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ node ./node_modules/@swc/cli/bin/swc.js $DEP -o $TARGET --no-swcrc -C jsc.parser
name = 'build:types'
target = 'types/lexer.d.ts'
dep = 'src/lexer.ts'
# `--types node` is explicit: TypeScript 6 no longer auto-includes @types/node
# for a file passed on the command line, so `Buffer` (lexer.ts) would error.
run = '''
tsc --strict --declaration --emitDeclarationOnly --outdir types src/lexer.ts
tsc --strict --declaration --emitDeclarationOnly --types node --outdir types src/lexer.ts
'''

[[task]]
Expand Down
Loading
Loading