Skip to content

Commit

Permalink
Correct relative path of sources
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed Nov 27, 2024
1 parent dd4dea1 commit cfd0b1a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions openrewrite/src/core/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ export class ParseError implements SourceFile {
return new ParseError(
randomId(),
new Markers(randomId(), [ParseExceptionResult.build(parser, exception)]),
relativeTo ? path.resolve(input.path, relativeTo) : input.path,
relativeTo ? path.relative(relativeTo, input.path) : input.path,
input.fileAttributes,
parser.getCharset(ctx),
false,
Expand Down Expand Up @@ -761,4 +761,4 @@ class ParseErrorPrinter<P> extends ParseErrorVisitor<PrintOutputCapture<P>> {
}
return e;
}
}
}
3 changes: 2 additions & 1 deletion openrewrite/src/javascript/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
} from "../core";
import {binarySearch, compareTextSpans, getNextSibling, getPreviousSibling, TextSpan} from "./parserUtils";
import {JavaScriptTypeMapping} from "./typeMapping";
import path from "node:path";

export class JavaScriptParser extends Parser {

Expand Down Expand Up @@ -56,7 +57,7 @@ export class JavaScriptParser extends Parser {
const input = new ParserInput(filePath, null, false, () => Buffer.from(ts.sys.readFile(filePath)!));
try {
const parsed = new JavaScriptParserVisitor(this, sourceFile, typeChecker).visit(sourceFile) as SourceFile;
result.push(parsed);
result.push(parsed.withSourcePath(relativeTo != null ? path.relative(relativeTo, input.path) : input.path));
} catch (error) {
result.push(ParseError.build(this, input, relativeTo, ctx, error instanceof Error ? error : new Error('Parser threw unknown error: ' + error), null));
}
Expand Down

0 comments on commit cfd0b1a

Please sign in to comment.