Skip to content

Commit be8fff5

Browse files
committed
fix(build/emitter): remove length property check
Although an indexed property getter needs a corresponding length property, that's what Web IDL validation should check.
1 parent 90af280 commit be8fff5

2 files changed

Lines changed: 11 additions & 17 deletions

File tree

baselines/dom.iterable.generated.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ interface NodeListOf<TNode extends Node> {
185185
values(): IterableIterator<TNode>;
186186
}
187187

188+
interface Plugin {
189+
[Symbol.iterator](): IterableIterator<undefined>;
190+
}
191+
188192
interface PluginArray {
189193
[Symbol.iterator](): IterableIterator<any>;
190194
}

src/build/emitter.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,31 +1459,24 @@ export function emitWebIdl(
14591459
}
14601460

14611461
function emitIterator(i: Browser.Interface) {
1462-
// check anonymous unsigned long getter and length property
1463-
const isIterableGetter = (m: Browser.AnonymousMethod) =>
1462+
// https://heycam.github.io/webidl/#dfn-indexed-property-getter
1463+
const isIndexedPropertyGetter = (m: Browser.AnonymousMethod) =>
14641464
m.getter &&
14651465
m.signature[0]?.param?.length === 1 &&
14661466
typeof m.signature[0].param[0].type === "string" &&
14671467
integerTypes.has(m.signature[0].param[0].type);
14681468

14691469
function findIterableGetter() {
1470-
const anonymousGetter = i.anonymousMethods?.method.find(isIterableGetter);
1470+
const anonymousGetter = i.anonymousMethods?.method.find(
1471+
isIndexedPropertyGetter
1472+
);
14711473

14721474
if (anonymousGetter) return anonymousGetter;
14731475
else if (i.methods)
1474-
return mapToArray(i.methods.method).find(isIterableGetter);
1476+
return mapToArray(i.methods.method).find(isIndexedPropertyGetter);
14751477
else return undefined;
14761478
}
14771479

1478-
function hasLengthProperty(i: Browser.Interface | undefined) {
1479-
const p = i?.properties?.property.length;
1480-
return (
1481-
p?.name === "length" &&
1482-
typeof p.type === "string" &&
1483-
integerTypes.has(p.type)
1484-
);
1485-
}
1486-
14871480
function getIteratorSubtypes() {
14881481
if (i.iterator) {
14891482
if (i.iterator.type.length === 1) {
@@ -1492,10 +1485,7 @@ export function emitWebIdl(
14921485
return i.iterator.type.map(convertDomTypeToTsType);
14931486
} else if (i.name !== "Window") {
14941487
const iterableGetter = findIterableGetter();
1495-
const lengthProperty =
1496-
hasLengthProperty(i) ||
1497-
(i.extends && hasLengthProperty(allInterfacesMap[i.extends]));
1498-
if (iterableGetter && lengthProperty) {
1488+
if (iterableGetter) {
14991489
return [
15001490
convertDomTypeToTsType({
15011491
type: iterableGetter.signature[0].type,

0 commit comments

Comments
 (0)