@wular/pnext 0.1.5 → 0.1.7
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/bin/pnext +9 -2
- package/dist/server/_chunks/aliases-j47a10ce.js +44 -0
- package/dist/server/_chunks/analyze-arswqe6s.js +445 -0
- package/dist/server/_chunks/boot-af0mv3dy.js +36 -0
- package/dist/server/_chunks/build-spy3dxp4.js +84 -0
- package/dist/server/_chunks/build-t9h0hec3.js +3550 -0
- package/dist/server/_chunks/build-tier-m7yvqz61.js +2472 -0
- package/dist/server/_chunks/compile-53j02j27.js +22 -0
- package/dist/server/_chunks/config-1yzwexq6.js +27 -0
- package/dist/server/_chunks/config-n2z7yxps.js +22 -0
- package/dist/server/_chunks/create-meec9hs6.js +134 -0
- package/dist/server/_chunks/dev-fjmqg6en.js +220 -0
- package/dist/server/_chunks/esbuild-yyktfrtt.js +15 -0
- package/dist/server/_chunks/generate-n9sh6hzt.js +21 -0
- package/dist/server/_chunks/index-0374j2b9.js +66 -0
- package/dist/server/_chunks/index-06nyqntx.js +213 -0
- package/dist/server/_chunks/index-1011cscr.js +5263 -0
- package/dist/server/_chunks/index-11sfk4hb.js +170 -0
- package/dist/server/_chunks/index-20ppawv7.js +297 -0
- package/dist/server/_chunks/index-2dv4y4wd.js +1065 -0
- package/dist/server/_chunks/index-2vz0wzdn.js +59 -0
- package/dist/server/_chunks/index-2wfv4kvx.js +182 -0
- package/dist/server/_chunks/index-357na4a8.js +109 -0
- package/dist/server/_chunks/index-3b3at80h.js +109 -0
- package/dist/server/_chunks/index-3tf1xjsp.js +6166 -0
- package/dist/server/_chunks/index-3xbr4eyv.js +105 -0
- package/dist/server/_chunks/index-4399bvd2.js +18 -0
- package/dist/server/_chunks/index-4hgjrqh7.js +851 -0
- package/dist/server/_chunks/index-4q2gbfwk.js +2530 -0
- package/dist/server/_chunks/index-4t92hdxd.js +172 -0
- package/dist/server/_chunks/index-4zzebszd.js +10 -0
- package/dist/server/_chunks/index-5gyr4emz.js +107 -0
- package/dist/server/_chunks/index-5hr4062s.js +70 -0
- package/dist/server/_chunks/index-68m3mwbd.js +84 -0
- package/dist/server/_chunks/index-6b009mt0.js +56 -0
- package/dist/server/_chunks/index-6e4fqv30.js +588 -0
- package/dist/server/_chunks/index-6gex3pfa.js +15 -0
- package/dist/server/_chunks/index-6kp9r0d9.js +11 -0
- package/dist/server/_chunks/index-6q7zvrap.js +134 -0
- package/dist/server/_chunks/index-73z4esab.js +38 -0
- package/dist/server/_chunks/index-79ngvam8.js +60 -0
- package/dist/server/_chunks/index-7wc9n8be.js +25 -0
- package/dist/server/_chunks/index-8k7pfejn.js +1599 -0
- package/dist/server/_chunks/index-8kcxdfya.js +206 -0
- package/dist/server/_chunks/index-91x12ykq.js +274 -0
- package/dist/server/_chunks/index-9ch50vtq.js +18 -0
- package/dist/server/_chunks/index-9hx2641q.js +28 -0
- package/dist/server/_chunks/index-9n2914ww.js +535 -0
- package/dist/server/_chunks/index-9ych9ma8.js +207 -0
- package/dist/server/_chunks/index-b6wtkdp4.js +24 -0
- package/dist/server/_chunks/index-bcws5eh2.js +35 -0
- package/dist/server/_chunks/index-c0g2wf3z.js +92 -0
- package/dist/server/_chunks/index-cf4rvxv6.js +95 -0
- package/dist/server/_chunks/index-cjgqs13g.js +65 -0
- package/dist/server/_chunks/index-ckkdpht5.js +41 -0
- package/dist/server/_chunks/index-cyfednwb.js +87 -0
- package/dist/server/_chunks/index-danncfhy.js +311 -0
- package/dist/server/_chunks/index-dg0f05zs.js +199 -0
- package/dist/server/_chunks/index-e3a6yx84.js +18 -0
- package/dist/server/_chunks/index-e88tyv35.js +45 -0
- package/dist/server/_chunks/index-eajaspjk.js +1253 -0
- package/dist/server/_chunks/index-eeaanp2e.js +483 -0
- package/dist/server/_chunks/index-egykcqg3.js +101 -0
- package/dist/server/_chunks/index-en7n9f7m.js +22 -0
- package/dist/server/_chunks/index-ezgj0tr1.js +88 -0
- package/dist/server/_chunks/index-fkp000p1.js +590 -0
- package/dist/server/_chunks/index-fn1chkkd.js +214 -0
- package/dist/server/_chunks/index-fp8r0sqs.js +64 -0
- package/dist/server/_chunks/index-ggk2j965.js +9432 -0
- package/dist/server/_chunks/index-grta8ap3.js +238 -0
- package/dist/server/_chunks/index-h2a70tg4.js +7 -0
- package/dist/server/_chunks/index-h4xy648y.js +51 -0
- package/dist/server/_chunks/index-hkdfj58q.js +92 -0
- package/dist/server/_chunks/index-j2zrcp1k.js +66 -0
- package/dist/server/_chunks/index-jcsjq3d1.js +20 -0
- package/dist/server/_chunks/index-jepjvcrf.js +198 -0
- package/dist/server/_chunks/index-jks0x0a1.js +14 -0
- package/dist/server/_chunks/index-jx7bqvw1.js +57 -0
- package/dist/server/_chunks/index-k1g3epw0.js +1299 -0
- package/dist/server/_chunks/index-knp0s912.js +7 -0
- package/dist/server/_chunks/index-kq8kpzye.js +472 -0
- package/dist/server/_chunks/index-kqyy1d4f.js +50 -0
- package/dist/server/_chunks/index-kresp2n8.js +445 -0
- package/dist/server/_chunks/index-ms9v9tnx.js +31 -0
- package/dist/server/_chunks/index-n4hxpng2.js +11 -0
- package/dist/server/_chunks/index-ncnes8c6.js +17 -0
- package/dist/server/_chunks/index-nqh3xhdc.js +57 -0
- package/dist/server/_chunks/index-nyrba2kr.js +4130 -0
- package/dist/server/_chunks/index-p77b4kcx.js +296 -0
- package/dist/server/_chunks/index-pym1cezq.js +39 -0
- package/dist/server/_chunks/index-q738kkhj.js +100 -0
- package/dist/server/_chunks/index-qjj6gddn.js +54 -0
- package/dist/server/_chunks/index-qm6kmhqs.js +110 -0
- package/dist/server/_chunks/index-qn4z5s3c.js +819 -0
- package/dist/server/_chunks/index-qpwsgt3a.js +158 -0
- package/dist/server/_chunks/index-r97ptz1q.js +97 -0
- package/dist/server/_chunks/index-ras0sdab.js +26 -0
- package/dist/server/_chunks/index-rcs322t1.js +19 -0
- package/dist/server/_chunks/index-rn8dyr1f.js +126 -0
- package/dist/server/_chunks/index-rt9qq1va.js +4 -0
- package/dist/server/_chunks/index-rthrsed5.js +356 -0
- package/dist/server/_chunks/index-sctcgyvv.js +185 -0
- package/dist/server/_chunks/index-sjpckxqn.js +213 -0
- package/dist/server/_chunks/index-sq3kvz3g.js +200 -0
- package/dist/server/_chunks/index-stbk3jhn.js +31 -0
- package/dist/server/_chunks/index-sv8m6789.js +266 -0
- package/dist/server/_chunks/index-tgcakdxc.js +125 -0
- package/dist/server/_chunks/index-tgsfjmep.js +74 -0
- package/dist/server/_chunks/index-tq0pc7eg.js +154 -0
- package/dist/server/_chunks/index-tq1f96v7.js +51 -0
- package/dist/server/_chunks/index-tqn2qnnn.js +241 -0
- package/dist/server/_chunks/index-tvqkq6e6.js +128 -0
- package/dist/server/_chunks/index-v1ags1na.js +132 -0
- package/dist/server/_chunks/index-vvmmknm1.js +1431 -0
- package/dist/server/_chunks/index-vvq7rqtn.js +329 -0
- package/dist/server/_chunks/index-vz0km5qk.js +33 -0
- package/dist/server/_chunks/index-w6h8m6vp.js +138 -0
- package/dist/server/_chunks/index-web361b8.js +138 -0
- package/dist/server/_chunks/index-wpfhfbs4.js +194 -0
- package/dist/server/_chunks/index-x0y005nh.js +283 -0
- package/dist/server/_chunks/index-x3yn4ywm.js +22 -0
- package/dist/server/_chunks/index-x93hv0sc.js +271 -0
- package/dist/server/_chunks/index-xvj80c3a.js +30 -0
- package/dist/server/_chunks/index-xywjg2vc.js +100 -0
- package/dist/server/_chunks/index-y2jr2n72.js +152 -0
- package/dist/server/_chunks/index-y36a0ybw.js +57 -0
- package/dist/server/_chunks/index-ye9hmsvf.js +47 -0
- package/dist/server/_chunks/index-yhxkxghe.js +56 -0
- package/dist/server/_chunks/index-ym67zqxp.js +130 -0
- package/dist/server/_chunks/index-ytjvpbm2.js +736 -0
- package/dist/server/_chunks/index-yz54pxrh.js +960 -0
- package/dist/server/_chunks/index-z4z9zv3b.js +733 -0
- package/dist/server/_chunks/index-z84ab1w0.js +1270 -0
- package/dist/server/_chunks/index-z88qv16t.js +11 -0
- package/dist/server/_chunks/index-zqpqyg8p.js +666 -0
- package/dist/server/_chunks/loader-7yw0j98z.js +78 -0
- package/dist/server/_chunks/modules-jn8bmbn8.js +74 -0
- package/dist/server/_chunks/pipeline-yy9jhydf.js +832 -0
- package/dist/server/_chunks/production-jar9ztm3.js +44 -0
- package/dist/server/_chunks/proxy-config-j84dgksn.js +21 -0
- package/dist/server/_chunks/proxy-w1d0wmsn.js +33 -0
- package/dist/server/_chunks/router-k1reahfn.js +498 -0
- package/dist/server/_chunks/routes-2s277fc6.js +64 -0
- package/dist/server/_chunks/run-pvd8bs1t.js +696 -0
- package/dist/server/_chunks/server-mt4a994c.js +1835 -0
- package/dist/server/_chunks/tsconfig-defaults-1nb3308g.js +20 -0
- package/dist/server/_chunks/typegen-0qr0459b.js +35 -0
- package/dist/server/api/client-cache.js +14 -0
- package/dist/server/cli/index.js +378 -0
- package/dist/server/cli/start.js +137 -0
- package/dist/server/client/reference.js +16 -0
- package/dist/server/compat/next/cache.js +56 -0
- package/dist/server/compat/next/canonical-url.js +13 -0
- package/dist/server/compat/next/client-cache.js +57 -0
- package/dist/server/compat/next/client-navigation.js +232 -0
- package/dist/server/compat/next/client-only.js +1 -0
- package/dist/server/compat/next/client-script.js +178 -0
- package/dist/server/compat/next/client-server.js +34 -0
- package/dist/server/compat/next/config-headers.js +32 -0
- package/dist/server/compat/next/config-loader.js +25 -0
- package/dist/server/compat/next/config.js +10 -0
- package/dist/server/compat/next/constants.js +18 -0
- package/dist/server/compat/next/custom-server.js +10 -0
- package/dist/server/compat/next/dist/client/components/app-router-headers.js +48 -0
- package/dist/server/compat/next/dist/server/web/spec-extension/revalidate.js +27 -0
- package/dist/server/compat/next/dist/server/web/spec-extension/unstable-cache.js +25 -0
- package/dist/server/compat/next/dist/server/web/spec-extension/unstable-no-store.js +25 -0
- package/dist/server/compat/next/dynamic.js +32 -0
- package/dist/server/compat/next/error.js +112 -0
- package/dist/server/compat/next/font/cache.js +14 -0
- package/dist/server/compat/next/font/google.js +3 -0
- package/dist/server/compat/next/font/index.js +1 -0
- package/dist/server/compat/next/font/local.js +22 -0
- package/dist/server/compat/next/font/runtime-client.js +33 -0
- package/dist/server/compat/next/font/runtime.js +41 -0
- package/dist/server/compat/next/font/shared.js +22 -0
- package/dist/server/compat/next/form.js +129 -0
- package/dist/server/compat/next/head.js +10 -0
- package/dist/server/compat/next/headers.js +30 -0
- package/dist/server/compat/next/image/client.js +11 -0
- package/dist/server/compat/next/image/config.js +18 -0
- package/dist/server/compat/next/image/optimizer.js +25 -0
- package/dist/server/compat/next/image/patterns.js +12 -0
- package/dist/server/compat/next/image/props.js +16 -0
- package/dist/server/compat/next/image/shared.js +86 -0
- package/dist/server/compat/next/image/static-metadata.js +32 -0
- package/dist/server/compat/next/image/validate.js +8 -0
- package/dist/server/compat/next/image.js +59 -0
- package/dist/server/compat/next/index.js +1 -0
- package/dist/server/compat/next/legacy-image.js +78 -0
- package/dist/server/compat/next/legacy-request-apis.js +24 -0
- package/dist/server/compat/next/link-transform.js +14 -0
- package/dist/server/compat/next/link.js +14 -0
- package/dist/server/compat/next/navigation.js +190 -0
- package/dist/server/compat/next/offline.js +45 -0
- package/dist/server/compat/next/og.js +8 -0
- package/dist/server/compat/next/preferred-region.js +8 -0
- package/dist/server/compat/next/redirects.js +30 -0
- package/dist/server/compat/next/resource-hints.js +30 -0
- package/dist/server/compat/next/rewrites.js +41 -0
- package/dist/server/compat/next/root-params.js +121 -0
- package/dist/server/compat/next/route-state.js +23 -0
- package/dist/server/compat/next/router.js +103 -0
- package/dist/server/compat/next/script.js +37 -0
- package/dist/server/compat/next/server-only.js +1 -0
- package/dist/server/compat/next/server.js +131 -0
- package/dist/server/compat/next/svgr.js +14 -0
- package/dist/server/compat/next/telemetry.js +10 -0
- package/dist/server/compat/next/usage.js +13 -0
- package/dist/server/compat/next/user-agent.js +12 -0
- package/dist/server/compat/next/web-vitals.js +35 -0
- package/dist/server/compat/react/action-state.js +11 -0
- package/dist/server/compat/react/client-lite.js +83 -0
- package/dist/server/compat/react/client.js +131 -0
- package/dist/server/compat/react/compiler-runtime.js +42 -0
- package/dist/server/compat/react/dom-client.js +106 -0
- package/dist/server/compat/react/dom-react-server.js +37 -0
- package/dist/server/compat/react/dom-server.js +40 -0
- package/dist/server/compat/react/dom.js +52 -0
- package/dist/server/compat/react/hooks-extra.js +12 -0
- package/dist/server/compat/react/internals.js +14 -0
- package/dist/server/compat/react/parity.js +11 -0
- package/dist/server/compat/react/preact.js +113 -0
- package/dist/server/compat/react/react-server.js +133 -0
- package/dist/server/compat/react/router-shim.js +8 -0
- package/dist/server/compat/react/server-component-use.js +14 -0
- package/dist/server/compat/react/server-inserted-html.js +14 -0
- package/dist/server/compat/react/server.js +194 -0
- package/dist/server/compat/react/style-values.js +10 -0
- package/dist/server/compat/react/use.js +10 -0
- package/dist/server/compat/react/view-transition.js +12 -0
- package/dist/server/generation.json +1 -0
- package/package.json +4 -1
- package/src/api/dynamic.tsx +2 -0
- package/src/api/server.ts +24 -6
- package/src/cli/adapters/vercel-warm.ts +315 -61
- package/src/cli/adapters/vercel.ts +348 -71
- package/src/cli/build.ts +58 -33
- package/src/cli/index.ts +23 -10
- package/src/cli/serve/entry.ts +21 -159
- package/src/cli/serve/immutable.ts +31 -0
- package/src/cli/serve/pipeline.ts +82 -84
- package/src/cli/start.ts +3 -1
- package/src/client/chunk-fold.ts +19 -6
- package/src/client/react-tier.ts +3 -2
- package/src/client/reference-stub.ts +21 -2
- package/src/compat/actions/client-plugin.ts +4 -2
- package/src/compat/actions/config.ts +6 -5
- package/src/compat/actions/extensions.ts +2 -3
- package/src/compat/aliases.ts +8 -1
- package/src/compat/bundler/config.ts +88 -0
- package/src/compat/bundler/optimize-package-imports.ts +86 -26
- package/src/compat/bundler/relay-transform.ts +15 -3
- package/src/compat/cache-control.ts +16 -8
- package/src/compat/css/modules.ts +18 -5
- package/src/compat/lifecycle/error-funnel.ts +1 -1
- package/src/compat/lifecycle/instrumentation.ts +117 -24
- package/src/compat/lifecycle/testmode.ts +3 -2
- package/src/compat/next/config-loader.ts +137 -13
- package/src/compat/next/font/runtime.ts +22 -2
- package/src/compat/next/og.ts +3 -3
- package/src/compat/next/usage.ts +3 -2
- package/src/compat/pages/api.ts +83 -14
- package/src/compat/pages/router.ts +30 -14
- package/src/compat/register/bundler.ts +3 -1
- package/src/compat/register/middleware.ts +1 -1
- package/src/compat/register/otel.ts +5 -9
- package/src/compat/register/render.ts +3 -1
- package/src/compat/register/use-cache.ts +3 -1
- package/src/compat/release.ts +46 -0
- package/src/compat/segment/serve.ts +1 -1
- package/src/compat/validation/validate.ts +10 -7
- package/src/config.ts +51 -7
- package/src/css/assets.ts +213 -0
- package/src/css/build.ts +174 -238
- package/src/dev/server.ts +27 -8
- package/src/extensions.ts +4 -0
- package/src/render/hooks.ts +13 -0
- package/src/render/renderer.ts +52 -32
- package/src/request/context.ts +9 -0
- package/src/resolve/dynamic.ts +3 -1
- package/src/resolve/imports.ts +12 -52
- package/src/resolve/package-json.ts +56 -0
- package/src/resolve/scan-facts.ts +65 -0
- package/src/routing/href.ts +10 -3
- package/src/routing/match.ts +287 -0
- package/src/routing/metadata-files.ts +19 -5
- package/src/routing/proxy-config.ts +137 -0
- package/src/routing/proxy.ts +35 -134
- package/src/routing/routes.ts +22 -281
- package/src/runtime/fingerprint.ts +23 -8
- package/src/runtime/load.ts +170 -0
- package/src/runtime/loader.ts +215 -43
- package/src/runtime/module-cache.ts +13 -0
- package/src/runtime/modules.ts +370 -81
- package/src/runtime/prebundle.ts +81 -0
- package/src/runtime/production.ts +391 -0
- package/src/runtime/release-graph.ts +334 -0
- package/src/runtime/vendor-build.ts +724 -13
- package/src/runtime/vendor.ts +16 -3
- package/src/types.ts +2 -0
- package/src/utils/fs.ts +89 -3
|
@@ -0,0 +1,733 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
isCommonJsModuleSource
|
|
4
|
+
} from "./index-yz54pxrh.js";
|
|
5
|
+
import {
|
|
6
|
+
loadNative
|
|
7
|
+
} from "./index-7wc9n8be.js";
|
|
8
|
+
import {
|
|
9
|
+
__require
|
|
10
|
+
} from "./index-rt9qq1va.js";
|
|
11
|
+
|
|
12
|
+
// src/runtime/module-transform.ts
|
|
13
|
+
var transformSync = (...args) => loadNative(() => __require("oxc-transform")).transformSync(...args);
|
|
14
|
+
var NON_LITERAL_DYNAMIC_IMPORT = /\bimport\s*\(\s*(?!['"])[^)]/;
|
|
15
|
+
var REQUIRE_CALL = /\brequire\s*\(/;
|
|
16
|
+
var COMMONJS_EXPORTS = /\bmodule\.exports\b|\bexports\s*\.\s*[A-Za-z_$]/;
|
|
17
|
+
var ENUM_DECLARATION = /(?:^|[^.\w$])enum\s+[A-Za-z_$]/;
|
|
18
|
+
function transformBailReason(source, file) {
|
|
19
|
+
if (REQUIRE_CALL.test(source) || COMMONJS_EXPORTS.test(source) || isCommonJsModuleSource(source, file)) {
|
|
20
|
+
return "commonjs";
|
|
21
|
+
}
|
|
22
|
+
if (NON_LITERAL_DYNAMIC_IMPORT.test(source))
|
|
23
|
+
return "glob-import";
|
|
24
|
+
if (ENUM_DECLARATION.test(source))
|
|
25
|
+
return "enum";
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
function transformServerModule(source, file, define) {
|
|
29
|
+
const options = {
|
|
30
|
+
lang: langForFile(file),
|
|
31
|
+
jsx: { runtime: "automatic", importSource: "preact" },
|
|
32
|
+
sourcemap: false,
|
|
33
|
+
...define ? { define } : {}
|
|
34
|
+
};
|
|
35
|
+
const result = transformSync(file, source, options);
|
|
36
|
+
if (result.errors.length > 0)
|
|
37
|
+
return { bail: "parse-error" };
|
|
38
|
+
if (Object.keys(result.helpersUsed).length > 0)
|
|
39
|
+
return { bail: "helpers" };
|
|
40
|
+
return { code: dropUnreferencedImports(result.code) };
|
|
41
|
+
}
|
|
42
|
+
function langForFile(file) {
|
|
43
|
+
if (/\.[mc]?ts$/.test(file))
|
|
44
|
+
return "ts";
|
|
45
|
+
if (file.endsWith(".tsx"))
|
|
46
|
+
return "tsx";
|
|
47
|
+
return "jsx";
|
|
48
|
+
}
|
|
49
|
+
var SPECIFIER_RE = /(?:^|[\n;{}])\s*(?:import|export)\b[^;'"]*?\bfrom\s*("[^"]*"|'[^']*')|(?:^|[\n;{}])\s*import\s*("[^"]*"|'[^']*')|\bimport\s*\(\s*("[^"]*"|'[^']*')\s*\)/g;
|
|
50
|
+
function outputSpecifiers(code) {
|
|
51
|
+
const found = [];
|
|
52
|
+
SPECIFIER_RE.lastIndex = 0;
|
|
53
|
+
let match;
|
|
54
|
+
while (match = SPECIFIER_RE.exec(code)) {
|
|
55
|
+
for (let group = 1;group <= 3; group += 1) {
|
|
56
|
+
const literal = match[group];
|
|
57
|
+
if (literal === undefined)
|
|
58
|
+
continue;
|
|
59
|
+
const start = match.index + match[0].lastIndexOf(literal);
|
|
60
|
+
found.push({
|
|
61
|
+
start,
|
|
62
|
+
end: start + literal.length,
|
|
63
|
+
value: literal.slice(1, -1),
|
|
64
|
+
kind: group === 3 ? "dynamic-import" : "import-statement"
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return found;
|
|
69
|
+
}
|
|
70
|
+
function spliceSource(code, edits) {
|
|
71
|
+
let next = code;
|
|
72
|
+
for (const edit of [...edits].sort((a, b) => b.start - a.start)) {
|
|
73
|
+
next = `${next.slice(0, edit.start)}${edit.value}${next.slice(edit.end)}`;
|
|
74
|
+
}
|
|
75
|
+
return next;
|
|
76
|
+
}
|
|
77
|
+
var IMPORT_STATEMENT_RE = /(?:^|\n)[ \t]*import\s+([A-Za-z_$][\w$]*\s*,\s*)?(?:\*\s*as\s+([A-Za-z_$][\w$]*)|\{([^}]*)\}|([A-Za-z_$][\w$]*))\s+from\s*(?:"[^"]*"|'[^']*')\s*;?/g;
|
|
78
|
+
function dropUnreferencedImports(code) {
|
|
79
|
+
const statements = [];
|
|
80
|
+
IMPORT_STATEMENT_RE.lastIndex = 0;
|
|
81
|
+
let match;
|
|
82
|
+
while (match = IMPORT_STATEMENT_RE.exec(code)) {
|
|
83
|
+
const [text, defaultWithNamed, namespace, named, defaultOnly] = match;
|
|
84
|
+
const names = [];
|
|
85
|
+
if (defaultWithNamed)
|
|
86
|
+
names.push(defaultWithNamed.replace(/\s*,\s*$/, "").trim());
|
|
87
|
+
if (namespace)
|
|
88
|
+
names.push(namespace);
|
|
89
|
+
if (defaultOnly)
|
|
90
|
+
names.push(defaultOnly);
|
|
91
|
+
if (named !== undefined) {
|
|
92
|
+
for (const part of named.split(",")) {
|
|
93
|
+
const local = part.split(/\bas\b/).pop()?.trim();
|
|
94
|
+
if (!local)
|
|
95
|
+
continue;
|
|
96
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(local))
|
|
97
|
+
return code;
|
|
98
|
+
names.push(local);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (names.length === 0)
|
|
102
|
+
continue;
|
|
103
|
+
const leading = text.startsWith(`
|
|
104
|
+
`) ? 1 : 0;
|
|
105
|
+
statements.push({ start: match.index + leading, end: match.index + text.length, names });
|
|
106
|
+
}
|
|
107
|
+
if (statements.length === 0)
|
|
108
|
+
return code;
|
|
109
|
+
const gaps = [];
|
|
110
|
+
let cursor = 0;
|
|
111
|
+
for (const statement of statements) {
|
|
112
|
+
gaps.push(code.slice(cursor, statement.start));
|
|
113
|
+
cursor = statement.end;
|
|
114
|
+
}
|
|
115
|
+
gaps.push(code.slice(cursor));
|
|
116
|
+
const used = referencedNames(gaps.join(`
|
|
117
|
+
`));
|
|
118
|
+
const unused = statements.filter((statement) => statement.names.every((name) => !used.has(name)));
|
|
119
|
+
if (unused.length === 0)
|
|
120
|
+
return code;
|
|
121
|
+
return spliceSource(code, unused.map(({ start, end }) => ({ start, end, value: "" })));
|
|
122
|
+
}
|
|
123
|
+
var IDENTIFIER_RE = /[A-Za-z_$][\w$]*/g;
|
|
124
|
+
function referencedNames(body) {
|
|
125
|
+
const names = new Set;
|
|
126
|
+
IDENTIFIER_RE.lastIndex = 0;
|
|
127
|
+
let match;
|
|
128
|
+
while (match = IDENTIFIER_RE.exec(body)) {
|
|
129
|
+
if (body[match.index - 1] === "." && body[match.index - 2] !== ".")
|
|
130
|
+
continue;
|
|
131
|
+
names.add(match[0]);
|
|
132
|
+
}
|
|
133
|
+
return names;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// src/resolve/scan-facts.ts
|
|
137
|
+
var parseSync = (...args) => loadNative(() => __require("oxc-parser")).parseSync(...args);
|
|
138
|
+
var { Bun: bun } = globalThis;
|
|
139
|
+
var stylesheetOrData = /\.(?:css|scss|sass|less|styl|json)$/;
|
|
140
|
+
var emptyFacts = {
|
|
141
|
+
imports: [],
|
|
142
|
+
dynamicImports: [],
|
|
143
|
+
requires: [],
|
|
144
|
+
exportNames: [],
|
|
145
|
+
exportStars: [],
|
|
146
|
+
useClient: false,
|
|
147
|
+
useServer: false,
|
|
148
|
+
dynamicCalls: []
|
|
149
|
+
};
|
|
150
|
+
var emptyRewriteFacts = {
|
|
151
|
+
edges: [],
|
|
152
|
+
imports: [],
|
|
153
|
+
importMetas: [],
|
|
154
|
+
unreliable: false
|
|
155
|
+
};
|
|
156
|
+
var memo = new Map;
|
|
157
|
+
var hits = 0;
|
|
158
|
+
var misses = 0;
|
|
159
|
+
function scanFacts(file, source) {
|
|
160
|
+
if (stylesheetOrData.test(file))
|
|
161
|
+
return emptyFacts;
|
|
162
|
+
return parsed(file, source).scan;
|
|
163
|
+
}
|
|
164
|
+
function importSpecifiers(source, sourcefile = "source") {
|
|
165
|
+
const facts = scanFacts(sourcefile, source);
|
|
166
|
+
return [
|
|
167
|
+
...facts.imports.map((edge) => edge.specifier),
|
|
168
|
+
...facts.dynamicImports.map((entry) => entry.specifier),
|
|
169
|
+
...facts.requires.map((entry) => entry.specifier)
|
|
170
|
+
];
|
|
171
|
+
}
|
|
172
|
+
function moduleExportNames(source, sourcefile = "source.tsx") {
|
|
173
|
+
return scanFacts(sourcefile, source).exportNames;
|
|
174
|
+
}
|
|
175
|
+
function moduleExportStars(source, sourcefile = "source.tsx") {
|
|
176
|
+
return scanFacts(sourcefile, source).exportStars;
|
|
177
|
+
}
|
|
178
|
+
function dynamicCallFacts(source, file = "module.tsx") {
|
|
179
|
+
if (stylesheetOrData.test(file))
|
|
180
|
+
return [];
|
|
181
|
+
return parsed(file, source).scan.dynamicCalls;
|
|
182
|
+
}
|
|
183
|
+
function rewriteFacts(file, source) {
|
|
184
|
+
if (stylesheetOrData.test(file))
|
|
185
|
+
return emptyRewriteFacts;
|
|
186
|
+
return parsed(file, source).rewrite;
|
|
187
|
+
}
|
|
188
|
+
function moduleSpecifierEdges(source, file = "source") {
|
|
189
|
+
const facts = rewriteFacts(file, source);
|
|
190
|
+
return facts.unreliable ? textualEdges(source) : facts.edges;
|
|
191
|
+
}
|
|
192
|
+
function parsed(file, source, lang = langForFile2(file)) {
|
|
193
|
+
const key = `${lang}\x00${source.length}\x00${bun.hash(source).toString()}`;
|
|
194
|
+
const cached = memo.get(key);
|
|
195
|
+
if (cached) {
|
|
196
|
+
hits += 1;
|
|
197
|
+
return cached;
|
|
198
|
+
}
|
|
199
|
+
misses += 1;
|
|
200
|
+
const facts = parseFacts(file, source, lang);
|
|
201
|
+
memo.set(key, facts);
|
|
202
|
+
return facts;
|
|
203
|
+
}
|
|
204
|
+
function rewriteSpecifierLiterals(source, file, replace) {
|
|
205
|
+
const edges = moduleSpecifierEdges(source, file);
|
|
206
|
+
const edits = [];
|
|
207
|
+
for (const edge of edges) {
|
|
208
|
+
const value = replace(edge.specifier, edge.kind);
|
|
209
|
+
if (value !== undefined)
|
|
210
|
+
edits.push({ start: edge.start, end: edge.end, value });
|
|
211
|
+
}
|
|
212
|
+
return edits.length > 0 ? spliceSource(source, edits) : source;
|
|
213
|
+
}
|
|
214
|
+
var textualSpecifier = /(\bfrom\s*|\b(?:import|require)\s*\(\s*)(['"])([^'"]+)\2/g;
|
|
215
|
+
function textualEdges(source) {
|
|
216
|
+
const edges = [];
|
|
217
|
+
textualSpecifier.lastIndex = 0;
|
|
218
|
+
let match;
|
|
219
|
+
while (match = textualSpecifier.exec(source)) {
|
|
220
|
+
const start = match.index + match[1].length;
|
|
221
|
+
edges.push({
|
|
222
|
+
specifier: match[3],
|
|
223
|
+
start,
|
|
224
|
+
end: start + match[3].length + 2,
|
|
225
|
+
kind: match[1].includes("require") ? "require" : match[1].includes("import") ? "dynamic" : "import"
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
return edges;
|
|
229
|
+
}
|
|
230
|
+
function scanFactsStats() {
|
|
231
|
+
return { hits, misses, sources: memo.size };
|
|
232
|
+
}
|
|
233
|
+
function parseFacts(file, source, lang) {
|
|
234
|
+
const result = parseSync(file, source, { lang });
|
|
235
|
+
const imports = [];
|
|
236
|
+
const exportNames = [];
|
|
237
|
+
const exportStars = [];
|
|
238
|
+
const edges = [];
|
|
239
|
+
const importStatements = [];
|
|
240
|
+
for (const statement of result.module.staticImports) {
|
|
241
|
+
const names = [];
|
|
242
|
+
const bindings = [];
|
|
243
|
+
let bindsValue = statement.entries.length === 0;
|
|
244
|
+
for (const entry of statement.entries) {
|
|
245
|
+
const kind = entry.importName.kind;
|
|
246
|
+
bindings.push({
|
|
247
|
+
imported: kind === "Default" ? "default" : kind === "NamespaceObject" ? "*" : entry.importName.name ?? "",
|
|
248
|
+
local: entry.localName.value ?? "",
|
|
249
|
+
type: entry.isType
|
|
250
|
+
});
|
|
251
|
+
if (entry.isType)
|
|
252
|
+
continue;
|
|
253
|
+
bindsValue = true;
|
|
254
|
+
if (kind === "Default")
|
|
255
|
+
names.push("default");
|
|
256
|
+
else if (kind === "NamespaceObject")
|
|
257
|
+
names.push("*");
|
|
258
|
+
else if (entry.importName.name)
|
|
259
|
+
names.push(entry.importName.name);
|
|
260
|
+
}
|
|
261
|
+
importStatements.push({
|
|
262
|
+
specifier: statement.moduleRequest.value,
|
|
263
|
+
start: statement.start,
|
|
264
|
+
end: statement.end,
|
|
265
|
+
specifierStart: statement.moduleRequest.start,
|
|
266
|
+
specifierEnd: statement.moduleRequest.end,
|
|
267
|
+
bindings
|
|
268
|
+
});
|
|
269
|
+
edges.push({
|
|
270
|
+
specifier: statement.moduleRequest.value,
|
|
271
|
+
start: statement.moduleRequest.start,
|
|
272
|
+
end: statement.moduleRequest.end,
|
|
273
|
+
kind: statement.entries.length === 0 ? "side-effect" : "import"
|
|
274
|
+
});
|
|
275
|
+
if (!bindsValue)
|
|
276
|
+
continue;
|
|
277
|
+
imports.push({
|
|
278
|
+
specifier: statement.moduleRequest.value,
|
|
279
|
+
exports: names,
|
|
280
|
+
index: statement.start
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
const seenExportRequests = new Set;
|
|
284
|
+
for (const statement of result.module.staticExports) {
|
|
285
|
+
for (const entry of statement.entries) {
|
|
286
|
+
const request = entry.moduleRequest;
|
|
287
|
+
if (!request || seenExportRequests.has(request.start))
|
|
288
|
+
continue;
|
|
289
|
+
seenExportRequests.add(request.start);
|
|
290
|
+
edges.push({
|
|
291
|
+
specifier: request.value,
|
|
292
|
+
start: request.start,
|
|
293
|
+
end: request.end,
|
|
294
|
+
kind: "export"
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
for (const statement of result.module.staticExports) {
|
|
299
|
+
const edges2 = new Map;
|
|
300
|
+
for (const entry of statement.entries) {
|
|
301
|
+
if (entry.isType)
|
|
302
|
+
continue;
|
|
303
|
+
const exportKind = entry.exportName.kind;
|
|
304
|
+
if (exportKind === "Default")
|
|
305
|
+
exportNames.push("default");
|
|
306
|
+
else if (entry.exportName.name)
|
|
307
|
+
exportNames.push(entry.exportName.name);
|
|
308
|
+
const specifier = entry.moduleRequest?.value;
|
|
309
|
+
if (!specifier)
|
|
310
|
+
continue;
|
|
311
|
+
const importKind = entry.importName.kind;
|
|
312
|
+
const star = importKind === "AllButDefault";
|
|
313
|
+
if (star)
|
|
314
|
+
exportStars.push(specifier);
|
|
315
|
+
let edge = edges2.get(specifier);
|
|
316
|
+
if (!edge) {
|
|
317
|
+
edge = {
|
|
318
|
+
specifier,
|
|
319
|
+
exports: [],
|
|
320
|
+
index: statement.start,
|
|
321
|
+
reexport: true,
|
|
322
|
+
exportMap: {}
|
|
323
|
+
};
|
|
324
|
+
edges2.set(specifier, edge);
|
|
325
|
+
imports.push(edge);
|
|
326
|
+
}
|
|
327
|
+
if (star)
|
|
328
|
+
edge.star = true;
|
|
329
|
+
else if (importKind === "All")
|
|
330
|
+
edge.exports.push("*");
|
|
331
|
+
else {
|
|
332
|
+
const imported = importKind === "Default" ? "default" : entry.importName.name;
|
|
333
|
+
if (!imported)
|
|
334
|
+
continue;
|
|
335
|
+
edge.exports.push(imported);
|
|
336
|
+
const exported = exportKind === "Default" ? "default" : entry.exportName.name;
|
|
337
|
+
if (exported)
|
|
338
|
+
edge.exportMap[exported] = imported;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
imports.sort((a, b) => a.index - b.index);
|
|
343
|
+
const dynamicImports = [];
|
|
344
|
+
for (const entry of result.module.dynamicImports) {
|
|
345
|
+
const raw = source.slice(entry.moduleRequest.start, entry.moduleRequest.end);
|
|
346
|
+
const specifier = literalSpecifier(raw);
|
|
347
|
+
if (specifier === undefined)
|
|
348
|
+
continue;
|
|
349
|
+
dynamicImports.push({ specifier, index: entry.start });
|
|
350
|
+
const lead = raw.length - raw.trimStart().length;
|
|
351
|
+
edges.push({
|
|
352
|
+
specifier,
|
|
353
|
+
start: entry.moduleRequest.start + lead,
|
|
354
|
+
end: entry.moduleRequest.start + lead + specifier.length + 2,
|
|
355
|
+
kind: "dynamic"
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
const requires = requireCalls(source, result.comments);
|
|
359
|
+
for (const call of requires) {
|
|
360
|
+
edges.push({
|
|
361
|
+
specifier: call.specifier,
|
|
362
|
+
start: call.specifierStart,
|
|
363
|
+
end: call.specifierStart + call.specifier.length + 2,
|
|
364
|
+
kind: "require"
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
edges.sort((a, b) => a.start - b.start);
|
|
368
|
+
return {
|
|
369
|
+
scan: {
|
|
370
|
+
imports,
|
|
371
|
+
dynamicImports,
|
|
372
|
+
requires,
|
|
373
|
+
exportNames,
|
|
374
|
+
exportStars,
|
|
375
|
+
useClient: moduleDirective(source, result, "use client"),
|
|
376
|
+
useServer: moduleDirective(source, result, "use server"),
|
|
377
|
+
dynamicCalls: source.includes("@wular/pnext") || source.includes("next/dynamic") ? collectDynamicCalls(result.program) : []
|
|
378
|
+
},
|
|
379
|
+
rewrite: {
|
|
380
|
+
edges,
|
|
381
|
+
imports: importStatements,
|
|
382
|
+
importMetas: result.module.importMetas.map((meta) => ({ start: meta.start, end: meta.end })),
|
|
383
|
+
unreliable: result.errors.length > 0
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
function moduleDirective(source, result, directive) {
|
|
388
|
+
const sniffed = sniffDirective(source, directive);
|
|
389
|
+
if (sniffed !== undefined)
|
|
390
|
+
return sniffed;
|
|
391
|
+
if (!source.includes(directive))
|
|
392
|
+
return false;
|
|
393
|
+
return hasDirective(result.program.body, directive);
|
|
394
|
+
}
|
|
395
|
+
var continuesExpression = /[+\-*/%.,?:=<>!&|^~([`)\]}]/;
|
|
396
|
+
var wordContinuation = /^(?:in|instanceof)\b/;
|
|
397
|
+
var lineTerminator = /[\n\r\u2028\u2029]/;
|
|
398
|
+
function sniffDirective(source, directive) {
|
|
399
|
+
let index = 0;
|
|
400
|
+
if (source.startsWith("#!")) {
|
|
401
|
+
const nl = source.search(lineTerminator);
|
|
402
|
+
if (nl < 0)
|
|
403
|
+
return false;
|
|
404
|
+
index = nl + 1;
|
|
405
|
+
}
|
|
406
|
+
for (;; ) {
|
|
407
|
+
index = skipTrivia(source, index);
|
|
408
|
+
if (index < 0)
|
|
409
|
+
return;
|
|
410
|
+
const quote = source[index];
|
|
411
|
+
if (quote !== '"' && quote !== "'")
|
|
412
|
+
return false;
|
|
413
|
+
let end = index + 1;
|
|
414
|
+
while (end < source.length) {
|
|
415
|
+
const char = source[end];
|
|
416
|
+
if (char === "\\" || lineTerminator.test(char))
|
|
417
|
+
return;
|
|
418
|
+
if (char === quote)
|
|
419
|
+
break;
|
|
420
|
+
end += 1;
|
|
421
|
+
}
|
|
422
|
+
if (end >= source.length)
|
|
423
|
+
return;
|
|
424
|
+
const raw = source.slice(index + 1, end);
|
|
425
|
+
const after = skipTrivia(source, end + 1);
|
|
426
|
+
if (after < 0)
|
|
427
|
+
return;
|
|
428
|
+
const next = source[after];
|
|
429
|
+
let terminated = after >= source.length || next === ";";
|
|
430
|
+
if (!terminated && lineTerminator.test(source.slice(end + 1, after))) {
|
|
431
|
+
terminated = !continuesExpression.test(next) && !wordContinuation.test(source.slice(after, after + 11));
|
|
432
|
+
}
|
|
433
|
+
if (!terminated)
|
|
434
|
+
return;
|
|
435
|
+
if (raw === directive)
|
|
436
|
+
return true;
|
|
437
|
+
index = next === ";" ? after + 1 : after;
|
|
438
|
+
if (index >= source.length)
|
|
439
|
+
return false;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
function skipTrivia(source, index) {
|
|
443
|
+
for (;; ) {
|
|
444
|
+
while (index < source.length && /\s/.test(source[index]))
|
|
445
|
+
index += 1;
|
|
446
|
+
if (source[index] !== "/")
|
|
447
|
+
return index;
|
|
448
|
+
if (source[index + 1] === "/") {
|
|
449
|
+
let end = index + 2;
|
|
450
|
+
while (end < source.length && !lineTerminator.test(source[end]))
|
|
451
|
+
end += 1;
|
|
452
|
+
index = end;
|
|
453
|
+
continue;
|
|
454
|
+
}
|
|
455
|
+
if (source[index + 1] === "*") {
|
|
456
|
+
const end = source.indexOf("*/", index + 2);
|
|
457
|
+
if (end < 0)
|
|
458
|
+
return -1;
|
|
459
|
+
index = end + 2;
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
462
|
+
return index;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
function hasDirective(body, directive) {
|
|
466
|
+
for (const statement of body) {
|
|
467
|
+
if (statement.type !== "ExpressionStatement" || typeof statement.directive !== "string")
|
|
468
|
+
return false;
|
|
469
|
+
if (statement.directive === directive)
|
|
470
|
+
return true;
|
|
471
|
+
}
|
|
472
|
+
return false;
|
|
473
|
+
}
|
|
474
|
+
var requirePattern = /\brequire\s*\(\s*(['"])([^'"]+)\1\s*\)/g;
|
|
475
|
+
function requireCalls(source, comments) {
|
|
476
|
+
const calls = [];
|
|
477
|
+
if (!source.includes("require"))
|
|
478
|
+
return calls;
|
|
479
|
+
requirePattern.lastIndex = 0;
|
|
480
|
+
let match;
|
|
481
|
+
let cursor = 0;
|
|
482
|
+
while (match = requirePattern.exec(source)) {
|
|
483
|
+
const index = match.index;
|
|
484
|
+
while (cursor < comments.length && comments[cursor].end <= index)
|
|
485
|
+
cursor += 1;
|
|
486
|
+
if (cursor < comments.length && index >= comments[cursor].start)
|
|
487
|
+
continue;
|
|
488
|
+
calls.push({
|
|
489
|
+
specifier: match[2],
|
|
490
|
+
index,
|
|
491
|
+
specifierStart: index + match[0].indexOf(match[1])
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
return calls;
|
|
495
|
+
}
|
|
496
|
+
function literalSpecifier(raw) {
|
|
497
|
+
return /^\s*(['"])([^'"]*)\1\s*$/.exec(raw)?.[2] || undefined;
|
|
498
|
+
}
|
|
499
|
+
function isNode(value) {
|
|
500
|
+
return typeof value === "object" && value !== null && typeof value.type === "string";
|
|
501
|
+
}
|
|
502
|
+
function child(node, key) {
|
|
503
|
+
const value = node?.[key];
|
|
504
|
+
return isNode(value) ? value : undefined;
|
|
505
|
+
}
|
|
506
|
+
function stripJsonImportAttributes(source, file, compiled) {
|
|
507
|
+
const result = parseSync(file, source, { lang: "js", sourceType: "module" });
|
|
508
|
+
if (result.errors.length > 0)
|
|
509
|
+
return source;
|
|
510
|
+
const edits = [];
|
|
511
|
+
const visit = (node) => {
|
|
512
|
+
const target = child(node, "source");
|
|
513
|
+
const specifier = stringValue(target);
|
|
514
|
+
if (target && specifier !== undefined && compiled(specifier)) {
|
|
515
|
+
const attributes = node.attributes;
|
|
516
|
+
const options = child(node, "options");
|
|
517
|
+
if (attributes?.length && attributes.every(jsonTypeAttribute)) {
|
|
518
|
+
const end = source.indexOf("}", attributes.at(-1).end) + 1;
|
|
519
|
+
edits.push({ start: target.end, end, value: "" });
|
|
520
|
+
} else if (node.type === "ImportExpression" && options && jsonImportOptions(options)) {
|
|
521
|
+
edits.push({ start: target.end, end: options.end, value: "" });
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
for (const value of Object.values(node)) {
|
|
525
|
+
if (isNode(value))
|
|
526
|
+
visit(value);
|
|
527
|
+
else if (Array.isArray(value)) {
|
|
528
|
+
for (const item of value)
|
|
529
|
+
if (isNode(item))
|
|
530
|
+
visit(item);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
visit(result.program);
|
|
535
|
+
return edits.length > 0 ? spliceSource(source, edits) : source;
|
|
536
|
+
}
|
|
537
|
+
function propertyName(node) {
|
|
538
|
+
if (!node)
|
|
539
|
+
return;
|
|
540
|
+
return node.type === "Identifier" ? node.name : stringValue(node);
|
|
541
|
+
}
|
|
542
|
+
function jsonTypeAttribute(node) {
|
|
543
|
+
return !node.computed && propertyName(child(node, "key")) === "type" && stringValue(child(node, "value")) === "json";
|
|
544
|
+
}
|
|
545
|
+
function jsonImportOptions(options) {
|
|
546
|
+
const [property, ...rest] = options.properties ?? [];
|
|
547
|
+
const attributes = child(property, "value");
|
|
548
|
+
const entries = attributes?.properties;
|
|
549
|
+
return options.type === "ObjectExpression" && !!property && rest.length === 0 && property.type === "Property" && !property.computed && ["with", "assert"].includes(propertyName(child(property, "key")) ?? "") && attributes?.type === "ObjectExpression" && !!entries?.length && entries.every((entry) => entry.type === "Property" && jsonTypeAttribute(entry));
|
|
550
|
+
}
|
|
551
|
+
function collectDynamicCalls(program) {
|
|
552
|
+
const calls = [];
|
|
553
|
+
const visit = (value) => {
|
|
554
|
+
if (Array.isArray(value)) {
|
|
555
|
+
for (const item of value)
|
|
556
|
+
visit(item);
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
if (!isNode(value))
|
|
560
|
+
return;
|
|
561
|
+
if (value.type === "CallExpression") {
|
|
562
|
+
const fact = dynamicCallFact(value);
|
|
563
|
+
if (fact)
|
|
564
|
+
calls.push(fact);
|
|
565
|
+
}
|
|
566
|
+
for (const key in value) {
|
|
567
|
+
if (key === "type" || key === "loc" || key === "range")
|
|
568
|
+
continue;
|
|
569
|
+
const entry = value[key];
|
|
570
|
+
if (entry && typeof entry === "object")
|
|
571
|
+
visit(entry);
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
visit(program.body);
|
|
575
|
+
return calls.sort((a, b) => a.start - b.start);
|
|
576
|
+
}
|
|
577
|
+
function dynamicCallFact(call) {
|
|
578
|
+
const callee = child(call, "callee");
|
|
579
|
+
if (callee?.type !== "Identifier")
|
|
580
|
+
return;
|
|
581
|
+
const args = call.arguments;
|
|
582
|
+
if (!Array.isArray(args) || !isNode(args[0]))
|
|
583
|
+
return;
|
|
584
|
+
const loader = args[0];
|
|
585
|
+
let target;
|
|
586
|
+
let literal;
|
|
587
|
+
if (stringValue(loader) !== undefined) {
|
|
588
|
+
target = { specifier: loader, exportName: "default" };
|
|
589
|
+
literal = true;
|
|
590
|
+
} else if (loader.type === "ArrowFunctionExpression" || loader.type === "FunctionExpression") {
|
|
591
|
+
target = loaderImportTarget(loader) ?? firstImportTarget(loader);
|
|
592
|
+
}
|
|
593
|
+
if (!target)
|
|
594
|
+
return;
|
|
595
|
+
const specifier = stringValue(target.specifier);
|
|
596
|
+
if (specifier === undefined)
|
|
597
|
+
return;
|
|
598
|
+
const options = isNode(args[1]) ? args[1] : undefined;
|
|
599
|
+
return {
|
|
600
|
+
name: callee.name,
|
|
601
|
+
start: callee.start,
|
|
602
|
+
end: call.end,
|
|
603
|
+
specifier,
|
|
604
|
+
specifierStart: target.specifier.start,
|
|
605
|
+
specifierEnd: target.specifier.end,
|
|
606
|
+
exportName: target.exportName,
|
|
607
|
+
...literal ? { literal } : {},
|
|
608
|
+
loaderEnd: loader.end,
|
|
609
|
+
...options ? { optionsStart: options.start, optionsEnd: options.end } : {}
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
function stringValue(node) {
|
|
613
|
+
if (!node)
|
|
614
|
+
return;
|
|
615
|
+
if (node.type !== "Literal" && node.type !== "StringLiteral")
|
|
616
|
+
return;
|
|
617
|
+
return typeof node.value === "string" ? node.value : undefined;
|
|
618
|
+
}
|
|
619
|
+
function unwrapExpression(node) {
|
|
620
|
+
let current = node;
|
|
621
|
+
for (;; ) {
|
|
622
|
+
if (!current)
|
|
623
|
+
return;
|
|
624
|
+
if (current.type === "ParenthesizedExpression" || current.type === "ChainExpression") {
|
|
625
|
+
current = child(current, "expression");
|
|
626
|
+
} else if (current.type === "AwaitExpression") {
|
|
627
|
+
current = child(current, "argument");
|
|
628
|
+
} else if (current.type === "TSAsExpression" || current.type === "TSNonNullExpression" || current.type === "TSSatisfiesExpression") {
|
|
629
|
+
current = child(current, "expression");
|
|
630
|
+
} else {
|
|
631
|
+
return current;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
function loaderResult(fn) {
|
|
636
|
+
const body = child(fn, "body");
|
|
637
|
+
if (!body)
|
|
638
|
+
return;
|
|
639
|
+
if (body.type !== "BlockStatement" && body.type !== "FunctionBody")
|
|
640
|
+
return unwrapExpression(body);
|
|
641
|
+
const statements = body.body;
|
|
642
|
+
if (!Array.isArray(statements))
|
|
643
|
+
return;
|
|
644
|
+
for (const statement of statements) {
|
|
645
|
+
if (isNode(statement) && statement.type === "ReturnStatement") {
|
|
646
|
+
return unwrapExpression(child(statement, "argument"));
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
function importSource(node) {
|
|
652
|
+
if (node?.type !== "ImportExpression")
|
|
653
|
+
return;
|
|
654
|
+
const source = child(node, "source");
|
|
655
|
+
return source && stringValue(source) !== undefined ? source : undefined;
|
|
656
|
+
}
|
|
657
|
+
function loaderImportTarget(fn) {
|
|
658
|
+
const result = loaderResult(fn);
|
|
659
|
+
if (!result)
|
|
660
|
+
return;
|
|
661
|
+
const direct = importSource(result);
|
|
662
|
+
if (direct)
|
|
663
|
+
return { specifier: direct, exportName: "default" };
|
|
664
|
+
if (result.type === "MemberExpression" && result.computed !== true) {
|
|
665
|
+
const source2 = importSource(unwrapExpression(child(result, "object")));
|
|
666
|
+
const property = child(result, "property");
|
|
667
|
+
if (source2 && property?.type === "Identifier") {
|
|
668
|
+
return { specifier: source2, exportName: property.name };
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
if (result.type !== "CallExpression")
|
|
672
|
+
return;
|
|
673
|
+
const callee = child(result, "callee");
|
|
674
|
+
if (callee?.type !== "MemberExpression" || callee.computed === true)
|
|
675
|
+
return;
|
|
676
|
+
if (child(callee, "property")?.name !== "then")
|
|
677
|
+
return;
|
|
678
|
+
const source = importSource(unwrapExpression(child(callee, "object")));
|
|
679
|
+
if (!source)
|
|
680
|
+
return;
|
|
681
|
+
return { specifier: source, exportName: thenArmExport(result) ?? "default" };
|
|
682
|
+
}
|
|
683
|
+
function thenArmExport(thenCall) {
|
|
684
|
+
const args = thenCall.arguments;
|
|
685
|
+
if (!Array.isArray(args) || !isNode(args[0]))
|
|
686
|
+
return;
|
|
687
|
+
const arm = args[0];
|
|
688
|
+
if (arm.type !== "ArrowFunctionExpression" && arm.type !== "FunctionExpression")
|
|
689
|
+
return;
|
|
690
|
+
const params = arm.params;
|
|
691
|
+
const param = Array.isArray(params) && isNode(params[0]) ? params[0] : undefined;
|
|
692
|
+
if (param?.type !== "Identifier")
|
|
693
|
+
return;
|
|
694
|
+
const result = loaderResult(arm);
|
|
695
|
+
if (result?.type !== "MemberExpression" || result.computed === true)
|
|
696
|
+
return;
|
|
697
|
+
const object = unwrapExpression(child(result, "object"));
|
|
698
|
+
if (object?.type !== "Identifier" || object.name !== param.name)
|
|
699
|
+
return;
|
|
700
|
+
const property = child(result, "property");
|
|
701
|
+
return property?.type === "Identifier" ? property.name : undefined;
|
|
702
|
+
}
|
|
703
|
+
function firstImportTarget(fn) {
|
|
704
|
+
let found;
|
|
705
|
+
const visit = (value) => {
|
|
706
|
+
if (found)
|
|
707
|
+
return;
|
|
708
|
+
if (Array.isArray(value)) {
|
|
709
|
+
for (const item of value)
|
|
710
|
+
visit(item);
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
if (!isNode(value))
|
|
714
|
+
return;
|
|
715
|
+
const source = importSource(value);
|
|
716
|
+
if (source) {
|
|
717
|
+
found = source;
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
for (const key in value) {
|
|
721
|
+
const entry = value[key];
|
|
722
|
+
if (entry && typeof entry === "object")
|
|
723
|
+
visit(entry);
|
|
724
|
+
}
|
|
725
|
+
};
|
|
726
|
+
visit(fn.body);
|
|
727
|
+
return found ? { specifier: found, exportName: "default" } : undefined;
|
|
728
|
+
}
|
|
729
|
+
function langForFile2(file) {
|
|
730
|
+
return /\.[mc]?ts$/.test(file) ? "ts" : "tsx";
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
export { transformBailReason, transformServerModule, outputSpecifiers, spliceSource, scanFacts, importSpecifiers, moduleExportNames, moduleExportStars, dynamicCallFacts, rewriteFacts, moduleSpecifierEdges, rewriteSpecifierLiterals, scanFactsStats, stripJsonImportAttributes };
|