From 2d9a0c2ebc86a632f6fa2bba292073f16ce00acb Mon Sep 17 00:00:00 2001 From: crisbeto Date: Sat, 23 Mar 2019 13:10:39 +0100 Subject: [PATCH] build: update to typescript 3.2 Updates to TypeScript 3.2 and fixes some compilation errors. --- package.json | 2 +- .../attributeSelectorsStylesheetRule.ts | 4 +++- .../attribute-selectors/attributeSelectorsTemplateRule.ts | 4 +++- .../upgrade-rules/class-names/classNamesIdentifierRule.ts | 4 +++- .../css-selectors/cssSelectorsStylesheetRule.ts | 4 +++- .../css-selectors/cssSelectorsTemplateRule.ts | 4 +++- .../element-selectors/elementSelectorsStylesheetRule.ts | 4 +++- .../element-selectors/elementSelectorsTemplateRule.ts | 4 +++- .../upgrade-rules/input-names/inputNamesStylesheetRule.ts | 4 +++- .../upgrade-rules/input-names/inputNamesTemplateRule.ts | 4 +++- .../upgrade-rules/output-names/outputNamesTemplateRule.ts | 4 +++- .../property-names/propertyNamesAccessRule.ts | 4 +++- .../upgrade-rules/signature-check/methodCallsCheckRule.ts | 4 +++- src/cdk/schematics/testing/test-case-setup.ts | 6 +++--- src/cdk/schematics/utils/ast.ts | 7 +++---- src/cdk/schematics/utils/version-agnostic-typescript.ts | 2 +- yarn.lock | 4 ++-- 17 files changed, 46 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index 8f1719d33d31..34c2000fd0c0 100644 --- a/package.json +++ b/package.json @@ -137,7 +137,7 @@ "tsconfig-paths": "^2.3.0", "tslint": "^5.12.0", "tsutils": "^3.0.0", - "typescript": "~3.1.1", + "typescript": "~3.2.0", "uglify-js": "^2.8.14" } } diff --git a/src/cdk/schematics/ng-update/upgrade-rules/attribute-selectors/attributeSelectorsStylesheetRule.ts b/src/cdk/schematics/ng-update/upgrade-rules/attribute-selectors/attributeSelectorsStylesheetRule.ts index df5e61729f0b..d92b02b933bd 100644 --- a/src/cdk/schematics/ng-update/upgrade-rules/attribute-selectors/attributeSelectorsStylesheetRule.ts +++ b/src/cdk/schematics/ng-update/upgrade-rules/attribute-selectors/attributeSelectorsStylesheetRule.ts @@ -9,6 +9,8 @@ import {green, red} from 'chalk'; import {IOptions, Replacement, RuleFailure, Rules} from 'tslint'; import * as ts from 'typescript'; + +import {AttributeSelectorUpgradeData} from '../../data'; import {ExternalResource} from '../../tslint/component-file'; import {ComponentWalker} from '../../tslint/component-walker'; import {findAllSubstringIndices} from '../../typescript/literal'; @@ -28,7 +30,7 @@ export class Rule extends Rules.AbstractRule { export class Walker extends ComponentWalker { /** Change data that upgrades to the specified target version. */ - data = getUpgradeDataFromWalker(this, 'attributeSelectors'); + data: AttributeSelectorUpgradeData[] = getUpgradeDataFromWalker(this, 'attributeSelectors'); constructor(sourceFile: ts.SourceFile, options: IOptions) { super(sourceFile, options); diff --git a/src/cdk/schematics/ng-update/upgrade-rules/attribute-selectors/attributeSelectorsTemplateRule.ts b/src/cdk/schematics/ng-update/upgrade-rules/attribute-selectors/attributeSelectorsTemplateRule.ts index b5c36406a085..5892a039573d 100644 --- a/src/cdk/schematics/ng-update/upgrade-rules/attribute-selectors/attributeSelectorsTemplateRule.ts +++ b/src/cdk/schematics/ng-update/upgrade-rules/attribute-selectors/attributeSelectorsTemplateRule.ts @@ -9,6 +9,8 @@ import {green, red} from 'chalk'; import {Replacement, RuleFailure, Rules} from 'tslint'; import * as ts from 'typescript'; + +import {AttributeSelectorUpgradeData} from '../../data'; import {ExternalResource} from '../../tslint/component-file'; import {ComponentWalker} from '../../tslint/component-walker'; import {findAllSubstringIndices} from '../../typescript/literal'; @@ -27,7 +29,7 @@ export class Rule extends Rules.AbstractRule { export class Walker extends ComponentWalker { /** Change data that upgrades to the specified target version. */ - data = getUpgradeDataFromWalker(this, 'attributeSelectors'); + data: AttributeSelectorUpgradeData[] = getUpgradeDataFromWalker(this, 'attributeSelectors'); visitInlineTemplate(node: ts.StringLiteralLike) { this._createReplacementsForContent(node, node.getText()).forEach(data => { diff --git a/src/cdk/schematics/ng-update/upgrade-rules/class-names/classNamesIdentifierRule.ts b/src/cdk/schematics/ng-update/upgrade-rules/class-names/classNamesIdentifierRule.ts index 63396cd49136..e5b844885903 100644 --- a/src/cdk/schematics/ng-update/upgrade-rules/class-names/classNamesIdentifierRule.ts +++ b/src/cdk/schematics/ng-update/upgrade-rules/class-names/classNamesIdentifierRule.ts @@ -9,6 +9,8 @@ import {green, red} from 'chalk'; import {RuleFailure, Rules, RuleWalker} from 'tslint'; import * as ts from 'typescript'; + +import {ClassNameUpgradeData} from '../../data'; import { isExportSpecifierNode, isImportSpecifierNode, @@ -34,7 +36,7 @@ export class Rule extends Rules.AbstractRule { export class Walker extends RuleWalker { /** Change data that upgrades to the specified target version. */ - data = getUpgradeDataFromWalker(this, 'classNames'); + data: ClassNameUpgradeData[] = getUpgradeDataFromWalker(this, 'classNames'); /** * List of identifier names that have been imported from `@angular/material` or `@angular/cdk` diff --git a/src/cdk/schematics/ng-update/upgrade-rules/css-selectors/cssSelectorsStylesheetRule.ts b/src/cdk/schematics/ng-update/upgrade-rules/css-selectors/cssSelectorsStylesheetRule.ts index c5f1e9491455..111b4f88daea 100644 --- a/src/cdk/schematics/ng-update/upgrade-rules/css-selectors/cssSelectorsStylesheetRule.ts +++ b/src/cdk/schematics/ng-update/upgrade-rules/css-selectors/cssSelectorsStylesheetRule.ts @@ -9,6 +9,8 @@ import {green, red} from 'chalk'; import {IOptions, Replacement, RuleFailure, Rules} from 'tslint'; import * as ts from 'typescript'; + +import {CssSelectorUpgradeData} from '../../data'; import {ExternalResource} from '../../tslint/component-file'; import {ComponentWalker} from '../../tslint/component-walker'; import {findAllSubstringIndices} from '../../typescript/literal'; @@ -27,7 +29,7 @@ export class Rule extends Rules.AbstractRule { export class Walker extends ComponentWalker { /** Change data that upgrades to the specified target version. */ - data = getUpgradeDataFromWalker(this, 'cssSelectors'); + data: CssSelectorUpgradeData[] = getUpgradeDataFromWalker(this, 'cssSelectors'); constructor(sourceFile: ts.SourceFile, options: IOptions) { super(sourceFile, options); diff --git a/src/cdk/schematics/ng-update/upgrade-rules/css-selectors/cssSelectorsTemplateRule.ts b/src/cdk/schematics/ng-update/upgrade-rules/css-selectors/cssSelectorsTemplateRule.ts index ae4c1924bb0e..906f54bdd1ff 100644 --- a/src/cdk/schematics/ng-update/upgrade-rules/css-selectors/cssSelectorsTemplateRule.ts +++ b/src/cdk/schematics/ng-update/upgrade-rules/css-selectors/cssSelectorsTemplateRule.ts @@ -9,6 +9,8 @@ import {green, red} from 'chalk'; import {Replacement, RuleFailure, Rules} from 'tslint'; import * as ts from 'typescript'; + +import {CssSelectorUpgradeData} from '../../data'; import {ExternalResource} from '../../tslint/component-file'; import {ComponentWalker} from '../../tslint/component-walker'; import {findAllSubstringIndices} from '../../typescript/literal'; @@ -27,7 +29,7 @@ export class Rule extends Rules.AbstractRule { export class Walker extends ComponentWalker { /** Change data that upgrades to the specified target version. */ - data = getUpgradeDataFromWalker(this, 'cssSelectors'); + data: CssSelectorUpgradeData[] = getUpgradeDataFromWalker(this, 'cssSelectors'); visitInlineTemplate(node: ts.StringLiteralLike) { this._createReplacementsForContent(node, node.getText()).forEach(data => { diff --git a/src/cdk/schematics/ng-update/upgrade-rules/element-selectors/elementSelectorsStylesheetRule.ts b/src/cdk/schematics/ng-update/upgrade-rules/element-selectors/elementSelectorsStylesheetRule.ts index 62cc052c4a7d..c2c12a332acb 100644 --- a/src/cdk/schematics/ng-update/upgrade-rules/element-selectors/elementSelectorsStylesheetRule.ts +++ b/src/cdk/schematics/ng-update/upgrade-rules/element-selectors/elementSelectorsStylesheetRule.ts @@ -9,6 +9,8 @@ import {green, red} from 'chalk'; import {IOptions, Replacement, RuleFailure, Rules} from 'tslint'; import * as ts from 'typescript'; + +import {ElementSelectorUpgradeData} from '../../data'; import {ExternalResource} from '../../tslint/component-file'; import {ComponentWalker} from '../../tslint/component-walker'; import {findAllSubstringIndices} from '../../typescript/literal'; @@ -27,7 +29,7 @@ export class Rule extends Rules.AbstractRule { export class Walker extends ComponentWalker { /** Change data that upgrades to the specified target version. */ - data = getUpgradeDataFromWalker(this, 'elementSelectors'); + data: ElementSelectorUpgradeData[] = getUpgradeDataFromWalker(this, 'elementSelectors'); constructor(sourceFile: ts.SourceFile, options: IOptions) { super(sourceFile, options); diff --git a/src/cdk/schematics/ng-update/upgrade-rules/element-selectors/elementSelectorsTemplateRule.ts b/src/cdk/schematics/ng-update/upgrade-rules/element-selectors/elementSelectorsTemplateRule.ts index f2a3ab3ad44e..d4e391154274 100644 --- a/src/cdk/schematics/ng-update/upgrade-rules/element-selectors/elementSelectorsTemplateRule.ts +++ b/src/cdk/schematics/ng-update/upgrade-rules/element-selectors/elementSelectorsTemplateRule.ts @@ -9,6 +9,8 @@ import {green, red} from 'chalk'; import {Replacement, RuleFailure, Rules} from 'tslint'; import * as ts from 'typescript'; + +import {ElementSelectorUpgradeData} from '../../data'; import {ExternalResource} from '../../tslint/component-file'; import {ComponentWalker} from '../../tslint/component-walker'; import {findAllSubstringIndices} from '../../typescript/literal'; @@ -27,7 +29,7 @@ export class Rule extends Rules.AbstractRule { export class Walker extends ComponentWalker { /** Change data that upgrades to the specified target version. */ - data = getUpgradeDataFromWalker(this, 'elementSelectors'); + data: ElementSelectorUpgradeData[] = getUpgradeDataFromWalker(this, 'elementSelectors'); visitInlineTemplate(node: ts.StringLiteralLike) { this._createReplacementsForContent(node, node.getText()).forEach(data => { diff --git a/src/cdk/schematics/ng-update/upgrade-rules/input-names/inputNamesStylesheetRule.ts b/src/cdk/schematics/ng-update/upgrade-rules/input-names/inputNamesStylesheetRule.ts index 71cec67710c9..10d3c2a6a8c3 100644 --- a/src/cdk/schematics/ng-update/upgrade-rules/input-names/inputNamesStylesheetRule.ts +++ b/src/cdk/schematics/ng-update/upgrade-rules/input-names/inputNamesStylesheetRule.ts @@ -9,6 +9,8 @@ import {green, red} from 'chalk'; import {IOptions, Replacement, RuleFailure, Rules} from 'tslint'; import * as ts from 'typescript'; + +import {InputNameUpgradeData} from '../../data'; import {ExternalResource} from '../../tslint/component-file'; import {ComponentWalker} from '../../tslint/component-walker'; import {findAllSubstringIndices} from '../../typescript/literal'; @@ -32,7 +34,7 @@ export class Rule extends Rules.AbstractRule { export class Walker extends ComponentWalker { /** Change data that upgrades to the specified target version. */ - data = getUpgradeDataFromWalker(this, 'inputNames'); + data: InputNameUpgradeData[] = getUpgradeDataFromWalker(this, 'inputNames'); constructor(sourceFile: ts.SourceFile, options: IOptions) { super(sourceFile, options); diff --git a/src/cdk/schematics/ng-update/upgrade-rules/input-names/inputNamesTemplateRule.ts b/src/cdk/schematics/ng-update/upgrade-rules/input-names/inputNamesTemplateRule.ts index fcead6b8b87c..4edbdc7526e2 100644 --- a/src/cdk/schematics/ng-update/upgrade-rules/input-names/inputNamesTemplateRule.ts +++ b/src/cdk/schematics/ng-update/upgrade-rules/input-names/inputNamesTemplateRule.ts @@ -9,6 +9,8 @@ import {green, red} from 'chalk'; import {Replacement, RuleFailure, Rules} from 'tslint'; import * as ts from 'typescript'; + +import {InputNameUpgradeData} from '../../data'; import {findInputsOnElementWithAttr, findInputsOnElementWithTag} from '../../html-parsing/angular'; import {ExternalResource} from '../../tslint/component-file'; import {ComponentWalker} from '../../tslint/component-walker'; @@ -27,7 +29,7 @@ export class Rule extends Rules.AbstractRule { export class Walker extends ComponentWalker { /** Change data that upgrades to the specified target version. */ - data = getUpgradeDataFromWalker(this, 'inputNames'); + data: InputNameUpgradeData[] = getUpgradeDataFromWalker(this, 'inputNames'); visitInlineTemplate(node: ts.StringLiteralLike) { this._createReplacementsForContent(node, node.getText()).forEach(data => { diff --git a/src/cdk/schematics/ng-update/upgrade-rules/output-names/outputNamesTemplateRule.ts b/src/cdk/schematics/ng-update/upgrade-rules/output-names/outputNamesTemplateRule.ts index b23d184f500a..a5a23f59188f 100644 --- a/src/cdk/schematics/ng-update/upgrade-rules/output-names/outputNamesTemplateRule.ts +++ b/src/cdk/schematics/ng-update/upgrade-rules/output-names/outputNamesTemplateRule.ts @@ -9,6 +9,8 @@ import {green, red} from 'chalk'; import {Replacement, RuleFailure, Rules} from 'tslint'; import * as ts from 'typescript'; + +import {OutputNameUpgradeData} from '../../data'; import { findOutputsOnElementWithAttr, findOutputsOnElementWithTag, @@ -30,7 +32,7 @@ export class Rule extends Rules.AbstractRule { export class Walker extends ComponentWalker { /** Change data that upgrades to the specified target version. */ - data = getUpgradeDataFromWalker(this, 'outputNames'); + data: OutputNameUpgradeData[] = getUpgradeDataFromWalker(this, 'outputNames'); visitInlineTemplate(node: ts.StringLiteralLike) { this._createReplacementsForContent(node, node.getText()).forEach(data => { diff --git a/src/cdk/schematics/ng-update/upgrade-rules/property-names/propertyNamesAccessRule.ts b/src/cdk/schematics/ng-update/upgrade-rules/property-names/propertyNamesAccessRule.ts index 19ab3a6821aa..7f131c6c8c0b 100644 --- a/src/cdk/schematics/ng-update/upgrade-rules/property-names/propertyNamesAccessRule.ts +++ b/src/cdk/schematics/ng-update/upgrade-rules/property-names/propertyNamesAccessRule.ts @@ -9,6 +9,8 @@ import {green, red} from 'chalk'; import {ProgramAwareRuleWalker, RuleFailure, Rules} from 'tslint'; import * as ts from 'typescript'; + +import {PropertyNameUpgradeData} from '../../data'; import {getUpgradeDataFromWalker} from '../../upgrade-data'; /** @@ -24,7 +26,7 @@ export class Rule extends Rules.TypedRule { export class Walker extends ProgramAwareRuleWalker { /** Change data that upgrades to the specified target version. */ - data = getUpgradeDataFromWalker(this, 'propertyNames'); + data: PropertyNameUpgradeData[] = getUpgradeDataFromWalker(this, 'propertyNames'); visitPropertyAccessExpression(node: ts.PropertyAccessExpression) { const hostType = this.getTypeChecker().getTypeAtLocation(node.expression); diff --git a/src/cdk/schematics/ng-update/upgrade-rules/signature-check/methodCallsCheckRule.ts b/src/cdk/schematics/ng-update/upgrade-rules/signature-check/methodCallsCheckRule.ts index 8a6bb14dd334..f395b12f2316 100644 --- a/src/cdk/schematics/ng-update/upgrade-rules/signature-check/methodCallsCheckRule.ts +++ b/src/cdk/schematics/ng-update/upgrade-rules/signature-check/methodCallsCheckRule.ts @@ -9,6 +9,8 @@ import {bold} from 'chalk'; import {ProgramAwareRuleWalker, RuleFailure, Rules} from 'tslint'; import * as ts from 'typescript'; + +import {MethodCallUpgradeData} from '../../data'; import {getUpgradeDataFromWalker} from '../../upgrade-data'; /** @@ -24,7 +26,7 @@ export class Rule extends Rules.TypedRule { export class Walker extends ProgramAwareRuleWalker { /** Change data that upgrades to the specified target version. */ - data = getUpgradeDataFromWalker(this, 'methodCallChecks'); + data: MethodCallUpgradeData[] = getUpgradeDataFromWalker(this, 'methodCallChecks'); visitCallExpression(node: ts.CallExpression) { if (ts.isPropertyAccessExpression(node.expression)) { diff --git a/src/cdk/schematics/testing/test-case-setup.ts b/src/cdk/schematics/testing/test-case-setup.ts index e97797e73db0..735e48742e34 100644 --- a/src/cdk/schematics/testing/test-case-setup.ts +++ b/src/cdk/schematics/testing/test-case-setup.ts @@ -9,8 +9,8 @@ import {getSystemPath, normalize} from '@angular-devkit/core'; import {TempScopedNodeJsSyncHost} from '@angular-devkit/core/node/testing'; import * as virtualFs from '@angular-devkit/core/src/virtual-fs/host'; -import {SchematicTestRunner} from '@angular-devkit/schematics/testing'; -import {mkdirpSync, readFileSync, writeFileSync, removeSync} from 'fs-extra'; +import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing'; +import {mkdirpSync, readFileSync, removeSync, writeFileSync} from 'fs-extra'; import {sync as globSync} from 'glob'; import {dirname, join, extname, basename, relative, sep} from 'path'; import {createTestApp, runPostScheduledTasks} from '../testing'; @@ -32,7 +32,7 @@ export function readFileContent(filePath: string): string { */ export function createFileSystemTestApp(runner: SchematicTestRunner) { const tempFileSystemHost = new TempScopedNodeJsSyncHost(); - const appTree = createTestApp(runner, {name: 'cdk-testing'}); + const appTree: UnitTestTree = createTestApp(runner, {name: 'cdk-testing'}); const tempPath = getSystemPath(tempFileSystemHost.root); // Since the TSLint fix task expects all files to be present on the real file system, we diff --git a/src/cdk/schematics/utils/ast.ts b/src/cdk/schematics/utils/ast.ts index 07822261ccd6..ef067b766b59 100644 --- a/src/cdk/schematics/utils/ast.ts +++ b/src/cdk/schematics/utils/ast.ts @@ -15,17 +15,16 @@ import {getWorkspace} from '@schematics/angular/utility/config'; import {findModuleFromOptions as internalFindModule} from '@schematics/angular/utility/find-module'; import {getAppModulePath} from '@schematics/angular/utility/ng-ast-utils'; import {getProjectMainFile} from './project-main-file'; -import {ts} from './version-agnostic-typescript'; +import {ts, typescript} from './version-agnostic-typescript'; /** Reads file given path and returns TypeScript source file. */ -export function getSourceFile(host: Tree, path: string) { +export function getSourceFile(host: Tree, path: string): typescript.SourceFile { const buffer = host.read(path); if (!buffer) { throw new SchematicsException(`Could not find file for path: ${path}`); } - const content = buffer.toString(); - return ts.createSourceFile(path, content, ts.ScriptTarget.Latest, true); + return ts.createSourceFile(path, buffer.toString(), ts.ScriptTarget.Latest, true); } /** Import and add module to root app module. */ diff --git a/src/cdk/schematics/utils/version-agnostic-typescript.ts b/src/cdk/schematics/utils/version-agnostic-typescript.ts index 821fca983886..2facf19edb27 100644 --- a/src/cdk/schematics/utils/version-agnostic-typescript.ts +++ b/src/cdk/schematics/utils/version-agnostic-typescript.ts @@ -36,4 +36,4 @@ try { } } -export {ts}; +export {ts, typescript}; diff --git a/yarn.lock b/yarn.lock index fa1d3c3b84b2..8883166853f2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10504,7 +10504,7 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -typescript@3.2.4: +typescript@3.2.4, typescript@~3.2.0: version "3.2.4" resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.2.4.tgz#c585cb952912263d915b462726ce244ba510ef3d" integrity sha512-0RNDbSdEokBeEAkgNbxJ+BLwSManFy9TeXz8uW+48j/xhEXv1ePME60olyzw2XzUqUBNAYFeJadIqAgNqIACwg== @@ -10514,7 +10514,7 @@ typescript@^3.2.2: resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.2.2.tgz#fe8101c46aa123f8353523ebdcf5730c2ae493e5" integrity sha512-VCj5UiSyHBjwfYacmDuc/NOk4QQixbE+Wn7MFJuS0nRuPQbof132Pw4u53dm264O8LPc2MVsc7RJNml5szurkg== -typescript@~3.1.1, typescript@~3.1.6: +typescript@~3.1.6: version "3.1.6" resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.1.6.tgz#b6543a83cfc8c2befb3f4c8fba6896f5b0c9be68" integrity sha512-tDMYfVtvpb96msS1lDX9MEdHrW4yOuZ4Kdc4Him9oU796XldPYF/t2+uKoX0BBa0hXXwDlqYQbXY5Rzjzc5hBA==