Skip to content
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

Closed
wants to merge 1 commit into from
Closed

fix(ngcc): handle new __spreadArrays tslib helper #33617

wants to merge 1 commit into from

Conversation

alan-agius4
Copy link
Contributor

@alan-agius4 alan-agius4 commented Nov 6, 2019

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

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?

  • Yes
  • No

Other information

@alan-agius4 alan-agius4 added area: compiler Issues related to `ngc`, Angular's template compiler comp: ngcc labels Nov 6, 2019
@ngbot ngbot bot modified the milestone: needsTriage Nov 6, 2019
@alan-agius4 alan-agius4 added the target: patch This PR is targeted for the next patch release label Nov 6, 2019
@alan-agius4 alan-agius4 marked this pull request as ready for review November 6, 2019 10:00
@alan-agius4 alan-agius4 requested review from a team as code owners November 6, 2019 10:00
Copy link
Member

@JoostK JoostK left a 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
@alan-agius4 alan-agius4 changed the title fix(compiler-cli): handle new __spreadArrays tslib helper fix(ngcc): handle new __spreadArrays tslib helper Nov 6, 2019
@alan-agius4
Copy link
Contributor Author

@JoostK. commit scope changed.

Thanks for the review.

@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker PR action: time-zone labels Nov 6, 2019
switch (helper) {
case TsHelperFn.Spread:
case TsHelperFn.SpreadArrays:
return evaluateTsSpreadHelper(node, args);
Copy link
Member

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?

Copy link
Member

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;
}

Copy link
Member

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.

@alan-agius4 alan-agius4 added the action: presubmit The PR is in need of a google3 presubmit label Nov 6, 2019
@atscott
Copy link
Contributor

atscott commented Nov 6, 2019

presubmit
ivy presubmit

@atscott atscott closed this in d749dd3 Nov 6, 2019
atscott pushed a commit that referenced this pull request Nov 6, 2019
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
@alan-agius4 alan-agius4 deleted the ngcc-spread-arrays branch November 7, 2019 04:57
mohaxspb pushed a commit to mohaxspb/angular that referenced this pull request Nov 7, 2019
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
mohaxspb pushed a commit to mohaxspb/angular that referenced this pull request Nov 7, 2019
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
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Dec 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker action: presubmit The PR is in need of a google3 presubmit area: compiler Issues related to `ngc`, Angular's template compiler cla: yes target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NGCC fails with array spread in module declarations
5 participants