@nstudio/nativescript-compiler 9.2.0-alpha.17 → 9.2.0-alpha.18

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.
Files changed (162) hide show
  1. package/README.md +3 -0
  2. package/dist/kotlin/access.js +8 -7
  3. package/dist/kotlin/assignment.js +22 -13
  4. package/dist/kotlin/builtins.js +67 -0
  5. package/dist/kotlin/calls.js +3 -2
  6. package/dist/kotlin/class-declaration.js +4 -9
  7. package/dist/kotlin/class-methods.js +2 -2
  8. package/dist/kotlin/core-api.js +1 -1
  9. package/dist/kotlin/declarations.js +1 -1
  10. package/dist/kotlin/expression-statements.js +13 -1
  11. package/dist/kotlin/functions.js +1 -0
  12. package/dist/kotlin/literals.js +4 -8
  13. package/dist/kotlin/names.js +4 -4
  14. package/dist/kotlin/native/api.js +1 -1
  15. package/dist/kotlin/operators.js +25 -25
  16. package/dist/kotlin/optional-chains.js +1 -1
  17. package/dist/kotlin/overrides.js +2 -2
  18. package/dist/kotlin/state-backend.js +6 -2
  19. package/dist/kotlin/translator.js +1 -1
  20. package/dist/kotlin/types.js +4 -4
  21. package/dist/semantics/classes.js +15 -0
  22. package/dist/semantics/facts.js +1 -1
  23. package/dist/semantics/lang.js +10 -0
  24. package/dist/semantics/lower.js +54 -0
  25. package/dist/semantics/lowering-methods.js +5 -0
  26. package/dist/semantics/placement.js +9 -3
  27. package/dist/semantics/signals.js +11 -0
  28. package/dist/semantics/states/missing.js +7 -0
  29. package/dist/semantics/tdz.js +54 -15
  30. package/dist/semantics/throws.js +1 -1
  31. package/dist/semantics/translator-methods.js +1 -1
  32. package/dist/swift/access.js +7 -9
  33. package/dist/swift/assignment.js +20 -14
  34. package/dist/swift/calls.js +6 -3
  35. package/dist/swift/classes.js +7 -9
  36. package/dist/swift/components.js +3 -3
  37. package/dist/swift/control-flow.js +1 -1
  38. package/dist/swift/conversion.js +5 -2
  39. package/dist/swift/core-api.js +2 -2
  40. package/dist/swift/declarations.js +1 -1
  41. package/dist/swift/expressions.js +6 -2
  42. package/dist/swift/from-any.js +1 -1
  43. package/dist/swift/functions.js +5 -6
  44. package/dist/swift/global-calls.js +1 -1
  45. package/dist/swift/lenient.js +1 -6
  46. package/dist/swift/literals.js +8 -3
  47. package/dist/swift/modules.js +3 -3
  48. package/dist/swift/names.js +3 -3
  49. package/dist/swift/native/calls.js +1 -1
  50. package/dist/swift/object-classes.js +84 -1
  51. package/dist/swift/operators.js +31 -29
  52. package/dist/swift/placement.js +4 -3
  53. package/dist/swift/state-backend.js +3 -2
  54. package/dist/swift/static-calls.js +2 -3
  55. package/dist/swift/syntax.js +9 -5
  56. package/dist/swift/translator.js +1 -1
  57. package/dist/swift/type-facts.js +3 -3
  58. package/dist/swift/types.js +3 -3
  59. package/dist/targets/ios/build.js +1 -1
  60. package/kit-android/generated/kotlin/org/nativescript/kit/__Modules.kt +1 -0
  61. package/kit-android/generated/kotlin/org/nativescript/kit/__Objects.kt +525 -99
  62. package/kit-android/generated/kotlin/org/nativescript/kit/accessibility_accessibility_common.kt +2 -2
  63. package/kit-android/generated/kotlin/org/nativescript/kit/application_application_common.kt +29 -6
  64. package/kit-android/generated/kotlin/org/nativescript/kit/application_helpers_common.kt +14 -0
  65. package/kit-android/generated/kotlin/org/nativescript/kit/color_color_utils.kt +3 -3
  66. package/kit-android/generated/kotlin/org/nativescript/kit/css_mediaquery_index.kt +49 -1
  67. package/kit-android/generated/kotlin/org/nativescript/kit/data_observable_array_index.kt +0 -8
  68. package/kit-android/generated/kotlin/org/nativescript/kit/data_observable_index.kt +0 -16
  69. package/kit-android/generated/kotlin/org/nativescript/kit/data_virtual_array_index.kt +6 -4
  70. package/kit-android/generated/kotlin/org/nativescript/kit/http_http_request_index.kt +19 -7
  71. package/kit-android/generated/kotlin/org/nativescript/kit/http_http_request_internal_http_request_internal_common.kt +14 -0
  72. package/kit-android/generated/kotlin/org/nativescript/kit/http_http_request_internal_index.kt +19 -10
  73. package/kit-android/generated/kotlin/org/nativescript/kit/matrix_index.kt +17 -29
  74. package/kit-android/generated/kotlin/org/nativescript/kit/media_query_list_index.kt +144 -22
  75. package/kit-android/generated/kotlin/org/nativescript/kit/npm_css_what_src_parse.kt +8 -3
  76. package/kit-android/generated/kotlin/org/nativescript/kit/org.nativescript.NativeScriptLifecycleCallbacks.kt +2 -10
  77. package/kit-android/generated/kotlin/org/nativescript/kit/ui_builder_index.kt +0 -2
  78. package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_bindable_expression_parser.kt +6 -10
  79. package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_properties_index.kt +531 -8
  80. package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_view_base_index.kt +0 -9
  81. package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_weak_event_listener_index.kt +3 -3
  82. package/kit-android/generated/kotlin/org/nativescript/kit/ui_styling_style_index.kt +19 -0
  83. package/kit-android/generated/kotlin/org/nativescript/kit/ui_styling_style_properties.kt +5 -2
  84. package/kit-android/generated/kotlin/org/nativescript/kit/ui_styling_style_scope.kt +232 -174
  85. package/kit-android/generated/kotlin/org/nativescript/kit/ui_text_view_text_view_common.kt +1 -1
  86. package/kit-android/generated/kotlin/org/nativescript/kit/utils_android_runtime_version.kt +75 -0
  87. package/kit-android/generated/manifest.json +21 -18
  88. package/kit-android/generated/source-lines.json +1 -1
  89. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Array.kt +497 -42
  90. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Intl.kt +1 -1
  91. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/JSON.kt +22 -2
  92. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Strings.kt +32 -18
  93. package/kit-apple/Overlays/xml-free/Core/ui.builder.index.swift +1 -1
  94. package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity1.swift +14 -10
  95. package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity2.swift +3 -9
  96. package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity3Plus.swift +20 -21
  97. package/kit-apple/Sources/NativeScriptKit/Core/Object_eventName_object_index_section_view_ios_android.swift +5 -7
  98. package/kit-apple/Sources/NativeScriptKit/Core/Object_eventName_object_ios_android_.swift +130 -0
  99. package/kit-apple/Sources/NativeScriptKit/Core/Object_eventName_object_oldIndex_newIndex.swift +2 -4
  100. package/kit-apple/Sources/NativeScriptKit/Core/Object_specified_substituted_reads.swift +115 -0
  101. package/kit-apple/Sources/NativeScriptKit/Core/Object_substituted_values_reads.swift +113 -0
  102. package/kit-apple/Sources/NativeScriptKit/Core/Object_substituted_values_reads_.swift +113 -0
  103. package/kit-apple/Sources/NativeScriptKit/Core/application.application-common.swift +348 -330
  104. package/kit-apple/Sources/NativeScriptKit/Core/application.application.ios.swift +358 -359
  105. package/kit-apple/Sources/NativeScriptKit/Core/application.helpers-common.swift +47 -29
  106. package/kit-apple/Sources/NativeScriptKit/Core/connectivity.index.ios.swift +3 -1
  107. package/kit-apple/Sources/NativeScriptKit/Core/css-mediaquery.index.swift +95 -53
  108. package/kit-apple/Sources/NativeScriptKit/Core/css.CSS3Parser.swift +1 -1
  109. package/kit-apple/Sources/NativeScriptKit/Core/css.parser.swift +1 -1
  110. package/kit-apple/Sources/NativeScriptKit/Core/data.observable-array.index.swift +2 -2
  111. package/kit-apple/Sources/NativeScriptKit/Core/file-system.file-system-access.ios.swift +52 -43
  112. package/kit-apple/Sources/NativeScriptKit/Core/http.http-request-internal.http-request-internal-common.swift +18 -0
  113. package/kit-apple/Sources/NativeScriptKit/Core/http.http-request-internal.index.ios.swift +66 -51
  114. package/kit-apple/Sources/NativeScriptKit/Core/image-source.index.ios.swift +67 -51
  115. package/kit-apple/Sources/NativeScriptKit/Core/kit-index.json +143 -32
  116. package/kit-apple/Sources/NativeScriptKit/Core/manifest.json +30 -19
  117. package/kit-apple/Sources/NativeScriptKit/Core/media-query-list.index.swift +190 -78
  118. package/kit-apple/Sources/NativeScriptKit/Core/native-window.native-window.ios.swift +1 -1
  119. package/kit-apple/Sources/NativeScriptKit/Core/npm.css-what.src.parse.swift +205 -201
  120. package/kit-apple/Sources/NativeScriptKit/Core/npm.css-what.src.stringify.swift +41 -42
  121. package/kit-apple/Sources/NativeScriptKit/Core/npm.css-what.src.types.swift +1 -1
  122. package/kit-apple/Sources/NativeScriptKit/Core/trace.index.swift +2 -2
  123. package/kit-apple/Sources/NativeScriptKit/Core/ui.animation.index.ios.swift +77 -65
  124. package/kit-apple/Sources/NativeScriptKit/Core/ui.builder.index.swift +4 -4
  125. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.properties.index.swift +1272 -824
  126. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view-base.index.swift +2 -2
  127. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view.index.ios.swift +8 -8
  128. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view.view-common.swift +1 -1
  129. package/kit-apple/Sources/NativeScriptKit/Core/ui.frame.frame-common.swift +2 -1
  130. package/kit-apple/Sources/NativeScriptKit/Core/ui.frame.index.ios.swift +6 -6
  131. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.flexbox-layout.index.ios.swift +22 -21
  132. package/kit-apple/Sources/NativeScriptKit/Core/ui.page.index.ios.swift +202 -188
  133. package/kit-apple/Sources/NativeScriptKit/Core/ui.repeater.index.swift +2 -6
  134. package/kit-apple/Sources/NativeScriptKit/Core/ui.split-view.index.ios.swift +3 -3
  135. package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.background.ios.swift +2 -2
  136. package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.clip-path-function.swift +1 -1
  137. package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.css-animation-parser.swift +1 -1
  138. package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.css-selector.swift +2 -2
  139. package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.font-common.swift +2 -2
  140. package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.style-scope.swift +869 -838
  141. package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.style.index.swift +46 -31
  142. package/kit-apple/Sources/NativeScriptKit/Core/ui.text-base.formatted-string.swift +1 -2
  143. package/kit-apple/Sources/NativeScriptKit/Core/ui.text-view.text-view-common.swift +1 -1
  144. package/kit-apple/Sources/NativeScriptKit/Core/ui.transition.index.ios.swift +2 -2
  145. package/kit-apple/Sources/NativeScriptKit/Core/ui.transition.modal-transition.ios.swift +4 -4
  146. package/kit-apple/Sources/NativeScriptKit/Core/ui.transition.page-transition.ios.swift +2 -2
  147. package/kit-apple/Sources/NativeScriptKit/Core/ui.transition.shared-transition-helper.ios.swift +17 -17
  148. package/kit-apple/Sources/NativeScriptKit/Core/utils.android-runtime-version.swift +77 -0
  149. package/kit-apple/Sources/NativeScriptKit/Core/utils.debug-source.swift +2 -2
  150. package/kit-apple/Sources/NativeScriptKit/Core/xhr.index.swift +62 -61
  151. package/kit-apple/Sources/NativeScriptKit/Runtime/Array.swift +4 -0
  152. package/kit-apple/Sources/NativeScriptKit/Runtime/Dynamic.swift +2 -0
  153. package/kit-apple/Sources/NativeScriptKit/Runtime/Interop.swift +1 -1
  154. package/kit-apple/Sources/NativeScriptKit/Runtime/Intl.swift +1 -1
  155. package/kit-apple/Sources/NativeScriptKit/Runtime/Iterators.swift +1 -1
  156. package/kit-apple/Sources/NativeScriptKit/Runtime/JSON.swift +280 -9
  157. package/kit-apple/Sources/NativeScriptKit/Runtime/Lowering.swift +3 -2
  158. package/kit-apple/Sources/NativeScriptKit/Runtime/Prototypes.swift +1 -0
  159. package/kit-apple/Sources/NativeScriptKit/Runtime/Symbol.swift +1 -0
  160. package/kit-apple/Sources/NativeScriptKit/Runtime/Values.swift +1 -0
  161. package/kit-apple/Sources/NativeScriptKit/Runtime/Views.swift +2 -0
  162. package/package.json +2 -2
@@ -440,10 +440,17 @@ public protocol JSToJSONConvertible: AnyObject {
440
440
  func jsToJSON(_ key: String) throws -> Any?
441
441
  }
442
442
 
443
+ /// Generated typed object shapes implement this to write directly into `JSUTF8Buffer` on the fast path
444
+ /// (no replacer, no indent, no `jsOrder`/`jsExtra`/`jsNulls`/`jsUnset`, depth < 64), bypassing `jsKeys` and `subscript[jsKey:]`.
445
+ public protocol JSJSONFastSerializable: AnyObject {
446
+ var jsCanFastJSON: Bool { get }
447
+ func jsWriteJSONFast(to out: JSUTF8Buffer, writeField: (StaticString, String, Any?) throws -> Void) throws -> Bool
448
+ }
449
+
443
450
  /// What JSON.stringify does with an instance of a class, found once per class: casts to the runtime's
444
451
  /// protocols look up conformances, and a value cast to one only to fail costs as much as one that succeeds.
445
452
  private enum JSJSONClassKind {
446
- case null, plainObject, numbers, strings, values, array, match, matchIndices, toJSON, date, function, other
453
+ case null, plainObject, fastObject, numbers, strings, values, array, match, matchIndices, toJSON, date, function, other
447
454
  /// A dynamic object whose `toJSON` is looked up; an error's is not.
448
455
  case dynamic, error
449
456
  }
@@ -501,14 +508,224 @@ private struct JSJSONWriter {
501
508
 
502
509
  var text: String { output.string }
503
510
 
504
- /// `value`, the root property `""` of `holder`, serialized iteratively.
511
+ /// `value`, the property `key` of `holder`, after its `toJSON` and the replacer; false, writing nothing, when
512
+ /// it serializes to undefined. Uses direct recursion below depth 64 for speed, spilling to `frames` past that
513
+ /// so arbitrarily deep structures (e.g. 5000+ nested arrays) never overflow the call stack.
505
514
  mutating func property(_ holder: AnyObject?, _ key: @autoclosure () -> String, _ value: Any?) throws -> Bool {
506
- guard let resolved = try resolve(holder, key(), value) else { return false }
507
- guard try emitOrPush(resolved) else { return false }
508
- try drain()
515
+ if depth >= 64 {
516
+ guard let resolved = try resolve(holder, key(), value) else { return false }
517
+ guard try emitOrPush(resolved) else { return false }
518
+ try drain()
519
+ return true
520
+ }
521
+ var v = jsFlat(value)
522
+ if let value = v, jsIsClassInstance(value) {
523
+ let object = jsObjectReference(value)
524
+ let kind = kind(of: object)
525
+ switch kind {
526
+ case .plainObject:
527
+ let plain = unsafeDowncast(object, to: JSObject.self)
528
+ if let f = jsFlat(plain["toJSON"]), jsIsFunction(f) {
529
+ v = try jsInvoke(f, plain, [key()])
530
+ } else if replacer == nil {
531
+ try membersDirect(plain, plain.keys) { plain[$0] }
532
+ return true
533
+ }
534
+ case .fastObject:
535
+ let fast = object as! JSJSONFastSerializable
536
+ if fast.jsCanFastJSON {
537
+ if replacer == nil && allowed == nil && gap.isEmpty {
538
+ if try writeFastDirect(fast) { return true }
539
+ }
540
+ if replacer == nil {
541
+ let dynamic = object as! JSDynamic
542
+ try membersDirect(dynamic, dynamic.jsKeys) { dynamic[jsKey: $0] }
543
+ return true
544
+ }
545
+ } else {
546
+ let dynamic = object as! JSDynamic
547
+ if let f = jsFlat(dynamic[jsKey: "toJSON"]), jsIsFunction(f) {
548
+ v = try jsInvoke(f, dynamic, [key()])
549
+ } else if replacer == nil {
550
+ try membersDirect(dynamic, dynamic.jsKeys) { dynamic[jsKey: $0] }
551
+ return true
552
+ }
553
+ }
554
+ case .dynamic:
555
+ let dynamic = object as! JSDynamic
556
+ if let f = jsFlat(dynamic[jsKey: "toJSON"]), jsIsFunction(f) {
557
+ v = try jsInvoke(f, dynamic, [key()])
558
+ } else if replacer == nil {
559
+ try membersDirect(dynamic, dynamic.jsKeys) { dynamic[jsKey: $0] }
560
+ return true
561
+ }
562
+ case .toJSON: v = try (object as! JSToJSONConvertible).jsToJSON(key())
563
+ case .date: v = unsafeDowncast(object, to: JSDate.self).toJSON() ?? jsNull
564
+ default: if replacer == nil { return try writeDirect(object: object, kind) }
565
+ }
566
+ }
567
+ if let replacer { v = try jsFlat(jsInvoke(replacer, holder, [key(), v])) }
568
+ guard let v else { return false }
569
+ return try writeDirect(v)
570
+ }
571
+
572
+ private mutating func writeDirect(_ value: Any) throws -> Bool {
573
+ if jsIsClassInstance(value) {
574
+ let object = jsObjectReference(value)
575
+ return try writeDirect(object: object, kind(of: object))
576
+ }
577
+ let output = self.output
578
+ func scalar<T>(_ value: T) -> Bool {
579
+ if T.self == String.self { output.appendJSONString(unsafeBitCast(value, to: String.self)) }
580
+ else if T.self == Double.self { output.appendJSONNumber(unsafeBitCast(value, to: Double.self)) }
581
+ else if T.self == Bool.self { output.append(unsafeBitCast(value, to: Bool.self) ? "true" : "false") }
582
+ else { return false }
583
+ return true
584
+ }
585
+ if _openExistential(value, do: scalar) { return true }
586
+ if value is JSBigInt { throw JSException(JSTypeError("Do not know how to serialize a BigInt")) }
587
+ if let n = jsNumeric(value) {
588
+ output.appendJSONNumber(n)
589
+ } else if jsIsFunction(value) {
590
+ return false
591
+ } else if jsIsTuple(value) {
592
+ let list = Mirror(reflecting: value).children.map { jsFlat($0.value) }
593
+ try elementsDirect(nil, list.count) { list[$0] }
594
+ } else {
595
+ return try writeBridgedDirect(value)
596
+ }
509
597
  return true
510
598
  }
511
599
 
600
+ private mutating func writeDirect(object: AnyObject, _ kind: JSJSONClassKind) throws -> Bool {
601
+ switch kind {
602
+ case .null:
603
+ output.append("null")
604
+ case .plainObject:
605
+ let plain = unsafeDowncast(object, to: JSObject.self)
606
+ try membersDirect(plain, plain.keys) { plain[$0] }
607
+ case .fastObject:
608
+ if replacer == nil && allowed == nil && gap.isEmpty {
609
+ let fast = object as! JSJSONFastSerializable
610
+ if try writeFastDirect(fast) { break }
611
+ }
612
+ let dynamic = object as! JSDynamic
613
+ try membersDirect(dynamic, dynamic.jsKeys) { dynamic[jsKey: $0] }
614
+ case .dynamic, .error:
615
+ let dynamic = object as! JSDynamic
616
+ try membersDirect(dynamic, dynamic.jsKeys) { dynamic[jsKey: $0] }
617
+ case .numbers:
618
+ let array = unsafeDowncast(object, to: JSArray<Double>.self)
619
+ array.track()
620
+ if replacer == nil && gap.isEmpty && array.shared == nil && jsSideProperties(array, create: false) == nil {
621
+ output.appendJSONNumbers(array)
622
+ } else {
623
+ try elementsDirect(array, array.storage.count) {
624
+ let d = array.storage[$0]
625
+ return d.isNaN ? JSArray<Double>.untyped(d) : d
626
+ }
627
+ }
628
+ case .strings:
629
+ let array = unsafeDowncast(object, to: JSArray<String>.self)
630
+ array.track()
631
+ if replacer == nil && gap.isEmpty && array.shared == nil && jsSideProperties(array, create: false) == nil {
632
+ output.appendJSONStrings(array)
633
+ } else {
634
+ try elementsDirect(array, array.storage.count) { jsIsHoleString(array.storage[$0]) ? nil : array.storage[$0] }
635
+ }
636
+ case .values where unsafeDowncast(object, to: JSArray<Any?>.self).jsTracker == nil && unsafeDowncast(object, to: JSArray<Any?>.self).shared == nil:
637
+ let array = unsafeDowncast(object, to: JSArray<Any?>.self)
638
+ try elementsDirect(array, array.storage.count) { array.storage[$0] }
639
+ case .match:
640
+ let values = unsafeDowncast(object, to: JSMatch.self).values
641
+ try elementsDirect(values, values.storage.count) { values.storage[$0] }
642
+ case .matchIndices:
643
+ let values = unsafeDowncast(object, to: JSMatchIndices.self).values
644
+ try elementsDirect(values, values.storage.count) { values.storage[$0] }
645
+ case .values, .array:
646
+ let array = object as! JSArrayProtocol
647
+ let values = array.jsAnyElements
648
+ try elementsDirect(array, values.count) { values[$0] }
649
+ case .date:
650
+ guard let iso = unsafeDowncast(object, to: JSDate.self).toJSON() else { output.append("null"); break }
651
+ output.appendJSONString(iso)
652
+ case .function:
653
+ return false
654
+ case .toJSON, .other:
655
+ return try writeBridgedDirect(object)
656
+ }
657
+ return true
658
+ }
659
+
660
+ private mutating func writeBridgedDirect(_ value: Any) throws -> Bool {
661
+ switch value {
662
+ case let s as String: output.appendJSONString(s)
663
+ case let b as Bool: output.append(b ? "true" : "false")
664
+ case let n where jsNumeric(n) != nil: output.appendJSONNumber(jsNumeric(n)!)
665
+ case let array as JSArrayProtocol:
666
+ let values = array.jsAnyElements
667
+ try elementsDirect(array, values.count) { values[$0] }
668
+ case let dynamic as JSDynamic:
669
+ try membersDirect(dynamic, dynamic.jsKeys) { dynamic[jsKey: $0] }
670
+ default: output.append("{}")
671
+ }
672
+ return true
673
+ }
674
+
675
+ private mutating func elementsDirect(_ object: AnyObject?, _ count: Int, _ element: (Int) -> Any?) throws {
676
+ try enter(object)
677
+ defer { leave(object) }
678
+ guard count > 0 else { return output.append("[]") }
679
+ output.append(0x5B)
680
+ depth += 1
681
+ for i in 0..<count {
682
+ if i > 0 { output.append(0x2C) }
683
+ newline()
684
+ if try !property(object, String(i), element(i)) { output.append("null") }
685
+ }
686
+ depth -= 1
687
+ newline()
688
+ output.append(0x5D)
689
+ }
690
+
691
+ private mutating func writeFastDirect(_ fast: JSJSONFastSerializable) throws -> Bool {
692
+ try enter(fast)
693
+ defer { leave(fast) }
694
+ depth += 1
695
+ defer { depth -= 1 }
696
+ let mark = output.count
697
+ if try fast.jsWriteJSONFast(to: output, writeField: { prefix, key, value in
698
+ let fieldMark = self.output.count
699
+ self.output.append(prefix)
700
+ if try !self.property(fast, key, value) { self.output.truncate(to: fieldMark) }
701
+ }) {
702
+ return true
703
+ }
704
+ output.truncate(to: mark)
705
+ return false
706
+ }
707
+
708
+ private mutating func membersDirect(_ object: AnyObject, _ keys: [String], _ member: (String) -> Any?) throws {
709
+ try enter(object)
710
+ defer { leave(object) }
711
+ output.append(0x7B)
712
+ depth += 1
713
+ var empty = true
714
+ for key in allowed ?? keys {
715
+ if allowed != nil, !keys.contains(key) { continue }
716
+ let start = output.count
717
+ if !empty { output.append(0x2C) }
718
+ newline()
719
+ output.appendJSONString(key)
720
+ output.append(0x3A)
721
+ if !gap.isEmpty { output.append(0x20) }
722
+ if try property(object, key, member(key)) { empty = false } else { output.truncate(to: start) }
723
+ }
724
+ depth -= 1
725
+ if !empty { newline() }
726
+ output.append(0x7D)
727
+ }
728
+
512
729
  /// Runs `toJSON` and `replacer`, returning `nil` if the property is omitted (undefined or function).
513
730
  private mutating func resolve(_ holder: AnyObject?, _ key: @autoclosure () -> String, _ value: Any?) throws -> Any? {
514
731
  var v = jsFlat(value)
@@ -518,6 +735,12 @@ private struct JSJSONWriter {
518
735
  case .plainObject:
519
736
  let plain = unsafeDowncast(object, to: JSObject.self)
520
737
  if let f = jsFlat(plain["toJSON"]), jsIsFunction(f) { v = try jsInvoke(f, plain, [key()]) }
738
+ case .fastObject:
739
+ let fast = object as! JSJSONFastSerializable
740
+ if !fast.jsCanFastJSON {
741
+ let dynamic = object as! JSDynamic
742
+ if let f = jsFlat(dynamic[jsKey: "toJSON"]), jsIsFunction(f) { v = try jsInvoke(f, dynamic, [key()]) }
743
+ }
521
744
  case .dynamic:
522
745
  let dynamic = object as! JSDynamic
523
746
  if let f = jsFlat(dynamic[jsKey: "toJSON"]), jsIsFunction(f) { v = try jsInvoke(f, dynamic, [key()]) }
@@ -606,6 +829,7 @@ private struct JSJSONWriter {
606
829
  case is JSDate: .date
607
830
  case let f where jsIsFunction(f): .function
608
831
  case is JSError: .error
832
+ case is JSJSONFastSerializable: .fastObject
609
833
  case is JSDynamic: .dynamic
610
834
  default: .other
611
835
  }
@@ -651,7 +875,7 @@ private struct JSJSONWriter {
651
875
  case .plainObject:
652
876
  let plain = unsafeDowncast(object, to: JSObject.self)
653
877
  try pushObject(plain, .plain(plain), plain.keys)
654
- case .dynamic, .error:
878
+ case .dynamic, .fastObject, .error:
655
879
  let dynamic = object as! JSDynamic
656
880
  try pushObject(dynamic, .dynamic(dynamic), dynamic.jsKeys)
657
881
  case .numbers:
@@ -832,7 +1056,7 @@ func jsJSONQuote(_ s: String) -> String {
832
1056
  return output.string
833
1057
  }
834
1058
 
835
- extension JSUTF8Buffer {
1059
+ public extension JSUTF8Buffer {
836
1060
  /// Number::toString. Integers below 2^53 are written digit by digit, and a number with at most three decimals
837
1061
  /// is found as the integer of its hundredths (say) whose quotient is the same double: what parsing those digits
838
1062
  /// would give, so that they are its shortest round-trip form. Other fractions take Swift's shortest digits,
@@ -867,14 +1091,61 @@ extension JSUTF8Buffer {
867
1091
  }
868
1092
  append(0x22)
869
1093
  }
1094
+
1095
+ @inline(__always) func appendJSONBool(_ b: Bool) {
1096
+ append(b ? "true" : "false")
1097
+ }
1098
+
1099
+ @inline(__always) func appendJSONLiteral(_ text: StaticString) {
1100
+ append(text)
1101
+ }
1102
+
1103
+ func appendJSONNumbers(_ array: JSArray<Double>) {
1104
+ array.track()
1105
+ let items = array.held
1106
+ guard !items.isEmpty else { return append("[]") }
1107
+ append(0x5B)
1108
+ for i in 0..<items.count {
1109
+ if i > 0 { append(0x2C) }
1110
+ let d = items[i]
1111
+ if d.isFinite { appendJSONNumber(d) } else { append("null") }
1112
+ }
1113
+ append(0x5D)
1114
+ }
1115
+
1116
+ func appendJSONStrings(_ array: JSArray<String>) {
1117
+ array.track()
1118
+ let items = array.held
1119
+ guard !items.isEmpty else { return append("[]") }
1120
+ append(0x5B)
1121
+ for i in 0..<items.count {
1122
+ if i > 0 { append(0x2C) }
1123
+ let s = items[i]
1124
+ if jsIsHoleString(s) { append("null") } else { appendJSONString(s) }
1125
+ }
1126
+ append(0x5D)
1127
+ }
1128
+ func appendJSONNumbersIfPlain(_ prefix: StaticString, _ array: JSArray<Double>?) -> Bool {
1129
+ guard let array, array.shared == nil, jsSideProperties(array, create: false) == nil else { return false }
1130
+ append(prefix)
1131
+ appendJSONNumbers(array)
1132
+ return true
1133
+ }
1134
+
1135
+ func appendJSONStringsIfPlain(_ prefix: StaticString, _ array: JSArray<String>?) -> Bool {
1136
+ guard let array, array.shared == nil, jsSideProperties(array, create: false) == nil else { return false }
1137
+ append(prefix)
1138
+ appendJSONStrings(array)
1139
+ return true
1140
+ }
870
1141
  }
871
1142
 
872
1143
  /// UTF-8 text written a byte or a run at a time, into storage that doubles as it fills: an array would check
873
1144
  /// that its storage is unshared on every append.
874
- private nonisolated final class JSUTF8Buffer {
1145
+ public nonisolated final class JSUTF8Buffer {
875
1146
  private var base: UnsafeMutablePointer<UInt8>
876
1147
  private var capacity: Int
877
- private(set) var count = 0
1148
+ public private(set) var count = 0
878
1149
 
879
1150
  init(capacity: Int = 256) {
880
1151
  self.capacity = capacity
@@ -11,11 +11,11 @@ public final class JSAsyncLoop {
11
11
  nonisolated deinit {}
12
12
  private var running = false
13
13
  private var pending = false
14
- private var iteration: ((@escaping () -> Void) -> Void)?
14
+ private var iteration: ((@escaping @MainActor () -> Void) -> Void)?
15
15
 
16
16
  public init() {}
17
17
 
18
- public func run(_ body: @escaping (@escaping () -> Void) -> Void) {
18
+ public func run(_ body: @escaping (@escaping @MainActor () -> Void) -> Void) {
19
19
  iteration = body
20
20
  step()
21
21
  }
@@ -39,6 +39,7 @@ public func jsReport(_ body: () throws -> Void) {
39
39
 
40
40
  /// Without NativeScript's `Application` (a plain program, the differential tests), an uncaught error goes to
41
41
  /// `globalThis.__onUncaughtError` when script sets one, where core's handler is; else to standard error.
42
+ @MainActor
42
43
  public var jsUncaughtHandler: (Any?) -> Void = { value in
43
44
  if !jsReportedToScript(value) { jsError("Uncaught", value) }
44
45
  }
@@ -380,6 +380,7 @@ public func jsDecorate(_ cls: AnyClass, _ decorators: [Any?]) throws {
380
380
  /// An instance of a class generated from core: the properties script gives it beyond the
381
381
  /// fields it declares (`this[key] = v`, symbol-keyed ones included), its methods named by
382
382
  /// symbols (`[prop.setNative](value)`), and what its class's prototype defines.
383
+ @MainActor
383
384
  public protocol JSExpando: JSDynamic, JSSymbolKeyed, JSDeletable {
384
385
  var jsExpando: JSObject? { get set }
385
386
  /// The method a class declares under the symbol whose key this is; the method takes its receiver as `this`.
@@ -89,6 +89,7 @@ public func jsPropertyKey(_ value: Any?) -> String {
89
89
  public func jsIsSymbolKey(_ key: String) -> Bool { key.utf8.first == 0 }
90
90
 
91
91
  /// An object with symbol-keyed properties, which print after its other keys.
92
+ @MainActor
92
93
  public protocol JSSymbolKeyed: AnyObject {
93
94
  var jsSymbolKeys: [String] { get }
94
95
  }
@@ -23,6 +23,7 @@ public typealias JSFunction = ([Any?]) throws -> Any?
23
23
  /// An object whose properties dynamic code reaches by name (`o[key]`, JSON, `console.log`):
24
24
  /// plain objects (`JSObject`) and the classes generated for TypeScript classes and interfaces.
25
25
  /// A nil `jsClassName` prints as a plain object (`{ a: 1 }`), otherwise as `Name { a: 1 }`.
26
+ @MainActor
26
27
  public protocol JSDynamic: AnyObject {
27
28
  subscript(jsKey key: String) -> Any? { get set }
28
29
  var jsKeys: [String] { get }
@@ -1,4 +1,5 @@
1
1
  /// A native object that is another in every JavaScript sense: `===`, Map and Set keys, WeakMap keys see that one.
2
+ @MainActor
2
3
  public protocol JSStandIn: AnyObject {
3
4
  /// The object this one is, or nil where it is itself.
4
5
  var jsStandingFor: AnyObject? { get }
@@ -6,6 +7,7 @@ public protocol JSStandIn: AnyObject {
6
7
 
7
8
  /// An object of one shape's class standing for an object of another class (`T.jsView`): it keeps no fields of its
8
9
  /// own and reads and writes its root's keys, so it is the root in every JavaScript sense.
10
+ @MainActor
9
11
  public protocol JSViewing: JSDynamic, JSStandIn {
10
12
  var jsViewRoot: JSDynamic? { get }
11
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nstudio/nativescript-compiler",
3
- "version": "9.2.0-alpha.17",
3
+ "version": "9.2.0-alpha.18",
4
4
  "description": "NativeScript CLI plugin (`ns compile`) and compiler turning a NativeScript app into native Swift (iOS) or Kotlin (Android) with no JavaScript runtime; framework adapters (`@nstudio/nativescript-compiler-<framework>`) compile each framework.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -70,7 +70,7 @@
70
70
  "typescript": "~5.9.0"
71
71
  },
72
72
  "peerDependencies": {
73
- "@nativescript/core": "9.1.5-next.7",
73
+ "@nativescript/core": "9.2.0-next.2",
74
74
  "nativescript": ">=9.1.0"
75
75
  },
76
76
  "peerDependenciesMeta": {