@opencode/core 2.0.22 → 2.0.24
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/dist/account/sql.js +1 -1
- package/dist/agent.js +83 -83
- package/dist/aisdk-native.js +89 -89
- package/dist/aisdk.js +94 -94
- package/dist/app.js +9 -9
- package/dist/bus.js +69 -69
- package/dist/chunks/{instruction-discovery-4rr4p9ms.js → repository-00e0wh3q.js} +24 -24
- package/dist/chunks/{instruction-discovery-772hnq51.js → repository-012g15cx.js} +13 -13
- package/dist/chunks/{instruction-discovery-qyc0y5ej.js → repository-042aawn8.js} +16 -16
- package/dist/chunks/{instruction-discovery-67mhc6gs.js → repository-05t95569.js} +19 -19
- package/dist/chunks/{instruction-discovery-s4r1cmp3.js → repository-067895h7.js} +20 -20
- package/dist/chunks/{instruction-discovery-rqkavtkg.js → repository-0f0pgr2e.js} +3 -3
- package/dist/chunks/{instruction-discovery-gd7r64mz.js → repository-0g25qkkf.js} +11 -11
- package/dist/chunks/{instruction-discovery-na0cega3.js → repository-0h1qn0y5.js} +10 -10
- package/dist/chunks/{instruction-discovery-q0xm7vwc.js → repository-0j77ygfz.js} +6 -6
- package/dist/chunks/{instruction-discovery-0paq2nw3.js → repository-0paq2nw3.js} +1 -1
- package/dist/chunks/{instruction-discovery-5mxct2xg.js → repository-0qpq6ar5.js} +13 -13
- package/dist/chunks/{instruction-discovery-s225zym4.js → repository-0qqvk1tp.js} +17 -17
- package/dist/chunks/{instruction-discovery-0vbcp93d.js → repository-0vbcp93d.js} +2 -2
- package/dist/chunks/{instruction-discovery-1vnjqps3.js → repository-16558gs3.js} +46 -46
- package/dist/chunks/{instruction-discovery-rhraev7y.js → repository-1acjjqhc.js} +4 -4
- package/dist/chunks/{instruction-discovery-73tb2d7t.js → repository-1bbkgx8g.js} +3 -3
- package/dist/chunks/{instruction-discovery-r4akt23v.js → repository-1cw3fj19.js} +3 -3
- package/dist/chunks/{instruction-discovery-1dazxqgg.js → repository-1dazxqgg.js} +2 -2
- package/dist/chunks/{instruction-discovery-1dvck2a7.js → repository-1dvck2a7.js} +2 -2
- package/dist/chunks/{instruction-discovery-fqtvmpfq.js → repository-1gfgk62c.js} +8 -8
- package/dist/chunks/{instruction-discovery-qs2rp835.js → repository-1vvm3xv7.js} +11 -11
- package/dist/chunks/{instruction-discovery-wbx60fzd.js → repository-1wb0x8n3.js} +5 -5
- package/dist/chunks/{instruction-discovery-g259vpc3.js → repository-23294nz8.js} +26 -26
- package/dist/chunks/{instruction-discovery-wszd5dmy.js → repository-2455wr4j.js} +17 -16
- package/dist/chunks/{instruction-discovery-2a5m3afh.js → repository-2a5m3afh.js} +1 -1
- package/dist/chunks/{instruction-discovery-4ts7tf6z.js → repository-2ccvkpx1.js} +2 -2
- package/dist/chunks/{instruction-discovery-7dqw4kz8.js → repository-2k8khapm.js} +5 -5
- package/dist/chunks/{instruction-discovery-vn72gsba.js → repository-2m8jawch.js} +4 -4
- package/dist/chunks/{instruction-discovery-mqw81mrh.js → repository-2t9hnq90.js} +10 -10
- package/dist/chunks/{instruction-discovery-96c14hr5.js → repository-2texf5vf.js} +22 -22
- package/dist/chunks/{instruction-discovery-a56fhhr2.js → repository-2tyga0yy.js} +28 -60
- package/dist/chunks/{instruction-discovery-a5jrrkeg.js → repository-2wredcz9.js} +20 -20
- package/dist/chunks/{instruction-discovery-01wcheh0.js → repository-32xj3ztx.js} +62 -83
- package/dist/chunks/{instruction-discovery-wxyynt4w.js → repository-3556dn8t.js} +1 -1
- package/dist/chunks/repository-3b3navdj.js +253 -0
- package/dist/chunks/{instruction-discovery-3fc6dm20.js → repository-3fc6dm20.js} +1 -1
- package/dist/chunks/{instruction-discovery-3hepkmqq.js → repository-3hepkmqq.js} +1 -1
- package/dist/chunks/{instruction-discovery-3smtnn6g.js → repository-3smtnn6g.js} +1 -1
- package/dist/chunks/{instruction-discovery-sk3qaz4a.js → repository-3t0ybcrp.js} +58 -20
- package/dist/chunks/{instruction-discovery-4tgz421y.js → repository-3t7hfzt0.js} +30 -19
- package/dist/chunks/{instruction-discovery-3tvqynh2.js → repository-3tvqynh2.js} +1 -1
- package/dist/chunks/{instruction-discovery-cyk1kg6z.js → repository-3vy5pcbx.js} +33 -33
- package/dist/chunks/{instruction-discovery-3zsf4n22.js → repository-3zsf4n22.js} +1 -1
- package/dist/chunks/{instruction-discovery-qxmvdacm.js → repository-4344f0hm.js} +34 -34
- package/dist/chunks/repository-45085rbj.js +26 -0
- package/dist/chunks/repository-46tr0mr7.js +126 -0
- package/dist/chunks/{instruction-discovery-rz6t0wqc.js → repository-47phkfqm.js} +47 -47
- package/dist/chunks/{instruction-discovery-0yrmzdme.js → repository-4azg6a58.js} +16 -11
- package/dist/chunks/{instruction-discovery-3z218dsj.js → repository-4c5k237e.js} +39 -44
- package/dist/chunks/{instruction-discovery-k6hcwg2z.js → repository-4cw36es0.js} +9 -9
- package/dist/chunks/{instruction-discovery-axmmtzpw.js → repository-4ege8dpt.js} +19 -19
- package/dist/chunks/{instruction-discovery-bh3q4eyg.js → repository-4y69v0zr.js} +13 -13
- package/dist/chunks/{instruction-discovery-gw7cjrad.js → repository-4z58m4b4.js} +4 -4
- package/dist/chunks/{instruction-discovery-hzktwm2m.js → repository-4z7pkycv.js} +19 -19
- package/dist/chunks/{instruction-discovery-54ma36ye.js → repository-54ma36ye.js} +1 -1
- package/dist/chunks/{instruction-discovery-hjxrfacw.js → repository-56a9smke.js} +13 -13
- package/dist/chunks/{instruction-discovery-33w4ejhs.js → repository-56gdpj1q.js} +6 -6
- package/dist/chunks/{instruction-discovery-aszn3zwx.js → repository-56gyfky0.js} +5 -5
- package/dist/chunks/{instruction-discovery-w2h15q85.js → repository-57myy5jh.js} +5 -5
- package/dist/chunks/{instruction-discovery-5daktx2q.js → repository-5daktx2q.js} +1 -1
- package/dist/chunks/repository-5ej07zgb.js +143 -0
- package/dist/chunks/{instruction-discovery-vk0h33mx.js → repository-5k54pn5m.js} +10 -10
- package/dist/chunks/{instruction-discovery-vzcthcp8.js → repository-5m9w47nd.js} +1 -1
- package/dist/chunks/{instruction-discovery-93pbq578.js → repository-5ng375bv.js} +28 -28
- package/dist/chunks/{instruction-discovery-cr59q9qa.js → repository-5pptr25h.js} +40 -25
- package/dist/chunks/{instruction-discovery-a90g57x6.js → repository-5r637m3f.js} +57 -57
- package/dist/chunks/{instruction-discovery-5t3nmthw.js → repository-5t3nmthw.js} +2 -2
- package/dist/chunks/{instruction-discovery-vc32h82s.js → repository-5t80mpw4.js} +18 -18
- package/dist/chunks/{instruction-discovery-nrjg26ec.js → repository-5w6ne2rj.js} +11 -11
- package/dist/chunks/{instruction-discovery-d4k4eg4n.js → repository-68ga000j.js} +47 -47
- package/dist/chunks/{instruction-discovery-62s7jehk.js → repository-6b1pjwt3.js} +5 -5
- package/dist/chunks/{instruction-discovery-hjbc5kem.js → repository-6q2bdcd1.js} +4 -1
- package/dist/chunks/{instruction-discovery-an4n7p46.js → repository-6r4hjhnf.js} +20 -21
- package/dist/chunks/{instruction-discovery-6644et9y.js → repository-6x4qebe7.js} +33 -33
- package/dist/chunks/{instruction-discovery-x1ezjp6w.js → repository-6xb47vfp.js} +4 -2
- package/dist/chunks/{instruction-discovery-71az546q.js → repository-71az546q.js} +2 -2
- package/dist/chunks/{instruction-discovery-hjryqbzv.js → repository-77apbbcp.js} +45 -45
- package/dist/chunks/{instruction-discovery-7bmhse3q.js → repository-7bmhse3q.js} +1 -1
- package/dist/chunks/{instruction-discovery-87bs7bte.js → repository-7c08hygz.js} +11 -11
- package/dist/chunks/{instruction-discovery-xmh85kzb.js → repository-7d05dvcz.js} +11 -11
- package/dist/chunks/{instruction-discovery-fxvwdnb4.js → repository-7wnc14t4.js} +44 -21
- package/dist/chunks/{instruction-discovery-ysyp8d4a.js → repository-7z6z4pna.js} +21 -21
- package/dist/chunks/{instruction-discovery-84txncab.js → repository-84txncab.js} +1 -1
- package/dist/chunks/{instruction-discovery-kn7rctz9.js → repository-89za3yyg.js} +9 -9
- package/dist/chunks/{instruction-discovery-8d7r5vzw.js → repository-8d7r5vzw.js} +1 -1
- package/dist/chunks/{instruction-discovery-yppg54y4.js → repository-8hjmwb77.js} +13 -13
- package/dist/chunks/{instruction-discovery-fah0stq9.js → repository-8kys6q5k.js} +9 -9
- package/dist/chunks/{instruction-discovery-m0r31qfn.js → repository-8tsdq50x.js} +4 -4
- package/dist/chunks/{instruction-discovery-hehaxqkv.js → repository-96ctqc5x.js} +4 -4
- package/dist/chunks/{instruction-discovery-5sv8fqdt.js → repository-9815d8pv.js} +45 -35
- package/dist/chunks/{instruction-discovery-9e5bzkjp.js → repository-9e5bzkjp.js} +3 -3
- package/dist/chunks/{instruction-discovery-h53acpwd.js → repository-9mhtj97w.js} +16 -16
- package/dist/chunks/{instruction-discovery-fajwdt4h.js → repository-9mxexfbd.js} +14 -14
- package/dist/chunks/{instruction-discovery-s48x4bgh.js → repository-9s1pr29s.js} +41 -41
- package/dist/chunks/{instruction-discovery-th1qq6gc.js → repository-9yaf30yb.js} +35 -35
- package/dist/chunks/{instruction-discovery-mjv4tm51.js → repository-9yxvhatz.js} +4 -4
- package/dist/chunks/{instruction-discovery-79wzcjsa.js → repository-a199weyn.js} +6 -6
- package/dist/chunks/{instruction-discovery-6hh8tjw2.js → repository-a2ew8a62.js} +4 -4
- package/dist/chunks/{instruction-discovery-arxkpe44.js → repository-a6rczh0a.js} +60 -40
- package/dist/chunks/{instruction-discovery-1ajc00mn.js → repository-a7cd87s2.js} +58 -58
- package/dist/chunks/{instruction-discovery-aaet6srn.js → repository-aaet6srn.js} +2 -2
- package/dist/chunks/{instruction-discovery-068serwz.js → repository-addxnjmp.js} +4 -4
- package/dist/chunks/{instruction-discovery-zk4rm6sg.js → repository-ajh7mqgq.js} +20 -20
- package/dist/chunks/{instruction-discovery-fqzyqcjh.js → repository-aqryd466.js} +24 -24
- package/dist/chunks/{instruction-discovery-xjbrwz9c.js → repository-b20bdvd4.js} +12 -12
- package/dist/chunks/{instruction-discovery-80t7gq44.js → repository-b3cm3psy.js} +10 -7
- package/dist/chunks/{instruction-discovery-17z9v3bw.js → repository-b5f9cqb8.js} +33 -29
- package/dist/chunks/{instruction-discovery-b6gygkdw.js → repository-b6gygkdw.js} +2 -2
- package/dist/chunks/{instruction-discovery-ksgw4q3t.js → repository-b751st24.js} +3 -3
- package/dist/chunks/{instruction-discovery-c8g8cdht.js → repository-bzadqhw2.js} +4 -4
- package/dist/chunks/{instruction-discovery-qj8eh1ht.js → repository-c20khjev.js} +21 -21
- package/dist/chunks/{instruction-discovery-eqkxs06z.js → repository-c8bydgjz.js} +6 -6
- package/dist/chunks/{instruction-discovery-7e0zw79e.js → repository-cb3fgacg.js} +29 -29
- package/dist/chunks/{instruction-discovery-j4q93wg3.js → repository-ce3pkz8w.js} +5 -5
- package/dist/chunks/{instruction-discovery-b4twkq7r.js → repository-cfsekr6v.js} +6 -6
- package/dist/chunks/{instruction-discovery-caxch348.js → repository-chyvjp63.js} +12 -12
- package/dist/chunks/{instruction-discovery-r01t9b5y.js → repository-cjwramev.js} +4 -4
- package/dist/chunks/{instruction-discovery-ntngab6e.js → repository-cs63tcvs.js} +20 -10
- package/dist/chunks/{instruction-discovery-cwa6csj7.js → repository-d4he2qe1.js} +9 -9
- package/dist/chunks/{instruction-discovery-hn87b5yq.js → repository-dbp4m4ge.js} +33 -33
- package/dist/chunks/{instruction-discovery-fnwnhbfk.js → repository-dfcrteyq.js} +13 -13
- package/dist/chunks/{instruction-discovery-txp0vmzz.js → repository-dp8mmgq4.js} +15 -15
- package/dist/chunks/{instruction-discovery-dpkg50ah.js → repository-dpkg50ah.js} +1 -1
- package/dist/chunks/{instruction-discovery-53eqz1v2.js → repository-drnf6xwf.js} +2 -2
- package/dist/chunks/{instruction-discovery-yydx669n.js → repository-dt6m3qwv.js} +18 -18
- package/dist/chunks/{instruction-discovery-5qd3pb7m.js → repository-e3qxr5gk.js} +2 -2
- package/dist/chunks/{instruction-discovery-xw25vat5.js → repository-ecwx0042.js} +13 -13
- package/dist/chunks/{instruction-discovery-yphk03p8.js → repository-ef2cw19s.js} +9 -9
- package/dist/chunks/{instruction-discovery-ef5x83kb.js → repository-ef5x83kb.js} +1 -1
- package/dist/chunks/{instruction-discovery-ckf8nxjz.js → repository-embw8kgh.js} +4 -4
- package/dist/chunks/{instruction-discovery-38p5t189.js → repository-eqh5fpv6.js} +11 -11
- package/dist/chunks/{instruction-discovery-dn5164wf.js → repository-erq8vxjr.js} +3 -3
- package/dist/chunks/{instruction-discovery-ywxndyv1.js → repository-espax8zg.js} +4 -4
- package/dist/chunks/{instruction-discovery-75p81wsx.js → repository-etdaqrbr.js} +30 -30
- package/dist/chunks/{instruction-discovery-etq0c3wd.js → repository-etq0c3wd.js} +1 -1
- package/dist/chunks/{instruction-discovery-70f73jf1.js → repository-f6sbv01c.js} +47 -46
- package/dist/chunks/{instruction-discovery-6ehccv3h.js → repository-f8tnf7f1.js} +20 -25
- package/dist/chunks/{instruction-discovery-wvmj1et3.js → repository-f8xdbq78.js} +9 -9
- package/dist/chunks/{instruction-discovery-x8pk0y4v.js → repository-fj3b7143.js} +42 -42
- package/dist/chunks/{instruction-discovery-eq8x7ha8.js → repository-fy3w4x98.js} +31 -39
- package/dist/chunks/{instruction-discovery-h3rm5wyc.js → repository-fy698pgn.js} +13 -13
- package/dist/chunks/{instruction-discovery-yzzqahvy.js → repository-g34b934z.js} +22 -22
- package/dist/chunks/repository-g4nj3be3.js +507 -0
- package/dist/chunks/repository-g50bcqhp.js +43 -0
- package/dist/chunks/{instruction-discovery-g5w8qwbj.js → repository-g5w8qwbj.js} +1 -1
- package/dist/chunks/{instruction-discovery-nwb3b15q.js → repository-g69c5a8v.js} +14 -18
- package/dist/chunks/{instruction-discovery-gqawmzqm.js → repository-gc135ar8.js} +8 -8
- package/dist/chunks/{instruction-discovery-gd4qta3r.js → repository-gd4qta3r.js} +1 -1
- package/dist/chunks/{instruction-discovery-76jv6ta8.js → repository-gkcjs2dn.js} +13 -13
- package/dist/chunks/{instruction-discovery-r57kss4c.js → repository-gpng080p.js} +32 -32
- package/dist/chunks/{instruction-discovery-qgr4tws1.js → repository-gry8sgkd.js} +15 -15
- package/dist/chunks/{instruction-discovery-ved7ma53.js → repository-gy4662d6.js} +9 -9
- package/dist/chunks/{instruction-discovery-b0t1fydp.js → repository-h16n41p4.js} +20 -20
- package/dist/chunks/{instruction-discovery-h2b79v29.js → repository-h2b79v29.js} +2 -2
- package/dist/chunks/{instruction-discovery-x74ax8b2.js → repository-h2yw0gk4.js} +20 -20
- package/dist/chunks/{instruction-discovery-3bss0zm1.js → repository-h4jx6m0r.js} +14 -14
- package/dist/chunks/{instruction-discovery-nxq54803.js → repository-h4p4pa57.js} +11 -11
- package/dist/chunks/{instruction-discovery-nnxtdpka.js → repository-h6c2yg5r.js} +8 -8
- package/dist/chunks/{instruction-discovery-qtkea077.js → repository-h6qw898r.js} +11 -11
- package/dist/chunks/{instruction-discovery-h6vf3j39.js → repository-h6vf3j39.js} +1 -1
- package/dist/chunks/{instruction-discovery-7fx6jza6.js → repository-h6yzxz9r.js} +17 -17
- package/dist/chunks/{instruction-discovery-chamsvbn.js → repository-hdjgtqrb.js} +33 -33
- package/dist/chunks/{instruction-discovery-6wqmdryt.js → repository-hkgfm0m5.js} +24 -24
- package/dist/chunks/{instruction-discovery-vpw3bjrj.js → repository-hp7m3mgg.js} +28 -28
- package/dist/chunks/{instruction-discovery-7je2rhvj.js → repository-hw3ewgqj.js} +11 -11
- package/dist/chunks/{instruction-discovery-vj991bdt.js → repository-j2htzqze.js} +2 -2
- package/dist/chunks/{instruction-discovery-098a7yv1.js → repository-j3pg2mx4.js} +3 -3
- package/dist/chunks/{instruction-discovery-j56e64zr.js → repository-j56e64zr.js} +1 -1
- package/dist/chunks/{instruction-discovery-y56ehv6b.js → repository-j58c5xyq.js} +9 -9
- package/dist/chunks/{instruction-discovery-kgxgq8c4.js → repository-jnevnthy.js} +25 -25
- package/dist/chunks/{instruction-discovery-jqh9b0xq.js → repository-jqh9b0xq.js} +1 -1
- package/dist/chunks/{instruction-discovery-exnynncn.js → repository-k02x6tcx.js} +30 -30
- package/dist/chunks/{instruction-discovery-7fvn2yaq.js → repository-k37ga4vh.js} +13 -9
- package/dist/chunks/{instruction-discovery-srq8z0b0.js → repository-k70p9jzb.js} +9 -9
- package/dist/chunks/{instruction-discovery-b0xx1bw1.js → repository-kfj4fg87.js} +5 -5
- package/dist/chunks/{instruction-discovery-ccwzr35z.js → repository-kxam66j6.js} +13 -13
- package/dist/chunks/{instruction-discovery-m3fdjcah.js → repository-m3fdjcah.js} +1 -1
- package/dist/chunks/{instruction-discovery-b65pgdb7.js → repository-m44fkk4m.js} +18 -11
- package/dist/chunks/{instruction-discovery-4gksvbnk.js → repository-m993mvxq.js} +177 -177
- package/dist/chunks/{instruction-discovery-m9w0rfyh.js → repository-m9w0rfyh.js} +1 -1
- package/dist/chunks/{instruction-discovery-768hztz0.js → repository-mfct962c.js} +28 -28
- package/dist/chunks/{instruction-discovery-qg6jkzae.js → repository-mfmqp3ds.js} +43 -43
- package/dist/chunks/{instruction-discovery-rttzrg3r.js → repository-mjqndqed.js} +12 -12
- package/dist/chunks/{instruction-discovery-jpcc9kth.js → repository-mn0942hp.js} +24 -24
- package/dist/chunks/{instruction-discovery-s0ptdndk.js → repository-mpd66srn.js} +1 -1
- package/dist/chunks/{instruction-discovery-hz0q9sdq.js → repository-mxr1v1s0.js} +8 -8
- package/dist/chunks/{instruction-discovery-93hpb89x.js → repository-my4zabxr.js} +3 -3
- package/dist/chunks/{instruction-discovery-c9qfs3nh.js → repository-nszdq9jy.js} +78 -78
- package/dist/chunks/{instruction-discovery-wwsveqr1.js → repository-ntaqe8vs.js} +21 -21
- package/dist/chunks/{instruction-discovery-gt8knnyb.js → repository-ntbz9wjc.js} +8 -8
- package/dist/chunks/{instruction-discovery-dv1qgsyq.js → repository-p42hj8p8.js} +8 -8
- package/dist/chunks/{instruction-discovery-5ch8te7e.js → repository-p5ev1zz5.js} +9 -9
- package/dist/chunks/{instruction-discovery-fwq9htr3.js → repository-pe71rtbx.js} +11 -11
- package/dist/chunks/{instruction-discovery-w9p1c293.js → repository-pg4zag0e.js} +24 -24
- package/dist/chunks/{instruction-discovery-6a5ag3jq.js → repository-pgze7171.js} +5 -5
- package/dist/chunks/{instruction-discovery-pjvnvgmy.js → repository-pjvnvgmy.js} +1 -1
- package/dist/chunks/{instruction-discovery-1q5zb881.js → repository-pk7hbv6p.js} +24 -132
- package/dist/chunks/{instruction-discovery-pknna89w.js → repository-pknna89w.js} +1 -1
- package/dist/chunks/repository-prjw6x41.js +31 -0
- package/dist/chunks/{instruction-discovery-2daza0p7.js → repository-q0cdrezg.js} +14 -14
- package/dist/chunks/{instruction-discovery-qdyk8phn.js → repository-q6vgfyay.js} +6 -6
- package/dist/chunks/{instruction-discovery-36cgxzxf.js → repository-q76xcmv9.js} +16 -16
- package/dist/chunks/{instruction-discovery-4d8yn3gb.js → repository-q7jxq9y7.js} +20 -20
- package/dist/chunks/{instruction-discovery-2yez9773.js → repository-q7ngdz78.js} +24 -24
- package/dist/chunks/{instruction-discovery-qnc92qwc.js → repository-qnc92qwc.js} +1 -1
- package/dist/chunks/{instruction-discovery-n8vdnqrc.js → repository-qne3fa44.js} +5 -5
- package/dist/chunks/{instruction-discovery-qsdy395h.js → repository-qsdy395h.js} +1 -1
- package/dist/chunks/{instruction-discovery-cc4mqy7q.js → repository-qv02qg64.js} +12 -6
- package/dist/chunks/{instruction-discovery-k3c624dm.js → repository-qxjc9qry.js} +4 -4
- package/dist/chunks/{instruction-discovery-vm2gnf4v.js → repository-qy0n8417.js} +26 -26
- package/dist/chunks/{instruction-discovery-m58kmhef.js → repository-r3c58j5g.js} +6 -9
- package/dist/chunks/{instruction-discovery-e3bkmxas.js → repository-rb8xm6cm.js} +11 -11
- package/dist/chunks/{instruction-discovery-rdw6cm16.js → repository-rdw6cm16.js} +1 -1
- package/dist/chunks/{instruction-discovery-21201d4m.js → repository-rjfypheq.js} +27 -27
- package/dist/chunks/{instruction-discovery-bc819vt5.js → repository-rjsk0n41.js} +11 -11
- package/dist/chunks/{instruction-discovery-8faykdbn.js → repository-rk3ekeb4.js} +5 -5
- package/dist/chunks/{instruction-discovery-jw34hpx6.js → repository-rm4s95e7.js} +79 -79
- package/dist/chunks/{instruction-discovery-0n82x6dt.js → repository-rn938jk3.js} +39 -39
- package/dist/chunks/{instruction-discovery-geswxttb.js → repository-rpp7c75e.js} +48 -48
- package/dist/chunks/{instruction-discovery-4a973s6x.js → repository-s4075y1x.js} +5 -5
- package/dist/chunks/{instruction-discovery-42h9518d.js → repository-s8qvywtq.js} +14 -14
- package/dist/chunks/{instruction-discovery-jvy07h1s.js → repository-s8v3amej.js} +1 -1
- package/dist/chunks/{instruction-discovery-7ws0qf92.js → repository-s9nwmxxs.js} +29 -29
- package/dist/chunks/{instruction-discovery-h9zw7x04.js → repository-srhj5f56.js} +11 -11
- package/dist/chunks/{instruction-discovery-034ce5nj.js → repository-t5483b9c.js} +4 -4
- package/dist/chunks/{instruction-discovery-9t7a50xb.js → repository-t550f9t1.js} +4 -4
- package/dist/chunks/{instruction-discovery-3gc4y8jw.js → repository-t7wcnk30.js} +9 -9
- package/dist/chunks/{instruction-discovery-fagw50gs.js → repository-t7y8x8j8.js} +16 -16
- package/dist/chunks/{instruction-discovery-kgr5617j.js → repository-t8n7ymvq.js} +66 -46
- package/dist/chunks/{instruction-discovery-b1f75b2t.js → repository-tarna68p.js} +9 -9
- package/dist/chunks/{instruction-discovery-tazgh4e4.js → repository-tazgh4e4.js} +1 -1
- package/dist/chunks/{instruction-discovery-8sesv03m.js → repository-tbs2jyb2.js} +7 -7
- package/dist/chunks/{instruction-discovery-tcezcvh9.js → repository-tcezcvh9.js} +1 -1
- package/dist/chunks/{instruction-discovery-c5c0bz0t.js → repository-tdpndm1c.js} +5 -5
- package/dist/chunks/{instruction-discovery-tdstcens.js → repository-tdstcens.js} +1 -1
- package/dist/chunks/{instruction-discovery-ab44fxfx.js → repository-tg6e69q8.js} +5 -5
- package/dist/chunks/{instruction-discovery-pzxge5ds.js → repository-tgah08rb.js} +30 -30
- package/dist/chunks/{instruction-discovery-9prspse7.js → repository-tk5m56y0.js} +13 -13
- package/dist/chunks/{instruction-discovery-7wtms9gt.js → repository-tzy9a5tv.js} +30 -30
- package/dist/chunks/{instruction-discovery-adrzke39.js → repository-v0es1rhs.js} +9 -9
- package/dist/chunks/{instruction-discovery-p5pxx3ht.js → repository-ve1j3q85.js} +15 -15
- package/dist/chunks/{instruction-discovery-veqvce7d.js → repository-veqvce7d.js} +1 -1
- package/dist/chunks/{instruction-discovery-b2nc1zae.js → repository-vngdzw63.js} +19 -19
- package/dist/chunks/{instruction-discovery-0xcdhwc5.js → repository-vqkmcgyv.js} +3 -3
- package/dist/chunks/{instruction-discovery-5mmejq10.js → repository-vt8dt6j6.js} +30 -30
- package/dist/chunks/{instruction-discovery-vzs5sf6e.js → repository-vzs5sf6e.js} +1 -1
- package/dist/chunks/{instruction-discovery-w3wsvvr9.js → repository-w3wsvvr9.js} +1 -1
- package/dist/chunks/{instruction-discovery-609c7rjf.js → repository-w5ystqj3.js} +5 -5
- package/dist/chunks/{instruction-discovery-x5k8pkz3.js → repository-w6gqnbcy.js} +3 -3
- package/dist/chunks/{instruction-discovery-g6pt2ykv.js → repository-w7a2abxy.js} +17 -17
- package/dist/chunks/{instruction-discovery-kjcere04.js → repository-wb70vhte.js} +11 -11
- package/dist/chunks/{instruction-discovery-wd87259q.js → repository-wd87259q.js} +1 -1
- package/dist/chunks/{instruction-discovery-3j0eccra.js → repository-wnfszx78.js} +10 -10
- package/dist/chunks/{instruction-discovery-9vjnmhkc.js → repository-wnh11861.js} +15 -15
- package/dist/chunks/{instruction-discovery-fxt23bak.js → repository-x4k83k5f.js} +11 -11
- package/dist/chunks/{instruction-discovery-8r9kvmb6.js → repository-xhv84ab7.js} +25 -25
- package/dist/chunks/{instruction-discovery-xkntkrq7.js → repository-xkntkrq7.js} +2 -2
- package/dist/chunks/{instruction-discovery-br0fskr5.js → repository-xmy45d6e.js} +20 -20
- package/dist/chunks/{instruction-discovery-e709npfq.js → repository-xpwv3d90.js} +22 -22
- package/dist/chunks/{instruction-discovery-qnet8f1y.js → repository-xvvw76kz.js} +7 -7
- package/dist/chunks/{instruction-discovery-d737nyfv.js → repository-y16p1w2y.js} +9 -9
- package/dist/chunks/{instruction-discovery-y1fvbwt7.js → repository-y1fvbwt7.js} +1 -1
- package/dist/chunks/{instruction-discovery-gv15az23.js → repository-y1w7bwtd.js} +22 -22
- package/dist/chunks/{instruction-discovery-4g11qfmx.js → repository-y6brtjeh.js} +46 -41
- package/dist/chunks/repository-y6mhs71q.js +72 -0
- package/dist/chunks/{instruction-discovery-90gx0j5y.js → repository-ydszhw6d.js} +27 -27
- package/dist/chunks/{instruction-discovery-gb65a7a1.js → repository-yf33k1p3.js} +24 -24
- package/dist/chunks/{instruction-discovery-g2b38xbr.js → repository-yfe405ny.js} +13 -13
- package/dist/chunks/{instruction-discovery-e2jmw6zx.js → repository-yn96zvvk.js} +11 -11
- package/dist/chunks/{instruction-discovery-t9r88hzk.js → repository-yprc5htm.js} +24 -24
- package/dist/chunks/{instruction-discovery-386stjsv.js → repository-yqt58wae.js} +9 -9
- package/dist/chunks/{instruction-discovery-z0bkrqjs.js → repository-z0bkrqjs.js} +1 -1
- package/dist/chunks/{instruction-discovery-7pw8dncw.js → repository-z6b5w8cf.js} +4 -4
- package/dist/chunks/{instruction-discovery-3bc8czyk.js → repository-zd30eb5w.js} +5 -5
- package/dist/chunks/{instruction-discovery-y9e73xa5.js → repository-zhwzkc0c.js} +12 -12
- package/dist/chunks/{instruction-discovery-z468zaec.js → repository-zk46kswf.js} +15 -15
- package/dist/chunks/{instruction-discovery-zr2ceqn5.js → repository-zr2ceqn5.js} +1 -1
- package/dist/chunks/{instruction-discovery-7j2qha59.js → repository-zvjhkatg.js} +8 -8
- package/dist/chunks/{instruction-discovery-zxq2ej10.js → repository-zxq2ej10.js} +1 -1
- package/dist/chunks/{instruction-discovery-qygbw77c.js → repository-zyk1yjk8.js} +5 -5
- package/dist/codemode/catalog.js +1 -1
- package/dist/codemode/instructions.js +5 -5
- package/dist/codemode/tool.js +3 -3
- package/dist/codemode/web.js +1 -1
- package/dist/command.js +83 -83
- package/dist/config/discovery.js +82 -82
- package/dist/config/markdown.js +1 -1
- package/dist/config/normalize.js +99 -106
- package/dist/config/plugin/agent.js +118 -125
- package/dist/config/plugin/command.js +207 -215
- package/dist/config/plugin/compaction.js +154 -161
- package/dist/config/plugin/compatibility.js +134 -141
- package/dist/config/plugin/entry-observer.js +1 -1
- package/dist/config/plugin/formatter.js +117 -124
- package/dist/config/plugin/image.js +116 -123
- package/dist/config/plugin/instruction.js +90 -90
- package/dist/config/plugin/location-watcher.js +116 -123
- package/dist/config/plugin/mcp.js +125 -132
- package/dist/config/plugin/policy.js +117 -124
- package/dist/config/plugin/provider.js +116 -123
- package/dist/config/plugin/reference.js +118 -125
- package/dist/config/plugin/shell.js +116 -123
- package/dist/config/plugin/skill-file.js +102 -102
- package/dist/config/plugin/skill.js +137 -144
- package/dist/config/plugin/snapshot.js +116 -123
- package/dist/config/plugin/source.js +119 -126
- package/dist/config/plugin/tool-output.js +117 -125
- package/dist/config/plugin/websearch.js +115 -122
- package/dist/config/plugin/worktree.js +118 -125
- package/dist/config/variable.js +3 -3
- package/dist/config/watch.js +1 -1
- package/dist/config.js +119 -126
- package/dist/credential/sql.js +2 -2
- package/dist/credential.js +83 -83
- package/dist/database/database.js +66 -66
- package/dist/database/drizzle/effect-sqlite/driver.js +12 -12
- package/dist/database/drizzle/effect-sqlite/index.js +12 -12
- package/dist/database/drizzle/effect-sqlite/session.js +11 -11
- package/dist/database/drizzle/index.js +13 -13
- package/dist/database/drizzle/internal/drizzle-utils.js +1 -1
- package/dist/database/drizzle/sqlite-core/effect/count.js +1 -1
- package/dist/database/drizzle/sqlite-core/effect/db.js +9 -9
- package/dist/database/drizzle/sqlite-core/effect/delete.js +2 -2
- package/dist/database/drizzle/sqlite-core/effect/index.js +10 -10
- package/dist/database/drizzle/sqlite-core/effect/insert.js +2 -2
- package/dist/database/drizzle/sqlite-core/effect/query.js +1 -1
- package/dist/database/drizzle/sqlite-core/effect/raw.js +1 -1
- package/dist/database/drizzle/sqlite-core/effect/select.js +2 -2
- package/dist/database/drizzle/sqlite-core/effect/session.js +10 -10
- package/dist/database/drizzle/sqlite-core/effect/update.js +2 -2
- package/dist/database/drizzle.js +14 -14
- package/dist/database/migration/20260127222353_familiar_lady_ursula.js +1 -1
- package/dist/database/migration/20260211171708_add_project_commands.js +1 -1
- package/dist/database/migration/20260213144116_wakeful_the_professor.js +1 -1
- package/dist/database/migration/20260225215848_workspace.js +1 -1
- package/dist/database/migration/20260227213759_add_session_workspace_id.js +1 -1
- package/dist/database/migration/20260228203230_blue_harpoon.js +1 -1
- package/dist/database/migration/20260303231226_add_workspace_fields.js +1 -1
- package/dist/database/migration/20260309230000_move_org_to_state.js +1 -1
- package/dist/database/migration/20260312043431_session_message_cursor.js +1 -1
- package/dist/database/migration/20260323234822_events.js +1 -1
- package/dist/database/migration/20260410174513_workspace-name.js +1 -1
- package/dist/database/migration/20260413175956_chief_energizer.js +1 -1
- package/dist/database/migration/20260423070820_add_icon_url_override.js +1 -1
- package/dist/database/migration/20260427172553_slow_nightmare.js +1 -1
- package/dist/database/migration/20260428004200_add_session_path.js +1 -1
- package/dist/database/migration/20260501142318_next_venus.js +1 -1
- package/dist/database/migration/20260504145000_add_sync_owner.js +1 -1
- package/dist/database/migration/20260507164347_add_workspace_time.js +1 -1
- package/dist/database/migration/20260510033149_session_usage.js +1 -1
- package/dist/database/migration/20260511000411_data_migration_state.js +1 -1
- package/dist/database/migration/20260511173437_session-metadata.js +1 -1
- package/dist/database/migration/20260601010001_normalize_storage_paths.js +1 -1
- package/dist/database/migration/20260601202201_amazing_prowler.js +1 -1
- package/dist/database/migration/20260602002951_lowly_union_jack.js +1 -1
- package/dist/database/migration/20260602182828_add_project_directories.js +1 -1
- package/dist/database/migration/20260603001617_session_message_projection_indexes.js +1 -1
- package/dist/database/migration/20260603040000_session_message_projection_order.js +1 -1
- package/dist/database/migration/20260603141458_session_input_inbox.js +1 -1
- package/dist/database/migration/20260603160727_jittery_ezekiel_stane.js +1 -1
- package/dist/database/migration/20260604172448_event_sourced_session_input.js +1 -1
- package/dist/database/migration/20260605003541_add_session_context_snapshot.js +1 -1
- package/dist/database/migration/20260605042240_add_context_epoch_agent.js +1 -1
- package/dist/database/migration/20260611035744_credential.js +1 -1
- package/dist/database/migration/20260611192811_lush_chimera.js +1 -1
- package/dist/database/migration/20260612174303_project_dir_strategy.js +1 -1
- package/dist/database/migration/20260622142730_simplify_session_context_epoch.js +1 -1
- package/dist/database/migration/20260622170816_reset_v2_session_state.js +1 -1
- package/dist/database/migration/20260622202450_simplify_session_input.js +1 -1
- package/dist/database/migration/20260804233008_loose_psylocke.js +1 -1
- package/dist/database/migration/20260805200742_import_legacy_credentials.js +1 -1
- package/dist/database/migration/20260808023530_workspace_domain.js +1 -1
- package/dist/database/migration/20260811161259_execution_claim_attempts.js +1 -1
- package/dist/database/migration/20260812181746_session_inbox.js +1 -1
- package/dist/database/migration/20260812213948_worktree.js +1 -1
- package/dist/database/migration/20260819222447_session_viewed_state.js +1 -1
- package/dist/database/migration/20260823191254_nullable_workspace_binding.js +1 -1
- package/dist/database/migration/20260910120000_clear_v1_session_permission.js +1 -1
- package/dist/database/migration/20260923013825_project_time_active.js +1 -1
- package/dist/database/migration.gen.js +49 -49
- package/dist/database/migration.js +51 -51
- package/dist/database/path.js +2 -2
- package/dist/database/schema.gen.js +1 -1
- package/dist/database/schema.sql.js +1 -1
- package/dist/database/sqlite.bun.js +1 -1
- package/dist/database/sqlite.js +1 -1
- package/dist/database/sqlite.node.js +1 -1
- package/dist/database/sqlite.workerd.js +1 -1
- package/dist/database/v1-migration.bun.js +76 -76
- package/dist/database/v1-migration.js +1 -1
- package/dist/effect/app-node-builder.js +363 -372
- package/dist/effect/app-node-platform.js +2 -2
- package/dist/effect/keyed-mutex.js +1 -1
- package/dist/effect/websocket-constructor.js +1 -1
- package/dist/environment/driver.js +1 -1
- package/dist/environment/environment.js +93 -93
- package/dist/environment/exec-defaults.js +2 -2
- package/dist/environment/files.js +1 -1
- package/dist/environment/index.js +95 -95
- package/dist/environment/local.js +2 -2
- package/dist/environment/memory.js +2 -2
- package/dist/environment/unavailable.js +1 -1
- package/dist/event/sql.js +1 -1
- package/dist/event-logger.js +70 -70
- package/dist/file-access.js +100 -100
- package/dist/file-mutation.js +94 -94
- package/dist/file-retention.js +1 -1
- package/dist/filesystem/fff.bun.js +2 -2
- package/dist/filesystem/fff.js +1 -1
- package/dist/filesystem/fff.node.js +2 -2
- package/dist/filesystem/fff.workerd.js +2 -2
- package/dist/filesystem/location-watcher-policy.js +6 -6
- package/dist/filesystem/location-watcher.js +218 -226
- package/dist/filesystem/protected.js +1 -1
- package/dist/filesystem/search.js +97 -97
- package/dist/filesystem/watcher-binding.js +3 -3
- package/dist/filesystem/watcher.js +15 -15
- package/dist/filesystem.js +98 -98
- package/dist/form.js +80 -80
- package/dist/formatter/builtins.js +4 -4
- package/dist/formatter.js +87 -87
- package/dist/generate.js +101 -101
- package/dist/git.js +10 -10
- package/dist/github-copilot/chat/convert-to-openai-compatible-chat-messages.js +1 -1
- package/dist/github-copilot/chat/get-response-metadata.js +1 -1
- package/dist/github-copilot/chat/map-openai-compatible-finish-reason.js +1 -1
- package/dist/github-copilot/chat/openai-compatible-chat-language-model.js +7 -7
- package/dist/github-copilot/chat/openai-compatible-chat-options.js +1 -1
- package/dist/github-copilot/chat/openai-compatible-prepare-tools.js +1 -1
- package/dist/github-copilot/copilot-provider.js +17 -17
- package/dist/github-copilot/models.js +91 -91
- package/dist/github-copilot/openai-compatible-error.js +1 -1
- package/dist/github-copilot/responses/convert-to-openai-responses-input.js +1 -1
- package/dist/github-copilot/responses/map-openai-responses-finish-reason.js +1 -1
- package/dist/github-copilot/responses/openai-error.js +1 -1
- package/dist/github-copilot/responses/openai-responses-language-model.js +10 -10
- package/dist/github-copilot/responses/openai-responses-prepare-tools.js +6 -6
- package/dist/github-copilot/responses/tool/code-interpreter.js +1 -1
- package/dist/github-copilot/responses/tool/file-search.js +1 -1
- package/dist/github-copilot/responses/tool/image-generation.js +1 -1
- package/dist/github-copilot/responses/tool/web-search-preview.js +1 -1
- package/dist/github-copilot/responses/tool/web-search.js +1 -1
- package/dist/image/photon.js +2 -2
- package/dist/image.js +6 -6
- package/dist/instance/service.js +5 -5
- package/dist/instance.js +354 -363
- package/dist/instruction-discovery.js +85 -85
- package/dist/instructions/builtins.js +87 -87
- package/dist/instructions/index.js +3 -3
- package/dist/integration/connection.js +3 -3
- package/dist/integration.js +89 -89
- package/dist/job.js +74 -75
- package/dist/kv/sql.js +2 -2
- package/dist/kv.js +73 -73
- package/dist/location-activity.js +131 -132
- package/dist/location-lifecycle.js +107 -107
- package/dist/location-service-map.js +86 -86
- package/dist/location-services.js +351 -360
- package/dist/location.js +89 -89
- package/dist/managed-policy.js +5 -5
- package/dist/mcp/client.js +105 -101
- package/dist/mcp/index.js +107 -107
- package/dist/mcp/instructions.js +127 -127
- package/dist/mcp/oauth.js +92 -87
- package/dist/mcp/stdio.js +90 -90
- package/dist/mime.js +1 -1
- package/dist/modal/models.js +91 -91
- package/dist/model-resolver.js +98 -98
- package/dist/model.js +101 -99
- package/dist/models-dev.js +107 -107
- package/dist/oauth/page.js +1 -1
- package/dist/permission/saved.js +80 -80
- package/dist/permission/sql.js +5 -5
- package/dist/permission.js +115 -115
- package/dist/persistent-pty/binary.bun.js +3 -1
- package/dist/persistent-pty/binary.node.js +2 -0
- package/dist/persistent-pty/binary.workerd.js +2 -0
- package/dist/persistent-pty/daemon.js +1 -1
- package/dist/persistent-pty/index.js +89 -87
- package/dist/persistent-pty/pty-binding.js +1 -1
- package/dist/persistent-pty.js +75 -75
- package/dist/plugin/agent.js +104 -104
- package/dist/plugin/command.js +102 -102
- package/dist/plugin/hooks.js +5 -5
- package/dist/plugin/host.js +211 -219
- package/dist/plugin/identity.js +3 -3
- package/dist/plugin/instance.js +5 -5
- package/dist/plugin/internal.js +326 -335
- package/dist/plugin/mcp-codemode-defaults.js +3 -3
- package/dist/plugin/models-dev.js +96 -96
- package/dist/plugin/module.js +5 -5
- package/dist/plugin/optimize.js +4 -4
- package/dist/plugin/plan.js +102 -102
- package/dist/plugin/promise.js +1 -1
- package/dist/plugin/provider/amazon-bedrock.js +90 -90
- package/dist/plugin/provider/azure.js +117 -124
- package/dist/plugin/provider/cerebras.js +1 -1
- package/dist/plugin/provider/chatgpt.js +93 -93
- package/dist/plugin/provider/cloudflare-ai-gateway.js +113 -120
- package/dist/plugin/provider/cloudflare-workers-ai.js +114 -121
- package/dist/plugin/provider/cohere.js +2 -2
- package/dist/plugin/provider/configured.js +112 -119
- package/dist/plugin/provider/digitalocean.js +93 -93
- package/dist/plugin/provider/dynamic.js +2 -2
- package/dist/plugin/provider/factory.js +1 -1
- package/dist/plugin/provider/github-copilot.js +95 -95
- package/dist/plugin/provider/gitlab.js +93 -93
- package/dist/plugin/provider/google-vertex.js +90 -90
- package/dist/plugin/provider/kilo.js +1 -1
- package/dist/plugin/provider/llmgateway.js +78 -78
- package/dist/plugin/provider/lmstudio.js +116 -122
- package/dist/plugin/provider/local.js +118 -0
- package/dist/plugin/provider/modal.js +92 -92
- package/dist/plugin/provider/nvidia.js +1 -1
- package/dist/plugin/provider/ollama.js +116 -122
- package/dist/plugin/provider/openai.js +95 -95
- package/dist/plugin/provider/opencode.js +96 -96
- package/dist/plugin/provider/openrouter.js +91 -91
- package/dist/plugin/provider/perplexity.js +2 -2
- package/dist/plugin/provider/poe.js +79 -79
- package/dist/plugin/provider/prompt-cache-key.js +90 -90
- package/dist/plugin/provider/sap-ai-core.js +91 -91
- package/dist/plugin/provider/sdk-factory.js +1 -1
- package/dist/plugin/provider/snowflake-cortex.js +115 -122
- package/dist/plugin/provider/vercel.js +90 -90
- package/dist/plugin/provider/vllm.js +116 -122
- package/dist/plugin/provider/xai.js +91 -91
- package/dist/plugin/provider/zenmux.js +1 -1
- package/dist/plugin/provider.js +155 -163
- package/dist/plugin/sdk.js +76 -76
- package/dist/plugin/service.js +1 -1
- package/dist/plugin/skill.js +134 -141
- package/dist/plugin/source-directory.js +1 -1
- package/dist/plugin/supervisor.js +343 -352
- package/dist/plugin/tool-input-repair.js +4 -4
- package/dist/plugin/update.js +6 -6
- package/dist/plugin/vcs/git.js +86 -86
- package/dist/plugin/vcs/hg.js +86 -86
- package/dist/plugin/verbosity.js +93 -93
- package/dist/plugin/warming.js +114 -121
- package/dist/plugin/websearch/exa.js +7 -7
- package/dist/plugin/websearch/firecrawl.js +8 -8
- package/dist/plugin/websearch/index.js +9 -9
- package/dist/plugin/websearch/mcp.js +4 -4
- package/dist/plugin/websearch/parallel.js +8 -8
- package/dist/plugin/websearch/tavily.js +4 -4
- package/dist/plugin/websearch/tinyfish.js +8 -8
- package/dist/plugin.js +216 -224
- package/dist/project/schema.js +8 -8
- package/dist/project/sql.js +4 -4
- package/dist/project.js +90 -90
- package/dist/provider.js +101 -101
- package/dist/pty/protocol.js +1 -1
- package/dist/pty/ticket.js +1 -1
- package/dist/pty.js +89 -89
- package/dist/reference/instructions.js +85 -85
- package/dist/reference.js +91 -91
- package/dist/repository-cache.js +81 -81
- package/dist/repository.js +1 -1
- package/dist/ripgrep/binary.js +2 -2
- package/dist/ripgrep.js +95 -95
- package/dist/rpc.js +82 -82
- package/dist/schema.js +1 -1
- package/dist/session/affinity.js +1 -1
- package/dist/session/command.js +74 -74
- package/dist/session/compaction.js +133 -133
- package/dist/session/context.js +153 -153
- package/dist/session/diff.js +88 -88
- package/dist/session/environment.js +5 -5
- package/dist/session/error.js +7 -7
- package/dist/session/event.js +1 -1
- package/dist/session/execution/restart.js +212 -220
- package/dist/session/execution.js +127 -128
- package/dist/session/generate.js +152 -152
- package/dist/session/history.js +15 -15
- package/dist/session/inbox.js +88 -88
- package/dist/session/info.js +3 -3
- package/dist/session/instruction-entry.js +77 -77
- package/dist/session/instruction-state.js +8 -8
- package/dist/session/instructions.js +97 -97
- package/dist/session/message-updater.js +2 -2
- package/dist/session/message.js +1 -1
- package/dist/session/model-request.js +120 -120
- package/dist/session/model-transport.js +9 -9
- package/dist/session/move.js +125 -126
- package/dist/session/projector.js +84 -84
- package/dist/session/prompt.js +105 -105
- package/dist/session/provider-context.js +3 -3
- package/dist/session/revert.js +90 -93
- package/dist/session/run-coordinator.js +3 -3
- package/dist/session/runner/index.js +3 -3
- package/dist/session/runner/llm.js +222 -230
- package/dist/session/runner/max-steps.js +1 -1
- package/dist/session/runner/model.js +98 -98
- package/dist/session/runner/publish-llm-event.js +113 -3
- package/dist/session/runner/retry.js +4 -4
- package/dist/session/runner/step.js +123 -124
- package/dist/session/runner/to-llm-message.js +2 -2
- package/dist/session/schema.js +5 -5
- package/dist/session/session.js +162 -170
- package/dist/session/shell.js +130 -138
- package/dist/session/skill.js +103 -103
- package/dist/session/sql.js +5 -5
- package/dist/session/stats.js +73 -73
- package/dist/session/store.js +85 -85
- package/dist/session/subagent-completion.js +1 -1
- package/dist/session/subagent-job.js +203 -211
- package/dist/session/system-prompt.js +1 -1
- package/dist/session/title.js +151 -151
- package/dist/session/to-session-error.js +114 -112
- package/dist/session/transfer.js +210 -218
- package/dist/session/usage.js +1 -1
- package/dist/session.js +209 -217
- package/dist/shell/parse.js +6 -6
- package/dist/shell/result.js +1 -1
- package/dist/shell/scan.js +1561 -1030
- package/dist/shell/select.js +11 -11
- package/dist/shell.js +132 -140
- package/dist/skill/discovery.js +6 -6
- package/dist/skill/instructions.js +107 -107
- package/dist/skill.js +112 -112
- package/dist/snapshot.js +93 -93
- package/dist/state.js +1 -1
- package/dist/tool/html-markdown.js +1 -1
- package/dist/tool/http-body.js +1 -1
- package/dist/tool/mcp.js +128 -128
- package/dist/tool/plugin/edit.js +120 -120
- package/dist/tool/plugin/file-diff.js +1 -1
- package/dist/tool/plugin/glob.js +124 -124
- package/dist/tool/plugin/grep.js +124 -124
- package/dist/tool/plugin/mcp-resource.js +117 -117
- package/dist/tool/plugin/opencode.js +3 -3
- package/dist/tool/plugin/patch.js +122 -122
- package/dist/tool/plugin/question.js +103 -103
- package/dist/tool/plugin/read.js +125 -125
- package/dist/tool/plugin/shell.js +208 -216
- package/dist/tool/plugin/skill.js +111 -111
- package/dist/tool/plugin/subagent.js +212 -220
- package/dist/tool/plugin/webfetch.js +110 -110
- package/dist/tool/plugin/websearch.js +112 -112
- package/dist/tool/plugin/write.js +122 -122
- package/dist/tool/read-filesystem.js +100 -100
- package/dist/tool/runtime.js +1 -1
- package/dist/tool-output.js +7 -6
- package/dist/tool.js +14 -14
- package/dist/types/aisdk-native.d.ts +1 -0
- package/dist/types/instance/service.d.ts +2 -2
- package/dist/types/instance.d.ts +2 -2
- package/dist/types/job.d.ts +1 -1
- package/dist/types/location-service-map.d.ts +3 -3
- package/dist/types/mcp/oauth.d.ts +1 -10
- package/dist/types/model.d.ts +1 -0
- package/dist/types/persistent-pty/binary.bun.d.ts +1 -0
- package/dist/types/persistent-pty/binary.node.d.ts +1 -0
- package/dist/types/persistent-pty/binary.workerd.d.ts +1 -0
- package/dist/types/persistent-pty/daemon.d.ts +4 -4
- package/dist/types/persistent-pty/index.d.ts +3 -0
- package/dist/types/plugin/provider/chatgpt.d.ts +1 -1
- package/dist/types/plugin/provider/lmstudio.d.ts +2 -5
- package/dist/types/plugin/provider/local.d.ts +29 -0
- package/dist/types/plugin/provider/ollama.d.ts +2 -5
- package/dist/types/plugin/provider/vllm.d.ts +2 -5
- package/dist/types/session/command.d.ts +1 -1
- package/dist/types/session/compaction.d.ts +4 -1
- package/dist/types/session/diff.d.ts +2 -2
- package/dist/types/session/generate.d.ts +3 -2
- package/dist/types/session/prompt.d.ts +1 -1
- package/dist/types/session/revert.d.ts +2 -3
- package/dist/types/session/runner/index.d.ts +2 -1
- package/dist/types/session/session.d.ts +5 -5
- package/dist/types/session/shell.d.ts +1 -1
- package/dist/types/session/skill.d.ts +1 -1
- package/dist/types/session/to-session-error.d.ts +2 -0
- package/dist/types/session/transfer.d.ts +2 -3
- package/dist/types/session.d.ts +5 -4
- package/dist/types/shell/scan.d.ts +2 -1
- package/dist/types/tool-output.d.ts +1 -0
- package/dist/types/v1/config/migrate.d.ts +15 -319
- package/dist/types/vcs.d.ts +6 -0
- package/dist/types/worktree.d.ts +2 -1
- package/dist/util/error-summary.js +1 -1
- package/dist/util/error.js +1 -1
- package/dist/util/git-executable.js +2 -2
- package/dist/util/iife.js +1 -1
- package/dist/util/lazy.js +1 -1
- package/dist/util/slug.js +1 -1
- package/dist/util/token.js +1 -1
- package/dist/util/which.js +1 -1
- package/dist/util/wildcard.js +1 -1
- package/dist/v1/config/agent.js +7 -7
- package/dist/v1/config/command.js +3 -3
- package/dist/v1/config/error.js +4 -4
- package/dist/v1/config/mcp.js +4 -4
- package/dist/v1/config/migrate.js +96 -96
- package/dist/v1/config/permission.js +7 -7
- package/dist/v1/config/plugin.js +3 -3
- package/dist/v1/config/provider-options.js +1 -1
- package/dist/v1/config/provider.js +4 -4
- package/dist/variant.js +93 -93
- package/dist/vcs/patch.js +1 -1
- package/dist/vcs.js +91 -89
- package/dist/websearch.js +78 -78
- package/dist/wellknown/plugin.js +76 -76
- package/dist/wellknown.js +81 -81
- package/dist/workspace/driver.js +3 -3
- package/dist/workspace/sql.js +1 -1
- package/dist/workspace.js +80 -80
- package/dist/worktree/directory.js +2 -2
- package/dist/worktree/git.js +8 -8
- package/dist/worktree/sql.js +5 -5
- package/dist/worktree/strategies.js +89 -89
- package/dist/worktree.js +96 -96
- package/package.json +11 -13
- package/dist/chunks/instruction-discovery-21r38tys.js +0 -14
- package/dist/chunks/instruction-discovery-24x7sj2v.js +0 -137
- package/dist/chunks/instruction-discovery-669tq793.js +0 -15
- package/dist/chunks/instruction-discovery-bbx3sj05.js +0 -173
- package/dist/chunks/instruction-discovery-bscb95cy.js +0 -21
- package/dist/chunks/instruction-discovery-c49890bn.js +0 -194
- package/dist/chunks/instruction-discovery-fp86hj50.js +0 -145
- package/dist/chunks/instruction-discovery-j15mfg1p.js +0 -84
- package/dist/chunks/instruction-discovery-jzzgdak2.js +0 -34
- package/dist/chunks/instruction-discovery-mazbtkaa.js +0 -29
- package/dist/chunks/instruction-discovery-mp9mcqyr.js +0 -252
- package/dist/chunks/instruction-discovery-mvh4jj0m.js +0 -26
- package/dist/chunks/instruction-discovery-p813dxyq.js +0 -134
- package/dist/chunks/instruction-discovery-tvtrv512.js +0 -51
- package/dist/chunks/instruction-discovery-vncycja5.js +0 -21
- package/dist/chunks/instruction-discovery-wb3qhx4w.js +0 -507
- package/dist/chunks/instruction-discovery-yrhqyw5v.js +0 -15
- package/dist/filesystem/ignore.js +0 -58
- package/dist/id/id.js +0 -14
- package/dist/plugin/provider/gateway.js +0 -7
- package/dist/plugin/provider/venice.js +0 -7
- package/dist/types/filesystem/ignore.d.ts +0 -2
- package/dist/types/id/id.d.ts +0 -19
- package/dist/types/plugin/provider/gateway.d.ts +0 -1
- package/dist/types/plugin/provider/venice.d.ts +0 -1
- package/dist/types/v1/config/attachment.d.ts +0 -18
- package/dist/types/v1/config/config.d.ts +0 -1243
- package/dist/types/v1/config/formatter.d.ts +0 -15
- package/dist/types/v1/config/layout.d.ts +0 -4
- package/dist/types/v1/config/lsp.d.ts +0 -38
- package/dist/types/v1/config/server.d.ts +0 -10
- package/dist/types/v1/config/skills.d.ts +0 -7
- package/dist/v1/config/attachment.js +0 -11
- package/dist/v1/config/config.js +0 -23
- package/dist/v1/config/formatter.js +0 -10
- package/dist/v1/config/layout.js +0 -8
- package/dist/v1/config/lsp.js +0 -16
- package/dist/v1/config/server.js +0 -9
- package/dist/v1/config/skills.js +0 -8
- /package/dist/chunks/{instruction-discovery-0qkdqm5v.js → repository-0qkdqm5v.js} +0 -0
- /package/dist/chunks/{instruction-discovery-0zkw76rk.js → repository-0zkw76rk.js} +0 -0
- /package/dist/chunks/{instruction-discovery-17cy0kzp.js → repository-17cy0kzp.js} +0 -0
- /package/dist/chunks/{instruction-discovery-1cnp2v09.js → repository-1cnp2v09.js} +0 -0
- /package/dist/chunks/{instruction-discovery-1kg9ymc8.js → repository-1kg9ymc8.js} +0 -0
- /package/dist/chunks/{instruction-discovery-24dcb14g.js → repository-24dcb14g.js} +0 -0
- /package/dist/chunks/{instruction-discovery-2710q6r3.js → repository-2710q6r3.js} +0 -0
- /package/dist/chunks/{instruction-discovery-2axfhc9x.js → repository-2axfhc9x.js} +0 -0
- /package/dist/chunks/{instruction-discovery-2c3vjs8z.js → repository-2c3vjs8z.js} +0 -0
- /package/dist/chunks/{instruction-discovery-34c7v6d4.js → repository-34c7v6d4.js} +0 -0
- /package/dist/chunks/{instruction-discovery-359p4xyc.js → repository-359p4xyc.js} +0 -0
- /package/dist/chunks/{instruction-discovery-3asan66x.js → repository-3asan66x.js} +0 -0
- /package/dist/chunks/{instruction-discovery-3v8g72cx.js → repository-3v8g72cx.js} +0 -0
- /package/dist/chunks/{instruction-discovery-3w5fmr99.js → repository-3w5fmr99.js} +0 -0
- /package/dist/chunks/{instruction-discovery-3wcehsnq.js → repository-3wcehsnq.js} +0 -0
- /package/dist/chunks/{instruction-discovery-43n2bw4t.js → repository-43n2bw4t.js} +0 -0
- /package/dist/chunks/{instruction-discovery-4knz6hnm.js → repository-4knz6hnm.js} +0 -0
- /package/dist/chunks/{instruction-discovery-4vcrnpx2.js → repository-4vcrnpx2.js} +0 -0
- /package/dist/chunks/{instruction-discovery-4y7fprxs.js → repository-4y7fprxs.js} +0 -0
- /package/dist/chunks/{instruction-discovery-53557ph1.js → repository-53557ph1.js} +0 -0
- /package/dist/chunks/{instruction-discovery-550bvhaj.js → repository-550bvhaj.js} +0 -0
- /package/dist/chunks/{instruction-discovery-6prwharc.js → repository-6prwharc.js} +0 -0
- /package/dist/chunks/{instruction-discovery-7akdwqpd.js → repository-7akdwqpd.js} +0 -0
- /package/dist/chunks/{instruction-discovery-7m9af43g.js → repository-7m9af43g.js} +0 -0
- /package/dist/chunks/{instruction-discovery-822emrt2.js → repository-822emrt2.js} +0 -0
- /package/dist/chunks/{instruction-discovery-88xbtdfr.js → repository-88xbtdfr.js} +0 -0
- /package/dist/chunks/{instruction-discovery-8n3pysct.js → repository-8n3pysct.js} +0 -0
- /package/dist/chunks/{instruction-discovery-8wj87zfr.js → repository-8wj87zfr.js} +0 -0
- /package/dist/chunks/{instruction-discovery-9a4afbnw.js → repository-9a4afbnw.js} +0 -0
- /package/dist/chunks/{instruction-discovery-9rqn6x4v.js → repository-9rqn6x4v.js} +0 -0
- /package/dist/chunks/{instruction-discovery-a6k6eb26.js → repository-a6k6eb26.js} +0 -0
- /package/dist/chunks/{instruction-discovery-af5trqkr.js → repository-af5trqkr.js} +0 -0
- /package/dist/chunks/{instruction-discovery-afrmfg78.js → repository-afrmfg78.js} +0 -0
- /package/dist/chunks/{instruction-discovery-aqzs7mqg.js → repository-aqzs7mqg.js} +0 -0
- /package/dist/chunks/{instruction-discovery-atq7p7m5.js → repository-atq7p7m5.js} +0 -0
- /package/dist/chunks/{instruction-discovery-bkyjaxrp.js → repository-bkyjaxrp.js} +0 -0
- /package/dist/chunks/{instruction-discovery-bmr6ed5q.js → repository-bmr6ed5q.js} +0 -0
- /package/dist/chunks/{instruction-discovery-cf4snx6d.js → repository-cf4snx6d.js} +0 -0
- /package/dist/chunks/{instruction-discovery-cvy3z8tj.js → repository-cvy3z8tj.js} +0 -0
- /package/dist/chunks/{instruction-discovery-d9fn303g.js → repository-d9fn303g.js} +0 -0
- /package/dist/chunks/{instruction-discovery-d9jj8t3e.js → repository-d9jj8t3e.js} +0 -0
- /package/dist/chunks/{instruction-discovery-dajrwvna.js → repository-dajrwvna.js} +0 -0
- /package/dist/chunks/{instruction-discovery-dap0rakb.js → repository-dap0rakb.js} +0 -0
- /package/dist/chunks/{instruction-discovery-df08tz66.js → repository-df08tz66.js} +0 -0
- /package/dist/chunks/{instruction-discovery-dy18nga0.js → repository-dy18nga0.js} +0 -0
- /package/dist/chunks/{instruction-discovery-e5kj55wp.js → repository-e5kj55wp.js} +0 -0
- /package/dist/chunks/{instruction-discovery-e73j6tqm.js → repository-e73j6tqm.js} +0 -0
- /package/dist/chunks/{instruction-discovery-ec1grn59.js → repository-ec1grn59.js} +0 -0
- /package/dist/chunks/{instruction-discovery-eh3zwz77.js → repository-eh3zwz77.js} +0 -0
- /package/dist/chunks/{instruction-discovery-emrn6kk6.js → repository-emrn6kk6.js} +0 -0
- /package/dist/chunks/{instruction-discovery-f0mxakyp.js → repository-f0mxakyp.js} +0 -0
- /package/dist/chunks/{instruction-discovery-f6n9ztr4.js → repository-f6n9ztr4.js} +0 -0
- /package/dist/chunks/{instruction-discovery-faypxj3z.js → repository-faypxj3z.js} +0 -0
- /package/dist/chunks/{instruction-discovery-fd410y7t.js → repository-fd410y7t.js} +0 -0
- /package/dist/chunks/{instruction-discovery-fxgpk5d8.js → repository-fxgpk5d8.js} +0 -0
- /package/dist/chunks/{instruction-discovery-g4wezp1m.js → repository-g4wezp1m.js} +0 -0
- /package/dist/chunks/{instruction-discovery-g86h250q.js → repository-g86h250q.js} +0 -0
- /package/dist/chunks/{instruction-discovery-gebd4c9n.js → repository-gebd4c9n.js} +0 -0
- /package/dist/chunks/{instruction-discovery-gftt206x.js → repository-gftt206x.js} +0 -0
- /package/dist/chunks/{instruction-discovery-hk9envan.js → repository-hk9envan.js} +0 -0
- /package/dist/chunks/{instruction-discovery-j2ntwpah.js → repository-j2ntwpah.js} +0 -0
- /package/dist/chunks/{instruction-discovery-j5zkgpj8.js → repository-j5zkgpj8.js} +0 -0
- /package/dist/chunks/{instruction-discovery-jjkms2e6.js → repository-jjkms2e6.js} +0 -0
- /package/dist/chunks/{instruction-discovery-jr7sbwjy.js → repository-jr7sbwjy.js} +0 -0
- /package/dist/chunks/{instruction-discovery-jwfs4k6c.js → repository-jwfs4k6c.js} +0 -0
- /package/dist/chunks/{instruction-discovery-jzg6c2d5.js → repository-jzg6c2d5.js} +0 -0
- /package/dist/chunks/{instruction-discovery-mp448xyj.js → repository-mp448xyj.js} +0 -0
- /package/dist/chunks/{instruction-discovery-msx8hqn2.js → repository-msx8hqn2.js} +0 -0
- /package/dist/chunks/{instruction-discovery-n05xt0ee.js → repository-n05xt0ee.js} +0 -0
- /package/dist/chunks/{instruction-discovery-n3j8tn72.js → repository-n3j8tn72.js} +0 -0
- /package/dist/chunks/{instruction-discovery-njntx4h6.js → repository-njntx4h6.js} +0 -0
- /package/dist/chunks/{instruction-discovery-q3sfg36h.js → repository-q3sfg36h.js} +0 -0
- /package/dist/chunks/{instruction-discovery-q74kybfr.js → repository-q74kybfr.js} +0 -0
- /package/dist/chunks/{instruction-discovery-qaymkmh1.js → repository-qaymkmh1.js} +0 -0
- /package/dist/chunks/{instruction-discovery-qb87gjwd.js → repository-qb87gjwd.js} +0 -0
- /package/dist/chunks/{instruction-discovery-qfa1cgps.js → repository-qfa1cgps.js} +0 -0
- /package/dist/chunks/{instruction-discovery-qg3g05ea.js → repository-qg3g05ea.js} +0 -0
- /package/dist/chunks/{instruction-discovery-qrg20bc0.js → repository-qrg20bc0.js} +0 -0
- /package/dist/chunks/{instruction-discovery-rcb2kzg1.js → repository-rcb2kzg1.js} +0 -0
- /package/dist/chunks/{instruction-discovery-sdp7kfr6.js → repository-sdp7kfr6.js} +0 -0
- /package/dist/chunks/{instruction-discovery-ssg3fenm.js → repository-ssg3fenm.js} +0 -0
- /package/dist/chunks/{instruction-discovery-w803qqfp.js → repository-w803qqfp.js} +0 -0
- /package/dist/chunks/{instruction-discovery-wc3fc9cn.js → repository-wc3fc9cn.js} +0 -0
- /package/dist/chunks/{instruction-discovery-wer8tq1h.js → repository-wer8tq1h.js} +0 -0
- /package/dist/chunks/{instruction-discovery-wtztk69x.js → repository-wtztk69x.js} +0 -0
- /package/dist/chunks/{instruction-discovery-x0ckcb58.js → repository-x0ckcb58.js} +0 -0
- /package/dist/chunks/{instruction-discovery-x61499pn.js → repository-x61499pn.js} +0 -0
- /package/dist/chunks/{instruction-discovery-y44na4kk.js → repository-y44na4kk.js} +0 -0
- /package/dist/chunks/{instruction-discovery-y8cydn3q.js → repository-y8cydn3q.js} +0 -0
- /package/dist/chunks/{instruction-discovery-y8f7s663.js → repository-y8f7s663.js} +0 -0
- /package/dist/chunks/{instruction-discovery-ygaqb7jw.js → repository-ygaqb7jw.js} +0 -0
- /package/dist/chunks/{instruction-discovery-ym463w8f.js → repository-ym463w8f.js} +0 -0
- /package/dist/chunks/{instruction-discovery-z5v4ffb3.js → repository-z5v4ffb3.js} +0 -0
- /package/dist/chunks/{instruction-discovery-z9919s4g.js → repository-z9919s4g.js} +0 -0
package/dist/shell/scan.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
__export
|
|
3
|
-
} from "../chunks/
|
|
3
|
+
} from "../chunks/repository-9rqn6x4v.js";
|
|
4
4
|
|
|
5
5
|
// src/shell/scan.ts
|
|
6
6
|
var exports_scan = {};
|
|
@@ -10,716 +10,1271 @@ __export(exports_scan, {
|
|
|
10
10
|
scanPowerShell: () => scanPowerShell
|
|
11
11
|
});
|
|
12
12
|
var BASH_REDIRECTS = ["&>>", "&>", "<<<", "<<-", "<<", "<>", "<&", ">&", ">|", ">>", ">", "<"];
|
|
13
|
-
var
|
|
13
|
+
var BASH_LIST_OPERATORS = ["&&", "||", "|&"];
|
|
14
|
+
var BASH_CASE_OPERATORS = [";;&", ";;", ";&", ";|", ...BASH_LIST_OPERATORS];
|
|
15
|
+
var BASH_BINDING_BUILTINS = new Set([
|
|
16
|
+
"declare",
|
|
17
|
+
"typeset",
|
|
18
|
+
"local",
|
|
19
|
+
"export",
|
|
20
|
+
"readonly",
|
|
21
|
+
"private",
|
|
22
|
+
"unset",
|
|
23
|
+
"read",
|
|
24
|
+
"getln",
|
|
25
|
+
"vared",
|
|
26
|
+
"getopts",
|
|
27
|
+
"mapfile",
|
|
28
|
+
"readarray",
|
|
29
|
+
"compgen",
|
|
30
|
+
"zparseopts",
|
|
31
|
+
"zregexparse",
|
|
32
|
+
"zformat",
|
|
33
|
+
"zstyle",
|
|
34
|
+
"zstat",
|
|
35
|
+
"stat"
|
|
36
|
+
]);
|
|
37
|
+
var BASH_ARITHMETIC_COMPARISONS = new Set(["-eq", "-ne", "-lt", "-le", "-gt", "-ge"]);
|
|
38
|
+
var BASH_EXPANSION_RE = /\$(?:\\.|\\\n)*[({]|`/;
|
|
39
|
+
var BASH_ESCAPE_RE = /\\(?:x[\da-fA-F]{1,2}|[0-7]{1,3}|u[\da-fA-F]{1,4}|U[\da-fA-F]{1,8})/;
|
|
40
|
+
var BASH_ASSIGNMENT_DECLARATIONS = new Set(["declare", "typeset", "export", "readonly", "local"]);
|
|
41
|
+
var BASH_DECLARATIONS = new Set([...BASH_ASSIGNMENT_DECLARATIONS, "unset", "unsetenv"]);
|
|
42
|
+
var BASH_PRECOMMANDS = new Set(["builtin", "command", "time", "coproc", "!"]);
|
|
43
|
+
var ZSH_PRECOMMANDS = new Set(["noglob", "nocorrect", "exec", "-"]);
|
|
44
|
+
var ZSH_ARITHMETIC_BUILTINS = new Set([
|
|
45
|
+
"integer",
|
|
46
|
+
"float",
|
|
47
|
+
"exit",
|
|
48
|
+
"return",
|
|
49
|
+
"shift",
|
|
50
|
+
"break",
|
|
51
|
+
"continue",
|
|
52
|
+
"bye",
|
|
53
|
+
"logout"
|
|
54
|
+
]);
|
|
55
|
+
var BASH_NON_FUNCTION_KEYWORDS = new Set([
|
|
56
|
+
"if",
|
|
57
|
+
"for",
|
|
58
|
+
"select",
|
|
59
|
+
"case",
|
|
60
|
+
"then",
|
|
61
|
+
"elif",
|
|
62
|
+
"else",
|
|
63
|
+
"fi",
|
|
64
|
+
"do",
|
|
65
|
+
"done",
|
|
66
|
+
"in",
|
|
67
|
+
"esac"
|
|
68
|
+
]);
|
|
69
|
+
var BASH_UNIT_STARTS = "\\$'\"`<>";
|
|
14
70
|
var MAX_INPUT_LENGTH = 64 * 1024;
|
|
15
71
|
var MAX_SUBSTITUTION_DEPTH = 32;
|
|
16
|
-
|
|
17
|
-
|
|
72
|
+
var TOKEN_RE = /[A-Za-z_][A-Za-z0-9_]*(?=(?:\\\n)*(?:[ \t\n;|&()<>]|$))/y;
|
|
73
|
+
var BRACE_CLOSE_AHEAD_RE = /(?:\\\n)*(?:[ \t\n;&|()<>]|$)/y;
|
|
74
|
+
var SPACE_CONTINUATION_AHEAD_RE = /(?:\\\n)*[ \t\n]/y;
|
|
75
|
+
var NEGATION_AHEAD_RE = /(?:\\\n)*[ \t\n(]/y;
|
|
76
|
+
var COPROC_AHEAD_RE = /coproc(?:[ \t]|\\\n)+(?:--(?:[ \t]|\\\n)+)?(?:[A-Za-z_][A-Za-z0-9_]*(?:[ \t]|\\\n)+)?(?=(?:!(?:[ \t]|\\\n)*)*(?:[{(]|\[\[(?:\\\n)*[ \t\n]|(?:if|while|until|for|select|case|repeat)\b))/y;
|
|
77
|
+
var TIME_AHEAD_RE = /time(?:[ \t]|\\\n)+(?:-p(?:[ \t]|\\\n)+)?(?:--(?:[ \t]|\\\n)+)?(?=(?:!(?:[ \t]|\\\n)*)*(?:[{(]|\[\[(?:\\\n)*[ \t\n]|(?:if|while|until|for|select|case|repeat)\b))/y;
|
|
78
|
+
var FUNCTION_HEAD_RE = /(function[ \t](?:[ \t]|\\\n)*)?([A-Za-z_][\w.:+@%-]*)?(?:[ \t]|\\\n)*(\([ \t]*\))?((?:[ \t\n]|\\\n|#[^\n]*\n)*)/y;
|
|
79
|
+
var FUNCTION_BODY_RE = /[{(]|\[\[(?=(?:\\\n)*[ \t\n])|(?:if|while|until|for|select|case|repeat)(?=(?:\\\n)*(?:[ \t\n(]|$))/y;
|
|
80
|
+
var DO_AHEAD_RE = /(?:[ \t\n;]|\\\n|#[^\n]*(?:\n|$))*(?:do(?=(?:\\\n)*(?:[ \t\n;{(]|$))|\{(?=(?:\\\n)*[ \t\n]))/y;
|
|
81
|
+
var NOFORK_OPEN_RE = /\$\{(?:\\\n)*(?:[ \t\n]|\|)/y;
|
|
82
|
+
var ZSH_SAFE_FLAGS_RE = /\$\{\((?:[@AaBbCcDEfFikLMmNnOopqStUuVvWwXZz0-]|q[-+]?|[js]([^({[<\\])(?:(?!\1)[^)])*\1)*\)/y;
|
|
83
|
+
var ZSH_GLOB_MODIFIER_RE = /(?:[\^=~#+]|\\\n)*~/y;
|
|
84
|
+
var ZSH_SUBSCRIPT_RE = /\$(?:[\^=+~#]|\\\n)*(?:[A-Za-z_](?:[A-Za-z0-9_]|\\\n)*|[@*#?$!0-9-])(?:\\\n)*\[/y;
|
|
85
|
+
var LINE_CONTINUATION_RE = /(?:\\\n)*/y;
|
|
86
|
+
var PARAMETER_PREFIX_RE = /(?:\\\n)*(?:\([^)]*\))?(?:[!#^=+~]|\\\n)*/y;
|
|
87
|
+
var PARAMETER_NAME_RE = /(?:[A-Za-z_](?:[A-Za-z0-9_]|\\\n)*|\d(?:\d|\\\n)*|[@*#?$!-])(?:\\\n)*/y;
|
|
88
|
+
var PARAMETER_PROMPT_RE = /@(?:\\\n)*[EP](?:\\\n)*\}/y;
|
|
89
|
+
var BASH_ANSI_ESCAPES = {
|
|
90
|
+
a: "\x07",
|
|
91
|
+
b: "\b",
|
|
92
|
+
e: "\x1B",
|
|
93
|
+
E: "\x1B",
|
|
94
|
+
f: "\f",
|
|
95
|
+
n: `
|
|
96
|
+
`,
|
|
97
|
+
r: "\r",
|
|
98
|
+
t: "\t",
|
|
99
|
+
v: "\v",
|
|
100
|
+
"\\": "\\",
|
|
101
|
+
"'": "'",
|
|
102
|
+
'"': '"',
|
|
103
|
+
"?": "?"
|
|
104
|
+
};
|
|
105
|
+
function scan(input, dialect = "posix") {
|
|
106
|
+
if (input.length > MAX_INPUT_LENGTH)
|
|
107
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
108
|
+
const context = { remaining: MAX_INPUT_LENGTH * MAX_SUBSTITUTION_DEPTH, dialect };
|
|
109
|
+
const result = scanBash(input, 0, 0, context);
|
|
110
|
+
if (result.kind === "opaque")
|
|
111
|
+
return result;
|
|
112
|
+
if (context.boundDollar && context.boundOpen && context.variableSink)
|
|
113
|
+
return { kind: "opaque", reason: "dynamic-execution" };
|
|
114
|
+
return { kind: "scanned", commands: result.commands };
|
|
115
|
+
}
|
|
116
|
+
function bashStatement(state) {
|
|
117
|
+
const structure = state.structures.at(-1);
|
|
118
|
+
if (structure)
|
|
119
|
+
structure.count++;
|
|
18
120
|
}
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
|
|
121
|
+
function bashInHeader(state) {
|
|
122
|
+
const phase = state.structures.at(-1)?.phase;
|
|
123
|
+
return phase === "header" || phase === "pattern" || phase === "do";
|
|
124
|
+
}
|
|
125
|
+
function atCommandStart(state) {
|
|
126
|
+
return !state.words.length && !state.hasRedirect && !state.compoundEnd && !bashInHeader(state);
|
|
127
|
+
}
|
|
128
|
+
function pending(state) {
|
|
129
|
+
return state.wordStarted || state.words.length > 0 || state.hasRedirect || state.compoundEnd;
|
|
130
|
+
}
|
|
131
|
+
function endBashList(state) {
|
|
132
|
+
if (pending(state))
|
|
133
|
+
finishBashCommand(state);
|
|
134
|
+
return !state.dangling;
|
|
135
|
+
}
|
|
136
|
+
function closeBashList(state, end) {
|
|
137
|
+
if (!endBashList(state))
|
|
22
138
|
return { kind: "opaque", reason: "invalid-structure" };
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
139
|
+
if (state.invalid)
|
|
140
|
+
return { kind: "opaque", reason: state.invalid };
|
|
141
|
+
if (state.structures.length)
|
|
142
|
+
return { kind: "opaque", reason: "compound-command" };
|
|
143
|
+
return { kind: "scanned", commands: state.commands, end };
|
|
144
|
+
}
|
|
145
|
+
function finishBashWord(state) {
|
|
146
|
+
if (!state.wordStarted)
|
|
147
|
+
return;
|
|
148
|
+
if (/PS4/.test(state.word))
|
|
149
|
+
state.context.variableSink = true;
|
|
150
|
+
const evaluation = bashWordEvaluation(state);
|
|
151
|
+
if (state.context.dialect !== "bash" && (/(?:READ)?NULLCMD/.test(state.word) || (state.assignmentWord || evaluation === "binding") && /^(?:-[A-Za-z]*v)?(?:(?:dis_)?(?:functions|[gs]?aliases)|options|commands)(?:\+?=|\[|$)/.test(state.word)))
|
|
152
|
+
state.invalid ??= "dynamic-execution";
|
|
153
|
+
if (evaluation && bashEvaluatesExpansion(state, evaluation, state.context))
|
|
154
|
+
state.invalid ??= "dynamic-execution";
|
|
155
|
+
if (state.outer)
|
|
156
|
+
state.outer.output += ` ${state.literal} ${state.output}`;
|
|
157
|
+
const structure = state.structures.at(-1);
|
|
158
|
+
const repeatHeader = structure?.kind === "repeat" && structure.phase === "header";
|
|
159
|
+
if (!state.redirectTarget && repeatHeader)
|
|
160
|
+
structure.phase = "do";
|
|
161
|
+
if (!state.redirectTarget && !repeatHeader) {
|
|
162
|
+
if (!state.assignmentWord && state.commandWordIndex < 0)
|
|
163
|
+
state.commandWordIndex = state.words.length;
|
|
164
|
+
state.commandStart ??= state.wordStart;
|
|
165
|
+
state.words.push(state.word);
|
|
166
|
+
state.rawWords.push(state.input.slice(state.wordStart, state.wordEnd));
|
|
167
|
+
state.commandEnd = state.wordEnd;
|
|
168
|
+
}
|
|
169
|
+
state.redirectTarget = false;
|
|
170
|
+
state.hereString = false;
|
|
171
|
+
state.word = "";
|
|
172
|
+
state.literal = "";
|
|
173
|
+
state.output = "";
|
|
174
|
+
state.wordStarted = false;
|
|
175
|
+
state.assignmentWord = false;
|
|
176
|
+
state.assignmentHeadUnsafe = false;
|
|
177
|
+
}
|
|
178
|
+
function bashWordEvaluation(state) {
|
|
179
|
+
if (state.redirectTarget)
|
|
180
|
+
return state.hereString ? "deferred" : undefined;
|
|
181
|
+
const structure = state.structures.at(-1);
|
|
182
|
+
if (structure?.kind === "repeat" && structure.phase === "header")
|
|
183
|
+
return "arithmetic";
|
|
184
|
+
if (structure?.kind === "for" && structure.phase === "header" && structure.sawIn)
|
|
185
|
+
return "deferred";
|
|
186
|
+
if (state.commandWordIndex < 0)
|
|
187
|
+
return state.assignmentWord ? "deferred" : undefined;
|
|
188
|
+
const name = bashBuiltinIndex(state);
|
|
189
|
+
const command = state.words[name];
|
|
190
|
+
if (command === undefined)
|
|
191
|
+
return;
|
|
192
|
+
if (command === "let" || state.context.dialect !== "bash" && ZSH_ARITHMETIC_BUILTINS.has(command))
|
|
193
|
+
return "arithmetic";
|
|
194
|
+
if (command === "set")
|
|
195
|
+
return state.words.slice(name + 1).some((word) => /^[-+][A-Za-z0-9]*A/.test(word)) ? "binding" : "deferred";
|
|
196
|
+
if (BASH_BINDING_BUILTINS.has(command)) {
|
|
197
|
+
const options = state.words.slice(name + 1);
|
|
198
|
+
if (options.some((word) => word.startsWith("-") && /[EFin]/.test(word)))
|
|
199
|
+
return "arithmetic";
|
|
200
|
+
if (state.assignmentWord && BASH_ASSIGNMENT_DECLARATIONS.has(command) && options.every((word) => !word.startsWith("-")) && (command === "export" || command === "readonly" || state.context.dialect === "zsh" || !/\+?=(?:\(|[$`])/.test(state.word)))
|
|
201
|
+
return "deferred";
|
|
202
|
+
return "binding";
|
|
203
|
+
}
|
|
204
|
+
if (command === "printf" || command === "print") {
|
|
205
|
+
const options = [...state.words.slice(name + 1), state.word];
|
|
206
|
+
const flag = command === "print" ? /^-[A-Za-z]*v/ : /^-v/;
|
|
207
|
+
return options.some((word) => flag.test(word)) ? "binding" : undefined;
|
|
208
|
+
}
|
|
209
|
+
if (command === "wait")
|
|
210
|
+
return /^-[nf]*p/.test(state.word) || /^-[nf]*p$/.test(state.words.at(-1) ?? "") ? "binding" : undefined;
|
|
211
|
+
if (command === "test" || command === "[") {
|
|
212
|
+
if (state.words.at(-1) === "-v")
|
|
213
|
+
return "binding";
|
|
214
|
+
if (state.context.dialect !== "bash" && state.words.at(-1) === "-t")
|
|
215
|
+
return "arithmetic";
|
|
216
|
+
}
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
function bashBuiltinIndex(state) {
|
|
220
|
+
let name = state.commandWordIndex;
|
|
221
|
+
while (BASH_PRECOMMANDS.has(state.words[name] ?? "") || state.context.dialect !== "bash" && ZSH_PRECOMMANDS.has(state.words[name] ?? "")) {
|
|
222
|
+
const precommand = state.words[name++];
|
|
223
|
+
while (precommand !== "-" && state.words[name]?.startsWith("-")) {
|
|
224
|
+
if (precommand === "exec" && /^-[cl]*a$/.test(state.words[name]))
|
|
225
|
+
name++;
|
|
226
|
+
name++;
|
|
71
227
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
228
|
+
}
|
|
229
|
+
return name;
|
|
230
|
+
}
|
|
231
|
+
function finishBashCommand(state, boundary = false) {
|
|
232
|
+
finishBashWord(state);
|
|
233
|
+
if (state.redirectTarget)
|
|
234
|
+
state.invalid ??= "invalid-redirect";
|
|
235
|
+
state.redirectTarget = false;
|
|
236
|
+
if (state.compoundEnd && state.words.length > 0)
|
|
237
|
+
state.invalid ??= "invalid-structure";
|
|
238
|
+
const name = state.commandWordIndex;
|
|
239
|
+
const inHeader = bashInHeader(state);
|
|
240
|
+
if (name >= 0 && !state.words[name])
|
|
241
|
+
state.invalid ??= "invalid-structure";
|
|
242
|
+
if (name >= 0 && !inHeader) {
|
|
243
|
+
const resource = state.input.slice(state.commandStart, state.resourceEnd ?? state.wordEnd).replace(/^[ \t\n]+|[ \t\n]+$/g, "");
|
|
244
|
+
const command = {
|
|
245
|
+
resource,
|
|
246
|
+
words: state.words.slice(name),
|
|
247
|
+
rawWords: state.rawWords.slice(name),
|
|
248
|
+
...name === 0 && BASH_DECLARATIONS.has(state.rawWords[0]) && resource.startsWith(state.rawWords[0]) ? { declaration: true } : {},
|
|
249
|
+
...state.redirectWordCount !== undefined && state.redirectWordCount < state.words.length ? { redirectWordCount: state.redirectWordCount - name } : {}
|
|
250
|
+
};
|
|
251
|
+
state.commands.push(command);
|
|
252
|
+
const builtin = bashBuiltinIndex(state);
|
|
253
|
+
const builtinName = state.words[builtin];
|
|
254
|
+
const builtinArgs = state.words.slice(builtin + 1);
|
|
255
|
+
if (builtinName === "eval")
|
|
256
|
+
state.context.variableSink = true;
|
|
257
|
+
if (builtinName === "set" && builtinArgs.some((word) => /^-[A-Za-z0-9]*k/.test(word) || word === "keyword"))
|
|
258
|
+
state.invalid ??= "dynamic-execution";
|
|
259
|
+
if (builtinName === "alias" && builtinArgs.some((word) => word.includes("=")))
|
|
260
|
+
state.invalid ??= "dynamic-execution";
|
|
261
|
+
if (state.context.dialect !== "bash" && (builtinName === "emulate" || (builtinName === "setopt" || builtinName === "unsetopt" || builtinName === "set" && builtinArgs.some((word) => /^[-+][A-Za-z0-9]*o/.test(word))) && builtinArgs.some((word) => /^-[A-Za-z0-9]*m/.test(word) || /^(?:no)?(?:globsubst|kshglob|promptsubst|promptvars|aliases)$/.test(word.replace(/^[-+][A-Za-z0-9]*?o/i, "").toLowerCase().replace(/[_-]/g, "")))))
|
|
262
|
+
state.invalid ??= "dynamic-execution";
|
|
263
|
+
if (state.context.dialect !== "zsh" && builtinName === "compgen" && builtinArgs.some((word) => word.startsWith("-") && /[CF]/.test(word)))
|
|
264
|
+
state.invalid ??= "dynamic-execution";
|
|
265
|
+
if (BASH_BINDING_BUILTINS.has(builtinName ?? "")) {
|
|
266
|
+
for (const heredoc of state.heredocs)
|
|
267
|
+
heredoc.binding ??= true;
|
|
268
|
+
}
|
|
269
|
+
if (state.resourceEnd === undefined) {
|
|
270
|
+
for (const heredoc of state.heredocs) {
|
|
271
|
+
if (heredoc.command)
|
|
272
|
+
continue;
|
|
273
|
+
heredoc.command = command;
|
|
274
|
+
heredoc.start = state.commandStart;
|
|
107
275
|
}
|
|
108
|
-
} else if (!header() && !compoundEnd && (hasRedirect || boundary || separated)) {
|
|
109
|
-
const assignmentOnly = assignmentWords.length > 0 && assignmentWords.every(Boolean);
|
|
110
|
-
if (!assignmentOnly && !hasRedirect)
|
|
111
|
-
invalidStructure = true;
|
|
112
276
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
277
|
+
}
|
|
278
|
+
if (boundary && !state.words.length && !state.hasRedirect && !state.compoundEnd && !inHeader)
|
|
279
|
+
state.invalid ??= "invalid-structure";
|
|
280
|
+
if (state.words.length > (state.ampersandRedirectWords ?? Infinity))
|
|
281
|
+
state.invalid ??= "invalid-redirect";
|
|
282
|
+
state.commands.push(...state.nestedCommands.splice(0));
|
|
283
|
+
if (!inHeader && (state.words.length > 0 || state.hasRedirect))
|
|
284
|
+
bashStatement(state);
|
|
285
|
+
state.words.length = 0;
|
|
286
|
+
state.rawWords.length = 0;
|
|
287
|
+
state.commandWordIndex = -1;
|
|
288
|
+
state.commandStart = undefined;
|
|
289
|
+
state.hasRedirect = false;
|
|
290
|
+
state.resourceEnd = undefined;
|
|
291
|
+
state.redirectWordCount = undefined;
|
|
292
|
+
state.ampersandRedirectWords = undefined;
|
|
293
|
+
state.compoundEnd = false;
|
|
294
|
+
state.dangling = false;
|
|
295
|
+
}
|
|
296
|
+
function scanBash(input, start, depth, context, close, heredocs, outer) {
|
|
297
|
+
if (depth > MAX_SUBSTITUTION_DEPTH || context.remaining < 0)
|
|
298
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
299
|
+
const state = {
|
|
300
|
+
input,
|
|
301
|
+
context,
|
|
302
|
+
commands: [],
|
|
303
|
+
nestedCommands: [],
|
|
304
|
+
words: [],
|
|
305
|
+
rawWords: [],
|
|
306
|
+
heredocs: heredocs ?? [],
|
|
307
|
+
structures: [],
|
|
308
|
+
word: "",
|
|
309
|
+
literal: "",
|
|
310
|
+
output: "",
|
|
311
|
+
wordStarted: false,
|
|
312
|
+
wordStart: start,
|
|
313
|
+
wordEnd: start,
|
|
314
|
+
commandStart: undefined,
|
|
315
|
+
commandEnd: start,
|
|
316
|
+
resourceEnd: undefined,
|
|
317
|
+
redirectWordCount: undefined,
|
|
318
|
+
ampersandRedirectWords: undefined,
|
|
319
|
+
commandWordIndex: -1,
|
|
320
|
+
assignmentWord: false,
|
|
321
|
+
assignmentHeadUnsafe: false,
|
|
322
|
+
invalid: undefined,
|
|
323
|
+
redirectTarget: false,
|
|
324
|
+
hereString: false,
|
|
325
|
+
hasRedirect: false,
|
|
326
|
+
compoundEnd: false,
|
|
327
|
+
dangling: false,
|
|
328
|
+
outer
|
|
124
329
|
};
|
|
125
|
-
for (let index =
|
|
330
|
+
for (let index = start;index < input.length; index++) {
|
|
331
|
+
if (--context.remaining < 0)
|
|
332
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
126
333
|
const char = input[index];
|
|
127
|
-
if (
|
|
128
|
-
|
|
129
|
-
|
|
334
|
+
if (char === "\\" && input[index + 1] === `
|
|
335
|
+
`) {
|
|
336
|
+
index++;
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
if (!state.wordStarted) {
|
|
340
|
+
state.wordStart = index;
|
|
130
341
|
if (char === " " || char === "\t")
|
|
131
342
|
continue;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (structure?.phase === "pattern" && (char === "(" || char === "|"))
|
|
142
|
-
continue;
|
|
143
|
-
if (structure?.phase === "pattern" && char === ")") {
|
|
144
|
-
finishCommand();
|
|
145
|
-
structure.phase = "body";
|
|
146
|
-
structure.count = 0;
|
|
147
|
-
segment = index + 1;
|
|
148
|
-
continue;
|
|
149
|
-
}
|
|
150
|
-
if (structure?.kind === "for" && structure.phase === "header" && char === "(" && input[index + 1] !== "(") {
|
|
151
|
-
const values = bashExpansion(input, index, depth, "array");
|
|
152
|
-
if (!values)
|
|
153
|
-
return { kind: "opaque", reason: "compound-command" };
|
|
154
|
-
finishCommand();
|
|
155
|
-
const failure = addSubstitutions(values);
|
|
156
|
-
if (failure)
|
|
157
|
-
return failure;
|
|
158
|
-
commands.push(...nestedCommands.splice(0));
|
|
159
|
-
structure.phase = "do";
|
|
160
|
-
if (!/^(?:[ \t\n;]|\\\n|#[^\n]*(?:\n|$))*do(?=[ \t\n;]|$)/.test(input.slice(values.end + 1)))
|
|
161
|
-
structures.pop();
|
|
162
|
-
index = values.end;
|
|
163
|
-
segment = index + 1;
|
|
164
|
-
continue;
|
|
165
|
-
}
|
|
166
|
-
if (!words.length && !hasRedirect && !compoundEnd) {
|
|
167
|
-
const definition = bashFunctionHead(input, index);
|
|
168
|
-
if (definition && !header()) {
|
|
169
|
-
index += definition.length - 1;
|
|
170
|
-
segment = index + 1;
|
|
171
|
-
continue;
|
|
172
|
-
}
|
|
173
|
-
if (!header() && (token === "if" || token === "while" || token === "until" || token === "for" || token === "select" || token === "case")) {
|
|
174
|
-
if (depth + structures.length >= MAX_SUBSTITUTION_DEPTH)
|
|
175
|
-
return { kind: "opaque", reason: "compound-command" };
|
|
176
|
-
structures.push({
|
|
177
|
-
kind: token === "select" ? "for" : token,
|
|
178
|
-
phase: ["for", "select", "case"].includes(token) ? "header" : "condition",
|
|
179
|
-
count: 0
|
|
180
|
-
});
|
|
181
|
-
index += token.length - 1;
|
|
182
|
-
segment = index + 1;
|
|
183
|
-
inList = false;
|
|
184
|
-
continue;
|
|
185
|
-
}
|
|
186
|
-
if (token && ["then", "elif", "else", "fi", "do", "done", "esac"].includes(token) && (!header() || token === "do" && structure?.phase === "do" || token === "esac" && structure?.phase === "pattern")) {
|
|
187
|
-
if (!structure || dangling)
|
|
188
|
-
return { kind: "opaque", reason: "compound-command" };
|
|
189
|
-
if (token === "then") {
|
|
190
|
-
if (structure.kind !== "if" || structure.phase !== "condition" || !structure.count)
|
|
191
|
-
return { kind: "opaque", reason: "compound-command" };
|
|
192
|
-
structure.phase = "body";
|
|
193
|
-
} else if (token === "elif" || token === "else") {
|
|
194
|
-
if (structure.kind !== "if" || structure.phase !== "body" || !structure.count || structure.sawElse)
|
|
195
|
-
return { kind: "opaque", reason: "compound-command" };
|
|
196
|
-
structure.phase = token === "elif" ? "condition" : "body";
|
|
197
|
-
structure.sawElse = token === "else";
|
|
198
|
-
} else if (token === "do") {
|
|
199
|
-
if (!["for", "while", "until"].includes(structure.kind) || !["condition", "do"].includes(structure.phase) || structure.kind !== "for" && !structure.count)
|
|
200
|
-
return { kind: "opaque", reason: "compound-command" };
|
|
201
|
-
structure.phase = "body";
|
|
202
|
-
} else {
|
|
203
|
-
if (token === "fi" && (structure.kind !== "if" || structure.phase !== "body" || !structure.count) || token === "done" && (!["for", "while", "until"].includes(structure.kind) || structure.phase !== "body" || !structure.count) || token === "esac" && (structure.kind !== "case" || structure.phase === "header"))
|
|
204
|
-
return { kind: "opaque", reason: "compound-command" };
|
|
205
|
-
structures.pop();
|
|
206
|
-
statement();
|
|
207
|
-
compoundEnd = true;
|
|
208
|
-
dangling = false;
|
|
209
|
-
}
|
|
210
|
-
structure.count = 0;
|
|
211
|
-
index += token.length - 1;
|
|
212
|
-
segment = index + 1;
|
|
213
|
-
inList = false;
|
|
214
|
-
continue;
|
|
215
|
-
}
|
|
216
|
-
if (!header() && (char === "!" && /[ \t\n]/.test(input[index + 1] ?? "") || token === "coproc" && /^coproc[ \t]+(?:[A-Za-z_][A-Za-z0-9_]*[ \t]+)?(?:[{(]|(?:if|while|until|for|case)\b)/.test(input.slice(index)) || token === "time" && /^time[ \t]+(?:-p[ \t]+)?(?:[{(]|(?:if|while|until|for|case)\b)/.test(input.slice(index)))) {
|
|
217
|
-
index += token ? token.length - 1 : 0;
|
|
218
|
-
if (token === "time")
|
|
219
|
-
index += /^[ \t]+-p\b/.exec(input.slice(index + 1))?.[0].length ?? 0;
|
|
220
|
-
if (token === "coproc")
|
|
221
|
-
index += /^[ \t]+[A-Za-z_][A-Za-z0-9_]*[ \t]+(?=[{(]|(?:if|while|until|for|case)\b)/.exec(input.slice(index + 1))?.[0].length ?? 0;
|
|
222
|
-
segment = index + 1;
|
|
223
|
-
continue;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
if ((!words.length && !hasRedirect && !header() || structure?.kind === "for" && structure.phase === "header") && input.startsWith("((", index)) {
|
|
227
|
-
const expression = bashExpansion(input, index, depth, "arithmetic");
|
|
228
|
-
if (!expression)
|
|
229
|
-
return { kind: "opaque", reason: "invalid-structure" };
|
|
230
|
-
const failure = addSubstitutions(expression);
|
|
231
|
-
if (failure)
|
|
232
|
-
return failure;
|
|
233
|
-
commands.push(...nestedCommands.splice(0));
|
|
234
|
-
statement();
|
|
235
|
-
compoundEnd = !header();
|
|
236
|
-
dangling = false;
|
|
237
|
-
index = expression.end;
|
|
238
|
-
segment = index + 1;
|
|
239
|
-
continue;
|
|
240
|
-
}
|
|
241
|
-
if (!words.length && !hasRedirect && !header() && (char === "(" || char === "{" && /[ \t\n]/.test(input[index + 1] ?? ""))) {
|
|
242
|
-
const group = bashDelimited(input, index, depth);
|
|
243
|
-
if (!group || !group.source.trim())
|
|
244
|
-
return { kind: "opaque", reason: "invalid-structure" };
|
|
245
|
-
const result = scanBash(group.source, depth + 1, budget);
|
|
246
|
-
if (result.kind === "opaque")
|
|
247
|
-
return result;
|
|
248
|
-
commands.push(...result.commands);
|
|
249
|
-
statement();
|
|
250
|
-
compoundEnd = true;
|
|
251
|
-
dangling = false;
|
|
252
|
-
index = group.end;
|
|
253
|
-
segment = index + 1;
|
|
343
|
+
if (char === "}" && state.words.length === 0 && !state.redirectTarget && (close === "}" || close === "nofork") && state.structures.length === 0 && (heredocs !== undefined || state.heredocs.length === 0) && (close === "nofork" || (BRACE_CLOSE_AHEAD_RE.lastIndex = index + 1, BRACE_CLOSE_AHEAD_RE.test(input))))
|
|
344
|
+
return closeBashList(state, index);
|
|
345
|
+
if (char === "}")
|
|
346
|
+
return { kind: "opaque", reason: state.structures.length ? "compound-command" : "invalid-structure" };
|
|
347
|
+
const step = scanBashCommandStart(state, index, depth, context);
|
|
348
|
+
if (typeof step === "object")
|
|
349
|
+
return step;
|
|
350
|
+
if (step !== undefined) {
|
|
351
|
+
index = step;
|
|
254
352
|
continue;
|
|
255
353
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
354
|
+
}
|
|
355
|
+
if (char === "\\" && index + 1 >= input.length)
|
|
356
|
+
return { kind: "opaque", reason: "unterminated-escape" };
|
|
357
|
+
if (!state.assignmentWord && (`'"\\`.includes(char) || char === "$" && (input[index + 1] === "'" || input[index + 1] === '"')))
|
|
358
|
+
state.assignmentHeadUnsafe = true;
|
|
359
|
+
const inCasePattern = state.structures.at(-1)?.phase === "pattern";
|
|
360
|
+
const array = (char === "=" || char === "(") && state.assignmentWord && state.word.length > 1 && state.word.endsWith("=") && !state.word.endsWith("==") && (state.commandWordIndex < 0 || BASH_ASSIGNMENT_DECLARATIONS.has(state.rawWords[state.commandWordIndex]));
|
|
361
|
+
if (char === "=" && (!state.wordStarted || array) && input[index + 1] === "(") {
|
|
362
|
+
const end = scanBashNested(input, index + 2, depth, context, state.nestedCommands, ")");
|
|
363
|
+
if (typeof end === "object")
|
|
364
|
+
return end;
|
|
365
|
+
state.wordStarted = true;
|
|
366
|
+
state.word += input.slice(index, end + 1);
|
|
367
|
+
index = end;
|
|
368
|
+
state.wordEnd = index + 1;
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
const unit = BASH_UNIT_STARTS.includes(char) ? scanBashUnit(input, index, depth, context, state.nestedCommands, "word", !state.assignmentWord && state.commandWordIndex >= 0 && !BASH_DECLARATIONS.has(state.rawWords[0]), state) : undefined;
|
|
372
|
+
if (typeof unit === "object")
|
|
373
|
+
return unit;
|
|
374
|
+
if (unit !== undefined) {
|
|
375
|
+
state.wordStarted = true;
|
|
376
|
+
index = unit;
|
|
377
|
+
state.wordEnd = index + 1;
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
if (char === "[" && !inCasePattern && !state.assignmentWord && !state.assignmentHeadUnsafe && state.commandWordIndex < 0 && /^[A-Za-z_][A-Za-z0-9_]*$/.test(state.word)) {
|
|
381
|
+
const subscript = [];
|
|
382
|
+
const end = scanBashSubscript(input, index + 1, depth, context, subscript, BASH_SPANS.assignmentSubscript);
|
|
383
|
+
if (typeof end === "object")
|
|
384
|
+
return end;
|
|
385
|
+
const assign = bashOperator(input, end + 1, ["+=", "="]);
|
|
386
|
+
if (typeof assign === "object")
|
|
387
|
+
return assign;
|
|
388
|
+
if (assign) {
|
|
389
|
+
if (context.dialect === "posix" && /[$`]/.test(input.slice(index + 1, end)))
|
|
259
390
|
return { kind: "opaque", reason: "invalid-structure" };
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
compoundEnd = true;
|
|
266
|
-
dangling = false;
|
|
267
|
-
index = expression.end;
|
|
268
|
-
segment = index + 1;
|
|
391
|
+
state.nestedCommands.push(...subscript);
|
|
392
|
+
state.assignmentWord = true;
|
|
393
|
+
state.word += input.slice(index, end + 1);
|
|
394
|
+
index = end;
|
|
395
|
+
state.wordEnd = index + 1;
|
|
269
396
|
continue;
|
|
270
397
|
}
|
|
271
398
|
}
|
|
272
|
-
if (
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
if (
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
wordStarted = true;
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
const next = input[index + 1];
|
|
287
|
-
if ('$`"\\\n'.includes(next)) {
|
|
288
|
-
index++;
|
|
289
|
-
if (next !== `
|
|
290
|
-
`)
|
|
291
|
-
word += next;
|
|
292
|
-
} else
|
|
293
|
-
word += char;
|
|
294
|
-
} else if (char === "$" && "({[".includes(input[index + 1] ?? "\x00") || char === "`") {
|
|
295
|
-
const substitution = bashExpansion(input, index, depth, undefined, true);
|
|
296
|
-
if (!substitution || depth >= MAX_SUBSTITUTION_DEPTH)
|
|
297
|
-
return { kind: "opaque", reason: "command-substitution" };
|
|
298
|
-
const failure = addSubstitutions(substitution);
|
|
299
|
-
if (failure)
|
|
300
|
-
return failure;
|
|
301
|
-
word += input.slice(index, substitution.end + 1);
|
|
302
|
-
index = substitution.end;
|
|
303
|
-
} else
|
|
304
|
-
word += char;
|
|
305
|
-
wordEnd = index + 1;
|
|
306
|
-
continue;
|
|
307
|
-
}
|
|
308
|
-
if (char === "$" && input[index + 1] === "'") {
|
|
309
|
-
const literal = bashAnsiQuote(input, index + 1);
|
|
310
|
-
if (!literal)
|
|
311
|
-
return { kind: "opaque", reason: "unterminated-quote" };
|
|
312
|
-
wordStarted = true;
|
|
313
|
-
if (!assignmentWord)
|
|
314
|
-
assignmentHeadUnsafe = true;
|
|
315
|
-
word += literal.value;
|
|
316
|
-
index = literal.end;
|
|
317
|
-
wordEnd = index + 1;
|
|
318
|
-
continue;
|
|
319
|
-
}
|
|
320
|
-
if (char === "$" && input[index + 1] === '"') {
|
|
321
|
-
quote = "double";
|
|
322
|
-
wordStarted = true;
|
|
323
|
-
if (!assignmentWord)
|
|
324
|
-
assignmentHeadUnsafe = true;
|
|
325
|
-
wordEnd = ++index + 1;
|
|
326
|
-
continue;
|
|
327
|
-
}
|
|
328
|
-
if (char === "'") {
|
|
329
|
-
quote = "single";
|
|
330
|
-
wordStarted = true;
|
|
331
|
-
wordEnd = index + 1;
|
|
332
|
-
if (!assignmentWord)
|
|
333
|
-
assignmentHeadUnsafe = true;
|
|
334
|
-
continue;
|
|
335
|
-
}
|
|
336
|
-
if (char === '"') {
|
|
337
|
-
quote = "double";
|
|
338
|
-
wordStarted = true;
|
|
339
|
-
wordEnd = index + 1;
|
|
340
|
-
if (!assignmentWord)
|
|
341
|
-
assignmentHeadUnsafe = true;
|
|
342
|
-
continue;
|
|
343
|
-
}
|
|
344
|
-
if (char === "\\") {
|
|
345
|
-
if (index + 1 >= input.length)
|
|
346
|
-
return { kind: "opaque", reason: "unterminated-escape" };
|
|
347
|
-
if (input[index + 1] === `
|
|
348
|
-
`)
|
|
349
|
-
index++;
|
|
350
|
-
else {
|
|
351
|
-
wordStarted = true;
|
|
352
|
-
if (!assignmentWord)
|
|
353
|
-
assignmentHeadUnsafe = true;
|
|
354
|
-
word += input[++index];
|
|
355
|
-
wordEnd = index + 1;
|
|
356
|
-
}
|
|
357
|
-
continue;
|
|
358
|
-
}
|
|
359
|
-
if (char === "$" && "({[".includes(input[index + 1] ?? "\x00") || char === "`" || char === "[" && /^[A-Za-z_][A-Za-z0-9_]*$/.test(word) && /^\[[\s\S]*?\]\+?=/.test(input.slice(index)) || char === "(" && (assignmentWord || /[?*+@!]$/.test(word))) {
|
|
360
|
-
const substitution = char === "(" ? bashExpansion(input, index, depth, assignmentWord ? "array" : "pattern") : char === "[" ? bashExpansion(input, index, depth, "subscript") : bashExpansion(input, index, depth);
|
|
361
|
-
if (!substitution || depth >= MAX_SUBSTITUTION_DEPTH)
|
|
362
|
-
return { kind: "opaque", reason: "command-substitution" };
|
|
363
|
-
const failure = addSubstitutions(substitution);
|
|
364
|
-
if (failure)
|
|
365
|
-
return failure;
|
|
366
|
-
wordStarted = true;
|
|
367
|
-
word += input.slice(index, substitution.end + 1);
|
|
368
|
-
index = substitution.end;
|
|
369
|
-
wordEnd = index + 1;
|
|
370
|
-
continue;
|
|
371
|
-
}
|
|
372
|
-
if ((char === "<" || char === ">" || char === "=" && !wordStarted) && input[index + 1] === "(") {
|
|
373
|
-
const substitution = bashDelimited(input, index + 1, depth);
|
|
374
|
-
if (!substitution || depth >= MAX_SUBSTITUTION_DEPTH)
|
|
375
|
-
return { kind: "opaque", reason: "command-substitution" };
|
|
376
|
-
const failure = addSubstitutions(substitution);
|
|
377
|
-
if (failure)
|
|
378
|
-
return failure;
|
|
379
|
-
wordStarted = true;
|
|
380
|
-
word += input.slice(index, substitution.end + 1);
|
|
381
|
-
index = substitution.end;
|
|
382
|
-
wordEnd = index + 1;
|
|
399
|
+
if (char === "(" && (array || (inCasePattern || context.dialect === "bash") && /[?*+@!]$/.test(state.word))) {
|
|
400
|
+
const mode = array ? "array" : "pattern";
|
|
401
|
+
const end = scanBashArrayOrPattern(input, index, depth + 1, context, state.nestedCommands, mode);
|
|
402
|
+
if (typeof end === "object")
|
|
403
|
+
return end;
|
|
404
|
+
if (bashCrossesHeredoc(state, index, end))
|
|
405
|
+
return { kind: "opaque", reason: "heredoc" };
|
|
406
|
+
if (array && end + 1 < input.length && !`
|
|
407
|
+
;&|<>)`.includes(input[end + 1]))
|
|
408
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
409
|
+
state.wordStarted = true;
|
|
410
|
+
state.word += input.slice(index, end + 1);
|
|
411
|
+
index = end;
|
|
412
|
+
state.wordEnd = index + 1;
|
|
383
413
|
continue;
|
|
384
414
|
}
|
|
385
|
-
if (char === "#" && !wordStarted) {
|
|
415
|
+
if (char === "#" && !state.wordStarted) {
|
|
386
416
|
const newline = input.indexOf(`
|
|
387
417
|
`, index);
|
|
388
|
-
if (words.length > 0 || hasRedirect) {
|
|
389
|
-
finishCommand();
|
|
390
|
-
dangling = false;
|
|
391
|
-
inList = false;
|
|
392
|
-
}
|
|
393
418
|
if (newline === -1)
|
|
394
419
|
break;
|
|
395
420
|
index = newline - 1;
|
|
396
|
-
segment = newline;
|
|
397
421
|
continue;
|
|
398
422
|
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
if (
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
if (wordEnd < index)
|
|
406
|
-
commandEnd = wordEnd;
|
|
407
|
-
word = "";
|
|
408
|
-
wordStarted = false;
|
|
409
|
-
} else
|
|
410
|
-
finishWord();
|
|
411
|
-
if (redirectWordCount === undefined && assignmentWords.some((assignment) => !assignment)) {
|
|
412
|
-
redirectWordCount = words.length;
|
|
413
|
-
if (inList)
|
|
414
|
-
resourceEnd = commandEnd;
|
|
415
|
-
}
|
|
416
|
-
if (redirect === "<<" || redirect === "<<-") {
|
|
417
|
-
const delimiter = bashHeredocDelimiter(input, index);
|
|
418
|
-
if (!delimiter)
|
|
419
|
-
return { kind: "opaque", reason: "invalid-redirect" };
|
|
420
|
-
heredocs.push(delimiter);
|
|
421
|
-
wordEnd = delimiter.end + 1;
|
|
422
|
-
index = delimiter.end;
|
|
423
|
-
redirectTarget = false;
|
|
424
|
-
continue;
|
|
425
|
-
}
|
|
426
|
-
redirectTarget = true;
|
|
427
|
-
index += redirect.length - 1;
|
|
423
|
+
if (`<>&|;
|
|
424
|
+
`.includes(char)) {
|
|
425
|
+
const step = scanBashOperatorOrSeparator(state, index, depth, context);
|
|
426
|
+
if (typeof step === "object")
|
|
427
|
+
return step;
|
|
428
|
+
index = step;
|
|
428
429
|
continue;
|
|
429
430
|
}
|
|
430
|
-
if (
|
|
431
|
-
|
|
431
|
+
if (inCasePattern && char === ")") {
|
|
432
|
+
finishBashWord(state);
|
|
432
433
|
index--;
|
|
433
434
|
continue;
|
|
434
435
|
}
|
|
435
|
-
if ("
|
|
436
|
-
|
|
436
|
+
if (char === ")") {
|
|
437
|
+
if (close !== ")" || state.structures.length > 0 || heredocs === undefined && state.heredocs.length > 0)
|
|
438
|
+
return { kind: "opaque", reason: "compound-command" };
|
|
439
|
+
return closeBashList(state, index);
|
|
440
|
+
}
|
|
441
|
+
if (char === "(")
|
|
442
|
+
return { kind: "opaque", reason: state.wordStarted ? "dynamic-execution" : "compound-command" };
|
|
437
443
|
if (/\s/.test(char) && !`
|
|
438
444
|
`.includes(char))
|
|
439
445
|
return { kind: "opaque", reason: "invalid-structure" };
|
|
440
446
|
if (char === " " || char === "\t") {
|
|
441
|
-
|
|
447
|
+
finishBashWord(state);
|
|
442
448
|
continue;
|
|
443
449
|
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
450
|
+
state.wordStarted = true;
|
|
451
|
+
if (char === "=" && !state.assignmentWord && !state.assignmentHeadUnsafe && /^[A-Za-z_][A-Za-z0-9_]*\+?$/.test(state.word))
|
|
452
|
+
state.assignmentWord = true;
|
|
453
|
+
bashAppend(state, char);
|
|
454
|
+
state.wordEnd = index + 1;
|
|
455
|
+
}
|
|
456
|
+
if (close)
|
|
457
|
+
return { kind: "opaque", reason: close === ")" ? "command-substitution" : "invalid-structure" };
|
|
458
|
+
if (state.heredocs.length)
|
|
459
|
+
return { kind: "opaque", reason: "heredoc" };
|
|
460
|
+
return closeBashList(state, input.length);
|
|
461
|
+
}
|
|
462
|
+
function scanBashOperatorOrSeparator(state, index, depth, context) {
|
|
463
|
+
const input = state.input;
|
|
464
|
+
const char = input[index];
|
|
465
|
+
const redirect = "<>&".includes(char) ? bashOperator(input, index, BASH_REDIRECTS) : undefined;
|
|
466
|
+
if (typeof redirect === "object")
|
|
467
|
+
return redirect;
|
|
468
|
+
const caseHead = state.structures.at(-1);
|
|
469
|
+
if (redirect && caseHead?.kind === "case" && caseHead.phase !== "body")
|
|
470
|
+
return { kind: "opaque", reason: "invalid-redirect" };
|
|
471
|
+
if (redirect) {
|
|
472
|
+
state.hasRedirect = true;
|
|
473
|
+
state.commandStart ??= state.wordStart;
|
|
474
|
+
if (state.redirectTarget)
|
|
475
|
+
state.invalid ??= "invalid-redirect";
|
|
476
|
+
const fdPrefix = state.wordStarted && !state.assignmentHeadUnsafe && /^(?:\d+|\{[A-Za-z_][A-Za-z0-9_]*\})$/.test(state.word);
|
|
477
|
+
if (fdPrefix) {
|
|
478
|
+
if (state.wordEnd < index)
|
|
479
|
+
state.commandEnd = state.wordEnd;
|
|
480
|
+
state.word = "";
|
|
481
|
+
state.literal = "";
|
|
482
|
+
state.output = "";
|
|
483
|
+
state.wordStarted = false;
|
|
484
|
+
}
|
|
485
|
+
if (!fdPrefix)
|
|
486
|
+
finishBashWord(state);
|
|
487
|
+
if (redirect.startsWith("&") && context.dialect === "posix")
|
|
488
|
+
state.ampersandRedirectWords ??= state.words.length;
|
|
489
|
+
if (state.redirectWordCount === undefined && state.commandWordIndex >= 0) {
|
|
490
|
+
state.redirectWordCount = state.words.length;
|
|
491
|
+
if (state.dangling)
|
|
492
|
+
state.resourceEnd = state.commandEnd;
|
|
493
|
+
}
|
|
494
|
+
if (redirect === "<<" || redirect === "<<-") {
|
|
495
|
+
const delimiter = bashHeredocDelimiter(input, index + redirect.length, redirect === "<<-");
|
|
496
|
+
if (!delimiter)
|
|
497
|
+
return { kind: "opaque", reason: "invalid-redirect" };
|
|
498
|
+
state.heredocs.push(delimiter);
|
|
499
|
+
state.wordEnd = delimiter.end + 1;
|
|
500
|
+
state.redirectTarget = false;
|
|
501
|
+
return delimiter.end;
|
|
502
|
+
}
|
|
503
|
+
state.redirectTarget = true;
|
|
504
|
+
state.hereString = redirect === "<<<";
|
|
505
|
+
return index + redirect.length - 1;
|
|
506
|
+
}
|
|
507
|
+
if (state.structures.at(-1)?.phase === "pattern" && char === "|") {
|
|
508
|
+
finishBashWord(state);
|
|
509
|
+
return index - 1;
|
|
510
|
+
}
|
|
511
|
+
const structure = state.structures.at(-1);
|
|
512
|
+
const caseBody = structure?.kind === "case" && structure.phase === "body";
|
|
513
|
+
const operator = bashOperator(input, index, caseBody ? BASH_CASE_OPERATORS : BASH_LIST_OPERATORS);
|
|
514
|
+
if (typeof operator === "object")
|
|
515
|
+
return operator;
|
|
516
|
+
const separator = operator ?? char;
|
|
517
|
+
if (caseBody && separator.startsWith(";") && separator.length > 1) {
|
|
518
|
+
if (!endBashList(state))
|
|
519
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
520
|
+
structure.phase = "pattern";
|
|
521
|
+
structure.patternStarted = false;
|
|
522
|
+
return index + separator.length - 1;
|
|
523
|
+
}
|
|
524
|
+
if (structure?.kind === "case" && (structure.phase === "header" || structure.phase === "pattern")) {
|
|
525
|
+
if (separator !== `
|
|
526
|
+
`)
|
|
527
|
+
return { kind: "opaque", reason: "compound-command" };
|
|
528
|
+
if (structure.phase === "pattern" && (state.wordStarted || state.words.length > 0))
|
|
529
|
+
return { kind: "opaque", reason: "compound-command" };
|
|
530
|
+
finishBashWord(state);
|
|
531
|
+
return readBashHeredocs(state, index, depth, context);
|
|
532
|
+
}
|
|
533
|
+
if ((structure?.kind === "for" || structure?.kind === "repeat") && (structure.phase === "header" || structure.phase === "do")) {
|
|
534
|
+
if (separator !== ";" && separator !== `
|
|
535
|
+
`)
|
|
536
|
+
return { kind: "opaque", reason: "compound-command" };
|
|
537
|
+
if (structure.phase === "header" && !structure.sawIn && !state.wordStarted && state.words.length === 0)
|
|
538
|
+
return { kind: "opaque", reason: "compound-command" };
|
|
539
|
+
}
|
|
540
|
+
if (separator === `
|
|
541
|
+
` && !pending(state))
|
|
542
|
+
return readBashHeredocs(state, index, depth, context);
|
|
543
|
+
finishBashCommand(state, true);
|
|
544
|
+
if (structure?.kind === "for" && structure.phase === "header")
|
|
545
|
+
structure.phase = "do";
|
|
546
|
+
state.dangling = separator !== "&" && separator !== ";" && separator !== `
|
|
547
|
+
`;
|
|
548
|
+
if (separator === `
|
|
549
|
+
` && state.heredocs.length)
|
|
550
|
+
return index - 1;
|
|
551
|
+
return index + separator.length - 1;
|
|
552
|
+
}
|
|
553
|
+
function bashCommandKey(command) {
|
|
554
|
+
return JSON.stringify([command.resource, command.words]);
|
|
555
|
+
}
|
|
556
|
+
function readBashHeredocs(state, index, depth, context) {
|
|
557
|
+
let end = index;
|
|
558
|
+
for (const heredoc of state.heredocs.splice(0)) {
|
|
559
|
+
const body = bashHeredoc(state.input, end + 1, heredoc);
|
|
560
|
+
if (!body)
|
|
561
|
+
return { kind: "opaque", reason: "heredoc" };
|
|
562
|
+
if (heredoc.command)
|
|
563
|
+
heredoc.command.resource = state.input.slice(heredoc.start, body.end).trim();
|
|
564
|
+
const text = heredoc.quoted ? { word: body.source, literal: body.source, output: "" } : bashText();
|
|
565
|
+
if (!heredoc.quoted) {
|
|
566
|
+
const expansion = scanBashSpan(body.source, 0, depth, context, state.commands, BASH_SPANS.heredoc, true, text);
|
|
567
|
+
if (typeof expansion === "object")
|
|
568
|
+
return expansion;
|
|
569
|
+
}
|
|
570
|
+
if (heredoc.binding)
|
|
571
|
+
bashEvaluatesExpansion(text, "deferred", context);
|
|
572
|
+
end = body.end;
|
|
573
|
+
}
|
|
574
|
+
return end;
|
|
575
|
+
}
|
|
576
|
+
function bashCrossesHeredoc(state, start, end) {
|
|
577
|
+
return state.heredocs.length > 0 && state.input.slice(start, end).includes(`
|
|
578
|
+
`);
|
|
579
|
+
}
|
|
580
|
+
function scanBashCommandStart(state, index, depth, context) {
|
|
581
|
+
const input = state.input;
|
|
582
|
+
const char = input[index];
|
|
583
|
+
const structure = state.structures.at(-1);
|
|
584
|
+
if (structure?.phase === "pattern" && !structure.patternStarted && !state.words.length && char === "(") {
|
|
585
|
+
structure.patternStarted = true;
|
|
586
|
+
return index;
|
|
587
|
+
}
|
|
588
|
+
if (structure?.phase === "pattern" && char === "|") {
|
|
589
|
+
if (!state.words.length)
|
|
590
|
+
return { kind: "opaque", reason: "compound-command" };
|
|
591
|
+
finishBashWord(state);
|
|
592
|
+
structure.patternStarted = true;
|
|
593
|
+
return index;
|
|
594
|
+
}
|
|
595
|
+
if (structure?.phase === "pattern" && char === ")") {
|
|
596
|
+
if (!state.words.length)
|
|
597
|
+
return { kind: "opaque", reason: "compound-command" };
|
|
598
|
+
finishBashCommand(state);
|
|
599
|
+
structure.phase = "body";
|
|
600
|
+
structure.count = 0;
|
|
601
|
+
return index;
|
|
602
|
+
}
|
|
603
|
+
if (structure?.kind === "for" && structure.phase === "header" && char === "(" && input[index + 1] !== "(") {
|
|
604
|
+
const end = scanBashArrayOrPattern(input, index, depth + 1, context, state.nestedCommands, "array");
|
|
605
|
+
if (typeof end === "object")
|
|
606
|
+
return end;
|
|
607
|
+
if (bashCrossesHeredoc(state, index, end))
|
|
608
|
+
return { kind: "opaque", reason: "heredoc" };
|
|
609
|
+
finishBashCommand(state);
|
|
610
|
+
structure.phase = "do";
|
|
611
|
+
structure.parenthesized = true;
|
|
612
|
+
DO_AHEAD_RE.lastIndex = end + 1;
|
|
613
|
+
if (!DO_AHEAD_RE.test(input))
|
|
614
|
+
state.structures.pop();
|
|
615
|
+
return end;
|
|
616
|
+
}
|
|
617
|
+
if (structure?.kind === "repeat" && structure.phase === "do" && char !== `
|
|
618
|
+
` && char !== "#" && char !== ";") {
|
|
619
|
+
TOKEN_RE.lastIndex = index;
|
|
620
|
+
if (TOKEN_RE.exec(input)?.[0] !== "do")
|
|
621
|
+
state.structures.pop();
|
|
622
|
+
}
|
|
623
|
+
const keywordStep = scanBashKeyword(state, index, depth, context);
|
|
624
|
+
if (keywordStep !== undefined)
|
|
625
|
+
return keywordStep;
|
|
626
|
+
if (structure?.kind === "for" && structure.phase === "do" && char !== `
|
|
627
|
+
` && char !== "#" && char !== ";") {
|
|
628
|
+
SPACE_CONTINUATION_AHEAD_RE.lastIndex = index + 1;
|
|
629
|
+
if (char !== "{" || !SPACE_CONTINUATION_AHEAD_RE.test(input))
|
|
630
|
+
return { kind: "opaque", reason: "compound-command" };
|
|
631
|
+
state.structures.pop();
|
|
632
|
+
}
|
|
633
|
+
const atStart = atCommandStart(state);
|
|
634
|
+
const functionHead = atStart && char === "(" ? bashFunctionHeadLength(input, index) : 0;
|
|
635
|
+
if (functionHead)
|
|
636
|
+
return index + functionHead - 1;
|
|
637
|
+
if (atStart && char === "!") {
|
|
638
|
+
NEGATION_AHEAD_RE.lastIndex = index + 1;
|
|
639
|
+
if (NEGATION_AHEAD_RE.test(input))
|
|
640
|
+
return index;
|
|
641
|
+
}
|
|
642
|
+
const forHeader = structure?.kind === "for" && structure.phase === "header";
|
|
643
|
+
const compoundOpen = (atStart || forHeader) && "([".includes(char) ? bashOperator(input, index, ["((", "[["]) : undefined;
|
|
644
|
+
if (typeof compoundOpen === "object")
|
|
645
|
+
return compoundOpen;
|
|
646
|
+
if (compoundOpen === "((") {
|
|
647
|
+
if (forHeader && state.words.length > 0)
|
|
648
|
+
return { kind: "opaque", reason: "compound-command" };
|
|
649
|
+
const span = forHeader ? BASH_SPANS.forArithmetic : BASH_SPANS.arithmetic;
|
|
650
|
+
const end = scanBashArithmetic(input, index + 2, depth, context, state.commands, span);
|
|
651
|
+
if (typeof end === "number") {
|
|
652
|
+
if (bashCrossesHeredoc(state, index, end))
|
|
653
|
+
return { kind: "opaque", reason: "heredoc" };
|
|
654
|
+
if (!forHeader && context.dialect === "posix") {
|
|
655
|
+
const subshells = scanBash(input, index + 1, depth + 1, context, ")");
|
|
656
|
+
if (subshells.kind === "opaque")
|
|
657
|
+
return subshells;
|
|
658
|
+
if (subshells.end !== end)
|
|
659
|
+
return { kind: "opaque", reason: "compound-command" };
|
|
660
|
+
const seen = new Set(state.commands.map(bashCommandKey));
|
|
661
|
+
state.commands.push(...subshells.commands.filter((command) => !seen.has(bashCommandKey(command))));
|
|
481
662
|
}
|
|
482
|
-
|
|
483
|
-
if (structure?.kind === "for" && structure.phase === "header")
|
|
663
|
+
if (forHeader) {
|
|
484
664
|
structure.phase = "do";
|
|
485
|
-
|
|
486
|
-
`;
|
|
487
|
-
inList = dangling;
|
|
488
|
-
if (separator === `
|
|
489
|
-
` && heredocs.length) {
|
|
490
|
-
index--;
|
|
491
|
-
continue;
|
|
665
|
+
structure.sawIn = true;
|
|
492
666
|
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
667
|
+
if (!forHeader) {
|
|
668
|
+
bashStatement(state);
|
|
669
|
+
state.compoundEnd = true;
|
|
670
|
+
}
|
|
671
|
+
return end;
|
|
496
672
|
}
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
wordEnd = index + 1;
|
|
673
|
+
if (end)
|
|
674
|
+
return end;
|
|
675
|
+
if (forHeader)
|
|
676
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
502
677
|
}
|
|
503
|
-
if (
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
678
|
+
if (atStart && (char === "(" || char === "{" && (SPACE_CONTINUATION_AHEAD_RE.lastIndex = index + 1, SPACE_CONTINUATION_AHEAD_RE.test(input)))) {
|
|
679
|
+
const group = scanBash(input, index + 1, depth + 1, context, char === "{" ? "}" : ")", state.heredocs);
|
|
680
|
+
if (group.kind === "opaque")
|
|
681
|
+
return group;
|
|
682
|
+
if (!input.slice(index + 1, group.end).trim())
|
|
683
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
684
|
+
state.commands.push(...group.commands);
|
|
685
|
+
bashStatement(state);
|
|
686
|
+
state.compoundEnd = true;
|
|
687
|
+
return group.end;
|
|
510
688
|
}
|
|
511
|
-
if (
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
689
|
+
if (atStart && compoundOpen === "[[" && (SPACE_CONTINUATION_AHEAD_RE.lastIndex = index + 2, SPACE_CONTINUATION_AHEAD_RE.test(input))) {
|
|
690
|
+
const end = scanBashConditional(input, index + 2, depth, context, state.commands);
|
|
691
|
+
if (typeof end === "object")
|
|
692
|
+
return end;
|
|
693
|
+
if (bashCrossesHeredoc(state, index, end))
|
|
694
|
+
return { kind: "opaque", reason: "heredoc" };
|
|
695
|
+
bashStatement(state);
|
|
696
|
+
state.compoundEnd = true;
|
|
697
|
+
return end;
|
|
698
|
+
}
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
function scanBashKeyword(state, index, depth, context) {
|
|
702
|
+
const input = state.input;
|
|
703
|
+
const char = input[index];
|
|
704
|
+
if (!(char >= "A" && char <= "Z" || char >= "a" && char <= "z" || char === "_"))
|
|
705
|
+
return;
|
|
706
|
+
const structure = state.structures.at(-1);
|
|
707
|
+
TOKEN_RE.lastIndex = index;
|
|
708
|
+
const token = TOKEN_RE.exec(input)?.[0];
|
|
709
|
+
const end = index + (token?.length ?? 0) - 1;
|
|
710
|
+
if (structure?.kind === "case" && structure.phase === "header" && token === "in") {
|
|
711
|
+
if (state.words.length !== 1 || state.hasRedirect)
|
|
712
|
+
return { kind: "opaque", reason: "compound-command" };
|
|
713
|
+
finishBashCommand(state);
|
|
714
|
+
structure.phase = "pattern";
|
|
715
|
+
structure.patternStarted = false;
|
|
716
|
+
return end;
|
|
717
|
+
}
|
|
718
|
+
if (structure?.kind === "for" && (structure.phase === "header" || structure.phase === "do") && !structure.sawIn && !structure.parenthesized && token === "in" && (structure.phase === "do" || state.words.length >= 1)) {
|
|
719
|
+
structure.sawIn = true;
|
|
720
|
+
structure.phase = "header";
|
|
721
|
+
return end;
|
|
722
|
+
}
|
|
723
|
+
if (structure?.phase === "pattern" && !structure.patternStarted && !state.words.length && token === "esac") {
|
|
724
|
+
state.structures.pop();
|
|
725
|
+
bashStatement(state);
|
|
726
|
+
state.compoundEnd = true;
|
|
727
|
+
return end;
|
|
728
|
+
}
|
|
729
|
+
if (structure?.kind === "for" && structure.phase === "header" && !structure.sawIn && state.words.length === 1 && !state.hasRedirect && token === "do") {
|
|
730
|
+
finishBashCommand(state);
|
|
731
|
+
structure.phase = "do";
|
|
732
|
+
}
|
|
733
|
+
const inHeader = bashInHeader(state);
|
|
734
|
+
if (token && ["then", "elif", "else", "fi", "do", "done", "esac"].includes(token) && !state.words.length && !state.redirectTarget && (!inHeader || token === "do" && structure?.phase === "do")) {
|
|
735
|
+
if (state.hasRedirect && context.dialect !== "zsh" || !endBashList(state) || !structure)
|
|
736
|
+
return { kind: "opaque", reason: "compound-command" };
|
|
737
|
+
if (token === "then") {
|
|
738
|
+
if (structure.kind !== "if" || structure.phase !== "condition" || !structure.count)
|
|
739
|
+
return { kind: "opaque", reason: "compound-command" };
|
|
740
|
+
structure.phase = "body";
|
|
741
|
+
structure.count = 0;
|
|
742
|
+
return end;
|
|
743
|
+
}
|
|
744
|
+
if (token === "elif" || token === "else") {
|
|
745
|
+
if (structure.kind !== "if" || structure.phase !== "body" || !structure.count || structure.sawElse)
|
|
746
|
+
return { kind: "opaque", reason: "compound-command" };
|
|
747
|
+
structure.phase = token === "elif" ? "condition" : "body";
|
|
748
|
+
structure.sawElse = token === "else";
|
|
749
|
+
structure.count = 0;
|
|
750
|
+
return end;
|
|
751
|
+
}
|
|
752
|
+
if (token === "do") {
|
|
753
|
+
if (!["for", "while", "until", "repeat"].includes(structure.kind) || !["condition", "do"].includes(structure.phase) || structure.kind !== "for" && structure.kind !== "repeat" && !structure.count)
|
|
754
|
+
return { kind: "opaque", reason: "compound-command" };
|
|
755
|
+
structure.phase = "body";
|
|
756
|
+
structure.count = 0;
|
|
757
|
+
return end;
|
|
758
|
+
}
|
|
759
|
+
if (token === "fi" && (structure.kind !== "if" || structure.phase !== "body" || !structure.count) || token === "done" && (!["for", "while", "until", "repeat"].includes(structure.kind) || structure.phase !== "body" || !structure.count) || token === "esac" && (structure.kind !== "case" || structure.phase === "header"))
|
|
760
|
+
return { kind: "opaque", reason: "compound-command" };
|
|
761
|
+
state.structures.pop();
|
|
762
|
+
bashStatement(state);
|
|
763
|
+
state.compoundEnd = true;
|
|
764
|
+
return end;
|
|
765
|
+
}
|
|
766
|
+
if (!atCommandStart(state))
|
|
767
|
+
return;
|
|
768
|
+
const definitionLength = bashFunctionHeadLength(input, index);
|
|
769
|
+
if (definitionLength > 0)
|
|
770
|
+
return index + definitionLength - 1;
|
|
771
|
+
if (token === "if" || token === "while" || token === "until" || token === "for" || token === "select" || token === "case" || token === "repeat" && context.dialect !== "bash") {
|
|
772
|
+
if (depth + state.structures.length >= MAX_SUBSTITUTION_DEPTH)
|
|
773
|
+
return { kind: "opaque", reason: "compound-command" };
|
|
774
|
+
state.structures.push({
|
|
775
|
+
kind: token === "select" ? "for" : token,
|
|
776
|
+
phase: ["for", "select", "case", "repeat"].includes(token) ? "header" : "condition",
|
|
777
|
+
count: 0
|
|
778
|
+
});
|
|
779
|
+
state.dangling = false;
|
|
780
|
+
return end;
|
|
781
|
+
}
|
|
782
|
+
if (token === "coproc") {
|
|
783
|
+
COPROC_AHEAD_RE.lastIndex = index;
|
|
784
|
+
const coprocMatch = COPROC_AHEAD_RE.exec(input)?.[0];
|
|
785
|
+
if (coprocMatch)
|
|
786
|
+
return index + coprocMatch.length - 1;
|
|
787
|
+
}
|
|
788
|
+
if (token === "time") {
|
|
789
|
+
TIME_AHEAD_RE.lastIndex = index;
|
|
790
|
+
const timeMatch = TIME_AHEAD_RE.exec(input)?.[0];
|
|
791
|
+
if (timeMatch)
|
|
792
|
+
return index + timeMatch.length - 1;
|
|
793
|
+
}
|
|
794
|
+
return;
|
|
795
|
+
}
|
|
796
|
+
function bashFunctionHeadLength(input, start) {
|
|
797
|
+
FUNCTION_HEAD_RE.lastIndex = start;
|
|
798
|
+
const head = FUNCTION_HEAD_RE.exec(input);
|
|
799
|
+
if (!head || (head[1] ? !head[2] : !head[3] || BASH_NON_FUNCTION_KEYWORDS.has(head[2] ?? "")))
|
|
800
|
+
return 0;
|
|
801
|
+
FUNCTION_BODY_RE.lastIndex = start + head[0].length;
|
|
802
|
+
return FUNCTION_BODY_RE.test(input) ? head[0].length - head[4].length : 0;
|
|
803
|
+
}
|
|
804
|
+
var BASH_SPANS = {
|
|
805
|
+
double: { close: '"', reject: "", mode: "quoted" },
|
|
806
|
+
heredoc: { reject: "", mode: "quoted" },
|
|
807
|
+
arithmetic: { open: "(", close: ")", reject: ";#}", mode: "arithmetic" },
|
|
808
|
+
forArithmetic: { open: "(", close: ")", reject: "#}", mode: "arithmetic" },
|
|
809
|
+
bracketArithmetic: { close: "]", reject: `;|&<>()[
|
|
810
|
+
'"\\#`, mode: "arithmetic" },
|
|
811
|
+
subscript: { open: "[", close: "]", reject: '"}', mode: "arithmetic" },
|
|
812
|
+
quotedSubscript: { open: "[", close: "]", reject: '"', mode: "quoted" },
|
|
813
|
+
assignmentSubscript: { open: "[", close: "]", reject: `
|
|
814
|
+
\r\v\f;&|<>()`, mode: "arithmetic" },
|
|
815
|
+
arithmeticQuote: { close: "'", reject: '()[];"}', mode: "quoted" },
|
|
816
|
+
arithmeticDouble: { close: '"', reject: "()[];}", mode: "quoted" },
|
|
817
|
+
parameterQuote: { close: "'", reject: '"}[]', mode: "quoted" }
|
|
818
|
+
};
|
|
819
|
+
function scanBashUnit(input, index, depth, context, commands, mode, allowBracket, text) {
|
|
820
|
+
const char = input[index];
|
|
821
|
+
const next = input[index + 1] ?? "\x00";
|
|
822
|
+
if (char === "\\") {
|
|
823
|
+
if (mode === "quoted" && !'$`"\\\n'.includes(next))
|
|
824
|
+
return;
|
|
825
|
+
if (text && next !== `
|
|
826
|
+
`)
|
|
827
|
+
bashAppend(text, input.slice(index + 1, index + 2));
|
|
828
|
+
return index + 1;
|
|
829
|
+
}
|
|
830
|
+
if (char === "$" && context.dialect !== "bash" && zshEvaluates(input, index))
|
|
831
|
+
return { kind: "opaque", reason: "dynamic-execution" };
|
|
832
|
+
if (char === "$" && context.dialect !== "bash" && (mode === "word" || mode === "quoted") && (ZSH_SUBSCRIPT_RE.lastIndex = index, ZSH_SUBSCRIPT_RE.test(input))) {
|
|
833
|
+
const bracket = ZSH_SUBSCRIPT_RE.lastIndex;
|
|
834
|
+
const subscript = bashText();
|
|
835
|
+
const span = mode === "quoted" ? BASH_SPANS.quotedSubscript : BASH_SPANS.subscript;
|
|
836
|
+
const end = scanBashSpan(input, bracket, depth, context, commands, span, false, subscript);
|
|
837
|
+
if (typeof end === "object")
|
|
838
|
+
return end;
|
|
839
|
+
if (bashEvaluatesExpansion(subscript, "arithmetic", context))
|
|
840
|
+
return { kind: "opaque", reason: "dynamic-execution" };
|
|
841
|
+
if (text)
|
|
842
|
+
text.word += `${input.slice(index, bracket)}${subscript.word}]`;
|
|
843
|
+
return end;
|
|
844
|
+
}
|
|
845
|
+
const opener = char === "$" ? bashOperator(input, index, ["$$", "$((", "$(", "${", "$[", "$'", '$"']) : mode === "word" && (char === "<" || char === ">") ? bashOperator(input, index, [`${char}(`]) : undefined;
|
|
846
|
+
if (typeof opener === "object")
|
|
847
|
+
return opener;
|
|
848
|
+
if (opener === "$$") {
|
|
849
|
+
LINE_CONTINUATION_RE.lastIndex = index + 2;
|
|
850
|
+
const quoteStart = LINE_CONTINUATION_RE.exec(input) ? LINE_CONTINUATION_RE.lastIndex : index + 2;
|
|
851
|
+
if (input[quoteStart] === "'") {
|
|
852
|
+
const nextQuote = input.indexOf("'", quoteStart + 1);
|
|
853
|
+
if (nextQuote < 0)
|
|
854
|
+
return { kind: "opaque", reason: "unterminated-quote" };
|
|
855
|
+
if (input.slice(quoteStart + 1, nextQuote).includes("\\") && input.includes("'", nextQuote + 1))
|
|
856
|
+
return { kind: "opaque", reason: "unterminated-quote" };
|
|
857
|
+
}
|
|
858
|
+
if (text)
|
|
859
|
+
text.word += "$$";
|
|
860
|
+
return index + 1;
|
|
861
|
+
}
|
|
862
|
+
if (mode === "word" && opener === "$'") {
|
|
863
|
+
const quote = bashAnsiQuote(input, index + 1);
|
|
864
|
+
if (!quote)
|
|
865
|
+
return { kind: "opaque", reason: "unterminated-quote" };
|
|
866
|
+
const firstQuote = input.indexOf("'", index + 2);
|
|
867
|
+
if (quote.end !== firstQuote && (context.dialect !== "bash" && index >= 2 && input[index - 2] === "$" || context.dialect === "posix" && (input.indexOf("'", firstQuote + 1) < quote.end || /[#"\n]|\\'/.test(input.slice(firstQuote + 1)))))
|
|
868
|
+
return { kind: "opaque", reason: "unterminated-quote" };
|
|
869
|
+
if (text)
|
|
870
|
+
bashAppend(text, quote.value);
|
|
871
|
+
return quote.end;
|
|
872
|
+
}
|
|
873
|
+
if (mode === "arithmetic" && opener === "$'") {
|
|
874
|
+
const quote = bashAnsiQuote(input, index + 1);
|
|
875
|
+
if (!quote || quote.end !== input.indexOf("'", index + 2) || /[()[\];"}]/.test(quote.value))
|
|
876
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
877
|
+
if (text)
|
|
878
|
+
bashAppend(text, quote.value);
|
|
879
|
+
return scanBashSpan(input, index + 2, depth, context, commands, BASH_SPANS.arithmeticQuote, allowBracket, text);
|
|
880
|
+
}
|
|
881
|
+
if (mode === "word" && char === "'") {
|
|
882
|
+
const end = input.indexOf("'", index + 1);
|
|
883
|
+
if (end < 0)
|
|
884
|
+
return { kind: "opaque", reason: "unterminated-quote" };
|
|
885
|
+
if (text)
|
|
886
|
+
bashAppend(text, input.slice(index + 1, end));
|
|
887
|
+
return end;
|
|
888
|
+
}
|
|
889
|
+
if (mode === "arithmetic" && char === "'")
|
|
890
|
+
return scanBashSpan(input, index + 1, depth, context, commands, BASH_SPANS.arithmeticQuote, allowBracket, text);
|
|
891
|
+
if (mode === "word" && opener === '$"')
|
|
892
|
+
return scanBashSpan(input, index + 2, depth, context, commands, BASH_SPANS.double, allowBracket, text);
|
|
893
|
+
if (mode !== "quoted" && char === '"') {
|
|
894
|
+
const span = mode === "arithmetic" ? BASH_SPANS.arithmeticDouble : BASH_SPANS.double;
|
|
895
|
+
return scanBashSpan(input, index + 1, depth, context, commands, span, allowBracket, text);
|
|
896
|
+
}
|
|
897
|
+
const end = opener === "<(" || opener === ">(" ? scanBashNested(input, index + 2, depth, context, commands, ")") : opener && opener !== "$'" && opener !== '$"' || char === "`" ? scanBashDollarOrBacktick(input, index, depth, context, commands, mode !== "word", allowBracket, text) : undefined;
|
|
898
|
+
if (end === undefined && char === "$" && /[A-Za-z_0-9@*#?$!-]/.test(next)) {
|
|
899
|
+
if (text)
|
|
900
|
+
text.word += "$";
|
|
901
|
+
return index;
|
|
902
|
+
}
|
|
903
|
+
if (text && typeof end === "number")
|
|
904
|
+
text.word += input.slice(index, end + 1);
|
|
905
|
+
return end;
|
|
906
|
+
}
|
|
907
|
+
function zshEvaluates(input, index) {
|
|
908
|
+
let at = index + 1;
|
|
909
|
+
if (input.startsWith("{\\\n", at))
|
|
910
|
+
return true;
|
|
911
|
+
if (input[at] === "{" && input[at + 1] === "(") {
|
|
912
|
+
ZSH_SAFE_FLAGS_RE.lastIndex = index;
|
|
913
|
+
if (!ZSH_SAFE_FLAGS_RE.test(input))
|
|
914
|
+
return true;
|
|
915
|
+
at = ZSH_SAFE_FLAGS_RE.lastIndex;
|
|
916
|
+
}
|
|
917
|
+
if (input[at] === "{")
|
|
918
|
+
at++;
|
|
919
|
+
ZSH_GLOB_MODIFIER_RE.lastIndex = at;
|
|
920
|
+
return ZSH_GLOB_MODIFIER_RE.test(input);
|
|
921
|
+
}
|
|
922
|
+
function bashAppend(text, value) {
|
|
923
|
+
text.word += value;
|
|
924
|
+
text.literal += value;
|
|
520
925
|
}
|
|
521
|
-
function
|
|
522
|
-
|
|
926
|
+
function bashEvaluatesExpansion(text, evaluation, context) {
|
|
927
|
+
const combined = `${text.literal} ${text.output}`;
|
|
928
|
+
const hasExpansion = BASH_EXPANSION_RE.test(combined);
|
|
929
|
+
const hasEscape = BASH_ESCAPE_RE.test(text.literal);
|
|
930
|
+
if (hasExpansion || hasEscape || /[$`]/.test(text.literal))
|
|
931
|
+
context.boundDollar = true;
|
|
932
|
+
if (hasExpansion || hasEscape || /[({`]/.test(text.literal))
|
|
933
|
+
context.boundOpen = true;
|
|
934
|
+
if (evaluation === "deferred")
|
|
935
|
+
return false;
|
|
936
|
+
if (evaluation === "arithmetic" ? /[A-Za-z_]|(?:\$(?![?#!-]|\$(?!\[)))/.test(text.word) : text.word.includes("$") || combined.includes("["))
|
|
937
|
+
context.variableSink = true;
|
|
938
|
+
if (evaluation === "arithmetic")
|
|
939
|
+
return hasExpansion;
|
|
940
|
+
return combined.includes("[") && hasExpansion;
|
|
941
|
+
}
|
|
942
|
+
function bashText() {
|
|
943
|
+
return { word: "", literal: "", output: "" };
|
|
944
|
+
}
|
|
945
|
+
function scanBashSubscript(input, start, depth, context, commands, span = BASH_SPANS.subscript) {
|
|
946
|
+
const text = bashText();
|
|
947
|
+
const end = scanBashSpan(input, start, depth, context, commands, span, false, text);
|
|
948
|
+
if (typeof end === "number" && bashEvaluatesExpansion(text, "arithmetic", context))
|
|
949
|
+
return { kind: "opaque", reason: "dynamic-execution" };
|
|
950
|
+
return end;
|
|
951
|
+
}
|
|
952
|
+
function scanBashSpan(input, start, depth, context, commands, span, allowBracket, text) {
|
|
953
|
+
let nesting = 0;
|
|
954
|
+
for (let index = start;index < input.length; index++) {
|
|
955
|
+
if (--context.remaining < 0)
|
|
956
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
957
|
+
const char = input[index];
|
|
958
|
+
if (char === span.close && !nesting)
|
|
959
|
+
return index;
|
|
960
|
+
if (span.reject.includes(char) && !(char === "#" && /[\d$]/.test(input[index - 1] ?? "")))
|
|
961
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
962
|
+
if (char === span.open && ++nesting + depth > MAX_SUBSTITUTION_DEPTH)
|
|
963
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
964
|
+
if (char === span.close)
|
|
965
|
+
nesting--;
|
|
966
|
+
const unit = char === span.open || char === span.close ? undefined : scanBashUnit(input, index, depth, context, commands, span.mode, allowBracket, text);
|
|
967
|
+
if (typeof unit === "object")
|
|
968
|
+
return unit;
|
|
969
|
+
if (unit !== undefined)
|
|
970
|
+
index = unit;
|
|
971
|
+
else if (char === "\\" && (input[index + 1] === span.open || input[index + 1] === span.close)) {
|
|
972
|
+
if (text)
|
|
973
|
+
bashAppend(text, input.slice(index, index + 2));
|
|
974
|
+
index++;
|
|
975
|
+
} else if (text)
|
|
976
|
+
bashAppend(text, char);
|
|
977
|
+
}
|
|
978
|
+
return span.close ? { kind: "opaque", reason: "unterminated-quote" } : input.length;
|
|
979
|
+
}
|
|
980
|
+
function scanBashNested(input, start, depth, context, commands, close, text) {
|
|
981
|
+
const nested = scanBash(input, start, depth + 1, context, close, undefined, text);
|
|
982
|
+
if (nested.kind === "opaque")
|
|
983
|
+
return nested;
|
|
984
|
+
commands.push(...nested.commands);
|
|
985
|
+
return nested.end;
|
|
986
|
+
}
|
|
987
|
+
function bashOperator(input, index, operators) {
|
|
988
|
+
let text = "";
|
|
989
|
+
for (let cursor = index;text.length < 3 && cursor < input.length; cursor++) {
|
|
990
|
+
if (input.startsWith("\\\n", cursor))
|
|
991
|
+
cursor++;
|
|
992
|
+
else
|
|
993
|
+
text += input[cursor];
|
|
994
|
+
}
|
|
995
|
+
const operator = operators.find((candidate) => text.startsWith(candidate));
|
|
996
|
+
if (operator && !input.startsWith(operator, index))
|
|
997
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
998
|
+
return operator;
|
|
523
999
|
}
|
|
524
|
-
function
|
|
1000
|
+
function scanBashDollarOrBacktick(input, start, depth, context, commands, quoted, allowBracket, text) {
|
|
525
1001
|
if (depth >= MAX_SUBSTITUTION_DEPTH)
|
|
1002
|
+
return { kind: "opaque", reason: "command-substitution" };
|
|
1003
|
+
if (input[start] === "`")
|
|
1004
|
+
return scanBashBacktick(input, start, depth + 1, context, commands, quoted, text);
|
|
1005
|
+
if (input.startsWith("$((", start)) {
|
|
1006
|
+
const end = scanBashArithmetic(input, start + 3, depth + 1, context, commands, BASH_SPANS.arithmetic);
|
|
1007
|
+
if (end !== undefined)
|
|
1008
|
+
return end;
|
|
1009
|
+
}
|
|
1010
|
+
if (input.startsWith("$(", start))
|
|
1011
|
+
return scanBashNested(input, start + 2, depth, context, commands, ")", text);
|
|
1012
|
+
NOFORK_OPEN_RE.lastIndex = start;
|
|
1013
|
+
const nofork = NOFORK_OPEN_RE.exec(input);
|
|
1014
|
+
if (nofork)
|
|
1015
|
+
return scanBashNested(input, start + nofork[0].length, depth, context, commands, "nofork", text);
|
|
1016
|
+
if (input.startsWith("${", start)) {
|
|
1017
|
+
const parameter = bashText();
|
|
1018
|
+
const end = scanBashParameter(input, start + 2, depth + 1, context, commands, quoted, parameter);
|
|
1019
|
+
if (/^(?:\\\n)*!/.test(input.slice(start + 2))) {
|
|
1020
|
+
context.variableSink = true;
|
|
1021
|
+
if (bashEvaluatesExpansion(parameter, "binding", context))
|
|
1022
|
+
return { kind: "opaque", reason: "dynamic-execution" };
|
|
1023
|
+
}
|
|
1024
|
+
if (text) {
|
|
1025
|
+
text.literal += parameter.literal;
|
|
1026
|
+
text.output += parameter.output;
|
|
1027
|
+
}
|
|
1028
|
+
return end;
|
|
1029
|
+
}
|
|
1030
|
+
if (!allowBracket && context.dialect === "posix")
|
|
1031
|
+
return { kind: "opaque", reason: "command-substitution" };
|
|
1032
|
+
const expression = bashText();
|
|
1033
|
+
const end = scanBashSpan(input, start + 2, depth + 1, context, commands, BASH_SPANS.bracketArithmetic, true, expression);
|
|
1034
|
+
if (typeof end === "number" && bashEvaluatesExpansion(expression, "arithmetic", context))
|
|
1035
|
+
return { kind: "opaque", reason: "dynamic-execution" };
|
|
1036
|
+
return end;
|
|
1037
|
+
}
|
|
1038
|
+
function scanBashArithmetic(input, start, depth, context, commands, span) {
|
|
1039
|
+
const arithmetic = [];
|
|
1040
|
+
const text = bashText();
|
|
1041
|
+
const end = scanBashSpan(input, start, depth, context, arithmetic, span, true, text);
|
|
1042
|
+
if (typeof end === "object")
|
|
1043
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
1044
|
+
const close = bashOperator(input, end, ["))"]);
|
|
1045
|
+
if (typeof close === "object")
|
|
1046
|
+
return close;
|
|
1047
|
+
if (!close)
|
|
526
1048
|
return;
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
1049
|
+
if (bashEvaluatesExpansion(text, "arithmetic", context))
|
|
1050
|
+
return { kind: "opaque", reason: "dynamic-execution" };
|
|
1051
|
+
commands.push(...arithmetic);
|
|
1052
|
+
return end + 1;
|
|
1053
|
+
}
|
|
1054
|
+
function scanBashBacktick(input, start, depth, context, commands, quoted, text) {
|
|
1055
|
+
let source = "";
|
|
531
1056
|
for (let index = start + 1;index < input.length; index++) {
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
if (
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
index
|
|
540
|
-
continue;
|
|
1057
|
+
if (--context.remaining < 0)
|
|
1058
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
1059
|
+
if (input[index] === "`") {
|
|
1060
|
+
const inner = scanBash(source, 0, depth, context, undefined, undefined, text);
|
|
1061
|
+
if (inner.kind === "opaque")
|
|
1062
|
+
return { kind: "opaque", reason: "command-substitution" };
|
|
1063
|
+
commands.push(...inner.commands);
|
|
1064
|
+
return index;
|
|
541
1065
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
index = end;
|
|
549
|
-
continue;
|
|
550
|
-
}
|
|
551
|
-
const nested = char === '"' || input.startsWith('$"', index) ? bashExpansion(input, index + (char === "$" ? 1 : 0), depth + 1, "double") : bashExpansion(input, index, depth + 1);
|
|
552
|
-
if (!nested)
|
|
553
|
-
return;
|
|
554
|
-
index = nested.end;
|
|
1066
|
+
const next = input[index + 1] ?? "\x00";
|
|
1067
|
+
if (input[index] === "\\" && ("$`\\\n".includes(next) || quoted && next === '"')) {
|
|
1068
|
+
index++;
|
|
1069
|
+
if (next !== `
|
|
1070
|
+
`)
|
|
1071
|
+
source += next;
|
|
555
1072
|
continue;
|
|
556
1073
|
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
1074
|
+
source += input[index];
|
|
1075
|
+
}
|
|
1076
|
+
return { kind: "opaque", reason: "command-substitution" };
|
|
1077
|
+
}
|
|
1078
|
+
function scanBashParameter(input, start, depth, context, commands, quoted, text) {
|
|
1079
|
+
PARAMETER_PREFIX_RE.lastIndex = start;
|
|
1080
|
+
const nameStart = PARAMETER_PREFIX_RE.exec(input) ? PARAMETER_PREFIX_RE.lastIndex : start;
|
|
1081
|
+
PARAMETER_NAME_RE.lastIndex = nameStart;
|
|
1082
|
+
let colon = PARAMETER_NAME_RE.test(input) ? PARAMETER_NAME_RE.lastIndex : -1;
|
|
1083
|
+
const name = colon > nameStart ? input.slice(nameStart, colon).replace(/\\\n/g, "") : "";
|
|
1084
|
+
if (context.dialect !== "bash" && (/^(?:READ)?NULLCMD$/.test(name) || /^(?:(?:dis_)?(?:functions|[gs]?aliases)|options|commands)$/.test(name) && "[=:".includes(input[colon] ?? "")))
|
|
1085
|
+
return { kind: "opaque", reason: "dynamic-execution" };
|
|
1086
|
+
if (name === "PS4")
|
|
1087
|
+
context.variableSink = true;
|
|
1088
|
+
let evaluation;
|
|
1089
|
+
let wordOffset = 0;
|
|
1090
|
+
let literalOffset = 0;
|
|
1091
|
+
for (let index = start;index < input.length; index++) {
|
|
1092
|
+
if (--context.remaining < 0)
|
|
1093
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
1094
|
+
const char = input[index];
|
|
1095
|
+
if (char === "}") {
|
|
1096
|
+
if (evaluation && bashEvaluatesExpansion({ word: text.word.slice(wordOffset), literal: text.literal.slice(literalOffset), output: text.output }, evaluation, context))
|
|
1097
|
+
return { kind: "opaque", reason: "dynamic-execution" };
|
|
1098
|
+
return index;
|
|
562
1099
|
}
|
|
563
|
-
if (
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
if (
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
1100
|
+
if (index === colon && !evaluation) {
|
|
1101
|
+
if (char === ":" && !"-=?+".includes(input[index + 1] ?? ""))
|
|
1102
|
+
evaluation = "arithmetic";
|
|
1103
|
+
if (char === "=" || char === ":" && input[index + 1] === "=")
|
|
1104
|
+
evaluation = "deferred";
|
|
1105
|
+
if (evaluation) {
|
|
1106
|
+
wordOffset = text.word.length;
|
|
1107
|
+
literalOffset = text.literal.length;
|
|
1108
|
+
}
|
|
570
1109
|
}
|
|
571
|
-
if (
|
|
572
|
-
|
|
573
|
-
|
|
1110
|
+
if (char === "@") {
|
|
1111
|
+
PARAMETER_PROMPT_RE.lastIndex = index;
|
|
1112
|
+
if (PARAMETER_PROMPT_RE.test(input))
|
|
1113
|
+
return { kind: "opaque", reason: "dynamic-execution" };
|
|
574
1114
|
}
|
|
575
|
-
if (
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
1115
|
+
if (!quoted && context.dialect !== "bash" && char === "(" && index > start)
|
|
1116
|
+
return { kind: "opaque", reason: "dynamic-execution" };
|
|
1117
|
+
if (quoted && char === "'" && input[index - 1] === "$") {
|
|
1118
|
+
const ansi = bashAnsiQuote(input, index);
|
|
1119
|
+
if (!ansi)
|
|
1120
|
+
return { kind: "opaque", reason: "unterminated-quote" };
|
|
1121
|
+
text.literal += ansi.value;
|
|
1122
|
+
}
|
|
1123
|
+
const subscript = index === colon && char === "[";
|
|
1124
|
+
const unit = subscript ? scanBashSubscript(input, index + 1, depth, context, commands) : quoted && char === "'" ? scanBashSpan(input, index + 1, depth, context, commands, BASH_SPANS.parameterQuote, false, text) : quoted && char === '"' ? scanBashSpan(input, index + 1, depth, context, commands, BASH_SPANS.double, false, text) : scanBashUnit(input, index, depth, context, commands, quoted ? "quoted" : "word", false, text);
|
|
1125
|
+
if (typeof unit === "object")
|
|
1126
|
+
return unit;
|
|
1127
|
+
if (quoted && unit !== undefined && input.startsWith("$(", index) && input.slice(index, unit + 1).includes("}"))
|
|
1128
|
+
return { kind: "opaque", reason: "command-substitution" };
|
|
1129
|
+
if (subscript || index === nameStart && input.startsWith("${", index) && unit !== undefined) {
|
|
1130
|
+
LINE_CONTINUATION_RE.lastIndex = Number(unit) + 1;
|
|
1131
|
+
colon = LINE_CONTINUATION_RE.exec(input) ? LINE_CONTINUATION_RE.lastIndex : Number(unit) + 1;
|
|
1132
|
+
}
|
|
1133
|
+
if (unit !== undefined)
|
|
1134
|
+
index = unit;
|
|
1135
|
+
else
|
|
1136
|
+
bashAppend(text, char);
|
|
1137
|
+
}
|
|
1138
|
+
return { kind: "opaque", reason: "command-substitution" };
|
|
1139
|
+
}
|
|
1140
|
+
function scanBashConditional(input, start, depth, context, commands) {
|
|
1141
|
+
const words = [];
|
|
1142
|
+
let text = bashText();
|
|
1143
|
+
let wordStarted = false;
|
|
1144
|
+
let hasWord = false;
|
|
1145
|
+
let parenDepth = 0;
|
|
1146
|
+
let patternParenDepth = 0;
|
|
1147
|
+
const flushWord = () => {
|
|
1148
|
+
if (!hasWord)
|
|
1149
|
+
return;
|
|
1150
|
+
words.push(text);
|
|
1151
|
+
text = bashText();
|
|
1152
|
+
hasWord = false;
|
|
1153
|
+
};
|
|
1154
|
+
for (let index = start;index < input.length; index++) {
|
|
1155
|
+
if (--context.remaining < 0)
|
|
1156
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
1157
|
+
const char = input[index];
|
|
1158
|
+
if (char === "\\" && input[index + 1] === `
|
|
1159
|
+
`) {
|
|
1160
|
+
index++;
|
|
581
1161
|
continue;
|
|
582
1162
|
}
|
|
583
|
-
if (
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
1163
|
+
if (!wordStarted)
|
|
1164
|
+
flushWord();
|
|
1165
|
+
const close = !wordStarted && char === "]" ? bashOperator(input, index, ["]]"]) : undefined;
|
|
1166
|
+
if (typeof close === "object")
|
|
1167
|
+
return close;
|
|
1168
|
+
if (close) {
|
|
1169
|
+
BRACE_CLOSE_AHEAD_RE.lastIndex = index + 2;
|
|
1170
|
+
if (BRACE_CLOSE_AHEAD_RE.test(input)) {
|
|
1171
|
+
if (parenDepth !== 0)
|
|
1172
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
1173
|
+
const evaluated = words.some((word, at) => words[at - 1]?.word === "-v" && bashEvaluatesExpansion(word, "binding", context) || (context.dialect !== "bash" && words[at - 1]?.word === "-t" || BASH_ARITHMETIC_COMPARISONS.has(words[at - 1]?.word ?? "") || BASH_ARITHMETIC_COMPARISONS.has(words[at + 1]?.word ?? "")) && bashEvaluatesExpansion(word, "arithmetic", context));
|
|
1174
|
+
if (evaluated)
|
|
1175
|
+
return { kind: "opaque", reason: "dynamic-execution" };
|
|
1176
|
+
return index + 1;
|
|
590
1177
|
}
|
|
591
|
-
commandStart = true;
|
|
592
|
-
continue;
|
|
593
|
-
}
|
|
594
|
-
const token = boundary ? /^[A-Za-z_][A-Za-z0-9_]*(?=[ \t\n;()<>]|$)/.exec(input.slice(index))?.[0] : undefined;
|
|
595
|
-
if (token === "case" && commandStart)
|
|
596
|
-
cases.push("header");
|
|
597
|
-
if (token === "in" && cases.at(-1) === "header")
|
|
598
|
-
cases[cases.length - 1] = "pattern";
|
|
599
|
-
if (token === "esac" && (commandStart || cases.at(-1) === "pattern"))
|
|
600
|
-
cases.pop();
|
|
601
|
-
if (token) {
|
|
602
|
-
commandStart = commandStart && ["if", "while", "until", "then", "elif", "else", "do"].includes(token);
|
|
603
|
-
index += token.length - 1;
|
|
604
|
-
continue;
|
|
605
|
-
}
|
|
606
|
-
if (cases.length && char === ";" && /[;&]/.test(input[index + 1] ?? ""))
|
|
607
|
-
cases[cases.length - 1] = "pattern";
|
|
608
|
-
if (cases.at(-1) === "pattern" && char === "(")
|
|
609
|
-
continue;
|
|
610
|
-
if (cases.at(-1) === "pattern" && char === ")") {
|
|
611
|
-
cases[cases.length - 1] = "body";
|
|
612
|
-
commandStart = true;
|
|
613
|
-
continue;
|
|
614
1178
|
}
|
|
615
|
-
if (
|
|
616
|
-
const
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
1179
|
+
if (!wordStarted && char === "#") {
|
|
1180
|
+
const newline = input.indexOf(`
|
|
1181
|
+
`, index);
|
|
1182
|
+
if (newline < 0)
|
|
1183
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
1184
|
+
index = newline;
|
|
621
1185
|
continue;
|
|
622
1186
|
}
|
|
623
|
-
if (char === "
|
|
624
|
-
|
|
625
|
-
if (!
|
|
626
|
-
|
|
627
|
-
index = nested.end;
|
|
628
|
-
commandStart = false;
|
|
1187
|
+
if (char === " " || char === "\t" || char === `
|
|
1188
|
+
`) {
|
|
1189
|
+
if (!patternParenDepth)
|
|
1190
|
+
wordStarted = false;
|
|
629
1191
|
continue;
|
|
630
1192
|
}
|
|
631
|
-
if (char ===
|
|
632
|
-
return {
|
|
633
|
-
if (
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
if (input[++index] !== `
|
|
649
|
-
`)
|
|
650
|
-
source += input[index];
|
|
651
|
-
continue;
|
|
652
|
-
}
|
|
653
|
-
source += input[index];
|
|
654
|
-
}
|
|
655
|
-
return;
|
|
656
|
-
}
|
|
657
|
-
if (!mode && input.startsWith("$(", start) && !input.startsWith("$((", start))
|
|
658
|
-
return bashDelimited(input, start + 1, depth);
|
|
659
|
-
if (!mode && /^\$\{[ \t\n|]/.test(input.slice(start))) {
|
|
660
|
-
const nested = bashDelimited(input, start + 1, depth);
|
|
661
|
-
if (!nested)
|
|
662
|
-
return;
|
|
663
|
-
return { ...nested, source: nested.source.startsWith("|") ? nested.source.slice(1) : nested.source };
|
|
664
|
-
}
|
|
665
|
-
const kind = mode ?? (input[start + 1] === "{" ? "parameter" : input[start + 1] === "[" ? "subscript" : "arithmetic");
|
|
666
|
-
const arithmetic = ["arithmetic", "arithmetic-group", "subscript"].includes(kind);
|
|
667
|
-
const offset = mode ? kind === "heredoc" ? 0 : kind === "arithmetic" || kind === "test" ? 2 : 1 : kind === "arithmetic" ? 3 : 2;
|
|
668
|
-
const close = kind === "heredoc" ? undefined : kind === "double" ? '"' : kind === "parameter" ? "}" : kind === "subscript" ? "]" : kind === "test" ? "]]" : kind === "arithmetic" ? "))" : ")";
|
|
669
|
-
const substitutions = [];
|
|
670
|
-
for (let index = start + offset;index < input.length; index++) {
|
|
671
|
-
const char = input[index];
|
|
672
|
-
if (close && input.startsWith(close, index))
|
|
673
|
-
return { source: input.slice(start + offset, index), end: index + close.length - 1, substitutions };
|
|
674
|
-
if (char === "\\") {
|
|
675
|
-
if (kind !== "heredoc" && kind !== "double" || '$`\\\n"'.includes(input[index + 1] ?? "\x00"))
|
|
676
|
-
index++;
|
|
1193
|
+
if (char === ";")
|
|
1194
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
1195
|
+
if (char === "(" || char === ")") {
|
|
1196
|
+
if (char === ")" && parenDepth === 0)
|
|
1197
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
1198
|
+
const inPattern = patternParenDepth > 0 || char === "(" && ["=", "==", "!=", "=~"].includes(words.at(-1)?.word ?? "");
|
|
1199
|
+
parenDepth += char === "(" ? 1 : -1;
|
|
1200
|
+
if (inPattern) {
|
|
1201
|
+
patternParenDepth += char === "(" ? 1 : -1;
|
|
1202
|
+
wordStarted = true;
|
|
1203
|
+
hasWord = true;
|
|
1204
|
+
bashAppend(text, char);
|
|
1205
|
+
continue;
|
|
1206
|
+
}
|
|
1207
|
+
flushWord();
|
|
1208
|
+
words.push({ word: char, literal: "", output: "" });
|
|
1209
|
+
wordStarted = false;
|
|
677
1210
|
continue;
|
|
678
1211
|
}
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
index =
|
|
1212
|
+
const unit = scanBashUnit(input, index, depth, context, commands, "word", true, text);
|
|
1213
|
+
if (typeof unit === "object")
|
|
1214
|
+
return unit;
|
|
1215
|
+
if (unit !== undefined)
|
|
1216
|
+
index = unit;
|
|
1217
|
+
if (unit === undefined && !patternParenDepth && "&|<>".includes(char)) {
|
|
1218
|
+
flushWord();
|
|
1219
|
+
words.push({ word: char, literal: "", output: "" });
|
|
1220
|
+
wordStarted = false;
|
|
684
1221
|
continue;
|
|
685
1222
|
}
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
1223
|
+
wordStarted = true;
|
|
1224
|
+
hasWord = true;
|
|
1225
|
+
if (unit === undefined)
|
|
1226
|
+
bashAppend(text, char);
|
|
1227
|
+
}
|
|
1228
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
1229
|
+
}
|
|
1230
|
+
function scanBashArrayOrPattern(input, start, depth, context, commands, mode) {
|
|
1231
|
+
if (depth > MAX_SUBSTITUTION_DEPTH)
|
|
1232
|
+
return { kind: "opaque", reason: "command-substitution" };
|
|
1233
|
+
const text = mode === "array" ? bashText() : undefined;
|
|
1234
|
+
let wordStarted = false;
|
|
1235
|
+
for (let index = start + 1;index < input.length; index++) {
|
|
1236
|
+
if (--context.remaining < 0)
|
|
1237
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
1238
|
+
const char = input[index];
|
|
1239
|
+
if (char === "\\" && input[index + 1] === `
|
|
1240
|
+
`) {
|
|
1241
|
+
index++;
|
|
692
1242
|
continue;
|
|
693
1243
|
}
|
|
694
|
-
if (char === "
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
index = nested.end;
|
|
700
|
-
continue;
|
|
1244
|
+
if (text && (char === ")" || char === " " || char === "\t" || char === `
|
|
1245
|
+
`)) {
|
|
1246
|
+
bashEvaluatesExpansion(text, "deferred", context);
|
|
1247
|
+
text.literal = "";
|
|
1248
|
+
text.output = "";
|
|
701
1249
|
}
|
|
702
|
-
if (
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
1250
|
+
if (char === ")")
|
|
1251
|
+
return index;
|
|
1252
|
+
if (mode === "array" && !wordStarted && char === "#") {
|
|
1253
|
+
const newline = input.indexOf(`
|
|
1254
|
+
`, index);
|
|
1255
|
+
if (newline < 0)
|
|
1256
|
+
return { kind: "opaque", reason: "command-substitution" };
|
|
1257
|
+
index = newline;
|
|
708
1258
|
continue;
|
|
709
1259
|
}
|
|
710
|
-
if (
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
return;
|
|
714
|
-
substitutions.push(...nested.substitutions);
|
|
715
|
-
index = nested.end;
|
|
1260
|
+
if (char === " " || char === "\t" || mode === "array" && char === `
|
|
1261
|
+
`) {
|
|
1262
|
+
wordStarted = false;
|
|
716
1263
|
continue;
|
|
717
1264
|
}
|
|
718
|
-
if (
|
|
719
|
-
|
|
1265
|
+
if (char === `
|
|
1266
|
+
` || char === ";" || char === "&" || mode === "array" && "|(".includes(char))
|
|
1267
|
+
return { kind: "opaque", reason: "command-substitution" };
|
|
1268
|
+
wordStarted = true;
|
|
1269
|
+
const unit = mode === "array" && char === "=" && input[index + 1] === "(" ? scanBashNested(input, index + 2, depth, context, commands, ")") : char === "(" ? scanBashArrayOrPattern(input, index, depth + 1, context, commands, mode) : char === "[" ? scanBashSubscript(input, index + 1, depth, context, commands) : scanBashUnit(input, index, depth, context, commands, "word", false, text);
|
|
1270
|
+
if (typeof unit === "object")
|
|
1271
|
+
return unit;
|
|
1272
|
+
if (unit !== undefined)
|
|
1273
|
+
index = unit;
|
|
1274
|
+
else if (text)
|
|
1275
|
+
text.literal += char;
|
|
720
1276
|
}
|
|
721
|
-
|
|
722
|
-
return { source: input.slice(start), end: input.length - 1, substitutions };
|
|
1277
|
+
return { kind: "opaque", reason: "command-substitution" };
|
|
723
1278
|
}
|
|
724
1279
|
function bashAnsiQuote(input, start) {
|
|
725
1280
|
let value = "";
|
|
@@ -731,58 +1286,45 @@ function bashAnsiQuote(input, start) {
|
|
|
731
1286
|
continue;
|
|
732
1287
|
}
|
|
733
1288
|
const escaped = input[++index];
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
f: "\f",
|
|
740
|
-
n: `
|
|
741
|
-
`,
|
|
742
|
-
r: "\r",
|
|
743
|
-
t: "\t",
|
|
744
|
-
v: "\v",
|
|
745
|
-
"\\": "\\",
|
|
746
|
-
"'": "'",
|
|
747
|
-
'"': '"',
|
|
748
|
-
"?": "?"
|
|
749
|
-
};
|
|
750
|
-
if (escaped in simple)
|
|
751
|
-
value += simple[escaped];
|
|
752
|
-
else if (escaped === "c" && index + 1 < input.length)
|
|
753
|
-
value += String.fromCharCode(input[++index].toUpperCase().charCodeAt(0) & 31);
|
|
754
|
-
else {
|
|
755
|
-
const digits = escaped === "x" ? /^[\da-fA-F]{1,2}/.exec(input.slice(index + 1))?.[0] : escaped === "u" ? /^[\da-fA-F]{1,4}/.exec(input.slice(index + 1))?.[0] : escaped === "U" ? /^[\da-fA-F]{1,8}/.exec(input.slice(index + 1))?.[0] : /[0-7]/.test(escaped ?? "") ? /^[0-7]{1,3}/.exec(input.slice(index))?.[0] : undefined;
|
|
756
|
-
if (!digits)
|
|
757
|
-
value += `\\${escaped}`;
|
|
758
|
-
else {
|
|
759
|
-
const octal = /[0-7]/.test(escaped);
|
|
760
|
-
const point = parseInt(digits, octal ? 8 : 16);
|
|
761
|
-
value += point <= 1114111 ? String.fromCodePoint(point) : "";
|
|
762
|
-
index += digits.length - (octal ? 1 : 0);
|
|
763
|
-
}
|
|
1289
|
+
if (escaped === undefined)
|
|
1290
|
+
return;
|
|
1291
|
+
if (escaped in BASH_ANSI_ESCAPES) {
|
|
1292
|
+
value += BASH_ANSI_ESCAPES[escaped];
|
|
1293
|
+
continue;
|
|
764
1294
|
}
|
|
1295
|
+
const digits = escaped === "x" ? /^[\da-fA-F]{1,2}/.exec(input.slice(index + 1, index + 3))?.[0] : /[0-7]/.test(escaped) ? /^[0-7]{1,3}/.exec(input.slice(index, index + 3))?.[0] : undefined;
|
|
1296
|
+
if (!digits)
|
|
1297
|
+
return;
|
|
1298
|
+
const octal = /[0-7]/.test(escaped);
|
|
1299
|
+
const point = parseInt(digits, octal ? 8 : 16);
|
|
1300
|
+
if (point === 0)
|
|
1301
|
+
return;
|
|
1302
|
+
value += String.fromCodePoint(point);
|
|
1303
|
+
index += digits.length - (octal ? 1 : 0);
|
|
765
1304
|
}
|
|
766
1305
|
}
|
|
767
|
-
function bashHeredocDelimiter(input, start) {
|
|
768
|
-
const tabs = input[start + 2] === "-";
|
|
1306
|
+
function bashHeredocDelimiter(input, start, tabs) {
|
|
769
1307
|
let delimiter = "";
|
|
1308
|
+
let dashDelimiter;
|
|
770
1309
|
let quoted = false;
|
|
771
1310
|
let quote;
|
|
772
1311
|
let end = start;
|
|
773
1312
|
let started = false;
|
|
774
|
-
for (let index = start
|
|
1313
|
+
for (let index = start;index < input.length; index++) {
|
|
775
1314
|
const char = input[index];
|
|
776
1315
|
if (!started && /[ \t]/.test(char))
|
|
777
1316
|
continue;
|
|
778
1317
|
if (!started && char === "#")
|
|
779
1318
|
return;
|
|
780
1319
|
if (!quote && /[ \t\n;&|()<>]/.test(char))
|
|
781
|
-
return started ? { delimiter, quoted, tabs, end } : undefined;
|
|
1320
|
+
return started ? { delimiter, dashDelimiter, quoted, tabs, end } : undefined;
|
|
1321
|
+
if (!quote && char === "$" && input.startsWith("\\\n", index + 1))
|
|
1322
|
+
return;
|
|
782
1323
|
if (!quote && input.startsWith("$'", index)) {
|
|
783
1324
|
const literal = bashAnsiQuote(input, index + 1);
|
|
784
|
-
if (!literal)
|
|
1325
|
+
if (!literal || literal.end !== input.indexOf("'", index + 2))
|
|
785
1326
|
return;
|
|
1327
|
+
dashDelimiter = `${dashDelimiter ?? delimiter}$${input.slice(index + 2, literal.end)}`;
|
|
786
1328
|
delimiter += literal.value;
|
|
787
1329
|
quoted = true;
|
|
788
1330
|
started = true;
|
|
@@ -790,13 +1332,8 @@ function bashHeredocDelimiter(input, start) {
|
|
|
790
1332
|
end = index;
|
|
791
1333
|
continue;
|
|
792
1334
|
}
|
|
793
|
-
if (!quote && input.startsWith('$"', index))
|
|
794
|
-
|
|
795
|
-
quoted = true;
|
|
796
|
-
started = true;
|
|
797
|
-
end = ++index;
|
|
798
|
-
continue;
|
|
799
|
-
}
|
|
1335
|
+
if (!quote && input.startsWith('$"', index))
|
|
1336
|
+
return;
|
|
800
1337
|
if (char === quote) {
|
|
801
1338
|
quote = undefined;
|
|
802
1339
|
end = index;
|
|
@@ -814,7 +1351,10 @@ function bashHeredocDelimiter(input, start) {
|
|
|
814
1351
|
if (!quote || '$`"\\'.includes(next)) {
|
|
815
1352
|
quoted = true;
|
|
816
1353
|
started = true;
|
|
817
|
-
|
|
1354
|
+
const escaped = input[++index];
|
|
1355
|
+
if (dashDelimiter !== undefined)
|
|
1356
|
+
dashDelimiter += escaped;
|
|
1357
|
+
delimiter += escaped;
|
|
818
1358
|
end = index;
|
|
819
1359
|
continue;
|
|
820
1360
|
}
|
|
@@ -826,69 +1366,92 @@ function bashHeredocDelimiter(input, start) {
|
|
|
826
1366
|
end = index;
|
|
827
1367
|
continue;
|
|
828
1368
|
}
|
|
1369
|
+
if (dashDelimiter !== undefined)
|
|
1370
|
+
dashDelimiter += char;
|
|
829
1371
|
delimiter += char;
|
|
830
1372
|
started = true;
|
|
831
1373
|
end = index;
|
|
832
1374
|
}
|
|
833
1375
|
if (started && !quote)
|
|
834
|
-
return { delimiter, quoted, tabs, end };
|
|
1376
|
+
return { delimiter, dashDelimiter, quoted, tabs, end };
|
|
835
1377
|
}
|
|
836
1378
|
function bashHeredoc(input, start, delimiter) {
|
|
837
1379
|
const bodyStart = start;
|
|
838
1380
|
let lineStart = start;
|
|
839
1381
|
let line = "";
|
|
1382
|
+
let backslashes = 0;
|
|
840
1383
|
for (let index = start;index <= input.length; index++) {
|
|
841
1384
|
if (index < input.length && input[index] !== `
|
|
842
1385
|
`)
|
|
843
1386
|
continue;
|
|
844
|
-
const text = input.slice(start, index);
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
1387
|
+
const text = delimiter.tabs && start === lineStart ? input.slice(start, index).replace(/^\t+/, "") : input.slice(start, index);
|
|
1388
|
+
let run = 0;
|
|
1389
|
+
while (text[text.length - 1 - run] === "\\")
|
|
1390
|
+
run++;
|
|
1391
|
+
backslashes = run === text.length ? backslashes + run : run;
|
|
1392
|
+
const continued = !delimiter.quoted && backslashes % 2 === 1 && index < input.length;
|
|
1393
|
+
const maxLength = Math.max(delimiter.delimiter.length, delimiter.dashDelimiter?.length ?? 0);
|
|
1394
|
+
if (line.length <= maxLength)
|
|
1395
|
+
line += continued ? text.slice(0, -1) : text;
|
|
1396
|
+
if (continued) {
|
|
1397
|
+
backslashes--;
|
|
848
1398
|
start = index + 1;
|
|
849
1399
|
continue;
|
|
850
1400
|
}
|
|
851
|
-
if (line === delimiter.
|
|
1401
|
+
if (delimiter.dashDelimiter !== undefined && line === delimiter.dashDelimiter)
|
|
1402
|
+
return;
|
|
1403
|
+
if (line === delimiter.delimiter) {
|
|
1404
|
+
if (start > lineStart && input.slice(index + 1).includes(delimiter.delimiter))
|
|
1405
|
+
return;
|
|
852
1406
|
return { source: input.slice(bodyStart, lineStart), end: index };
|
|
1407
|
+
}
|
|
853
1408
|
line = "";
|
|
1409
|
+
backslashes = 0;
|
|
854
1410
|
start = index + 1;
|
|
855
1411
|
lineStart = start;
|
|
856
1412
|
}
|
|
857
1413
|
}
|
|
858
1414
|
function scanPowerShell(input) {
|
|
859
|
-
|
|
860
|
-
}
|
|
861
|
-
function scanPowerShellNested(input, depth, budget, hash = false) {
|
|
862
|
-
budget.remaining -= input.length;
|
|
863
|
-
if (input.length > MAX_INPUT_LENGTH || depth >= MAX_SUBSTITUTION_DEPTH || budget.remaining < 0)
|
|
1415
|
+
if (input.length > MAX_INPUT_LENGTH)
|
|
864
1416
|
return { kind: "opaque", reason: "invalid-structure" };
|
|
865
1417
|
if (/[\0\u0085\u2013-\u2015\u2018-\u201e\ufeff]/.test(input))
|
|
866
1418
|
return { kind: "opaque", reason: "invalid-structure" };
|
|
1419
|
+
const result = scanPowerShellList(input, 0, 0, { remaining: MAX_INPUT_LENGTH * MAX_SUBSTITUTION_DEPTH });
|
|
1420
|
+
if (result.kind === "opaque")
|
|
1421
|
+
return result;
|
|
1422
|
+
return { kind: "scanned", commands: result.commands };
|
|
1423
|
+
}
|
|
1424
|
+
function scanPowerShellList(input, start, depth, budget, close, hash = false, skipped) {
|
|
1425
|
+
if (depth >= MAX_SUBSTITUTION_DEPTH || budget.remaining < 0)
|
|
1426
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
867
1427
|
const commands = [];
|
|
868
1428
|
const nestedCommands = [];
|
|
869
1429
|
const words = [];
|
|
870
1430
|
const rawWords = [];
|
|
871
1431
|
const wordEnds = [];
|
|
872
|
-
|
|
1432
|
+
const initialExpression = hash === true || hash === "clause";
|
|
1433
|
+
const initialClause = hash === "clause" || hash === "switch" ? "member" : undefined;
|
|
1434
|
+
let segment = start;
|
|
873
1435
|
let word = "";
|
|
874
1436
|
let started = false;
|
|
875
|
-
let wordStart =
|
|
1437
|
+
let wordStart = start;
|
|
876
1438
|
let quote;
|
|
877
1439
|
let standalone = false;
|
|
878
|
-
let expression =
|
|
879
|
-
let
|
|
1440
|
+
let expression = initialExpression;
|
|
1441
|
+
let clause = initialClause;
|
|
1442
|
+
let after;
|
|
1443
|
+
let indexable = false;
|
|
880
1444
|
let stopParsing = false;
|
|
881
|
-
let commandEnd =
|
|
1445
|
+
let commandEnd = start;
|
|
882
1446
|
let statementHead = true;
|
|
883
1447
|
let invalid = false;
|
|
884
1448
|
let redirectTarget = false;
|
|
885
|
-
let comment = false;
|
|
886
1449
|
let dangling = false;
|
|
887
1450
|
let invocation = false;
|
|
888
1451
|
const finishWord = (end) => {
|
|
889
1452
|
if (!started)
|
|
890
1453
|
return;
|
|
891
|
-
if (word === "--%" && words.length > 0 && !expression && !/['"]/.test(input[wordStart]))
|
|
1454
|
+
if (word === "--%" && words.length > 0 && !expression && !clause && !redirectTarget && !/['"]/.test(input[wordStart]) && !rawWords.at(-1)?.endsWith(",") && !POWERSHELL_PARAMETER_COLON_RE.test(rawWords.at(-1) ?? ""))
|
|
892
1455
|
stopParsing = true;
|
|
893
1456
|
if (!redirectTarget) {
|
|
894
1457
|
if (!words.length && !invocation && !expression)
|
|
@@ -905,17 +1468,15 @@ function scanPowerShellNested(input, depth, budget, hash = false) {
|
|
|
905
1468
|
};
|
|
906
1469
|
const finishCommand = (end, required = false) => {
|
|
907
1470
|
finishWord(end);
|
|
908
|
-
|
|
909
|
-
const resource = input.slice(start, commandEnd).trimEnd();
|
|
910
|
-
if (words.length && !expression)
|
|
1471
|
+
if (words.length && !expression && !clause)
|
|
911
1472
|
commands.push({
|
|
912
|
-
resource,
|
|
1473
|
+
resource: input.slice(segment, commandEnd).trimEnd(),
|
|
913
1474
|
words: [...words],
|
|
914
1475
|
rawWords: [...rawWords],
|
|
915
|
-
wordEnds: wordEnds.map((
|
|
1476
|
+
wordEnds: wordEnds.map((value) => value - segment),
|
|
916
1477
|
...statementHead && !invocation ? { statementHead: true } : {}
|
|
917
1478
|
});
|
|
918
|
-
else if (!expression && invocation || required && !words.length && !nestedCommands.length)
|
|
1479
|
+
else if (!expression && !clause && invocation || required && !words.length && !nestedCommands.length || clause !== undefined && clause !== "member")
|
|
919
1480
|
invalid = true;
|
|
920
1481
|
if (redirectTarget)
|
|
921
1482
|
invalid = true;
|
|
@@ -925,16 +1486,25 @@ function scanPowerShellNested(input, depth, budget, hash = false) {
|
|
|
925
1486
|
wordEnds.length = 0;
|
|
926
1487
|
redirectTarget = false;
|
|
927
1488
|
invocation = false;
|
|
928
|
-
expression =
|
|
929
|
-
|
|
1489
|
+
expression = initialExpression;
|
|
1490
|
+
clause = initialClause;
|
|
1491
|
+
after = undefined;
|
|
1492
|
+
indexable = false;
|
|
930
1493
|
stopParsing = false;
|
|
931
1494
|
};
|
|
932
|
-
|
|
1495
|
+
let index = start;
|
|
1496
|
+
for (;index < input.length; index++) {
|
|
1497
|
+
if (--budget.remaining < 0)
|
|
1498
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
1499
|
+
if (skipped?.has(index))
|
|
1500
|
+
continue;
|
|
933
1501
|
const char = input[index];
|
|
1502
|
+
const inExpression = expression && !redirectTarget;
|
|
1503
|
+
const atBoundary = !started || !inExpression && word.endsWith(",");
|
|
934
1504
|
if (!started)
|
|
935
1505
|
wordStart = index;
|
|
936
1506
|
if (stopParsing) {
|
|
937
|
-
const stop = powerShellStopParsing(input, index);
|
|
1507
|
+
const stop = powerShellStopParsing(input, index, skipped);
|
|
938
1508
|
const text = input.slice(index, stop).trim();
|
|
939
1509
|
if (text) {
|
|
940
1510
|
wordStart = index + input.slice(index, stop).search(/\S/);
|
|
@@ -946,43 +1516,42 @@ function scanPowerShellNested(input, depth, budget, hash = false) {
|
|
|
946
1516
|
index = stop - 1;
|
|
947
1517
|
continue;
|
|
948
1518
|
}
|
|
949
|
-
if (quote
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
finishWord(index + 1);
|
|
958
|
-
} else
|
|
959
|
-
word += char;
|
|
960
|
-
continue;
|
|
961
|
-
}
|
|
962
|
-
if (quote === "double") {
|
|
963
|
-
if (char === '"' && input[index + 1] === '"') {
|
|
964
|
-
word += '"';
|
|
965
|
-
index++;
|
|
966
|
-
} else if (char === '"') {
|
|
1519
|
+
if (quote) {
|
|
1520
|
+
let nextQuote = index + 1;
|
|
1521
|
+
while (skipped?.has(nextQuote))
|
|
1522
|
+
nextQuote++;
|
|
1523
|
+
if (char === quote && input[nextQuote] === quote) {
|
|
1524
|
+
word += quote;
|
|
1525
|
+
index = nextQuote;
|
|
1526
|
+
} else if (char === quote) {
|
|
967
1527
|
quote = undefined;
|
|
968
|
-
if (standalone)
|
|
1528
|
+
if (standalone) {
|
|
969
1529
|
finishWord(index + 1);
|
|
970
|
-
|
|
971
|
-
|
|
1530
|
+
indexable = "closed";
|
|
1531
|
+
}
|
|
1532
|
+
} else if (quote === '"' && char === "`") {
|
|
1533
|
+
const escape = powerShellEscape(input, index, false, skipped);
|
|
972
1534
|
if (!escape)
|
|
973
1535
|
return { kind: "opaque", reason: "unterminated-escape" };
|
|
974
1536
|
word += escape.value;
|
|
975
1537
|
index = escape.end;
|
|
976
|
-
} else if (char === "$" && input[index + 1] === "
|
|
977
|
-
const
|
|
978
|
-
if (
|
|
1538
|
+
} else if (quote === '"' && char === "$" && input[index + 1] === "{") {
|
|
1539
|
+
const end = powerShellBracedVariable(input, index, skipped);
|
|
1540
|
+
if (end === undefined)
|
|
1541
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
1542
|
+
word += input.slice(index, end + 1);
|
|
1543
|
+
index = end;
|
|
1544
|
+
} else if (quote === '"' && char === "$" && input[index + 1] === "(") {
|
|
1545
|
+
const sub = powerShellSubExpression(input, index + 2, false, budget, skipped);
|
|
1546
|
+
if (!sub)
|
|
979
1547
|
return { kind: "opaque", reason: "invalid-structure" };
|
|
980
|
-
const result =
|
|
1548
|
+
const result = scanPowerShellList(input, index + 2, depth + 1, budget, ")", false, sub.skipped);
|
|
981
1549
|
if (result.kind === "opaque")
|
|
982
1550
|
return result;
|
|
983
1551
|
nestedCommands.push(...result.commands);
|
|
984
|
-
|
|
985
|
-
|
|
1552
|
+
const end = sub.rawEnd !== undefined && sub.rawEnd > result.end ? sub.rawEnd : result.end;
|
|
1553
|
+
word += input.slice(index, end + 1);
|
|
1554
|
+
index = end;
|
|
986
1555
|
} else
|
|
987
1556
|
word += char;
|
|
988
1557
|
continue;
|
|
@@ -990,176 +1559,203 @@ function scanPowerShellNested(input, depth, budget, hash = false) {
|
|
|
990
1559
|
if (char === "'" || char === '"') {
|
|
991
1560
|
if (!started && words.length === 0 && !invocation)
|
|
992
1561
|
expression = true;
|
|
993
|
-
quote = char
|
|
994
|
-
standalone = !
|
|
1562
|
+
quote = char;
|
|
1563
|
+
standalone = atBoundary || expression && !redirectTarget || indexable === "member" && /[.:]$/.test(word);
|
|
1564
|
+
if (!standalone)
|
|
1565
|
+
indexable = false;
|
|
995
1566
|
started = true;
|
|
996
1567
|
continue;
|
|
997
1568
|
}
|
|
998
1569
|
if (char === "`") {
|
|
999
|
-
const escape = powerShellEscape(input, index);
|
|
1570
|
+
const escape = powerShellEscape(input, index, atBoundary || inExpression, skipped);
|
|
1000
1571
|
if (!escape)
|
|
1001
1572
|
return { kind: "opaque", reason: "unterminated-escape" };
|
|
1002
|
-
|
|
1573
|
+
const rawSpace = /\s/.test(input[index + 1] ?? "");
|
|
1574
|
+
if ((inExpression || atBoundary) && started && rawSpace)
|
|
1575
|
+
finishWord(index);
|
|
1576
|
+
else if (!atBoundary || !rawSpace) {
|
|
1003
1577
|
started = true;
|
|
1578
|
+
indexable = false;
|
|
1004
1579
|
word += escape.value;
|
|
1005
1580
|
}
|
|
1006
1581
|
index = escape.end;
|
|
1007
1582
|
continue;
|
|
1008
1583
|
}
|
|
1009
|
-
if (!started && words.length > 0 && !expression &&
|
|
1584
|
+
if (!started && words.length > 0 && !expression && !clause && !redirectTarget && testAt(POWERSHELL_STOP_PARSING_RE, input, index)) {
|
|
1010
1585
|
word = "--%";
|
|
1011
1586
|
started = true;
|
|
1012
1587
|
finishWord(index + 3);
|
|
1013
|
-
stopParsing = true;
|
|
1014
1588
|
index += 2;
|
|
1015
1589
|
continue;
|
|
1016
1590
|
}
|
|
1017
|
-
if (char === "<" && input[index + 1] === "#" &&
|
|
1018
|
-
const
|
|
1019
|
-
if (
|
|
1591
|
+
if (char === "<" && input[index + 1] === "#" && (atBoundary || inExpression || indexable === "member")) {
|
|
1592
|
+
const memberOperator = indexable === "member" && /[.:]$/.test(started ? word : words.at(-1) ?? "");
|
|
1593
|
+
if (started)
|
|
1594
|
+
finishWord(index);
|
|
1595
|
+
const end = input.indexOf("#>", index + 2);
|
|
1596
|
+
if (end < 0)
|
|
1020
1597
|
return { kind: "opaque", reason: "invalid-structure" };
|
|
1021
|
-
if (!
|
|
1022
|
-
|
|
1023
|
-
index = end;
|
|
1598
|
+
if (!memberOperator)
|
|
1599
|
+
indexable = false;
|
|
1600
|
+
index = end + 1;
|
|
1024
1601
|
continue;
|
|
1025
1602
|
}
|
|
1026
|
-
if (char === "#" && (
|
|
1027
|
-
|
|
1603
|
+
if (char === "#" && (atBoundary || indexable === "member" || inExpression && !(close === "]" && /^[\p{L}\p{Nl}_][\p{L}\p{Nl}\d_.#+`\\]*$/u.test(word)))) {
|
|
1604
|
+
const prev = started ? word : words.at(-1) ?? "";
|
|
1605
|
+
const memberOperator = indexable === "member" && /[.:]$/.test(prev);
|
|
1606
|
+
if (clause && clause !== "member" || prev.endsWith(",") || memberOperator)
|
|
1607
|
+
finishWord(index);
|
|
1608
|
+
else if (words.length || started || invocation)
|
|
1028
1609
|
finishCommand(index);
|
|
1029
1610
|
statementHead = !dangling;
|
|
1030
|
-
comment = true;
|
|
1031
1611
|
const endings = [input.indexOf(`
|
|
1032
1612
|
`, index), input.indexOf("\r", index)].filter((ending) => ending >= 0);
|
|
1033
1613
|
const newline = endings.length > 0 ? Math.min(...endings) : -1;
|
|
1034
|
-
if (newline === -1)
|
|
1614
|
+
if (newline === -1) {
|
|
1615
|
+
index = input.length;
|
|
1035
1616
|
break;
|
|
1036
|
-
|
|
1617
|
+
}
|
|
1037
1618
|
index = input[newline] === "\r" && input[newline + 1] === `
|
|
1038
1619
|
` ? newline + 1 : newline;
|
|
1039
|
-
segment = index + 1;
|
|
1040
1620
|
continue;
|
|
1041
1621
|
}
|
|
1042
|
-
|
|
1622
|
+
if (inExpression && started && (char === ">" || char === "*" && input[index + 1] === ">"))
|
|
1623
|
+
finishWord(index);
|
|
1624
|
+
const redirect = !started && (char === ">" || char === "*" || /\d/.test(char) && (words.length > 0 || testAt(POWERSHELL_MERGE_REDIRECT_RE, input, index))) ? powerShellRedirect(input, index) : undefined;
|
|
1043
1625
|
if (redirect === false)
|
|
1044
1626
|
return { kind: "opaque", reason: "invalid-redirect" };
|
|
1045
1627
|
if (redirect) {
|
|
1046
|
-
if (redirectTarget)
|
|
1047
|
-
return { kind: "opaque", reason: "invalid-redirect" };
|
|
1048
|
-
if (words.length === 0)
|
|
1628
|
+
if (redirectTarget || words.length === 0 || clause && clause !== "member")
|
|
1049
1629
|
return { kind: "opaque", reason: "invalid-redirect" };
|
|
1050
1630
|
redirectTarget = !redirect.includes("&");
|
|
1631
|
+
indexable = false;
|
|
1051
1632
|
index += redirect.length - 1;
|
|
1052
1633
|
commandEnd = index + 1;
|
|
1053
1634
|
continue;
|
|
1054
1635
|
}
|
|
1055
|
-
if (!started && !words.length && !invocation && !expression &&
|
|
1056
|
-
const
|
|
1057
|
-
if (
|
|
1058
|
-
|
|
1059
|
-
compound = true;
|
|
1060
|
-
index += keyword.length - 1;
|
|
1636
|
+
if (!started && !words.length && !invocation && !expression && !clause && char === ":") {
|
|
1637
|
+
const label = matchAt(POWERSHELL_LABEL_RE, input, index);
|
|
1638
|
+
if (label) {
|
|
1639
|
+
index += label[0].length - 1;
|
|
1061
1640
|
continue;
|
|
1062
1641
|
}
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1642
|
+
}
|
|
1643
|
+
if (!started && !invocation && !clause && (!words.length ? !expression : words.every((item) => item.startsWith("["))) && /[A-Za-z]/.test(char)) {
|
|
1644
|
+
const keyword = matchAt(POWERSHELL_KEYWORD_RE, input, index)?.[0]?.toLowerCase();
|
|
1645
|
+
if (keyword && (words.length > 0 ? keyword === "param" && testAt(POWERSHELL_PARAM_RE, input, index) || keyword === "class" || keyword === "enum" : keyword === "param" && testAt(POWERSHELL_PARAM_RE, input, index) || keyword === "foreach" && testAt(POWERSHELL_FOREACH_RE, input, index) || keyword === "until" && after === "do" || (keyword === "else" || keyword === "elseif") && after === "if" || (keyword === "catch" || keyword === "finally") && after === "try" || /^(?:if|for|while|do|switch|function|filter|workflow|parallel|sequence|configuration|try|begin|process|end|clean|trap|class|enum|data|dynamicparam|using|break|continue)$/.test(keyword))) {
|
|
1646
|
+
expression = /^(?:class|enum|break|continue)$/.test(keyword);
|
|
1647
|
+
clause = keyword === "using" || keyword === "break" || keyword === "continue" ? "member" : keyword === "param" || keyword === "until" || keyword === "while" && after === "do" ? "paren" : keyword === "do" ? "do" : keyword === "if" || keyword === "elseif" ? "if" : keyword === "try" || keyword === "catch" ? "try" : keyword === "switch" ? "switch" : keyword === "class" || keyword === "enum" ? "clause" : "block";
|
|
1648
|
+
after = undefined;
|
|
1066
1649
|
index += keyword.length - 1;
|
|
1067
1650
|
continue;
|
|
1068
1651
|
}
|
|
1069
|
-
if (keyword && /^(?:return|throw|exit
|
|
1652
|
+
if (!words.length && keyword && /^(?:return|throw|exit)$/.test(keyword)) {
|
|
1653
|
+
after = undefined;
|
|
1070
1654
|
index += keyword.length - 1;
|
|
1071
|
-
segment = index + 1;
|
|
1072
1655
|
continue;
|
|
1073
1656
|
}
|
|
1074
1657
|
}
|
|
1075
|
-
|
|
1076
|
-
|
|
1658
|
+
const assign = inExpression && !clause && (char === "=" || /[-+*/%]/.test(char) && input[index + 1] === "=");
|
|
1659
|
+
if (assign || inExpression && close === ")" && !started && testAt(POWERSHELL_IN_RE, input, index)) {
|
|
1660
|
+
if (assign)
|
|
1661
|
+
finishWord(index);
|
|
1077
1662
|
words.length = 0;
|
|
1078
1663
|
rawWords.length = 0;
|
|
1079
1664
|
wordEnds.length = 0;
|
|
1080
1665
|
expression = false;
|
|
1081
|
-
|
|
1666
|
+
indexable = false;
|
|
1667
|
+
if (!assign || char !== "=")
|
|
1082
1668
|
index++;
|
|
1083
|
-
segment = index + 1;
|
|
1084
|
-
continue;
|
|
1085
|
-
}
|
|
1086
|
-
if (expression && !started && /^in\b/i.test(input.slice(index))) {
|
|
1087
|
-
words.length = 0;
|
|
1088
|
-
rawWords.length = 0;
|
|
1089
|
-
wordEnds.length = 0;
|
|
1090
|
-
expression = false;
|
|
1091
|
-
index++;
|
|
1092
|
-
segment = index + 1;
|
|
1093
1669
|
continue;
|
|
1094
1670
|
}
|
|
1095
|
-
if (char === "@" &&
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1671
|
+
if (atBoundary && char === "@" && !testAt(POWERSHELL_AT_OPENER_RE, input, index + 1))
|
|
1672
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
1673
|
+
if (atBoundary && char === "@" && (input[index + 1] === "'" || input[index + 1] === '"')) {
|
|
1674
|
+
if (started)
|
|
1675
|
+
finishWord(index);
|
|
1676
|
+
wordStart = index;
|
|
1677
|
+
const literal = powerShellHereString(input, index, depth, budget, skipped);
|
|
1678
|
+
if (literal.kind === "opaque")
|
|
1679
|
+
return literal;
|
|
1099
1680
|
if (!words.length && !invocation)
|
|
1100
1681
|
expression = true;
|
|
1101
|
-
|
|
1102
|
-
const result = powerShellExpansions(literal.source, depth + 1, budget);
|
|
1103
|
-
if (result.kind === "opaque")
|
|
1104
|
-
return result;
|
|
1105
|
-
nestedCommands.push(...result.commands);
|
|
1106
|
-
}
|
|
1682
|
+
nestedCommands.push(...literal.commands);
|
|
1107
1683
|
word = literal.source;
|
|
1108
1684
|
started = true;
|
|
1109
1685
|
index = literal.end;
|
|
1110
1686
|
finishWord(index + 1);
|
|
1687
|
+
indexable = "closed";
|
|
1111
1688
|
continue;
|
|
1112
1689
|
}
|
|
1113
1690
|
if (char === "$" && input[index + 1] === "{") {
|
|
1114
|
-
const end = input
|
|
1115
|
-
if (end
|
|
1691
|
+
const end = powerShellBracedVariable(input, index, skipped);
|
|
1692
|
+
if (end === undefined)
|
|
1116
1693
|
return { kind: "opaque", reason: "invalid-structure" };
|
|
1117
|
-
if (!started && !words.length && !invocation)
|
|
1694
|
+
if (!started && !words.length && !invocation && hash !== "switch")
|
|
1118
1695
|
expression = true;
|
|
1696
|
+
indexable = atBoundary || indexable === "member" && /[.:]$/.test(word) ? "closed" : false;
|
|
1119
1697
|
word += input.slice(index, end + 1);
|
|
1120
1698
|
started = true;
|
|
1121
1699
|
index = end;
|
|
1700
|
+
if (expression && !redirectTarget && input[index + 1] !== "[")
|
|
1701
|
+
finishWord(index + 1);
|
|
1122
1702
|
continue;
|
|
1123
1703
|
}
|
|
1124
|
-
const opener = (char === "$" || char === "@") && input[index + 1] === "(" ? index + 1 : char === "@" && input[index + 1] === "{" ? index + 1 : char === "(" || char === "{" || char === "[" && (
|
|
1704
|
+
const opener = (char === "$" || atBoundary && char === "@") && input[index + 1] === "(" ? index + 1 : atBoundary && char === "@" && input[index + 1] === "{" ? index + 1 : char === "(" || char === "{" || char === "[" && (inExpression || Boolean(indexable) || !started && !invocation && (!words.length || clause === "block" || clause === "try")) ? index : undefined;
|
|
1125
1705
|
if (opener !== undefined) {
|
|
1126
|
-
|
|
1706
|
+
const openChar = input[opener];
|
|
1707
|
+
const standaloneBlock = atBoundary || inExpression || char === "(" || openChar === "{";
|
|
1708
|
+
const blockClose = openChar === "(" ? ")" : openChar === "[" ? "]" : "}";
|
|
1709
|
+
const blockHash = openChar === "[" ? true : char === "@" && openChar === "{" ? true : clause === "switch" && openChar === "{" ? "switch" : clause === "clause" && openChar === "{" ? "clause" : close === "]" && char === "(" && started ? "clause" : false;
|
|
1710
|
+
if (started && (char === "{" || char === "(" || char === "@" && atBoundary)) {
|
|
1127
1711
|
finishWord(index);
|
|
1712
|
+
if (stopParsing) {
|
|
1713
|
+
index--;
|
|
1714
|
+
continue;
|
|
1715
|
+
}
|
|
1128
1716
|
wordStart = index;
|
|
1129
1717
|
}
|
|
1130
1718
|
if (!started && !words.length && !invocation)
|
|
1131
1719
|
expression = true;
|
|
1132
|
-
const
|
|
1133
|
-
if (!block)
|
|
1134
|
-
return { kind: "opaque", reason: "invalid-structure" };
|
|
1135
|
-
const result = scanPowerShellNested(block.source, depth + 1, budget, input[opener] === "[" || char === "@" && input[opener] === "{");
|
|
1720
|
+
const result = scanPowerShellList(input, opener + 1, depth + 1, budget, blockClose, blockHash, skipped);
|
|
1136
1721
|
if (result.kind === "opaque")
|
|
1137
1722
|
return result;
|
|
1138
1723
|
nestedCommands.push(...result.commands);
|
|
1139
1724
|
started = true;
|
|
1140
|
-
word += input.slice(index,
|
|
1141
|
-
index =
|
|
1142
|
-
if (
|
|
1725
|
+
word += input.slice(index, result.end + 1);
|
|
1726
|
+
index = result.end;
|
|
1727
|
+
if (openChar === "[") {
|
|
1728
|
+
indexable = "closed";
|
|
1729
|
+
if (input[index + 1] !== "[")
|
|
1730
|
+
finishWord(index + 1);
|
|
1731
|
+
} else if (standaloneBlock) {
|
|
1143
1732
|
finishWord(index + 1);
|
|
1144
|
-
|
|
1733
|
+
indexable = "closed";
|
|
1734
|
+
}
|
|
1735
|
+
if (clause === "paren" && char === "(" || clause && clause !== "paren" && char === "{") {
|
|
1736
|
+
const completed = clause === "do" || clause === "if" || clause === "try" ? clause : undefined;
|
|
1737
|
+
clause = "member";
|
|
1145
1738
|
finishCommand(index + 1);
|
|
1146
|
-
|
|
1739
|
+
after = completed;
|
|
1147
1740
|
}
|
|
1148
1741
|
continue;
|
|
1149
1742
|
}
|
|
1150
|
-
if (char ===
|
|
1743
|
+
if (char === close)
|
|
1744
|
+
break;
|
|
1745
|
+
if (char === "}" || char === ")" || char === "]" && inExpression)
|
|
1151
1746
|
return { kind: "opaque", reason: "invalid-structure" };
|
|
1152
|
-
if (!started && words.length === 0 && (char === "&" && input[index + 1] !== "&" || char === "." && (
|
|
1747
|
+
if (!started && words.length === 0 && (char === "&" && input[index + 1] !== "&" || char === "." && (!input[index + 1] || /[\s"'$(),;{|}&]/.test(input[index + 1])))) {
|
|
1153
1748
|
if (invocation)
|
|
1154
1749
|
return { kind: "opaque", reason: "invalid-structure" };
|
|
1750
|
+
segment = index;
|
|
1155
1751
|
invocation = true;
|
|
1752
|
+
after = undefined;
|
|
1156
1753
|
continue;
|
|
1157
1754
|
}
|
|
1158
|
-
if (!started && !words.length && !invocation && powerShellExpression(input.slice(index)))
|
|
1159
|
-
expression = true;
|
|
1160
1755
|
if (/\s/.test(char) && char !== `
|
|
1161
1756
|
` && char !== "\r") {
|
|
1162
1757
|
finishWord(index);
|
|
1758
|
+
indexable = false;
|
|
1163
1759
|
continue;
|
|
1164
1760
|
}
|
|
1165
1761
|
const next = input[index + 1];
|
|
@@ -1167,12 +1763,25 @@ function scanPowerShellNested(input, depth, budget, hash = false) {
|
|
|
1167
1763
|
` ? char + next : char === "&" && next === "&" || char === "|" && next === "|" ? char + next : char === ";" || char === "|" || char === "&" || char === `
|
|
1168
1764
|
` || char === "\r" ? char : undefined;
|
|
1169
1765
|
if (separator) {
|
|
1170
|
-
if ((separator ===
|
|
1766
|
+
if (close === "]" && (separator === ";" || separator === "|" || separator === "||" || separator === "&&" || separator === "&"))
|
|
1767
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
1768
|
+
if (separator === `
|
|
1171
1769
|
` || separator === "\r" || separator === `\r
|
|
1172
|
-
`)
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1770
|
+
`) {
|
|
1771
|
+
const prev = started ? word : words.at(-1) ?? "";
|
|
1772
|
+
const memberOperator = indexable === "member" && /[.:]$/.test(prev);
|
|
1773
|
+
if (clause && clause !== "member" || prev.endsWith(",") || memberOperator) {
|
|
1774
|
+
finishWord(index);
|
|
1775
|
+
index += separator.length - 1;
|
|
1776
|
+
if (!memberOperator)
|
|
1777
|
+
indexable = false;
|
|
1778
|
+
continue;
|
|
1779
|
+
}
|
|
1780
|
+
if (!started && !words.length && !invocation) {
|
|
1781
|
+
index += separator.length - 1;
|
|
1782
|
+
indexable = false;
|
|
1783
|
+
continue;
|
|
1784
|
+
}
|
|
1176
1785
|
}
|
|
1177
1786
|
finishCommand(index, dangling || ![";", `
|
|
1178
1787
|
`, "\r", `\r
|
|
@@ -1182,190 +1791,47 @@ function scanPowerShellNested(input, depth, budget, hash = false) {
|
|
|
1182
1791
|
`].includes(separator);
|
|
1183
1792
|
statementHead = !dangling;
|
|
1184
1793
|
index += separator.length - 1;
|
|
1185
|
-
segment = index + 1;
|
|
1186
1794
|
continue;
|
|
1187
1795
|
}
|
|
1796
|
+
if (!started && !words.length && !invocation && hash !== "switch" && testAt(POWERSHELL_EXPRESSION_RE, input, index))
|
|
1797
|
+
expression = true;
|
|
1798
|
+
if ((atBoundary || indexable === "member" && /[.:]$/.test(word)) && char === "$")
|
|
1799
|
+
indexable = testAt(POWERSHELL_INDEXABLE_VAR_RE, input, index + 1) ? "variable" : false;
|
|
1800
|
+
else if (indexable === "closed")
|
|
1801
|
+
indexable = char === "." && input[index + 1] !== "." && !/\s/.test(input[index + 1] ?? "") || !started && char === ":" && input[index + 1] === ":" && !/\s/.test(input[index + 2] ?? "") || !started && char === "?" && input[index + 1] === "." && input[index + 2] !== "." && !/\s/.test(input[index + 2] ?? "") ? "member" : !started && char === "?" && input[index + 1] === "[" ? "closed" : false;
|
|
1802
|
+
else if (indexable === "variable")
|
|
1803
|
+
indexable = char === "." && input[index + 1] !== "." && !/\s/.test(input[index + 1] ?? "") || char === ":" && input[index + 1] === ":" && !/\s/.test(input[index + 2] ?? "") ? "member" : char === "." && input[index + 1] === "." || !/[\p{L}\p{Nl}\d_:?]/u.test(char) ? false : "variable";
|
|
1804
|
+
else if (indexable === "member")
|
|
1805
|
+
indexable = char === "." && input[index + 1] === "." ? false : char === "." && !/\s/.test(input[index + 1] ?? "") || char === ":" && (input[index + 1] === ":" || input[index - 1] === ":") || char === "?" && input[index + 1] === "." && input[index + 2] !== "." || /[\p{L}\p{Nl}\d_]/u.test(char) ? "member" : false;
|
|
1806
|
+
after = undefined;
|
|
1188
1807
|
started = true;
|
|
1189
1808
|
dangling = false;
|
|
1190
1809
|
word += char;
|
|
1191
1810
|
}
|
|
1811
|
+
if (close !== undefined && input[index] !== close)
|
|
1812
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
1192
1813
|
if (quote)
|
|
1193
1814
|
return { kind: "opaque", reason: "unterminated-quote" };
|
|
1194
|
-
|
|
1195
|
-
finishCommand(input.length);
|
|
1815
|
+
finishCommand(index);
|
|
1196
1816
|
if (redirectTarget || invalid || dangling)
|
|
1197
1817
|
return { kind: "opaque", reason: "invalid-structure" };
|
|
1198
1818
|
if (commands.some((command) => !command.words[0]))
|
|
1199
1819
|
return { kind: "opaque", reason: "dynamic-command-name" };
|
|
1200
|
-
return { kind: "scanned", commands };
|
|
1201
|
-
}
|
|
1202
|
-
function powerShellBlock(input, start, depth) {
|
|
1203
|
-
if (depth >= MAX_SUBSTITUTION_DEPTH)
|
|
1204
|
-
return;
|
|
1205
|
-
let quote;
|
|
1206
|
-
let standalone = false;
|
|
1207
|
-
let started = false;
|
|
1208
|
-
let head = true;
|
|
1209
|
-
let expression = false;
|
|
1210
|
-
let token = "";
|
|
1211
|
-
const close = input[start] === "(" ? ")" : input[start] === "[" ? "]" : "}";
|
|
1212
|
-
for (let index = start + 1;index < input.length; index++) {
|
|
1213
|
-
const char = input[index];
|
|
1214
|
-
if (quote === "single") {
|
|
1215
|
-
if (char === "'" && input[index + 1] === "'") {
|
|
1216
|
-
token += "'";
|
|
1217
|
-
index++;
|
|
1218
|
-
} else if (char === "'") {
|
|
1219
|
-
quote = undefined;
|
|
1220
|
-
started = !standalone;
|
|
1221
|
-
if (standalone)
|
|
1222
|
-
token = "";
|
|
1223
|
-
} else
|
|
1224
|
-
token += char;
|
|
1225
|
-
continue;
|
|
1226
|
-
}
|
|
1227
|
-
if (quote === "double") {
|
|
1228
|
-
if (char === "`") {
|
|
1229
|
-
const escape = powerShellEscape(input, index);
|
|
1230
|
-
if (!escape)
|
|
1231
|
-
return;
|
|
1232
|
-
token += escape.value;
|
|
1233
|
-
index = escape.end;
|
|
1234
|
-
} else if (char === '"' && input[index + 1] === '"') {
|
|
1235
|
-
token += '"';
|
|
1236
|
-
index++;
|
|
1237
|
-
} else if (char === '"') {
|
|
1238
|
-
quote = undefined;
|
|
1239
|
-
started = !standalone;
|
|
1240
|
-
if (standalone)
|
|
1241
|
-
token = "";
|
|
1242
|
-
} else if (char === "$" && input[index + 1] === "(") {
|
|
1243
|
-
const nested = powerShellBlock(input, index + 1, depth + 1);
|
|
1244
|
-
if (!nested)
|
|
1245
|
-
return;
|
|
1246
|
-
index = nested.end;
|
|
1247
|
-
} else
|
|
1248
|
-
token += char;
|
|
1249
|
-
continue;
|
|
1250
|
-
}
|
|
1251
|
-
if (char === "`") {
|
|
1252
|
-
const escape = powerShellEscape(input, index);
|
|
1253
|
-
if (!escape)
|
|
1254
|
-
return;
|
|
1255
|
-
if (started || /\S/.test(escape.value)) {
|
|
1256
|
-
started = true;
|
|
1257
|
-
token += escape.value;
|
|
1258
|
-
}
|
|
1259
|
-
index = escape.end;
|
|
1260
|
-
continue;
|
|
1261
|
-
}
|
|
1262
|
-
if (char === "<" && input[index + 1] === "#" && !started) {
|
|
1263
|
-
const end = powerShellComment(input, index);
|
|
1264
|
-
if (end === undefined)
|
|
1265
|
-
return;
|
|
1266
|
-
index = end;
|
|
1267
|
-
continue;
|
|
1268
|
-
}
|
|
1269
|
-
if (char === "#" && (!started || expression)) {
|
|
1270
|
-
const endings = [input.indexOf(`
|
|
1271
|
-
`, index), input.indexOf("\r", index)].filter((ending) => ending >= 0);
|
|
1272
|
-
const newline = endings.length > 0 ? Math.min(...endings) : -1;
|
|
1273
|
-
if (newline < 0)
|
|
1274
|
-
return;
|
|
1275
|
-
index = newline;
|
|
1276
|
-
started = false;
|
|
1277
|
-
head = true;
|
|
1278
|
-
expression = false;
|
|
1279
|
-
token = "";
|
|
1280
|
-
continue;
|
|
1281
|
-
}
|
|
1282
|
-
if (char === "@" && /['"]/.test(input[index + 1] ?? "")) {
|
|
1283
|
-
const literal = powerShellHereString(input, index);
|
|
1284
|
-
if (!literal)
|
|
1285
|
-
return;
|
|
1286
|
-
index = literal.end;
|
|
1287
|
-
started = false;
|
|
1288
|
-
head = false;
|
|
1289
|
-
continue;
|
|
1290
|
-
}
|
|
1291
|
-
if (head && !started && (char === "&" && input[index + 1] !== "&" || char === "." && /\s/.test(input[index + 1] ?? ""))) {
|
|
1292
|
-
head = false;
|
|
1293
|
-
continue;
|
|
1294
|
-
}
|
|
1295
|
-
if (expression && (char === "=" || !started && /^in\b/i.test(input.slice(index)))) {
|
|
1296
|
-
if (char !== "=")
|
|
1297
|
-
index++;
|
|
1298
|
-
expression = false;
|
|
1299
|
-
head = true;
|
|
1300
|
-
started = false;
|
|
1301
|
-
token = "";
|
|
1302
|
-
continue;
|
|
1303
|
-
}
|
|
1304
|
-
if (char === "'" || char === '"') {
|
|
1305
|
-
quote = char === "'" ? "single" : "double";
|
|
1306
|
-
standalone = !started;
|
|
1307
|
-
if (head && !started)
|
|
1308
|
-
expression = true;
|
|
1309
|
-
started = true;
|
|
1310
|
-
continue;
|
|
1311
|
-
}
|
|
1312
|
-
const redirect = !started && (char === ">" || char === "*" || /\d/.test(char)) ? powerShellRedirect(input, index) : undefined;
|
|
1313
|
-
if (redirect === false)
|
|
1314
|
-
return;
|
|
1315
|
-
if (redirect) {
|
|
1316
|
-
index += redirect.length - 1;
|
|
1317
|
-
token = "";
|
|
1318
|
-
continue;
|
|
1319
|
-
}
|
|
1320
|
-
if (char === "$" && input[index + 1] === "{") {
|
|
1321
|
-
const end = input.indexOf("}", index + 2);
|
|
1322
|
-
if (end < 0)
|
|
1323
|
-
return;
|
|
1324
|
-
if (head && !started)
|
|
1325
|
-
expression = true;
|
|
1326
|
-
index = end;
|
|
1327
|
-
started = true;
|
|
1328
|
-
continue;
|
|
1329
|
-
}
|
|
1330
|
-
if (!started && !head && !expression && /^--%(?=$|[\s;|&(){}])/.test(input.slice(index))) {
|
|
1331
|
-
index = powerShellStopParsing(input, index + 3) - 1;
|
|
1332
|
-
continue;
|
|
1333
|
-
}
|
|
1334
|
-
if (char === close)
|
|
1335
|
-
return { source: input.slice(start + 1, index), end: index };
|
|
1336
|
-
if (char === "(" || char === "{" || char === "[" && (!started || expression)) {
|
|
1337
|
-
if (head && !started)
|
|
1338
|
-
expression = true;
|
|
1339
|
-
const nested = powerShellBlock(input, index, depth + 1);
|
|
1340
|
-
if (!nested)
|
|
1341
|
-
return;
|
|
1342
|
-
index = nested.end;
|
|
1343
|
-
started = false;
|
|
1344
|
-
head = false;
|
|
1345
|
-
token = "";
|
|
1346
|
-
continue;
|
|
1347
|
-
}
|
|
1348
|
-
if (/[\s;&|]/.test(char)) {
|
|
1349
|
-
if (token === "--%" && !expression) {
|
|
1350
|
-
index = powerShellStopParsing(input, index) - 1;
|
|
1351
|
-
token = "";
|
|
1352
|
-
continue;
|
|
1353
|
-
}
|
|
1354
|
-
if (/[;&|\r\n]/.test(char)) {
|
|
1355
|
-
head = true;
|
|
1356
|
-
expression = false;
|
|
1357
|
-
} else if (started)
|
|
1358
|
-
head = false;
|
|
1359
|
-
started = false;
|
|
1360
|
-
token = "";
|
|
1361
|
-
continue;
|
|
1362
|
-
}
|
|
1363
|
-
if (head && !started && powerShellExpression(input.slice(index)))
|
|
1364
|
-
expression = true;
|
|
1365
|
-
started = true;
|
|
1366
|
-
token += char;
|
|
1367
|
-
}
|
|
1820
|
+
return { kind: "scanned", commands, end: index };
|
|
1368
1821
|
}
|
|
1822
|
+
var POWERSHELL_STOP_PARSING_RE = /--%(?=$|[\s;|&(){}])/y;
|
|
1823
|
+
var POWERSHELL_PARAMETER_COLON_RE = /^-[\p{L}\p{Nl}_?][\p{L}\p{Nl}\d_?-]*:$/u;
|
|
1824
|
+
var POWERSHELL_MERGE_REDIRECT_RE = /\d>&/y;
|
|
1825
|
+
var POWERSHELL_LABEL_RE = /:[A-Za-z_]\w*(?=\s*(?:while|for|foreach|do|switch)(?=$|[\s&(),;{|}]))/iy;
|
|
1826
|
+
var POWERSHELL_KEYWORD_RE = /[A-Za-z]+(?=$|[\s&(),;{|}])/y;
|
|
1827
|
+
var POWERSHELL_FOREACH_RE = /foreach\s*\(/isy;
|
|
1828
|
+
var POWERSHELL_PARAM_RE = /param\s*\(/isy;
|
|
1829
|
+
var POWERSHELL_IN_RE = /in(?=$|[\s&(),;{|}])/iy;
|
|
1830
|
+
var POWERSHELL_AT_OPENER_RE = /[({'"\p{L}\p{Nl}\d_?]/uy;
|
|
1831
|
+
var POWERSHELL_INDEXABLE_VAR_RE = /(?::[\p{L}\p{Nl}\d_?]+|[\p{L}\p{Nl}\d_][\p{L}\p{Nl}\d_?]*)/uy;
|
|
1832
|
+
var POWERSHELL_HERE_HEADER_RE = /@['"][^\S\r\n]*(?:\r\n|\r|\n)/y;
|
|
1833
|
+
var POWERSHELL_UNICODE_ESCAPE_RE = /u\{([0-9a-f]{1,6})\}/iy;
|
|
1834
|
+
var POWERSHELL_EXPRESSION_RE = /(?:!*(?:\+\+|--|[+-])?\$(?:\{|(?:\?|\$|\^)(?=$|[\s;|&(){},#>])|:[\p{L}\p{Nl}\d_?]+|[\p{L}\p{Nl}\d_][\p{L}\p{Nl}\d_?]*(?::[\p{L}\p{Nl}\d_?]+)?)|!(?![\p{L}\p{Nl}_.\d])|\+(?![=\p{L}\p{Nl}_.\d])|--(?!=)|-(?![=\p{L}\p{Nl}\d_?.])|,(?!\s*$)|!*[+-]?(?:0[xX][\da-fA-F]+|0[bB][01]+|(?:\d+(?:\.(?!\.)\d*|(?!\.(?!\.)))|\.\d+)(?:[eE][+-]?\d+)?)(?:[dDlLnN]|[uU][sSyYlL]?|[sSyY])?(?:[kKmMgGtTpP][bB])?(?=$|[\s!#%&()*+,\-/.;<=>\]|{}])|-(?:not|bnot|join|[ic]?split)(?![\p{L}\p{Nl}]))/iuy;
|
|
1369
1835
|
var POWERSHELL_ESCAPES = {
|
|
1370
1836
|
"0": "\x00",
|
|
1371
1837
|
a: "\x07",
|
|
@@ -1378,80 +1844,145 @@ var POWERSHELL_ESCAPES = {
|
|
|
1378
1844
|
t: "\t",
|
|
1379
1845
|
v: "\v"
|
|
1380
1846
|
};
|
|
1381
|
-
function
|
|
1382
|
-
|
|
1847
|
+
function matchAt(regex, input, index) {
|
|
1848
|
+
regex.lastIndex = index;
|
|
1849
|
+
return regex.exec(input);
|
|
1850
|
+
}
|
|
1851
|
+
function testAt(regex, input, index) {
|
|
1852
|
+
regex.lastIndex = index;
|
|
1853
|
+
return regex.test(input);
|
|
1854
|
+
}
|
|
1855
|
+
function powerShellEscape(input, start, lineContinuation = false, skipped) {
|
|
1856
|
+
let next = start + 1;
|
|
1857
|
+
while (skipped?.has(next))
|
|
1858
|
+
next++;
|
|
1859
|
+
const char = input[next];
|
|
1383
1860
|
if (char === undefined)
|
|
1384
1861
|
return;
|
|
1385
1862
|
if (char === "\r" || char === `
|
|
1386
1863
|
`)
|
|
1387
1864
|
return {
|
|
1388
|
-
value: char === "\r" && input[
|
|
1865
|
+
value: lineContinuation && char === "\r" && input[next + 1] === `
|
|
1389
1866
|
` ? `\r
|
|
1390
1867
|
` : char,
|
|
1391
|
-
end:
|
|
1392
|
-
` ?
|
|
1868
|
+
end: next + (lineContinuation && char === "\r" && input[next + 1] === `
|
|
1869
|
+
` ? 1 : 0)
|
|
1393
1870
|
};
|
|
1394
|
-
if (char === "u" && input[
|
|
1395
|
-
const code =
|
|
1871
|
+
if (char === "u" && input[next + 1] === "{") {
|
|
1872
|
+
const code = matchAt(POWERSHELL_UNICODE_ESCAPE_RE, input, next);
|
|
1396
1873
|
if (!code || Number.parseInt(code[1], 16) > 1114111)
|
|
1397
1874
|
return;
|
|
1398
|
-
return { value: String.fromCodePoint(Number.parseInt(code[1], 16)), end:
|
|
1875
|
+
return { value: String.fromCodePoint(Number.parseInt(code[1], 16)), end: next + code[0].length - 1 };
|
|
1876
|
+
}
|
|
1877
|
+
return { value: POWERSHELL_ESCAPES[char] ?? char, end: next };
|
|
1878
|
+
}
|
|
1879
|
+
function powerShellBracedVariable(input, start, skipped) {
|
|
1880
|
+
for (let index = start + 2;index < input.length; index++) {
|
|
1881
|
+
if (skipped?.has(index))
|
|
1882
|
+
continue;
|
|
1883
|
+
if (input[index] === "`") {
|
|
1884
|
+
const escape = powerShellEscape(input, index, false, skipped);
|
|
1885
|
+
if (!escape)
|
|
1886
|
+
return;
|
|
1887
|
+
index = escape.end;
|
|
1888
|
+
continue;
|
|
1889
|
+
}
|
|
1890
|
+
if (input[index] === "}")
|
|
1891
|
+
return index > start + 2 ? index : undefined;
|
|
1399
1892
|
}
|
|
1400
|
-
return { value: POWERSHELL_ESCAPES[char] ?? char, end: start + 1 };
|
|
1401
1893
|
}
|
|
1402
|
-
function
|
|
1403
|
-
|
|
1894
|
+
function powerShellSubExpression(input, start, hereString, budget, skipped) {
|
|
1895
|
+
const nextSkipped = new Set(skipped);
|
|
1896
|
+
let depth = 1;
|
|
1897
|
+
let rawEnd;
|
|
1898
|
+
for (let index = start;index < input.length; index++) {
|
|
1899
|
+
if (--budget.remaining < 0)
|
|
1900
|
+
return;
|
|
1901
|
+
if (nextSkipped.has(index))
|
|
1902
|
+
continue;
|
|
1903
|
+
const char = input[index];
|
|
1904
|
+
if (char === "(")
|
|
1905
|
+
depth++;
|
|
1906
|
+
else if (char === ")") {
|
|
1907
|
+
if (--depth === 0 && rawEnd === undefined)
|
|
1908
|
+
rawEnd = index;
|
|
1909
|
+
} else if (!hereString && (char === '"' || char === "`")) {
|
|
1910
|
+
let next = index + 1;
|
|
1911
|
+
while (nextSkipped.has(next))
|
|
1912
|
+
next++;
|
|
1913
|
+
if (input[next] === '"') {
|
|
1914
|
+
nextSkipped.add(index);
|
|
1915
|
+
index = next;
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
return { skipped: nextSkipped, rawEnd };
|
|
1404
1920
|
}
|
|
1405
|
-
function powerShellStopParsing(input, start) {
|
|
1921
|
+
function powerShellStopParsing(input, start, skipped) {
|
|
1406
1922
|
let quoted = false;
|
|
1407
1923
|
for (let index = start;index < input.length; index++) {
|
|
1924
|
+
if (skipped?.has(index))
|
|
1925
|
+
continue;
|
|
1408
1926
|
if (input[index] === '"')
|
|
1409
1927
|
quoted = !quoted;
|
|
1410
1928
|
if (input[index] === "\r" || input[index] === `
|
|
1411
|
-
` || input[index] === "|" && !quoted)
|
|
1929
|
+
` || (input[index] === "|" || input[index] === "&" && input[index + 1] === "&") && !quoted)
|
|
1412
1930
|
return index;
|
|
1413
1931
|
}
|
|
1414
1932
|
return input.length;
|
|
1415
1933
|
}
|
|
1416
|
-
function
|
|
1417
|
-
const
|
|
1418
|
-
return end < 0 ? undefined : end + 1;
|
|
1419
|
-
}
|
|
1420
|
-
function powerShellHereString(input, start) {
|
|
1421
|
-
const header = /^@['"][ \t]*(?:\r\n|\r|\n)/.exec(input.slice(start));
|
|
1934
|
+
function powerShellHereString(input, start, depth, budget, skipped) {
|
|
1935
|
+
const header = matchAt(POWERSHELL_HERE_HEADER_RE, input, start);
|
|
1422
1936
|
if (!header)
|
|
1423
|
-
return;
|
|
1937
|
+
return { kind: "opaque", reason: "unterminated-quote" };
|
|
1938
|
+
const quote = input[start + 1];
|
|
1424
1939
|
const body = start + header[0].length;
|
|
1940
|
+
const commands = [];
|
|
1941
|
+
let lineStart = true;
|
|
1425
1942
|
for (let index = body;index < input.length; index++) {
|
|
1426
|
-
if (
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
if (input[index] !== input[start + 1] || input[index + 1] !== "@")
|
|
1943
|
+
if (--budget.remaining < 0)
|
|
1944
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
1945
|
+
if (skipped?.has(index))
|
|
1430
1946
|
continue;
|
|
1431
|
-
|
|
1947
|
+
if (lineStart && input[index] === quote && input[index + 1] === "@") {
|
|
1948
|
+
const end = index > body && input[index - 1] === `
|
|
1432
1949
|
` && input[index - 2] === "\r" ? index - 2 : index > body ? index - 1 : index;
|
|
1433
|
-
|
|
1434
|
-
}
|
|
1435
|
-
}
|
|
1436
|
-
function powerShellExpansions(input, depth, budget) {
|
|
1437
|
-
const commands = [];
|
|
1438
|
-
for (let index = 0;index < input.length; index++) {
|
|
1439
|
-
if (input[index] === "`") {
|
|
1440
|
-
index++;
|
|
1441
|
-
continue;
|
|
1950
|
+
return { kind: "scanned", commands, source: input.slice(body, end), end: index + 1 };
|
|
1442
1951
|
}
|
|
1443
|
-
if (
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1952
|
+
if (quote === '"') {
|
|
1953
|
+
if (input[index] === "`") {
|
|
1954
|
+
const escape = powerShellEscape(input, index, false, skipped);
|
|
1955
|
+
if (!escape)
|
|
1956
|
+
return { kind: "opaque", reason: "unterminated-escape" };
|
|
1957
|
+
index = escape.end;
|
|
1958
|
+
lineStart = false;
|
|
1959
|
+
continue;
|
|
1960
|
+
}
|
|
1961
|
+
if (input[index] === "$" && input[index + 1] === "{") {
|
|
1962
|
+
const end = powerShellBracedVariable(input, index, skipped);
|
|
1963
|
+
if (end === undefined)
|
|
1964
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
1965
|
+
index = end;
|
|
1966
|
+
lineStart = false;
|
|
1967
|
+
continue;
|
|
1968
|
+
}
|
|
1969
|
+
if (input[index] === "$" && input[index + 1] === "(") {
|
|
1970
|
+
const sub = powerShellSubExpression(input, index + 2, true, budget, skipped);
|
|
1971
|
+
if (!sub)
|
|
1972
|
+
return { kind: "opaque", reason: "invalid-structure" };
|
|
1973
|
+
const result = scanPowerShellList(input, index + 2, depth + 1, budget, ")", false, sub.skipped);
|
|
1974
|
+
if (result.kind === "opaque")
|
|
1975
|
+
return result;
|
|
1976
|
+
commands.push(...result.commands);
|
|
1977
|
+
index = sub.rawEnd !== undefined && sub.rawEnd > result.end ? sub.rawEnd : result.end;
|
|
1978
|
+
lineStart = false;
|
|
1979
|
+
continue;
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
lineStart = input[index] === "\r" || input[index] === `
|
|
1983
|
+
`;
|
|
1453
1984
|
}
|
|
1454
|
-
return { kind: "
|
|
1985
|
+
return { kind: "opaque", reason: "unterminated-quote" };
|
|
1455
1986
|
}
|
|
1456
1987
|
function powerShellRedirect(input, index) {
|
|
1457
1988
|
let cursor = index;
|