Handle unconventional newlines (#1050)
The `\r` test has had to be deleted because jest doesn't properly save and parse the snapshot back. Fixes #883master
parent
61ad2f1d34
commit
926f9c4dfb
17
src/util.js
17
src/util.js
|
@ -166,20 +166,23 @@ function skipNewline(text, index, opts) {
|
||||||
const backwards = opts && opts.backwards;
|
const backwards = opts && opts.backwards;
|
||||||
if (index === false) {
|
if (index === false) {
|
||||||
return false;
|
return false;
|
||||||
} else if (backwards) {
|
}
|
||||||
if (text.charAt(index) === "\n") {
|
|
||||||
|
const atIndex = text.charAt(index);
|
||||||
|
if (backwards) {
|
||||||
|
if (atIndex === "\n" || atIndex === "\r" || atIndex === "\u2028" || atIndex === "\u2029") {
|
||||||
return index - 1;
|
return index - 1;
|
||||||
}
|
}
|
||||||
if (text.charAt(index - 1) === "\r" && text.charAt(index) === "\n") {
|
if (text.charAt(index - 1) === "\r" && atIndex === "\n") {
|
||||||
return index - 2;
|
return index - 2;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (text.charAt(index) === "\n") {
|
if (atIndex === "\r" && text.charAt(index + 1) === "\n") {
|
||||||
return index + 1;
|
|
||||||
}
|
|
||||||
if (text.charAt(index) === "\r" && text.charAt(index + 1) === "\n") {
|
|
||||||
return index + 2;
|
return index + 2;
|
||||||
}
|
}
|
||||||
|
if (atIndex === "\n" || atIndex === "\r" || atIndex === "\u2028" || atIndex === "\u2029") {
|
||||||
|
return index + 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return index;
|
return index;
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`backslash_2028.js 1`] = `
|
||||||
|
"1;/*a*///b
/*c*/2
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
1; /*a*/ //b
/*c*/2
|
||||||
|
"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`backslash_2029.js 1`] = `
|
||||||
|
"1;/*a*///b
/*c*/2
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
1; /*a*/ //b
/*c*/2
|
||||||
|
"
|
||||||
|
`;
|
|
@ -0,0 +1 @@
|
||||||
|
1;/*a*///b
/*c*/2
|
|
@ -0,0 +1 @@
|
||||||
|
1;/*a*///b
/*c*/2
|
|
@ -0,0 +1 @@
|
||||||
|
run_spec(__dirname);
|
Loading…
Reference in New Issue