Handle unconventional newlines (#1050)

The `\r` test has had to be deleted because jest doesn't properly save and parse the snapshot back.

Fixes #883
master
Christopher Chedeau 2017-04-05 10:54:39 -07:00 committed by GitHub
parent 61ad2f1d34
commit 926f9c4dfb
5 changed files with 28 additions and 7 deletions

View File

@ -166,20 +166,23 @@ function skipNewline(text, index, opts) {
const backwards = opts && opts.backwards;
if (index === 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;
}
if (text.charAt(index - 1) === "\r" && text.charAt(index) === "\n") {
if (text.charAt(index - 1) === "\r" && atIndex === "\n") {
return index - 2;
}
} else {
if (text.charAt(index) === "\n") {
return index + 1;
}
if (text.charAt(index) === "\r" && text.charAt(index + 1) === "\n") {
if (atIndex === "\r" && text.charAt(index + 1) === "\n") {
return index + 2;
}
if (atIndex === "\n" || atIndex === "\r" || atIndex === "\u2028" || atIndex === "\u2029") {
return index + 1;
}
}
return index;

View File

@ -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
"
`;

View File

@ -0,0 +1 @@
1;/*a*///b/*c*/2

View File

@ -0,0 +1 @@
1;/*a*///b/*c*/2

View File

@ -0,0 +1 @@
run_spec(__dirname);