Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): ensure native async is downlevell…
Browse files Browse the repository at this point in the history
…ed in third-party libraries

Application code (TS files) will only contain native async if the TypeScript configuration target is ES2017+. However, third-party libraries can contain native async regardless of the target option. To address these third-party libraries, all non-application files need to be analyzed to determine if they must have native async downlevelled. The analysis is first resource path based and then a string match search for the async keyword. This approach has the potential for rare false positives (for example, the word async in a comment) but the outcome would only be a small amount of additional processing for that one file due to the no-op transformation. This is in contrast to a more exact method covering those rare false positives but that would require a more expensive analysis operation on every file and result in longer overall build times.
  • Loading branch information
clydin authored and alan-agius4 committed Aug 11, 2021
1 parent c846b67 commit 22e0208
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ export default custom<AngularCustomOptions>(() => {
if (esTarget < ScriptTarget.ES2015) {
// TypeScript files will have already been downlevelled
customOptions.forceES5 = !/\.tsx?$/.test(this.resourcePath);
} else if (esTarget >= ScriptTarget.ES2017) {
} else if (esTarget >= ScriptTarget.ES2017 || /\.[cm]?js$/.test(this.resourcePath)) {
// Application code (TS files) will only contain native async if target is ES2017+.
// However, third-party libraries can regardless of the target option.
// APF packages with code in [f]esm2015 directories is downlevelled to ES2015 and
// will not have native async.
customOptions.forceAsyncTransformation =
!/[\\\/][_f]?esm2015[\\\/]/.test(this.resourcePath) && source.includes('async');
}
Expand Down

0 comments on commit 22e0208

Please sign in to comment.