Skip to content

Commit d67e7ad

Browse files
clydinalan-agius4
authored andcommitted
fix(@angular-devkit/build-angular): ensure native async is downlevelled 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.
1 parent 498d140 commit d67e7ad

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/angular_devkit/build_angular/src/babel/webpack-loader.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ export default custom<AngularCustomOptions>(() => {
6767
if (esTarget !== undefined) {
6868
if (esTarget < ScriptTarget.ES2015) {
6969
customOptions.forceES5 = true;
70-
} else if (esTarget >= ScriptTarget.ES2017) {
70+
} else if (esTarget >= ScriptTarget.ES2017 || /\.[cm]?js$/.test(this.resourcePath)) {
71+
// Application code (TS files) will only contain native async if target is ES2017+.
72+
// However, third-party libraries can regardless of the target option.
73+
// APF packages with code in [f]esm2015 directories is downlevelled to ES2015 and
74+
// will not have native async.
7175
customOptions.forceAsyncTransformation =
7276
!/[\\\/][_f]?esm2015[\\\/]/.test(this.resourcePath) && source.includes('async');
7377
}

0 commit comments

Comments
 (0)