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
[ivy] i18n extraction #22931
Conversation
0) { | ||
return {emitSkipped: true, diagnostics: [], emittedFiles: []}; | ||
} | ||
|
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've moved this block of code here, because it's duplicated between both render2 and render3, but we can duplicate it if you prefer
6429758
to
319d247
Compare
319d247
to
7ebf68c
Compare
You can preview 6429758 at https://pr22931-6429758.ngbuilds.io/. |
7ebf68c
to
5346322
Compare
You can preview 319d247 at https://pr22931-319d247.ngbuilds.io/. |
You can preview 7ebf68c at https://pr22931-7ebf68c.ngbuilds.io/. |
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 { |
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.
EvenThought
-> EvenThough
?
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.
ahah yeah probably, it's some code that misko wrote :)
5346322
to
6a5957d
Compare
it('should not emit js', () => { | ||
writeConfig(); | ||
writeSources(); | ||
describe('render3', () => { |
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.
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, |
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.
why ?
894c5f4
to
1e50c57
Compare
You can preview 0c403ab at https://pr22931-0c403ab.ngbuilds.io/. |
You can preview 894c5f4 at https://pr22931-894c5f4.ngbuilds.io/. |
You can preview 1e50c57 at https://pr22931-1e50c57.ngbuilds.io/. |
e372c30
to
a00377f
Compare
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); } |
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 be visitI18nTextAttribute
(I rename the visitITextAttribute
in a pending PR)
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'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 { |
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'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); |
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.
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 **/ |
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.
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
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.
waiting for that PR to be merged to add new tests
} | ||
const referenceDataSlots = new Map<string, number>(); | ||
const hasI18nAttr = element instanceof t.I18nElement; |
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.
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') { |
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.
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.
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.
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) { |
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.
Please remove until it is designed
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.
The error message is explicit enough I think, it's the next step anyway, we might as well keep it
d91252d
to
a48e878
Compare
You can preview a48e878 at https://pr22931-a48e878.ngbuilds.io/. |
You can preview c97330e at https://pr22931-c97330e.ngbuilds.io/. |
You can preview 60aa2b1 at https://pr22931-60aa2b1.ngbuilds.io/. |
You can preview 64fb4a6 at https://pr22931-64fb4a6.ngbuilds.io/. |
Hi @ocombe! This PR has merge conflicts due to recent upstream merges. |
1 similar comment
Hi @ocombe! This PR has merge conflicts due to recent upstream merges. |
Are you planning to resolve merge conflicts? |
No, I'm closing the PR, @vicb will take this over and recreate the PR with some refactoring. |
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 Type
What kind of change does this PR introduce?
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?