@@ -23,7 +23,7 @@ import {
2323} from './nodes' ;
2424import { blockElements , TagName } from '../lib/elements' ;
2525import { AstPath } from 'prettier' ;
26- import { findLastIndex , isASTNode , isPreTagContent } from './helpers' ;
26+ import { findLastIndex , isPreTagContent } from './helpers' ;
2727import { ParserOptions , isBracketSameLine } from '../options' ;
2828
2929const unsupportedLanguages = [ 'coffee' , 'coffeescript' , 'styl' , 'stylus' , 'sass' ] ;
@@ -76,21 +76,17 @@ export function getChildren(node: SvelteNode): SvelteNode[] {
7676export function getSiblings ( path : AstPath ) : SvelteNode [ ] {
7777 let parent : SvelteNode = path . getParentNode ( ) ;
7878
79+ if ( parent . type === 'Fragment' ) return parent . nodes ;
80+
7981 return getChildren ( parent ) ;
8082}
8183
8284/**
83- * Returns the previous sibling node.
85+ * Returns the next sibling node.
8486 */
85- export function getPreviousNode ( path : AstPath ) : SvelteNode | undefined {
87+ export function getNextNode ( path : AstPath ) : SvelteNode | undefined {
8688 const node : SvelteNode = path . getNode ( ) ;
87- return getSiblings ( path ) . find ( ( child ) => child . end === node . start ) ;
88- }
8989
90- /**
91- * Returns the next sibling node.
92- */
93- export function getNextNode ( path : AstPath , node : SvelteNode = path . getNode ( ) ) : SvelteNode | undefined {
9490 return getSiblings ( path ) . find ( ( child ) => child . start === node . end ) ;
9591}
9692
@@ -122,7 +118,7 @@ export function getLeadingComment(path: AstPath): Comment | undefined {
122118 * Did there use to be any embedded object (that has been snipped out of the AST to be moved)
123119 * at the specified position?
124120 */
125- export function doesEmbedStartAfterNode ( node : SvelteNode , path : AstPath , siblings = getSiblings ( path ) ) {
121+ export function doesEmbedStartAfterNode ( node : SvelteNode , path : AstPath ) {
126122 // If node is not at the top level of html, an embed cannot start after it,
127123 // because embeds are only at the top level
128124 if ( ! isNodeTopLevelHTML ( node , path ) ) {
@@ -132,15 +128,15 @@ export function doesEmbedStartAfterNode(node: SvelteNode, path: AstPath, sibling
132128 const position = node . end ;
133129 const root = path . stack [ 0 ] as Root ;
134130
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 ) ;
137133 const nextNode = siblings [ siblings . indexOf ( node ) + 1 ] ;
138134 return embeds . find ( ( n ) => n && n . start >= position && ( ! nextNode || n . end <= nextNode . start ) ) ;
139135}
140136
141137export 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 ) ;
144140}
145141
146142export function isEmptyTextNode ( node : SvelteNode | undefined ) : node is Text {
0 commit comments