typenative 0.7.0 → 0.7.1

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.
Files changed (217) hide show
  1. package/bin/node/assert.js +2 -2
  2. package/bin/node/child_process.js +66 -8
  3. package/bin/node/fs.js +1012 -4
  4. package/bin/node/histogram.js +1991 -0
  5. package/bin/node/process.js +14 -2
  6. package/bin/node/sqlite.js +1488 -5
  7. package/bin/node/stream.js +2 -1
  8. package/bin/node/system_extra.js +3 -270
  9. package/bin/node/test.js +39 -1
  10. package/bin/node/test_report.js +47 -1
  11. package/bin/node/test_run.js +57 -2
  12. package/bin/node/util.js +8 -5
  13. package/bin/node/webassembly.js +20 -5
  14. package/bin/node/webview.js +3257 -244
  15. package/bin/node/zlib.js +118 -14
  16. package/bin/node/zlib_iter.js +585 -0
  17. package/bin/transpiler.js +1370 -258
  18. package/bin/version.js +1 -1
  19. package/govendor/software.sslmate.com/src/go-pkcs12/.gitattributes +10 -0
  20. package/govendor/software.sslmate.com/src/go-pkcs12/LICENSE +28 -0
  21. package/govendor/software.sslmate.com/src/go-pkcs12/README.md +31 -0
  22. package/govendor/software.sslmate.com/src/go-pkcs12/bmp-string.go +63 -0
  23. package/govendor/software.sslmate.com/src/go-pkcs12/crypto.go +331 -0
  24. package/govendor/software.sslmate.com/src/go-pkcs12/errors.go +23 -0
  25. package/govendor/software.sslmate.com/src/go-pkcs12/go.mod +3 -0
  26. package/govendor/software.sslmate.com/src/go-pkcs12/internal/rc2/rc2.go +271 -0
  27. package/govendor/software.sslmate.com/src/go-pkcs12/mac.go +202 -0
  28. package/govendor/software.sslmate.com/src/go-pkcs12/pbkdf.go +184 -0
  29. package/govendor/software.sslmate.com/src/go-pkcs12/pkcs12.go +1000 -0
  30. package/govendor/software.sslmate.com/src/go-pkcs12/safebags.go +107 -0
  31. package/package.json +10 -1
  32. package/types/tsconfig.json +17 -0
  33. package/types/typenative-npm.d.ts +492 -12
  34. package/types/typenative.d.ts +88 -2
  35. package/.gitattributes +0 -1
  36. package/.github/workflows/ci.yml +0 -68
  37. package/.github/workflows/npm-publish-github-packages.yml +0 -88
  38. package/CHANGELOG.md +0 -1746
  39. package/CONTRIBUTION.md +0 -133
  40. package/conformance.md +0 -1497
  41. package/examples/README.md +0 -114
  42. package/examples/angular-templates/README.md +0 -141
  43. package/examples/angular-templates/bench.mjs +0 -173
  44. package/examples/angular-templates/dom-type-globals.d.ts +0 -21
  45. package/examples/angular-templates/dom-type-stubs.ts +0 -21
  46. package/examples/angular-templates/main.ts +0 -135
  47. package/examples/angular-templates/parity.mjs +0 -157
  48. package/examples/angular-templates/run-node.mjs +0 -69
  49. package/examples/angular-templates/vendor/angular/compiler/LICENSE +0 -21
  50. package/examples/desktop-notes/README.md +0 -106
  51. package/examples/desktop-notes/bench.mjs +0 -125
  52. package/examples/desktop-notes/main.ts +0 -131
  53. package/examples/desktop-notes/package-lock.json +0 -726
  54. package/examples/desktop-notes/package.json +0 -9
  55. package/examples/desktop-notes/ui.ts +0 -176
  56. package/examples/dupe-finder/README.md +0 -78
  57. package/examples/dupe-finder/bench.mjs +0 -120
  58. package/examples/dupe-finder/main.ts +0 -87
  59. package/examples/fibonacci/README.md +0 -89
  60. package/examples/fibonacci/bench.mjs +0 -87
  61. package/examples/fibonacci/main.ts +0 -21
  62. package/examples/hello-world/README.md +0 -62
  63. package/examples/hello-world/bench.mjs +0 -66
  64. package/examples/hello-world/main.ts +0 -7
  65. package/examples/json-server/README.md +0 -132
  66. package/examples/json-server/bench.mjs +0 -263
  67. package/examples/json-server/main.ts +0 -67
  68. package/examples/mandelbrot-png/README.md +0 -63
  69. package/examples/mandelbrot-png/bench.mjs +0 -95
  70. package/examples/mandelbrot-png/main.ts +0 -98
  71. package/examples/mandelbrot-png/preview.png +0 -0
  72. package/examples/marked-cli/README.md +0 -174
  73. package/examples/marked-cli/bench.mjs +0 -178
  74. package/examples/marked-cli/main.ts +0 -410
  75. package/examples/marked-cli/parity.mjs +0 -185
  76. package/examples/marked-cli/vendor/marked/LICENSE +0 -44
  77. package/examples/marked-cli/vendor/marked/VENDOR.md +0 -26
  78. package/examples/openai-chat/README.md +0 -148
  79. package/examples/openai-chat/bench.mjs +0 -175
  80. package/examples/openai-chat/main.ts +0 -488
  81. package/examples/react-compiler/README.md +0 -185
  82. package/examples/react-compiler/bench.mjs +0 -181
  83. package/examples/react-compiler/main.ts +0 -324
  84. package/examples/react-compiler/parity.mjs +0 -362
  85. package/examples/react-compiler/run-node.mjs +0 -90
  86. package/examples/react-compiler/vendor/babel/LICENSE +0 -22
  87. package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-lower.json +0 -15
  88. package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-upper.json +0 -51
  89. package/examples/react-compiler/vendor/charcodes/package.json +0 -25
  90. package/examples/react-compiler/vendor/invariant/LICENSE +0 -21
  91. package/examples/react-compiler/vendor/invariant/invariant.cjs +0 -51
  92. package/examples/react-compiler/vendor/invariant/invariant.d.cts +0 -11
  93. package/examples/react-compiler/vendor/invariant/types/LICENSE +0 -21
  94. package/examples/react-compiler/vendor/jridgewell/gen-mapping/LICENSE +0 -19
  95. package/examples/react-compiler/vendor/jridgewell/resolve-uri/LICENSE +0 -19
  96. package/examples/react-compiler/vendor/jridgewell/sourcemap-codec/LICENSE +0 -19
  97. package/examples/react-compiler/vendor/jridgewell/trace-mapping/LICENSE +0 -19
  98. package/examples/react-compiler/vendor/js-tokens/LICENSE +0 -21
  99. package/examples/react-compiler/vendor/js-tokens/index.cjs +0 -23
  100. package/examples/react-compiler/vendor/js-tokens/index.d.cts +0 -13
  101. package/examples/react-compiler/vendor/jsesc/LICENSE-MIT.txt +0 -20
  102. package/examples/react-compiler/vendor/jsesc/jsesc.cjs +0 -337
  103. package/examples/react-compiler/vendor/jsesc/jsesc.d.cts +0 -384
  104. package/examples/react-compiler/vendor/jsesc/types/LICENSE +0 -21
  105. package/examples/react-compiler/vendor/picocolors/LICENSE +0 -15
  106. package/examples/react-compiler/vendor/picocolors/picocolors.cjs +0 -75
  107. package/examples/react-compiler/vendor/picocolors/picocolors.d.cts +0 -5
  108. package/examples/react-compiler/vendor/picocolors/types.d.ts +0 -51
  109. package/examples/react-compiler/vendor/react-compiler/LICENSE +0 -21
  110. package/examples/react-compiler/vendor/stubs/babel-core.ts +0 -31
  111. package/examples/react-compiler/vendor/stubs/debug.ts +0 -18
  112. package/examples/react-compiler/vendor/stubs/js-tokens.d.ts +0 -13
  113. package/examples/react-compiler/vendor/stubs/pretty-format.ts +0 -18
  114. package/examples/react-compiler/vendor/zod/LICENSE +0 -21
  115. package/examples/react-compiler/vendor/zod-validation-error/LICENSE +0 -9
  116. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/NonEmptyArray.ts +0 -5
  117. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinPath.ts +0 -49
  118. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinValues.ts +0 -48
  119. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/stringify.ts +0 -50
  120. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/titleCase.ts +0 -6
  121. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/MessageBuilder.ts +0 -126
  122. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/ValidationError.ts +0 -39
  123. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/custom.ts +0 -12
  124. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/errorMap.ts +0 -78
  125. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/index.ts +0 -2
  126. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidElement.ts +0 -12
  127. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidKey.ts +0 -12
  128. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidStringFormat.ts +0 -131
  129. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidType.ts +0 -54
  130. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidUnion.ts +0 -12
  131. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidValue.ts +0 -40
  132. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/notMultipleOf.ts +0 -12
  133. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooBig.ts +0 -76
  134. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooSmall.ts +0 -76
  135. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/types.ts +0 -27
  136. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/unrecognizedKeys.ts +0 -27
  137. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromError.ts +0 -13
  138. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodError.ts +0 -61
  139. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodIssue.ts +0 -38
  140. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/index.ts +0 -20
  141. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationError.ts +0 -5
  142. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationErrorLike.ts +0 -8
  143. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isZodErrorLike.ts +0 -11
  144. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/toValidationError.ts +0 -20
  145. package/examples/react-compiler/vendor.mjs +0 -688
  146. package/examples/todo-cli/README.md +0 -69
  147. package/examples/todo-cli/bench.mjs +0 -89
  148. package/examples/todo-cli/main.ts +0 -92
  149. package/examples/yaml-cli/README.md +0 -152
  150. package/examples/yaml-cli/bench.mjs +0 -265
  151. package/examples/yaml-cli/main.ts +0 -251
  152. package/examples/yaml-cli/parity.mjs +0 -156
  153. package/examples/yaml-cli/vendor/yaml/LICENSE +0 -13
  154. package/examples/yaml-cli/vendor/yaml/VENDOR.md +0 -25
  155. package/performance/README.md +0 -248
  156. package/performance/any-dynamic.ts +0 -21
  157. package/performance/any-record-view.ts +0 -20
  158. package/performance/arr-for-of.ts +0 -29
  159. package/performance/arr-hof.ts +0 -21
  160. package/performance/arr-push-index.ts +0 -15
  161. package/performance/arr-push-local.ts +0 -39
  162. package/performance/arr-slice-concat.ts +0 -24
  163. package/performance/arr-sort.ts +0 -21
  164. package/performance/async-await.ts +0 -24
  165. package/performance/async-promise-all.ts +0 -38
  166. package/performance/bigint-arith.ts +0 -36
  167. package/performance/buf-encode.ts +0 -29
  168. package/performance/class-accessors.ts +0 -48
  169. package/performance/class-dispatch.ts +0 -52
  170. package/performance/date-format.ts +0 -18
  171. package/performance/events-emit.ts +0 -27
  172. package/performance/exc-throw-rare.ts +0 -25
  173. package/performance/exc-try-catch.ts +0 -26
  174. package/performance/fn-closures.ts +0 -29
  175. package/performance/fn-recursion-tree.ts +0 -31
  176. package/performance/fn-rest-spread.ts +0 -43
  177. package/performance/gen-for-of.ts +0 -46
  178. package/performance/gen-next.ts +0 -32
  179. package/performance/iter-helpers.ts +0 -38
  180. package/performance/json-any.ts +0 -30
  181. package/performance/json-roundtrip.ts +0 -27
  182. package/performance/map-delete.ts +0 -24
  183. package/performance/map-iterate.ts +0 -26
  184. package/performance/map-number-keys.ts +0 -37
  185. package/performance/map-string-keys.ts +0 -22
  186. package/performance/num-arith-loop.ts +0 -14
  187. package/performance/num-bitwise.ts +0 -21
  188. package/performance/num-hash-imul.ts +0 -36
  189. package/performance/num-mod-int.ts +0 -16
  190. package/performance/num-to-string.ts +0 -16
  191. package/performance/obj-alloc.ts +0 -32
  192. package/performance/obj-keys-entries.ts +0 -44
  193. package/performance/obj-optional-chain.ts +0 -42
  194. package/performance/obj-record-dict.ts +0 -24
  195. package/performance/obj-spread-destructure.ts +0 -40
  196. package/performance/regex-exec.ts +0 -29
  197. package/performance/regex-replace-fn.ts +0 -24
  198. package/performance/regex-site.ts +0 -28
  199. package/performance/set-ops.ts +0 -20
  200. package/performance/str-char-scan.ts +0 -35
  201. package/performance/str-concat-plus.ts +0 -18
  202. package/performance/str-concat.ts +0 -24
  203. package/performance/str-methods.ts +0 -24
  204. package/performance/str-short-scan.ts +0 -26
  205. package/performance/str-split-join.ts +0 -23
  206. package/performance/str-switch-compare.ts +0 -50
  207. package/performance/str-template.ts +0 -16
  208. package/performance/str-unicode.ts +0 -25
  209. package/performance/typed-array.ts +0 -30
  210. package/performance/union-switch.ts +0 -57
  211. package/performance/union-typeof.ts +0 -40
  212. package/performance/wasm-call.ts +0 -63
  213. package/tsparser/check.go +0 -158
  214. package/tsparser/go.mod +0 -14
  215. package/tsparser/go.sum +0 -22
  216. package/tsparser/main.go +0 -363
  217. package/tsparser/tsparser.exe +0 -4
@@ -1,362 +0,0 @@
1
- // Parity check: Node.js vs the TypeNative build of the React Compiler.
2
- //
3
- // Compiles main.ts to a native binary with the TypeNative CLI from this repo
4
- // checkout, then runs the vendored React Compiler over each fixture below with
5
- // both runtimes. stdout, stderr and the exit code must match byte for byte —
6
- // including the `// CompileSuccess`/`// CompileError` lines the compiler's
7
- // logger produces, so memo slot and block counts are checked too. Failures are
8
- // written to .cache/failures/.
9
- //
10
- // The fixtures mirror what the compiler's own test fixtures cover: components
11
- // and hooks, the compiler's test pragmas on the first line, JSX with
12
- // conditionals, lists and event handlers, and the error paths (a compile
13
- // error, a skipped function, an unparseable file).
14
- //
15
- // Usage: node parity.mjs [filter] (filter: a substring of a fixture name)
16
-
17
- import { spawn, spawnSync } from 'node:child_process';
18
- import fs from 'node:fs';
19
- import os from 'node:os';
20
- import path from 'node:path';
21
- import { fileURLToPath } from 'node:url';
22
-
23
- const here = path.dirname(fileURLToPath(import.meta.url));
24
- const repoRoot = path.resolve(here, '..', '..');
25
- const cli = path.join(repoRoot, 'bin', 'cli.js');
26
- const cache = path.join(here, '.cache');
27
- const fixturesDir = path.join(cache, 'fixtures');
28
- const failuresDir = path.join(cache, 'failures');
29
- const exePath = path.join(cache, process.platform === 'win32' ? 'react-compile.exe' : 'react-compile');
30
- const filter = process.argv[2] ?? '';
31
-
32
- function run(command, args, options = {}) {
33
- const result = spawnSync(command, args, { stdio: 'inherit', ...options });
34
- if (result.status !== 0) {
35
- console.error(`${command} ${args.join(' ')} failed`);
36
- process.exit(1);
37
- }
38
- }
39
-
40
- // A component with hooks, a derived list, conditionals and event handlers,
41
- // the shape of a real screen
42
- const todoList = `// @compilationMode:"infer"
43
- import { useState } from 'react';
44
-
45
- export function TodoList({ todos, filter, onToggle }) {
46
- const [query, setQuery] = useState('');
47
- const visible = todos.filter(
48
- (todo) => (filter === 'all' || todo.status === filter) && todo.title.includes(query),
49
- );
50
- const remaining = todos.filter((todo) => todo.status !== 'done').length;
51
-
52
- if (todos.length === 0) {
53
- return <p className="empty">Nothing to do</p>;
54
- }
55
- return (
56
- <section>
57
- <input value={query} onChange={(e) => setQuery(e.target.value)} placeholder="Search" />
58
- <ul>
59
- {visible.map((todo) => (
60
- <li key={todo.id} className={todo.status} onClick={() => onToggle(todo.id)}>
61
- {todo.title}
62
- </li>
63
- ))}
64
- </ul>
65
- <footer>{remaining} of {todos.length} left</footer>
66
- </section>
67
- );
68
- }
69
-
70
- export function useTotal(items, taxRate) {
71
- const subtotal = items.reduce((sum, item) => sum + item.price * item.quantity, 0);
72
- const tax = subtotal * taxRate;
73
- return { subtotal, tax, total: subtotal + tax };
74
- }
75
- `;
76
-
77
- const FIXTURES = {
78
- // The example's built-in demo (infer mode: only components and hooks)
79
- 'demo-infer': todoList,
80
- // All mode: plain functions compile too (memo slots on every function)
81
- 'mode-all': `import { useState } from 'react';
82
-
83
- export function Component({ label }) {
84
- const [count, setCount] = useState(0);
85
- return (
86
- <button onClick={() => setCount(count + 1)}>
87
- {label}: {count}
88
- </button>
89
- );
90
- }
91
-
92
- function helper(values) {
93
- return values.map((v) => v * 2).join(',');
94
- }
95
- `,
96
- // Annotation mode: only "use memo" functions compile, others are skipped
97
- 'mode-annotation': `// @compilationMode:"annotation"
98
- export function Component({ items }) {
99
- "use memo";
100
- return <ul>{items.map((item) => <li key={item.id}>{item.title}</li>)}</ul>;
101
- }
102
-
103
- export function Skipped({ items }) {
104
- return <ul>{items.map((item) => <li key={item.id}>{item.title}</li>)}</ul>;
105
- }
106
- `,
107
- // JSX outlining: large JSX subtrees are extracted into their own functions
108
- 'jsx-outlining': `// @enableJsxOutlining
109
- export function Dashboard({ user, stats, onRefresh }) {
110
- const unread = stats.filter((s) => !s.read).length;
111
- return (
112
- <div className="dashboard">
113
- <header>
114
- <h1>Welcome back, {user.name}</h1>
115
- <span className={unread > 0 ? 'badge active' : 'badge'}>{unread} unread</span>
116
- <button onClick={() => onRefresh()}>Refresh</button>
117
- </header>
118
- <main>
119
- {stats.map((stat) => (
120
- <div key={stat.id} className="stat">
121
- <h3>{stat.title}</h3>
122
- <p>{stat.value}</p>
123
- </div>
124
- ))}
125
- </main>
126
- <footer>{user.email}</footer>
127
- </div>
128
- );
129
- }
130
- `,
131
- // Hooks through a custom hook, mutable refs, effects
132
- 'hooks-and-refs': `import { useEffect, useRef, useState } from 'react';
133
-
134
- export function useCounter(start) {
135
- const [count, setCount] = useState(start);
136
- const increment = () => setCount((c) => c + 1);
137
- const reset = () => setCount(start);
138
- return { count, increment, reset };
139
- }
140
-
141
- export function Stopwatch({ running }) {
142
- const { count, increment, reset } = useCounter(0);
143
- const last = useRef(null);
144
- useEffect(() => {
145
- last.current = count;
146
- }, [count]);
147
- return (
148
- <p onClick={increment} onDoubleClick={reset}>
149
- {count} (was {last.current})
150
- </p>
151
- );
152
- }
153
- `,
154
- // Control flow: nested conditionals, ternaries, fragments, void tags
155
- 'control-flow': `export function Panel({ open, kind, children }) {
156
- if (!open) {
157
- return null;
158
- }
159
- return (
160
- <>
161
- <div className={kind === 'error' ? 'panel error' : 'panel'}>
162
- {kind === 'error' ? <strong>Something went wrong</strong> : <span>Info</span>}
163
- {children}
164
- <br />
165
- <hr />
166
- </div>
167
- <img src="x.png" alt="an image" />
168
- </>
169
- );
170
- }
171
- `,
172
- // Values captured by closures stay reactive; destructuring in parameters
173
- 'closures-and-destructuring': `import { useMemo, useState } from 'react';
174
-
175
- export function SortableList({ entries, compare }) {
176
- const [key, setKey] = useState('name');
177
- const [reverse, setReverse] = useState(false);
178
- const sorted = useMemo(() => {
179
- const copy = [...entries];
180
- copy.sort((a, b) => (a[key] < b[key] ? -1 : 1));
181
- if (reverse) copy.reverse();
182
- return copy;
183
- }, [entries, key, reverse]);
184
- return (
185
- <ol data-key={key}>
186
- {sorted.map(({ id, name }) => (
187
- <li key={id} onClick={() => setKey(name)}>
188
- {name}
189
- </li>
190
- ))}
191
- <li onClick={() => setReverse(!reverse)}>reverse</li>
192
- </ol>
193
- );
194
- }
195
- `,
196
- // "use no memo": the compiler skips the function and logs why
197
- 'skip-use-no-memo': `export function Unmemoized({ text }) {
198
- "use no memo";
199
- return <p>{text}</p>;
200
- }
201
-
202
- export function Memoized({ text }) {
203
- return <p>{text}</p>;
204
- }
205
- `,
206
- // A compile error: hooks cannot run conditionally
207
- 'error-conditional-hook': `import { useState } from 'react';
208
-
209
- export function Component({ enabled }) {
210
- if (enabled) {
211
- const [value, setValue] = useState(0);
212
- return <button onClick={() => setValue(value + 1)}>{value}</button>;
213
- }
214
- return null;
215
- }
216
- `,
217
- // A compile error: mutating props during render
218
- 'error-mutate-prop': `export function Component({ items }) {
219
- items.sort((a, b) => a.id - b.id);
220
- return items.map((item) => <li key={item.id}>{item.title}</li>);
221
- }
222
- `,
223
- // A compile error: unknown hook-like call in a component
224
- 'error-unknown-hook': `import { useUnknown } from 'somewhere';
225
-
226
- export function Component() {
227
- const value = useUnknown();
228
- return <p>{value}</p>;
229
- }
230
- `,
231
- // A file the parser rejects: the error is printed as a comment, exit 1
232
- 'parse-error': `export function Broken({
233
- return <div>never parsed</div>;
234
- }
235
- `,
236
- // TypeScript source: the parser runs with the typescript plugin
237
- 'typescript-syntax': `import { useState } from 'react';
238
-
239
- type Item = { id: number; title: string; done?: boolean };
240
-
241
- export function Checklist({ initial }: { initial: Item[] }) {
242
- const [items, setItems] = useState<Item[]>(initial);
243
- const done = items.filter((item): item is Item & { done: true } => item.done === true).length;
244
- return (
245
- <ul>
246
- {items.map((item) => (
247
- <li key={item.id} onClick={() => setItems(items.map((i) => (i.id === item.id ? { ...i, done: !i.done } : i)))}>
248
- {item.done ? '\\u2713' : '\\u25cb'} {item.title}
249
- </li>
250
- ))}
251
- <footer>{done}/{items.length} done</footer>
252
- </ul>
253
- );
254
- }
255
- `,
256
- // Preserve existing memoization: manual useMemo/useCallback must survive
257
- 'validate-manual-memo': `// @validatePreserveExistingMemoizationGuarantees
258
- import { useCallback, useMemo } from 'react';
259
-
260
- export function Grid({ rows, cols, onSelect }) {
261
- const cells = useMemo(() => {
262
- const out = [];
263
- for (const row of rows) {
264
- for (const col of cols) {
265
- out.push({ row, col });
266
- }
267
- }
268
- return out;
269
- }, [rows, cols]);
270
- const select = useCallback((cell) => onSelect(cell.row, cell.col), [onSelect]);
271
- return (
272
- <table>
273
- {cells.map((cell) => (
274
- <td key={\`\${cell.row}:\${cell.col}\`} onClick={() => select(cell)}>
275
- {cell.row} / {cell.col}
276
- </td>
277
- ))}
278
- </table>
279
- );
280
- }
281
- `,
282
- // State updates in effects and event handlers; optional chaining
283
- 'effects-and-optional-chains': `import { useEffect, useState } from 'react';
284
-
285
- export function Ticker({ interval, onPause }) {
286
- const [ticks, setTicks] = useState(0);
287
- useEffect(() => {
288
- if (interval == null) return;
289
- const id = setInterval(() => setTicks((t) => t + 1), interval);
290
- return () => clearInterval(id);
291
- }, [interval]);
292
- return (
293
- <div>
294
- <span>{ticks} ticks</span>
295
- {onPause != null && <button onClick={() => onPause?.(ticks)}>Pause</button>}
296
- </div>
297
- );
298
- }
299
- `,
300
- };
301
-
302
- function spawnCollect(command, args) {
303
- return new Promise((resolve) => {
304
- const child = spawn(command, args, { cwd: here });
305
- let stdout = '';
306
- let stderr = '';
307
- const timer = setTimeout(() => child.kill('SIGKILL'), 60_000);
308
- child.stdout.on('data', (d) => (stdout += d));
309
- child.stderr.on('data', (d) => (stderr += d));
310
- child.on('close', (code, signal) => {
311
- clearTimeout(timer);
312
- resolve({ stdout, stderr, code: signal ? signal : code });
313
- });
314
- });
315
- }
316
-
317
- const names = Object.keys(FIXTURES).filter((name) => name.includes(filter));
318
- if (names.length === 0) {
319
- console.error(`no fixtures match "${filter}"`);
320
- process.exit(1);
321
- }
322
-
323
- console.log('Compiling main.ts with TypeNative ...');
324
- run(process.execPath, [cli, '--source', path.join(here, 'main.ts'), '--output', exePath], { cwd: repoRoot });
325
- // (the Node build once, up front: fixtures run in parallel, and each
326
- // run-node.mjs would otherwise rebuild a stale cache at the same time)
327
- run(process.execPath, ['run-node.mjs', '--build'], { cwd: here });
328
-
329
- fs.rmSync(failuresDir, { recursive: true, force: true });
330
- fs.mkdirSync(failuresDir, { recursive: true });
331
- fs.mkdirSync(fixturesDir, { recursive: true });
332
-
333
- let passed = 0;
334
- let next = 0;
335
- const failed = [];
336
- async function worker() {
337
- while (next < names.length) {
338
- const index = next++;
339
- const name = names[index];
340
- const file = path.join(fixturesDir, `${name}.jsx`);
341
- fs.writeFileSync(file, FIXTURES[name]);
342
- const [node, native] = await Promise.all([
343
- spawnCollect(process.execPath, ['run-node.mjs', file]),
344
- spawnCollect(exePath, [file])
345
- ]);
346
- if (node.stdout === native.stdout && node.stderr === native.stderr && node.code === native.code) {
347
- passed++;
348
- continue;
349
- }
350
- failed.push(name);
351
- const report = (label, r) => `--- ${label} (exit ${r.code})\n${r.stdout}${r.stderr ? `--- ${label} stderr\n${r.stderr}` : ''}`;
352
- fs.writeFileSync(
353
- path.join(failuresDir, `${index}-${name}.txt`),
354
- `${name}\n--- source\n${FIXTURES[name]}\n${report('node', node)}${report('native', native)}`
355
- );
356
- }
357
- }
358
- await Promise.all(Array.from({ length: Math.max(1, Math.min(8, os.availableParallelism() - 1)) }, worker));
359
-
360
- for (const name of failed.sort()) console.log(`FAIL ${name}`);
361
- console.log(`${passed}/${names.length} fixtures match (${((100 * passed) / Math.max(1, names.length)).toFixed(2)}%)`);
362
- process.exitCode = failed.length > 0 ? 1 : 0;
@@ -1,90 +0,0 @@
1
- // Runs main.ts under Node.js, compiled to JavaScript.
2
- //
3
- // Node runs TypeScript itself only by stripping types, and the React
4
- // Compiler's source uses enums, which that mode rejects. So this compiles
5
- // main.ts and every file it imports to JavaScript with the `typescript`
6
- // package of this repository (into .cache/node/, rebuilt when a source file
7
- // is newer than the build), then runs .cache/node/main.js with the given
8
- // arguments. That is also how the compiler runs for Node users: the
9
- // published babel-plugin-react-compiler is JavaScript.
10
- //
11
- // Usage: node run-node.mjs [file.jsx]
12
- // node run-node.mjs --build (build only; used by parity.mjs and bench.mjs)
13
-
14
- import fs from 'node:fs';
15
- import { createRequire } from 'node:module';
16
- import path from 'node:path';
17
- import { fileURLToPath, pathToFileURL } from 'node:url';
18
-
19
- const here = path.dirname(fileURLToPath(import.meta.url));
20
- const outDir = path.join(here, '.cache', 'node');
21
- export const nodeMain = path.join(outDir, 'main.js');
22
-
23
- function newestSource(dir, newest = 0) {
24
- for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
25
- const full = path.join(dir, entry.name);
26
- if (entry.isDirectory()) newest = newestSource(full, newest);
27
- else newest = Math.max(newest, fs.statSync(full).mtimeMs);
28
- }
29
- return newest;
30
- }
31
-
32
- export function buildNode() {
33
- const sources = Math.max(fs.statSync(path.join(here, 'main.ts')).mtimeMs, newestSource(path.join(here, 'vendor')));
34
- if (fs.existsSync(nodeMain) && fs.statSync(nodeMain).mtimeMs >= sources) return;
35
-
36
- const ts = createRequire(path.join(here, '..', '..', 'package.json'))('typescript');
37
- fs.rmSync(outDir, { recursive: true, force: true });
38
- const program = ts.createProgram([path.join(here, 'main.ts')], {
39
- target: ts.ScriptTarget.ES2024,
40
- module: ts.ModuleKind.ESNext,
41
- moduleResolution: ts.ModuleResolutionKind.Bundler,
42
- rewriteRelativeImportExtensions: true,
43
- allowImportingTsExtensions: true,
44
- resolveJsonModule: true,
45
- esModuleInterop: true,
46
- useDefineForClassFields: false,
47
- lib: [],
48
- types: [],
49
- noLib: true,
50
- noCheck: true,
51
- skipLibCheck: true,
52
- rootDir: here,
53
- outDir,
54
- });
55
- const result = program.emit();
56
- for (const d of result.diagnostics) console.error(ts.flattenDiagnosticMessageText(d.messageText, '\n'));
57
- // CommonJS (.cjs) and JSON files are imported as they are
58
- for (const file of program.getSourceFiles()) {
59
- const name = file.fileName;
60
- if (!name.startsWith(here) || name.endsWith('.ts') || name.endsWith('.cts') || name.endsWith('package.json')) continue;
61
- copy(name);
62
- }
63
- copyNonTs(path.join(here, 'vendor'));
64
- fs.writeFileSync(path.join(outDir, 'package.json'), '{ "type": "module" }\n');
65
- }
66
-
67
- function copy(file) {
68
- const dest = path.join(outDir, path.relative(here, file));
69
- fs.mkdirSync(path.dirname(dest), { recursive: true });
70
- fs.copyFileSync(file, dest);
71
- }
72
-
73
- function copyNonTs(dir) {
74
- for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
75
- const full = path.join(dir, entry.name);
76
- if (entry.isDirectory()) copyNonTs(full);
77
- // (not the package.json files kept for their license fields)
78
- else if (entry.name.endsWith('.cjs') || (entry.name.endsWith('.json') && entry.name !== 'package.json')) copy(full);
79
- }
80
- }
81
-
82
- if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
83
- buildNode();
84
- if (process.argv[2] !== '--build') {
85
- process.argv = [process.argv[0], nodeMain, ...process.argv.slice(2)];
86
- // (a worker process the compiler spawns runs this same module)
87
- process.env.TN_NODE_MAIN = nodeMain;
88
- await import(pathToFileURL(nodeMain).href);
89
- }
90
- }
@@ -1,22 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2014-present Sebastian McKenzie and other contributors
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,15 +0,0 @@
1
- [
2
- "decodeURI",
3
- "decodeURIComponent",
4
- "encodeURI",
5
- "encodeURIComponent",
6
- "escape",
7
- "eval",
8
- "globalThis",
9
- "isFinite",
10
- "isNaN",
11
- "parseFloat",
12
- "parseInt",
13
- "undefined",
14
- "unescape"
15
- ]
@@ -1,51 +0,0 @@
1
- [
2
- "AggregateError",
3
- "Array",
4
- "ArrayBuffer",
5
- "Atomics",
6
- "BigInt",
7
- "BigInt64Array",
8
- "BigUint64Array",
9
- "Boolean",
10
- "DataView",
11
- "Date",
12
- "Error",
13
- "EvalError",
14
- "FinalizationRegistry",
15
- "Float16Array",
16
- "Float32Array",
17
- "Float64Array",
18
- "Function",
19
- "Infinity",
20
- "Int16Array",
21
- "Int32Array",
22
- "Int8Array",
23
- "Intl",
24
- "Iterator",
25
- "JSON",
26
- "Map",
27
- "Math",
28
- "NaN",
29
- "Number",
30
- "Object",
31
- "Promise",
32
- "Proxy",
33
- "RangeError",
34
- "ReferenceError",
35
- "Reflect",
36
- "RegExp",
37
- "Set",
38
- "SharedArrayBuffer",
39
- "String",
40
- "Symbol",
41
- "SyntaxError",
42
- "TypeError",
43
- "Uint16Array",
44
- "Uint32Array",
45
- "Uint8Array",
46
- "Uint8ClampedArray",
47
- "URIError",
48
- "WeakMap",
49
- "WeakRef",
50
- "WeakSet"
51
- ]
@@ -1,25 +0,0 @@
1
- {
2
- "name": "charcodes",
3
- "version": "0.2.1",
4
- "description": "Char codes constants",
5
- "main": "lib/index.js",
6
- "module": "lib/index.mjs",
7
- "repository": {
8
- "type": "git",
9
- "url": "git+https://github.com/xtuc/charcodes.git"
10
- },
11
- "engines": {
12
- "node": ">=6"
13
- },
14
- "keywords": [
15
- "charcodes",
16
- "ascii",
17
- "constants"
18
- ],
19
- "author": "Sven Sauleau",
20
- "license": "MIT",
21
- "bugs": {
22
- "url": "https://github.com/xtuc/charcodes/issues"
23
- },
24
- "homepage": "https://github.com/xtuc/charcodes#readme"
25
- }
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2013-present, Facebook, Inc.
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,51 +0,0 @@
1
- /**
2
- * Copyright (c) 2013-present, Facebook, Inc.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- 'use strict';
9
-
10
- /**
11
- * Use invariant() to assert state which your program assumes to be true.
12
- *
13
- * Provide sprintf-style format (only %s is supported) and arguments
14
- * to provide information about what broke and what you were
15
- * expecting.
16
- *
17
- * The invariant message will be stripped in production, but the invariant
18
- * will remain to ensure logic does not differ in production.
19
- */
20
-
21
- var NODE_ENV = process.env.NODE_ENV;
22
-
23
- var invariant = function(condition, format, a, b, c, d, e, f) {
24
- if (NODE_ENV !== 'production') {
25
- if (format === undefined) {
26
- throw new Error('invariant requires an error message argument');
27
- }
28
- }
29
-
30
- if (!condition) {
31
- var error;
32
- if (format === undefined) {
33
- error = new Error(
34
- 'Minified exception occurred; use the non-minified dev environment ' +
35
- 'for the full error message and additional helpful warnings.'
36
- );
37
- } else {
38
- var args = [a, b, c, d, e, f];
39
- var argIndex = 0;
40
- error = new Error(
41
- format.replace(/%s/g, function() { return args[argIndex++]; })
42
- );
43
- error.name = 'Invariant Violation';
44
- }
45
-
46
- error.framesToPop = 1; // we don't care about invariant's own frame
47
- throw error;
48
- }
49
- };
50
-
51
- module.exports = invariant;
@@ -1,11 +0,0 @@
1
- declare let invariant: invariant.InvariantStatic;
2
-
3
- export = invariant;
4
- export as namespace invariant;
5
-
6
- declare namespace invariant {
7
- interface InvariantStatic {
8
- (testValue: false, format: string, ...extra: any[]): never;
9
- (testValue: any, format: string, ...extra: any[]): asserts testValue;
10
- }
11
- }
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) Microsoft Corporation.
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE