Repository navigation
Conversation
| } | ||
|
|
||
| extension Parameter { | ||
| fileprivate var escapedSwiftIdentifier: String { |
There was a problem hiding this comment.
@JS func f(_ in: String) still generates invalid Swift and JS, because parseParameters (SwiftToSkeleton.swift:1590) keeps the backticks in param.name:
public func _bjs_f(_ `in`Bytes: Int32, _ `in`Length: Int32) -> Void {f: function bjs_f(`in`) {
const `in`Bytes = textEncoder.encode(`in`);The import path already strips them with normalizeIdentifier. If this path does the same, the escaping in this PR covers both spellings:
let name = SwiftToSkeleton.normalizeIdentifier(param.secondName?.text ?? param.firstName.text)@JS func checkEscaped(_ `in`: String) {}| "protected", "public", "arguments", "eval", | ||
| ] | ||
|
|
||
| fileprivate var escapedJSIdentifier: String { |
There was a problem hiding this comment.
For @JS protocol Delegate { func handle(in: Int) } the d.ts now has handle(_in: number), but the glue still uses in:
TestModule["bjs_Delegate_handle"] = function bjs_Delegate_handle(self, in) {func handle(in: Int) -> Void {
let inValue = in.bridgeJSLowerParameter()@JSFunction func f(in: Int) has the same problem. It would be good to resolve in this PR, but follow up is fine as well ✌️ The JS side is in ImportedThunkBuilder.liftParameter:
} else if liftingFragment.parameters.count == 1 {
let name = scope.variable(param.escapedJSIdentifier)
parameterNames.append(name)
valuesToLift = [name]
}The Swift side needs backtickIfNeeded() where CallJSEmission.lowerParameter reads param.name.
| @@ -0,0 +1 @@ | |||
| @JS func check(extension: Int, break: Double, function: Bool, in: String) {} | |||
There was a problem hiding this comment.
This PR also changes the constructor and method paths. They generate correctly today, and these cases would keep it that way:
@JS class ReservedWordBox {
@JS init(in: Int) {}
@JS func run(for: Int) {}
@JS static func make(default: Int) -> Int { 0 }
}
Currently parameter names using reserved words, such as
extensionorbreak, generate invalid Swift and/or JS. Reserved words are now escaped with backticks in Swift and with a leading underscore in JS. Originally I removed the parameter names from the generated thunks entirely, just usingparam0param1etc., but this made the generated code harder to read.