Skip to content

Commit

Permalink
fix: of keyword context in for statement only (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford authored Jun 24, 2024
1 parent fc43bd7 commit 2f48134
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 5 deletions.
5 changes: 3 additions & 2 deletions 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.asm.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const copy = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1 ? function (sr
outBuf16[i++] = (ch & 0xff) << 8 | ch >>> 8;
}
};
const words = 'xportmportlassetaourceromsyncunctionssertvoyiedelecontininstantybreareturdebuggeawaithrwhileforifcatcfinallels';

const words = 'xportmportlassforetaourceromsyncunctionssertvoyiedelecontininstantybreareturdebuggeawaithrwhileifcatcfinallels';

let source, name;
export function parse (_source, _name = '@') {
Expand Down
2 changes: 1 addition & 1 deletion src/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +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) ||
openTokenDepth > 0 && openTokenStack[openTokenDepth - 1].token == AnyParen && *(lastTokenPos) == 'f' && *(lastTokenPos - 1) == 'o' && readPrecedingKeywordn(openTokenStack[openTokenDepth - 1].pos, &FOR[0], 3) ||
lastToken == '}' && (isExpressionTerminator(openTokenStack[openTokenDepth].pos) || openTokenStack[openTokenDepth].token == ClassBrace) ||
isExpressionKeyword(lastTokenPos) ||
lastToken == '/' && lastSlashWasDivision ||
Expand Down
4 changes: 4 additions & 0 deletions test/_unit.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ function assertExportIs(source, actual, expected) {

suite('Lexer', () => {
beforeEach(async () => await init);

test('keyword case again', () => {
parse('if (of / 2) {}');
});

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

0 comments on commit 2f48134

Please sign in to comment.