Skip to content

Commit c2b13a7

Browse files
filipesilvavikerman
authored andcommitted
feat(@angular-devkit/build-optimizer): don't use getImportTslibTransformer
This transformer can cause size regressions when it introduces `tslib` imports across independent chunks. It should be deprecated because tslib adoption has become more ubiquitous. Should also speed up Build Optimizer processing time because there's one less thing to do. Closes #15401 without adding the warning, because some libraries like zone.js should inline the helpers.
1 parent 176698f commit c2b13a7

File tree

3 files changed

+3
-21
lines changed

3 files changed

+3
-21
lines changed

packages/angular_devkit/build_optimizer/src/build-optimizer/build-optimizer.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
TransformJavascriptOutput,
1212
transformJavascript,
1313
} from '../helpers/transform-javascript';
14-
import { getImportTslibTransformer, testImportTslib } from '../transforms/import-tslib';
1514
import { getPrefixClassesTransformer, testPrefixClasses } from '../transforms/prefix-classes';
1615
import { getPrefixFunctionsTransformer } from '../transforms/prefix-functions';
1716
import {
@@ -109,8 +108,6 @@ export function buildOptimizer(options: BuildOptimizerOptions): TransformJavascr
109108
selectedGetScrubFileTransformer = getScrubFileTransformerForCore;
110109
}
111110

112-
const isWebpackBundle = content.indexOf('__webpack_require__') !== -1;
113-
114111
// Determine which transforms to apply.
115112
const getTransforms = [];
116113

@@ -133,22 +130,10 @@ export function buildOptimizer(options: BuildOptimizerOptions): TransformJavascr
133130
typeCheck = true;
134131
}
135132

136-
// tests are not needed for fast path
137-
// usage will be expanded once transformers are verified safe
138-
const ignoreTest = !options.emitSourceMap && !typeCheck;
139-
140133
if (testPrefixClasses(content)) {
141134
getTransforms.unshift(getPrefixClassesTransformer);
142135
}
143136

144-
// This transform introduces import/require() calls, but this won't work properly on libraries
145-
// built with Webpack. These libraries use __webpack_require__() calls instead, which will break
146-
// with a new import that wasn't part of it's original module list.
147-
// We ignore this transform for such libraries.
148-
if (!isWebpackBundle && (ignoreTest || testImportTslib(content))) {
149-
getTransforms.unshift(getImportTslibTransformer);
150-
}
151-
152137
getTransforms.push(getWrapEnumsTransformer);
153138

154139
const transformJavascriptOpts: TransformJavascriptOptions = {

packages/angular_devkit/build_optimizer/src/build-optimizer/build-optimizer_spec.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ describe('build-optimizer', () => {
2222
it('applies scrub-file and prefix-functions to side-effect free modules', () => {
2323
const input = tags.stripIndent`
2424
${imports}
25-
var __extends = (this && this.__extends) || function (d, b) {
26-
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
27-
function __() { this.constructor = d; }
28-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
29-
};
3025
var ChangeDetectionStrategy;
3126
(function (ChangeDetectionStrategy) {
3227
ChangeDetectionStrategy[ChangeDetectionStrategy["OnPush"] = 0] = "OnPush";
@@ -55,7 +50,6 @@ describe('build-optimizer', () => {
5550
var RenderType_MdOption = ɵcrt({ encapsulation: 2, styles: styles_MdOption});
5651
`;
5752
const output = tags.oneLine`
58-
import { __extends } from "tslib";
5953
${imports}
6054
var ChangeDetectionStrategy = /*@__PURE__*/ (function (ChangeDetectionStrategy) {
6155
ChangeDetectionStrategy[ChangeDetectionStrategy["OnPush"] = 0] = "OnPush";

packages/angular_devkit/build_optimizer/src/transforms/import-tslib.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ export function testImportTslib(content: string) {
1717
return regex.test(content);
1818
}
1919

20+
/**
21+
* @deprecated From 0.900.0
22+
*/
2023
export function getImportTslibTransformer(): ts.TransformerFactory<ts.SourceFile> {
2124
return (context: ts.TransformationContext): ts.Transformer<ts.SourceFile> => {
2225

0 commit comments

Comments
 (0)