Skip to content

Commit

Permalink
fix: import type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Apr 27, 2024
1 parent c565b83 commit 5a88d9f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
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.
4 changes: 2 additions & 2 deletions src/lexer.h
Expand Up @@ -126,11 +126,11 @@ void addImport (const char16_t* statement_start, const char16_t* start, const ch
}
else if (dynamic == STANDARD_IMPORT) {
import->statement_end = end + 1;
import->import_ty = Dynamic;
import->import_ty = Static;
}
else {
import->statement_end = 0;
import->import_ty = Static;
import->import_ty = Dynamic;
}
import->start = start;
import->end = end;
Expand Down
27 changes: 27 additions & 0 deletions test/_unit.cjs
Expand Up @@ -39,6 +39,33 @@ function assertExportIs(source, actual, expected) {
suite('Lexer', () => {
beforeEach(async () => await init);

test('import types', () => {
const input = `
// dynamic
const { a } = await import('a');
const { b } = await import.source('b');
// static
import b from 'b';
import { c } from 'c';
import source z from 'z';
// meta
import.meta.url
`;

const [imports] = parse(input);
assert.strictEqual(imports[0].t, 2);
assert.strictEqual(imports[1].t, 5);
assert.strictEqual(imports[2].t, 1);
assert.strictEqual(imports[3].t, 1);
assert.strictEqual(imports[4].t, 4);
assert.strictEqual(imports[5].t, 3);
});

test('Another regex case', () => {
parse(`import{readFileSync as e}from"fs";import{join as t}from"path";import o from"#db";import r from"#core/error_logger";let l={};let i={};function setFile(e){l=e}function autoSetFile(){try{let r=JSON.parse(e(t(o.theme.dirs.extra,"i18n.default.json")).toString());i=r}catch(e){r.couldNotLoadI18nDefault()}{let i=t(o.theme.dirs.extra,"i18n."+o.language+".json");try{let t=JSON.parse(e(i).toString());l=t}catch(e){r.couldNotLoadI18nFile()}}}function i18n(e){let t;if(/[0-9]/.test(e)){let o=[];for(let t of/[0-9]+/g.exec(e)){e=e.replace(t,"{NUMBER}");o.push(t)}t=l[e]??i[e]??e;for(let e of o)t=t.replace("{NUMBER}",e)}else t=l[e]??i[e]??e;return t}var a={i18n:i18n,setFile:setFile,autoSetFile:autoSetFile};export{a as default};
//# sourceMappingURL=i18n.js.map`);
});

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

0 comments on commit 5a88d9f

Please sign in to comment.