Skip to content

Commit fe191fe

Browse files
committed
Merge branch 'master' into tsbuild
2 parents 70fa29b + 8bc1932 commit fe191fe

186 files changed

Lines changed: 1392 additions & 566 deletions

File tree

Some content is hidden

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

scripts/configurePrerelease.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ function updateTsFile(tsFilePath: string, tsFileContents: string, majorMinor: st
5656
const majorMinorRgx = /export const versionMajorMinor = "(\d+\.\d+)"/;
5757
const majorMinorMatch = majorMinorRgx.exec(tsFileContents);
5858
assert(majorMinorMatch !== null, `The file seems to no longer have a string matching '${majorMinorRgx}'.`);
59-
const parsedMajorMinor = majorMinorMatch[1];
59+
const parsedMajorMinor = majorMinorMatch![1];
6060
assert(parsedMajorMinor === majorMinor, `versionMajorMinor does not match. ${tsFilePath}: '${parsedMajorMinor}'; package.json: '${majorMinor}'`);
6161

6262
const versionRgx = /export const version = `\$\{versionMajorMinor\}\.(\d)(-dev)?`;/;
6363
const patchMatch = versionRgx.exec(tsFileContents);
6464
assert(patchMatch !== null, "The file seems to no longer have a string matching " + versionRgx.toString());
65-
const parsedPatch = patchMatch[1];
65+
const parsedPatch = patchMatch![1];
6666
if (parsedPatch !== patch) {
6767
throw new Error(`patch does not match. ${tsFilePath}: '${parsedPatch}; package.json: '${patch}'`);
6868
}
@@ -74,7 +74,7 @@ function parsePackageJsonVersion(versionString: string): { majorMinor: string, p
7474
const versionRgx = /(\d+\.\d+)\.(\d+)($|\-)/;
7575
const match = versionString.match(versionRgx);
7676
assert(match !== null, "package.json 'version' should match " + versionRgx.toString());
77-
return { majorMinor: match[1], patch: match[2] };
77+
return { majorMinor: match![1], patch: match![2] };
7878
}
7979

8080
/** e.g. 0-dev.20170707 */

scripts/tslint/rules/nextLineRule.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ function walk(ctx: Lint.WalkContext<void>, checkCatch: boolean, checkElse: boole
5252
return;
5353
}
5454

55-
const tryClosingBrace = tryBlock.getLastToken(sourceFile);
56-
const catchKeyword = catchClause.getFirstToken(sourceFile);
55+
const tryClosingBrace = tryBlock.getLastToken(sourceFile)!;
56+
const catchKeyword = catchClause.getFirstToken(sourceFile)!;
5757
const tryClosingBraceLoc = sourceFile.getLineAndCharacterOfPosition(tryClosingBrace.getEnd());
5858
const catchKeywordLoc = sourceFile.getLineAndCharacterOfPosition(catchKeyword.getStart(sourceFile));
5959
if (tryClosingBraceLoc.line === catchKeywordLoc.line) {

scripts/tslint/rules/noInOperatorRule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class Rule extends Lint.Rules.AbstractRule {
1212
function walk(ctx: Lint.WalkContext<void>): void {
1313
ts.forEachChild(ctx.sourceFile, recur);
1414
function recur(node: ts.Node): void {
15-
if (node.kind === ts.SyntaxKind.InKeyword && node.parent!.kind === ts.SyntaxKind.BinaryExpression) {
15+
if (node.kind === ts.SyntaxKind.InKeyword && node.parent.kind === ts.SyntaxKind.BinaryExpression) {
1616
ctx.addFailureAtNode(node, Rule.FAILURE_STRING);
1717
}
1818
}

scripts/tslint/rules/noIncrementDecrementRule.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function walk(ctx: Lint.WalkContext<void>): void {
2828
}
2929

3030
function check(node: ts.UnaryExpression): void {
31-
if (!isAllowedLocation(node.parent!)) {
31+
if (!isAllowedLocation(node.parent)) {
3232
ctx.addFailureAtNode(node, Rule.POSTFIX_FAILURE_STRING);
3333
}
3434
}
@@ -47,7 +47,7 @@ function isAllowedLocation(node: ts.Node): boolean {
4747
// Can be in a comma operator in a for statement (`for (let a = 0, b = 10; a < b; a++, b--)`)
4848
case ts.SyntaxKind.BinaryExpression:
4949
return (node as ts.BinaryExpression).operatorToken.kind === ts.SyntaxKind.CommaToken &&
50-
node.parent!.kind === ts.SyntaxKind.ForStatement;
50+
node.parent.kind === ts.SyntaxKind.ForStatement;
5151

5252
default:
5353
return false;

src/compiler/checker.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2993,7 +2993,7 @@ namespace ts {
29932993
}
29942994
}
29952995

2996-
function typeToString(type: Type, enclosingDeclaration?: Node, flags: TypeFormatFlags = TypeFormatFlags.AllowUniqueESSymbolType, writer: EmitTextWriter = createTextWriter("")): string {
2996+
function typeToString(type: Type, enclosingDeclaration?: Node, flags: TypeFormatFlags = TypeFormatFlags.AllowUniqueESSymbolType | TypeFormatFlags.UseAliasDefinedOutsideCurrentScope, writer: EmitTextWriter = createTextWriter("")): string {
29972997
const typeNode = nodeBuilder.typeToTypeNode(type, enclosingDeclaration, toNodeBuilderFlags(flags) | NodeBuilderFlags.IgnoreErrors, writer);
29982998
if (typeNode === undefined) return Debug.fail("should always get typenode");
29992999
const options = { removeComments: true };
@@ -3941,7 +3941,7 @@ namespace ts {
39413941
}
39423942
}
39433943

3944-
function typePredicateToString(typePredicate: TypePredicate, enclosingDeclaration?: Node, flags?: TypeFormatFlags, writer?: EmitTextWriter): string {
3944+
function typePredicateToString(typePredicate: TypePredicate, enclosingDeclaration?: Node, flags: TypeFormatFlags = TypeFormatFlags.UseAliasDefinedOutsideCurrentScope, writer?: EmitTextWriter): string {
39453945
return writer ? typePredicateToStringWorker(writer).getText() : usingSingleLineStringWriter(typePredicateToStringWorker);
39463946

39473947
function typePredicateToStringWorker(writer: EmitTextWriter) {
@@ -24153,6 +24153,16 @@ namespace ts {
2415324153
}
2415424154
}
2415524155

24156+
/**
24157+
* The name cannot be used as 'Object' of user defined types with special target.
24158+
*/
24159+
function checkClassNameCollisionWithObject(name: Identifier): void {
24160+
if (languageVersion === ScriptTarget.ES5 && name.escapedText === "Object"
24161+
&& moduleKind !== ModuleKind.ES2015 && moduleKind !== ModuleKind.ESNext) {
24162+
error(name, Diagnostics.Class_name_cannot_be_Object_when_targeting_ES5_with_module_0, ModuleKind[moduleKind]); // https://github.com/Microsoft/TypeScript/issues/17494
24163+
}
24164+
}
24165+
2415624166
/**
2415724167
* Check each type parameter and check that type parameters have no duplicate type parameter declarations
2415824168
*/
@@ -24279,6 +24289,9 @@ namespace ts {
2427924289
checkTypeNameIsReserved(node.name, Diagnostics.Class_name_cannot_be_0);
2428024290
checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
2428124291
checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name);
24292+
if (!(node.flags & NodeFlags.Ambient)) {
24293+
checkClassNameCollisionWithObject(node.name);
24294+
}
2428224295
}
2428324296
checkTypeParameters(getEffectiveTypeParameterDeclarations(node));
2428424297
checkExportsOnMergedDeclarations(node);
@@ -24489,7 +24502,7 @@ namespace ts {
2448924502
continue;
2449024503
}
2449124504

24492-
if (isPrototypeProperty(base) && isPrototypeProperty(derived) || base.flags & SymbolFlags.PropertyOrAccessor && derived.flags & SymbolFlags.PropertyOrAccessor) {
24505+
if (isPrototypeProperty(base) || base.flags & SymbolFlags.PropertyOrAccessor && derived.flags & SymbolFlags.PropertyOrAccessor) {
2449324506
// method is overridden with method or property/accessor is overridden with property/accessor - correct case
2449424507
continue;
2449524508
}

src/compiler/core.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,21 +1006,6 @@ namespace ts {
10061006
return to;
10071007
}
10081008

1009-
/**
1010-
* Appends a range of value to begin of an array, returning the array.
1011-
*
1012-
* @param to The array to which `value` is to be appended. If `to` is `undefined`, a new array
1013-
* is created if `value` was appended.
1014-
* @param from The values to append to the array. If `from` is `undefined`, nothing is
1015-
* appended. If an element of `from` is `undefined`, that element is not appended.
1016-
*/
1017-
export function prependRange<T>(to: T[], from: ReadonlyArray<T> | undefined): T[] | undefined {
1018-
if (from === undefined || from.length === 0) return to;
1019-
if (to === undefined) return from.slice();
1020-
to.unshift(...from);
1021-
return to;
1022-
}
1023-
10241009
/**
10251010
* @return Whether the value was added.
10261011
*/

src/compiler/diagnosticMessages.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2357,6 +2357,11 @@
23572357
"category": "Error",
23582358
"code": 2724
23592359
},
2360+
"Class name cannot be 'Object' when targeting ES5 with module {0}.": {
2361+
"category": "Error",
2362+
"code": 2725
2363+
},
2364+
23602365
"Import declaration '{0}' is using private name '{1}'.": {
23612366
"category": "Error",
23622367
"code": 4000

src/compiler/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6707,7 +6707,7 @@ namespace ts {
67076707
<JSDocParameterTag>createNode(SyntaxKind.JSDocParameterTag, atToken.pos);
67086708
let comment: string | undefined;
67096709
if (indent !== undefined) comment = parseTagComments(indent + scanner.getStartPos() - atToken.pos);
6710-
const nestedTypeLiteral = parseNestedTypeLiteral(typeExpression, name, target);
6710+
const nestedTypeLiteral = target !== PropertyLikeParse.CallbackParameter && parseNestedTypeLiteral(typeExpression, name, target);
67116711
if (nestedTypeLiteral) {
67126712
typeExpression = nestedTypeLiteral;
67136713
isNameFirst = true;

src/compiler/program.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2670,6 +2670,11 @@ namespace ts {
26702670
return isSameFile(filePath, out) || isSameFile(filePath, removeFileExtension(out) + Extension.Dts);
26712671
}
26722672

2673+
// If declarationDir is specified, return if its a file in that directory
2674+
if (options.declarationDir && containsPath(options.declarationDir, filePath, currentDirectory, !host.useCaseSensitiveFileNames())) {
2675+
return true;
2676+
}
2677+
26732678
// If --outDir, check if file is in that directory
26742679
if (options.outDir) {
26752680
return containsPath(options.outDir, filePath, currentDirectory, !host.useCaseSensitiveFileNames());
@@ -2678,8 +2683,8 @@ namespace ts {
26782683
if (fileExtensionIsOneOf(filePath, supportedJavascriptExtensions) || fileExtensionIs(filePath, Extension.Dts)) {
26792684
// Otherwise just check if sourceFile with the name exists
26802685
const filePathWithoutExtension = removeFileExtension(filePath);
2681-
return !!getSourceFileByPath(combinePaths(filePathWithoutExtension, Extension.Ts) as Path) ||
2682-
!!getSourceFileByPath(combinePaths(filePathWithoutExtension, Extension.Tsx) as Path);
2686+
return !!getSourceFileByPath((filePathWithoutExtension + Extension.Ts) as Path) ||
2687+
!!getSourceFileByPath((filePathWithoutExtension + Extension.Tsx) as Path);
26832688
}
26842689
return false;
26852690
}

src/compiler/transformers/es2015.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ namespace ts {
529529
createVariableStatement(/*modifiers*/ undefined,
530530
createVariableDeclarationList(taggedTemplateStringDeclarations)));
531531
}
532-
prependRange(statements, endLexicalEnvironment());
532+
prependStatements(statements, endLexicalEnvironment());
533533
exitSubtree(ancestorFacts, HierarchyFacts.None, HierarchyFacts.None);
534534
return updateSourceFileNode(
535535
node,
@@ -837,7 +837,7 @@ namespace ts {
837837
setEmitFlags(statement, EmitFlags.NoComments | EmitFlags.NoTokenSourceMaps);
838838
statements.push(statement);
839839

840-
prependRange(statements, endLexicalEnvironment());
840+
prependStatements(statements, endLexicalEnvironment());
841841

842842
const block = createBlock(setTextRange(createNodeArray(statements), /*location*/ node.members), /*multiLine*/ true);
843843
setEmitFlags(block, EmitFlags.NoComments);
@@ -980,7 +980,7 @@ namespace ts {
980980
);
981981
}
982982

983-
prependRange(statements, endLexicalEnvironment());
983+
prependStatements(statements, endLexicalEnvironment());
984984

985985
if (constructor) {
986986
prependCaptureNewTargetIfNeeded(statements, constructor, /*copyOnWrite*/ false);
@@ -1896,7 +1896,7 @@ namespace ts {
18961896
}
18971897

18981898
const lexicalEnvironment = context.endLexicalEnvironment();
1899-
prependRange(statements, lexicalEnvironment);
1899+
prependStatements(statements, lexicalEnvironment);
19001900

19011901
prependCaptureNewTargetIfNeeded(statements, node, /*copyOnWrite*/ false);
19021902

@@ -2712,7 +2712,7 @@ namespace ts {
27122712
if (loopOutParameters.length) {
27132713
copyOutParameters(loopOutParameters, CopyDirection.ToOutParameter, statements);
27142714
}
2715-
prependRange(statements, lexicalEnvironment);
2715+
prependStatements(statements, lexicalEnvironment);
27162716
loopBody = createBlock(statements, /*multiline*/ true);
27172717
}
27182718

0 commit comments

Comments
 (0)