feat(core): support TypeScript 4.7 (#45749)

Adds support for TypeScript 4.7. Changes include:
* Bumping the TS version as well as some Bazel dependencies to include https://github.com/bazelbuild/rules_nodejs/pull/3420.
* Adding a backwards-compatibility layer for calls to `updateTypeParameterDeclaration`.
* Making `LView` generic in order to make it easier to type the context based on the usage. Currently the context can be 4 different types which coupled with stricter type checking would required a lot of extra casting all over `core`.
* Fixing a bunch of miscellaneous type errors.
* Removing assertions of `ReferenceEntry.isDefinition` in a few of the language service tests. The field isn't returned by TS anymore and we weren't using it for anything.
* Resolving in error in the language service that was caused by TS attempting to parse HTML files when we try to open them. Previous TS was silently setting them as `ScriptKind.Unknown` and ignoring the errors, but now it throws. I've worked around it by setting them as `ScriptKind.JSX`.

PR Close #45749
This commit is contained in:
Kristiyan Kostadinov
2022-04-29 12:19:45 -04:00
committed by Dylan Hunn
parent fcc548a95f
commit 29039fcdbc
48 changed files with 419 additions and 176 deletions
@@ -43,9 +43,9 @@ export const diff = <T>(differ: DefaultIterableDiffer<T>, a: T[], b: T[]):
if (!alreadySet[record.previousIndex]) {
a[record.currentIndex] = a[record.previousIndex];
} else {
a[record.currentIndex] = {} as T;
a[record.currentIndex] = {} as unknown as T;
}
Object.keys(b[record.currentIndex]).forEach(prop => {
Object.keys(b[record.currentIndex] as unknown as {}).forEach(prop => {
// TypeScript's type inference didn't follow the check from above.
if (record.currentIndex === null) {
return;
@@ -14,7 +14,7 @@ export const initializeExtendedWindowOperations = () => {
extendWindowOperations(window, {inspectedApplication: chromeWindowExtensions});
};
const extendWindowOperations = <T>(target, classImpl: T) => {
const extendWindowOperations = <T extends {}>(target, classImpl: T) => {
for (const key of Object.keys(classImpl)) {
if (target[key] != null) {
console.warn(`A window function or object named ${key} would be overwritten`);
+1 -2
View File
@@ -27,7 +27,7 @@ export interface DirectiveDebugMetadata {
export function getComponent<T>(element: Element): T | null;
// @public
export function getContext<T>(element: Element): T | null;
export function getContext<T extends ({} | RootContext)>(element: Element): T | null;
// @public
export function getDirectiveMetadata(directiveOrComponentInstance: any): ComponentDebugMetadata | DirectiveDebugMetadata | null;
@@ -59,7 +59,6 @@ export interface Listener {
useCapture: boolean;
}
// (No @packageDocumentation comment for this package)
```
@@ -24,11 +24,11 @@
"@angular/compiler-cli": "file:../../../dist/packages-dist/compiler-cli",
"@babel/core": "^7.16.0",
"@bazel/bazelisk": "file:../../../node_modules/@bazel/bazelisk",
"@bazel/concatjs": "5.4.0",
"@bazel/esbuild": "5.4.0",
"@bazel/protractor": "5.4.0",
"@bazel/rollup": "5.4.0",
"@bazel/terser": "5.4.0",
"@bazel/concatjs": "5.4.1",
"@bazel/esbuild": "5.4.1",
"@bazel/protractor": "5.4.1",
"@bazel/rollup": "5.4.1",
"@bazel/terser": "5.4.1",
"@rollup/plugin-commonjs": "file:../../../node_modules/@rollup/plugin-commonjs",
"@rollup/plugin-node-resolve": "file:../../../node_modules/@rollup/plugin-node-resolve",
"@types/jasmine": "2.8.8",
@@ -265,10 +265,10 @@
"@bazel/bazelisk@file:../../../node_modules/@bazel/bazelisk":
version "1.11.0"
"@bazel/[email protected].0":
version "5.4.0"
resolved "https://registry.yarnpkg.com/@bazel/concatjs/-/concatjs-5.4.0.tgz#04e752a6ea3e684f00879e6683657c4ede72df6e"
integrity sha512-jlupaDKxqFS3B1lttOIgkKxirP7v5Qx7KCFtOXO7JxtvYJD/qKtKXEQggTrGKJqLPyiZlNiYimHHGICLSWIZcQ==
"@bazel/[email protected].1":
version "5.4.1"
resolved "https://registry.yarnpkg.com/@bazel/concatjs/-/concatjs-5.4.1.tgz#590b7944d89136863ba4e3e264c555b0efc815de"
integrity sha512-E5lVBdJNeTcXgDM4phmY2JbHdwWIJZ61ls22McXpWhsDlfItURhNuzxbg/+8gDDX0AlMsJnBpAtFLNVH5c2xwA==
dependencies:
protobufjs "6.8.8"
source-map-support "0.5.9"
@@ -0,0 +1,5 @@
load("//integration:index.bzl", "ng_integration_test")
ng_integration_test(
name = "test",
)
@@ -0,0 +1,73 @@
/**
* @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 compilerCli from '@angular/compiler-cli';
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 localize from '@angular/localize';
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,
compilerCli,
core,
coreTesting,
elements,
forms,
localize,
platformBrowser,
platformBrowserTesting,
platformBrowserDynamic,
platformBrowserDynamicTesting,
platformBrowserAnimations,
platformServer,
platformServerInit,
platformServerTesting,
router,
routerTesting,
routerUpgrade,
serviceWorker,
upgrade,
upgradeStatic,
upgradeTesting,
};
@@ -0,0 +1,29 @@
{
"name": "angular-integration",
"description": "Assert that users with module: nodenext in their tsconfig can import our packages",
"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/localize": "file:../../dist/packages-dist/localize",
"@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": "file:../../node_modules/typescript",
"zone.js": "file:../../dist/zone.js-dist/archive/zone.js.tgz"
},
"scripts": {
"test": "tsc"
}
}
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"experimentalDecorators": true,
"module": "NodeNext",
"moduleResolution": "node",
"outDir": "./dist/out-tsc",
"rootDir": ".",
"target": "es5",
"lib": [
"es5",
"dom",
"es2015.collection",
"es2015.iterable",
"es2015.promise"
],
"types": [],
},
"files": [
"include-all.ts",
"node_modules/@types/jasmine/index.d.ts"
]
}
@@ -0,0 +1,9 @@
load("//integration:index.bzl", "ng_integration_test")
ng_integration_test(
name = "test",
# Special case for `typings_test_ts47` test as we want to pin
# `typescript` at version 4.7.x for that test and not link to the
# root @npm//typescript package.
pinned_npm_packages = ["typescript"],
)
@@ -0,0 +1,71 @@
/**
* @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 localize from '@angular/localize';
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,
localize,
platformBrowser,
platformBrowserTesting,
platformBrowserDynamic,
platformBrowserDynamicTesting,
platformBrowserAnimations,
platformServer,
platformServerInit,
platformServerTesting,
router,
routerTesting,
routerUpgrade,
serviceWorker,
upgrade,
upgradeStatic,
upgradeTesting,
};
@@ -0,0 +1,29 @@
{
"name": "angular-integration",
"description": "Assert that users with TypeScript 4.7 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/localize": "file:../../dist/packages-dist/localize",
"@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.7.0-beta",
"zone.js": "file:../../dist/zone.js-dist/archive/zone.js.tgz"
},
"scripts": {
"test": "tsc"
}
}
@@ -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",
"lib": [
"es5",
"dom",
"es2015.collection",
"es2015.iterable",
"es2015.promise"
],
"types": [],
},
"files": [
"include-all.ts",
"node_modules/@types/jasmine/index.d.ts"
]
}
+8 -8
View File
@@ -66,13 +66,13 @@
"@babel/template": "7.16.7",
"@babel/traverse": "7.17.9",
"@babel/types": "7.17.0",
"@bazel/concatjs": "5.4.0",
"@bazel/esbuild": "5.4.0",
"@bazel/jasmine": "5.4.0",
"@bazel/protractor": "5.4.0",
"@bazel/rollup": "5.4.0",
"@bazel/runfiles": "5.4.0",
"@bazel/terser": "5.4.0",
"@bazel/concatjs": "5.4.1",
"@bazel/esbuild": "5.4.1",
"@bazel/jasmine": "5.4.1",
"@bazel/protractor": "5.4.1",
"@bazel/rollup": "5.4.1",
"@bazel/runfiles": "5.4.1",
"@bazel/terser": "5.4.1",
"@microsoft/api-extractor": "7.22.2",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^21.0.0",
@@ -170,7 +170,7 @@
"tsickle": "0.38.1",
"tslib": "^2.3.0",
"tslint": "6.1.3",
"typescript": "~4.6.2",
"typescript": "4.7.0-beta",
"webtreemap": "^2.0.1",
"xhr2": "0.2.1",
"yargs": "^17.2.1"
+1 -1
View File
@@ -35,7 +35,7 @@
"rollup": "^2.56.3",
"rollup-plugin-sourcemaps": "^0.6.3",
"terser": "^5.9.0",
"typescript": ">=4.6.2 <4.7"
"typescript": ">=4.6.2 <4.8"
},
"peerDependenciesMeta": {
"terser": {
@@ -93,8 +93,8 @@ export const spyProperty = <T, P extends keyof T>(ctx: T, prop: P): IPropertySpy
let value = ctx[prop];
const setMockValue = (mockValue: typeof value) => value = mockValue;
const setSpy = jasmine.createSpy(`set ${prop}`).and.callFake(setMockValue);
const getSpy = jasmine.createSpy(`get ${prop}`).and.callFake(() => value);
const setSpy = jasmine.createSpy(`set ${String(prop)}`).and.callFake(setMockValue);
const getSpy = jasmine.createSpy(`get ${String(prop)}`).and.callFake(() => value);
const installSpies = () => {
value = ctx[prop];
@@ -697,7 +697,7 @@ runInEachFileSystem(() => {
});
it('should correctly handle pre-release versions and version ranges', () => {
Object.assign(DEFAULT_NGCC_CONFIG.packages, {
Object.assign(DEFAULT_NGCC_CONFIG.packages!, {
'package-1': {
entryPoints: {
'./entry-point-1': {},
+1 -1
View File
@@ -66,7 +66,7 @@
},
"peerDependencies": {
"@angular/compiler": "0.0.0-PLACEHOLDER",
"typescript": ">=4.6.2 <4.7"
"typescript": ">=4.6.2 <4.8"
},
"repository": {
"type": "git",
@@ -10,6 +10,8 @@ import ts from 'typescript';
import {ClassDeclaration} from '../../reflection';
const PARSED_TS_VERSION = parseFloat(ts.versionMajorMinor);
/**
* A `Set` of `ts.SyntaxKind`s of `ts.Expression` which are safe to wrap in a `ts.AsExpression`
@@ -134,6 +136,21 @@ export function tsCallMethod(
/* argumentsArray */ args);
}
/**
* Updates a `ts.TypeParameter` declaration.
*
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.7.
* We should remove it once we have dropped support for the older versions.
*/
export function tsUpdateTypeParameterDeclaration(
node: ts.TypeParameterDeclaration, name: ts.Identifier, constraint: ts.TypeNode|undefined,
defaultType: ts.TypeNode|undefined): ts.TypeParameterDeclaration {
return PARSED_TS_VERSION < 4.7 ?
ts.factory.updateTypeParameterDeclaration(node, name, constraint, defaultType) :
(ts.factory.updateTypeParameterDeclaration as any)(
node, /* modifiers */[], name, constraint, defaultType);
}
export function checkIfClassIsExported(node: ClassDeclaration): boolean {
// A class is exported if one of two conditions is met:
// 1) it has the 'export' modifier.
@@ -12,7 +12,7 @@ import {ClassDeclaration, ReflectionHost} from '../../reflection';
import {TypeCtorMetadata} from '../api';
import {checkIfGenericTypeBoundsCanBeEmitted, ReferenceEmitEnvironment} from './tcb_util';
import {tsCreateTypeQueryForCoercedInput} from './ts_util';
import {tsCreateTypeQueryForCoercedInput, tsUpdateTypeParameterDeclaration} from './ts_util';
export function generateTypeCtorDeclarationFn(
node: ClassDeclaration<ts.ClassDeclaration>, meta: TypeCtorMetadata, nodeTypeRef: ts.EntityName,
@@ -244,11 +244,9 @@ function typeParametersWithDefaultTypes(params: ReadonlyArray<ts.TypeParameterDe
return params.map(param => {
if (param.default === undefined) {
return ts.factory.updateTypeParameterDeclaration(
/* node */ param,
/* name */ param.name,
/* constraint */ param.constraint,
/* defaultType */ ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword));
return tsUpdateTypeParameterDeclaration(
param, param.name, param.constraint,
ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword));
} else {
return param;
}
@@ -10,6 +10,7 @@ import ts from 'typescript';
import {OwningModule, Reference} from '../../imports';
import {DeclarationNode, ReflectionHost} from '../../reflection';
import {tsUpdateTypeParameterDeclaration} from './ts_util';
import {canEmitType, TypeEmitter} from './type_emitter';
@@ -73,11 +74,7 @@ export class TypeParameterEmitter {
const defaultType =
typeParam.default !== undefined ? emitter.emitType(typeParam.default) : undefined;
return ts.factory.updateTypeParameterDeclaration(
/* node */ typeParam,
/* name */ typeParam.name,
/* constraint */ constraint,
/* defaultType */ defaultType);
return tsUpdateTypeParameterDeclaration(typeParam, typeParam.name, constraint, defaultType);
});
}
@@ -480,7 +480,7 @@ describe('type check blocks', () => {
expect(tcb(TEMPLATE, DIRECTIVES))
.toContain(
'var _t1: i0.Dir = null!; ' +
'var _t2: typeof _t1["fieldA"] = null!; ' +
'var _t2: (typeof _t1)["fieldA"] = null!; ' +
'_t2 = (((ctx).foo)); ');
});
@@ -26,7 +26,7 @@ const MIN_TS_VERSION = '4.6.2';
* Note: this check is disabled in g3, search for
* `angularCompilerOptions.disableTypeScriptVersionCheck` config param value in g3.
*/
const MAX_TS_VERSION = '4.7.0';
const MAX_TS_VERSION = '4.8.0';
/**
* The currently used version of TypeScript, which can be adjusted for testing purposes using
@@ -105,8 +105,12 @@ describe('perform watch', () => {
expect(fs.existsSync(genPath)).toBe(true);
expect(fileExistsSpy!).toHaveBeenCalledWith(mainTsPath);
expect(fileExistsSpy!).toHaveBeenCalledWith(utilTsPath);
expect(getSourceFileSpy!).toHaveBeenCalledWith(mainTsPath, ts.ScriptTarget.ES5);
expect(getSourceFileSpy!).toHaveBeenCalledWith(utilTsPath, ts.ScriptTarget.ES5);
expect(getSourceFileSpy!).toHaveBeenCalledWith(mainTsPath, jasmine.objectContaining({
languageVersion: ts.ScriptTarget.ES5
}));
expect(getSourceFileSpy!).toHaveBeenCalledWith(utilTsPath, jasmine.objectContaining({
languageVersion: ts.ScriptTarget.ES5
}));
fileExistsSpy!.calls.reset();
getSourceFileSpy!.calls.reset();
+4 -3
View File
@@ -78,16 +78,17 @@ class ChainedInjector implements Injector {
constructor(private injector: Injector, private parentInjector: Injector) {}
get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T {
const value = this.injector.get(token, NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR as T, flags);
const value = this.injector.get<T|typeof NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR>(
token, NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR, flags);
if (value !== NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR ||
notFoundValue === NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR) {
notFoundValue === (NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR as unknown as T)) {
// Return the value from the root element injector when
// - it provides it
// (value !== NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR)
// - the module injector should not be checked
// (notFoundValue === NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR)
return value;
return value as T;
}
return this.parentInjector.get(token, notFoundValue, flags);
@@ -196,10 +196,10 @@ export function readPatchedData(target: any): LView|LContext|null {
return (typeof data === 'number') ? getLViewById(data) : data || null;
}
export function readPatchedLView(target: any): LView|null {
export function readPatchedLView<T>(target: any): LView<T>|null {
const value = readPatchedData(target);
if (value) {
return isLView(value) ? value : value.lView;
return (isLView(value) ? value : value.lView) as LView<T>;
}
return null;
}
+3 -2
View File
@@ -489,7 +489,7 @@ function lookupTokenUsingNodeInjector<T>(
// At this point, we have an injector which *may* contain the token, so we step through
// the providers and directives associated with the injector's corresponding node to get
// the instance.
const instance: T|null = searchTokensOnInjector<T>(
const instance: T|{}|null = searchTokensOnInjector<T>(
injectorIndex, lView, token, previousTView, flags, hostTElementNode);
if (instance !== NOT_FOUND) {
return instance;
@@ -803,7 +803,8 @@ function lookupTokenUsingEmbeddedInjector<T>(
// Before we go to the next LView, check if the token exists on the current embedded injector.
const embeddedViewInjector = currentLView[EMBEDDED_VIEW_INJECTOR];
if (embeddedViewInjector) {
const embeddedViewInjectorValue = embeddedViewInjector.get(token, NOT_FOUND as T, flags);
const embeddedViewInjectorValue =
embeddedViewInjector.get(token, NOT_FOUND as T | {}, flags);
if (embeddedViewInjectorValue !== NOT_FOUND) {
return embeddedViewInjectorValue;
}
@@ -10,6 +10,7 @@ import {assertDefined} from '../../util/assert';
import {getComponentViewByInstance} from '../context_discovery';
import {CONTEXT, RootContext, RootContextFlags, TVIEW} from '../interfaces/view';
import {getRootView} from '../util/view_traversal_utils';
import {detectChangesInternal, markViewDirty, scheduleTick, tickRootContext} from './shared';
/**
@@ -53,7 +54,7 @@ export function markDirty(component: {}): void {
* single change detection run. By default, the scheduler is `requestAnimationFrame`, but can
* be changed when calling `renderComponent` and providing the `scheduler` option.
*/
export function tick<T>(component: T): void {
export function tick(component: {}): void {
const rootView = getRootView(component);
const rootContext = rootView[CONTEXT] as RootContext;
tickRootContext(rootContext);
@@ -40,7 +40,7 @@ import {getOrCreateLViewCleanup, getOrCreateTViewCleanup, handleError, loadCompo
export function ɵɵlistener(
eventName: string, listenerFn: (e?: any) => any, useCapture?: boolean,
eventTargetResolver?: GlobalTargetResolver): typeof ɵɵlistener {
const lView = getLView();
const lView = getLView<{}|null>();
const tView = getTView();
const tNode = getCurrentTNode()!;
listenerInternal(
@@ -73,7 +73,7 @@ export function ɵɵlistener(
export function ɵɵsyntheticHostListener(
eventName: string, listenerFn: (e?: any) => any): typeof ɵɵsyntheticHostListener {
const tNode = getCurrentTNode()!;
const lView = getLView();
const lView = getLView<{}|null>();
const tView = getTView();
const currentDef = getCurrentDirectiveDef(tView.data);
const renderer = loadComponentRenderer(currentDef, tNode, lView);
@@ -114,7 +114,7 @@ function findExistingListener(
}
function listenerInternal(
tView: TView, lView: LView, renderer: Renderer3, tNode: TNode, eventName: string,
tView: TView, lView: LView<{}|null>, renderer: Renderer3, tNode: TNode, eventName: string,
listenerFn: (e?: any) => any, useCapture: boolean,
eventTargetResolver?: GlobalTargetResolver): void {
const isTNodeDirectiveHost = isDirectiveHost(tNode);
@@ -250,7 +250,7 @@ function executeListenerWithErrorHandling(
* (the procedural renderer does this already, so in those cases, we should skip)
*/
function wrapListener(
tNode: TNode, lView: LView, context: {}|null, listenerFn: (e?: any) => any,
tNode: TNode, lView: LView<{}|null>, context: {}|null, listenerFn: (e?: any) => any,
wrapWithPreventDefault: boolean): EventListener {
// Note: we are performing most of the work in the listener function itself
// to optimize listener registration.
@@ -73,7 +73,7 @@ interface TViewDebug extends ITView {
*
* Simple slice will keep the same type, and we need it to be LView
*/
export function cloneToLViewFromTViewBlueprint(tView: TView): LView {
export function cloneToLViewFromTViewBlueprint<T>(tView: TView): LView<T> {
const debugTView = tView as TViewDebug;
const lView = getLViewToClone(debugTView.type, tView.template && tView.template.name);
return lView.concat(tView.blueprint) as any;
@@ -387,9 +387,9 @@ export function attachLContainerDebug(lContainer: LContainer) {
attachDebugObject(lContainer, new LContainerDebug(lContainer));
}
export function toDebug(obj: LView): ILViewDebug;
export function toDebug(obj: LView|null): ILViewDebug|null;
export function toDebug(obj: LView|LContainer|null): ILViewDebug|ILContainerDebug|null;
export function toDebug<T>(obj: LView<T>): ILViewDebug<T>;
export function toDebug<T>(obj: LView<T>|null): ILViewDebug<T>|null;
export function toDebug<T>(obj: LView<T>|LContainer|null): ILViewDebug<T>|ILContainerDebug|null;
export function toDebug(obj: any): any {
if (obj) {
const debug = (obj as any).debug;
@@ -432,8 +432,8 @@ function toHtml(value: any, includeChildren: boolean = false): string|null {
return null;
}
export class LViewDebug implements ILViewDebug {
constructor(private readonly _raw_lView: LView) {}
export class LViewDebug<T = unknown> implements ILViewDebug<T> {
constructor(private readonly _raw_lView: LView<T>) {}
/**
* Flags associated with the `LView` unpacked into a more readable state.
@@ -453,8 +453,8 @@ export class LViewDebug implements ILViewDebug {
indexWithinInitPhase: flags >> LViewFlags.IndexWithinInitPhaseShift,
};
}
get parent(): ILViewDebug|ILContainerDebug|null {
return toDebug(this._raw_lView[PARENT]);
get parent(): ILViewDebug<T>|ILContainerDebug|null {
return toDebug<T>(this._raw_lView[PARENT] as LView<T>| LContainer | null);
}
get hostHTML(): string|null {
return toHtml(this._raw_lView[HOST], true);
@@ -462,7 +462,7 @@ export class LViewDebug implements ILViewDebug {
get html(): string {
return (this.nodes || []).map(mapToHTML).join('');
}
get context(): {}|null {
get context(): T {
return this._raw_lView[CONTEXT];
}
/**
@@ -498,8 +498,8 @@ export class LViewDebug implements ILViewDebug {
get childHead(): ILViewDebug|ILContainerDebug|null {
return toDebug(this._raw_lView[CHILD_HEAD]);
}
get next(): ILViewDebug|ILContainerDebug|null {
return toDebug(this._raw_lView[NEXT]);
get next(): ILViewDebug<T>|ILContainerDebug|null {
return toDebug<T>(this._raw_lView[NEXT] as LView<T>| LContainer | null);
}
get childTail(): ILViewDebug|ILContainerDebug|null {
return toDebug(this._raw_lView[CHILD_TAIL]);
@@ -534,11 +534,11 @@ export class LViewDebug implements ILViewDebug {
/**
* Normalized view of child views (and containers) attached at this location.
*/
get childViews(): Array<ILViewDebug|ILContainerDebug> {
const childViews: Array<ILViewDebug|ILContainerDebug> = [];
get childViews(): Array<ILViewDebug<T>|ILContainerDebug> {
const childViews: Array<ILViewDebug<T>|ILContainerDebug> = [];
let child = this.childHead;
while (child) {
childViews.push(child);
childViews.push(child as ILViewDebug<T>| ILContainerDebug);
child = child.next;
}
return childViews;

Some files were not shown because too many files have changed in this diff Show More