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

feat(compiler-cli): expose function to allow short-circuiting of linking #40137

Closed
wants to merge 3 commits into from

Conversation

JoostK
Copy link
Member

@JoostK JoostK commented Dec 15, 2020

The linker is implemented using a Babel transform such that Babel needs
to parse and walk a source file to find the declarations that need to be
compiled. If it can be determined that a source file is known not to
contain any declarations the parsing and walking can be skipped as a
performance improvement. This commit adds an exposed function for tools
that integrate the linker to use to allow short-circuiting of the linker
transform.

@JoostK JoostK added area: compiler Issues related to `ngc`, Angular's template compiler target: minor This PR is targeted for the next minor release compiler: linker labels Dec 15, 2020
@JoostK JoostK added this to In progress in ng-linker via automation Dec 15, 2020
@ngbot ngbot bot added this to the Backlog milestone Dec 15, 2020
@google-cla google-cla bot added the cla: yes label Dec 15, 2020
* @param source the source file content as a string.
* @returns whether the source file may contain declarations that need to be linked.
*/
export function sourceFileMayNeedLinking(source: string): boolean {
Copy link
Member Author

@JoostK JoostK Dec 15, 2020

Choose a reason for hiding this comment

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

A couple notes:

  1. This function is currently exposed from @angular/compiler-cli/linker, which prompts integrators to import from both @angular/compiler-cli/linker and @angular/compiler-cli/linker/babel which may not be ideal (the former entry-point is to support linker transform tooling such as the default Babel plugin, not so much integrators of the linker).
  2. This file is currently named predicate.ts which may or may not be terrible. Suggestions welcome.
  3. We may want to take the source file path as an input, just so we could potentially make use of it in the future. This would allow us to skip e.g. node_modules/@angular/core/fesm2015/core.js (if we were to publish that fully compiled to NPM) which does contain ɵɵngDeclareComponent for the JIT functions. Curious what others think here.
  4. Alternative function name suggestions also welcome.

Copy link
Member

Choose a reason for hiding this comment

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

  1. I'm OK with two entry-points here
  2. Generally I would recommend the file name matches the main export so: source_file_may_need_linking.ts (or may_need_linking.ts see 4.)
  3. I think it is a good idea to include the path in the API.
  4. The current name is a bit of a mouthful. How about just mayNeedLinking() or even needsLinking() (ignoring the fact that in some cases running the linker may have no effect).

@JoostK JoostK marked this pull request as ready for review December 15, 2020 22:27
@JoostK JoostK added the action: review The PR is still awaiting reviews from at least one requested reviewer label Dec 15, 2020
@JoostK JoostK moved this from In progress to Review in progress in ng-linker Dec 15, 2020
* @param source the source file content as a string.
* @returns whether the source file may contain declarations that need to be linked.
*/
export function sourceFileMayNeedLinking(source: string): boolean {
Copy link
Member

Choose a reason for hiding this comment

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

  1. I'm OK with two entry-points here
  2. Generally I would recommend the file name matches the main export so: source_file_may_need_linking.ts (or may_need_linking.ts see 4.)
  3. I think it is a good idea to include the path in the API.
  4. The current name is a bit of a mouthful. How about just mayNeedLinking() or even needsLinking() (ignoring the fact that in some cases running the linker may have no effect).

@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 Dec 16, 2020
Copy link
Member

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

LGTM - just a question about the file path param.

@@ -18,9 +18,10 @@ import {declarationFunctions} from './partial_linkers/partial_linker_selector';
* This function may return true even for source files that don't actually contain any declarations
* that need to be compiled.
*
* @param path the path of the source file for which to determine whether linking may be needed.
Copy link
Member

Choose a reason for hiding this comment

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

Is the path absolute or relative (and if so relative to what)?

The linker is implemented using a Babel transform such that Babel needs
to parse and walk a source file to find the declarations that need to be
compiled. If it can be determined that a source file is known not to
contain any declarations the parsing and walking can be skipped as a
performance improvement. This commit adds an exposed function for tools
that integrate the linker to use to allow short-circuiting of the linker
transform.
@JoostK JoostK added action: merge The PR is ready for merge by the caretaker and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Dec 22, 2020
@JoostK JoostK moved this from Review in progress to Reviewer approved in ng-linker Dec 22, 2020
ng-linker automation moved this from Reviewer approved to Done Dec 22, 2020
@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 Jan 22, 2021
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 area: compiler Issues related to `ngc`, Angular's template compiler cla: yes compiler: linker target: minor This PR is targeted for the next minor release
Projects
No open projects
ng-linker
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants