1
- import { builders , utils } from "prettier/doc" ;
2
- import {
3
- AnyNode ,
4
- ContentCtx ,
5
- Doc ,
6
- ElementCstNode ,
7
- Embed ,
8
- Options ,
9
- Path
10
- } from "./types" ;
1
+ const { builders, utils } = require ( "prettier/doc" ) ;
11
2
12
3
const {
13
4
dedentToRoot,
@@ -22,7 +13,7 @@ const {
22
13
23
14
// Replace the string content newlines within a doc tree with literallines so
24
15
// that all of the indentation lines up appropriately
25
- function replaceNewlines ( doc : Doc ) {
16
+ function replaceNewlines ( doc ) {
26
17
return utils . mapDoc ( doc , ( currentDoc ) =>
27
18
typeof currentDoc === "string" && currentDoc . includes ( "\n" )
28
19
? currentDoc . split ( / ( \n ) / g) . map ( ( v , i ) => ( i % 2 === 0 ? v : literalline ) )
@@ -31,16 +22,12 @@ function replaceNewlines(doc: Doc) {
31
22
}
32
23
33
24
// Get the start and end element tags from the current node on the tree
34
- function getElementTags (
35
- path : Path < ElementCstNode > ,
36
- opts : Options ,
37
- print : ( path : Path < AnyNode > ) => Doc
38
- ) {
25
+ function getElementTags ( path , opts , print ) {
39
26
const node = path . getValue ( ) ;
40
27
const { OPEN , Name, attribute, START_CLOSE , SLASH_OPEN , END_NAME , END } =
41
28
node . children ;
42
29
43
- const parts : Doc [ ] = [ OPEN [ 0 ] . image , Name [ 0 ] . image ] ;
30
+ const parts = [ OPEN [ 0 ] . image , Name [ 0 ] . image ] ;
44
31
45
32
if ( attribute ) {
46
33
parts . push (
@@ -60,7 +47,7 @@ function getElementTags(
60
47
61
48
// Get the name of the parser that is represented by the given element node,
62
49
// return null if a matching parser cannot be found
63
- function getParser ( node : ElementCstNode , opts : Options ) {
50
+ function getParser ( node , opts ) {
64
51
const { Name, attribute } = node . children ;
65
52
const parser = Name [ 0 ] . image . toLowerCase ( ) ;
66
53
@@ -103,14 +90,14 @@ function getParser(node: ElementCstNode, opts: Options) {
103
90
104
91
// Get the source string that will be passed into the embedded parser from the
105
92
// content of the inside of the element node
106
- function getSource ( content : ContentCtx ) {
93
+ function getSource ( content ) {
107
94
return content . chardata
108
95
. map ( ( node ) => {
109
96
const { SEA_WS , TEXT } = node . children ;
110
97
const [ { image } ] = SEA_WS || TEXT ;
111
98
112
99
return {
113
- offset : node . location ! . startOffset ,
100
+ offset : node . location . startOffset ,
114
101
printed : image
115
102
} ;
116
103
} )
@@ -119,7 +106,7 @@ function getSource(content: ContentCtx) {
119
106
. join ( "" ) ;
120
107
}
121
108
122
- const embed : Embed = ( path , print , textToDoc , opts ) => {
109
+ function embed ( path , print , textToDoc , opts ) {
123
110
const node = path . getValue ( ) ;
124
111
125
112
// If the node isn't an element node, then skip
@@ -143,8 +130,7 @@ const embed: Embed = (path, print, textToDoc, opts) => {
143
130
144
131
// Get the open and close tags of this element, then return the properly
145
132
// formatted content enclosed within them
146
- const nodePath = path as Path < typeof node > ;
147
- const { openTag, closeTag } = getElementTags ( nodePath , opts , print ) ;
133
+ const { openTag, closeTag } = getElementTags ( path , opts , print ) ;
148
134
149
135
return group ( [
150
136
openTag ,
@@ -161,4 +147,4 @@ const embed: Embed = (path, print, textToDoc, opts) => {
161
147
] ) ;
162
148
} ;
163
149
164
- export default embed ;
150
+ module . exports = embed ;
0 commit comments