Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix(compiler-cli): compile dep without Array when useFactory in @Inje… #42994

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

Closed
wants to merge 1 commit into from

Conversation

wszgrcy
Copy link
Contributor

@wszgrcy wszgrcy commented Jul 30, 2021

…ctable

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: #42987

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@google-cla google-cla bot added the cla: yes label Jul 30, 2021
@pullapprove pullapprove bot requested a review from JoostK July 30, 2021 01:56
@wszgrcy wszgrcy force-pushed the wszgrcy-fix-branch branch 2 times, most recently from 7f6c69b to e51b927 Compare July 30, 2021 02:15
…parameters (angular#42987)

if node is not decorator node ,then think maybe is a token node.
@wszgrcy wszgrcy force-pushed the wszgrcy-fix-branch branch from fcd8197 to c5e9d0a Compare July 30, 2021 02:54
@AndrewKushnir AndrewKushnir requested a review from alxhub August 2, 2021 23:54
@AndrewKushnir
Copy link
Contributor

FYI, adding @alxhub to this thread, since he helped with initial investigation, see #42987 (comment).

@AndrewKushnir AndrewKushnir added action: review The PR is still awaiting reviews from at least one requested reviewer area: compiler Issues related to `ngc`, Angular's template compiler target: patch This PR is targeted for the next patch release labels Aug 2, 2021
@ngbot ngbot bot modified the milestone: Backlog Aug 2, 2021
@@ -43,6 +45,46 @@ runInEachFileSystem(() => {
expect(res).not.toContain(jasmine.objectContaining({name: 'ɵprov'}));
});
});

describe('fix', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the compiler we typically have input->output tests, as they are usually better readable and provide a stronger guarantee that programs are compiled as expected. These can either live in packages/compiler-cli/test/ngtsc/ngtsc_spec.ts or as compliance test in packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_di/di. The compliance tests are a bit harder to get started with, but having one for this scenario would make sense to me. Please let me know if you need help with this.

maybeUpdateDecorator(el.expression, reflector, token);
isDecorator = maybeUpdateDecorator(el.expression, reflector, token);
}
if (!isDecorator) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice this logic is greedily accepting the last regular element as token, which seems really loose to me. However the runtime implements the exact same logic, so let's keep as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before I change this part of logic, when want to add parameter decorator, token must use new Inject(xxx) to mark.
Now when the item in array is not parameter decorator(new instance or class), while think this item is a token(token can be any type without parameter decorator)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. It's loose in the sense that e.g. [A, B, C] would be interpreted as C and e.g. [new Optional(), new Inject(B), C] also as C, which should arguably report a diagnostic that something is wrong. As part of this bug fix however I think the current approach is fine, especially since it mirrors the runtime implementation.

Copy link
Contributor Author

@wszgrcy wszgrcy Aug 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the logic is similar with

export function injectArgs(types: (ProviderToken<any>|any[])[]): any[] {
const args: any[] = [];
for (let i = 0; i < types.length; i++) {
const arg = resolveForwardRef(types[i]);
if (Array.isArray(arg)) {
if (arg.length === 0) {
throw new Error('Arguments array must have arguments.');
}
let type: Type<any>|undefined = undefined;
let flags: InjectFlags = InjectFlags.Default;
for (let j = 0; j < arg.length; j++) {
const meta = arg[j];
const flag = getInjectFlag(meta);
if (typeof flag === 'number') {
// Special case when we handle @Inject decorator.
if (flag === DecoratorFlags.Inject) {
type = meta.token;
} else {
flags |= flag;
}
} else {
type = meta;
}
}
args.push(ɵɵinject(type!, flags));
} else {
args.push(ɵɵinject(arg));
}
}
return args;

In line 160,If is not decorator, guess is a token

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct and what I meant by "I think the current approach is fine, especially since it mirrors the runtime implementation."

Still, I would like to see this change tested in integration-like tests as commented here.

@JoostK JoostK added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Aug 19, 2021
@wszgrcy wszgrcy closed this Aug 22, 2021
@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 Sep 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews 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.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.