emit temporary vars at the top of the scope#23956
Conversation
|
is that my fault? |
| if (statementOffset > 0 || some(statements) || some(trailingStatements)) { | ||
| const block = convertToFunctionBody(body, /*multiLine*/ true); | ||
| addRange(statements, block.statements.slice(statementOffset)); | ||
| addRange(statements, trailingStatements); |
There was a problem hiding this comment.
Given the change in position, leadingStatements would be a more appropriate term now.
|
why travis-ci fault again😂 |
rbuckton
left a comment
There was a problem hiding this comment.
@Kingwl this is a good change, but upon further review it seems like its not comprehensive. There are a number of other places where we are still adding hoisted declarations at the end of the scope rather than at the beginning.
If you search for all references to endLexicalEnvironment you'll see a number of additional cases in:
- src/compiler/transformers/es2015.ts
- src/compiler/transformers/es2017.ts
- src/compiler/transformers/esnext.ts
- src/compiler/transformers/generators.ts
- src/compiler/transformers/module.ts
- src/compiler/transformers/system.ts
- src/compiler/transformers/ts.ts
Most (but not all) of these cases look something like this:
addRange(statements, endLexicalEnvironment());To fully resolve these (and consider the linked issue closed), I would recommend adding the following function to src/compiler/core.ts (after the existing addRange function):
export function prependRange<T>(to: T[], from: ReadonlyArray<T> | undefined) {
if (some(from)) to.unshift(...from);
}Then I would replace these specific addRange calls with prependRange.
87903a9 to
b6d06ef
Compare
|
what |
|
Thank you for the contribution! |
Fixes #23732
looks a easy fix
but something need to consider: some temporary variable has swapped and name has changed