Skip to content

Commit

Permalink
Ignore some imports that are not found in typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
pfgithub committed Jan 7, 2025
1 parent 995e299 commit 9c786bf
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
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

0 comments on commit 9c786bf

Please sign in to comment.