Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e06c7bc

Browse files
authored
fix: Handle all possible element kinds when walking exports (#2631)
1 parent 7ccadf0 commit e06c7bc

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

‎src/bindings/util.ts‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import {
1919
Global,
2020
Program,
2121
Property,
22-
PropertyPrototype
22+
PropertyPrototype,
23+
InterfacePrototype
2324
} from "../program";
2425

2526
/** Walker base class. */
@@ -94,6 +95,10 @@ export abstract class ExportsWalker {
9495
this.visitClassInstances(name, <ClassPrototype>element);
9596
break;
9697
}
98+
case ElementKind.InterfacePrototype: {
99+
this.visitInterfaceInstances(name, <InterfacePrototype>element);
100+
break;
101+
}
97102
case ElementKind.PropertyPrototype: {
98103
let propertyInstance = (<PropertyPrototype>element).instance;
99104
if (!propertyInstance) break;
@@ -112,8 +117,13 @@ export abstract class ExportsWalker {
112117
if (hasCompiledMember(element)) this.visitNamespace(name, element);
113118
break;
114119
}
115-
case ElementKind.TypeDefinition: break;
116-
default: assert(false);
120+
case ElementKind.TypeDefinition:
121+
case ElementKind.IndexSignature: break;
122+
default: {
123+
// Not (directly) reachable exports:
124+
// File, Local, Function, Class, Interface
125+
assert(false);
126+
}
117127
}
118128
}
119129

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

153+
private visitInterfaceInstances(name: string, element: InterfacePrototype): void {
154+
let instances = element.instances;
155+
if (instances) {
156+
// TODO: for (let instance of instances.values()) {
157+
for (let _values = Map_values(instances), i = 0, k = _values.length; i < k; ++i) {
158+
let instance = <Interface>unchecked(_values[i]);
159+
assert(instance.kind == ElementKind.Interface);
160+
if (instance.is(CommonFlags.Compiled)) this.visitInterface(name, instance);
161+
}
162+
}
163+
}
164+
142165
abstract visitGlobal(name: string, element: Global): void;
143166
abstract visitEnum(name: string, element: Enum): void;
144167
abstract visitFunction(name: string, element: Function): void;

‎tests/compiler/bindings/esm.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,10 @@ immutableGlobalNested;
169169
declare function Date_getTimezoneOffset(): i32;
170170

171171
Date_getTimezoneOffset();
172+
173+
// Not yet instrumented element kinds:
174+
175+
export class ExportedClass {}
176+
export interface ExportedInterface {}
177+
export type ExportedType = ExportedClass;
178+
export namespace ExportedNamespace {}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /