TypeScript: Octal escape sequences should be a lexical/syntactic error in strict mode and ES5

The following code should be disallowed in strict mode and ES5:

"\5";
"\05";
"\55";
"\055";

This is disallowed by Annex B.1.2 of the EcmaScript 5 spec.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Reactions: 1
  • Comments: 21 (10 by maintainers)

Most upvoted comments

Yeah, just give it a shot and see how it goes 👍🏻

List of things to do for resolving this:

  • parser.ts:

    • Not really needed, but there is a comment here that is no longer relevant and should be removed: // Octal literals are not allowed...
  • scanner.ts:

    • At the end of scanEscapeSequence() should add:
      if (isDigit(ch)) tokenFlags |= TokenFlags.ContainsInvalidEscape;
      
      but…
  • types.ts:

    • ContainsInvalidEscape = 1 << 11 is defined here but it’s unused!
    • TemplateLiteralLikeFlags = ContainsInvalidEscape ⇒ this is fishy, probably should be its own value
  • binder.ts:

    • See checkStrictModeNumericLiteral and make a similar checker for strings with the ContainsInvalidEscape flag.

One decision to make is whether to allow octal escapes in TS when not producing strict-mode code. It would probably be easier to forbid them anyway (especially since they’re never allowed in template strings) but if not, then the scanner mode should also parse the octal escapes in case the output is not strict.