Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct relative path of sources #162

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
}
5 changes: 3 additions & 2 deletions 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 Expand Up @@ -142,7 +143,7 @@ export class JavaScriptParser extends Parser {
if (sourceFile) {
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