Skip to content

Commit

Permalink
fix: Handle all possible element kinds when walking exports (#2631)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Jan 22, 2023
1 parent 7ccadf0 commit e06c7bc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/bindings/util.ts
Expand Up @@ -19,7 +19,8 @@ import {
Global,
Program,
Property,
PropertyPrototype
PropertyPrototype,
InterfacePrototype
} from "../program";

/** Walker base class. */
Expand Down Expand Up @@ -94,6 +95,10 @@ export abstract class ExportsWalker {
this.visitClassInstances(name, <ClassPrototype>element);
break;
}
case ElementKind.InterfacePrototype: {
this.visitInterfaceInstances(name, <InterfacePrototype>element);
break;
}
case ElementKind.PropertyPrototype: {
let propertyInstance = (<PropertyPrototype>element).instance;
if (!propertyInstance) break;
Expand All @@ -112,8 +117,13 @@ export abstract class ExportsWalker {
if (hasCompiledMember(element)) this.visitNamespace(name, element);
break;
}
case ElementKind.TypeDefinition: break;
default: assert(false);
case ElementKind.TypeDefinition:
case ElementKind.IndexSignature: break;
default: {
// Not (directly) reachable exports:
// File, Local, Function, Class, Interface
assert(false);
}
}
}

Expand All @@ -134,11 +144,24 @@ export abstract class ExportsWalker {
// TODO: for (let instance of instances.values()) {
for (let _values = Map_values(instances), i = 0, k = _values.length; i < k; ++i) {
let instance = unchecked(_values[i]);
assert(instance.kind == ElementKind.Class);
if (instance.is(CommonFlags.Compiled)) this.visitClass(name, instance);
}
}
}

private visitInterfaceInstances(name: string, element: InterfacePrototype): void {
let instances = element.instances;
if (instances) {
// TODO: for (let instance of instances.values()) {
for (let _values = Map_values(instances), i = 0, k = _values.length; i < k; ++i) {
let instance = <Interface>unchecked(_values[i]);
assert(instance.kind == ElementKind.Interface);
if (instance.is(CommonFlags.Compiled)) this.visitInterface(name, instance);
}
}
}

abstract visitGlobal(name: string, element: Global): void;
abstract visitEnum(name: string, element: Enum): void;
abstract visitFunction(name: string, element: Function): void;
Expand Down
7 changes: 7 additions & 0 deletions tests/compiler/bindings/esm.ts
Expand Up @@ -169,3 +169,10 @@ immutableGlobalNested;
declare function Date_getTimezoneOffset(): i32;

Date_getTimezoneOffset();

// Not yet instrumented element kinds:

export class ExportedClass {}
export interface ExportedInterface {}
export type ExportedType = ExportedClass;
export namespace ExportedNamespace {}

0 comments on commit e06c7bc

Please sign in to comment.