Skip to content

Commit d6ebd8b

Browse files
authored
Update arg parser, fix deprecated JSKit types (#10)
This makes the output fully compatible with JavaScriptKit 0.9. I've also updated dependencies in `Package.swift` to use their latest stable versions. * Update arg parser, fix deprecated JSKit types * Fix `JSPromise` compatibility
1 parent 8dbbeaf commit d6ebd8b

File tree

5 files changed

+17
-16
lines changed

5 files changed

+17
-16
lines changed

Package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ let package = Package(
1313
dependencies: [
1414
// Dependencies declare other packages that this package depends on.
1515
// .package(url: /* package url */, from: "1.0.0"),
16-
.package(name: "swift-argument-parser", url: "https://github.com/apple/swift-argument-parser", from: "0.0.1"),
17-
.package(name: "swift-format", url: "https://github.com/apple/swift-format.git", .branch("swift-5.2-branch")),
18-
.package(name: "SwiftSyntax", url: "https://github.com/apple/swift-syntax.git", .branch("swift-5.2-branch")),
16+
.package(name: "swift-argument-parser", url: "https://github.com/apple/swift-argument-parser", from: "0.3.1"),
17+
.package(name: "swift-format", url: "https://github.com/apple/swift-format.git", .branch("swift-5.3-branch")),
18+
.package(name: "SwiftSyntax", url: "https://github.com/apple/swift-syntax.git", .upToNextMinor(from: "0.50300.0")),
1919
],
2020
targets: [
2121
// Targets are the basic building blocks of a package. A target can define a module or a test suite.

Sources/Commands/GenerateCode.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ public struct GenerateCode: ParsableCommand {
1919

2020
/// The path to the output directory.
2121
@Option(name: .shortAndLong, help: "The path to the output directory.")
22-
public var ouputDirectory: String
22+
public var outputDirectory: String
2323

2424
/// Create a file for each definition.
25-
@Flag(name: .long, default: true, inversion: .prefixedNo, help: "Create a file for each definition.")
26-
public var createSeparateFiles: Bool
25+
@Flag(name: .long, inversion: .prefixedNo, help: "Create a file for each definition.")
26+
public var createSeparateFiles: Bool = true
2727

2828
/// Print verbose output.
2929
@Flag(help: "Print verbose output.")
30-
public var verbose: Bool
30+
public var verbose: Bool = false
3131

3232
/// Run swift-format over output.
33-
@Flag(name: .long, default: true, inversion: .prefixedNo, help: "Run swift-format over output.")
34-
public var prettyPrint: Bool
33+
@Flag(name: .long, inversion: .prefixedNo, help: "Run swift-format over output.")
34+
public var prettyPrint: Bool = true
3535

3636
/// Initialize a `GenerateCode` instance
3737
public init() {}
@@ -42,14 +42,15 @@ public struct GenerateCode: ParsableCommand {
4242

4343
if verbose {
4444
print("inputDirectory: \(inputDirectory)")
45-
print("ouputDirectory: \(ouputDirectory)")
45+
print("outputDirectory: \(outputDirectory)")
4646
print("createSeparateFiles: \(createSeparateFiles)")
4747
}
4848

4949
guard let tokenisationResult = try Tokenizer.tokenize(filesInDirectoryAt: URL(fileURLWithPath: inputDirectory)) else {
5050
print("Error tokenizing input files.")
5151
Self.exit(withError: ExitCode.failure)
5252
}
53+
print("files tokenized successfully")
5354

5455
let parser = Parser(input: tokenisationResult)
5556
let definitions: [Definition]
@@ -89,8 +90,8 @@ public struct GenerateCode: ParsableCommand {
8990
9091
"""
9192

92-
let packageDirectory = URL(fileURLWithPath: ouputDirectory).appendingPathComponent("WebAPI")
93-
let sourcesDirectory = packageDirectory.appendingPathComponent("Sources").appendingPathComponent("WebAPI")
93+
let packageDirectory = URL(fileURLWithPath: outputDirectory).appendingPathComponent("WebIDL")
94+
let sourcesDirectory = packageDirectory.appendingPathComponent("Sources").appendingPathComponent("WebIDL")
9495

9596
let fileManager = FileManager.default
9697

Sources/WebIDL/IntermediateRepresentation/IRGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public class IRGenerator {
287287

288288
case .promiseType(let promise):
289289
let returnType = handleType(promise.returnType)
290-
return ir.registerBasicType(withTypeName: "Promise<\(returnType.identifier)>")
290+
return ir.registerBasicType(withTypeName: "JSPromise<\(returnType.identifier), JSError>")
291291
}
292292
}
293293

Sources/WebIDL/IntermediateRepresentation/Type Nodes/DictionaryNode.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ class DictionaryNode: TypeNode, Equatable {
7070
7171
private let dictionary: [String : JSValue]
7272
73-
public init(uniqueKeysWithValues elements: [(Key, JSValueConvertible)]) {
73+
public init(uniqueKeysWithValues elements: [(Key, ConvertibleToJSValue)]) {
7474
self.dictionary = Dictionary(uniqueKeysWithValues: elements.map({ ($0.0.rawValue, $0.1.jsValue()) }))
7575
}
7676
77-
public init(dictionaryLiteral elements: (Key, JSValueConvertible)...) {
77+
public init(dictionaryLiteral elements: (Key, ConvertibleToJSValue)...) {
7878
self.dictionary = Dictionary(uniqueKeysWithValues: elements.map({ ($0.0.rawValue, $0.1.jsValue()) }))
7979
}
8080

Sources/WebIDL/IntermediateRepresentation/Type Nodes/EnumerationWithRawValueNode.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class EnumerationWithRawValueNode: TypeNode, Equatable {
3535
}
3636

3737
var declaration = """
38-
public enum \(typeName): String, JSValueCodable {
38+
public enum \(typeName): String, JSValueCompatible {
3939
4040
public static func construct(from jsValue: JSValue) -> \(typeName)? {
4141
if let string = jsValue.string,

0 commit comments

Comments
 (0)