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

[ivy] i18n extraction #22931

Closed
wants to merge 4 commits into from
Closed

[ivy] i18n extraction #22931

wants to merge 4 commits into from

Conversation

ocombe
Copy link
Contributor

@ocombe ocombe commented Mar 22, 2018

PR Type

What kind of change does this PR introduce?

[x] Feature

What is the current behavior?

Cannot run ng-xi18n with ivy

What is the new behavior?

Can use ng-xi18n with ivy

Does this PR introduce a breaking change?

[x] No

@ocombe ocombe added state: blocked action: review The PR is still awaiting reviews from at least one requested reviewer area: i18n target: major This PR is targeted for the next major release labels Mar 22, 2018
@ocombe ocombe requested a review from vicb March 22, 2018 16:41
0) {
return {emitSkipped: true, diagnostics: [], emittedFiles: []};
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've moved this block of code here, because it's duplicated between both render2 and render3, but we can duplicate it if you prefer

@ocombe ocombe changed the title Feat/ivy/ng xi18n [ivy] i18n extraction Mar 22, 2018
@mary-poppins
Copy link

You can preview 6429758 at https://pr22931-6429758.ngbuilds.io/.

@mary-poppins
Copy link

You can preview 319d247 at https://pr22931-319d247.ngbuilds.io/.

@mary-poppins
Copy link

You can preview 7ebf68c at https://pr22931-7ebf68c.ngbuilds.io/.

@mary-poppins
Copy link

You can preview 5346322 at https://pr22931-5346322.ngbuilds.io/.

// TODO(misko): Forgetting to export HelloWorld and not having NgModule fails silently.

@NgModule({declarations: [HelloWorld]})
export class INeedToExistEvenThoughtIAmNotNeeded {
Copy link
Contributor

Choose a reason for hiding this comment

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

EvenThought -> EvenThough?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ahah yeah probably, it's some code that misko wrote :)

it('should not emit js', () => {
writeConfig();
writeSources();
describe('render3', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

move to a separate file

@@ -87,7 +87,7 @@ export class TemplateParser {
constructor(
private _config: CompilerConfig, private _reflector: CompileReflector,
private _exprParser: Parser, private _schemaRegistry: ElementSchemaRegistry,
private _htmlParser: HtmlParser, private _console: Console,
public htmlParser: HtmlParser, private _console: Console,
Copy link
Contributor

Choose a reason for hiding this comment

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

why ?

@ocombe ocombe force-pushed the feat/ivy/ng-xi18n branch 3 times, most recently from 894c5f4 to 1e50c57 Compare March 29, 2018 14:58
@mary-poppins
Copy link

You can preview 0c403ab at https://pr22931-0c403ab.ngbuilds.io/.

@mary-poppins
Copy link

You can preview 894c5f4 at https://pr22931-894c5f4.ngbuilds.io/.

@mary-poppins
Copy link

You can preview 1e50c57 at https://pr22931-1e50c57.ngbuilds.io/.

@ocombe
Copy link
Contributor Author

ocombe commented Mar 29, 2018

@chuckjaz I've moved the extraction from a separate visitor to TemplateDefinitionBuilder as @vicb requested, can you review that and tell me if it's ok, or if you have another idea in mind that would not make me change the definition of OutputContext? Thanks

constructor(
public name: string, public value: string, public meta: I18nMeta,
public sourceSpan: ParseSourceSpan, public valueSpan?: ParseSourceSpan) {}
visit<Result>(visitor: I18nVisitor<Result>): Result { return visitor.visitI18nAttribute(this); }
Copy link
Contributor

Choose a reason for hiding this comment

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

should be visitI18nTextAttribute (I rename the visitITextAttribute in a pending PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll update once that PR gets merged

@@ -70,6 +87,15 @@ export class Element implements Node {
visit<Result>(visitor: Visitor<Result>): Result { return visitor.visitElement(this); }
}

export class I18nElement implements Node {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to see design for that. We probably do not need to duplicate all the props but wrap an Element

}
} else {
for (const node of nodes) {
const newNode = node.visit(visitor);
if (newNode) {
result.push(newNode);
Array.isArray(newNode) ? result.push(...newNode) : result.push(newNode);
Copy link
Contributor

Choose a reason for hiding this comment

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

hum let's see but should not be required

@@ -46,6 +48,14 @@ const CLASS_ATTR = 'class';
// Default selector used by `<ng-content>` if none specified
const DEFAULT_CONTENT_SELECTOR = '*';

/** Name of the i18n attributes **/
Copy link
Contributor

@vicb vicb Apr 26, 2018

Choose a reason for hiding this comment

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

What we discussed about is:
html (string) -> htmlAST (nodes) -> ivyAST (nodes) -> i18IvyAST (nodes).

So this file (htmlAST (nodes) -> ivyAST (nodes)) must remain unchanged

And there should be a new transformer ivyAST (nodes) -> i18IvyAST (nodes).

Edit: thinking more about it, you probably can leave this here. You will need to add tests in r3_template_transform_spec - it's pending in a PR for now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

waiting for that PR to be merged to add new tests

}
const referenceDataSlots = new Map<string, number>();
const hasI18nAttr = element instanceof t.I18nElement;
Copy link
Contributor

@vicb vicb Apr 26, 2018

Choose a reason for hiding this comment

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

NO !
We use the visitor pattern to avoid this kind of hacks.

outputAttrs[name] = attr;
}
visitElement(element: t.Element, elementIndex?: number) {
if (typeof elementIndex === 'undefined') {
Copy link
Contributor

@vicb vicb Apr 26, 2018

Choose a reason for hiding this comment

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

NO!
Remove the extra params - is it not intended to pass extra argument when you like but it is part of the visitor pattern.

One way to refactor would be extract the common code in a common private function but the visitX methods should not be hacked. Make it hard to understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it was causing the tests to fail anyway

@@ -808,6 +751,10 @@ class TemplateDefinitionBuilder implements t.Visitor<void>, LocalResolver {
this.convertPropertyBinding(o.variable(CONTEXT_NAME), text.value));
}

visitI18nBoundText(text: t.BoundText) {
Copy link
Contributor

@vicb vicb Apr 26, 2018

Choose a reason for hiding this comment

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

Please remove until it is designed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The error message is explicit enough I think, it's the next step anyway, we might as well keep it

@mary-poppins
Copy link

You can preview a48e878 at https://pr22931-a48e878.ngbuilds.io/.

@ocombe ocombe mentioned this pull request May 6, 2018
20 tasks
@mary-poppins
Copy link

You can preview c97330e at https://pr22931-c97330e.ngbuilds.io/.

@mary-poppins
Copy link

You can preview 60aa2b1 at https://pr22931-60aa2b1.ngbuilds.io/.

@mary-poppins
Copy link

You can preview 64fb4a6 at https://pr22931-64fb4a6.ngbuilds.io/.

@ocombe ocombe added the action: review The PR is still awaiting reviews from at least one requested reviewer label May 10, 2018
@ngbot
Copy link

ngbot bot commented May 10, 2018

Hi @ocombe! This PR has merge conflicts due to recent upstream merges.
Please help to unblock it by resolving these conflicts. Thanks!

1 similar comment
@ngbot
Copy link

ngbot bot commented May 10, 2018

Hi @ocombe! This PR has merge conflicts due to recent upstream merges.
Please help to unblock it by resolving these conflicts. Thanks!

@mkljczk
Copy link

mkljczk commented Jun 8, 2018

Are you planning to resolve merge conflicts?

@ocombe
Copy link
Contributor Author

ocombe commented Jun 8, 2018

No, I'm closing the PR, @vicb will take this over and recreate the PR with some refactoring.

@ocombe ocombe closed this Jun 8, 2018
@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 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: review The PR is still awaiting reviews from at least one requested reviewer area: i18n cla: yes state: blocked target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants