Skip to content

Commit

Permalink
fix(@angular-devkit/build-optimizer): wrap classes with a let variable
Browse files Browse the repository at this point in the history
Classes can technically be re-assigned.  By using a let variable this behavior will be retained and prevent potential runtime errors.

Fixes #14930
  • Loading branch information
clydin authored and kyliau committed Jul 9, 2019
1 parent f6953f0 commit 8752f21
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
Expand Up @@ -659,7 +659,7 @@ function createWrappedClass(
ts.createVariableDeclarationList([
ts.createVariableDeclaration(name, undefined, pureIife),
],
ts.NodeFlags.Const,
ts.NodeFlags.Let,
),
));

Expand Down
Expand Up @@ -39,14 +39,14 @@ describe('wrap enums and classes transformer', () => {
`;

const output = tags.stripIndent`
const CustomComponentEffects = /*@__PURE__*/ (() => {
let CustomComponentEffects = /*@__PURE__*/ (() => {
${defaultClass.replace('export default ', '')}
return CustomComponentEffects;
})();
export default CustomComponentEffects;
const CustomComponent = /*@__PURE__*/ (() => {
let CustomComponent = /*@__PURE__*/ (() => {
${namedClass}
return CustomComponent;
Expand Down Expand Up @@ -78,7 +78,7 @@ describe('wrap enums and classes transformer', () => {
`;

const output = tags.stripIndent`
const CustomComponentEffects = /*@__PURE__*/ (() => {
let CustomComponentEffects = /*@__PURE__*/ (() => {
${input}
return CustomComponentEffects;
Expand All @@ -104,7 +104,7 @@ describe('wrap enums and classes transformer', () => {
`;

const output = tags.stripIndent`
const ApplicationModule = /*@__PURE__*/ (() => {
let ApplicationModule = /*@__PURE__*/ (() => {
${input}
return ApplicationModule;
Expand All @@ -131,7 +131,7 @@ describe('wrap enums and classes transformer', () => {
`;

const output = tags.stripIndent`
const CommonModule = /*@__PURE__*/ (() => {
let CommonModule = /*@__PURE__*/ (() => {
${input}
return CommonModule;
Expand All @@ -154,7 +154,7 @@ describe('wrap enums and classes transformer', () => {
`;

const output = tags.stripIndent`
export const Foo = /*@__PURE__*/ (() => {
export let Foo = /*@__PURE__*/ (() => {
${input.replace('export ', '')}
return Foo;
Expand All @@ -170,7 +170,7 @@ describe('wrap enums and classes transformer', () => {
TemplateRef.__NG_ELEMENT_ID__ = () => SWITCH_TEMPLATE_REF_FACTORY(TemplateRef, ElementRef);
`;
const output = tags.stripIndent`
export const TemplateRef = /*@__PURE__*/ (() => {
export let TemplateRef = /*@__PURE__*/ (() => {
class TemplateRef { }
TemplateRef.__NG_ELEMENT_ID__ = () => SWITCH_TEMPLATE_REF_FACTORY(TemplateRef, ElementRef);
return TemplateRef;
Expand All @@ -187,7 +187,7 @@ describe('wrap enums and classes transformer', () => {
TemplateRef.somethingElse = true;
`;
const output = tags.stripIndent`
export const TemplateRef = /*@__PURE__*/ (() => {
export let TemplateRef = /*@__PURE__*/ (() => {
class TemplateRef {
}
TemplateRef.__NG_ELEMENT_ID__ = () => SWITCH_TEMPLATE_REF_FACTORY(TemplateRef, ElementRef);
Expand Down Expand Up @@ -231,14 +231,14 @@ describe('wrap enums and classes transformer', () => {
`;

const output = tags.stripIndent`
const Foo = /*@__PURE__*/ (() => {
let Foo = /*@__PURE__*/ (() => {
${defaultClass.replace('export default Foo;', '')}
return Foo;
})();
export default Foo;
const AggregateColumnDirective = /*@__PURE__*/ (() => {
let AggregateColumnDirective = /*@__PURE__*/ (() => {
${namedClass}
return AggregateColumnDirective;
Expand All @@ -261,7 +261,7 @@ describe('wrap enums and classes transformer', () => {
`;

const output = tags.stripIndent`
const AggregateColumnDirective = /*@__PURE__*/ (() => {
let AggregateColumnDirective = /*@__PURE__*/ (() => {
${input}
return AggregateColumnDirective;
Expand Down Expand Up @@ -293,7 +293,7 @@ describe('wrap enums and classes transformer', () => {

const output = tags.stripIndent`
var FooDirective_1;
const FooDirective = /*@__PURE__*/ (() => {
let FooDirective = /*@__PURE__*/ (() => {
${classContent}
return FooDirective;
Expand All @@ -316,7 +316,7 @@ describe('wrap enums and classes transformer', () => {
`;

const output = tags.stripIndent`
const ChipList = /*@__PURE__*/ (() => {
let ChipList = /*@__PURE__*/ (() => {
${input}
return ChipList;
})();`;
Expand Down Expand Up @@ -349,7 +349,7 @@ describe('wrap enums and classes transformer', () => {
ChipList = __decorate$4([NotifyPropertyChanges], ChipList);`;

const output = tags.stripIndent`
const ChipList = /*@__PURE__*/ (() => {
let ChipList = /*@__PURE__*/ (() => {
${input}
return ChipList;
})();`;
Expand Down Expand Up @@ -394,7 +394,7 @@ describe('wrap enums and classes transformer', () => {
const output = tags.stripIndent`
const minutesMilliSeconds = 60000;
const AggregateColumnDirective = /*@__PURE__*/ (() => {
let AggregateColumnDirective = /*@__PURE__*/ (() => {
${firstClass}
return AggregateColumnDirective;
Expand All @@ -403,7 +403,7 @@ describe('wrap enums and classes transformer', () => {
const CSS = 'e-css';
const PRIMARY = 'e-primary';
const ChipList = /*@__PURE__*/ (() => {
let ChipList = /*@__PURE__*/ (() => {
${secondClass}
return ChipList;
Expand Down

0 comments on commit 8752f21

Please sign in to comment.