@@ -23,7 +23,7 @@ import {
23
23
} from './nodes' ;
24
24
import { blockElements , TagName } from '../lib/elements' ;
25
25
import { AstPath } from 'prettier' ;
26
- import { findLastIndex , isASTNode , isPreTagContent } from './helpers' ;
26
+ import { findLastIndex , isPreTagContent } from './helpers' ;
27
27
import { ParserOptions , isBracketSameLine } from '../options' ;
28
28
29
29
const unsupportedLanguages = [ 'coffee' , 'coffeescript' , 'styl' , 'stylus' , 'sass' ] ;
@@ -76,21 +76,17 @@ export function getChildren(node: SvelteNode): SvelteNode[] {
76
76
export function getSiblings ( path : AstPath ) : SvelteNode [ ] {
77
77
let parent : SvelteNode = path . getParentNode ( ) ;
78
78
79
+ if ( parent . type === 'Fragment' ) return parent . nodes ;
80
+
79
81
return getChildren ( parent ) ;
80
82
}
81
83
82
84
/**
83
- * Returns the previous sibling node.
85
+ * Returns the next sibling node.
84
86
*/
85
- export function getPreviousNode ( path : AstPath ) : SvelteNode | undefined {
87
+ export function getNextNode ( path : AstPath ) : SvelteNode | undefined {
86
88
const node : SvelteNode = path . getNode ( ) ;
87
- return getSiblings ( path ) . find ( ( child ) => child . end === node . start ) ;
88
- }
89
89
90
- /**
91
- * Returns the next sibling node.
92
- */
93
- export function getNextNode ( path : AstPath , node : SvelteNode = path . getNode ( ) ) : SvelteNode | undefined {
94
90
return getSiblings ( path ) . find ( ( child ) => child . start === node . end ) ;
95
91
}
96
92
@@ -122,7 +118,7 @@ export function getLeadingComment(path: AstPath): Comment | undefined {
122
118
* Did there use to be any embedded object (that has been snipped out of the AST to be moved)
123
119
* at the specified position?
124
120
*/
125
- export function doesEmbedStartAfterNode ( node : SvelteNode , path : AstPath , siblings = getSiblings ( path ) ) {
121
+ export function doesEmbedStartAfterNode ( node : SvelteNode , path : AstPath ) {
126
122
// If node is not at the top level of html, an embed cannot start after it,
127
123
// because embeds are only at the top level
128
124
if ( ! isNodeTopLevelHTML ( node , path ) ) {
@@ -132,15 +128,15 @@ export function doesEmbedStartAfterNode(node: SvelteNode, path: AstPath, sibling
132
128
const position = node . end ;
133
129
const root = path . stack [ 0 ] as Root ;
134
130
135
- const embeds = [ root . css , root . html , root . instance , root . js , root . module ] as SvelteNode [ ] ;
136
-
131
+ const embeds = [ root . css , root . fragment , root . instance , root . module , root . options ] as SvelteNode [ ] ;
132
+ const siblings = getSiblings ( path ) ;
137
133
const nextNode = siblings [ siblings . indexOf ( node ) + 1 ] ;
138
134
return embeds . find ( ( n ) => n && n . start >= position && ( ! nextNode || n . end <= nextNode . start ) ) ;
139
135
}
140
136
141
137
export function isNodeTopLevelHTML ( node : SvelteNode , path : AstPath ) : boolean {
142
- const root = path . stack [ 0 ] ;
143
- return ! ! root . html && ! ! root . html . children && root . html . children . includes ( node ) ;
138
+ const root = path . stack [ 0 ] as Root | undefined ;
139
+ return ! ! root && root . fragment . nodes . includes ( node ) ;
144
140
}
145
141
146
142
export function isEmptyTextNode ( node : SvelteNode | undefined ) : node is Text {
0 commit comments