Repository navigation
[acorn-optimizer] Don't ignore usages in default arguments #20435
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| /* | ||
| * Copyright 2023 The Emscripten Authors. All rights reserved. | ||
| * Emscripten is available under two separate licenses, the MIT license and the | ||
| * University of Illinois/NCSA Open Source License. Both these licenses can be | ||
| * found in the LICENSE file. | ||
| */ | ||
|
|
||
| #include <stdio.h> | ||
|
|
||
| int main(int argc, char* argv[]) { | ||
| printf("hello, world! (%d)\n", argc); | ||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| var usedAsDefaultArg = 42; | ||
|
|
||
| function g(a, b = usedAsDefaultArg) { | ||
| return a + b + 1; | ||
| } | ||
|
|
||
| Module["g"] = g; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| var usedAsDefaultArg = 42; | ||
| var notUsed = 43; | ||
|
|
||
| // exported | ||
| function g(a, b = usedAsDefaultArg) { | ||
| return a+b+1; | ||
| } | ||
|
|
||
| Module['g'] = g; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -370,12 +370,20 @@ function runJSDCE(ast, aggressive) { | |
| ensureData(scopes[scopes.length - 1], node.id.name).def = 1; | ||
| } | ||
| const scope = {}; | ||
| scopes.push(scope); | ||
| node.params.forEach((param) => { | ||
| if (param.type === 'RestElement') { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the test cover this? (what is a rest element?)
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RestElement is Do you want me to add a specific test for this?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, if the assert was already hit then that sounds enough then. |
||
| param = param.argument; | ||
| } | ||
| if (param.type === 'AssignmentPattern') { | ||
| c(param.right); | ||
| param = param.left; | ||
| } | ||
| assert(param.type === 'Identifier', param.type); | ||
| const name = param.name; | ||
| ensureData(scope, name).def = 1; | ||
| scope[name].param = 1; | ||
| }); | ||
| scopes.push(scope); | ||
| c(node.body); | ||
| // we can ignore self-references, i.e., references to ourselves inside | ||
| // ourselves, for named defined (defun) functions | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did these tests really not pass before? We have lots of existing tests with
argv,There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one passes ok, but the one below will fail. Specifically you have to do
-sENVIRONMENT=web -sSTRICT --closure=1.In particular note the
-sENVIRONMENT=web.. if you include node support the issue witharguments_doesn't show up because node support assigs to this variable.The reason I added two version of this test is that I've often wanted a simple test that just does hello world but includes argv.