Repository navigation
js_parser: keep typeof name and the lookups of a body-declared var inside with
#47890
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
5
commits into
main
Choose a base branch
from
robobun/66cda391/with-lookups
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.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7dbe8b8
js_parser: keep `typeof name` and the lookups of a body-declared `var…
robobun f12b745
Merge branch 'main' into robobun/66cda391/with-lookups
robobun 09e6f12
test/aot: mark the program for the error of a call through a with blo…
robobun 31726ee
js_parser: cut the added comments to one line each
robobun 3f73226
ci: retrigger
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
28 changes: 28 additions & 0 deletions
28
test/aot/parallel/language/store-to-a-var-of-a-with-block-after-a-call.cjs
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,28 @@ | ||
| // Inside `with`, the declaration `var result = made` asks the object for `result` when it runs: behind the call that gave the object that property. So it stores in the object, as the assignment does, in a function and at the top of the file. | ||
| function make(object) { | ||
| object.result = "property"; | ||
| return "made"; | ||
| } | ||
| function assign(object) { | ||
| with (object) { | ||
| var result; | ||
| const made = make(object); | ||
| result = made; | ||
| } | ||
| return result; | ||
| } | ||
| function declare(object) { | ||
| with (object) { | ||
| const made = make(object); | ||
| var result = made; | ||
| } | ||
| return result; | ||
| } | ||
| const objects = [{}, {}, {}]; | ||
| console.log(String(assign(objects[0])), objects[0].result); | ||
| console.log(String(declare(objects[1])), objects[1].result); | ||
| with (objects[2]) { | ||
| const made = make(objects[2]); | ||
| var result = made; | ||
| } | ||
| console.log(String(result), objects[2].result); |
19 changes: 19 additions & 0 deletions
19
test/aot/parallel/tree-shaking/unused-typeof-of-a-global-beside-a-direct-eval.cjs
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,19 @@ | ||
| // Beside a direct `eval`, the `typeof` of a name that nothing uses is left out, as without the `eval`: the getter of the global does not run. Only `with` keeps such a `typeof`. The marked call makes the compiler ask what is left of each expression that nothing uses. | ||
| const seen = []; | ||
| Object.defineProperty(globalThis, "watchedGlobal", { | ||
| get() { | ||
| seen.push("getter"); | ||
| return 1; | ||
| }, | ||
| configurable: true, | ||
| }); | ||
| function pure() {} | ||
| /* @__PURE__ */ pure(); | ||
| var yes = 1; | ||
| function run() { | ||
| eval("0"); | ||
| yes && typeof watchedGlobal; | ||
| yes ? typeof watchedGlobal : 0; | ||
| } | ||
| run(); | ||
| console.log("reads:", seen.join(" ")); |
29 changes: 29 additions & 0 deletions
29
test/aot/parallel/tree-shaking/unused-typeof-of-a-name-inside-a-with-block.cjs
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,29 @@ | ||
| // Inside `with` the `typeof` of a name looks the name up in the object, also where nothing uses what it gives: behind `&&`, `||`, `??` and in an arm of `?:`. The marked call makes the compiler ask what is left of each expression that nothing uses. | ||
| const seen = []; | ||
| const scope = new Proxy( | ||
| {}, | ||
| { | ||
| has(target, key) { | ||
| if (/^p[0-9]$/.test(key)) seen.push(key); | ||
| return false; | ||
| }, | ||
| }, | ||
| ); | ||
| function pure() {} | ||
| /* @__PURE__ */ pure(); | ||
| var yes = 1, | ||
| no = 0, | ||
| nothing = null; | ||
| with (scope) { | ||
| yes && typeof p1; | ||
| no || typeof p2; | ||
| nothing ?? typeof p3; | ||
| yes ? typeof p4 : typeof p5; | ||
| { | ||
| var p6; | ||
| yes && typeof p6; | ||
| } | ||
| label: if (no) var p7; | ||
| else yes && typeof p7; | ||
| } | ||
| console.log(seen.join(" ")); |
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.