refactor(tsc-wrapped): cleanup (#16178)

PR Close #16178
This commit is contained in:
Victor Berchet 2017-04-19 16:09:06 -07:00 committed by Miško Hevery
parent da668848c9
commit cd29d68f3c
6 changed files with 15 additions and 31 deletions

View File

@ -9,14 +9,11 @@ import * as path from 'path';
import * as ts from 'typescript'; import * as ts from 'typescript';
import {MetadataCollector} from './collector'; 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. // The character set used to produce private names.
const PRIVATE_NAME_CHARS = [ const PRIVATE_NAME_CHARS = 'abcdefghijklmnopqrstuvwxyz';
'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'
];
interface Symbol { interface Symbol {
module: string; module: string;
@ -199,7 +196,6 @@ export class MetadataBundler {
private canonicalizeSymbols(exportedSymbols: Symbol[]) { private canonicalizeSymbols(exportedSymbols: Symbol[]) {
const symbols = Array.from(this.symbolMap.values()); const symbols = Array.from(this.symbolMap.values());
this.exported = new Set(exportedSymbols); this.exported = new Set(exportedSymbols);
;
symbols.forEach(this.canonicalizeSymbol, this); symbols.forEach(this.canonicalizeSymbol, this);
} }
@ -433,18 +429,15 @@ export class MetadataBundler {
if (isMetadataImportedSymbolReferenceExpression(value)) { if (isMetadataImportedSymbolReferenceExpression(value)) {
// References to imported symbols are separated into two, references to bundled modules and // References to imported symbols are separated into two, references to bundled modules and
// references to modules // references to modules external to the bundle. If the module reference is relative it is
// external to the bundle. If the module reference is relative it is assuemd to be in the // assumed to be in the bundle. If it is Global it is assumed to be outside the bundle.
// bundle. If it is Global // References to symbols outside the bundle are left unmodified. References to symbol inside
// it is assumed to be outside the bundle. References to symbols outside the bundle are left // the bundle need to be converted to a bundle import reference reachable from the bundle
// unmodified. Refernces // index.
// to symbol inside the bundle need to be converted to a bundle import reference reachable
// from the bundle index.
if (value.module.startsWith('.')) { if (value.module.startsWith('.')) {
// Reference is to a symbol defined inside the module. Convert the reference to a reference // Reference is to a symbol defined inside the module. Convert the reference to a reference
// to the canonical // to the canonical symbol.
// symbol.
const referencedModule = resolveModule(value.module, moduleName); const referencedModule = resolveModule(value.module, moduleName);
const referencedName = value.name; const referencedName = value.name;
return createReference(this.canonicalSymbolOf(referencedModule, referencedName)); return createReference(this.canonicalSymbolOf(referencedModule, referencedName));
@ -453,7 +446,7 @@ export class MetadataBundler {
// Value is a reference to a symbol defined outside the module. // Value is a reference to a symbol defined outside the module.
if (value.arguments) { if (value.arguments) {
// If a reference has arguments the arguments need to be converted. // If a reference has arguments the arguments need to be converted.
const result: MetadataImportedSymbolReferenceExpression = { return {
__symbolic: 'reference', __symbolic: 'reference',
name: value.name, name: value.name,
module: value.module, 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'); 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 { function getRootExport(symbol: Symbol): Symbol {
return symbol.reexportedAs ? getRootExport(symbol.reexportedAs) : symbol; return symbol.reexportedAs ? getRootExport(symbol.reexportedAs) : symbol;
} }

View File

@ -94,7 +94,6 @@ export class MetadataCollector {
value: evaluator.evaluateNode(returnStatement.expression) value: evaluator.evaluateNode(returnStatement.expression)
}; };
if (functionDeclaration.parameters.some(p => p.initializer != null)) { if (functionDeclaration.parameters.some(p => p.initializer != null)) {
const defaults: MetadataValue[] = [];
func.defaults = functionDeclaration.parameters.map( func.defaults = functionDeclaration.parameters.map(
p => p.initializer && evaluator.evaluateNode(p.initializer)); p => p.initializer && evaluator.evaluateNode(p.initializer));
} }
@ -358,7 +357,6 @@ export class MetadataCollector {
case ts.SyntaxKind.ClassDeclaration: case ts.SyntaxKind.ClassDeclaration:
const classDeclaration = <ts.ClassDeclaration>node; const classDeclaration = <ts.ClassDeclaration>node;
if (classDeclaration.name) { if (classDeclaration.name) {
const className = classDeclaration.name.text;
if (isExported(classDeclaration)) { if (isExported(classDeclaration)) {
if (!metadata) metadata = {}; if (!metadata) metadata = {};
metadata[exportedName(classDeclaration)] = classMetadataOf(classDeclaration); metadata[exportedName(classDeclaration)] = classMetadataOf(classDeclaration);

View File

@ -8,7 +8,6 @@
import {writeFileSync} from 'fs'; import {writeFileSync} from 'fs';
import {normalize} from 'path'; import {normalize} from 'path';
import * as tsickle from 'tsickle';
import * as ts from 'typescript'; import * as ts from 'typescript';
import NgOptions from './options'; import NgOptions from './options';
@ -98,8 +97,7 @@ export class MetadataWriterHost extends DelegatingHost {
} }
if (isDts) { if (isDts) {
// TODO: remove this early return after https://github.com/Microsoft/TypeScript/pull/8412 // TODO: remove this early return after https://github.com/Microsoft/TypeScript/pull/8412
// is // is released
// released
return; return;
} }

View File

@ -9,7 +9,7 @@
import * as ts from 'typescript'; import * as ts from 'typescript';
import {CollectorOptions} from './collector'; 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'; import {Symbols} from './symbols';
// In TypeScript 2.1 the spread element kind was renamed. // In TypeScript 2.1 the spread element kind was renamed.
@ -86,7 +86,7 @@ export function errorSymbol(
const {line, character} = const {line, character} =
ts.getLineAndCharacterOfPosition(sourceFile, node.getStart(sourceFile)); ts.getLineAndCharacterOfPosition(sourceFile, node.getStart(sourceFile));
result = {__symbolic: 'error', message, line, character}; result = {__symbolic: 'error', message, line, character};
}; }
} }
if (!result) { if (!result) {
result = {__symbolic: 'error', message}; result = {__symbolic: 'error', message};

View File

@ -55,7 +55,7 @@ export function main(
let host = ts.createCompilerHost(parsed.options, true); 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. // metadata and the synthetic flat module index.
if (ngOptions.flatModuleOutFile && !ngOptions.skipMetadataEmit) { if (ngOptions.flatModuleOutFile && !ngOptions.skipMetadataEmit) {
const files = parsed.fileNames.filter(f => !DTS.test(f)); const files = parsed.fileNames.filter(f => !DTS.test(f));
@ -170,7 +170,7 @@ export function main(
// CLI entry point // CLI entry point
if (require.main === module) { if (require.main === module) {
const args = process.argv.slice(2); 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); check(errors);
const project = options.project || '.'; const project = options.project || '.';
// TODO(alexeagle): command line should be TSC-compatible, remove "CliOptions" here // TODO(alexeagle): command line should be TSC-compatible, remove "CliOptions" here

View File

@ -12,8 +12,7 @@ export interface VinylFile extends Object {
// Content of the virtual file // Content of the virtual file
contents: Buffer; contents: Buffer;
} }
;
export function isVinylFile(obj: any): obj is VinylFile { export function isVinylFile(obj: any): obj is VinylFile {
return (typeof obj === 'object') && ('path' in obj) && ('contents' in obj); return (typeof obj === 'object') && ('path' in obj) && ('contents' in obj);
}; }