style(compiler-cli): reformat of codebase with new clang-format version (#36520)
This commit reformats the packages/compiler-cli tree using the new version of clang-format. PR Close #36520
This commit is contained in:
@ -11,7 +11,7 @@ import * as ts from 'typescript';
|
||||
|
||||
import {MetadataCollector} from '../../src/metadata/collector';
|
||||
import {CompilerHost, CompilerOptions, LibrarySummary} from '../../src/transformers/api';
|
||||
import {TsCompilerAotCompilerTypeCheckHostAdapter, createCompilerHost} from '../../src/transformers/compiler_host';
|
||||
import {createCompilerHost, TsCompilerAotCompilerTypeCheckHostAdapter} from '../../src/transformers/compiler_host';
|
||||
import {Directory, Entry, MockAotContext, MockCompilerHost} from '../mocks';
|
||||
|
||||
const dummyModule = 'export let foo: any[];';
|
||||
@ -53,12 +53,15 @@ describe('NgCompilerHost', () => {
|
||||
} = {}) {
|
||||
return new TsCompilerAotCompilerTypeCheckHostAdapter(
|
||||
rootNames, options, ngHost, new MetadataCollector(), codeGenerator,
|
||||
new Map(librarySummaries.map(entry => [entry.fileName, entry] as[string, LibrarySummary])));
|
||||
new Map(
|
||||
librarySummaries.map(entry => [entry.fileName, entry] as [string, LibrarySummary])));
|
||||
}
|
||||
|
||||
describe('fileNameToModuleName', () => {
|
||||
let host: TsCompilerAotCompilerTypeCheckHostAdapter;
|
||||
beforeEach(() => { host = createHost(); });
|
||||
beforeEach(() => {
|
||||
host = createHost();
|
||||
});
|
||||
|
||||
it('should use a package import when accessing a package from a source file', () => {
|
||||
expect(host.fileNameToModuleName('/tmp/node_modules/@angular/core.d.ts', '/tmp/main.ts'))
|
||||
@ -239,9 +242,8 @@ describe('NgCompilerHost', () => {
|
||||
|
||||
it('should not get tripped on nested node_modules', () => {
|
||||
const genSf = generate('/tmp/node_modules/lib1/node_modules/lib2/thing', {
|
||||
'tmp': {
|
||||
'node_modules': {'lib1': {'node_modules': {'lib2': {'thing.ts': `// some content`}}}}
|
||||
}
|
||||
'tmp':
|
||||
{'node_modules': {'lib1': {'node_modules': {'lib2': {'thing.ts': `// some content`}}}}}
|
||||
});
|
||||
expect(genSf.moduleName).toBe('lib2/thing.ngfactory');
|
||||
});
|
||||
@ -387,8 +389,9 @@ describe('NgCompilerHost', () => {
|
||||
() => host.updateGeneratedFile(new compiler.GeneratedFile(
|
||||
'/tmp/src/index.ts', '/tmp/src/index.ngfactory.ts',
|
||||
[new compiler.DeclareVarStmt(
|
||||
'x', new compiler.ExternalExpr(
|
||||
new compiler.ExternalReference('otherModule', 'aName')))])))
|
||||
'x',
|
||||
new compiler.ExternalExpr(
|
||||
new compiler.ExternalReference('otherModule', 'aName')))])))
|
||||
.toThrowError([
|
||||
`Illegal State: external references changed in /tmp/src/index.ngfactory.ts.`,
|
||||
`Old: aModule.`, `New: otherModule`
|
||||
|
@ -8,8 +8,8 @@
|
||||
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {MetadataCollector, isClassMetadata} from '../../src/metadata/index';
|
||||
import {InlineResourcesMetadataTransformer, getInlineResourcesTransformFactory} from '../../src/transformers/inline_resources';
|
||||
import {isClassMetadata, MetadataCollector} from '../../src/metadata/index';
|
||||
import {getInlineResourcesTransformFactory, InlineResourcesMetadataTransformer} from '../../src/transformers/inline_resources';
|
||||
import {MetadataCache} from '../../src/transformers/metadata_cache';
|
||||
import {MockAotContext, MockCompilerHost} from '../mocks';
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {MetadataCollector, ModuleMetadata} from '../../src/metadata/index';
|
||||
import {LowerMetadataTransform, LoweringRequest, RequestLocationMap, getExpressionLoweringTransformFactory} from '../../src/transformers/lower_expressions';
|
||||
import {getExpressionLoweringTransformFactory, LoweringRequest, LowerMetadataTransform, RequestLocationMap} from '../../src/transformers/lower_expressions';
|
||||
import {MetadataCache} from '../../src/transformers/metadata_cache';
|
||||
import {Directory, MockAotContext, MockCompilerHost} from '../mocks';
|
||||
|
||||
@ -196,14 +196,16 @@ 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(
|
||||
{
|
||||
getRequests(sourceFile: ts.SourceFile): RequestLocationMap{
|
||||
getRequests(sourceFile: ts.SourceFile): RequestLocationMap {
|
||||
if (sourceFile.fileName == moduleSourceFile.fileName) {
|
||||
return requests;
|
||||
} else {return new Map();}
|
||||
} else {
|
||||
return new Map();
|
||||
}
|
||||
}
|
||||
},
|
||||
program)]
|
||||
@ -254,6 +256,7 @@ function collect(annotatedSource: string) {
|
||||
'someName.ts', unannotatedSource, ts.ScriptTarget.Latest, /* setParentNodes */ true);
|
||||
return {
|
||||
metadata: cache.getMetadata(sourceFile),
|
||||
requests: transformer.getRequests(sourceFile), annotations
|
||||
requests: transformer.getRequests(sourceFile),
|
||||
annotations
|
||||
};
|
||||
}
|
@ -23,10 +23,9 @@ describe('metadata reader', () => {
|
||||
readFile: (fileName) => context.readFile(fileName),
|
||||
getSourceFileMetadata: (fileName) => {
|
||||
const sourceText = context.readFile(fileName);
|
||||
return sourceText != null ?
|
||||
metadataCollector.getMetadata(
|
||||
ts.createSourceFile(fileName, sourceText, ts.ScriptTarget.Latest)) :
|
||||
undefined;
|
||||
return sourceText != null ? metadataCollector.getMetadata(ts.createSourceFile(
|
||||
fileName, sourceText, ts.ScriptTarget.Latest)) :
|
||||
undefined;
|
||||
},
|
||||
};
|
||||
});
|
||||
@ -42,11 +41,13 @@ describe('metadata reader', () => {
|
||||
expect(readMetadata('node_modules/@angular/unused.d.ts', host)).toEqual([dummyMetadata]);
|
||||
});
|
||||
|
||||
it('should be able to read empty metadata ',
|
||||
() => { expect(readMetadata('node_modules/@angular/empty.d.ts', host)).toEqual([]); });
|
||||
it('should be able to read empty metadata ', () => {
|
||||
expect(readMetadata('node_modules/@angular/empty.d.ts', host)).toEqual([]);
|
||||
});
|
||||
|
||||
it('should return undefined for missing modules',
|
||||
() => { expect(readMetadata('node_modules/@angular/missing.d.ts', host)).toBeUndefined(); });
|
||||
it('should return undefined for missing modules', () => {
|
||||
expect(readMetadata('node_modules/@angular/missing.d.ts', host)).toBeUndefined();
|
||||
});
|
||||
|
||||
it(`should add missing v${METADATA_VERSION} metadata from v1 metadata and .d.ts files`, () => {
|
||||
expect(readMetadata('metadata_versions/v1.d.ts', host)).toEqual([
|
||||
@ -117,8 +118,8 @@ const FILES: Entry = {
|
||||
'node_modules': {
|
||||
'@angular': {
|
||||
'core.d.ts': dummyModule,
|
||||
'core.metadata.json':
|
||||
`{"__symbolic":"module", "version": ${METADATA_VERSION}, "metadata": {"foo": {"__symbolic": "class"}}}`,
|
||||
'core.metadata.json': `{"__symbolic":"module", "version": ${
|
||||
METADATA_VERSION}, "metadata": {"foo": {"__symbolic": "class"}}}`,
|
||||
'router': {'index.d.ts': dummyModule, 'src': {'providers.d.ts': dummyModule}},
|
||||
'unused.d.ts': dummyModule,
|
||||
'empty.d.ts': 'export declare var a: string;',
|
||||
|
@ -38,7 +38,7 @@ describe('TypeScriptNodeEmitter', () => {
|
||||
});
|
||||
|
||||
function emitStmt(
|
||||
stmt: o.Statement | o.Statement[], format: Format = Format.Flat, preamble?: string): string {
|
||||
stmt: o.Statement|o.Statement[], format: Format = Format.Flat, preamble?: string): string {
|
||||
const stmts = Array.isArray(stmt) ? stmt : [stmt];
|
||||
|
||||
const program = ts.createProgram(
|
||||
@ -246,8 +246,8 @@ describe('TypeScriptNodeEmitter', () => {
|
||||
expect(emitStmt(new o.DeclareFunctionStmt(
|
||||
'someFn', [], [new o.ReturnStatement(o.literal(1))], o.INT_TYPE)))
|
||||
.toEqual(`function someFn() { return 1; }`);
|
||||
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [new o.FnParam('param1', o.INT_TYPE)], [
|
||||
]))).toEqual(`function someFn(param1) { }`);
|
||||
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [new o.FnParam('param1', o.INT_TYPE)], [])))
|
||||
.toEqual(`function someFn(param1) { }`);
|
||||
});
|
||||
|
||||
describe('comments', () => {
|
||||
@ -256,8 +256,9 @@ describe('TypeScriptNodeEmitter', () => {
|
||||
.toBe('/* SomePreamble */ a;');
|
||||
});
|
||||
|
||||
it('should support singleline comments',
|
||||
() => { expect(emitStmt(new o.CommentStmt('Simple comment'))).toBe('// Simple comment'); });
|
||||
it('should support singleline comments', () => {
|
||||
expect(emitStmt(new o.CommentStmt('Simple comment'))).toBe('// Simple comment');
|
||||
});
|
||||
|
||||
it('should support multiline comments', () => {
|
||||
expect(emitStmt(new o.CommentStmt('Multiline comment', true)))
|
||||
@ -314,86 +315,90 @@ describe('TypeScriptNodeEmitter', () => {
|
||||
`try { body(); } catch (error) { var stack = error.stack; catchFn(error, stack); }`);
|
||||
});
|
||||
|
||||
it('should support support throwing',
|
||||
() => { expect(emitStmt(new o.ThrowStmt(someVar))).toEqual('throw someVar;'); });
|
||||
it('should support support throwing', () => {
|
||||
expect(emitStmt(new o.ThrowStmt(someVar))).toEqual('throw someVar;');
|
||||
});
|
||||
|
||||
describe('classes', () => {
|
||||
let callSomeMethod: o.Statement;
|
||||
|
||||
beforeEach(() => { callSomeMethod = o.THIS_EXPR.callMethod('someMethod', []).toStmt(); });
|
||||
beforeEach(() => {
|
||||
callSomeMethod = o.THIS_EXPR.callMethod('someMethod', []).toStmt();
|
||||
});
|
||||
|
||||
|
||||
it('should support declaring classes', () => {
|
||||
expect(emitStmt(new o.ClassStmt('SomeClass', null !, [], [], null !, [
|
||||
]))).toEqual('class SomeClass { }');
|
||||
expect(emitStmt(new o.ClassStmt('SomeClass', null !, [], [], null !, [], [
|
||||
expect(emitStmt(new o.ClassStmt('SomeClass', null!, [], [], null!, [])))
|
||||
.toEqual('class SomeClass { }');
|
||||
expect(emitStmt(new o.ClassStmt('SomeClass', null!, [], [], null!, [], [
|
||||
o.StmtModifier.Exported
|
||||
]))).toEqual('class SomeClass { } exports.SomeClass = SomeClass;');
|
||||
expect(emitStmt(new o.ClassStmt('SomeClass', o.variable('SomeSuperClass'), [], [], null !, [
|
||||
]))).toEqual('class SomeClass extends SomeSuperClass { }');
|
||||
expect(
|
||||
emitStmt(new o.ClassStmt('SomeClass', o.variable('SomeSuperClass'), [], [], null!, [])))
|
||||
.toEqual('class SomeClass extends SomeSuperClass { }');
|
||||
});
|
||||
|
||||
it('should support declaring constructors', () => {
|
||||
const superCall = o.SUPER_EXPR.callFn([o.variable('someParam')]).toStmt();
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [], [], new o.ClassMethod(null !, [], []), [])))
|
||||
expect(emitStmt(
|
||||
new o.ClassStmt('SomeClass', null!, [], [], new o.ClassMethod(null!, [], []), [])))
|
||||
.toEqual(`class SomeClass { constructor() { } }`);
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [], [],
|
||||
new o.ClassMethod(null !, [new o.FnParam('someParam', o.INT_TYPE)], []), [])))
|
||||
'SomeClass', null!, [], [],
|
||||
new o.ClassMethod(null!, [new o.FnParam('someParam', o.INT_TYPE)], []), [])))
|
||||
.toEqual(`class SomeClass { constructor(someParam) { } }`);
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [], [], new o.ClassMethod(null !, [], [superCall]), [])))
|
||||
'SomeClass', null!, [], [], new o.ClassMethod(null!, [], [superCall]), [])))
|
||||
.toEqual(`class SomeClass { constructor() { super(someParam); } }`);
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [], [], new o.ClassMethod(null !, [], [callSomeMethod]), [])))
|
||||
'SomeClass', null!, [], [], new o.ClassMethod(null!, [], [callSomeMethod]), [])))
|
||||
.toEqual(`class SomeClass { constructor() { this.someMethod(); } }`);
|
||||
});
|
||||
|
||||
it('should support declaring fields', () => {
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [new o.ClassField('someField')], [], null !, [])))
|
||||
'SomeClass', null!, [new o.ClassField('someField')], [], null!, [])))
|
||||
.toEqual(`class SomeClass { constructor() { this.someField = null; } }`);
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [new o.ClassField('someField', o.INT_TYPE)], [], null !, [])))
|
||||
'SomeClass', null!, [new o.ClassField('someField', o.INT_TYPE)], [], null!, [])))
|
||||
.toEqual(`class SomeClass { constructor() { this.someField = null; } }`);
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !,
|
||||
[new o.ClassField('someField', o.INT_TYPE, [o.StmtModifier.Private])], [], null !,
|
||||
'SomeClass', null!,
|
||||
[new o.ClassField('someField', o.INT_TYPE, [o.StmtModifier.Private])], [], null!,
|
||||
[])))
|
||||
.toEqual(`class SomeClass { constructor() { this.someField = null; } }`);
|
||||
});
|
||||
|
||||
it('should support declaring getters', () => {
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [], [new o.ClassGetter('someGetter', [])], null !, [])))
|
||||
'SomeClass', null!, [], [new o.ClassGetter('someGetter', [])], null!, [])))
|
||||
.toEqual(`class SomeClass { get someGetter() { } }`);
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [], [new o.ClassGetter('someGetter', [], o.INT_TYPE)], null !,
|
||||
'SomeClass', null!, [], [new o.ClassGetter('someGetter', [], o.INT_TYPE)], null!,
|
||||
[])))
|
||||
.toEqual(`class SomeClass { get someGetter() { } }`);
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [], [new o.ClassGetter('someGetter', [callSomeMethod])],
|
||||
null !, [])))
|
||||
'SomeClass', null!, [], [new o.ClassGetter('someGetter', [callSomeMethod])], null!,
|
||||
[])))
|
||||
.toEqual(`class SomeClass { get someGetter() { this.someMethod(); } }`);
|
||||
expect(
|
||||
emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null !, [],
|
||||
[new o.ClassGetter('someGetter', [], null !, [o.StmtModifier.Private])], null !, [])))
|
||||
'SomeClass', null!, [],
|
||||
[new o.ClassGetter('someGetter', [], null!, [o.StmtModifier.Private])], null!, [])))
|
||||
.toEqual(`class SomeClass { get someGetter() { } }`);
|
||||
});
|
||||
|
||||
it('should support methods', () => {
|
||||
expect(emitStmt(new o.ClassStmt('SomeClass', null !, [], [], null !, [
|
||||
expect(emitStmt(new o.ClassStmt('SomeClass', null!, [], [], null!, [
|
||||
new o.ClassMethod('someMethod', [], [])
|
||||
]))).toEqual(`class SomeClass { someMethod() { } }`);
|
||||
expect(emitStmt(new o.ClassStmt('SomeClass', null !, [], [], null !, [
|
||||
expect(emitStmt(new o.ClassStmt('SomeClass', null!, [], [], null!, [
|
||||
new o.ClassMethod('someMethod', [], [], o.INT_TYPE)
|
||||
]))).toEqual(`class SomeClass { someMethod() { } }`);
|
||||
expect(emitStmt(new o.ClassStmt('SomeClass', null !, [], [], null !, [
|
||||
expect(emitStmt(new o.ClassStmt('SomeClass', null!, [], [], null!, [
|
||||
new o.ClassMethod('someMethod', [new o.FnParam('someParam', o.INT_TYPE)], [])
|
||||
]))).toEqual(`class SomeClass { someMethod(someParam) { } }`);
|
||||
expect(emitStmt(new o.ClassStmt('SomeClass', null !, [], [], null !, [
|
||||
expect(emitStmt(new o.ClassStmt('SomeClass', null!, [], [], null!, [
|
||||
new o.ClassMethod('someMethod', [], [callSomeMethod])
|
||||
]))).toEqual(`class SomeClass { someMethod() { this.someMethod(); } }`);
|
||||
});
|
||||
@ -431,7 +436,7 @@ describe('TypeScriptNodeEmitter', () => {
|
||||
|
||||
it('should support combined types', () => {
|
||||
const writeVarExpr = o.variable('a').set(o.NULL_EXPR);
|
||||
expect(emitStmt(writeVarExpr.toDeclStmt(new o.ArrayType(null !)))).toEqual('var a = null;');
|
||||
expect(emitStmt(writeVarExpr.toDeclStmt(new o.ArrayType(null!)))).toEqual('var a = null;');
|
||||
expect(emitStmt(writeVarExpr.toDeclStmt(new o.ArrayType(o.INT_TYPE)))).toEqual('var a = null;');
|
||||
|
||||
expect(emitStmt(writeVarExpr.toDeclStmt(new o.MapType(null)))).toEqual('var a = null;');
|
||||
@ -439,7 +444,7 @@ describe('TypeScriptNodeEmitter', () => {
|
||||
});
|
||||
|
||||
describe('source maps', () => {
|
||||
function emitStmt(stmt: o.Statement | o.Statement[], preamble?: string): string {
|
||||
function emitStmt(stmt: o.Statement|o.Statement[], preamble?: string): string {
|
||||
const stmts = Array.isArray(stmt) ? stmt : [stmt];
|
||||
|
||||
const program = ts.createProgram(
|
||||
@ -473,13 +478,15 @@ describe('TypeScriptNodeEmitter', () => {
|
||||
function mappingItemsOf(text: string) {
|
||||
// find the source map:
|
||||
const sourceMapMatch = /sourceMappingURL\=data\:application\/json;base64,(.*)$/.exec(text);
|
||||
const sourceMapBase64 = sourceMapMatch ![1];
|
||||
const sourceMapBase64 = sourceMapMatch![1];
|
||||
const sourceMapBuffer = Buffer.from(sourceMapBase64, 'base64');
|
||||
const sourceMapText = sourceMapBuffer.toString('utf8');
|
||||
const sourceMapParsed = JSON.parse(sourceMapText);
|
||||
const consumer = new sourceMap.SourceMapConsumer(sourceMapParsed);
|
||||
const mappings: any[] = [];
|
||||
consumer.eachMapping((mapping: any) => { mappings.push(mapping); });
|
||||
consumer.eachMapping((mapping: any) => {
|
||||
mappings.push(mapping);
|
||||
});
|
||||
return mappings;
|
||||
}
|
||||
|
||||
@ -503,7 +510,7 @@ describe('TypeScriptNodeEmitter', () => {
|
||||
generatedColumn: 0,
|
||||
originalLine: 1,
|
||||
originalColumn: 0,
|
||||
name: null ! // TODO: Review use of `!` here (#19904)
|
||||
name: null! // TODO: Review use of `!` here (#19904)
|
||||
},
|
||||
{
|
||||
source: sourceUrl,
|
||||
@ -511,7 +518,7 @@ describe('TypeScriptNodeEmitter', () => {
|
||||
generatedColumn: 16,
|
||||
originalLine: 1,
|
||||
originalColumn: 26,
|
||||
name: null ! // TODO: Review use of `!` here (#19904)
|
||||
name: null! // TODO: Review use of `!` here (#19904)
|
||||
}
|
||||
]);
|
||||
});
|
||||
@ -558,7 +565,10 @@ const FILES: Directory = {
|
||||
somePackage: {'someGenFile.ts': `export var a: number;`}
|
||||
};
|
||||
|
||||
const enum Format { Raw, Flat }
|
||||
const enum Format {
|
||||
Raw,
|
||||
Flat
|
||||
}
|
||||
|
||||
function normalizeResult(result: string, format: Format): string {
|
||||
// Remove TypeScript prefixes
|
||||
|
@ -10,11 +10,12 @@ import * as ng from '@angular/compiler-cli';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {formatDiagnostics} from '../../src/perform_compile';
|
||||
import {CompilerHost, EmitFlags, LazyRoute} from '../../src/transformers/api';
|
||||
import {createSrcToOutPathMapper} from '../../src/transformers/program';
|
||||
import {StructureIsReused, tsStructureIsReused} from '../../src/transformers/util';
|
||||
import {TestSupport, expectNoDiagnosticsInProgram, setup, stripAnsi} from '../test_support';
|
||||
import {expectNoDiagnosticsInProgram, setup, stripAnsi, TestSupport} from '../test_support';
|
||||
|
||||
describe('ng program', () => {
|
||||
let testSupport: TestSupport;
|
||||
@ -83,21 +84,21 @@ describe('ng program', () => {
|
||||
|
||||
const originalGetSourceFile = host.getSourceFile;
|
||||
const cache = new Map<string, ts.SourceFile>();
|
||||
host.getSourceFile = function(
|
||||
fileName: string, languageVersion: ts.ScriptTarget): ts.SourceFile |
|
||||
undefined {
|
||||
const sf = originalGetSourceFile.call(host, fileName, languageVersion);
|
||||
if (sf) {
|
||||
if (cache.has(sf.fileName)) {
|
||||
const oldSf = cache.get(sf.fileName) !;
|
||||
if (oldSf.getFullText() === sf.getFullText()) {
|
||||
return oldSf;
|
||||
}
|
||||
}
|
||||
cache.set(sf.fileName, sf);
|
||||
}
|
||||
return sf;
|
||||
};
|
||||
host.getSourceFile = function(fileName: string, languageVersion: ts.ScriptTarget):
|
||||
ts.SourceFile|
|
||||
undefined {
|
||||
const sf = originalGetSourceFile.call(host, fileName, languageVersion);
|
||||
if (sf) {
|
||||
if (cache.has(sf.fileName)) {
|
||||
const oldSf = cache.get(sf.fileName)!;
|
||||
if (oldSf.getFullText() === sf.getFullText()) {
|
||||
return oldSf;
|
||||
}
|
||||
}
|
||||
cache.set(sf.fileName, sf);
|
||||
}
|
||||
return sf;
|
||||
};
|
||||
return host;
|
||||
}
|
||||
|
||||
@ -248,7 +249,8 @@ describe('ng program', () => {
|
||||
fileCache.delete(path.posix.join(testSupport.basePath, 'src/index.ts'));
|
||||
const p6 = ng.createProgram({
|
||||
rootNames: [path.posix.join(testSupport.basePath, 'src/index.ts')],
|
||||
options: testSupport.createCompilerOptions(options), host,
|
||||
options: testSupport.createCompilerOptions(options),
|
||||
host,
|
||||
oldProgram: p5
|
||||
});
|
||||
const p7 = compile(p6, options, undefined, host).program;
|
||||
@ -295,7 +297,6 @@ describe('ng program', () => {
|
||||
describe(
|
||||
'verify that program structure is reused within tsc in order to speed up incremental compilation',
|
||||
() => {
|
||||
|
||||
it('should reuse the old ts program completely if nothing changed', () => {
|
||||
testSupport.writeFiles({'src/index.ts': createModuleAndCompSource('main')});
|
||||
const host = createWatchModeHost();
|
||||
@ -351,7 +352,6 @@ describe('ng program', () => {
|
||||
expect(tsStructureIsReused(p2.getTsProgram())).toBe(StructureIsReused.SafeModules);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('should not typecheck templates if skipTemplateCodegen is set but fullTemplateTypeCheck is not',
|
||||
@ -473,7 +473,7 @@ describe('ng program', () => {
|
||||
|
||||
host.writeFile =
|
||||
(fileName: string, data: string, writeByteOrderMark: boolean,
|
||||
onError: ((message: string) => void) | undefined,
|
||||
onError: ((message: string) => void)|undefined,
|
||||
sourceFiles?: ReadonlyArray<ts.SourceFile>) => {
|
||||
written.set(fileName, {original: sourceFiles, data});
|
||||
};
|
||||
@ -487,19 +487,19 @@ describe('ng program', () => {
|
||||
const writeData = written.get(path.posix.join(testSupport.basePath, fileName));
|
||||
expect(writeData).toBeTruthy();
|
||||
expect(
|
||||
writeData !.original !.some(
|
||||
writeData!.original!.some(
|
||||
sf => sf.fileName === path.posix.join(testSupport.basePath, checks.originalFileName)))
|
||||
.toBe(true);
|
||||
switch (checks.shouldBe) {
|
||||
case ShouldBe.Empty:
|
||||
expect(writeData !.data).toMatch(/^(\s*\/\*([^*]|\*[^/])*\*\/\s*)?$/);
|
||||
expect(writeData!.data).toMatch(/^(\s*\/\*([^*]|\*[^/])*\*\/\s*)?$/);
|
||||
break;
|
||||
case ShouldBe.EmptyExport:
|
||||
expect(writeData !.data)
|
||||
expect(writeData!.data)
|
||||
.toMatch(/^((\s*\/\*([^*]|\*[^/])*\*\/\s*)|(\s*export\s*{\s*}\s*;\s*)|())$/);
|
||||
break;
|
||||
case ShouldBe.NoneEmpty:
|
||||
expect(writeData !.data).not.toBe('');
|
||||
expect(writeData!.data).not.toBe('');
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1099,15 +1099,15 @@ describe('ng program', () => {
|
||||
});
|
||||
const host = ng.createCompilerHost({options});
|
||||
const originalGetSourceFile = host.getSourceFile;
|
||||
host.getSourceFile = (fileName: string, languageVersion: ts.ScriptTarget,
|
||||
onError?: ((message: string) => void) | undefined): ts.SourceFile |
|
||||
undefined => {
|
||||
// We should never try to load .ngfactory.ts files
|
||||
if (fileName.match(/\.ngfactory\.ts$/)) {
|
||||
throw new Error(`Non existent ngfactory file: ` + fileName);
|
||||
}
|
||||
return originalGetSourceFile.call(host, fileName, languageVersion, onError);
|
||||
};
|
||||
host.getSourceFile =
|
||||
(fileName: string, languageVersion: ts.ScriptTarget,
|
||||
onError?: ((message: string) => void)|undefined): ts.SourceFile|undefined => {
|
||||
// We should never try to load .ngfactory.ts files
|
||||
if (fileName.match(/\.ngfactory\.ts$/)) {
|
||||
throw new Error(`Non existent ngfactory file: ` + fileName);
|
||||
}
|
||||
return originalGetSourceFile.call(host, fileName, languageVersion, onError);
|
||||
};
|
||||
const program = ng.createProgram({rootNames: allRootNames, options, host});
|
||||
const structuralErrors = program.getNgStructuralDiagnostics();
|
||||
expect(structuralErrors.length).toBe(1);
|
||||
@ -1115,5 +1115,4 @@ describe('ng program', () => {
|
||||
.toContain('Function expressions are not supported');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -9,12 +9,11 @@
|
||||
import {ClassField, ClassMethod, ClassStmt, PartialModule, Statement, StmtModifier} from '@angular/compiler';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {MetadataCollector, isClassMetadata} from '../../src/metadata/index';
|
||||
import {isClassMetadata, MetadataCollector} from '../../src/metadata/index';
|
||||
import {MetadataCache} from '../../src/transformers/metadata_cache';
|
||||
import {PartialModuleMetadataTransformer} from '../../src/transformers/r3_metadata_transform';
|
||||
|
||||
describe('r3_transform_spec', () => {
|
||||
|
||||
it('should add a static method to collected metadata', () => {
|
||||
const fileName = '/some/directory/someFileName.ts';
|
||||
const className = 'SomeClass';
|
||||
|
@ -30,8 +30,9 @@ describe('r3_transform_spec', () => {
|
||||
.toContain('static someMethod(v) { return v; }');
|
||||
});
|
||||
|
||||
it('should be able to generate a static field declaration',
|
||||
() => { expect(emitStaticField(o.literal(10))).toContain('SomeClass.someField = 10'); });
|
||||
it('should be able to generate a static field declaration', () => {
|
||||
expect(emitStaticField(o.literal(10))).toContain('SomeClass.someField = 10');
|
||||
});
|
||||
|
||||
it('should be able to import a symbol', () => {
|
||||
expect(emitStaticMethod(new o.ReturnStatement(
|
||||
@ -90,8 +91,8 @@ describe('r3_transform_spec', () => {
|
||||
}
|
||||
|
||||
function emitStaticMethod(
|
||||
stmt: o.Statement | o.Statement[], parameters: string[] = [],
|
||||
methodName: string = 'someMethod', className: string = 'SomeClass'): string {
|
||||
stmt: o.Statement|o.Statement[], parameters: string[] = [], methodName: string = 'someMethod',
|
||||
className: string = 'SomeClass'): string {
|
||||
const module: PartialModule = {
|
||||
fileName: someGenFileName,
|
||||
statements: [classMethod(stmt, parameters, methodName, className)]
|
||||
@ -122,7 +123,7 @@ const FILES: Directory = {
|
||||
};
|
||||
|
||||
function classMethod(
|
||||
stmt: o.Statement | o.Statement[], parameters: string[] = [], methodName: string = 'someMethod',
|
||||
stmt: o.Statement|o.Statement[], parameters: string[] = [], methodName: string = 'someMethod',
|
||||
className: string = 'SomeClass'): o.ClassStmt {
|
||||
const statements = Array.isArray(stmt) ? stmt : [stmt];
|
||||
return new o.ClassStmt(
|
||||
|
Reference in New Issue
Block a user