@@ -66,6 +66,12 @@ export const convertRawTypstAstStringToObject = (rawTypstAstString: string) => {
6666 ) ;
6767
6868 const parsed = parse ( escapedRawTypstAstYamlString ) ;
69+
70+ // Handle empty file case
71+ if ( parsed . ast . c === null ) {
72+ parsed . ast . c = [ ] ;
73+ }
74+
6975 return parsed . ast as TypstAstNode ;
7076} ;
7177
@@ -164,6 +170,14 @@ export const convertRawTypstAstObjectToTextlintAstObject = (
164170 if ( ! match ) {
165171 if ( c !== undefined ) {
166172 // If root node
173+
174+ if ( c . length === 0 ) {
175+ return {
176+ start : { line : 1 , column : 0 } ,
177+ end : { line : 1 , column : 0 } ,
178+ } ;
179+ }
180+
167181 const rootChildrenStartLocation = extractLocation ( c [ 0 ] . s , c [ 0 ] . c ) ;
168182 const rootChildrenEndLocation = extractLocation (
169183 c [ c . length - 1 ] . s ,
@@ -193,7 +207,7 @@ export const convertRawTypstAstObjectToTextlintAstObject = (
193207 const nodeRawText = extractRawSourceByLocation ( typstSource , location ) ;
194208 const nodeLength = nodeRawText . length ;
195209
196- if ( node . c && node . c . length > 0 ) {
210+ if ( node . c ) {
197211 // If TxtParentNode
198212 let childOffset = startOffset ;
199213 const whitespaceNodes : TxtTextNode [ ] = [ ] ;
@@ -372,7 +386,7 @@ export const convertRawTypstAstObjectToTextlintAstObject = (
372386 } ;
373387
374388 // If the source code starts with a single newline, add a Break node before the first node.
375- if ( textlintAstObject . c ) {
389+ if ( textlintAstObject . c && textlintAstObject . c . length > 0 ) {
376390 const rootChildrenStartLocation = extractLocation (
377391 textlintAstObject . c [ 0 ] . s ,
378392 textlintAstObject . c [ 0 ] . c ,
0 commit comments