@@ -66,6 +66,12 @@ export const convertRawTypstAstStringToObject = (rawTypstAstString: string) => {
66
66
) ;
67
67
68
68
const parsed = parse ( escapedRawTypstAstYamlString ) ;
69
+
70
+ // Handle empty file case
71
+ if ( parsed . ast . c === null ) {
72
+ parsed . ast . c = [ ] ;
73
+ }
74
+
69
75
return parsed . ast as TypstAstNode ;
70
76
} ;
71
77
@@ -164,6 +170,14 @@ export const convertRawTypstAstObjectToTextlintAstObject = (
164
170
if ( ! match ) {
165
171
if ( c !== undefined ) {
166
172
// 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
+
167
181
const rootChildrenStartLocation = extractLocation ( c [ 0 ] . s , c [ 0 ] . c ) ;
168
182
const rootChildrenEndLocation = extractLocation (
169
183
c [ c . length - 1 ] . s ,
@@ -193,7 +207,7 @@ export const convertRawTypstAstObjectToTextlintAstObject = (
193
207
const nodeRawText = extractRawSourceByLocation ( typstSource , location ) ;
194
208
const nodeLength = nodeRawText . length ;
195
209
196
- if ( node . c && node . c . length > 0 ) {
210
+ if ( node . c ) {
197
211
// If TxtParentNode
198
212
let childOffset = startOffset ;
199
213
const whitespaceNodes : TxtTextNode [ ] = [ ] ;
@@ -372,7 +386,7 @@ export const convertRawTypstAstObjectToTextlintAstObject = (
372
386
} ;
373
387
374
388
// 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 ) {
376
390
const rootChildrenStartLocation = extractLocation (
377
391
textlintAstObject . c [ 0 ] . s ,
378
392
textlintAstObject . c [ 0 ] . c ,
0 commit comments