@@ -2329,7 +2329,7 @@ impl Engine {
23292329 namespace : crate :: ast:: Namespace :: NONE ,
23302330 name : self . get_interned_string ( & op) ,
23312331 hashes : FnCallHashes :: from_native_only ( hash) ,
2332- args : IntoIterator :: into_iter ( [ root, rhs] ) . collect ( ) ,
2332+ args : IntoIterator :: into_iter ( [ root. clone ( ) , rhs. clone ( ) ] ) . collect ( ) ,
23332333 op_token : native_only. then ( || op_token. clone ( ) ) ,
23342334 capture_parent_scope : false ,
23352335 } ;
@@ -2430,6 +2430,129 @@ impl Engine {
24302430 op_base. into_fn_call_expr ( pos)
24312431 }
24322432
2433+ Token :: PipeArrow => {
2434+ // Pipeline: lhs |> fn(args...) => fn(lhs, args...)
2435+ match rhs {
2436+ Expr :: FnCall ( f, func_pos) => {
2437+ // take inner FnCallExpr
2438+ let mut f = * f;
2439+
2440+ let args_len = f. args . len ( ) + 1 ;
2441+ f. args . insert ( 0 , root) ;
2442+
2443+ // Recalculate hash for the new argument count, preserving namespace if any
2444+ #[ cfg( not( feature = "no_module" ) ) ]
2445+ {
2446+ let hash = if f. namespace . is_empty ( ) {
2447+ calc_fn_hash ( None , & f. name , args_len)
2448+ } else {
2449+ calc_fn_hash (
2450+ f. namespace . path . iter ( ) . map ( Ident :: as_str) ,
2451+ & f. name ,
2452+ args_len,
2453+ )
2454+ } ;
2455+ f. hashes = if is_valid_function_name ( & f. name ) {
2456+ FnCallHashes :: from_hash ( hash)
2457+ } else {
2458+ FnCallHashes :: from_native_only ( hash)
2459+ } ;
2460+ }
2461+ #[ cfg( feature = "no_module" ) ]
2462+ {
2463+ f. hashes = if is_valid_function_name ( & f. name ) {
2464+ FnCallHashes :: from_hash ( calc_fn_hash ( None , & f. name , args_len) )
2465+ } else {
2466+ FnCallHashes :: from_native_only ( calc_fn_hash (
2467+ None , & f. name , args_len,
2468+ ) )
2469+ } ;
2470+ }
2471+
2472+ Expr :: FnCall ( f. into ( ) , func_pos)
2473+ }
2474+ Expr :: MethodCall ( f, func_pos) => {
2475+ let mut f = * f;
2476+
2477+ let args_len = f. args . len ( ) + 1 ;
2478+ f. args . insert ( 0 , root) ;
2479+
2480+ // Recalculate hash for the new argument count
2481+ f. hashes = if is_valid_function_name ( & f. name ) {
2482+ #[ cfg( not( feature = "no_function" ) ) ]
2483+ {
2484+ FnCallHashes :: from_hash ( calc_fn_hash ( None , & f. name , args_len) )
2485+ }
2486+ #[ cfg( feature = "no_function" ) ]
2487+ {
2488+ FnCallHashes :: from_native_only ( calc_fn_hash (
2489+ None , & f. name , args_len,
2490+ ) )
2491+ }
2492+ } else {
2493+ FnCallHashes :: from_native_only ( calc_fn_hash (
2494+ None , & f. name , args_len,
2495+ ) )
2496+ } ;
2497+
2498+ Expr :: FnCall ( f. into ( ) , func_pos)
2499+ }
2500+ Expr :: Variable ( x, ..) => {
2501+ // Pipeline into a bare function name: lhs |> func => func(lhs)
2502+ let x = * x; // move out
2503+
2504+ #[ cfg( not( feature = "no_module" ) ) ]
2505+ let ( _index, name, namespace, _hash) = x;
2506+ #[ cfg( feature = "no_module" ) ]
2507+ let ( index, name) = x;
2508+
2509+ let args_len = 1usize ;
2510+
2511+ #[ cfg( not( feature = "no_module" ) ) ]
2512+ let hashes = if is_valid_function_name ( & name) {
2513+ FnCallHashes :: from_hash ( calc_fn_hash (
2514+ namespace. path . iter ( ) . map ( Ident :: as_str) ,
2515+ & name,
2516+ args_len,
2517+ ) )
2518+ } else {
2519+ FnCallHashes :: from_native_only ( calc_fn_hash (
2520+ namespace. path . iter ( ) . map ( Ident :: as_str) ,
2521+ & name,
2522+ args_len,
2523+ ) )
2524+ } ;
2525+
2526+ #[ cfg( feature = "no_module" ) ]
2527+ let hashes = if is_valid_function_name ( & name) {
2528+ FnCallHashes :: from_hash ( calc_fn_hash ( None , & name, args_len) )
2529+ } else {
2530+ FnCallHashes :: from_native_only ( calc_fn_hash ( None , & name, args_len) )
2531+ } ;
2532+
2533+ let fn_call = FnCallExpr {
2534+ #[ cfg( not( feature = "no_module" ) ) ]
2535+ namespace : {
2536+ #[ cfg( not( feature = "no_module" ) ) ]
2537+ {
2538+ let mut ns = crate :: ast:: Namespace :: NONE ;
2539+ ns. path = namespace. path ;
2540+ ns. index = namespace. index ;
2541+ ns
2542+ }
2543+ } ,
2544+ name : name. clone ( ) ,
2545+ hashes,
2546+ args : IntoIterator :: into_iter ( [ root] ) . collect ( ) ,
2547+ capture_parent_scope : false ,
2548+ op_token : None ,
2549+ } ;
2550+
2551+ Expr :: FnCall ( fn_call. into ( ) , pos)
2552+ }
2553+ _ => op_base. into_fn_call_expr ( pos) ,
2554+ }
2555+ }
24332556 _ => op_base. into_fn_call_expr ( pos) ,
24342557 } ;
24352558 }
0 commit comments