Skip to content

Commit 010cf9e

Browse files
committed
feat(core): support TypeScript 4.4
Adds support for TypeScript 4.4. High-level overview of the changes made in this PR: * Bumps the various packages to `[email protected]` and `[email protected]`. * The `useUnknownInCatchVariables` compiler option has been disabled so that we don't have to cast error objects explicitly everywhere. * TS now passes in a third argument to the `__spreadArray` call inside child class constructors. I had to update a couple of places in the runtime and ngcc to be able to pick up the calls correctly. * TS now generates code like `(0, foo)(arg1, arg2)` for imported function calls. I had to update a few of our tests to account for it. See microsoft/TypeScript#44624. * Our `ngtsc` test setup calls the private `matchFiles` function from TS. I had to update our usage, because a new parameter was added. * There was one place where we were setting the readonly `hasTrailingComma` property. I updated the usage to pass in the value when constructing the object instead. * Some browser types were updated which meant that I had to resolve some trivial type errors. * The downlevel decorators tranform was running into an issue where the Closure synthetic comments were being emitted twice. I've worked around it by recreating the class declaration node instead of cloning it.
1 parent 91183eb commit 010cf9e

File tree

55 files changed

+132
-142
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+132
-142
lines changed

aio/aio-builds-setup/dockerbuild/scripts-js/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"shelljs": "^0.8.4",
3434
"source-map-support": "^0.5.19",
3535
"tar-stream": "^2.1.3",
36-
"tslib": "^2.2.0"
36+
"tslib": "^2.3.0"
3737
},
3838
"devDependencies": {
3939
"@types/body-parser": "^1.19.0",
@@ -49,6 +49,6 @@
4949
"supertest": "^4.0.2",
5050
"tslint": "^6.1.3",
5151
"tslint-jasmine-noSkipOrFocus": "^1.0.9",
52-
"typescript": "~4.3.4"
52+
"typescript": "~4.4.2"
5353
}
5454
}

aio/aio-builds-setup/dockerbuild/scripts-js/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"noUnusedParameters": true, /* Report errors on unused parameters. */
3434
"noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
3535
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
36+
"useUnknownInCatchVariables": false, /* Avoid having to cast error objects inside `catch` clauses. */
3637

3738
/* Module Resolution Options */
3839
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */

aio/aio-builds-setup/dockerbuild/scripts-js/yarn.lock

+8-8
Original file line numberDiff line numberDiff line change
@@ -2505,10 +2505,10 @@ tslib@^1.8.1:
25052505
version "1.9.3"
25062506
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286"
25072507

2508-
tslib@^2.2.0:
2509-
version "2.2.0"
2510-
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.2.0.tgz#fb2c475977e35e241311ede2693cee1ec6698f5c"
2511-
integrity sha512-gS9GVHRU+RGn5KQM2rllAlR3dU6m7AcpJKdtH8gFvQiC4Otgk98XnmMU+nZenHt/+VhnBPWwgrJsyrdcw6i23w==
2508+
tslib@^2.3.0:
2509+
version "2.3.1"
2510+
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.3.1.tgz#e8a335add5ceae51aa261d32a490158ef042ef01"
2511+
integrity sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==
25122512

25132513
tslint-jasmine-noSkipOrFocus@^1.0.9:
25142514
version "1.0.9"
@@ -2563,10 +2563,10 @@ typedarray-to-buffer@^3.1.5:
25632563
dependencies:
25642564
is-typedarray "^1.0.0"
25652565

2566-
typescript@~4.3.4:
2567-
version "4.3.4"
2568-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.4.tgz#3f85b986945bcf31071decdd96cf8bfa65f9dcbc"
2569-
integrity sha512-uauPG7XZn9F/mo+7MrsRjyvbxFpzemRjKEZXS4AK83oP2KKOJPvb+9cO/gmnv8arWZvhnjVOXz7B49m1l0e9Ew==
2566+
typescript@~4.4.2:
2567+
version "4.4.2"
2568+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.2.tgz#6d618640d430e3569a1dfb44f7d7e600ced3ee86"
2569+
integrity sha512-gzP+t5W4hdy4c+68bfcv0t400HVJMMd2+H9B7gae1nQlBzCqvrXX+6GL/b3GAgyTH966pzrZ70/fRjwAtZksSQ==
25702570

25712571
undefsafe@^2.0.2:
25722572
version "2.0.2"

aio/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
"@webcomponents/custom-elements": "1.5.0",
103103
"rxjs": "^6.6.7",
104104
"safevalues": "^0.1.8",
105-
"tslib": "^2.2.0",
105+
"tslib": "^2.3.0",
106106
"zone.js": "~0.11.4"
107107
},
108108
"devDependencies": {
@@ -181,7 +181,7 @@
181181
"ts-node": "^10.0.0",
182182
"tsec": "^0.1.5",
183183
"tslint": "~6.1.3",
184-
"typescript": "~4.3.4",
184+
"typescript": "~4.4.2",
185185
"uglify-js": "^3.13.3",
186186
"unist-util-filter": "^2.0.3",
187187
"unist-util-source": "^3.0.0",

aio/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"noFallthroughCasesInSwitch": true,
1111
"noUnusedLocals": true,
1212
"noUnusedParameters": true,
13+
"useUnknownInCatchVariables": false,
1314
"sourceMap": true,
1415
"declaration": false,
1516
"downlevelIteration": true,

aio/yarn.lock

+5-5
Original file line numberDiff line numberDiff line change
@@ -12773,7 +12773,7 @@ tslib@^1.10.0, tslib@^1.13.0, tslib@^1.8.1, tslib@^1.9.0:
1277312773
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
1277412774
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
1277512775

12776-
tslib@^2.0.0, tslib@^2.0.1, tslib@^2.2.0:
12776+
tslib@^2.0.0, tslib@^2.0.1, tslib@^2.2.0, tslib@^2.3.0:
1277712777
version "2.3.1"
1277812778
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.3.1.tgz#e8a335add5ceae51aa261d32a490158ef042ef01"
1277912779
integrity sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==
@@ -12912,10 +12912,10 @@ typescript@~3.2.2:
1291212912
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.2.4.tgz#c585cb952912263d915b462726ce244ba510ef3d"
1291312913
integrity sha512-0RNDbSdEokBeEAkgNbxJ+BLwSManFy9TeXz8uW+48j/xhEXv1ePME60olyzw2XzUqUBNAYFeJadIqAgNqIACwg==
1291412914

12915-
typescript@~4.3.4:
12916-
version "4.3.5"
12917-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.5.tgz#4d1c37cc16e893973c45a06886b7113234f119f4"
12918-
integrity sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==
12915+
typescript@~4.4.2:
12916+
version "4.4.2"
12917+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.2.tgz#6d618640d430e3569a1dfb44f7d7e600ced3ee86"
12918+
integrity sha512-gzP+t5W4hdy4c+68bfcv0t400HVJMMd2+H9B7gae1nQlBzCqvrXX+6GL/b3GAgyTH966pzrZ70/fRjwAtZksSQ==
1291912919

1292012920
ua-parser-js@^0.7.28:
1292112921
version "0.7.28"

integration/BUILD.bazel

+6-6
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,18 @@ INTEGRATION_TESTS = {
9595
# root @npm//typescript package.
9696
"pinned_npm_packages": ["typescript"],
9797
},
98-
"typings_test_ts42": {
99-
# Special case for `typings_test_ts42` test as we want to pin
100-
# `typescript` at version 4.2.x for that test and not link to the
101-
# root @npm//typescript package.
102-
"pinned_npm_packages": ["typescript"],
103-
},
10498
"typings_test_ts43": {
10599
# Special case for `typings_test_ts43` test as we want to pin
106100
# `typescript` at version 4.3.x for that test and not link to the
107101
# root @npm//typescript package.
108102
"pinned_npm_packages": ["typescript"],
109103
},
104+
"typings_test_ts44": {
105+
# Special case for `typings_test_ts44` test as we want to pin
106+
# `typescript` at version 4.4.x for that test and not link to the
107+
# root @npm//typescript package.
108+
"pinned_npm_packages": ["typescript"],
109+
},
110110
}
111111

112112
[

integration/typings_test_ts42/package.json renamed to integration/typings_test_ts44/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-integration",
3-
"description": "Assert that users with TypeScript 4.2 can type-check an Angular application",
3+
"description": "Assert that users with TypeScript 4.4 can type-check an Angular application",
44
"version": "0.0.0",
55
"license": "MIT",
66
"dependencies": {
@@ -19,7 +19,7 @@
1919
"@angular/upgrade": "file:../../dist/packages-dist/upgrade",
2020
"@types/jasmine": "file:../../node_modules/@types/jasmine",
2121
"rxjs": "file:../../node_modules/rxjs",
22-
"typescript": "4.2.4",
22+
"typescript": "4.4.2",
2323
"zone.js": "file:../../dist/zone.js-dist/archive/zone.js.tgz"
2424
},
2525
"scripts": {

package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@
147147
"terser": "^4.4.0",
148148
"tmp": "0.2.1",
149149
"tsickle": "0.38.1",
150-
"tslib": "^2.2.0",
150+
"tslib": "^2.3.0",
151151
"tslint": "6.1.3",
152-
"typescript": "~4.3.4",
152+
"typescript": "~4.4.2",
153153
"xhr2": "0.2.1",
154154
"yargs": "^17.0.0"
155155
},
@@ -191,6 +191,7 @@
191191
"// 4": "Overwrite graceful-fs to a version that does not rely on the 'natives' package. This fixes gulp for >= 10.13, more information: #28213",
192192
"// 5": "Ensure a single version of webdriver-manager so it is hoisted as the integration tests depend on it being found at ../../node_modules/webdriver-manager",
193193
"// 6": "Ensure that `@babel/*` packages match the below versions to avoid conflicts with `types/babel__*`",
194+
"// 7": "TypeScript has to be resolved to 4.4 temporarily until @microsoft/api-extractor is updated",
194195
"resolutions": {
195196
"**/graceful-fs": "4.2.8",
196197
"**/webdriver-manager": "12.1.8",
@@ -200,6 +201,7 @@
200201
"@babel/preset-env": "7.10.2",
201202
"@babel/template": "7.8.6",
202203
"@babel/traverse": "7.8.6",
203-
"@babel/types": "7.8.6"
204+
"@babel/types": "7.8.6",
205+
"typescript": "4.4.2"
204206
}
205207
}

packages/animations/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"node": "^12.14.1 || >=14.0.0"
99
},
1010
"dependencies": {
11-
"tslib": "^2.2.0"
11+
"tslib": "^2.3.0"
1212
},
1313
"peerDependencies": {
1414
"@angular/core": "0.0.0-PLACEHOLDER"

packages/bazel/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626
"@microsoft/api-extractor": "7.18.7",
2727
"shelljs": "0.8.4",
2828
"tsickle": "^0.38.0",
29-
"tslib": "^2.2.0"
29+
"tslib": "^2.3.0"
3030
},
3131
"peerDependencies": {
3232
"@angular/compiler-cli": "0.0.0-PLACEHOLDER",
3333
"@bazel/typescript": ">=1.0.0",
3434
"terser": "^4.3.1",
35-
"typescript": ">=4.2.3 <4.4",
35+
"typescript": ">=4.2.3 <4.5",
3636
"rollup": ">=1.20.0",
3737
"rollup-plugin-commonjs": ">=9.0.0",
3838
"rollup-plugin-node-resolve": ">=4.2.0",

packages/benchpress/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"description": "Benchpress - a framework for e2e performance tests",
55
"main": "index.js",
66
"typings": "./index.d.ts",
7-
"strictNullChecks": true,
87
"dependencies": {
98
"@angular/core": "^12.0.0",
109
"reflect-metadata": "^0.1.13"

packages/common/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"locales": "locales",
1111
"dependencies": {
12-
"tslib": "^2.2.0"
12+
"tslib": "^2.3.0"
1313
},
1414
"peerDependencies": {
1515
"@angular/core": "0.0.0-PLACEHOLDER",

packages/compiler-cli/ngcc/src/host/esm5_host.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ export class Esm5ReflectionHost extends Esm2015ReflectionHost {
573573
*
574574
* 1. `__spread(arguments)`
575575
* 2. `__spreadArray([], __read(arguments))`
576+
* 3. `__spreadArray([], __read(arguments), false)`
576577
*
577578
* The tslib helpers may have been emitted inline as in the above example, or they may be read
578579
* from a namespace import.
@@ -587,8 +588,8 @@ export class Esm5ReflectionHost extends Esm2015ReflectionHost {
587588
// `__spread(arguments)`
588589
return call.args.length === 1 && isArgumentsIdentifier(call.args[0]);
589590
} else if (call.helper === KnownDeclaration.TsHelperSpreadArray) {
590-
// `__spreadArray([], __read(arguments))`
591-
if (call.args.length !== 2) {
591+
// `__spreadArray([], __read(arguments), false)`
592+
if (call.args.length !== 2 && call.args.length !== 3) {
592593
return false;
593594
}
594595

packages/compiler-cli/ngcc/test/integration/ngcc_spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ runInEachFileSystem(() => {
381381

382382
const jsContents = fs.readFile(_(`/node_modules/test-package/esm5/src/index.js`));
383383
// Verify that the ES5 bundle does contain the expected downleveling syntax.
384-
expect(jsContents).toContain('__spreadArray([], __read(arguments))');
384+
expect(jsContents).toContain('__spreadArray([], __read(arguments), false)');
385385
expect(jsContents)
386386
.toContain(
387387
'var ɵSubClass_BaseFactory; return function SubClass_Factory(t) { return (ɵSubClass_BaseFactory || (ɵSubClass_BaseFactory = ɵngcc0.ɵɵgetInheritedFactory(SubClass)))(t || SubClass); };');
@@ -420,7 +420,7 @@ runInEachFileSystem(() => {
420420

421421
const jsContents = fs.readFile(_(`/node_modules/test-package/esm5/src/index.js`));
422422
// Verify that the ES5 bundle does contain the expected downleveling syntax.
423-
expect(jsContents).toContain('__spreadArray([], __read(arguments))');
423+
expect(jsContents).toContain('__spreadArray([], __read(arguments), false)');
424424
expect(jsContents)
425425
.toContain(
426426
'var ɵSubClass_BaseFactory; return function SubClass_Factory(t) { return (ɵSubClass_BaseFactory || (ɵSubClass_BaseFactory = ɵngcc0.ɵɵgetInheritedFactory(SubClass)))(t || SubClass); };');

packages/compiler-cli/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
"semver": "^7.0.0",
2424
"source-map": "^0.6.1",
2525
"sourcemap-codec": "^1.4.8",
26-
"tslib": "^2.2.0",
26+
"tslib": "^2.3.0",
2727
"yargs": "^17.0.0"
2828
},
2929
"peerDependencies": {
3030
"@angular/compiler": "0.0.0-PLACEHOLDER",
31-
"typescript": ">=4.2.3 <4.4"
31+
"typescript": ">=4.2.3 <4.5"
3232
},
3333
"repository": {
3434
"type": "git",

packages/compiler-cli/src/ngtsc/file_system/testing/src/test_helper.ts

+11-9
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ runInEachFileSystem.windows = (callback: (os: string) => void) =>
6969
export function initMockFileSystem(os: string, cwd?: AbsoluteFsPath): MockFileSystem {
7070
const fs = createMockFileSystem(os, cwd);
7171
setFileSystem(fs);
72-
monkeyPatchTypeScript(os, fs);
72+
monkeyPatchTypeScript(fs);
7373
return fs;
7474
}
7575

@@ -88,11 +88,7 @@ function createMockFileSystem(os: string, cwd?: AbsoluteFsPath): MockFileSystem
8888
}
8989
}
9090

91-
function monkeyPatchTypeScript(os: string, fs: MockFileSystem) {
92-
ts.sys.directoryExists = path => {
93-
const absPath = fs.resolve(path);
94-
return fs.exists(absPath) && fs.stat(absPath).isDirectory();
95-
};
91+
function monkeyPatchTypeScript(fs: MockFileSystem) {
9692
ts.sys.fileExists = path => {
9793
const absPath = fs.resolve(path);
9894
return fs.exists(absPath) && fs.stat(absPath).isFile();
@@ -102,6 +98,7 @@ function monkeyPatchTypeScript(os: string, fs: MockFileSystem) {
10298
ts.sys.readFile = fs.readFile.bind(fs);
10399
ts.sys.resolvePath = fs.resolve.bind(fs);
104100
ts.sys.writeFile = fs.writeFile.bind(fs);
101+
ts.sys.directoryExists = directoryExists;
105102
ts.sys.readDirectory = readDirectory;
106103

107104
function getDirectories(path: string): string[] {
@@ -132,21 +129,26 @@ function monkeyPatchTypeScript(os: string, fs: MockFileSystem) {
132129
return fs.realpath(fs.resolve(path));
133130
}
134131

132+
function directoryExists(path: string) {
133+
const absPath = fs.resolve(path);
134+
return fs.exists(absPath) && fs.stat(absPath).isDirectory();
135+
}
136+
135137
// Rather than completely re-implementing we are using the `ts.matchFiles` function,
136138
// which is internal to the `ts` namespace.
137139
const tsMatchFiles: (
138140
path: string, extensions: ReadonlyArray<string>|undefined,
139141
excludes: ReadonlyArray<string>|undefined, includes: ReadonlyArray<string>|undefined,
140142
useCaseSensitiveFileNames: boolean, currentDirectory: string, depth: number|undefined,
141-
getFileSystemEntries: (path: string) => FileSystemEntries,
142-
realpath: (path: string) => string) => string[] = (ts as any).matchFiles;
143+
getFileSystemEntries: (path: string) => FileSystemEntries, realpath: (path: string) => string,
144+
directoryExists: (path: string) => boolean) => string[] = (ts as any).matchFiles;
143145

144146
function readDirectory(
145147
path: string, extensions?: ReadonlyArray<string>, excludes?: ReadonlyArray<string>,
146148
includes?: ReadonlyArray<string>, depth?: number): string[] {
147149
return tsMatchFiles(
148150
path, extensions, excludes, includes, fs.isCaseSensitive(), fs.pwd(), depth,
149-
getFileSystemEntries, realPath);
151+
getFileSystemEntries, realPath, directoryExists);
150152
}
151153
}
152154

packages/compiler-cli/src/transformers/downlevel_decorators_transform.ts

+5-9
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ function extractMetadataFromSingleDecorator(
6767
for (const arg of call.arguments) {
6868
args.push(arg);
6969
}
70-
const argsArrayLiteral = ts.createArrayLiteral(args);
71-
argsArrayLiteral.elements.hasTrailingComma = true;
70+
const argsArrayLiteral = ts.createArrayLiteral(ts.createNodeArray(args, true));
7271
metadataProperties.push(ts.createPropertyAssignment('args', argsArrayLiteral));
7372
}
7473
break;
@@ -480,8 +479,6 @@ export function getDownlevelDecoratorsTransform(
480479
* - creates a propDecorators property
481480
*/
482481
function transformClassDeclaration(classDecl: ts.ClassDeclaration): ts.ClassDeclaration {
483-
classDecl = ts.getMutableClone(classDecl);
484-
485482
const newMembers: ts.ClassElement[] = [];
486483
const decoratedProperties = new Map<string, ts.Decorator[]>();
487484
let classParameters: ParameterDecorationInfo[]|null = null;
@@ -556,11 +553,10 @@ export function getDownlevelDecoratorsTransform(
556553

557554
const members = ts.setTextRange(
558555
ts.createNodeArray(newMembers, classDecl.members.hasTrailingComma), classDecl.members);
559-
560-
return ts.updateClassDeclaration(
561-
classDecl, decoratorsToKeep.size ? Array.from(decoratorsToKeep) : undefined,
562-
classDecl.modifiers, classDecl.name, classDecl.typeParameters, classDecl.heritageClauses,
563-
members);
556+
const newClassDecl = ts.createClassDeclaration(
557+
decoratorsToKeep.size ? Array.from(decoratorsToKeep) : undefined, classDecl.modifiers,
558+
classDecl.name, classDecl.typeParameters, classDecl.heritageClauses, members);
559+
return ts.setTextRange(newClassDecl, classDecl);
564560
}
565561

566562
/**

packages/compiler-cli/src/typescript_support.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {compareVersions} from './diagnostics/typescript_version';
1515
* Note: this check is disabled in g3, search for
1616
* `angularCompilerOptions.disableTypeScriptVersionCheck` config param value in g3.
1717
*/
18-
const MIN_TS_VERSION = '4.2.3';
18+
const MIN_TS_VERSION = '4.3.2';
1919

2020
/**
2121
* Supremum of supported TypeScript versions
@@ -25,7 +25,7 @@ const MIN_TS_VERSION = '4.2.3';
2525
* Note: this check is disabled in g3, search for
2626
* `angularCompilerOptions.disableTypeScriptVersionCheck` config param value in g3.
2727
*/
28-
const MAX_TS_VERSION = '4.4.0';
28+
const MAX_TS_VERSION = '4.5.0';
2929

3030
/**
3131
* The currently used version of TypeScript, which can be adjusted for testing purposes using

0 commit comments

Comments
 (0)