@lynx-js/react 0.126.2 → 0.127.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.
- package/CHANGELOG.md +18 -0
- package/components/tsconfig.tsbuildinfo +1 -1
- package/docs/directives.md +90 -0
- package/docs/global-events.md +50 -0
- package/docs/import-attributes.md +43 -0
- package/docs/macros.md +285 -0
- package/package.json +3 -2
- package/refresh/.turbo/turbo-build.log +1 -1
- package/refresh/dist/index.js +26 -6
- package/refresh/package.json +1 -1
- package/runtime/__test__/core/main-thread-object.test.js +149 -0
- package/runtime/__test__/element-template/fixtures/background/main-thread-function/run-on-main-thread/index.tsx +26 -3
- package/runtime/__test__/element-template/imports/main-thread-object-api.test.ts +10 -0
- package/runtime/__test__/element-template/internal/legacy-internal-guardrail.test.ts +3 -0
- package/runtime/__test__/element-template/runtime/background/main-thread-function/compiled-fixtures.test.tsx +4 -0
- package/runtime/__test__/snapshot/ctxNotFound.test.ts +271 -0
- package/runtime/__test__/snapshot/event.test.jsx +7 -7
- package/runtime/__test__/snapshot/lazy.test.js +73 -1
- package/runtime/__test__/snapshot/lynx/portals.test.jsx +75 -37
- package/runtime/__test__/snapshot/snapshotPatch.test.jsx +59 -47
- package/runtime/__test__/snapshot/spread.test.jsx +10 -10
- package/runtime/__test__/snapshot/worklet/main-thread-object.test.jsx +306 -0
- package/runtime/__test__/snapshot/worklet/workletRef.test.jsx +1 -0
- package/runtime/__test__/worklet-runtime/mainThreadObject.test.js +182 -0
- package/runtime/__test__/worklet-runtime/object-methods.test.js +60 -0
- package/runtime/__test__/worklet-runtime/workletRef.test.js +362 -2
- package/runtime/__test__/worklet-runtime/workletRuntime.test.js +246 -1
- package/runtime/lazy/compat.js +2 -0
- package/runtime/lazy/element-template-internal.js +1 -0
- package/runtime/lazy/element-template.js +2 -0
- package/runtime/lazy/internal.js +2 -0
- package/runtime/lazy/react.js +2 -0
- package/runtime/lib/core/background-function/run-on-background.d.ts +16 -0
- package/runtime/lib/core/background-function/run-on-background.js +16 -0
- package/runtime/lib/core/background-function/run-on-background.js.map +1 -1
- package/runtime/lib/core/capture-main-thread-object.d.ts +1 -0
- package/runtime/lib/core/capture-main-thread-object.js +16 -0
- package/runtime/lib/core/capture-main-thread-object.js.map +1 -0
- package/runtime/lib/core/globalProps.d.ts +2 -0
- package/runtime/lib/core/globalProps.js.map +1 -1
- package/runtime/lib/core/hooks/react.d.ts +4 -0
- package/runtime/lib/core/hooks/react.js +4 -0
- package/runtime/lib/core/hooks/react.js.map +1 -1
- package/runtime/lib/core/hooks/useLynxGlobalEventListener.d.ts +2 -0
- package/runtime/lib/core/hooks/useLynxGlobalEventListener.js +2 -0
- package/runtime/lib/core/hooks/useLynxGlobalEventListener.js.map +1 -1
- package/runtime/lib/core/initData.d.ts +2 -0
- package/runtime/lib/core/initData.js +2 -0
- package/runtime/lib/core/initData.js.map +1 -1
- package/runtime/lib/core/main-thread-object-handle-registry.d.ts +3 -0
- package/runtime/lib/core/main-thread-object-handle-registry.js +17 -0
- package/runtime/lib/core/main-thread-object-handle-registry.js.map +1 -0
- package/runtime/lib/core/main-thread-object.d.ts +77 -0
- package/runtime/lib/core/main-thread-object.js +261 -0
- package/runtime/lib/core/main-thread-object.js.map +1 -0
- package/runtime/lib/core/main-thread-ref-id.d.ts +1 -0
- package/runtime/lib/core/main-thread-ref-id.js +14 -0
- package/runtime/lib/core/main-thread-ref-id.js.map +1 -0
- package/runtime/lib/core/main-thread-ref-init-value.d.ts +1 -1
- package/runtime/lib/core/main-thread-ref-init-value.js +4 -2
- package/runtime/lib/core/main-thread-ref-init-value.js.map +1 -1
- package/runtime/lib/core/main-thread-ref.d.ts +4 -0
- package/runtime/lib/core/main-thread-ref.js +5 -8
- package/runtime/lib/core/main-thread-ref.js.map +1 -1
- package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
- package/runtime/lib/element-template/index.d.ts +2 -0
- package/runtime/lib/element-template/index.js +1 -0
- package/runtime/lib/element-template/index.js.map +1 -1
- package/runtime/lib/element-template/internal.d.ts +1 -0
- package/runtime/lib/element-template/internal.js +1 -0
- package/runtime/lib/element-template/internal.js.map +1 -1
- package/runtime/lib/element-template/protocol/types.d.ts +1 -1
- package/runtime/lib/internal.d.ts +1 -0
- package/runtime/lib/internal.js +1 -0
- package/runtime/lib/internal.js.map +1 -1
- package/runtime/lib/lynx-api.d.ts +34 -0
- package/runtime/lib/lynx-api.js +21 -0
- package/runtime/lib/lynx-api.js.map +1 -1
- package/runtime/lib/lynx.js +4 -1
- package/runtime/lib/lynx.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/error.d.ts +11 -1
- package/runtime/lib/snapshot/lifecycle/patch/error.js +24 -16
- package/runtime/lib/snapshot/lifecycle/patch/error.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.d.ts +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js +29 -7
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +2 -2
- package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
- package/runtime/lib/snapshot/lynx/children.d.ts +2 -0
- package/runtime/lib/snapshot/lynx/children.js.map +1 -1
- package/runtime/lib/snapshot/lynx/element.d.ts +8 -0
- package/runtime/lib/snapshot/lynx/element.js +4 -0
- package/runtime/lib/snapshot/lynx/element.js.map +1 -1
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.d.ts +2 -0
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.js +2 -0
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.js.map +1 -1
- package/runtime/lib/snapshot/worklet/ref/updateInitValue.js.map +1 -1
- package/runtime/lib/tsconfig.tsbuildinfo +1 -1
- package/runtime/lib/worklet-runtime/bindings/bindings.d.ts +3 -3
- package/runtime/lib/worklet-runtime/bindings/bindings.js +9 -1
- package/runtime/lib/worklet-runtime/bindings/bindings.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/types.d.ts +3 -6
- package/runtime/lib/worklet-runtime/bindings/types.js.map +1 -1
- package/runtime/lib/worklet-runtime/hydrate.js +26 -7
- package/runtime/lib/worklet-runtime/hydrate.js.map +1 -1
- package/runtime/lib/worklet-runtime/mainThreadObject.d.ts +8 -0
- package/runtime/lib/worklet-runtime/mainThreadObject.js +67 -0
- package/runtime/lib/worklet-runtime/mainThreadObject.js.map +1 -0
- package/runtime/lib/worklet-runtime/workletRef.d.ts +11 -7
- package/runtime/lib/worklet-runtime/workletRef.js +72 -9
- package/runtime/lib/worklet-runtime/workletRef.js.map +1 -1
- package/runtime/lib/worklet-runtime/workletRuntime.js +68 -9
- package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
- package/runtime/package.json +2 -3
- package/runtime/src/core/background-function/run-on-background.ts +16 -0
- package/runtime/src/core/capture-main-thread-object.ts +17 -0
- package/runtime/src/core/globalProps.ts +2 -0
- package/runtime/src/core/hooks/react.ts +4 -0
- package/runtime/src/core/hooks/useLynxGlobalEventListener.ts +2 -0
- package/runtime/src/core/initData.ts +2 -0
- package/runtime/src/core/main-thread-object-handle-registry.ts +25 -0
- package/runtime/src/core/main-thread-object.ts +387 -0
- package/runtime/src/core/main-thread-ref-id.ts +16 -0
- package/runtime/src/core/main-thread-ref-init-value.ts +12 -4
- package/runtime/src/core/main-thread-ref.ts +7 -8
- package/runtime/src/element-template/background/commit-hook.ts +1 -1
- package/runtime/src/element-template/index.ts +6 -0
- package/runtime/src/element-template/internal.ts +2 -0
- package/runtime/src/element-template/protocol/types.ts +1 -1
- package/runtime/src/internal.ts +1 -0
- package/runtime/src/lynx-api.ts +38 -0
- package/runtime/src/lynx.ts +5 -1
- package/runtime/src/snapshot/lifecycle/patch/error.ts +36 -19
- package/runtime/src/snapshot/lifecycle/patch/snapshotPatchApply.ts +29 -7
- package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +2 -2
- package/runtime/src/snapshot/lynx/children.ts +2 -0
- package/runtime/src/snapshot/lynx/element.ts +8 -0
- package/runtime/src/snapshot/worklet/call/runOnMainThread.ts +2 -0
- package/runtime/src/snapshot/worklet/ref/updateInitValue.ts +1 -1
- package/runtime/src/worklet-runtime/bindings/bindings.ts +17 -2
- package/runtime/src/worklet-runtime/bindings/types.ts +7 -11
- package/runtime/src/worklet-runtime/hydrate.ts +43 -10
- package/runtime/src/worklet-runtime/mainThreadObject.ts +117 -0
- package/runtime/src/worklet-runtime/workletRef.ts +120 -19
- package/runtime/src/worklet-runtime/workletRuntime.ts +83 -11
- package/runtime/worklet-runtime/dev.js +154 -17
- package/runtime/worklet-runtime/main.js +1 -1
- package/testing-library/.turbo/turbo-build.log +6 -6
- package/testing-library/dist/index.d.ts +165 -2
- package/testing-library/package.json +2 -1
- package/testing-library/src/__tests__/lynx.test.jsx +1 -1
- package/testing-library/src/__tests__/worklet.test.jsx +46 -1
- package/testing-library/tsconfig.docs.json +9 -0
- package/testing-library/typedoc.json +22 -0
- package/transform/.turbo/turbo-build$colon$wasm.log +150 -78
- package/transform/__test__/fixture.spec.js +72 -30
- package/transform/__test__/object-methods.spec.js +84 -0
- package/transform/crates/swc_plugin_worklet/decl_collect.rs +10 -0
- package/transform/crates/swc_plugin_worklet/extract_ident.rs +14 -0
- package/transform/crates/swc_plugin_worklet/gen_stmt.rs +202 -3
- package/transform/crates/swc_plugin_worklet/lib.rs +468 -3
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_js.js +8 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_lepus.js +10 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_expose_object_method_capture_channels_js.js +27 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_expose_object_method_capture_channels_lepus.js +45 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_js.js +16 -14
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +16 -16
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_js.js +7 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +7 -7
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_computed_object_method_key_lepus.js +24 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_object_method_local_decls_lepus.js +16 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_js.js +42 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +58 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js.js +3 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus.js +3 -3
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_object_methods_js.js +9 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_object_methods_lepus.js +16 -0
- package/transform/dist/wasm.cjs +1 -1
- package/transform/rspack-napi/tsconfig.tsbuildinfo +1 -1
- package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +66 -469
- package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
- package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +364 -30
- package/transform/swc-plugin-reactlynx-compat/swc_plugin_reactlynx_compat.wasm +0 -0
- package/transform/vitest.config.ts +5 -1
- package/types/react.docs.d.ts +130 -11
- package/testing-library/node_modules/.bin/rsbuild +0 -68
- package/testing-library/node_modules/.bin/rspeedy +0 -68
- package/testing-library/node_modules/.bin/rstest +0 -68
- package/transform/node_modules/.bin/esbuild +0 -59
- package/transform/node_modules/.bin/napi +0 -68
|
@@ -4,13 +4,38 @@ use crate::worklet_type::WorkletType;
|
|
|
4
4
|
use crate::TransformMode;
|
|
5
5
|
use std::collections::HashSet;
|
|
6
6
|
use std::vec;
|
|
7
|
-
use swc_core::common::DUMMY_SP;
|
|
7
|
+
use swc_core::common::{EqIgnoreSpan, DUMMY_SP};
|
|
8
8
|
use swc_core::ecma::ast::*;
|
|
9
|
+
use swc_core::ecma::utils::private_ident;
|
|
10
|
+
use swc_core::ecma::visit::{noop_visit_mut_type, VisitMut, VisitMutWith};
|
|
9
11
|
use swc_core::{quote, quote_expr};
|
|
10
12
|
use swc_plugins_shared::target::TransformTarget;
|
|
11
13
|
|
|
12
14
|
pub struct StmtGen {}
|
|
13
15
|
|
|
16
|
+
#[derive(Clone, Copy)]
|
|
17
|
+
enum CaptureRoot {
|
|
18
|
+
Ident,
|
|
19
|
+
ThisMember,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
struct CaptureRootReplacer {
|
|
23
|
+
source: Expr,
|
|
24
|
+
replacement: Ident,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
impl VisitMut for CaptureRootReplacer {
|
|
28
|
+
noop_visit_mut_type!();
|
|
29
|
+
|
|
30
|
+
fn visit_mut_expr(&mut self, expr: &mut Expr) {
|
|
31
|
+
if expr.eq_ignore_span(&self.source) {
|
|
32
|
+
*expr = Expr::Ident(self.replacement.clone());
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
expr.visit_mut_children_with(self);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
14
39
|
struct RegisterWorkletParams<'a> {
|
|
15
40
|
mode: TransformMode,
|
|
16
41
|
target: TransformTarget,
|
|
@@ -41,7 +66,16 @@ impl StmtGen {
|
|
|
41
66
|
collect_main_thread: bool,
|
|
42
67
|
) -> (Box<Expr>, Stmt, Option<Stmt>) {
|
|
43
68
|
let hash = Expr::Lit(hash.into());
|
|
44
|
-
let extracted_value = ident_collector.take_values();
|
|
69
|
+
let mut extracted_value = ident_collector.take_values();
|
|
70
|
+
let mut extracted_this_expr = ident_collector.take_this_expr();
|
|
71
|
+
if StmtGen::wrap_main_thread_object_candidates(&mut extracted_value, CaptureRoot::Ident)
|
|
72
|
+
| StmtGen::wrap_main_thread_object_candidates(
|
|
73
|
+
&mut extracted_this_expr,
|
|
74
|
+
CaptureRoot::ThisMember,
|
|
75
|
+
)
|
|
76
|
+
{
|
|
77
|
+
named_imports.insert("captureMainThreadObject".into());
|
|
78
|
+
}
|
|
45
79
|
let extracted_idents = ident_collector.take_idents();
|
|
46
80
|
let extracted_js_fns = ident_collector.take_js_fns();
|
|
47
81
|
|
|
@@ -70,7 +104,7 @@ impl StmtGen {
|
|
|
70
104
|
target
|
|
71
105
|
},
|
|
72
106
|
extracted_value,
|
|
73
|
-
|
|
107
|
+
extracted_this_expr,
|
|
74
108
|
extracted_js_fns.clone(),
|
|
75
109
|
hash.clone(),
|
|
76
110
|
named_imports,
|
|
@@ -193,6 +227,171 @@ impl StmtGen {
|
|
|
193
227
|
.into()
|
|
194
228
|
}
|
|
195
229
|
|
|
230
|
+
fn wrap_main_thread_object_candidates(
|
|
231
|
+
extracted_value: &mut Box<Expr>,
|
|
232
|
+
capture_root: CaptureRoot,
|
|
233
|
+
) -> bool {
|
|
234
|
+
let mut wrapped = false;
|
|
235
|
+
let Some(object) = extracted_value.as_mut_object() else {
|
|
236
|
+
return false;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
for prop in &mut object.props {
|
|
240
|
+
let Some(prop) = prop.as_mut_prop() else {
|
|
241
|
+
continue;
|
|
242
|
+
};
|
|
243
|
+
let Prop::KeyValue(key_value) = prop.as_mut() else {
|
|
244
|
+
continue;
|
|
245
|
+
};
|
|
246
|
+
if !key_value.value.is_object() {
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
let source = match capture_root {
|
|
250
|
+
CaptureRoot::Ident => StmtGen::find_root_ident(&key_value.value).map(Expr::Ident),
|
|
251
|
+
CaptureRoot::ThisMember => StmtGen::find_root_this_member(&key_value.value),
|
|
252
|
+
};
|
|
253
|
+
let Some(source) = source else {
|
|
254
|
+
continue;
|
|
255
|
+
};
|
|
256
|
+
wrapped |= StmtGen::wrap_main_thread_object_candidate(&mut key_value.value, source);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
wrapped
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
fn wrap_main_thread_object_candidate(value: &mut Box<Expr>, source: Expr) -> bool {
|
|
263
|
+
let Some(object) = value.as_mut_object() else {
|
|
264
|
+
return false;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
for prop in &mut object.props {
|
|
268
|
+
let Some(prop) = prop.as_mut_prop() else {
|
|
269
|
+
continue;
|
|
270
|
+
};
|
|
271
|
+
let Prop::KeyValue(key_value) = prop.as_mut() else {
|
|
272
|
+
continue;
|
|
273
|
+
};
|
|
274
|
+
if !key_value.value.is_object() {
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
let child_source = StmtGen::append_member(source.clone(), &key_value.key);
|
|
278
|
+
StmtGen::wrap_main_thread_object_candidate(&mut key_value.value, child_source);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
let mut fallback = value.clone();
|
|
282
|
+
let source_argument = source.clone();
|
|
283
|
+
let capture_argument = if source.is_ident() {
|
|
284
|
+
source
|
|
285
|
+
} else {
|
|
286
|
+
let capture_source = private_ident!("__mainThreadObjectSource");
|
|
287
|
+
fallback.visit_mut_with(&mut CaptureRootReplacer {
|
|
288
|
+
source,
|
|
289
|
+
replacement: capture_source.clone(),
|
|
290
|
+
});
|
|
291
|
+
Expr::Ident(capture_source)
|
|
292
|
+
};
|
|
293
|
+
let captured = CallExpr {
|
|
294
|
+
ctxt: Default::default(),
|
|
295
|
+
span: DUMMY_SP,
|
|
296
|
+
args: vec![capture_argument.clone().into()],
|
|
297
|
+
callee: Callee::Expr(quote_expr!("captureMainThreadObject")),
|
|
298
|
+
type_args: None,
|
|
299
|
+
}
|
|
300
|
+
.into();
|
|
301
|
+
let captured_or_fallback: Expr = BinExpr {
|
|
302
|
+
span: DUMMY_SP,
|
|
303
|
+
op: BinaryOp::NullishCoalescing,
|
|
304
|
+
left: captured,
|
|
305
|
+
right: fallback,
|
|
306
|
+
}
|
|
307
|
+
.into();
|
|
308
|
+
*value = if source_argument.is_ident() {
|
|
309
|
+
captured_or_fallback.into()
|
|
310
|
+
} else {
|
|
311
|
+
CallExpr {
|
|
312
|
+
ctxt: Default::default(),
|
|
313
|
+
span: DUMMY_SP,
|
|
314
|
+
callee: Callee::Expr(
|
|
315
|
+
ArrowExpr {
|
|
316
|
+
ctxt: Default::default(),
|
|
317
|
+
span: DUMMY_SP,
|
|
318
|
+
params: vec![Pat::Ident(capture_argument.expect_ident().into())],
|
|
319
|
+
body: Box::new(ArrowFunctionBody::Expr(captured_or_fallback.into())),
|
|
320
|
+
is_async: false,
|
|
321
|
+
is_generator: false,
|
|
322
|
+
type_params: None,
|
|
323
|
+
return_type: None,
|
|
324
|
+
}
|
|
325
|
+
.into(),
|
|
326
|
+
),
|
|
327
|
+
args: vec![source_argument.into()],
|
|
328
|
+
type_args: None,
|
|
329
|
+
}
|
|
330
|
+
.into()
|
|
331
|
+
};
|
|
332
|
+
true
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
fn append_member(source: Expr, property: &PropName) -> Expr {
|
|
336
|
+
let property = match property {
|
|
337
|
+
PropName::Ident(ident) => MemberProp::Ident(ident.clone()),
|
|
338
|
+
PropName::Str(value) => MemberProp::Computed(ComputedPropName {
|
|
339
|
+
span: DUMMY_SP,
|
|
340
|
+
expr: Expr::Lit(Lit::Str(value.clone())).into(),
|
|
341
|
+
}),
|
|
342
|
+
PropName::Num(value) => MemberProp::Computed(ComputedPropName {
|
|
343
|
+
span: DUMMY_SP,
|
|
344
|
+
expr: Expr::Lit(Lit::Num(value.clone())).into(),
|
|
345
|
+
}),
|
|
346
|
+
PropName::BigInt(value) => MemberProp::Computed(ComputedPropName {
|
|
347
|
+
span: DUMMY_SP,
|
|
348
|
+
expr: Expr::Lit(Lit::BigInt(value.clone())).into(),
|
|
349
|
+
}),
|
|
350
|
+
PropName::Computed(value) => MemberProp::Computed(value.clone()),
|
|
351
|
+
};
|
|
352
|
+
StmtGen::append_member_prop(source, property)
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
fn append_member_prop(source: Expr, property: MemberProp) -> Expr {
|
|
356
|
+
MemberExpr {
|
|
357
|
+
span: DUMMY_SP,
|
|
358
|
+
obj: source.into(),
|
|
359
|
+
prop: property,
|
|
360
|
+
}
|
|
361
|
+
.into()
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
fn find_root_ident(expr: &Expr) -> Option<Ident> {
|
|
365
|
+
match expr {
|
|
366
|
+
Expr::Ident(ident) => Some(ident.clone()),
|
|
367
|
+
Expr::Member(member) => StmtGen::find_root_ident(&member.obj),
|
|
368
|
+
Expr::Object(object) => object.props.iter().find_map(|prop| {
|
|
369
|
+
let prop = prop.as_prop()?;
|
|
370
|
+
match prop.as_ref() {
|
|
371
|
+
Prop::Shorthand(ident) => Some(ident.clone()),
|
|
372
|
+
Prop::KeyValue(key_value) => StmtGen::find_root_ident(&key_value.value),
|
|
373
|
+
_ => None,
|
|
374
|
+
}
|
|
375
|
+
}),
|
|
376
|
+
_ => None,
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
fn find_root_this_member(expr: &Expr) -> Option<Expr> {
|
|
381
|
+
match expr {
|
|
382
|
+
Expr::Member(member) if member.obj.is_this() => Some(Expr::Member(member.clone())),
|
|
383
|
+
Expr::Member(member) => StmtGen::find_root_this_member(&member.obj),
|
|
384
|
+
Expr::Object(object) => object.props.iter().find_map(|prop| {
|
|
385
|
+
let prop = prop.as_prop()?;
|
|
386
|
+
match prop.as_ref() {
|
|
387
|
+
Prop::KeyValue(key_value) => StmtGen::find_root_this_member(&key_value.value),
|
|
388
|
+
_ => None,
|
|
389
|
+
}
|
|
390
|
+
}),
|
|
391
|
+
_ => None,
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
196
395
|
/*
|
|
197
396
|
* registerWorklet($type, $hash, $function);
|
|
198
397
|
*/
|