Skip to content

feat(ivy): ngtsc compiles @Component, @Directive, @NgModule#24427

Closed
alxhub wants to merge 1 commit intoangular:masterfrom
alxhub:ngtsc-todo
Closed

feat(ivy): ngtsc compiles @Component, @Directive, @NgModule#24427
alxhub wants to merge 1 commit intoangular:masterfrom
alxhub:ngtsc-todo

Conversation

@alxhub
Copy link
Member

@alxhub alxhub commented Jun 11, 2018

This change supports compilation of components, directives, and modules
within ngtsc. Support is not complete, but is enough to compile and test
//packages/core/test/bundling/todo in full AOT mode. Code size benefits
are not yet achieved as //packages/core itself does not get compiled, and
some decorators (e.g. @input) are not stripped, leading to unwanted code
being retained by the tree-shaker. This will be improved in future commits.

@mary-poppins
Copy link

You can preview 184cdd3 at https://pr24427-184cdd3.ngbuilds.io/.

Copy link
Member

Choose a reason for hiding this comment

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

a precompiled

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

Choose a reason for hiding this comment

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

Just a heads up, makeBindingParser is ridiculously slow due to its construction of DomElementSchemaRegistry. I noticed while profiling the Ivy Todo app in JIT mode where all calls to makeBindingParser summed up to ~100ms. Constructing the schema registry only once reduced that to nil.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hey! Wow, this is good feedback.

makeBindingParser is only temporary - eventually the DomElementSchemaRegistry will (in JIT mode) be something that the user can override, and the BindingParser itself will be rewritten to not depend on Compile*Metadata.

Copy link
Member

Choose a reason for hiding this comment

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

o -> from?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, ty!

@mary-poppins
Copy link

You can preview 76d8c04 at https://pr24427-76d8c04.ngbuilds.io/.

@alxhub alxhub force-pushed the ngtsc-todo branch 2 times, most recently from 42f4206 to 401431f Compare June 12, 2018 02:44
@mary-poppins
Copy link

You can preview 401431f at https://pr24427-401431f.ngbuilds.io/.

@mary-poppins
Copy link

You can preview 19d8b6e at https://pr24427-19d8b6e.ngbuilds.io/.

Copy link
Contributor

Choose a reason for hiding this comment

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

In current implementation, a component would be given ng-component as its selector when not specified, is this being a breaking change?

if (!selector) {
selector = this._schemaRegistry.getDefaultComponentElementName();
}

(Even I don't think this feature should be depend upon)

Copy link
Member Author

Choose a reason for hiding this comment

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

This is selector scope registration, which determines what selectors we look for when parsing a template of another component. If a component/directive doesn't have a selector, then it cannot be in the selector scope because it can never match an element in a template.

Copy link
Contributor

Choose a reason for hiding this comment

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

@alxhub A selector-less component would indeed match <ng-component> in template:

https://stackblitz.com/edit/angular-hxgxhz?file=src%2Fapp%2Fhello.component.ts

Copy link
Member Author

Choose a reason for hiding this comment

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

....

I have no words.

@alxhub alxhub added the target: major This PR is targeted for the next major release label Jun 12, 2018
Copy link
Member

Choose a reason for hiding this comment

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

Forgot to mention yesterday, I find it somewhat suspicious that in the guard above, the original node mapping is not used. I'm not familiar with what TS considers as "original" node so I can't really say if this is bad or not.

  • one more occurrence in registerSelector

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that's a good point. Original nodes are "untransformed" nodes. During the analysis phase (when registerModule and registerSelector) are called, ts.getOriginalNode(node) will always be node, because the original source files are analyzed.

During the emit phase, when TS is running transformers, other transformers (before Angular's) may change the AST, so by the time we go to codegen data for the node, the reference could be different. ts.getOriginalNode walks back from the transformed node to the untransformed one that was seen during our analysis phase.

Here it's not necessary (and is a no-op) as registerModule and registerSelector are always called during the analysis phase, so the nodes we deal with will always be original.

@mary-poppins
Copy link

You can preview 3632542 at https://pr24427-3632542.ngbuilds.io/.

@mary-poppins
Copy link

You can preview b26605d at https://pr24427-b26605d.ngbuilds.io/.

Copy link
Contributor

Choose a reason for hiding this comment

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

debug

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

dbg

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

nigt: expect(reference).toBeAnInstanceOf(ExternalExpr, 'Expected expression reference to be an external (import) expression')

Copy link
Member Author

Choose a reason for hiding this comment

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

That doesn't narrow the type of reference :)

@mary-poppins
Copy link

You can preview e8d5225 at https://pr24427-e8d5225.ngbuilds.io/.

This change supports compilation of components, directives, and modules
within ngtsc. Support is not complete, but is enough to compile and test
//packages/core/test/bundling/todo in full AOT mode. Code size benefits
are not yet achieved as //packages/core itself does not get compiled, and
some decorators (e.g. @input) are not stripped, leading to unwanted code
being retained by the tree-shaker. This will be improved in future commits.
@mary-poppins
Copy link

You can preview 38f210a at https://pr24427-38f210a.ngbuilds.io/.

@alxhub alxhub added the action: merge The PR is ready for merge by the caretaker label Jun 14, 2018
@mhevery mhevery closed this in 27bc7dc Jun 14, 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: merge The PR is ready for merge by the caretaker cla: yes target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants