Skip to content
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

Ignore some imports that are not found in typescript #77

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions Source/JavaScriptCore/runtime/AbstractModuleRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,9 @@ JSModuleNamespaceObject* AbstractModuleRecord::getModuleNamespace(JSGlobalObject
RETURN_IF_EXCEPTION(scope, nullptr);
switch (resolution.type) {
case Resolution::Type::NotFound:
#if USE(BUN_JSC_ADDITIONS)
if(m_isTypeScript) break;
#endif
throwSyntaxError(globalObject, scope, makeString("Exported binding name '"_s, StringView(name.get()), "' is not found."_s));
return nullptr;

Expand Down
11 changes: 10 additions & 1 deletion Source/JavaScriptCore/runtime/AbstractModuleRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ class AbstractModuleRecord : public JSInternalFieldObjectImpl<2> {
Identifier localName;
};

enum class ImportEntryType { Single, Namespace };
enum class ImportEntryType {
Single,
#if USE(BUN_JSC_ADDITIONS)
// If the corresponding export is not found, do not emit an error.
SingleTypeScript,
#endif
Namespace,
};
struct ImportEntry {
ImportEntryType type;
Identifier moduleRequest;
Expand Down Expand Up @@ -161,6 +168,8 @@ class AbstractModuleRecord : public JSInternalFieldObjectImpl<2> {
WriteBarrier<Unknown>& internalField(Field field) { return Base::internalField(static_cast<uint32_t>(field)); }
WriteBarrier<Unknown> internalField(Field field) const { return Base::internalField(static_cast<uint32_t>(field)); }

bool m_isTypeScript = false;

protected:
AbstractModuleRecord(VM&, Structure*, const Identifier&);
void finishCreation(JSGlobalObject*, VM&);
Expand Down
6 changes: 5 additions & 1 deletion Source/JavaScriptCore/runtime/JSModuleEnvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ void JSModuleEnvironment::getOwnSpecialPropertyNames(JSObject* cell, JSGlobalObj
if (propertyNamesArray.includeStringProperties()) {
for (const auto& pair : thisObject->moduleRecord()->importEntries()) {
const AbstractModuleRecord::ImportEntry& importEntry = pair.value;
if (importEntry.type == AbstractModuleRecord::ImportEntryType::Single)
if (importEntry.type == AbstractModuleRecord::ImportEntryType::Single
#if USE(BUN_JSC_ADDITIONS)
|| importEntry.type == AbstractModuleRecord::ImportEntryType::SingleTypeScript
#endif
)
propertyNamesArray.add(importEntry.localName);
}
}
Expand Down
11 changes: 11 additions & 0 deletions Source/JavaScriptCore/runtime/JSModuleRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ void JSModuleRecord::instantiateDeclarations(JSGlobalObject* globalObject, Modul
RETURN_IF_EXCEPTION(scope, void());
switch (resolution.type) {
case Resolution::Type::NotFound: {
#if USE(BUN_JSC_ADDITIONS)
if(m_isTypeScript) break;
#endif
throwSyntaxError(globalObject, scope, makeString("export '"_s, StringView(exportEntry.exportName.impl()), "' not found in '"_s, StringView(exportEntry.moduleName.impl()), "'"_s));
return;
}
Expand Down Expand Up @@ -191,11 +194,19 @@ void JSModuleRecord::instantiateDeclarations(JSGlobalObject* globalObject, Modul
break;
}

#if USE(BUN_JSC_ADDITIONS)
case AbstractModuleRecord::ImportEntryType::SingleTypeScript:
#endif
case AbstractModuleRecord::ImportEntryType::Single: {
Resolution resolution = importedModule->resolveExport(globalObject, importEntry.importName);
RETURN_IF_EXCEPTION(scope, void());
switch (resolution.type) {
case Resolution::Type::NotFound: {
#if USE(BUN_JSC_ADDITIONS)
if(importEntry.type == AbstractModuleRecord::ImportEntryType::SingleTypeScript) {
break;
}
#endif
if (!(importEntry.localName.isNull() || importEntry.localName.isPrivateName() || importEntry.localName.isSymbol())) {
Resolution otherResolution = importedModule->resolveExport(globalObject, vm.propertyNames->defaultKeyword);
if (otherResolution.type == Resolution::Type::Resolved && otherResolution.localName == importEntry.localName) {
Expand Down
Loading