Skip to content

Commit f1a1b7f

Browse files
committed
Merge branch 'master' into improve-arity-error
2 parents 995f1a6 + 5e20c1c commit f1a1b7f

File tree

105 files changed

+4928
-1170
lines changed

Some content is hidden

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

105 files changed

+4928
-1170
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/binder.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ namespace ts {
149149
inStrictMode = bindInStrictMode(file, opts);
150150
classifiableNames = createMap<string>();
151151
symbolCount = 0;
152-
skipTransformFlagAggregation = isDeclarationFile(file);
152+
skipTransformFlagAggregation = file.isDeclarationFile;
153153

154154
Symbol = objectAllocator.getSymbolConstructor();
155155

@@ -182,7 +182,7 @@ namespace ts {
182182
return bindSourceFile;
183183

184184
function bindInStrictMode(file: SourceFile, opts: CompilerOptions): boolean {
185-
if ((opts.alwaysStrict === undefined ? opts.strict : opts.alwaysStrict) && !isDeclarationFile(file)) {
185+
if ((opts.alwaysStrict === undefined ? opts.strict : opts.alwaysStrict) && !file.isDeclarationFile) {
186186
// bind in strict mode source files with alwaysStrict option
187187
return true;
188188
}
@@ -2527,7 +2527,7 @@ namespace ts {
25272527
}
25282528

25292529
function bindFunctionDeclaration(node: FunctionDeclaration) {
2530-
if (!isDeclarationFile(file) && !isInAmbientContext(node)) {
2530+
if (!file.isDeclarationFile && !isInAmbientContext(node)) {
25312531
if (isAsyncFunction(node)) {
25322532
emitFlags |= NodeFlags.HasAsyncFunctions;
25332533
}
@@ -2544,7 +2544,7 @@ namespace ts {
25442544
}
25452545

25462546
function bindFunctionExpression(node: FunctionExpression) {
2547-
if (!isDeclarationFile(file) && !isInAmbientContext(node)) {
2547+
if (!file.isDeclarationFile && !isInAmbientContext(node)) {
25482548
if (isAsyncFunction(node)) {
25492549
emitFlags |= NodeFlags.HasAsyncFunctions;
25502550
}
@@ -2558,7 +2558,7 @@ namespace ts {
25582558
}
25592559

25602560
function bindPropertyOrMethodOrAccessor(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags) {
2561-
if (!isDeclarationFile(file) && !isInAmbientContext(node)) {
2561+
if (!file.isDeclarationFile && !isInAmbientContext(node)) {
25622562
if (isAsyncFunction(node)) {
25632563
emitFlags |= NodeFlags.HasAsyncFunctions;
25642564
}

src/compiler/checker.ts

Lines changed: 635 additions & 557 deletions
Large diffs are not rendered by default.

src/compiler/core.ts

Lines changed: 2 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);

src/compiler/declarationEmitter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ namespace ts {
984984
const enumMemberValue = resolver.getConstantValue(node);
985985
if (enumMemberValue !== undefined) {
986986
write(" = ");
987-
write(enumMemberValue.toString());
987+
write(getTextOfConstantValue(enumMemberValue));
988988
}
989989
write(",");
990990
writeLine();
@@ -1840,7 +1840,7 @@ namespace ts {
18401840
function writeReferencePath(referencedFile: SourceFile, addBundledFileReference: boolean, emitOnlyDtsFiles: boolean): boolean {
18411841
let declFileName: string;
18421842
let addedBundledEmitReference = false;
1843-
if (isDeclarationFile(referencedFile)) {
1843+
if (referencedFile.isDeclarationFile) {
18441844
// Declaration file, use declaration file name
18451845
declFileName = referencedFile.fileName;
18461846
}

src/compiler/diagnosticMessages.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,25 +1855,29 @@
18551855
"category": "Error",
18561856
"code": 2552
18571857
},
1858-
"Expected {0} arguments, but got {1}.": {
1858+
"Computed values are not permitted in an enum with string valued members.": {
18591859
"category": "Error",
18601860
"code": 2553
18611861
},
1862-
"Expected at least {0} arguments, but got {1}.": {
1862+
"Expected {0} arguments, but got {1}.": {
18631863
"category": "Error",
18641864
"code": 2554
18651865
},
1866+
"Expected at least {0} arguments, but got {1}.": {
1867+
"category": "Error",
1868+
"code": 2555
1869+
},
18661870
"Expected {0} arguments, but got a minimum of {1}.": {
18671871
"category": "Error",
18681872
"code": 2555
18691873
},
18701874
"Expected at least {0} arguments, but got a minimum of {1}.": {
18711875
"category": "Error",
1872-
"code": 2556
1876+
"code": 2557
18731877
},
18741878
"Expected {0} type arguments, but got {1}.": {
18751879
"category": "Error",
1876-
"code": 2557
1880+
"code": 2558
18771881
},
18781882
"JSX element attributes type '{0}' may not be a union type.": {
18791883
"category": "Error",

src/compiler/emitter.ts

Lines changed: 43 additions & 15 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

@@ -781,6 +788,7 @@ namespace ts {
781788

782789
function emitIdentifier(node: Identifier) {
783790
write(getTextOfNode(node, /*includeTrivia*/ false));
791+
emitTypeArguments(node, node.typeArguments);
784792
}
785793

786794
//
@@ -815,6 +823,7 @@ namespace ts {
815823
function emitTypeParameter(node: TypeParameterDeclaration) {
816824
emit(node.name);
817825
emitWithPrefix(" extends ", node.constraint);
826+
emitWithPrefix(" = ", node.default);
818827
}
819828

820829
function emitParameter(node: ParameterDeclaration) {
@@ -955,7 +964,10 @@ namespace ts {
955964

956965
function emitTypeLiteral(node: TypeLiteralNode) {
957966
write("{");
958-
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+
}
959971
write("}");
960972
}
961973

@@ -1002,9 +1014,15 @@ namespace ts {
10021014
}
10031015

10041016
function emitMappedType(node: MappedTypeNode) {
1017+
const emitFlags = getEmitFlags(node);
10051018
write("{");
1006-
writeLine();
1007-
increaseIndent();
1019+
if (emitFlags & EmitFlags.SingleLine) {
1020+
write(" ");
1021+
}
1022+
else {
1023+
writeLine();
1024+
increaseIndent();
1025+
}
10081026
writeIfPresent(node.readonlyToken, "readonly ");
10091027
write("[");
10101028
emit(node.typeParameter.name);
@@ -1015,8 +1033,13 @@ namespace ts {
10151033
write(": ");
10161034
emit(node.type);
10171035
write(";");
1018-
writeLine();
1019-
decreaseIndent();
1036+
if (emitFlags & EmitFlags.SingleLine) {
1037+
write(" ");
1038+
}
1039+
else {
1040+
writeLine();
1041+
decreaseIndent();
1042+
}
10201043
write("}");
10211044
}
10221045

@@ -1035,7 +1058,7 @@ namespace ts {
10351058
}
10361059
else {
10371060
write("{");
1038-
emitList(node, elements, ListFormat.ObjectBindingPatternElements);
1061+
emitList(node, elements, getEmitFlags(node) & EmitFlags.SingleLine ? ListFormat.ObjectBindingPatternElements : ListFormat.ObjectBindingPatternElementsWithSpaceBetweenBraces);
10391062
write("}");
10401063
}
10411064
}
@@ -1131,7 +1154,7 @@ namespace ts {
11311154
// check if constant enum value is integer
11321155
const constantValue = getConstantValue(expression);
11331156
// isFinite handles cases when constantValue is undefined
1134-
return isFinite(constantValue)
1157+
return typeof constantValue === "number" && isFinite(constantValue)
11351158
&& Math.floor(constantValue) === constantValue
11361159
&& printerOptions.removeComments;
11371160
}
@@ -2637,7 +2660,9 @@ namespace ts {
26372660
if (node.kind === SyntaxKind.StringLiteral && (<StringLiteral>node).textSourceNode) {
26382661
const textSourceNode = (<StringLiteral>node).textSourceNode;
26392662
if (isIdentifier(textSourceNode)) {
2640-
return "\"" + escapeNonAsciiCharacters(escapeString(getTextOfNode(textSourceNode))) + "\"";
2663+
return getEmitFlags(node) & EmitFlags.NoAsciiEscaping ?
2664+
`"${escapeString(getTextOfNode(textSourceNode))}"` :
2665+
`"${escapeNonAsciiString(getTextOfNode(textSourceNode))}"`;
26412666
}
26422667
else {
26432668
return getLiteralTextOfNode(textSourceNode);
@@ -2950,11 +2975,14 @@ namespace ts {
29502975
// Precomputed Formats
29512976
Modifiers = SingleLine | SpaceBetweenSiblings,
29522977
HeritageClauses = SingleLine | SpaceBetweenSiblings,
2953-
TypeLiteralMembers = MultiLine | Indented,
2978+
SingleLineTypeLiteralMembers = SingleLine | SpaceBetweenBraces | SpaceBetweenSiblings | Indented,
2979+
MultiLineTypeLiteralMembers = MultiLine | Indented,
2980+
29542981
TupleTypeElements = CommaDelimited | SpaceBetweenSiblings | SingleLine | Indented,
29552982
UnionTypeConstituents = BarDelimited | SpaceBetweenSiblings | SingleLine,
29562983
IntersectionTypeConstituents = AmpersandDelimited | SpaceBetweenSiblings | SingleLine,
2957-
ObjectBindingPatternElements = SingleLine | AllowTrailingComma | SpaceBetweenBraces | CommaDelimited | SpaceBetweenSiblings,
2984+
ObjectBindingPatternElements = SingleLine | CommaDelimited | SpaceBetweenSiblings,
2985+
ObjectBindingPatternElementsWithSpaceBetweenBraces = SingleLine | AllowTrailingComma | SpaceBetweenBraces | CommaDelimited | SpaceBetweenSiblings,
29582986
ArrayBindingPatternElements = SingleLine | AllowTrailingComma | CommaDelimited | SpaceBetweenSiblings,
29592987
ObjectLiteralExpressionProperties = PreserveLines | CommaDelimited | SpaceBetweenSiblings | SpaceBetweenBraces | Indented | Braces,
29602988
ArrayLiteralExpressionElements = PreserveLines | CommaDelimited | SpaceBetweenSiblings | AllowTrailingComma | Indented | SquareBrackets,

0 commit comments

Comments
 (0)