Skip to content

Commit c6fb34a

Browse files
alan-agius4Keen Yee Liau
authored and
Keen Yee Liau
committed
fix(@schematics/angular): enable tsc downlevelIteration
We by default now use ES2015. Users can use ES2015 iterations however the ES5 build will fail. Fixes angular#14697
1 parent e70b0e4 commit c6fb34a

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

packages/schematics/angular/migrations/update-8/differential-loading.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,16 @@ function updateTsConfig(tree: Tree, tsConfigPath: string): void {
131131
if (isExtendedConfig) {
132132
removePropertyInAstObject(recorder, compilerOptions, 'target');
133133
removePropertyInAstObject(recorder, compilerOptions, 'module');
134+
removePropertyInAstObject(recorder, compilerOptions, 'downlevelIteration');
134135
} else {
136+
const downlevelIteration = findPropertyInAstObject(compilerOptions, 'downlevelIteration');
137+
if (!downlevelIteration) {
138+
insertPropertyInAstObjectInOrder(recorder, compilerOptions, 'downlevelIteration', true, 4);
139+
} else if (!downlevelIteration.value) {
140+
const { start, end } = downlevelIteration;
141+
recorder.remove(start.offset, end.offset - start.offset);
142+
recorder.insertLeft(start.offset, 'true');
143+
}
135144
const scriptTarget = findPropertyInAstObject(compilerOptions, 'target');
136145
if (!scriptTarget) {
137146
insertPropertyInAstObjectInOrder(recorder, compilerOptions, 'target', 'es2015', 4);

packages/schematics/angular/migrations/update-8/differential-loading_spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,29 @@ describe('Migration to version 8', () => {
8080
expect(module).toBe('esnext');
8181
});
8282

83+
it(`should create 'downlevelIteration' property when doesn't exists`, () => {
84+
const tree2 = schematicRunner.runSchematic('migration-07', {}, tree.branch());
85+
const compilerOptions = {
86+
...oldTsConfig.compilerOptions,
87+
};
88+
89+
tree.overwrite(tsConfigPath, JSON.stringify({ compilerOptions }, null, 2));
90+
const { downlevelIteration } = JSON.parse(tree2.readContent(tsConfigPath)).compilerOptions;
91+
expect(downlevelIteration).toBe(true);
92+
});
93+
94+
it(`should update 'downlevelIteration' to true when it's false`, () => {
95+
const tree2 = schematicRunner.runSchematic('migration-07', {}, tree.branch());
96+
const compilerOptions = {
97+
...oldTsConfig.compilerOptions,
98+
downlevelIteration: false,
99+
};
100+
101+
tree.overwrite(tsConfigPath, JSON.stringify({ compilerOptions }, null, 2));
102+
const { downlevelIteration } = JSON.parse(tree2.readContent(tsConfigPath)).compilerOptions;
103+
expect(downlevelIteration).toBe(true);
104+
});
105+
83106
it(`should create browserslist file if it doesn't exist`, () => {
84107
tree.delete('/browserslist');
85108
const tree2 = schematicRunner.runSchematic('migration-07', {}, tree.branch());

packages/schematics/angular/workspace/files/tsconfig.json.template

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
"outDir": "./dist/out-tsc",
66
"sourceMap": true,
77
"declaration": false,
8+
"downlevelIteration": true,
9+
"experimentalDecorators": true,
810
"module": "esnext",
911
"moduleResolution": "node",
10-
"experimentalDecorators": true,
1112
"importHelpers": true,
1213
"target": "es2015",
1314
"typeRoots": [

0 commit comments

Comments
 (0)