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:
@ -14,7 +14,7 @@ import {NgtscTestEnvironment} from './env';
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
describe('ngtsc component indexing', () => {
|
||||
let env !: NgtscTestEnvironment;
|
||||
let env!: NgtscTestEnvironment;
|
||||
let testSourceFile: AbsoluteFsPath;
|
||||
let testTemplateFile: AbsoluteFsPath;
|
||||
|
||||
@ -177,10 +177,10 @@ runInEachFileSystem(() => {
|
||||
expect(testComp).toBeDefined();
|
||||
expect(testImportComp).toBeDefined();
|
||||
|
||||
expect(testComp !.template.usedComponents.size).toBe(0);
|
||||
expect(testImportComp !.template.usedComponents.size).toBe(1);
|
||||
expect(testComp!.template.usedComponents.size).toBe(0);
|
||||
expect(testImportComp!.template.usedComponents.size).toBe(1);
|
||||
|
||||
const [usedComp] = Array.from(testImportComp !.template.usedComponents);
|
||||
const [usedComp] = Array.from(testImportComp!.template.usedComponents);
|
||||
expect(indexed.get(usedComp)).toEqual(testComp);
|
||||
});
|
||||
});
|
||||
|
@ -6,13 +6,13 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {CustomTransformers, Program, defaultGatherDiagnostics} from '@angular/compiler-cli';
|
||||
import {CustomTransformers, defaultGatherDiagnostics, Program} from '@angular/compiler-cli';
|
||||
import * as api from '@angular/compiler-cli/src/transformers/api';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {createCompilerHost, createProgram} from '../../index';
|
||||
import {main, mainDiagnosticsForTest, readNgcCommandLineAndConfiguration} from '../../src/main';
|
||||
import {AbsoluteFsPath, FileSystem, NgtscCompilerHost, absoluteFrom, getFileSystem} from '../../src/ngtsc/file_system';
|
||||
import {absoluteFrom, AbsoluteFsPath, FileSystem, getFileSystem, NgtscCompilerHost} from '../../src/ngtsc/file_system';
|
||||
import {Folder, MockFileSystem} from '../../src/ngtsc/file_system/testing';
|
||||
import {IndexedComponent} from '../../src/ngtsc/indexer';
|
||||
import {NgtscProgram} from '../../src/ngtsc/program';
|
||||
@ -115,7 +115,7 @@ export class NgtscTestEnvironment {
|
||||
if (this.multiCompileHostExt === null) {
|
||||
throw new Error(`Not tracking written files - call enableMultipleCompilations()`);
|
||||
}
|
||||
this.changedResources !.clear();
|
||||
this.changedResources!.clear();
|
||||
this.multiCompileHostExt.flushWrittenFileTracking();
|
||||
}
|
||||
|
||||
@ -123,7 +123,9 @@ export class NgtscTestEnvironment {
|
||||
* Older versions of the CLI do not provide the `CompilerHost.getModifiedResourceFiles()` method.
|
||||
* This results in the `changedResources` set being `null`.
|
||||
*/
|
||||
simulateLegacyCLICompilerHost() { this.changedResources = null; }
|
||||
simulateLegacyCLICompilerHost() {
|
||||
this.changedResources = null;
|
||||
}
|
||||
|
||||
getFilesWrittenSinceLastFlush(): Set<string> {
|
||||
if (this.multiCompileHostExt === null) {
|
||||
@ -142,7 +144,7 @@ export class NgtscTestEnvironment {
|
||||
const absFilePath = this.fs.resolve(this.basePath, fileName);
|
||||
if (this.multiCompileHostExt !== null) {
|
||||
this.multiCompileHostExt.invalidate(absFilePath);
|
||||
this.changedResources !.add(absFilePath);
|
||||
this.changedResources!.add(absFilePath);
|
||||
}
|
||||
this.fs.ensureDir(this.fs.dirname(absFilePath));
|
||||
this.fs.writeFile(absFilePath, content);
|
||||
@ -156,8 +158,7 @@ export class NgtscTestEnvironment {
|
||||
this.multiCompileHostExt.invalidate(absFilePath);
|
||||
}
|
||||
|
||||
tsconfig(extraOpts: {[key: string]: string | boolean | null} = {}, extraRootDirs?: string[]):
|
||||
void {
|
||||
tsconfig(extraOpts: {[key: string]: string|boolean|null} = {}, extraRootDirs?: string[]): void {
|
||||
const tsconfig: {[key: string]: any} = {
|
||||
extends: './tsconfig-base.json',
|
||||
angularCompilerOptions: {...extraOpts, enableIvy: true},
|
||||
@ -179,7 +180,7 @@ export class NgtscTestEnvironment {
|
||||
*/
|
||||
driveMain(customTransformers?: CustomTransformers): void {
|
||||
const errorSpy = jasmine.createSpy('consoleError').and.callFake(console.error);
|
||||
let reuseProgram: {program: Program | undefined}|undefined = undefined;
|
||||
let reuseProgram: {program: Program|undefined}|undefined = undefined;
|
||||
if (this.multiCompileHostExt !== null) {
|
||||
reuseProgram = {
|
||||
program: this.oldProgram || undefined,
|
||||
@ -191,7 +192,7 @@ export class NgtscTestEnvironment {
|
||||
expect(errorSpy).not.toHaveBeenCalled();
|
||||
expect(exitCode).toBe(0);
|
||||
if (this.multiCompileHostExt !== null) {
|
||||
this.oldProgram = reuseProgram !.program !;
|
||||
this.oldProgram = reuseProgram!.program!;
|
||||
}
|
||||
}
|
||||
|
||||
@ -200,7 +201,7 @@ export class NgtscTestEnvironment {
|
||||
*/
|
||||
driveDiagnostics(): ReadonlyArray<ts.Diagnostic> {
|
||||
// ngtsc only produces ts.Diagnostic messages.
|
||||
let reuseProgram: {program: Program | undefined}|undefined = undefined;
|
||||
let reuseProgram: {program: Program|undefined}|undefined = undefined;
|
||||
if (this.multiCompileHostExt !== null) {
|
||||
reuseProgram = {
|
||||
program: this.oldProgram || undefined,
|
||||
@ -212,7 +213,7 @@ export class NgtscTestEnvironment {
|
||||
|
||||
|
||||
if (this.multiCompileHostExt !== null) {
|
||||
this.oldProgram = reuseProgram !.program !;
|
||||
this.oldProgram = reuseProgram!.program!;
|
||||
}
|
||||
|
||||
// In ngtsc, only `ts.Diagnostic`s are produced.
|
||||
@ -245,7 +246,7 @@ export class NgtscTestEnvironment {
|
||||
}
|
||||
|
||||
class AugmentedCompilerHost extends NgtscCompilerHost {
|
||||
delegate !: ts.CompilerHost;
|
||||
delegate!: ts.CompilerHost;
|
||||
}
|
||||
|
||||
const ROOT_PREFIX = 'root/';
|
||||
@ -283,7 +284,7 @@ class MultiCompileHostExt extends AugmentedCompilerHost implements Partial<ts.Co
|
||||
fileName: string, languageVersion: ts.ScriptTarget, onError?: (message: string) => void,
|
||||
shouldCreateNewSourceFile?: boolean): ts.SourceFile|undefined {
|
||||
if (this.cache.has(fileName)) {
|
||||
return this.cache.get(fileName) !;
|
||||
return this.cache.get(fileName)!;
|
||||
}
|
||||
const sf = super.getSourceFile(fileName, languageVersion);
|
||||
if (sf !== undefined) {
|
||||
@ -292,7 +293,9 @@ class MultiCompileHostExt extends AugmentedCompilerHost implements Partial<ts.Co
|
||||
return sf;
|
||||
}
|
||||
|
||||
flushWrittenFileTracking(): void { this.writtenFiles.clear(); }
|
||||
flushWrittenFileTracking(): void {
|
||||
this.writtenFiles.clear();
|
||||
}
|
||||
|
||||
writeFile(
|
||||
fileName: string, data: string, writeByteOrderMark: boolean,
|
||||
@ -302,9 +305,13 @@ class MultiCompileHostExt extends AugmentedCompilerHost implements Partial<ts.Co
|
||||
this.writtenFiles.add(fileName);
|
||||
}
|
||||
|
||||
getFilesWrittenSinceLastFlush(): Set<string> { return this.writtenFiles; }
|
||||
getFilesWrittenSinceLastFlush(): Set<string> {
|
||||
return this.writtenFiles;
|
||||
}
|
||||
|
||||
invalidate(fileName: string): void { this.cache.delete(fileName); }
|
||||
invalidate(fileName: string): void {
|
||||
this.cache.delete(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
class ResourceLoadingCompileHost extends AugmentedCompilerHost implements api.CompilerHost {
|
||||
@ -323,7 +330,7 @@ function makeWrapHost(wrapped: AugmentedCompilerHost): (host: ts.CompilerHost) =
|
||||
return new Proxy(delegate, {
|
||||
get: (target: ts.CompilerHost, name: string): any => {
|
||||
if ((wrapped as any)[name] !== undefined) {
|
||||
return (wrapped as any)[name] !.bind(wrapped);
|
||||
return (wrapped as any)[name]!.bind(wrapped);
|
||||
}
|
||||
return (target as any)[name];
|
||||
}
|
||||
|
@ -8,19 +8,19 @@
|
||||
|
||||
interface FnWithArg<T> {
|
||||
(...args: any[]): T;
|
||||
new (...args: any[]): T;
|
||||
new(...args: any[]): T;
|
||||
}
|
||||
|
||||
function callableClassDecorator(): FnWithArg<(clazz: any) => any> {
|
||||
return null !;
|
||||
return null!;
|
||||
}
|
||||
|
||||
function callableParamDecorator(): FnWithArg<(a: any, b: any, c: any) => void> {
|
||||
return null !;
|
||||
return null!;
|
||||
}
|
||||
|
||||
function callablePropDecorator(): FnWithArg<(a: any, b: any) => any> {
|
||||
return null !;
|
||||
return null!;
|
||||
}
|
||||
|
||||
export const Component = callableClassDecorator();
|
||||
@ -66,7 +66,9 @@ export function forwardRef<T>(fn: () => T): T {
|
||||
return fn();
|
||||
}
|
||||
|
||||
export interface SimpleChanges { [propName: string]: any; }
|
||||
export interface SimpleChanges {
|
||||
[propName: string]: any;
|
||||
}
|
||||
|
||||
export type ɵɵNgModuleDefWithMeta<ModuleT, DeclarationsT, ImportsT, ExportsT> = any;
|
||||
export type ɵɵDirectiveDefWithMeta<
|
||||
@ -89,11 +91,15 @@ export const CUSTOM_ELEMENTS_SCHEMA: any = false;
|
||||
export const NO_ERRORS_SCHEMA: any = false;
|
||||
|
||||
export class EventEmitter<T> {
|
||||
subscribe(generatorOrNext?: any, error?: any, complete?: any): unknown { return null; }
|
||||
subscribe(generatorOrNext?: any, error?: any, complete?: any): unknown {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export interface QueryList<T>/* implements Iterable<T> */ { [Symbol.iterator]: () => Iterator<T>; }
|
||||
export interface QueryList<T>/* implements Iterable<T> */ {
|
||||
[Symbol.iterator]: () => Iterator<T>;
|
||||
}
|
||||
|
||||
export type NgIterable<T> = Array<T>| Iterable<T>;
|
||||
export type NgIterable<T> = Array<T>|Iterable<T>;
|
||||
|
||||
export class NgZone {}
|
||||
|
@ -16,7 +16,7 @@ const testFiles = loadStandardTestFiles();
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
describe('ngtsc incremental compilation with errors', () => {
|
||||
let env !: NgtscTestEnvironment;
|
||||
let env!: NgtscTestEnvironment;
|
||||
|
||||
beforeEach(() => {
|
||||
env = NgtscTestEnvironment.setup(testFiles);
|
||||
@ -66,7 +66,7 @@ runInEachFileSystem(() => {
|
||||
`);
|
||||
const diags = env.driveDiagnostics();
|
||||
expect(diags.length).toBe(1);
|
||||
expect(diags[0].file !.fileName).toBe(_('/other.ts'));
|
||||
expect(diags[0].file!.fileName).toBe(_('/other.ts'));
|
||||
expectToHaveWritten([]);
|
||||
|
||||
// Remove the error. /other.js should now be emitted again.
|
||||
@ -92,7 +92,7 @@ runInEachFileSystem(() => {
|
||||
|
||||
const diags = env.driveDiagnostics();
|
||||
expect(diags.length).toBe(1);
|
||||
expect(diags[0].file !.fileName).toBe(_('/other.ts'));
|
||||
expect(diags[0].file!.fileName).toBe(_('/other.ts'));
|
||||
expectToHaveWritten([]);
|
||||
|
||||
// Remove the error. All files should be emitted.
|
||||
@ -128,7 +128,7 @@ runInEachFileSystem(() => {
|
||||
|
||||
const diags = env.driveDiagnostics();
|
||||
expect(diags.length).toBe(1);
|
||||
expect(diags[0].file !.fileName).toBe(_('/other.ts'));
|
||||
expect(diags[0].file!.fileName).toBe(_('/other.ts'));
|
||||
expectToHaveWritten([]);
|
||||
|
||||
// Remove the error. All files should be emitted.
|
||||
@ -175,7 +175,7 @@ runInEachFileSystem(() => {
|
||||
|
||||
const diags = env.driveDiagnostics();
|
||||
expect(diags.length).toBe(1);
|
||||
expect(diags[0].file !.fileName).toBe(_('/other.ts'));
|
||||
expect(diags[0].file!.fileName).toBe(_('/other.ts'));
|
||||
expectToHaveWritten([]);
|
||||
|
||||
// Remove the error. All files should be emitted.
|
||||
|
@ -15,7 +15,7 @@ const testFiles = loadStandardTestFiles();
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
describe('ngtsc incremental compilation', () => {
|
||||
let env !: NgtscTestEnvironment;
|
||||
let env!: NgtscTestEnvironment;
|
||||
|
||||
beforeEach(() => {
|
||||
env = NgtscTestEnvironment.setup(testFiles);
|
||||
|
@ -17,7 +17,7 @@ const testFiles = loadStandardTestFiles();
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
describe('ModuleWithProviders generic type transform', () => {
|
||||
let env !: NgtscTestEnvironment;
|
||||
let env!: NgtscTestEnvironment;
|
||||
|
||||
beforeEach(() => {
|
||||
env = NgtscTestEnvironment.setup(testFiles);
|
||||
|
@ -16,7 +16,7 @@ const testFiles = loadStandardTestFiles();
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
describe('monorepos', () => {
|
||||
let env !: NgtscTestEnvironment;
|
||||
let env!: NgtscTestEnvironment;
|
||||
|
||||
beforeEach(() => {
|
||||
env = NgtscTestEnvironment.setup(testFiles, absoluteFrom('/app'));
|
||||
|
@ -38,12 +38,12 @@ const setClassMetadataRegExp = (expectedType: string): RegExp =>
|
||||
const testFiles = loadStandardTestFiles();
|
||||
|
||||
function getDiagnosticSourceCode(diag: ts.Diagnostic): string {
|
||||
return diag.file !.text.substr(diag.start !, diag.length !);
|
||||
return diag.file!.text.substr(diag.start!, diag.length!);
|
||||
}
|
||||
|
||||
runInEachFileSystem(os => {
|
||||
describe('ngtsc behavioral tests', () => {
|
||||
let env !: NgtscTestEnvironment;
|
||||
let env!: NgtscTestEnvironment;
|
||||
|
||||
beforeEach(() => {
|
||||
env = NgtscTestEnvironment.setup(testFiles);
|
||||
@ -369,7 +369,6 @@ runInEachFileSystem(os => {
|
||||
// that start with `C:`.
|
||||
if (os !== 'Windows' || platform() === 'win32') {
|
||||
describe('when closure annotations are requested', () => {
|
||||
|
||||
it('should add @nocollapse to static fields', () => {
|
||||
env.tsconfig({
|
||||
'annotateForClosureCompiler': true,
|
||||
@ -531,7 +530,6 @@ runInEachFileSystem(os => {
|
||||
verifyOutput(env.getContents('test.js'));
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@ -1714,7 +1712,8 @@ runInEachFileSystem(os => {
|
||||
});
|
||||
|
||||
['ContentChild', 'ContentChildren'].forEach(decorator => {
|
||||
it(`should throw if \`descendants\` field of @${decorator}'s options argument has wrong type`,
|
||||
it(`should throw if \`descendants\` field of @${
|
||||
decorator}'s options argument has wrong type`,
|
||||
() => {
|
||||
env.tsconfig({});
|
||||
env.write('test.ts', `
|
||||
@ -2148,7 +2147,6 @@ runInEachFileSystem(os => {
|
||||
expect(jsContents)
|
||||
.toContain('Test.ɵfac = function Test_Factory(t) { i0.ɵɵinvalidFactory()');
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@ -3466,7 +3464,9 @@ runInEachFileSystem(os => {
|
||||
});
|
||||
|
||||
describe('ngfactory shims', () => {
|
||||
beforeEach(() => { env.tsconfig({'generateNgFactoryShims': true}); });
|
||||
beforeEach(() => {
|
||||
env.tsconfig({'generateNgFactoryShims': true});
|
||||
});
|
||||
|
||||
it('should generate correct type annotation for NgModuleFactory calls in ngfactories', () => {
|
||||
env.write('test.ts', `
|
||||
@ -3568,7 +3568,9 @@ runInEachFileSystem(os => {
|
||||
|
||||
|
||||
describe('ngsummary shim generation', () => {
|
||||
beforeEach(() => { env.tsconfig({'generateNgSummaryShims': true}); });
|
||||
beforeEach(() => {
|
||||
env.tsconfig({'generateNgSummaryShims': true});
|
||||
});
|
||||
|
||||
it('should generate a summary stub for decorated classes in the input file only', () => {
|
||||
env.write('test.ts', `
|
||||
@ -3792,7 +3794,6 @@ runInEachFileSystem(os => {
|
||||
});
|
||||
|
||||
it('should use imported types in setClassMetadata if they can be represented as values', () => {
|
||||
|
||||
env.write(`types.ts`, `
|
||||
export class MyTypeA {}
|
||||
export class MyTypeB {}
|
||||
@ -3824,7 +3825,6 @@ runInEachFileSystem(os => {
|
||||
|
||||
it('should use imported types in setClassMetadata if they can be represented as values and imported as `* as foo`',
|
||||
() => {
|
||||
|
||||
env.write(`types.ts`, `
|
||||
export class MyTypeA {}
|
||||
export class MyTypeB {}
|
||||
@ -3855,7 +3855,6 @@ runInEachFileSystem(os => {
|
||||
});
|
||||
|
||||
it('should use default-imported types if they can be represented as values', () => {
|
||||
|
||||
env.write(`types.ts`, `
|
||||
export default class Default {}
|
||||
export class Other {}
|
||||
@ -3883,7 +3882,6 @@ runInEachFileSystem(os => {
|
||||
|
||||
it('should use `undefined` in setClassMetadata if types can\'t be represented as values',
|
||||
() => {
|
||||
|
||||
env.write(`types.ts`, `
|
||||
export type MyType = Map<any, any>;
|
||||
`);
|
||||
@ -4059,7 +4057,6 @@ runInEachFileSystem(os => {
|
||||
it('should not generate an error when a local ref is unresolved' +
|
||||
' (outside of template type-checking)',
|
||||
() => {
|
||||
|
||||
env.write('test.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@ -4347,7 +4344,7 @@ runInEachFileSystem(os => {
|
||||
}
|
||||
});
|
||||
|
||||
it('should throw if @Component is missing a template', async() => {
|
||||
it('should throw if @Component is missing a template', async () => {
|
||||
env.write('test.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@ -4359,10 +4356,10 @@ runInEachFileSystem(os => {
|
||||
|
||||
const diags = await driveDiagnostics();
|
||||
expect(diags[0].messageText).toBe('component is missing a template');
|
||||
expect(diags[0].file !.fileName).toBe(absoluteFrom('/test.ts'));
|
||||
expect(diags[0].file!.fileName).toBe(absoluteFrom('/test.ts'));
|
||||
});
|
||||
|
||||
it('should throw if `styleUrls` is defined incorrectly in @Component', async() => {
|
||||
it('should throw if `styleUrls` is defined incorrectly in @Component', async () => {
|
||||
env.write('test.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@ -4376,7 +4373,7 @@ runInEachFileSystem(os => {
|
||||
|
||||
const diags = await driveDiagnostics();
|
||||
expect(diags[0].messageText).toBe('styleUrls must be an array of strings');
|
||||
expect(diags[0].file !.fileName).toBe(absoluteFrom('/test.ts'));
|
||||
expect(diags[0].file!.fileName).toBe(absoluteFrom('/test.ts'));
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -4497,7 +4494,7 @@ runInEachFileSystem(os => {
|
||||
|
||||
// Verify that the error is for the correct class.
|
||||
const error = errors[0] as ts.Diagnostic;
|
||||
const id = expectTokenAtPosition(error.file !, error.start !, ts.isIdentifier);
|
||||
const id = expectTokenAtPosition(error.file!, error.start!, ts.isIdentifier);
|
||||
expect(id.text).toBe('Dir');
|
||||
expect(ts.isClassDeclaration(id.parent)).toBe(true);
|
||||
});
|
||||
@ -4804,7 +4801,7 @@ runInEachFileSystem(os => {
|
||||
|
||||
const diag = env.driveDiagnostics();
|
||||
expect(diag.length).toBe(1);
|
||||
expect(diag[0] !.code).toEqual(ngErrorCode(ErrorCode.NGMODULE_REEXPORT_NAME_COLLISION));
|
||||
expect(diag[0]!.code).toEqual(ngErrorCode(ErrorCode.NGMODULE_REEXPORT_NAME_COLLISION));
|
||||
});
|
||||
|
||||
it('should not error when two directives with the same declared name are exported from the same NgModule, but one is exported from the file directly',
|
||||
@ -6701,9 +6698,7 @@ export const Foo = Foo__PRE_R3__;
|
||||
const diags = env.driveDiagnostics();
|
||||
expect(diags.length).toBe(0);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
function expectTokenAtPosition<T extends ts.Node>(
|
||||
@ -6714,5 +6709,7 @@ export const Foo = Foo__PRE_R3__;
|
||||
return node as T;
|
||||
}
|
||||
|
||||
function normalize(input: string): string { return input.replace(/\s+/g, ' ').trim(); }
|
||||
function normalize(input: string): string {
|
||||
return input.replace(/\s+/g, ' ').trim();
|
||||
}
|
||||
});
|
||||
|
@ -20,7 +20,7 @@ const testFiles = loadStandardTestFiles();
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
describe('ngtsc module scopes', () => {
|
||||
let env !: NgtscTestEnvironment;
|
||||
let env!: NgtscTestEnvironment;
|
||||
|
||||
beforeEach(() => {
|
||||
env = NgtscTestEnvironment.setup(testFiles);
|
||||
@ -92,11 +92,11 @@ runInEachFileSystem(() => {
|
||||
const diags = env.driveDiagnostics();
|
||||
expect(diags.length).toBe(1);
|
||||
const node = findContainingClass(diagnosticToNode(diags[0], ts.isIdentifier));
|
||||
expect(node.name !.text).toEqual('TestDir');
|
||||
expect(node.name!.text).toEqual('TestDir');
|
||||
|
||||
const relatedNodes = new Set(diags[0].relatedInformation !.map(
|
||||
const relatedNodes = new Set(diags[0].relatedInformation!.map(
|
||||
related =>
|
||||
findContainingClass(diagnosticToNode(related, ts.isIdentifier)).name !.text));
|
||||
findContainingClass(diagnosticToNode(related, ts.isIdentifier)).name!.text));
|
||||
expect(relatedNodes).toContain('ModuleA');
|
||||
expect(relatedNodes).toContain('ModuleB');
|
||||
expect(relatedNodes.size).toBe(2);
|
||||
@ -141,11 +141,11 @@ runInEachFileSystem(() => {
|
||||
const diags = env.driveDiagnostics();
|
||||
expect(diags.length).toBe(1);
|
||||
const node = findContainingClass(diagnosticToNode(diags[0], ts.isIdentifier));
|
||||
expect(node.name !.text).toEqual('TestDir');
|
||||
expect(node.name!.text).toEqual('TestDir');
|
||||
|
||||
const relatedNodes = new Set(diags[0].relatedInformation !.map(
|
||||
const relatedNodes = new Set(diags[0].relatedInformation!.map(
|
||||
related =>
|
||||
findContainingClass(diagnosticToNode(related, ts.isIdentifier)).name !.text));
|
||||
findContainingClass(diagnosticToNode(related, ts.isIdentifier)).name!.text));
|
||||
expect(relatedNodes).toContain('ModuleA');
|
||||
expect(relatedNodes).toContain('ModuleB');
|
||||
expect(relatedNodes.size).toBe(2);
|
||||
@ -386,13 +386,13 @@ runInEachFileSystem(() => {
|
||||
});
|
||||
|
||||
function diagnosticToNode<T extends ts.Node>(
|
||||
diagnostic: ts.Diagnostic | Diagnostic | ts.DiagnosticRelatedInformation,
|
||||
diagnostic: ts.Diagnostic|Diagnostic|ts.DiagnosticRelatedInformation,
|
||||
guard: (node: ts.Node) => node is T): T {
|
||||
const diag = diagnostic as ts.Diagnostic | ts.DiagnosticRelatedInformation;
|
||||
if (diag.file === undefined) {
|
||||
throw new Error(`Expected ts.Diagnostic to have a file source`);
|
||||
}
|
||||
const node = getTokenAtPosition(diag.file, diag.start !);
|
||||
const node = getTokenAtPosition(diag.file, diag.start!);
|
||||
expect(guard(node)).toBe(true);
|
||||
return node as T;
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ export function getMappedSegments(
|
||||
while (currentMapping) {
|
||||
const nextMapping = mappings.shift();
|
||||
if (nextMapping) {
|
||||
const source = sources.get(currentMapping.source) !;
|
||||
const source = sources.get(currentMapping.source)!;
|
||||
const segment = {
|
||||
generated: generated.getSegment('generated', currentMapping, nextMapping),
|
||||
source: source.getSegment('original', currentMapping, nextMapping),
|
||||
|
@ -14,13 +14,13 @@ import {tsSourceMapBug29300Fixed} from '../../src/ngtsc/util/src/ts_source_map_b
|
||||
import {loadStandardTestFiles} from '../helpers/src/mock_file_loading';
|
||||
|
||||
import {NgtscTestEnvironment} from './env';
|
||||
import {SegmentMapping, getMappedSegments} from './sourcemap_utils';
|
||||
import {getMappedSegments, SegmentMapping} from './sourcemap_utils';
|
||||
|
||||
const testFiles = loadStandardTestFiles();
|
||||
|
||||
runInEachFileSystem((os) => {
|
||||
describe('template source-mapping', () => {
|
||||
let env !: NgtscTestEnvironment;
|
||||
let env!: NgtscTestEnvironment;
|
||||
|
||||
beforeEach(() => {
|
||||
env = NgtscTestEnvironment.setup(testFiles);
|
||||
@ -323,7 +323,6 @@ runInEachFileSystem((os) => {
|
||||
|
||||
expect(mappings).toContain(
|
||||
{source: '</div>', generated: 'i0.ɵɵelementEnd()', sourceUrl: '../test.ts'});
|
||||
|
||||
});
|
||||
|
||||
it('should map ng-template [ngFor] scenario', () => {
|
||||
@ -518,7 +517,7 @@ runInEachFileSystem((os) => {
|
||||
});
|
||||
}
|
||||
|
||||
function compileAndMap(template: string, templateUrl: string | null = null) {
|
||||
function compileAndMap(template: string, templateUrl: string|null = null) {
|
||||
const templateConfig = templateUrl ? `templateUrl: '${templateUrl}'` :
|
||||
('template: `' + template.replace(/`/g, '\\`') + '`');
|
||||
env.tsconfig({sourceMap: true});
|
||||
|
@ -19,7 +19,7 @@ const testFiles = loadStandardTestFiles();
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
describe('ngtsc type checking', () => {
|
||||
let env !: NgtscTestEnvironment;
|
||||
let env!: NgtscTestEnvironment;
|
||||
|
||||
beforeEach(() => {
|
||||
env = NgtscTestEnvironment.setup(testFiles);
|
||||
@ -1502,8 +1502,9 @@ export declare class AnimationEvent {
|
||||
});
|
||||
|
||||
describe('legacy schema checking with the DOM schema', () => {
|
||||
beforeEach(
|
||||
() => { env.tsconfig({ivyTemplateTypeCheck: true, fullTemplateTypeCheck: false}); });
|
||||
beforeEach(() => {
|
||||
env.tsconfig({ivyTemplateTypeCheck: true, fullTemplateTypeCheck: false});
|
||||
});
|
||||
|
||||
it('should check for unknown elements', () => {
|
||||
env.write('test.ts', `
|
||||
@ -1734,7 +1735,7 @@ export declare class AnimationEvent {
|
||||
}
|
||||
});
|
||||
|
||||
it('should be correct for direct templates', async() => {
|
||||
it('should be correct for direct templates', async () => {
|
||||
env.write('test.ts', `
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
|
||||
@ -1750,11 +1751,11 @@ export declare class AnimationEvent {
|
||||
|
||||
const diags = await driveDiagnostics();
|
||||
expect(diags.length).toBe(1);
|
||||
expect(diags[0].file !.fileName).toBe(_('/test.ts'));
|
||||
expect(diags[0].file!.fileName).toBe(_('/test.ts'));
|
||||
expect(getSourceCodeForDiagnostic(diags[0])).toBe('user.does_not_exist');
|
||||
});
|
||||
|
||||
it('should be correct for indirect templates', async() => {
|
||||
it('should be correct for indirect templates', async () => {
|
||||
env.write('test.ts', `
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
|
||||
@ -1772,12 +1773,12 @@ export declare class AnimationEvent {
|
||||
|
||||
const diags = await driveDiagnostics();
|
||||
expect(diags.length).toBe(1);
|
||||
expect(diags[0].file !.fileName).toBe(_('/test.ts') + ' (TestCmp template)');
|
||||
expect(diags[0].file!.fileName).toBe(_('/test.ts') + ' (TestCmp template)');
|
||||
expect(getSourceCodeForDiagnostic(diags[0])).toBe('user.does_not_exist');
|
||||
expect(getSourceCodeForDiagnostic(diags[0].relatedInformation ![0])).toBe('TEMPLATE');
|
||||
expect(getSourceCodeForDiagnostic(diags[0].relatedInformation![0])).toBe('TEMPLATE');
|
||||
});
|
||||
|
||||
it('should be correct for external templates', async() => {
|
||||
it('should be correct for external templates', async () => {
|
||||
env.write('template.html', `<p>
|
||||
{{user.does_not_exist}}
|
||||
</p>`);
|
||||
@ -1795,9 +1796,9 @@ export declare class AnimationEvent {
|
||||
|
||||
const diags = await driveDiagnostics();
|
||||
expect(diags.length).toBe(1);
|
||||
expect(diags[0].file !.fileName).toBe(_('/template.html'));
|
||||
expect(diags[0].file!.fileName).toBe(_('/template.html'));
|
||||
expect(getSourceCodeForDiagnostic(diags[0])).toBe('user.does_not_exist');
|
||||
expect(getSourceCodeForDiagnostic(diags[0].relatedInformation ![0]))
|
||||
expect(getSourceCodeForDiagnostic(diags[0].relatedInformation![0]))
|
||||
.toBe(`'./template.html'`);
|
||||
});
|
||||
});
|
||||
@ -1841,6 +1842,6 @@ export declare class AnimationEvent {
|
||||
});
|
||||
|
||||
function getSourceCodeForDiagnostic(diag: ts.Diagnostic): string {
|
||||
const text = diag.file !.text;
|
||||
return text.substr(diag.start !, diag.length !);
|
||||
const text = diag.file!.text;
|
||||
return text.substr(diag.start!, diag.length!);
|
||||
}
|
||||
|
Reference in New Issue
Block a user