Skip to content

Commit e66f5dd

Browse files
committed
docs: add comments about why span changes work
DX-433
1 parent 1598462 commit e66f5dd

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/openapi-generator/src/sourceFile.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,19 @@ export async function parseSource(
1919
src: string,
2020
): Promise<SourceFile | undefined> {
2121
try {
22+
// Parse an empty string to get the last span
2223
const lastSpan = swc.parseSync('');
23-
lastSpanEnd = lastSpan.span.end;
2424

2525
const module = swc.parseSync(src, {
2626
syntax: 'typescript',
2727
target: 'esnext',
2828
comments: true,
2929
});
3030

31+
// Set the start of the module to the end of the last span, so that we don't have any
32+
// issues when parsing files that start with comments
3133
module.span.start = lastSpan.span.start;
34+
lastSpanEnd = lastSpan.span.end;
3235

3336
const symbols = parseTopLevelSymbols(src, lastSpanEnd, module.body);
3437
return {

0 commit comments

Comments
 (0)