Skip to content

Commit 20b16a2

Browse files
alan-agius4vikerman
authored andcommitted
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.
1 parent e1c616b commit 20b16a2

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export function buildOptimizer(options: BuildOptimizerOptions): TransformJavascr
149149
getTransforms.unshift(getImportTslibTransformer);
150150
}
151151

152-
getTransforms.unshift(getWrapEnumsTransformer);
152+
getTransforms.push(getWrapEnumsTransformer);
153153

154154
const transformJavascriptOpts: TransformJavascriptOptions = {
155155
content: content,

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

+29
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,35 @@ describe('build-optimizer', () => {
9999
expect(tags.oneLine`${boOutput.content}`).toEqual(output);
100100
expect(boOutput.emitSkipped).toEqual(false);
101101
});
102+
103+
it('should not wrap classes which had all static properties dropped in IIFE', () => {
104+
const classDeclaration = tags.oneLine`
105+
import { Injectable } from '@angular/core';
106+
107+
class Platform {
108+
constructor(_doc) {
109+
}
110+
init() {
111+
}
112+
}
113+
`;
114+
const input = tags.oneLine`
115+
${classDeclaration}
116+
117+
Platform.decorators = [
118+
{ type: Injectable }
119+
];
120+
121+
/** @nocollapse */
122+
Platform.ctorParameters = () => [
123+
{ type: undefined, decorators: [{ type: Inject, args: [DOCUMENT] }] }
124+
];
125+
`;
126+
127+
const boOutput = buildOptimizer({ content: input, isSideEffectFree: true });
128+
expect(tags.oneLine`${boOutput.content}`).toEqual(classDeclaration);
129+
expect(boOutput.emitSkipped).toEqual(false);
130+
});
102131
});
103132

104133

0 commit comments

Comments
 (0)