Merge branch 'master' into transforms

This commit is contained in:
Ron Buckton 2016-08-02 11:47:18 -07:00
commit c725ee457d
38 changed files with 439 additions and 108 deletions

View File

@ -12937,6 +12937,14 @@ namespace ts {
return (target.flags & TypeFlags.Nullable) !== 0 || isTypeComparableTo(source, target);
}
function getBestChoiceType(type1: Type, type2: Type): Type {
const firstAssignableToSecond = isTypeAssignableTo(type1, type2);
const secondAssignableToFirst = isTypeAssignableTo(type2, type1);
return secondAssignableToFirst && !firstAssignableToSecond ? type1 :
firstAssignableToSecond && !secondAssignableToFirst ? type2 :
getUnionType([type1, type2], /*subtypeReduction*/ true);
}
function checkBinaryExpression(node: BinaryExpression, contextualMapper?: TypeMapper) {
return checkBinaryLikeExpression(node.left, node.operatorToken, node.right, contextualMapper, node);
}
@ -13080,7 +13088,7 @@ namespace ts {
leftType;
case SyntaxKind.BarBarToken:
return getTypeFacts(leftType) & TypeFacts.Falsy ?
getUnionType([removeDefinitelyFalsyTypes(leftType), rightType], /*subtypeReduction*/ true) :
getBestChoiceType(removeDefinitelyFalsyTypes(leftType), rightType) :
leftType;
case SyntaxKind.EqualsToken:
checkAssignmentOperator(rightType);
@ -13207,7 +13215,7 @@ namespace ts {
checkExpression(node.condition);
const type1 = checkExpression(node.whenTrue, contextualMapper);
const type2 = checkExpression(node.whenFalse, contextualMapper);
return getUnionType([type1, type2], /*subtypeReduction*/ true);
return getBestChoiceType(type1, type2);
}
function typeContainsLiteralFromEnum(type: Type, enumType: EnumType) {

5
src/lib/es5.d.ts vendored
View File

@ -1108,6 +1108,11 @@ interface Array<T> {
* Removes the last element from an array and returns it.
*/
pop(): T | undefined;
/**
* Combines two or more arrays.
* @param items Additional items to add to the end of array1.
*/
concat(...items: T[][]): T[];
/**
* Combines two or more arrays.
* @param items Additional items to add to the end of array1.

View File

@ -453,9 +453,9 @@ namespace ts.formatting {
case SyntaxKind.MethodDeclaration:
if ((<MethodDeclaration>node).asteriskToken) {
return SyntaxKind.AsteriskToken;
}
// fall-through
}/*
fall-through
*/
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.Parameter:
return (<Declaration>node).name.kind;
@ -732,7 +732,7 @@ namespace ts.formatting {
else {
// indent token only if end line of previous range does not match start line of the token
const prevEndLine = savePreviousRange && sourceFile.getLineAndCharacterOfPosition(savePreviousRange.end).line;
indentToken = lastTriviaWasNewLine && tokenStart.line !== prevEndLine;
indentToken = lastTriviaWasNewLine && tokenStart.line !== prevEndLine;
}
}
}
@ -892,7 +892,7 @@ namespace ts.formatting {
}
function indentationIsDifferent(indentationString: string, startLinePosition: number): boolean {
return indentationString !== sourceFile.text.substr(startLinePosition , indentationString.length);
return indentationString !== sourceFile.text.substr(startLinePosition, indentationString.length);
}
function indentMultilineComment(commentRange: TextRange, indentation: number, firstLineIsIndented: boolean) {
@ -936,7 +936,7 @@ namespace ts.formatting {
// shift all parts on the delta size
const delta = indentation - nonWhitespaceColumnInFirstPart.column;
for (let i = startIndex, len = parts.length; i < len; i++, startLine++) {
for (let i = startIndex, len = parts.length; i < len; i++ , startLine++) {
const startLinePos = getStartPositionOfLine(startLine, sourceFile);
const nonWhitespaceCharacterAndColumn =
i === 0

View File

@ -231,6 +231,13 @@ namespace ts.formatting {
public NoSpaceBeforeCloseBraceInJsxExpression: Rule;
public SpaceBeforeCloseBraceInJsxExpression: Rule;
// JSX opening elements
public SpaceBeforeJsxAttribute: Rule;
public SpaceBeforeSlashInJsxOpeningElement: Rule;
public NoSpaceBeforeGreaterThanTokenInJsxOpeningElement: Rule;
public NoSpaceBeforeEqualInJsxAttribute: Rule;
public NoSpaceAfterEqualInJsxAttribute: Rule;
constructor() {
///
/// Common Rules
@ -322,7 +329,7 @@ namespace ts.formatting {
// Add a space between statements. All keywords except (do,else,case) has open/close parens after them.
// So, we have a rule to add a space for [),Any], [do,Any], [else,Any], and [case,Any]
this.SpaceBetweenStatements = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.CloseParenToken, SyntaxKind.DoKeyword, SyntaxKind.ElseKeyword, SyntaxKind.CaseKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.isNonJsxElementContext, Rules.IsNotForContext), RuleAction.Space));
this.SpaceBetweenStatements = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.CloseParenToken, SyntaxKind.DoKeyword, SyntaxKind.ElseKeyword, SyntaxKind.CaseKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsNonJsxElementContext, Rules.IsNotForContext), RuleAction.Space));
// This low-pri rule takes care of "try {" and "finally {" in case the rule SpaceBeforeOpenBraceInControl didn't execute on FormatOnEnter.
this.SpaceAfterTryFinally = new Rule(RuleDescriptor.create2(Shared.TokenRange.FromTokens([SyntaxKind.TryKeyword, SyntaxKind.FinallyKeyword]), SyntaxKind.OpenBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Space));
@ -386,6 +393,13 @@ namespace ts.formatting {
// template string
this.NoSpaceBetweenTagAndTemplateString = new Rule(RuleDescriptor.create3(SyntaxKind.Identifier, Shared.TokenRange.FromTokens([SyntaxKind.NoSubstitutionTemplateLiteral, SyntaxKind.TemplateHead])), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Delete));
// jsx opening element
this.SpaceBeforeJsxAttribute = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.Identifier), RuleOperation.create2(new RuleOperationContext(Rules.IsNextTokenParentJsxAttribute, Rules.IsNonJsxSameLineTokenContext), RuleAction.Space));
this.SpaceBeforeSlashInJsxOpeningElement = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.SlashToken), RuleOperation.create2(new RuleOperationContext(Rules.IsJsxSelfClosingElementContext, Rules.IsNonJsxSameLineTokenContext), RuleAction.Space));
this.NoSpaceBeforeGreaterThanTokenInJsxOpeningElement = new Rule(RuleDescriptor.create1(SyntaxKind.SlashToken, SyntaxKind.GreaterThanToken), RuleOperation.create2(new RuleOperationContext(Rules.IsJsxSelfClosingElementContext, Rules.IsNonJsxSameLineTokenContext), RuleAction.Delete));
this.NoSpaceBeforeEqualInJsxAttribute = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.EqualsToken), RuleOperation.create2(new RuleOperationContext(Rules.IsJsxAttributeContext, Rules.IsNonJsxSameLineTokenContext), RuleAction.Delete));
this.NoSpaceAfterEqualInJsxAttribute = new Rule(RuleDescriptor.create3(SyntaxKind.EqualsToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsJsxAttributeContext, Rules.IsNonJsxSameLineTokenContext), RuleAction.Delete));
// These rules are higher in priority than user-configurable rules.
this.HighPriorityCommonRules = [
this.IgnoreBeforeComment, this.IgnoreAfterLineComment,
@ -413,6 +427,8 @@ namespace ts.formatting {
this.SpaceAfterVoidOperator,
this.SpaceBetweenAsyncAndOpenParen, this.SpaceBetweenAsyncAndFunctionKeyword,
this.NoSpaceBetweenTagAndTemplateString,
this.SpaceBeforeJsxAttribute, this.SpaceBeforeSlashInJsxOpeningElement, this.NoSpaceBeforeGreaterThanTokenInJsxOpeningElement,
this.NoSpaceBeforeEqualInJsxAttribute, this.NoSpaceAfterEqualInJsxAttribute,
// TypeScript-specific rules
this.NoSpaceAfterConstructor, this.NoSpaceAfterModuleImport,
@ -450,8 +466,8 @@ namespace ts.formatting {
///
// Insert space after comma delimiter
this.SpaceAfterComma = new Rule(RuleDescriptor.create3(SyntaxKind.CommaToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.isNonJsxElementContext, Rules.IsNextTokenNotCloseBracket), RuleAction.Space));
this.NoSpaceAfterComma = new Rule(RuleDescriptor.create3(SyntaxKind.CommaToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.isNonJsxElementContext), RuleAction.Delete));
this.SpaceAfterComma = new Rule(RuleDescriptor.create3(SyntaxKind.CommaToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsNonJsxElementContext, Rules.IsNextTokenNotCloseBracket), RuleAction.Space));
this.NoSpaceAfterComma = new Rule(RuleDescriptor.create3(SyntaxKind.CommaToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsNonJsxElementContext), RuleAction.Delete));
// Insert space before and after binary operators
this.SpaceBeforeBinaryOperator = new Rule(RuleDescriptor.create4(Shared.TokenRange.Any, Shared.TokenRange.BinaryOperators), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsBinaryOpContext), RuleAction.Space));
@ -498,10 +514,10 @@ namespace ts.formatting {
this.SpaceBeforeTemplateMiddleAndTail = new Rule(RuleDescriptor.create4(Shared.TokenRange.Any, Shared.TokenRange.FromTokens([SyntaxKind.TemplateMiddle, SyntaxKind.TemplateTail])), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Space));
// No space after { and before } in JSX expression
this.NoSpaceAfterOpenBraceInJsxExpression = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBraceToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.isJsxExpressionContext), RuleAction.Delete));
this.SpaceAfterOpenBraceInJsxExpression = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBraceToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.isJsxExpressionContext), RuleAction.Space));
this.NoSpaceBeforeCloseBraceInJsxExpression = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.isJsxExpressionContext), RuleAction.Delete));
this.SpaceBeforeCloseBraceInJsxExpression = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.isJsxExpressionContext), RuleAction.Space));
this.NoSpaceAfterOpenBraceInJsxExpression = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBraceToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsJsxExpressionContext), RuleAction.Delete));
this.SpaceAfterOpenBraceInJsxExpression = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBraceToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsJsxExpressionContext), RuleAction.Space));
this.NoSpaceBeforeCloseBraceInJsxExpression = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsJsxExpressionContext), RuleAction.Delete));
this.SpaceBeforeCloseBraceInJsxExpression = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsJsxExpressionContext), RuleAction.Space));
// Insert space after function keyword for anonymous functions
this.SpaceAfterAnonymousFunctionKeyword = new Rule(RuleDescriptor.create1(SyntaxKind.FunctionKeyword, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsFunctionDeclContext), RuleAction.Space));
@ -741,14 +757,26 @@ namespace ts.formatting {
return context.TokensAreOnSameLine() && context.contextNode.kind !== SyntaxKind.JsxText;
}
static isNonJsxElementContext(context: FormattingContext): boolean {
static IsNonJsxElementContext(context: FormattingContext): boolean {
return context.contextNode.kind !== SyntaxKind.JsxElement;
}
static isJsxExpressionContext(context: FormattingContext): boolean {
static IsJsxExpressionContext(context: FormattingContext): boolean {
return context.contextNode.kind === SyntaxKind.JsxExpression;
}
static IsNextTokenParentJsxAttribute(context: FormattingContext): boolean {
return context.nextTokenParent.kind === SyntaxKind.JsxAttribute;
}
static IsJsxAttributeContext(context: FormattingContext): boolean {
return context.contextNode.kind === SyntaxKind.JsxAttribute;
}
static IsJsxSelfClosingElementContext(context: FormattingContext): boolean {
return context.contextNode.kind === SyntaxKind.JsxSelfClosingElement;
}
static IsNotBeforeBlockInFunctionDeclarationContext(context: FormattingContext): boolean {
return !Rules.IsFunctionDeclContext(context) && !Rules.IsBeforeBlockContext(context);
}

View File

@ -3095,14 +3095,16 @@ namespace ts {
const oldSettings = program && program.getCompilerOptions();
const newSettings = hostCache.compilationSettings();
const changesInCompilationSettingsAffectSyntax = oldSettings &&
const shouldCreateNewSourceFiles = oldSettings &&
(oldSettings.target !== newSettings.target ||
oldSettings.module !== newSettings.module ||
oldSettings.moduleResolution !== newSettings.moduleResolution ||
oldSettings.noResolve !== newSettings.noResolve ||
oldSettings.jsx !== newSettings.jsx ||
oldSettings.allowJs !== newSettings.allowJs ||
oldSettings.disableSizeLimit !== oldSettings.disableSizeLimit);
oldSettings.disableSizeLimit !== oldSettings.disableSizeLimit ||
oldSettings.baseUrl !== newSettings.baseUrl ||
!mapIsEqualTo(oldSettings.paths, newSettings.paths));
// Now create a new compiler
const compilerHost: CompilerHost = {
@ -3154,7 +3156,7 @@ namespace ts {
const oldSourceFiles = program.getSourceFiles();
const oldSettingsKey = documentRegistry.getKeyForCompilationSettings(oldSettings);
for (const oldSourceFile of oldSourceFiles) {
if (!newProgram.getSourceFile(oldSourceFile.fileName) || changesInCompilationSettingsAffectSyntax) {
if (!newProgram.getSourceFile(oldSourceFile.fileName) || shouldCreateNewSourceFiles) {
documentRegistry.releaseDocumentWithKey(oldSourceFile.path, oldSettingsKey);
}
}
@ -3188,7 +3190,7 @@ namespace ts {
// Check if the language version has changed since we last created a program; if they are the same,
// it is safe to reuse the sourceFiles; if not, then the shape of the AST can change, and the oldSourceFile
// can not be reused. we have to dump all syntax trees and create new ones.
if (!changesInCompilationSettingsAffectSyntax) {
if (!shouldCreateNewSourceFiles) {
// Check if the old program had this file already
const oldSourceFile = program && program.getSourceFileByPath(path);
if (oldSourceFile) {

View File

@ -3,21 +3,21 @@ var a: string[] = [];
>a : Symbol(a, Decl(arrayConcat2.ts, 0, 3))
a.concat("hello", 'world');
>a.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
>a.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>a : Symbol(a, Decl(arrayConcat2.ts, 0, 3))
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
a.concat('Hello');
>a.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
>a.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>a : Symbol(a, Decl(arrayConcat2.ts, 0, 3))
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
var b = new Array<string>();
>b : Symbol(b, Decl(arrayConcat2.ts, 5, 3))
>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
b.concat('hello');
>b.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
>b.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>b : Symbol(b, Decl(arrayConcat2.ts, 5, 3))
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))

View File

@ -5,17 +5,17 @@ var a: string[] = [];
a.concat("hello", 'world');
>a.concat("hello", 'world') : string[]
>a.concat : (...items: (string | string[])[]) => string[]
>a.concat : { (...items: string[][]): string[]; (...items: (string | string[])[]): string[]; }
>a : string[]
>concat : (...items: (string | string[])[]) => string[]
>concat : { (...items: string[][]): string[]; (...items: (string | string[])[]): string[]; }
>"hello" : string
>'world' : string
a.concat('Hello');
>a.concat('Hello') : string[]
>a.concat : (...items: (string | string[])[]) => string[]
>a.concat : { (...items: string[][]): string[]; (...items: (string | string[])[]): string[]; }
>a : string[]
>concat : (...items: (string | string[])[]) => string[]
>concat : { (...items: string[][]): string[]; (...items: (string | string[])[]): string[]; }
>'Hello' : string
var b = new Array<string>();
@ -25,8 +25,8 @@ var b = new Array<string>();
b.concat('hello');
>b.concat('hello') : string[]
>b.concat : (...items: (string | string[])[]) => string[]
>b.concat : { (...items: string[][]): string[]; (...items: (string | string[])[]): string[]; }
>b : string[]
>concat : (...items: (string | string[])[]) => string[]
>concat : { (...items: string[][]): string[]; (...items: (string | string[])[]): string[]; }
>'hello' : string

View File

@ -2,8 +2,8 @@
var x = [].concat([{ a: 1 }], [{ a: 2 }])
>x : Symbol(x, Decl(arrayConcatMap.ts, 0, 3))
>[].concat([{ a: 1 }], [{ a: 2 }]) .map : Symbol(Array.map, Decl(lib.d.ts, --, --))
>[].concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
>[].concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>a : Symbol(a, Decl(arrayConcatMap.ts, 0, 20))
>a : Symbol(a, Decl(arrayConcatMap.ts, 0, 32))

View File

@ -4,9 +4,9 @@ var x = [].concat([{ a: 1 }], [{ a: 2 }])
>[].concat([{ a: 1 }], [{ a: 2 }]) .map(b => b.a) : any[]
>[].concat([{ a: 1 }], [{ a: 2 }]) .map : <U>(callbackfn: (value: any, index: number, array: any[]) => U, thisArg?: any) => U[]
>[].concat([{ a: 1 }], [{ a: 2 }]) : any[]
>[].concat : (...items: any[]) => any[]
>[].concat : { (...items: any[][]): any[]; (...items: any[]): any[]; }
>[] : undefined[]
>concat : (...items: any[]) => any[]
>concat : { (...items: any[][]): any[]; (...items: any[]): any[]; }
>[{ a: 1 }] : { a: number; }[]
>{ a: 1 } : { a: number; }
>a : number

View File

@ -0,0 +1,19 @@
//// [asOpEmitParens.ts]
declare var x;
// Must emit as (x + 1) * 3
(x + 1 as number) * 3;
// Should still emit as x.y
(x as any).y;
// Emit as new (x())
new (x() as any);
//// [asOpEmitParens.js]
// Must emit as (x + 1) * 3
(x + 1) * 3;
// Should still emit as x.y
x.y;
// Emit as new (x())
new (x());

View File

@ -0,0 +1,16 @@
=== tests/cases/conformance/expressions/asOperator/asOpEmitParens.ts ===
declare var x;
>x : Symbol(x, Decl(asOpEmitParens.ts, 0, 11))
// Must emit as (x + 1) * 3
(x + 1 as number) * 3;
>x : Symbol(x, Decl(asOpEmitParens.ts, 0, 11))
// Should still emit as x.y
(x as any).y;
>x : Symbol(x, Decl(asOpEmitParens.ts, 0, 11))
// Emit as new (x())
new (x() as any);
>x : Symbol(x, Decl(asOpEmitParens.ts, 0, 11))

View File

@ -0,0 +1,30 @@
=== tests/cases/conformance/expressions/asOperator/asOpEmitParens.ts ===
declare var x;
>x : any
// Must emit as (x + 1) * 3
(x + 1 as number) * 3;
>(x + 1 as number) * 3 : number
>(x + 1 as number) : number
>x + 1 as number : number
>x + 1 : any
>x : any
>1 : number
>3 : number
// Should still emit as x.y
(x as any).y;
>(x as any).y : any
>(x as any) : any
>x as any : any
>x : any
>y : any
// Emit as new (x())
new (x() as any);
>new (x() as any) : any
>(x() as any) : any
>x() as any : any
>x() : any
>x : any

View File

@ -0,0 +1,35 @@
//// [bestChoiceType.ts]
// Repro from #10041
(''.match(/ /) || []).map(s => s.toLowerCase());
// Similar cases
function f1() {
let x = ''.match(/ /);
let y = x || [];
let z = y.map(s => s.toLowerCase());
}
function f2() {
let x = ''.match(/ /);
let y = x ? x : [];
let z = y.map(s => s.toLowerCase());
}
//// [bestChoiceType.js]
// Repro from #10041
(''.match(/ /) || []).map(function (s) { return s.toLowerCase(); });
// Similar cases
function f1() {
var x = ''.match(/ /);
var y = x || [];
var z = y.map(function (s) { return s.toLowerCase(); });
}
function f2() {
var x = ''.match(/ /);
var y = x ? x : [];
var z = y.map(function (s) { return s.toLowerCase(); });
}

View File

@ -0,0 +1,63 @@
=== tests/cases/compiler/bestChoiceType.ts ===
// Repro from #10041
(''.match(/ /) || []).map(s => s.toLowerCase());
>(''.match(/ /) || []).map : Symbol(Array.map, Decl(lib.d.ts, --, --))
>''.match : Symbol(String.match, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>match : Symbol(String.match, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>map : Symbol(Array.map, Decl(lib.d.ts, --, --))
>s : Symbol(s, Decl(bestChoiceType.ts, 3, 26))
>s.toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --))
>s : Symbol(s, Decl(bestChoiceType.ts, 3, 26))
>toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --))
// Similar cases
function f1() {
>f1 : Symbol(f1, Decl(bestChoiceType.ts, 3, 48))
let x = ''.match(/ /);
>x : Symbol(x, Decl(bestChoiceType.ts, 8, 7))
>''.match : Symbol(String.match, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>match : Symbol(String.match, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
let y = x || [];
>y : Symbol(y, Decl(bestChoiceType.ts, 9, 7))
>x : Symbol(x, Decl(bestChoiceType.ts, 8, 7))
let z = y.map(s => s.toLowerCase());
>z : Symbol(z, Decl(bestChoiceType.ts, 10, 7))
>y.map : Symbol(Array.map, Decl(lib.d.ts, --, --))
>y : Symbol(y, Decl(bestChoiceType.ts, 9, 7))
>map : Symbol(Array.map, Decl(lib.d.ts, --, --))
>s : Symbol(s, Decl(bestChoiceType.ts, 10, 18))
>s.toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --))
>s : Symbol(s, Decl(bestChoiceType.ts, 10, 18))
>toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --))
}
function f2() {
>f2 : Symbol(f2, Decl(bestChoiceType.ts, 11, 1))
let x = ''.match(/ /);
>x : Symbol(x, Decl(bestChoiceType.ts, 14, 7))
>''.match : Symbol(String.match, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>match : Symbol(String.match, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
let y = x ? x : [];
>y : Symbol(y, Decl(bestChoiceType.ts, 15, 7))
>x : Symbol(x, Decl(bestChoiceType.ts, 14, 7))
>x : Symbol(x, Decl(bestChoiceType.ts, 14, 7))
let z = y.map(s => s.toLowerCase());
>z : Symbol(z, Decl(bestChoiceType.ts, 16, 7))
>y.map : Symbol(Array.map, Decl(lib.d.ts, --, --))
>y : Symbol(y, Decl(bestChoiceType.ts, 15, 7))
>map : Symbol(Array.map, Decl(lib.d.ts, --, --))
>s : Symbol(s, Decl(bestChoiceType.ts, 16, 18))
>s.toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --))
>s : Symbol(s, Decl(bestChoiceType.ts, 16, 18))
>toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --))
}

View File

@ -0,0 +1,88 @@
=== tests/cases/compiler/bestChoiceType.ts ===
// Repro from #10041
(''.match(/ /) || []).map(s => s.toLowerCase());
>(''.match(/ /) || []).map(s => s.toLowerCase()) : string[]
>(''.match(/ /) || []).map : <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]
>(''.match(/ /) || []) : RegExpMatchArray
>''.match(/ /) || [] : RegExpMatchArray
>''.match(/ /) : RegExpMatchArray | null
>''.match : { (regexp: string): RegExpMatchArray | null; (regexp: RegExp): RegExpMatchArray | null; }
>'' : string
>match : { (regexp: string): RegExpMatchArray | null; (regexp: RegExp): RegExpMatchArray | null; }
>/ / : RegExp
>[] : never[]
>map : <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]
>s => s.toLowerCase() : (s: string) => string
>s : string
>s.toLowerCase() : string
>s.toLowerCase : () => string
>s : string
>toLowerCase : () => string
// Similar cases
function f1() {
>f1 : () => void
let x = ''.match(/ /);
>x : RegExpMatchArray | null
>''.match(/ /) : RegExpMatchArray | null
>''.match : { (regexp: string): RegExpMatchArray | null; (regexp: RegExp): RegExpMatchArray | null; }
>'' : string
>match : { (regexp: string): RegExpMatchArray | null; (regexp: RegExp): RegExpMatchArray | null; }
>/ / : RegExp
let y = x || [];
>y : RegExpMatchArray
>x || [] : RegExpMatchArray
>x : RegExpMatchArray | null
>[] : never[]
let z = y.map(s => s.toLowerCase());
>z : string[]
>y.map(s => s.toLowerCase()) : string[]
>y.map : <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]
>y : RegExpMatchArray
>map : <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]
>s => s.toLowerCase() : (s: string) => string
>s : string
>s.toLowerCase() : string
>s.toLowerCase : () => string
>s : string
>toLowerCase : () => string
}
function f2() {
>f2 : () => void
let x = ''.match(/ /);
>x : RegExpMatchArray | null
>''.match(/ /) : RegExpMatchArray | null
>''.match : { (regexp: string): RegExpMatchArray | null; (regexp: RegExp): RegExpMatchArray | null; }
>'' : string
>match : { (regexp: string): RegExpMatchArray | null; (regexp: RegExp): RegExpMatchArray | null; }
>/ / : RegExp
let y = x ? x : [];
>y : RegExpMatchArray
>x ? x : [] : RegExpMatchArray
>x : RegExpMatchArray | null
>x : RegExpMatchArray
>[] : never[]
let z = y.map(s => s.toLowerCase());
>z : string[]
>y.map(s => s.toLowerCase()) : string[]
>y.map : <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]
>y : RegExpMatchArray
>map : <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]
>s => s.toLowerCase() : (s: string) => string
>s : string
>s.toLowerCase() : string
>s.toLowerCase : () => string
>s : string
>toLowerCase : () => string
}

View File

@ -14,15 +14,15 @@ var fa: number[];
fa = fa.concat([0]);
>fa : Symbol(fa, Decl(concatError.ts, 8, 3))
>fa.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
>fa.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>fa : Symbol(fa, Decl(concatError.ts, 8, 3))
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
fa = fa.concat(0);
>fa : Symbol(fa, Decl(concatError.ts, 8, 3))
>fa.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
>fa.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>fa : Symbol(fa, Decl(concatError.ts, 8, 3))
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))

View File

@ -16,9 +16,9 @@ fa = fa.concat([0]);
>fa = fa.concat([0]) : number[]
>fa : number[]
>fa.concat([0]) : number[]
>fa.concat : (...items: (number | number[])[]) => number[]
>fa.concat : { (...items: number[][]): number[]; (...items: (number | number[])[]): number[]; }
>fa : number[]
>concat : (...items: (number | number[])[]) => number[]
>concat : { (...items: number[][]): number[]; (...items: (number | number[])[]): number[]; }
>[0] : number[]
>0 : number
@ -26,9 +26,9 @@ fa = fa.concat(0);
>fa = fa.concat(0) : number[]
>fa : number[]
>fa.concat(0) : number[]
>fa.concat : (...items: (number | number[])[]) => number[]
>fa.concat : { (...items: number[][]): number[]; (...items: (number | number[])[]): number[]; }
>fa : number[]
>concat : (...items: (number | number[])[]) => number[]
>concat : { (...items: number[][]): number[]; (...items: (number | number[])[]): number[]; }
>0 : number

View File

@ -0,0 +1,8 @@
//// [concatTuples.ts]
let ijs: [number, number][] = [[1, 2]];
ijs = ijs.concat([[3, 4], [5, 6]]);
//// [concatTuples.js]
var ijs = [[1, 2]];
ijs = ijs.concat([[3, 4], [5, 6]]);

View File

@ -0,0 +1,10 @@
=== tests/cases/compiler/concatTuples.ts ===
let ijs: [number, number][] = [[1, 2]];
>ijs : Symbol(ijs, Decl(concatTuples.ts, 0, 3))
ijs = ijs.concat([[3, 4], [5, 6]]);
>ijs : Symbol(ijs, Decl(concatTuples.ts, 0, 3))
>ijs.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>ijs : Symbol(ijs, Decl(concatTuples.ts, 0, 3))
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))

View File

@ -0,0 +1,23 @@
=== tests/cases/compiler/concatTuples.ts ===
let ijs: [number, number][] = [[1, 2]];
>ijs : [number, number][]
>[[1, 2]] : [number, number][]
>[1, 2] : [number, number]
>1 : number
>2 : number
ijs = ijs.concat([[3, 4], [5, 6]]);
>ijs = ijs.concat([[3, 4], [5, 6]]) : [number, number][]
>ijs : [number, number][]
>ijs.concat([[3, 4], [5, 6]]) : [number, number][]
>ijs.concat : { (...items: [number, number][][]): [number, number][]; (...items: ([number, number] | [number, number][])[]): [number, number][]; }
>ijs : [number, number][]
>concat : { (...items: [number, number][][]): [number, number][]; (...items: ([number, number] | [number, number][])[]): [number, number][]; }
>[[3, 4], [5, 6]] : [number, number][]
>[3, 4] : [number, number]
>3 : number
>4 : number
>[5, 6] : [number, number]
>5 : number
>6 : number

View File

@ -15,9 +15,9 @@ function rebase(fn: (base: any, ...args: any[]) => any): (...args: any[]) => any
>fn : Symbol(fn, Decl(emitSkipsThisWithRestParameter.ts, 0, 16))
>apply : Symbol(Function.apply, Decl(lib.d.ts, --, --))
>this : Symbol(this, Decl(emitSkipsThisWithRestParameter.ts, 1, 20))
>[ this ].concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
>[ this ].concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>this : Symbol(this, Decl(emitSkipsThisWithRestParameter.ts, 1, 20))
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>args : Symbol(args, Decl(emitSkipsThisWithRestParameter.ts, 1, 30))
};

View File

@ -18,10 +18,10 @@ function rebase(fn: (base: any, ...args: any[]) => any): (...args: any[]) => any
>apply : (this: Function, thisArg: any, argArray?: any) => any
>this : any
>[ this ].concat(args) : any[]
>[ this ].concat : (...items: any[]) => any[]
>[ this ].concat : { (...items: any[][]): any[]; (...items: any[]): any[]; }
>[ this ] : any[]
>this : any
>concat : (...items: any[]) => any[]
>concat : { (...items: any[][]): any[]; (...items: any[]): any[]; }
>args : any[]
};

View File

@ -3,9 +3,9 @@ var array: symbol[];
>array : Symbol(array, Decl(iteratorSpreadInArray7.ts, 0, 3))
array.concat([...new SymbolIterator]);
>array.concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --))
>array.concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>array : Symbol(array, Decl(iteratorSpreadInArray7.ts, 0, 3))
>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --))
>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>SymbolIterator : Symbol(SymbolIterator, Decl(iteratorSpreadInArray7.ts, 1, 38))
class SymbolIterator {

View File

@ -4,9 +4,9 @@ var array: symbol[];
array.concat([...new SymbolIterator]);
>array.concat([...new SymbolIterator]) : symbol[]
>array.concat : (...items: (symbol | symbol[])[]) => symbol[]
>array.concat : { (...items: symbol[][]): symbol[]; (...items: (symbol | symbol[])[]): symbol[]; }
>array : symbol[]
>concat : (...items: (symbol | symbol[])[]) => symbol[]
>concat : { (...items: symbol[][]): symbol[]; (...items: (symbol | symbol[])[]): symbol[]; }
>[...new SymbolIterator] : symbol[]
>...new SymbolIterator : symbol
>new SymbolIterator : SymbolIterator

View File

@ -28,8 +28,8 @@ var e: Ellement;
>Ellement : Symbol(Ellement, Decl(nonContextuallyTypedLogicalOr.ts, 3, 1))
(c || e).dummy;
>(c || e).dummy : Symbol(dummy, Decl(nonContextuallyTypedLogicalOr.ts, 0, 22), Decl(nonContextuallyTypedLogicalOr.ts, 5, 20))
>(c || e).dummy : Symbol(Contextual.dummy, Decl(nonContextuallyTypedLogicalOr.ts, 0, 22))
>c : Symbol(c, Decl(nonContextuallyTypedLogicalOr.ts, 10, 3))
>e : Symbol(e, Decl(nonContextuallyTypedLogicalOr.ts, 11, 3))
>dummy : Symbol(dummy, Decl(nonContextuallyTypedLogicalOr.ts, 0, 22), Decl(nonContextuallyTypedLogicalOr.ts, 5, 20))
>dummy : Symbol(Contextual.dummy, Decl(nonContextuallyTypedLogicalOr.ts, 0, 22))

View File

@ -29,8 +29,8 @@ var e: Ellement;
(c || e).dummy;
>(c || e).dummy : any
>(c || e) : Contextual | Ellement
>c || e : Contextual | Ellement
>(c || e) : Contextual
>c || e : Contextual
>c : Contextual
>e : Ellement
>dummy : any

View File

@ -300,9 +300,9 @@ class ListWrapper {
>ListWrapper : Symbol(ListWrapper, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 38, 1))
>a : Symbol(a, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 68, 40))
>b : Symbol(b, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 68, 50))
>a.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
>a.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>a : Symbol(a, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 68, 40))
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>b : Symbol(b, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 68, 50))
static insert<T>(dit: typeof ListWrapper, list: T[], index: number, value: T) { list.splice(index, 0, value); }

View File

@ -348,9 +348,9 @@ class ListWrapper {
>a : any[]
>b : any[]
>a.concat(b) : any[]
>a.concat : (...items: any[]) => any[]
>a.concat : { (...items: any[][]): any[]; (...items: any[]): any[]; }
>a : any[]
>concat : (...items: any[]) => any[]
>concat : { (...items: any[][]): any[]; (...items: any[]): any[]; }
>b : any[]
static insert<T>(dit: typeof ListWrapper, list: T[], index: number, value: T) { list.splice(index, 0, value); }

View File

@ -69,8 +69,8 @@ var b: { Foo2: Derived; }
>Derived : Derived
var r = true ? a : b; // ok
>r : { Foo?: Base; } | { Foo2: Derived; }
>true ? a : b : { Foo?: Base; } | { Foo2: Derived; }
>r : { Foo?: Base; }
>true ? a : b : { Foo?: Base; }
>true : boolean
>a : { Foo?: Base; }
>b : { Foo2: Derived; }

View File

@ -69,8 +69,8 @@ var b: { Foo2?: Derived; }
>Derived : Derived
var r = true ? a : b; // ok
>r : { Foo: Base; } | { Foo2?: Derived; }
>true ? a : b : { Foo: Base; } | { Foo2?: Derived; }
>r : { Foo2?: Derived; }
>true ? a : b : { Foo2?: Derived; }
>true : boolean
>a : { Foo: Base; }
>b : { Foo2?: Derived; }

View File

@ -1,20 +0,0 @@
tests/cases/compiler/b.d.ts(2,20): error TS2305: Module '"tests/cases/compiler/a".ns' has no exported member 'IFoo'.
==== tests/cases/compiler/a.d.ts (0 errors) ====
export = ns;
export as namespace ns;
declare namespace ns {
export var x: number;
export interface IFoo { }
}
==== tests/cases/compiler/b.d.ts (1 errors) ====
declare namespace ns.something {
export var p: ns.IFoo;
~~~~
!!! error TS2305: Module '"tests/cases/compiler/a".ns' has no exported member 'IFoo'.
}

View File

@ -71,9 +71,9 @@ var flat = _.reduceRight(list, (a, b) => a.concat(b), []);
>list : Symbol(list, Decl(underscoreTest1_underscoreTests.ts, 13, 3))
>a : Symbol(a, Decl(underscoreTest1_underscoreTests.ts, 14, 32))
>b : Symbol(b, Decl(underscoreTest1_underscoreTests.ts, 14, 34))
>a.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
>a.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>a : Symbol(a, Decl(underscoreTest1_underscoreTests.ts, 14, 32))
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>b : Symbol(b, Decl(underscoreTest1_underscoreTests.ts, 14, 34))
var even = _.find([1, 2, 3, 4, 5, 6], (num) => num % 2 == 0);

View File

@ -124,9 +124,9 @@ var flat = _.reduceRight(list, (a, b) => a.concat(b), []);
>a : number[]
>b : number[]
>a.concat(b) : number[]
>a.concat : (...items: (number | number[])[]) => number[]
>a.concat : { (...items: number[][]): number[]; (...items: (number | number[])[]): number[]; }
>a : number[]
>concat : (...items: (number | number[])[]) => number[]
>concat : { (...items: number[][]): number[]; (...items: (number | number[])[]): number[]; }
>b : number[]
>[] : undefined[]

View File

@ -0,0 +1,19 @@
// @strictNullChecks: true
// Repro from #10041
(''.match(/ /) || []).map(s => s.toLowerCase());
// Similar cases
function f1() {
let x = ''.match(/ /);
let y = x || [];
let z = y.map(s => s.toLowerCase());
}
function f2() {
let x = ''.match(/ /);
let y = x ? x : [];
let z = y.map(s => s.toLowerCase());
}

View File

@ -0,0 +1,2 @@
let ijs: [number, number][] = [[1, 2]];
ijs = ijs.concat([[3, 4], [5, 6]]);

View File

@ -1,14 +0,0 @@
// @filename: a.d.ts
export = ns;
export as namespace ns;
declare namespace ns {
export var x: number;
export interface IFoo { }
}
// @filename: b.d.ts
declare namespace ns.something {
export var p: ns.IFoo;
}

View File

@ -0,0 +1,9 @@
declare var x;
// Must emit as (x + 1) * 3
(x + 1 as number) * 3;
// Should still emit as x.y
(x as any).y;
// Emit as new (x())
new (x() as any);

View File

@ -70,7 +70,7 @@
////<div>, {integer}</div>;/*commaInJsxElement2*/
////<span>)</span>;/*closingParenInJsxElement*/
////<span>) </span>;/*closingParenInJsxElement2*/
////<Router routes={ 3 } />;/*jsxExpressionSpaces*/
////<Router routes = { 3 } / >;/*jsxExpressionSpaces*/
////<Router routes={ (3) } />;/*jsxExpressionSpaces2*/
format.document();
@ -85,7 +85,7 @@ goTo.marker("indent1");
verify.indentationIs(12);
goTo.marker("1");
verify.currentLineContentIs(' class1= {');
verify.currentLineContentIs(' class1={');
goTo.marker("2");
verify.currentLineContentIs(' }>');
@ -95,7 +95,7 @@ goTo.marker("indent2");
verify.indentationIs(12);
goTo.marker("3");
verify.currentLineContentIs(' class2= {');
verify.currentLineContentIs(' class2={');
goTo.marker("4");
verify.currentLineContentIs(' }>');
@ -105,9 +105,9 @@ goTo.marker("indent3");
verify.indentationIs(12);
goTo.marker("5");
verify.currentLineContentIs(' class3= {');
verify.currentLineContentIs(' class3={');
goTo.marker("6");
verify.currentLineContentIs(' }/>');
verify.currentLineContentIs(' } />');
goTo.marker("attrAutoformat");