Skip to content

Commit 9f54a36

Browse files
committed
fix(semantic): error on \00 in strict mode (#15743)
`\00` matches LegacyOctalEscapeSequence and should be an error in strict mode. https://tc39.es/ecma262/2025/multipage/ecmascript-language-lexical-grammar.html#sec-string-literals-early-errors
1 parent 1f09d3c commit 9f54a36

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

crates/oxc_semantic/src/checker/javascript.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ pub fn check_string_literal(lit: &StringLiteral, ctx: &SemanticBuilder<'_>) {
361361
if c == '\\' {
362362
match chars.next() {
363363
Some('0') => {
364-
if chars.peek().is_some_and(|c| ('1'..='9').contains(c)) {
364+
if chars.peek().is_some_and(char::is_ascii_digit) {
365365
return ctx.error(legacy_octal(lit.span));
366366
}
367367
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const escape00 = "\00";

tasks/coverage/snapshots/parser_misc.snap

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
parser_misc Summary:
22
AST Parsed : 49/49 (100.00%)
33
Positive Passed: 49/49 (100.00%)
4-
Negative Passed: 112/112 (100.00%)
4+
Negative Passed: 113/113 (100.00%)
55

66
× Cannot assign to 'arguments' in strict mode
77
╭─[misc/fail/arguments-eval.ts:1:10]
@@ -72,6 +72,13 @@ Negative Passed: 112/112 (100.00%)
7272
If you're in the middle of a rebase, the top section is the code being rebased onto and the bottom section is the code coming from the current commit being rebased.
7373
If you have nested conflicts, resolve the outermost conflict first.
7474

75+
× '0'-prefixed octal literals and octal escape sequences are deprecated
76+
╭─[misc/fail/escape-00.js:1:25]
77+
1export const escape00 = "\00";
78+
· ─────
79+
╰────
80+
help: for octal literals use the '0o' prefix instead
81+
7582
× Expected `,` or `]` but found `const`
7683
╭─[misc/fail/imbalanced-array-expr.js:2:1]
7784
1const foo = [0, 1

0 commit comments

Comments
 (0)