File tree 2 files changed +22
-1
lines changed
packages/angular_devkit/build_optimizer/src/transforms
2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,13 @@ import * as ts from 'typescript';
11
11
export function testImportTslib ( content : string ) {
12
12
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 ) * \} ; / ;
13
13
14
- return regex . test ( content ) ;
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 ) ;
15
21
}
16
22
17
23
export function getImportTslibTransformer ( ) : ts . TransformerFactory < ts . SourceFile > {
Original file line number Diff line number Diff line change @@ -96,4 +96,19 @@ describe('import-tslib', () => {
96
96
97
97
expect ( tags . oneLine `${ transform ( input ) } ` ) . toEqual ( tags . oneLine `${ output } ` ) ;
98
98
} ) ;
99
+
100
+ it ( 'tests false for files using __webpack_require__' , ( ) => {
101
+ const input = tags . stripIndent `
102
+ function __webpack_require__(moduleId) {
103
+ var __extends = (this && this.__extends) || function (d, b) {
104
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
105
+ function __() { this.constructor = d; }
106
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
107
+ };
108
+ exports.meaning = 42;
109
+ }
110
+ ` ;
111
+
112
+ expect ( testImportTslib ( input ) ) . toBeFalsy ( ) ;
113
+ } ) ;
99
114
} ) ;
You can’t perform that action at this time.
0 commit comments