File tree Expand file tree Collapse file tree 2 files changed +17
-10
lines changed
packages/angular_devkit/build_optimizer/src Expand file tree Collapse file tree 2 files changed +17
-10
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,16 @@ export function buildOptimizer(options: BuildOptimizerOptions): TransformJavascr
8787 content = readFileSync ( inputFilePath as string , 'UTF-8' ) ;
8888 }
8989
90+ if ( ! content ) {
91+ return {
92+ content : null ,
93+ sourceMap : null ,
94+ emitSkipped : true ,
95+ } ;
96+ }
97+
98+ const isWebpackBundle = content . indexOf ( '__webpack_require__' ) !== - 1 ;
99+
90100 // Determine which transforms to apply.
91101 const getTransforms = [ ] ;
92102
@@ -119,7 +129,11 @@ export function buildOptimizer(options: BuildOptimizerOptions): TransformJavascr
119129 getTransforms . unshift ( getPrefixClassesTransformer ) ;
120130 }
121131
122- if ( ignoreTest || testImportTslib ( content ) ) {
132+ // This transform introduces import/require() calls, but this won't work properly on libraries
133+ // built with Webpack. These libraries use __webpack_require__() calls instead, which will break
134+ // with a new import that wasn't part of it's original module list.
135+ // We ignore this transform for such libraries.
136+ if ( ! isWebpackBundle && ( ignoreTest || testImportTslib ( content ) ) ) {
123137 getTransforms . unshift ( getImportTslibTransformer ) ;
124138 }
125139
Original file line number Diff line number Diff line change @@ -11,13 +11,7 @@ import * as ts from 'typescript';
1111export function testImportTslib ( content : string ) {
1212 const regex = / v a r ( _ _ e x t e n d s | _ _ d e c o r a t e | _ _ m e t a d a t a | _ _ p a r a m ) = \( .* \r ? \n ( .* \r ? \n ) * \} ; / ;
1313
14- // This transform introduces import/require() calls, but this won't work properly on libraries
15- // built with Webpack. These libraries use __webpack_require__() calls instead, which will break
16- // with a new import that wasn't part of it's original module list.
17- // We ignore this transform for such libraries.
18- const webpackRequireRegex = / _ _ w e b p a c k _ r e q u i r e _ _ / ;
19-
20- return regex . test ( content ) && ! webpackRequireRegex . test ( content ) ;
14+ return regex . test ( content ) ;
2115}
2216
2317export function getImportTslibTransformer ( ) : ts . TransformerFactory < ts . SourceFile > {
@@ -35,8 +29,7 @@ export function getImportTslibTransformer(): ts.TransformerFactory<ts.SourceFile
3529 const declarations = node . declarationList . declarations ;
3630
3731 if ( declarations . length === 1 && ts . isIdentifier ( declarations [ 0 ] . name ) ) {
38- // NOTE: the replace is unnecessary with TS2.5+; tests currently run with TS2.4
39- const name = ( declarations [ 0 ] . name as ts . Identifier ) . text . replace ( / ^ _ _ _ / , '__' ) ;
32+ const name = ( declarations [ 0 ] . name as ts . Identifier ) . text ;
4033
4134 if ( isHelperName ( name ) ) {
4235 // TODO: maybe add a few more checks, like checking the first part of the assignment.
You can’t perform that action at this time.
0 commit comments