X Tutup
The Wayback Machine - https://web.archive.org/web/20220320201338/https://github.com/angular/angular/pull/39408
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(compiler): treat i18n attributes with no bindings as static attributes #39408

Closed
wants to merge 5 commits into from

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Oct 24, 2020

Currently i18n attributes are treated the same no matter if they have data bindings or not. This both generates more code since they have to go through the ɵɵi18nAttributes instruction and prevents the translated attributes from being injected using the @Attribute decorator.

These changes makes it so that static translated attributes are treated in the same way as regular static attributes and all other i18n attributes go through the old code path.

Fixes #38231.

…butes

Currently `i18n` attributes are treated the same no matter if they have data bindings or not. This
both generates more code since they have to go through the `ɵɵi18nAttributes` instruction and
prevents the translated attributes from being injected using the `@Attribute` decorator.

These changes makes it so that static translated attributes are treated in the same way as regular
static attributes and all other `i18n` attributes go through the old code path.

Fixes angular#38231.
@google-cla google-cla bot added the cla: yes label Oct 24, 2020
@ngbot ngbot bot added this to the needsTriage milestone Oct 24, 2020
@ngbot ngbot bot added this to the needsTriage milestone Oct 24, 2020
@ngbot ngbot bot added this to the needsTriage milestone Oct 24, 2020
@ngbot ngbot bot added this to the needsTriage milestone Oct 24, 2020
@crisbeto crisbeto marked this pull request as ready for review Oct 24, 2020
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Looks great, thanks for this PR @crisbeto 👍

I think we can also simplify the i18nAttributes instruction by removing the code that takes care of the static value processing here. There might be even more refactoring in that function that we can look at: we may not need the hasBinding check (since we know that it's a dynamic value, this we'd have bindings) and ICU-related logic there (we do not support ICUs in attrs atm).

packages/compiler/src/render3/view/template.ts Outdated Show resolved Hide resolved
packages/core/test/acceptance/i18n_spec.ts Show resolved Hide resolved
@crisbeto crisbeto force-pushed the 38231/static-i18n-attrs branch from 79c6211 to 61bddae Compare Oct 25, 2020
Copy link
Member Author

@crisbeto crisbeto left a comment

Thanks for the feedback @AndrewKushnir, all of it should be addressed now. Also something I was thinking about while addressing the feedback: would it make sense to rename the i18nAttribute instruction to something like i18nDynamicAttribute to be more explicit about its uses? It doesn't have to happen as a part of this PR.

packages/core/src/render3/i18n/i18n_parse.ts Show resolved Hide resolved
packages/core/test/render3/i18n/i18n_spec.ts Show resolved Hide resolved
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Just left a couple comments, please see below.

Also something I was thinking about while addressing the feedback: would it make sense to rename the i18nAttribute instruction to something like i18nDynamicAttribute to be more explicit about its uses?

Yeah, that makes sense, let's have a followup PR with the rename (once this PR lands). The "dynamic" sounds good, I was also thinking if we could call it "bound" (i.e. i18nBoundAttributes), which might be more aligned with the compiler terminology (where we have t.BoundAttribute).

packages/compiler/src/render3/view/i18n/util.ts Outdated Show resolved Hide resolved
packages/core/src/render3/i18n/i18n_parse.ts Outdated Show resolved Hide resolved
packages/core/src/render3/i18n/i18n_parse.ts Outdated Show resolved Hide resolved
@petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Oct 26, 2020

+1 for i18nBoundAttributes

Copy link
Member

@petebacondarwin petebacondarwin left a comment

Nice bit of refactoring. I agree with @AndrewKushnir's comments and added a few more.
Thanks for jumping on this @crisbeto!

packages/compiler/src/render3/view/i18n/util.ts Outdated Show resolved Hide resolved
packages/compiler/src/util.ts Outdated Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Outdated Show resolved Hide resolved
packages/core/test/acceptance/i18n_spec.ts Outdated Show resolved Hide resolved
packages/core/src/render3/i18n/i18n_parse.ts Outdated Show resolved Hide resolved
packages/core/src/render3/i18n/i18n_parse.ts Outdated Show resolved Hide resolved
@crisbeto
Copy link
Member Author

@crisbeto crisbeto commented Oct 26, 2020

I've addressed the latest set of feedback.

Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Thanks for the updates @crisbeto 👍

It's really great to see how the i18nAttributesFirstPass function is now simplified!

packages/core/src/render3/i18n/i18n_parse.ts Outdated Show resolved Hide resolved
packages/core/src/render3/i18n/i18n_parse.ts Show resolved Hide resolved
packages/core/src/render3/i18n/i18n_parse.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

LGTM, thanks @crisbeto 👍

@AndrewKushnir AndrewKushnir requested a review from mhevery Oct 26, 2020
Copy link
Member

@petebacondarwin petebacondarwin left a comment

Nice!

@AndrewKushnir AndrewKushnir removed the request for review from mhevery Oct 27, 2020
@AndrewKushnir
Copy link
Contributor

@AndrewKushnir AndrewKushnir commented Oct 27, 2020

@AndrewKushnir
Copy link
Contributor

@AndrewKushnir AndrewKushnir commented Oct 27, 2020

@alxhub
Copy link
Contributor

@alxhub alxhub commented Oct 27, 2020

Merging to RC for now - please open a separate patch PR if this needs to merge to the patch branch.

alxhub added a commit that referenced this issue Oct 27, 2020
…butes (#39408)

Currently `i18n` attributes are treated the same no matter if they have data bindings or not. This
both generates more code since they have to go through the `ɵɵi18nAttributes` instruction and
prevents the translated attributes from being injected using the `@Attribute` decorator.

These changes makes it so that static translated attributes are treated in the same way as regular
static attributes and all other `i18n` attributes go through the old code path.

Fixes #38231.

PR Close #39408
crisbeto added a commit to crisbeto/angular that referenced this issue Oct 29, 2020
This is follow-up from [an earlier discussion](angular#39408 (comment)).
After some testing, it looks like the type of `Element.attributes` was correct in specifying that it
only has `TextAttribute` instances. This means that the extra checks that filter out `BoundAttribute`
instances from the array isn't necessary. There is another loop a bit further down that actually
extracts the bound i18n attributes.
josephperrott added a commit that referenced this issue Oct 29, 2020
This is follow-up from [an earlier discussion](#39408 (comment)).
After some testing, it looks like the type of `Element.attributes` was correct in specifying that it
only has `TextAttribute` instances. This means that the extra checks that filter out `BoundAttribute`
instances from the array isn't necessary. There is another loop a bit further down that actually
extracts the bound i18n attributes.

PR Close #39498
josephperrott added a commit that referenced this issue Oct 29, 2020
This is follow-up from [an earlier discussion](#39408 (comment)).
After some testing, it looks like the type of `Element.attributes` was correct in specifying that it
only has `TextAttribute` instances. This means that the extra checks that filter out `BoundAttribute`
instances from the array isn't necessary. There is another loop a bit further down that actually
extracts the bound i18n attributes.

PR Close #39498
@angular-automatic-lock-bot
Copy link

@angular-automatic-lock-bot angular-automatic-lock-bot bot commented Nov 27, 2020

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 Nov 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

4 participants
X Tutup