mirror of
https://github.com/swc-project/swc.git
synced 2024-11-28 11:13:43 +03:00
fix(ecmascript/lexer): Normalize \r\n and \r to \n in template literals (#1286)
swc_ecma_parser: - Normalize \r\n and \r to \n in template literals. Co-authored-by: 강동윤 <kdy1997.dev@gmail.com>
This commit is contained in:
parent
edf74fc1ec
commit
576fb6a532
@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs"]
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_codegen"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.41.4"
|
||||
version = "0.41.5"
|
||||
|
||||
[dependencies]
|
||||
bitflags = "1"
|
||||
|
@ -1 +1 @@
|
||||
`\r\n \n`;
|
||||
`\n \n`;
|
||||
|
@ -1 +1 @@
|
||||
`\n\r\n\r`;
|
||||
`\n\n\n`;
|
||||
|
@ -1 +1 @@
|
||||
`\n\r\n`;
|
||||
`\n\n`;
|
||||
|
@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs", "examples/**/*.rs"]
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_parser"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.43.5"
|
||||
version = "0.43.6"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
@ -1019,23 +1019,22 @@ impl<'a, I: Input> Lexer<'a, I> {
|
||||
} else if c.is_line_break() {
|
||||
self.state.had_line_break = true;
|
||||
let c = if c == '\r' && self.peek() == Some('\n') {
|
||||
raw.push_str("\\r\\n");
|
||||
self.bump(); // '\r'
|
||||
'\n'
|
||||
} else {
|
||||
match c {
|
||||
'\n' => raw.push_str("\n"),
|
||||
'\r' => raw.push_str("\r"),
|
||||
'\u{2028}' => raw.push_str("\u{2028}"),
|
||||
'\u{2029}' => raw.push_str("\u{2029}"),
|
||||
'\n' => '\n',
|
||||
'\r' => '\n',
|
||||
'\u{2028}' => '\u{2028}',
|
||||
'\u{2029}' => '\u{2029}',
|
||||
_ => unreachable!(),
|
||||
}
|
||||
c
|
||||
};
|
||||
self.bump();
|
||||
if let Some(ref mut cooked) = cooked {
|
||||
cooked.push(c);
|
||||
}
|
||||
raw.push(c);
|
||||
} else {
|
||||
self.bump();
|
||||
if let Some(ref mut cooked) = cooked {
|
||||
|
@ -1309,3 +1309,15 @@ fn issue_1272_2_js() {
|
||||
assert_eq!(tokens.len(), 1);
|
||||
assert_eq!(errors, vec![]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn normalize_tpl_carriage_return() {
|
||||
assert_eq!(
|
||||
lex_tokens(Syntax::default(), "`\r\n`"),
|
||||
lex_tokens(Syntax::default(), "`\n`")
|
||||
);
|
||||
assert_eq!(
|
||||
lex_tokens(Syntax::default(), "`\r`"),
|
||||
lex_tokens(Syntax::default(), "`\n`")
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user