Treat template literal tag as IIFE (#18541)

This commit is contained in:
fisker Cheung authored and GitHub committed 2025-12-30 00:12:32 +08:00
1 parent a34cc31307
commit 33ae836128
5 files changed
+42 -10

No files matched your search

@@ -1,7 +1,7 @@
import {
createTypeCheckFunction,
hasNodeIgnoreComment,
isIifeCallee,
isIifeCalleeOrTaggedTemplateExpressionTag,
isJsxElement,
isUnionType,
shouldUnionTypePrintOwnComments,
@@ -40,7 +40,7 @@ function willPrintOwnComments(path) {
isClassOrInterface(parent)) ||
// Not tested, don't know how to
(key === "patterns" && parent.type === "MatchOrPattern") ||
isIifeCallee(path)
isIifeCalleeOrTaggedTemplateExpressionTag(path)
) {
return true;
}
+4 -4
View File
@@ -14,7 +14,7 @@ import {
CommentCheckFlags,
createTypeCheckFunction,
hasComment,
isIifeCallee,
isIifeCalleeOrTaggedTemplateExpressionTag,
} from "../utilities/index.js";
import isIgnored from "../utilities/is-ignored.js";
import { printAngular } from "./angular.js";
@@ -85,7 +85,7 @@ function print(path, options, print, args) {
return doc;
}
doc = printCommentsForIifeCallee(path, options, doc);
doc = printCommentsForFunction(path, options, doc);
const hasDecorators = isNonEmptyArray(node.decorators);
const decoratorsDoc = printDecorators(path, options, print);
@@ -112,13 +112,13 @@ function print(path, options, print, args) {
]);
}
function printCommentsForIifeCallee(path, options, doc) {
function printCommentsForFunction(path, options, doc) {
const { node } = path;
if (
(hasComment(node, CommentCheckFlags.Leading) ||
hasComment(node, CommentCheckFlags.Trailing)) &&
isIifeCallee(path)
isIifeCalleeOrTaggedTemplateExpressionTag(path)
) {
return [indent([softline, printComments(path, doc, options)]), softline];
}
+4 -4
View File
@@ -1103,13 +1103,13 @@ function isShorthandSpecifier(specifier) {
}
}
function isIifeCallee(path) {
function isIifeCalleeOrTaggedTemplateExpressionTag(path) {
const { node } = path;
return (
(node.type === "FunctionExpression" ||
node.type === "ArrowFunctionExpression") &&
path.key === "callee" &&
isCallExpression(path.parent)
((path.key === "callee" && isCallExpression(path.parent)) ||
(path.key === "tag" && path.parent.type === "TaggedTemplateExpression"))
);
}
@@ -1142,7 +1142,7 @@ export {
isFlowObjectTypePropertyAFunction,
isFunctionCompositionArgs,
isFunctionOrArrowExpression,
isIifeCallee,
isIifeCalleeOrTaggedTemplateExpressionTag,
isIntersectionType,
isJsxElement,
isLiteral,