diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 57e23531398..5ab0dad085f 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1062,6 +1062,11 @@ module ts { if (node.kind === SyntaxKind.NumericLiteral && (isInStrictMode || languageVersion >= ScriptTarget.ES5)) { var numberLiteralSource = getSourceTextOfNodeFromSourceText(sourceText, node); // This regex checks if the number is written in octal + // Note that theoretically would match 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 (/0[0-7]+/.test(numberLiteralSource)) { if (isInStrictMode) { grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_allowed_in_strict_mode); diff --git a/tests/baselines/reference/scannerNumericLiteral8.errors.txt b/tests/baselines/reference/scannerNumericLiteral8.errors.txt new file mode 100644 index 00000000000..a55568d91e0 --- /dev/null +++ b/tests/baselines/reference/scannerNumericLiteral8.errors.txt @@ -0,0 +1,4 @@ +==== tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral8.ts (1 errors) ==== + -03 + ~~ +!!! Octal literals are not available when targeting ECMAScript 5 and higher. \ No newline at end of file diff --git a/tests/baselines/reference/scannerNumericLiteral9.errors.txt b/tests/baselines/reference/scannerNumericLiteral9.errors.txt new file mode 100644 index 00000000000..610c1c0a5fc --- /dev/null +++ b/tests/baselines/reference/scannerNumericLiteral9.errors.txt @@ -0,0 +1,6 @@ +==== tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral9.ts (2 errors) ==== + 009 + ~~ +!!! Octal literals are not available when targeting ECMAScript 5 and higher. + ~ +!!! ';' expected. \ No newline at end of file diff --git a/tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral8.ts b/tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral8.ts new file mode 100644 index 00000000000..858e3eada0f --- /dev/null +++ b/tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral8.ts @@ -0,0 +1,2 @@ +// @target: ES5 +-03 \ No newline at end of file diff --git a/tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral9.ts b/tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral9.ts new file mode 100644 index 00000000000..cf187b83edf --- /dev/null +++ b/tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral9.ts @@ -0,0 +1,2 @@ +// @target: ES5 +009 \ No newline at end of file