Disallow old style octal literal types

This commit is contained in:
arusakov
2016-12-19 11:36:20 +03:00
parent 0f78f53780
commit 142a6f6420
10 changed files with 55 additions and 13 deletions

View File

@@ -21845,8 +21845,13 @@ namespace ts {
function checkGrammarNumericLiteral(node: NumericLiteral): boolean {
// Grammar checking
if (node.isOctalLiteral && languageVersion >= ScriptTarget.ES5) {
return grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher);
if (node.isOctalLiteral) {
if (languageVersion >= ScriptTarget.ES5) {
return grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_Use_the_syntax_0o_0, node.text);
}
if (isChildOfLiteralType(node)) {
return grammarErrorOnNode(node, Diagnostics.Octal_literal_types_must_use_ES2015_syntax_Use_the_syntax_0o_0, node.text);
}
}
}

View File

@@ -227,7 +227,7 @@
"category": "Error",
"code": 1084
},
"Octal literals are not available when targeting ECMAScript 5 and higher.": {
"Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o{0}'.": {
"category": "Error",
"code": 1085
},
@@ -3234,5 +3234,9 @@
"Add {0} to existing import declaration from {1}": {
"category": "Message",
"code": 90015
},
"Octal literal types must use ES2015 syntax. Use the syntax '0o{0}'.": {
"category": "Error",
"code": 8017
}
}

View File

@@ -732,6 +732,16 @@ namespace ts {
return false;
}
export function isChildOfLiteralType(node: Node): boolean {
while (node) {
if (node.kind === SyntaxKind.LiteralType) {
return true;
}
node = node.parent;
}
return false;
}
// Warning: This has the same semantics as the forEach family of functions,
// in that traversal terminates in the event that 'visitor' supplies a truthy value.
export function forEachReturnStatement<T>(body: Block, visitor: (stmt: ReturnStatement) => T): T {