Allow falsey, yet valid options for codeFrameColumns() (#7341)
Allow for overriding default linesAbove/linesBelow values.
This commit is contained in:
parent
493996e02a
commit
a01007a3d3
@ -127,9 +127,7 @@ function getMarkerLines(
|
|||||||
loc.start,
|
loc.start,
|
||||||
);
|
);
|
||||||
const endLoc: Location = Object.assign({}, startLoc, loc.end);
|
const endLoc: Location = Object.assign({}, startLoc, loc.end);
|
||||||
const linesAbove = opts.linesAbove || 2;
|
const { linesAbove = 2, linesBelow = 3 } = opts || {};
|
||||||
const linesBelow = opts.linesBelow || 3;
|
|
||||||
|
|
||||||
const startLine = startLoc.line;
|
const startLine = startLoc.line;
|
||||||
const startColumn = startLoc.column;
|
const startColumn = startLoc.column;
|
||||||
const endLine = endLoc.line;
|
const endLine = endLoc.line;
|
||||||
|
|||||||
@ -184,6 +184,57 @@ describe("@babel/code-frame", function() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("opts.linesAbove no lines above", function() {
|
||||||
|
const rawLines = [
|
||||||
|
"class Foo {",
|
||||||
|
" constructor() {",
|
||||||
|
" console.log(arguments);",
|
||||||
|
" }",
|
||||||
|
"};",
|
||||||
|
].join("\n");
|
||||||
|
assert.equal(
|
||||||
|
codeFrameColumns(rawLines, { start: { line: 2 } }, { linesAbove: 0 }),
|
||||||
|
[
|
||||||
|
"> 2 | constructor() {",
|
||||||
|
" 3 | console.log(arguments);",
|
||||||
|
" 4 | }",
|
||||||
|
" 5 | };",
|
||||||
|
].join("\n"),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("opts.linesBelow no lines below", function() {
|
||||||
|
const rawLines = [
|
||||||
|
"class Foo {",
|
||||||
|
" constructor() {",
|
||||||
|
" console.log(arguments);",
|
||||||
|
" }",
|
||||||
|
"};",
|
||||||
|
].join("\n");
|
||||||
|
assert.equal(
|
||||||
|
codeFrameColumns(rawLines, { start: { line: 2 } }, { linesBelow: 0 }),
|
||||||
|
[" 1 | class Foo {", "> 2 | constructor() {"].join("\n"),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("opts.linesBelow single line", function() {
|
||||||
|
const rawLines = [
|
||||||
|
"class Foo {",
|
||||||
|
" constructor() {",
|
||||||
|
" console.log(arguments);",
|
||||||
|
" }",
|
||||||
|
"};",
|
||||||
|
].join("\n");
|
||||||
|
assert.equal(
|
||||||
|
codeFrameColumns(
|
||||||
|
rawLines,
|
||||||
|
{ start: { line: 2 } },
|
||||||
|
{ linesAbove: 0, linesBelow: 0 },
|
||||||
|
),
|
||||||
|
["> 2 | constructor() {"].join("\n"),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("opts.forceColor", function() {
|
it("opts.forceColor", function() {
|
||||||
const marker = chalk.red.bold;
|
const marker = chalk.red.bold;
|
||||||
const gutter = chalk.grey;
|
const gutter = chalk.grey;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user