Skip to content

Commit ffe8b2c

Browse files
committed
replace FastPath with AstPath
1 parent b120c4d commit ffe8b2c

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) {
@@ -329,7 +329,7 @@ async function formatBodyContent(
329329
async function embedTag(
330330
tag: 'script' | 'style' | 'template',
331331
text: string,
332-
path: FastPath,
332+
path: AstPath,
333333
formatBodyContent: (content: string) => Promise<Doc>,
334334
print: PrintFn,
335335
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';
@@ -57,7 +57,7 @@ import {
5757
const { join, line, group, indent, dedent, softline, hardline, fill, breakParent, literalline } =
5858
doc.builders;
5959

60-
export type PrintFn = (path: FastPath) => Doc;
60+
export type PrintFn = (path: AstPath) => Doc;
6161

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

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

8383
const n = path.getValue();
@@ -499,7 +499,7 @@ export function print(path: FastPath, options: ParserOptions, print: PrintFn): D
499499
if (ifNode.else) {
500500
def.push(
501501
path.map(
502-
(ifPath: FastPath<any>) => ifPath.call(print, 'else'),
502+
(ifPath: AstPath<any>) => ifPath.call(print, 'else'),
503503
'children',
504504
)[0],
505505
);
@@ -741,7 +741,7 @@ export function print(path: FastPath, options: ParserOptions, print: PrintFn): D
741741
function printTopLevelParts(
742742
n: ASTNode,
743743
options: ParserOptions,
744-
path: FastPath<any>,
744+
path: AstPath<any>,
745745
print: PrintFn,
746746
): Doc {
747747
if (options.svelteSortOrder === 'none') {
@@ -827,7 +827,7 @@ function printTopLevelParts(
827827
}
828828

829829
function printAttributeNodeValue(
830-
path: FastPath<any>,
830+
path: AstPath<any>,
831831
print: PrintFn,
832832
quotes: boolean,
833833
node: AttributeNode | StyleDirectiveNode,
@@ -841,7 +841,7 @@ function printAttributeNodeValue(
841841
}
842842
}
843843

844-
function printSvelteBlockChildren(path: FastPath, print: PrintFn, options: ParserOptions): Doc {
844+
function printSvelteBlockChildren(path: AstPath, print: PrintFn, options: ParserOptions): Doc {
845845
const node = path.getValue();
846846
const children = node.children;
847847
if (!children || children.length === 0) {
@@ -878,7 +878,7 @@ function printSvelteBlockChildren(path: FastPath, print: PrintFn, options: Parse
878878
function printPre(
879879
node: Parameters<typeof printRaw>[0],
880880
originalText: string,
881-
path: FastPath,
881+
path: AstPath,
882882
print: PrintFn,
883883
): Doc {
884884
const result: Doc = [];
@@ -898,7 +898,7 @@ function printPre(
898898
return result;
899899
}
900900

901-
function printChildren(path: FastPath, print: PrintFn, options: ParserOptions): Doc {
901+
function printChildren(path: AstPath, print: PrintFn, options: ParserOptions): Doc {
902902
if (isPreTagContent(path)) {
903903
return path.map(print, 'children');
904904
}
@@ -1052,7 +1052,7 @@ function printChildren(path: FastPath, print: PrintFn, options: ParserOptions):
10521052
*/
10531053
function prepareChildren(
10541054
children: Node[],
1055-
path: FastPath,
1055+
path: AstPath,
10561056
print: PrintFn,
10571057
options: ParserOptions,
10581058
): Node[] {
@@ -1109,7 +1109,7 @@ function prepareChildren(
11091109
function printSvelteOptions(
11101110
node: OptionsNode,
11111111
idx: number,
1112-
path: FastPath,
1112+
path: AstPath,
11131113
print: PrintFn,
11141114
): void {
11151115
svelteOptionsDoc = group([
@@ -1183,7 +1183,7 @@ function splitTextToDocs(node: TextNode): Doc[] {
11831183
return docs;
11841184
}
11851185

1186-
function printJS(path: FastPath, print: PrintFn, name: string) {
1186+
function printJS(path: AstPath, print: PrintFn, name: string) {
11871187
return path.call(print, name);
11881188
}
11891189

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(
@@ -543,7 +543,7 @@ export function isInsideQuotedAttribute(path: FastPath, options: ParserOptions):
543543
*/
544544
export function canOmitSoftlineBeforeClosingTag(
545545
node: Node,
546-
path: FastPath,
546+
path: AstPath,
547547
options: ParserOptions,
548548
): boolean {
549549
return (
@@ -565,7 +565,7 @@ function hugsStartOfNextNode(node: Node, options: ParserOptions): boolean {
565565
return !options.originalText.substring(node.end).match(/^\s/);
566566
}
567567

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

0 commit comments

Comments
 (0)