Fix bundled @babel/code-frame for test (#19340)
This commit is contained in:
1 parent
2680e80adb
commit
21a8c81940
8 files changed
+48
-57
No files matched your search
Vendored
+17
-6
@@ -4,11 +4,11 @@ const path = require("node:path");
|
|||||||
const root = path.join(__dirname, "../../");
|
const root = path.join(__dirname, "../../");
|
||||||
|
|
||||||
function setupVscode() {
|
function setupVscode() {
|
||||||
const settingsFile = path.join(__dirname, "../../.vscode/settings.json");
|
const vscodeDirectory = path.join(root, ".vscode/");
|
||||||
|
const settingsFile = path.join(vscodeDirectory, "settings.json");
|
||||||
const settingsExampleFile = path.join(
|
const settingsExampleFile = path.join(
|
||||||
__dirname,
|
vscodeDirectory,
|
||||||
"../../.vscode/settings.example.json",
|
"settings.example.json",
|
||||||
);
|
);
|
||||||
|
|
||||||
if (fs.existsSync(settingsFile) || !fs.existsSync(settingsExampleFile)) {
|
if (fs.existsSync(settingsFile) || !fs.existsSync(settingsExampleFile)) {
|
||||||
@@ -29,8 +29,19 @@ module.exports = {
|
|||||||
name: "plugin-prepare",
|
name: "plugin-prepare",
|
||||||
factory: () => ({
|
factory: () => ({
|
||||||
hooks: {
|
hooks: {
|
||||||
async afterAllInstalled({ cwd }) {
|
async afterAllInstalled({ cwd: rawCwd }) {
|
||||||
if (cwd !== root) {
|
console.log(`Yarn plugin "prepare" running in "${rawCwd}".`);
|
||||||
|
|
||||||
|
let cwd = rawCwd;
|
||||||
|
|
||||||
|
if (process.platform === "win32" && cwd.startsWith("/")) {
|
||||||
|
cwd = cwd.slice(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (path.join(cwd, "./") !== root) {
|
||||||
|
console.log(
|
||||||
|
`Yarn plugin "prepare" skipped, yarn command not running in "${root}".`,
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import indexToPosition from "index-to-position";
|
import indexToPosition from "index-to-position";
|
||||||
import { codeFrameColumns } from "../../../vendors/babel-code-frame-for-test.js";
|
import { codeFrameColumns } from "../../../vendors/babel-code-frame-for-test.js";
|
||||||
|
|
||||||
const codeFrameColumnsOptions = {
|
const codeFrameColumnsOptions = {
|
||||||
linesAbove: Number.POSITIVE_INFINITY,
|
linesAbove: Number.POSITIVE_INFINITY,
|
||||||
linesBelow: Number.POSITIVE_INFINITY,
|
linesBelow: Number.POSITIVE_INFINITY,
|
||||||
@@ -8,11 +9,7 @@ const codeFrameColumnsOptions = {
|
|||||||
const locationForRange = (text, range) => {
|
const locationForRange = (text, range) => {
|
||||||
const [start, end] = [...range]
|
const [start, end] = [...range]
|
||||||
.sort((indexA, indexB) => indexA - indexB)
|
.sort((indexA, indexB) => indexA - indexB)
|
||||||
.map((index) => indexToPosition(text, index, { oneBased: true }));
|
.map((index) => indexToPosition(text, index, { oneBasedLine: true }));
|
||||||
|
|
||||||
if (start.line !== end.line) {
|
|
||||||
end.column -= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return { start, end };
|
return { start, end };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -519,7 +519,7 @@ exports[`range-3.js format 1`] = `
|
|||||||
> 3 | thisWillBeFormatted (2 ,3, )
|
> 3 | thisWillBeFormatted (2 ,3, )
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
> 4 |
|
> 4 |
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^
|
||||||
> 5 | thisWontBeFormatted (2, 90 ,)
|
> 5 | thisWontBeFormatted (2, 90 ,)
|
||||||
| ^
|
| ^
|
||||||
6 |
|
6 |
|
||||||
@@ -625,7 +625,7 @@ exports[`range-8.js format 1`] = `
|
|||||||
> 3 | thisWillBeFormatted (2 ,3, )<|>
|
> 3 | thisWillBeFormatted (2 ,3, )<|>
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
> 4 |
|
> 4 |
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^
|
||||||
> 5 | thisWontBeFormatted (2, 90 ,)
|
> 5 | thisWontBeFormatted (2, 90 ,)
|
||||||
| ^
|
| ^
|
||||||
6 |
|
6 |
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ exports[`range.js format 1`] = `
|
|||||||
> 2 | };
|
> 2 | };
|
||||||
| ^^
|
| ^^
|
||||||
> 3 |
|
> 3 |
|
||||||
| ^^
|
| ^
|
||||||
> 4 | foo(module { export let foo = "foo"; })
|
> 4 | foo(module { export let foo = "foo"; })
|
||||||
| ^^
|
| ^^
|
||||||
5 |
|
5 |
|
||||||
|
|||||||
@@ -604,9 +604,9 @@ exports[`multiple-statements.js format 1`] = `
|
|||||||
> 7 | );
|
> 7 | );
|
||||||
| ^^
|
| ^^
|
||||||
> 8 |
|
> 8 |
|
||||||
| ^^
|
| ^
|
||||||
> 9 | call(
|
> 9 | call(
|
||||||
| ^^
|
| ^^^^^
|
||||||
> 10 | 1, 2,3
|
> 10 | 1, 2,3
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
11 | );
|
11 | );
|
||||||
@@ -646,17 +646,17 @@ exports[`multiple-statements2.js format 1`] = `
|
|||||||
> 5 | call(
|
> 5 | call(
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
> 6 | 1, 2,3
|
> 6 | 1, 2,3
|
||||||
| ^^^^^
|
| ^^^^^^^^
|
||||||
> 7 | );
|
> 7 | );
|
||||||
| ^^^^^
|
| ^^
|
||||||
> 8 |
|
> 8 |
|
||||||
| ^^^^^
|
| ^
|
||||||
> 9 | call(
|
> 9 | call(
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
> 10 | 1, 2,3
|
> 10 | 1, 2,3
|
||||||
| ^^^^^
|
| ^^^^^^^^
|
||||||
> 11 | );
|
> 11 | );
|
||||||
| ^^^^^
|
| ^^
|
||||||
> 12 |
|
> 12 |
|
||||||
| ^
|
| ^
|
||||||
13 | call(
|
13 | call(
|
||||||
@@ -691,7 +691,7 @@ exports[`nested.js format 1`] = `
|
|||||||
> 2 | if (condition) {
|
> 2 | if (condition) {
|
||||||
| ^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^
|
||||||
> 3 | body
|
> 3 | body
|
||||||
| ^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^
|
||||||
> 4 | }
|
> 4 | }
|
||||||
| ^^^
|
| ^^^
|
||||||
5 | }
|
5 | }
|
||||||
@@ -821,9 +821,9 @@ exports[`object-expression2.js format 1`] = `
|
|||||||
> 6 | {
|
> 6 | {
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
> 7 | a: 1,
|
> 7 | a: 1,
|
||||||
| ^^^^^
|
| ^^^^^^^^^^^^^^^^^^^
|
||||||
> 8 | b:2
|
> 8 | b:2
|
||||||
| ^^^^^
|
| ^^^^^^^^^^^^^^^^^
|
||||||
> 9 | },
|
> 9 | },
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
10 | ]
|
10 | ]
|
||||||
@@ -890,7 +890,7 @@ exports[`range-end.js format 1`] = `
|
|||||||
> 7 | call(
|
> 7 | call(
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
> 8 | 1, 2,3
|
> 8 | 1, 2,3
|
||||||
| ^^^^^
|
| ^^^^^^^^
|
||||||
> 9 | );
|
> 9 | );
|
||||||
| ^^
|
| ^^
|
||||||
: =====================================output=====================================
|
: =====================================output=====================================
|
||||||
@@ -916,7 +916,7 @@ exports[`range-start.js format 1`] = `
|
|||||||
> 2 | 1, 2,3
|
> 2 | 1, 2,3
|
||||||
| ^^^^^^^^
|
| ^^^^^^^^
|
||||||
> 3 | );
|
> 3 | );
|
||||||
| ^^^^^^^^
|
| ^^
|
||||||
> 4 |
|
> 4 |
|
||||||
| ^
|
| ^
|
||||||
5 |
|
5 |
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ exports[`cross-array.json format 1`] = `
|
|||||||
> 5 | 8
|
> 5 | 8
|
||||||
| ^
|
| ^
|
||||||
> 6 | ],
|
> 6 | ],
|
||||||
| ^
|
| ^^
|
||||||
> 7 | b: [1, 2, 3, 4],
|
> 7 | b: [1, 2, 3, 4],
|
||||||
| ^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^
|
||||||
8 | c: [1, 2]
|
8 | c: [1, 2]
|
||||||
|
|||||||
@@ -35,11 +35,11 @@ exports[`issue-4926.ts format 1`] = `
|
|||||||
> 5 | for (let attr in this) {
|
> 5 | for (let attr in this) {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
> 6 | if (this[attr] !== keyevent[attr]) return false
|
> 6 | if (this[attr] !== keyevent[attr]) return false
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
> 7 | }
|
> 7 | }
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^
|
||||||
> 8 | return true
|
> 8 | return true
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^
|
||||||
> 9 | }
|
> 9 | }
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
10 | }
|
10 | }
|
||||||
|
|||||||
Vendored
+10
-27
@@ -1,8 +1,8 @@
|
|||||||
// node_modules/@babel/code-frame/lib/common-BO7XIBW3.js
|
// node_modules/@babel/code-frame/lib/common-shared.js
|
||||||
var NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
|
var NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
|
||||||
function getMarkerLines(loc, source, opts, startLineBaseZero) {
|
function getMarkerLines(loc, source, opts, startLineBaseZero) {
|
||||||
const startLoc = {
|
const startLoc = {
|
||||||
column: 0,
|
column: null,
|
||||||
line: -1,
|
line: -1,
|
||||||
...loc.start
|
...loc.start
|
||||||
};
|
};
|
||||||
@@ -31,27 +31,29 @@ function getMarkerLines(loc, source, opts, startLineBaseZero) {
|
|||||||
if (lineDiff) {
|
if (lineDiff) {
|
||||||
for (let i = 0; i <= lineDiff; i++) {
|
for (let i = 0; i <= lineDiff; i++) {
|
||||||
const lineNumber = i + startLine;
|
const lineNumber = i + startLine;
|
||||||
if (!startColumn) {
|
if (startColumn == null) {
|
||||||
markerLines[lineNumber] = true;
|
markerLines[lineNumber] = true;
|
||||||
} else if (i === 0) {
|
} else if (i === 0) {
|
||||||
const sourceLength = source[lineNumber - 1].length;
|
const sourceLength = source[lineNumber - 1].length;
|
||||||
markerLines[lineNumber] = [startColumn, sourceLength - startColumn + 1];
|
markerLines[lineNumber] = [startColumn, sourceLength - startColumn];
|
||||||
} else if (i === lineDiff) {
|
} else if (i === lineDiff) {
|
||||||
markerLines[lineNumber] = [0, endColumn];
|
markerLines[lineNumber] = [0, endColumn];
|
||||||
} else {
|
} else {
|
||||||
const sourceLength = source[lineNumber - i].length;
|
const sourceLength = source[lineNumber - 1].length;
|
||||||
markerLines[lineNumber] = [0, sourceLength];
|
markerLines[lineNumber] = [0, sourceLength];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (startColumn === endColumn) {
|
if (startColumn === endColumn) {
|
||||||
if (startColumn) {
|
if (startColumn != null) {
|
||||||
markerLines[startLine] = [startColumn, 0];
|
markerLines[startLine] = [startColumn, 0];
|
||||||
} else {
|
} else {
|
||||||
markerLines[startLine] = true;
|
markerLines[startLine] = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
markerLines[startLine] = [startColumn, endColumn - startColumn];
|
const safeStart = startColumn ?? 0;
|
||||||
|
const safeEnd = endColumn ?? safeStart;
|
||||||
|
markerLines[startLine] = [safeStart, safeEnd - safeStart];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
@@ -92,7 +94,7 @@ function _codeFrameColumns(rawLines, loc, opts = {}, colorOpts) {
|
|||||||
if (hasMarker) {
|
if (hasMarker) {
|
||||||
let markerLine = "";
|
let markerLine = "";
|
||||||
if (Array.isArray(hasMarker)) {
|
if (Array.isArray(hasMarker)) {
|
||||||
const markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " ");
|
const markerSpacing = line.slice(0, hasMarker[0]).replace(/[^\t]/g, " ");
|
||||||
const numberOfMarkers = hasMarker[1] || 1;
|
const numberOfMarkers = hasMarker[1] || 1;
|
||||||
markerLine = ["\n ", defs.gutter(gutter.replace(/\d/g, " ")), " ", markerSpacing, defs.marker("^").repeat(numberOfMarkers)].join("");
|
markerLine = ["\n ", defs.gutter(gutter.replace(/\d/g, " ")), " ", markerSpacing, defs.marker("^").repeat(numberOfMarkers)].join("");
|
||||||
if (lastMarkerLine && opts.message) {
|
if (lastMarkerLine && opts.message) {
|
||||||
@@ -112,32 +114,13 @@ ${frame}`;
|
|||||||
}
|
}
|
||||||
|
|
||||||
// node_modules/@babel/code-frame/lib/browser.js
|
// node_modules/@babel/code-frame/lib/browser.js
|
||||||
var deprecationWarningShown = false;
|
|
||||||
function codeFrameColumns(rawLines, loc, opts = {}) {
|
function codeFrameColumns(rawLines, loc, opts = {}) {
|
||||||
return _codeFrameColumns(rawLines, loc, opts);
|
return _codeFrameColumns(rawLines, loc, opts);
|
||||||
}
|
}
|
||||||
function browser(rawLines, lineNumber, colNumber, opts = {}) {
|
|
||||||
if (!deprecationWarningShown) {
|
|
||||||
deprecationWarningShown = true;
|
|
||||||
const message = "Passing lineNumber and colNumber is deprecated to @babel/code-frame. Please use `codeFrameColumns`.";
|
|
||||||
const deprecationError = new Error(message);
|
|
||||||
deprecationError.name = "DeprecationWarning";
|
|
||||||
console.warn(new Error(message));
|
|
||||||
}
|
|
||||||
colNumber = Math.max(colNumber, 0);
|
|
||||||
const location = {
|
|
||||||
start: {
|
|
||||||
column: colNumber,
|
|
||||||
line: lineNumber
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return codeFrameColumns(rawLines, location, opts);
|
|
||||||
}
|
|
||||||
function highlight(code) {
|
function highlight(code) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
export {
|
export {
|
||||||
codeFrameColumns,
|
codeFrameColumns,
|
||||||
browser as default,
|
|
||||||
highlight
|
highlight
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user