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 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

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

@petebacondarwin petebacondarwin Dec 16, 2020

  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 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

@petebacondarwin petebacondarwin Dec 16, 2020

  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).

Copy link
Member

@petebacondarwin petebacondarwin left a comment

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

@petebacondarwin petebacondarwin Dec 17, 2020

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

JoostK added 2 commits Dec 22, 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 force-pushed the linker/predicate branch from 96fbf2b to 94a6765 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
twerske added a commit to twerske/angular that referenced this issue Jan 5, 2021
…ing (angular#40137)

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.

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

@angular-automatic-lock-bot angular-automatic-lock-bot bot commented Jan 22, 2021

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.
Projects
No open projects
ng-linker
  
Done
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants