Skip to content

Commit b56d465

Browse files
Added richer WebIDL-derived doc coverage using the bridgejs-development skill: new fixtures model lib.dom-style comments (MDN reference blocks, @param text) and updated Vitest snapshots to show how those JSDoc comments render into DocC. Key files: Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/WebIDLDOMDocs.d.ts, Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/DOMLike.d.ts, and the refreshed snapshot in Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/__snapshots__/ts2swift.test.js.snap. Tests run: npm test -- -u (TS2Swift JavaScript).
1 parent df68ef7 commit b56d465

File tree

3 files changed

+249
-0
lines changed

3 files changed

+249
-0
lines changed

Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/__snapshots__/ts2swift.test.js.snap

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,26 @@ exports[`ts2swift > snapshots Swift output for Async.d.ts > Async 1`] = `
4848
"
4949
`;
5050

51+
exports[`ts2swift > snapshots Swift output for DOMLike.d.ts > DOMLike 1`] = `
52+
"// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit,
53+
// DO NOT EDIT.
54+
//
55+
// To update this file, just rebuild your project or run
56+
// \`swift package bridge-js\`.
57+
58+
@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit
59+
60+
/// Schedules a function to be run after a delay.
61+
///
62+
/// - Parameters:
63+
/// - handler: A function to execute after the timer expires.
64+
/// - timeout: The time, in milliseconds, the timer should wait before the handler is executed.
65+
/// - args: Additional arguments to pass to the handler.
66+
/// - Returns: A numeric identifier for the timer.
67+
@JSFunction func setTimeout(_ handler: JSObject, _ timeout: JSUndefinedOr<Double>, _ args: [JSValue]) throws(JSException) -> Double
68+
"
69+
`;
70+
5171
exports[`ts2swift > snapshots Swift output for Documentation.d.ts > Documentation 1`] = `
5272
"// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit,
5373
// DO NOT EDIT.
@@ -429,3 +449,90 @@ exports[`ts2swift > snapshots Swift output for VoidParameterVoidReturn.d.ts > Vo
429449
@JSFunction func check() throws(JSException) -> Void
430450
"
431451
`;
452+
453+
exports[`ts2swift > snapshots Swift output for WebIDLDOMDocs.d.ts > WebIDLDOMDocs 1`] = `
454+
"// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit,
455+
// DO NOT EDIT.
456+
//
457+
// To update this file, just rebuild your project or run
458+
// \`swift package bridge-js\`.
459+
460+
@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit
461+
462+
/// [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document)
463+
@JSGetter var document: Document
464+
465+
/// A simple Document subset with WebIDL-derived comments.
466+
@JSClass struct Document {
467+
/// Creates an instance of the element for the specified tag.
468+
///
469+
/// - Parameters:
470+
/// - tagName: The name of an element.
471+
///
472+
/// [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/createElement)
473+
@JSFunction func createElement(_ tagName: String, _ options: JSUndefinedOr<ElementCreationOptions>) throws(JSException) -> Element
474+
/// Returns an element with namespace namespace. Its namespace prefix will be everything before ":" (U+003E) in qualifiedName or null. Its local name will be everything after ":" (U+003E) in qualifiedName or qualifiedName.
475+
///
476+
/// If localName does not match the Name production an "InvalidCharacterError" DOMException will be thrown.
477+
///
478+
/// If one of the following conditions is true a "NamespaceError" DOMException will be thrown:
479+
///
480+
/// localName does not match the QName production.
481+
/// Namespace prefix is not null and namespace is the empty string.
482+
/// Namespace prefix is "xml" and namespace is not the XML namespace.
483+
/// qualifiedName or namespace prefix is "xmlns" and namespace is not the XMLNS namespace.
484+
/// namespace is the XMLNS namespace and neither qualifiedName nor namespace prefix is "xmlns".
485+
///
486+
/// When supplied, options's is can be used to create a customized built-in element.
487+
///
488+
/// [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/createElementNS)
489+
@JSFunction func createElementNS(_ namespaceURI: Optional<String>, _ qualifiedName: String, _ options: JSObject) throws(JSException) -> Element
490+
/// Creates a TreeWalker object.
491+
///
492+
/// - Parameters:
493+
/// - root: The root element or node to start traversing on.
494+
/// - whatToShow: The type of nodes or elements to appear in the node list
495+
/// - filter: A custom NodeFilter function to use. For more information, see filter. Use null for no filter.
496+
/// - Returns: The created TreeWalker.
497+
///
498+
/// [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/createTreeWalker)
499+
@JSFunction func createTreeWalker(_ root: Node, _ whatToShow: JSUndefinedOr<Double>, _ filter: JSUndefinedOr<JSObject>) throws(JSException) -> TreeWalker
500+
}
501+
502+
@JSClass struct ElementCreationOptions {
503+
@JSGetter var \`is\`: JSUndefinedOr<String>
504+
@JSSetter func setIs(_ value: JSUndefinedOr<String>) throws(JSException)
505+
}
506+
507+
@JSClass struct Element {
508+
/// [MDN Reference](https://developer.mozilla.org/docs/Web/API/Node/textContent)
509+
@JSGetter var textContent: Optional<String>
510+
@JSSetter func setTextContent(_ value: Optional<String>) throws(JSException)
511+
/// Returns a copy of node. If deep is true, the copy also includes the node's descendants.
512+
///
513+
/// [MDN Reference](https://developer.mozilla.org/docs/Web/API/Node/cloneNode)
514+
@JSFunction func cloneNode(_ subtree: JSObject) throws(JSException) -> Node
515+
}
516+
517+
/// Minimal stubs to mirror lib.dom.d.ts documentation converted from WebIDL.
518+
@JSClass struct Node {
519+
/// [MDN Reference](https://developer.mozilla.org/docs/Web/API/Node/textContent)
520+
@JSGetter var textContent: Optional<String>
521+
@JSSetter func setTextContent(_ value: Optional<String>) throws(JSException)
522+
/// Returns a copy of node. If deep is true, the copy also includes the node's descendants.
523+
///
524+
/// [MDN Reference](https://developer.mozilla.org/docs/Web/API/Node/cloneNode)
525+
@JSFunction func cloneNode(_ subtree: JSObject) throws(JSException) -> Node
526+
}
527+
528+
@JSClass struct TreeWalker {
529+
/// [MDN Reference](https://developer.mozilla.org/docs/Web/API/TreeWalker/currentNode)
530+
@JSGetter var currentNode: Node
531+
@JSSetter func setCurrentNode(_ value: Node) throws(JSException)
532+
/// Moves the currentNode to the next visible node in the document order.
533+
///
534+
/// [MDN Reference](https://developer.mozilla.org/docs/Web/API/TreeWalker/nextNode)
535+
@JSFunction func nextNode() throws(JSException) -> Optional<Node>
536+
}
537+
"
538+
`;
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* Represents a node in the DOM tree.
3+
*/
4+
export interface Node {
5+
/**
6+
* Returns the name of the node, depending on its type.
7+
*/
8+
readonly nodeName: string;
9+
}
10+
11+
/**
12+
* A string tokenizer that supports adding and removing tokens.
13+
*
14+
* Mirrors DOMTokenList in lib.dom.d.ts.
15+
*/
16+
export interface DOMTokenList {
17+
/**
18+
* Adds the specified token(s) to the list.
19+
* @param tokens A set of space-separated tokens to add to the list.
20+
*/
21+
add(...tokens: string[]): void;
22+
23+
/**
24+
* Returns true if the list contains a given token, otherwise false.
25+
* @param token Token to locate in the list.
26+
* @returns True if the token is present, otherwise false.
27+
*/
28+
contains(token: string): boolean;
29+
}
30+
31+
/**
32+
* Represents an element in the document.
33+
*/
34+
export interface Element extends Node {
35+
/**
36+
* Returns a live DOMTokenList of class values.
37+
*/
38+
readonly classList: DOMTokenList;
39+
40+
/**
41+
* Returns the first element that is a descendant of node that matches selectors.
42+
* @param selectors Selectors to match against.
43+
* @returns The first matching element or null if there is no such element.
44+
*/
45+
querySelector(selectors: string): Element | null;
46+
47+
/**
48+
* Appends nodes or strings after the last child of this element.
49+
* @param nodes Nodes or strings to append.
50+
*/
51+
append(...nodes: (Node | string)[]): void;
52+
}
53+
54+
/**
55+
* Schedules a function to be run after a delay.
56+
* @param handler A function to execute after the timer expires.
57+
* @param timeout The time, in milliseconds, the timer should wait before the handler is executed.
58+
* @param args Additional arguments to pass to the handler.
59+
* @returns A numeric identifier for the timer.
60+
*/
61+
export function setTimeout(handler: (...args: any[]) => void, timeout?: number, ...args: any[]): number;
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
* Minimal stubs to mirror lib.dom.d.ts documentation converted from WebIDL.
3+
*/
4+
5+
interface Node {
6+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Node/textContent) */
7+
textContent: string | null;
8+
/**
9+
* Returns a copy of node. If deep is true, the copy also includes the node's descendants.
10+
*
11+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Node/cloneNode)
12+
*/
13+
cloneNode(subtree?: boolean): Node;
14+
}
15+
16+
interface Element extends Node {}
17+
type HTMLElement = Element;
18+
type SVGElement = Element;
19+
type MathMLElement = Element;
20+
type DocumentFragment = Node;
21+
22+
interface ElementCreationOptions {
23+
is?: string;
24+
}
25+
26+
/**
27+
* A simple Document subset with WebIDL-derived comments.
28+
*/
29+
interface Document {
30+
/**
31+
* Creates an instance of the element for the specified tag.
32+
* @param tagName The name of an element.
33+
*
34+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/createElement)
35+
*/
36+
createElement(tagName: string, options?: ElementCreationOptions): HTMLElement;
37+
38+
/**
39+
* Returns an element with namespace namespace. Its namespace prefix will be everything before ":" (U+003E) in qualifiedName or null. Its local name will be everything after ":" (U+003E) in qualifiedName or qualifiedName.
40+
*
41+
* If localName does not match the Name production an "InvalidCharacterError" DOMException will be thrown.
42+
*
43+
* If one of the following conditions is true a "NamespaceError" DOMException will be thrown:
44+
*
45+
* localName does not match the QName production.
46+
* Namespace prefix is not null and namespace is the empty string.
47+
* Namespace prefix is "xml" and namespace is not the XML namespace.
48+
* qualifiedName or namespace prefix is "xmlns" and namespace is not the XMLNS namespace.
49+
* namespace is the XMLNS namespace and neither qualifiedName nor namespace prefix is "xmlns".
50+
*
51+
* When supplied, options's is can be used to create a customized built-in element.
52+
*
53+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/createElementNS)
54+
*/
55+
createElementNS(namespaceURI: string | null, qualifiedName: string, options?: string | ElementCreationOptions): Element;
56+
57+
/**
58+
* Creates a TreeWalker object.
59+
* @param root The root element or node to start traversing on.
60+
* @param whatToShow The type of nodes or elements to appear in the node list
61+
* @param filter A custom NodeFilter function to use. For more information, see filter. Use null for no filter.
62+
* @returns The created TreeWalker.
63+
*
64+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/createTreeWalker)
65+
*/
66+
createTreeWalker(root: Node, whatToShow?: number, filter?: (node: Node) => number | null): TreeWalker;
67+
}
68+
69+
interface TreeWalker {
70+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/TreeWalker/currentNode) */
71+
currentNode: Node;
72+
/**
73+
* Moves the currentNode to the next visible node in the document order.
74+
*
75+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/TreeWalker/nextNode)
76+
*/
77+
nextNode(): Node | null;
78+
}
79+
80+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document) */
81+
export const document: Document;

0 commit comments

Comments
 (0)