Skip to content
This repository has been archived by the owner on Apr 9, 2022. It is now read-only.

Commit

Permalink
feat(@angular-devkit/build-optimizer): remove angular es5 whitelist
Browse files Browse the repository at this point in the history
Partially address #816

Fix #523
  • Loading branch information
filipesilva authored and hansl committed May 30, 2018
1 parent 1664f4b commit ae72a14
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,16 @@ const whitelistedAngularModules = [
/[\\/]node_modules[\\/]@angular[\\/]cdk[\\/]/,
];

// TODO: this code is very fragile and should be reworked.
// See: https://github.com/angular/devkit/issues/523
const es5AngularModules = [
// Angular 4 packaging format has .es5.js as the extension.
/\.es5\.js$/, // Angular 4
// Angular 5 has esm5 folders.
// Angular 6 has fesm5 folders.
/[\\/]node_modules[\\/]@angular[\\/][^\\/]+[\\/]f?esm5[\\/]/,
// All Angular versions have UMD with es5.
/\.umd\.js$/,
];

// Factories created by AOT are known to have no side effects and contain es5 code.
// Factories created by AOT are known to have no side effects.
// In Angular 2/4 the file path for factories can be `.ts`, but in Angular 5 it is `.js`.
const ngFactories = [
/\.ngfactory\.[jt]s/,
/\.ngstyle\.[jt]s/,
];

function isKnownSideEffectFree(filePath: string) {
return ngFactories.some((re) => re.test(filePath)) || (
whitelistedAngularModules.some((re) => re.test(filePath))
&& es5AngularModules.some((re) => re.test(filePath))
);
return ngFactories.some((re) => re.test(filePath)) ||
whitelistedAngularModules.some((re) => re.test(filePath));
}

export interface BuildOptimizerOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,24 +89,6 @@ describe('build-optimizer', () => {
});
});

it('supports es2015 modules', () => {
// prefix-functions would add PURE_IMPORTS_START and PURE to the super call.
// This test ensures it isn't applied to es2015 modules.
const output = tags.oneLine`
import { Injectable } from '@angular/core';
class Clazz extends BaseClazz { constructor(e) { super(e); } }
`;
const input = tags.stripIndent`
${output}
Clazz.ctorParameters = () => [ { type: Injectable } ];
`;

const inputFilePath = '/node_modules/@angular/core/@angular/core.js';
const boOutput = buildOptimizer({ content: input, inputFilePath });
expect(tags.oneLine`${boOutput.content}`).toEqual(output);
expect(boOutput.emitSkipped).toEqual(false);
});

it('supports flagging module as side-effect free', () => {
const output = tags.oneLine`
/** PURE_IMPORTS_START PURE_IMPORTS_END */
Expand Down

0 comments on commit ae72a14

Please sign in to comment.