babel-code-frame: Handle code with tabs
Previously, the `^` marker was misaligned if the line above contained tabs. Fixes T7282. Note: This commit handles a very subtle edge-case differently: When the passed in column number is larger than the length of the line. Previously, the `^` marker would be faithfully placed at that exact column number. Now, it is placed at the end of the line instead (after the last character of the line to be precise). Ideally, we should define what should happen in edge cases, but that's out of scope for this PR.
This commit is contained in:
parent
580b09abb1
commit
f80463120b
@ -11,7 +11,6 @@
|
||||
"babel-runtime": "^5.0.0",
|
||||
"chalk": "^1.1.0",
|
||||
"esutils": "^2.0.2",
|
||||
"js-tokens": "^1.0.1",
|
||||
"repeating": "^1.1.3"
|
||||
"js-tokens": "^1.0.2"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import repeating from "repeating";
|
||||
import jsTokens from "js-tokens";
|
||||
import esutils from "esutils";
|
||||
import chalk from "chalk";
|
||||
@ -100,9 +99,11 @@ export default function (
|
||||
let paddedNumber = ` ${number}`.slice(-numberMaxWidth);
|
||||
let gutter = ` ${paddedNumber} | `;
|
||||
if (number === lineNumber) {
|
||||
let markerLine = colNumber
|
||||
? `\n ${gutter.replace(/\d/g, " ")}${repeating(" ", colNumber - 1)}^`
|
||||
: "";
|
||||
let markerLine = "";
|
||||
if (colNumber) {
|
||||
let markerSpacing = line.slice(0, colNumber - 1).replace(/[^\t]/g, " ");
|
||||
markerLine =`\n ${gutter.replace(/\d/g, " ")}${markerSpacing}^`;
|
||||
}
|
||||
return `>${gutter}${line}${markerLine}`;
|
||||
} else {
|
||||
return ` ${gutter}${line}`;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user