6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
import { custom } from 'babel-loader' ;
9
+ import { ScriptTarget } from 'typescript' ;
9
10
10
11
interface AngularCustomOptions {
11
12
forceES5 : boolean ;
@@ -62,9 +63,11 @@ export default custom<AngularCustomOptions>(() => {
62
63
} ) ;
63
64
64
65
return {
65
- async customOptions ( { forceES5, ...loaderOptions } , { source } ) {
66
- let shouldProcess = forceES5 ;
66
+ async customOptions ( { scriptTarget, ...loaderOptions } , { source } ) {
67
+ // Must process file if plugins are added
68
+ let shouldProcess = Array . isArray ( loaderOptions . plugins ) && loaderOptions . plugins . length > 0 ;
67
69
70
+ // Analyze file for linking
68
71
let shouldLink = false ;
69
72
const { hasLinkerSupport, requiresLinking } = await checkLinking ( this . resourcePath , source ) ;
70
73
if ( requiresLinking && ! hasLinkerSupport ) {
@@ -77,17 +80,27 @@ export default custom<AngularCustomOptions>(() => {
77
80
}
78
81
shouldProcess ||= shouldLink ;
79
82
83
+ // Analyze for ES target processing
84
+ let forceES5 = false ;
85
+ const esTarget = scriptTarget as ScriptTarget ;
86
+ if ( esTarget < ScriptTarget . ES2015 ) {
87
+ forceES5 = true ;
88
+ }
89
+ shouldProcess ||= forceES5 ;
90
+
91
+ // Add provided loader options to default base options
80
92
const options : Record < string , unknown > = {
81
93
...baseOptions ,
82
94
...loaderOptions ,
83
95
} ;
84
96
97
+ // Skip babel processing if no actions are needed
85
98
if ( ! shouldProcess ) {
86
99
// Force the current file to be ignored
87
100
options . ignore = [ ( ) => true ] ;
88
101
}
89
102
90
- return { custom : { forceES5 : ! ! forceES5 , shouldLink } , loader : options } ;
103
+ return { custom : { forceES5, shouldLink } , loader : options } ;
91
104
} ,
92
105
config ( configuration , { customOptions } ) {
93
106
return {
0 commit comments