typenative 0.4.1 → 0.6.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/.github/workflows/ci.yml +2 -2
- package/.github/workflows/npm-publish-github-packages.yml +2 -2
- package/CHANGELOG.md +442 -1
- package/CONTRIBUTION.md +2 -1
- package/README.md +73 -25
- package/bin/cli.js +2 -0
- package/bin/index.js +75 -5
- package/bin/main.js +2 -0
- package/bin/node/assert.js +2 -2
- package/bin/node/async_hooks.js +1 -1
- package/bin/node/buffer.js +16 -5
- package/bin/node/child_process.js +7 -7
- package/bin/node/cluster.js +3 -3
- package/bin/node/core.js +41 -0
- package/bin/node/crypto_keys.js +21 -21
- package/bin/node/dgram.js +1 -1
- package/bin/node/diagnostics_channel.js +3 -3
- package/bin/node/dns.js +2 -2
- package/bin/node/events.js +18 -13
- package/bin/node/fetch.js +2 -2
- package/bin/node/fs.js +3 -3
- package/bin/node/fs_watch.js +5 -5
- package/bin/node/http.js +3 -3
- package/bin/node/http2.js +3 -3
- package/bin/node/net.js +8 -8
- package/bin/node/path.js +17 -3
- package/bin/node/process.js +47 -11
- package/bin/node/punycode.js +2 -2
- package/bin/node/readline.js +1 -1
- package/bin/node/registry.js +4 -1
- package/bin/node/sqlite.js +6 -6
- package/bin/node/stream.js +81 -15
- package/bin/node/stream_web.js +10 -10
- package/bin/node/system_extra.js +3 -3
- package/bin/node/test.js +674 -366
- package/bin/node/test_coverage.js +187 -0
- package/bin/node/test_report.js +1392 -0
- package/bin/node/test_run.js +575 -0
- package/bin/node/timers.js +8 -6
- package/bin/node/tls.js +5 -5
- package/bin/node/url.js +1 -1
- package/bin/node/util.js +31 -7
- package/bin/node/util_extra.js +7 -7
- package/bin/node/webview.js +654 -0
- package/bin/node/worker_threads.js +1 -1
- package/bin/node/zlib.js +3 -3
- package/bin/parse-node.js +6 -2
- package/bin/regex_vm.js +2057 -0
- package/bin/transpiler.js +32872 -11265
- package/bin/typecheck-node.js +2 -1
- package/bin/version.js +1 -1
- package/conformance.md +515 -345
- package/examples/README.md +71 -11
- package/examples/angular-templates/README.md +139 -0
- package/examples/angular-templates/bench.mjs +173 -0
- package/examples/angular-templates/dom-type-globals.d.ts +21 -0
- package/examples/angular-templates/dom-type-stubs.ts +21 -0
- package/examples/angular-templates/main.ts +135 -0
- package/examples/angular-templates/parity.mjs +157 -0
- package/examples/angular-templates/run-node.mjs +69 -0
- package/examples/angular-templates/vendor/angular/compiler/LICENSE +21 -0
- package/examples/desktop-notes/README.md +106 -0
- package/examples/desktop-notes/bench.mjs +125 -0
- package/examples/desktop-notes/main.ts +131 -0
- package/examples/desktop-notes/package-lock.json +726 -0
- package/examples/desktop-notes/package.json +9 -0
- package/examples/desktop-notes/ui.ts +176 -0
- package/examples/dupe-finder/README.md +78 -0
- package/examples/dupe-finder/bench.mjs +120 -0
- package/examples/dupe-finder/main.ts +87 -0
- package/examples/fibonacci/README.md +7 -7
- package/examples/hello-world/README.md +6 -6
- package/examples/json-server/README.md +19 -18
- package/examples/mandelbrot-png/README.md +63 -0
- package/examples/mandelbrot-png/bench.mjs +95 -0
- package/examples/mandelbrot-png/main.ts +98 -0
- package/examples/mandelbrot-png/preview.png +0 -0
- package/examples/marked-cli/README.md +160 -0
- package/examples/marked-cli/bench.mjs +178 -0
- package/examples/marked-cli/main.ts +292 -0
- package/examples/marked-cli/parity.mjs +185 -0
- package/examples/marked-cli/vendor/marked/LICENSE +44 -0
- package/examples/marked-cli/vendor/marked/VENDOR.md +26 -0
- package/examples/openai-chat/README.md +148 -0
- package/examples/openai-chat/bench.mjs +175 -0
- package/examples/openai-chat/main.ts +488 -0
- package/examples/react-compiler/README.md +170 -0
- package/examples/react-compiler/bench.mjs +181 -0
- package/examples/react-compiler/main.ts +158 -0
- package/examples/react-compiler/parity.mjs +362 -0
- package/examples/react-compiler/run-node.mjs +88 -0
- package/examples/react-compiler/vendor/babel/LICENSE +22 -0
- package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-lower.json +15 -0
- package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-upper.json +51 -0
- package/examples/react-compiler/vendor/charcodes/package.json +25 -0
- package/examples/react-compiler/vendor/invariant/LICENSE +21 -0
- package/examples/react-compiler/vendor/invariant/invariant.cjs +51 -0
- package/examples/react-compiler/vendor/invariant/invariant.d.cts +11 -0
- package/examples/react-compiler/vendor/invariant/types/LICENSE +21 -0
- package/examples/react-compiler/vendor/jridgewell/gen-mapping/LICENSE +19 -0
- package/examples/react-compiler/vendor/jridgewell/resolve-uri/LICENSE +19 -0
- package/examples/react-compiler/vendor/jridgewell/sourcemap-codec/LICENSE +19 -0
- package/examples/react-compiler/vendor/jridgewell/trace-mapping/LICENSE +19 -0
- package/examples/react-compiler/vendor/js-tokens/LICENSE +21 -0
- package/examples/react-compiler/vendor/js-tokens/index.cjs +23 -0
- package/examples/react-compiler/vendor/js-tokens/index.d.cts +13 -0
- package/examples/react-compiler/vendor/jsesc/LICENSE-MIT.txt +20 -0
- package/examples/react-compiler/vendor/jsesc/jsesc.cjs +337 -0
- package/examples/react-compiler/vendor/jsesc/jsesc.d.cts +384 -0
- package/examples/react-compiler/vendor/jsesc/types/LICENSE +21 -0
- package/examples/react-compiler/vendor/picocolors/LICENSE +15 -0
- package/examples/react-compiler/vendor/picocolors/picocolors.cjs +75 -0
- package/examples/react-compiler/vendor/picocolors/picocolors.d.cts +5 -0
- package/examples/react-compiler/vendor/picocolors/types.d.ts +51 -0
- package/examples/react-compiler/vendor/react-compiler/LICENSE +21 -0
- package/examples/react-compiler/vendor/stubs/babel-core.ts +31 -0
- package/examples/react-compiler/vendor/stubs/debug.ts +18 -0
- package/examples/react-compiler/vendor/stubs/js-tokens.d.ts +13 -0
- package/examples/react-compiler/vendor/stubs/pretty-format.ts +18 -0
- package/examples/react-compiler/vendor/zod/LICENSE +21 -0
- package/examples/react-compiler/vendor/zod-validation-error/LICENSE +9 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/NonEmptyArray.ts +5 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinPath.ts +49 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinValues.ts +48 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/stringify.ts +50 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/titleCase.ts +6 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/MessageBuilder.ts +126 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/ValidationError.ts +39 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/custom.ts +12 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/errorMap.ts +78 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/index.ts +2 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidElement.ts +12 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidKey.ts +12 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidStringFormat.ts +131 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidType.ts +54 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidUnion.ts +12 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidValue.ts +40 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/notMultipleOf.ts +12 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooBig.ts +76 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooSmall.ts +76 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/types.ts +27 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/unrecognizedKeys.ts +27 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromError.ts +13 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodError.ts +61 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodIssue.ts +38 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/index.ts +20 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationError.ts +5 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationErrorLike.ts +8 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isZodErrorLike.ts +11 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/toValidationError.ts +20 -0
- package/examples/react-compiler/vendor.mjs +688 -0
- package/examples/todo-cli/README.md +69 -0
- package/examples/todo-cli/bench.mjs +89 -0
- package/examples/todo-cli/main.ts +92 -0
- package/examples/yaml-cli/README.md +146 -0
- package/examples/yaml-cli/bench.mjs +265 -0
- package/examples/yaml-cli/main.ts +29 -0
- package/examples/yaml-cli/parity.mjs +156 -0
- package/examples/yaml-cli/vendor/yaml/LICENSE +13 -0
- package/examples/yaml-cli/vendor/yaml/VENDOR.md +25 -0
- package/govendor/github.com/jchv/go-webview2/LICENSE +22 -0
- package/govendor/github.com/jchv/go-webview2/README.md +21 -0
- package/govendor/github.com/jchv/go-webview2/common.go +84 -0
- package/govendor/github.com/jchv/go-webview2/go.mod +3 -0
- package/govendor/github.com/jchv/go-webview2/internal/w32/w32.go +194 -0
- package/govendor/github.com/jchv/go-webview2/internal/w32/w32_386.go +14 -0
- package/govendor/github.com/jchv/go-webview2/internal/w32/w32_64bit.go +15 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_COLOR.go +8 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND.go +9 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_KEY_EVENT_KIND.go +10 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_MOVE_FOCUS_REASON.go +9 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_PHYSICAL_KEY_STATUS.go +10 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_WEB_RESOURCE_CONTEXT.go +23 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2AcceleratorKeyPressedEventArgs.go +78 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2AcceleratorKeyPressedEventHandler.go +52 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Controller.go +132 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Controller2.go +74 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2CreateCoreWebView2ControllerCompletedHandler.go +48 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2NavigationCompletedEventArgs.go +17 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2NavigationCompletedEventHandler.go +48 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Settings.go +270 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequest.go +43 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequestedEventArgs.go +51 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequestedEventHandler.go +48 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceResponse.go +21 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2_2.go +21 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2_3.go +60 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebViewSettings.go +396 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium.go +361 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_386.go +24 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_amd64.go +22 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_arm64.go +26 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc.go +13 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc_go17.go +51 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc_go18.go +16 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/corewebview2.go +411 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/guid.go +223 -0
- package/govendor/github.com/jchv/go-webview2/webview.go +482 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/README.md +3 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/module.go +153 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/module_386.go +6 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/module_amd64.go +6 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/module_arm64.go +6 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/arm64/WebView2Loader.dll +0 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/x64/WebView2Loader.dll +0 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/x86/WebView2Loader.dll +0 -0
- package/govendor/github.com/jchv/go-winloader/LICENSE.md +7 -0
- package/govendor/github.com/jchv/go-winloader/README.md +124 -0
- package/govendor/github.com/jchv/go-winloader/common.go +11 -0
- package/govendor/github.com/jchv/go-winloader/go.mod +3 -0
- package/govendor/github.com/jchv/go-winloader/internal/loader/loader.go +25 -0
- package/govendor/github.com/jchv/go-winloader/internal/loader/machine.go +53 -0
- package/govendor/github.com/jchv/go-winloader/internal/memloader/cache.go +42 -0
- package/govendor/github.com/jchv/go-winloader/internal/memloader/loader.go +253 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/export.go +76 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/format.go +522 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/import.go +106 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/module.go +91 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/reloc.go +177 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/util.go +40 -0
- package/govendor/github.com/jchv/go-winloader/internal/vmem/common.go +55 -0
- package/govendor/github.com/jchv/go-winloader/internal/vmem/memory_other.go +71 -0
- package/govendor/github.com/jchv/go-winloader/internal/vmem/memory_windows.go +179 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/hacks_other.go +17 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/hacks_windows.go +73 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/loader_windows.go +64 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/machine_windows.go +32 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_386.go +9 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_amd64.go +9 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_arm64.go +9 -0
- package/govendor/github.com/jchv/go-winloader/loader_other.go +24 -0
- package/govendor/github.com/jchv/go-winloader/loader_windows.go +33 -0
- package/govendor/manifest.txt +3 -1
- package/package.json +8 -5
- package/performance/README.md +195 -0
- package/performance/any-dynamic.ts +21 -0
- package/performance/any-record-view.ts +20 -0
- package/performance/arr-hof.ts +21 -0
- package/performance/arr-push-index.ts +15 -0
- package/performance/arr-sort.ts +21 -0
- package/performance/async-await.ts +24 -0
- package/performance/class-dispatch.ts +52 -0
- package/performance/events-emit.ts +27 -0
- package/performance/exc-throw-rare.ts +25 -0
- package/performance/exc-try-catch.ts +26 -0
- package/performance/fn-closures.ts +29 -0
- package/performance/fn-recursion-tree.ts +31 -0
- package/performance/gen-for-of.ts +46 -0
- package/performance/json-roundtrip.ts +27 -0
- package/performance/map-delete.ts +24 -0
- package/performance/map-string-keys.ts +22 -0
- package/performance/num-arith-loop.ts +14 -0
- package/performance/num-bitwise.ts +21 -0
- package/performance/num-mod-int.ts +16 -0
- package/performance/num-to-string.ts +16 -0
- package/performance/obj-alloc.ts +32 -0
- package/performance/regex-exec.ts +29 -0
- package/performance/regex-site.ts +28 -0
- package/performance/set-ops.ts +20 -0
- package/performance/str-char-scan.ts +35 -0
- package/performance/str-concat-plus.ts +18 -0
- package/performance/str-concat.ts +24 -0
- package/performance/str-short-scan.ts +26 -0
- package/performance/str-split-join.ts +23 -0
- package/performance/str-template.ts +16 -0
- package/performance/union-switch.ts +57 -0
- package/tsparser/check.go +2 -1
- package/tsparser/main.go +5 -0
- package/types/typenative-npm.d.ts +193 -4
- package/types/typenative.d.ts +138 -41
|
@@ -0,0 +1,688 @@
|
|
|
1
|
+
// Re-creates vendor/ from the pinned upstream sources.
|
|
2
|
+
//
|
|
3
|
+
// Fetches the React Compiler (facebook/react
|
|
4
|
+
// compiler/packages/babel-plugin-react-compiler/src), the Babel packages it
|
|
5
|
+
// runs on (@babel/parser, types, traverse, generator, template, code-frame and
|
|
6
|
+
// their helpers, from babel/babel at the v7.29.13 tag), zod 4 and
|
|
7
|
+
// zod-validation-error 4, and the small packages those import, into
|
|
8
|
+
// .cache/upstream/. It then copies every file reachable from main.ts's entry
|
|
9
|
+
// modules into vendor/ with mechanical edits only:
|
|
10
|
+
//
|
|
11
|
+
// * relative import specifiers carry their file extension
|
|
12
|
+
// (`'../HIR'` -> `'../HIR/index.ts'`), and package specifiers point at
|
|
13
|
+
// the vendored copy (`'@babel/types'` -> `'../../types/src/index.ts'`);
|
|
14
|
+
// * Babel's build-time constants are folded the way Babel's own build
|
|
15
|
+
// folds them for its Babel 7 CommonJS release: `process.env.BABEL_8_BREAKING`,
|
|
16
|
+
// `USE_ESM` and `IS_STANDALONE` become `false`, `PACKAGE_JSON.version`
|
|
17
|
+
// becomes the package's version, and conditional imports
|
|
18
|
+
// (`import x from "..." with { if: "..." }`, whose condition is true in
|
|
19
|
+
// that build) lose their `with` clause;
|
|
20
|
+
// * Babel's `@bit` class-field decorators become the getters and setters
|
|
21
|
+
// over one flags field that Babel's build plugin
|
|
22
|
+
// (scripts/babel-plugin-bit-decorator) turns them into, and
|
|
23
|
+
// @babel/generator's `__node("Type")` macro becomes the generator's
|
|
24
|
+
// index and `this.token("x")` of one character `this.tokenChar(120)`, as
|
|
25
|
+
// its build (`pluginGeneratorOptimization`) does: the printer tracks the
|
|
26
|
+
// last character it wrote only on the tokenChar() path.
|
|
27
|
+
//
|
|
28
|
+
// No other line of upstream code changes. Three packages are replaced by
|
|
29
|
+
// hand-written stubs in vendor/stubs/ (kept as they are; see the comments
|
|
30
|
+
// there): `debug` and `pretty-format`, which the compiler and Babel only reach
|
|
31
|
+
// on debug-logging paths, and `@babel/core`, of which the compiler uses the
|
|
32
|
+
// `NodePath` class, plugin types and a test helper's `transformFromAstSync`. js-tokens@4 ships no declarations, so
|
|
33
|
+
// vendor/stubs/js-tokens.d.ts declares the parts Babel uses.
|
|
34
|
+
//
|
|
35
|
+
// Usage: node vendor.mjs
|
|
36
|
+
|
|
37
|
+
import { spawnSync } from 'node:child_process';
|
|
38
|
+
import fs from 'node:fs';
|
|
39
|
+
import { createRequire } from 'node:module';
|
|
40
|
+
import path from 'node:path';
|
|
41
|
+
import { fileURLToPath } from 'node:url';
|
|
42
|
+
|
|
43
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
44
|
+
const repoRoot = path.resolve(here, '..', '..');
|
|
45
|
+
const ts = createRequire(path.join(repoRoot, 'package.json'))('typescript');
|
|
46
|
+
const upstream = path.join(here, '.cache', 'upstream');
|
|
47
|
+
const vendor = path.join(here, 'vendor');
|
|
48
|
+
|
|
49
|
+
const REACT_COMMIT = '76baa3b5434fad315ece9cfd4d20d7a8d6c34a25';
|
|
50
|
+
const BABEL_TAG = 'v7.29.13';
|
|
51
|
+
const BABEL_VERSION = '7.29.13';
|
|
52
|
+
const ZOD_VALIDATION_ERROR_TAG = 'v4.0.2';
|
|
53
|
+
const RESOLVE_URI_TAG = 'v3.1.2';
|
|
54
|
+
const NPM = [
|
|
55
|
+
'zod@4.1.12',
|
|
56
|
+
'charcodes@0.2.1',
|
|
57
|
+
'jsesc@3.1.0',
|
|
58
|
+
'@types/jsesc@3.0.3',
|
|
59
|
+
'picocolors@1.1.1',
|
|
60
|
+
'js-tokens@4.0.0',
|
|
61
|
+
'invariant@2.2.4',
|
|
62
|
+
'@types/invariant@2.2.37',
|
|
63
|
+
'@jridgewell/gen-mapping@0.3.13',
|
|
64
|
+
'@jridgewell/trace-mapping@0.3.31',
|
|
65
|
+
'@jridgewell/sourcemap-codec@1.6.0',
|
|
66
|
+
];
|
|
67
|
+
const BABEL_PACKAGES = [
|
|
68
|
+
'parser',
|
|
69
|
+
'types',
|
|
70
|
+
'traverse',
|
|
71
|
+
'generator',
|
|
72
|
+
'template',
|
|
73
|
+
'code-frame',
|
|
74
|
+
'helper-string-parser',
|
|
75
|
+
'helper-validator-identifier',
|
|
76
|
+
'helper-globals',
|
|
77
|
+
];
|
|
78
|
+
|
|
79
|
+
function run(command, args, options = {}) {
|
|
80
|
+
const result = spawnSync(command, args, { stdio: 'inherit', shell: process.platform === 'win32', ...options });
|
|
81
|
+
if (result.status !== 0) {
|
|
82
|
+
console.error(`${command} ${args.join(' ')} failed`);
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// A sparse, blobless checkout of `paths` of a repository at `ref`
|
|
88
|
+
function fetchGit(name, url, ref, paths) {
|
|
89
|
+
const dir = path.join(upstream, name);
|
|
90
|
+
if (fs.existsSync(path.join(dir, '.done'))) return dir;
|
|
91
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
92
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
93
|
+
console.log(`Fetching ${url} ${ref} ...`);
|
|
94
|
+
const git = (...args) => run('git', ['-C', dir, ...args]);
|
|
95
|
+
git('init', '--quiet');
|
|
96
|
+
git('remote', 'add', 'origin', url);
|
|
97
|
+
git('sparse-checkout', 'set', '--no-cone', ...paths);
|
|
98
|
+
git('fetch', '--quiet', '--depth', '1', '--filter=blob:none', 'origin', ref);
|
|
99
|
+
git('checkout', '--quiet', 'FETCH_HEAD');
|
|
100
|
+
fs.writeFileSync(path.join(dir, '.done'), '');
|
|
101
|
+
return dir;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// An npm package tarball, unpacked (no install scripts run)
|
|
105
|
+
function fetchNpm(spec) {
|
|
106
|
+
const dir = path.join(upstream, 'npm', spec.replace('/', '__'));
|
|
107
|
+
// (the tarball's single top-level directory: `package/`, or the package's
|
|
108
|
+
// name for @types packages)
|
|
109
|
+
const unpacked = () => path.join(dir, fs.readdirSync(dir).find((e) => !e.startsWith('.')));
|
|
110
|
+
if (fs.existsSync(path.join(dir, '.done'))) return unpacked();
|
|
111
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
112
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
113
|
+
console.log(`Fetching ${spec} from npm ...`);
|
|
114
|
+
const result = spawnSync('npm', ['pack', '--silent', '--ignore-scripts', spec], {
|
|
115
|
+
cwd: dir,
|
|
116
|
+
encoding: 'utf-8',
|
|
117
|
+
shell: process.platform === 'win32',
|
|
118
|
+
});
|
|
119
|
+
if (result.status !== 0) {
|
|
120
|
+
console.error(result.stderr);
|
|
121
|
+
process.exit(1);
|
|
122
|
+
}
|
|
123
|
+
const tarball = result.stdout.trim().split('\n').pop();
|
|
124
|
+
run('tar', ['xzf', tarball], { cwd: dir });
|
|
125
|
+
fs.rmSync(path.join(dir, tarball));
|
|
126
|
+
fs.writeFileSync(path.join(dir, '.done'), '');
|
|
127
|
+
return unpacked();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const react = fetchGit('react', 'https://github.com/facebook/react.git', REACT_COMMIT, [
|
|
131
|
+
'/compiler/packages/babel-plugin-react-compiler/src/',
|
|
132
|
+
'/LICENSE',
|
|
133
|
+
]);
|
|
134
|
+
const babel = fetchGit('babel', 'https://github.com/babel/babel.git', `refs/tags/${BABEL_TAG}`, [
|
|
135
|
+
...BABEL_PACKAGES.map((p) => `/packages/babel-${p}/`),
|
|
136
|
+
'/LICENSE',
|
|
137
|
+
]);
|
|
138
|
+
const zve = fetchGit(
|
|
139
|
+
'zod-validation-error',
|
|
140
|
+
'https://github.com/causaly/zod-validation-error.git',
|
|
141
|
+
`refs/tags/${ZOD_VALIDATION_ERROR_TAG}`,
|
|
142
|
+
['/lib/', '/LICENSE'],
|
|
143
|
+
);
|
|
144
|
+
const resolveUri = fetchGit('resolve-uri', 'https://github.com/jridgewell/resolve-uri.git', `refs/tags/${RESOLVE_URI_TAG}`, [
|
|
145
|
+
'/src/',
|
|
146
|
+
'/LICENSE',
|
|
147
|
+
]);
|
|
148
|
+
const npm = Object.fromEntries(NPM.map((spec) => [spec.slice(0, spec.lastIndexOf('@')), fetchNpm(spec)]));
|
|
149
|
+
|
|
150
|
+
// Upstream directory -> vendor directory. Every vendored file lives under one
|
|
151
|
+
// of these roots, at the same relative path.
|
|
152
|
+
const roots = [
|
|
153
|
+
{ from: path.join(react, 'compiler/packages/babel-plugin-react-compiler/src'), to: 'react-compiler/src' },
|
|
154
|
+
...BABEL_PACKAGES.map((p) => ({ from: path.join(babel, `packages/babel-${p}`), to: `babel/${p}`, babel: p })),
|
|
155
|
+
{ from: path.join(npm['zod'], 'src'), to: 'zod/src' },
|
|
156
|
+
{ from: path.join(zve, 'lib'), to: 'zod-validation-error/lib' },
|
|
157
|
+
{ from: path.join(resolveUri, 'src'), to: 'jridgewell/resolve-uri/src' },
|
|
158
|
+
{ from: path.join(npm['@jridgewell/gen-mapping'], 'src'), to: 'jridgewell/gen-mapping/src' },
|
|
159
|
+
{ from: path.join(npm['@jridgewell/trace-mapping'], 'src'), to: 'jridgewell/trace-mapping/src' },
|
|
160
|
+
{ from: path.join(npm['@jridgewell/sourcemap-codec'], 'src'), to: 'jridgewell/sourcemap-codec/src' },
|
|
161
|
+
{ from: path.join(npm['charcodes'], 'src'), to: 'charcodes/src' },
|
|
162
|
+
{ from: npm['jsesc'], to: 'jsesc' },
|
|
163
|
+
{ from: npm['@types/jsesc'], to: 'jsesc/types' },
|
|
164
|
+
{ from: npm['picocolors'], to: 'picocolors' },
|
|
165
|
+
{ from: npm['js-tokens'], to: 'js-tokens' },
|
|
166
|
+
{ from: npm['invariant'], to: 'invariant' },
|
|
167
|
+
{ from: npm['@types/invariant'], to: 'invariant/types' },
|
|
168
|
+
{ from: path.join(vendor, 'stubs'), to: 'stubs' },
|
|
169
|
+
];
|
|
170
|
+
|
|
171
|
+
// Package specifiers -> the upstream file that stands for them
|
|
172
|
+
const packages = {
|
|
173
|
+
'@babel/parser': path.join(babel, 'packages/babel-parser/src/index.ts'),
|
|
174
|
+
'@babel/types': path.join(babel, 'packages/babel-types/src/index.ts'),
|
|
175
|
+
'@babel/traverse': path.join(babel, 'packages/babel-traverse/src/index.ts'),
|
|
176
|
+
'@babel/generator': path.join(babel, 'packages/babel-generator/src/index.ts'),
|
|
177
|
+
'@babel/template': path.join(babel, 'packages/babel-template/src/index.ts'),
|
|
178
|
+
'@babel/code-frame': path.join(babel, 'packages/babel-code-frame/src/index.ts'),
|
|
179
|
+
'@babel/helper-string-parser': path.join(babel, 'packages/babel-helper-string-parser/src/index.ts'),
|
|
180
|
+
'@babel/helper-validator-identifier': path.join(babel, 'packages/babel-helper-validator-identifier/src/index.ts'),
|
|
181
|
+
'@babel/helper-globals/data/builtin-lower.json': path.join(babel, 'packages/babel-helper-globals/data/builtin-lower.json'),
|
|
182
|
+
'@babel/helper-globals/data/builtin-upper.json': path.join(babel, 'packages/babel-helper-globals/data/builtin-upper.json'),
|
|
183
|
+
'zod/v4': path.join(npm['zod'], 'src/v4/classic/index.ts'),
|
|
184
|
+
'zod/v4/core': path.join(npm['zod'], 'src/v4/core/index.ts'),
|
|
185
|
+
'zod-validation-error/v4': path.join(zve, 'lib/v4/index.ts'),
|
|
186
|
+
'@jridgewell/resolve-uri': path.join(resolveUri, 'src/resolve-uri.ts'),
|
|
187
|
+
'@jridgewell/gen-mapping': path.join(npm['@jridgewell/gen-mapping'], 'src/gen-mapping.ts'),
|
|
188
|
+
'@jridgewell/trace-mapping': path.join(npm['@jridgewell/trace-mapping'], 'src/trace-mapping.ts'),
|
|
189
|
+
'@jridgewell/sourcemap-codec': path.join(npm['@jridgewell/sourcemap-codec'], 'src/sourcemap-codec.ts'),
|
|
190
|
+
'charcodes': path.join(npm['charcodes'], 'src/index.js'),
|
|
191
|
+
'jsesc': path.join(npm['jsesc'], 'jsesc.js'),
|
|
192
|
+
'picocolors': path.join(npm['picocolors'], 'picocolors.js'),
|
|
193
|
+
'picocolors/types': path.join(npm['picocolors'], 'types.d.ts'),
|
|
194
|
+
'js-tokens': path.join(npm['js-tokens'], 'index.js'),
|
|
195
|
+
'invariant': path.join(npm['invariant'], 'invariant.js'),
|
|
196
|
+
'@babel/core': path.join(vendor, 'stubs', 'babel-core.ts'),
|
|
197
|
+
'debug': path.join(vendor, 'stubs', 'debug.ts'),
|
|
198
|
+
'pretty-format': path.join(vendor, 'stubs', 'pretty-format.ts'),
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
// CommonJS files are vendored as .cjs (Node then loads them as CommonJS
|
|
202
|
+
// whatever the nearest package.json says), each with its declarations
|
|
203
|
+
// beside it as .d.cts
|
|
204
|
+
const commonJs = new Map([
|
|
205
|
+
[path.join(npm['jsesc'], 'jsesc.js'), path.join(npm['@types/jsesc'], 'index.d.ts')],
|
|
206
|
+
[path.join(npm['picocolors'], 'picocolors.js'), path.join(npm['picocolors'], 'picocolors.d.ts')],
|
|
207
|
+
[path.join(npm['js-tokens'], 'index.js'), path.join(vendor, 'stubs', 'js-tokens.d.ts')],
|
|
208
|
+
[path.join(npm['invariant'], 'invariant.js'), path.join(npm['@types/invariant'], 'index.d.ts')],
|
|
209
|
+
]);
|
|
210
|
+
|
|
211
|
+
// The modules main.ts imports
|
|
212
|
+
const entries = [
|
|
213
|
+
path.join(react, 'compiler/packages/babel-plugin-react-compiler/src/Entrypoint/index.ts'),
|
|
214
|
+
path.join(react, 'compiler/packages/babel-plugin-react-compiler/src/CompilerError.ts'),
|
|
215
|
+
path.join(react, 'compiler/packages/babel-plugin-react-compiler/src/Utils/TestUtils.ts'),
|
|
216
|
+
packages['@babel/parser'],
|
|
217
|
+
packages['@babel/traverse'],
|
|
218
|
+
packages['@babel/generator'],
|
|
219
|
+
packages['@babel/types'],
|
|
220
|
+
];
|
|
221
|
+
|
|
222
|
+
// Node built-ins keep their specifier
|
|
223
|
+
const builtins = new Set(['crypto', 'node:crypto', 'node:util', 'util', 'fs', 'path']);
|
|
224
|
+
|
|
225
|
+
function rootOf(file) {
|
|
226
|
+
const root = roots.find((r) => file === r.from || file.startsWith(r.from + path.sep));
|
|
227
|
+
if (!root) throw new Error(`not under a vendored root: ${file}`);
|
|
228
|
+
return root;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// charcodes' source is Flow whose every line (`export const tab: 9 = 9;`) is
|
|
232
|
+
// also TypeScript: vendored as .ts
|
|
233
|
+
const flowAsTs = new Set([packages['charcodes']]);
|
|
234
|
+
|
|
235
|
+
function destination(file) {
|
|
236
|
+
const root = rootOf(file);
|
|
237
|
+
let rel = path.relative(root.from, file);
|
|
238
|
+
if (commonJs.has(file)) rel = rel.replace(/\.js$/, '.cjs');
|
|
239
|
+
if (flowAsTs.has(file)) rel = rel.replace(/\.js$/, '.ts');
|
|
240
|
+
return path.join(vendor, root.to, rel);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function isFile(p) {
|
|
244
|
+
try {
|
|
245
|
+
return fs.statSync(p).isFile();
|
|
246
|
+
} catch {
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// The upstream file that becomes `vendored` (a path in vendor/)
|
|
252
|
+
function upstreamOf(vendored) {
|
|
253
|
+
for (const root of roots) {
|
|
254
|
+
const base = path.join(vendor, root.to);
|
|
255
|
+
if (root.to === 'stubs' || !vendored.startsWith(base + path.sep)) continue;
|
|
256
|
+
const rel = path.relative(base, vendored);
|
|
257
|
+
for (const candidate of [rel, rel.replace(/\.cjs$/, '.js'), rel.replace(/\.ts$/, '.js')]) {
|
|
258
|
+
const file = path.join(root.from, candidate);
|
|
259
|
+
if (isFile(file)) return file;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// The upstream file a specifier in `from` refers to
|
|
266
|
+
function resolve(specifier, from) {
|
|
267
|
+
// The stubs import vendored files by their vendor/ paths
|
|
268
|
+
if (specifier.startsWith('.') && rootOf(from).to === 'stubs') {
|
|
269
|
+
const target = path.resolve(path.dirname(from), specifier);
|
|
270
|
+
const found = target.startsWith(path.join(vendor, 'stubs') + path.sep) ? target : upstreamOf(target);
|
|
271
|
+
if (!found) throw new Error(`cannot resolve ${specifier} from ${from}`);
|
|
272
|
+
return found;
|
|
273
|
+
}
|
|
274
|
+
if (specifier.startsWith('.')) {
|
|
275
|
+
const base = path.resolve(path.dirname(from), specifier);
|
|
276
|
+
const candidates = [
|
|
277
|
+
base,
|
|
278
|
+
base + '.ts',
|
|
279
|
+
base + '.tsx',
|
|
280
|
+
base.replace(/\.js$/, '.ts'),
|
|
281
|
+
base + '.d.ts',
|
|
282
|
+
base.replace(/\.ts$/, '.d.ts'),
|
|
283
|
+
base.replace(/\.d\.ts$/, '.ts'),
|
|
284
|
+
path.join(base, 'index.ts'),
|
|
285
|
+
];
|
|
286
|
+
const found = candidates.find(isFile);
|
|
287
|
+
if (!found) throw new Error(`cannot resolve ${specifier} from ${from}`);
|
|
288
|
+
return found;
|
|
289
|
+
}
|
|
290
|
+
if (packages[specifier]) return packages[specifier];
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function relativeSpecifier(fromFile, toFile) {
|
|
295
|
+
let rel = path.relative(path.dirname(fromFile), toFile).split(path.sep).join('/');
|
|
296
|
+
if (!rel.startsWith('.')) rel = './' + rel;
|
|
297
|
+
return rel;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// The module specifiers of a source file, with their positions
|
|
301
|
+
function specifiers(source) {
|
|
302
|
+
const found = [];
|
|
303
|
+
const visit = (node) => {
|
|
304
|
+
if ((ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) && node.moduleSpecifier) {
|
|
305
|
+
found.push(node.moduleSpecifier);
|
|
306
|
+
} else if (ts.isImportTypeNode(node) && ts.isLiteralTypeNode(node.argument)) {
|
|
307
|
+
found.push(node.argument.literal);
|
|
308
|
+
} else if (
|
|
309
|
+
ts.isCallExpression(node) &&
|
|
310
|
+
node.expression.kind === ts.SyntaxKind.ImportKeyword &&
|
|
311
|
+
node.arguments.length > 0 &&
|
|
312
|
+
ts.isStringLiteral(node.arguments[0])
|
|
313
|
+
) {
|
|
314
|
+
found.push(node.arguments[0]);
|
|
315
|
+
} else if (ts.isImportEqualsDeclaration(node) && ts.isExternalModuleReference(node.moduleReference)) {
|
|
316
|
+
found.push(node.moduleReference.expression);
|
|
317
|
+
}
|
|
318
|
+
ts.forEachChild(node, visit);
|
|
319
|
+
};
|
|
320
|
+
visit(source);
|
|
321
|
+
return found;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// Babel's @bit decorators (scripts/babel-plugin-bit-decorator/plugin.cjs):
|
|
325
|
+
// `@bit.storage flags: number = 0` holds the bits, and each
|
|
326
|
+
// `@bit accessor name = false` (or `@bit(MASK)`, which must name the next
|
|
327
|
+
// bit) becomes a getter and setter of the next bit. The storage field starts
|
|
328
|
+
// with the bits of the accessors initialized to true. The `declare const bit`
|
|
329
|
+
// that types the decorator goes, like every other declaration after type
|
|
330
|
+
// stripping.
|
|
331
|
+
function bitDecorators(source, text) {
|
|
332
|
+
const edits = [];
|
|
333
|
+
const visit = (node) => {
|
|
334
|
+
if (ts.isVariableStatement(node) && node.getText(source).startsWith('declare const bit:')) {
|
|
335
|
+
edits.push({ start: node.getStart(source), end: node.getEnd(), text: '' });
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
if (ts.isClassLike(node)) {
|
|
339
|
+
let storage = null;
|
|
340
|
+
let initial = 0;
|
|
341
|
+
let mask = 1;
|
|
342
|
+
const accessors = [];
|
|
343
|
+
for (const member of node.members) {
|
|
344
|
+
const decorators = (ts.canHaveDecorators(member) && ts.getDecorators(member)) || [];
|
|
345
|
+
for (const decorator of decorators) {
|
|
346
|
+
const expr = decorator.expression.getText(source);
|
|
347
|
+
if (expr === 'bit.storage') {
|
|
348
|
+
storage = { member, decorator };
|
|
349
|
+
} else if (expr === 'bit' || expr.startsWith('bit(')) {
|
|
350
|
+
const value = member.initializer.getText(source);
|
|
351
|
+
if (value !== 'true' && value !== 'false') throw new Error(`@bit field ${member.name.getText(source)} needs a boolean`);
|
|
352
|
+
if (value === 'true') initial |= mask;
|
|
353
|
+
accessors.push({ member, mask });
|
|
354
|
+
mask <<= 1;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
if (accessors.length > 0) {
|
|
359
|
+
if (!storage) throw new Error('@bit without @bit.storage');
|
|
360
|
+
const name = storage.member.name.getText(source);
|
|
361
|
+
// drop `@bit.storage ` and set the initial bits
|
|
362
|
+
let end = storage.decorator.getEnd();
|
|
363
|
+
while (/\s/.test(text[end])) end++;
|
|
364
|
+
edits.push({ start: storage.decorator.getStart(source), end, text: '' });
|
|
365
|
+
const init = storage.member.initializer;
|
|
366
|
+
edits.push({ start: init.getStart(source), end: init.getEnd(), text: String(initial) });
|
|
367
|
+
let indent = '';
|
|
368
|
+
for (let i = storage.member.getStart(source) - 1; i >= 0 && text[i] === ' '; i--) indent += ' ';
|
|
369
|
+
for (const { member, mask } of accessors) {
|
|
370
|
+
const key = member.name.getText(source);
|
|
371
|
+
const replacement =
|
|
372
|
+
`get ${key}() {\n${indent} return (this.${name} & ${mask}) > 0;\n${indent}}\n` +
|
|
373
|
+
`${indent}set ${key}(v) {\n${indent} if (v) this.${name} |= ${mask};\n${indent} else this.${name} &= ${~mask};\n${indent}}`;
|
|
374
|
+
edits.push({ start: member.getStart(source), end: member.getEnd(), text: replacement });
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
ts.forEachChild(node, visit);
|
|
379
|
+
};
|
|
380
|
+
visit(source);
|
|
381
|
+
return edits;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// Babel's build-time flags (scripts/babel-plugin-toggle-boolean-flag), with
|
|
385
|
+
// the values of its Babel 7 ES-module build. Like that plugin, the pass folds
|
|
386
|
+
// every `if`, `?:`, `&&` and `||` whose outcome the flags decide (an `if`
|
|
387
|
+
// becomes the statements of the branch taken, or goes), and a conditional
|
|
388
|
+
// import (`with { if: "..." }`) loses its condition when it holds and is
|
|
389
|
+
// removed when it doesn't. Flags left anywhere else are an error, as there.
|
|
390
|
+
const FLAGS = new Map([
|
|
391
|
+
['USE_ESM', true],
|
|
392
|
+
['IS_STANDALONE', false],
|
|
393
|
+
['process.env.BABEL_8_BREAKING', false],
|
|
394
|
+
]);
|
|
395
|
+
|
|
396
|
+
function unparen(node) {
|
|
397
|
+
while (ts.isParenthesizedExpression(node)) node = node.expression;
|
|
398
|
+
return node;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function flagName(node, source) {
|
|
402
|
+
if (ts.isIdentifier(node) || ts.isPropertyAccessExpression(node)) {
|
|
403
|
+
const name = node.getText(source);
|
|
404
|
+
if (FLAGS.has(name)) return name;
|
|
405
|
+
}
|
|
406
|
+
return null;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// The plugin's evaluate(): { value } when the flags decide the test,
|
|
410
|
+
// { text } when they simplify it to `text`, { unrelated } otherwise
|
|
411
|
+
function evaluate(node, source) {
|
|
412
|
+
node = unparen(node);
|
|
413
|
+
const unrelated = { unrelated: true, text: node.getText(source), compound: true };
|
|
414
|
+
const name = flagName(node, source);
|
|
415
|
+
if (name) return { value: FLAGS.get(name) };
|
|
416
|
+
if (ts.isPrefixUnaryExpression(node) && node.operator === ts.SyntaxKind.ExclamationToken) {
|
|
417
|
+
const arg = evaluate(node.operand, source);
|
|
418
|
+
if (arg.unrelated) return unrelated;
|
|
419
|
+
if (arg.text !== undefined) return { text: arg.compound ? `!(${arg.text})` : `!${arg.text}` };
|
|
420
|
+
return { value: !arg.value };
|
|
421
|
+
}
|
|
422
|
+
if (ts.isBinaryExpression(node)) {
|
|
423
|
+
const op = node.operatorToken.kind;
|
|
424
|
+
if (op === ts.SyntaxKind.BarBarToken || op === ts.SyntaxKind.AmpersandAmpersandToken) {
|
|
425
|
+
const or = op === ts.SyntaxKind.BarBarToken;
|
|
426
|
+
const left = evaluate(node.left, source);
|
|
427
|
+
const right = evaluate(node.right, source);
|
|
428
|
+
if (or) {
|
|
429
|
+
if (left.value === true || right.value === true) return { value: true };
|
|
430
|
+
if (left.value === false && right.value === false) return { value: false };
|
|
431
|
+
if (left.value === false) return right.unrelated ? { text: right.text, compound: true } : right;
|
|
432
|
+
if (right.value === false) return left.unrelated ? { text: left.text, compound: true } : left;
|
|
433
|
+
} else {
|
|
434
|
+
if (left.value === true && right.value === true) return { value: true };
|
|
435
|
+
if (left.value === false || right.value === false) return { value: false };
|
|
436
|
+
if (left.value === true) return right.unrelated ? { text: right.text, compound: true } : right;
|
|
437
|
+
if (right.value === true) return left.unrelated ? { text: left.text, compound: true } : left;
|
|
438
|
+
}
|
|
439
|
+
if (left.unrelated && right.unrelated) return unrelated;
|
|
440
|
+
const wrap = (r) => (r.compound ? `(${r.text})` : r.text);
|
|
441
|
+
return { text: `${wrap(left)} ${or ? '||' : '&&'} ${wrap(right)}`, compound: true };
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
return unrelated;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// One pass of folding, outermost tests first; null when nothing changed
|
|
448
|
+
function foldFlags(text) {
|
|
449
|
+
const source = ts.createSourceFile('x.ts', text, ts.ScriptTarget.ESNext, true, ts.ScriptKind.TS);
|
|
450
|
+
const edits = [];
|
|
451
|
+
const visit = (node) => {
|
|
452
|
+
if (ts.isIfStatement(node) || ts.isConditionalExpression(node)) {
|
|
453
|
+
const test = ts.isIfStatement(node) ? node.expression : node.condition;
|
|
454
|
+
const res = evaluate(test, source);
|
|
455
|
+
if (!res.unrelated) {
|
|
456
|
+
if (res.text !== undefined) {
|
|
457
|
+
// (the branches are folded, the test isn't visited again)
|
|
458
|
+
edits.push({ start: test.getStart(source), end: test.getEnd(), text: res.text });
|
|
459
|
+
for (const branch of ts.isIfStatement(node)
|
|
460
|
+
? [node.thenStatement, node.elseStatement]
|
|
461
|
+
: [node.whenTrue, node.whenFalse]) {
|
|
462
|
+
if (branch) visit(branch);
|
|
463
|
+
}
|
|
464
|
+
return;
|
|
465
|
+
} else if (ts.isIfStatement(node)) {
|
|
466
|
+
const branch = res.value ? node.thenStatement : node.elseStatement;
|
|
467
|
+
let replacement = '';
|
|
468
|
+
if (branch && ts.isBlock(branch)) {
|
|
469
|
+
replacement = text.slice(branch.getStart(source) + 1, branch.getEnd() - 1);
|
|
470
|
+
// (an `else if` taking several statements keeps its braces)
|
|
471
|
+
if (ts.isIfStatement(node.parent) && node.parent.elseStatement === node) replacement = `{${replacement}}`;
|
|
472
|
+
} else if (branch) {
|
|
473
|
+
replacement = branch.getText(source);
|
|
474
|
+
}
|
|
475
|
+
edits.push({ start: node.getStart(source), end: node.getEnd(), text: replacement });
|
|
476
|
+
return;
|
|
477
|
+
} else {
|
|
478
|
+
const branch = res.value ? node.whenTrue : node.whenFalse;
|
|
479
|
+
edits.push({ start: node.getStart(source), end: node.getEnd(), text: `(${branch.getText(source)})` });
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
} else if (
|
|
484
|
+
ts.isBinaryExpression(node) &&
|
|
485
|
+
(node.operatorToken.kind === ts.SyntaxKind.BarBarToken ||
|
|
486
|
+
node.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken)
|
|
487
|
+
) {
|
|
488
|
+
const res = evaluate(node, source);
|
|
489
|
+
if (!res.unrelated) {
|
|
490
|
+
const replacement = res.text !== undefined ? (res.compound ? `(${res.text})` : res.text) : String(res.value);
|
|
491
|
+
edits.push({ start: node.getStart(source), end: node.getEnd(), text: replacement });
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
} else if (ts.isImportDeclaration(node) && node.attributes) {
|
|
495
|
+
const attr = node.attributes.elements.find((e) => e.name.text === 'if');
|
|
496
|
+
if (attr) {
|
|
497
|
+
const condition = ts.createSourceFile('c.ts', `(${attr.value.text})`, ts.ScriptTarget.ESNext, true, ts.ScriptKind.TS);
|
|
498
|
+
const res = evaluate(condition.statements[0].expression, condition);
|
|
499
|
+
if (res.value === true) {
|
|
500
|
+
if (node.attributes.elements.length !== 1) throw new Error('unexpected import attributes');
|
|
501
|
+
let start = node.attributes.getStart(source);
|
|
502
|
+
while (start > 0 && /\s/.test(text[start - 1])) start--;
|
|
503
|
+
edits.push({ start, end: node.attributes.getEnd(), text: '' });
|
|
504
|
+
} else if (res.value === false) {
|
|
505
|
+
edits.push({ start: node.getStart(source), end: node.getEnd(), text: '' });
|
|
506
|
+
} else {
|
|
507
|
+
throw new Error(`cannot evaluate import condition ${attr.value.text}`);
|
|
508
|
+
}
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
ts.forEachChild(node, visit);
|
|
513
|
+
};
|
|
514
|
+
visit(source);
|
|
515
|
+
return edits.length > 0 ? applyEdits(text, edits) : null;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
function applyEdits(text, edits) {
|
|
519
|
+
edits.sort((a, b) => b.start - a.start);
|
|
520
|
+
let out = text;
|
|
521
|
+
for (const edit of edits) out = out.slice(0, edit.start) + edit.text + out.slice(edit.end);
|
|
522
|
+
return out;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
// @babel/generator's `__node("Type")`: the index of the node type among the
|
|
526
|
+
// sorted names that the generators/*.ts files (but deprecated.ts) export, as
|
|
527
|
+
// pluginGeneratorOptimization in Babel's babel.config.js computes it
|
|
528
|
+
let generatorNames = null;
|
|
529
|
+
function nodeIndex(type) {
|
|
530
|
+
if (!generatorNames) {
|
|
531
|
+
generatorNames = [];
|
|
532
|
+
const dir = path.join(babel, 'packages/babel-generator/src/generators');
|
|
533
|
+
for (const name of fs.readdirSync(dir).filter((f) => f.endsWith('.ts') && f !== 'deprecated.ts')) {
|
|
534
|
+
const file = path.join(dir, name);
|
|
535
|
+
const source = ts.createSourceFile(file, fs.readFileSync(file, 'utf-8'), ts.ScriptTarget.ESNext, true);
|
|
536
|
+
const visit = (node) => {
|
|
537
|
+
let exported;
|
|
538
|
+
if (ts.isExportSpecifier(node)) exported = node.name.text;
|
|
539
|
+
else if (
|
|
540
|
+
ts.isFunctionDeclaration(node) &&
|
|
541
|
+
node.name &&
|
|
542
|
+
node.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword)
|
|
543
|
+
) {
|
|
544
|
+
exported = node.name.text;
|
|
545
|
+
}
|
|
546
|
+
if (exported && !exported.startsWith('_')) generatorNames.push(exported);
|
|
547
|
+
ts.forEachChild(node, visit);
|
|
548
|
+
};
|
|
549
|
+
visit(source);
|
|
550
|
+
}
|
|
551
|
+
generatorNames.sort();
|
|
552
|
+
}
|
|
553
|
+
const index = generatorNames.indexOf(type);
|
|
554
|
+
if (index === -1) throw new Error(`Unknown generator type: ${type}`);
|
|
555
|
+
return index;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
// Babel's build of one source file: @bit decorators, flags, PACKAGE_JSON,
|
|
559
|
+
// __node()
|
|
560
|
+
function babelBuild(file, text) {
|
|
561
|
+
const generator = file.startsWith(path.join(babel, 'packages/babel-generator/src') + path.sep);
|
|
562
|
+
let source = ts.createSourceFile(file, text, ts.ScriptTarget.ESNext, true, ts.ScriptKind.TS);
|
|
563
|
+
text = applyEdits(text, bitDecorators(source, text));
|
|
564
|
+
for (let folded; (folded = foldFlags(text)) !== null; ) text = folded;
|
|
565
|
+
source = ts.createSourceFile(file, text, ts.ScriptTarget.ESNext, true, ts.ScriptKind.TS);
|
|
566
|
+
const edits = [];
|
|
567
|
+
const visit = (node) => {
|
|
568
|
+
const name = flagName(node, source);
|
|
569
|
+
if (name) {
|
|
570
|
+
const { line } = source.getLineAndCharacterOfPosition(node.getStart(source));
|
|
571
|
+
throw new Error(`${file}:${line + 1}: ${name} could not be stripped`);
|
|
572
|
+
}
|
|
573
|
+
if (ts.isPropertyAccessExpression(node) && node.getText(source) === 'PACKAGE_JSON.version') {
|
|
574
|
+
edits.push({ start: node.getStart(source), end: node.getEnd(), text: JSON.stringify(BABEL_VERSION) });
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
if (
|
|
578
|
+
ts.isCallExpression(node) &&
|
|
579
|
+
ts.isIdentifier(node.expression) &&
|
|
580
|
+
node.expression.text === '__node' &&
|
|
581
|
+
node.arguments.length === 1 &&
|
|
582
|
+
ts.isStringLiteral(node.arguments[0])
|
|
583
|
+
) {
|
|
584
|
+
edits.push({ start: node.getStart(source), end: node.getEnd(), text: String(nodeIndex(node.arguments[0].text)) });
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
if (
|
|
588
|
+
generator &&
|
|
589
|
+
ts.isCallExpression(node) &&
|
|
590
|
+
ts.isPropertyAccessExpression(node.expression) &&
|
|
591
|
+
node.expression.expression.kind === ts.SyntaxKind.ThisKeyword &&
|
|
592
|
+
node.expression.name.text === 'token' &&
|
|
593
|
+
node.arguments.length === 1 &&
|
|
594
|
+
ts.isStringLiteral(node.arguments[0]) &&
|
|
595
|
+
node.arguments[0].text.length === 1
|
|
596
|
+
) {
|
|
597
|
+
const name = node.expression.name;
|
|
598
|
+
const arg = node.arguments[0];
|
|
599
|
+
edits.push({ start: name.getStart(source), end: name.getEnd(), text: 'tokenChar' });
|
|
600
|
+
edits.push({ start: arg.getStart(source), end: arg.getEnd(), text: String(arg.text.charCodeAt(0)) });
|
|
601
|
+
}
|
|
602
|
+
ts.forEachChild(node, visit);
|
|
603
|
+
};
|
|
604
|
+
visit(source);
|
|
605
|
+
return applyEdits(text, edits);
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
const done = new Map();
|
|
609
|
+
const missing = new Set();
|
|
610
|
+
const queue = [...entries];
|
|
611
|
+
|
|
612
|
+
function vendorFile(file) {
|
|
613
|
+
if (done.has(file)) return;
|
|
614
|
+
const dest = destination(file);
|
|
615
|
+
done.set(file, dest);
|
|
616
|
+
let text = fs.readFileSync(file, 'utf-8');
|
|
617
|
+
if (file.endsWith('.json')) {
|
|
618
|
+
write(dest, text);
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
621
|
+
if (file.endsWith('.js') && !flowAsTs.has(file)) {
|
|
622
|
+
// CommonJS: vendored as is; its declarations sit beside it
|
|
623
|
+
write(dest, text);
|
|
624
|
+
const declarations = commonJs.get(file);
|
|
625
|
+
if (declarations) {
|
|
626
|
+
write(dest.replace(/\.cjs$/, '.d.cts'), fs.readFileSync(declarations, 'utf-8'));
|
|
627
|
+
}
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
if (rootOf(file).babel !== undefined) text = babelBuild(file, text);
|
|
631
|
+
const source = ts.createSourceFile(file, text, ts.ScriptTarget.ESNext, true, ts.ScriptKind.TS);
|
|
632
|
+
const edits = [];
|
|
633
|
+
const found = specifiers(source);
|
|
634
|
+
for (const literal of found) {
|
|
635
|
+
const target = resolve(literal.text, file);
|
|
636
|
+
if (target === null) {
|
|
637
|
+
if (!builtins.has(literal.text)) missing.add(`${literal.text} (${path.relative(upstream, file)})`);
|
|
638
|
+
continue;
|
|
639
|
+
}
|
|
640
|
+
queue.push(target);
|
|
641
|
+
const quote = text[literal.getStart(source)];
|
|
642
|
+
edits.push({
|
|
643
|
+
start: literal.getStart(source),
|
|
644
|
+
end: literal.getEnd(),
|
|
645
|
+
text: quote + relativeSpecifier(dest, destination(target)) + quote,
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
write(dest, applyEdits(text, edits));
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
function write(dest, content) {
|
|
652
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
653
|
+
fs.writeFileSync(dest, content);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
// Package files that come along whatever is imported: licenses, and the
|
|
657
|
+
// declaration files that the CommonJS declarations import
|
|
658
|
+
const extras = [
|
|
659
|
+
[path.join(react, 'LICENSE'), 'react-compiler/LICENSE'],
|
|
660
|
+
[path.join(babel, 'LICENSE'), 'babel/LICENSE'],
|
|
661
|
+
[path.join(npm['zod'], 'LICENSE'), 'zod/LICENSE'],
|
|
662
|
+
[path.join(zve, 'LICENSE'), 'zod-validation-error/LICENSE'],
|
|
663
|
+
[path.join(resolveUri, 'LICENSE'), 'jridgewell/resolve-uri/LICENSE'],
|
|
664
|
+
[path.join(npm['@jridgewell/gen-mapping'], 'LICENSE'), 'jridgewell/gen-mapping/LICENSE'],
|
|
665
|
+
[path.join(npm['@jridgewell/trace-mapping'], 'LICENSE'), 'jridgewell/trace-mapping/LICENSE'],
|
|
666
|
+
[path.join(npm['@jridgewell/sourcemap-codec'], 'LICENSE'), 'jridgewell/sourcemap-codec/LICENSE'],
|
|
667
|
+
[path.join(npm['jsesc'], 'LICENSE-MIT.txt'), 'jsesc/LICENSE-MIT.txt'],
|
|
668
|
+
[path.join(npm['@types/jsesc'], 'LICENSE'), 'jsesc/types/LICENSE'],
|
|
669
|
+
[path.join(npm['picocolors'], 'LICENSE'), 'picocolors/LICENSE'],
|
|
670
|
+
[path.join(npm['picocolors'], 'types.d.ts'), 'picocolors/types.d.ts'],
|
|
671
|
+
[path.join(npm['js-tokens'], 'LICENSE'), 'js-tokens/LICENSE'],
|
|
672
|
+
// (charcodes ships no LICENSE file; its package.json declares MIT)
|
|
673
|
+
[path.join(npm['charcodes'], 'package.json'), 'charcodes/package.json'],
|
|
674
|
+
[path.join(npm['invariant'], 'LICENSE'), 'invariant/LICENSE'],
|
|
675
|
+
[path.join(npm['@types/invariant'], 'LICENSE'), 'invariant/types/LICENSE'],
|
|
676
|
+
];
|
|
677
|
+
|
|
678
|
+
for (const entry of fs.existsSync(vendor) ? fs.readdirSync(vendor) : []) {
|
|
679
|
+
if (entry !== 'stubs') fs.rmSync(path.join(vendor, entry), { recursive: true, force: true });
|
|
680
|
+
}
|
|
681
|
+
while (queue.length > 0) vendorFile(queue.shift());
|
|
682
|
+
for (const [from, to] of extras) write(path.join(vendor, to), fs.readFileSync(from, 'utf-8'));
|
|
683
|
+
|
|
684
|
+
if (missing.size > 0) {
|
|
685
|
+
console.error('Unresolved package imports:\n ' + [...missing].sort().join('\n '));
|
|
686
|
+
process.exit(1);
|
|
687
|
+
}
|
|
688
|
+
console.log(`Vendored ${done.size} files into vendor/`);
|