Skip to content

Commit 162dfd7

Browse files
committed
Define cross-module extensions
1 parent bd49bf4 commit 162dfd7

File tree

6 files changed

+39
-2
lines changed

6 files changed

+39
-2
lines changed

Sources/CSSOM/Generated.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,10 @@ public extension ElementCSSInlineStyle {
16651665
@inlinable var attributeStyleMap: StylePropertyMap { jsObject[Strings.attributeStyleMap].fromJSValue()! }
16661666
}
16671667

1668+
extension SVGElement: ElementCSSInlineStyle {}
1669+
1670+
extension MathMLElement: ElementCSSInlineStyle {}
1671+
16681672
public protocol GeometryUtils: JSBridgedClass {}
16691673
public extension GeometryUtils {
16701674
@inlinable func getBoxQuads(options: BoxQuadOptions? = nil) -> [DOMQuad] {
@@ -1688,6 +1692,10 @@ public extension GeometryUtils {
16881692
}
16891693
}
16901694

1695+
extension Text: GeometryUtils {}
1696+
1697+
extension CSSPseudoElement: GeometryUtils {}
1698+
16911699
public protocol LinkStyle: JSBridgedClass {}
16921700
public extension LinkStyle {
16931701
@inlinable var sheet: CSSStyleSheet? { jsObject[Strings.sheet].fromJSValue() }

Sources/FileSystem/Generated.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,10 @@ public extension NavigatorStorage {
439439
@inlinable var storage: StorageManager { jsObject[Strings.storage].fromJSValue()! }
440440
}
441441

442+
extension WorkerNavigator: NavigatorStorage {}
443+
444+
extension Navigator: NavigatorStorage {}
445+
442446
public class OpenFilePickerOptions: BridgedDictionary {
443447
public convenience init(multiple: Bool) {
444448
let object = JSObject.global[Strings.Object].function!.new()

Sources/WebAnimations/Generated.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public extension Animatable {
2020
}
2121
}
2222

23+
extension Element: Animatable {}
24+
2325
public class Animation: EventTarget {
2426
@inlinable override public class var constructor: JSFunction? { JSObject.global[Strings.Animation].function }
2527

Sources/WebGPU/Generated.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3532,6 +3532,10 @@ public extension NavigatorGPU {
35323532
@inlinable var gpu: GPU { jsObject[Strings.gpu].fromJSValue()! }
35333533
}
35343534

3535+
extension Navigator: NavigatorGPU {}
3536+
3537+
extension WorkerNavigator: NavigatorGPU {}
3538+
35353539
public typealias GPUBufferUsageFlags = UInt32
35363540
public typealias GPUMapModeFlags = UInt32
35373541
public typealias GPUTextureUsageFlags = UInt32

Sources/WebIDLToSwift/MergeDeclarations.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,9 @@ enum DeclarationMerger {
114114
}
115115
}
116116

117-
let includes = Dictionary(grouping: allNodes(ofType: IDLIncludes.self)) { $0.target }
117+
var includes = Dictionary(grouping: allNodes(ofType: IDLIncludes.self)) { $0.target }
118118
.mapValues { $0.map(\.includes).filter { !Self.ignoredParents.contains($0) } }
119+
.filter { !$0.value.isEmpty }
119120

120121
let mergedInterfaces = Dictionary(
121122
grouping: allNodes(ofType: IDLInterface.self).map {
@@ -145,7 +146,7 @@ enum DeclarationMerger {
145146
partialResult.exposedToAll = partialResult.exposedToAll || interface.exposedToAll
146147
partialResult.global = partialResult.global || interface.global
147148
}
148-
interface.mixins = includes[interface.name, default: []]
149+
interface.mixins = includes.removeValue(forKey: interface.name) ?? []
149150
if let decl = interface.members.first(where: { $0 is IDLIterableDeclaration }) as? IDLIterableDeclaration {
150151
interface.mixins.append(decl.async ? "AsyncSequence" : "Sequence")
151152
}
@@ -214,6 +215,7 @@ enum DeclarationMerger {
214215
+ Array(mergedDictionaries.values)
215216
+ Array(mixins.values)
216217
+ Array(mergedNamespaces.values)
218+
+ Array(includes.map(Extension.init))
217219
return MergeResult(
218220
declarations: arrays
219221
+ [Typedefs(typedefs: allTypes)]
@@ -298,6 +300,14 @@ struct MergedInterface: DeclarationFile {
298300
var global: Bool
299301
}
300302

303+
struct Extension: DeclarationFile {
304+
// sort next to declaration of protocol, hopefully
305+
var name: String { protocols.joined(separator: ", ") }
306+
let conformer: String
307+
var protocols: [String]
308+
}
309+
310+
301311
struct Typedefs: DeclarationFile, SwiftRepresentable {
302312
let name = "Typedefs"
303313
let typedefs: [IDLTypealias]

Sources/WebIDLToSwift/WebIDL+SwiftRepresentation.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,3 +783,12 @@ extension IDLValue: SwiftRepresentable {
783783
}
784784
}
785785
}
786+
787+
extension Extension: SwiftRepresentable {
788+
var swiftRepresentation: SwiftSource {
789+
"""
790+
extension \(conformer): \(raw: protocols.joined(separator: ", ")) {}
791+
\n
792+
"""
793+
}
794+
}

0 commit comments

Comments
 (0)