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.5.2
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.5.3
Choose a head ref
  • 2 commits
  • 6 files changed
  • 1 contributor

Commits on May 17, 2024

  1. fix: handling of of keyword (#174)

    guybedford authored May 17, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    4c1fac8 View commit details
  2. 1.5.3

    guybedford committed May 17, 2024
    Copy the full SHA
    fc43bd7 View commit details
Showing with 15 additions and 15 deletions.
  1. +1 −1 lib/lexer.asm.js
  2. +1 −1 lib/lexer.emcc.asm.js
  3. BIN lib/lexer.wasm
  4. +1 −1 package.json
  5. +3 −7 src/lexer.c
  6. +9 −5 test/_unit.cjs
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.5.2",
"version": "1.5.3",
"description": "Lexes ES modules returning their import/export metadata",
"main": "dist/lexer.cjs",
"module": "dist/lexer.js",
10 changes: 3 additions & 7 deletions src/lexer.c
Original file line number Diff line number Diff line change
@@ -189,6 +189,7 @@ bool parse () {
!(lastToken == '.' && (*(lastTokenPos - 1) >= '0' && *(lastTokenPos - 1) <= '9')) &&
!(lastToken == '+' && *(lastTokenPos - 1) == '+') && !(lastToken == '-' && *(lastTokenPos - 1) == '-') ||
lastToken == ')' && isParenKeyword(openTokenStack[openTokenDepth].pos) ||
openTokenDepth > 0 && openTokenStack[openTokenDepth - 1].token == AnyParen && *(lastTokenPos) == 'f' && *(lastTokenPos - 1) == 'o' && isParenKeyword(openTokenStack[openTokenDepth - 1].pos) ||
lastToken == '}' && (isExpressionTerminator(openTokenStack[openTokenDepth].pos) || openTokenStack[openTokenDepth].token == ClassBrace) ||
isExpressionKeyword(lastTokenPos) ||
lastToken == '/' && lastSlashWasDivision ||
@@ -871,7 +872,7 @@ bool readPrecedingKeywordn (char16_t* pos, const char16_t* compare, size_t n) {
}

// Detects one of case, debugger, delete, do, else, in, instanceof, new,
// return, throw, typeof, void, yield ,await, of
// return, throw, typeof, void, yield ,await
bool isExpressionKeyword (char16_t* pos) {
switch (*pos) {
case 'd':
@@ -908,12 +909,7 @@ bool isExpressionKeyword (char16_t* pos) {
return false;
}
case 'f':
if (*(pos - 1) != 'o')
return false;
// of
if (pos -2 == source || isBrOrWsOrPunctuatorNotDot(*(pos - 2)))
return true;
if (*(pos - 2) != 'e')
if (*(pos - 1) != 'o' || *(pos - 2) != 'e')
return false;
switch (*(pos - 3)) {
case 'c':
14 changes: 9 additions & 5 deletions test/_unit.cjs
Original file line number Diff line number Diff line change
@@ -39,6 +39,15 @@ function assertExportIs(source, actual, expected) {
suite('Lexer', () => {
beforeEach(async () => await init);

test(`Regex case`, () => {
const source = `for(let t of/[0-9]+/g.exec(e)){}`
parse(source);
});

test('keyword case', () => {
parse('const of=1;console.log(1+of/1)');
});

test('import types', () => {
const input = `
// dynamic
@@ -61,11 +70,6 @@ suite('Lexer', () => {
assert.strictEqual(imports[5].t, 3);
});

test(`Regex case`, () => {
const source = `for(let t of/[0-9]+/g.exec(e)){}`
parse(source);
});

test(`Source phase imports`, () => {
const source = `
import source