-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Conversation
* @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 { |
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.
A couple notes:
- 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). - This file is currently named
predicate.ts
which may or may not be terrible. Suggestions welcome. - 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. - Alternative function name suggestions also welcome.
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'm OK with two entry-points here
- Generally I would recommend the file name matches the main export so:
source_file_may_need_linking.ts
(ormay_need_linking.ts
see 4.) - I think it is a good idea to include the path in the API.
- The current name is a bit of a mouthful. How about just
mayNeedLinking()
or evenneedsLinking()
(ignoring the fact that in some cases running the linker may have no effect).
* @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 { |
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'm OK with two entry-points here
- Generally I would recommend the file name matches the main export so:
source_file_may_need_linking.ts
(ormay_need_linking.ts
see 4.) - I think it is a good idea to include the path in the API.
- The current name is a bit of a mouthful. How about just
mayNeedLinking()
or evenneedsLinking()
(ignoring the fact that in some cases running the linker may have no effect).
packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_linker_selector.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/linker/test/file_linker/predicate_spec.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/test/compliance/linked/linked_compile_spec.ts
Outdated
Show resolved
Hide resolved
b4e5da6
to
96fbf2b
Compare
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.
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. |
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.
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.
96fbf2b
to
94a6765
Compare
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. |
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.