Skip to content

Commit 00c30a3

Browse files
author
Yui T
committed
Merge branch 'master' into fixThrowExceptionOnEmitFile
2 parents 3cb6c9c + b757490 commit 00c30a3

File tree

275 files changed

+5909
-5690
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

275 files changed

+5909
-5690
lines changed

Jakefile

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ function concatenateFiles(destinationFile, sourceFiles) {
128128
}
129129

130130
var useDebugMode = false;
131+
var generateDeclarations = false;
131132
var host = (process.env.host || process.env.TYPESCRIPT_HOST || "node");
132133
var compilerFilename = "tsc.js";
133134
/* Compiles a file from a list of sources
@@ -142,6 +143,9 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOu
142143
file(outFile, prereqs, function() {
143144
var dir = useBuiltCompiler ? builtLocalDirectory : LKGDirectory;
144145
var options = "-removeComments --module commonjs -noImplicitAny "; //" -propagateEnumConstants "
146+
if (generateDeclarations) {
147+
options += "--declaration ";
148+
}
145149

146150
var cmd = host + " " + dir + compilerFilename + " " + options + " ";
147151
if (useDebugMode) {
@@ -250,7 +254,7 @@ task("local", ["generate-diagnostics", "lib", tscFile, servicesFile]);
250254
// Local target to build the compiler and services
251255
desc("Emit debug mode files with sourcemaps");
252256
task("debug", function() {
253-
useDebugMode = true;
257+
useDebugMode = true;
254258
});
255259

256260

@@ -264,6 +268,12 @@ task("clean", function() {
264268
jake.rmRf(builtDirectory);
265269
});
266270

271+
// generate declarations for compiler and services
272+
desc("Generate declarations for compiler and services");
273+
task("declaration", function() {
274+
generateDeclarations = true;
275+
});
276+
267277
// Generate Markdown spec
268278
var word2mdJs = path.join(scriptsDirectory, "word2md.js");
269279
var word2mdTs = path.join(scriptsDirectory, "word2md.ts");
@@ -283,12 +293,12 @@ compileFile(word2mdJs,
283293
// The generated spec.md; built for the 'generate-spec' task
284294
file(specMd, [word2mdJs, specWord], function () {
285295
jake.cpR(headerMd, specMd, {silent: true});
286-
var specWordFullPath = path.resolve(specWord);
296+
var specWordFullPath = path.resolve(specWord);
287297
var cmd = "cscript //nologo " + word2mdJs + ' "' + specWordFullPath + '" >>' + specMd;
288-
console.log(cmd);
289-
child_process.exec(cmd, function () {
290-
complete();
291-
});
298+
console.log(cmd);
299+
child_process.exec(cmd, function () {
300+
complete();
301+
});
292302
}, {async: true})
293303

294304

src/compiler/checker.ts

Lines changed: 271 additions & 241 deletions
Large diffs are not rendered by default.

src/compiler/emitter.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
/// <reference path="parser.ts"/>
55

66
module ts {
7-
interface EmitTextWriter extends TextWriter {
7+
interface EmitTextWriter extends SymbolWriter {
8+
write(s: string): void;
9+
getText(): string;
810
rawWrite(s: string): void;
911
writeLiteral(s: string): void;
1012
getTextPos(): number;
@@ -14,7 +16,7 @@ module ts {
1416
}
1517

1618
var indentStrings: string[] = ["", " "];
17-
function getIndentString(level: number) {
19+
export function getIndentString(level: number) {
1820
if (indentStrings[level] === undefined) {
1921
indentStrings[level] = getIndentString(level - 1) + indentStrings[1];
2022
}
@@ -147,9 +149,17 @@ module ts {
147149
}
148150
}
149151

152+
function writeKind(text: string, kind: SymbolDisplayPartKind) {
153+
write(text);
154+
}
155+
function writeSymbol(text: string, symbol: Symbol) {
156+
write(text);
157+
}
150158
return {
151159
write: write,
152160
trackSymbol: trackSymbol,
161+
writeKind: writeKind,
162+
writeSymbol: writeSymbol,
153163
rawWrite: rawWrite,
154164
writeLiteral: writeLiteral,
155165
writeLine: writeLine,
@@ -160,6 +170,7 @@ module ts {
160170
getLine: () => lineCount + 1,
161171
getColumn: () => lineStart ? indent * getIndentSize() + 1 : output.length - linePos + 1,
162172
getText: () => output,
173+
clear: () => { }
163174
};
164175
}
165176

src/compiler/parser.ts

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -395,100 +395,6 @@ module ts {
395395
return false;
396396
}
397397

398-
/**
399-
* Note: this function only works when given a node with valid parent pointers.
400-
*/
401-
export function isTypeNode(node: Node): boolean {
402-
if (node.kind >= SyntaxKind.FirstTypeNode && node.kind <= SyntaxKind.LastTypeNode) {
403-
return true;
404-
}
405-
406-
switch (node.kind) {
407-
case SyntaxKind.AnyKeyword:
408-
case SyntaxKind.NumberKeyword:
409-
case SyntaxKind.StringKeyword:
410-
case SyntaxKind.BooleanKeyword:
411-
return true;
412-
case SyntaxKind.VoidKeyword:
413-
return node.parent.kind !== SyntaxKind.PrefixOperator;
414-
case SyntaxKind.StringLiteral:
415-
// Specialized signatures can have string literals as their parameters' type names
416-
return node.parent.kind === SyntaxKind.Parameter;
417-
// Identifiers and qualified names may be type nodes, depending on their context. Climb
418-
// above them to find the lowest container
419-
case SyntaxKind.Identifier:
420-
// If the identifier is the RHS of a qualified name, then it's a type iff its parent is.
421-
if (node.parent.kind === SyntaxKind.QualifiedName) {
422-
node = node.parent;
423-
}
424-
// Fall through
425-
case SyntaxKind.QualifiedName:
426-
// At this point, node is either a qualified name or an identifier
427-
var parent = node.parent;
428-
if (parent.kind === SyntaxKind.TypeQuery) {
429-
return false;
430-
}
431-
// Do not recursively call isTypeNode on the parent. In the example:
432-
//
433-
// var a: A.B.C;
434-
//
435-
// Calling isTypeNode would consider the qualified name A.B a type node. Only C or
436-
// A.B.C is a type node.
437-
if (parent.kind >= SyntaxKind.FirstTypeNode && parent.kind <= SyntaxKind.LastTypeNode) {
438-
return true;
439-
}
440-
switch (parent.kind) {
441-
case SyntaxKind.TypeParameter:
442-
return node === (<TypeParameterDeclaration>parent).constraint;
443-
case SyntaxKind.Property:
444-
case SyntaxKind.Parameter:
445-
case SyntaxKind.VariableDeclaration:
446-
return node === (<VariableDeclaration>parent).type;
447-
case SyntaxKind.FunctionDeclaration:
448-
case SyntaxKind.FunctionExpression:
449-
case SyntaxKind.ArrowFunction:
450-
case SyntaxKind.Constructor:
451-
case SyntaxKind.Method:
452-
case SyntaxKind.GetAccessor:
453-
case SyntaxKind.SetAccessor:
454-
return node === (<FunctionDeclaration>parent).type;
455-
case SyntaxKind.CallSignature:
456-
case SyntaxKind.ConstructSignature:
457-
case SyntaxKind.IndexSignature:
458-
return node === (<SignatureDeclaration>parent).type;
459-
case SyntaxKind.TypeAssertion:
460-
return node === (<TypeAssertion>parent).type;
461-
case SyntaxKind.CallExpression:
462-
case SyntaxKind.NewExpression:
463-
return (<CallExpression>parent).typeArguments && (<CallExpression>parent).typeArguments.indexOf(node) >= 0;
464-
}
465-
}
466-
467-
return false;
468-
}
469-
470-
/**
471-
* Note: this function only works when given a node with valid parent pointers.
472-
*
473-
* returns true if the given identifier is the name of a type declaration node (class, interface, enum, type parameter, etc)
474-
*/
475-
export function isTypeDeclarationName(name: Node): boolean {
476-
return name.kind == SyntaxKind.Identifier &&
477-
isTypeDeclaration(name.parent) &&
478-
(<Declaration>name.parent).name === name;
479-
}
480-
481-
482-
export function isTypeDeclaration(node: Node): boolean {
483-
switch (node.kind) {
484-
case SyntaxKind.TypeParameter:
485-
case SyntaxKind.ClassDeclaration:
486-
case SyntaxKind.InterfaceDeclaration:
487-
case SyntaxKind.EnumDeclaration:
488-
return true;
489-
}
490-
}
491-
492398
export function getContainingFunction(node: Node): SignatureDeclaration {
493399
while (true) {
494400
node = node.parent;

src/compiler/types.ts

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -643,14 +643,19 @@ module ts {
643643
getTypeOfNode(node: Node): Type;
644644
getApparentType(type: Type): ApparentType;
645645
typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string;
646+
writeType(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;
646647
symbolToString(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): string;
647-
typeToDisplayParts(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): SymbolDisplayPart[];
648-
symbolToDisplayParts(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): SymbolDisplayPart[];
648+
writeSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags): void;
649649
getFullyQualifiedName(symbol: Symbol): string;
650650
getAugmentedPropertiesOfApparentType(type: Type): Symbol[];
651651
getRootSymbol(symbol: Symbol): Symbol;
652652
getContextualType(node: Node): Type;
653653
getResolvedSignature(node: CallExpression, candidatesOutArray?: Signature[]): Signature;
654+
getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature;
655+
writeSignature(signatures: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;
656+
writeTypeParameter(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;
657+
writeTypeParametersOfSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaraiton?: Node, flags?: TypeFormatFlags): void;
658+
isImplementationOfOverload(node: FunctionDeclaration): boolean;
654659

655660
// Returns the constant value of this enum member, or 'undefined' if the enum member has a
656661
// computed value.
@@ -660,20 +665,36 @@ module ts {
660665
getAliasedSymbol(symbol: Symbol): Symbol;
661666
}
662667

663-
export interface TextWriter {
664-
write(s: string): void;
665-
trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): void;
668+
export interface SymbolWriter {
669+
writeKind(text: string, kind: SymbolDisplayPartKind): void;
670+
writeSymbol(text: string, symbol: Symbol): void;
666671
writeLine(): void;
667672
increaseIndent(): void;
668673
decreaseIndent(): void;
669-
getText(): string;
674+
clear(): void;
675+
676+
// Called when the symbol writer encounters a symbol to write. Currently only used by the
677+
// declaration emitter to help determine if it should patch up the final declaration file
678+
// with import statements it previously saw (but chose not to emit).
679+
trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): void;
670680
}
671681

672682
export enum TypeFormatFlags {
673-
None = 0x00000000,
674-
WriteArrayAsGenericType = 0x00000001, // Write Array<T> instead T[]
675-
UseTypeOfFunction = 0x00000002, // Write typeof instead of function type literal
676-
NoTruncation = 0x00000004, // Don't truncate typeToString result
683+
None = 0x00000000,
684+
WriteArrayAsGenericType = 0x00000001, // Write Array<T> instead T[]
685+
UseTypeOfFunction = 0x00000002, // Write typeof instead of function type literal
686+
NoTruncation = 0x00000004, // Don't truncate typeToString result
687+
WriteArrowStyleSignature = 0x00000008, // Write arrow style signature
688+
WriteOwnNameForAnyLike = 0x00000010, // Write symbol's own name instead of 'any' for any like types (eg. unknown, __resolving__ etc)
689+
WriteTypeArgumentsOfSignature = 0x00000020, // Write the type arguments instead of type parameters of the signature
690+
}
691+
692+
export enum SymbolFormatFlags {
693+
None = 0x00000000,
694+
WriteTypeParametersOrArguments = 0x00000001, // Write symbols's type argument if it is instantiated symbol
695+
// eg. class C<T> { p: T } <-- Show p as C<T>.p here
696+
// var a: C<number>;
697+
// var p = a.p; <--- Here p is property of C<number> so show it as C<number>.p instead of just C.p
677698
}
678699

679700
export enum SymbolAccessibility {
@@ -701,8 +722,8 @@ module ts {
701722
hasSemanticErrors(): boolean;
702723
isDeclarationVisible(node: Declaration): boolean;
703724
isImplementationOfOverload(node: FunctionDeclaration): boolean;
704-
writeTypeAtLocation(location: Node, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: TextWriter): void;
705-
writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: TextWriter): void;
725+
writeTypeAtLocation(location: Node, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
726+
writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
706727
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult;
707728
isImportDeclarationEntityNameReferenceDeclarationVisibile(entityName: EntityName): SymbolAccessiblityResult;
708729

@@ -743,6 +764,8 @@ module ts {
743764
Transient = 0x02000000, // Transient symbol (created during type check)
744765
Prototype = 0x04000000, // Symbol for the prototype property (without source code representation)
745766

767+
Undefined = 0x08000000, // Symbol for the undefined
768+
746769
Value = Variable | Property | EnumMember | Function | Class | Enum | ValueModule | Method | GetAccessor | SetAccessor,
747770
Type = Class | Interface | Enum | TypeLiteral | ObjectLiteral | TypeParameter,
748771
Namespace = ValueModule | NamespaceModule,
@@ -1190,45 +1213,24 @@ module ts {
11901213
verticalTab = 0x0B, // \v
11911214
}
11921215

1193-
export class SymbolDisplayPart {
1194-
constructor(public text: string,
1195-
public kind: SymbolDisplayPartKind,
1196-
public symbol: Symbol) {
1197-
}
1198-
1199-
public toJSON() {
1200-
return {
1201-
text: this.text,
1202-
kind: SymbolDisplayPartKind[this.kind]
1203-
};
1204-
}
1205-
1206-
public static toString(parts: SymbolDisplayPart[]) {
1207-
return parts.map(p => p.text).join("");
1208-
}
1209-
}
1210-
12111216
export enum SymbolDisplayPartKind {
12121217
aliasName,
12131218
className,
12141219
enumName,
12151220
fieldName,
12161221
interfaceName,
12171222
keyword,
1218-
labelName,
12191223
lineBreak,
12201224
numericLiteral,
12211225
stringLiteral,
12221226
localName,
12231227
methodName,
12241228
moduleName,
1225-
namespaceName,
12261229
operator,
12271230
parameterName,
12281231
propertyName,
12291232
punctuation,
12301233
space,
1231-
anonymousTypeIndicator,
12321234
text,
12331235
typeParameterName,
12341236
enumMemberName,

0 commit comments

Comments
 (0)