Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: guybedford/es-module-lexer
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.4.1
Choose a base ref
...
head repository: guybedford/es-module-lexer
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1.4.2
Choose a head ref
  • 2 commits
  • 7 files changed
  • 2 contributors

Commits on Mar 19, 2024

  1. fix: handle regexp as default export (#167)

    fpipita authored Mar 19, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    d78f7d4 View commit details
  2. 1.4.2

    guybedford committed Mar 19, 2024
    Copy the full SHA
    f44438c View commit details
Showing with 31 additions and 3 deletions.
  1. +6 −0 lexer.js
  2. +1 −1 lib/lexer.asm.js
  3. +1 −1 lib/lexer.emcc.asm.js
  4. BIN lib/lexer.wasm
  5. +1 −1 package.json
  6. +5 −0 src/lexer.c
  7. +17 −0 test/_unit.cjs
6 changes: 6 additions & 0 deletions lexer.js
Original file line number Diff line number Diff line change
@@ -186,6 +186,7 @@ export function parse (_source, _name) {
// - if a closing brace or paren, what token came before the corresponding
// opening brace or paren (lastOpenTokenIndex)
const lastToken = source.charCodeAt(lastTokenPos);
const lastExport = exports[exports.length - 1];
if (isExpressionPunctuator(lastToken) &&
!(lastToken === 46/*.*/ && (source.charCodeAt(lastTokenPos - 1) >= 48/*0*/ && source.charCodeAt(lastTokenPos - 1) <= 57/*9*/)) &&
!(lastToken === 43/*+*/ && source.charCodeAt(lastTokenPos - 1) === 43/*+*/) && !(lastToken === 45/*-*/ && source.charCodeAt(lastTokenPos - 1) === 45/*-*/) ||
@@ -197,6 +198,11 @@ export function parse (_source, _name) {
regularExpression();
lastSlashWasDivision = false;
}
else if (lastExport && lastTokenPos >= lastExport.s && lastTokenPos <= lastExport.e) {
// export default /some-regexp/
regularExpression();
lastSlashWasDivision = false;
}
else {
lastSlashWasDivision = true;
}
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
@@ -1,6 +1,6 @@
{
"name": "es-module-lexer",
"version": "1.4.1",
"version": "1.4.2",
"description": "Lexes ES modules returning their import/export metadata",
"main": "dist/lexer.cjs",
"module": "dist/lexer.js",
5 changes: 5 additions & 0 deletions src/lexer.c
Original file line number Diff line number Diff line change
@@ -195,6 +195,11 @@ bool parse () {
regularExpression();
lastSlashWasDivision = false;
}
else if (export_write_head != NULL && lastTokenPos >= export_write_head->start && lastTokenPos <= export_write_head->end) {
// export default /some-regexp/
regularExpression();
lastSlashWasDivision = false;
}
else {
// Final check - if the last token was "break x" or "continue x"
while (lastTokenPos > source && !isBrOrWsOrPunctuatorNotDot(*(--lastTokenPos)));
17 changes: 17 additions & 0 deletions test/_unit.cjs
Original file line number Diff line number Diff line change
@@ -252,6 +252,23 @@ suite('Lexer', () => {
`);
});

test('Regexp default export', () => {
const source = `
export default /[\`]/
export default 1/2
export default /* asdf */ 1/2
export default /* asdf */ /regex/
export default
// line comment
/regex/
export default
// line comment
1 / 2
`;
const [, exports] = parse(source);
assert.deepStrictEqual(exports.map(expt => expt.n), ['default', 'default', 'default', 'default', 'default', 'default']);
});

if (!js)
test('Regexp keyword prefixes', () => {
const [imports] = parse(`