Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): support TypeScript 4.3 #42022

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions aio/aio-builds-setup/dockerbuild/scripts-js/package.json
Expand Up @@ -33,7 +33,7 @@
"shelljs": "^0.8.4",
"source-map-support": "^0.5.19",
"tar-stream": "^2.1.3",
"tslib": "^2.1.0"
"tslib": "^2.2.0"
},
"devDependencies": {
"@types/body-parser": "^1.19.0",
Expand All @@ -49,6 +49,6 @@
"supertest": "^4.0.2",
"tslint": "^6.1.3",
"tslint-jasmine-noSkipOrFocus": "^1.0.9",
"typescript": "^4.2.4"
"typescript": "^4.3.2"
}
}
16 changes: 8 additions & 8 deletions aio/aio-builds-setup/dockerbuild/scripts-js/yarn.lock
Expand Up @@ -2505,10 +2505,10 @@ tslib@^1.8.1:
version "1.9.3"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286"

tslib@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.1.0.tgz#da60860f1c2ecaa5703ab7d39bc05b6bf988b97a"
integrity sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A==
tslib@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.2.0.tgz#fb2c475977e35e241311ede2693cee1ec6698f5c"
integrity sha512-gS9GVHRU+RGn5KQM2rllAlR3dU6m7AcpJKdtH8gFvQiC4Otgk98XnmMU+nZenHt/+VhnBPWwgrJsyrdcw6i23w==

tslint-jasmine-noSkipOrFocus@^1.0.9:
version "1.0.9"
Expand Down Expand Up @@ -2563,10 +2563,10 @@ typedarray-to-buffer@^3.1.5:
dependencies:
is-typedarray "^1.0.0"

typescript@^4.2.4:
version "4.2.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.2.4.tgz#8610b59747de028fda898a8aef0e103f156d0961"
integrity sha512-V+evlYHZnQkaz8TRBuxTA92yZBPotr5H+WhQ7bD3hZUndx5tGOa1fuCgeSjxAzM1RiN5IzvadIXTVefuuwZCRg==
typescript@^4.3.2:
version "4.3.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.2.tgz#399ab18aac45802d6f2498de5054fcbbe716a805"
integrity sha512-zZ4hShnmnoVnAHpVHWpTcxdv7dWP60S2FsydQLV8V5PbS3FifjWFFRiHSWpDJahly88PRyV5teTSLoq4eG7mKw==

undefsafe@^2.0.2:
version "2.0.2"
Expand Down
4 changes: 2 additions & 2 deletions aio/package.json
Expand Up @@ -99,7 +99,7 @@
"@angular/service-worker": "12.0.1",
"@webcomponents/custom-elements": "1.4.3",
"rxjs": "^6.6.7",
"tslib": "^2.1.0",
"tslib": "^2.2.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
Expand Down Expand Up @@ -168,7 +168,7 @@
"tree-kill": "^1.1.0",
"ts-node": "^9.1.1",
"tslint": "~6.1.3",
"typescript": "~4.2.4",
"typescript": "~4.3.2",
"uglify-js": "^3.13.3",
"unist-util-filter": "^2.0.3",
"unist-util-source": "^3.0.0",
Expand Down
7 changes: 6 additions & 1 deletion aio/yarn.lock
Expand Up @@ -12184,7 +12184,7 @@ typedarray@^0.0.6:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=

typescript@4.2.4, typescript@~4.2.4:
typescript@4.2.4:
version "4.2.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.2.4.tgz#8610b59747de028fda898a8aef0e103f156d0961"
integrity sha512-V+evlYHZnQkaz8TRBuxTA92yZBPotr5H+WhQ7bD3hZUndx5tGOa1fuCgeSjxAzM1RiN5IzvadIXTVefuuwZCRg==
Expand All @@ -12194,6 +12194,11 @@ typescript@~3.2.2:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.2.4.tgz#c585cb952912263d915b462726ce244ba510ef3d"
integrity sha512-0RNDbSdEokBeEAkgNbxJ+BLwSManFy9TeXz8uW+48j/xhEXv1ePME60olyzw2XzUqUBNAYFeJadIqAgNqIACwg==

typescript@~4.3.2:
version "4.3.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.2.tgz#399ab18aac45802d6f2498de5054fcbbe716a805"
integrity sha512-zZ4hShnmnoVnAHpVHWpTcxdv7dWP60S2FsydQLV8V5PbS3FifjWFFRiHSWpDJahly88PRyV5teTSLoq4eG7mKw==

ua-parser-js@^0.7.23:
version "0.7.28"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.28.tgz#8ba04e653f35ce210239c64661685bf9121dec31"
Expand Down
6 changes: 6 additions & 0 deletions integration/BUILD.bazel
Expand Up @@ -100,6 +100,12 @@ INTEGRATION_TESTS = {
# root @npm//typescript package.
"pinned_npm_packages": ["typescript"],
},
"typings_test_ts43": {
# Special case for `typings_test_ts43` test as we want to pin
# `typescript` at version 4.3.x for that test and not link to the
# root @npm//typescript package.
"pinned_npm_packages": ["typescript"],
},
}

[
Expand Down
69 changes: 69 additions & 0 deletions integration/typings_test_ts43/include-all.ts
@@ -0,0 +1,69 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/



import * as animations from '@angular/animations';
import * as animationsBrowser from '@angular/animations/browser';
import * as animationsBrowserTesting from '@angular/animations/browser/testing';
import * as common from '@angular/common';
import * as commonHttp from '@angular/common/http';
import * as commonTesting from '@angular/common/testing';
import * as commonHttpTesting from '@angular/common/testing';
import * as compiler from '@angular/compiler';
import * as compilerTesting from '@angular/compiler/testing';
import * as core from '@angular/core';
import * as coreTesting from '@angular/core/testing';
import * as elements from '@angular/elements';
import * as forms from '@angular/forms';
import * as platformBrowser from '@angular/platform-browser';
import * as platformBrowserDynamic from '@angular/platform-browser-dynamic';
import * as platformBrowserDynamicTesting from '@angular/platform-browser-dynamic/testing';
import * as platformBrowserAnimations from '@angular/platform-browser/animations';
import * as platformBrowserTesting from '@angular/platform-browser/testing';
import * as platformServer from '@angular/platform-server';
import * as platformServerInit from '@angular/platform-server/init';
import * as platformServerTesting from '@angular/platform-server/testing';
import * as router from '@angular/router';
import * as routerTesting from '@angular/router/testing';
import * as routerUpgrade from '@angular/router/upgrade';
import * as serviceWorker from '@angular/service-worker';
import * as upgrade from '@angular/upgrade';
import * as upgradeStatic from '@angular/upgrade/static';
import * as upgradeTesting from '@angular/upgrade/static/testing';

export default {
animations,
animationsBrowser,
animationsBrowserTesting,
common,
commonTesting,
commonHttp,
commonHttpTesting,
compiler,
compilerTesting,
core,
coreTesting,
elements,
forms,
platformBrowser,
platformBrowserTesting,
platformBrowserDynamic,
platformBrowserDynamicTesting,
platformBrowserAnimations,
platformServer,
platformServerInit,
platformServerTesting,
router,
routerTesting,
routerUpgrade,
serviceWorker,
upgrade,
upgradeStatic,
upgradeTesting,
};
28 changes: 28 additions & 0 deletions integration/typings_test_ts43/package.json
@@ -0,0 +1,28 @@
{
"name": "angular-integration",
"description": "Assert that users with TypeScript 4.3 can type-check an Angular application",
"version": "0.0.0",
"license": "MIT",
"dependencies": {
"@angular/animations": "file:../../dist/packages-dist/animations",
"@angular/common": "file:../../dist/packages-dist/common",
"@angular/compiler": "file:../../dist/packages-dist/compiler",
"@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli",
"@angular/core": "file:../../dist/packages-dist/core",
"@angular/elements": "file:../../dist/packages-dist/elements",
"@angular/forms": "file:../../dist/packages-dist/forms",
"@angular/platform-browser": "file:../../dist/packages-dist/platform-browser",
"@angular/platform-browser-dynamic": "file:../../dist/packages-dist/platform-browser-dynamic",
"@angular/platform-server": "file:../../dist/packages-dist/platform-server",
"@angular/router": "file:../../dist/packages-dist/router",
"@angular/service-worker": "file:../../dist/packages-dist/service-worker",
"@angular/upgrade": "file:../../dist/packages-dist/upgrade",
"@types/jasmine": "file:../../node_modules/@types/jasmine",
"rxjs": "file:../../node_modules/rxjs",
"typescript": "4.3.2",
"zone.js": "file:../../dist/zone.js-dist/archive/zone.js.tgz"
},
"scripts": {
"test": "tsc"
}
}
26 changes: 26 additions & 0 deletions integration/typings_test_ts43/tsconfig.json
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"experimentalDecorators": true,
"module": "commonjs",
"moduleResolution": "node",
"outDir": "./dist/out-tsc",
"rootDir": ".",
"target": "es5",
devversion marked this conversation as resolved.
Show resolved Hide resolved
"lib": [
"es5",
"dom",
"es2015.collection",
"es2015.iterable",
"es2015.promise"
],
"types": [],
},
"files": [
"include-all.ts",
"node_modules/@types/jasmine/index.d.ts"
]
}
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -151,9 +151,9 @@
"terser": "^4.4.0",
"tmp": "0.2.1",
"tsickle": "0.38.1",
"tslib": "^2.1.0",
"tslib": "^2.2.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is tslib@2.2 required by tsc@4.3? I'm just wondering if we dodge a bullet here by switching from peerdeps on tslib to deps, which now allows us to simply increment the version.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great question. Tslib v2.2.0 updated the helpers for ECMAScript private fields to support instance methods, accessors and static methods (it supported private fields in previous versions already).

I think only if one uses such "newly supported" type of ECMAScript private fields, the new tslib version would be required. Angular itself doesn't use them at all, so we would also be fine staying on an older version based on what I can tell.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we stay on the old version and start using private fields (which might be tricky to prevent) things could break when we don't expect it. So I think it's better to update, and risk that tslib will be present in final bundles twice until the app also updates to tslib 2.2.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

"tslint": "6.1.3",
"typescript": "~4.2.4",
"typescript": "~4.3.2",
"xhr2": "0.2.1",
"yaml": "^1.10.0",
"yargs": "^17.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/animations/package.json
Expand Up @@ -8,7 +8,7 @@
"node": "^12.14.1 || >=14.0.0"
},
"dependencies": {
"tslib": "^2.1.0"
"tslib": "^2.2.0"
JoostK marked this conversation as resolved.
Show resolved Hide resolved
},
"peerDependencies": {
"@angular/core": "0.0.0-PLACEHOLDER"
Expand Down
4 changes: 2 additions & 2 deletions packages/bazel/package.json
Expand Up @@ -26,13 +26,13 @@
"@microsoft/api-extractor": "7.7.11",
"shelljs": "0.8.4",
"tsickle": "^0.38.0",
"tslib": "^2.1.0"
"tslib": "^2.2.0"
},
"peerDependencies": {
"@angular/compiler-cli": "0.0.0-PLACEHOLDER",
"@bazel/typescript": ">=1.0.0",
"terser": "^4.3.1",
"typescript": ">=4.2.3 <4.3",
"typescript": ">=4.2.3 <4.4",
"rollup": ">=1.20.0",
"rollup-plugin-commonjs": ">=9.0.0",
"rollup-plugin-node-resolve": ">=4.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/common/package.json
Expand Up @@ -9,7 +9,7 @@
},
"locales": "locales",
"dependencies": {
"tslib": "^2.1.0"
"tslib": "^2.2.0"
},
"peerDependencies": {
"@angular/core": "0.0.0-PLACEHOLDER",
Expand Down
22 changes: 12 additions & 10 deletions packages/compiler-cli/ngcc/src/host/esm2015_host.ts
Expand Up @@ -11,6 +11,7 @@ import * as ts from 'typescript';
import {absoluteFromSourceFile} from '../../../src/ngtsc/file_system';
import {Logger} from '../../../src/ngtsc/logging';
import {ClassDeclaration, ClassMember, ClassMemberKind, CtorParameter, Declaration, DeclarationNode, Decorator, EnumMember, Import, isConcreteDeclaration, isDecoratorIdentifier, isNamedClassDeclaration, isNamedFunctionDeclaration, isNamedVariableDeclaration, KnownDeclaration, reflectObjectLiteral, SpecialDeclarationKind, TypeScriptReflectionHost, TypeValueReference, TypeValueReferenceKind, ValueUnavailableKind} from '../../../src/ngtsc/reflection';
import {isSymbolWithValueDeclaration, SymbolWithValueDeclaration} from '../../../src/ngtsc/util/src/typescript';
import {isWithinPackage} from '../analysis/util';
import {BundleProgram} from '../packages/bundle_program';
import {findAll, getNameText, hasNameIdentifier, isDefined, stripDollarSuffix} from '../utils';
Expand Down Expand Up @@ -213,7 +214,7 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N

// That didn't work so now try getting it from the "inner" declaration.
const classSymbol = this.getClassSymbol(clazz);
if (classSymbol === undefined ||
if (classSymbol?.implementation.valueDeclaration === undefined ||
!isNamedDeclaration(classSymbol.implementation.valueDeclaration)) {
return null;
}
Expand Down Expand Up @@ -241,7 +242,7 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N
}

private getNameFromClassSymbolDeclaration(
classSymbol: NgccClassSymbol, declaration: ts.Declaration): ts.Identifier {
classSymbol: NgccClassSymbol, declaration: ts.Declaration|undefined): ts.Identifier {
if (declaration === undefined) {
throw new Error(
`getInternalNameOfClass() called on a class with an undefined internal declaration. External class name: ${
Expand Down Expand Up @@ -721,12 +722,12 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N
return undefined;
}

let implementationSymbol = declarationSymbol;
let implementationSymbol: ts.Symbol|undefined = declarationSymbol;
if (innerDeclaration !== null && isNamedDeclaration(innerDeclaration)) {
implementationSymbol = this.checker.getSymbolAtLocation(innerDeclaration.name) as ClassSymbol;
implementationSymbol = this.checker.getSymbolAtLocation(innerDeclaration.name);
}

if (implementationSymbol === undefined) {
if (!isSymbolWithValueDeclaration(implementationSymbol)) {
return undefined;
}

Expand All @@ -740,8 +741,9 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N
return classSymbol;
}

private getAdjacentSymbol(declarationSymbol: ClassSymbol, implementationSymbol: ClassSymbol):
ClassSymbol|undefined {
private getAdjacentSymbol(
declarationSymbol: ClassSymbol,
implementationSymbol: SymbolWithValueDeclaration): SymbolWithValueDeclaration|undefined {
if (declarationSymbol === implementationSymbol) {
return undefined;
}
Expand All @@ -755,9 +757,9 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N
if (adjacentDeclaration === undefined || !isNamedVariableDeclaration(adjacentDeclaration)) {
return undefined;
}
const adjacentSymbol =
this.checker.getSymbolAtLocation(adjacentDeclaration.name) as ClassSymbol;
if (adjacentSymbol === declarationSymbol || adjacentSymbol === implementationSymbol) {
const adjacentSymbol = this.checker.getSymbolAtLocation(adjacentDeclaration.name);
if (adjacentSymbol === declarationSymbol || adjacentSymbol === implementationSymbol ||
!isSymbolWithValueDeclaration(adjacentSymbol)) {
return undefined;
}
return adjacentSymbol;
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-cli/ngcc/src/host/esm5_host.ts
Expand Up @@ -292,7 +292,7 @@ export class Esm5ReflectionHost extends Esm2015ReflectionHost {
const members: ClassMember[] = [];
if (propertyDefinition.setter) {
members.push({
node,
node: node!,
implementation: propertyDefinition.setter,
kind: ClassMemberKind.Setter,
type: null,
Expand All @@ -310,7 +310,7 @@ export class Esm5ReflectionHost extends Esm2015ReflectionHost {
}
if (propertyDefinition.getter) {
members.push({
node,
node: node!,
implementation: propertyDefinition.getter,
kind: ClassMemberKind.Getter,
type: null,
Expand Down
5 changes: 3 additions & 2 deletions packages/compiler-cli/ngcc/src/host/ngcc_host.ts
Expand Up @@ -8,6 +8,7 @@
import * as ts from 'typescript';

import {ClassDeclaration, Declaration, Decorator, ReflectionHost} from '../../../src/ngtsc/reflection';
import {SymbolWithValueDeclaration} from '../../../src/ngtsc/util/src/typescript';

export const PRE_R3_MARKER = '__PRE_R3__';
export const POST_R3_MARKER = '__POST_R3__';
Expand Down Expand Up @@ -47,13 +48,13 @@ export interface NgccClassSymbol {
* inner declaration does not need to satisfy the requirements imposed on a publicly visible class
* declaration.
*/
implementation: ts.Symbol;
implementation: SymbolWithValueDeclaration;

/**
* Represents the symbol corresponding to a variable within a class IIFE that may be used to
* attach static properties or decorated.
*/
adjacent?: ts.Symbol;
adjacent?: SymbolWithValueDeclaration;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-cli/ngcc/src/host/umd_host.ts
Expand Up @@ -421,7 +421,7 @@ export class UmdReflectionHost extends Esm5ReflectionHost {
const exportsSymbol = this.checker.getSymbolsInScope(id, ts.SymbolFlags.Variable)
.find(symbol => symbol.name === 'exports');

const node = exportsSymbol !== undefined &&
const node = exportsSymbol?.valueDeclaration !== undefined &&
!ts.isFunctionExpression(exportsSymbol.valueDeclaration.parent) ?
// There is a locally defined `exports` variable that is not a function parameter.
// So this `exports` identifier must be a local variable and does not represent the module.
Expand Down