Better error recovery for when an arrow function is missing a curly brace.
Also better identification of arrow function expressions.
This commit is contained in:
Родитель
1abedc30c4
Коммит
819ea95953
|
@ -293,6 +293,12 @@ module ts {
|
|||
Count // Number of parsing contexts
|
||||
}
|
||||
|
||||
enum Tristate {
|
||||
False,
|
||||
True,
|
||||
Maybe
|
||||
}
|
||||
|
||||
function parsingContextErrors(context: ParsingContext): DiagnosticMessage {
|
||||
switch (context) {
|
||||
case ParsingContext.SourceElements: return Diagnostics.Declaration_or_statement_expected;
|
||||
|
@ -1256,6 +1262,11 @@ module ts {
|
|||
}
|
||||
}
|
||||
|
||||
function isExpressionStatement(): boolean {
|
||||
// As per the gramar, neither { nor 'function' can start an expression statement.
|
||||
return token !== SyntaxKind.OpenBraceToken && token !== SyntaxKind.FunctionKeyword && isExpression();
|
||||
}
|
||||
|
||||
function parseExpression(noIn?: boolean): Expression {
|
||||
var expr = parseAssignmentExpression(noIn);
|
||||
while (parseOptional(SyntaxKind.CommaToken)) {
|
||||
|
@ -1399,33 +1410,42 @@ module ts {
|
|||
function tryParseParenthesizedArrowFunctionExpression(): Expression {
|
||||
var pos = getNodePos();
|
||||
|
||||
// Note isParenthesizedArrowFunctionExpression returns true, false or undefined.
|
||||
var triState = isParenthesizedArrowFunctionExpression();
|
||||
if (triState !== false) {
|
||||
// If we *definitely* had an arrow function expression, then just parse one out.
|
||||
// Otherwise we *maybe* had an arrow function and we need to *try* to parse it out
|
||||
// (which will ensure we rollback if we fail).
|
||||
var sig = triState === true
|
||||
? parseSignatureAndArrow()
|
||||
: tryParse(parseSignatureAndArrow);
|
||||
|
||||
// If we got a signature, we're good to go. consume the rest of this arrow function.
|
||||
if (sig) {
|
||||
return parseArrowExpressionTail(pos, sig, /*noIn:*/ false);
|
||||
}
|
||||
if (triState === Tristate.False) {
|
||||
// Was not a parenthesized arrow function.
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Was not a parenthesized arrow function.
|
||||
return undefined;
|
||||
// If we *definitely* had an arrow function expression, then just parse one out.
|
||||
if (triState === Tristate.True) {
|
||||
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken);
|
||||
|
||||
// If we have an arrow, then try to parse the body.
|
||||
if (parseExpected(SyntaxKind.EqualsGreaterThanToken)) {
|
||||
return parseArrowExpressionTail(pos, sig, /*noIn:*/ false);
|
||||
}
|
||||
// If not, we're probably better off bailing out and returning a bogus function expression.
|
||||
else {
|
||||
return makeFunctionExpression(SyntaxKind.ArrowFunction, pos, undefined, sig, createMissingNode());
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, *maybe* had an arrow function and we need to *try* to parse it out
|
||||
// (which will ensure we rollback if we fail).
|
||||
var sig = tryParse(parseSignatureAndArrow);
|
||||
if (sig === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
else {
|
||||
return parseArrowExpressionTail(pos, sig, /*noIn:*/ false);
|
||||
}
|
||||
}
|
||||
|
||||
// Note: this function returns a tristate:
|
||||
//
|
||||
// true -> there is definitely a parenthesized arrow function here.
|
||||
// false -> there is definitely *not* a parenthesized arrow function here.
|
||||
// undefined -> there *might* be a parenthesized arrow function here. Speculatively
|
||||
// look ahead to be sure.
|
||||
function isParenthesizedArrowFunctionExpression(): boolean {
|
||||
// True -> There is definitely a parenthesized arrow function here.
|
||||
// False -> There is definitely *not* a parenthesized arrow function here.
|
||||
// Maybe -> There *might* be a parenthesized arrow function here.
|
||||
// Speculatively look ahead to be sure.
|
||||
function isParenthesizedArrowFunctionExpression(): Tristate {
|
||||
if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) {
|
||||
return lookAhead(() => {
|
||||
var first = token;
|
||||
|
@ -1436,7 +1456,7 @@ module ts {
|
|||
// that this must be an arrow function. Note, this may be too aggressive
|
||||
// for the "()" case. It's not uncommon for this to appear while editing
|
||||
// code. We should look to see if there's actually a => before proceeding.
|
||||
return true;
|
||||
return Tristate.True;
|
||||
}
|
||||
|
||||
if (!isIdentifier()) {
|
||||
|
@ -1444,31 +1464,30 @@ module ts {
|
|||
// look like a lambda. Note: we could be a little more lenient and allow
|
||||
// (public or (private. These would not ever actually be allowed,
|
||||
// but we could provide a good error message instead of bailing out.
|
||||
return false;
|
||||
return Tristate.False;
|
||||
}
|
||||
|
||||
// This *could* be a parenthesized arrow function. Return 'undefined' to let
|
||||
// the caller know.
|
||||
return undefined;
|
||||
return Tristate.Maybe;
|
||||
}
|
||||
else {
|
||||
Debug.assert(first === SyntaxKind.LessThanToken);
|
||||
|
||||
// If we have "<" not followed by an identifier, then this definitely is not
|
||||
// an arrow function.
|
||||
// If we have "<" not followed by an identifier,
|
||||
// then this definitely is not an arrow function.
|
||||
if (!isIdentifier()) {
|
||||
return false;
|
||||
return Tristate.False;
|
||||
}
|
||||
|
||||
// This *could* be a parenthesized arrow function. Return 'undefined' to let
|
||||
// the caller know.
|
||||
return undefined;
|
||||
// This *could* be a parenthesized arrow function.
|
||||
return Tristate.Maybe;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Definitely not a parenthesized arrow function.
|
||||
return false;
|
||||
return Tristate.False;
|
||||
}
|
||||
|
||||
function parseSignatureAndArrow(): ParsedSignature {
|
||||
|
@ -1478,7 +1497,28 @@ module ts {
|
|||
}
|
||||
|
||||
function parseArrowExpressionTail(pos: number, sig: ParsedSignature, noIn: boolean): FunctionExpression {
|
||||
var body = token === SyntaxKind.OpenBraceToken ? parseBody() : parseAssignmentExpression(noIn);
|
||||
var body: Expression;
|
||||
|
||||
if (token === SyntaxKind.OpenBraceToken) {
|
||||
body = parseBody(/* ignoreMissingOpenBrace */ false)
|
||||
}
|
||||
// We didn't have a block. However, we may be in an error situation. For example,
|
||||
// if the user wrote:
|
||||
//
|
||||
// a =>
|
||||
// var v = 0;
|
||||
// }
|
||||
//
|
||||
// (i.e. they're missing the open brace). Check to see if that's the case so we can
|
||||
// try to recover better. If we don't do this, then the next close curly we see may end
|
||||
// up preemptively closing the containing construct.
|
||||
else if (isStatement(/* inErrorRecovery */ true) && !isExpressionStatement() && token !== SyntaxKind.FunctionKeyword) {
|
||||
body = parseBody(/* ignoreMissingOpenBrace */ true);
|
||||
}
|
||||
else {
|
||||
body = parseAssignmentExpression(noIn);
|
||||
}
|
||||
|
||||
return makeFunctionExpression(SyntaxKind.ArrowFunction, pos, undefined, sig, body);
|
||||
}
|
||||
|
||||
|
@ -1755,8 +1795,8 @@ module ts {
|
|||
node.name = parsePropertyName();
|
||||
if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) {
|
||||
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken);
|
||||
var body = parseBody();
|
||||
node.initializer = makeFunctionExpression(SyntaxKind.FunctionExpression, node.pos, undefined, sig, body);
|
||||
var body = parseBody(/* ignoreMissingOpenBrace */ false);
|
||||
node.initializer = makeFunctionExpression(SyntaxKind.FunctionExpression, node.pos, node.name, sig, body);
|
||||
}
|
||||
else {
|
||||
parseExpected(SyntaxKind.ColonToken);
|
||||
|
@ -1789,7 +1829,7 @@ module ts {
|
|||
parseExpected(SyntaxKind.FunctionKeyword);
|
||||
var name = isIdentifier() ? parseIdentifier() : undefined;
|
||||
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken);
|
||||
var body = parseBody();
|
||||
var body = parseBody(/* ignoreMissingOpenBrace */ false);
|
||||
return makeFunctionExpression(SyntaxKind.FunctionExpression, pos, name, sig, body);
|
||||
}
|
||||
|
||||
|
@ -1816,9 +1856,9 @@ module ts {
|
|||
|
||||
// STATEMENTS
|
||||
|
||||
function parseBlock(): Block {
|
||||
function parseBlock(ignoreMissingOpenBrace: boolean): Block {
|
||||
var node = <Block>createNode(SyntaxKind.Block);
|
||||
if (parseExpected(SyntaxKind.OpenBraceToken)) {
|
||||
if (parseExpected(SyntaxKind.OpenBraceToken) || ignoreMissingOpenBrace) {
|
||||
node.statements = parseList(ParsingContext.BlockStatements, parseStatement);
|
||||
parseExpected(SyntaxKind.CloseBraceToken);
|
||||
}
|
||||
|
@ -1828,8 +1868,8 @@ module ts {
|
|||
return finishNode(node);
|
||||
}
|
||||
|
||||
function parseBody(): Block {
|
||||
var block = parseBlock();
|
||||
function parseBody(ignoreMissingOpenBrace: boolean): Block {
|
||||
var block = parseBlock(ignoreMissingOpenBrace);
|
||||
block.kind = SyntaxKind.FunctionBlock;
|
||||
return block;
|
||||
}
|
||||
|
@ -2016,7 +2056,7 @@ module ts {
|
|||
function parseTokenAndBlock(token: SyntaxKind, kind: SyntaxKind): Block {
|
||||
var pos = getNodePos();
|
||||
parseExpected(token);
|
||||
var result = parseBlock();
|
||||
var result = parseBlock(/* ignoreMissingOpenBrace */ false);
|
||||
result.kind = kind;
|
||||
result.pos = pos;
|
||||
return result;
|
||||
|
@ -2031,7 +2071,7 @@ module ts {
|
|||
var typeAnnotationColonLength = scanner.getTextPos() - typeAnnotationColonStart;
|
||||
var typeAnnotation = parseTypeAnnotation();
|
||||
parseExpected(SyntaxKind.CloseParenToken);
|
||||
var result = <CatchBlock>parseBlock();
|
||||
var result = <CatchBlock>parseBlock(/* ignoreMissingOpenBrace */ false);
|
||||
result.kind = SyntaxKind.CatchBlock;
|
||||
result.pos = pos;
|
||||
result.variable = variable;
|
||||
|
@ -2108,14 +2148,10 @@ module ts {
|
|||
}
|
||||
}
|
||||
|
||||
function isStatementOrFunction(inErrorRecovery: boolean): boolean {
|
||||
return token === SyntaxKind.FunctionKeyword || isStatement(inErrorRecovery);
|
||||
}
|
||||
|
||||
function parseStatement(): Statement {
|
||||
switch (token) {
|
||||
case SyntaxKind.OpenBraceToken:
|
||||
return parseBlock();
|
||||
return parseBlock(/* ignoreMissingOpenBrace */ false);
|
||||
case SyntaxKind.VarKeyword:
|
||||
return parseVariableStatement();
|
||||
case SyntaxKind.FunctionKeyword:
|
||||
|
@ -2162,7 +2198,7 @@ module ts {
|
|||
var initialPosition = scanner.getTokenPos();
|
||||
var errorCountBeforeBody = file.syntacticErrors.length;
|
||||
if (token === SyntaxKind.OpenBraceToken) {
|
||||
var body = parseBody();
|
||||
var body = parseBody(/* ignoreMissingOpenBrace */ false);
|
||||
if (body && inAmbientContext && file.syntacticErrors.length === errorCountBeforeBody) {
|
||||
var diagnostic = isConstructor ? Diagnostics.A_constructor_implementation_cannot_be_declared_in_an_ambient_context : Diagnostics.A_function_implementation_cannot_be_declared_in_an_ambient_context;
|
||||
grammarErrorAtPos(initialPosition, 1, diagnostic);
|
||||
|
@ -2334,7 +2370,7 @@ module ts {
|
|||
node.typeParameters = sig.typeParameters;
|
||||
node.parameters = sig.parameters;
|
||||
node.type = sig.type;
|
||||
node.body = parseBody();
|
||||
node.body = parseBody(/* ignoreMissingOpenBrace */ false);
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
|
@ -2358,7 +2394,7 @@ module ts {
|
|||
if (token === SyntaxKind.OpenBracketToken) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// If we were able to get any potential identifier...
|
||||
if (idToken !== undefined) {
|
||||
// If we have a non-keyword identifier, or if we have an accessor, then it's safe to parse.
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
==== tests/cases/compiler/arrowFunctionMissingCurlyWithSemicolon.ts (1 errors) ====
|
||||
// Should error at semicolon.
|
||||
var f = () => ;
|
||||
~
|
||||
!!! Expression expected.
|
||||
var b = 1 * 2 * 3 * 4;
|
||||
var square = (x: number) => x * x;
|
|
@ -90,10 +90,10 @@ var h;
|
|||
x = h;
|
||||
var i;
|
||||
x = i;
|
||||
x = { f: function () {
|
||||
x = { f: function f() {
|
||||
return 1;
|
||||
} };
|
||||
x = { f: function (x) {
|
||||
x = { f: function f(x) {
|
||||
return x;
|
||||
} };
|
||||
function j(a) {
|
||||
|
|
|
@ -66,7 +66,7 @@ t = { f: function (x) { return 1; } };
|
|||
t = { f: function f() {
|
||||
return 1;
|
||||
} };
|
||||
t = { f: function (x) {
|
||||
t = { f: function f(x) {
|
||||
return '';
|
||||
} };
|
||||
a = { f: function () { return 1; } };
|
||||
|
|
|
@ -32,7 +32,7 @@ var badFundule: Function = bad; // error
|
|||
//// [assignmentToObjectAndFunction.js]
|
||||
var errObj = { toString: 0 };
|
||||
var goodObj = {
|
||||
toString: function (x) {
|
||||
toString: function toString(x) {
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
|
|
@ -72,7 +72,7 @@ var C = (function () {
|
|||
})();
|
||||
var a;
|
||||
var b = {
|
||||
foo: function (x, y) {
|
||||
foo: function foo(x, y) {
|
||||
},
|
||||
a: function foo(x, y) {
|
||||
},
|
||||
|
|
|
@ -72,7 +72,7 @@ var C = (function () {
|
|||
})();
|
||||
var a;
|
||||
var b = {
|
||||
foo: function (x, x) {
|
||||
foo: function foo(x, x) {
|
||||
},
|
||||
a: function foo(x, x) {
|
||||
},
|
||||
|
|
|
@ -89,7 +89,7 @@ a(1);
|
|||
a.foo();
|
||||
a.foo(1);
|
||||
var b = {
|
||||
foo: function (x) {
|
||||
foo: function foo(x) {
|
||||
},
|
||||
a: function foo(x, y) {
|
||||
},
|
||||
|
|
|
@ -95,7 +95,7 @@ a(1);
|
|||
a.foo();
|
||||
a.foo(1);
|
||||
var b = {
|
||||
foo: function (x) {
|
||||
foo: function foo(x) {
|
||||
if (x === void 0) { x = 1; }
|
||||
},
|
||||
a: function foo(x, y) {
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
==== tests/cases/compiler/emptyMemberAccess.ts (1 errors) ====
|
||||
==== tests/cases/compiler/emptyMemberAccess.ts (2 errors) ====
|
||||
function getObj() {
|
||||
|
||||
().toString();
|
||||
~
|
||||
!!! '=>' expected.
|
||||
~~~~~~~~
|
||||
!!! Cannot find name 'toString'.
|
||||
|
||||
}
|
||||
|
|
@ -51,7 +51,7 @@ function foo(x, y) {
|
|||
function foo2(x, y) {
|
||||
}
|
||||
var x = { a: new C() };
|
||||
var x2 = { a: { bar: function () {
|
||||
var x2 = { a: { bar: function bar() {
|
||||
return 1;
|
||||
} } };
|
||||
var D = (function () {
|
||||
|
|
|
@ -54,7 +54,7 @@ var M;
|
|||
M.x = 1;
|
||||
})(M || (M = {}));
|
||||
x = M;
|
||||
x = { f: function () {
|
||||
x = { f: function f() {
|
||||
} };
|
||||
function f(a) {
|
||||
x = a;
|
||||
|
|
|
@ -59,5 +59,5 @@ var E;
|
|||
})(E || (E = {}));
|
||||
x = E;
|
||||
x = 0 /* A */;
|
||||
x = { f: function () {
|
||||
x = { f: function f() {
|
||||
} };
|
||||
|
|
|
@ -46,7 +46,7 @@ var a;
|
|||
x = a;
|
||||
var b;
|
||||
x = b;
|
||||
x = { f: function () {
|
||||
x = { f: function f() {
|
||||
} };
|
||||
var M;
|
||||
(function (M) {
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
==== tests/cases/compiler/nameCollisionsInPropertyAssignments.ts (1 errors) ====
|
||||
var x = 1
|
||||
var y = { x() { x++; } };
|
||||
~
|
||||
!!! An arithmetic operand must be of type 'any', 'number' or an enum type.
|
|
@ -4,6 +4,6 @@ var y = { x() { x++; } };
|
|||
|
||||
//// [nameCollisionsInPropertyAssignments.js]
|
||||
var x = 1;
|
||||
var y = { x: function () {
|
||||
var y = { x: function x() {
|
||||
x++;
|
||||
} };
|
||||
|
|
|
@ -126,7 +126,7 @@ var C = (function () {
|
|||
return C;
|
||||
})();
|
||||
var a;
|
||||
var b = { foo: function (x) {
|
||||
var b = { foo: function foo(x) {
|
||||
return '';
|
||||
} };
|
||||
function foo1(x) {
|
||||
|
|
|
@ -126,7 +126,7 @@ var C = (function () {
|
|||
return C;
|
||||
})();
|
||||
var a;
|
||||
var b = { foo: function (x) {
|
||||
var b = { foo: function foo(x) {
|
||||
return '';
|
||||
} };
|
||||
function foo1(x) {
|
||||
|
|
|
@ -126,7 +126,7 @@ var C = (function () {
|
|||
return C;
|
||||
})();
|
||||
var a;
|
||||
var b = { foo: function (x) {
|
||||
var b = { foo: function foo(x) {
|
||||
return '';
|
||||
} };
|
||||
function foo1(x) {
|
||||
|
|
|
@ -143,7 +143,7 @@ var C = (function () {
|
|||
})();
|
||||
var a;
|
||||
var b = {
|
||||
foo: function (x) {
|
||||
foo: function foo(x) {
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
|
|
@ -90,7 +90,7 @@ var C = (function () {
|
|||
return C;
|
||||
})();
|
||||
var a;
|
||||
var b = { new: function (x) {
|
||||
var b = { new: function new(x) {
|
||||
return '';
|
||||
} };
|
||||
function foo1b(x) {
|
||||
|
|
|
@ -90,7 +90,7 @@ var C = (function () {
|
|||
return C;
|
||||
})();
|
||||
var a;
|
||||
var b = { new: function (x) {
|
||||
var b = { new: function new(x) {
|
||||
return '';
|
||||
} };
|
||||
function foo1b(x) {
|
||||
|
|
|
@ -126,7 +126,7 @@ var C = (function () {
|
|||
return C;
|
||||
})();
|
||||
var a;
|
||||
var b = { foo: function (x) {
|
||||
var b = { foo: function foo(x) {
|
||||
return x;
|
||||
} };
|
||||
function foo1(x) {
|
||||
|
|
|
@ -126,7 +126,7 @@ var C = (function () {
|
|||
return C;
|
||||
})();
|
||||
var a;
|
||||
var b = { foo: function (x, y) {
|
||||
var b = { foo: function foo(x, y) {
|
||||
return x;
|
||||
} };
|
||||
function foo1(x) {
|
||||
|
|
|
@ -128,7 +128,7 @@ var C = (function () {
|
|||
return C;
|
||||
})();
|
||||
var a;
|
||||
var b = { foo: function (x) {
|
||||
var b = { foo: function foo(x) {
|
||||
return '';
|
||||
} };
|
||||
function foo1(x) {
|
||||
|
|
|
@ -148,7 +148,7 @@ var D = (function () {
|
|||
return D;
|
||||
})();
|
||||
var a;
|
||||
var b = { foo: function (x, y) {
|
||||
var b = { foo: function foo(x, y) {
|
||||
return '';
|
||||
} };
|
||||
function foo1(x) {
|
||||
|
|
|
@ -167,7 +167,7 @@ var D = (function () {
|
|||
return D;
|
||||
})();
|
||||
var a;
|
||||
var b = { foo: function (x, y) {
|
||||
var b = { foo: function foo(x, y) {
|
||||
return '';
|
||||
} };
|
||||
function foo1(x) {
|
||||
|
|
|
@ -128,7 +128,7 @@ var C = (function () {
|
|||
return C;
|
||||
})();
|
||||
var a;
|
||||
var b = { foo: function (x) {
|
||||
var b = { foo: function foo(x) {
|
||||
return null;
|
||||
} };
|
||||
function foo1(x) {
|
||||
|
|
|
@ -128,7 +128,7 @@ var C = (function () {
|
|||
return C;
|
||||
})();
|
||||
var a;
|
||||
var b = { foo: function (x) {
|
||||
var b = { foo: function foo(x) {
|
||||
return null;
|
||||
} };
|
||||
function foo1(x) {
|
||||
|
|
|
@ -126,7 +126,7 @@ var C = (function () {
|
|||
return C;
|
||||
})();
|
||||
var a;
|
||||
var b = { foo: function (x) {
|
||||
var b = { foo: function foo(x) {
|
||||
return x;
|
||||
} };
|
||||
function foo1(x) {
|
||||
|
|
|
@ -126,7 +126,7 @@ var C = (function () {
|
|||
return C;
|
||||
})();
|
||||
var a;
|
||||
var b = { foo: function (x) {
|
||||
var b = { foo: function foo(x) {
|
||||
return x;
|
||||
} };
|
||||
function foo1(x) {
|
||||
|
|
|
@ -128,7 +128,7 @@ var C = (function () {
|
|||
return C;
|
||||
})();
|
||||
var a;
|
||||
var b = { foo: function (x, y) {
|
||||
var b = { foo: function foo(x, y) {
|
||||
return x;
|
||||
} };
|
||||
function foo1(x) {
|
||||
|
|
|
@ -128,7 +128,7 @@ var C = (function () {
|
|||
return C;
|
||||
})();
|
||||
var a;
|
||||
var b = { foo: function (x, y) {
|
||||
var b = { foo: function foo(x, y) {
|
||||
return x;
|
||||
} };
|
||||
function foo1(x) {
|
||||
|
|
|
@ -128,7 +128,7 @@ var C = (function () {
|
|||
return C;
|
||||
})();
|
||||
var a;
|
||||
var b = { foo: function (x, y) {
|
||||
var b = { foo: function foo(x, y) {
|
||||
return x;
|
||||
} };
|
||||
function foo1(x) {
|
||||
|
|
|
@ -89,7 +89,7 @@ var C = (function () {
|
|||
return C;
|
||||
})();
|
||||
var a;
|
||||
var b = { new: function (x) {
|
||||
var b = { new: function new(x) {
|
||||
return '';
|
||||
} };
|
||||
function foo1b(x) {
|
||||
|
|
|
@ -106,7 +106,7 @@ var D = (function () {
|
|||
return D;
|
||||
})();
|
||||
var a;
|
||||
var b = { new: function (x, y) {
|
||||
var b = { new: function new(x, y) {
|
||||
return '';
|
||||
} };
|
||||
function foo1b(x) {
|
||||
|
|
|
@ -125,7 +125,7 @@ var D = (function () {
|
|||
return D;
|
||||
})();
|
||||
var a;
|
||||
var b = { new: function (x, y) {
|
||||
var b = { new: function new(x, y) {
|
||||
return '';
|
||||
} };
|
||||
function foo1b(x) {
|
||||
|
|
|
@ -96,7 +96,7 @@ var C = (function () {
|
|||
return C;
|
||||
})();
|
||||
var a;
|
||||
var b = { new: function (x) {
|
||||
var b = { new: function new(x) {
|
||||
return null;
|
||||
} };
|
||||
function foo1b(x) {
|
||||
|
|
|
@ -92,7 +92,7 @@ var C = (function () {
|
|||
return C;
|
||||
})();
|
||||
var a;
|
||||
var b = { new: function (x) {
|
||||
var b = { new: function new(x) {
|
||||
return null;
|
||||
} };
|
||||
function foo1b(x) {
|
||||
|
|
|
@ -86,7 +86,7 @@ var C = (function () {
|
|||
return C;
|
||||
})();
|
||||
var a;
|
||||
var b = { new: function (x) {
|
||||
var b = { new: function new(x) {
|
||||
return x;
|
||||
} };
|
||||
function foo1b(x) {
|
||||
|
|
|
@ -86,7 +86,7 @@ var C = (function () {
|
|||
return C;
|
||||
})();
|
||||
var a;
|
||||
var b = { new: function (x) {
|
||||
var b = { new: function new(x) {
|
||||
return new C(x);
|
||||
} };
|
||||
function foo1b(x) {
|
||||
|
|
|
@ -88,7 +88,7 @@ var C = (function () {
|
|||
return C;
|
||||
})();
|
||||
var a;
|
||||
var b = { new: function (x, y) {
|
||||
var b = { new: function new(x, y) {
|
||||
return new C(x, y);
|
||||
} };
|
||||
function foo1b(x) {
|
||||
|
|
|
@ -88,7 +88,7 @@ var C = (function () {
|
|||
return C;
|
||||
})();
|
||||
var a;
|
||||
var b = { new: function (x, y) {
|
||||
var b = { new: function new(x, y) {
|
||||
return new C(x, y);
|
||||
} };
|
||||
function foo1b(x) {
|
||||
|
|
|
@ -88,7 +88,7 @@ var C = (function () {
|
|||
return C;
|
||||
})();
|
||||
var a;
|
||||
var b = { new: function (x, y) {
|
||||
var b = { new: function new(x, y) {
|
||||
return new C(x, y);
|
||||
} };
|
||||
function foo1b(x) {
|
||||
|
|
|
@ -48,7 +48,7 @@ var C = (function () {
|
|||
})();
|
||||
var a;
|
||||
var b = {
|
||||
foo: function (x) {
|
||||
foo: function foo(x) {
|
||||
return x;
|
||||
},
|
||||
a: function foo(x) {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserEmptyParenthesizedExpression1.ts (1 errors) ====
|
||||
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserEmptyParenthesizedExpression1.ts (2 errors) ====
|
||||
function getObj() {
|
||||
().toString();
|
||||
~
|
||||
!!! '=>' expected.
|
||||
~~~~~~~~
|
||||
!!! Cannot find name 'toString'.
|
||||
}
|
|
@ -2,5 +2,5 @@
|
|||
var v = { foo() { } };
|
||||
|
||||
//// [parserFunctionPropertyAssignment1.js]
|
||||
var v = { foo: function () {
|
||||
var v = { foo: function foo() {
|
||||
} };
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
var v = { 0() { } };
|
||||
|
||||
//// [parserFunctionPropertyAssignment2.js]
|
||||
var v = { 0: function () {
|
||||
var v = { 0: function 0() {
|
||||
} };
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
var v = { "foo"() { } };
|
||||
|
||||
//// [parserFunctionPropertyAssignment3.js]
|
||||
var v = { "foo": function () {
|
||||
var v = { "foo": function "foo"() {
|
||||
} };
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
var v = { 0<T>() { } };
|
||||
|
||||
//// [parserFunctionPropertyAssignment4.js]
|
||||
var v = { 0: function () {
|
||||
var v = { 0: function 0() {
|
||||
} };
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserMissingLambdaOpenBrace1.ts (9 errors) ====
|
||||
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserMissingLambdaOpenBrace1.ts (5 errors) ====
|
||||
class C {
|
||||
where(filter: Iterator<T, boolean>): Query<T> {
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -10,18 +10,10 @@
|
|||
!!! Cannot find name 'fromDoWhile'.
|
||||
var index = 0;
|
||||
~~~
|
||||
!!! Expression expected.
|
||||
!!! '{' expected.
|
||||
return this.doWhile((item, i) => filter(item, i) ? test(item, index++) : true);
|
||||
~~~~~~~
|
||||
!!! Property 'doWhile' does not exist on type 'C'.
|
||||
~~~~
|
||||
!!! Cannot find name 'test'.
|
||||
});
|
||||
~
|
||||
!!! Unexpected token. A constructor, method, accessor, or property was expected.
|
||||
~
|
||||
!!! Unexpected token. A constructor, method, accessor, or property was expected.
|
||||
}
|
||||
}
|
||||
~
|
||||
!!! Declaration or statement expected.
|
||||
}
|
|
@ -2,6 +2,6 @@
|
|||
var x = { n() { } };
|
||||
|
||||
//// [sourceMapValidationFunctionPropertyAssignment.js]
|
||||
var x = { n: function () {
|
||||
var x = { n: function n() {
|
||||
} };
|
||||
//# sourceMappingURL=sourceMapValidationFunctionPropertyAssignment.js.map
|
|
@ -1,2 +1,2 @@
|
|||
//// [sourceMapValidationFunctionPropertyAssignment.js.map]
|
||||
{"version":3,"file":"sourceMapValidationFunctionPropertyAssignment.js","sourceRoot":"","sources":["sourceMapValidationFunctionPropertyAssignment.ts"],"names":[],"mappings":"AAAA,IAAI,CAAC,GAAG,EAAE,CAAC,EAAD;AAAM,CAAC,EAAE,CAAC"}
|
||||
{"version":3,"file":"sourceMapValidationFunctionPropertyAssignment.js","sourceRoot":"","sources":["sourceMapValidationFunctionPropertyAssignment.ts"],"names":["n"],"mappings":"AAAA,IAAI,CAAC,GAAG,EAAE,CAAC,EAAD,SAAA,CAAC;AAAKA,CAACA,EAAE,CAAC"}
|
|
@ -8,7 +8,7 @@ sources: sourceMapValidationFunctionPropertyAssignment.ts
|
|||
emittedFile:tests/cases/compiler/sourceMapValidationFunctionPropertyAssignment.js
|
||||
sourceFile:sourceMapValidationFunctionPropertyAssignment.ts
|
||||
-------------------------------------------------------------------
|
||||
>>>var x = { n: function () {
|
||||
>>>var x = { n: function n() {
|
||||
1 >
|
||||
2 >^^^^
|
||||
3 > ^
|
||||
|
@ -16,6 +16,8 @@ sourceFile:sourceMapValidationFunctionPropertyAssignment.ts
|
|||
5 > ^^
|
||||
6 > ^
|
||||
7 > ^^
|
||||
8 > ^^^^^^^^^
|
||||
9 > ^
|
||||
1 >
|
||||
2 >var
|
||||
3 > x
|
||||
|
@ -23,6 +25,8 @@ sourceFile:sourceMapValidationFunctionPropertyAssignment.ts
|
|||
5 > {
|
||||
6 > n
|
||||
7 >
|
||||
8 >
|
||||
9 > n
|
||||
1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0)
|
||||
2 >Emitted(1, 5) Source(1, 5) + SourceIndex(0)
|
||||
3 >Emitted(1, 6) Source(1, 6) + SourceIndex(0)
|
||||
|
@ -30,6 +34,8 @@ sourceFile:sourceMapValidationFunctionPropertyAssignment.ts
|
|||
5 >Emitted(1, 11) Source(1, 11) + SourceIndex(0)
|
||||
6 >Emitted(1, 12) Source(1, 12) + SourceIndex(0)
|
||||
7 >Emitted(1, 14) Source(1, 11) + SourceIndex(0)
|
||||
8 >Emitted(1, 23) Source(1, 11) + SourceIndex(0)
|
||||
9 >Emitted(1, 24) Source(1, 12) + SourceIndex(0)
|
||||
---
|
||||
>>>} };
|
||||
1 >
|
||||
|
@ -37,12 +43,12 @@ sourceFile:sourceMapValidationFunctionPropertyAssignment.ts
|
|||
3 > ^^
|
||||
4 > ^
|
||||
5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
|
||||
1 >n() {
|
||||
1 >() {
|
||||
2 >}
|
||||
3 > }
|
||||
4 > ;
|
||||
1 >Emitted(2, 1) Source(1, 17) + SourceIndex(0)
|
||||
2 >Emitted(2, 2) Source(1, 18) + SourceIndex(0)
|
||||
1 >Emitted(2, 1) Source(1, 17) + SourceIndex(0) name (n)
|
||||
2 >Emitted(2, 2) Source(1, 18) + SourceIndex(0) name (n)
|
||||
3 >Emitted(2, 4) Source(1, 20) + SourceIndex(0)
|
||||
4 >Emitted(2, 5) Source(1, 21) + SourceIndex(0)
|
||||
---
|
||||
|
|
|
@ -42,7 +42,7 @@ var C = (function () {
|
|||
})();
|
||||
var a;
|
||||
var b = {
|
||||
foo: function (x) {
|
||||
foo: function foo(x) {
|
||||
},
|
||||
a: function foo(x, y) {
|
||||
},
|
||||
|
|
|
@ -41,8 +41,8 @@ var C = (function () {
|
|||
})();
|
||||
var a;
|
||||
var b = {
|
||||
foo: function (x) {
|
||||
foo: function foo(x) {
|
||||
},
|
||||
foo: function (x) {
|
||||
foo: function foo(x) {
|
||||
},
|
||||
};
|
||||
|
|
|
@ -29,7 +29,7 @@ var MyClass = (function () {
|
|||
return MyClass;
|
||||
})();
|
||||
var obj = {
|
||||
f: function () {
|
||||
f: function f() {
|
||||
return this.spaaace;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -88,7 +88,7 @@ var C = (function () {
|
|||
})();
|
||||
var aa = {
|
||||
id: 12,
|
||||
biz: function () {
|
||||
biz: function biz() {
|
||||
throw this;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
==== tests/cases/compiler/uncaughtCompilerError2.ts (1 errors) ====
|
||||
==== tests/cases/compiler/uncaughtCompilerError2.ts (2 errors) ====
|
||||
function getObj() {
|
||||
().toString();
|
||||
~
|
||||
!!! '=>' expected.
|
||||
~~~~~~~~
|
||||
!!! Cannot find name 'toString'.
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
// Should error at semicolon.
|
||||
var f = () => ;
|
||||
var b = 1 * 2 * 3 * 4;
|
||||
var square = (x: number) => x * x;
|
Загрузка…
Ссылка в новой задаче