Skip to content
Open
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
7 changes: 6 additions & 1 deletion src/lualib/SourceMapTraceBack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ export function __TS__SourceMapTraceBack(this: void, fileName: string, sourceMap
return `${file}:${line}`;
};

let [result] = string.gsub(trace, "(%S+)%.lua:(%d+)", (file, line) =>
// Rewrite stack trace frames from "{PATH}.lua:{LINE}" to "{PATH}.ts:{ORIGINAL_LINE}".
// https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1665
// Avoid matching anonymous function stack entries like `in function <...>`
// by excluding `<` before the file path.
// TODO: This will still fail for paths containing spaces.
Copy link

Copilot AI Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The TODO comment mentions that paths with spaces will fail, but this is a known limitation of the current implementation. Consider adding more context about why this limitation exists (the pattern uses [^%s<]+ which excludes whitespace) and potential workarounds or future solutions.

Suggested change
// TODO: This will still fail for paths containing spaces.
// TODO: This will still fail for paths containing spaces.
// The Lua pattern used here ("([^%s<]+)%.lua:(%d+)") excludes whitespace to avoid matching
// anonymous function stack entries (e.g., 'in function <...>'). As a result, file paths with spaces
// are not matched and will not be rewritten in the stack trace.
// Potential workarounds: use a more sophisticated pattern, escape spaces in file paths, or
// post-process stack traces to handle these cases in the future.

Copilot uses AI. Check for mistakes.
let [result] = string.gsub(trace, "([^%s<]+)%.lua:(%d+)", (file, line) =>
replacer(`${file}.lua`, `${file}.ts`, line)
);

Expand Down
Loading