diff --git a/src/language-js/parentheses/identifier.js b/src/language-js/parentheses/identifier.js index 979df088d..e0c2da173 100644 --- a/src/language-js/parentheses/identifier.js +++ b/src/language-js/parentheses/identifier.js @@ -93,6 +93,23 @@ function shouldAddParenthesesToIdentifier(path) { } } + if (node.name === "await") { + const statement = path.findAncestor( + (node) => node.type === "ExpressionStatement", + ); + if (statement) { + const { expression } = statement; + if ( + startsWithNoLookaheadToken( + expression, + (leftmostNode) => leftmostNode === node, + ) + ) { + return true; + } + } + } + // `(type) satisfies never;` and similar cases if ( key === "expression" && diff --git a/src/language-js/parse/babel.js b/src/language-js/parse/babel.js index 2861305db..b2f550ecd 100644 --- a/src/language-js/parse/babel.js +++ b/src/language-js/parse/babel.js @@ -7,8 +7,8 @@ import createBabelParseError from "./utilities/create-babel-parse-error.js"; import createParser from "./utilities/create-parser.js"; import { getSourceType, + SOURCE_TYPE_COMBINATIONS, SOURCE_TYPE_COMMONJS, - SOURCE_TYPE_MODULE, } from "./utilities/source-types.js"; import wrapExpression from "./utilities/wrap-expression.js"; @@ -22,7 +22,6 @@ const createBabelParser = (options) => createParser(createParse(options)); /** @type {ParserOptions} */ const parseOptions = { - sourceType: SOURCE_TYPE_MODULE, allowImportExportEverywhere: true, allowReturnOutsideFunction: true, allowNewTargetOutsideFunction: true, @@ -132,8 +131,11 @@ function createParse({ isExpression = false, optionsCombinations }) { let combinations = optionsCombinations; const sourceType = options.__babelSourceType ?? getSourceType(filepath); - if (sourceType && sourceType !== SOURCE_TYPE_MODULE) { - combinations = combinations.map((options) => ({ + + combinations = ( + sourceType ? [sourceType] : SOURCE_TYPE_COMBINATIONS + ).flatMap((sourceType) => + combinations.map((options) => ({ ...options, sourceType, // `sourceType: "commonjs"` does not allow these two properties @@ -143,8 +145,8 @@ function createParse({ isExpression = false, optionsCombinations }) { allowNewTargetOutsideFunction: undefined, } : undefined), - })); - } + })), + ); const shouldEnableV8intrinsicPlugin = /%[A-Z]/.test(text); if (text.includes("|>")) { diff --git a/tests/format/flow/await/__snapshots__/format.test.js.snap b/tests/format/flow/await/__snapshots__/format.test.js.snap index ca984fea4..973bdb524 100644 --- a/tests/format/flow/await/__snapshots__/format.test.js.snap +++ b/tests/format/flow/await/__snapshots__/format.test.js.snap @@ -43,7 +43,7 @@ export class C1 { p = await(0); } -await(0); +(await)(0); async function foo() { function bar(x = await(2)) {} @@ -55,7 +55,7 @@ export class C2 { } function foo(promise) { - await(promise); + (await)(promise); } function a() { @@ -63,18 +63,18 @@ function a() { } () => { - await(x); + (await)(x); }; function foo() { - await(foo); + (await)(foo); } export class C { p = await(0); } -await(0); +(await)(0); ================================================================================ `; diff --git a/tests/format/js/_errors_/html-like-comments/__snapshots__/format.test.js.snap b/tests/format/js/_errors_/html-like-comments/__snapshots__/format.test.js.snap deleted file mode 100644 index c28ec72b4..000000000 --- a/tests/format/js/_errors_/html-like-comments/__snapshots__/format.test.js.snap +++ /dev/null @@ -1,58 +0,0 @@ -// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing - -exports[`html-like-comments.js format[babel] 1`] = ` -"Unexpected token (2:1) - 1 | alert( -> 2 | -Cause: Unexpected token (1:0)" -`; - -exports[`comment.js format[babel] 1`] = ` -"Unexpected token (1:1) -> 1 | -Cause: Unexpected token (1:0)" -`; - -exports[`comment.js format[babel-ts] 1`] = ` -"Unexpected token (1:1) -> 1 | -Cause: Unexpected token (1:0)" -`; - exports[`comment.js format[flow] 1`] = ` "Unexpected token \`!\`, expected the token \`>\` (1:2) > 1 | Cause: Expression expected." `; + +exports[`html-like-comments.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] + printWidth: 80 (default) | +=====================================input====================================== +alert( +