From 17cdff607a8fa1ad086a955d92f6e6cf5e973dde Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Fri, 13 Jun 2025 17:27:07 +0800 Subject: [PATCH] Support type cast comments for `meriyah` parser (#17600) --- changelog_unreleased/javascript/17491.md | 4 ++-- src/language-js/parse/meriyah.js | 2 +- tests/config/run-format-test.js | 9 ++++----- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/changelog_unreleased/javascript/17491.md b/changelog_unreleased/javascript/17491.md index 809a9c8cd..4440ee625 100644 --- a/changelog_unreleased/javascript/17491.md +++ b/changelog_unreleased/javascript/17491.md @@ -1,4 +1,4 @@ -#### Support type cast comments for `acorn` and `espree` parser (#17491, #17566 by @ArnaudBarre, #17587 by #fisker) +#### Support type cast comments for `acorn`, `espree`, and `meriyah` parser (#17491, #17566 by @ArnaudBarre, #17587, #17600 by #fisker) This was previously only supported by the Babel parser. @@ -7,7 +7,7 @@ This was previously only supported by the Babel parser. // Input /** @type {MyType} */ (x).foo; -// Prettier stable (--parser=acorn or --parser=espree) +// Prettier stable (--parser=acorn|espree|meriyah) /** @type {MyType} */ x.foo; // Prettier main diff --git a/src/language-js/parse/meriyah.js b/src/language-js/parse/meriyah.js index fc27bd3a8..cceba7717 100644 --- a/src/language-js/parse/meriyah.js +++ b/src/language-js/parse/meriyah.js @@ -30,7 +30,7 @@ const parseOptions = { // Enable implied strict mode impliedStrict: false, // Enable non-standard parenthesized expression node - preserveParens: false, + preserveParens: true, // Enable lexical binding and scope tracking lexical: false, // Adds a source attribute in every node’s loc object when the locations option is `true` diff --git a/tests/config/run-format-test.js b/tests/config/run-format-test.js index f5024d86b..d68b834e4 100644 --- a/tests/config/run-format-test.js +++ b/tests/config/run-format-test.js @@ -59,16 +59,15 @@ const unstableTests = new Map( const unstableAstTests = new Map(); const commentClosureTypecaseTests = new Set( [ - // These tests only work for `babel`, `acorn`, and `oxc` + // These tests works on `babel`, `acorn`, `espree`, `oxc`, and `meriyah` "comments-closure-typecast", ].map((directory) => path.join(__dirname, "../format/js", directory)), ); const espreeDisabledTests = new Set(); const acornDisabledTests = new Set(); -const meriyahDisabledTests = new Set([ - ...commentClosureTypecaseTests, - ...[ +const meriyahDisabledTests = new Set( + [ // Parsing to different ASTs "js/decorators/member-expression.js", // Meriyah parse RegExp relay on runtime behavior @@ -79,7 +78,7 @@ const meriyahDisabledTests = new Set([ "js/babel-plugins/regexp-modifiers.js", "js/regex/regexp-modifiers.js", ].map((file) => path.join(__dirname, "../format", file)), -]); +); const babelTsDisabledTests = new Set( ["conformance/types/moduleDeclaration/kind-detection.ts"].map((file) => path.join(__dirname, "../format/typescript", file),