-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
esm: improve error messages for ambiguous module syntax #60376
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
a3cd540
aac23bb
9457af9
8078665
0dfdc54
354f6a5
89e45e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,8 +2,8 @@ | |||||||||
|
|
||||||||||
| const { | ||||||||||
| Array, | ||||||||||
| ArrayPrototypeFind, | ||||||||||
| ArrayPrototypeJoin, | ||||||||||
| ArrayPrototypeSome, | ||||||||||
| FunctionPrototype, | ||||||||||
| ObjectSetPrototypeOf, | ||||||||||
| PromisePrototypeThen, | ||||||||||
|
|
@@ -61,11 +61,11 @@ const CJSGlobalLike = [ | |||||||||
| '__filename', | ||||||||||
| '__dirname', | ||||||||||
| ]; | ||||||||||
| const isCommonJSGlobalLikeNotDefinedError = (errorMessage) => | ||||||||||
| ArrayPrototypeSome( | ||||||||||
| const getUndefinedCJSGlobalLike = (errorMessage) => | ||||||||||
| ArrayPrototypeFind( | ||||||||||
| CJSGlobalLike, | ||||||||||
| (globalLike) => errorMessage === `${globalLike} is not defined`, | ||||||||||
| ); | ||||||||||
| ) ?? null; | ||||||||||
|
|
||||||||||
|
|
||||||||||
| /** | ||||||||||
|
|
@@ -75,11 +75,28 @@ const isCommonJSGlobalLikeNotDefinedError = (errorMessage) => | |||||||||
| * @returns {void} | ||||||||||
| */ | ||||||||||
| const explainCommonJSGlobalLikeNotDefinedError = (e, url, hasTopLevelAwait) => { | ||||||||||
| if (e?.name === 'ReferenceError' && | ||||||||||
| isCommonJSGlobalLikeNotDefinedError(e.message)) { | ||||||||||
| const undefinedGlobal = getUndefinedCJSGlobalLike(e?.message); | ||||||||||
| if (e?.name === 'ReferenceError' && undefinedGlobal !== null) { | ||||||||||
|
||||||||||
| const undefinedGlobal = getUndefinedCJSGlobalLike(e?.message); | |
| if (e?.name === 'ReferenceError' && undefinedGlobal !== null) { | |
| const notDefinedGlobalLike = e?.name === 'ReferenceError' && findCommonJSGlobalLikeNotDefinedError(e.message); | |
| if (notDefinedGlobalLike) { |
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.
wdyt of this suggestion? That would remove one optional chaining, and skip the function call for unrelated errorrs
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.
Just my codding style. 😢 updated to use short-circuit evaluation. Thanks!
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.
That's not useful, it it?
Uh oh!
There was an error while loading. Please reload this page.
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.
Right.. It's redundant since ArrayPrototypeFind returns undefined when not found.
Thanks for review. I applied it