Skip to content

Update arg parser, fix deprecated JSKit types #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ let package = Package(
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(name: "swift-argument-parser", url: "https://github.com/apple/swift-argument-parser", from: "0.0.1"),
.package(name: "swift-format", url: "https://github.com/apple/swift-format.git", .branch("swift-5.2-branch")),
.package(name: "SwiftSyntax", url: "https://github.com/apple/swift-syntax.git", .branch("swift-5.2-branch")),
.package(name: "swift-argument-parser", url: "https://github.com/apple/swift-argument-parser", from: "0.3.1"),
.package(name: "swift-format", url: "https://github.com/apple/swift-format.git", .branch("swift-5.3-branch")),
.package(name: "SwiftSyntax", url: "https://github.com/apple/swift-syntax.git", .upToNextMinor(from: "0.50300.0")),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand Down
19 changes: 10 additions & 9 deletions Sources/Commands/GenerateCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ public struct GenerateCode: ParsableCommand {

/// The path to the output directory.
@Option(name: .shortAndLong, help: "The path to the output directory.")
public var ouputDirectory: String
public var outputDirectory: String

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

/// Print verbose output.
@Flag(help: "Print verbose output.")
public var verbose: Bool
public var verbose: Bool = false

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

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

if verbose {
print("inputDirectory: \(inputDirectory)")
print("ouputDirectory: \(ouputDirectory)")
print("outputDirectory: \(outputDirectory)")
print("createSeparateFiles: \(createSeparateFiles)")
}

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

let parser = Parser(input: tokenisationResult)
let definitions: [Definition]
Expand Down Expand Up @@ -89,8 +90,8 @@ public struct GenerateCode: ParsableCommand {

"""

let packageDirectory = URL(fileURLWithPath: ouputDirectory).appendingPathComponent("WebAPI")
let sourcesDirectory = packageDirectory.appendingPathComponent("Sources").appendingPathComponent("WebAPI")
let packageDirectory = URL(fileURLWithPath: outputDirectory).appendingPathComponent("WebIDL")
let sourcesDirectory = packageDirectory.appendingPathComponent("Sources").appendingPathComponent("WebIDL")

let fileManager = FileManager.default

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public class IRGenerator {

case .promiseType(let promise):
let returnType = handleType(promise.returnType)
return ir.registerBasicType(withTypeName: "Promise<\(returnType.identifier)>")
return ir.registerBasicType(withTypeName: "JSPromise<\(returnType.identifier), JSError>")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ class DictionaryNode: TypeNode, Equatable {

private let dictionary: [String : JSValue]

public init(uniqueKeysWithValues elements: [(Key, JSValueConvertible)]) {
public init(uniqueKeysWithValues elements: [(Key, ConvertibleToJSValue)]) {
self.dictionary = Dictionary(uniqueKeysWithValues: elements.map({ ($0.0.rawValue, $0.1.jsValue()) }))
}

public init(dictionaryLiteral elements: (Key, JSValueConvertible)...) {
public init(dictionaryLiteral elements: (Key, ConvertibleToJSValue)...) {
self.dictionary = Dictionary(uniqueKeysWithValues: elements.map({ ($0.0.rawValue, $0.1.jsValue()) }))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class EnumerationWithRawValueNode: TypeNode, Equatable {
}

var declaration = """
public enum \(typeName): String, JSValueCodable {
public enum \(typeName): String, JSValueCompatible {

public static func construct(from jsValue: JSValue) -> \(typeName)? {
if let string = jsValue.string,
Expand Down