Skip to content

Commit 1fc9ab8

Browse files
committed
replace FastPath with AstPath
1 parent 727ddce commit 1fc9ab8

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

src/embed.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Doc, doc, FastPath, Options } from 'prettier';
1+
import { Doc, doc, AstPath, Options } from 'prettier';
22
import { getText } from './lib/getText';
33
import { snippedTagContentAttribute } from './lib/snipTagContent';
44
import { isBracketSameLine, ParserOptions } from './options';
@@ -49,7 +49,7 @@ export function getVisitorKeys(node: any, nonTraversableKeys: Set<string>): stri
4949
// - deepest property is calling embed first
5050
// - if embed returns a function, it will be called after the traversal in a second pass, in the same order (deepest first)
5151
// For performance reasons we try to only return functions when we're sure we need to transform something.
52-
export function embed(path: FastPath, _options: Options) {
52+
export function embed(path: AstPath, _options: Options) {
5353
const node: Node = path.getNode();
5454
const options = _options as ParserOptions;
5555
if (!options.locStart || !options.locEnd || !options.originalText) {
@@ -343,7 +343,7 @@ async function formatBodyContent(
343343
async function embedTag(
344344
tag: 'script' | 'style' | 'template',
345345
text: string,
346-
path: FastPath,
346+
path: AstPath,
347347
formatBodyContent: (content: string) => Promise<Doc>,
348348
print: PrintFn,
349349
isTopLevel: boolean,

src/print/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Doc, doc, FastPath } from 'prettier';
1+
import { Doc, doc, AstPath } from 'prettier';
22
import { PrintFn } from '.';
33
import { formattableAttributes } from '../lib/elements';
44
import { snippedTagContentAttribute } from '../lib/snipTagContent';
@@ -29,7 +29,7 @@ export function isASTNode(n: any): n is ASTNode {
2929
return n && n.__isRoot;
3030
}
3131

32-
export function isPreTagContent(path: FastPath): boolean {
32+
export function isPreTagContent(path: AstPath): boolean {
3333
const stack = path.stack as Node[];
3434

3535
return stack.some(

src/print/index.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Doc, doc, FastPath } from 'prettier';
1+
import { Doc, doc, AstPath } from 'prettier';
22
import { formattableAttributes, selfClosingTags } from '../lib/elements';
33
import { hasSnippedContent, unsnipContent } from '../lib/snipTagContent';
44
import { isBracketSameLine, ParserOptions, parseSortOrder, SortOrderPart } from '../options';
@@ -56,7 +56,7 @@ import {
5656
const { join, line, group, indent, dedent, softline, hardline, fill, breakParent, literalline } =
5757
doc.builders;
5858

59-
export type PrintFn = (path: FastPath) => Doc;
59+
export type PrintFn = (path: AstPath) => Doc;
6060

6161
declare module 'prettier' {
6262
export namespace doc {
@@ -76,7 +76,7 @@ let ignoreNext = false;
7676
let ignoreRange = false;
7777
let svelteOptionsDoc: Doc | undefined;
7878

79-
export function print(path: FastPath, options: ParserOptions, print: PrintFn): Doc {
79+
export function print(path: AstPath, options: ParserOptions, print: PrintFn): Doc {
8080
const bracketSameLine = isBracketSameLine(options);
8181

8282
const n = path.getValue();
@@ -498,7 +498,7 @@ export function print(path: FastPath, options: ParserOptions, print: PrintFn): D
498498
if (ifNode.else) {
499499
def.push(
500500
path.map(
501-
(ifPath: FastPath<any>) => ifPath.call(print, 'else'),
501+
(ifPath: AstPath<any>) => ifPath.call(print, 'else'),
502502
'children',
503503
)[0],
504504
);
@@ -739,7 +739,7 @@ export function print(path: FastPath, options: ParserOptions, print: PrintFn): D
739739
function printTopLevelParts(
740740
n: ASTNode,
741741
options: ParserOptions,
742-
path: FastPath<any>,
742+
path: AstPath<any>,
743743
print: PrintFn,
744744
): Doc {
745745
if (options.svelteSortOrder === 'none') {
@@ -825,7 +825,7 @@ function printTopLevelParts(
825825
}
826826

827827
function printAttributeNodeValue(
828-
path: FastPath<any>,
828+
path: AstPath<any>,
829829
print: PrintFn,
830830
quotes: boolean,
831831
node: AttributeNode | StyleDirectiveNode,
@@ -839,7 +839,7 @@ function printAttributeNodeValue(
839839
}
840840
}
841841

842-
function printSvelteBlockChildren(path: FastPath, print: PrintFn, options: ParserOptions): Doc {
842+
function printSvelteBlockChildren(path: AstPath, print: PrintFn, options: ParserOptions): Doc {
843843
const node = path.getValue();
844844
const children = node.children;
845845
if (!children || children.length === 0) {
@@ -876,7 +876,7 @@ function printSvelteBlockChildren(path: FastPath, print: PrintFn, options: Parse
876876
function printPre(
877877
node: Parameters<typeof printRaw>[0],
878878
originalText: string,
879-
path: FastPath,
879+
path: AstPath,
880880
print: PrintFn,
881881
): Doc {
882882
const result: Doc = [];
@@ -896,7 +896,7 @@ function printPre(
896896
return result;
897897
}
898898

899-
function printChildren(path: FastPath, print: PrintFn, options: ParserOptions): Doc {
899+
function printChildren(path: AstPath, print: PrintFn, options: ParserOptions): Doc {
900900
if (isPreTagContent(path)) {
901901
return path.map(print, 'children');
902902
}
@@ -1050,7 +1050,7 @@ function printChildren(path: FastPath, print: PrintFn, options: ParserOptions):
10501050
*/
10511051
function prepareChildren(
10521052
children: Node[],
1053-
path: FastPath,
1053+
path: AstPath,
10541054
print: PrintFn,
10551055
options: ParserOptions,
10561056
): Node[] {
@@ -1107,7 +1107,7 @@ function prepareChildren(
11071107
function printSvelteOptions(
11081108
node: OptionsNode,
11091109
idx: number,
1110-
path: FastPath,
1110+
path: AstPath,
11111111
print: PrintFn,
11121112
): void {
11131113
svelteOptionsDoc = group([
@@ -1181,7 +1181,7 @@ function splitTextToDocs(node: TextNode): Doc[] {
11811181
return docs;
11821182
}
11831183

1184-
function printJS(path: FastPath, print: PrintFn, name: string) {
1184+
function printJS(path: AstPath, print: PrintFn, name: string) {
11851185
return path.call(print, name);
11861186
}
11871187

src/print/node-helpers.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ import {
2525
CommentInfo,
2626
} from './nodes';
2727
import { blockElements, TagName } from '../lib/elements';
28-
import { FastPath } from 'prettier';
28+
import { AstPath } from 'prettier';
2929
import { findLastIndex, isASTNode, isPreTagContent } from './helpers';
3030
import { ParserOptions, isBracketSameLine } from '../options';
3131

3232
const unsupportedLanguages = ['coffee', 'coffeescript', 'styl', 'stylus', 'sass'];
3333

34-
export function isInlineElement(path: FastPath, options: ParserOptions, node: Node) {
34+
export function isInlineElement(path: AstPath, options: ParserOptions, node: Node) {
3535
return (
3636
node && node.type === 'Element' && !isBlockElement(node, options) && !isPreTagContent(path)
3737
);
@@ -82,7 +82,7 @@ export function getChildren(node: Node): Node[] {
8282
/**
8383
* Returns siblings, that is, the children of the parent.
8484
*/
85-
export function getSiblings(path: FastPath): Node[] {
85+
export function getSiblings(path: AstPath): Node[] {
8686
let parent: Node = path.getParentNode();
8787

8888
if (isASTNode(parent)) {
@@ -95,22 +95,22 @@ export function getSiblings(path: FastPath): Node[] {
9595
/**
9696
* Returns the previous sibling node.
9797
*/
98-
export function getPreviousNode(path: FastPath): Node | undefined {
98+
export function getPreviousNode(path: AstPath): Node | undefined {
9999
const node: Node = path.getNode();
100100
return getSiblings(path).find((child) => child.end === node.start);
101101
}
102102

103103
/**
104104
* Returns the next sibling node.
105105
*/
106-
export function getNextNode(path: FastPath, node: Node = path.getNode()): Node | undefined {
106+
export function getNextNode(path: AstPath, node: Node = path.getNode()): Node | undefined {
107107
return getSiblings(path).find((child) => child.start === node.end);
108108
}
109109

110110
/**
111111
* Returns the comment that is above the current node.
112112
*/
113-
export function getLeadingComment(path: FastPath): CommentNode | undefined {
113+
export function getLeadingComment(path: AstPath): CommentNode | undefined {
114114
const siblings = getSiblings(path);
115115

116116
let node: Node = path.getNode();
@@ -135,7 +135,7 @@ export function getLeadingComment(path: FastPath): CommentNode | undefined {
135135
* Did there use to be any embedded object (that has been snipped out of the AST to be moved)
136136
* at the specified position?
137137
*/
138-
export function doesEmbedStartAfterNode(node: Node, path: FastPath, siblings = getSiblings(path)) {
138+
export function doesEmbedStartAfterNode(node: Node, path: AstPath, siblings = getSiblings(path)) {
139139
// If node is not at the top level of html, an embed cannot start after it,
140140
// because embeds are only at the top level
141141
if (!isNodeTopLevelHTML(node, path)) {
@@ -151,7 +151,7 @@ export function doesEmbedStartAfterNode(node: Node, path: FastPath, siblings = g
151151
return embeds.find((n) => n && n.start >= position && (!nextNode || n.end <= nextNode.start));
152152
}
153153

154-
export function isNodeTopLevelHTML(node: Node, path: FastPath): boolean {
154+
export function isNodeTopLevelHTML(node: Node, path: AstPath): boolean {
155155
const root = path.stack[0];
156156
return !!root.html && !!root.html.children && root.html.children.includes(node);
157157
}
@@ -355,7 +355,7 @@ export function trimTextNodeLeft(node: TextNode): void {
355355
* Remove all leading whitespace up until the first non-empty text node,
356356
* and all trailing whitespace from the last non-empty text node onwards.
357357
*/
358-
export function trimChildren(children: Node[], path: FastPath): void {
358+
export function trimChildren(children: Node[], path: AstPath): void {
359359
let firstNonEmptyNode = children.findIndex(
360360
(n) => !isEmptyTextNode(n) && !doesEmbedStartAfterNode(n, path),
361361
);
@@ -528,7 +528,7 @@ export function checkWhitespaceAtEndOfSvelteBlock(
528528
return 'none';
529529
}
530530

531-
export function isInsideQuotedAttribute(path: FastPath, options: ParserOptions): boolean {
531+
export function isInsideQuotedAttribute(path: AstPath, options: ParserOptions): boolean {
532532
const stack = path.stack as Node[];
533533

534534
return stack.some(
@@ -544,7 +544,7 @@ export function isInsideQuotedAttribute(path: FastPath, options: ParserOptions):
544544
*/
545545
export function canOmitSoftlineBeforeClosingTag(
546546
node: Node,
547-
path: FastPath,
547+
path: AstPath,
548548
options: ParserOptions,
549549
): boolean {
550550
return (
@@ -566,7 +566,7 @@ function hugsStartOfNextNode(node: Node, options: ParserOptions): boolean {
566566
return !options.originalText.substring(node.end).match(/^\s/);
567567
}
568568

569-
function isLastChildWithinParentBlockElement(path: FastPath, options: ParserOptions): boolean {
569+
function isLastChildWithinParentBlockElement(path: AstPath, options: ParserOptions): boolean {
570570
const parent = path.getParentNode() as Node | undefined;
571571
if (!parent || !isBlockElement(parent, options)) {
572572
return false;

0 commit comments

Comments
 (0)