mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-20 22:51:17 -05:00
Fixes #2632 (invoking methods on numbers)
This commit is contained in:
@@ -569,5 +569,6 @@ namespace ts {
|
||||
decorators_can_only_be_used_in_a_ts_file: { code: 8017, category: DiagnosticCategory.Error, key: "'decorators' can only be used in a .ts file." },
|
||||
Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_class_extends_clauses: { code: 9002, category: DiagnosticCategory.Error, key: "Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clauses." },
|
||||
class_expressions_are_not_currently_supported: { code: 9003, category: DiagnosticCategory.Error, key: "'class' expressions are not currently supported." },
|
||||
Numeric_literal_0_cannot_be_followed_by_an_expression: { code: 9004, category: DiagnosticCategory.Error, key: "Numeric literal {0} cannot be followed by an expression." },
|
||||
};
|
||||
}
|
||||
@@ -2268,5 +2268,9 @@
|
||||
"'class' expressions are not currently supported.": {
|
||||
"category": "Error",
|
||||
"code": 9003
|
||||
},
|
||||
"Numeric literal {0} cannot be followed by an expression.": {
|
||||
"category": "Error",
|
||||
"code": 9004
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,6 +100,8 @@ namespace ts {
|
||||
visitNode(cbNode, (<FunctionLikeDeclaration>node).type) ||
|
||||
visitNode(cbNode, (<ArrowFunction>node).equalsGreaterThanToken) ||
|
||||
visitNode(cbNode, (<FunctionLikeDeclaration>node).body);
|
||||
case SyntaxKind.NumericLiteral:
|
||||
return visitNode(cbNode, (<LiteralExpression>node).invalidDotExpression);
|
||||
case SyntaxKind.TypeReference:
|
||||
return visitNode(cbNode, (<TypeReferenceNode>node).typeName) ||
|
||||
visitNodes(cbNodes, (<TypeReferenceNode>node).typeArguments);
|
||||
@@ -1830,20 +1832,37 @@ namespace ts {
|
||||
}
|
||||
|
||||
let tokenPos = scanner.getTokenPos();
|
||||
let nextCharCode: number;
|
||||
|
||||
nextToken();
|
||||
finishNode(node);
|
||||
|
||||
// Octal literals are not allowed in strict mode or ES5
|
||||
// Note that theoretically the following condition would hold true literals like 009,
|
||||
// which is not octal.But because of how the scanner separates the tokens, we would
|
||||
// never get a token like this. Instead, we would get 00 and 9 as two separate tokens.
|
||||
// We also do not need to check for negatives because any prefix operator would be part of a
|
||||
// parent unary expression.
|
||||
if (node.kind === SyntaxKind.NumericLiteral
|
||||
&& sourceText.charCodeAt(tokenPos) === CharacterCodes._0
|
||||
&& isOctalDigit(sourceText.charCodeAt(tokenPos + 1))) {
|
||||
|
||||
node.flags |= NodeFlags.OctalLiteral;
|
||||
if (node.kind === SyntaxKind.NumericLiteral) {
|
||||
// Octal literals are not allowed in strict mode or ES5
|
||||
// Note that theoretically the following condition would hold true literals like 009,
|
||||
// which is not octal.But because of how the scanner separates the tokens, we would
|
||||
// never get a token like this. Instead, we would get 00 and 9 as two separate tokens.
|
||||
// We also do not need to check for negatives because any prefix operator would be part of a
|
||||
// parent unary expression.
|
||||
if (sourceText.charCodeAt(tokenPos) === CharacterCodes._0 && isOctalDigit(sourceText.charCodeAt(tokenPos + 1))) {
|
||||
node.flags |= NodeFlags.OctalLiteral;
|
||||
}
|
||||
else if (token === SyntaxKind.DotToken) {
|
||||
// Issue #2632 Keep space for 3 .toString()
|
||||
if (isWhiteSpace(sourceText.charCodeAt(node.end))) {
|
||||
node.end++;
|
||||
scanner.setTextPos(node.end + 1);
|
||||
}
|
||||
}
|
||||
else if (token === SyntaxKind.Identifier && sourceText.charCodeAt(node.end-1) === CharacterCodes.dot) {
|
||||
nextCharCode = sourceText.charCodeAt(node.end);
|
||||
if (!isWhiteSpace(nextCharCode) && !isLineBreak(nextCharCode)) {
|
||||
// Eat up an invalid expression following '1.' e.g. 1.something()
|
||||
node.invalidDotExpression = parseLeftHandSideExpressionOrHigher();
|
||||
parseErrorAtPosition(node.end, node.invalidDotExpression.end - node.end, Diagnostics.Numeric_literal_0_cannot_be_followed_by_an_expression, "'" + sourceText.substring(tokenPos, node.end) + "'");
|
||||
node.end = node.invalidDotExpression.end;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
|
||||
@@ -737,6 +737,7 @@ namespace ts {
|
||||
text: string;
|
||||
isUnterminated?: boolean;
|
||||
hasExtendedUnicodeEscape?: boolean;
|
||||
invalidDotExpression?: LeftHandSideExpression; // 1.toString() we attach the node but never emit it
|
||||
}
|
||||
|
||||
export interface TemplateExpression extends PrimaryExpression {
|
||||
@@ -1881,7 +1882,7 @@ namespace ts {
|
||||
CarriageReturnLineFeed = 0,
|
||||
LineFeed = 1,
|
||||
}
|
||||
|
||||
|
||||
export interface LineAndCharacter {
|
||||
line: number;
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user