build: upgrade to TypeScript 2.7 (#22669)

Fixes: #21571

PR Close #22669
This commit is contained in:
Chuck Jazdzewski 2018-02-08 08:59:25 -08:00 committed by Kara Erickson
parent a225b48482
commit 8449eb8d62
30 changed files with 222 additions and 162 deletions

View File

@ -43,6 +43,6 @@
"protractor": "~5.1.2",
"ts-node": "~4.1.0",
"tslint": "~5.9.1",
"typescript": "2.4.2"
"typescript": "file:../../node_modules/typescript"
}
}

View File

@ -28,9 +28,9 @@
rxjs "^5.5.6"
"@angular/animations@file:../../dist/packages-dist/animations":
version "6.0.0-beta.1-b36cc7db7"
version "6.0.0-beta.7-2027ec8895"
dependencies:
tslib "^1.7.1"
tslib "^1.9.0"
"@angular/cli@1.6.6":
version "1.6.6"
@ -97,55 +97,55 @@
node-sass "^4.7.2"
"@angular/common@file:../../dist/packages-dist/common":
version "6.0.0-beta.1-b36cc7db7"
version "6.0.0-beta.7-2027ec8895"
dependencies:
tslib "^1.7.1"
tslib "^1.9.0"
"@angular/compiler-cli@file:../../dist/packages-dist/compiler-cli":
version "6.0.0-beta.1-b36cc7db7"
version "6.0.0-beta.7-2027ec8895"
dependencies:
chokidar "^1.4.2"
minimist "^1.2.0"
reflect-metadata "^0.1.2"
tsickle "^0.26.0"
tsickle "^0.27.2"
"@angular/compiler@file:../../dist/packages-dist/compiler":
version "6.0.0-beta.1-b36cc7db7"
version "6.0.0-beta.7-2027ec8895"
dependencies:
tslib "^1.7.1"
tslib "^1.9.0"
"@angular/core@file:../../dist/packages-dist/core":
version "6.0.0-beta.1-b36cc7db7"
version "6.0.0-beta.7-2027ec8895"
dependencies:
tslib "^1.7.1"
tslib "^1.9.0"
"@angular/forms@file:../../dist/packages-dist/forms":
version "6.0.0-beta.1-b36cc7db7"
version "6.0.0-beta.7-2027ec8895"
dependencies:
tslib "^1.7.1"
tslib "^1.9.0"
"@angular/http@file:../../dist/packages-dist/http":
version "6.0.0-beta.1-b36cc7db7"
version "6.0.0-beta.7-2027ec8895"
dependencies:
tslib "^1.7.1"
tslib "^1.9.0"
"@angular/language-service@file:../../dist/packages-dist/language-service":
version "6.0.0-beta.1-b36cc7db7"
version "6.0.0-beta.7-2027ec8895"
"@angular/platform-browser-dynamic@file:../../dist/packages-dist/platform-browser-dynamic":
version "6.0.0-beta.1-b36cc7db7"
version "6.0.0-beta.7-2027ec8895"
dependencies:
tslib "^1.7.1"
tslib "^1.9.0"
"@angular/platform-browser@file:../../dist/packages-dist/platform-browser":
version "6.0.0-beta.1-b36cc7db7"
version "6.0.0-beta.7-2027ec8895"
dependencies:
tslib "^1.7.1"
tslib "^1.9.0"
"@angular/router@file:../../dist/packages-dist/router":
version "6.0.0-beta.1-b36cc7db7"
version "6.0.0-beta.7-2027ec8895"
dependencies:
tslib "^1.7.1"
tslib "^1.9.0"
"@ngtools/json-schema@1.1.0", "@ngtools/json-schema@^1.1.0":
version "1.1.0"
@ -6366,7 +6366,7 @@ source-map-resolve@^0.5.0:
source-map-url "^0.4.0"
urix "^0.1.0"
source-map-support@^0.4.1, source-map-support@^0.4.2, source-map-support@~0.4.0:
source-map-support@^0.4.1, source-map-support@~0.4.0:
version "0.4.18"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.18.tgz#0286a6de8be42641338594e97ccea75f0a2c585f"
dependencies:
@ -6854,16 +6854,16 @@ tsconfig@^7.0.0:
strip-bom "^3.0.0"
strip-json-comments "^2.0.0"
tsickle@^0.26.0:
version "0.26.0"
resolved "https://registry.yarnpkg.com/tsickle/-/tsickle-0.26.0.tgz#40b30a2dd6abcb33b182e37596674bd1cfe4039c"
tsickle@^0.27.2:
version "0.27.2"
resolved "https://registry.yarnpkg.com/tsickle/-/tsickle-0.27.2.tgz#f33d46d046f73dd5c155a37922e422816e878736"
dependencies:
minimist "^1.2.0"
mkdirp "^0.5.1"
source-map "^0.5.6"
source-map-support "^0.4.2"
source-map "^0.6.0"
source-map-support "^0.5.0"
tslib@^1.7.1, tslib@^1.8.0, tslib@^1.8.1:
tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.0:
version "1.9.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.0.tgz#e37a86fda8cbbaf23a057f473c9f4dc64e5fc2e8"
@ -6929,9 +6929,8 @@ typedarray@^0.0.6, typedarray@~0.0.5:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
typescript@2.4.2:
version "2.4.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.4.2.tgz#f8395f85d459276067c988aa41837a8f82870844"
"typescript@file:../../node_modules/typescript":
version "2.7.2"
typescript@~2.6.2:
version "2.6.2"

View File

@ -28,7 +28,7 @@
"dependencies": {
"core-js": "^2.4.1",
"reflect-metadata": "^0.1.3",
"rxjs": "5.5.5",
"rxjs": "5.5.6",
"tslib": "^1.7.1",
"zone.js": "^0.8.12"
},
@ -104,7 +104,7 @@
"tslint": "5.7.0",
"tslint-eslint-rules": "4.1.1",
"tsutils": "2.20.0",
"typescript": "2.6.x",
"typescript": "2.7.x",
"uglify-js": "2.8.29",
"universal-analytics": "0.4.15",
"vlq": "0.2.2",

View File

@ -13,7 +13,7 @@
},
"peerDependencies": {
"@angular/compiler-cli": "0.0.0-PLACEHOLDER",
"typescript": ">=2.4.2 <2.7"
"typescript": ">=2.7.2 <2.8"
},
"repository": {
"type": "git",

View File

@ -15,7 +15,7 @@
"chokidar": "^1.4.2"
},
"peerDependencies": {
"typescript": ">=2.4.2 <2.7",
"typescript": ">=2.7.2 <2.8",
"@angular/compiler": "0.0.0-PLACEHOLDER"
},
"repository": {

View File

@ -46,7 +46,9 @@ export function getClassMembers(
if (declaration) {
const type = checker.getTypeAtLocation(declaration);
const node = program.getSourceFile(staticSymbol.filePath);
return new TypeWrapper(type, {node, program, checker}).members();
if (node) {
return new TypeWrapper(type, {node, program, checker}).members();
}
}
}

View File

@ -190,9 +190,12 @@ export function getExpressionLoweringTransformFactory(
// Return the factory
return (context: ts.TransformationContext) => (sourceFile: ts.SourceFile): ts.SourceFile => {
// We need to use the original SourceFile for reading metadata, and not the transformed one.
const requests = requestsMap.getRequests(program.getSourceFile(sourceFile.fileName));
if (requests && requests.size) {
return transformSourceFile(sourceFile, requests, context);
const originalFile = program.getSourceFile(sourceFile.fileName);
if (originalFile) {
const requests = requestsMap.getRequests(originalFile);
if (requests && requests.size) {
return transformSourceFile(sourceFile, requests, context);
}
}
return sourceFile;
};

View File

@ -73,9 +73,9 @@ class AngularCompilerProgram implements Program {
private host: CompilerHost, oldProgram?: Program) {
this.rootNames = [...rootNames];
if (ts.version < '2.4.2' || (ts.version >= '2.7.0' && !options.disableTypeScriptVersionCheck)) {
if (ts.version < '2.7.2' || (ts.version >= '2.8.0' && !options.disableTypeScriptVersionCheck)) {
throw new Error(
`The Angular Compiler requires TypeScript >=2.4.2 and <2.7 but ${ts.version} was found instead.`);
`The Angular Compiler requires TypeScript >=2.7.2 and <2.8.0 but ${ts.version} was found instead.`);
}
this.oldTsProgram = oldProgram ? oldProgram.getTsProgram() : undefined;
@ -304,7 +304,10 @@ class AngularCompilerProgram implements Program {
genFile = genFileByFileName.get(sourceFile.fileName);
if (!sourceFile.isDeclarationFile && !GENERATED_FILES.test(sourceFile.fileName)) {
// Note: sourceFile is the transformed sourcefile, not the original one!
emittedSourceFiles.push(this.tsProgram.getSourceFile(sourceFile.fileName));
const originalFile = this.tsProgram.getSourceFile(sourceFile.fileName);
if (originalFile) {
emittedSourceFiles.push(originalFile);
}
}
}
this.writeFile(outFileName, outData, writeByteOrderMark, onError, genFile, sourceFiles);

View File

@ -240,16 +240,18 @@ export function getDiagnosticTemplateInfo(
const members = getClassMembers(context.program, context.checker, type);
if (members) {
const sourceFile = context.program.getSourceFile(type.filePath);
const query = getSymbolQuery(
context.program, context.checker, sourceFile,
() =>
getPipesTable(sourceFile, context.program, context.checker, compiledTemplate.pipes));
return {
fileName: templateFile,
offset: 0, query, members,
htmlAst: compiledTemplate.htmlAst,
templateAst: compiledTemplate.templateAst
};
if (sourceFile) {
const query = getSymbolQuery(
context.program, context.checker, sourceFile,
() => getPipesTable(
sourceFile, context.program, context.checker, compiledTemplate.pipes));
return {
fileName: templateFile,
offset: 0, query, members,
htmlAst: compiledTemplate.htmlAst,
templateAst: compiledTemplate.templateAst
};
}
}
}
}

View File

@ -41,7 +41,7 @@ describe('symbol query', () => {
const service = ts.createLanguageService(host, registry);
program = service.getProgram();
checker = program.getTypeChecker();
sourceFile = program.getSourceFile('/quickstart/app/app.component.ts');
sourceFile = program.getSourceFile('/quickstart/app/app.component.ts') !;
const options: CompilerOptions = Object.create(host.getCompilationSettings());
options.genDir = '/dist';
options.basePath = '/quickstart';

View File

@ -47,13 +47,13 @@ describe('Collector', () => {
it('should not have errors in test data', () => { expectValidSources(service, program); });
it('should return undefined for modules that have no metadata', () => {
const sourceFile = program.getSourceFile('app/empty.ts');
const sourceFile = program.getSourceFile('app/empty.ts') !;
const metadata = collector.getMetadata(sourceFile);
expect(metadata).toBeUndefined();
});
it('should treat all symbols of .d.ts files as exported', () => {
const sourceFile = program.getSourceFile('declarations.d.ts');
const sourceFile = program.getSourceFile('declarations.d.ts') !;
const metadata = collector.getMetadata(sourceFile);
expect(metadata).toEqual({
__symbolic: 'module',
@ -66,7 +66,7 @@ describe('Collector', () => {
});
it('should return an interface reference for types', () => {
const sourceFile = program.getSourceFile('/exported-type.ts');
const sourceFile = program.getSourceFile('/exported-type.ts') !;
const metadata = collector.getMetadata(sourceFile);
expect(metadata).toEqual({
__symbolic: 'module',
@ -76,7 +76,7 @@ describe('Collector', () => {
});
it('should return an interface reference for interfaces', () => {
const sourceFile = program.getSourceFile('app/hero.ts');
const sourceFile = program.getSourceFile('app/hero.ts') !;
const metadata = collector.getMetadata(sourceFile);
expect(metadata).toEqual({
__symbolic: 'module',
@ -86,13 +86,13 @@ describe('Collector', () => {
});
it('should preserve module names from TypeScript sources', () => {
const sourceFile = program.getSourceFile('named-module.d.ts');
const sourceFile = program.getSourceFile('named-module.d.ts') !;
const metadata = collector.getMetadata(sourceFile);
expect(metadata !['importAs']).toEqual('some-named-module');
});
it('should be able to collect a simple component\'s metadata', () => {
const sourceFile = program.getSourceFile('app/hero-detail.component.ts');
const sourceFile = program.getSourceFile('app/hero-detail.component.ts') !;
const metadata = collector.getMetadata(sourceFile);
expect(metadata).toEqual({
__symbolic: 'module',
@ -144,7 +144,7 @@ describe('Collector', () => {
});
it('should be able to get a more complicated component\'s metadata', () => {
const sourceFile = program.getSourceFile('/app/app.component.ts');
const sourceFile = program.getSourceFile('/app/app.component.ts') !;
const metadata = collector.getMetadata(sourceFile);
expect(metadata).toEqual({
__symbolic: 'module',
@ -236,7 +236,7 @@ describe('Collector', () => {
});
it('should return the values of exported variables', () => {
const sourceFile = program.getSourceFile('/app/mock-heroes.ts');
const sourceFile = program.getSourceFile('/app/mock-heroes.ts') !;
const metadata = collector.getMetadata(sourceFile);
expect(metadata).toEqual({
__symbolic: 'module',
@ -262,7 +262,7 @@ describe('Collector', () => {
let casesMetadata: ModuleMetadata;
beforeEach(() => {
casesFile = program.getSourceFile('/app/cases-data.ts');
casesFile = program.getSourceFile('/app/cases-data.ts') !;
casesMetadata = collector.getMetadata(casesFile) !;
});
@ -322,7 +322,7 @@ describe('Collector', () => {
});
it('should report errors for destructured imports', () => {
const unsupported1 = program.getSourceFile('/unsupported-1.ts');
const unsupported1 = program.getSourceFile('/unsupported-1.ts') !;
const metadata = collector.getMetadata(unsupported1);
expect(metadata).toEqual({
__symbolic: 'module',
@ -338,7 +338,7 @@ describe('Collector', () => {
});
it('should report an error for references to unexpected types', () => {
const unsupported1 = program.getSourceFile('/unsupported-2.ts');
const unsupported1 = program.getSourceFile('/unsupported-2.ts') !;
const metadata = collector.getMetadata(unsupported1) !;
const barClass = <ClassMetadata>metadata.metadata['Bar'];
const ctor = <ConstructorMetadata>barClass.members !['__ctor__'][0];
@ -353,7 +353,7 @@ describe('Collector', () => {
});
it('should be able to handle import star type references', () => {
const importStar = program.getSourceFile('/import-star.ts');
const importStar = program.getSourceFile('/import-star.ts') !;
const metadata = collector.getMetadata(importStar) !;
const someClass = <ClassMetadata>metadata.metadata['SomeClass'];
const ctor = <ConstructorMetadata>someClass.members !['__ctor__'][0];
@ -364,7 +364,7 @@ describe('Collector', () => {
});
it('should record all exported classes', () => {
const sourceFile = program.getSourceFile('/exported-classes.ts');
const sourceFile = program.getSourceFile('/exported-classes.ts') !;
const metadata = collector.getMetadata(sourceFile);
expect(metadata).toEqual({
__symbolic: 'module',
@ -378,7 +378,7 @@ describe('Collector', () => {
});
it('should be able to record functions', () => {
const exportedFunctions = program.getSourceFile('/exported-functions.ts');
const exportedFunctions = program.getSourceFile('/exported-functions.ts') !;
const metadata = collector.getMetadata(exportedFunctions);
expect(metadata).toEqual({
__symbolic: 'module',
@ -438,7 +438,7 @@ describe('Collector', () => {
});
it('should be able to handle import star type references', () => {
const importStar = program.getSourceFile('/import-star.ts');
const importStar = program.getSourceFile('/import-star.ts') !;
const metadata = collector.getMetadata(importStar) !;
const someClass = <ClassMetadata>metadata.metadata['SomeClass'];
const ctor = <ConstructorMetadata>someClass.members !['__ctor__'][0];
@ -449,14 +449,14 @@ describe('Collector', () => {
});
it('should be able to collect the value of an enum', () => {
const enumSource = program.getSourceFile('/exported-enum.ts');
const enumSource = program.getSourceFile('/exported-enum.ts') !;
const metadata = collector.getMetadata(enumSource) !;
const someEnum: any = metadata.metadata['SomeEnum'];
expect(someEnum).toEqual({A: 0, B: 1, C: 100, D: 101});
});
it('should ignore a non-export enum', () => {
const enumSource = program.getSourceFile('/private-enum.ts');
const enumSource = program.getSourceFile('/private-enum.ts') !;
const metadata = collector.getMetadata(enumSource) !;
const publicEnum: any = metadata.metadata['PublicEnum'];
const privateEnum: any = metadata.metadata['PrivateEnum'];
@ -465,7 +465,7 @@ describe('Collector', () => {
});
it('should be able to collect enums initialized from consts', () => {
const enumSource = program.getSourceFile('/exported-enum.ts');
const enumSource = program.getSourceFile('/exported-enum.ts') !;
const metadata = collector.getMetadata(enumSource) !;
const complexEnum: any = metadata.metadata['ComplexEnum'];
expect(complexEnum).toEqual({
@ -484,7 +484,7 @@ describe('Collector', () => {
});
it('should be able to collect a simple static method', () => {
const staticSource = program.getSourceFile('/static-method.ts');
const staticSource = program.getSourceFile('/static-method.ts') !;
const metadata = collector.getMetadata(staticSource) !;
expect(metadata).toBeDefined();
const classData = <ClassMetadata>metadata.metadata['MyModule'];
@ -502,7 +502,7 @@ describe('Collector', () => {
});
it('should be able to collect a call to a static method', () => {
const staticSource = program.getSourceFile('/static-method-call.ts');
const staticSource = program.getSourceFile('/static-method-call.ts') !;
const metadata = collector.getMetadata(staticSource) !;
expect(metadata).toBeDefined();
const classData = <ClassMetadata>metadata.metadata['Foo'];
@ -537,7 +537,7 @@ describe('Collector', () => {
});
it('should be able to collect a static field', () => {
const staticSource = program.getSourceFile('/static-field.ts');
const staticSource = program.getSourceFile('/static-field.ts') !;
const metadata = collector.getMetadata(staticSource) !;
expect(metadata).toBeDefined();
const classData = <ClassMetadata>metadata.metadata['MyModule'];
@ -546,7 +546,7 @@ describe('Collector', () => {
});
it('should be able to collect a reference to a static field', () => {
const staticSource = program.getSourceFile('/static-field-reference.ts');
const staticSource = program.getSourceFile('/static-field-reference.ts') !;
const metadata = collector.getMetadata(staticSource) !;
expect(metadata).toBeDefined();
const classData = <ClassMetadata>metadata.metadata['Foo'];
@ -580,7 +580,7 @@ describe('Collector', () => {
});
it('should be able to collect a method with a conditional expression', () => {
const source = program.getSourceFile('/static-method-with-if.ts');
const source = program.getSourceFile('/static-method-with-if.ts') !;
const metadata = collector.getMetadata(source) !;
expect(metadata).toBeDefined();
const classData = <ClassMetadata>metadata.metadata['MyModule'];
@ -605,7 +605,7 @@ describe('Collector', () => {
});
it('should be able to collect a method with a default parameter', () => {
const source = program.getSourceFile('/static-method-with-default.ts');
const source = program.getSourceFile('/static-method-with-default.ts') !;
const metadata = collector.getMetadata(source) !;
expect(metadata).toBeDefined();
const classData = <ClassMetadata>metadata.metadata['MyModule'];
@ -634,7 +634,7 @@ describe('Collector', () => {
});
it('should be able to collect re-exported symbols', () => {
const source = program.getSourceFile('/re-exports.ts');
const source = program.getSourceFile('/re-exports.ts') !;
const metadata = collector.getMetadata(source) !;
expect(metadata.exports).toEqual([
{from: './static-field', export: ['MyModule']},
@ -644,13 +644,13 @@ describe('Collector', () => {
});
it('should be able to collect a export as symbol', () => {
const source = program.getSourceFile('export-as.d.ts');
const source = program.getSourceFile('export-as.d.ts') !;
const metadata = collector.getMetadata(source) !;
expect(metadata.metadata).toEqual({SomeFunction: {__symbolic: 'function'}});
});
it('should be able to collect exports with no module specifier', () => {
const source = program.getSourceFile('/re-exports-2.ts');
const source = program.getSourceFile('/re-exports-2.ts') !;
const metadata = collector.getMetadata(source) !;
expect(metadata.metadata).toEqual({
MyClass: Object({__symbolic: 'class'}),
@ -672,7 +672,7 @@ describe('Collector', () => {
});
it('should collect an error symbol if collecting a reference to a non-exported symbol', () => {
const source = program.getSourceFile('/local-symbol-ref.ts');
const source = program.getSourceFile('/local-symbol-ref.ts') !;
const metadata = collector.getMetadata(source) !;
expect(metadata.metadata).toEqual({
REQUIRED_VALIDATOR: {
@ -700,7 +700,7 @@ describe('Collector', () => {
});
it('should collect an error symbol if collecting a reference to a non-exported function', () => {
const source = program.getSourceFile('/local-function-ref.ts');
const source = program.getSourceFile('/local-function-ref.ts') !;
const metadata = collector.getMetadata(source) !;
expect(metadata.metadata).toEqual({
REQUIRED_VALIDATOR: {
@ -728,7 +728,7 @@ describe('Collector', () => {
});
it('should collect an error for a simple function that references a local variable', () => {
const source = program.getSourceFile('/local-symbol-ref-func.ts');
const source = program.getSourceFile('/local-symbol-ref-func.ts') !;
const metadata = collector.getMetadata(source) !;
expect(metadata.metadata).toEqual({
foo: {
@ -746,7 +746,7 @@ describe('Collector', () => {
});
it('should collect any for interface parameter reference', () => {
const source = program.getSourceFile('/interface-reference.ts');
const source = program.getSourceFile('/interface-reference.ts') !;
const metadata = collector.getMetadata(source) !;
expect((metadata.metadata['SomeClass'] as ClassMetadata).members).toEqual({
__ctor__: [{
@ -886,24 +886,24 @@ describe('Collector', () => {
describe('in strict mode', () => {
it('should throw if an error symbol is collecting a reference to a non-exported symbol', () => {
const source = program.getSourceFile('/local-symbol-ref.ts');
const source = program.getSourceFile('/local-symbol-ref.ts') !;
expect(() => collector.getMetadata(source, true)).toThrowError(/Reference to a local symbol/);
});
it('should throw if an error if collecting a reference to a non-exported function', () => {
const source = program.getSourceFile('/local-function-ref.ts');
const source = program.getSourceFile('/local-function-ref.ts') !;
expect(() => collector.getMetadata(source, true))
.toThrowError(/Reference to a non-exported function/);
});
it('should throw for references to unexpected types', () => {
const unsupported2 = program.getSourceFile('/unsupported-2.ts');
const unsupported2 = program.getSourceFile('/unsupported-2.ts') !;
expect(() => collector.getMetadata(unsupported2, true))
.toThrowError(/Reference to non-exported class/);
});
it('should throw for errors in a static method', () => {
const unsupported3 = program.getSourceFile('/unsupported-3.ts');
const unsupported3 = program.getSourceFile('/unsupported-3.ts') !;
expect(() => collector.getMetadata(unsupported3, true))
.toThrowError(/Reference to a non-exported class/);
});
@ -913,33 +913,33 @@ describe('Collector', () => {
it('should not throw with a class with no name', () => {
const fileName = '/invalid-class.ts';
override(fileName, 'export class');
const invalidClass = program.getSourceFile(fileName);
const invalidClass = program.getSourceFile(fileName) !;
expect(() => collector.getMetadata(invalidClass)).not.toThrow();
});
it('should not throw with a function with no name', () => {
const fileName = '/invalid-function.ts';
override(fileName, 'export function');
const invalidFunction = program.getSourceFile(fileName);
const invalidFunction = program.getSourceFile(fileName) !;
expect(() => collector.getMetadata(invalidFunction)).not.toThrow();
});
});
describe('inheritance', () => {
it('should record `extends` clauses for declared classes', () => {
const metadata = collector.getMetadata(program.getSourceFile('/class-inheritance.ts')) !;
const metadata = collector.getMetadata(program.getSourceFile('/class-inheritance.ts') !) !;
expect(metadata.metadata['DeclaredChildClass'])
.toEqual({__symbolic: 'class', extends: {__symbolic: 'reference', name: 'ParentClass'}});
});
it('should record `extends` clauses for classes in the same file', () => {
const metadata = collector.getMetadata(program.getSourceFile('/class-inheritance.ts')) !;
const metadata = collector.getMetadata(program.getSourceFile('/class-inheritance.ts') !) !;
expect(metadata.metadata['ChildClassSameFile'])
.toEqual({__symbolic: 'class', extends: {__symbolic: 'reference', name: 'ParentClass'}});
});
it('should record `extends` clauses for classes in a different file', () => {
const metadata = collector.getMetadata(program.getSourceFile('/class-inheritance.ts')) !;
const metadata = collector.getMetadata(program.getSourceFile('/class-inheritance.ts') !) !;
expect(metadata.metadata['ChildClassOtherFile']).toEqual({
__symbolic: 'class',
extends: {
@ -959,7 +959,7 @@ describe('Collector', () => {
}
it('should collect the correct arity for a class', () => {
const metadata = collector.getMetadata(program.getSourceFile('/class-arity.ts')) !;
const metadata = collector.getMetadata(program.getSourceFile('/class-arity.ts') !) !;
const zero = metadata.metadata['Zero'];
if (expectClass(zero)) expect(zero.arity).toBeUndefined();

View File

@ -47,7 +47,7 @@ describe('Evaluator', () => {
});
it('should be able to fold literal expressions', () => {
const consts = program.getSourceFile('consts.ts');
const consts = program.getSourceFile('consts.ts') !;
expect(evaluator.isFoldable(findVarInitializer(consts, 'someName'))).toBeTruthy();
expect(evaluator.isFoldable(findVarInitializer(consts, 'someBool'))).toBeTruthy();
expect(evaluator.isFoldable(findVarInitializer(consts, 'one'))).toBeTruthy();
@ -55,7 +55,7 @@ describe('Evaluator', () => {
});
it('should be able to fold expressions with foldable references', () => {
const expressions = program.getSourceFile('expressions.ts');
const expressions = program.getSourceFile('expressions.ts') !;
symbols.define('someName', 'some-name');
symbols.define('someBool', true);
symbols.define('one', 1);
@ -69,7 +69,7 @@ describe('Evaluator', () => {
});
it('should be able to evaluate literal expressions', () => {
const consts = program.getSourceFile('consts.ts');
const consts = program.getSourceFile('consts.ts') !;
expect(evaluator.evaluateNode(findVarInitializer(consts, 'someName'))).toBe('some-name');
expect(evaluator.evaluateNode(findVarInitializer(consts, 'someBool'))).toBe(true);
expect(evaluator.evaluateNode(findVarInitializer(consts, 'one'))).toBe(1);
@ -77,7 +77,7 @@ describe('Evaluator', () => {
});
it('should be able to evaluate expressions', () => {
const expressions = program.getSourceFile('expressions.ts');
const expressions = program.getSourceFile('expressions.ts') !;
symbols.define('someName', 'some-name');
symbols.define('someBool', true);
symbols.define('one', 1);
@ -124,7 +124,7 @@ describe('Evaluator', () => {
});
it('should report recursive references as symbolic', () => {
const expressions = program.getSourceFile('expressions.ts');
const expressions = program.getSourceFile('expressions.ts') !;
expect(evaluator.evaluateNode(findVarInitializer(expressions, 'recursiveA')))
.toEqual({__symbolic: 'reference', name: 'recursiveB'});
expect(evaluator.evaluateNode(findVarInitializer(expressions, 'recursiveB')))
@ -132,13 +132,13 @@ describe('Evaluator', () => {
});
it('should correctly handle special cases for CONST_EXPR', () => {
const const_expr = program.getSourceFile('const_expr.ts');
const const_expr = program.getSourceFile('const_expr.ts') !;
expect(evaluator.evaluateNode(findVarInitializer(const_expr, 'bTrue'))).toEqual(true);
expect(evaluator.evaluateNode(findVarInitializer(const_expr, 'bFalse'))).toEqual(false);
});
it('should resolve a forwardRef', () => {
const forwardRef = program.getSourceFile('forwardRef.ts');
const forwardRef = program.getSourceFile('forwardRef.ts') !;
expect(evaluator.evaluateNode(findVarInitializer(forwardRef, 'bTrue'))).toEqual(true);
expect(evaluator.evaluateNode(findVarInitializer(forwardRef, 'bFalse'))).toEqual(false);
});
@ -146,7 +146,7 @@ describe('Evaluator', () => {
it('should return new expressions', () => {
symbols.define('Value', {__symbolic: 'reference', module: './classes', name: 'Value'});
evaluator = new Evaluator(symbols, new Map());
const newExpression = program.getSourceFile('newExpression.ts');
const newExpression = program.getSourceFile('newExpression.ts') !;
expect(evaluator.evaluateNode(findVarInitializer(newExpression, 'someValue'))).toEqual({
__symbolic: 'new',
expression:
@ -162,7 +162,7 @@ describe('Evaluator', () => {
});
it('should support referene to a declared module type', () => {
const declared = program.getSourceFile('declared.ts');
const declared = program.getSourceFile('declared.ts') !;
const aDecl = findVar(declared, 'a') !;
expect(evaluator.evaluateNode(aDecl.type !)).toEqual({
__symbolic: 'select',
@ -172,7 +172,7 @@ describe('Evaluator', () => {
});
it('should return errors for unsupported expressions', () => {
const errors = program.getSourceFile('errors.ts');
const errors = program.getSourceFile('errors.ts') !;
const fDecl = findVar(errors, 'f') !;
expect(evaluator.evaluateNode(fDecl.initializer !))
.toEqual({__symbolic: 'error', message: 'Lambda not supported', line: 1, character: 12});
@ -202,14 +202,14 @@ describe('Evaluator', () => {
});
it('should be able to fold an array spread', () => {
const expressions = program.getSourceFile('expressions.ts');
const expressions = program.getSourceFile('expressions.ts') !;
symbols.define('arr', [1, 2, 3, 4]);
const arrSpread = findVar(expressions, 'arrSpread') !;
expect(evaluator.evaluateNode(arrSpread.initializer !)).toEqual([0, 1, 2, 3, 4, 5]);
});
it('should be able to produce a spread expression', () => {
const expressions = program.getSourceFile('expressions.ts');
const expressions = program.getSourceFile('expressions.ts') !;
const arrSpreadRef = findVar(expressions, 'arrSpreadRef') !;
expect(evaluator.evaluateNode(arrSpreadRef.initializer !)).toEqual([
0, {__symbolic: 'spread', expression: {__symbolic: 'reference', name: 'arrImport'}}, 5

View File

@ -43,8 +43,8 @@ describe('Symbols', () => {
host = new Host(FILES, ['consts.ts', 'expressions.ts', 'imports.ts']);
service = ts.createLanguageService(host);
program = service.getProgram();
expressions = program.getSourceFile('expressions.ts');
imports = program.getSourceFile('imports.ts');
expressions = program.getSourceFile('expressions.ts') !;
imports = program.getSourceFile('imports.ts') !;
});
it('should not have syntax errors in the test sources', () => {

View File

@ -104,6 +104,7 @@ export class MockIdentifier extends MockNode implements ts.Identifier {
public text: string;
public escapedText: ts.__String;
// tslint:disable
public _declarationBrand: any;
public _primaryExpressionBrand: any;
public _memberExpressionBrand: any;
public _leftHandSideExpressionBrand: any;

View File

@ -85,6 +85,7 @@ export function setup(): TestSupport {
'experimentalDecorators': true,
'skipLibCheck': true,
'strict': true,
'strictPropertyInitialization': false,
'types': [],
'outDir': path.resolve(basePath, 'built'),
'rootDir': basePath,

View File

@ -192,7 +192,7 @@ function convert(annotatedSource: string) {
const program = ts.createProgram(
[fileName], {module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2017}, host);
const moduleSourceFile = program.getSourceFile(fileName);
const moduleSourceFile = program.getSourceFile(fileName) !;
const transformers: ts.CustomTransformers = {
before: [getExpressionLoweringTransformFactory(
{

View File

@ -446,45 +446,57 @@ describe('ng program', () => {
{rootNames: [path.resolve(testSupport.basePath, 'src/index.ts')], options, host});
program.emit();
const enum ShouldBe { Empty, EmptyExport, NoneEmpty }
function assertGenFile(
fileName: string, checks: {originalFileName: string, shouldBeEmpty: boolean}) {
fileName: string, checks: {originalFileName: string, shouldBe: ShouldBe}) {
const writeData = written.get(path.join(testSupport.basePath, fileName));
expect(writeData).toBeTruthy();
expect(writeData !.original !.some(
sf => sf.fileName === path.join(testSupport.basePath, checks.originalFileName)))
.toBe(true);
if (checks.shouldBeEmpty) {
// The file should only contain comments (the preamble comment added by ngc).
expect(writeData !.data).toMatch(/^(\s*\/\*([^*]|\*[^/])*\*\/\s*)?$/);
} else {
expect(writeData !.data).not.toBe('');
switch (checks.shouldBe) {
case ShouldBe.Empty:
expect(writeData !.data).toMatch(/^(\s*\/\*([^*]|\*[^/])*\*\/\s*)?$/);
break;
case ShouldBe.EmptyExport:
expect(writeData !.data)
.toMatch(/^((\s*\/\*([^*]|\*[^/])*\*\/\s*)|(\s*export\s*{\s*}\s*;\s*)|())$/);
break;
case ShouldBe.NoneEmpty:
expect(writeData !.data).not.toBe('');
break;
}
}
assertGenFile(
'built/src/util.ngfactory.js', {originalFileName: 'src/util.ts', shouldBeEmpty: true});
'built/src/util.ngfactory.js', {originalFileName: 'src/util.ts', shouldBe: ShouldBe.Empty});
assertGenFile(
'built/src/util.ngfactory.d.ts', {originalFileName: 'src/util.ts', shouldBeEmpty: true});
'built/src/util.ngfactory.d.ts',
{originalFileName: 'src/util.ts', shouldBe: ShouldBe.EmptyExport});
assertGenFile(
'built/src/util.ngsummary.js', {originalFileName: 'src/util.ts', shouldBeEmpty: true});
'built/src/util.ngsummary.js', {originalFileName: 'src/util.ts', shouldBe: ShouldBe.Empty});
assertGenFile(
'built/src/util.ngsummary.d.ts', {originalFileName: 'src/util.ts', shouldBeEmpty: true});
'built/src/util.ngsummary.d.ts',
{originalFileName: 'src/util.ts', shouldBe: ShouldBe.EmptyExport});
assertGenFile(
'built/src/util.ngsummary.json', {originalFileName: 'src/util.ts', shouldBeEmpty: false});
'built/src/util.ngsummary.json',
{originalFileName: 'src/util.ts', shouldBe: ShouldBe.NoneEmpty});
// Note: we always fill non shim and shim style files as they might
// be shared by component with and without ViewEncapsulation.
assertGenFile(
'built/src/main.css.ngstyle.js', {originalFileName: 'src/main.ts', shouldBeEmpty: false});
'built/src/main.css.ngstyle.js',
{originalFileName: 'src/main.ts', shouldBe: ShouldBe.NoneEmpty});
assertGenFile(
'built/src/main.css.ngstyle.d.ts', {originalFileName: 'src/main.ts', shouldBeEmpty: true});
'built/src/main.css.ngstyle.d.ts',
{originalFileName: 'src/main.ts', shouldBe: ShouldBe.EmptyExport});
// Note: this file is not empty as we actually generated code for it
assertGenFile(
'built/src/main.css.shim.ngstyle.js',
{originalFileName: 'src/main.ts', shouldBeEmpty: false});
{originalFileName: 'src/main.ts', shouldBe: ShouldBe.NoneEmpty});
assertGenFile(
'built/src/main.css.shim.ngstyle.d.ts',
{originalFileName: 'src/main.ts', shouldBeEmpty: true});
{originalFileName: 'src/main.ts', shouldBe: ShouldBe.EmptyExport});
});
it('should not emit /// references in .d.ts files', () => {

View File

@ -279,7 +279,7 @@ describe('compiler (unbundled Angular)', () => {
};
compile([FILES, angularFiles], {
postCompile: program => {
const factorySource = program.getSourceFile('/app/app.ngfactory.ts');
const factorySource = program.getSourceFile('/app/app.ngfactory.ts') !;
expect(factorySource.text).not.toContain('\'/app/app.ngfactory\'');
}
});

View File

@ -218,7 +218,7 @@ export interface DirectiveDefArgs<T> {
/**
* Factory method used to create an instance of directive.
*/
factory: () => T | [T];
factory: () => T | ({0: T} & any[]); /* trying to say T | [T, ...any] */
/**
* Static attributes to set on host element.

View File

@ -256,7 +256,9 @@ export function _sanitizeHtml(defaultDoc: any, unsafeHtmlInput: string): string
}
function getTemplateContent(el: Node): Node|null {
return 'content' in el && isTemplateElement(el) ? el.content : null;
return 'content' in (el as any /** Microsoft/TypeScript#21517 */) && isTemplateElement(el) ?
el.content :
null;
}
function isTemplateElement(el: Node): el is HTMLTemplateElement {
return el.nodeType === Node.ELEMENT_NODE && el.nodeName === 'TEMPLATE';

View File

@ -41,7 +41,10 @@ export function withBody<T>(html: string, blockFn: T): T {
let returnValue: any = undefined;
if (typeof blockFn === 'function') {
document.body.innerHTML = html;
let blockReturn = blockFn();
// TODO(i): I'm not sure why a cast is required here but otherwise I get
// TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'never' has
// no compatible call signatures.
let blockReturn = (blockFn as any)();
if (blockReturn instanceof Promise) {
blockReturn = blockReturn.then(done, done.fail);
} else {

View File

@ -72,7 +72,13 @@ function angularOnlyFilter(ls: ts.LanguageService): ts.LanguageService {
dispose: () => ls.dispose(),
getApplicableRefactors: (fileName, positionOrRaneg) => <ts.ApplicableRefactorInfo[]>[],
getEditsForRefactor: (fileName, formatOptions, positionOrRange, refactorName, actionName) =>
undefined
undefined,
getDefinitionAndBoundSpan: (fileName: string, position: number):
ts.DefinitionInfoAndBoundSpan =>
({definitions: [], textSpan: {start: 0, length: 0}}),
getCombinedCodeFix:
(scope: ts.CombinedCodeFixScope, fixId: {}, formatOptions: ts.FormatCodeSettings):
ts.CombinedCodeActions => ({changes: [], commands: undefined})
};
}
@ -172,7 +178,11 @@ export function create(info: any /* ts.server.PluginCreateInfo */): ts.LanguageS
getProgram: () => ls.getProgram(),
dispose: () => ls.dispose(),
getApplicableRefactors: tryFilenameOneCall(ls.getApplicableRefactors),
getEditsForRefactor: tryFilenameFourCall(ls.getEditsForRefactor)
getEditsForRefactor: tryFilenameFourCall(ls.getEditsForRefactor),
getDefinitionAndBoundSpan: tryFilenameOneCall(ls.getDefinitionAndBoundSpan),
getCombinedCodeFix:
(scope: ts.CombinedCodeFixScope, fixId: {}, formatOptions: ts.FormatCodeSettings) =>
tryCall(undefined, () => ls.getCombinedCodeFix(scope, fixId, formatOptions))
};
}
@ -300,7 +310,9 @@ export function create(info: any /* ts.server.PluginCreateInfo */): ts.LanguageS
const ours = ls.getDiagnostics(fileName);
if (ours && ours.length) {
const file = oldLS.getProgram().getSourceFile(fileName);
base.push.apply(base, ours.map(d => diagnosticToDiagnostic(d, file)));
if (file) {
base.push.apply(base, ours.map(d => diagnosticToDiagnostic(d, file)));
}
}
});

View File

@ -212,7 +212,7 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
return result;
}
getSourceFile(fileName: string): ts.SourceFile {
getSourceFile(fileName: string): ts.SourceFile|undefined {
return this.tsService.getProgram().getSourceFile(fileName);
}
@ -339,10 +339,12 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
let [declaration, decorator] = this.getTemplateClassDeclFromNode(node);
if (declaration && declaration.name) {
const sourceFile = this.getSourceFile(fileName);
return this.getSourceFromDeclaration(
fileName, version, this.stringOf(node) || '', shrink(spanOf(node)),
this.reflector.getStaticSymbol(sourceFile.fileName, declaration.name.text),
declaration, node, sourceFile);
if (sourceFile) {
return this.getSourceFromDeclaration(
fileName, version, this.stringOf(node) || '', shrink(spanOf(node)),
this.reflector.getStaticSymbol(sourceFile.fileName, declaration.name.text),
declaration, node, sourceFile);
}
}
break;
}

View File

@ -106,7 +106,7 @@ import {el} from '../../../testing/src/browser_util';
};
const manager = new EventManager([domEventPlugin], new FakeNgZone());
let remover = null;
let remover: any = null;
Zone.root.run(() => { remover = manager.addEventListener(element, 'click', handler); });
getDOM().dispatchEvent(element, dispatchedEvent);
expect(receivedEvent).toBe(dispatchedEvent);
@ -136,8 +136,8 @@ import {el} from '../../../testing/src/browser_util';
};
const manager = new EventManager([domEventPlugin], new FakeNgZone());
let remover1 = null;
let remover2 = null;
let remover1: any = null;
let remover2: any = null;
Zone.root.run(() => { remover1 = manager.addEventListener(element, 'click', handler1); });
Zone.root.fork({name: 'test'}).run(() => {
remover2 = manager.addEventListener(element, 'click', handler2);
@ -172,8 +172,8 @@ import {el} from '../../../testing/src/browser_util';
};
const manager = new EventManager([domEventPlugin], new FakeNgZone());
let remover1 = null;
let remover2 = null;
let remover1: any = null;
let remover2: any = null;
Zone.root.run(() => { remover1 = manager.addEventListener(element, 'click', handler1); });
Zone.root.fork({name: 'test'}).run(() => {
remover2 = manager.addEventListener(element, 'click', handler2);
@ -239,8 +239,8 @@ import {el} from '../../../testing/src/browser_util';
};
const manager = new EventManager([domEventPlugin], new FakeNgZone());
let remover1 = null;
let remover2 = null;
let remover1: any = null;
let remover2: any = null;
Zone.root.run(() => { remover1 = manager.addEventListener(element, 'click', handler); });
Zone.root.fork({name: 'test'}).run(() => {
remover2 = manager.addEventListener(element, 'click', handler);
@ -274,8 +274,8 @@ import {el} from '../../../testing/src/browser_util';
};
const manager = new EventManager([domEventPlugin], new FakeNgZone());
let remover1 = null;
let remover2 = null;
let remover1: any = null;
let remover2: any = null;
// handler1 is added in root zone
Zone.root.run(() => { remover1 = manager.addEventListener(element, 'click', handler1); });
// handler2 is added in 'angular' zone

View File

@ -92,10 +92,12 @@ export class MockRequest extends MockBody implements Request {
readonly referrer: string = '';
readonly referrerPolicy: ReferrerPolicy = 'no-referrer';
readonly type: RequestType = '';
readonly signal: AbortSignal = null as any;
url: string;
constructor(input: string|Request, init: RequestInit = {}) {
super(init !== undefined ? init.body || null : null);
super(init !== undefined ? (init.body as(string | null)) || null : null);
if (typeof input !== 'string') {
throw 'Not implemented';
}

View File

@ -8,7 +8,7 @@ set -u -e -o pipefail
# packages, then install them from the resulting .tgz files later.
ANGULAR_PKGS=$(npm pack dist/packages-dist/{common,forms,core,compiler,compiler-cli,platform-{browser,server},platform-browser-dynamic,router,http,animations} | awk "{ printf \"$PWD/\"; print }")
TYPESCRIPT_2_4=typescript@2.4.x
TYPESCRIPT_VERSION=typescript@2.7.2
PKGS=(
reflect-metadata@0.1.8
zone.js@0.8.7
@ -33,7 +33,7 @@ cp -v package.json $TMP
(
cd $TMP
set -ex -o pipefail
npm install ${PKGS[*]} $TYPESCRIPT_2_4
npm install ${PKGS[*]} $TYPESCRIPT_VERSION
npm install ${ANGULAR_PKGS[*]}
./node_modules/.bin/tsc --version

View File

@ -1,7 +1,16 @@
/**
* @license
* Copyright Google Inc. 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
*/
const {set, cd, sed} = require('shelljs');
const path = require('path');
const log = console.log;
console.log('===== about to run the postinstall.js script =====');
log('===== about to run the postinstall.js script =====');
// fail on first error
set('-e');
// print commands as being executed
@ -12,8 +21,9 @@ cd(path.join(__dirname, '../'));
// https://github.com/ReactiveX/rxjs/pull/3302
// make node_modules/rxjs compilable with Typescript 2.7
// remove when we update to rxjs v6
console.log('\n# patch: reactivex/rxjs#3302 make node_modules/rxjs compilable with Typescript 2.7')
sed('-i', "('response' in xhr)", "('response' in (xhr as any))", "node_modules/rxjs/src/observable/dom/AjaxObservable.ts")
log('\n# patch: reactivex/rxjs#3302 make node_modules/rxjs compilable with Typescript 2.7');
sed('-i', '(\'response\' in xhr)', '(\'response\' in (xhr as any))',
'node_modules/rxjs/src/observable/dom/AjaxObservable.ts');
console.log('===== finished running the postinstall.js script =====');
log('===== finished running the postinstall.js script =====');

View File

@ -85,15 +85,21 @@ export declare const VERSION: Version;
export declare const WORKER_APP_LOCATION_PROVIDERS: ({
provide: typeof PlatformLocation;
useClass: typeof WebWorkerPlatformLocation;
useFactory?: undefined;
multi?: undefined;
deps?: undefined;
} | {
provide: InjectionToken<(() => void)[]>;
useFactory: (platformLocation: WebWorkerPlatformLocation, zone: NgZone) => () => Promise<boolean>;
useFactory: typeof appInitFnFactory;
multi: boolean;
deps: (typeof NgZone | typeof PlatformLocation)[];
useClass?: undefined;
} | {
provide: InjectionToken<Promise<any>>;
useFactory: (platformLocation: WebWorkerPlatformLocation) => Promise<any>;
useFactory: typeof locationInitialized;
deps: (typeof PlatformLocation)[];
useClass?: undefined;
multi?: undefined;
})[];
/** @experimental */

View File

@ -2,7 +2,7 @@
export declare const RouterUpgradeInitializer: {
provide: InjectionToken<((compRef: ComponentRef<any>) => void)[]>;
multi: boolean;
useFactory: (ngUpgrade: UpgradeModule) => () => void;
useFactory: typeof locationSyncBootstrapListener;
deps: (typeof UpgradeModule)[];
};

View File

@ -6202,9 +6202,9 @@ rx-lite@^3.1.2:
version "3.1.2"
resolved "https://registry.yarnpkg.com/rx-lite/-/rx-lite-3.1.2.tgz#19ce502ca572665f3b647b10939f97fd1615f102"
rxjs@5.5.5:
version "5.5.5"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-5.5.5.tgz#e164f11d38eaf29f56f08c3447f74ff02dd84e97"
rxjs@5.5.6:
version "5.5.6"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-5.5.6.tgz#e31fb96d6fd2ff1fd84bcea8ae9c02d007179c02"
dependencies:
symbol-observable "1.0.1"
@ -7204,9 +7204,9 @@ typedarray@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
typescript@2.6.x:
version "2.6.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.6.2.tgz#3c5b6fd7f6de0914269027f03c0946758f7673a4"
typescript@2.7.x:
version "2.7.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.7.2.tgz#2d615a1ef4aee4f574425cdff7026edf81919836"
uglify-js@1.2.6, uglify-js@~1.2.5:
version "1.2.6"