@expo/expo-modules-macros-plugin 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
@@ -90,23 +90,21 @@ internal struct JSFunction {
90
90
  // No omittable trailing run: a single flat call with every argument decoded.
91
91
  lines.append(contentsOf: callAndEncodeLines(receiver: receiver, arity: maximum, decodingFrom: required))
92
92
  } else {
93
- // One call shape per accepted arity. Each branch decodes only the trailing slots it has and
94
- // fills the rest (defaulted params drop their label so Swift applies the default; optional
95
- // params are passed `nil`). A value-returning function binds the result from a `switch`
96
- // expression and encodes once after it; a no-return one calls inline in a `switch` statement
97
- // and returns `.undefined`.
98
- if returnType != nil {
99
- lines.append("let result = switch arguments.count {")
100
- } else {
101
- lines.append("switch arguments.count {")
93
+ // One call shape per accepted arity, branching on `arguments.count`. A branch decodes a
94
+ // trailing slot before the call, so this is a `switch` statement (not an expression): a
95
+ // value-returning function declares `result` up front and each branch assigns it.
96
+ if let returnType {
97
+ lines.append("let result: \(expressionType(returnType))")
102
98
  }
99
+ lines.append("switch arguments.count {")
103
100
  for arity in required...maximum {
104
101
  let label = arity == maximum ? "default:" : "case \(arity):"
105
102
  lines.append(label)
106
103
  for index in required..<arity {
107
104
  lines.append(" " + decodeStatement(at: index))
108
105
  }
109
- lines.append(" \(callExpression(receiver: receiver, arity: arity))")
106
+ let assignment = returnType != nil ? "result = " : ""
107
+ lines.append(" \(assignment)\(callExpression(receiver: receiver, arity: arity))")
110
108
  }
111
109
  lines.append("}")
112
110
  lines.append(contentsOf: encodeResultLines())
@@ -340,7 +338,7 @@ internal func buildDecorateJavaScriptObject(functions: [JSFunction], properties:
340
338
  let body = decorateBody(functions: functions, properties: properties, receiver: .module)
341
339
  return """
342
340
  @JavaScriptActor
343
- public func _decorateModule(object: borrowing JavaScriptObject, in runtime: JavaScriptRuntime, appContext: AppContext) throws {
341
+ public func _decorateModule(object: borrowing JavaScriptObject, in runtime: JavaScriptRuntime) throws {
344
342
  \(raw: body)
345
343
  }
346
344
  """
@@ -361,7 +359,7 @@ internal func buildDecorateSharedObject(
361
359
  let body = decorateBody(functions: functions, properties: properties, receiver: .sharedObject(typeName: typeName))
362
360
  return """
363
361
  @JavaScriptActor
364
- public override class func _decorateSharedObject(prototype: borrowing JavaScriptObject, in runtime: JavaScriptRuntime, appContext: AppContext) throws {
362
+ public override class func _decorateSharedObject(prototype: borrowing JavaScriptObject, in runtime: JavaScriptRuntime) throws {
365
363
  \(raw: body)
366
364
  }
367
365
  """
@@ -42,14 +42,12 @@ internal struct JSConstructor {
42
42
  .joined(separator: "\n")
43
43
  }
44
44
 
45
- /// The `_constructSharedObject` entry point the runtime calls to build an instance from JS
46
- /// arguments. Overrides the base `SharedObject` class method so core can dispatch to it through the
47
- /// concrete type's metatype; the body returns the concrete instance, which promotes to the base
48
- /// `SharedObject?` return type. `this`/`appContext` may go unreferenced, which is harmless.
45
+ /// Builds an instance from the JS arguments. Overrides the base `SharedObject` class method; returns
46
+ /// the concrete instance, which promotes to the base `SharedObject?` return type.
49
47
  func buildConstructor(typeName: String) -> DeclSyntax {
50
48
  return """
51
49
  @JavaScriptActor
52
- public override class func _constructSharedObject(this: JavaScriptValue, arguments: borrowing JavaScriptValuesBuffer, in runtime: JavaScriptRuntime, appContext: AppContext) throws -> SharedObject? {
50
+ public override class func _constructSharedObject(this: JavaScriptValue, arguments: borrowing JavaScriptValuesBuffer, in runtime: JavaScriptRuntime) throws -> SharedObject? {
53
51
  \(raw: bodyStatements(typeName: typeName, indent: " "))
54
52
  }
55
53
  """
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expo/expo-modules-macros-plugin",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "Swift macro plugin for Expo modules",
5
5
  "license": "MIT",
6
6
  "author": "650 Industries, Inc.",