fix(@angular-devkit/build-optimizer): don't wrap classes which static properties have been removed

At the moment the `wrap-enums` transfomers is being run prior to `scrub-file` and this is resulting classes which all static properties have been dropped to be wrapped in IIFE.
This commit is contained in:
Alan Agius 2019-07-30 09:19:35 +02:00 committed by vikerman
parent e1c616b0f6
commit 20b16a247a
2 changed files with 30 additions and 1 deletions

View File

@ -149,7 +149,7 @@ export function buildOptimizer(options: BuildOptimizerOptions): TransformJavascr
getTransforms.unshift(getImportTslibTransformer); getTransforms.unshift(getImportTslibTransformer);
} }
getTransforms.unshift(getWrapEnumsTransformer); getTransforms.push(getWrapEnumsTransformer);
const transformJavascriptOpts: TransformJavascriptOptions = { const transformJavascriptOpts: TransformJavascriptOptions = {
content: content, content: content,

View File

@ -99,6 +99,35 @@ describe('build-optimizer', () => {
expect(tags.oneLine`${boOutput.content}`).toEqual(output); expect(tags.oneLine`${boOutput.content}`).toEqual(output);
expect(boOutput.emitSkipped).toEqual(false); expect(boOutput.emitSkipped).toEqual(false);
}); });
it('should not wrap classes which had all static properties dropped in IIFE', () => {
const classDeclaration = tags.oneLine`
import { Injectable } from '@angular/core';
class Platform {
constructor(_doc) {
}
init() {
}
}
`;
const input = tags.oneLine`
${classDeclaration}
Platform.decorators = [
{ type: Injectable }
];
/** @nocollapse */
Platform.ctorParameters = () => [
{ type: undefined, decorators: [{ type: Inject, args: [DOCUMENT] }] }
];
`;
const boOutput = buildOptimizer({ content: input, isSideEffectFree: true });
expect(tags.oneLine`${boOutput.content}`).toEqual(classDeclaration);
expect(boOutput.emitSkipped).toEqual(false);
});
}); });