Add new ESLint prefer-ast-path-node (#13470)

* Add new lint rule `prefer-path-get-value`

* Add new rule

* Apply fix

* Ingore projects in benchmark

* Add comment
This commit is contained in:
Sosuke Suzuki authored and GitHub committed 2022-09-11 18:39:06 +09:00
1 parent 58fc024774
commit e92dcbd1a5
66 files changed
+269 -181

No files matched your search

+1
View File
@@ -12,3 +12,4 @@
/website/build/
/website/static/playground.js
/website/static/lib/
/scripts/benchmark/*/
+1
View File
@@ -311,6 +311,7 @@ module.exports = {
"prettier-internal-rules/prefer-indent-if-break": "error",
"prettier-internal-rules/prefer-is-non-empty-array": "error",
"prettier-internal-rules/prefer-fs-promises-submodule": "error",
"prettier-internal-rules/prefer-ast-path-node": "error",
},
},
{
@@ -19,5 +19,6 @@ module.exports = {
"prefer-indent-if-break": require("./prefer-indent-if-break.js"),
"prefer-is-non-empty-array": require("./prefer-is-non-empty-array.js"),
"prefer-fs-promises-submodule": require("./prefer-fs-promises-submodule.js"),
"prefer-ast-path-node": require("./prefer-ast-path-node.js"),
},
};
@@ -0,0 +1,50 @@
"use strict";
const selector = [
"CallExpression[arguments.length=0]",
"> MemberExpression",
].join("");
const messageId = "prefer-ast-path-node";
const getNodeFunctionNames = new Set(["getValue", "getNode"]);
module.exports = {
meta: {
type: "suggestion",
docs: {
url: "https://github.com/prettier/prettier/blob/main/scripts/tools/eslint-plugin-prettier-internal-rules/prefer-ast-path-node.js",
},
fixable: "code",
messages: {
[messageId]:
"Prefer `path.node` instead of `path.getValue()` and `path.getNode()`",
},
},
create(context) {
return {
[selector](node) {
if (!node.object?.name?.toLowerCase().endsWith("path")) {
return;
}
if (!getNodeFunctionNames.has(node.property?.name)) {
return;
}
context.report({
node,
messageId,
fix: (fixer) => [
fixer.replaceTextRange(
[
node.property.range[0],
// remove `()` for CallExpression
node.property.range[1] + 2,
],
"node"
),
],
});
},
};
},
};
@@ -540,3 +540,45 @@ test("prefer-fs-promises-submodule", {
parserOptions: { sourceType: "module" },
})),
});
test("prefer-ast-path-node", {
valid: [
"path.getNode(2)",
"path.getNode",
"getNode",
"this.getNode()",
"path.node",
],
invalid: [
{
code: "path.getNode()",
output: "path.node",
errors: 1,
},
{
code: "const node = path.getNode()",
output: "const node = path.node",
errors: 1,
},
{
code: "path.getValue()",
output: "path.node",
errors: 1,
},
{
code: "const node = path.getValue()",
output: "const node = path.node",
errors: 1,
},
{
code: "fooPath.getValue()",
output: "fooPath.node",
errors: 1,
},
{
code: "fooPath.getNode()",
output: "fooPath.node",
errors: 1,
},
],
});
+1 -1
View File
@@ -2,7 +2,7 @@ import { hardline } from "../document/builders.js";
import printFrontMatter from "../utils/front-matter/print.js";
function embed(path) {
const node = path.getValue();
const { node } = path;
if (node.type === "front-matter") {
return async (textToDoc) => {
+4 -4
View File
@@ -85,7 +85,7 @@ function shouldPrintComma(options) {
}
function genericPrint(path, options, print) {
const node = path.getValue();
const { node } = path;
switch (node.type) {
case "front-matter":
@@ -312,7 +312,7 @@ function genericPrint(path, options, print) {
case "media-query-list": {
const parts = [];
path.each((childPath) => {
const node = childPath.getValue();
const { node } = childPath;
if (node.type === "media-query" && node.value === "") {
return;
}
@@ -864,7 +864,7 @@ function genericPrint(path, options, print) {
case "value-paren_group": {
const parentNode = path.getParentNode();
const printedGroups = path.map(() => {
const child = path.getValue();
const child = path.node;
return typeof child === "string" ? child : print();
}, "groups");
@@ -908,7 +908,7 @@ function genericPrint(path, options, print) {
join(
[line],
path.map((childPath, index) => {
const child = childPath.getValue();
const child = childPath.node;
const isLast = index === node.groups.length - 1;
const hasComma = () =>
Boolean(
+2 -2
View File
@@ -106,7 +106,7 @@ function insideAtRuleNode(path, atRuleNameOrAtRuleNames) {
}
function insideURLFunctionInImportAtRuleNode(path) {
const node = path.getValue();
const { node } = path;
const atRuleAncestorNode = getAncestorNode(path, "css-atrule");
return (
@@ -271,7 +271,7 @@ function isSCSSMapItemNode(path, options) {
return false;
}
const node = path.getValue();
const { node } = path;
// Ignore empty item (i.e. `$key: ()`)
if (node.groups.length === 0) {
+5 -5
View File
@@ -17,7 +17,7 @@ import visitorKeys from "./visitor-keys.evaluate.js";
const getVisitorKeys = createGetVisitorKeys(visitorKeys, "kind");
function genericPrint(path, options, print) {
const node = path.getValue();
const { node } = path;
switch (node.kind) {
case "Document": {
@@ -497,7 +497,7 @@ function printSequence(path, options, print, property) {
if (
index < sequence.length - 1 &&
isNextLineEmpty(options.originalText, path.getValue(), locEnd)
isNextLineEmpty(options.originalText, path.node, locEnd)
) {
return [printed, hardline];
}
@@ -511,7 +511,7 @@ function canAttachComment(node) {
}
function printComment(commentPath) {
const comment = commentPath.getValue();
const comment = commentPath.node;
if (comment.kind === "Comment") {
return "#" + comment.value.trimEnd();
}
@@ -521,7 +521,7 @@ function printComment(commentPath) {
}
function printInterfaces(path, options, print) {
const node = path.getValue();
const { node } = path;
const parts = [];
const { interfaces } = node;
const printed = path.map(print, "interfaces");
@@ -554,7 +554,7 @@ function clean(node, newNode /* , parent */) {
clean.ignoredProperties = new Set(["loc", "comments"]);
function hasPrettierIgnore(path) {
const node = path.getValue();
const { node } = path;
return node?.comments?.some(
(comment) => comment.value.trim() === "prettier-ignore"
);
+9 -9
View File
@@ -37,7 +37,7 @@ const NEWLINES_TO_PRESERVE_MAX = 2;
// https://github.com/glimmerjs/glimmer-vm/blob/master/packages/%40glimmer/syntax/lib/generation/print.ts
function print(path, options, print) {
const node = path.getValue();
const { node } = path;
const favoriteQuote = options.singleQuote ? "'" : '"';
@@ -420,7 +420,7 @@ function sortByLoc(a, b) {
}
function printStartingTag(path, print) {
const node = path.getValue();
const { node } = path;
const types = ["attributes", "modifiers", "comments"].filter((property) =>
isNonEmptyArray(node[property])
@@ -429,7 +429,7 @@ function printStartingTag(path, print) {
for (const attributeType of types) {
path.each((attributePath) => {
const index = attributes.indexOf(attributePath.getValue());
const index = attributes.indexOf(attributePath.node);
attributes.splice(index, 1, [line, print()]);
}, attributeType);
}
@@ -442,7 +442,7 @@ function printStartingTag(path, print) {
}
function printChildren(path, options, print) {
const node = path.getValue();
const { node } = path;
const isEmpty = node.children.every((node) => isWhitespaceNode(node));
if (options.htmlWhitespaceSensitivity === "ignore" && isEmpty) {
return "";
@@ -520,7 +520,7 @@ function printInverseBlockClosingMustache(node) {
}
function printOpenBlock(path, print) {
const node = path.getValue();
const { node } = path;
const openingMustache = printOpeningBlockOpeningMustache(node);
const closingMustache = printOpeningBlockClosingMustache(node);
@@ -566,7 +566,7 @@ function printElseIfBlock(path, print) {
}
function printCloseBlock(path, print, options) {
const node = path.getValue();
const { node } = path;
if (options.htmlWhitespaceSensitivity === "ignore") {
const escape = blockStatementHasOnlyWhitespaceInProgram(node)
@@ -609,7 +609,7 @@ function blockStatementHasElse(node) {
}
function printProgram(path, print, options) {
const node = path.getValue();
const { node } = path;
if (blockStatementHasOnlyWhitespaceInProgram(node)) {
return "";
@@ -625,7 +625,7 @@ function printProgram(path, print, options) {
}
function printInverse(path, print, options) {
const node = path.getValue();
const { node } = path;
const inverse = print("inverse");
const printed =
@@ -755,7 +755,7 @@ function printPath(path, print) {
}
function printParams(path, print) {
const node = path.getValue();
const { node } = path;
const parts = [];
if (node.params.length > 0) {
+3 -3
View File
@@ -2,7 +2,7 @@ import { htmlVoidElements } from "html-void-elements";
import getLast from "../utils/get-last.js";
function isLastNodeOfSiblings(path) {
const node = path.getValue();
const { node } = path;
const parentNode = path.getParentNode(0);
if (
@@ -68,7 +68,7 @@ function isNextNodeOfSomeType(path, types) {
}
function getSiblingNode(path, offset) {
const node = path.getValue();
const { node } = path;
const parentNode = path.getParentNode(0) ?? {};
const children =
parentNode.children ?? parentNode.body ?? parentNode.parts ?? [];
@@ -93,7 +93,7 @@ function isPrettierIgnoreNode(node) {
}
function hasPrettierIgnore(path) {
const node = path.getValue();
const { node } = path;
const previousPreviousNode = getPreviousNode(path, 2);
return (
isPrettierIgnoreNode(node) || isPrettierIgnoreNode(previousPreviousNode)
+1 -1
View File
@@ -246,7 +246,7 @@ async function printEmbeddedAttributeValue(node, htmlTextToDoc, options) {
}
function embed(path, options) {
const node = path.getValue();
const { node } = path;
switch (node.type) {
case "element": {
+4 -4
View File
@@ -26,7 +26,7 @@ import {
} from "./tag.js";
function printChild(childPath, options, print) {
const child = childPath.getValue();
const child = childPath.node;
if (hasPrettierIgnore(child)) {
return [
@@ -111,14 +111,14 @@ function printBetweenLine(prevNode, nextNode) {
}
function printChildren(path, options, print) {
const node = path.getValue();
const { node } = path;
if (forceBreakChildren(node)) {
return [
breakParent,
...path.map((childPath) => {
const childNode = childPath.getValue();
const childNode = childPath.node;
const prevBetweenLine = !childNode.prev
? ""
: printBetweenLine(childNode.prev, childNode);
@@ -137,7 +137,7 @@ function printChildren(path, options, print) {
const groupIds = node.children.map(() => Symbol(""));
return path.map((childPath, childIndex) => {
const childNode = childPath.getValue();
const childNode = childPath.node;
if (isTextLikeNode(childNode)) {
if (childNode.prev && isTextLikeNode(childNode.prev)) {
+1 -1
View File
@@ -28,7 +28,7 @@ import {
import { printChildren } from "./children.js";
function printElement(path, options, print) {
const node = path.getValue();
const { node } = path;
if (shouldPreserveContent(node, options)) {
return [
+3 -3
View File
@@ -214,7 +214,7 @@ function needsToBorrowParentOpeningTagEndMarker(node) {
}
function printAttributes(path, options, print) {
const node = path.getValue();
const { node } = path;
if (!isNonEmptyArray(node.attrs)) {
return node.isSelfClosing
@@ -239,7 +239,7 @@ function printAttributes(path, options, print) {
: () => false;
const printedAttributes = path.map((attributePath) => {
const attribute = attributePath.getValue();
const attribute = attributePath.node;
return hasPrettierIgnoreAttribute(attribute)
? replaceEndOfLine(
options.originalText.slice(locStart(attribute), locEnd(attribute))
@@ -311,7 +311,7 @@ function printOpeningTagEnd(node) {
}
function printOpeningTag(path, options, print) {
const node = path.getValue();
const { node } = path;
return [
printOpeningTagStart(node, options),
+1 -1
View File
@@ -29,7 +29,7 @@ import visitorKeys from "./visitor-keys.js";
const getVisitorKeys = createGetVisitorKeys(visitorKeys);
function genericPrint(path, options, print) {
const node = path.getValue();
const { node } = path;
switch (node.type) {
case "front-matter":
+1 -1
View File
@@ -954,7 +954,7 @@ function getCommentChildNodes(node, options) {
* @returns {boolean}
*/
function willPrintOwnComments(path /*, options */) {
const node = path.getValue();
const { node } = path;
const parent = path.getParentNode();
const hasFlowAnnotations = (node) =>
+5 -5
View File
@@ -9,7 +9,7 @@ import formatGraphql from "./embed/graphql.js";
import { formatHtml, formatAngular } from "./embed/html.js";
function embed(path) {
const node = path.getValue();
const { node } = path;
if (
node.type !== "TemplateLiteral" ||
@@ -51,7 +51,7 @@ function embed(path) {
* markdown`...`
*/
function isMarkdown(path) {
const node = path.getValue();
const { node } = path;
const parent = path.getParentNode();
return (
parent &&
@@ -70,7 +70,7 @@ function isMarkdown(path) {
* css.resolve``
*/
function isStyledJsx(path) {
const node = path.getValue();
const { node } = path;
const parent = path.getParentNode();
const parentParent = path.getParentNode(1);
return (
@@ -224,7 +224,7 @@ function isStyledExtend(node) {
* support Relay Classic formatting.
*/
function isGraphQL(path) {
const node = path.getValue();
const { node } = path;
const parent = path.getParentNode();
return (
@@ -261,7 +261,7 @@ function hasLanguageComment(node, languageName) {
*/
function isHtml(path) {
return (
hasLanguageComment(path.getValue(), "HTML") ||
hasLanguageComment(path.node, "HTML") ||
path.match(
(node) => node.type === "TemplateLiteral",
(node, name) =>
+1 -1
View File
@@ -4,7 +4,7 @@ import { mapDoc, replaceEndOfLine, cleanDoc } from "../../document/utils.js";
import { printTemplateExpressions } from "../print/template-literal.js";
async function format(textToDoc, print, path /*, options*/) {
const node = path.getValue();
const { node } = path;
// Get full template literal with expressions replaced by placeholders
const rawQuasis = node.quasis.map((q) => q.value.raw);
+1 -1
View File
@@ -5,7 +5,7 @@ import {
} from "../print/template-literal.js";
async function format(textToDoc, print, path /*, options*/) {
const node = path.getValue();
const { node } = path;
const numQuasis = node.quasis.length;
if (numQuasis === 1 && node.quasis[0].value.raw.trim() === "") {
+1 -1
View File
@@ -8,7 +8,7 @@ import {
// The counter is needed to distinguish nested embeds.
let htmlTemplateLiteralCounter = 0;
async function format(textToDoc, print, path, options, parser) {
const node = path.getValue();
const { node } = path;
const counter = htmlTemplateLiteralCounter;
htmlTemplateLiteralCounter = (htmlTemplateLiteralCounter + 1) >>> 0;
+1 -1
View File
@@ -7,7 +7,7 @@ import {
import { escapeTemplateCharacters } from "../print/template-literal.js";
async function format(textToDoc, print, path /*, options*/) {
const node = path.getValue();
const { node } = path;
let text = node.quasis[0].value.raw.replace(
/((?:\\\\)*)\\`/g,
(_, backslashes) => "\\".repeat(backslashes.length / 2) + "`"
+5 -5
View File
@@ -22,7 +22,7 @@ function needsParens(path, options) {
}
const name = path.getName();
const node = path.getValue();
const { node } = path;
// to avoid unexpected `}}` in HTML interpolations
if (
@@ -44,7 +44,7 @@ function needsParens(path, options) {
// parser. The Flow parser turns Flow comments into type annotation nodes in its
// AST, which we handle separately.
options.parser !== "flow" &&
hasFlowShorthandAnnotationComment(path.getValue())
hasFlowShorthandAnnotationComment(path.node)
) {
return true;
}
@@ -854,7 +854,7 @@ function isStatement(node) {
function isPathInForStatementInitializer(path) {
let i = 0;
let node = path.getValue();
let { node } = path;
while (node) {
const parent = path.getParentNode(i++);
if (parent && parent.type === "ForStatement" && parent.init === node) {
@@ -889,7 +889,7 @@ function endsWithRightBracket(node) {
}
function isFollowedByRightBracket(path) {
const node = path.getValue();
const { node } = path;
const parent = path.getParentNode();
const name = path.getName();
switch (parent.type) {
@@ -929,7 +929,7 @@ function isFollowedByRightBracket(path) {
}
function shouldWrapFunctionForExportDefault(path, options) {
const node = path.getValue();
const { node } = path;
const parent = path.getParentNode();
if (node.type === "FunctionExpression" || node.type === "ClassExpression") {
+3 -3
View File
@@ -6,7 +6,7 @@ import { printBinaryishExpression } from "./binaryish.js";
/** @typedef {import("../../common/ast-path.js").default} AstPath */
function printAngular(path, options, print) {
const node = path.getValue();
const { node } = path;
// Angular nodes always starts with `NG`
if (!node.type.startsWith("NG")) {
@@ -43,7 +43,7 @@ function printAngular(path, options, print) {
(childPath, index) => [
index === 0
? ""
: isNgForOf(childPath.getValue(), index, node)
: isNgForOf(childPath.node, index, node)
? " "
: [";", line],
print(),
@@ -108,7 +108,7 @@ function isNgForOf(node, index, parentNode) {
* @returns {boolean}
*/
function hasNgSideEffect(path) {
return hasNode(path.getValue(), (node) => {
return hasNode(path.node, (node) => {
switch (node.type) {
case undefined:
return false;
+3 -6
View File
@@ -24,7 +24,7 @@ import { printOptionalToken, printTypeAnnotation } from "./misc.js";
/** @typedef {import("../../document/builders.js").Doc} Doc */
function printArray(path, options, print) {
const node = path.getValue();
const { node } = path;
/** @type{Doc[]} */
const parts = [];
@@ -154,10 +154,7 @@ function printArrayItems(path, options, printPath, print) {
printedElements.push(separatorParts, group(print()));
separatorParts = [",", line];
if (
childPath.getValue() &&
isNextLineEmpty(childPath.getValue(), options)
) {
if (childPath.node && isNextLineEmpty(childPath.node, options)) {
separatorParts.push(softline);
}
}, printPath);
@@ -175,7 +172,7 @@ function printArrayItemsConcisely(path, options, print, trailingComma) {
if (!isLast) {
parts.push(
isNextLineEmpty(childPath.getValue(), options)
isNextLineEmpty(childPath.node, options)
? [hardline, hardline]
: hasComment(
elements[i + 1],
+4 -4
View File
@@ -79,7 +79,7 @@ function printAssignment(
}
function printAssignmentExpression(path, options, print) {
const node = path.getValue();
const { node } = path;
return printAssignment(
path,
options,
@@ -95,7 +95,7 @@ function printVariableDeclarator(path, options, print) {
}
function chooseLayout(path, options, print, leftDoc, rightPropertyName) {
const node = path.getValue();
const { node } = path;
const rightNode = node[rightPropertyName];
if (!rightNode) {
@@ -178,7 +178,7 @@ function chooseLayout(path, options, print, leftDoc, rightPropertyName) {
}
function shouldBreakAfterOperator(path, options, print, hasShortKey) {
const rightNode = path.getValue();
const rightNode = path.node;
if (isBinaryish(rightNode) && !shouldInlineLogicalExpression(rightNode)) {
return true;
@@ -336,7 +336,7 @@ function isPoorlyBreakableMemberOrCallChain(
print,
deep = false
) {
const node = path.getValue();
const { node } = path;
const goDeeper = () =>
isPoorlyBreakableMemberOrCallChain(path, options, print, true);
+2 -2
View File
@@ -28,7 +28,7 @@ import {
let uid = 0;
function printBinaryishExpression(path, options, print) {
const node = path.getValue();
const { node } = path;
const parent = path.getParentNode();
const parentParent = path.getParentNode(1);
const isInsideParenthesis =
@@ -189,7 +189,7 @@ function printBinaryishExpressions(
isNested,
isInsideParenthesis
) {
const node = path.getValue();
const { node } = path;
// Simply print the node normally.
if (!isBinaryish(node)) {
+3 -3
View File
@@ -13,7 +13,7 @@ import { printBody } from "./statement.js";
/** @typedef {import("../../document/builders.js").Doc} Doc */
function printBlock(path, options, print) {
const node = path.getValue();
const { node } = path;
const parts = [];
if (node.type === "StaticBlock") {
@@ -61,7 +61,7 @@ function printBlock(path, options, print) {
}
function printBlockBody(path, options, print) {
const node = path.getValue();
const { node } = path;
const nodeHasDirectives = isNonEmptyArray(node.directives);
const nodeHasBody = node.body.some((node) => node.type !== "EmptyStatement");
@@ -78,7 +78,7 @@ function printBlockBody(path, options, print) {
parts.push(print());
if (index < directives.length - 1 || nodeHasBody || nodeHasComment) {
parts.push(hardline);
if (isNextLineEmpty(childPath.getValue(), options)) {
if (isNextLineEmpty(childPath.node, options)) {
parts.push(hardline);
}
}
+2 -2
View File
@@ -38,7 +38,7 @@ import { ArgExpansionBailout } from "../../common/errors.js";
import { isConciselyPrintedArray } from "./array.js";
function printCallArguments(path, options, print) {
const node = path.getValue();
const { node } = path;
const args = getCallArguments(node);
if (args.length === 0) {
@@ -58,7 +58,7 @@ function printCallArguments(path, options, print) {
const lastArgIndex = args.length - 1;
const printedArguments = [];
iterateCallArgumentsPath(path, (argPath, index) => {
const arg = argPath.getValue();
const arg = argPath.node;
const parts = [print()];
if (index === lastArgIndex) {
+1 -1
View File
@@ -15,7 +15,7 @@ import printCallArguments from "./call-arguments.js";
import { printOptionalToken, printFunctionTypeParameters } from "./misc.js";
function printCallExpression(path, options, print) {
const node = path.getValue();
const { node } = path;
const parentNode = path.getParentNode();
const isNew = node.type === "NewExpression";
const isDynamicImport = node.type === "ImportExpression";
+4 -4
View File
@@ -22,7 +22,7 @@ import { printAssignment } from "./assignment.js";
import { printClassMemberDecorators } from "./decorators.js";
function printClass(path, options, print) {
const node = path.getValue();
const { node } = path;
const parts = [];
if (node.declare) {
@@ -121,7 +121,7 @@ function shouldIndentOnlyHeritageClauses(node) {
}
function printList(path, options, print, listName) {
const node = path.getValue();
const { node } = path;
if (!isNonEmptyArray(node[listName])) {
return "";
}
@@ -157,7 +157,7 @@ function printSuperClass(path, options, print) {
}
function printClassMethod(path, options, print) {
const node = path.getValue();
const { node } = path;
const parts = [];
if (isNonEmptyArray(node.decorators)) {
@@ -191,7 +191,7 @@ function printClassMethod(path, options, print) {
}
function printClassProperty(path, options, print) {
const node = path.getValue();
const { node } = path;
const parts = [];
const semi = options.semi ? ";" : "";
+1 -1
View File
@@ -6,7 +6,7 @@ import { locStart, locEnd } from "../loc.js";
import isBlockComment from "../utils/is-block-comment.js";
function printComment(commentPath, options) {
const comment = commentPath.getValue();
const comment = commentPath.node;
if (isLineComment(comment)) {
// Supports `//`, `#!`, `<!--`, and `-->`
+2 -2
View File
@@ -10,7 +10,7 @@ import { locStart, locEnd } from "../loc.js";
import { getParentExportDeclaration } from "../utils/index.js";
function printClassMemberDecorators(path, options, print) {
const node = path.getValue();
const { node } = path;
return group([
join(line, path.map(print, "decorators")),
hasNewlineBetweenOrAfterDecorators(node, options) ? hardline : line,
@@ -27,7 +27,7 @@ function printDecoratorsBeforeExport(path, options, print) {
}
function printDecorators(path, options, print) {
const node = path.getValue();
const { node } = path;
const { decorators } = node;
if (
+1 -1
View File
@@ -36,7 +36,7 @@ import {
} from "./misc.js";
function printFlow(path, options, print) {
const node = path.getValue();
const { node } = path;
const semi = options.semi ? ";" : "";
/** @type{Doc[]} */
const parts = [];
+1 -1
View File
@@ -35,7 +35,7 @@ function printFunctionParameters(
expandArg,
printTypeParams
) {
const functionNode = path.getValue();
const functionNode = path.node;
const parameters = getFunctionParameters(functionNode);
const typeParams = printTypeParams
? printFunctionTypeParameters(path, options, print)
+8 -8
View File
@@ -48,7 +48,7 @@ import { printPropertyKey } from "./property.js";
import { printFunctionTypeParameters } from "./misc.js";
function printFunction(path, print, options, args) {
const node = path.getValue();
const { node } = path;
let expandArg = false;
if (
@@ -120,7 +120,7 @@ function printFunction(path, print, options, args) {
}
function printMethod(path, options, print) {
const node = path.getValue();
const { node } = path;
const { kind } = node;
const value = node.value || node;
const parts = [];
@@ -159,7 +159,7 @@ function printMethod(path, options, print) {
}
function printMethodInternal(path, options, print) {
const node = path.getValue();
const { node } = path;
const parametersDoc = printFunctionParameters(path, print, options);
const returnTypeDoc = printReturnType(path, print, options);
const shouldGroupParameters = shouldGroupFunctionParameters(
@@ -184,7 +184,7 @@ function printMethodInternal(path, options, print) {
}
function printArrowFunctionSignature(path, options, print, args) {
const node = path.getValue();
const { node } = path;
const parts = [];
if (node.async) {
@@ -288,7 +288,7 @@ function printArrowChain(
}
function printArrowFunction(path, options, print, args) {
let node = path.getValue();
let { node } = path;
/** @type {Doc[]} */
const signatures = [];
const body = [];
@@ -413,7 +413,7 @@ function shouldPrintParamsWithoutParens(path, options) {
}
if (options.arrowParens === "avoid") {
const node = path.getValue();
const { node } = path;
return canPrintParamsWithoutParens(node);
}
@@ -424,7 +424,7 @@ function shouldPrintParamsWithoutParens(path, options) {
/** @returns {Doc} */
function printReturnType(path, print, options) {
const node = path.getValue();
const { node } = path;
const returnType = print("returnType");
if (
@@ -452,7 +452,7 @@ function printReturnType(path, print, options) {
// `ReturnStatement` and `ThrowStatement`
function printReturnOrThrowArgument(path, options, print) {
const node = path.getValue();
const { node } = path;
const semi = options.semi ? ";" : "";
const parts = [];
+2 -2
View File
@@ -7,7 +7,7 @@ import {
} from "../../document/builders.js";
function printHtmlBinding(path, options, print) {
const node = path.getValue();
const { node } = path;
if (options.__onHtmlBindingRoot && path.getName() === null) {
options.__onHtmlBindingRoot(node, options);
@@ -25,7 +25,7 @@ function printHtmlBinding(path, options, print) {
functionDeclarationPath.map(print, "params")
);
const { params } = functionDeclarationPath.getValue();
const { params } = functionDeclarationPath.node;
if (params.length === 1) {
return printed;
}
+1 -1
View File
@@ -5,7 +5,7 @@ import { getTypeParametersGroupId } from "./type-parameters.js";
import { printTypeScriptModifiers } from "./misc.js";
function printInterface(path, options, print) {
const node = path.getValue();
const { node } = path;
const parts = [];
if (node.declare) {
parts.push("declare ");
+11 -11
View File
@@ -54,7 +54,7 @@ const isEmptyStringOrAnyLine = (doc) =>
// To support that case properly, all leading and trailing spaces
// are stripped from the list of children, and replaced with a single hardline.
function printJsxElementInternal(path, options, print) {
const node = path.getValue();
const { node } = path;
if (node.type === "JSXElement" && isEmptyJsxElement(node)) {
return [print("openingElement"), print("closingElement")];
@@ -271,7 +271,7 @@ function printJsxChildren(
) {
const parts = [];
path.each((childPath, i, children) => {
const child = childPath.getValue();
const child = childPath.node;
if (isLiteral(child)) {
const text = rawText(child);
@@ -465,7 +465,7 @@ function maybeWrapJsxElementInParens(path, elem, options) {
}
function printJsxAttribute(path, options, print) {
const node = path.getValue();
const { node } = path;
const parts = [];
parts.push(print("name"));
@@ -495,7 +495,7 @@ function printJsxAttribute(path, options, print) {
}
function printJsxExpressionContainer(path, options, print) {
const node = path.getValue();
const { node } = path;
const shouldInline = (node, parent) =>
node.type === "JSXEmptyExpression" ||
@@ -528,7 +528,7 @@ function printJsxExpressionContainer(path, options, print) {
}
function printJsxOpeningElement(path, options, print) {
const node = path.getValue();
const { node } = path;
const nameHasComments =
(node.name && hasComment(node.name)) ||
@@ -635,7 +635,7 @@ function shouldPrintBracketSameLine(node, options, nameHasComments) {
}
function printJsxClosingElement(path, options, print) {
const node = path.getValue();
const { node } = path;
const parts = [];
parts.push("</");
@@ -659,7 +659,7 @@ function printJsxClosingElement(path, options, print) {
}
function printJsxOpeningClosingFragment(path, options /*, print*/) {
const node = path.getValue();
const { node } = path;
const nodeHasComment = hasComment(node);
const hasOwnLineComment = hasComment(node, CommentCheckFlags.Line);
const isOpeningFragment = node.type === "JSXOpeningFragment";
@@ -688,7 +688,7 @@ function printJsxElement(path, options, print) {
}
function printJsxEmptyExpression(path, options /*, print*/) {
const node = path.getValue();
const { node } = path;
const requiresHardline = hasComment(node, CommentCheckFlags.Line);
return [
@@ -699,7 +699,7 @@ function printJsxEmptyExpression(path, options /*, print*/) {
// `JSXSpreadAttribute` and `JSXSpreadChild`
function printJsxSpreadAttribute(path, options, print) {
const node = path.getValue();
const { node } = path;
return [
"{",
path.call(
@@ -721,7 +721,7 @@ function printJsxSpreadAttribute(path, options, print) {
}
function printJsx(path, options, print) {
const node = path.getValue();
const { node } = path;
// JSX nodes always starts with `JSX`
if (!node.type.startsWith("JSX")) {
@@ -833,7 +833,7 @@ function isJsxWhitespaceExpression(node) {
* @returns {boolean}
*/
function hasJsxIgnoreComment(path) {
const node = path.getValue();
const { node } = path;
const parent = path.getParentNode();
if (!parent || !node || !isJsxNode(node) || !isJsxNode(parent)) {
return false;
+1 -1
View File
@@ -2,7 +2,7 @@ import { printString, printNumber } from "../../common/util.js";
import { replaceEndOfLine } from "../../document/utils.js";
function printLiteral(path, options /*, print*/) {
const node = path.getValue();
const { node } = path;
switch (node.type) {
case "RegExpLiteral": // Babel 6 Literal split
+2 -2
View File
@@ -86,7 +86,7 @@ function printMemberChain(path, options, print) {
}
function rec(path) {
const node = path.getValue();
const { node } = path;
if (
isCallExpression(node) &&
(isMemberish(node.callee) || isCallExpression(node.callee))
@@ -136,7 +136,7 @@ function printMemberChain(path, options, print) {
// Note: the comments of the root node have already been printed, so we
// need to extract this first call without printing them as they would
// if handled inside of the recursive call.
const node = path.getValue();
const { node } = path;
printedNodes.unshift({
node,
printed: [
+2 -2
View File
@@ -7,7 +7,7 @@ import {
import { printOptionalToken } from "./misc.js";
function printMemberExpression(path, options, print) {
const node = path.getValue();
const { node } = path;
const parent = path.getParentNode();
let firstNonMemberParent;
@@ -50,7 +50,7 @@ function printMemberExpression(path, options, print) {
function printMemberLookup(path, options, print) {
const property = print("property");
const node = path.getValue();
const { node } = path;
const optional = printOptionalToken(path);
if (!node.computed) {
+5 -5
View File
@@ -3,7 +3,7 @@ import { indent, join, line } from "../../document/builders.js";
import { isFlowAnnotationComment } from "../utils/index.js";
function printOptionalToken(path) {
const node = path.getValue();
const { node } = path;
if (
!node.optional ||
// It's an optional computed method parsed by typescript-estree.
@@ -22,7 +22,7 @@ function printOptionalToken(path) {
}
function printDefiniteToken(path) {
return path.getValue().definite ||
return path.node.definite ||
path.match(
undefined,
(node, name) =>
@@ -33,7 +33,7 @@ function printDefiniteToken(path) {
}
function printFunctionTypeParameters(path, options, print) {
const fun = path.getValue();
const fun = path.node;
if (fun.typeArguments) {
return print("typeArguments");
}
@@ -44,7 +44,7 @@ function printFunctionTypeParameters(path, options, print) {
}
function printTypeAnnotation(path, options, print) {
const node = path.getValue();
const { node } = path;
if (!node.typeAnnotation) {
return "";
}
@@ -66,7 +66,7 @@ function printBindExpressionCallee(path, options, print) {
}
function printTypeScriptModifiers(path, options, print) {
const node = path.getValue();
const { node } = path;
if (!isNonEmptyArray(node.modifiers)) {
return "";
}
+8 -8
View File
@@ -29,7 +29,7 @@ import {
*/
function printImportDeclaration(path, options, print) {
const node = path.getValue();
const { node } = path;
const semi = options.semi ? ";" : "";
/** @type{Doc[]} */
const parts = [];
@@ -53,7 +53,7 @@ function printImportDeclaration(path, options, print) {
}
function printExportDeclaration(path, options, print) {
const node = path.getValue();
const { node } = path;
/** @type{Doc[]} */
const parts = [];
@@ -102,7 +102,7 @@ function printExportDeclaration(path, options, print) {
}
function printExportAllDeclaration(path, options, print) {
const node = path.getValue();
const { node } = path;
const semi = options.semi ? ";" : "";
/** @type{Doc[]} */
const parts = [];
@@ -158,7 +158,7 @@ function shouldExportDeclarationPrintSemi(node, options) {
}
function printModuleSource(path, options, print) {
const node = path.getValue();
const { node } = path;
if (!node.source) {
return "";
@@ -175,7 +175,7 @@ function printModuleSource(path, options, print) {
}
function printModuleSpecifiers(path, options, print) {
const node = path.getValue();
const { node } = path;
if (shouldNotPrintSpecifiers(node, options)) {
return "";
@@ -189,7 +189,7 @@ function printModuleSpecifiers(path, options, print) {
const groupedSpecifiers = [];
path.each(() => {
const specifierType = path.getValue().type;
const specifierType = path.node.type;
if (
specifierType === "ExportNamespaceSpecifier" ||
specifierType === "ExportDefaultSpecifier" ||
@@ -269,7 +269,7 @@ function shouldNotPrintSpecifiers(node, options) {
}
function printImportAssertions(path, options, print) {
const node = path.getValue();
const { node } = path;
if (isNonEmptyArray(node.assertions)) {
return [
" assert {",
@@ -283,7 +283,7 @@ function printImportAssertions(path, options, print) {
}
function printModuleSpecifier(path, options, print) {
const node = path.getValue();
const { node } = path;
const { type } = node;
+2 -2
View File
@@ -31,7 +31,7 @@ import { printHardlineAfterHeritage } from "./class.js";
function printObject(path, options, print) {
const semi = options.semi ? ";" : "";
const node = path.getValue();
const { node } = path;
const isTypeAnnotation = node.type === "ObjectTypeAnnotation";
const fields = [
@@ -50,7 +50,7 @@ function printObject(path, options, print) {
// printing them.
const propsAndLoc = fields.flatMap((field) =>
path.map((childPath) => {
const node = childPath.getValue();
const { node } = childPath;
return {
node,
printed: print(),
+2 -2
View File
@@ -12,7 +12,7 @@ import { printAssignment } from "./assignment.js";
const needsQuoteProps = new WeakMap();
function printPropertyKey(path, options, print) {
const node = path.getValue();
const { node } = path;
if (node.computed) {
return ["[", print("key"), "]"];
@@ -88,7 +88,7 @@ function printPropertyKey(path, options, print) {
}
function printProperty(path, options, print) {
const node = path.getValue();
const { node } = path;
if (node.shorthand) {
return print("value");
}
+4 -4
View File
@@ -17,13 +17,13 @@ import { shouldPrintParamsWithoutParens } from "./function.js";
*/
function printStatementSequence(path, options, print, property) {
const node = path.getValue();
const { node } = path;
const parts = [];
const isClassBody = node.type === "ClassBody";
const lastStatement = getLastStatement(node[property]);
path.each((path, index, statements) => {
const node = path.getValue();
const { node } = path;
// Skip printing EmptyStatement nodes to avoid leaving stray
// semicolons lying around.
@@ -83,7 +83,7 @@ function getLastStatement(statements) {
}
function statementNeedsASIProtection(path, options) {
const node = path.getValue();
const { node } = path;
if (node.type !== "ExpressionStatement") {
return false;
@@ -96,7 +96,7 @@ function statementNeedsASIProtection(path, options) {
}
function expressionNeedsASIProtection(path, options) {
const node = path.getValue();
const { node } = path;
switch (node.type) {
case "ParenthesizedExpression":
case "TypeCastExpression":
+4 -4
View File
@@ -21,7 +21,7 @@ import {
} from "../utils/index.js";
function printTemplateLiteral(path, print, options) {
const node = path.getValue();
const { node } = path;
const isTemplateLiteral = node.type === "TemplateLiteral";
if (
@@ -72,7 +72,7 @@ function printTemplateLiteral(path, print, options) {
// expression inside at the beginning of ${ instead of the beginning
// of the `.
const { tabWidth } = options;
const quasi = childPath.getValue();
const quasi = childPath.node;
const indentSize = getIndentSize(quasi.value.raw, tabWidth);
let printed = expressions[i];
@@ -114,7 +114,7 @@ function printJestEachTemplateLiteral(path, options, print) {
* ${1} | ${2} | ${3}
* ${2} | ${1} | ${3}
*/
const node = path.getValue();
const { node } = path;
const headerNames = node.quasis[0].value.raw.trim().split(/\s*\|\s*/);
if (
headerNames.length > 1 ||
@@ -197,7 +197,7 @@ function printJestEachTemplateLiteral(path, options, print) {
}
function printTemplateExpression(path, print) {
const node = path.getValue();
const { node } = path;
let printed = print();
if (hasComment(node)) {
printed = group([indent([softline, printed]), softline]);
+3 -3
View File
@@ -102,7 +102,7 @@ function conditionalExpressionChainContainsJsx(node) {
}
function printTernaryTest(path, options, print) {
const node = path.getValue();
const { node } = path;
const isConditionalExpression = node.type === "ConditionalExpression";
const alternateNodePropertyName = isConditionalExpression
? "alternate"
@@ -138,7 +138,7 @@ const ancestorNameMap = new Map([
["YieldExpression", "argument"],
]);
function shouldExtraIndentForConditionalExpression(path) {
const node = path.getValue();
const { node } = path;
if (node.type !== "ConditionalExpression") {
return false;
}
@@ -188,7 +188,7 @@ function shouldExtraIndentForConditionalExpression(path) {
* @returns {Doc}
*/
function printTernary(path, options, print) {
const node = path.getValue();
const { node } = path;
const isConditionalExpression = node.type === "ConditionalExpression";
const consequentNodePropertyName = isConditionalExpression
? "consequent"
+8 -8
View File
@@ -58,7 +58,7 @@ function shouldHugType(node) {
function printOpaqueType(path, options, print) {
const semi = options.semi ? ";" : "";
const node = path.getValue();
const { node } = path;
const parts = [];
parts.push("opaque type ", print("id"), print("typeParameters"));
@@ -77,7 +77,7 @@ function printOpaqueType(path, options, print) {
function printTypeAlias(path, options, print) {
const semi = options.semi ? ";" : "";
const node = path.getValue();
const { node } = path;
const parts = [];
if (node.declare) {
parts.push("declare ");
@@ -93,7 +93,7 @@ function printTypeAlias(path, options, print) {
// `TSIntersectionType` and `IntersectionTypeAnnotation`
function printIntersectionType(path, options, print) {
const node = path.getValue();
const { node } = path;
const types = path.map(print, "types");
const result = [];
let wasIndented = false;
@@ -122,7 +122,7 @@ function printIntersectionType(path, options, print) {
// `TSUnionType` and `UnionTypeAnnotation`
function printUnionType(path, options, print) {
const node = path.getValue();
const { node } = path;
// single-line variation
// A | B | C
@@ -204,7 +204,7 @@ function printUnionType(path, options, print) {
// `TSFunctionType` and `FunctionTypeAnnotation`
function printFunctionType(path, options, print) {
const node = path.getValue();
const { node } = path;
const parts = [];
// FunctionTypeAnnotation is ambiguous:
// declare function foo(a: B): void; OR
@@ -286,7 +286,7 @@ function printFunctionType(path, options, print) {
// `TSTupleType` and `TupleTypeAnnotation`
function printTupleType(path, options, print) {
const node = path.getValue();
const { node } = path;
const typesField = node.type === "TSTupleType" ? "elementTypes" : "types";
const types = node[typesField];
const isNonEmptyTuple = isNonEmptyArray(types);
@@ -306,7 +306,7 @@ function printTupleType(path, options, print) {
// `TSIndexedAccessType`, `IndexedAccessType`, and `OptionalIndexedAccessType`
function printIndexedAccessType(path, options, print) {
const node = path.getValue();
const { node } = path;
const leftDelimiter =
node.type === "OptionalIndexedAccessType" && node.optional ? "?.[" : "[";
return [print("objectType"), leftDelimiter, print("indexType"), "]"];
@@ -314,7 +314,7 @@ function printIndexedAccessType(path, options, print) {
// `TSJSDocNullableType`, `TSJSDocNonNullableType`
function printJSDocType(path, print, token) {
const node = path.getValue();
const { node } = path;
return [
node.postfix ? "" : token,
print("typeAnnotation"),
+3 -3
View File
@@ -25,7 +25,7 @@ import { isArrowFunctionVariableDeclarator } from "./assignment.js";
const getTypeParametersGroupId = createGroupIdMapper("typeParameters");
function printTypeParameters(path, options, print, paramsKey) {
const node = path.getValue();
const { node } = path;
if (!node[paramsKey]) {
return "";
@@ -93,7 +93,7 @@ function printTypeParameters(path, options, print, paramsKey) {
}
function printDanglingCommentsForInline(path, options) {
const node = path.getValue();
const { node } = path;
if (!hasComment(node, CommentCheckFlags.Dangling)) {
return "";
}
@@ -110,7 +110,7 @@ function printDanglingCommentsForInline(path, options) {
}
function printTypeParameter(path, options, print) {
const node = path.getValue();
const { node } = path;
const parts = [];
const parent = path.getParentNode();
+1 -1
View File
@@ -47,7 +47,7 @@ import {
} from "./type-annotation.js";
function printTypescript(path, options, print) {
const node = path.getValue();
const { node } = path;
// TypeScript nodes always starts with `TS`
if (!node.type.startsWith("TS")) {
+2 -2
View File
@@ -4,7 +4,7 @@ import visitorKeys from "./traverse/json-visitor-keys.js";
import preprocess from "./print-preprocess.js";
function genericPrint(path, options, print) {
const node = path.getValue();
const { node } = path;
switch (node.type) {
case "JsonRoot":
return [print("node"), hardline];
@@ -14,7 +14,7 @@ function genericPrint(path, options, print) {
}
const printed = path.map(
() => (path.getValue() === null ? "null" : print()),
() => (path.node === null ? "null" : print()),
"elements"
);
+3 -3
View File
@@ -90,7 +90,7 @@ import { printLiteral } from "./print/literal.js";
import { printDecorators } from "./print/decorators.js";
function genericPrint(path, options, print, args) {
const node = path.getValue();
const { node } = path;
const printed = printPathNoParens(path, options, print, args);
if (!printed) {
@@ -184,7 +184,7 @@ function printPathNoParens(path, options, print, args) {
}
}
const node = path.getValue();
const { node } = path;
const semi = options.semi ? ";" : "";
/** @type{Doc[]} */
let parts = [];
@@ -695,7 +695,7 @@ function printPathNoParens(path, options, print, args) {
join(
hardline,
path.map((casePath, index, cases) => {
const caseNode = casePath.getValue();
const caseNode = casePath.node;
return [
print(),
index !== cases.length - 1 &&
+5 -5
View File
@@ -317,7 +317,7 @@ function isTheOnlyJsxElementInMarkdown(options, path) {
return false;
}
const node = path.getValue();
const { node } = path;
if (!node.expression || !isJsxNode(node.expression)) {
return false;
@@ -810,7 +810,7 @@ function isFunctionCompositionArgs(args) {
* @returns {boolean}
*/
function isLongCurriedCallExpression(path) {
const node = path.getValue();
const { node } = path;
const parent = path.getParentNode();
return (
isCallExpression(node) &&
@@ -1132,7 +1132,7 @@ function getFunctionParameters(node) {
}
function iterateFunctionParametersPath(path, iteratee) {
const node = path.getValue();
const { node } = path;
let index = 0;
const callback = (childPath) => iteratee(childPath, index++);
if (node.this) {
@@ -1168,7 +1168,7 @@ function getCallArguments(node) {
}
function iterateCallArgumentsPath(path, iteratee) {
const node = path.getValue();
const { node } = path;
if (node.type === "ImportExpression") {
path.call((sourcePath) => iteratee(sourcePath, 0), "source");
@@ -1211,7 +1211,7 @@ function hasNodeIgnoreComment(node) {
}
function hasIgnoreComment(path) {
const node = path.getValue();
const { node } = path;
return hasNodeIgnoreComment(node);
}
+1 -1
View File
@@ -8,7 +8,7 @@ import printFrontMatter from "../utils/front-matter/print.js";
import { getFencedCodeBlockValue } from "./utils.js";
function embed(path, options) {
const node = path.getValue();
const { node } = path;
if (node.type === "code" && node.lang !== null) {
const parser = inferParserByLanguage(node.lang, options);
+1 -1
View File
@@ -1,7 +1,7 @@
import { hardline } from "../document/builders.js";
function embed(path, options) {
const node = path.getValue();
const { node } = path;
// Try to format `.prettierrc`, `.stylelintrc`, and `.lintstagedrc` as `json` first
if (
+1 -1
View File
@@ -20,7 +20,7 @@ import {
import { alignWithSpaces } from "./misc.js";
function printBlock(path, print, options) {
const node = path.getValue();
const { node } = path;
const parentIndent = getAncestorCount(path, (ancestorNode) =>
isNode(ancestorNode, ["sequence", "mapping"])
);
@@ -9,7 +9,7 @@ import { isEmptyNode, getLast, hasEndComments } from "../utils.js";
import { printNextEmptyLine, alignWithSpaces } from "./misc.js";
function printFlowMapping(path, print, options) {
const node = path.getValue();
const { node } = path;
const isMapping = node.type === "flowMapping";
const openMarker = isMapping ? "{" : "[";
const closeMarker = isMapping ? "}" : "]";
@@ -42,7 +42,7 @@ function printFlowMapping(path, print, options) {
}
function printChildren(path, print, options) {
const node = path.getValue();
const { node } = path;
const parts = path.map(
(childPath, index) => [
print(),
+1 -1
View File
@@ -3,7 +3,7 @@ import { hasEndComments, isNextLineEmpty, isNode } from "../utils.js";
const printedEmptyLineCache = new WeakMap();
function printNextEmptyLine(path, originalText) {
const node = path.getValue();
const { node } = path;
const root = path.stack[0];
let isNextEmptyLinePrintedSet;
+2 -6
View File
@@ -45,7 +45,7 @@ import printBlock from "./print/block.js";
const getVisitorKeys = createGetVisitorKeys(visitorKeys);
function genericPrint(path, options, print) {
const node = path.getValue();
const { node } = path;
/** @type {Doc[]} */
const parts = [];
@@ -133,11 +133,7 @@ function genericPrint(path, options, print) {
hardline,
path.map(
(path) => [
isPreviousLineEmpty(
options.originalText,
path.getValue(),
locStart
)
isPreviousLineEmpty(options.originalText, path.node, locStart)
? hardline
: "",
print(),
+2 -2
View File
@@ -68,7 +68,7 @@ function isNextLineEmpty(node, text) {
}
function isLastDescendantNode(path) {
const node = path.getValue();
const { node } = path;
switch (node.type) {
case "tag":
@@ -106,7 +106,7 @@ function isPrettierIgnore(comment) {
}
function hasPrettierIgnore(path) {
const node = path.getValue();
const { node } = path;
if (node.type === "documentBody") {
const document = path.getParentNode();
+2 -2
View File
@@ -76,7 +76,7 @@ async function printAstToDoc(ast, options, alignmentSize = 0) {
function mainPrintInternal(args) {
ensurePrintingNode(path);
const value = path.getValue();
const value = path.node;
if (value === undefined || value === null) {
return "";
@@ -122,7 +122,7 @@ function printPrettierIgnoredNode(node, options) {
}
function callPluginPrintFunction(path, options, printPath, args, embeds) {
const node = path.getValue();
const { node } = path;
const { printer } = options;
let doc;
+7 -7
View File
@@ -406,7 +406,7 @@ function breakTies(tiesToBreak, text, options) {
}
function printComment(path, options) {
const comment = path.getValue();
const comment = path.node;
comment.printed = true;
return options.printer.printComment(path, options);
}
@@ -427,7 +427,7 @@ function findExpressionIndexForComment(quasis, comment, options) {
}
function printLeadingComment(path, options) {
const comment = path.getValue();
const comment = path.node;
const parts = [printComment(path, options)];
const { printer, originalText, locStart, locEnd } = options;
@@ -462,7 +462,7 @@ function printLeadingComment(path, options) {
}
function printTrailingComment(path, options, previousComment) {
const comment = path.getValue();
const comment = path.node;
const printed = printComment(path, options);
const { printer, originalText, locStart } = options;
@@ -510,14 +510,14 @@ function printTrailingComment(path, options, previousComment) {
function printDanglingComments(path, options, sameIndent, filter) {
const parts = [];
const node = path.getValue();
const { node } = path;
if (!node || !node.comments) {
return "";
}
path.each(() => {
const comment = path.getValue();
const comment = path.node;
if (!comment.leading && !comment.trailing && (!filter || filter(comment))) {
parts.push(printComment(path, options));
}
@@ -534,7 +534,7 @@ function printDanglingComments(path, options, sameIndent, filter) {
}
function printCommentsSeparately(path, options, ignored) {
const value = path.getValue();
const value = path.node;
if (!value) {
return {};
}
@@ -554,7 +554,7 @@ function printCommentsSeparately(path, options, ignored) {
const trailingParts = [];
let printedTrailingComment;
path.each(() => {
const comment = path.getValue();
const comment = path.node;
if (ignored && ignored.has(comment)) {
return;
}
+1 -1
View File
@@ -51,7 +51,7 @@ function createPrintPreCheckFunction(options) {
parentNode,
allowedProperties: visitorKeys,
printingProperty: name,
printingValue: path.getValue(),
printingValue: path.node,
pathStack:
path.stack.length > 5
? ["...", ...path.stack.slice(-5)]
+1 -1
View File
@@ -62,7 +62,7 @@ async function printEmbeddedLanguages(
}
function recurse() {
const node = path.getValue();
const { node } = path;
if (node === null || typeof node !== "object" || hasPrettierIgnore(path)) {
return;
}