Skip to content

build: update to typescript 3.2 #15587

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

Merged
merged 1 commit into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand All @@ -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)) {
Expand Down
6 changes: 3 additions & 3 deletions src/cdk/schematics/testing/test-case-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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
Expand Down
7 changes: 3 additions & 4 deletions src/cdk/schematics/utils/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/schematics/utils/version-agnostic-typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ try {
}
}

export {ts};
export {ts, typescript};
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to export the typescript thing here? Shouldn't everything just use the agnostic TypeScript version which is also typed?

Copy link
Member Author

Choose a reason for hiding this comment

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

My understanding is that the ts and the typescript refer to two different namespaces. ts didn't have SourceFile which we needed.

Copy link
Member

@devversion devversion Mar 25, 2019

Choose a reason for hiding this comment

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

The ts object should be typed with typeof typescript but I could see that this one omits the actual types as it's not declared as namespace. Though it feels ambiguous to export ts and typescript.

Why can't we just rely on the implicit type from ts.createSourceFile? I don't bother too much, but there is definitely some ambiguity now. If you want to explicitly type it, how about just importing typescript there and type it from there? We just need to use the agnostic TS version at runtime

Copy link
Member Author

Choose a reason for hiding this comment

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

We can't let it infer the type from createSourceFile, because Bazel was throwing an error about a dependency being brought in implicitly.

Copy link
Member

@devversion devversion Mar 25, 2019

Choose a reason for hiding this comment

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

hmm. There should be no change of transitive dependencies with the current changes. I'm okay getting it in like that. I can just explore cleaning up the ambiguous export in a follow-up then.

4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10504,7 +10504,7 @@ typedarray@^0.0.6:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=

[email protected]:
[email protected], 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==
Expand All @@ -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==
Expand Down