-
Notifications
You must be signed in to change notification settings - Fork 150
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
fix: avoid URL illegal constructor error #458
Conversation
src/utils/static-eval.ts
Outdated
@@ -327,7 +327,7 @@ const visitors: Record< | |||
|
|||
return { | |||
test: node.test, | |||
then: thenValue.value, | |||
then: thenValue.value === URL ? undefined : thenValue.value, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks wrong. Why would URL always be undefined?
I suspect the root cause is somewhere else since this code represents the ternary from what I can tell.
src/utils/static-eval.ts
Outdated
@@ -327,7 +327,7 @@ const visitors: Record< | |||
|
|||
return { | |||
test: node.test, | |||
then: thenValue.value, | |||
then: thenValue.value === URL ? undefined : thenValue.value, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be confusing for future readers. Can we add a comment explaining why the special case here?
src/utils/types.ts
Outdated
export interface ConditionalValue { | ||
test: string; | ||
then: any; | ||
// then is reserved for thenables | ||
ifTrue: any; | ||
else: any; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Went with a new (and I think better) solution!
then
is reservered for thenables, so changed everything in the code from then
-> ifTrue
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, nice catch!
nodeFileTrace
errors onconst URLParser = typeof window === 'undefined' ? URL : 'b'
withTypeError: Class constructor URL cannot be invoked without 'new'
.This is because this code:
calls
URL()
sinceConditionalExpression
is an async function returning a thenable.Solution: rename all
.then
fields to.ifTrue
sincethen
is reserved for thenables.Closes #447