Skip to content

Commit abf0133

Browse files
authored
Use field in InterfaceIR to determine whether to inherit from Prototype/_JsObject (#74)
rather than checking for the name to end in _iface
1 parent 3506061 commit abf0133

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

type-generation/src/astToIR.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ export type InterfaceIR = {
128128
extraBases?: string[];
129129
// This is used to decide whether the class should be a Protocol or not.
130130
concrete?: boolean;
131+
jsobject?: boolean;
131132
// Control how numbers are rendered in the class. Normally they are rendered
132133
// as int | float, but sometimes we just want it to be written as int.
133134
// This is handled in an adhoc manner in adjustInterfaceIR.
@@ -1175,6 +1176,7 @@ export class Converter {
11751176
[],
11761177
typeParams,
11771178
);
1179+
concreteIR.jsobject = true;
11781180
this.nameContext = undefined;
11791181
return [ifaceIR, concreteIR];
11801182
}
@@ -1278,7 +1280,9 @@ export class Converter {
12781280
//
12791281
// Otherwise it's a global namespace object?
12801282
try {
1281-
return this.membersDeclarationToIR(name, typeNode, [], []);
1283+
const res = this.membersDeclarationToIR(name, typeNode, [], []);
1284+
res.jsobject = true;
1285+
return res;
12821286
} catch (e) {
12831287
console.warn(varDecl.getText());
12841288
console.warn(getNodeLocation(varDecl));
@@ -1326,6 +1330,7 @@ export class Converter {
13261330
[],
13271331
typeParams,
13281332
);
1333+
result.jsobject = true;
13291334

13301335
this.ifaceTypeParamConstraints.clear();
13311336

type-generation/src/extract.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ function fixupClassBases(nameToCls: Map<string, InterfaceIR>): void {
6767
}
6868
}
6969
}
70-
if (cls.name.endsWith("_iface") && !cls.concrete) {
70+
if (!cls.jsobject && !cls.concrete) {
7171
cls.extraBases.push("Protocol");
7272
}
73-
if (!cls.name.endsWith("_iface")) {
73+
if (cls.jsobject) {
7474
cls.extraBases.push("_JsObject");
7575
}
7676
cls.bases.sort(({ name: a }, { name: b }) => {

type-generation/tests/a.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ describe("emit", () => {
472472
const res = emitFile("declare var a : boolean;");
473473
assert.strictEqual(removeTypeIgnores(res.at(-1)!), "a: bool = ...");
474474
});
475-
it("extends", () => {
475+
it("interface extends tests", () => {
476476
const res = emitFile(`
477477
interface B {
478478
b: number;

0 commit comments

Comments
 (0)