@@ -25,6 +25,7 @@ import {
2525} from "../core" ;
2626import { binarySearch , compareTextSpans , getNextSibling , getPreviousSibling , TextSpan } from "./parserUtils" ;
2727import { JavaScriptTypeMapping } from "./typeMapping" ;
28+ import path from "node:path" ;
2829
2930export class JavaScriptParser extends Parser {
3031
@@ -56,7 +57,7 @@ export class JavaScriptParser extends Parser {
5657 const input = new ParserInput ( filePath , null , false , ( ) => Buffer . from ( ts . sys . readFile ( filePath ) ! ) ) ;
5758 try {
5859 const parsed = new JavaScriptParserVisitor ( this , sourceFile , typeChecker ) . visit ( sourceFile ) as SourceFile ;
59- result . push ( parsed ) ;
60+ result . push ( parsed . withSourcePath ( relativeTo != null ? path . relative ( relativeTo , input . path ) : input . path ) ) ;
6061 } catch ( error ) {
6162 result . push ( ParseError . build ( this , input , relativeTo , ctx , error instanceof Error ? error : new Error ( 'Parser threw unknown error: ' + error ) , null ) ) ;
6263 }
@@ -142,7 +143,7 @@ export class JavaScriptParser extends Parser {
142143 if ( sourceFile ) {
143144 try {
144145 const parsed = new JavaScriptParserVisitor ( this , sourceFile , typeChecker ) . visit ( sourceFile ) as SourceFile ;
145- result . push ( parsed ) ;
146+ result . push ( parsed . withSourcePath ( relativeTo != null ? path . relative ( relativeTo , input . path ) : input . path ) ) ;
146147 } catch ( error ) {
147148 result . push ( ParseError . build ( this , input , relativeTo , ctx , error instanceof Error ? error : new Error ( 'Parser threw unknown error: ' + error ) , null ) ) ;
148149 }
0 commit comments