Skip to content

Commit

Permalink
fix(ecma/lexer): hexadecimal escape sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
RiESAEX committed Nov 23, 2021
1 parent d0cabc3 commit d68d7e7
Show file tree
Hide file tree
Showing 20 changed files with 49 additions and 13 deletions.
5 changes: 5 additions & 0 deletions crates/swc/tests/fixture/issue-2822/1/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"jsc": {
"target": "es5"
}
}
1 change: 1 addition & 0 deletions crates/swc/tests/fixture/issue-2822/1/input/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log`\x22\x21\x224`
22 changes: 22 additions & 0 deletions crates/swc/tests/fixture/issue-2822/1/output/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function _taggedTemplateLiteral(strings, raw) {
if (!raw) {
raw = strings.slice(0);
}
return Object.freeze(Object.defineProperties(strings, {
raw: {
value: Object.freeze(raw)
}
}));
}
function _templateObject() {
var data = _taggedTemplateLiteral([
"\"!\"4"
], [
"\\x22\\x21\\x224"
]);
_templateObject = function _templateObject() {
return data;
};
return data;
}
console.log(_templateObject());
5 changes: 5 additions & 0 deletions crates/swc/tests/fixture/issue-2822/2/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"jsc": {
"target": "es2015"
}
}
1 change: 1 addition & 0 deletions crates/swc/tests/fixture/issue-2822/2/input/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`\x22\x21\x224`
1 change: 1 addition & 0 deletions crates/swc/tests/fixture/issue-2822/2/output/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`\x22\x21\x224`;
Original file line number Diff line number Diff line change
@@ -1 +1 @@
var x = `\0\0x00\u0000 0 00 0000`;
var x = `\0\x00\u0000 0 00 0000`;
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// @target: es6
var x = `\0\0x00\u0000 0 00 0000`;
var x = `\0\x00\u0000 0 00 0000`;
Original file line number Diff line number Diff line change
@@ -1 +1 @@
var x = `\x1f\u001f 1F 1f`;
var x = `\x1F\u001f 1F 1f`;
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// @target: es6
var x = `\x1f\u001f 1F 1f`;
var x = `\x1F\u001f 1F 1f`;
1 change: 1 addition & 0 deletions crates/swc_ecma_minifier/src/compress/pure/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ where
}) && (M::force_str_for_tpl()
|| (!c.value.contains("\\n") && !c.value.contains("\\r")))
&& !c.value.contains("\\0")
&& !c.value.contains("\\x")
{
*e = Expr::Lit(Lit::Str(Str {
value: c
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_parser/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ impl<'a, I: Input> Lexer<'a, I> {

// read hexadecimal escape sequences
'x' => {
raw.push_str("0x");
raw.push_str("x");
self.bump(); // 'x'
return self.read_hex_char(start, 2, raw).map(Some);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"end": 33,
"ctxt": 0
},
"value": "\\0\\0x00\\u0000 0 00 0000",
"value": "\\0\\x00\\u0000 0 00 0000",
"hasEscape": true,
"kind": {
"type": "normal",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"end": 48,
"ctxt": 0
},
"value": "\\0\\0x00\\u0000 0 00 0000",
"value": "\\0\\x00\\u0000 0 00 0000",
"hasEscape": true,
"kind": {
"type": "normal",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"end": 24,
"ctxt": 0
},
"value": "\\0x19\\u0019 19",
"value": "\\x19\\u0019 19",
"hasEscape": true,
"kind": {
"type": "normal",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"end": 39,
"ctxt": 0
},
"value": "\\0x19\\u0019 19",
"value": "\\x19\\u0019 19",
"hasEscape": true,
"kind": {
"type": "normal",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"end": 27,
"ctxt": 0
},
"value": "\\0x1F\\u001f 1F 1f",
"value": "\\x1F\\u001f 1F 1f",
"hasEscape": true,
"kind": {
"type": "normal",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"end": 42,
"ctxt": 0
},
"value": "\\0x1F\\u001f 1F 1f",
"value": "\\x1F\\u001f 1F 1f",
"hasEscape": true,
"kind": {
"type": "normal",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"end": 24,
"ctxt": 0
},
"value": "\\0x20\\u0020 20",
"value": "\\x20\\u0020 20",
"hasEscape": true,
"kind": {
"type": "normal",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"end": 39,
"ctxt": 0
},
"value": "\\0x20\\u0020 20",
"value": "\\x20\\u0020 20",
"hasEscape": true,
"kind": {
"type": "normal",
Expand Down

0 comments on commit d68d7e7

Please sign in to comment.