Repository navigation
js_parser: keep the declaration that names a single-use function or class outside a bundle #36313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
robobun
wants to merge
19
commits into
main
Choose a base branch
from
farm/c47e5de4/fix-inline-anonymous-fn-name
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+341
−62
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
6df0a85
js_parser: don't inline single-use anonymous fn/arrow/class initializers
robobun 986958a
test: reference #20398 and #22770, cover array-literal substitution path
robobun 872aca5
review: shorten NamedEvaluation comment
robobun b2411a3
test: mark FunctionHoistingKeepNames3/4 todo (pre-existing --keep-nam…
robobun d46d625
ci: retrigger
robobun a331541
test: link #36320 from FunctionHoistingKeepNames todo comments
robobun 71a08f7
Merge remote-tracking branch 'origin/main' into farm/c47e5de4/fix-inl…
robobun 25dd207
js_parser: keep the declaration that names a single-use function when…
robobun f487910
test(aot): read block functions once, and update four stored frame co…
robobun 5d93520
Merge remote-tracking branch 'origin/main' into farm/c47e5de4/fix-inl…
robobun 2cca0a3
Sweep what was built around the single-use inliner
robobun 0691f3d
test: leave the printed text of a fold and of a block function to the…
robobun 543dded
Merge remote-tracking branch 'origin/main' into farm/c47e5de4/fix-inl…
robobun 05c34e9
test: show the moved function in bun pm diff from runtime-transpiler.…
robobun b066c2a
aot: name a function that a let or const names and the next return reads
robobun 39810c3
aot: leave the value of a let or const of Bun's own modules in the re…
robobun 4287928
aot: name a returned function in Bun's own modules too, and hold each…
robobun 5bd0d7f
Merge remote-tracking branch 'origin/main' into farm/c47e5de4/fix-inl…
robobun 60e8b13
test: the class of describe(MyClass) has its name under bun test too
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
.../inferred-names/a-function-read-once-behind-type-syntax-takes-the-name-of-its-variable.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // Prints the names of functions, arrows and classes that a `let` or `const` names through type syntax and that are read once: each has the name of its variable. | ||
| type Run = () => void; | ||
| const row = (label: string, run: () => { name: string }) => console.log(label + ":", JSON.stringify(run().name)); | ||
|
|
||
| row("an assertion", () => { const q = (() => {}) as Run; return q; }); | ||
| row("an assertion around a function", () => { const q = function () {} as Run; return q; }); | ||
| row("an annotation", () => { const q: Run = () => {}; return q; }); | ||
| row("satisfies", () => { const q = (() => {}) satisfies Run; return q; }); | ||
| row("a non-null assertion", () => { const q = (() => {})!; return q; }); | ||
| row("an assertion in angle brackets", () => { const q = <Run>(() => {}); return q; }); | ||
| row("an assertion in the return", () => { const q = () => {}; return q as Run; }); | ||
| row("an assertion in a second variable", () => { const a = () => {}; const b = a as Run; return b; }); | ||
| row("an assertion around a class", () => { const Q = class {} as { name: string }; return Q; }); | ||
| row("type parameters", () => { const q = <T,>(x: T) => x; return q; }); |
43 changes: 43 additions & 0 deletions
43
test/aot/parallel/inferred-names/a-function-read-once-takes-the-name-of-its-variable.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // Prints the names of functions, arrows and classes that a `let` or `const` names and that are read once, and of functions that a block declares: each has the name of its variable, also in a stack trace. | ||
| const nameOf = f => f.name; | ||
| const frame = e => e.stack.split("\n")[1].match(/at (?:new )?(\S+) \(/)?.[1]; | ||
| const row = (label, run) => { | ||
| let value; | ||
| try { | ||
| value = run(); | ||
| } catch (error) { | ||
| value = "throws " + error.name; | ||
| } | ||
| console.log(label + ":", JSON.stringify(value)); | ||
| }; | ||
|
|
||
| row("an arrow", () => { const q = () => {}; return q.name; }); | ||
| row("a function", () => { let q = function () {}; return q.name; }); | ||
| row("a class", () => { const Q = class {}; return Q.name; }); | ||
| row("an async arrow", () => { const q = async () => {}; return q.name; }); | ||
| row("a generator", () => { const q = function* () {}; return q.name; }); | ||
| row("an argument", () => { const q = () => {}; return nameOf(q); }); | ||
| row("a frame", () => { const q = () => frame(new Error()); const top = q(); return top; }); | ||
| row("an instance", () => { const Q = class {}; return new Q().constructor.name; }); | ||
| row("a bound function", () => { const q = () => {}; return q.bind(null).name; }); | ||
|
|
||
| // The `return` behind the declaration reads the variable and nothing else. | ||
| row("a returned function", () => nameOf((() => { const q = function () {}; return q; })())); | ||
| row("a returned arrow", () => nameOf((() => { let q = () => {}; return q; })())); | ||
| row("a returned class", () => nameOf((() => { const Q = class {}; return Q; })())); | ||
| row("a returned function behind a second variable", () => nameOf((() => { const a = function () {}; const b = a; return b; })())); | ||
| row("a returned function of a branch", () => nameOf((() => { const q = row ? function () {} : 0; return q; })())); | ||
|
|
||
| // A read in a place that names a function gives no second name. | ||
| row("a property", () => { const q = () => {}; const o = { k: q }; return o.k.name; }); | ||
| row("an assignment", () => { let sink; const q = () => {}; sink = q; return sink.name; }); | ||
| row("a second declaration", () => { const a = () => {}; const b = a; return b.name + b.name; }); | ||
| row("an operand", () => { const q = () => {}; const w = q ?? 1; return w.name + w.name; }); | ||
| row("an element", () => { const f = () => 0; const a = [f]; return a[0].name; }); | ||
|
|
||
| row("a function in a block", () => { { function q() {} return q.name; } }); | ||
| row("a function in an arm of if", () => { if (row) { function q() {} return nameOf(q); } }); | ||
| row("a frame of a function in a block", () => { { function q() { return frame(new Error()); } const top = q(); return top; } }); | ||
| row("a function in a clause", () => { switch (1) { case 1: function q() {} return q.name; } }); | ||
|
|
||
| row("a function with its own name", () => { const q = function named() {}; return q.name; }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.