Repository navigation
[acorn-optimizer] Don't ignore usages in default arguments - #20435
Conversation
709a77c to
e6c105d
Compare
|
Looking at number of issues and custom code related to scope tracking, may I suggest looking at escope or its more active fork eslint-scope? While Acorn takes care of AST, this battle-tested package specifically focuses on taking an AST and augmenting it with scope information, so you can tell from each node whether it's a local binding, global binding, what it resolves to and so on. Here's demo from the original project: https://mazurov.github.io/escope-demo/. I know Emscripten generally tries not to rely on many 3rd-party packages, but given the complexity of scope tracking, especially in JS with all the different kinds of bindings and scopes, I really believe it would be worth it in terms of saved time on individual bugs. |
Sounds reasonable. I don't think anyone would object if you or someone else wants to convert I don't think we need to block this PR on that though. |
Certainly not, it's just that I couldn't help but notice series of custom fixes for scoping issues lately, and figured I'd bring it up. I'll create a separate issue for that. |
e6c105d to
b02d73a
Compare
This includes a unit test and real world test based on a user reported issue where `function run(args = arguments_)` was failing to keep the `arguments_` global alive.
b02d73a to
6535541
Compare
| self.assertContained('error: noExitRuntime cannot be referenced via __deps mechansim', err) | ||
|
|
||
| def test_hello_world_argv(self): | ||
| self.do_runf(test_file('hello_world_argv.c'), 'hello, world! (1)') |
There was a problem hiding this comment.
Did these tests really not pass before? We have lots of existing tests with argv,
$ grep argv test/*.c | wc -l
74
There was a problem hiding this comment.
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 with arguments_ 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.
| const scope = {}; | ||
| scopes.push(scope); | ||
| node.params.forEach((param) => { | ||
| if (param.type === 'RestElement') { |
There was a problem hiding this comment.
Does the test cover this? (what is a rest element?)
There was a problem hiding this comment.
RestElement is f(a, b, ...c) .. here c is RestElement. I didn't write a specific test for it, but we do have at least one library function with this pattern because I hit the assertion without it.
Do you want me to add a specific test for this?
There was a problem hiding this comment.
I see, if the assert was already hit then that sounds enough then.
This includes a unit test and real world test based on a user reported issue where
function run(args = arguments_)was failing to keep thearguments_global alive.