Skip to content
Prev Previous commit
Next Next commit
Use of union types and type aliases in compiler
  • Loading branch information
ahejlsberg committed Oct 28, 2014
commit 1fede10b6c8ef48156520a32a5825565f3680982
14 changes: 7 additions & 7 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ module ts {
// import a = |b.c|; // Value, type, namespace
// import a = |b.c|.d; // Namespace
if (entityName.kind === SyntaxKind.Identifier && isRightSideOfQualifiedNameOrPropertyAccess(entityName)) {
entityName = entityName.parent;
entityName = <QualifiedName>entityName.parent;
}
// Check for case 1 and 3 in the above example
if (entityName.kind === SyntaxKind.Identifier || entityName.parent.kind === SyntaxKind.QualifiedName) {
Expand Down Expand Up @@ -8070,7 +8070,7 @@ module ts {

function isInRightSideOfImportOrExportAssignment(node: EntityName) {
while (node.parent.kind === SyntaxKind.QualifiedName) {
node = node.parent;
node = <QualifiedName>node.parent;
}

if (node.parent.kind === SyntaxKind.ImportDeclaration) {
Expand Down Expand Up @@ -8104,7 +8104,7 @@ module ts {
}

if (isRightSideOfQualifiedNameOrPropertyAccess(entityName)) {
entityName = entityName.parent;
entityName = <QualifiedName>entityName.parent;
}

if (isExpression(entityName)) {
Expand All @@ -8117,7 +8117,7 @@ module ts {
else if (entityName.kind === SyntaxKind.QualifiedName || entityName.kind === SyntaxKind.PropertyAccess) {
var symbol = getNodeLinks(entityName).resolvedSymbol;
if (!symbol) {
checkPropertyAccess(<PropertyAccess>entityName);
checkPropertyAccess(<QualifiedName>entityName);
}
return getNodeLinks(entityName).resolvedSymbol;
}
Expand Down Expand Up @@ -8149,10 +8149,10 @@ module ts {
return getSymbolOfNode(node.parent);
}

if (node.kind === SyntaxKind.Identifier && isInRightSideOfImportOrExportAssignment(node)) {
if (node.kind === SyntaxKind.Identifier && isInRightSideOfImportOrExportAssignment(<Identifier>node)) {
return node.parent.kind === SyntaxKind.ExportAssignment
? getSymbolOfEntityName(<Identifier>node)
: getSymbolOfPartOfRightHandSideOfImport(node);
: getSymbolOfPartOfRightHandSideOfImport(<Identifier>node);
}

switch (node.kind) {
Expand Down Expand Up @@ -8233,7 +8233,7 @@ module ts {
return symbol && getTypeOfSymbol(symbol);
}

if (isInRightSideOfImportOrExportAssignment(node)) {
if (isInRightSideOfImportOrExportAssignment(<Identifier>node)) {
var symbol = getSymbolInfo(node);
var declaredType = symbol && getDeclaredTypeOfSymbol(symbol);
return declaredType !== unknownType ? declaredType : getTypeOfSymbol(symbol);
Expand Down
7 changes: 4 additions & 3 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,10 @@ module ts {
break;
// If not a primitive, the possible types are specified in what is effectively a map of options.
default:
var value = (args[i++] || "").toLowerCase();
if (hasProperty(opt.type, value)) {
options[opt.name] = opt.type[value];
var map = <Map<number>>opt.type;
var key = (args[i++] || "").toLowerCase();
if (hasProperty(map, key)) {
options[opt.name] = map[key];
}
else {
errors.push(createCompilerDiagnostic(opt.error));
Expand Down
1 change: 0 additions & 1 deletion src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,6 @@ module ts {
return finishNode(node);
}
error(Diagnostics.Identifier_expected);

var node = <Identifier>createMissingNode();
node.text = "";
return node;
Expand Down
71 changes: 24 additions & 47 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,7 @@ module ts {
right: Identifier;
}

export interface EntityName extends Node {
// Identifier, QualifiedName, or Missing
}
export type EntityName = Identifier | QualifiedName;

export interface ParsedSignature {
typeParameters?: NodeArray<TypeParameterDeclaration>;
Expand Down Expand Up @@ -312,7 +310,7 @@ module ts {
export interface ParameterDeclaration extends VariableDeclaration { }

export interface FunctionDeclaration extends Declaration, ParsedSignature {
body?: Node; // Block or Expression
body?: Block | Expression;
}

export interface MethodDeclaration extends FunctionDeclaration { }
Expand Down Expand Up @@ -378,7 +376,7 @@ module ts {
}

export interface FunctionExpression extends Expression, FunctionDeclaration {
body: Node; // Required, whereas the member inherited from FunctionDeclaration is optional
body: Block | Expression; // Required, whereas the member inherited from FunctionDeclaration is optional
}

// The text property of a LiteralExpression stores the interpreted value of the literal in text form. For a StringLiteral
Expand Down Expand Up @@ -536,7 +534,7 @@ module ts {
}

export interface ModuleDeclaration extends Declaration {
body: Node; // Block or ModuleDeclaration
body: Block | ModuleDeclaration;
}

export interface ImportDeclaration extends Declaration {
Expand Down Expand Up @@ -588,40 +586,24 @@ module ts {
}

export interface SourceMapSpan {
/** Line number in the js file*/
emittedLine: number;
/** Column number in the js file */
emittedColumn: number;
/** Line number in the ts file */
sourceLine: number;
/** Column number in the ts file */
sourceColumn: number;
/** Optional name (index into names array) associated with this span */
nameIndex?: number;
/** ts file (index into sources array) associated with this span*/
sourceIndex: number;
emittedLine: number; // Line number in the .js file
emittedColumn: number; // Column number in the .js file
sourceLine: number; // Line number in the .ts file
sourceColumn: number; // Column number in the .ts file
nameIndex?: number; // Optional name (index into names array) associated with this span
sourceIndex: number; // .ts file (index into sources array) associated with this span*/
}

export interface SourceMapData {
/** Where the sourcemap file is written */
sourceMapFilePath: string;
/** source map URL written in the js file */
jsSourceMappingURL: string;
/** Source map's file field - js file name*/
sourceMapFile: string;
/** Source map's sourceRoot field - location where the sources will be present if not "" */
sourceMapSourceRoot: string;
/** Source map's sources field - list of sources that can be indexed in this source map*/
sourceMapSources: string[];
/** input source file (which one can use on program to get the file)
this is one to one mapping with the sourceMapSources list*/
inputSourceFileNames: string[];
/** Source map's names field - list of names that can be indexed in this source map*/
sourceMapNames?: string[];
/** Source map's mapping field - encoded source map spans*/
sourceMapMappings: string;
/** Raw source map spans that were encoded into the sourceMapMappings*/
sourceMapDecodedMappings: SourceMapSpan[];
sourceMapFilePath: string; // Where the sourcemap file is written
jsSourceMappingURL: string; // source map URL written in the .js file
sourceMapFile: string; // Source map's file field - .js file name
sourceMapSourceRoot: string; // Source map's sourceRoot field - location where the sources will be present if not ""
sourceMapSources: string[]; // Source map's sources field - list of sources that can be indexed in this source map
inputSourceFileNames: string[]; // Input source file (which one can use on program to get the file), 1:1 mapping with the sourceMapSources list
sourceMapNames?: string[]; // Source map's names field - list of names that can be indexed in this source map
sourceMapMappings: string; // Source map's mapping field - encoded source map spans
sourceMapDecodedMappings: SourceMapSpan[]; // Raw source map spans that were encoded into the sourceMapMappings
}

// Return code used by getEmitOutput function to indicate status of the function
Expand Down Expand Up @@ -674,11 +656,8 @@ module ts {
isUndefinedSymbol(symbol: Symbol): boolean;
isArgumentsSymbol(symbol: Symbol): boolean;
hasEarlyErrors(sourceFile?: SourceFile): boolean;

// Returns the constant value of this enum member, or 'undefined' if the enum member has a
// computed value.
// Returns the constant value of this enum member, or 'undefined' if the enum member has a computed value.
getEnumMemberValue(node: EnumMember): number;

isValidPropertyAccess(node: PropertyAccess, propertyName: string): boolean;
getAliasedSymbol(symbol: Symbol): Symbol;
}
Expand Down Expand Up @@ -765,16 +744,14 @@ module ts {
writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult;
isImportDeclarationEntityNameReferenceDeclarationVisibile(entityName: EntityName): SymbolAccessiblityResult;

// Returns the constant value this property access resolves to, or 'undefined' if it does
// resolve to a constant.
// Returns the constant value this property access resolves to, or 'undefined' for a non-constant
getConstantValue(node: PropertyAccess): number;
hasEarlyErrors(sourceFile?: SourceFile): boolean;
}

export enum SymbolFlags {
FunctionScopedVariable = 0x00000001, // Variable (var) or parameter
BlockScopedVariable = 0x00000002, // A block-scoped variable (let ot const)
BlockScopedVariable = 0x00000002, // A block-scoped variable (let or const)
Property = 0x00000004, // Property or enum member
EnumMember = 0x00000008, // Enum member
Function = 0x00000010, // Function
Expand Down Expand Up @@ -1097,7 +1074,7 @@ module ts {
target?: ScriptTarget;
version?: boolean;
watch?: boolean;
[option: string]: any;
[option: string]: string | number | boolean;
}

export enum ModuleKind {
Expand Down Expand Up @@ -1130,7 +1107,7 @@ module ts {

export interface CommandLineOption {
name: string;
type: any; // "string", "number", "boolean", or an object literal mapping named values to actual values
type: string | Map<number>; // "string", "number", "boolean", or an object literal mapping named values to actual values
shortName?: string; // A short pneumonic for convenience - for instance, 'h' can be used in place of 'help'.
description?: DiagnosticMessage; // The message describing what the command line switch does
paramName?: DiagnosticMessage; // The name to be used for a non-boolean option's parameter.
Expand Down