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
fix(ngcc): handle new __spreadArrays
tslib helper
#33617
Conversation
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.
Awesome, thanks! ❤️
Could you please change the commit scope into ngcc, we have it as dedicated scope.
We already have special cases for the `__spread` helper function and with this change we handle the new tslib helper introduced in version 1.10 `__spreadArrays`. For more context see: https://github.com/microsoft/tslib/releases/tag/1.10.0 Fixes: #33614
__spreadArrays
tslib helper__spreadArrays
tslib helper
@JoostK. commit scope changed. Thanks for the review. |
switch (helper) { | ||
case TsHelperFn.Spread: | ||
case TsHelperFn.SpreadArrays: | ||
return evaluateTsSpreadHelper(node, args); |
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.
Should we consider evaluating SpreadArrays
differently, given that this was introduced because the two scenarios emit different downlevelled code?
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.
function spreadArrays() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
}
function spread() {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
}
Our current helper does this:
function evaluateTsSpreadHelper(node: ts.Node, args: ResolvedValueArray): ResolvedValueArray {
const result: ResolvedValueArray = [];
for (const arg of args) {
if (arg instanceof DynamicValue) {
result.push(DynamicValue.fromDynamicInput(node, arg));
} else if (Array.isArray(arg)) {
result.push(...arg);
} else {
result.push(arg);
}
}
return result;
}
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.
I guess that if the arg
is already an array then it has been dealt with elsewhere and any downlevelling of the iterator is irrelevant.
We already have special cases for the `__spread` helper function and with this change we handle the new tslib helper introduced in version 1.10 `__spreadArrays`. For more context see: https://github.com/microsoft/tslib/releases/tag/1.10.0 Fixes: #33614 PR Close #33617
We already have special cases for the `__spread` helper function and with this change we handle the new tslib helper introduced in version 1.10 `__spreadArrays`. For more context see: https://github.com/microsoft/tslib/releases/tag/1.10.0 Fixes: angular#33614 PR Close angular#33617
We already have special cases for the `__spread` helper function and with this change we handle the new tslib helper introduced in version 1.10 `__spreadArrays`. For more context see: https://github.com/microsoft/tslib/releases/tag/1.10.0 Fixes: angular#33614 PR Close angular#33617
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #33614
What is the new behavior?
We already have special cases for the
__spread
helper function and with this change we handle the new tslib helper introduced in version 1.10__spreadArrays
.For more context see: https://github.com/microsoft/tslib/releases/tag/1.10.0
Fixes: #33614
Does this PR introduce a breaking change?
Other information