build: upgrade to TypeScript 2.7 (#22669)
Fixes: #21571 PR Close #22669
This commit is contained in:

committed by
Kara Erickson

parent
a225b48482
commit
8449eb8d62
@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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';
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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', () => {
|
||||
|
@ -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;
|
||||
|
@ -85,6 +85,7 @@ export function setup(): TestSupport {
|
||||
'experimentalDecorators': true,
|
||||
'skipLibCheck': true,
|
||||
'strict': true,
|
||||
'strictPropertyInitialization': false,
|
||||
'types': [],
|
||||
'outDir': path.resolve(basePath, 'built'),
|
||||
'rootDir': basePath,
|
||||
|
@ -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(
|
||||
{
|
||||
|
@ -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', () => {
|
||||
|
Reference in New Issue
Block a user