Skip to content

Commit d8d3fbc

Browse files
authored
Merge pull request #77 from oven-sh/pfg/allow-type-imports
Ignore some imports that are not found in typescript
2 parents 5ebbd7b + 9c786bf commit d8d3fbc

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

Source/JavaScriptCore/runtime/AbstractModuleRecord.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,9 @@ JSModuleNamespaceObject* AbstractModuleRecord::getModuleNamespace(JSGlobalObject
781781
RETURN_IF_EXCEPTION(scope, nullptr);
782782
switch (resolution.type) {
783783
case Resolution::Type::NotFound:
784+
#if USE(BUN_JSC_ADDITIONS)
785+
if(m_isTypeScript) break;
786+
#endif
784787
throwSyntaxError(globalObject, scope, makeString("Exported binding name '"_s, StringView(name.get()), "' is not found."_s));
785788
return nullptr;
786789

Source/JavaScriptCore/runtime/AbstractModuleRecord.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,14 @@ class AbstractModuleRecord : public JSInternalFieldObjectImpl<2> {
8989
Identifier localName;
9090
};
9191

92-
enum class ImportEntryType { Single, Namespace };
92+
enum class ImportEntryType {
93+
Single,
94+
#if USE(BUN_JSC_ADDITIONS)
95+
// If the corresponding export is not found, do not emit an error.
96+
SingleTypeScript,
97+
#endif
98+
Namespace,
99+
};
93100
struct ImportEntry {
94101
ImportEntryType type;
95102
Identifier moduleRequest;
@@ -161,6 +168,8 @@ class AbstractModuleRecord : public JSInternalFieldObjectImpl<2> {
161168
WriteBarrier<Unknown>& internalField(Field field) { return Base::internalField(static_cast<uint32_t>(field)); }
162169
WriteBarrier<Unknown> internalField(Field field) const { return Base::internalField(static_cast<uint32_t>(field)); }
163170

171+
bool m_isTypeScript = false;
172+
164173
protected:
165174
AbstractModuleRecord(VM&, Structure*, const Identifier&);
166175
void finishCreation(JSGlobalObject*, VM&);

Source/JavaScriptCore/runtime/JSModuleEnvironment.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ void JSModuleEnvironment::getOwnSpecialPropertyNames(JSObject* cell, JSGlobalObj
9999
if (propertyNamesArray.includeStringProperties()) {
100100
for (const auto& pair : thisObject->moduleRecord()->importEntries()) {
101101
const AbstractModuleRecord::ImportEntry& importEntry = pair.value;
102-
if (importEntry.type == AbstractModuleRecord::ImportEntryType::Single)
102+
if (importEntry.type == AbstractModuleRecord::ImportEntryType::Single
103+
#if USE(BUN_JSC_ADDITIONS)
104+
|| importEntry.type == AbstractModuleRecord::ImportEntryType::SingleTypeScript
105+
#endif
106+
)
103107
propertyNamesArray.add(importEntry.localName);
104108
}
105109
}

Source/JavaScriptCore/runtime/JSModuleRecord.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ void JSModuleRecord::instantiateDeclarations(JSGlobalObject* globalObject, Modul
140140
RETURN_IF_EXCEPTION(scope, void());
141141
switch (resolution.type) {
142142
case Resolution::Type::NotFound: {
143+
#if USE(BUN_JSC_ADDITIONS)
144+
if(m_isTypeScript) break;
145+
#endif
143146
throwSyntaxError(globalObject, scope, makeString("export '"_s, StringView(exportEntry.exportName.impl()), "' not found in '"_s, StringView(exportEntry.moduleName.impl()), "'"_s));
144147
return;
145148
}
@@ -191,11 +194,19 @@ void JSModuleRecord::instantiateDeclarations(JSGlobalObject* globalObject, Modul
191194
break;
192195
}
193196

197+
#if USE(BUN_JSC_ADDITIONS)
198+
case AbstractModuleRecord::ImportEntryType::SingleTypeScript:
199+
#endif
194200
case AbstractModuleRecord::ImportEntryType::Single: {
195201
Resolution resolution = importedModule->resolveExport(globalObject, importEntry.importName);
196202
RETURN_IF_EXCEPTION(scope, void());
197203
switch (resolution.type) {
198204
case Resolution::Type::NotFound: {
205+
#if USE(BUN_JSC_ADDITIONS)
206+
if(importEntry.type == AbstractModuleRecord::ImportEntryType::SingleTypeScript) {
207+
break;
208+
}
209+
#endif
199210
if (!(importEntry.localName.isNull() || importEntry.localName.isPrivateName() || importEntry.localName.isSymbol())) {
200211
Resolution otherResolution = importedModule->resolveExport(globalObject, vm.propertyNames->defaultKeyword);
201212
if (otherResolution.type == Resolution::Type::Resolved && otherResolution.localName == importEntry.localName) {

0 commit comments

Comments
 (0)