Add column range to babel-code-frame (#5646)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import assert from "assert";
|
||||
import chalk from "chalk";
|
||||
import codeFrame from "..";
|
||||
import codeFrame, { codeFrameColumns } from "..";
|
||||
|
||||
describe("babel-code-frame", function () {
|
||||
it("basic usage", function () {
|
||||
@@ -30,19 +30,6 @@ describe("babel-code-frame", function () {
|
||||
].join("\n"));
|
||||
});
|
||||
|
||||
it("optional column number", function () {
|
||||
const rawLines = [
|
||||
"class Foo {",
|
||||
" constructor()",
|
||||
"};",
|
||||
].join("\n");
|
||||
assert.equal(codeFrame(rawLines, 2, null), [
|
||||
" 1 | class Foo {",
|
||||
"> 2 | constructor()",
|
||||
" 3 | };",
|
||||
].join("\n"));
|
||||
});
|
||||
|
||||
it("maximum context lines and padding", function () {
|
||||
const rawLines = [
|
||||
"/**",
|
||||
@@ -205,4 +192,90 @@ describe("babel-code-frame", function () {
|
||||
].join("\n"))
|
||||
);
|
||||
});
|
||||
|
||||
it("basic usage, new API", function () {
|
||||
const rawLines = [
|
||||
"class Foo {",
|
||||
" constructor()",
|
||||
"};",
|
||||
].join("\n");
|
||||
assert.equal(codeFrameColumns(rawLines, { start: { line: 2, column: 16 } }), [
|
||||
" 1 | class Foo {",
|
||||
"> 2 | constructor()",
|
||||
" | ^",
|
||||
" 3 | };",
|
||||
].join("\n"));
|
||||
});
|
||||
|
||||
it("mark multiple columns", function() {
|
||||
const rawLines = [
|
||||
"class Foo {",
|
||||
" constructor()",
|
||||
"};",
|
||||
].join("\n");
|
||||
assert.equal(
|
||||
codeFrameColumns(rawLines, { start: { line: 2, column: 3 }, end: { line: 2, column: 16 } }), [
|
||||
" 1 | class Foo {",
|
||||
"> 2 | constructor()",
|
||||
" | ^^^^^^^^^^^^^",
|
||||
" 3 | };",
|
||||
].join("\n"));
|
||||
});
|
||||
|
||||
it("mark multiple columns across lines", function() {
|
||||
const rawLines = [
|
||||
"class Foo {",
|
||||
" constructor() {",
|
||||
" }",
|
||||
"};",
|
||||
].join("\n");
|
||||
assert.equal(
|
||||
codeFrameColumns(rawLines, { start: { line: 2, column: 17 }, end: { line: 3, column: 3 } }), [
|
||||
" 1 | class Foo {",
|
||||
"> 2 | constructor() {",
|
||||
" | ^",
|
||||
"> 3 | }",
|
||||
" | ^^^",
|
||||
" 4 | };",
|
||||
].join("\n"));
|
||||
});
|
||||
|
||||
it("mark multiple columns across multiple lines", function() {
|
||||
const rawLines = [
|
||||
"class Foo {",
|
||||
" constructor() {",
|
||||
" console.log(arguments);",
|
||||
" }",
|
||||
"};",
|
||||
].join("\n");
|
||||
assert.equal(
|
||||
codeFrameColumns(rawLines, { start: { line: 2, column: 17 }, end: { line: 4, column: 3 } }), [
|
||||
" 1 | class Foo {",
|
||||
"> 2 | constructor() {",
|
||||
" | ^",
|
||||
"> 3 | console.log(arguments);",
|
||||
" | ^^^^^^^^^^^^^^^^^^^^^^^^^^^",
|
||||
"> 4 | }",
|
||||
" | ^^^",
|
||||
" 5 | };",
|
||||
].join("\n"));
|
||||
});
|
||||
|
||||
it("mark across multiple lines without columns", function() {
|
||||
const rawLines = [
|
||||
"class Foo {",
|
||||
" constructor() {",
|
||||
" console.log(arguments);",
|
||||
" }",
|
||||
"};",
|
||||
].join("\n");
|
||||
assert.equal(
|
||||
codeFrameColumns(rawLines, { start: { line: 2 }, end: { line: 4 } }), [
|
||||
" 1 | class Foo {",
|
||||
"> 2 | constructor() {",
|
||||
"> 3 | console.log(arguments);",
|
||||
"> 4 | }",
|
||||
" 5 | };",
|
||||
].join("\n"));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user