Fix bundled @babel/code-frame for test (#19340)

This commit is contained in:
fisker Cheung authored and GitHub committed 2026-06-10 23:58:54 +08:00
1 parent 2680e80adb
commit 21a8c81940
8 files changed
+48 -57

No files matched your search

+17 -6
View File
@@ -4,11 +4,11 @@ const path = require("node:path");
const root = path.join(__dirname, "../../");
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(
__dirname,
"../../.vscode/settings.example.json",
vscodeDirectory,
"settings.example.json",
);
if (fs.existsSync(settingsFile) || !fs.existsSync(settingsExampleFile)) {
@@ -29,8 +29,19 @@ module.exports = {
name: "plugin-prepare",
factory: () => ({
hooks: {
async afterAllInstalled({ cwd }) {
if (cwd !== root) {
async afterAllInstalled({ cwd: rawCwd }) {
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;
}
+2 -5
View File
@@ -1,5 +1,6 @@
import indexToPosition from "index-to-position";
import { codeFrameColumns } from "../../../vendors/babel-code-frame-for-test.js";
const codeFrameColumnsOptions = {
linesAbove: Number.POSITIVE_INFINITY,
linesBelow: Number.POSITIVE_INFINITY,
@@ -8,11 +9,7 @@ const codeFrameColumnsOptions = {
const locationForRange = (text, range) => {
const [start, end] = [...range]
.sort((indexA, indexB) => indexA - indexB)
.map((index) => indexToPosition(text, index, { oneBased: true }));
if (start.line !== end.line) {
end.column -= 1;
}
.map((index) => indexToPosition(text, index, { oneBasedLine: true }));
return { start, end };
};
@@ -519,7 +519,7 @@ exports[`range-3.js format 1`] = `
> 3 | thisWillBeFormatted (2 ,3, )
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 4 |
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^
> 5 | thisWontBeFormatted (2, 90 ,)
| ^
6 |
@@ -625,7 +625,7 @@ exports[`range-8.js format 1`] = `
> 3 | thisWillBeFormatted (2 ,3, )<|>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 4 |
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^
> 5 | thisWontBeFormatted (2, 90 ,)
| ^
6 |
@@ -237,7 +237,7 @@ exports[`range.js format 1`] = `
> 2 | };
| ^^
> 3 |
| ^^
| ^
> 4 | foo(module { export let foo = "foo"; })
| ^^
5 |
@@ -604,9 +604,9 @@ exports[`multiple-statements.js format 1`] = `
> 7 | );
| ^^
> 8 |
| ^^
| ^
> 9 | call(
| ^^
| ^^^^^
> 10 | 1, 2,3
| ^^^^^
11 | );
@@ -646,17 +646,17 @@ exports[`multiple-statements2.js format 1`] = `
> 5 | call(
| ^^^^^
> 6 | 1, 2,3
| ^^^^^
| ^^^^^^^^
> 7 | );
| ^^^^^
| ^^
> 8 |
| ^^^^^
| ^
> 9 | call(
| ^^^^^
> 10 | 1, 2,3
| ^^^^^
| ^^^^^^^^
> 11 | );
| ^^^^^
| ^^
> 12 |
| ^
13 | call(
@@ -691,7 +691,7 @@ exports[`nested.js format 1`] = `
> 2 | if (condition) {
| ^^^^^^^^^^^^^^^^^^
> 3 | body
| ^^^^^^^^^^^^^^^^^^
| ^^^^^^^^
> 4 | }
| ^^^
5 | }
@@ -821,9 +821,9 @@ exports[`object-expression2.js format 1`] = `
> 6 | {
| ^^^^^
> 7 | a: 1,
| ^^^^^
| ^^^^^^^^^^^^^^^^^^^
> 8 | b:2
| ^^^^^
| ^^^^^^^^^^^^^^^^^
> 9 | },
| ^^^^^^
10 | ]
@@ -890,7 +890,7 @@ exports[`range-end.js format 1`] = `
> 7 | call(
| ^^^^^
> 8 | 1, 2,3
| ^^^^^
| ^^^^^^^^
> 9 | );
| ^^
: =====================================output=====================================
@@ -916,7 +916,7 @@ exports[`range-start.js format 1`] = `
> 2 | 1, 2,3
| ^^^^^^^^
> 3 | );
| ^^^^^^^^
| ^^
> 4 |
| ^
5 |
@@ -15,7 +15,7 @@ exports[`cross-array.json format 1`] = `
> 5 | 8
| ^
> 6 | ],
| ^
| ^^
> 7 | b: [1, 2, 3, 4],
| ^^^^^^^^^^^^^
8 | c: [1, 2]
@@ -35,11 +35,11 @@ exports[`issue-4926.ts format 1`] = `
> 5 | for (let attr in this) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 6 | if (this[attr] !== keyevent[attr]) return false
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 7 | }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^
> 8 | return true
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^
> 9 | }
| ^^^^^
10 | }
+10 -27
View File
@@ -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]/;
function getMarkerLines(loc, source, opts, startLineBaseZero) {
const startLoc = {
column: 0,
column: null,
line: -1,
...loc.start
};
@@ -31,27 +31,29 @@ function getMarkerLines(loc, source, opts, startLineBaseZero) {
if (lineDiff) {
for (let i = 0; i <= lineDiff; i++) {
const lineNumber = i + startLine;
if (!startColumn) {
if (startColumn == null) {
markerLines[lineNumber] = true;
} else if (i === 0) {
const sourceLength = source[lineNumber - 1].length;
markerLines[lineNumber] = [startColumn, sourceLength - startColumn + 1];
markerLines[lineNumber] = [startColumn, sourceLength - startColumn];
} else if (i === lineDiff) {
markerLines[lineNumber] = [0, endColumn];
} else {
const sourceLength = source[lineNumber - i].length;
const sourceLength = source[lineNumber - 1].length;
markerLines[lineNumber] = [0, sourceLength];
}
}
} else {
if (startColumn === endColumn) {
if (startColumn) {
if (startColumn != null) {
markerLines[startLine] = [startColumn, 0];
} else {
markerLines[startLine] = true;
}
} else {
markerLines[startLine] = [startColumn, endColumn - startColumn];
const safeStart = startColumn ?? 0;
const safeEnd = endColumn ?? safeStart;
markerLines[startLine] = [safeStart, safeEnd - safeStart];
}
}
return {
@@ -92,7 +94,7 @@ function _codeFrameColumns(rawLines, loc, opts = {}, colorOpts) {
if (hasMarker) {
let markerLine = "";
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;
markerLine = ["\n ", defs.gutter(gutter.replace(/\d/g, " ")), " ", markerSpacing, defs.marker("^").repeat(numberOfMarkers)].join("");
if (lastMarkerLine && opts.message) {
@@ -112,32 +114,13 @@ ${frame}`;
}
// node_modules/@babel/code-frame/lib/browser.js
var deprecationWarningShown = false;
function 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) {
return code;
}
export {
codeFrameColumns,
browser as default,
highlight
};