mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge pull request #2255 from Microsoft/returnStatus
Address omitted return keyword.
This commit is contained in:
+91
-21
@@ -2918,6 +2918,7 @@ module ts {
|
||||
function createPropertyAccessExpression(expression: LeftHandSideExpression, name: Identifier): PropertyAccessExpression {
|
||||
var result = <PropertyAccessExpression>createSynthesizedNode(SyntaxKind.PropertyAccessExpression);
|
||||
result.expression = expression;
|
||||
result.dotToken = createSynthesizedNode(SyntaxKind.DotToken);
|
||||
result.name = name;
|
||||
|
||||
return result;
|
||||
@@ -3033,13 +3034,38 @@ module ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function indentIfOnDifferentLines(parent: Node, node1: Node, node2: Node) {
|
||||
var isSynthesized = nodeIsSynthesized(parent);
|
||||
|
||||
var realNodesAreOnDifferentLines = !isSynthesized && !nodeEndIsOnSameLineAsNodeStart(node1, node2);
|
||||
var synthesizedNodeIsOnDifferentLine = synthesizedNodeStartsOnNewLine(node2);
|
||||
if (realNodesAreOnDifferentLines || synthesizedNodeIsOnDifferentLine) {
|
||||
increaseIndent();
|
||||
writeLine();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function emitPropertyAccess(node: PropertyAccessExpression) {
|
||||
if (tryEmitConstantValue(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
emit(node.expression);
|
||||
|
||||
var indented = indentIfOnDifferentLines(node, node.expression, node.dotToken);
|
||||
|
||||
write(".");
|
||||
|
||||
indented = indented || indentIfOnDifferentLines(node, node.dotToken, node.name);
|
||||
|
||||
emit(node.name);
|
||||
|
||||
if (indented) {
|
||||
decreaseIndent();
|
||||
}
|
||||
}
|
||||
|
||||
function emitQualifiedName(node: QualifiedName) {
|
||||
@@ -3273,25 +3299,31 @@ module ts {
|
||||
else {
|
||||
emit(node.left);
|
||||
|
||||
if (node.operatorToken.kind !== SyntaxKind.CommaToken) {
|
||||
// If there was a newline between the left side of the binary expression and the
|
||||
// operator, then try to preserve that.
|
||||
var indented1 = indentIfOnDifferentLines(node, node.left, node.operatorToken);
|
||||
|
||||
// Otherwise just emit the operator right afterwards. For everything but
|
||||
// comma, emit a space before the operator.
|
||||
if (!indented1 && node.operatorToken.kind !== SyntaxKind.CommaToken) {
|
||||
write(" ");
|
||||
}
|
||||
|
||||
write(tokenToString(node.operatorToken.kind));
|
||||
|
||||
var shouldPlaceOnNewLine = !nodeIsSynthesized(node) && !nodeEndIsOnSameLineAsNodeStart(node.operatorToken, node.right);
|
||||
|
||||
// Check if the right expression is on a different line versus the operator itself. If so,
|
||||
// we'll emit newline.
|
||||
if (shouldPlaceOnNewLine || synthesizedNodeStartsOnNewLine(node.right)) {
|
||||
increaseIndent();
|
||||
writeLine();
|
||||
emit(node.right);
|
||||
decreaseIndent();
|
||||
if (!indented1) {
|
||||
var indented2 = indentIfOnDifferentLines(node, node.operatorToken, node.right);
|
||||
}
|
||||
else {
|
||||
|
||||
if (!indented2) {
|
||||
write(" ");
|
||||
emit(node.right);
|
||||
}
|
||||
|
||||
emit(node.right);
|
||||
|
||||
// If we indented the left or the right side, then dedent now.
|
||||
if (indented1 || indented2) {
|
||||
decreaseIndent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3302,10 +3334,45 @@ module ts {
|
||||
|
||||
function emitConditionalExpression(node: ConditionalExpression) {
|
||||
emit(node.condition);
|
||||
write(" ? ");
|
||||
var indent1 = indentIfOnDifferentLines(node, node.condition, node.questionToken);
|
||||
if (!indent1) {
|
||||
write(" ");
|
||||
}
|
||||
|
||||
write("?");
|
||||
|
||||
if (!indent1) {
|
||||
var indent2 = indentIfOnDifferentLines(node, node.questionToken, node.whenTrue);
|
||||
}
|
||||
|
||||
if (!indent2) {
|
||||
write(" ");
|
||||
}
|
||||
|
||||
emit(node.whenTrue);
|
||||
write(" : ");
|
||||
|
||||
if (indent1 || indent2) {
|
||||
decreaseIndent();
|
||||
}
|
||||
|
||||
var indent3 = indentIfOnDifferentLines(node, node.whenTrue, node.colonToken);
|
||||
if (!indent3) {
|
||||
write(" ");
|
||||
}
|
||||
|
||||
write(":");
|
||||
if (!indent3) {
|
||||
var indent4 = indentIfOnDifferentLines(node, node.colonToken, node.whenFalse);
|
||||
}
|
||||
|
||||
if (!indent4) {
|
||||
write(" ");
|
||||
}
|
||||
|
||||
emit(node.whenFalse);
|
||||
if (indent3 || indent4) {
|
||||
decreaseIndent();
|
||||
}
|
||||
}
|
||||
|
||||
function isSingleLineEmptyBlock(node: Node) {
|
||||
@@ -3678,10 +3745,16 @@ module ts {
|
||||
equals.left = value;
|
||||
equals.operatorToken = createSynthesizedNode(SyntaxKind.EqualsEqualsEqualsToken);
|
||||
equals.right = createVoidZero();
|
||||
return createConditionalExpression(equals, defaultValue, value);
|
||||
}
|
||||
|
||||
function createConditionalExpression(condition: Expression, whenTrue: Expression, whenFalse: Expression) {
|
||||
var cond = <ConditionalExpression>createSynthesizedNode(SyntaxKind.ConditionalExpression);
|
||||
cond.condition = equals;
|
||||
cond.whenTrue = defaultValue;
|
||||
cond.whenFalse = value;
|
||||
cond.condition = condition;
|
||||
cond.questionToken = createSynthesizedNode(SyntaxKind.QuestionToken);
|
||||
cond.whenTrue = whenTrue;
|
||||
cond.colonToken = createSynthesizedNode(SyntaxKind.ColonToken);
|
||||
cond.whenFalse = whenFalse;
|
||||
return cond;
|
||||
}
|
||||
|
||||
@@ -3704,10 +3777,7 @@ module ts {
|
||||
if (propName.kind !== SyntaxKind.Identifier) {
|
||||
return createElementAccess(object, propName);
|
||||
}
|
||||
var node = <PropertyAccessExpression>createSynthesizedNode(SyntaxKind.PropertyAccessExpression);
|
||||
node.expression = parenthesizeForAccess(object);
|
||||
node.name = propName;
|
||||
return node;
|
||||
return createPropertyAccessExpression(parenthesizeForAccess(object), propName);
|
||||
}
|
||||
|
||||
function createElementAccess(object: Expression, index: Expression): Expression {
|
||||
|
||||
+19
-10
@@ -120,6 +120,7 @@ module ts {
|
||||
return visitNodes(cbNodes, (<ObjectLiteralExpression>node).properties);
|
||||
case SyntaxKind.PropertyAccessExpression:
|
||||
return visitNode(cbNode, (<PropertyAccessExpression>node).expression) ||
|
||||
visitNode(cbNode, (<PropertyAccessExpression>node).dotToken) ||
|
||||
visitNode(cbNode, (<PropertyAccessExpression>node).name);
|
||||
case SyntaxKind.ElementAccessExpression:
|
||||
return visitNode(cbNode, (<ElementAccessExpression>node).expression) ||
|
||||
@@ -156,7 +157,9 @@ module ts {
|
||||
visitNode(cbNode, (<BinaryExpression>node).right);
|
||||
case SyntaxKind.ConditionalExpression:
|
||||
return visitNode(cbNode, (<ConditionalExpression>node).condition) ||
|
||||
visitNode(cbNode, (<ConditionalExpression>node).questionToken) ||
|
||||
visitNode(cbNode, (<ConditionalExpression>node).whenTrue) ||
|
||||
visitNode(cbNode, (<ConditionalExpression>node).colonToken) ||
|
||||
visitNode(cbNode, (<ConditionalExpression>node).whenFalse);
|
||||
case SyntaxKind.SpreadElementExpression:
|
||||
return visitNode(cbNode, (<SpreadElementExpression>node).expression);
|
||||
@@ -1327,13 +1330,16 @@ module ts {
|
||||
|
||||
function parseOptionalToken(t: SyntaxKind): Node {
|
||||
if (token === t) {
|
||||
var node = createNode(t);
|
||||
nextToken();
|
||||
return finishNode(node);
|
||||
return parseTokenNode();
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function parseExpectedToken(t: SyntaxKind, reportAtCurrentPosition: boolean, diagnosticMessage: DiagnosticMessage, arg0?: any): Node {
|
||||
return parseOptionalToken(t) ||
|
||||
createMissingNode(t, reportAtCurrentPosition, diagnosticMessage, arg0);
|
||||
}
|
||||
|
||||
function parseTokenNode<T extends Node>(): T {
|
||||
var node = <T>createNode(token);
|
||||
nextToken();
|
||||
@@ -2162,8 +2168,7 @@ module ts {
|
||||
literal = parseLiteralNode();
|
||||
}
|
||||
else {
|
||||
literal = <LiteralExpression>createMissingNode(
|
||||
SyntaxKind.TemplateTail, /*reportAtCurrentPosition:*/ false, Diagnostics._0_expected, tokenToString(SyntaxKind.CloseBraceToken));
|
||||
literal = <LiteralExpression>parseExpectedToken(SyntaxKind.TemplateTail, /*reportAtCurrentPosition:*/ false, Diagnostics._0_expected, tokenToString(SyntaxKind.CloseBraceToken));
|
||||
}
|
||||
|
||||
span.literal = literal;
|
||||
@@ -3186,7 +3191,8 @@ module ts {
|
||||
|
||||
function parseConditionalExpressionRest(leftOperand: Expression): Expression {
|
||||
// Note: we are passed in an expression which was produced from parseBinaryExpressionOrHigher.
|
||||
if (!parseOptional(SyntaxKind.QuestionToken)) {
|
||||
var questionToken = parseOptionalToken(SyntaxKind.QuestionToken);
|
||||
if (!questionToken) {
|
||||
return leftOperand;
|
||||
}
|
||||
|
||||
@@ -3194,8 +3200,10 @@ module ts {
|
||||
// we do not that for the 'whenFalse' part.
|
||||
var node = <ConditionalExpression>createNode(SyntaxKind.ConditionalExpression, leftOperand.pos);
|
||||
node.condition = leftOperand;
|
||||
node.questionToken = questionToken;
|
||||
node.whenTrue = allowInAnd(parseAssignmentExpressionOrHigher);
|
||||
parseExpected(SyntaxKind.ColonToken);
|
||||
node.colonToken = parseExpectedToken(SyntaxKind.ColonToken, /*reportAtCurrentPosition:*/ false,
|
||||
Diagnostics._0_expected, tokenToString(SyntaxKind.ColonToken));
|
||||
node.whenFalse = parseAssignmentExpressionOrHigher();
|
||||
return finishNode(node);
|
||||
}
|
||||
@@ -3458,7 +3466,7 @@ module ts {
|
||||
// If it wasn't then just try to parse out a '.' and report an error.
|
||||
var node = <PropertyAccessExpression>createNode(SyntaxKind.PropertyAccessExpression, expression.pos);
|
||||
node.expression = expression;
|
||||
parseExpected(SyntaxKind.DotToken, Diagnostics.super_must_be_followed_by_an_argument_list_or_member_access);
|
||||
node.dotToken = parseExpectedToken(SyntaxKind.DotToken, /*reportAtCurrentPosition:*/ false, Diagnostics.super_must_be_followed_by_an_argument_list_or_member_access);
|
||||
node.name = parseRightSideOfDot(/*allowIdentifierNames:*/ true);
|
||||
return finishNode(node);
|
||||
}
|
||||
@@ -3474,10 +3482,11 @@ module ts {
|
||||
|
||||
function parseMemberExpressionRest(expression: LeftHandSideExpression): MemberExpression {
|
||||
while (true) {
|
||||
var dotOrBracketStart = scanner.getTokenPos();
|
||||
if (parseOptional(SyntaxKind.DotToken)) {
|
||||
var dotToken = parseOptionalToken(SyntaxKind.DotToken);
|
||||
if (dotToken) {
|
||||
var propertyAccess = <PropertyAccessExpression>createNode(SyntaxKind.PropertyAccessExpression, expression.pos);
|
||||
propertyAccess.expression = expression;
|
||||
propertyAccess.dotToken = dotToken;
|
||||
propertyAccess.name = parseRightSideOfDot(/*allowIdentifierNames:*/ true);
|
||||
expression = finishNode(propertyAccess);
|
||||
continue;
|
||||
|
||||
+1
-1
@@ -411,7 +411,7 @@ module ts {
|
||||
// The emitter emitted something, inform the caller if that happened in the presence
|
||||
// of diagnostics or not.
|
||||
if (diagnostics.length > 0 || emitOutput.diagnostics.length > 0) {
|
||||
ExitStatus.DiagnosticsPresent_OutputsGenerated;
|
||||
return ExitStatus.DiagnosticsPresent_OutputsGenerated;
|
||||
}
|
||||
|
||||
return ExitStatus.Success;
|
||||
|
||||
@@ -641,7 +641,9 @@ module ts {
|
||||
|
||||
export interface ConditionalExpression extends Expression {
|
||||
condition: Expression;
|
||||
questionToken: Node;
|
||||
whenTrue: Expression;
|
||||
colonToken: Node;
|
||||
whenFalse: Expression;
|
||||
}
|
||||
|
||||
@@ -694,6 +696,7 @@ module ts {
|
||||
|
||||
export interface PropertyAccessExpression extends MemberExpression {
|
||||
expression: LeftHandSideExpression;
|
||||
dotToken: Node;
|
||||
name: Identifier;
|
||||
}
|
||||
|
||||
|
||||
@@ -543,7 +543,9 @@ declare module "typescript" {
|
||||
}
|
||||
interface ConditionalExpression extends Expression {
|
||||
condition: Expression;
|
||||
questionToken: Node;
|
||||
whenTrue: Expression;
|
||||
colonToken: Node;
|
||||
whenFalse: Expression;
|
||||
}
|
||||
interface FunctionExpression extends PrimaryExpression, FunctionLikeDeclaration {
|
||||
@@ -580,6 +582,7 @@ declare module "typescript" {
|
||||
}
|
||||
interface PropertyAccessExpression extends MemberExpression {
|
||||
expression: LeftHandSideExpression;
|
||||
dotToken: Node;
|
||||
name: Identifier;
|
||||
}
|
||||
interface ElementAccessExpression extends MemberExpression {
|
||||
|
||||
@@ -1636,10 +1636,18 @@ declare module "typescript" {
|
||||
>TypeNode : TypeNode
|
||||
|
||||
initializer?: Expression;
|
||||
|
||||
>initializer : Expression
|
||||
>Expression : Expression
|
||||
}
|
||||
|
||||
interface ObjectLiteralElement extends Declaration {
|
||||
|
||||
>ObjectLiteralElement : ObjectLiteralElement
|
||||
>Declaration : Declaration
|
||||
|
||||
_objectLiteralBrandBrand: any;
|
||||
|
||||
>_objectLiteralBrandBrand : any
|
||||
}
|
||||
|
||||
@@ -1746,6 +1754,10 @@ declare module "typescript" {
|
||||
|
||||
* AccessorDeclaration
|
||||
|
||||
*/
|
||||
|
||||
interface FunctionLikeDeclaration extends SignatureDeclaration {
|
||||
|
||||
>FunctionLikeDeclaration : FunctionLikeDeclaration
|
||||
>SignatureDeclaration : SignatureDeclaration
|
||||
|
||||
|
||||
@@ -574,7 +574,9 @@ declare module "typescript" {
|
||||
}
|
||||
interface ConditionalExpression extends Expression {
|
||||
condition: Expression;
|
||||
questionToken: Node;
|
||||
whenTrue: Expression;
|
||||
colonToken: Node;
|
||||
whenFalse: Expression;
|
||||
}
|
||||
interface FunctionExpression extends PrimaryExpression, FunctionLikeDeclaration {
|
||||
@@ -611,6 +613,7 @@ declare module "typescript" {
|
||||
}
|
||||
interface PropertyAccessExpression extends MemberExpression {
|
||||
expression: LeftHandSideExpression;
|
||||
dotToken: Node;
|
||||
name: Identifier;
|
||||
}
|
||||
interface ElementAccessExpression extends MemberExpression {
|
||||
|
||||
@@ -1782,10 +1782,18 @@ declare module "typescript" {
|
||||
>condition : Expression
|
||||
>Expression : Expression
|
||||
|
||||
questionToken: Node;
|
||||
>questionToken : Node
|
||||
>Node : Node
|
||||
|
||||
whenTrue: Expression;
|
||||
>whenTrue : Expression
|
||||
>Expression : Expression
|
||||
|
||||
colonToken: Node;
|
||||
>colonToken : Node
|
||||
>Node : Node
|
||||
|
||||
whenFalse: Expression;
|
||||
>whenFalse : Expression
|
||||
>Expression : Expression
|
||||
@@ -1892,6 +1900,10 @@ declare module "typescript" {
|
||||
>expression : LeftHandSideExpression
|
||||
>LeftHandSideExpression : LeftHandSideExpression
|
||||
|
||||
dotToken: Node;
|
||||
>dotToken : Node
|
||||
>Node : Node
|
||||
|
||||
name: Identifier;
|
||||
>name : Identifier
|
||||
>Identifier : Identifier
|
||||
|
||||
@@ -575,7 +575,9 @@ declare module "typescript" {
|
||||
}
|
||||
interface ConditionalExpression extends Expression {
|
||||
condition: Expression;
|
||||
questionToken: Node;
|
||||
whenTrue: Expression;
|
||||
colonToken: Node;
|
||||
whenFalse: Expression;
|
||||
}
|
||||
interface FunctionExpression extends PrimaryExpression, FunctionLikeDeclaration {
|
||||
@@ -612,6 +614,7 @@ declare module "typescript" {
|
||||
}
|
||||
interface PropertyAccessExpression extends MemberExpression {
|
||||
expression: LeftHandSideExpression;
|
||||
dotToken: Node;
|
||||
name: Identifier;
|
||||
}
|
||||
interface ElementAccessExpression extends MemberExpression {
|
||||
@@ -2030,7 +2033,8 @@ function transform(contents, compilerOptions) {
|
||||
// Create a compilerHost object to allow the compiler to read and write files
|
||||
var compilerHost = {
|
||||
getSourceFile: function (fileName, target) {
|
||||
return files[fileName] !== undefined ? ts.createSourceFile(fileName, files[fileName], target) : undefined;
|
||||
return files[fileName] !== undefined ?
|
||||
ts.createSourceFile(fileName, files[fileName], target) : undefined;
|
||||
},
|
||||
writeFile: function (name, text, writeByteOrderMark) {
|
||||
outputs.push({ name: name, text: text, writeByteOrderMark: writeByteOrderMark });
|
||||
@@ -2050,7 +2054,8 @@ function transform(contents, compilerOptions) {
|
||||
return {
|
||||
outputs: outputs,
|
||||
errors: errors.map(function (e) {
|
||||
return e.file.fileName + "(" + (e.file.getLineAndCharacterOfPosition(e.start).line + 1) + "): " + ts.flattenDiagnosticMessageText(e.messageText, os.EOL);
|
||||
return e.file.fileName + "(" + (e.file.getLineAndCharacterOfPosition(e.start).line + 1) + "): "
|
||||
+ ts.flattenDiagnosticMessageText(e.messageText, os.EOL);
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1732,10 +1732,18 @@ declare module "typescript" {
|
||||
>condition : Expression
|
||||
>Expression : Expression
|
||||
|
||||
questionToken: Node;
|
||||
>questionToken : Node
|
||||
>Node : Node
|
||||
|
||||
whenTrue: Expression;
|
||||
>whenTrue : Expression
|
||||
>Expression : Expression
|
||||
|
||||
colonToken: Node;
|
||||
>colonToken : Node
|
||||
>Node : Node
|
||||
|
||||
whenFalse: Expression;
|
||||
>whenFalse : Expression
|
||||
>Expression : Expression
|
||||
@@ -1842,6 +1850,10 @@ declare module "typescript" {
|
||||
>expression : LeftHandSideExpression
|
||||
>LeftHandSideExpression : LeftHandSideExpression
|
||||
|
||||
dotToken: Node;
|
||||
>dotToken : Node
|
||||
>Node : Node
|
||||
|
||||
name: Identifier;
|
||||
>name : Identifier
|
||||
>Identifier : Identifier
|
||||
|
||||
@@ -612,7 +612,9 @@ declare module "typescript" {
|
||||
}
|
||||
interface ConditionalExpression extends Expression {
|
||||
condition: Expression;
|
||||
questionToken: Node;
|
||||
whenTrue: Expression;
|
||||
colonToken: Node;
|
||||
whenFalse: Expression;
|
||||
}
|
||||
interface FunctionExpression extends PrimaryExpression, FunctionLikeDeclaration {
|
||||
@@ -649,6 +651,7 @@ declare module "typescript" {
|
||||
}
|
||||
interface PropertyAccessExpression extends MemberExpression {
|
||||
expression: LeftHandSideExpression;
|
||||
dotToken: Node;
|
||||
name: Identifier;
|
||||
}
|
||||
interface ElementAccessExpression extends MemberExpression {
|
||||
@@ -2107,7 +2110,9 @@ function watch(rootFileNames, options) {
|
||||
});
|
||||
}
|
||||
function logErrors(fileName) {
|
||||
var allDiagnostics = services.getCompilerOptionsDiagnostics().concat(services.getSyntacticDiagnostics(fileName)).concat(services.getSemanticDiagnostics(fileName));
|
||||
var allDiagnostics = services.getCompilerOptionsDiagnostics()
|
||||
.concat(services.getSyntacticDiagnostics(fileName))
|
||||
.concat(services.getSemanticDiagnostics(fileName));
|
||||
allDiagnostics.forEach(function (diagnostic) {
|
||||
if (diagnostic.file) {
|
||||
var lineChar = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
||||
@@ -2120,6 +2125,7 @@ function watch(rootFileNames, options) {
|
||||
}
|
||||
}
|
||||
// Initialize files constituting the program as all .ts files in the current directory
|
||||
var currentDirectoryFiles = fs.readdirSync(process.cwd()).filter(function (fileName) { return fileName.length >= 3 && fileName.substr(fileName.length - 3, 3) === ".ts"; });
|
||||
var currentDirectoryFiles = fs.readdirSync(process.cwd()).
|
||||
filter(function (fileName) { return fileName.length >= 3 && fileName.substr(fileName.length - 3, 3) === ".ts"; });
|
||||
// Start the watcher
|
||||
watch(currentDirectoryFiles, { module: 1 /* CommonJS */ });
|
||||
|
||||
@@ -1905,10 +1905,18 @@ declare module "typescript" {
|
||||
>condition : Expression
|
||||
>Expression : Expression
|
||||
|
||||
questionToken: Node;
|
||||
>questionToken : Node
|
||||
>Node : Node
|
||||
|
||||
whenTrue: Expression;
|
||||
>whenTrue : Expression
|
||||
>Expression : Expression
|
||||
|
||||
colonToken: Node;
|
||||
>colonToken : Node
|
||||
>Node : Node
|
||||
|
||||
whenFalse: Expression;
|
||||
>whenFalse : Expression
|
||||
>Expression : Expression
|
||||
@@ -2015,6 +2023,10 @@ declare module "typescript" {
|
||||
>expression : LeftHandSideExpression
|
||||
>LeftHandSideExpression : LeftHandSideExpression
|
||||
|
||||
dotToken: Node;
|
||||
>dotToken : Node
|
||||
>Node : Node
|
||||
|
||||
name: Identifier;
|
||||
>name : Identifier
|
||||
>Identifier : Identifier
|
||||
|
||||
@@ -3,4 +3,5 @@ var x = [].concat([{ a: 1 }], [{ a: 2 }])
|
||||
.map(b => b.a);
|
||||
|
||||
//// [arrayConcatMap.js]
|
||||
var x = [].concat([{ a: 1 }], [{ a: 2 }]).map(function (b) { return b.a; });
|
||||
var x = [].concat([{ a: 1 }], [{ a: 2 }])
|
||||
.map(function (b) { return b.a; });
|
||||
|
||||
@@ -37,9 +37,9 @@ y
|
||||
//// [asiArith.js]
|
||||
var x = 1;
|
||||
var y = 1;
|
||||
var z = x +
|
||||
+ +y;
|
||||
var z = x
|
||||
+ + +y;
|
||||
var a = 1;
|
||||
var b = 1;
|
||||
var c = x -
|
||||
- -y;
|
||||
var c = x
|
||||
- - -y;
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
tests/cases/compiler/conditionalExpressionNewLine1.ts(1,9): error TS2304: Cannot find name 'a'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine1.ts(1,13): error TS2304: Cannot find name 'b'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine1.ts(1,17): error TS2304: Cannot find name 'c'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/conditionalExpressionNewLine1.ts (3 errors) ====
|
||||
var v = a ? b : c;
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'a'.
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'b'.
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'c'.
|
||||
@@ -0,0 +1,5 @@
|
||||
//// [conditionalExpressionNewLine1.ts]
|
||||
var v = a ? b : c;
|
||||
|
||||
//// [conditionalExpressionNewLine1.js]
|
||||
var v = a ? b : c;
|
||||
@@ -0,0 +1,31 @@
|
||||
tests/cases/compiler/conditionalExpressionNewLine10.ts(1,9): error TS2304: Cannot find name 'a'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine10.ts(2,5): error TS2304: Cannot find name 'b'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine10.ts(3,7): error TS2304: Cannot find name 'd'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine10.ts(4,7): error TS2304: Cannot find name 'e'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine10.ts(5,5): error TS2304: Cannot find name 'c'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine10.ts(6,7): error TS2304: Cannot find name 'f'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine10.ts(7,7): error TS2304: Cannot find name 'g'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/conditionalExpressionNewLine10.ts (7 errors) ====
|
||||
var v = a
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'a'.
|
||||
? b
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'b'.
|
||||
? d
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'd'.
|
||||
: e
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'e'.
|
||||
: c
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'c'.
|
||||
? f
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'f'.
|
||||
: g;
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'g'.
|
||||
@@ -0,0 +1,17 @@
|
||||
//// [conditionalExpressionNewLine10.ts]
|
||||
var v = a
|
||||
? b
|
||||
? d
|
||||
: e
|
||||
: c
|
||||
? f
|
||||
: g;
|
||||
|
||||
//// [conditionalExpressionNewLine10.js]
|
||||
var v = a
|
||||
? b
|
||||
? d
|
||||
: e
|
||||
: c
|
||||
? f
|
||||
: g;
|
||||
@@ -0,0 +1,14 @@
|
||||
tests/cases/compiler/conditionalExpressionNewLine2.ts(1,9): error TS2304: Cannot find name 'a'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine2.ts(2,5): error TS2304: Cannot find name 'b'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine2.ts(2,9): error TS2304: Cannot find name 'c'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/conditionalExpressionNewLine2.ts (3 errors) ====
|
||||
var v = a
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'a'.
|
||||
? b : c;
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'b'.
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'c'.
|
||||
@@ -0,0 +1,7 @@
|
||||
//// [conditionalExpressionNewLine2.ts]
|
||||
var v = a
|
||||
? b : c;
|
||||
|
||||
//// [conditionalExpressionNewLine2.js]
|
||||
var v = a
|
||||
? b : c;
|
||||
@@ -0,0 +1,14 @@
|
||||
tests/cases/compiler/conditionalExpressionNewLine3.ts(1,9): error TS2304: Cannot find name 'a'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine3.ts(2,3): error TS2304: Cannot find name 'b'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine3.ts(2,7): error TS2304: Cannot find name 'c'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/conditionalExpressionNewLine3.ts (3 errors) ====
|
||||
var v = a ?
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'a'.
|
||||
b : c;
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'b'.
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'c'.
|
||||
@@ -0,0 +1,7 @@
|
||||
//// [conditionalExpressionNewLine3.ts]
|
||||
var v = a ?
|
||||
b : c;
|
||||
|
||||
//// [conditionalExpressionNewLine3.js]
|
||||
var v = a ?
|
||||
b : c;
|
||||
@@ -0,0 +1,14 @@
|
||||
tests/cases/compiler/conditionalExpressionNewLine4.ts(1,9): error TS2304: Cannot find name 'a'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine4.ts(1,13): error TS2304: Cannot find name 'b'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine4.ts(2,3): error TS2304: Cannot find name 'c'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/conditionalExpressionNewLine4.ts (3 errors) ====
|
||||
var v = a ? b :
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'a'.
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'b'.
|
||||
c;
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'c'.
|
||||
@@ -0,0 +1,7 @@
|
||||
//// [conditionalExpressionNewLine4.ts]
|
||||
var v = a ? b :
|
||||
c;
|
||||
|
||||
//// [conditionalExpressionNewLine4.js]
|
||||
var v = a ? b :
|
||||
c;
|
||||
@@ -0,0 +1,14 @@
|
||||
tests/cases/compiler/conditionalExpressionNewLine5.ts(1,9): error TS2304: Cannot find name 'a'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine5.ts(1,13): error TS2304: Cannot find name 'b'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine5.ts(2,5): error TS2304: Cannot find name 'c'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/conditionalExpressionNewLine5.ts (3 errors) ====
|
||||
var v = a ? b
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'a'.
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'b'.
|
||||
: c;
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'c'.
|
||||
@@ -0,0 +1,7 @@
|
||||
//// [conditionalExpressionNewLine5.ts]
|
||||
var v = a ? b
|
||||
: c;
|
||||
|
||||
//// [conditionalExpressionNewLine5.js]
|
||||
var v = a ? b
|
||||
: c;
|
||||
@@ -0,0 +1,15 @@
|
||||
tests/cases/compiler/conditionalExpressionNewLine6.ts(1,9): error TS2304: Cannot find name 'a'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine6.ts(2,5): error TS2304: Cannot find name 'b'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine6.ts(3,5): error TS2304: Cannot find name 'c'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/conditionalExpressionNewLine6.ts (3 errors) ====
|
||||
var v = a
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'a'.
|
||||
? b
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'b'.
|
||||
: c;
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'c'.
|
||||
@@ -0,0 +1,9 @@
|
||||
//// [conditionalExpressionNewLine6.ts]
|
||||
var v = a
|
||||
? b
|
||||
: c;
|
||||
|
||||
//// [conditionalExpressionNewLine6.js]
|
||||
var v = a
|
||||
? b
|
||||
: c;
|
||||
@@ -0,0 +1,15 @@
|
||||
tests/cases/compiler/conditionalExpressionNewLine7.ts(1,9): error TS2304: Cannot find name 'a'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine7.ts(2,3): error TS2304: Cannot find name 'b'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine7.ts(3,3): error TS2304: Cannot find name 'c'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/conditionalExpressionNewLine7.ts (3 errors) ====
|
||||
var v = a ?
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'a'.
|
||||
b :
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'b'.
|
||||
c;
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'c'.
|
||||
@@ -0,0 +1,9 @@
|
||||
//// [conditionalExpressionNewLine7.ts]
|
||||
var v = a ?
|
||||
b :
|
||||
c;
|
||||
|
||||
//// [conditionalExpressionNewLine7.js]
|
||||
var v = a ?
|
||||
b :
|
||||
c;
|
||||
@@ -0,0 +1,27 @@
|
||||
tests/cases/compiler/conditionalExpressionNewLine8.ts(1,9): error TS2304: Cannot find name 'a'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine8.ts(2,5): error TS2304: Cannot find name 'b'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine8.ts(2,9): error TS2304: Cannot find name 'd'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine8.ts(2,13): error TS2304: Cannot find name 'e'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine8.ts(3,5): error TS2304: Cannot find name 'c'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine8.ts(3,9): error TS2304: Cannot find name 'f'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine8.ts(3,13): error TS2304: Cannot find name 'g'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/conditionalExpressionNewLine8.ts (7 errors) ====
|
||||
var v = a
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'a'.
|
||||
? b ? d : e
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'b'.
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'd'.
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'e'.
|
||||
: c ? f : g;
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'c'.
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'f'.
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'g'.
|
||||
@@ -0,0 +1,9 @@
|
||||
//// [conditionalExpressionNewLine8.ts]
|
||||
var v = a
|
||||
? b ? d : e
|
||||
: c ? f : g;
|
||||
|
||||
//// [conditionalExpressionNewLine8.js]
|
||||
var v = a
|
||||
? b ? d : e
|
||||
: c ? f : g;
|
||||
@@ -0,0 +1,29 @@
|
||||
tests/cases/compiler/conditionalExpressionNewLine9.ts(1,9): error TS2304: Cannot find name 'a'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine9.ts(2,5): error TS2304: Cannot find name 'b'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine9.ts(3,7): error TS2304: Cannot find name 'd'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine9.ts(3,11): error TS2304: Cannot find name 'e'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine9.ts(4,5): error TS2304: Cannot find name 'c'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine9.ts(5,7): error TS2304: Cannot find name 'f'.
|
||||
tests/cases/compiler/conditionalExpressionNewLine9.ts(5,11): error TS2304: Cannot find name 'g'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/conditionalExpressionNewLine9.ts (7 errors) ====
|
||||
var v = a
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'a'.
|
||||
? b
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'b'.
|
||||
? d : e
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'd'.
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'e'.
|
||||
: c
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'c'.
|
||||
? f : g;
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'f'.
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'g'.
|
||||
@@ -0,0 +1,13 @@
|
||||
//// [conditionalExpressionNewLine9.ts]
|
||||
var v = a
|
||||
? b
|
||||
? d : e
|
||||
: c
|
||||
? f : g;
|
||||
|
||||
//// [conditionalExpressionNewLine9.js]
|
||||
var v = a
|
||||
? b
|
||||
? d : e
|
||||
: c
|
||||
? f : g;
|
||||
@@ -314,8 +314,7 @@ var TypeScriptAllInOne;
|
||||
Program.prototype.if = function (retValue) {
|
||||
if (retValue === void 0) { retValue = != 0; }
|
||||
return 1;
|
||||
^
|
||||
retValue;
|
||||
^ retValue;
|
||||
bfs.TYPES();
|
||||
if (retValue != 0) {
|
||||
return 1 &&
|
||||
@@ -500,7 +499,8 @@ var CLASS = (function () {
|
||||
CLASS.prototype.Foo = function () {
|
||||
var myEvent = function () { return 1; };
|
||||
if (myEvent() == 1)
|
||||
return true ? : ;
|
||||
return true ?
|
||||
: ;
|
||||
else
|
||||
return false;
|
||||
};
|
||||
|
||||
@@ -11,5 +11,6 @@ var Position;
|
||||
(function (Position) {
|
||||
Position[Position["IgnoreRulesSpecific"] = 0] = "IgnoreRulesSpecific";
|
||||
})(Position || (Position = {}));
|
||||
var x = IgnoreRulesSpecific.;
|
||||
var x = IgnoreRulesSpecific.
|
||||
;
|
||||
var y = 0 /* IgnoreRulesSpecific */;
|
||||
|
||||
@@ -12,6 +12,7 @@ var Position2;
|
||||
(function (Position2) {
|
||||
Position2[Position2["IgnoreRulesSpecific"] = 0] = "IgnoreRulesSpecific";
|
||||
})(Position2 || (Position2 = {}));
|
||||
var x = IgnoreRulesSpecific.; // error
|
||||
var x = IgnoreRulesSpecific.
|
||||
; // error
|
||||
var y = 1;
|
||||
var z = 0 /* IgnoreRulesSpecific */; // no error
|
||||
|
||||
@@ -228,7 +228,8 @@ var C = (function () {
|
||||
// Not fine, since we can *only* consist of a single throw statement
|
||||
// if no return statements are present but we are a get accessor.
|
||||
throw null;
|
||||
throw undefined.;
|
||||
throw undefined.
|
||||
;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
|
||||
@@ -15,8 +15,9 @@ var s3 = s2.func(num => num.toString())
|
||||
|
||||
|
||||
//// [genericChainedCalls.js]
|
||||
var r1 = v1.func(function (num) { return num.toString(); }).func(function (str) { return str.length; }) // error, number doesn't have a length
|
||||
.func(function (num) { return num.toString(); });
|
||||
var r1 = v1.func(function (num) { return num.toString(); })
|
||||
.func(function (str) { return str.length; }) // error, number doesn't have a length
|
||||
.func(function (num) { return num.toString(); });
|
||||
var s1 = v1.func(function (num) { return num.toString(); });
|
||||
var s2 = s1.func(function (str) { return str.length; }); // should also error
|
||||
var s3 = s2.func(function (num) { return num.toString(); });
|
||||
|
||||
@@ -69,7 +69,10 @@ var TypeScript;
|
||||
};
|
||||
PullTypeSymbol.prototype.getScopedNameEx = function (scopeSymbol, useConstraintInName, getPrettyTypeName, getTypeParamMarkerInfo) {
|
||||
if (this.isArray()) {
|
||||
var elementMemberName = this._elementType ? (this._elementType.isArray() || this._elementType.isNamedTypeSymbol() ? this._elementType.getScopedNameEx(scopeSymbol, false, getPrettyTypeName, getTypeParamMarkerInfo) : this._elementType.getMemberTypeNameEx(false, scopeSymbol, getPrettyTypeName)) : 1;
|
||||
var elementMemberName = this._elementType ?
|
||||
(this._elementType.isArray() || this._elementType.isNamedTypeSymbol() ?
|
||||
this._elementType.getScopedNameEx(scopeSymbol, false, getPrettyTypeName, getTypeParamMarkerInfo) :
|
||||
this._elementType.getMemberTypeNameEx(false, scopeSymbol, getPrettyTypeName)) : 1;
|
||||
return TypeScript.MemberName.create(elementMemberName, "", "[]");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -17,6 +17,6 @@ var r2: I1<number> = v1.func(num => num.toString()) // Correctly returns an I1<s
|
||||
//// [overEagerReturnTypeSpecialization.js]
|
||||
//Note: Below simpler repro
|
||||
var r1 = v1.func(function (num) { return num.toString(); }) // Correctly returns an I1<string>
|
||||
.func(function (str) { return str.length; }); // should error
|
||||
.func(function (str) { return str.length; }); // should error
|
||||
var r2 = v1.func(function (num) { return num.toString(); }) // Correctly returns an I1<string>
|
||||
.func(function (str) { return str.length; }); // should be ok
|
||||
.func(function (str) { return str.length; }); // should be ok
|
||||
|
||||
@@ -43,7 +43,9 @@ var Bugs;
|
||||
rest[_i - 1] = arguments[_i];
|
||||
}
|
||||
var index = rest[0];
|
||||
return typeof args[index] !== 'undefined' ? args[index] : match;
|
||||
return typeof args[index] !== 'undefined'
|
||||
? args[index]
|
||||
: match;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -8,5 +8,6 @@ function foo() {
|
||||
//// [parse1.js]
|
||||
var bar = 42;
|
||||
function foo() {
|
||||
bar.;
|
||||
bar.
|
||||
;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,8 @@ var Foo = (function () {
|
||||
function Foo() {
|
||||
}
|
||||
Foo.prototype.f1 = function () {
|
||||
if (this.)
|
||||
if (this.
|
||||
)
|
||||
;
|
||||
};
|
||||
Foo.prototype.f2 = function () {
|
||||
|
||||
@@ -5,5 +5,5 @@
|
||||
2;
|
||||
|
||||
//// [parserGreaterThanTokenAmbiguity10.js]
|
||||
1 >>>
|
||||
2;
|
||||
1
|
||||
>>> 2;
|
||||
|
||||
@@ -5,5 +5,5 @@
|
||||
2;
|
||||
|
||||
//// [parserGreaterThanTokenAmbiguity15.js]
|
||||
1 >>=
|
||||
2;
|
||||
1
|
||||
>>= 2;
|
||||
|
||||
@@ -5,5 +5,5 @@
|
||||
2;
|
||||
|
||||
//// [parserGreaterThanTokenAmbiguity20.js]
|
||||
1 >>>=
|
||||
2;
|
||||
1
|
||||
>>>= 2;
|
||||
|
||||
@@ -4,4 +4,4 @@
|
||||
|
||||
//// [parserGreaterThanTokenAmbiguity4.js]
|
||||
1 >
|
||||
> 2;
|
||||
> 2;
|
||||
|
||||
@@ -5,5 +5,5 @@
|
||||
2;
|
||||
|
||||
//// [parserGreaterThanTokenAmbiguity5.js]
|
||||
1 >>
|
||||
2;
|
||||
1
|
||||
>> 2;
|
||||
|
||||
@@ -4,4 +4,4 @@
|
||||
|
||||
//// [parserGreaterThanTokenAmbiguity9.js]
|
||||
1 >>
|
||||
> 2;
|
||||
> 2;
|
||||
|
||||
@@ -3,4 +3,5 @@
|
||||
/notregexp/a.foo();
|
||||
|
||||
//// [parserRegularExpressionDivideAmbiguity1.js]
|
||||
1 / notregexp / a.foo();
|
||||
1
|
||||
/ notregexp / a.foo();
|
||||
|
||||
@@ -39,7 +39,11 @@ var CharacterInfo = (function () {
|
||||
};
|
||||
CharacterInfo.hexValue = function (c) {
|
||||
Debug.assert(isHexDigit(c));
|
||||
return isDecimalDigit(c) ? (c - CharacterCodes._0) : (c >= CharacterCodes.A && c <= CharacterCodes.F) ? c - CharacterCodes.A + 10 : c - CharacterCodes.a + 10;
|
||||
return isDecimalDigit(c)
|
||||
? (c - CharacterCodes._0)
|
||||
: (c >= CharacterCodes.A && c <= CharacterCodes.F)
|
||||
? c - CharacterCodes.A + 10
|
||||
: c - CharacterCodes.a + 10;
|
||||
};
|
||||
return CharacterInfo;
|
||||
})();
|
||||
|
||||
@@ -105,74 +105,92 @@ function foo12(x: number | string | boolean) {
|
||||
// the type of a variable or parameter is narrowed by any type guard in the condition when false,
|
||||
// provided the false expression contains no assignments to the variable or parameter.
|
||||
function foo(x) {
|
||||
return typeof x === "string" ? x.length // string
|
||||
: x++; // number
|
||||
return typeof x === "string"
|
||||
? x.length // string
|
||||
: x++; // number
|
||||
}
|
||||
function foo2(x) {
|
||||
// x is assigned in the if true branch, the type is not narrowed
|
||||
return typeof x === "string" ? (x = 10 && x) // string | number
|
||||
: x; // string | number
|
||||
return typeof x === "string"
|
||||
? (x = 10 && x) // string | number
|
||||
: x; // string | number
|
||||
}
|
||||
function foo3(x) {
|
||||
// x is assigned in the if false branch, the type is not narrowed
|
||||
// even though assigned using same type as narrowed expression
|
||||
return typeof x === "string" ? (x = "Hello" && x) // string | number
|
||||
: x; // string | number
|
||||
return typeof x === "string"
|
||||
? (x = "Hello" && x) // string | number
|
||||
: x; // string | number
|
||||
}
|
||||
function foo4(x) {
|
||||
// false branch updates the variable - so here it is not number
|
||||
// even though assigned using same type as narrowed expression
|
||||
return typeof x === "string" ? x // string | number
|
||||
: (x = 10 && x); // string | number
|
||||
return typeof x === "string"
|
||||
? x // string | number
|
||||
: (x = 10 && x); // string | number
|
||||
}
|
||||
function foo5(x) {
|
||||
// false branch updates the variable - so here it is not number
|
||||
return typeof x === "string" ? x // string | number
|
||||
: (x = "hello" && x); // string | number
|
||||
return typeof x === "string"
|
||||
? x // string | number
|
||||
: (x = "hello" && x); // string | number
|
||||
}
|
||||
function foo6(x) {
|
||||
// Modify in both branches
|
||||
return typeof x === "string" ? (x = 10 && x) // string | number
|
||||
: (x = "hello" && x); // string | number
|
||||
return typeof x === "string"
|
||||
? (x = 10 && x) // string | number
|
||||
: (x = "hello" && x); // string | number
|
||||
}
|
||||
function foo7(x) {
|
||||
return typeof x === "string" ? x === "hello" // string
|
||||
: typeof x === "boolean" ? x // boolean
|
||||
: x == 10; // number
|
||||
return typeof x === "string"
|
||||
? x === "hello" // string
|
||||
: typeof x === "boolean"
|
||||
? x // boolean
|
||||
: x == 10; // number
|
||||
}
|
||||
function foo8(x) {
|
||||
var b;
|
||||
return typeof x === "string" ? x === "hello" : ((b = x) &&
|
||||
(typeof x === "boolean" ? x // boolean
|
||||
: x == 10)); // number
|
||||
return typeof x === "string"
|
||||
? x === "hello"
|
||||
: ((b = x) &&
|
||||
(typeof x === "boolean"
|
||||
? x // boolean
|
||||
: x == 10)); // number
|
||||
}
|
||||
function foo9(x) {
|
||||
var y = 10;
|
||||
// usage of x or assignment to separate variable shouldn't cause narrowing of type to stop
|
||||
return typeof x === "string" ? ((y = x.length) && x === "hello") // string
|
||||
: x === 10; // number
|
||||
return typeof x === "string"
|
||||
? ((y = x.length) && x === "hello") // string
|
||||
: x === 10; // number
|
||||
}
|
||||
function foo10(x) {
|
||||
// Mixing typeguards
|
||||
var b;
|
||||
return typeof x === "string" ? x // string
|
||||
: ((b = x) // x is number | boolean
|
||||
&& typeof x === "number" && x.toString()); // x is number
|
||||
return typeof x === "string"
|
||||
? x // string
|
||||
: ((b = x) // x is number | boolean
|
||||
&& typeof x === "number"
|
||||
&& x.toString()); // x is number
|
||||
}
|
||||
function foo11(x) {
|
||||
// Mixing typeguards
|
||||
// Assigning value to x deep inside another guard stops narrowing of type too
|
||||
var b;
|
||||
return typeof x === "string" ? x // number | boolean | string - changed in the false branch
|
||||
: ((b = x) // x is number | boolean | string - because the assignment changed it
|
||||
&& typeof x === "number" && (x = 10) // assignment to x
|
||||
&& x); // x is number | boolean | string
|
||||
return typeof x === "string"
|
||||
? x // number | boolean | string - changed in the false branch
|
||||
: ((b = x) // x is number | boolean | string - because the assignment changed it
|
||||
&& typeof x === "number"
|
||||
&& (x = 10) // assignment to x
|
||||
&& x); // x is number | boolean | string
|
||||
}
|
||||
function foo12(x) {
|
||||
// Mixing typeguards
|
||||
// Assigning value to x in outer guard shouldn't stop narrowing in the inner expression
|
||||
var b;
|
||||
return typeof x === "string" ? (x = 10 && x.toString().length) // number | boolean | string - changed here
|
||||
: ((b = x) // x is number | boolean | string - changed in true branch
|
||||
&& typeof x === "number" && x); // x is number
|
||||
return typeof x === "string"
|
||||
? (x = 10 && x.toString().length) // number | boolean | string - changed here
|
||||
: ((b = x) // x is number | boolean | string - changed in true branch
|
||||
&& typeof x === "number"
|
||||
&& x); // x is number
|
||||
}
|
||||
|
||||
@@ -82,32 +82,44 @@ module m1 {
|
||||
//// [typeGuardsInFunctionAndModuleBlock.js]
|
||||
// typeguards are scoped in function/module block
|
||||
function foo(x) {
|
||||
return typeof x === "string" ? x : function f() {
|
||||
var b = x; // number | boolean
|
||||
return typeof x === "boolean" ? x.toString() // boolean
|
||||
: x.toString(); // number
|
||||
}();
|
||||
return typeof x === "string"
|
||||
? x
|
||||
: function f() {
|
||||
var b = x; // number | boolean
|
||||
return typeof x === "boolean"
|
||||
? x.toString() // boolean
|
||||
: x.toString(); // number
|
||||
}();
|
||||
}
|
||||
function foo2(x) {
|
||||
return typeof x === "string" ? x : function f(a) {
|
||||
var b = x; // new scope - number | boolean
|
||||
return typeof x === "boolean" ? x.toString() // boolean
|
||||
: x.toString(); // number
|
||||
}(x); // x here is narrowed to number | boolean
|
||||
return typeof x === "string"
|
||||
? x
|
||||
: function f(a) {
|
||||
var b = x; // new scope - number | boolean
|
||||
return typeof x === "boolean"
|
||||
? x.toString() // boolean
|
||||
: x.toString(); // number
|
||||
}(x); // x here is narrowed to number | boolean
|
||||
}
|
||||
function foo3(x) {
|
||||
return typeof x === "string" ? x : (function () {
|
||||
var b = x; // new scope - number | boolean
|
||||
return typeof x === "boolean" ? x.toString() // boolean
|
||||
: x.toString(); // number
|
||||
})();
|
||||
return typeof x === "string"
|
||||
? x
|
||||
: (function () {
|
||||
var b = x; // new scope - number | boolean
|
||||
return typeof x === "boolean"
|
||||
? x.toString() // boolean
|
||||
: x.toString(); // number
|
||||
})();
|
||||
}
|
||||
function foo4(x) {
|
||||
return typeof x === "string" ? x : (function (a) {
|
||||
var b = x; // new scope - number | boolean
|
||||
return typeof x === "boolean" ? x.toString() // boolean
|
||||
: x.toString(); // number
|
||||
})(x); // x here is narrowed to number | boolean
|
||||
return typeof x === "string"
|
||||
? x
|
||||
: (function (a) {
|
||||
var b = x; // new scope - number | boolean
|
||||
return typeof x === "boolean"
|
||||
? x.toString() // boolean
|
||||
: x.toString(); // number
|
||||
})(x); // x here is narrowed to number | boolean
|
||||
}
|
||||
// Type guards affect nested function expressions, but not nested function declarations
|
||||
function foo5(x) {
|
||||
@@ -129,8 +141,9 @@ var m;
|
||||
y = x; // string;
|
||||
}
|
||||
else {
|
||||
y = typeof x === "boolean" ? x.toString() // boolean
|
||||
: x.toString(); // number
|
||||
y = typeof x === "boolean"
|
||||
? x.toString() // boolean
|
||||
: x.toString(); // number
|
||||
}
|
||||
})(m2 || (m2 = {}));
|
||||
})(m || (m = {}));
|
||||
@@ -147,8 +160,9 @@ var m1;
|
||||
y = x; // string;
|
||||
}
|
||||
else {
|
||||
y = typeof x === "boolean" ? x.toString() // boolean
|
||||
: x.toString(); // number
|
||||
y = typeof x === "boolean"
|
||||
? x.toString() // boolean
|
||||
: x.toString(); // number
|
||||
}
|
||||
})(m3 = m2.m3 || (m2.m3 = {}));
|
||||
})(m2 || (m2 = {}));
|
||||
|
||||
@@ -258,8 +258,9 @@ function foo10(x) {
|
||||
else {
|
||||
var y;
|
||||
var b = x; // number | boolean
|
||||
return typeof x === "number" ? x === 10 // number
|
||||
: x; // x should be boolean
|
||||
return typeof x === "number"
|
||||
? x === 10 // number
|
||||
: x; // x should be boolean
|
||||
}
|
||||
}
|
||||
function foo11(x) {
|
||||
@@ -271,13 +272,15 @@ function foo11(x) {
|
||||
else {
|
||||
var y;
|
||||
var b = x; // number | boolean | string - because below we are changing value of x in if statement
|
||||
return typeof x === "number" ? (
|
||||
// change value of x
|
||||
x = 10 && x.toString() // number | boolean | string
|
||||
) : (
|
||||
// do not change value
|
||||
y = x && x.toString() // number | boolean | string
|
||||
);
|
||||
return typeof x === "number"
|
||||
? (
|
||||
// change value of x
|
||||
x = 10 && x.toString() // number | boolean | string
|
||||
)
|
||||
: (
|
||||
// do not change value
|
||||
y = x && x.toString() // number | boolean | string
|
||||
);
|
||||
}
|
||||
}
|
||||
function foo12(x) {
|
||||
@@ -289,7 +292,8 @@ function foo12(x) {
|
||||
else {
|
||||
x = 10;
|
||||
var b = x; // number | boolean | string
|
||||
return typeof x === "number" ? x.toString() // number
|
||||
: x.toString(); // boolean | string
|
||||
return typeof x === "number"
|
||||
? x.toString() // number
|
||||
: x.toString(); // boolean | string
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,36 +72,40 @@ function foo3(x) {
|
||||
}
|
||||
function foo4(x) {
|
||||
return typeof x !== "string" // string | number | boolean
|
||||
&& typeof x !== "number" // number | boolean
|
||||
&& x; // boolean
|
||||
&& typeof x !== "number" // number | boolean
|
||||
&& x; // boolean
|
||||
}
|
||||
function foo5(x) {
|
||||
// usage of x or assignment to separate variable shouldn't cause narrowing of type to stop
|
||||
var b;
|
||||
return typeof x !== "string" // string | number | boolean
|
||||
&& ((b = x) && (typeof x !== "number" // number | boolean
|
||||
&& x)); // boolean
|
||||
&& ((b = x) && (typeof x !== "number" // number | boolean
|
||||
&& x)); // boolean
|
||||
}
|
||||
function foo6(x) {
|
||||
// Mixing typeguard narrowing in if statement with conditional expression typeguard
|
||||
return typeof x !== "string" // string | number | boolean
|
||||
&& (typeof x !== "number" // number | boolean
|
||||
? x // boolean
|
||||
: x === 10); // number
|
||||
&& (typeof x !== "number" // number | boolean
|
||||
? x // boolean
|
||||
: x === 10); // number
|
||||
}
|
||||
function foo7(x) {
|
||||
var y;
|
||||
var z;
|
||||
// Mixing typeguard narrowing
|
||||
// Assigning value to x deep inside another guard stops narrowing of type too
|
||||
return typeof x !== "string" && ((z = x) // string | number | boolean - x changed deeper in conditional expression
|
||||
&& (typeof x === "number" ? (x = 10 && x.toString()) // number | boolean | string
|
||||
: (y = x && x.toString()))); // number | boolean | string
|
||||
return typeof x !== "string"
|
||||
&& ((z = x) // string | number | boolean - x changed deeper in conditional expression
|
||||
&& (typeof x === "number"
|
||||
? (x = 10 && x.toString()) // number | boolean | string
|
||||
: (y = x && x.toString()))); // number | boolean | string
|
||||
}
|
||||
function foo8(x) {
|
||||
// Mixing typeguard
|
||||
// Assigning value to x in outer guard shouldn't stop narrowing in the inner expression
|
||||
return typeof x !== "string" && (x = 10) // change x - number| string
|
||||
&& (typeof x === "number" ? x // number
|
||||
: x.length); // string
|
||||
return typeof x !== "string"
|
||||
&& (x = 10) // change x - number| string
|
||||
&& (typeof x === "number"
|
||||
? x // number
|
||||
: x.length); // string
|
||||
}
|
||||
|
||||
@@ -72,36 +72,40 @@ function foo3(x) {
|
||||
}
|
||||
function foo4(x) {
|
||||
return typeof x === "string" // string | number | boolean
|
||||
|| typeof x === "number" // number | boolean
|
||||
|| x; // boolean
|
||||
|| typeof x === "number" // number | boolean
|
||||
|| x; // boolean
|
||||
}
|
||||
function foo5(x) {
|
||||
// usage of x or assignment to separate variable shouldn't cause narrowing of type to stop
|
||||
var b;
|
||||
return typeof x === "string" // string | number | boolean
|
||||
|| ((b = x) || (typeof x === "number" // number | boolean
|
||||
|| x)); // boolean
|
||||
|| ((b = x) || (typeof x === "number" // number | boolean
|
||||
|| x)); // boolean
|
||||
}
|
||||
function foo6(x) {
|
||||
// Mixing typeguard
|
||||
return typeof x === "string" // string | number | boolean
|
||||
|| (typeof x !== "number" // number | boolean
|
||||
? x // boolean
|
||||
: x === 10); // number
|
||||
|| (typeof x !== "number" // number | boolean
|
||||
? x // boolean
|
||||
: x === 10); // number
|
||||
}
|
||||
function foo7(x) {
|
||||
var y;
|
||||
var z;
|
||||
// Mixing typeguard narrowing
|
||||
// Assigning value to x deep inside another guard stops narrowing of type too
|
||||
return typeof x === "string" || ((z = x) // string | number | boolean - x changed deeper in conditional expression
|
||||
|| (typeof x === "number" ? (x = 10 && x.toString()) // number | boolean | string
|
||||
: (y = x && x.toString()))); // number | boolean | string
|
||||
return typeof x === "string"
|
||||
|| ((z = x) // string | number | boolean - x changed deeper in conditional expression
|
||||
|| (typeof x === "number"
|
||||
? (x = 10 && x.toString()) // number | boolean | string
|
||||
: (y = x && x.toString()))); // number | boolean | string
|
||||
}
|
||||
function foo8(x) {
|
||||
// Mixing typeguard
|
||||
// Assigning value to x in outer guard shouldn't stop narrowing in the inner expression
|
||||
return typeof x === "string" || (x = 10) // change x - number| string
|
||||
|| (typeof x === "number" ? x // number
|
||||
: x.length); // string
|
||||
return typeof x === "string"
|
||||
|| (x = 10) // change x - number| string
|
||||
|| (typeof x === "number"
|
||||
? x // number
|
||||
: x.length); // string
|
||||
}
|
||||
|
||||
@@ -1018,7 +1018,11 @@ _.omit({ name: 'moe', age: 50, userid: 'moe1' }, 'userid');
|
||||
var iceCream = { flavor: "chocolate" };
|
||||
_.defaults(iceCream, { flavor: "vanilla", sprinkles: "lots" });
|
||||
_.clone({ name: 'moe' });
|
||||
_.chain([1, 2, 3, 200]).filter(function (num) { return num % 2 == 0; }).tap(alert).map(function (num) { return num * num; }).value();
|
||||
_.chain([1, 2, 3, 200])
|
||||
.filter(function (num) { return num % 2 == 0; })
|
||||
.tap(alert)
|
||||
.map(function (num) { return num * num; })
|
||||
.value();
|
||||
_.has({ a: 1, b: 2, c: 3 }, "b");
|
||||
var moe = { name: 'moe', luckyNumbers: [13, 27, 34] };
|
||||
var clone = { name: 'moe', luckyNumbers: [13, 27, 34] };
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
//// [wrappedIncovations1.ts]
|
||||
var v = this
|
||||
.foo()
|
||||
.bar()
|
||||
.baz();
|
||||
|
||||
//// [wrappedIncovations1.js]
|
||||
var v = this
|
||||
.foo()
|
||||
.bar()
|
||||
.baz();
|
||||
@@ -0,0 +1,20 @@
|
||||
=== tests/cases/compiler/wrappedIncovations1.ts ===
|
||||
var v = this
|
||||
>v : any
|
||||
>this .foo() .bar() .baz() : any
|
||||
>this .foo() .bar() .baz : any
|
||||
>this .foo() .bar() : any
|
||||
>this .foo() .bar : any
|
||||
>this .foo() : any
|
||||
>this .foo : any
|
||||
>this : any
|
||||
|
||||
.foo()
|
||||
>foo : any
|
||||
|
||||
.bar()
|
||||
>bar : any
|
||||
|
||||
.baz();
|
||||
>baz : any
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
//// [wrappedIncovations2.ts]
|
||||
var v = this.
|
||||
foo().
|
||||
bar().
|
||||
baz();
|
||||
|
||||
//// [wrappedIncovations2.js]
|
||||
var v = this.
|
||||
foo().
|
||||
bar().
|
||||
baz();
|
||||
@@ -0,0 +1,20 @@
|
||||
=== tests/cases/compiler/wrappedIncovations2.ts ===
|
||||
var v = this.
|
||||
>v : any
|
||||
>this. foo(). bar(). baz() : any
|
||||
>this. foo(). bar(). baz : any
|
||||
>this. foo(). bar() : any
|
||||
>this. foo(). bar : any
|
||||
>this. foo() : any
|
||||
>this. foo : any
|
||||
>this : any
|
||||
|
||||
foo().
|
||||
>foo : any
|
||||
|
||||
bar().
|
||||
>bar : any
|
||||
|
||||
baz();
|
||||
>baz : any
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
var v = a ? b : c;
|
||||
@@ -0,0 +1,7 @@
|
||||
var v = a
|
||||
? b
|
||||
? d
|
||||
: e
|
||||
: c
|
||||
? f
|
||||
: g;
|
||||
@@ -0,0 +1,2 @@
|
||||
var v = a
|
||||
? b : c;
|
||||
@@ -0,0 +1,2 @@
|
||||
var v = a ?
|
||||
b : c;
|
||||
@@ -0,0 +1,2 @@
|
||||
var v = a ? b :
|
||||
c;
|
||||
@@ -0,0 +1,2 @@
|
||||
var v = a ? b
|
||||
: c;
|
||||
@@ -0,0 +1,3 @@
|
||||
var v = a
|
||||
? b
|
||||
: c;
|
||||
@@ -0,0 +1,3 @@
|
||||
var v = a ?
|
||||
b :
|
||||
c;
|
||||
@@ -0,0 +1,3 @@
|
||||
var v = a
|
||||
? b ? d : e
|
||||
: c ? f : g;
|
||||
@@ -0,0 +1,5 @@
|
||||
var v = a
|
||||
? b
|
||||
? d : e
|
||||
: c
|
||||
? f : g;
|
||||
@@ -0,0 +1,4 @@
|
||||
var v = this
|
||||
.foo()
|
||||
.bar()
|
||||
.baz();
|
||||
@@ -0,0 +1,4 @@
|
||||
var v = this.
|
||||
foo().
|
||||
bar().
|
||||
baz();
|
||||
@@ -664,7 +664,7 @@ module m3 { }\
|
||||
var oldText = ScriptSnapshot.fromString(source);
|
||||
var newTextAndChange = withInsert(oldText, 0, "");
|
||||
|
||||
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 7);
|
||||
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 8);
|
||||
});
|
||||
|
||||
it('Class to interface',() => {
|
||||
|
||||
Reference in New Issue
Block a user