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:
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
export {AliasStrategy, AliasingHost, PrivateExportAliasingHost, UnifiedModulesAliasingHost} from './src/alias';
|
||||
export {AliasingHost, AliasStrategy, PrivateExportAliasingHost, UnifiedModulesAliasingHost} from './src/alias';
|
||||
export {ImportRewriter, NoopImportRewriter, R3SymbolsImportRewriter, validateAndRewriteCoreSymbol} from './src/core';
|
||||
export {DefaultImportRecorder, DefaultImportTracker, NOOP_DEFAULT_IMPORT_RECORDER} from './src/default';
|
||||
export {AbsoluteModuleStrategy, ImportFlags, LocalIdentifierStrategy, LogicalProjectStrategy, ReferenceEmitStrategy, ReferenceEmitter, RelativePathStrategy, UnifiedModulesStrategy} from './src/emitter';
|
||||
|
@ -10,7 +10,7 @@ import {Expression, ExternalExpr} from '@angular/compiler';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {UnifiedModulesHost} from '../../core/api';
|
||||
import {ClassDeclaration, ReflectionHost, isNamedClassDeclaration} from '../../reflection';
|
||||
import {ClassDeclaration, isNamedClassDeclaration, ReflectionHost} from '../../reflection';
|
||||
|
||||
import {ImportFlags, ReferenceEmitStrategy} from './emitter';
|
||||
import {Reference} from './references';
|
||||
@ -203,7 +203,9 @@ export class PrivateExportAliasingHost implements AliasingHost {
|
||||
*
|
||||
* Thus, `getAliasIn` always returns `null`.
|
||||
*/
|
||||
getAliasIn(): null { return null; }
|
||||
getAliasIn(): null {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,11 +36,17 @@ export interface ImportRewriter {
|
||||
* `ImportRewriter` that does no rewriting.
|
||||
*/
|
||||
export class NoopImportRewriter implements ImportRewriter {
|
||||
shouldImportSymbol(symbol: string, specifier: string): boolean { return true; }
|
||||
shouldImportSymbol(symbol: string, specifier: string): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
rewriteSymbol(symbol: string, specifier: string): string { return symbol; }
|
||||
rewriteSymbol(symbol: string, specifier: string): string {
|
||||
return symbol;
|
||||
}
|
||||
|
||||
rewriteSpecifier(specifier: string, inContextOfFile: string): string { return specifier; }
|
||||
rewriteSpecifier(specifier: string, inContextOfFile: string): string {
|
||||
return specifier;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,7 +76,9 @@ const CORE_MODULE = '@angular/core';
|
||||
export class R3SymbolsImportRewriter implements ImportRewriter {
|
||||
constructor(private r3SymbolsPath: string) {}
|
||||
|
||||
shouldImportSymbol(symbol: string, specifier: string): boolean { return true; }
|
||||
shouldImportSymbol(symbol: string, specifier: string): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
rewriteSymbol(symbol: string, specifier: string): string {
|
||||
if (specifier !== CORE_MODULE) {
|
||||
@ -89,8 +97,8 @@ export class R3SymbolsImportRewriter implements ImportRewriter {
|
||||
|
||||
const relativePathToR3Symbols = relativePathBetween(inContextOfFile, this.r3SymbolsPath);
|
||||
if (relativePathToR3Symbols === null) {
|
||||
throw new Error(
|
||||
`Failed to rewrite import inside ${CORE_MODULE}: ${inContextOfFile} -> ${this.r3SymbolsPath}`);
|
||||
throw new Error(`Failed to rewrite import inside ${CORE_MODULE}: ${inContextOfFile} -> ${
|
||||
this.r3SymbolsPath}`);
|
||||
}
|
||||
|
||||
return relativePathToR3Symbols;
|
||||
@ -101,5 +109,5 @@ export function validateAndRewriteCoreSymbol(name: string): string {
|
||||
if (!CORE_SUPPORTED_SYMBOLS.has(name)) {
|
||||
throw new Error(`Importing unexpected symbol ${name} while compiling ${CORE_MODULE}`);
|
||||
}
|
||||
return CORE_SUPPORTED_SYMBOLS.get(name) !;
|
||||
return CORE_SUPPORTED_SYMBOLS.get(name)!;
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
* @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
|
||||
*/
|
||||
|
||||
import * as ts from 'typescript';
|
||||
|
||||
@ -96,7 +96,7 @@ export class DefaultImportTracker implements DefaultImportRecorder {
|
||||
if (!this.sourceFileToImportMap.has(sf)) {
|
||||
this.sourceFileToImportMap.set(sf, new Map<ts.Identifier, ts.ImportDeclaration>());
|
||||
}
|
||||
this.sourceFileToImportMap.get(sf) !.set(id, decl);
|
||||
this.sourceFileToImportMap.get(sf)!.set(id, decl);
|
||||
}
|
||||
|
||||
recordUsedIdentifier(id: ts.Identifier): void {
|
||||
@ -105,18 +105,18 @@ export class DefaultImportTracker implements DefaultImportRecorder {
|
||||
// The identifier's source file has no registered default imports at all.
|
||||
return;
|
||||
}
|
||||
const identiferToDeclaration = this.sourceFileToImportMap.get(sf) !;
|
||||
const identiferToDeclaration = this.sourceFileToImportMap.get(sf)!;
|
||||
if (!identiferToDeclaration.has(id)) {
|
||||
// The identifier isn't from a registered default import.
|
||||
return;
|
||||
}
|
||||
const decl = identiferToDeclaration.get(id) !;
|
||||
const decl = identiferToDeclaration.get(id)!;
|
||||
|
||||
// Add the default import declaration to the set of used import declarations for the file.
|
||||
if (!this.sourceFileToUsedImports.has(sf)) {
|
||||
this.sourceFileToUsedImports.set(sf, new Set<ts.ImportDeclaration>());
|
||||
}
|
||||
this.sourceFileToUsedImports.get(sf) !.add(decl);
|
||||
this.sourceFileToUsedImports.get(sf)!.add(decl);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -127,7 +127,9 @@ export class DefaultImportTracker implements DefaultImportRecorder {
|
||||
*/
|
||||
importPreservingTransformer(): ts.TransformerFactory<ts.SourceFile> {
|
||||
return (context: ts.TransformationContext) => {
|
||||
return (sf: ts.SourceFile) => { return this.transformSourceFile(sf); };
|
||||
return (sf: ts.SourceFile) => {
|
||||
return this.transformSourceFile(sf);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@ -142,7 +144,7 @@ export class DefaultImportTracker implements DefaultImportRecorder {
|
||||
}
|
||||
|
||||
// There are declarations that need to be preserved.
|
||||
const importsToPreserve = this.sourceFileToUsedImports.get(originalSf) !;
|
||||
const importsToPreserve = this.sourceFileToUsedImports.get(originalSf)!;
|
||||
|
||||
// Generate a new statement list which preserves any imports present in `importsToPreserve`.
|
||||
const statements = sf.statements.map(stmt => {
|
||||
|
@ -9,7 +9,7 @@ import {Expression, ExternalExpr, ExternalReference, WrappedNodeExpr} from '@ang
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {UnifiedModulesHost} from '../../core/api';
|
||||
import {LogicalFileSystem, LogicalProjectPath, PathSegment, absoluteFromSourceFile, dirname, relative} from '../../file_system';
|
||||
import {absoluteFromSourceFile, dirname, LogicalFileSystem, LogicalProjectPath, PathSegment, relative} from '../../file_system';
|
||||
import {stripExtension} from '../../file_system/src/util';
|
||||
import {ReflectionHost} from '../../reflection';
|
||||
import {getSourceFile, isDeclaration, isTypeDeclaration, nodeNameForError} from '../../util/src/typescript';
|
||||
@ -93,8 +93,8 @@ export class ReferenceEmitter {
|
||||
return emitted;
|
||||
}
|
||||
}
|
||||
throw new Error(
|
||||
`Unable to write a reference to ${nodeNameForError(ref.node)} in ${ref.node.getSourceFile().fileName} from ${context.fileName}`);
|
||||
throw new Error(`Unable to write a reference to ${nodeNameForError(ref.node)} in ${
|
||||
ref.node.getSourceFile().fileName} from ${context.fileName}`);
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,11 +149,11 @@ export class AbsoluteModuleStrategy implements ReferenceEmitStrategy {
|
||||
return null;
|
||||
} else if (!isDeclaration(ref.node)) {
|
||||
// It's not possible to import something which isn't a declaration.
|
||||
throw new Error(
|
||||
`Debug assert: unable to import a Reference to non-declaration of type ${ts.SyntaxKind[ref.node.kind]}.`);
|
||||
throw new Error(`Debug assert: unable to import a Reference to non-declaration of type ${
|
||||
ts.SyntaxKind[ref.node.kind]}.`);
|
||||
} else if ((importFlags & ImportFlags.AllowTypeImports) === 0 && isTypeDeclaration(ref.node)) {
|
||||
throw new Error(
|
||||
`Importing a type-only declaration of type ${ts.SyntaxKind[ref.node.kind]} in a value position is not allowed.`);
|
||||
throw new Error(`Importing a type-only declaration of type ${
|
||||
ts.SyntaxKind[ref.node.kind]} in a value position is not allowed.`);
|
||||
}
|
||||
|
||||
// Try to find the exported name of the declaration, if one is available.
|
||||
@ -162,8 +162,9 @@ export class AbsoluteModuleStrategy implements ReferenceEmitStrategy {
|
||||
if (symbolName === null) {
|
||||
// TODO(alxhub): make this error a ts.Diagnostic pointing at whatever caused this import to be
|
||||
// triggered.
|
||||
throw new Error(
|
||||
`Symbol ${ref.debugName} declared in ${getSourceFile(ref.node).fileName} is not exported from ${specifier} (import into ${context.fileName})`);
|
||||
throw new Error(`Symbol ${ref.debugName} declared in ${
|
||||
getSourceFile(ref.node).fileName} is not exported from ${specifier} (import into ${
|
||||
context.fileName})`);
|
||||
}
|
||||
|
||||
return new ExternalExpr(new ExternalReference(specifier, symbolName));
|
||||
@ -173,7 +174,7 @@ export class AbsoluteModuleStrategy implements ReferenceEmitStrategy {
|
||||
|null {
|
||||
const exports = this.getExportsOfModule(moduleName, fromFile);
|
||||
if (exports !== null && exports.has(target)) {
|
||||
return exports.get(target) !;
|
||||
return exports.get(target)!;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -184,7 +185,7 @@ export class AbsoluteModuleStrategy implements ReferenceEmitStrategy {
|
||||
if (!this.moduleExportsCache.has(moduleName)) {
|
||||
this.moduleExportsCache.set(moduleName, this.enumerateExportsOfModule(moduleName, fromFile));
|
||||
}
|
||||
return this.moduleExportsCache.get(moduleName) !;
|
||||
return this.moduleExportsCache.get(moduleName)!;
|
||||
}
|
||||
|
||||
protected enumerateExportsOfModule(specifier: string, fromFile: string):
|
||||
|
@ -80,7 +80,9 @@ export class Reference<T extends ts.Node = ts.Node> {
|
||||
*
|
||||
* See `bestGuessOwningModule`.
|
||||
*/
|
||||
get hasOwningModuleGuess(): boolean { return this.bestGuessOwningModule !== null; }
|
||||
get hasOwningModuleGuess(): boolean {
|
||||
return this.bestGuessOwningModule !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A name for the node, if one is available.
|
||||
@ -93,14 +95,18 @@ export class Reference<T extends ts.Node = ts.Node> {
|
||||
return id !== null ? id.text : null;
|
||||
}
|
||||
|
||||
get alias(): Expression|null { return this._alias; }
|
||||
get alias(): Expression|null {
|
||||
return this._alias;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Record a `ts.Identifier` by which it's valid to refer to this node, within the context of this
|
||||
* `Reference`.
|
||||
*/
|
||||
addIdentifier(identifier: ts.Identifier): void { this.identifiers.push(identifier); }
|
||||
addIdentifier(identifier: ts.Identifier): void {
|
||||
this.identifiers.push(identifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a `ts.Identifier` within this `Reference` that can be used to refer within the context of a
|
||||
|
@ -39,7 +39,7 @@ runInEachFileSystem(() => {
|
||||
module: ts.ModuleKind.ES2015,
|
||||
});
|
||||
const fooClause = getDeclaration(program, _('/test.ts'), 'Foo', ts.isImportClause);
|
||||
const fooId = fooClause.name !;
|
||||
const fooId = fooClause.name!;
|
||||
const fooDecl = fooClause.parent;
|
||||
|
||||
const tracker = new DefaultImportTracker();
|
||||
@ -48,7 +48,7 @@ runInEachFileSystem(() => {
|
||||
program.emit(undefined, undefined, undefined, undefined, {
|
||||
before: [tracker.importPreservingTransformer()],
|
||||
});
|
||||
const testContents = host.readFile('/test.js') !;
|
||||
const testContents = host.readFile('/test.js')!;
|
||||
expect(testContents).toContain(`import Foo from './dep';`);
|
||||
|
||||
// The control should have the import elided.
|
||||
@ -69,7 +69,7 @@ runInEachFileSystem(() => {
|
||||
module: ts.ModuleKind.CommonJS,
|
||||
});
|
||||
const fooClause = getDeclaration(program, _('/test.ts'), 'Foo', ts.isImportClause);
|
||||
const fooId = ts.updateIdentifier(fooClause.name !);
|
||||
const fooId = ts.updateIdentifier(fooClause.name!);
|
||||
const fooDecl = fooClause.parent;
|
||||
|
||||
const tracker = new DefaultImportTracker();
|
||||
@ -81,7 +81,7 @@ runInEachFileSystem(() => {
|
||||
tracker.importPreservingTransformer(),
|
||||
],
|
||||
});
|
||||
const testContents = host.readFile('/test.js') !;
|
||||
const testContents = host.readFile('/test.js')!;
|
||||
expect(testContents).toContain(`var dep_1 = require("./dep");`);
|
||||
expect(testContents).toContain(`var ref = dep_1["default"];`);
|
||||
});
|
||||
|
@ -8,8 +8,8 @@
|
||||
import {ExternalExpr} from '@angular/compiler';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {LogicalFileSystem, absoluteFrom as _} from '../../file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../file_system/testing';
|
||||
import {absoluteFrom as _, LogicalFileSystem} from '../../file_system';
|
||||
import {runInEachFileSystem, TestFile} from '../../file_system/testing';
|
||||
import {Declaration, TypeScriptReflectionHost} from '../../reflection';
|
||||
import {getDeclaration, makeProgram} from '../../testing';
|
||||
import {AbsoluteModuleStrategy, ImportFlags, LogicalProjectStrategy} from '../src/emitter';
|
||||
@ -42,7 +42,7 @@ runInEachFileSystem(() => {
|
||||
]);
|
||||
const decl =
|
||||
getDeclaration(program, _('/node_modules/external.d.ts'), 'Foo', ts.isClassDeclaration);
|
||||
const context = program.getSourceFile(_('/context.ts')) !;
|
||||
const context = program.getSourceFile(_('/context.ts'))!;
|
||||
|
||||
const reference = new Reference(decl);
|
||||
const emitted = strategy.emit(reference, context, ImportFlags.None);
|
||||
@ -65,7 +65,7 @@ runInEachFileSystem(() => {
|
||||
]);
|
||||
const decl =
|
||||
getDeclaration(program, _('/node_modules/external.d.ts'), 'Foo', ts.isClassDeclaration);
|
||||
const context = program.getSourceFile(_('/context.ts')) !;
|
||||
const context = program.getSourceFile(_('/context.ts'))!;
|
||||
|
||||
const reference = new Reference(decl, {
|
||||
specifier: 'external',
|
||||
@ -92,7 +92,7 @@ runInEachFileSystem(() => {
|
||||
]);
|
||||
const decl = getDeclaration(
|
||||
program, _('/node_modules/external.d.ts'), 'Foo', ts.isInterfaceDeclaration);
|
||||
const context = program.getSourceFile(_('/context.ts')) !;
|
||||
const context = program.getSourceFile(_('/context.ts'))!;
|
||||
|
||||
const reference = new Reference(decl, {
|
||||
specifier: 'external',
|
||||
@ -116,7 +116,7 @@ runInEachFileSystem(() => {
|
||||
]);
|
||||
const decl = getDeclaration(
|
||||
program, _('/node_modules/external.d.ts'), 'Foo', ts.isInterfaceDeclaration);
|
||||
const context = program.getSourceFile(_('/context.ts')) !;
|
||||
const context = program.getSourceFile(_('/context.ts'))!;
|
||||
|
||||
const reference =
|
||||
new Reference(decl, {specifier: 'external', resolutionContext: context.fileName});
|
||||
@ -139,7 +139,9 @@ runInEachFileSystem(() => {
|
||||
return null;
|
||||
}
|
||||
const fakeExports = new Map<string, Declaration>();
|
||||
realExports.forEach((decl, name) => { fakeExports.set(`test${name}`, decl); });
|
||||
realExports.forEach((decl, name) => {
|
||||
fakeExports.set(`test${name}`, decl);
|
||||
});
|
||||
return fakeExports;
|
||||
}
|
||||
}
|
||||
@ -158,12 +160,12 @@ runInEachFileSystem(() => {
|
||||
const logicalFs = new LogicalFileSystem([_('/')]);
|
||||
const strategy = new LogicalProjectStrategy(new TestHost(checker), logicalFs);
|
||||
const decl = getDeclaration(program, _('/index.ts'), 'Foo', ts.isClassDeclaration);
|
||||
const context = program.getSourceFile(_('/context.ts')) !;
|
||||
const context = program.getSourceFile(_('/context.ts'))!;
|
||||
const ref = strategy.emit(new Reference(decl), context);
|
||||
expect(ref).not.toBeNull();
|
||||
|
||||
// Expect the prefixed name from the TestHost.
|
||||
expect((ref !as ExternalExpr).value.name).toEqual('testFoo');
|
||||
expect((ref! as ExternalExpr).value.name).toEqual('testFoo');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user