From cd29d68f3c2de303e2922af23f7405b582973ac8 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Wed, 19 Apr 2017 16:09:06 -0700 Subject: [PATCH] refactor(tsc-wrapped): cleanup (#16178) PR Close #16178 --- tools/@angular/tsc-wrapped/src/bundler.ts | 29 ++++++------------- tools/@angular/tsc-wrapped/src/collector.ts | 2 -- .../@angular/tsc-wrapped/src/compiler_host.ts | 4 +-- tools/@angular/tsc-wrapped/src/evaluator.ts | 4 +-- tools/@angular/tsc-wrapped/src/main.ts | 4 +-- tools/@angular/tsc-wrapped/src/vinyl_file.ts | 3 +- 6 files changed, 15 insertions(+), 31 deletions(-) diff --git a/tools/@angular/tsc-wrapped/src/bundler.ts b/tools/@angular/tsc-wrapped/src/bundler.ts index 95f0bee0fa..d47fede4fe 100644 --- a/tools/@angular/tsc-wrapped/src/bundler.ts +++ b/tools/@angular/tsc-wrapped/src/bundler.ts @@ -9,14 +9,11 @@ import * as path from 'path'; import * as ts from 'typescript'; import {MetadataCollector} from './collector'; -import {ClassMetadata, ConstructorMetadata, FunctionMetadata, MemberMetadata, MetadataArray, MetadataEntry, MetadataError, MetadataImportedSymbolReferenceExpression, MetadataMap, MetadataObject, MetadataSymbolicBinaryExpression, MetadataSymbolicCallExpression, MetadataSymbolicExpression, MetadataSymbolicIfExpression, MetadataSymbolicIndexExpression, MetadataSymbolicPrefixExpression, MetadataSymbolicReferenceExpression, MetadataSymbolicSelectExpression, MetadataSymbolicSpreadExpression, MetadataValue, MethodMetadata, ModuleMetadata, VERSION, isClassMetadata, isConstructorMetadata, isFunctionMetadata, isInterfaceMetadata, isMetadataError, isMetadataGlobalReferenceExpression, isMetadataImportedSymbolReferenceExpression, isMetadataModuleReferenceExpression, isMetadataSymbolicExpression, isMetadataSymbolicReferenceExpression, isMethodMetadata} from './schema'; +import {ClassMetadata, ConstructorMetadata, FunctionMetadata, MemberMetadata, MetadataEntry, MetadataError, MetadataImportedSymbolReferenceExpression, MetadataMap, MetadataObject, MetadataSymbolicExpression, MetadataSymbolicReferenceExpression, MetadataValue, MethodMetadata, ModuleMetadata, VERSION, isClassMetadata, isConstructorMetadata, isFunctionMetadata, isInterfaceMetadata, isMetadataError, isMetadataGlobalReferenceExpression, isMetadataImportedSymbolReferenceExpression, isMetadataModuleReferenceExpression, isMetadataSymbolicExpression, isMethodMetadata} from './schema'; // The character set used to produce private names. -const PRIVATE_NAME_CHARS = [ - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', - 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' -]; +const PRIVATE_NAME_CHARS = 'abcdefghijklmnopqrstuvwxyz'; interface Symbol { module: string; @@ -199,7 +196,6 @@ export class MetadataBundler { private canonicalizeSymbols(exportedSymbols: Symbol[]) { const symbols = Array.from(this.symbolMap.values()); this.exported = new Set(exportedSymbols); - ; symbols.forEach(this.canonicalizeSymbol, this); } @@ -433,18 +429,15 @@ export class MetadataBundler { if (isMetadataImportedSymbolReferenceExpression(value)) { // References to imported symbols are separated into two, references to bundled modules and - // references to modules - // external to the bundle. If the module reference is relative it is assuemd to be in the - // bundle. If it is Global - // it is assumed to be outside the bundle. References to symbols outside the bundle are left - // unmodified. Refernces - // to symbol inside the bundle need to be converted to a bundle import reference reachable - // from the bundle index. + // references to modules external to the bundle. If the module reference is relative it is + // assumed to be in the bundle. If it is Global it is assumed to be outside the bundle. + // References to symbols outside the bundle are left unmodified. References to symbol inside + // the bundle need to be converted to a bundle import reference reachable from the bundle + // index. if (value.module.startsWith('.')) { // Reference is to a symbol defined inside the module. Convert the reference to a reference - // to the canonical - // symbol. + // to the canonical symbol. const referencedModule = resolveModule(value.module, moduleName); const referencedName = value.name; return createReference(this.canonicalSymbolOf(referencedModule, referencedName)); @@ -453,7 +446,7 @@ export class MetadataBundler { // Value is a reference to a symbol defined outside the module. if (value.arguments) { // If a reference has arguments the arguments need to be converted. - const result: MetadataImportedSymbolReferenceExpression = { + return { __symbolic: 'reference', name: value.name, module: value.module, @@ -538,10 +531,6 @@ function isPrimitive(o: any): o is boolean|string|number { return o === null || (typeof o !== 'function' && typeof o !== 'object'); } -function isMetadataArray(o: MetadataValue): o is MetadataArray { - return Array.isArray(o); -} - function getRootExport(symbol: Symbol): Symbol { return symbol.reexportedAs ? getRootExport(symbol.reexportedAs) : symbol; } diff --git a/tools/@angular/tsc-wrapped/src/collector.ts b/tools/@angular/tsc-wrapped/src/collector.ts index 43c24a27f5..694814dcaa 100644 --- a/tools/@angular/tsc-wrapped/src/collector.ts +++ b/tools/@angular/tsc-wrapped/src/collector.ts @@ -94,7 +94,6 @@ export class MetadataCollector { value: evaluator.evaluateNode(returnStatement.expression) }; if (functionDeclaration.parameters.some(p => p.initializer != null)) { - const defaults: MetadataValue[] = []; func.defaults = functionDeclaration.parameters.map( p => p.initializer && evaluator.evaluateNode(p.initializer)); } @@ -358,7 +357,6 @@ export class MetadataCollector { case ts.SyntaxKind.ClassDeclaration: const classDeclaration = node; if (classDeclaration.name) { - const className = classDeclaration.name.text; if (isExported(classDeclaration)) { if (!metadata) metadata = {}; metadata[exportedName(classDeclaration)] = classMetadataOf(classDeclaration); diff --git a/tools/@angular/tsc-wrapped/src/compiler_host.ts b/tools/@angular/tsc-wrapped/src/compiler_host.ts index f5ab08ef67..ae8939fad1 100644 --- a/tools/@angular/tsc-wrapped/src/compiler_host.ts +++ b/tools/@angular/tsc-wrapped/src/compiler_host.ts @@ -8,7 +8,6 @@ import {writeFileSync} from 'fs'; import {normalize} from 'path'; -import * as tsickle from 'tsickle'; import * as ts from 'typescript'; import NgOptions from './options'; @@ -98,8 +97,7 @@ export class MetadataWriterHost extends DelegatingHost { } if (isDts) { // TODO: remove this early return after https://github.com/Microsoft/TypeScript/pull/8412 - // is - // released + // is released return; } diff --git a/tools/@angular/tsc-wrapped/src/evaluator.ts b/tools/@angular/tsc-wrapped/src/evaluator.ts index 5f83f6fe5c..6b5f4d3623 100644 --- a/tools/@angular/tsc-wrapped/src/evaluator.ts +++ b/tools/@angular/tsc-wrapped/src/evaluator.ts @@ -9,7 +9,7 @@ import * as ts from 'typescript'; import {CollectorOptions} from './collector'; -import {MetadataEntry, MetadataError, MetadataGlobalReferenceExpression, MetadataImportedSymbolReferenceExpression, MetadataSymbolicCallExpression, MetadataSymbolicReferenceExpression, MetadataValue, isMetadataError, isMetadataGlobalReferenceExpression, isMetadataImportedSymbolReferenceExpression, isMetadataModuleReferenceExpression, isMetadataSymbolicReferenceExpression, isMetadataSymbolicSpreadExpression} from './schema'; +import {MetadataEntry, MetadataError, MetadataImportedSymbolReferenceExpression, MetadataSymbolicCallExpression, MetadataValue, isMetadataError, isMetadataModuleReferenceExpression, isMetadataSymbolicReferenceExpression, isMetadataSymbolicSpreadExpression} from './schema'; import {Symbols} from './symbols'; // In TypeScript 2.1 the spread element kind was renamed. @@ -86,7 +86,7 @@ export function errorSymbol( const {line, character} = ts.getLineAndCharacterOfPosition(sourceFile, node.getStart(sourceFile)); result = {__symbolic: 'error', message, line, character}; - }; + } } if (!result) { result = {__symbolic: 'error', message}; diff --git a/tools/@angular/tsc-wrapped/src/main.ts b/tools/@angular/tsc-wrapped/src/main.ts index 741aa4cb0e..82455b1409 100644 --- a/tools/@angular/tsc-wrapped/src/main.ts +++ b/tools/@angular/tsc-wrapped/src/main.ts @@ -55,7 +55,7 @@ export function main( let host = ts.createCompilerHost(parsed.options, true); - // If the comilation is a flat module index then produce the flat module index + // If the compilation is a flat module index then produce the flat module index // metadata and the synthetic flat module index. if (ngOptions.flatModuleOutFile && !ngOptions.skipMetadataEmit) { const files = parsed.fileNames.filter(f => !DTS.test(f)); @@ -170,7 +170,7 @@ export function main( // CLI entry point if (require.main === module) { const args = process.argv.slice(2); - let {options, fileNames, errors} = (ts as any).parseCommandLine(args); + let {options, errors} = (ts as any).parseCommandLine(args); check(errors); const project = options.project || '.'; // TODO(alexeagle): command line should be TSC-compatible, remove "CliOptions" here diff --git a/tools/@angular/tsc-wrapped/src/vinyl_file.ts b/tools/@angular/tsc-wrapped/src/vinyl_file.ts index 41b619d48c..87ffe1d797 100644 --- a/tools/@angular/tsc-wrapped/src/vinyl_file.ts +++ b/tools/@angular/tsc-wrapped/src/vinyl_file.ts @@ -12,8 +12,7 @@ export interface VinylFile extends Object { // Content of the virtual file contents: Buffer; } -; export function isVinylFile(obj: any): obj is VinylFile { return (typeof obj === 'object') && ('path' in obj) && ('contents' in obj); -}; \ No newline at end of file +} \ No newline at end of file