-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Destructuring breaks program order #32305
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
Comments
Clarification: |
I haven't combed through the spec to find the exact specification, but it's safe to assume V8 is getting it right and we're not. The last line should be something like var _b = f(), _a = g(), x = _b[_a]; instead of var _a = g(), x = f()[_a]; |
https://tc39.es/ecma262/#sec-runtime-semantics-keyeddestructuringassignmentevaluation This is a bit hard to follow but it looks like the RHS gets evaluated before the LHS meaning |
Also, note that while this is "only downlevel behavior", this still does have significant implications. I am guessing most people aren't targetting such an old version of JS, but |
We intend to fix the bug.
|
@Validark if something is tagged |
Also I would love to know what non-pathological code you're writing that ends up depending on this? |
Actually, @RyanCavanaugh, I am one of the primary developers of a TypeScript-to-Lua program for the Roblox platform. View our project page here. I have been actively trying to think of ways it could break, and I have looked to the TypeScript compiler to see how it compiles certain things and handles certain cases. We still have yet to make it to v1, and there are a few issues on my to-do list, but I am proud of some of the things we have accomplished thus far with the project. It would be cool if you checked out this playground we made! Keep in mind that in roblox-ts, the type checker is law and lying to it is sin: We do type-based emits because that's the most efficient way for our use-case. |
Uh oh!
There was an error while loading. Please reload this page.
I was wondering in what order destructuring is supposed to execute expressions, so I wrote the following test. I tried it in Chrome's V8 and Node, and they both gave me the same answer. I tried it in ts-node/TS, and it gave me a different answer.
TypeScript Version: any
Search Terms: destructuring breaks program order
Code
Expected behavior:
f g
Actual behavior:
g f
Playground Link: https://www.typescriptlang.org/play/?target=1#code/GYVwdgxgLglg9mABMAFASkQbwFCL4iBAZzgBsBTAOlLgHMUAiYBtAbl3wCdyoROlMiAB4AuRAEZEAX3ZTsoSLASJ6GHPgLEyVGvQa0W7Dd179EDIQ0QBDIucuzshMEShZEAbVUBdMUOmIALzI6KxAA
Code 2
This also means that the program state can be contaminated (with bad practices?)
Expected behavior:
0
Actual behavior:
1
Playground Link:
https://www.typescriptlang.org/play/?target=1#code/DYUwLgBAlhC8EAYDcAoFAzArgOwMZigHtsJ0AKASggG8UBIXYgZ0NADphCBzMqC1CIIgAncJmElqiAFwQARAEM5AGggBGWXIBGKiACZNuORAC+EBUxoBtANYgAntOyYAtlpDCAutKZhhUbC4TVBM0RmxfGggrAGoYqG8IAA9TOFJKVHCWdk4eJIogA
Related Issues: #31469
Babel seems to compile it as
f g
as well: https://babeljs.io/repl#?babili=false&browsers=chrome%2068&build=&builtIns=usage&spec=false&loose=false&code_lz=GYVwdgxgLglg9mABMAFASkQbwFCL4iBAZzgBsBTAOlLgHMUAiYBtAbl3wCdyoROlMiAB4AuRAEZEAX3ZTsoSLASJ6GHPgLEyVGvQa0W7Dd179EDIQ1nZCYIlCyIA2qoC6YodMQBeZOlZAA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=false&presets=es2015%2Cflow&prettier=false&targets=&version=7.5.2&externalPlugins=I don't understand what ECMAScript is saying about what it should be, but I believe this is relevant: https://tc39.es/ecma262/#sec-runtime-semantics-destructuringassignmentevaluation
In my opinion, TS's compilation makes the most sense. I don't know who is correct. Maybe TS is correct and everyone else is wrong. Again, I don't understand the ECMAScript document. But I can definitively say that TS differs from everyone else in this way.
The text was updated successfully, but these errors were encountered: