diff --git a/packages/zone.js/rollup-es5.config.js b/packages/zone.js/rollup-es5.config.js index b840d3f5281..60699d7176c 100644 --- a/packages/zone.js/rollup-es5.config.js +++ b/packages/zone.js/rollup-es5.config.js @@ -14,7 +14,16 @@ if (bazel_stamp_file) { } } -const banner = `/** +// Add 'use strict' to the bundle, https://github.com/angular/angular/pull/40456 +// When rollup build esm bundle of zone.js, there will be no 'use strict' +// since all esm bundles are `strict`, but when webpack load the esm bundle, +// because zone.js is a module without export and import, webpack is unable +// to determine the bundle is `esm` module or not, so it doesn't add the 'use strict' +// which webpack does to all other `esm` modules which has export or import. +// And it causes issues such as https://github.com/angular/angular/issues/40215 +// `this` should be `undefined` but is assigned with `Window` instead. +const banner = `'use strict'; +/** * @license Angular v${version} * (c) 2010-2020 Google LLC. https://angular.io/ * License: MIT diff --git a/packages/zone.js/rollup-es5_global-es2015.config.js b/packages/zone.js/rollup-es5_global-es2015.config.js index 37bdfd1eddb..c54fd03eea6 100644 --- a/packages/zone.js/rollup-es5_global-es2015.config.js +++ b/packages/zone.js/rollup-es5_global-es2015.config.js @@ -14,7 +14,16 @@ if (bazel_stamp_file) { } } -const banner = `/** +// Add 'use strict' to the bundle, https://github.com/angular/angular/pull/40456 +// When rollup build esm bundle of zone.js, there will be no 'use strict' +// since all esm bundles are `strict`, but when webpack load the esm bundle, +// because zone.js is a module without export and import, webpack is unable +// to determine the bundle is `esm` module or not, so it doesn't add the 'use strict' +// which webpack does to all other `esm` modules which has export or import. +// And it causes issues such as https://github.com/angular/angular/issues/40215 +// `this` should be `undefined` but is assigned with `Window` instead. +const banner = `'use strict'; +/** * @license Angular v${version} * (c) 2010-2020 Google LLC. https://angular.io/ * License: MIT diff --git a/packages/zone.js/test/npm_package/npm_package.spec.ts b/packages/zone.js/test/npm_package/npm_package.spec.ts index ebf76c6281c..739a622e009 100644 --- a/packages/zone.js/test/npm_package/npm_package.spec.ts +++ b/packages/zone.js/test/npm_package/npm_package.spec.ts @@ -86,6 +86,12 @@ describe('Zone.js npm_package', () => { expect(shx.cat('zone.umd.js')).not.toContain('sourceMappingURL'); }); }); + + it('zone.js(es5) should contain use strict', () => { + checkInSubFolder('./bundles', () => { + expect(shx.cat('zone.umd.js')).toMatch(/^\s*'use strict';/); + }); + }); }); describe('es2015', () => { @@ -99,6 +105,11 @@ describe('Zone.js npm_package', () => { expect(shx.cat('zone.js')).not.toContain('sourceMappingURL'); }); }); + it('zone.js(es2015) should contain use strict', () => { + checkInSubFolder('./fesm2015', () => { + expect(shx.cat('zone.js')).toMatch(/^\s*'use strict';/); + }); + }); });