Skip to content

Commit 870adbc

Browse files
clydinKeen Yee Liau
authored and
Keen Yee Liau
committed
fix(@angular-devkit/build-optimizer): wrap classes with a let variable
Classes can technically be re-assigned. By using a let variable this behavior will be retained and prevent potential runtime errors. Fixes #14930
1 parent 67cd378 commit 870adbc

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

packages/angular_devkit/build_optimizer/src/transforms/wrap-enums.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ function createWrappedClass(
659659
ts.createVariableDeclarationList([
660660
ts.createVariableDeclaration(name, undefined, pureIife),
661661
],
662-
ts.NodeFlags.Const,
662+
ts.NodeFlags.Let,
663663
),
664664
));
665665

packages/angular_devkit/build_optimizer/src/transforms/wrap-enums_spec.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ describe('wrap enums and classes transformer', () => {
3939
`;
4040

4141
const output = tags.stripIndent`
42-
const CustomComponentEffects = /*@__PURE__*/ (() => {
42+
let CustomComponentEffects = /*@__PURE__*/ (() => {
4343
${defaultClass.replace('export default ', '')}
4444
4545
return CustomComponentEffects;
4646
})();
4747
export default CustomComponentEffects;
4848
49-
const CustomComponent = /*@__PURE__*/ (() => {
49+
let CustomComponent = /*@__PURE__*/ (() => {
5050
${namedClass}
5151
5252
return CustomComponent;
@@ -78,7 +78,7 @@ describe('wrap enums and classes transformer', () => {
7878
`;
7979

8080
const output = tags.stripIndent`
81-
const CustomComponentEffects = /*@__PURE__*/ (() => {
81+
let CustomComponentEffects = /*@__PURE__*/ (() => {
8282
${input}
8383
8484
return CustomComponentEffects;
@@ -104,7 +104,7 @@ describe('wrap enums and classes transformer', () => {
104104
`;
105105

106106
const output = tags.stripIndent`
107-
const ApplicationModule = /*@__PURE__*/ (() => {
107+
let ApplicationModule = /*@__PURE__*/ (() => {
108108
${input}
109109
110110
return ApplicationModule;
@@ -131,7 +131,7 @@ describe('wrap enums and classes transformer', () => {
131131
`;
132132

133133
const output = tags.stripIndent`
134-
const CommonModule = /*@__PURE__*/ (() => {
134+
let CommonModule = /*@__PURE__*/ (() => {
135135
${input}
136136
137137
return CommonModule;
@@ -154,7 +154,7 @@ describe('wrap enums and classes transformer', () => {
154154
`;
155155

156156
const output = tags.stripIndent`
157-
export const Foo = /*@__PURE__*/ (() => {
157+
export let Foo = /*@__PURE__*/ (() => {
158158
${input.replace('export ', '')}
159159
160160
return Foo;
@@ -170,7 +170,7 @@ describe('wrap enums and classes transformer', () => {
170170
TemplateRef.__NG_ELEMENT_ID__ = () => SWITCH_TEMPLATE_REF_FACTORY(TemplateRef, ElementRef);
171171
`;
172172
const output = tags.stripIndent`
173-
export const TemplateRef = /*@__PURE__*/ (() => {
173+
export let TemplateRef = /*@__PURE__*/ (() => {
174174
class TemplateRef { }
175175
TemplateRef.__NG_ELEMENT_ID__ = () => SWITCH_TEMPLATE_REF_FACTORY(TemplateRef, ElementRef);
176176
return TemplateRef;
@@ -187,7 +187,7 @@ describe('wrap enums and classes transformer', () => {
187187
TemplateRef.somethingElse = true;
188188
`;
189189
const output = tags.stripIndent`
190-
export const TemplateRef = /*@__PURE__*/ (() => {
190+
export let TemplateRef = /*@__PURE__*/ (() => {
191191
class TemplateRef {
192192
}
193193
TemplateRef.__NG_ELEMENT_ID__ = () => SWITCH_TEMPLATE_REF_FACTORY(TemplateRef, ElementRef);
@@ -231,14 +231,14 @@ describe('wrap enums and classes transformer', () => {
231231
`;
232232

233233
const output = tags.stripIndent`
234-
const Foo = /*@__PURE__*/ (() => {
234+
let Foo = /*@__PURE__*/ (() => {
235235
${defaultClass.replace('export default Foo;', '')}
236236
237237
return Foo;
238238
})();
239239
export default Foo;
240240
241-
const AggregateColumnDirective = /*@__PURE__*/ (() => {
241+
let AggregateColumnDirective = /*@__PURE__*/ (() => {
242242
${namedClass}
243243
244244
return AggregateColumnDirective;
@@ -261,7 +261,7 @@ describe('wrap enums and classes transformer', () => {
261261
`;
262262

263263
const output = tags.stripIndent`
264-
const AggregateColumnDirective = /*@__PURE__*/ (() => {
264+
let AggregateColumnDirective = /*@__PURE__*/ (() => {
265265
${input}
266266
267267
return AggregateColumnDirective;
@@ -293,7 +293,7 @@ describe('wrap enums and classes transformer', () => {
293293

294294
const output = tags.stripIndent`
295295
var FooDirective_1;
296-
const FooDirective = /*@__PURE__*/ (() => {
296+
let FooDirective = /*@__PURE__*/ (() => {
297297
${classContent}
298298
299299
return FooDirective;
@@ -316,7 +316,7 @@ describe('wrap enums and classes transformer', () => {
316316
`;
317317

318318
const output = tags.stripIndent`
319-
const ChipList = /*@__PURE__*/ (() => {
319+
let ChipList = /*@__PURE__*/ (() => {
320320
${input}
321321
return ChipList;
322322
})();`;
@@ -349,7 +349,7 @@ describe('wrap enums and classes transformer', () => {
349349
ChipList = __decorate$4([NotifyPropertyChanges], ChipList);`;
350350

351351
const output = tags.stripIndent`
352-
const ChipList = /*@__PURE__*/ (() => {
352+
let ChipList = /*@__PURE__*/ (() => {
353353
${input}
354354
return ChipList;
355355
})();`;
@@ -394,7 +394,7 @@ describe('wrap enums and classes transformer', () => {
394394
const output = tags.stripIndent`
395395
const minutesMilliSeconds = 60000;
396396
397-
const AggregateColumnDirective = /*@__PURE__*/ (() => {
397+
let AggregateColumnDirective = /*@__PURE__*/ (() => {
398398
${firstClass}
399399
400400
return AggregateColumnDirective;
@@ -403,7 +403,7 @@ describe('wrap enums and classes transformer', () => {
403403
const CSS = 'e-css';
404404
const PRIMARY = 'e-primary';
405405
406-
const ChipList = /*@__PURE__*/ (() => {
406+
let ChipList = /*@__PURE__*/ (() => {
407407
${secondClass}
408408
409409
return ChipList;

0 commit comments

Comments
 (0)