Skip to content

Commit 3402469

Browse files
committed
Fix: Async scroll...() methods are non-async in fact
1 parent 8517969 commit 3402469

File tree

6 files changed

+68
-31
lines changed

6 files changed

+68
-31
lines changed

baselines/dom.generated.d.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13237,28 +13237,28 @@ interface Element extends Node, ARIAMixin, Animatable, ChildNode, NonDocumentTyp
1323713237
*
1323813238
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/scroll)
1323913239
*/
13240-
scroll(options?: ScrollToOptions): Promise<void>;
13241-
scroll(x: number, y: number): Promise<void>;
13240+
scroll(options?: ScrollToOptions): void;
13241+
scroll(x: number, y: number): void;
1324213242
/**
1324313243
* The **`scrollBy()`** method of the Element interface scrolls an element by the given amount.
1324413244
*
1324513245
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/scrollBy)
1324613246
*/
13247-
scrollBy(options?: ScrollToOptions): Promise<void>;
13248-
scrollBy(x: number, y: number): Promise<void>;
13247+
scrollBy(options?: ScrollToOptions): void;
13248+
scrollBy(x: number, y: number): void;
1324913249
/**
1325013250
* The Element interface's **`scrollIntoView()`** method scrolls the element's ancestor containers such that the element on which scrollIntoView() is called is visible to the user.
1325113251
*
1325213252
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/scrollIntoView)
1325313253
*/
13254-
scrollIntoView(arg?: boolean | ScrollIntoViewOptions): Promise<void>;
13254+
scrollIntoView(arg?: boolean | ScrollIntoViewOptions): void;
1325513255
/**
1325613256
* The **`scrollTo()`** method of the Element interface scrolls to a particular set of coordinates inside a given element.
1325713257
*
1325813258
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/scrollTo)
1325913259
*/
13260-
scrollTo(options?: ScrollToOptions): Promise<void>;
13261-
scrollTo(x: number, y: number): Promise<void>;
13260+
scrollTo(options?: ScrollToOptions): void;
13261+
scrollTo(x: number, y: number): void;
1326213262
/**
1326313263
* The **`setAttribute()`** method of the Element interface sets the value of an attribute on the specified element. If the attribute already exists, the value is updated; otherwise a new attribute is added with the specified name and value.
1326413264
*

baselines/ts5.5/dom.generated.d.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13224,28 +13224,28 @@ interface Element extends Node, ARIAMixin, Animatable, ChildNode, NonDocumentTyp
1322413224
*
1322513225
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/scroll)
1322613226
*/
13227-
scroll(options?: ScrollToOptions): Promise<void>;
13228-
scroll(x: number, y: number): Promise<void>;
13227+
scroll(options?: ScrollToOptions): void;
13228+
scroll(x: number, y: number): void;
1322913229
/**
1323013230
* The **`scrollBy()`** method of the Element interface scrolls an element by the given amount.
1323113231
*
1323213232
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/scrollBy)
1323313233
*/
13234-
scrollBy(options?: ScrollToOptions): Promise<void>;
13235-
scrollBy(x: number, y: number): Promise<void>;
13234+
scrollBy(options?: ScrollToOptions): void;
13235+
scrollBy(x: number, y: number): void;
1323613236
/**
1323713237
* The Element interface's **`scrollIntoView()`** method scrolls the element's ancestor containers such that the element on which scrollIntoView() is called is visible to the user.
1323813238
*
1323913239
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/scrollIntoView)
1324013240
*/
13241-
scrollIntoView(arg?: boolean | ScrollIntoViewOptions): Promise<void>;
13241+
scrollIntoView(arg?: boolean | ScrollIntoViewOptions): void;
1324213242
/**
1324313243
* The **`scrollTo()`** method of the Element interface scrolls to a particular set of coordinates inside a given element.
1324413244
*
1324513245
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/scrollTo)
1324613246
*/
13247-
scrollTo(options?: ScrollToOptions): Promise<void>;
13248-
scrollTo(x: number, y: number): Promise<void>;
13247+
scrollTo(options?: ScrollToOptions): void;
13248+
scrollTo(x: number, y: number): void;
1324913249
/**
1325013250
* The **`setAttribute()`** method of the Element interface sets the value of an attribute on the specified element. If the attribute already exists, the value is updated; otherwise a new attribute is added with the specified name and value.
1325113251
*

baselines/ts5.6/dom.generated.d.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13234,28 +13234,28 @@ interface Element extends Node, ARIAMixin, Animatable, ChildNode, NonDocumentTyp
1323413234
*
1323513235
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/scroll)
1323613236
*/
13237-
scroll(options?: ScrollToOptions): Promise<void>;
13238-
scroll(x: number, y: number): Promise<void>;
13237+
scroll(options?: ScrollToOptions): void;
13238+
scroll(x: number, y: number): void;
1323913239
/**
1324013240
* The **`scrollBy()`** method of the Element interface scrolls an element by the given amount.
1324113241
*
1324213242
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/scrollBy)
1324313243
*/
13244-
scrollBy(options?: ScrollToOptions): Promise<void>;
13245-
scrollBy(x: number, y: number): Promise<void>;
13244+
scrollBy(options?: ScrollToOptions): void;
13245+
scrollBy(x: number, y: number): void;
1324613246
/**
1324713247
* The Element interface's **`scrollIntoView()`** method scrolls the element's ancestor containers such that the element on which scrollIntoView() is called is visible to the user.
1324813248
*
1324913249
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/scrollIntoView)
1325013250
*/
13251-
scrollIntoView(arg?: boolean | ScrollIntoViewOptions): Promise<void>;
13251+
scrollIntoView(arg?: boolean | ScrollIntoViewOptions): void;
1325213252
/**
1325313253
* The **`scrollTo()`** method of the Element interface scrolls to a particular set of coordinates inside a given element.
1325413254
*
1325513255
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/scrollTo)
1325613256
*/
13257-
scrollTo(options?: ScrollToOptions): Promise<void>;
13258-
scrollTo(x: number, y: number): Promise<void>;
13257+
scrollTo(options?: ScrollToOptions): void;
13258+
scrollTo(x: number, y: number): void;
1325913259
/**
1326013260
* The **`setAttribute()`** method of the Element interface sets the value of an attribute on the specified element. If the attribute already exists, the value is updated; otherwise a new attribute is added with the specified name and value.
1326113261
*

baselines/ts5.9/dom.generated.d.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13234,28 +13234,28 @@ interface Element extends Node, ARIAMixin, Animatable, ChildNode, NonDocumentTyp
1323413234
*
1323513235
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/scroll)
1323613236
*/
13237-
scroll(options?: ScrollToOptions): Promise<void>;
13238-
scroll(x: number, y: number): Promise<void>;
13237+
scroll(options?: ScrollToOptions): void;
13238+
scroll(x: number, y: number): void;
1323913239
/**
1324013240
* The **`scrollBy()`** method of the Element interface scrolls an element by the given amount.
1324113241
*
1324213242
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/scrollBy)
1324313243
*/
13244-
scrollBy(options?: ScrollToOptions): Promise<void>;
13245-
scrollBy(x: number, y: number): Promise<void>;
13244+
scrollBy(options?: ScrollToOptions): void;
13245+
scrollBy(x: number, y: number): void;
1324613246
/**
1324713247
* The Element interface's **`scrollIntoView()`** method scrolls the element's ancestor containers such that the element on which scrollIntoView() is called is visible to the user.
1324813248
*
1324913249
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/scrollIntoView)
1325013250
*/
13251-
scrollIntoView(arg?: boolean | ScrollIntoViewOptions): Promise<void>;
13251+
scrollIntoView(arg?: boolean | ScrollIntoViewOptions): void;
1325213252
/**
1325313253
* The **`scrollTo()`** method of the Element interface scrolls to a particular set of coordinates inside a given element.
1325413254
*
1325513255
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/scrollTo)
1325613256
*/
13257-
scrollTo(options?: ScrollToOptions): Promise<void>;
13258-
scrollTo(x: number, y: number): Promise<void>;
13257+
scrollTo(options?: ScrollToOptions): void;
13258+
scrollTo(x: number, y: number): void;
1325913259
/**
1326013260
* The **`setAttribute()`** method of the Element interface sets the value of an attribute on the specified element. If the attribute already exists, the value is updated; otherwise a new attribute is added with the specified name and value.
1326113261
*

inputfiles/patches/scroll.kdl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
interface Element {
2+
method scroll overrideType=void
3+
method scroll overrideType=void
4+
method scrollBy overrideType=void
5+
method scrollBy overrideType=void
6+
method scrollTo overrideType=void
7+
method scrollTo overrideType=void
8+
method scrollIntoView overrideType=void
9+
}

src/build/patches.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
Typed,
1010
Dictionary,
1111
Member,
12+
Signature,
1213
} from "./types.js";
1314
import { readdir, readFile } from "fs/promises";
1415
import { merge } from "./helpers.js";
@@ -168,7 +169,34 @@ function handleMixinandInterfaces(
168169
}
169170
case "method": {
170171
const methodName = string(child.values[0]);
171-
method[methodName] = handleMethod(child);
172+
const m = handleMethod(child);
173+
if (method[methodName]) {
174+
// ts: The goal here is to merge multiple method signatures together for methods with the same name.
175+
const existingSig = method[methodName].signature;
176+
const newSigEntry = Array.isArray(m.signature) ? m.signature[0] : m.signature && (m.signature as any)[0];
177+
if (Array.isArray(existingSig)) {
178+
// Both are arrays, push new entry (if newSigEntry is available)
179+
if (newSigEntry !== undefined) {
180+
existingSig.push(newSigEntry);
181+
}
182+
} else if (
183+
existingSig &&
184+
typeof existingSig === "object" &&
185+
!Array.isArray(existingSig)
186+
) {
187+
// Existing is an object, add next numeric key
188+
let nextKey = 0;
189+
// Only own, string keys that are numbers
190+
while (Object.prototype.hasOwnProperty.call(existingSig, String(nextKey))) {
191+
nextKey++;
192+
}
193+
if (newSigEntry !== undefined) {
194+
(existingSig as Record<string, any>)[String(nextKey)] = newSigEntry;
195+
}
196+
}
197+
break;
198+
}
199+
method[methodName] = m;
172200
break;
173201
}
174202
default:
@@ -265,15 +293,15 @@ function handleMethod(child: Node): Partial<Method> {
265293
}
266294
}
267295

268-
const signature: Method["signature"] = [
296+
const signature: DeepPartial<Signature>[] | Record<string, DeepPartial<Signature>> = child.properties?.overrideType ? {"0": {overrideType: string(child.properties?.overrideType), param: params}} : [
269297
{
270298
param: params,
271299
...(typeNode
272300
? handleTyped(typeNode)
273301
: { type: string(child.properties?.returns) }),
274302
},
275303
];
276-
return { name, signature };
304+
return { name, signature } as Partial<Method>;
277305
}
278306

279307
/**

0 commit comments

Comments
 (0)