diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 513e47e0747..e3d78092282 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7009,6 +7009,19 @@ module ts { return type; } + function checkNumericLiteral(node: LiteralExpression): Type { + // Grammar checking + if (node.flags & NodeFlags.OctalLiteral) { + if (node.parserContextFlags & ParserContextFlags.StrictMode) { + grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_allowed_in_strict_mode); + } + else if (compilerOptions.target >= ScriptTarget.ES5) { + grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher); + } + } + return numberType; + } + function checkExpressionWorker(node: Expression, contextualMapper: TypeMapper): Type { switch (node.kind) { case SyntaxKind.Identifier: @@ -7023,7 +7036,7 @@ module ts { case SyntaxKind.FalseKeyword: return booleanType; case SyntaxKind.NumericLiteral: - return numberType; + return checkNumericLiteral(node); case SyntaxKind.TemplateExpression: return checkTemplateExpression(node); case SyntaxKind.StringLiteral: diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index a740c5f9cb4..22028913157 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4658,7 +4658,7 @@ module ts { return checkMethod(node); case SyntaxKind.ModuleDeclaration: return checkModuleDeclaration(node); //case SyntaxKind.ObjectLiteralExpression: return checkObjectLiteralExpression(node); - case SyntaxKind.NumericLiteral: return checkNumericLiteral(node); + //case SyntaxKind.NumericLiteral: return checkNumericLiteral(node); case SyntaxKind.Parameter: return checkParameter(node); case SyntaxKind.PostfixUnaryExpression: return checkPostfixUnaryExpression(node); case SyntaxKind.PrefixUnaryExpression: return checkPrefixUnaryExpression(node); diff --git a/tests/baselines/reference/literals.errors.txt b/tests/baselines/reference/literals.errors.txt index f33d26af7a4..d43e89bb4db 100644 --- a/tests/baselines/reference/literals.errors.txt +++ b/tests/baselines/reference/literals.errors.txt @@ -1,9 +1,9 @@ -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(9,10): 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(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 (6 errors) ====