@expo/expo-modules-macros-plugin 0.5.0 → 0.5.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
@@ -411,10 +411,11 @@ internal func buildDecorateJavaScriptObject(functions: [JSFunction], properties:
411
411
 
412
412
  /// The shared-object counterpart of `_decorateModule`. Core supplies the class `prototype`; this binds
413
413
  /// every `@JS func` and `@JS var` of the given shared-object type onto it. Because a shared object has a
414
- /// distinct native instance behind each JS object, the bindings are **static** and recover the typed
415
- /// receiver from the JS `this` per call (`try SharedObject.native(from: this.asObject(in: runtime), as: <Type>.self)`)
416
- /// rather than capturing a singleton `self`. The first parameter is `prototype` (not `object` as on
417
- /// `_decorateModule`) because it's the shared class prototype, not an instance. The constructor is
414
+ /// distinct native instance behind each JS object, the bindings recover the typed receiver from the JS
415
+ /// `this` per call (`try SharedObject.native(from: this.asObject(in: runtime), as: <Type>.self)`)
416
+ /// rather than capturing a singleton `self`. Overrides the base `SharedObject` class method so core can
417
+ /// dispatch to it through the concrete type's metatype. The first parameter is `prototype` (not `object`
418
+ /// as on `_decorateModule`) because it's the shared class prototype, not an instance. The constructor is
418
419
  /// bound separately (see `JSConstructor.buildConstructor`). Only emitted when the type has at least one
419
420
  /// `@JS func`/`var`.
420
421
  internal func buildDecorateSharedObject(
@@ -423,7 +424,7 @@ internal func buildDecorateSharedObject(
423
424
  let body = decorateBody(functions: functions, properties: properties, receiver: .sharedObject(typeName: typeName))
424
425
  return """
425
426
  @JavaScriptActor
426
- public static func _decorateSharedObject(prototype: borrowing JavaScriptObject, in runtime: JavaScriptRuntime, appContext: AppContext) throws {
427
+ public override class func _decorateSharedObject(prototype: borrowing JavaScriptObject, in runtime: JavaScriptRuntime, appContext: AppContext) throws {
427
428
  \(raw: body)
428
429
  }
429
430
  """
@@ -1,9 +1,10 @@
1
1
  import SwiftSyntax
2
2
 
3
3
  /// A `@JS init` collected for direct JSI binding. A shared-object type has at most one (JS classes
4
- /// have a single constructor). Instead of a `Constructor { … }` DSL entry, the macro synthesizes a
5
- /// static `_constructSharedObject(...)` that decodes the JS arguments and returns a fresh instance;
6
- /// unlike the method/property bindings it produces the native instance rather than recovering one.
4
+ /// have a single constructor). Instead of a `Constructor { … }` DSL entry, the macro synthesizes an
5
+ /// override of `SharedObject._constructSharedObject(...)` that decodes the JS arguments and returns a
6
+ /// fresh instance; unlike the method/property bindings it produces the native instance rather than
7
+ /// recovering one.
7
8
  internal struct JSConstructor {
8
9
  let parameters: [FunctionParameterSyntax]
9
10
 
@@ -47,12 +48,14 @@ internal struct JSConstructor {
47
48
  .joined(separator: "\n")
48
49
  }
49
50
 
50
- /// The static `_constructSharedObject` entry point the runtime calls to build an instance from JS
51
- /// arguments, returning the concrete type. `this`/`appContext` may go unreferenced, which is harmless.
51
+ /// The `_constructSharedObject` entry point the runtime calls to build an instance from JS
52
+ /// arguments. Overrides the base `SharedObject` class method so core can dispatch to it through the
53
+ /// concrete type's metatype; the body returns the concrete instance, which promotes to the base
54
+ /// `SharedObject?` return type. `this`/`appContext` may go unreferenced, which is harmless.
52
55
  func buildConstructor(typeName: String) -> DeclSyntax {
53
56
  return """
54
57
  @JavaScriptActor
55
- public static func _constructSharedObject(this: JavaScriptValue, arguments: borrowing JavaScriptValuesBuffer, in runtime: JavaScriptRuntime, appContext: AppContext) throws -> \(raw: typeName) {
58
+ public override class func _constructSharedObject(this: JavaScriptValue, arguments: borrowing JavaScriptValuesBuffer, in runtime: JavaScriptRuntime, appContext: AppContext) throws -> SharedObject? {
56
59
  \(raw: bodyStatements(typeName: typeName, indent: " "))
57
60
  }
58
61
  """
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expo/expo-modules-macros-plugin",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Swift macro plugin for Expo modules",
5
5
  "license": "MIT",
6
6
  "author": "650 Industries, Inc.",