fix(es/codegen): Fix codegen of \\0 (#8433)

**Related issue:**

 - Closes #8431
This commit is contained in:
Donny/강동윤 2024-01-19 11:11:05 +09:00 committed by GitHub
parent fefe9636f0
commit 9f1ce3acd6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
41 changed files with 81 additions and 49 deletions

View File

@ -1 +1 @@
console.log("\x000");
console.log("\00");

View File

@ -0,0 +1,23 @@
{
"jsc": {
"parser": {
"syntax": "ecmascript",
"jsx": false
},
"target": "es2022",
"loose": false,
"minify": {
"mangle": true,
"compress": {
"defaults": true,
"arguments": true,
"passes": 2
}
}
},
"module": {
"type": "es6"
},
"minify": true,
"isModule": true
}

View File

@ -0,0 +1,2 @@
export const exampleCode_0 = '\0';
export const exampleCode_x00 = '\x00';

View File

@ -0,0 +1 @@
export const exampleCode_0="\0";export const exampleCode_x00="\0";

View File

@ -1 +1 @@
var USTAR = "ustar\x0000";
var USTAR = "ustar\000";

View File

@ -1,2 +1,2 @@
//// [scannerStringLiteralWithContainingNullCharacter1.ts]
" \x00 ";
" \0 ";

View File

@ -1,2 +1,2 @@
//// [templateStringControlCharacterEscapes01.ts]
var x = "\x00\x00\x00 0 00 0000";
var x = "\0\0\0 0 00 0000";

View File

@ -1,2 +1,2 @@
//// [unicodeExtendedEscapesInStrings01_ES5.ts]
var x = "\x00";
var x = "\0";

View File

@ -1,2 +1,2 @@
//// [unicodeExtendedEscapesInStrings02_ES5.ts]
var x = "\x00";
var x = "\0";

View File

@ -1,2 +1,2 @@
//// [unicodeExtendedEscapesInStrings03_ES5.ts]
var x = "\x00";
var x = "\0";

View File

@ -1,2 +1,2 @@
//// [unicodeExtendedEscapesInStrings04_ES5.ts]
var x = "\x00";
var x = "\0";

View File

@ -1,2 +1,2 @@
//// [unicodeExtendedEscapesInTemplates01_ES5.ts]
var x = "\x00";
var x = "\0";

View File

@ -1,2 +1,2 @@
//// [unicodeExtendedEscapesInTemplates02_ES5.ts]
var x = "\x00";
var x = "\0";

View File

@ -1,2 +1,2 @@
//// [unicodeExtendedEscapesInTemplates03_ES5.ts]
var x = "\x00";
var x = "\0";

View File

@ -1,2 +1,2 @@
//// [unicodeExtendedEscapesInTemplates04_ES5.ts]
var x = "\x00";
var x = "\0";

View File

@ -3951,7 +3951,11 @@ fn get_quoted_utf16(v: &str, ascii_only: bool, target: EsVersion) -> String {
while let Some(c) = iter.next() {
match c {
'\x00' => {
buf.push_str("\\x00");
if target < EsVersion::Es5 {
buf.push_str("\\x00");
} else {
buf.push_str("\\0");
}
}
'\u{0008}' => buf.push_str("\\b"),
'\u{000c}' => buf.push_str("\\f"),

View File

@ -101,6 +101,7 @@ pub(crate) fn assert_min(from: &str, to: &str) {
assert_eq!(DebugUsingDisplay(out.trim()), DebugUsingDisplay(to),);
}
#[track_caller]
pub(crate) fn assert_min_target(from: &str, to: &str, target: EsVersion) {
let out = parse_then_emit(
from,
@ -117,6 +118,7 @@ pub(crate) fn assert_min_target(from: &str, to: &str, target: EsVersion) {
}
/// Clone of the regular `assert_min` function but with TypeScript syntax.
#[track_caller]
pub(crate) fn assert_min_typescript(from: &str, to: &str) {
let out = parse_then_emit(
from,
@ -611,7 +613,7 @@ fn test_get_quoted_utf16() {
es2020("abcde", "\"abcde\"");
es2020(
"\x00\r\n\u{85}\u{2028}\u{2029};",
"\"\\x00\\r\\n\\x85\\u2028\\u2029;\"",
"\"\\0\\r\\n\\x85\\u2028\\u2029;\"",
);
es2020("\n", "\"\\n\"");
@ -619,7 +621,7 @@ fn test_get_quoted_utf16() {
es2020("'string'", "\"'string'\"");
es2020("\u{0}", "\"\\x00\"");
es2020("\u{0}", "\"\\0\"");
es2020("\u{1}", "\"\\x01\"");
es2020("\u{1000}", "\"\\u1000\"");
@ -655,7 +657,7 @@ fn issue_1452_1() {
fn issue_1619_1() {
assert_min_target(
"\"\\x00\" + \"\\x31\"",
"\"\\x00\"+\"1\"",
"\"\\0\"+\"1\"",
EsVersion::latest(),
);
}
@ -664,7 +666,7 @@ fn issue_1619_1() {
fn issue_1619_2() {
assert_min_target(
"\"\\x00\" + \"\\x31\"",
"\"\\x00\"+\"1\"",
"\"\\0\"+\"1\"",
EsVersion::latest(),
);
}

View File

@ -1,3 +1,3 @@
import*as commonjsHelpers from"\x00commonjsHelpers.js";const string1="test";const string2="test";const string3='te"st';const string4="te'st";const string5="test\ntest\ntest";const string6=`Yet another string primitive`;const string7="This is a very long string which needs to wrap across multiple lines because otherwise my code is unreadable.";const string8="中文 español English हिन्दी العربية português বাংলা русский 日本語 ਪੰਜਾਬੀ 한국어 தமிழ்";const string9=``;const string10=`xx\`x`;const string11=`${foo+2}`;const string12=` foo ${bar+`baz ${qux}`}`;const string13=String.raw`foo`;const string14=foo`bar`;const string15=`foo
import*as commonjsHelpers from"\0commonjsHelpers.js";const string1="test";const string2="test";const string3='te"st';const string4="te'st";const string5="test\ntest\ntest";const string6=`Yet another string primitive`;const string7="This is a very long string which needs to wrap across multiple lines because otherwise my code is unreadable.";const string8="中文 español English हिन्दी العربية português বাংলা русский 日本語 ਪੰਜਾਬੀ 한국어 தமிழ்";const string9=``;const string10=`xx\`x`;const string11=`${foo+2}`;const string12=` foo ${bar+`baz ${qux}`}`;const string13=String.raw`foo`;const string14=foo`bar`;const string15=`foo
bar
ↂωↂ`;const string16=`\``;const string17=`${4+4} equals 4 + 4`;const string18=`This is ${undefined}`;const string19=`This is ${NaN}`;const string20=`This is ${null}`;const string21=`This is ${Infinity}`;const string22="This is ${1/0}";const string23="This is ${1/0}";const string24="This is ${NaN}";const string25="This is ${null}";const string26=`This is ${1/0}`;const string27=`This is ${0/0}`;const string28="This is ${0/0}";const string29="This is ${0/0}";const string30=`${4**11}`;const string31=`${4**12}`;const string32=`${4**14}`;const string33="";const string34="\b";const string35="\f";const string36=" ";const string37="\v";const string38="\n";const string39="\\n";const string40="\\";const string41='\\"';const string42="'\"";const string43="\\\\";const string44="\x00";const string45="\x00!";const string46="\x001";const string47="\\0";const string48="\\0!";const string49="\x07";const string50="\x07!";const string51="\x071";const string52="\x07";const string53="\\7";const string54="\\7!";const string55="\\01";const string56="\x10";const string57="\\x10";const string58="\x1b";const string59="\\x1B";const string60="ꯍ";const string61="ꯍ";const string62="U000123AB";const string63="𒎫";const string64="\uD808\uDFAB";const string65="\uD808";const string66="\uD808X";const string67="\uDFAB";const string68="\uDFABX";const string69="€";const string70="ÿ";const string71="🍕";const string72="\uD801\uDC02\uDC03\uD804";const string73="π";const ="🐈";const 貓abc="🐈";const abc貓="🐈";const string74="\u2028";const string75="\u2029";const string76="\uFEFF";const string77="\x10";const string78=" ";const string79=" ";const string80="2";const string81="\x16";const string82="\x06";const string83="\x00a";const string84='"test"test"test';const string85="\"test'test'test";const string86='"test"test"test';const string87="'test'test'test";const string88="😄";const string89=new RegExp("\r").test("\r");const string90=new RegExp(" ").test(" ");const string91=new RegExp("\x1b").test("["+"\x1b"+"]");const string92=new RegExp("\\x1b").test("\x1b");const string93=new RegExp("\x1b").test("\x1b");const string94="퟿";const string95="ퟻ";const string96=sql`'#ERROR'`;const string97=" ";const string98="\ud83d\ude00";const string99="\ud83d@\ude00";const string100="a";const string101="\u2028";const string102="\uD800";const string103="\u{D800}";const string104="\uDBFF";const string105="\u{DBFF}";const string106="\uDC00";const string107="\u{DC00}";const string108="\uDFFF";const string109="\u{DFFF}";const string110="￿";const string111="￿";const string112="\ud800";const string113="\uD800";React.createElement("div",null,"this should not parse as unicode: \\u00a0");const a="֑-ۯۺ-ࣿ‏\ud802-\ud803\ud83a-\ud83bיִ-﷿ﹰ-ﻼ";const b="A-Za-zÀ-ÖØ-öø-ʸ̀-֐ऀ-῿‎Ⰰ-\ud801\ud804-\ud839\ud83c-\udbff豈-﬜︀-﹯﻽-￿";var x="\u{D800}";var x2="\u{D800}";var x3="\u{D800}\u{D800}";const zzz="\x00a";
ↂωↂ`;const string16=`\``;const string17=`${4+4} equals 4 + 4`;const string18=`This is ${undefined}`;const string19=`This is ${NaN}`;const string20=`This is ${null}`;const string21=`This is ${Infinity}`;const string22="This is ${1/0}";const string23="This is ${1/0}";const string24="This is ${NaN}";const string25="This is ${null}";const string26=`This is ${1/0}`;const string27=`This is ${0/0}`;const string28="This is ${0/0}";const string29="This is ${0/0}";const string30=`${4**11}`;const string31=`${4**12}`;const string32=`${4**14}`;const string33="";const string34="\b";const string35="\f";const string36=" ";const string37="\v";const string38="\n";const string39="\\n";const string40="\\";const string41='\\"';const string42="'\"";const string43="\\\\";const string44="\0";const string45="\0!";const string46="\01";const string47="\\0";const string48="\\0!";const string49="\x07";const string50="\x07!";const string51="\x071";const string52="\x07";const string53="\\7";const string54="\\7!";const string55="\\01";const string56="\x10";const string57="\\x10";const string58="\x1b";const string59="\\x1B";const string60="ꯍ";const string61="ꯍ";const string62="U000123AB";const string63="𒎫";const string64="\uD808\uDFAB";const string65="\uD808";const string66="\uD808X";const string67="\uDFAB";const string68="\uDFABX";const string69="€";const string70="ÿ";const string71="🍕";const string72="\uD801\uDC02\uDC03\uD804";const string73="π";const ="🐈";const 貓abc="🐈";const abc貓="🐈";const string74="\u2028";const string75="\u2029";const string76="\uFEFF";const string77="\x10";const string78=" ";const string79=" ";const string80="2";const string81="\x16";const string82="\x06";const string83="\0a";const string84='"test"test"test';const string85="\"test'test'test";const string86='"test"test"test';const string87="'test'test'test";const string88="😄";const string89=new RegExp("\r").test("\r");const string90=new RegExp(" ").test(" ");const string91=new RegExp("\x1b").test("["+"\x1b"+"]");const string92=new RegExp("\\x1b").test("\x1b");const string93=new RegExp("\x1b").test("\x1b");const string94="퟿";const string95="ퟻ";const string96=sql`'#ERROR'`;const string97=" ";const string98="\ud83d\ude00";const string99="\ud83d@\ude00";const string100="a";const string101="\u2028";const string102="\uD800";const string103="\u{D800}";const string104="\uDBFF";const string105="\u{DBFF}";const string106="\uDC00";const string107="\u{DC00}";const string108="\uDFFF";const string109="\u{DFFF}";const string110="￿";const string111="￿";const string112="\ud800";const string113="\uD800";React.createElement("div",null,"this should not parse as unicode: \\u00a0");const a="֑-ۯۺ-ࣿ‏\ud802-\ud803\ud83a-\ud83bיִ-﷿ﹰ-ﻼ";const b="A-Za-zÀ-ÖØ-öø-ʸ̀-֐ऀ-῿‎Ⰰ-\ud801\ud804-\ud839\ud83c-\udbff豈-﬜︀-﹯﻽-￿";var x="\u{D800}";var x2="\u{D800}";var x3="\u{D800}\u{D800}";const zzz="\0a";

View File

@ -1 +1 @@
"\x00\x01\x02\x03\x04\x05\x06\x07\b \n\v\f\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe"+a;
"\0\x01\x02\x03\x04\x05\x06\x07\b \n\v\f\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe"+a;

View File

@ -1 +1 @@
"use strict";("\x00");
"use strict";("\0");

View File

@ -1 +1 @@
"use strict";("\x00x");
"use strict";("\0x");

View File

@ -1 +1 @@
"\n\r \v\b\f\\'\"\x00";
"\n\r \v\b\f\\'\"\0";

View File

@ -1 +1 @@
"Hello\x00World";
"Hello\0World";

View File

@ -1 +1 @@
function a(){"use strict";"\x00"}
function a(){"use strict";"\0"}

View File

@ -1 +1 @@
("\x00");
("\0");

View File

@ -1 +1 @@
(function(){"use strict";"\x00"}());
(function(){"use strict";"\0"}());

View File

@ -1 +1 @@
("\x00");
("\0");

View File

@ -1 +1 @@
"\x00\x01\x02\x03\x04\x05\x06\x07\b \n\v\f\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x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ed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe" + a;

View File

@ -1,2 +1,2 @@
"use strict";
("\x00");
("\0");

View File

@ -1,2 +1,2 @@
"use strict";
("\x00x");
("\0x");

View File

@ -1 +1 @@
"\n\r \v\b\f\\'\"\x00";
"\n\r \v\b\f\\'\"\0";

View File

@ -1 +1 @@
"Hello\x00World";
"Hello\0World";

View File

@ -1,4 +1,4 @@
function a() {
"use strict";
"\x00";
"\0";
}

View File

@ -1 +1 @@
("\x00");
("\0");

View File

@ -1,4 +1,4 @@
(function() {
"use strict";
"\x00";
"\0";
}());

View File

@ -1 +1 @@
("\x00");
("\0");

View File

@ -2097,7 +2097,7 @@
}
})
}) : t.push({
string: s.replace(i, "\x00"),
string: s.replace(i, "\0"),
attributes: n.attributes
}), o = a + u.length;
}

View File

@ -1,4 +1,4 @@
var x = {
var r = {
"\0": "foo",
get "\0" () {
return "bar";
@ -10,12 +10,12 @@ var x = {
return "foobar";
}
};
class r {
class e {
get "\0"() {
return "bar";
}
set "\0"(x) {
save(x);
set "\0"(r) {
save(r);
}
*"\0"() {
return "foobar";

View File

@ -1,4 +1,4 @@
var x = {
var r = {
"\0\x01": "foo",
get "\0\x01" () {
return "bar";
@ -10,12 +10,12 @@ var x = {
return "foobar";
}
};
class r {
class e {
get "\0\x01"() {
return "bar";
}
set "\0\x01"(x) {
save(x);
set "\0\x01"(r) {
save(r);
}
*"\0\x01"() {
return "foobar";

View File

@ -1,2 +1,2 @@
var x = "\0\08?\0?Àÿ";
var a = " 080\x000À0";
var a = "\0\08?\0?Àÿ";
var r = " 080\x000À0";

View File

@ -1,2 +1,2 @@
"use strict";
console.log("\x001");
console.log("\01");