diff --git a/packages/angular_devkit/build_angular/src/babel/plugins/adjust-typescript-enums_spec.ts b/packages/angular_devkit/build_angular/src/babel/plugins/adjust-typescript-enums_spec.ts index 1d5845700d..8efa5cf4cd 100644 --- a/packages/angular_devkit/build_angular/src/babel/plugins/adjust-typescript-enums_spec.ts +++ b/packages/angular_devkit/build_angular/src/babel/plugins/adjust-typescript-enums_spec.ts @@ -43,10 +43,9 @@ describe('adjust-typescript-enums Babel plugin', () => { `, expected: ` var ChangeDetectionStrategy = /*#__PURE__*/ (() => { - (function (ChangeDetectionStrategy) { - ChangeDetectionStrategy[ChangeDetectionStrategy["OnPush"] = 0] = "OnPush"; - ChangeDetectionStrategy[ChangeDetectionStrategy["Default"] = 1] = "Default"; - })(ChangeDetectionStrategy || (ChangeDetectionStrategy = {})); + ChangeDetectionStrategy = ChangeDetectionStrategy || {}; + ChangeDetectionStrategy[(ChangeDetectionStrategy["OnPush"] = 0)] = "OnPush"; + ChangeDetectionStrategy[(ChangeDetectionStrategy["Default"] = 1)] = "Default"; return ChangeDetectionStrategy; })(); `, @@ -64,10 +63,9 @@ describe('adjust-typescript-enums Babel plugin', () => { `, expected: ` export var ChangeDetectionStrategy = /*#__PURE__*/ (() => { - (function (ChangeDetectionStrategy) { - ChangeDetectionStrategy[ChangeDetectionStrategy["OnPush"] = 0] = "OnPush"; - ChangeDetectionStrategy[ChangeDetectionStrategy["Default"] = 1] = "Default"; - })(ChangeDetectionStrategy || (ChangeDetectionStrategy = {})); + ChangeDetectionStrategy = ChangeDetectionStrategy || {}; + ChangeDetectionStrategy[(ChangeDetectionStrategy["OnPush"] = 0)] = "OnPush"; + ChangeDetectionStrategy[(ChangeDetectionStrategy["Default"] = 1)] = "Default"; return ChangeDetectionStrategy; })(); `, @@ -85,10 +83,9 @@ describe('adjust-typescript-enums Babel plugin', () => { `, expected: ` export var ChangeDetectionStrategy = /*#__PURE__*/ (() => { - (function (ChangeDetectionStrategy) { - ChangeDetectionStrategy[ChangeDetectionStrategy["OnPush"] = 5] = "OnPush"; - ChangeDetectionStrategy[ChangeDetectionStrategy["Default"] = 8] = "Default"; - })(ChangeDetectionStrategy || (ChangeDetectionStrategy = {})); + ChangeDetectionStrategy = ChangeDetectionStrategy || {}; + ChangeDetectionStrategy[(ChangeDetectionStrategy["OnPush"] = 5)] = "OnPush"; + ChangeDetectionStrategy[(ChangeDetectionStrategy["Default"] = 8)] = "Default"; return ChangeDetectionStrategy; })(); `, @@ -98,20 +95,19 @@ describe('adjust-typescript-enums Babel plugin', () => { it('wraps string-based TypeScript enums', () => { testCase({ input: ` - var NotificationKind; - (function (NotificationKind) { - NotificationKind["NEXT"] = "N"; - NotificationKind["ERROR"] = "E"; - NotificationKind["COMPLETE"] = "C"; - })(NotificationKind || (NotificationKind = {})); + var NotificationKind; + (function (NotificationKind) { + NotificationKind["NEXT"] = "N"; + NotificationKind["ERROR"] = "E"; + NotificationKind["COMPLETE"] = "C"; + })(NotificationKind || (NotificationKind = {})); `, expected: ` var NotificationKind = /*#__PURE__*/ (() => { - (function (NotificationKind) { - NotificationKind["NEXT"] = "N"; - NotificationKind["ERROR"] = "E"; - NotificationKind["COMPLETE"] = "C"; - })(NotificationKind || (NotificationKind = {})); + NotificationKind = NotificationKind || {}; + NotificationKind["NEXT"] = "N"; + NotificationKind["ERROR"] = "E"; + NotificationKind["COMPLETE"] = "C"; return NotificationKind; })(); `, @@ -165,15 +161,14 @@ describe('adjust-typescript-enums Babel plugin', () => { * @deprecated use @angular/common/http instead */ var RequestMethod = /*#__PURE__*/ (() => { - (function (RequestMethod) { - RequestMethod[RequestMethod["Get"] = 0] = "Get"; - RequestMethod[RequestMethod["Post"] = 1] = "Post"; - RequestMethod[RequestMethod["Put"] = 2] = "Put"; - RequestMethod[RequestMethod["Delete"] = 3] = "Delete"; - RequestMethod[RequestMethod["Options"] = 4] = "Options"; - RequestMethod[RequestMethod["Head"] = 5] = "Head"; - RequestMethod[RequestMethod["Patch"] = 6] = "Patch"; - })(RequestMethod || (RequestMethod = {})); + RequestMethod = RequestMethod || {}; + RequestMethod[(RequestMethod["Get"] = 0)] = "Get"; + RequestMethod[(RequestMethod["Post"] = 1)] = "Post"; + RequestMethod[(RequestMethod["Put"] = 2)] = "Put"; + RequestMethod[(RequestMethod["Delete"] = 3)] = "Delete"; + RequestMethod[(RequestMethod["Options"] = 4)] = "Options"; + RequestMethod[(RequestMethod["Head"] = 5)] = "Head"; + RequestMethod[(RequestMethod["Patch"] = 6)] = "Patch"; return RequestMethod; })(); `, diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/javascript-transformer-worker.ts b/packages/angular_devkit/build_angular/src/builders/browser-esbuild/javascript-transformer-worker.ts index 3a7cde1adb..1a4bc1106f 100644 --- a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/javascript-transformer-worker.ts +++ b/packages/angular_devkit/build_angular/src/builders/browser-esbuild/javascript-transformer-worker.ts @@ -55,7 +55,10 @@ async function transformWithBabel({ return useInputSourcemap ? data : data.replace(/^\/\/# sourceMappingURL=[^\r\n]*/gm, ''); } - const angularPackage = /[\\/]node_modules[\\/]@angular[\\/]/.test(filename); + // @angular/platform-server/init entry-point has side-effects. + const safeAngularPackage = + /[\\/]node_modules[\\/]@angular[\\/]/.test(filename) && + !/@angular[\\/]platform-server[\\/]f?esm2022[\\/]init/.test(filename); // Lazy load the linker plugin only when linking is required if (shouldLink) { @@ -86,7 +89,7 @@ async function transformWithBabel({ }, forceAsyncTransformation, optimize: options.advancedOptimizations && { - pureTopLevel: angularPackage, + pureTopLevel: safeAngularPackage, }, }, ],