Skip to content

Commit 06ea1ac

Browse files
authored
Stricter node type check (#14165)
1 parent c1b9765 commit 06ea1ac

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

src/language-js/print/jsx.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const { getLast, getPreferredQuote } = require("../../common/util.js");
2525
const {
2626
isJsxNode,
2727
rawText,
28-
isLiteral,
2928
isCallExpression,
3029
isStringLiteral,
3130
isBinaryish,
@@ -279,7 +278,7 @@ function printJsxChildren(
279278
const parts = [];
280279
path.each((childPath, i, children) => {
281280
const child = childPath.getValue();
282-
if (isLiteral(child)) {
281+
if (child.type === "JSXText") {
283282
const text = rawText(child);
284283

285284
// Contains a non-whitespace character
@@ -812,7 +811,7 @@ function isEmptyJsxElement(node) {
812811
// if there is one text child and does not contain any meaningful text
813812
// we can treat the element as empty.
814813
const child = node.children[0];
815-
return isLiteral(child) && !isMeaningfulJsxText(child);
814+
return child.type === "JSXText" && !isMeaningfulJsxText(child);
816815
}
817816

818817
// Meaningful if it contains non-whitespace characters,
@@ -823,7 +822,7 @@ function isEmptyJsxElement(node) {
823822
*/
824823
function isMeaningfulJsxText(node) {
825824
return (
826-
isLiteral(node) &&
825+
node.type === "JSXText" &&
827826
(containsNonJsxWhitespaceRegex.test(rawText(node)) ||
828827
!/\n/.test(rawText(node)))
829828
);
@@ -833,7 +832,7 @@ function isMeaningfulJsxText(node) {
833832
function isJsxWhitespaceExpression(node) {
834833
return (
835834
node.type === "JSXExpressionContainer" &&
836-
isLiteral(node.expression) &&
835+
isStringLiteral(node.expression) &&
837836
node.expression.value === " " &&
838837
!hasComment(node.expression)
839838
);

src/language-js/print/typescript.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const {
1515
},
1616
} = require("../../document/index.js");
1717
const {
18-
isLiteral,
18+
isStringLiteral,
1919
getTypeScriptMappedTypeModifier,
2020
shouldPrintComma,
2121
isCallExpression,
@@ -449,7 +449,7 @@ function printTypescript(path, options, print) {
449449
return ["require(", print("expression"), ")"];
450450
case "TSModuleDeclaration": {
451451
const parent = path.getParentNode();
452-
const isExternalModule = isLiteral(node.id);
452+
const isExternalModule = isStringLiteral(node.id);
453453
const parentIsDeclaration = parent.type === "TSModuleDeclaration";
454454
const bodyIsDeclaration =
455455
node.body && node.body.type === "TSModuleDeclaration";

0 commit comments

Comments
 (0)