Merge pull request #3464 from lydell/code-frame-tabs
babel-code-frame: Handle code with tabs
This commit is contained in:
commit
98685d21d7
@ -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}`;
|
||||
|
||||
@ -93,6 +93,20 @@ suite("babel-code-frame", function () {
|
||||
].join("\n"));
|
||||
});
|
||||
|
||||
test("tabs", function () {
|
||||
const rawLines = [
|
||||
"\tclass Foo {",
|
||||
"\t \t\t constructor\t(\t)",
|
||||
"\t};",
|
||||
].join('\n');
|
||||
assert.equal(codeFrame(rawLines, 2, 25), [
|
||||
" 1 | \tclass Foo {",
|
||||
"> 2 | \t \t\t constructor\t(\t)",
|
||||
" | \t \t\t \t \t ^",
|
||||
" 3 | \t};",
|
||||
].join('\n'));
|
||||
});
|
||||
|
||||
test("opts.highlightCode", function () {
|
||||
const rawLines = "console.log('babel')";
|
||||
const result = codeFrame(rawLines, 1, 9, {highlightCode: true})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user