From feb6b519ee0e23eeb272227825ad84ecf1af05ab Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Mon, 30 May 2022 13:44:54 +0800 Subject: [PATCH 1/4] Update release script (#12591) --- .../__tests__/steps/publish-to-npm.spec.js | 2 +- .../__tests__/steps/version-check.spec.js | 15 ++++ scripts/release/release.js | 16 ++-- scripts/release/steps/publish-to-npm.js | 57 +------------- .../show-instructions-after-npm-publish.js | 58 ++++++++++++++ scripts/release/steps/wait-for-bot-release.js | 78 +++++++++++++++++++ 6 files changed, 165 insertions(+), 61 deletions(-) create mode 100644 scripts/release/__tests__/steps/version-check.spec.js create mode 100644 scripts/release/steps/show-instructions-after-npm-publish.js create mode 100644 scripts/release/steps/wait-for-bot-release.js diff --git a/scripts/release/__tests__/steps/publish-to-npm.spec.js b/scripts/release/__tests__/steps/publish-to-npm.spec.js index d663e0e7e..ced6df5ef 100644 --- a/scripts/release/__tests__/steps/publish-to-npm.spec.js +++ b/scripts/release/__tests__/steps/publish-to-npm.spec.js @@ -1,4 +1,4 @@ -import { getReleaseUrl } from "../../steps/publish-to-npm.js"; +import { getReleaseUrl } from "../../steps/show-instructions-after-npm-publish.js"; describe("publish-to-npm", () => { describe("getReleaseUrl", () => { diff --git a/scripts/release/__tests__/steps/version-check.spec.js b/scripts/release/__tests__/steps/version-check.spec.js new file mode 100644 index 000000000..478f3a532 --- /dev/null +++ b/scripts/release/__tests__/steps/version-check.spec.js @@ -0,0 +1,15 @@ +import { isVersionReleased } from "../../steps/wait-for-bot-release.js"; + +describe("isVersionReleased", () => { + test("returns true for existing version", async () => { + const result = await isVersionReleased("1.0.0"); + expect(result).toBe(true); + }); + test("rejects true for non-existing version", async () => { + await expect( + isVersionReleased("999.0.0") + ).rejects.toThrowErrorMatchingInlineSnapshot( + '"prettier@999.0.0 doesn\'t exit."' + ); + }); +}); diff --git a/scripts/release/release.js b/scripts/release/release.js index 56bec2599..9f78aeda8 100644 --- a/scripts/release/release.js +++ b/scripts/release/release.js @@ -15,8 +15,9 @@ async function run() { const params = minimist(process.argv.slice(2), { string: ["version"], - boolean: ["dry"], + boolean: ["dry", "manual"], alias: { v: "version" }, + default: { manual: false }, }); const { stdout: previousVersion } = await runGit([ @@ -39,16 +40,21 @@ async function run() { "./steps/validate-new-version.js", "./steps/check-git-status.js", "./steps/install-dependencies.js", - "./steps/run-tests.js", + params.manual && "./steps/run-tests.js", "./steps/update-version.js", - "./steps/generate-bundles.js", + params.manual && "./steps/generate-bundles.js", "./steps/update-changelog.js", "./steps/push-to-git.js", - "./steps/publish-to-npm.js", + params.manual + ? "./steps/publish-to-npm.js" + : "./steps/wait-for-bot-release.js", + "./steps/show-instructions-after-npm-publish.js", "./steps/update-dependents-count.js", "./steps/bump-prettier.js", "./steps/post-publish-steps.js", - ].map((step) => importDefault(step)) + ] + .filter(Boolean) + .map((step) => importDefault(step)) ); try { diff --git a/scripts/release/steps/publish-to-npm.js b/scripts/release/steps/publish-to-npm.js index 59fbd90d2..775c0e439 100644 --- a/scripts/release/steps/publish-to-npm.js +++ b/scripts/release/steps/publish-to-npm.js @@ -1,16 +1,6 @@ -import chalk from "chalk"; -import outdent from "outdent"; import { execa } from "execa"; -import semver from "semver"; import enquirer from "enquirer"; -import { - getBlogPostInfo, - getChangelogContent, - logPromise, - waitForEnter, -} from "../utils.js"; - -const outdentString = outdent.string; +import { logPromise } from "../utils.js"; /** * Retry "npm publish" when to enter OTP is failed. @@ -37,53 +27,10 @@ async function retryNpmPublish() { } } -export function getReleaseUrl(version, previousVersion) { - const semverDiff = semver.diff(version, previousVersion); - const isPatch = semverDiff === "patch"; - let body; - if (isPatch) { - const urlToChangelog = - "https://github.com/prettier/prettier/blob/main/CHANGELOG.md#" + - version.split(".").join(""); - body = `🔗 [Changelog](${urlToChangelog})`; - } else { - const blogPostInfo = getBlogPostInfo(version); - body = getChangelogContent({ - version, - previousVersion, - body: `🔗 [Release note](https://prettier.io/${blogPostInfo.path})`, - }); - } - body = encodeURIComponent(body); - return `https://github.com/prettier/prettier/releases/new?tag=${version}&title=${version}&body=${body}`; -} - -export default async function publishToNpm({ dry, version, previousVersion }) { +export default async function publishToNpm({ dry }) { if (dry) { return; } await logPromise("Publishing to npm", retryNpmPublish()); - - const releaseUrl = getReleaseUrl(version, previousVersion); - - console.log( - outdentString(chalk` - {green.bold Prettier ${version} published!} - - {yellow.bold Some manual steps are necessary.} - - {bold.underline Create a GitHub Release} - - Go to {cyan.underline ${releaseUrl}} - - Press {bgGreen.black Publish release } - - {bold.underline Test the new release} - - In a new session, run {yellow npm i prettier@latest} in another directory - - Test the API and CLI - - After that, we can proceed to bump this repo's Prettier dependency. - Press ENTER to continue. - `) - ); - await waitForEnter(); } diff --git a/scripts/release/steps/show-instructions-after-npm-publish.js b/scripts/release/steps/show-instructions-after-npm-publish.js new file mode 100644 index 000000000..5a015ca5f --- /dev/null +++ b/scripts/release/steps/show-instructions-after-npm-publish.js @@ -0,0 +1,58 @@ +import chalk from "chalk"; +import outdent from "outdent"; +import semver from "semver"; +import { + getBlogPostInfo, + getChangelogContent, + waitForEnter, +} from "../utils.js"; + +const outdentString = outdent.string; + +export function getReleaseUrl(version, previousVersion) { + const semverDiff = semver.diff(version, previousVersion); + const isPatch = semverDiff === "patch"; + let body; + if (isPatch) { + const urlToChangelog = + "https://github.com/prettier/prettier/blob/main/CHANGELOG.md#" + + version.split(".").join(""); + body = `🔗 [Changelog](${urlToChangelog})`; + } else { + const blogPostInfo = getBlogPostInfo(version); + body = getChangelogContent({ + version, + previousVersion, + body: `🔗 [Release note](https://prettier.io/${blogPostInfo.path})`, + }); + } + body = encodeURIComponent(body); + return `https://github.com/prettier/prettier/releases/new?tag=${version}&title=${version}&body=${body}`; +} + +export default async function showInstructionsAfterNpmPublish({ + version, + previousVersion, +}) { + const releaseUrl = getReleaseUrl(version, previousVersion); + + console.log( + outdentString(chalk` + {green.bold Prettier ${version} published!} + + {yellow.bold Some manual steps are necessary.} + + {bold.underline Create a GitHub Release} + - Go to {cyan.underline ${releaseUrl}} + - Press {bgGreen.black Publish release } + + {bold.underline Test the new release} + - In a new session, run {yellow npm i prettier@latest} in another directory + - Test the API and CLI + + After that, we can proceed to bump this repo's Prettier dependency. + Press ENTER to continue. + `) + ); + await waitForEnter(); +} diff --git a/scripts/release/steps/wait-for-bot-release.js b/scripts/release/steps/wait-for-bot-release.js new file mode 100644 index 000000000..c17a97338 --- /dev/null +++ b/scripts/release/steps/wait-for-bot-release.js @@ -0,0 +1,78 @@ +import chalk from "chalk"; +import outdent from "outdent"; +import fetch from "node-fetch"; +import { waitForEnter, logPromise } from "../utils.js"; + +const outdentString = outdent.string; + +export async function isVersionReleased(version) { + const response = await fetch("https://registry.npmjs.org/prettier/"); + const result = await response.json(); + const versionExists = version in result.time; + + if (!versionExists) { + throw new Error(`prettier@${version} doesn't exit.`); + } + + return versionExists; +} + +async function checkBotPermission() { + const response = await fetch("https://registry.npmjs.org/prettier/"); + const { maintainers } = await response.json(); + + return maintainers.some(({ name }) => name === "prettier-bot"); +} + +checkBotPermission(); + +const sleep = () => + new Promise((resolve) => { + setTimeout(resolve, 30_000); + }); + +export default async function waitForBotRelease({ dry, version }) { + if (dry) { + return; + } + + if (!(await checkBotPermission())) { + console.log( + outdentString(chalk/* indent */ ` + 1. Go to {green.underline https://www.npmjs.com/package/prettier/access} + 2. Add "{yellow prettier-bot}" as prettier package maintainer. + + Press ENTER to continue. + `) + ); + + await waitForEnter(); + } + + console.log( + outdentString(chalk/* indent */ ` + 1. Go to {green.underline https://github.com/prettier/release-workflow/actions/workflows/release.yml} + 2. Click "{green Run workflow}" button, type "{yellow.underline ${version}}" in "Version to release", uncheck all checkboxes, hit the "{bgGreen Run workflow}" button. + + Press ENTER to continue. + `) + ); + + await waitForEnter(); + + let released = false; + while (!released) { + try { + released = await logPromise( + "Checking release status", + isVersionReleased(version) + ); + } catch { + // No op + } + + if (!released) { + await logPromise("Wait for 30s", sleep()); + } + } +} From a808df643d2080358a885c168d77266481fbb40d Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Wed, 1 Jun 2022 06:47:51 +0900 Subject: [PATCH 2/4] Update `@typescript-eslint/typescript-estree` to `5.27.0` and move tests (#12959) * Install latest typescript-estree * Move tests for type parameter of typeof * Update changelog --- changelog_unreleased/typescript/12896.md | 2 +- package.json | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 16 ---------- .../__snapshots__/jsfmt.spec.js.snap | 14 +++++++++ .../instantiation-expression/typeof.ts} | 1 - yarn.lock | 30 +++++++++---------- 6 files changed, 31 insertions(+), 34 deletions(-) rename tests/format/{misc/typescript-babel-only/ts-4.7-instantiation-expression.ts => typescript/instantiation-expression/typeof.ts} (68%) diff --git a/changelog_unreleased/typescript/12896.md b/changelog_unreleased/typescript/12896.md index d1b07bd0d..0a3d95ee6 100644 --- a/changelog_unreleased/typescript/12896.md +++ b/changelog_unreleased/typescript/12896.md @@ -1,4 +1,4 @@ -#### [HIGHLIGHT]Support TypeScript 4.7 (#12896, #12897, #12898, #12900, #12921, #12924 by @sosukesuzuki) +#### [HIGHLIGHT]Support TypeScript 4.7 (#12896, #12897, #12898, #12900, #12921, #12924, #12959 by @sosukesuzuki) Support [TypeScript 4.7](https://devblogs.microsoft.com/typescript/announcing-typescript-4-7) new features! diff --git a/package.json b/package.json index b4efcf10d..d7b521eb9 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "@babel/parser": "7.18.0", "@glimmer/syntax": "0.84.2", "@iarna/toml": "2.2.5", - "@typescript-eslint/typescript-estree": "5.26.0", + "@typescript-eslint/typescript-estree": "5.27.0", "acorn": "8.7.0", "acorn-jsx": "5.3.2", "angular-estree-parser": "2.5.0", diff --git a/tests/format/misc/typescript-babel-only/__snapshots__/jsfmt.spec.js.snap b/tests/format/misc/typescript-babel-only/__snapshots__/jsfmt.spec.js.snap index 0bab1a843..9a2dd84d4 100644 --- a/tests/format/misc/typescript-babel-only/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/misc/typescript-babel-only/__snapshots__/jsfmt.spec.js.snap @@ -184,22 +184,6 @@ type Foo = ================================================================================ `; -exports[`ts-4.7-instantiation-expression.ts format 1`] = ` -====================================options===================================== -parsers: ["babel-ts"] -printWidth: 80 - | printWidth -=====================================input====================================== -// typeof -let x: typeof y.z; - -=====================================output===================================== -// typeof -let x: typeof y.z; - -================================================================================ -`; - exports[`tuple-labeled-ts.ts format 1`] = ` ====================================options===================================== parsers: ["babel-ts"] diff --git a/tests/format/typescript/instantiation-expression/__snapshots__/jsfmt.spec.js.snap b/tests/format/typescript/instantiation-expression/__snapshots__/jsfmt.spec.js.snap index 29fb2537b..974c9bdab 100644 --- a/tests/format/typescript/instantiation-expression/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/typescript/instantiation-expression/__snapshots__/jsfmt.spec.js.snap @@ -68,3 +68,17 @@ new A(); ================================================================================ `; + +exports[`typeof.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +let x: typeof y.z; + +=====================================output===================================== +let x: typeof y.z; + +================================================================================ +`; diff --git a/tests/format/misc/typescript-babel-only/ts-4.7-instantiation-expression.ts b/tests/format/typescript/instantiation-expression/typeof.ts similarity index 68% rename from tests/format/misc/typescript-babel-only/ts-4.7-instantiation-expression.ts rename to tests/format/typescript/instantiation-expression/typeof.ts index f5e71be1f..7287d407d 100644 --- a/tests/format/misc/typescript-babel-only/ts-4.7-instantiation-expression.ts +++ b/tests/format/typescript/instantiation-expression/typeof.ts @@ -1,2 +1 @@ -// typeof let x: typeof y.z; diff --git a/yarn.lock b/yarn.lock index 11c2f1955..046284e63 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1761,10 +1761,10 @@ resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.20.0.tgz#fa39c3c2aa786568302318f1cb51fcf64258c20c" integrity sha512-+d8wprF9GyvPwtoB4CxBAR/s0rpP25XKgnOvMf/gMXYDvlUC3rPFHupdTQ/ow9vn7UDe5rX02ovGYQbv/IUCbg== -"@typescript-eslint/types@5.26.0": - version "5.26.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.26.0.tgz#cb204bb154d3c103d9cc4d225f311b08219469f3" - integrity sha512-8794JZFE1RN4XaExLWLI2oSXsVImNkl79PzTOOWt9h0UHROwJedNOD2IJyfL0NbddFllcktGIO2aOu10avQQyA== +"@typescript-eslint/types@5.27.0": + version "5.27.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.27.0.tgz#c3f44b9dda6177a9554f94a74745ca495ba9c001" + integrity sha512-lY6C7oGm9a/GWhmUDOs3xAVRz4ty/XKlQ2fOLr8GAIryGn0+UBOoJDWyHer3UgrHkenorwvBnphhP+zPmzmw0A== "@typescript-eslint/typescript-estree@5.20.0": version "5.20.0" @@ -1779,13 +1779,13 @@ semver "^7.3.5" tsutils "^3.21.0" -"@typescript-eslint/typescript-estree@5.26.0": - version "5.26.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.26.0.tgz#16cbceedb0011c2ed4f607255f3ee1e6e43b88c3" - integrity sha512-EyGpw6eQDsfD6jIqmXP3rU5oHScZ51tL/cZgFbFBvWuCwrIptl+oueUZzSmLtxFuSOQ9vDcJIs+279gnJkfd1w== +"@typescript-eslint/typescript-estree@5.27.0": + version "5.27.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.27.0.tgz#7965f5b553c634c5354a47dcce0b40b94611e995" + integrity sha512-QywPMFvgZ+MHSLRofLI7BDL+UczFFHyj0vF5ibeChDAJgdTV8k4xgEwF0geFhVlPc1p8r70eYewzpo6ps+9LJQ== dependencies: - "@typescript-eslint/types" "5.26.0" - "@typescript-eslint/visitor-keys" "5.26.0" + "@typescript-eslint/types" "5.27.0" + "@typescript-eslint/visitor-keys" "5.27.0" debug "^4.3.4" globby "^11.1.0" is-glob "^4.0.3" @@ -1812,12 +1812,12 @@ "@typescript-eslint/types" "5.20.0" eslint-visitor-keys "^3.0.0" -"@typescript-eslint/visitor-keys@5.26.0": - version "5.26.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.26.0.tgz#7195f756e367f789c0e83035297c45b417b57f57" - integrity sha512-wei+ffqHanYDOQgg/fS6Hcar6wAWv0CUPQ3TZzOWd2BLfgP539rb49bwua8WRAs7R6kOSLn82rfEu2ro6Llt8Q== +"@typescript-eslint/visitor-keys@5.27.0": + version "5.27.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.27.0.tgz#97aa9a5d2f3df8215e6d3b77f9d214a24db269bd" + integrity sha512-46cYrteA2MrIAjv9ai44OQDUoCZyHeGIc4lsjCUX2WT6r4C+kidz1bNiR4017wHOPUythYeH+Sc7/cFP97KEAA== dependencies: - "@typescript-eslint/types" "5.26.0" + "@typescript-eslint/types" "5.27.0" eslint-visitor-keys "^3.3.0" abab@^2.0.3, abab@^2.0.5: From 83ec3c36e34864470a6cb88889d837c46777ab7d Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Wed, 1 Jun 2022 19:23:13 +0800 Subject: [PATCH 3/4] Build: stricter warning check (#12956) --- package.json | 2 +- scripts/build/bundler.mjs | 20 +- scripts/build/config.mjs | 5 +- .../build/esbuild-plugins/throw-warnings.mjs | 64 +++++- src/main/load-parser.js | 24 ++ src/main/parser.js | 19 +- yarn.lock | 208 +++++++++--------- 7 files changed, 206 insertions(+), 136 deletions(-) create mode 100644 src/main/load-parser.js diff --git a/package.json b/package.json index d7b521eb9..ec3ff7f23 100644 --- a/package.json +++ b/package.json @@ -105,7 +105,7 @@ "cross-env": "7.0.3", "cspell": "5.19.7", "enquirer": "2.3.6", - "esbuild": "0.14.38", + "esbuild": "0.14.42", "esbuild-visualizer": "0.3.1", "eslint": "8.14.0", "eslint-config-prettier": "8.5.0", diff --git a/scripts/build/bundler.mjs b/scripts/build/bundler.mjs index d58cca000..e1fe88b71 100644 --- a/scripts/build/bundler.mjs +++ b/scripts/build/bundler.mjs @@ -177,7 +177,9 @@ function* getEsbuildOptions(bundle, buildOptions) { }), buildOptions.reports && esbuildPluginVisualizer({ formats: buildOptions.reports }), - esbuildPluginThrowWarnings(), + esbuildPluginThrowWarnings({ + allowDynamicRequire: bundle.target === "node", + }), ].filter(Boolean), minify: shouldMinify, legalComments: "none", @@ -229,6 +231,12 @@ async function runBuild(bundle, esbuildOptions, buildOptions) { } const { format, plugins, outfile } = esbuildOptions; + const temporaryFile = path.join( + DIST_DIR, + `_${bundle.output}.${esbuildOptions.format}.${ + esbuildOptions.format === "esm" ? "mjs" : "js" + }` + ); await esbuild.build({ ...esbuildOptions, @@ -236,15 +244,16 @@ async function runBuild(bundle, esbuildOptions, buildOptions) { format: format === "umd" ? "cjs" : format, minify: false, target: undefined, + outfile: temporaryFile, }); - const text = await fs.readFile(outfile); + const text = await fs.readFile(temporaryFile); const { code } = await babel.transformAsync(text, { filename: outfile, ...getBabelConfig(bundle), }); - await fs.writeFile(outfile, code); + await fs.writeFile(temporaryFile, code); await esbuild.build({ ...esbuildOptions, @@ -252,9 +261,10 @@ async function runBuild(bundle, esbuildOptions, buildOptions) { plugins: plugins.filter( ({ name }) => name === "umd" || name === "throw-warnings" ), - entryPoints: [outfile], - allowOverwrite: true, + entryPoints: [temporaryFile], }); + + await fs.unlink(temporaryFile); } async function* createBundle(bundle, buildOptions) { diff --git a/scripts/build/config.mjs b/scripts/build/config.mjs index 5241d8255..4c55bd896 100644 --- a/scripts/build/config.mjs +++ b/scripts/build/config.mjs @@ -298,9 +298,8 @@ const coreBundles = [ }, replaceDiffPackageEntry("lib/diff/array.js"), { - module: path.join(PROJECT_ROOT, "src/main/parser.js"), - find: "return requireParser(opts.parser);", - replacement: "", + module: path.join(PROJECT_ROOT, "src/main/load-parser.js"), + text: "module.exports = () => {};", }, ], }, diff --git a/scripts/build/esbuild-plugins/throw-warnings.mjs b/scripts/build/esbuild-plugins/throw-warnings.mjs index 7148d1f1c..85c5a47ba 100644 --- a/scripts/build/esbuild-plugins/throw-warnings.mjs +++ b/scripts/build/esbuild-plugins/throw-warnings.mjs @@ -1,19 +1,71 @@ -const ignoredWarnings = new Set([ - // Duplicated case clause - "This case clause will never be evaluated because it duplicates an earlier case clause", -]); +// https://github.com/evanw/esbuild/commit/1916318ca7f803253dbdae0942af1c9a6d3a6910 +const ESBUILD_MESSAGE_IDS = [ + "assign-to-constant", + "call-import-namespace", + "commonjs-variable-in-esm", + "delete-super-property", + "direct-eval", + "duplicate-case", + "duplicate-object-key", + "empty-import-meta", + "equals-nan", + "equals-negative-zero", + "equals-new-object", + "html-comment-in-js", + "impossible-typeof", + "private-name-will-throw", + "semicolon-after-return", + "suspicious-boolean-not", + "this-is-undefined-in-esm", + "unsupported-dynamic-import", + "unsupported-jsx-comment", + "unsupported-regexp", + "unsupported-require-call", + "different-path-case", + "ignored-bare-import", + "ignored-dynamic-import", + "import-is-undefined", + "package.json", + "require-resolve-not-external", + "tsconfig.json", +]; +const logOverride = Object.fromEntries( + ESBUILD_MESSAGE_IDS.map((id) => [id, "warning"]) +); -export default function esbuildPluginThrowWarnings() { +export default function esbuildPluginThrowWarnings({ allowDynamicRequire }) { return { name: "throw-warnings", setup(build) { + const options = build.initialOptions; + options.logOverride = { + ...logOverride, + ...options.logOverride, + }; + build.onEnd((result) => { if (result.errors.length > 0) { return; } for (const warning of result.warnings) { - if (ignoredWarnings.has(warning.text)) { + if ( + allowDynamicRequire && + warning.text === + 'This call to "require" will not be bundled because the argument is not a string literal' + ) { + continue; + } + + if ( + [ + "node_modules/flow-parser/flow_parser.js", + "dist/_parser-flow.js.umd.js", + "dist/_parser-flow.js.esm.mjs", + ].includes(warning.location.file) && + warning.text === + "This case clause will never be evaluated because it duplicates an earlier case clause" + ) { continue; } diff --git a/src/main/load-parser.js b/src/main/load-parser.js new file mode 100644 index 000000000..177439681 --- /dev/null +++ b/src/main/load-parser.js @@ -0,0 +1,24 @@ +// This module only works in Node.js +// Will be replaced when bundling `standalone.js` + +"use strict"; + +const path = require("path"); +const { ConfigError } = require("../common/errors.js"); +const { locStart, locEnd } = require("../language-js/loc.js"); + +function requireParser(parser) { + try { + return { + parse: require(path.resolve(process.cwd(), parser)), + astFormat: "estree", + locStart, + locEnd, + }; + } catch { + /* istanbul ignore next */ + throw new ConfigError(`Couldn't resolve parser "${parser}"`); + } +} + +module.exports = requireParser; diff --git a/src/main/parser.js b/src/main/parser.js index bb1285f7d..a5c9606b9 100644 --- a/src/main/parser.js +++ b/src/main/parser.js @@ -1,8 +1,8 @@ "use strict"; -const path = require("path"); const { ConfigError } = require("../common/errors.js"); const jsLoc = require("../language-js/loc.js"); +const loadParser = require("./load-parser.js"); const { locStart, locEnd } = jsLoc; @@ -50,22 +50,7 @@ function resolveParser(opts, parsers = getParsers(opts)) { ); } - // This line of code will be removed when bundling `standalone.js` - return requireParser(opts.parser); - } -} - -function requireParser(parser) { - try { - return { - parse: require(path.resolve(process.cwd(), parser)), - astFormat: "estree", - locStart, - locEnd, - }; - } catch { - /* istanbul ignore next */ - throw new ConfigError(`Couldn't resolve parser "${parser}"`); + return loadParser(opts.parser); } } diff --git a/yarn.lock b/yarn.lock index 046284e63..1612dfd19 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2822,90 +2822,90 @@ es-to-primitive@^1.2.1: is-date-object "^1.0.1" is-symbol "^1.0.2" -esbuild-android-64@0.14.38: - version "0.14.38" - resolved "https://registry.yarnpkg.com/esbuild-android-64/-/esbuild-android-64-0.14.38.tgz#5b94a1306df31d55055f64a62ff6b763a47b7f64" - integrity sha512-aRFxR3scRKkbmNuGAK+Gee3+yFxkTJO/cx83Dkyzo4CnQl/2zVSurtG6+G86EQIZ+w+VYngVyK7P3HyTBKu3nw== +esbuild-android-64@0.14.42: + version "0.14.42" + resolved "https://registry.yarnpkg.com/esbuild-android-64/-/esbuild-android-64-0.14.42.tgz#d7ab3d44d3671218d22bce52f65642b12908d954" + integrity sha512-P4Y36VUtRhK/zivqGVMqhptSrFILAGlYp0Z8r9UQqHJ3iWztRCNWnlBzD9HRx0DbueXikzOiwyOri+ojAFfW6A== -esbuild-android-arm64@0.14.38: - version "0.14.38" - resolved "https://registry.yarnpkg.com/esbuild-android-arm64/-/esbuild-android-arm64-0.14.38.tgz#78acc80773d16007de5219ccce544c036abd50b8" - integrity sha512-L2NgQRWuHFI89IIZIlpAcINy9FvBk6xFVZ7xGdOwIm8VyhX1vNCEqUJO3DPSSy945Gzdg98cxtNt8Grv1CsyhA== +esbuild-android-arm64@0.14.42: + version "0.14.42" + resolved "https://registry.yarnpkg.com/esbuild-android-arm64/-/esbuild-android-arm64-0.14.42.tgz#45336d8bec49abddb3a022996a23373f45a57c27" + integrity sha512-0cOqCubq+RWScPqvtQdjXG3Czb3AWI2CaKw3HeXry2eoA2rrPr85HF7IpdU26UWdBXgPYtlTN1LUiuXbboROhg== -esbuild-darwin-64@0.14.38: - version "0.14.38" - resolved "https://registry.yarnpkg.com/esbuild-darwin-64/-/esbuild-darwin-64-0.14.38.tgz#e02b1291f629ebdc2aa46fabfacc9aa28ff6aa46" - integrity sha512-5JJvgXkX87Pd1Og0u/NJuO7TSqAikAcQQ74gyJ87bqWRVeouky84ICoV4sN6VV53aTW+NE87qLdGY4QA2S7KNA== +esbuild-darwin-64@0.14.42: + version "0.14.42" + resolved "https://registry.yarnpkg.com/esbuild-darwin-64/-/esbuild-darwin-64-0.14.42.tgz#6dff5e44cd70a88c33323e2f5fb598e40c68a9e0" + integrity sha512-ipiBdCA3ZjYgRfRLdQwP82rTiv/YVMtW36hTvAN5ZKAIfxBOyPXY7Cejp3bMXWgzKD8B6O+zoMzh01GZsCuEIA== -esbuild-darwin-arm64@0.14.38: - version "0.14.38" - resolved "https://registry.yarnpkg.com/esbuild-darwin-arm64/-/esbuild-darwin-arm64-0.14.38.tgz#01eb6650ec010b18c990e443a6abcca1d71290a9" - integrity sha512-eqF+OejMI3mC5Dlo9Kdq/Ilbki9sQBw3QlHW3wjLmsLh+quNfHmGMp3Ly1eWm981iGBMdbtSS9+LRvR2T8B3eQ== +esbuild-darwin-arm64@0.14.42: + version "0.14.42" + resolved "https://registry.yarnpkg.com/esbuild-darwin-arm64/-/esbuild-darwin-arm64-0.14.42.tgz#2c7313e1b12d2fa5b889c03213d682fb92ca8c4f" + integrity sha512-bU2tHRqTPOaoH/4m0zYHbFWpiYDmaA0gt90/3BMEFaM0PqVK/a6MA2V/ypV5PO0v8QxN6gH5hBPY4YJ2lopXgA== -esbuild-freebsd-64@0.14.38: - version "0.14.38" - resolved "https://registry.yarnpkg.com/esbuild-freebsd-64/-/esbuild-freebsd-64-0.14.38.tgz#790b8786729d4aac7be17648f9ea8e0e16475b5e" - integrity sha512-epnPbhZUt93xV5cgeY36ZxPXDsQeO55DppzsIgWM8vgiG/Rz+qYDLmh5ts3e+Ln1wA9dQ+nZmVHw+RjaW3I5Ig== +esbuild-freebsd-64@0.14.42: + version "0.14.42" + resolved "https://registry.yarnpkg.com/esbuild-freebsd-64/-/esbuild-freebsd-64-0.14.42.tgz#ad1c5a564a7e473b8ce95ee7f76618d05d6daffc" + integrity sha512-75h1+22Ivy07+QvxHyhVqOdekupiTZVLN1PMwCDonAqyXd8TVNJfIRFrdL8QmSJrOJJ5h8H1I9ETyl2L8LQDaw== -esbuild-freebsd-arm64@0.14.38: - version "0.14.38" - resolved "https://registry.yarnpkg.com/esbuild-freebsd-arm64/-/esbuild-freebsd-arm64-0.14.38.tgz#b66340ab28c09c1098e6d9d8ff656db47d7211e6" - integrity sha512-/9icXUYJWherhk+y5fjPI5yNUdFPtXHQlwP7/K/zg8t8lQdHVj20SqU9/udQmeUo5pDFHMYzcEFfJqgOVeKNNQ== +esbuild-freebsd-arm64@0.14.42: + version "0.14.42" + resolved "https://registry.yarnpkg.com/esbuild-freebsd-arm64/-/esbuild-freebsd-arm64-0.14.42.tgz#4bdb480234144f944f1930829bace7561135ddc7" + integrity sha512-W6Jebeu5TTDQMJUJVarEzRU9LlKpNkPBbjqSu+GUPTHDCly5zZEQq9uHkmHHl7OKm+mQ2zFySN83nmfCeZCyNA== -esbuild-linux-32@0.14.38: - version "0.14.38" - resolved "https://registry.yarnpkg.com/esbuild-linux-32/-/esbuild-linux-32-0.14.38.tgz#7927f950986fd39f0ff319e92839455912b67f70" - integrity sha512-QfgfeNHRFvr2XeHFzP8kOZVnal3QvST3A0cgq32ZrHjSMFTdgXhMhmWdKzRXP/PKcfv3e2OW9tT9PpcjNvaq6g== +esbuild-linux-32@0.14.42: + version "0.14.42" + resolved "https://registry.yarnpkg.com/esbuild-linux-32/-/esbuild-linux-32-0.14.42.tgz#ef18fd19f067e9d2b5f677d6b82fa81519f5a8c2" + integrity sha512-Ooy/Bj+mJ1z4jlWcK5Dl6SlPlCgQB9zg1UrTCeY8XagvuWZ4qGPyYEWGkT94HUsRi2hKsXvcs6ThTOjBaJSMfg== -esbuild-linux-64@0.14.38: - version "0.14.38" - resolved "https://registry.yarnpkg.com/esbuild-linux-64/-/esbuild-linux-64-0.14.38.tgz#4893d07b229d9cfe34a2b3ce586399e73c3ac519" - integrity sha512-uuZHNmqcs+Bj1qiW9k/HZU3FtIHmYiuxZ/6Aa+/KHb/pFKr7R3aVqvxlAudYI9Fw3St0VCPfv7QBpUITSmBR1Q== +esbuild-linux-64@0.14.42: + version "0.14.42" + resolved "https://registry.yarnpkg.com/esbuild-linux-64/-/esbuild-linux-64-0.14.42.tgz#d84e7333b1c1b22cf8b5b9dbb5dd9b2ecb34b79f" + integrity sha512-2L0HbzQfbTuemUWfVqNIjOfaTRt9zsvjnme6lnr7/MO9toz/MJ5tZhjqrG6uDWDxhsaHI2/nsDgrv8uEEN2eoA== -esbuild-linux-arm64@0.14.38: - version "0.14.38" - resolved "https://registry.yarnpkg.com/esbuild-linux-arm64/-/esbuild-linux-arm64-0.14.38.tgz#8442402e37d0b8ae946ac616784d9c1a2041056a" - integrity sha512-HlMGZTEsBrXrivr64eZ/EO0NQM8H8DuSENRok9d+Jtvq8hOLzrxfsAT9U94K3KOGk2XgCmkaI2KD8hX7F97lvA== +esbuild-linux-arm64@0.14.42: + version "0.14.42" + resolved "https://registry.yarnpkg.com/esbuild-linux-arm64/-/esbuild-linux-arm64-0.14.42.tgz#dc19e282f8c4ffbaa470c02a4d171e4ae0180cca" + integrity sha512-c3Ug3e9JpVr8jAcfbhirtpBauLxzYPpycjWulD71CF6ZSY26tvzmXMJYooQ2YKqDY4e/fPu5K8bm7MiXMnyxuA== -esbuild-linux-arm@0.14.38: - version "0.14.38" - resolved "https://registry.yarnpkg.com/esbuild-linux-arm/-/esbuild-linux-arm-0.14.38.tgz#d5dbf32d38b7f79be0ec6b5fb2f9251fd9066986" - integrity sha512-FiFvQe8J3VKTDXG01JbvoVRXQ0x6UZwyrU4IaLBZeq39Bsbatd94Fuc3F1RGqPF5RbIWW7RvkVQjn79ejzysnA== +esbuild-linux-arm@0.14.42: + version "0.14.42" + resolved "https://registry.yarnpkg.com/esbuild-linux-arm/-/esbuild-linux-arm-0.14.42.tgz#d49870e63e2242b8156bf473f2ee5154226be328" + integrity sha512-STq69yzCMhdRaWnh29UYrLSr/qaWMm/KqwaRF1pMEK7kDiagaXhSL1zQGXbYv94GuGY/zAwzK98+6idCMUOOCg== -esbuild-linux-mips64le@0.14.38: - version "0.14.38" - resolved "https://registry.yarnpkg.com/esbuild-linux-mips64le/-/esbuild-linux-mips64le-0.14.38.tgz#95081e42f698bbe35d8ccee0e3a237594b337eb5" - integrity sha512-qd1dLf2v7QBiI5wwfil9j0HG/5YMFBAmMVmdeokbNAMbcg49p25t6IlJFXAeLzogv1AvgaXRXvgFNhScYEUXGQ== +esbuild-linux-mips64le@0.14.42: + version "0.14.42" + resolved "https://registry.yarnpkg.com/esbuild-linux-mips64le/-/esbuild-linux-mips64le-0.14.42.tgz#f4e6ff9bf8a6f175470498826f48d093b054fc22" + integrity sha512-QuvpHGbYlkyXWf2cGm51LBCHx6eUakjaSrRpUqhPwjh/uvNUYvLmz2LgPTTPwCqaKt0iwL+OGVL0tXA5aDbAbg== -esbuild-linux-ppc64le@0.14.38: - version "0.14.38" - resolved "https://registry.yarnpkg.com/esbuild-linux-ppc64le/-/esbuild-linux-ppc64le-0.14.38.tgz#dceb0a1b186f5df679618882a7990bd422089b47" - integrity sha512-mnbEm7o69gTl60jSuK+nn+pRsRHGtDPfzhrqEUXyCl7CTOCLtWN2bhK8bgsdp6J/2NyS/wHBjs1x8aBWwP2X9Q== +esbuild-linux-ppc64le@0.14.42: + version "0.14.42" + resolved "https://registry.yarnpkg.com/esbuild-linux-ppc64le/-/esbuild-linux-ppc64le-0.14.42.tgz#ac9c66fc80ba9f8fda15a4cc08f4e55f6c0aed63" + integrity sha512-8ohIVIWDbDT+i7lCx44YCyIRrOW1MYlks9fxTo0ME2LS/fxxdoJBwHWzaDYhjvf8kNpA+MInZvyOEAGoVDrMHg== -esbuild-linux-riscv64@0.14.38: - version "0.14.38" - resolved "https://registry.yarnpkg.com/esbuild-linux-riscv64/-/esbuild-linux-riscv64-0.14.38.tgz#61fb8edb75f475f9208c4a93ab2bfab63821afd2" - integrity sha512-+p6YKYbuV72uikChRk14FSyNJZ4WfYkffj6Af0/Tw63/6TJX6TnIKE+6D3xtEc7DeDth1fjUOEqm+ApKFXbbVQ== +esbuild-linux-riscv64@0.14.42: + version "0.14.42" + resolved "https://registry.yarnpkg.com/esbuild-linux-riscv64/-/esbuild-linux-riscv64-0.14.42.tgz#21e0ae492a3a9bf4eecbfc916339a66e204256d0" + integrity sha512-DzDqK3TuoXktPyG1Lwx7vhaF49Onv3eR61KwQyxYo4y5UKTpL3NmuarHSIaSVlTFDDpcIajCDwz5/uwKLLgKiQ== -esbuild-linux-s390x@0.14.38: - version "0.14.38" - resolved "https://registry.yarnpkg.com/esbuild-linux-s390x/-/esbuild-linux-s390x-0.14.38.tgz#34c7126a4937406bf6a5e69100185fd702d12fe0" - integrity sha512-0zUsiDkGJiMHxBQ7JDU8jbaanUY975CdOW1YDrurjrM0vWHfjv9tLQsW9GSyEb/heSK1L5gaweRjzfUVBFoybQ== +esbuild-linux-s390x@0.14.42: + version "0.14.42" + resolved "https://registry.yarnpkg.com/esbuild-linux-s390x/-/esbuild-linux-s390x-0.14.42.tgz#06d40b957250ffd9a2183bfdfc9a03d6fd21b3e8" + integrity sha512-YFRhPCxl8nb//Wn6SiS5pmtplBi4z9yC2gLrYoYI/tvwuB1jldir9r7JwAGy1Ck4D7sE7wBN9GFtUUX/DLdcEQ== -esbuild-netbsd-64@0.14.38: - version "0.14.38" - resolved "https://registry.yarnpkg.com/esbuild-netbsd-64/-/esbuild-netbsd-64-0.14.38.tgz#322ea9937d9e529183ee281c7996b93eb38a5d95" - integrity sha512-cljBAApVwkpnJZfnRVThpRBGzCi+a+V9Ofb1fVkKhtrPLDYlHLrSYGtmnoTVWDQdU516qYI8+wOgcGZ4XIZh0Q== +esbuild-netbsd-64@0.14.42: + version "0.14.42" + resolved "https://registry.yarnpkg.com/esbuild-netbsd-64/-/esbuild-netbsd-64-0.14.42.tgz#185664f05f10914f14ed43bd9e22b7de584267f7" + integrity sha512-QYSD2k+oT9dqB/4eEM9c+7KyNYsIPgzYOSrmfNGDIyJrbT1d+CFVKvnKahDKNJLfOYj8N4MgyFaU9/Ytc6w5Vw== -esbuild-openbsd-64@0.14.38: - version "0.14.38" - resolved "https://registry.yarnpkg.com/esbuild-openbsd-64/-/esbuild-openbsd-64-0.14.38.tgz#1ca29bb7a2bf09592dcc26afdb45108f08a2cdbd" - integrity sha512-CDswYr2PWPGEPpLDUO50mL3WO/07EMjnZDNKpmaxUPsrW+kVM3LoAqr/CE8UbzugpEiflYqJsGPLirThRB18IQ== +esbuild-openbsd-64@0.14.42: + version "0.14.42" + resolved "https://registry.yarnpkg.com/esbuild-openbsd-64/-/esbuild-openbsd-64-0.14.42.tgz#c29006f659eb4e55283044bbbd4eb4054fae8839" + integrity sha512-M2meNVIKWsm2HMY7+TU9AxM7ZVwI9havdsw6m/6EzdXysyCFFSoaTQ/Jg03izjCsK17FsVRHqRe26Llj6x0MNA== -esbuild-sunos-64@0.14.38: - version "0.14.38" - resolved "https://registry.yarnpkg.com/esbuild-sunos-64/-/esbuild-sunos-64-0.14.38.tgz#c9446f7d8ebf45093e7bb0e7045506a88540019b" - integrity sha512-2mfIoYW58gKcC3bck0j7lD3RZkqYA7MmujFYmSn9l6TiIcAMpuEvqksO+ntBgbLep/eyjpgdplF7b+4T9VJGOA== +esbuild-sunos-64@0.14.42: + version "0.14.42" + resolved "https://registry.yarnpkg.com/esbuild-sunos-64/-/esbuild-sunos-64-0.14.42.tgz#aa9eec112cd1e7105e7bb37000eca7d460083f8f" + integrity sha512-uXV8TAZEw36DkgW8Ak3MpSJs1ofBb3Smkc/6pZ29sCAN1KzCAQzsje4sUwugf+FVicrHvlamCOlFZIXgct+iqQ== esbuild-visualizer@0.3.1: version "0.3.1" @@ -2916,46 +2916,46 @@ esbuild-visualizer@0.3.1: open "^7.4.2" yargs "^16.2.0" -esbuild-windows-32@0.14.38: - version "0.14.38" - resolved "https://registry.yarnpkg.com/esbuild-windows-32/-/esbuild-windows-32-0.14.38.tgz#f8e9b4602fd0ccbd48e5c8d117ec0ba4040f2ad1" - integrity sha512-L2BmEeFZATAvU+FJzJiRLFUP+d9RHN+QXpgaOrs2klshoAm1AE6Us4X6fS9k33Uy5SzScn2TpcgecbqJza1Hjw== +esbuild-windows-32@0.14.42: + version "0.14.42" + resolved "https://registry.yarnpkg.com/esbuild-windows-32/-/esbuild-windows-32-0.14.42.tgz#c3fc450853c61a74dacc5679de301db23b73e61e" + integrity sha512-4iw/8qWmRICWi9ZOnJJf9sYt6wmtp3hsN4TdI5NqgjfOkBVMxNdM9Vt3626G1Rda9ya2Q0hjQRD9W1o+m6Lz6g== -esbuild-windows-64@0.14.38: - version "0.14.38" - resolved "https://registry.yarnpkg.com/esbuild-windows-64/-/esbuild-windows-64-0.14.38.tgz#280f58e69f78535f470905ce3e43db1746518107" - integrity sha512-Khy4wVmebnzue8aeSXLC+6clo/hRYeNIm0DyikoEqX+3w3rcvrhzpoix0S+MF9vzh6JFskkIGD7Zx47ODJNyCw== +esbuild-windows-64@0.14.42: + version "0.14.42" + resolved "https://registry.yarnpkg.com/esbuild-windows-64/-/esbuild-windows-64-0.14.42.tgz#b877aa37ff47d9fcf0ccb1ca6a24b31475a5e555" + integrity sha512-j3cdK+Y3+a5H0wHKmLGTJcq0+/2mMBHPWkItR3vytp/aUGD/ua/t2BLdfBIzbNN9nLCRL9sywCRpOpFMx3CxzA== -esbuild-windows-arm64@0.14.38: - version "0.14.38" - resolved "https://registry.yarnpkg.com/esbuild-windows-arm64/-/esbuild-windows-arm64-0.14.38.tgz#d97e9ac0f95a4c236d9173fa9f86c983d6a53f54" - integrity sha512-k3FGCNmHBkqdJXuJszdWciAH77PukEyDsdIryEHn9cKLQFxzhT39dSumeTuggaQcXY57UlmLGIkklWZo2qzHpw== +esbuild-windows-arm64@0.14.42: + version "0.14.42" + resolved "https://registry.yarnpkg.com/esbuild-windows-arm64/-/esbuild-windows-arm64-0.14.42.tgz#79da8744626f24bc016dc40d016950b5a4a2bac5" + integrity sha512-+lRAARnF+hf8J0mN27ujO+VbhPbDqJ8rCcJKye4y7YZLV6C4n3pTRThAb388k/zqF5uM0lS5O201u0OqoWSicw== -esbuild@0.14.38: - version "0.14.38" - resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.14.38.tgz#99526b778cd9f35532955e26e1709a16cca2fb30" - integrity sha512-12fzJ0fsm7gVZX1YQ1InkOE5f9Tl7cgf6JPYXRJtPIoE0zkWAbHdPHVPPaLi9tYAcEBqheGzqLn/3RdTOyBfcA== +esbuild@0.14.42: + version "0.14.42" + resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.14.42.tgz#98587df0b024d5f6341b12a1d735a2bff55e1836" + integrity sha512-V0uPZotCEHokJdNqyozH6qsaQXqmZEOiZWrXnds/zaH/0SyrIayRXWRB98CENO73MIZ9T3HBIOsmds5twWtmgw== optionalDependencies: - esbuild-android-64 "0.14.38" - esbuild-android-arm64 "0.14.38" - esbuild-darwin-64 "0.14.38" - esbuild-darwin-arm64 "0.14.38" - esbuild-freebsd-64 "0.14.38" - esbuild-freebsd-arm64 "0.14.38" - esbuild-linux-32 "0.14.38" - esbuild-linux-64 "0.14.38" - esbuild-linux-arm "0.14.38" - esbuild-linux-arm64 "0.14.38" - esbuild-linux-mips64le "0.14.38" - esbuild-linux-ppc64le "0.14.38" - esbuild-linux-riscv64 "0.14.38" - esbuild-linux-s390x "0.14.38" - esbuild-netbsd-64 "0.14.38" - esbuild-openbsd-64 "0.14.38" - esbuild-sunos-64 "0.14.38" - esbuild-windows-32 "0.14.38" - esbuild-windows-64 "0.14.38" - esbuild-windows-arm64 "0.14.38" + esbuild-android-64 "0.14.42" + esbuild-android-arm64 "0.14.42" + esbuild-darwin-64 "0.14.42" + esbuild-darwin-arm64 "0.14.42" + esbuild-freebsd-64 "0.14.42" + esbuild-freebsd-arm64 "0.14.42" + esbuild-linux-32 "0.14.42" + esbuild-linux-64 "0.14.42" + esbuild-linux-arm "0.14.42" + esbuild-linux-arm64 "0.14.42" + esbuild-linux-mips64le "0.14.42" + esbuild-linux-ppc64le "0.14.42" + esbuild-linux-riscv64 "0.14.42" + esbuild-linux-s390x "0.14.42" + esbuild-netbsd-64 "0.14.42" + esbuild-openbsd-64 "0.14.42" + esbuild-sunos-64 "0.14.42" + esbuild-windows-32 "0.14.42" + esbuild-windows-64 "0.14.42" + esbuild-windows-arm64 "0.14.42" escalade@^3.1.1: version "3.1.1" From be9d63e543b6ac28aa6eee7ab8dc45849cd8f0b3 Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Sat, 4 Jun 2022 23:25:27 +0900 Subject: [PATCH 4/4] Avoid printing attribute per line in Vue SFC blocks (#12895) * Avoid print single attribute perline for Vue SFC blocks * Add tests * Add changelog * Fix typo * Add more tests --- changelog_unreleased/vue/12895.md | 19 +++ src/language-html/print/tag.js | 8 +- src/language-html/utils/index.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 147 ++++++++++++++++++ .../single-attribute-per-line/sfc-blocks.vue | 29 ++++ 5 files changed, 202 insertions(+), 2 deletions(-) create mode 100644 changelog_unreleased/vue/12895.md create mode 100644 tests/format/vue/single-attribute-per-line/sfc-blocks.vue diff --git a/changelog_unreleased/vue/12895.md b/changelog_unreleased/vue/12895.md new file mode 100644 index 000000000..8a4eeaff3 --- /dev/null +++ b/changelog_unreleased/vue/12895.md @@ -0,0 +1,19 @@ +#### Avoid printing attribute per line in Vue SFC blocks (#12895 by @sosukesuzuki) + + +```vue + + + + + + + + +``` diff --git a/src/language-html/print/tag.js b/src/language-html/print/tag.js index 7d97ec0fd..000688983 100644 --- a/src/language-html/print/tag.js +++ b/src/language-html/print/tag.js @@ -17,6 +17,7 @@ const { isPreLikeNode, hasPrettierIgnore, shouldPreserveContent, + isVueSfcBlock, } = require("../utils/index.js"); function printClosingTag(node, options) { @@ -251,8 +252,11 @@ function printAttributes(path, options, print) { node.attrs[0].fullName === "src" && node.children.length === 0; - const attributeLine = - options.singleAttributePerLine && node.attrs.length > 1 ? hardline : line; + const shouldPrintAttributePerLine = + options.singleAttributePerLine && + node.attrs.length > 1 && + !isVueSfcBlock(node, options); + const attributeLine = shouldPrintAttributePerLine ? hardline : line; /** @type {Doc[]} */ const parts = [ diff --git a/src/language-html/utils/index.js b/src/language-html/utils/index.js index 00b1e2412..4164edc4e 100644 --- a/src/language-html/utils/index.js +++ b/src/language-html/utils/index.js @@ -674,6 +674,7 @@ module.exports = { isVueScriptTag, isVueSlotAttribute, isVueSfcBindingsAttribute, + isVueSfcBlock, isDanglingSpaceSensitiveNode, isIndentationSensitiveNode, isLeadingSpaceSensitiveNode, diff --git a/tests/format/vue/single-attribute-per-line/__snapshots__/jsfmt.spec.js.snap b/tests/format/vue/single-attribute-per-line/__snapshots__/jsfmt.spec.js.snap index 0a2ce5116..7da8e503a 100644 --- a/tests/format/vue/single-attribute-per-line/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/vue/single-attribute-per-line/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,152 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`sfc-blocks.vue - {"singleAttributePerLine":true} format 1`] = ` +====================================options===================================== +parsers: ["vue"] +printWidth: 80 +singleAttributePerLine: true + | printWidth +=====================================input====================================== + + + + + + + + + + + + + + + + + + +=====================================output===================================== + + + + + + + + + + + + + + + + + + +================================================================================ +`; + +exports[`sfc-blocks.vue format 1`] = ` +====================================options===================================== +parsers: ["vue"] +printWidth: 80 + | printWidth +=====================================input====================================== + + + + + + + + + + + + + + + + + + +=====================================output===================================== + + + + + + + + + + + + + + + + + + +================================================================================ +`; + exports[`single-attribute-per-line.vue - {"singleAttributePerLine":true} format 1`] = ` ====================================options===================================== parsers: ["vue"] diff --git a/tests/format/vue/single-attribute-per-line/sfc-blocks.vue b/tests/format/vue/single-attribute-per-line/sfc-blocks.vue new file mode 100644 index 000000000..9118346d5 --- /dev/null +++ b/tests/format/vue/single-attribute-per-line/sfc-blocks.vue @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + +