Merge pull request #13016 from arusakov/disallow_old_style_octal_literal_types
Disallow old style octal literal types
This commit is contained in:
commit
8ae0376e75
10 changed files with 55 additions and 13 deletions
|
@ -21848,8 +21848,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
},
|
||||
|
@ -3238,5 +3238,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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -2,8 +2,8 @@ tests/cases/conformance/expressions/literals/literals.ts(9,10): error TS2362: Th
|
|||
tests/cases/conformance/expressions/literals/literals.ts(9,17): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
|
||||
tests/cases/conformance/expressions/literals/literals.ts(10,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
|
||||
tests/cases/conformance/expressions/literals/literals.ts(10,21): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
|
||||
tests/cases/conformance/expressions/literals/literals.ts(20,9): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher.
|
||||
tests/cases/conformance/expressions/literals/literals.ts(25,10): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher.
|
||||
tests/cases/conformance/expressions/literals/literals.ts(20,9): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o1'.
|
||||
tests/cases/conformance/expressions/literals/literals.ts(25,10): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o3'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/expressions/literals/literals.ts (6 errors) ====
|
||||
|
@ -36,14 +36,14 @@ tests/cases/conformance/expressions/literals/literals.ts(25,10): error TS1085: O
|
|||
var n = 1e4;
|
||||
var n = 001; // Error in ES5
|
||||
~~~
|
||||
!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher.
|
||||
!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o1'.
|
||||
var n = 0x1;
|
||||
var n = -1;
|
||||
var n = -1.0;
|
||||
var n = -1e-4;
|
||||
var n = -003; // Error in ES5
|
||||
~~~
|
||||
!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher.
|
||||
!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o3'.
|
||||
var n = -0x1;
|
||||
|
||||
var s: string;
|
||||
|
|
|
@ -12,7 +12,7 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(13,21)
|
|||
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(14,19): error TS2300: Duplicate identifier '0'.
|
||||
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(15,19): error TS2300: Duplicate identifier '0'.
|
||||
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(16,19): error TS2300: Duplicate identifier '0x0'.
|
||||
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(17,19): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher.
|
||||
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(17,19): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o0'.
|
||||
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(17,19): error TS2300: Duplicate identifier '000'.
|
||||
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(18,23): error TS2300: Duplicate identifier '1e2'.
|
||||
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(19,22): error TS2300: Duplicate identifier '3.2e1'.
|
||||
|
@ -125,7 +125,7 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(45,55)
|
|||
!!! error TS2300: Duplicate identifier '0x0'.
|
||||
var e14 = { 0: 0, 000: 0 };
|
||||
~~~
|
||||
!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher.
|
||||
!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o0'.
|
||||
~~~
|
||||
!!! error TS2300: Duplicate identifier '000'.
|
||||
var e15 = { "100": 0, 1e2: 0 };
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
tests/cases/compiler/oldStyleOctalLiteralTypes.ts(1,8): error TS8017: Octal literal types must use ES2015 syntax. Use the syntax '0o10'.
|
||||
tests/cases/compiler/oldStyleOctalLiteralTypes.ts(2,9): error TS8017: Octal literal types must use ES2015 syntax. Use the syntax '0o20'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/oldStyleOctalLiteralTypes.ts (2 errors) ====
|
||||
let x: 010;
|
||||
~~~
|
||||
!!! error TS8017: Octal literal types must use ES2015 syntax. Use the syntax '0o10'.
|
||||
let y: -020;
|
||||
~~~
|
||||
!!! error TS8017: Octal literal types must use ES2015 syntax. Use the syntax '0o20'.
|
||||
|
8
tests/baselines/reference/oldStyleOctalLiteralTypes.js
Normal file
8
tests/baselines/reference/oldStyleOctalLiteralTypes.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
//// [oldStyleOctalLiteralTypes.ts]
|
||||
let x: 010;
|
||||
let y: -020;
|
||||
|
||||
|
||||
//// [oldStyleOctalLiteralTypes.js]
|
||||
var x;
|
||||
var y;
|
|
@ -1,7 +1,7 @@
|
|||
tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral2.ts(1,1): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher.
|
||||
tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral2.ts(1,1): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o1'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral2.ts (1 errors) ====
|
||||
01
|
||||
~~
|
||||
!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher.
|
||||
!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o1'.
|
|
@ -1,7 +1,7 @@
|
|||
tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral8.ts(1,2): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher.
|
||||
tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral8.ts(1,2): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o3'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral8.ts (1 errors) ====
|
||||
-03
|
||||
~~
|
||||
!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher.
|
||||
!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o3'.
|
3
tests/cases/compiler/oldStyleOctalLiteralTypes.ts
Normal file
3
tests/cases/compiler/oldStyleOctalLiteralTypes.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
// @target: ES3
|
||||
let x: 010;
|
||||
let y: -020;
|
Loading…
Reference in a new issue