forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 52
Attach importer sourceURL/line/column to module link SyntaxErrors #378
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
Open
robobun
wants to merge
2
commits into
main
Choose a base branch
from
farm/0eec2e41/import-link-error-location
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+61
−8
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,6 +89,50 @@ | |
| ASSERT(jsModule); | ||
| #endif | ||
|
|
||
| #if USE(BUN_JSC_ADDITIONS) | ||
| auto throwLinkSyntaxError = [&](String&& message, unsigned sourceOffset = 0) { | ||
| JSObject* error = createSyntaxError(globalObject, message); | ||
| auto attrs = static_cast<unsigned>(PropertyAttribute::DontEnum); | ||
| unsigned line = 0; | ||
| unsigned column = 0; | ||
| String sourceURL; | ||
| if (jsModule && jsModule->sourceCode().provider()) { | ||
| auto& sourceCode = jsModule->sourceCode(); | ||
| sourceURL = sourceCode.provider()->sourceURL(); | ||
| if (sourceOffset) { | ||
| StringView source = sourceCode.provider()->source(); | ||
| unsigned end = std::min<unsigned>(sourceOffset, source.length()); | ||
| unsigned lineStart = 0; | ||
| line = sourceCode.firstLine().oneBasedInt(); | ||
| for (unsigned i = 0; i < end; ++i) { | ||
| if (source[i] == '\n') { | ||
| ++line; | ||
| lineStart = i + 1; | ||
| } | ||
| } | ||
|
Check warning on line 112 in Source/JavaScriptCore/runtime/CyclicModuleRecord.cpp
|
||
| column = end - lineStart + 1; | ||
| } | ||
| } | ||
| if (sourceURL.isEmpty()) | ||
| sourceURL = moduleKey().string(); | ||
| if (auto* errorInstance = dynamicDowncast<ErrorInstance>(error)) { | ||
| if (!sourceURL.isEmpty()) | ||
| errorInstance->setSourceURL(sourceURL); | ||
| if (line) { | ||
| errorInstance->setLine(line); | ||
| errorInstance->setColumn(column); | ||
| } | ||
| } | ||
| if (!sourceURL.isEmpty()) | ||
| error->putDirect(vm, vm.propertyNames->sourceURL, jsString(vm, WTF::move(sourceURL)), attrs); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @robobun don't set both here. just set the one. |
||
| if (line) { | ||
| error->putDirect(vm, vm.propertyNames->line, jsNumber(line), attrs); | ||
| error->putDirect(vm, vm.propertyNames->column, jsNumber(column), attrs); | ||
| } | ||
| throwException(globalObject, scope, error); | ||
| }; | ||
| #endif | ||
|
|
||
| ModuleProgramExecutable* moduleProgramExecutable = nullptr; | ||
| JSModuleEnvironment* env = nullptr; | ||
|
|
||
|
|
@@ -106,23 +150,23 @@ | |
| case Resolution::Type::NotFound: | ||
| #if USE(BUN_JSC_ADDITIONS) | ||
| if (m_isTypeScript) break; | ||
| throwSyntaxError(globalObject, scope, makeString("export '"_s, StringView(e.exportName.impl()), "' not found in '"_s, StringView(e.moduleName.impl()), "'"_s)); | ||
| throwLinkSyntaxError(makeString("export '"_s, StringView(e.exportName.impl()), "' not found in '"_s, StringView(e.moduleName.impl()), "'"_s)); | ||
| #else | ||
| throwSyntaxError(globalObject, scope, makeString("Indirectly exported binding name '"_s, StringView(e.exportName.impl()), "' is not found."_s)); | ||
| #endif | ||
| return; | ||
|
|
||
| case Resolution::Type::Ambiguous: | ||
| #if USE(BUN_JSC_ADDITIONS) | ||
| throwSyntaxError(globalObject, scope, makeString("Cannot export '"_s, StringView(e.exportName.impl()), "' multiple times in '"_s, StringView(e.moduleName.impl()), "'"_s)); | ||
| throwLinkSyntaxError(makeString("Cannot export '"_s, StringView(e.exportName.impl()), "' multiple times in '"_s, StringView(e.moduleName.impl()), "'"_s)); | ||
| #else | ||
| throwSyntaxError(globalObject, scope, makeString("Indirectly exported binding name '"_s, StringView(e.exportName.impl()), "' cannot be resolved due to ambiguous multiple bindings."_s)); | ||
| #endif | ||
| return; | ||
|
|
||
| case Resolution::Type::Error: | ||
| #if USE(BUN_JSC_ADDITIONS) | ||
| throwSyntaxError(globalObject, scope, "export default cannot be used with export *"_s); | ||
| throwLinkSyntaxError("export default cannot be used with export *"_s); | ||
| #else | ||
| throwSyntaxError(globalObject, scope, "Indirectly exported binding name 'default' cannot be resolved by star export entries."_s); | ||
| #endif | ||
|
|
@@ -209,19 +253,19 @@ | |
| Resolution otherResolution = importedModule->resolveExport(globalObject, vm.propertyNames->defaultKeyword); | ||
| RETURN_IF_EXCEPTION(scope, void()); | ||
| if (otherResolution.type == Resolution::Type::Resolved && otherResolution.localName == in.localName) { | ||
| throwSyntaxError(globalObject, scope, makeString("Export named '"_s, in.importName.string(), "' not found in module '"_s, importedModule->moduleKey().string(), "'. Did you mean to import default?"_s)); | ||
| throwLinkSyntaxError(makeString("Export named '"_s, in.importName.string(), "' not found in module '"_s, importedModule->moduleKey().string(), "'. Did you mean to import default?"_s), in.sourceOffset); | ||
| return; | ||
| } | ||
| } | ||
| throwSyntaxError(globalObject, scope, makeString("Export named '"_s, in.importName.string(), "' not found in module '"_s, importedModule->moduleKey().string(), "'."_s)); | ||
| throwLinkSyntaxError(makeString("Export named '"_s, in.importName.string(), "' not found in module '"_s, importedModule->moduleKey().string(), "'."_s), in.sourceOffset); | ||
| #else | ||
| throwSyntaxError(globalObject, scope, makeString("Importing binding name '"_s, StringView(in.importName.impl()), "' is not found."_s)); | ||
| #endif | ||
| return; | ||
|
|
||
| case Resolution::Type::Ambiguous: | ||
| #if USE(BUN_JSC_ADDITIONS) | ||
| throwSyntaxError(globalObject, scope, makeString("Export named '"_s, in.importName.string(), "' cannot be resolved due to ambiguous multiple bindings in module '"_s, importedModule->moduleKey().string(), "'."_s)); | ||
| throwLinkSyntaxError(makeString("Export named '"_s, in.importName.string(), "' cannot be resolved due to ambiguous multiple bindings in module '"_s, importedModule->moduleKey().string(), "'."_s), in.sourceOffset); | ||
| #else | ||
| throwSyntaxError(globalObject, scope, makeString("Importing binding name '"_s, StringView(in.importName.impl()), "' cannot be resolved due to ambiguous multiple bindings."_s)); | ||
| #endif | ||
|
|
@@ -233,11 +277,11 @@ | |
| Resolution otherResolution = importedModule->resolveExport(globalObject, in.localName); | ||
| RETURN_IF_EXCEPTION(scope, void()); | ||
| if (otherResolution.type == Resolution::Type::Resolved) { | ||
| throwSyntaxError(globalObject, scope, makeString("module '"_s, importedModule->moduleKey().string(), "' does not have an export named 'default'. Did you mean '"_s, String(in.localName.impl()), "'?"_s)); | ||
| throwLinkSyntaxError(makeString("module '"_s, importedModule->moduleKey().string(), "' does not have an export named 'default'. Did you mean '"_s, String(in.localName.impl()), "'?"_s), in.sourceOffset); | ||
| return; | ||
| } | ||
| } | ||
| throwSyntaxError(globalObject, scope, makeString("Missing 'default' export in module '"_s, importedModule->moduleKey().string(), "'."_s)); | ||
| throwLinkSyntaxError(makeString("Missing 'default' export in module '"_s, importedModule->moduleKey().string(), "'."_s), in.sourceOffset); | ||
| #else | ||
| throwSyntaxError(globalObject, scope, "Importing binding name 'default' cannot be resolved by star export entries."_s); | ||
| #endif | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.