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

Handle all possible element kinds when walking exports #2631

Merged
merged 1 commit into from Jan 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 {}