Stricter node type check (#14165)
This commit is contained in:
1 parent
c1b976572c
commit
06ea1ac0d0
2 files changed
+6
-7
No files matched your search
@@ -25,7 +25,6 @@ const { getLast, getPreferredQuote } = require("../../common/util.js");
|
||||
const {
|
||||
isJsxNode,
|
||||
rawText,
|
||||
isLiteral,
|
||||
isCallExpression,
|
||||
isStringLiteral,
|
||||
isBinaryish,
|
||||
@@ -279,7 +278,7 @@ function printJsxChildren(
|
||||
const parts = [];
|
||||
path.each((childPath, i, children) => {
|
||||
const child = childPath.getValue();
|
||||
if (isLiteral(child)) {
|
||||
if (child.type === "JSXText") {
|
||||
const text = rawText(child);
|
||||
|
||||
// Contains a non-whitespace character
|
||||
@@ -812,7 +811,7 @@ function isEmptyJsxElement(node) {
|
||||
// if there is one text child and does not contain any meaningful text
|
||||
// we can treat the element as empty.
|
||||
const child = node.children[0];
|
||||
return isLiteral(child) && !isMeaningfulJsxText(child);
|
||||
return child.type === "JSXText" && !isMeaningfulJsxText(child);
|
||||
}
|
||||
|
||||
// Meaningful if it contains non-whitespace characters,
|
||||
@@ -823,7 +822,7 @@ function isEmptyJsxElement(node) {
|
||||
*/
|
||||
function isMeaningfulJsxText(node) {
|
||||
return (
|
||||
isLiteral(node) &&
|
||||
node.type === "JSXText" &&
|
||||
(containsNonJsxWhitespaceRegex.test(rawText(node)) ||
|
||||
!/\n/.test(rawText(node)))
|
||||
);
|
||||
@@ -833,7 +832,7 @@ function isMeaningfulJsxText(node) {
|
||||
function isJsxWhitespaceExpression(node) {
|
||||
return (
|
||||
node.type === "JSXExpressionContainer" &&
|
||||
isLiteral(node.expression) &&
|
||||
isStringLiteral(node.expression) &&
|
||||
node.expression.value === " " &&
|
||||
!hasComment(node.expression)
|
||||
);
|
||||
|
||||
@@ -15,7 +15,7 @@ const {
|
||||
},
|
||||
} = require("../../document/index.js");
|
||||
const {
|
||||
isLiteral,
|
||||
isStringLiteral,
|
||||
getTypeScriptMappedTypeModifier,
|
||||
shouldPrintComma,
|
||||
isCallExpression,
|
||||
@@ -449,7 +449,7 @@ function printTypescript(path, options, print) {
|
||||
return ["require(", print("expression"), ")"];
|
||||
case "TSModuleDeclaration": {
|
||||
const parent = path.getParentNode();
|
||||
const isExternalModule = isLiteral(node.id);
|
||||
const isExternalModule = isStringLiteral(node.id);
|
||||
const parentIsDeclaration = parent.type === "TSModuleDeclaration";
|
||||
const bodyIsDeclaration =
|
||||
node.body && node.body.type === "TSModuleDeclaration";
|
||||
|
||||
Reference in new issue
Block a user