Skip to content

Commit

Permalink
fix(es/codegen): Do not produce octal literals (#8565)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 authored Jan 28, 2024
1 parent 2367507 commit 07634a0
Show file tree
Hide file tree
Showing 12 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
console.log("\00");
console.log("\x000");
2 changes: 2 additions & 0 deletions crates/swc/tests/fixture/next.js/octal/1/input/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

export const shouldNotBeOctal = '\x001'
1 change: 1 addition & 0 deletions crates/swc/tests/fixture/next.js/octal/1/output/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export var shouldNotBeOctal = "\x001";
Original file line number Diff line number Diff line change
@@ -1 +1 @@
var USTAR = "ustar\000";
var USTAR = "ustar\x0000";
2 changes: 1 addition & 1 deletion crates/swc_ecma_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3998,7 +3998,7 @@ fn get_quoted_utf16(v: &str, ascii_only: bool, target: EsVersion) -> String {
while let Some(c) = iter.next() {
match c {
'\x00' => {
if target < EsVersion::Es5 {
if target < EsVersion::Es5 || matches!(iter.peek(), Some('0'..='9')) {
buf.push_str("\\x00");
} else {
buf.push_str("\\0");
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_codegen/tests/fixture/string/output.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
var a = "\0\08?\0?Àÿ";
var r = " 080\x000À0";
var x = "\0\08?\0?Àÿ";
var a = " 080\x000À0";
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"use strict";
console.log("\01");
console.log("\x001");

0 comments on commit 07634a0

Please sign in to comment.