diff --git a/.yarn/plugins/plugin-prepare.cjs b/.yarn/plugins/plugin-prepare.cjs index 52a8087ea..25bc38228 100644 --- a/.yarn/plugins/plugin-prepare.cjs +++ b/.yarn/plugins/plugin-prepare.cjs @@ -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; } diff --git a/tests/config/format-test/visualize-range.js b/tests/config/format-test/visualize-range.js index 8eb0da4e3..6a4b228ad 100644 --- a/tests/config/format-test/visualize-range.js +++ b/tests/config/format-test/visualize-range.js @@ -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 }; }; diff --git a/tests/format/js/cursor/__snapshots__/format.test.js.snap b/tests/format/js/cursor/__snapshots__/format.test.js.snap index 60407b2c0..e37574577 100644 --- a/tests/format/js/cursor/__snapshots__/format.test.js.snap +++ b/tests/format/js/cursor/__snapshots__/format.test.js.snap @@ -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 | diff --git a/tests/format/js/module-blocks/__snapshots__/format.test.js.snap b/tests/format/js/module-blocks/__snapshots__/format.test.js.snap index 1aa98d3c5..1282bd018 100644 --- a/tests/format/js/module-blocks/__snapshots__/format.test.js.snap +++ b/tests/format/js/module-blocks/__snapshots__/format.test.js.snap @@ -237,7 +237,7 @@ exports[`range.js format 1`] = ` > 2 | }; | ^^ > 3 | - | ^^ + | ^ > 4 | foo(module { export let foo = "foo"; }) | ^^ 5 | diff --git a/tests/format/js/range/__snapshots__/format.test.js.snap b/tests/format/js/range/__snapshots__/format.test.js.snap index 6679d1dbb..a3dfd474a 100644 --- a/tests/format/js/range/__snapshots__/format.test.js.snap +++ b/tests/format/js/range/__snapshots__/format.test.js.snap @@ -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 | diff --git a/tests/format/json/range/__snapshots__/format.test.js.snap b/tests/format/json/range/__snapshots__/format.test.js.snap index c9436edb0..12438e99b 100644 --- a/tests/format/json/range/__snapshots__/format.test.js.snap +++ b/tests/format/json/range/__snapshots__/format.test.js.snap @@ -15,7 +15,7 @@ exports[`cross-array.json format 1`] = ` > 5 | 8 | ^ > 6 | ], - | ^ + | ^^ > 7 | b: [1, 2, 3, 4], | ^^^^^^^^^^^^^ 8 | c: [1, 2] diff --git a/tests/format/typescript/range/__snapshots__/format.test.js.snap b/tests/format/typescript/range/__snapshots__/format.test.js.snap index ff19917cb..9dcf2f0c7 100644 --- a/tests/format/typescript/range/__snapshots__/format.test.js.snap +++ b/tests/format/typescript/range/__snapshots__/format.test.js.snap @@ -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 | } diff --git a/vendors/babel-code-frame-for-test.js b/vendors/babel-code-frame-for-test.js index 3d76b7522..09b736026 100644 --- a/vendors/babel-code-frame-for-test.js +++ b/vendors/babel-code-frame-for-test.js @@ -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 };