@xano/sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +788 -0
- package/LICENSE +21 -0
- package/README.md +541 -0
- package/dist/.build-fingerprint +1 -0
- package/dist/agent-file-refresh-ZEMK33AX.js +38 -0
- package/dist/answer-shape-K67TAAPY.js +33 -0
- package/dist/backend-dir-2U53CIAL.js +39 -0
- package/dist/backend-slot-7QXW2QYC.js +28 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +255 -0
- package/dist/branch-NCRNWQBQ.js +61 -0
- package/dist/branch-commands-ACIRCEQJ.js +79 -0
- package/dist/bundle.d.ts +223 -0
- package/dist/bundle.js +153 -0
- package/dist/capture-WAXPD7DR.js +41 -0
- package/dist/chunk-27GWNP2I.js +23 -0
- package/dist/chunk-2CMJZDCL.js +177 -0
- package/dist/chunk-2EZ3ZJZZ.js +302 -0
- package/dist/chunk-2GNFDZA2.js +390 -0
- package/dist/chunk-2MNLRIOX.js +11 -0
- package/dist/chunk-2TFRR6JV.js +104 -0
- package/dist/chunk-2ZUEE4EK.js +408 -0
- package/dist/chunk-36JUQZVQ.js +22 -0
- package/dist/chunk-3DRXWLJ5.js +83 -0
- package/dist/chunk-3JDU4VRL.js +137 -0
- package/dist/chunk-3KZCLN4Z.js +241 -0
- package/dist/chunk-3LDULPRE.js +168 -0
- package/dist/chunk-3M4LFYNQ.js +111 -0
- package/dist/chunk-3XI5CTUE.js +22 -0
- package/dist/chunk-3YW23UFH.js +50 -0
- package/dist/chunk-45UIT5T2.js +862 -0
- package/dist/chunk-4BW2SG2N.js +46 -0
- package/dist/chunk-4KHEMC32.js +79 -0
- package/dist/chunk-4POWHT2K.js +321 -0
- package/dist/chunk-4Q2GN7NW.js +192 -0
- package/dist/chunk-5A2PLKZB.js +70 -0
- package/dist/chunk-5FBYXK5P.js +159 -0
- package/dist/chunk-5HVXPTU4.js +323 -0
- package/dist/chunk-5QU2P5CA.js +304 -0
- package/dist/chunk-5V5XU32D.js +191 -0
- package/dist/chunk-5ZSO4T2G.js +10 -0
- package/dist/chunk-622HUCZT.js +10 -0
- package/dist/chunk-65HWOMGV.js +177 -0
- package/dist/chunk-6ELFRN3P.js +365 -0
- package/dist/chunk-6HO3NCSJ.js +1055 -0
- package/dist/chunk-6IUMKYWI.js +457 -0
- package/dist/chunk-6KEB3C3U.js +65 -0
- package/dist/chunk-6MR5TI5V.js +987 -0
- package/dist/chunk-6NNTNXN7.js +157 -0
- package/dist/chunk-6PBR37LN.js +97 -0
- package/dist/chunk-6QXLMMT3.js +155 -0
- package/dist/chunk-6ZGJCBZS.js +224 -0
- package/dist/chunk-73IVBKMA.js +250 -0
- package/dist/chunk-7G3CTU7I.js +286 -0
- package/dist/chunk-A3UDOZB6.js +222 -0
- package/dist/chunk-A6E77GDW.js +85 -0
- package/dist/chunk-AHJWCYQO.js +660 -0
- package/dist/chunk-AKNCFVKZ.js +36 -0
- package/dist/chunk-AM4FKL4J.js +237 -0
- package/dist/chunk-AN6BL47T.js +26 -0
- package/dist/chunk-AOSYVMUS.js +147 -0
- package/dist/chunk-APWXY5SL.js +182 -0
- package/dist/chunk-AWEIIR2U.js +218 -0
- package/dist/chunk-AWQ7BQTQ.js +73 -0
- package/dist/chunk-BAUZOWGX.js +393 -0
- package/dist/chunk-BHACRS6R.js +940 -0
- package/dist/chunk-BWPNT55T.js +680 -0
- package/dist/chunk-C6RIMRU4.js +187 -0
- package/dist/chunk-CGVQZXYG.js +263 -0
- package/dist/chunk-CIMQZRRE.js +162 -0
- package/dist/chunk-CJHQKJU4.js +113 -0
- package/dist/chunk-CTMO46PK.js +1897 -0
- package/dist/chunk-D53J55C5.js +106 -0
- package/dist/chunk-D7VGG3WS.js +90 -0
- package/dist/chunk-DAD3ONIS.js +245 -0
- package/dist/chunk-DGWHAVRG.js +162 -0
- package/dist/chunk-DX4QR4B2.js +483 -0
- package/dist/chunk-EHP3WPEG.js +21 -0
- package/dist/chunk-ELP2HMXC.js +432 -0
- package/dist/chunk-ERVIASGL.js +21 -0
- package/dist/chunk-ET4Y4XCB.js +865 -0
- package/dist/chunk-ETO6LGLD.js +4750 -0
- package/dist/chunk-EUUUMY7J.js +24 -0
- package/dist/chunk-FQJ2TTHP.js +218 -0
- package/dist/chunk-FQOF7E2E.js +133 -0
- package/dist/chunk-FWD7AL6N.js +21 -0
- package/dist/chunk-FXFV3KU6.js +138 -0
- package/dist/chunk-FXRQOWTE.js +171 -0
- package/dist/chunk-G554NZNI.js +210 -0
- package/dist/chunk-GSGDWJB5.js +13 -0
- package/dist/chunk-H2V3N23D.js +66 -0
- package/dist/chunk-H5C7MBCR.js +159 -0
- package/dist/chunk-HHN734BU.js +371 -0
- package/dist/chunk-HRVBLCVJ.js +243 -0
- package/dist/chunk-HVRUQXGD.js +1264 -0
- package/dist/chunk-I4F5TCJH.js +130 -0
- package/dist/chunk-IDOTCMDV.js +57 -0
- package/dist/chunk-IGOLHKWF.js +427 -0
- package/dist/chunk-JGE7CAWB.js +148 -0
- package/dist/chunk-JTUKLCXS.js +92 -0
- package/dist/chunk-JZGVVJSI.js +66 -0
- package/dist/chunk-K4WX6UUU.js +923 -0
- package/dist/chunk-K5BBGTYZ.js +217 -0
- package/dist/chunk-K6RXBGUB.js +427 -0
- package/dist/chunk-KTSDSD36.js +165 -0
- package/dist/chunk-L5JYN3NM.js +1038 -0
- package/dist/chunk-LIEOKXKD.js +354 -0
- package/dist/chunk-LLNZGEFK.js +51 -0
- package/dist/chunk-LPECSJ2J.js +55 -0
- package/dist/chunk-LQCMKAJ7.js +413 -0
- package/dist/chunk-LRN4ZJCQ.js +1145 -0
- package/dist/chunk-MJ4ZVHKN.js +17 -0
- package/dist/chunk-MXHSQOC4.js +3061 -0
- package/dist/chunk-N5GKCWE5.js +367 -0
- package/dist/chunk-NA3PXMEF.js +10 -0
- package/dist/chunk-NAQDMEHV.js +76 -0
- package/dist/chunk-NWKXM5RD.js +109 -0
- package/dist/chunk-NZOWWHU5.js +196 -0
- package/dist/chunk-OHX6MIUZ.js +184 -0
- package/dist/chunk-OOXWYAA4.js +15 -0
- package/dist/chunk-OPHB5ORL.js +1990 -0
- package/dist/chunk-OXA6PSZT.js +1725 -0
- package/dist/chunk-P2HAGF6H.js +73 -0
- package/dist/chunk-PTHVMXZI.js +3036 -0
- package/dist/chunk-PZ5AY32C.js +10 -0
- package/dist/chunk-Q325JKYB.js +189 -0
- package/dist/chunk-Q7DGTQ5G.js +255 -0
- package/dist/chunk-QCNYHBL7.js +601 -0
- package/dist/chunk-QO6BVGS5.js +145 -0
- package/dist/chunk-QXTKSOFI.js +76 -0
- package/dist/chunk-ROY4YAEQ.js +66 -0
- package/dist/chunk-RTJRZFFY.js +447 -0
- package/dist/chunk-SAVJUS2X.js +128 -0
- package/dist/chunk-SFLHVCKX.js +173 -0
- package/dist/chunk-STSFNCY4.js +127 -0
- package/dist/chunk-SWBF2LTK.js +170 -0
- package/dist/chunk-T5KELPAR.js +109 -0
- package/dist/chunk-TFFGOFVZ.js +1481 -0
- package/dist/chunk-TLHIFK4M.js +256 -0
- package/dist/chunk-TLQE7ZN3.js +156 -0
- package/dist/chunk-TPHWJ7UG.js +1981 -0
- package/dist/chunk-TRJCALW3.js +291 -0
- package/dist/chunk-TTEIYD5P.js +133 -0
- package/dist/chunk-U64O2MXY.js +407 -0
- package/dist/chunk-UCQ2VUTG.js +630 -0
- package/dist/chunk-UTI5G6OJ.js +44 -0
- package/dist/chunk-UVHDMMIP.js +188 -0
- package/dist/chunk-UZ6QQWJT.js +120 -0
- package/dist/chunk-VAX3UZOY.js +686 -0
- package/dist/chunk-W3HBUKFO.js +57 -0
- package/dist/chunk-WKQLGKCL.js +2823 -0
- package/dist/chunk-WQFNASK4.js +560 -0
- package/dist/chunk-WRBKLYSJ.js +224 -0
- package/dist/chunk-WTPZRR4I.js +17 -0
- package/dist/chunk-WZDJ2LLX.js +2385 -0
- package/dist/chunk-X2NL4KUO.js +14 -0
- package/dist/chunk-X4DVXBFY.js +38 -0
- package/dist/chunk-X677DMZM.js +7050 -0
- package/dist/chunk-XBKMWY7F.js +612 -0
- package/dist/chunk-XNCP4KYO.js +78 -0
- package/dist/chunk-XVBGLISP.js +35 -0
- package/dist/chunk-XW6KISBB.js +1192 -0
- package/dist/chunk-YGZHHAAB.js +8156 -0
- package/dist/chunk-YHEFQUQB.js +186 -0
- package/dist/chunk-YLDALTWZ.js +653 -0
- package/dist/chunk-YU4HSQW7.js +229 -0
- package/dist/chunk-ZDPP6RKB.js +27 -0
- package/dist/chunk-ZFDZKNGG.js +194 -0
- package/dist/chunk-ZIY7RNUT.js +49 -0
- package/dist/chunk-ZYJP6BOO.js +30 -0
- package/dist/cli.d.ts +1111 -0
- package/dist/cli.js +165 -0
- package/dist/codegen-command-VR2GWR6C.js +173 -0
- package/dist/codegen.d.ts +115 -0
- package/dist/codegen.js +19 -0
- package/dist/commands-GJMJ4XYZ.js +76 -0
- package/dist/completion-ZQLO6PB6.js +738 -0
- package/dist/config-MBYGCAFK.js +136 -0
- package/dist/deploy-command-JVZPWHMK.js +180 -0
- package/dist/deploy-source-3W45CXMP.js +81 -0
- package/dist/dev-env-sync-HN44K4D5.js +188 -0
- package/dist/diagnostics-UEAAHWVF.js +30 -0
- package/dist/display-name-hint-ABBPVQIR.js +46 -0
- package/dist/emit-CyhBDxli.d.ts +7007 -0
- package/dist/env-example-refresh-ET5HMMDW.js +126 -0
- package/dist/env-pull-command-TNMNB3CV.js +323 -0
- package/dist/env-target-O4HRKTGZ.js +40 -0
- package/dist/env-var-command-ZIRDCAZA.js +427 -0
- package/dist/ephemeral-P7F3PMAD.js +54 -0
- package/dist/ephemeral-command-CLJJKOFT.js +592 -0
- package/dist/ephemeral-state-PYCBSOGX.js +61 -0
- package/dist/file-lock-PT74GWYW.js +10 -0
- package/dist/generate-command-AYEOLA26.js +510 -0
- package/dist/gitignore-3SJ3WNRG.js +51 -0
- package/dist/guards-4EBNCZDC.js +162 -0
- package/dist/hosted-file-PSHJB3HX.js +28 -0
- package/dist/impersonate-command-5JAS3WSV.js +152 -0
- package/dist/import-EQSFU6JC.js +19 -0
- package/dist/index.d.ts +5470 -0
- package/dist/index.js +371 -0
- package/dist/init-command-X2FR4UAK.js +125 -0
- package/dist/init-modules-RY7UHAOL.js +50 -0
- package/dist/init-web-M4YZSZK6.js +42 -0
- package/dist/internal.d.ts +179 -0
- package/dist/internal.js +2634 -0
- package/dist/io-RC56QSN5.js +26 -0
- package/dist/keep-data-merge-7MPLVAVI.js +1119 -0
- package/dist/lambda-config-reconcile-OUZ4OYAB.js +116 -0
- package/dist/landed-753YLJ5H.js +40 -0
- package/dist/landing-record-SU52SKXU.js +61 -0
- package/dist/live-diff-YONW2VI3.js +65 -0
- package/dist/local-engine-choice-CH5X3W7E.js +79 -0
- package/dist/local-engine-command-Z3OL7VOD.js +766 -0
- package/dist/local-engine-config-5U3SC434.js +39 -0
- package/dist/local-engine-deploy-PCQ4SNPB.js +39 -0
- package/dist/local-engine-process-EHTE5LLU.js +63 -0
- package/dist/local-engine-state-A4FTRFAF.js +32 -0
- package/dist/local-engine-update-check-6L645VBL.js +162 -0
- package/dist/lock-MRRHW5GS.js +87 -0
- package/dist/lock-commands-2QG25HL7.js +963 -0
- package/dist/login-command-QPYRWOXZ.js +538 -0
- package/dist/logout-command-WOIQLDP6.js +56 -0
- package/dist/loop-ALIZLOSX.js +191 -0
- package/dist/marketplace-command-K5YL42NO.js +977 -0
- package/dist/marketplace-resolve-LY32JES5.js +40 -0
- package/dist/meta-client-YXGPW53C.js +244 -0
- package/dist/module-manifest-JFGHU2TC.js +38 -0
- package/dist/near-key.d.ts +13 -0
- package/dist/near-key.js +8 -0
- package/dist/node.d.ts +95 -0
- package/dist/node.js +969 -0
- package/dist/operation-outcome-TZSESNC7.js +51 -0
- package/dist/output-target-AL3I44GG.js +47 -0
- package/dist/package-manager-PRAHUSCN.js +34 -0
- package/dist/plan-disclosure-6G4MLZKD.js +114 -0
- package/dist/plugin-contributions-WRNY5ABG.js +28 -0
- package/dist/plugin-prompt-4VA3B4FF.js +20 -0
- package/dist/plugin-questions-JTSYA74Q.js +24 -0
- package/dist/plugin.d.ts +396 -0
- package/dist/plugin.js +1 -0
- package/dist/preflight-command-2T5Z36MI.js +321 -0
- package/dist/profile-command-AH3PIM4X.js +800 -0
- package/dist/profile-pointer-GRWJU3YD.js +31 -0
- package/dist/profile-select-74TRDEPD.js +23 -0
- package/dist/project-dependency-KSH63ODT.js +35 -0
- package/dist/project-sdk-REPPOIBD.js +24 -0
- package/dist/promote-command-PCWT5N6S.js +140 -0
- package/dist/prompt-II3F3LND.js +27 -0
- package/dist/publish-command-TTDUUJI5.js +414 -0
- package/dist/pull-command-VBO7C4S3.js +161 -0
- package/dist/pull-superseded-GJWLG7XO.js +20 -0
- package/dist/release-command-N4ZPKMHR.js +146 -0
- package/dist/release-ns-command-3KFDMZ6G.js +1745 -0
- package/dist/response-HlXahv4K.d.ts +925 -0
- package/dist/retry-command-AS5EVREX.js +34 -0
- package/dist/routes-manifest-SNWUVBT6.js +43 -0
- package/dist/runtime-XETHVF33.js +14 -0
- package/dist/scaffold.d.ts +1911 -0
- package/dist/scaffold.js +107 -0
- package/dist/secrets-file-LVZD6IIM.js +56 -0
- package/dist/secrets-fill-command-TTCPSVXN.js +218 -0
- package/dist/seed-VU7C3QYS.js +46 -0
- package/dist/sent-writes-N7X4OVXT.js +22 -0
- package/dist/source-resolve-S2XA3XZF.js +83 -0
- package/dist/static-host-B2Y6AG3W.js +352 -0
- package/dist/status-command-RUDXTF7I.js +554 -0
- package/dist/store-6VNCD4D7.js +20 -0
- package/dist/store-ARM6VMO5.js +98 -0
- package/dist/store-DuYfzKlW.d.ts +3144 -0
- package/dist/suggest-6FOOYKHG.js +12 -0
- package/dist/sveltekit.d.ts +154 -0
- package/dist/sveltekit.js +109 -0
- package/dist/sync-contributions-UCEROO26.js +415 -0
- package/dist/table-ENAVMITR.js +42 -0
- package/dist/tables-command-GUPXXSB5.js +156 -0
- package/dist/tenant-IIHPOHGP.js +42 -0
- package/dist/tenant-command-D5HGI2X4.js +965 -0
- package/dist/test-command-TIKZMDPZ.js +476 -0
- package/dist/tests-BGGIOK3L.js +26 -0
- package/dist/token-NICJUTMT.js +72 -0
- package/dist/toolchain-hooks-GHKLUJOH.js +96 -0
- package/dist/toolchain-modules-5EAZUONB.js +24 -0
- package/dist/tracked-backend-EIBUMDZA.js +80 -0
- package/dist/update-check-2W2NLDTC.js +136 -0
- package/dist/upgrade-command-QHNFWM7O.js +531 -0
- package/dist/verify-rollout-DRCK5TDD.js +61 -0
- package/dist/whoami-command-STGINTXH.js +51 -0
- package/dist/workspace-2CLHU2LK.js +93 -0
- package/dist/workspace-binding-56PIIPCP.js +54 -0
- package/dist/workspace-command-JEXQETJD.js +535 -0
- package/dist/workspace-env-F2RFMSC5.js +70 -0
- package/dist/workspace-export-OJSH2HIW.js +21 -0
- package/dist/writable-VA7OISSK.js +25 -0
- package/dist/xano-ICFUSPFR.js +42 -0
- package/dist/xanosdk-import-GN42TO2B.js +56 -0
- package/dist/xanosdk-project-S6DXJONQ.js +41 -0
- package/dist/xdo-CxDr2Q1C.d.ts +1371 -0
- package/guides/README.md +33 -0
- package/guides/authoring.md +921 -0
- package/guides/cli.md +401 -0
- package/guides/codegen.md +177 -0
- package/guides/codes.md +404 -0
- package/guides/coverage.md +74 -0
- package/guides/deploying.md +1525 -0
- package/guides/environment.md +400 -0
- package/guides/marketplace.md +415 -0
- package/guides/module-contract.md +558 -0
- package/guides/object-kinds.md +433 -0
- package/guides/project-structure.md +43 -0
- package/guides/scaffold.md +351 -0
- package/guides/typed-frontend.md +242 -0
- package/llms/client.md +63 -0
- package/llms/errors.md +56 -0
- package/llms/fields.md +176 -0
- package/llms/filters.md +183 -0
- package/llms/kinds-agent-mcp.md +30 -0
- package/llms/kinds-core.md +100 -0
- package/llms/kinds-knowledge.md +20 -0
- package/llms/kinds-realtime.md +76 -0
- package/llms/lambda.md +94 -0
- package/llms/legacy.md +44 -0
- package/llms/lock.md +40 -0
- package/llms/object-kinds.md +34 -0
- package/llms/statements-calls.md +62 -0
- package/llms/statements-catalog.md +320 -0
- package/llms/statements-data.md +66 -0
- package/llms/statements-runtime.md +68 -0
- package/llms/tests.md +59 -0
- package/llms/toolchain.md +16 -0
- package/llms/triggers.md +36 -0
- package/llms/values.md +29 -0
- package/llms-full.txt +2085 -0
- package/llms.txt +493 -0
- package/manifest.json +11224 -0
- package/package.json +162 -0
- package/types/lambda-globals.d.ts +129 -0
|
@@ -0,0 +1,686 @@
|
|
|
1
|
+
// src/values/lambda-source.ts
|
|
2
|
+
var REGEX_PRECEDING_KEYWORDS = /* @__PURE__ */ new Set([
|
|
3
|
+
"return",
|
|
4
|
+
"typeof",
|
|
5
|
+
"case",
|
|
6
|
+
"in",
|
|
7
|
+
"of",
|
|
8
|
+
"new",
|
|
9
|
+
"delete",
|
|
10
|
+
"void",
|
|
11
|
+
"do",
|
|
12
|
+
"else",
|
|
13
|
+
"yield",
|
|
14
|
+
"await",
|
|
15
|
+
"instanceof",
|
|
16
|
+
"throw"
|
|
17
|
+
]);
|
|
18
|
+
var WORD_CHAR = /^(?:[\p{ID_Continue}$\\]|\u200C|\u200D)$/u;
|
|
19
|
+
var BLOCK_KEYWORDS = /* @__PURE__ */ new Set(["do", "else"]);
|
|
20
|
+
var CONTROL_HEADS = /* @__PURE__ */ new Set(["if", "while", "for", "with"]);
|
|
21
|
+
function maskNonCode(src) {
|
|
22
|
+
return scanSource(src).mask;
|
|
23
|
+
}
|
|
24
|
+
function scanSource(src) {
|
|
25
|
+
const out = [];
|
|
26
|
+
const spans = [];
|
|
27
|
+
const templates = [];
|
|
28
|
+
let templateStart = -1;
|
|
29
|
+
const parens = [];
|
|
30
|
+
let i = 0;
|
|
31
|
+
let prevSignificant = "";
|
|
32
|
+
let prevWord = "";
|
|
33
|
+
let wordIsProperty = false;
|
|
34
|
+
let wordOpen = false;
|
|
35
|
+
let punctRun = "";
|
|
36
|
+
let punctOpen = false;
|
|
37
|
+
let afterControlHead = false;
|
|
38
|
+
const braces = [];
|
|
39
|
+
let closedObject = false;
|
|
40
|
+
const at = (k) => src[k] ?? "";
|
|
41
|
+
const top = () => templates[templates.length - 1] ?? 0;
|
|
42
|
+
const setTop = (v) => {
|
|
43
|
+
templates[templates.length - 1] = v;
|
|
44
|
+
};
|
|
45
|
+
const push = (ch, masked = false, shown) => {
|
|
46
|
+
out.push(shown ?? (masked ? ch === "\n" ? "\n" : " " : ch));
|
|
47
|
+
if (/\s/.test(ch)) {
|
|
48
|
+
wordOpen = false;
|
|
49
|
+
punctOpen = false;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const before = prevSignificant;
|
|
53
|
+
prevSignificant = ch;
|
|
54
|
+
afterControlHead = false;
|
|
55
|
+
closedObject = false;
|
|
56
|
+
if (!masked && WORD_CHAR.test(ch)) {
|
|
57
|
+
if (wordOpen) prevWord += ch;
|
|
58
|
+
else {
|
|
59
|
+
prevWord = ch;
|
|
60
|
+
wordIsProperty = before === "." || before === "#";
|
|
61
|
+
}
|
|
62
|
+
wordOpen = true;
|
|
63
|
+
punctRun = "";
|
|
64
|
+
punctOpen = false;
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
prevWord = "";
|
|
68
|
+
wordOpen = false;
|
|
69
|
+
if (masked) {
|
|
70
|
+
punctRun = "";
|
|
71
|
+
punctOpen = false;
|
|
72
|
+
} else {
|
|
73
|
+
punctRun = punctOpen ? punctRun + ch : ch;
|
|
74
|
+
punctOpen = true;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const record = (kind, start) => {
|
|
78
|
+
if (templates.length === 0) spans.push({ kind, start, end: i });
|
|
79
|
+
};
|
|
80
|
+
const regexHere = () => {
|
|
81
|
+
if (prevSignificant === "" || afterControlHead) return true;
|
|
82
|
+
if (prevWord !== "") return !wordIsProperty && REGEX_PRECEDING_KEYWORDS.has(prevWord);
|
|
83
|
+
if (punctRun.endsWith("++") || punctRun.endsWith("--") || closedObject) return false;
|
|
84
|
+
if (punctRun.endsWith("...")) return true;
|
|
85
|
+
return "(,=:[!&|?{};+-*%~^<>/".includes(prevSignificant);
|
|
86
|
+
};
|
|
87
|
+
const objectHere = () => {
|
|
88
|
+
if (prevSignificant === "" || afterControlHead) return false;
|
|
89
|
+
if (prevWord !== "") return !wordIsProperty && REGEX_PRECEDING_KEYWORDS.has(prevWord) && !BLOCK_KEYWORDS.has(prevWord);
|
|
90
|
+
if (punctRun.endsWith("=>")) return false;
|
|
91
|
+
if (punctRun.endsWith("...")) return true;
|
|
92
|
+
return "(,=:[!&|?+-*%~^<>/".includes(prevSignificant);
|
|
93
|
+
};
|
|
94
|
+
while (i < src.length) {
|
|
95
|
+
const ch = at(i);
|
|
96
|
+
const next = at(i + 1);
|
|
97
|
+
if (templates.length > 0 && top() >= 0) {
|
|
98
|
+
if (ch === "{") setTop(top() + 1);
|
|
99
|
+
else if (ch === "}") {
|
|
100
|
+
setTop(top() - 1);
|
|
101
|
+
if (top() === 0) {
|
|
102
|
+
setTop(-1);
|
|
103
|
+
push(ch, true, ")");
|
|
104
|
+
i++;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (templates.length > 0 && top() === -1) {
|
|
110
|
+
if (ch === "\\") {
|
|
111
|
+
push(ch, true);
|
|
112
|
+
push(at(i + 1), true);
|
|
113
|
+
i += 2;
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (ch === "`") {
|
|
117
|
+
templates.pop();
|
|
118
|
+
push(ch, true);
|
|
119
|
+
i++;
|
|
120
|
+
if (templates.length === 0) spans.push({ kind: "template", start: templateStart, end: i });
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (ch === "$" && next === "{") {
|
|
124
|
+
setTop(1);
|
|
125
|
+
push(ch, true);
|
|
126
|
+
push("{", true, "(");
|
|
127
|
+
i += 2;
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
push(ch, true);
|
|
131
|
+
i++;
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
const start = i;
|
|
135
|
+
if (ch === "/" && (next === "/" || next === "*")) {
|
|
136
|
+
const saved = [prevSignificant, prevWord, wordIsProperty, punctRun, afterControlHead, closedObject];
|
|
137
|
+
if (next === "/") {
|
|
138
|
+
while (i < src.length && at(i) !== "\n") push(at(i++), true);
|
|
139
|
+
} else {
|
|
140
|
+
push(at(i++), true);
|
|
141
|
+
push(at(i++), true);
|
|
142
|
+
while (i < src.length && !(at(i) === "*" && at(i + 1) === "/")) push(at(i++), true);
|
|
143
|
+
if (i < src.length) {
|
|
144
|
+
push(at(i++), true);
|
|
145
|
+
push(at(i++), true);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
[prevSignificant, prevWord, wordIsProperty, punctRun, afterControlHead, closedObject] = saved;
|
|
149
|
+
wordOpen = false;
|
|
150
|
+
punctOpen = false;
|
|
151
|
+
record("comment", start);
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (ch === '"' || ch === "'") {
|
|
155
|
+
push(ch, true);
|
|
156
|
+
i++;
|
|
157
|
+
while (i < src.length && at(i) !== ch && at(i) !== "\n") {
|
|
158
|
+
if (at(i) === "\\") push(at(i++), true);
|
|
159
|
+
if (i < src.length) push(at(i++), true);
|
|
160
|
+
}
|
|
161
|
+
if (at(i) === ch) push(at(i++), true);
|
|
162
|
+
record("string", start);
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (ch === "`") {
|
|
166
|
+
if (templates.length === 0) templateStart = i;
|
|
167
|
+
templates.push(-1);
|
|
168
|
+
push(ch, true);
|
|
169
|
+
i++;
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
if (ch === "/" && regexHere()) {
|
|
173
|
+
push(ch, true);
|
|
174
|
+
i++;
|
|
175
|
+
while (i < src.length && at(i) !== "\n") {
|
|
176
|
+
if (at(i) === "\\") {
|
|
177
|
+
push(at(i++), true);
|
|
178
|
+
if (i < src.length) push(at(i++), true);
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (at(i) === "[") {
|
|
182
|
+
while (i < src.length && at(i) !== "]" && at(i) !== "\n") {
|
|
183
|
+
if (at(i) === "\\") push(at(i++), true);
|
|
184
|
+
if (i < src.length) push(at(i++), true);
|
|
185
|
+
}
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (at(i) === "/") {
|
|
189
|
+
push(at(i++), true);
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
push(at(i++), true);
|
|
193
|
+
}
|
|
194
|
+
while (/[A-Za-z]/.test(at(i))) push(at(i++), true);
|
|
195
|
+
record("regex", start);
|
|
196
|
+
prevSignificant = "/";
|
|
197
|
+
prevWord = "re";
|
|
198
|
+
wordIsProperty = true;
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
if (ch === "(") {
|
|
202
|
+
parens.push(!wordIsProperty && CONTROL_HEADS.has(prevWord));
|
|
203
|
+
push(ch);
|
|
204
|
+
i++;
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
if (ch === ")") {
|
|
208
|
+
const control = parens.pop() ?? false;
|
|
209
|
+
push(ch);
|
|
210
|
+
afterControlHead = control;
|
|
211
|
+
i++;
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
if (ch === "{") {
|
|
215
|
+
braces.push(objectHere());
|
|
216
|
+
push(ch);
|
|
217
|
+
i++;
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
if (ch === "}") {
|
|
221
|
+
const object = braces.pop() ?? false;
|
|
222
|
+
push(ch);
|
|
223
|
+
closedObject = object;
|
|
224
|
+
i++;
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
push(ch);
|
|
228
|
+
i++;
|
|
229
|
+
}
|
|
230
|
+
if (templates.length > 0) spans.push({ kind: "template", start: templateStart, end: src.length });
|
|
231
|
+
return { mask: out.join(""), spans };
|
|
232
|
+
}
|
|
233
|
+
var PUNCTUATORS = [
|
|
234
|
+
"...",
|
|
235
|
+
"??=",
|
|
236
|
+
"&&=",
|
|
237
|
+
"||=",
|
|
238
|
+
"**=",
|
|
239
|
+
"===",
|
|
240
|
+
"!==",
|
|
241
|
+
"?.",
|
|
242
|
+
"??",
|
|
243
|
+
"=>",
|
|
244
|
+
"==",
|
|
245
|
+
"!=",
|
|
246
|
+
"**",
|
|
247
|
+
"*=",
|
|
248
|
+
"+=",
|
|
249
|
+
"-=",
|
|
250
|
+
"/=",
|
|
251
|
+
"%=",
|
|
252
|
+
"&&",
|
|
253
|
+
"||",
|
|
254
|
+
"&=",
|
|
255
|
+
"|=",
|
|
256
|
+
"^=",
|
|
257
|
+
"++",
|
|
258
|
+
"--"
|
|
259
|
+
];
|
|
260
|
+
function tokenize(src) {
|
|
261
|
+
const { mask, spans } = scanSource(src);
|
|
262
|
+
const toks = [];
|
|
263
|
+
const spanAt = new Map(spans.map((s) => [s.start, s]));
|
|
264
|
+
let nl = false;
|
|
265
|
+
let i = 0;
|
|
266
|
+
while (i < mask.length) {
|
|
267
|
+
const span = spanAt.get(i);
|
|
268
|
+
if (span !== void 0) {
|
|
269
|
+
if (span.kind === "comment") {
|
|
270
|
+
if (src.slice(span.start, span.end).includes("\n")) nl = true;
|
|
271
|
+
} else {
|
|
272
|
+
toks.push({ kind: span.kind, text: src.slice(span.start, span.end), start: span.start, end: span.end, nl });
|
|
273
|
+
nl = false;
|
|
274
|
+
}
|
|
275
|
+
i = Math.max(span.end, i + 1);
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
const ch = mask[i];
|
|
279
|
+
if (ch === "\n" || ch === "\u2028" || ch === "\u2029") {
|
|
280
|
+
nl = true;
|
|
281
|
+
i++;
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
if (/\s/.test(ch)) {
|
|
285
|
+
i++;
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
const rest = mask.slice(i);
|
|
289
|
+
const word = /^[\p{ID_Start}$_#\\](?:[\p{ID_Continue}$\\]||)*/u.exec(rest)?.[0];
|
|
290
|
+
const num = /^(?:\d|\.\d)[\w.]*/.exec(rest)?.[0];
|
|
291
|
+
let kind;
|
|
292
|
+
let text;
|
|
293
|
+
if (num !== void 0) [kind, text] = ["num", num];
|
|
294
|
+
else if (word !== void 0) [kind, text] = ["id", word];
|
|
295
|
+
else {
|
|
296
|
+
kind = "punct";
|
|
297
|
+
text = PUNCTUATORS.find((p) => rest.startsWith(p) && !(p === "?." && /\d/.test(rest[2] ?? ""))) ?? ch;
|
|
298
|
+
}
|
|
299
|
+
toks.push({ kind, text, start: i, end: i + text.length, nl });
|
|
300
|
+
nl = false;
|
|
301
|
+
i += text.length;
|
|
302
|
+
}
|
|
303
|
+
const match = new Array(toks.length).fill(-1);
|
|
304
|
+
const stack = [];
|
|
305
|
+
const pair = { ")": "(", "]": "[", "}": "{" };
|
|
306
|
+
toks.forEach((t, k) => {
|
|
307
|
+
if (t.kind !== "punct") return;
|
|
308
|
+
if (t.text === "(" || t.text === "[" || t.text === "{") stack.push(k);
|
|
309
|
+
else if (pair[t.text] !== void 0) {
|
|
310
|
+
const open = stack[stack.length - 1];
|
|
311
|
+
if (open === void 0 || toks[open].text !== pair[t.text]) return;
|
|
312
|
+
stack.pop();
|
|
313
|
+
match[open] = k;
|
|
314
|
+
match[k] = open;
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
return { src, toks, match };
|
|
318
|
+
}
|
|
319
|
+
var SourceShapeError = class extends Error {
|
|
320
|
+
constructor(message, offset) {
|
|
321
|
+
super(message);
|
|
322
|
+
this.offset = offset;
|
|
323
|
+
this.name = "SourceShapeError";
|
|
324
|
+
}
|
|
325
|
+
offset;
|
|
326
|
+
};
|
|
327
|
+
var OPERAND_KEYWORDS = /* @__PURE__ */ new Set([
|
|
328
|
+
"return",
|
|
329
|
+
"typeof",
|
|
330
|
+
"instanceof",
|
|
331
|
+
"in",
|
|
332
|
+
"of",
|
|
333
|
+
"new",
|
|
334
|
+
"delete",
|
|
335
|
+
"void",
|
|
336
|
+
"throw",
|
|
337
|
+
"yield",
|
|
338
|
+
"await",
|
|
339
|
+
"case",
|
|
340
|
+
"do",
|
|
341
|
+
"else",
|
|
342
|
+
"extends",
|
|
343
|
+
"as",
|
|
344
|
+
"satisfies",
|
|
345
|
+
"keyof",
|
|
346
|
+
"function",
|
|
347
|
+
"class",
|
|
348
|
+
"if",
|
|
349
|
+
"while",
|
|
350
|
+
"for",
|
|
351
|
+
"with",
|
|
352
|
+
"switch",
|
|
353
|
+
"try",
|
|
354
|
+
"catch",
|
|
355
|
+
"finally",
|
|
356
|
+
"const",
|
|
357
|
+
"let",
|
|
358
|
+
"var",
|
|
359
|
+
"import",
|
|
360
|
+
"export",
|
|
361
|
+
"default",
|
|
362
|
+
"is"
|
|
363
|
+
]);
|
|
364
|
+
var NON_CONTINUING = /* @__PURE__ */ new Set(["!", "~", "++", "--", "{", ";", "@", "#", "..."]);
|
|
365
|
+
var SourceReader = class {
|
|
366
|
+
src;
|
|
367
|
+
toks;
|
|
368
|
+
match;
|
|
369
|
+
constructor(tokens) {
|
|
370
|
+
this.src = tokens.src;
|
|
371
|
+
this.toks = tokens.toks;
|
|
372
|
+
this.match = tokens.match;
|
|
373
|
+
}
|
|
374
|
+
/** The source offset of token `i` (the end of the source past the last token). */
|
|
375
|
+
offset(i) {
|
|
376
|
+
return this.toks[i]?.start ?? this.src.length;
|
|
377
|
+
}
|
|
378
|
+
isP(i, text) {
|
|
379
|
+
const t = this.toks[i];
|
|
380
|
+
return t?.kind === "punct" && t.text === text;
|
|
381
|
+
}
|
|
382
|
+
isId(i, text) {
|
|
383
|
+
const t = this.toks[i];
|
|
384
|
+
return t?.kind === "id" && (text === void 0 || t.text === text);
|
|
385
|
+
}
|
|
386
|
+
fail(message, i) {
|
|
387
|
+
throw new SourceShapeError(message, this.offset(i));
|
|
388
|
+
}
|
|
389
|
+
/** The partner of the bracket at `i`, or a refusal. */
|
|
390
|
+
close(i) {
|
|
391
|
+
const c = this.match[i] ?? -1;
|
|
392
|
+
if (c < 0) this.fail(`an unbalanced \`${this.toks[i]?.text ?? ""}\``, i);
|
|
393
|
+
return c;
|
|
394
|
+
}
|
|
395
|
+
/** Whether token `t` completes an operand, so a line break after it may end the statement. */
|
|
396
|
+
endsOperand(t) {
|
|
397
|
+
if (t === void 0) return false;
|
|
398
|
+
if (t.kind === "id") return !OPERAND_KEYWORDS.has(t.text);
|
|
399
|
+
if (t.kind === "punct") return t.text === ")" || t.text === "]" || t.text === "}" || t.text === "++" || t.text === "--";
|
|
400
|
+
return true;
|
|
401
|
+
}
|
|
402
|
+
/** Whether token `t`, at the start of a line, continues the expression before it. */
|
|
403
|
+
continues(t) {
|
|
404
|
+
if (t === void 0) return false;
|
|
405
|
+
if (t.kind === "punct") return !NON_CONTINUING.has(t.text);
|
|
406
|
+
if (t.kind === "id") return t.text === "in" || t.text === "instanceof";
|
|
407
|
+
return t.kind === "template";
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Index past the expression starting at `i`: it ends at a `;`, at a closer
|
|
411
|
+
* that belongs to an enclosing bracket, or at a line break where JavaScript's
|
|
412
|
+
* automatic semicolon insertion ends it — the token before completes an
|
|
413
|
+
* operand and the token after cannot continue one. A comma at this level
|
|
414
|
+
* refuses: an arrow's body and a default export are each ONE assignment
|
|
415
|
+
* expression, so a comma there means the rules have misread something.
|
|
416
|
+
*/
|
|
417
|
+
expressionEnd(i) {
|
|
418
|
+
let k = i;
|
|
419
|
+
let prev;
|
|
420
|
+
for (; ; ) {
|
|
421
|
+
const t = this.toks[k];
|
|
422
|
+
if (t === void 0) return k;
|
|
423
|
+
if (k > i && t.nl && this.endsOperand(prev) && !this.continues(t)) return k;
|
|
424
|
+
if (t.kind === "punct") {
|
|
425
|
+
if (t.text === ";" || t.text === ")" || t.text === "]" || t.text === "}") return k;
|
|
426
|
+
if (t.text === ",") this.fail("a comma outside every bracket", k);
|
|
427
|
+
if (t.text === "(" || t.text === "[" || t.text === "{") {
|
|
428
|
+
k = this.close(k);
|
|
429
|
+
prev = this.toks[k];
|
|
430
|
+
k++;
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
433
|
+
if (t.text === "!" && !t.nl && this.endsOperand(prev)) {
|
|
434
|
+
prev = { ...t, text: ")" };
|
|
435
|
+
k++;
|
|
436
|
+
continue;
|
|
437
|
+
}
|
|
438
|
+
if (t.text === "<" && !t.nl && this.endsOperand(prev)) {
|
|
439
|
+
const after = this.tryTypeArguments(k);
|
|
440
|
+
if (after !== -1) {
|
|
441
|
+
k = after;
|
|
442
|
+
prev = void 0;
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
if (t.kind === "id" && (t.text === "as" || t.text === "satisfies") && !t.nl && this.endsOperand(prev)) {
|
|
448
|
+
k = this.skipType(k + 1);
|
|
449
|
+
prev = { ...t, text: ")", kind: "punct" };
|
|
450
|
+
continue;
|
|
451
|
+
}
|
|
452
|
+
prev = t;
|
|
453
|
+
k++;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
/** Index past `<…>` type arguments at `i` when a call or tagged template follows them, else -1. */
|
|
457
|
+
tryTypeArguments(i) {
|
|
458
|
+
try {
|
|
459
|
+
const after = this.skipAngle(i);
|
|
460
|
+
return this.isP(after, "(") || this.toks[after]?.kind === "template" ? after : -1;
|
|
461
|
+
} catch {
|
|
462
|
+
return -1;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
/** Index past the `<…>` type parameter or argument list at `i`. */
|
|
466
|
+
skipAngle(i) {
|
|
467
|
+
if (!this.isP(i, "<")) this.fail("expected `<`", i);
|
|
468
|
+
let depth = 0;
|
|
469
|
+
for (let k = i; k < this.toks.length; k++) {
|
|
470
|
+
const t = this.toks[k];
|
|
471
|
+
if (t.kind !== "punct") continue;
|
|
472
|
+
if (t.text === "<") depth++;
|
|
473
|
+
else if (t.text === ">" && --depth === 0) return k + 1;
|
|
474
|
+
else if (t.text === "(" || t.text === "[" || t.text === "{") k = this.close(k);
|
|
475
|
+
else if (t.text === ";" || t.text === ")" || t.text === "]" || t.text === "}") break;
|
|
476
|
+
}
|
|
477
|
+
return this.fail("an unclosed `<`", i);
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Index past the TypeScript type starting at `i`: unions and intersections of
|
|
481
|
+
* keyword-prefixed operands (`keyof`, `typeof`, `readonly`, `infer`), function
|
|
482
|
+
* and constructor types, object and tuple types, names with type arguments,
|
|
483
|
+
* literals, type predicates, array suffixes, and conditional types.
|
|
484
|
+
*/
|
|
485
|
+
skipType(i, noConditional = false) {
|
|
486
|
+
let k = i;
|
|
487
|
+
if (this.isP(k, "|") || this.isP(k, "&")) k++;
|
|
488
|
+
k = this.skipTypeOperand(k);
|
|
489
|
+
while (this.isP(k, "|") || this.isP(k, "&")) k = this.skipTypeOperand(k + 1);
|
|
490
|
+
if (!noConditional && this.isId(k, "extends") && !this.toks[k].nl) {
|
|
491
|
+
k = this.skipType(k + 1, true);
|
|
492
|
+
if (!this.isP(k, "?")) this.fail("a conditional type without `?`", k);
|
|
493
|
+
k = this.skipType(k + 1);
|
|
494
|
+
if (!this.isP(k, ":")) this.fail("a conditional type without `:`", k);
|
|
495
|
+
k = this.skipType(k + 1);
|
|
496
|
+
}
|
|
497
|
+
return k;
|
|
498
|
+
}
|
|
499
|
+
skipTypeOperand(i) {
|
|
500
|
+
let k = i;
|
|
501
|
+
while (this.isId(k, "keyof") || this.isId(k, "readonly") || this.isId(k, "unique")) k++;
|
|
502
|
+
const t = this.toks[k];
|
|
503
|
+
if (t === void 0) return this.fail("a type is missing", k);
|
|
504
|
+
if (this.isId(k, "infer") && this.isId(k + 1)) {
|
|
505
|
+
k += 2;
|
|
506
|
+
} else if (this.isId(k, "typeof")) {
|
|
507
|
+
k++;
|
|
508
|
+
if (this.isId(k, "import") && this.isP(k + 1, "(")) k = this.close(k + 1) + 1;
|
|
509
|
+
else if (this.isId(k)) k++;
|
|
510
|
+
else this.fail("`typeof` without a name", k);
|
|
511
|
+
k = this.skipQualified(k);
|
|
512
|
+
} else if (this.isP(k, "(")) {
|
|
513
|
+
const c = this.close(k);
|
|
514
|
+
if (this.startsFunctionType(k)) {
|
|
515
|
+
if (!this.isP(c + 1, "=>")) this.fail("a function type without `=>`", c + 1);
|
|
516
|
+
return this.skipType(c + 2);
|
|
517
|
+
}
|
|
518
|
+
k = c + 1;
|
|
519
|
+
} else if (this.isP(k, "<")) {
|
|
520
|
+
k = this.skipAngle(k);
|
|
521
|
+
if (!this.isP(k, "(")) this.fail("a generic function type without parameters", k);
|
|
522
|
+
k = this.close(k) + 1;
|
|
523
|
+
if (!this.isP(k, "=>")) this.fail("a generic function type without `=>`", k);
|
|
524
|
+
return this.skipType(k + 1);
|
|
525
|
+
} else if (this.isId(k, "new") || this.isId(k, "abstract") && this.isId(k + 1, "new")) {
|
|
526
|
+
k += this.isId(k, "abstract") ? 2 : 1;
|
|
527
|
+
if (this.isP(k, "<")) k = this.skipAngle(k);
|
|
528
|
+
if (!this.isP(k, "(")) this.fail("a constructor type without parameters", k);
|
|
529
|
+
k = this.close(k) + 1;
|
|
530
|
+
if (!this.isP(k, "=>")) this.fail("a constructor type without `=>`", k);
|
|
531
|
+
return this.skipType(k + 1);
|
|
532
|
+
} else if (this.isP(k, "{") || this.isP(k, "[")) {
|
|
533
|
+
k = this.close(k) + 1;
|
|
534
|
+
} else if (t.kind === "string" || t.kind === "num" || t.kind === "template") {
|
|
535
|
+
k++;
|
|
536
|
+
} else if (this.isP(k, "-") && this.toks[k + 1]?.kind === "num") {
|
|
537
|
+
k += 2;
|
|
538
|
+
} else if (this.isId(k, "asserts") && this.isId(k + 1) && !this.isP(k + 1, ".")) {
|
|
539
|
+
k += 2;
|
|
540
|
+
if (this.isId(k, "is")) return this.skipType(k + 1);
|
|
541
|
+
return k;
|
|
542
|
+
} else if (this.isId(k, "import") && this.isP(k + 1, "(")) {
|
|
543
|
+
k = this.skipQualified(this.close(k + 1) + 1);
|
|
544
|
+
} else if (t.kind === "id") {
|
|
545
|
+
k = this.skipQualified(k + 1);
|
|
546
|
+
if (this.isId(k, "is") && !this.toks[k].nl) return this.skipType(k + 1);
|
|
547
|
+
} else {
|
|
548
|
+
return this.fail(`\`${t.text}\` where a type was expected`, k);
|
|
549
|
+
}
|
|
550
|
+
while (this.isP(k, "[") && !this.toks[k].nl) k = this.close(k) + 1;
|
|
551
|
+
return k;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Whether the `(` at `i` opens a function type's parameters rather than a
|
|
555
|
+
* parenthesized type — TypeScript's own rule: `()`, `(...`, or a first
|
|
556
|
+
* parameter (a name, `this`, or a pattern, after any modifier) followed by
|
|
557
|
+
* `:` `,` `?` `=`, or alone and followed by `) =>`. So `(x: T) => U` and
|
|
558
|
+
* `(x) => U` are function types and `(A | B)` is not.
|
|
559
|
+
*/
|
|
560
|
+
startsFunctionType(i) {
|
|
561
|
+
let k = i + 1;
|
|
562
|
+
if (this.isP(k, ")") || this.isP(k, "...")) return true;
|
|
563
|
+
while (["public", "private", "protected", "readonly"].includes(this.toks[k]?.text ?? "") && this.isId(k + 1)) k++;
|
|
564
|
+
if (this.isId(k)) k++;
|
|
565
|
+
else if ((this.isP(k, "[") || this.isP(k, "{")) && (this.match[k] ?? -1) > 0) k = this.match[k] + 1;
|
|
566
|
+
else return false;
|
|
567
|
+
if (this.isP(k, ":") || this.isP(k, ",") || this.isP(k, "?") || this.isP(k, "=")) return true;
|
|
568
|
+
return this.isP(k, ")") && this.isP(k + 1, "=>");
|
|
569
|
+
}
|
|
570
|
+
/** Past `.Name` segments and type arguments after a type name. */
|
|
571
|
+
skipQualified(i) {
|
|
572
|
+
let k = i;
|
|
573
|
+
while (this.isP(k, ".") && this.isId(k + 1)) k += 2;
|
|
574
|
+
if (this.isP(k, "<") && !this.toks[k].nl) k = this.skipAngle(k);
|
|
575
|
+
return k;
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Read one function expression at token `i` — `function` or arrow, optionally
|
|
579
|
+
* `async`, with type parameters, parameter annotations and a return type of any
|
|
580
|
+
* shape — behind optional parentheses and trailing `as T` / `satisfies T` /
|
|
581
|
+
* `!`. Returns the shape and the token index past everything read.
|
|
582
|
+
*/
|
|
583
|
+
parseFunctionExpression(i) {
|
|
584
|
+
if (this.isP(i, "(")) {
|
|
585
|
+
const c = this.close(i);
|
|
586
|
+
if (!this.isP(c + 1, "=>") && !this.isP(c + 1, ":")) {
|
|
587
|
+
const inner = this.parseFunctionExpression(i + 1);
|
|
588
|
+
if (inner.end !== c) this.fail("more than one function inside the parentheses", inner.end);
|
|
589
|
+
let k = c + 1;
|
|
590
|
+
for (; ; ) {
|
|
591
|
+
const t = this.toks[k];
|
|
592
|
+
if (t !== void 0 && !t.nl && (this.isId(k, "as") || this.isId(k, "satisfies"))) {
|
|
593
|
+
k = this.skipType(k + 1);
|
|
594
|
+
} else if (t !== void 0 && !t.nl && this.isP(k, "!")) {
|
|
595
|
+
k++;
|
|
596
|
+
} else break;
|
|
597
|
+
}
|
|
598
|
+
return { fn: inner.fn, end: k };
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
return this.parseFunction(i);
|
|
602
|
+
}
|
|
603
|
+
parseFunction(i) {
|
|
604
|
+
let k = i;
|
|
605
|
+
if (this.isId(k, "async") && !this.isP(k + 1, "=>") && this.toks[k + 1] !== void 0 && !this.toks[k + 1].nl) k++;
|
|
606
|
+
if (this.isId(k, "function")) {
|
|
607
|
+
k++;
|
|
608
|
+
if (this.isP(k, "*")) k++;
|
|
609
|
+
let name;
|
|
610
|
+
if (this.isId(k)) name = this.toks[k++].text;
|
|
611
|
+
if (this.isP(k, "<")) k = this.skipAngle(k);
|
|
612
|
+
if (!this.isP(k, "(")) this.fail("a `function` without a parameter list", k);
|
|
613
|
+
const pc = this.close(k);
|
|
614
|
+
const params2 = [this.toks[k].start, this.toks[pc].end];
|
|
615
|
+
k = pc + 1;
|
|
616
|
+
if (this.isP(k, ":")) k = this.skipType(k + 1);
|
|
617
|
+
if (!this.isP(k, "{")) this.fail("a `function` whose body does not follow its signature", k);
|
|
618
|
+
const bc = this.close(k);
|
|
619
|
+
return {
|
|
620
|
+
fn: { form: "function", params: params2, block: true, body: [this.toks[k].end, this.toks[bc].start], name },
|
|
621
|
+
end: bc + 1
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
if (this.isP(k, "<")) k = this.skipAngle(k);
|
|
625
|
+
let params;
|
|
626
|
+
if (this.isP(k, "(")) {
|
|
627
|
+
const pc = this.close(k);
|
|
628
|
+
params = [this.toks[k].start, this.toks[pc].end];
|
|
629
|
+
k = pc + 1;
|
|
630
|
+
if (this.isP(k, ":")) k = this.skipType(k + 1);
|
|
631
|
+
} else if (this.isId(k) && !OPERAND_KEYWORDS.has(this.toks[k].text)) {
|
|
632
|
+
params = [this.toks[k].start, this.toks[k].end];
|
|
633
|
+
k++;
|
|
634
|
+
} else {
|
|
635
|
+
return this.fail("no parameter list where a function starts", k);
|
|
636
|
+
}
|
|
637
|
+
if (!this.isP(k, "=>")) this.fail("no `=>` after the parameter list", k);
|
|
638
|
+
k++;
|
|
639
|
+
if (this.isP(k, "{")) {
|
|
640
|
+
const bc = this.close(k);
|
|
641
|
+
return {
|
|
642
|
+
fn: { form: "arrow", params, block: true, body: [this.toks[k].end, this.toks[bc].start], name: void 0 },
|
|
643
|
+
end: bc + 1
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
const end = this.expressionEnd(k);
|
|
647
|
+
if (end === k) this.fail("an arrow with no body", k);
|
|
648
|
+
return {
|
|
649
|
+
fn: { form: "arrow", params, block: false, body: [this.toks[k].start, this.toks[end - 1].end], name: void 0 },
|
|
650
|
+
end
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* Index past the statement at `i` by the same line-break rules as
|
|
655
|
+
* {@link expressionEnd}, commas allowed. For the top-level statements a lambda
|
|
656
|
+
* module may carry beside its default export: imports, `declare`, and re-exports.
|
|
657
|
+
*/
|
|
658
|
+
statementEnd(i) {
|
|
659
|
+
let k = i;
|
|
660
|
+
let prev;
|
|
661
|
+
for (; ; ) {
|
|
662
|
+
const t = this.toks[k];
|
|
663
|
+
if (t === void 0) return k;
|
|
664
|
+
if (k > i && t.nl && this.endsOperand(prev) && !this.continues(t)) return k;
|
|
665
|
+
if (this.isP(k, ";")) return k + 1;
|
|
666
|
+
if (this.isP(k, "(") || this.isP(k, "[") || this.isP(k, "{")) k = this.close(k);
|
|
667
|
+
prev = this.toks[k];
|
|
668
|
+
k++;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
function lineOf(src, offset) {
|
|
673
|
+
let line = 1;
|
|
674
|
+
for (let k = 0; k < offset && k < src.length; k++) if (src[k] === "\n") line++;
|
|
675
|
+
return line;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
export {
|
|
679
|
+
maskNonCode,
|
|
680
|
+
scanSource,
|
|
681
|
+
tokenize,
|
|
682
|
+
SourceShapeError,
|
|
683
|
+
SourceReader,
|
|
684
|
+
lineOf
|
|
685
|
+
};
|
|
686
|
+
//# sourceMappingURL=chunk-VAX3UZOY.js.map
|