Skip to content

Design Meeting Notes, 3/10/2023 #53198

Closed
Closed

Description

Parsing Octal Literals and Escapes

#51837

// allowed outside of strict mode
function loose() {
    // numeric octal
    console.log(0170);

    // octal string escapes
    console.log("\170");
    console.log("\0170");
}

// errors in strict mode
function strict() {
    "use strict";

    // numeric octal
    "use strict"; console.log(0170);

    // octal string escape
    "use strict"; console.log("\170");
    "use strict"; console.log("\0170");
}

function errorsAlways() {
    // octal template string escapes
    console.log(`\170`);
    console.log(`\0170`);
}

// valid ALWAYS
function validAlways() {
    // explicit octal
    console.log(0o170);

    // not even an octal string escape sequence
    console.log("\0o170");

    // Tagged Template Strings
    console.log(String.raw `\170`);
    console.log(String.raw `\0170`);
}

4.9 Playground
PR Build

  • In JS, octal numeric literals have a leading zero
    • It is an error to use this in strict mode
  • Octals also exist in string escape sequences
    • Don't need a leading zero(!)
    • It is an error to use this in strict mode
  • Octals also exist in template strings
    • It is an error to use this in any mode
  • You may write 0o170 in any mode
  • "\0o170" is not a string escape sequence, though.
  • You may write String.raw`\170` and get the string "slash one seven zero"
  • TS currently fails to error on \170 in strict mode.
  • This PR fixes this, but also treats octals in sloppy-mode is if they were in strict mode.
  • Does anyone want to stand up for sloppy mode?
    • No.
  • Think this is technically Annex B, so we can claim your engine technically might not support this.
  • Steelman case: Someone using TS for JS-only tooling purposes?
    • Probably rare, and parse errors can be ignored.
  • Saves some performance.
  • Conclusion: Ship it!

Testing Node 12.20

#53194

  • Made it so 5.0 says Node 12 is a minimum (even though we work on lower than that right now).
  • But Node 12 is old.
  • Our infra can't use stuff like ?? and ?. if we have to test on Node 12.
  • Also, stable sort is only mandated in ES2019 (so questionable if Node 12 can "guarantee" that even if it always has)
  • Could we say "TypeScript 5.x will always support Node 12?"
    • That's going to be 2.5 years! Node 12 doesn't even get security updates anymore, does it?
    • Node 12 goes out of maintenance in April.
    • TypeScript 5.1 goes out just after that - doesn't make sense to support.
  • Conclusion: should say Node 14 is what's supported in 5.1, so don't add a test runner we'd have to rip out immediately.

Activity

  1. fatcerberus commented on Mar 10, 2023

    @fatcerberus

    Wait, I could have sworn 0oXXX style octals weren't introduced until ES6 (or possibly later)... weird that 0XXX is disallowed in strict mode since that breaks any ES5 strict-mode code that uses them

  2. fatcerberus commented on Mar 10, 2023

    @fatcerberus

    Off-topic but I really don't like V8's error message for this:

    > function foo() { 'use strict'; 042; }
    function foo() { 'use strict'; 042; }
                                   ^^^
    
    Uncaught SyntaxError: Octal literals are not allowed in strict mode.
    

    0o42 is allowed so I guess that doesn't count as an octal literal 😉

  3. RyanCavanaugh commented on Mar 10, 2023

    @RyanCavanaugh
    Member

    I looked it up so I'll post it: The spec calls 017 a "LegacyOctalIntegerLiteral" and 0o17 an "OctalIntegerLiteral"

  4. RyanCavanaugh commented on Mar 10, 2023

    @RyanCavanaugh
    Member

    Also: octal integer literals allow separators!!

    const oOoOo = 0O0_0_0_0;
    
  5. jakebailey commented on Mar 10, 2023

    @jakebailey
    Member

    Note discrepancy: Node 12 went EOL last April, it's Node 14 that's going EOL this April.

  6. fatcerberus commented on Mar 10, 2023

    @fatcerberus

    Hmm, so by the same argument made in the notes, TS 5.1 should have a minimum target of node 16 😉

  7. jakebailey commented on Mar 10, 2023

    @jakebailey
    Member

    My recollection was that I basically said "TS is more conservative than most projects, so people are likely to have hit other things breaking earlier", but, I do think that we should try and not break the previous EOL version when possible because there really always are people stuck just one version behind.

    Once Node 14 is EOL, there should truly be no reason to be using Node 12.

  8. graphemecluster commented on Mar 11, 2023

    @graphemecluster
    Contributor

    Thank you for bring this to the design meeting — I've just updated the PR. 🎉🚀

  9. HolgerJeromin commented on Jun 23, 2023

    @HolgerJeromin
    Contributor

    Just wanted to add that this breaks VS2019 support with a suggested fix to hack in the registry...

    #54686

    I have no idea who could update EOL node in VS2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design NotesNotes from our design meetings

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions