Skip to content

Commit

Permalink
feat(@angular-devkit/build-optimizer): don't use getImportTslibTransf…
Browse files Browse the repository at this point in the history
…ormer

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.
  • Loading branch information
filipesilva authored and vikerman committed Oct 3, 2019
1 parent 176698f commit c2b13a7
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
TransformJavascriptOutput,
transformJavascript,
} from '../helpers/transform-javascript';
import { getImportTslibTransformer, testImportTslib } from '../transforms/import-tslib';
import { getPrefixClassesTransformer, testPrefixClasses } from '../transforms/prefix-classes';
import { getPrefixFunctionsTransformer } from '../transforms/prefix-functions';
import {
Expand Down Expand Up @@ -109,8 +108,6 @@ export function buildOptimizer(options: BuildOptimizerOptions): TransformJavascr
selectedGetScrubFileTransformer = getScrubFileTransformerForCore;
}

const isWebpackBundle = content.indexOf('__webpack_require__') !== -1;

// Determine which transforms to apply.
const getTransforms = [];

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

// tests are not needed for fast path
// usage will be expanded once transformers are verified safe
const ignoreTest = !options.emitSourceMap && !typeCheck;

if (testPrefixClasses(content)) {
getTransforms.unshift(getPrefixClassesTransformer);
}

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

getTransforms.push(getWrapEnumsTransformer);

const transformJavascriptOpts: TransformJavascriptOptions = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ describe('build-optimizer', () => {
it('applies scrub-file and prefix-functions to side-effect free modules', () => {
const input = tags.stripIndent`
${imports}
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var ChangeDetectionStrategy;
(function (ChangeDetectionStrategy) {
ChangeDetectionStrategy[ChangeDetectionStrategy["OnPush"] = 0] = "OnPush";
Expand Down Expand Up @@ -55,7 +50,6 @@ describe('build-optimizer', () => {
var RenderType_MdOption = ɵcrt({ encapsulation: 2, styles: styles_MdOption});
`;
const output = tags.oneLine`
import { __extends } from "tslib";
${imports}
var ChangeDetectionStrategy = /*@__PURE__*/ (function (ChangeDetectionStrategy) {
ChangeDetectionStrategy[ChangeDetectionStrategy["OnPush"] = 0] = "OnPush";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export function testImportTslib(content: string) {
return regex.test(content);
}

/**
* @deprecated From 0.900.0
*/
export function getImportTslibTransformer(): ts.TransformerFactory<ts.SourceFile> {
return (context: ts.TransformationContext): ts.Transformer<ts.SourceFile> => {

Expand Down

0 comments on commit c2b13a7

Please sign in to comment.