Skip to content

Commit d832c87

Browse files
alan-agius4hansl
authored andcommitted
fix(@schematics/angular): remove leading comments when removing core-js/es7/reflect (#13528)
Fixes #13491
1 parent 6ae1752 commit d832c87

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

packages/schematics/angular/migrations/update-7/polyfill-metadata.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,15 @@ function _removeReflectFromPolyfills(tree: Tree, path: string) {
2929
const recorder = tree.beginUpdate(path);
3030

3131
const sourceFile = ts.createSourceFile(path, source.toString(), ts.ScriptTarget.Latest);
32-
const imports = (
33-
sourceFile.statements
34-
.filter(s => s.kind === ts.SyntaxKind.ImportDeclaration) as ts.ImportDeclaration[]
35-
);
32+
const imports = sourceFile.statements
33+
.filter(s => s.kind === ts.SyntaxKind.ImportDeclaration) as ts.ImportDeclaration[];
3634

3735
for (const i of imports) {
38-
const module = i.moduleSpecifier.kind == ts.SyntaxKind.StringLiteral
39-
&& (i.moduleSpecifier as ts.StringLiteral).text;
36+
const module = ts.isStringLiteral(i.moduleSpecifier) && i.moduleSpecifier.text;
4037

4138
switch (module) {
4239
case 'core-js/es7/reflect':
43-
recorder.remove(i.getStart(sourceFile), i.getWidth(sourceFile));
40+
recorder.remove(i.getFullStart(), i.getFullWidth());
4441
break;
4542
}
4643
}

packages/schematics/angular/migrations/update-7/polyfill-metadata_spec.ts

+30-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,34 @@ import 'web-animations-js'; // Run \`npm install --save web-animations-js\`.
4242
import 'zone.js/dist/zone'; // Included with Angular CLI.
4343
`;
4444

45+
const newPolyfills = `
46+
/** IE9, IE10 and IE11 requires all of the following polyfills. **/
47+
// import 'core-js/es6/symbol';
48+
// import 'core-js/es6/object';
49+
import 'core-js/es6/function';
50+
import 'core-js/es6/parse-int';
51+
// import 'core-js/es6/parse-float';
52+
import 'core-js/es6/number';
53+
// import 'core-js/es6/math';
54+
// import 'core-js/es6/string';
55+
import 'core-js/es6/date';
56+
// import 'core-js/es6/array';
57+
// import 'core-js/es6/regexp';
58+
59+
/** IE10 and IE11 requires the following for the Reflect API. */
60+
import 'core-js/es6/reflect';
61+
62+
import 'web-animations-js'; // Run \`npm install --save web-animations-js\`.
63+
64+
(window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
65+
(window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
66+
67+
/***************************************************************************************************
68+
* Zone JS is required by default for Angular itself.
69+
*/
70+
import 'zone.js/dist/zone'; // Included with Angular CLI.
71+
`;
72+
4573

4674
describe('polyfillMetadataRule', () => {
4775
const schematicRunner = new SchematicTestRunner(
@@ -84,7 +112,7 @@ describe('polyfillMetadataRule', () => {
84112
const tree2 = await schematicRunner.runSchematicAsync('migration-03', {}, tree.branch())
85113
.toPromise();
86114

87-
expect(tree2.readContent(polyfillPath)).not.toMatch(/import .*es7.*reflect.*;/);
115+
expect(tree2.readContent(polyfillPath)).toBe(newPolyfills);
88116
});
89117

90118
it('should work as expected for a project with a root', async () => {
@@ -96,6 +124,6 @@ describe('polyfillMetadataRule', () => {
96124
const tree2 = await schematicRunner.runSchematicAsync('migration-03', {}, tree.branch())
97125
.toPromise();
98126

99-
expect(tree2.readContent(polyfillPath)).not.toMatch(/import .*es7.*reflect.*;/);
127+
expect(tree2.readContent(polyfillPath)).toBe(newPolyfills);
100128
});
101129
});

0 commit comments

Comments
 (0)