Skip to content
Merged
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
2 changes: 1 addition & 1 deletion scripts/engine.browser.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion scripts/engine.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2492,7 +2492,7 @@ var init_js_ts = __esm({
NAMED_DEFAULT_RE = /^\s*export\s+default\s+(?:async\s+)?(?:function|class)\s+(?!extends\b)[\w$]+/;
EXPORT_LIST_RE = /export\s*\{([^}]*)\}\s*(from\b)?/g;
CJS_OBJECT_RE = /module\.exports\s*=\s*\{([^}]*)\}/g;
DEFAULT_ID_RE = /(^|\n)\s*export(?:\s+default\s+|\s*=\s*)([A-Za-z_$][\w$]*)\s*;?\s*(?=\n|$)/g;
DEFAULT_ID_RE = /(^|\n)[ \t]*export(?:\s+default\s+|\s*=\s*)([A-Za-z_$][\w$]*)[ \t]*;?[ \t]*(?=\r?\n|$)/g;
jsTs = {
lang: "javascript/typescript",
exts: [".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs"],
Expand Down
4 changes: 3 additions & 1 deletion src/lang/js-ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ function stemOf(rel: string): string {
// so does a declaration file's `export = Foo;`.
const EXPORT_LIST_RE = /export\s*\{([^}]*)\}\s*(from\b)?/g;
const CJS_OBJECT_RE = /module\.exports\s*=\s*\{([^}]*)\}/g;
const DEFAULT_ID_RE = /(^|\n)\s*export(?:\s+default\s+|\s*=\s*)([A-Za-z_$][\w$]*)\s*;?\s*(?=\n|$)/g;
// Horizontal whitespace only around the line: comments are blanked to spaces
// and newlines, so a `\s*` here rescanned every blank line after each one.
const DEFAULT_ID_RE = /(^|\n)[ \t]*export(?:\s+default\s+|\s*=\s*)([A-Za-z_$][\w$]*)[ \t]*;?[ \t]*(?=\r?\n|$)/g;

function applyExportLists(content: string, symbols: CodeSymbol[]): void {
const markExported = (name: string | undefined): void => {
Expand Down
18 changes: 18 additions & 0 deletions tests/regex-tier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,24 @@ describe("TS/JS fallback: generators, ambient declarations, Unicode names", () =
// `export = Emitter` is how a declaration file exports its one value.
expect(syms("d.ts", src).find((s) => s.name === "Emitter")?.exported).toBe(true);
});

it("reads `export default Foo;` and `export = Foo` in a CRLF file", () => {
const exported = (src: string) => syms("d.ts", src).find((s) => s.kind === "class" && s.name === "Foo")?.exported;
expect(exported("class Foo {\r\n}\r\nexport default Foo;\r\n")).toBe(true);
expect(exported("declare class Foo {}\r\nexport = Foo \r\n")).toBe(true);
expect(exported("class Foo {\r\n}\r\nexport default Foo.bar;\r\n")).toBe(false);
});

it("stays linear on a long run of comment lines (previously ~33 s)", () => {
// Comments are blanked to spaces and newlines before the export-list pass,
// and `export default Foo;` used to be matched with a `\s*` that crossed
// them: every line rescanned all the blank lines after it.
const comments = Array.from({ length: 50000 }, (_, i) => `// comment line ${i}`).join("\n");
const src = `class Foo {}\n${comments}\nconst tail = 1;\nexport default Foo;\n`;
const t0 = performance.now();
expect(syms("big.ts", src).find((s) => s.kind === "class" && s.name === "Foo")?.exported).toBe(true);
expect(performance.now() - t0).toBeLessThan(1500);
});
});

describe("doc comments and body spans on the regex tier", () => {
Expand Down
Loading