@lynx-js/react 0.128.0 → 0.129.0

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 (174) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/components/tsconfig.tsbuildinfo +1 -1
  3. package/package.json +1 -1
  4. package/refresh/.turbo/turbo-build.log +1 -1
  5. package/runtime/__test__/core/entry-re-eval.test.ts +161 -0
  6. package/runtime/__test__/core/reload-scoped-dual-thread-communication.test.ts +129 -0
  7. package/runtime/__test__/core/thread-function-call.test.ts +1 -0
  8. package/runtime/__test__/element-template/fixtures/background/render/_shared.tsx +2 -0
  9. package/runtime/__test__/element-template/native/index.test.ts +8 -0
  10. package/runtime/__test__/element-template/native/main-thread-ref-init-value.test.ts +100 -0
  11. package/runtime/__test__/element-template/native/reload-dual-thread-communication.test.ts +101 -0
  12. package/runtime/__test__/element-template/native/reload.test.ts +50 -1
  13. package/runtime/__test__/element-template/runtime/background/commit-hook.test.ts +104 -47
  14. package/runtime/__test__/element-template/runtime/background/main-thread-function/compiled-fixtures.test.tsx +7 -1
  15. package/runtime/__test__/element-template/runtime/background/re-eval-reload.test.ts +69 -0
  16. package/runtime/__test__/element-template/runtime/hydration/hydration-listener.test.ts +31 -5
  17. package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +17 -3
  18. package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +2 -0
  19. package/runtime/__test__/element-template/runtime/template/main-thread-function.test.ts +89 -2
  20. package/runtime/__test__/element-template/test-utils/debug/compiledFixtureModule.ts +5 -0
  21. package/runtime/__test__/snapshot/lifecycle/re-eval-reload.test.jsx +114 -0
  22. package/runtime/__test__/snapshot/lifecycle/reload-background-function.test.jsx +169 -0
  23. package/runtime/__test__/snapshot/lifecycle/reload-delayed-background.test.jsx +63 -0
  24. package/runtime/__test__/snapshot/lifecycle/reload-delayed-main-thread.test.jsx +103 -0
  25. package/runtime/__test__/snapshot/lifecycle.test.jsx +61 -1
  26. package/runtime/__test__/snapshot/lynx/lazy-effect-scheduling.test.jsx +105 -0
  27. package/runtime/__test__/snapshot/ssr.test.jsx +2 -2
  28. package/runtime/__test__/snapshot/worklet/runOnBackground.test.js +6 -11
  29. package/runtime/__test__/snapshot/worklet/runOnMainThread.test.jsx +1 -1
  30. package/runtime/__test__/snapshot/worklet/workletRef.test.jsx +24 -1
  31. package/runtime/__test__/worklet-runtime/jsFunctionLifecycle.test.js +15 -1
  32. package/runtime/__test__/worklet-runtime/mainThreadObject.test.js +46 -0
  33. package/runtime/__test__/worklet-runtime/runOnMainThread.test.js +3 -3
  34. package/runtime/lib/core/background-function/exec-map.d.ts +2 -0
  35. package/runtime/lib/core/background-function/exec-map.js +7 -0
  36. package/runtime/lib/core/background-function/exec-map.js.map +1 -1
  37. package/runtime/lib/core/background-function/run-on-background.js +15 -16
  38. package/runtime/lib/core/background-function/run-on-background.js.map +1 -1
  39. package/runtime/lib/core/card-lifetime.d.ts +5 -0
  40. package/runtime/lib/core/card-lifetime.js +17 -0
  41. package/runtime/lib/core/card-lifetime.js.map +1 -0
  42. package/runtime/lib/core/entry-reload.d.ts +7 -0
  43. package/runtime/lib/core/entry-reload.js +49 -0
  44. package/runtime/lib/core/entry-reload.js.map +1 -0
  45. package/runtime/lib/core/lynx/lazy-bundle.js +4 -1
  46. package/runtime/lib/core/lynx/lazy-bundle.js.map +1 -1
  47. package/runtime/lib/core/main-thread-ref-id.js +4 -4
  48. package/runtime/lib/core/main-thread-ref-id.js.map +1 -1
  49. package/runtime/lib/core/reload-scoped-event.d.ts +5 -0
  50. package/runtime/lib/core/reload-scoped-event.js +26 -0
  51. package/runtime/lib/core/reload-scoped-event.js.map +1 -0
  52. package/runtime/lib/core/reload-version.js +4 -3
  53. package/runtime/lib/core/reload-version.js.map +1 -1
  54. package/runtime/lib/core/runtime-destroy.d.ts +2 -0
  55. package/runtime/lib/core/runtime-destroy.js +9 -0
  56. package/runtime/lib/core/runtime-destroy.js.map +1 -1
  57. package/runtime/lib/core/thread-function-call/main-thread.js +5 -4
  58. package/runtime/lib/core/thread-function-call/main-thread.js.map +1 -1
  59. package/runtime/lib/core/thread-function-call/return-value.js +6 -5
  60. package/runtime/lib/core/thread-function-call/return-value.js.map +1 -1
  61. package/runtime/lib/element-template/background/commit-hook.js +19 -16
  62. package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
  63. package/runtime/lib/element-template/background/hydration-listener.js +2 -6
  64. package/runtime/lib/element-template/background/hydration-listener.js.map +1 -1
  65. package/runtime/lib/element-template/main-thread-ref-init-value.d.ts +3 -0
  66. package/runtime/lib/element-template/main-thread-ref-init-value.js +38 -0
  67. package/runtime/lib/element-template/main-thread-ref-init-value.js.map +1 -0
  68. package/runtime/lib/element-template/native/index.js +2 -0
  69. package/runtime/lib/element-template/native/index.js.map +1 -1
  70. package/runtime/lib/element-template/native/mts-destroy.js +2 -0
  71. package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
  72. package/runtime/lib/element-template/native/patch-listener.js +1 -4
  73. package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
  74. package/runtime/lib/element-template/native/reload-background.d.ts +1 -1
  75. package/runtime/lib/element-template/native/reload-background.js +12 -1
  76. package/runtime/lib/element-template/native/reload-background.js.map +1 -1
  77. package/runtime/lib/element-template/native/reload-main-thread.d.ts +6 -0
  78. package/runtime/lib/element-template/native/reload-main-thread.js +18 -2
  79. package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
  80. package/runtime/lib/element-template/protocol/lifecycle-constant.d.ts +2 -1
  81. package/runtime/lib/element-template/protocol/lifecycle-constant.js +1 -0
  82. package/runtime/lib/element-template/protocol/lifecycle-constant.js.map +1 -1
  83. package/runtime/lib/element-template/protocol/types.d.ts +0 -2
  84. package/runtime/lib/element-template/protocol/types.js.map +1 -1
  85. package/runtime/lib/shared/index-map.d.ts +4 -1
  86. package/runtime/lib/shared/index-map.js +5 -2
  87. package/runtime/lib/shared/index-map.js.map +1 -1
  88. package/runtime/lib/snapshot/lifecycle/destroy.js +6 -0
  89. package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
  90. package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.d.ts +6 -2
  91. package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.js +21 -18
  92. package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.js.map +1 -1
  93. package/runtime/lib/snapshot/lifecycle/reload.d.ts +9 -2
  94. package/runtime/lib/snapshot/lifecycle/reload.js +29 -8
  95. package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
  96. package/runtime/lib/snapshot/list/list.js +3 -2
  97. package/runtime/lib/snapshot/list/list.js.map +1 -1
  98. package/runtime/lib/snapshot/lynx/calledByNative.js +3 -3
  99. package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
  100. package/runtime/lib/snapshot/snapshot/list.js +2 -1
  101. package/runtime/lib/snapshot/snapshot/list.js.map +1 -1
  102. package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.d.ts +4 -2
  103. package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.js +11 -11
  104. package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.js.map +1 -1
  105. package/runtime/lib/snapshot/worklet/call/runOnMainThread.d.ts +1 -0
  106. package/runtime/lib/snapshot/worklet/call/runOnMainThread.js +6 -1
  107. package/runtime/lib/snapshot/worklet/call/runOnMainThread.js.map +1 -1
  108. package/runtime/lib/snapshot/worklet/ctx.d.ts +1 -1
  109. package/runtime/lib/snapshot/worklet/ctx.js +6 -1
  110. package/runtime/lib/snapshot/worklet/ctx.js.map +1 -1
  111. package/runtime/lib/snapshot/worklet/ref/updateInitValue.js +6 -0
  112. package/runtime/lib/snapshot/worklet/ref/updateInitValue.js.map +1 -1
  113. package/runtime/lib/tsconfig.tsbuildinfo +1 -1
  114. package/runtime/lib/worklet-runtime/delayRunOnBackground.js +3 -1
  115. package/runtime/lib/worklet-runtime/delayRunOnBackground.js.map +1 -1
  116. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js +2 -1
  117. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +1 -1
  118. package/runtime/lib/worklet-runtime/listeners.js +2 -2
  119. package/runtime/lib/worklet-runtime/listeners.js.map +1 -1
  120. package/runtime/lib/worklet-runtime/mainThreadObject.js +3 -1
  121. package/runtime/lib/worklet-runtime/mainThreadObject.js.map +1 -1
  122. package/runtime/lib/worklet-runtime/runOnMainThread.js +4 -3
  123. package/runtime/lib/worklet-runtime/runOnMainThread.js.map +1 -1
  124. package/runtime/src/core/background-function/exec-map.ts +9 -0
  125. package/runtime/src/core/background-function/run-on-background.ts +14 -16
  126. package/runtime/src/core/card-lifetime.ts +18 -0
  127. package/runtime/src/core/entry-reload.ts +63 -0
  128. package/runtime/src/core/lynx/lazy-bundle.ts +4 -1
  129. package/runtime/src/core/main-thread-ref-id.ts +5 -4
  130. package/runtime/src/core/reload-scoped-event.ts +35 -0
  131. package/runtime/src/core/reload-version.ts +5 -3
  132. package/runtime/src/core/runtime-destroy.ts +11 -0
  133. package/runtime/src/core/thread-function-call/main-thread.ts +4 -4
  134. package/runtime/src/core/thread-function-call/return-value.ts +6 -5
  135. package/runtime/src/element-template/background/commit-hook.ts +20 -17
  136. package/runtime/src/element-template/background/hydration-listener.ts +2 -6
  137. package/runtime/src/element-template/main-thread-ref-init-value.ts +44 -0
  138. package/runtime/src/element-template/native/index.ts +2 -0
  139. package/runtime/src/element-template/native/mts-destroy.ts +3 -0
  140. package/runtime/src/element-template/native/patch-listener.ts +0 -5
  141. package/runtime/src/element-template/native/reload-background.ts +13 -1
  142. package/runtime/src/element-template/native/reload-main-thread.ts +30 -2
  143. package/runtime/src/element-template/protocol/lifecycle-constant.ts +1 -0
  144. package/runtime/src/element-template/protocol/types.ts +0 -2
  145. package/runtime/src/shared/index-map.ts +3 -2
  146. package/runtime/src/snapshot/lifecycle/destroy.ts +7 -0
  147. package/runtime/src/snapshot/lifecycle/event/firstScreenSync.ts +26 -19
  148. package/runtime/src/snapshot/lifecycle/reload.ts +47 -11
  149. package/runtime/src/snapshot/list/list.ts +9 -2
  150. package/runtime/src/snapshot/lynx/calledByNative.ts +3 -4
  151. package/runtime/src/snapshot/snapshot/list.ts +5 -1
  152. package/runtime/src/snapshot/snapshot/snapshotInstanceManager.ts +19 -12
  153. package/runtime/src/snapshot/worklet/call/runOnMainThread.ts +10 -1
  154. package/runtime/src/snapshot/worklet/ctx.ts +10 -1
  155. package/runtime/src/snapshot/worklet/ref/updateInitValue.ts +6 -0
  156. package/runtime/src/worklet-runtime/README.md +13 -0
  157. package/runtime/src/worklet-runtime/delayRunOnBackground.ts +3 -1
  158. package/runtime/src/worklet-runtime/jsFunctionLifecycle.ts +2 -1
  159. package/runtime/src/worklet-runtime/listeners.ts +4 -7
  160. package/runtime/src/worklet-runtime/mainThreadObject.ts +2 -1
  161. package/runtime/src/worklet-runtime/runOnMainThread.ts +4 -3
  162. package/runtime/types/types.d.ts +3 -1
  163. package/testing-library/.turbo/turbo-build.log +7 -7
  164. package/testing-library/src/__tests__/worklet.test.jsx +10 -5
  165. package/transform/.turbo/turbo-build$colon$wasm.log +339 -134
  166. package/transform/__test__/defines.spec.js +107 -0
  167. package/transform/crates/swc_plugin_worklet/definition_imports.rs +97 -0
  168. package/transform/crates/swc_plugin_worklet/lib.rs +7 -6
  169. package/transform/dist/wasm.cjs +1 -1
  170. package/transform/index.d.ts +3 -1
  171. package/transform/src/lib.rs +172 -11
  172. package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +57 -55
  173. package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
  174. package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +66 -274
@@ -2,6 +2,8 @@
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
4
 
5
+ import path from 'node:path';
6
+
5
7
  import { describe, expect, it } from 'vitest';
6
8
 
7
9
  import { transformReactLynx } from '../main.js';
@@ -273,6 +275,111 @@ function legacy(target, extra = {}) {
273
275
  });
274
276
  }
275
277
 
278
+ describe('worklet definition imports', () => {
279
+ const source = `
280
+ import { runOnBackground, useState } from '@lynx-js/react';
281
+ export function Repro() {
282
+ const [count, setCount] = useState(0);
283
+ const onTap = () => {
284
+ 'main thread';
285
+ runOnBackground(() => {
286
+ 'background only';
287
+ setCount(value => value + 1);
288
+ })();
289
+ };
290
+ return <view main-thread:bindtap={onTap}>{count}</view>;
291
+ }
292
+ `;
293
+
294
+ it.each(['test', 'development'])(
295
+ 'carries the runOnBackground import without unrelated component imports in %s mode',
296
+ async (mode) => {
297
+ const background = await transformReactLynx(source, options('JS', { mode }));
298
+ const mainThread = await transformReactLynx(source, options('LEPUS', { mode }));
299
+ expect(background.errors).toEqual([]);
300
+ expect(background.definesForWorklet).toEqual(mainThread.definesForWorklet);
301
+ const [definition] = background.definesForWorklet;
302
+ const dependency = definition.imports.find(item => item.imported === 'runOnBackground');
303
+ expect(dependency).toEqual({ source: '@lynx-js/react', imported: 'runOnBackground', local: dependency.local });
304
+ expect(definition.code).toContain(`${dependency.local}(_jsFn1)()`);
305
+ expect(definition.imports.some(item => item.imported === 'useState')).toBe(false);
306
+ },
307
+ );
308
+
309
+ it('resolves Windows relative imports in the Wasm transform', async () => {
310
+ const result = await transformReactLynx(
311
+ source.replace('\'@lynx-js/react\'', '\'./bridge.js\''),
312
+ options('JS', { filename: 'C:\\project\\src\\Repro.jsx' }),
313
+ );
314
+ expect(result.errors).toEqual([]);
315
+ expect(result.definesForWorklet[0].imports).toContainEqual(
316
+ expect.objectContaining({ source: 'C:/project/src/./bridge.js', imported: 'runOnBackground' }),
317
+ );
318
+ });
319
+
320
+ it('resolves relative imports from the owning module directory', async () => {
321
+ const filename = path.resolve('src/components/Repro.jsx');
322
+ const result = await transformReactLynx(
323
+ source.replace('\'@lynx-js/react\'', '\'./bridge.js\''),
324
+ options('JS', { filename }),
325
+ );
326
+ expect(result.errors).toEqual([]);
327
+ expect(result.definesForWorklet[0].imports).toContainEqual(expect.objectContaining({
328
+ source: `${path.dirname(filename)}/./bridge.js`.replaceAll('\\', '/'),
329
+ imported: 'runOnBackground',
330
+ }));
331
+ });
332
+
333
+ it('does not import bindings captured through the worklet context', async () => {
334
+ const result = await transformReactLynx(
335
+ `
336
+ import { value } from './values.js';
337
+ function worklet() { 'main thread'; return value; }
338
+ `,
339
+ options('JS'),
340
+ );
341
+ expect(result.errors).toEqual([]);
342
+ expect(result.definesForWorklet[0].imports).toHaveLength(1);
343
+ expect(result.definesForWorklet[0].code).toContain('this["_c"]');
344
+ });
345
+
346
+ it('preserves default, namespace and aliased imports and shorthand keys', async () => {
347
+ const opts = options('JS');
348
+ opts.worklet.customGlobalIdentNames = ['call', 'api', 'named'];
349
+ const result = await transformReactLynx(
350
+ `
351
+ import call, * as api from './bridge.js';
352
+ import { original as named } from './other.js';
353
+ function worklet() { 'main thread'; return [call(), api.value, { named }]; }
354
+ `,
355
+ opts,
356
+ );
357
+ expect(result.errors).toEqual([]);
358
+ const [definition] = result.definesForWorklet;
359
+ expect(definition.imports).toEqual(expect.arrayContaining([
360
+ { source: './bridge.js', imported: 'default', local: 'call' },
361
+ { source: './bridge.js', imported: '*', local: 'api', namespace: true },
362
+ { source: './other.js', imported: 'original', local: 'named' },
363
+ ]));
364
+ expect(definition.code).toContain('named');
365
+ });
366
+
367
+ it('does not carry an import shadowed by a worklet parameter', async () => {
368
+ const result = await transformReactLynx(
369
+ `
370
+ import { runOnBackground } from './bridge.js';
371
+ function worklet(runOnBackground) {
372
+ 'main thread';
373
+ runOnBackground(() => {})();
374
+ }
375
+ `,
376
+ options('JS'),
377
+ );
378
+ expect(result.errors).toEqual([]);
379
+ expect(result.definesForWorklet[0].imports).toHaveLength(1);
380
+ });
381
+ });
382
+
276
383
  describe('legacy slot codegen', () => {
277
384
  it('collects the definitions its frozen codegen emits', async () => {
278
385
  const { definesForSnapshot, definesForWorklet } = await transformReactLynx(
@@ -0,0 +1,97 @@
1
+ use rustc_hash::FxHashSet;
2
+ use swc_core::ecma::ast::*;
3
+ use swc_core::ecma::visit::{Visit, VisitWith};
4
+
5
+ #[derive(Default)]
6
+ struct References {
7
+ used: FxHashSet<Id>,
8
+ declared: FxHashSet<Id>,
9
+ }
10
+
11
+ impl Visit for References {
12
+ fn visit_ident(&mut self, ident: &Ident) {
13
+ self.used.insert(ident.to_id());
14
+ }
15
+
16
+ fn visit_binding_ident(&mut self, ident: &BindingIdent) {
17
+ self.declared.insert(ident.to_id());
18
+ }
19
+ }
20
+
21
+ pub fn collect_imports(stmt: &Stmt, imports: &[ImportDecl]) -> Vec<ModuleItem> {
22
+ let mut references = References::default();
23
+ stmt.visit_with(&mut references);
24
+ let mut items = vec![];
25
+ for import in imports {
26
+ if import.type_only {
27
+ continue;
28
+ }
29
+ let mut import = import.clone();
30
+ import.specifiers.retain(|specifier| {
31
+ if matches!(specifier, ImportSpecifier::Named(named) if named.is_type_only) {
32
+ return false;
33
+ }
34
+ let id = specifier.local().to_id();
35
+ references.used.contains(&id) && !references.declared.contains(&id)
36
+ });
37
+ if !import.specifiers.is_empty() {
38
+ items.push(ModuleItem::ModuleDecl(ModuleDecl::Import(import)));
39
+ }
40
+ }
41
+ items
42
+ }
43
+
44
+ #[cfg(test)]
45
+ mod tests {
46
+ use super::*;
47
+ use swc_core::common::DUMMY_SP;
48
+ use swc_core::quote;
49
+
50
+ #[test]
51
+ fn excludes_type_only_unused_and_locally_declared_bindings() {
52
+ let named = |name: &str, is_type_only| {
53
+ ImportSpecifier::Named(ImportNamedSpecifier {
54
+ span: DUMMY_SP,
55
+ local: Ident::new_no_ctxt(name.into(), DUMMY_SP),
56
+ imported: None,
57
+ is_type_only,
58
+ })
59
+ };
60
+ let import = ImportDecl {
61
+ span: DUMMY_SP,
62
+ phase: ImportPhase::Evaluation,
63
+ specifiers: vec![named("needed", false)],
64
+ src: Box::new("./values.js".into()),
65
+ type_only: false,
66
+ with: None,
67
+ };
68
+ let stmt = quote!("function handler(captured) { return [needed, captured]; }" as Stmt);
69
+ let collected = collect_imports(
70
+ &stmt,
71
+ &[
72
+ ImportDecl {
73
+ type_only: true,
74
+ ..import.clone()
75
+ },
76
+ ImportDecl {
77
+ specifiers: vec![named("needed", true)],
78
+ ..import.clone()
79
+ },
80
+ ImportDecl {
81
+ specifiers: vec![
82
+ named("needed", false),
83
+ named("captured", false),
84
+ named("unused", false),
85
+ ],
86
+ ..import
87
+ },
88
+ ],
89
+ );
90
+ assert_eq!(collected.len(), 1);
91
+ let ModuleItem::ModuleDecl(ModuleDecl::Import(import)) = &collected[0] else {
92
+ panic!("expected a dependency import");
93
+ };
94
+ assert_eq!(import.specifiers.len(), 1);
95
+ assert_eq!(import.specifiers[0].local().sym, "needed");
96
+ }
97
+ }
@@ -1,4 +1,5 @@
1
1
  mod decl_collect;
2
+ mod definition_imports;
2
3
  mod extract_ident;
3
4
  mod gen_stmt;
4
5
  mod globals;
@@ -71,6 +72,7 @@ pub struct WorkletVisitor {
71
72
  register_worklet: Ident,
72
73
  main_thread_programmability: Option<Rc<Cell<bool>>>,
73
74
  defines_collector: Option<DefinesCollector>,
75
+ imports: Vec<ImportDecl>,
74
76
  }
75
77
 
76
78
  impl Default for WorkletVisitor {
@@ -694,6 +696,7 @@ impl VisitMut for WorkletVisitor {
694
696
  // First process imports to detect shared-runtime modules.
695
697
  for item in &n.body {
696
698
  if let ModuleItem::ModuleDecl(ModuleDecl::Import(import_decl)) = item {
699
+ self.imports.push(import_decl.clone());
697
700
  if is_shared_runtime_import(import_decl) {
698
701
  for specifier in &import_decl.specifiers {
699
702
  match specifier {
@@ -957,6 +960,7 @@ impl WorkletVisitor {
957
960
  register_worklet: private_ident!("__registerWorklet"),
958
961
  main_thread_programmability: None,
959
962
  defines_collector: None,
963
+ imports: vec![],
960
964
  }
961
965
  }
962
966
 
@@ -1008,12 +1012,9 @@ impl WorkletVisitor {
1008
1012
  collect_unmergeable_define(&self.defines_collector, DefineKind::Worklet, hash);
1009
1013
  return;
1010
1014
  }
1011
- collect_define(
1012
- &self.defines_collector,
1013
- DefineKind::Worklet,
1014
- hash,
1015
- vec![self.registration_import(), ModuleItem::Stmt(stmt)],
1016
- );
1015
+ let mut items = definition_imports::collect_imports(&stmt, &self.imports);
1016
+ items.extend([self.registration_import(), ModuleItem::Stmt(stmt)]);
1017
+ collect_define(&self.defines_collector, DefineKind::Worklet, hash, items);
1017
1018
  }
1018
1019
 
1019
1020
  fn check_is_worklet_block(&self, n: &mut FunctionBody) -> Option<WorkletType> {