Skip to content

Commit dc40f5d

Browse files
author
Andy Hanson
committed
Merge branch 'master' into jsdoc
2 parents 0140e6d + fc4dd2b commit dc40f5d

File tree

104 files changed

+3234
-757
lines changed

Some content is hidden

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

104 files changed

+3234
-757
lines changed

Gulpfile.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ gulp.task(loggedIOJsPath, /*help*/ false, [], (done) => {
935935
const temp = path.join(builtLocalDirectory, "temp");
936936
mkdirP(temp, (err) => {
937937
if (err) { console.error(err); done(err); process.exit(1); }
938-
exec(host, [LKGCompiler, "--types --outdir", temp, loggedIOpath], () => {
938+
exec(host, [LKGCompiler, "--types", "--target es5", "--lib es5", "--outdir", temp, loggedIOpath], () => {
939939
fs.renameSync(path.join(temp, "/harness/loggedIO.js"), loggedIOJsPath);
940940
del(temp).then(() => done(), done);
941941
}, done);
@@ -946,7 +946,13 @@ const instrumenterPath = path.join(harnessDirectory, "instrumenter.ts");
946946
const instrumenterJsPath = path.join(builtLocalDirectory, "instrumenter.js");
947947
gulp.task(instrumenterJsPath, /*help*/ false, [servicesFile], () => {
948948
const settings: tsc.Settings = getCompilerSettings({
949-
outFile: instrumenterJsPath
949+
outFile: instrumenterJsPath,
950+
target: "es5",
951+
lib: [
952+
"es6",
953+
"dom",
954+
"scripthost"
955+
]
950956
}, /*useBuiltCompiler*/ true);
951957
return gulp.src(instrumenterPath)
952958
.pipe(newer(instrumenterJsPath))

src/compiler/checker.ts

Lines changed: 361 additions & 258 deletions
Large diffs are not rendered by default.

src/compiler/core.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ namespace ts {
230230
* If no such value is found, it applies the callback until the parent pointer is undefined or the callback returns "quit"
231231
* At that point findAncestor returns undefined.
232232
*/
233+
export function findAncestor<T extends Node>(node: Node, callback: (element: Node) => element is T): T | undefined;
234+
export function findAncestor(node: Node, callback: (element: Node) => boolean | "quit"): Node | undefined;
233235
export function findAncestor(node: Node, callback: (element: Node) => boolean | "quit"): Node {
234236
while (node) {
235237
const result = callback(node);
@@ -490,6 +492,35 @@ namespace ts {
490492
return result;
491493
}
492494

495+
/**
496+
* Maps an array. If the mapped value is an array, it is spread into the result.
497+
* Avoids allocation if all elements map to themselves.
498+
*
499+
* @param array The array to map.
500+
* @param mapfn The callback used to map the result into one or more values.
501+
*/
502+
export function sameFlatMap<T>(array: T[], mapfn: (x: T, i: number) => T | T[]): T[] {
503+
let result: T[];
504+
if (array) {
505+
for (let i = 0; i < array.length; i++) {
506+
const item = array[i];
507+
const mapped = mapfn(item, i);
508+
if (result || item !== mapped || isArray(mapped)) {
509+
if (!result) {
510+
result = array.slice(0, i);
511+
}
512+
if (isArray(mapped)) {
513+
addRange(result, mapped);
514+
}
515+
else {
516+
result.push(mapped);
517+
}
518+
}
519+
}
520+
}
521+
return result || array;
522+
}
523+
493524
/**
494525
* Computes the first matching span of elements and returns a tuple of the first span
495526
* and the remaining elements.

src/compiler/emitter.ts

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ namespace ts {
153153
for (let i = 0; i < numNodes; i++) {
154154
const currentNode = bundle ? bundle.sourceFiles[i] : node;
155155
const sourceFile = isSourceFile(currentNode) ? currentNode : currentSourceFile;
156-
const shouldSkip = compilerOptions.noEmitHelpers || (sourceFile && getExternalHelpersModuleName(sourceFile) !== undefined);
156+
const shouldSkip = compilerOptions.noEmitHelpers || getExternalHelpersModuleName(sourceFile) !== undefined;
157157
const shouldBundle = isSourceFile(currentNode) && !isOwnFileEmit;
158158
const helpers = getEmitHelpers(currentNode);
159159
if (helpers) {
@@ -212,7 +212,7 @@ namespace ts {
212212
emitLeadingCommentsOfPosition,
213213
} = comments;
214214

215-
let currentSourceFile: SourceFile;
215+
let currentSourceFile: SourceFile | undefined;
216216
let nodeIdToGeneratedName: string[]; // Map of generated names for specific nodes.
217217
let autoGeneratedIdToGeneratedName: string[]; // Map of generated names for temp and loop variables.
218218
let generatedNames: Map<string>; // Set of names generated by the NameGenerator.
@@ -264,7 +264,12 @@ namespace ts {
264264
return endPrint();
265265
}
266266

267-
function writeNode(hint: EmitHint, node: Node, sourceFile: SourceFile, output: EmitTextWriter) {
267+
/**
268+
* If `sourceFile` is `undefined`, `node` must be a synthesized `TypeNode`.
269+
*/
270+
function writeNode(hint: EmitHint, node: TypeNode, sourceFile: undefined, output: EmitTextWriter): void;
271+
function writeNode(hint: EmitHint, node: Node, sourceFile: SourceFile, output: EmitTextWriter): void;
272+
function writeNode(hint: EmitHint, node: Node, sourceFile: SourceFile | undefined, output: EmitTextWriter) {
268273
const previousWriter = writer;
269274
setWriter(output);
270275
print(hint, node, sourceFile);
@@ -305,8 +310,10 @@ namespace ts {
305310
return text;
306311
}
307312

308-
function print(hint: EmitHint, node: Node, sourceFile: SourceFile) {
309-
setSourceFile(sourceFile);
313+
function print(hint: EmitHint, node: Node, sourceFile: SourceFile | undefined) {
314+
if (sourceFile) {
315+
setSourceFile(sourceFile);
316+
}
310317
pipelineEmitWithNotification(hint, node);
311318
}
312319

@@ -733,6 +740,9 @@ namespace ts {
733740
// Transformation nodes
734741
case SyntaxKind.PartiallyEmittedExpression:
735742
return emitPartiallyEmittedExpression(<PartiallyEmittedExpression>node);
743+
744+
case SyntaxKind.CommaListExpression:
745+
return emitCommaList(<CommaListExpression>node);
736746
}
737747
}
738748

@@ -778,6 +788,7 @@ namespace ts {
778788

779789
function emitIdentifier(node: Identifier) {
780790
write(getTextOfNode(node, /*includeTrivia*/ false));
791+
emitTypeArguments(node, node.typeArguments);
781792
}
782793

783794
//
@@ -812,6 +823,7 @@ namespace ts {
812823
function emitTypeParameter(node: TypeParameterDeclaration) {
813824
emit(node.name);
814825
emitWithPrefix(" extends ", node.constraint);
826+
emitWithPrefix(" = ", node.default);
815827
}
816828

817829
function emitParameter(node: ParameterDeclaration) {
@@ -952,7 +964,10 @@ namespace ts {
952964

953965
function emitTypeLiteral(node: TypeLiteralNode) {
954966
write("{");
955-
emitList(node, node.members, ListFormat.TypeLiteralMembers);
967+
// If the literal is empty, do not add spaces between braces.
968+
if (node.members.length > 0) {
969+
emitList(node, node.members, getEmitFlags(node) & EmitFlags.SingleLine ? ListFormat.SingleLineTypeLiteralMembers : ListFormat.MultiLineTypeLiteralMembers);
970+
}
956971
write("}");
957972
}
958973

@@ -999,9 +1014,15 @@ namespace ts {
9991014
}
10001015

10011016
function emitMappedType(node: MappedTypeNode) {
1017+
const emitFlags = getEmitFlags(node);
10021018
write("{");
1003-
writeLine();
1004-
increaseIndent();
1019+
if (emitFlags & EmitFlags.SingleLine) {
1020+
write(" ");
1021+
}
1022+
else {
1023+
writeLine();
1024+
increaseIndent();
1025+
}
10051026
writeIfPresent(node.readonlyToken, "readonly ");
10061027
write("[");
10071028
emit(node.typeParameter.name);
@@ -1012,8 +1033,13 @@ namespace ts {
10121033
write(": ");
10131034
emit(node.type);
10141035
write(";");
1015-
writeLine();
1016-
decreaseIndent();
1036+
if (emitFlags & EmitFlags.SingleLine) {
1037+
write(" ");
1038+
}
1039+
else {
1040+
writeLine();
1041+
decreaseIndent();
1042+
}
10171043
write("}");
10181044
}
10191045

@@ -1032,7 +1058,7 @@ namespace ts {
10321058
}
10331059
else {
10341060
write("{");
1035-
emitList(node, elements, ListFormat.ObjectBindingPatternElements);
1061+
emitList(node, elements, getEmitFlags(node) & EmitFlags.SingleLine ? ListFormat.ObjectBindingPatternElements : ListFormat.ObjectBindingPatternElementsWithSpaceBetweenBraces);
10361062
write("}");
10371063
}
10381064
}
@@ -2101,6 +2127,10 @@ namespace ts {
21012127
emitExpression(node.expression);
21022128
}
21032129

2130+
function emitCommaList(node: CommaListExpression) {
2131+
emitExpressionList(node, node.elements, ListFormat.CommaListElements);
2132+
}
2133+
21042134
/**
21052135
* Emits any prologue directives at the start of a Statement list, returning the
21062136
* number of prologue directives written to the output.
@@ -2630,7 +2660,9 @@ namespace ts {
26302660
if (node.kind === SyntaxKind.StringLiteral && (<StringLiteral>node).textSourceNode) {
26312661
const textSourceNode = (<StringLiteral>node).textSourceNode;
26322662
if (isIdentifier(textSourceNode)) {
2633-
return "\"" + escapeNonAsciiCharacters(escapeString(getTextOfNode(textSourceNode))) + "\"";
2663+
return getEmitFlags(node) & EmitFlags.NoAsciiEscaping ?
2664+
`"${escapeString(getTextOfNode(textSourceNode))}"` :
2665+
`"${escapeNonAsciiString(getTextOfNode(textSourceNode))}"`;
26342666
}
26352667
else {
26362668
return getLiteralTextOfNode(textSourceNode);
@@ -2943,14 +2975,18 @@ namespace ts {
29432975
// Precomputed Formats
29442976
Modifiers = SingleLine | SpaceBetweenSiblings,
29452977
HeritageClauses = SingleLine | SpaceBetweenSiblings,
2946-
TypeLiteralMembers = MultiLine | Indented,
2978+
SingleLineTypeLiteralMembers = SingleLine | SpaceBetweenBraces | SpaceBetweenSiblings | Indented,
2979+
MultiLineTypeLiteralMembers = MultiLine | Indented,
2980+
29472981
TupleTypeElements = CommaDelimited | SpaceBetweenSiblings | SingleLine | Indented,
29482982
UnionTypeConstituents = BarDelimited | SpaceBetweenSiblings | SingleLine,
29492983
IntersectionTypeConstituents = AmpersandDelimited | SpaceBetweenSiblings | SingleLine,
2950-
ObjectBindingPatternElements = SingleLine | AllowTrailingComma | SpaceBetweenBraces | CommaDelimited | SpaceBetweenSiblings,
2984+
ObjectBindingPatternElements = SingleLine | CommaDelimited | SpaceBetweenSiblings,
2985+
ObjectBindingPatternElementsWithSpaceBetweenBraces = SingleLine | AllowTrailingComma | SpaceBetweenBraces | CommaDelimited | SpaceBetweenSiblings,
29512986
ArrayBindingPatternElements = SingleLine | AllowTrailingComma | CommaDelimited | SpaceBetweenSiblings,
29522987
ObjectLiteralExpressionProperties = PreserveLines | CommaDelimited | SpaceBetweenSiblings | SpaceBetweenBraces | Indented | Braces,
29532988
ArrayLiteralExpressionElements = PreserveLines | CommaDelimited | SpaceBetweenSiblings | AllowTrailingComma | Indented | SquareBrackets,
2989+
CommaListElements = CommaDelimited | SpaceBetweenSiblings | SingleLine,
29542990
CallExpressionArguments = CommaDelimited | SpaceBetweenSiblings | SingleLine | Parenthesis,
29552991
NewExpressionArguments = CommaDelimited | SpaceBetweenSiblings | SingleLine | Parenthesis | OptionalIfUndefined,
29562992
TemplateExpressionSpans = SingleLine | NoInterveningComments,

0 commit comments

Comments
 (0)