Skip to content
Merged
Changes from 3 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
8 changes: 7 additions & 1 deletion lib/src/legacy/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ export function removeLegacyImporter(string: string): string {
// syntax.
export function removeLegacyImporterFromSpan(span: SourceSpan): SourceSpan {
if (!span.url) return span;
return {...span, url: new URL(removeLegacyImporter(span.url.toString()))};
const url = removeLegacyImporter(span.url.toString());
try {
return {...span, url: new URL(url)};
} catch (_) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If the URL is absolute, it won't use the basename anyway, so you can just pass it in eagerly rather than catching this error.

// Relative URL
return {...span, url: new URL(url, `file://${process.cwd()}`)};
Copy link
Contributor

Choose a reason for hiding this comment

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

Just shoving a pathname into a URL string isn't safe in general. Use Node's pathToFileUrl().

}
}

// Converts [path] to a `file:` URL and adds the [legacyImporterProtocolPrefix]
Expand Down