typenative 0.5.0 → 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 +271 -1
- package/CONTRIBUTION.md +2 -1
- package/README.md +15 -7
- package/bin/cli.js +1 -0
- package/bin/index.js +62 -3
- package/bin/main.js +1 -0
- package/bin/node/core.js +41 -0
- package/bin/node/events.js +15 -10
- package/bin/node/process.js +13 -0
- package/bin/node/punycode.js +2 -2
- package/bin/node/timers.js +4 -2
- package/bin/node/url.js +1 -1
- package/bin/parse-node.js +2 -2
- package/bin/regex_vm.js +2057 -0
- package/bin/transpiler.js +17225 -4830
- package/bin/typecheck-node.js +2 -1
- package/bin/version.js +1 -1
- package/conformance.md +57 -15
- package/examples/README.md +46 -23
- 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 +11 -13
- package/examples/dupe-finder/README.md +7 -5
- 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 +11 -13
- package/examples/marked-cli/README.md +38 -37
- 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 +9 -9
- package/examples/yaml-cli/README.md +38 -28
- 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 +1 -0
- package/types/typenative-npm.d.ts +3 -2
- package/types/typenative.d.ts +42 -12
- package/ROUND2-HANDOFF.md +0 -200
package/types/typenative.d.ts
CHANGED
|
@@ -24,8 +24,11 @@ interface CallableFunction extends Function {
|
|
|
24
24
|
}
|
|
25
25
|
interface NewableFunction extends Function {}
|
|
26
26
|
|
|
27
|
-
/** The global `Function` as a value: an opaque constructor (`x instanceof Function` checks for a function)
|
|
28
|
-
interface FunctionConstructor extends Function {
|
|
27
|
+
/** The global `Function` as a value: an opaque constructor (`x instanceof Function` checks for a function). `new Function(...)` compiles to a binary that throws if the program ever calls the result: a native binary cannot evaluate dynamic code */
|
|
28
|
+
interface FunctionConstructor extends Function {
|
|
29
|
+
new (...args: string[]): Function;
|
|
30
|
+
(...args: string[]): Function;
|
|
31
|
+
}
|
|
29
32
|
declare var Function: FunctionConstructor;
|
|
30
33
|
|
|
31
34
|
interface IArguments {
|
|
@@ -40,6 +43,8 @@ interface Number {
|
|
|
40
43
|
toExponential(fractionDigits?: number): string;
|
|
41
44
|
}
|
|
42
45
|
|
|
46
|
+
type PropertyKey = string | number | symbol;
|
|
47
|
+
|
|
43
48
|
interface Object {
|
|
44
49
|
constructor: Function;
|
|
45
50
|
toString(): string;
|
|
@@ -169,6 +174,7 @@ interface RegExp {
|
|
|
169
174
|
readonly multiline: boolean;
|
|
170
175
|
readonly dotAll: boolean;
|
|
171
176
|
readonly unicode: boolean;
|
|
177
|
+
readonly unicodeSets: boolean;
|
|
172
178
|
readonly sticky: boolean;
|
|
173
179
|
test(string: string): boolean;
|
|
174
180
|
exec(string: string): RegExpExecArray | null;
|
|
@@ -257,23 +263,23 @@ interface Array<T> extends IterableIterator<T> {
|
|
|
257
263
|
/**
|
|
258
264
|
* Performs the callback for each element.
|
|
259
265
|
*/
|
|
260
|
-
forEach(callback: (value: T, index
|
|
266
|
+
forEach(callback: (value: T, index: number, array: T[]) => void): void;
|
|
261
267
|
/**
|
|
262
268
|
* Calls the callback function on each element of the array, accumulating a result.
|
|
263
269
|
*/
|
|
264
270
|
reduce<U>(
|
|
265
|
-
callback: (accumulator: U, value: T, index
|
|
271
|
+
callback: (accumulator: U, value: T, index: number, array: T[]) => U,
|
|
266
272
|
initialValue: U
|
|
267
273
|
): U;
|
|
268
|
-
reduce(callback: (accumulator: T, value: T, index
|
|
274
|
+
reduce(callback: (accumulator: T, value: T, index: number, array: T[]) => T): T;
|
|
269
275
|
/**
|
|
270
276
|
* Calls the callback function on each element of the array in reverse order, accumulating a result.
|
|
271
277
|
*/
|
|
272
278
|
reduceRight<U>(
|
|
273
|
-
callback: (accumulator: U, value: T, index
|
|
279
|
+
callback: (accumulator: U, value: T, index: number, array: T[]) => U,
|
|
274
280
|
initialValue: U
|
|
275
281
|
): U;
|
|
276
|
-
reduceRight(callback: (accumulator: T, value: T, index
|
|
282
|
+
reduceRight(callback: (accumulator: T, value: T, index: number, array: T[]) => T): T;
|
|
277
283
|
/**
|
|
278
284
|
* Returns the index of the first occurrence of a value in an array, or -1 if it is not present.
|
|
279
285
|
*/
|
|
@@ -329,8 +335,8 @@ interface Array<T> extends IterableIterator<T> {
|
|
|
329
335
|
/**
|
|
330
336
|
* Returns a new array formed by applying callback to each element and then flattening.
|
|
331
337
|
*/
|
|
332
|
-
flat(): T[];
|
|
333
|
-
flatMap<U>(callback: (value: T, index
|
|
338
|
+
flat(depth?: number): T[];
|
|
339
|
+
flatMap<U>(callback: (value: T, index: number, array: T[]) => U[]): U[];
|
|
334
340
|
/**
|
|
335
341
|
* Returns a copy of a section of an array with the fill value applied.
|
|
336
342
|
*/
|
|
@@ -359,9 +365,14 @@ interface Array<T> extends IterableIterator<T> {
|
|
|
359
365
|
[n: number]: T;
|
|
360
366
|
}
|
|
361
367
|
|
|
368
|
+
/** The read-only view of a Set: the same values, no mutating members used */
|
|
369
|
+
type ReadonlySet<T> = Set<T>;
|
|
370
|
+
|
|
362
371
|
interface ArrayConstructor {
|
|
363
372
|
new <T>(length: number): T[];
|
|
364
373
|
new <T>(...items: T[]): T[];
|
|
374
|
+
<T>(length: number): T[];
|
|
375
|
+
<T>(...items: T[]): T[];
|
|
365
376
|
isArray(arg: any): arg is any[];
|
|
366
377
|
from<T>(arrayLike: ArrayLike<T> | Iterable<T>): T[];
|
|
367
378
|
from<T, U>(arrayLike: ArrayLike<T> | Iterable<T>, mapFn: (value: T, index: number) => U): U[];
|
|
@@ -395,11 +406,11 @@ interface String {
|
|
|
395
406
|
isWellFormed(): boolean;
|
|
396
407
|
toWellFormed(): string;
|
|
397
408
|
/** Determines whether a string contains the specified substring. */
|
|
398
|
-
includes(searchString: string): boolean;
|
|
409
|
+
includes(searchString: string, position?: number): boolean;
|
|
399
410
|
/** Determines whether a string begins with the specified characters. */
|
|
400
|
-
startsWith(searchString: string): boolean;
|
|
411
|
+
startsWith(searchString: string, position?: number): boolean;
|
|
401
412
|
/** Determines whether a string ends with the specified characters. */
|
|
402
|
-
endsWith(searchString: string): boolean;
|
|
413
|
+
endsWith(searchString: string, endPosition?: number): boolean;
|
|
403
414
|
/** Splits a string into substrings using the specified separator. */
|
|
404
415
|
split(separator: string | RegExp, limit?: number): string[];
|
|
405
416
|
/** Removes whitespace from both ends of a string. */
|
|
@@ -633,6 +644,8 @@ interface ObjectConstructor {
|
|
|
633
644
|
/** An instance's class (null for other values) */
|
|
634
645
|
getPrototypeOf(obj: any): any;
|
|
635
646
|
getOwnPropertyDescriptors<T>(obj: T): { [P in keyof T]: PropertyDescriptor } & { [key: string]: PropertyDescriptor };
|
|
647
|
+
getOwnPropertyDescriptor(obj: any, key: PropertyKey): PropertyDescriptor | undefined;
|
|
648
|
+
getOwnPropertySymbols(obj: any): symbol[];
|
|
636
649
|
getOwnPropertyNames(obj: any): string[];
|
|
637
650
|
freeze<T>(obj: T): T;
|
|
638
651
|
seal<T>(obj: T): T;
|
|
@@ -755,6 +768,10 @@ interface ErrorOptions {
|
|
|
755
768
|
interface ErrorConstructor {
|
|
756
769
|
new (message?: string, options?: ErrorOptions): Error;
|
|
757
770
|
(message?: string, options?: ErrorOptions): Error;
|
|
771
|
+
// (V8's: accepted, without effect — there are no V8 stack frames)
|
|
772
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
773
|
+
stackTraceLimit: number;
|
|
774
|
+
prepareStackTrace?: (err: Error, stackTraces: any[]) => any;
|
|
758
775
|
}
|
|
759
776
|
|
|
760
777
|
declare var Error: ErrorConstructor;
|
|
@@ -1738,3 +1755,16 @@ declare namespace JSX {
|
|
|
1738
1755
|
children: {};
|
|
1739
1756
|
}
|
|
1740
1757
|
}
|
|
1758
|
+
|
|
1759
|
+
// Reflect: the Object operations as functions
|
|
1760
|
+
declare namespace Reflect {
|
|
1761
|
+
function apply(target: Function, thisArgument: any, argumentsList: ArrayLike<any>): any;
|
|
1762
|
+
function defineProperty(target: object, propertyKey: PropertyKey, attributes: PropertyDescriptor): boolean;
|
|
1763
|
+
function deleteProperty(target: object, propertyKey: PropertyKey): boolean;
|
|
1764
|
+
function get(target: object, propertyKey: PropertyKey, receiver?: any): any;
|
|
1765
|
+
function getOwnPropertyDescriptor(target: object, propertyKey: PropertyKey): PropertyDescriptor | undefined;
|
|
1766
|
+
function getPrototypeOf(target: object): object | null;
|
|
1767
|
+
function has(target: object, propertyKey: PropertyKey): boolean;
|
|
1768
|
+
function ownKeys(target: object): (string | symbol)[];
|
|
1769
|
+
function set(target: object, propertyKey: PropertyKey, value: any, receiver?: any): boolean;
|
|
1770
|
+
}
|
package/ROUND2-HANDOFF.md
DELETED
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
# Round 2 handoff: marked
|
|
2
|
-
|
|
3
|
-
You're picking up round 2 of 3 in a series of "flagship examples" for
|
|
4
|
-
TypeNative (a TypeScript-to-Go transpiler, repo `danisss9/TypeNative`). Each
|
|
5
|
-
round compiles a real, unmodified npm package's TypeScript source to a native
|
|
6
|
-
binary and proves its output matches Node byte for byte. Round 1 (the `yaml`
|
|
7
|
-
CLI) is done; round 3 is the Angular template parser. This round is
|
|
8
|
-
[marked](https://github.com/markedjs/marked).
|
|
9
|
-
|
|
10
|
-
If the original plan specifies something for round 2 that differs from this
|
|
11
|
-
brief, the plan wins.
|
|
12
|
-
|
|
13
|
-
## Where things stand
|
|
14
|
-
|
|
15
|
-
- Round 1 is on branch `claude/brave-ride-d67lzw`, PR
|
|
16
|
-
[danisss9/TypeNative#30](https://github.com/danisss9/TypeNative/pull/30),
|
|
17
|
-
open and already merged with current `main`. Each round ships as its own
|
|
18
|
-
PR. If #30 hasn't merged when you start, branch from it (round 2 needs its
|
|
19
|
-
transpiler fixes); otherwise branch from `main`. Don't open a PR unless the
|
|
20
|
-
user asks.
|
|
21
|
-
- Use `examples/yaml-cli/` as the template for everything:
|
|
22
|
-
[main.ts](examples/yaml-cli/main.ts), [parity.mjs](examples/yaml-cli/parity.mjs),
|
|
23
|
-
[bench.mjs](examples/yaml-cli/bench.mjs), [README.md](examples/yaml-cli/README.md),
|
|
24
|
-
[vendor/yaml/VENDOR.md](examples/yaml-cli/vendor/yaml/VENDOR.md).
|
|
25
|
-
- State at handoff: conformance 523/523 under both the Node CLI and the
|
|
26
|
-
self-hosted native compiler; yaml parity 1608/1608; `bootstrap:check`
|
|
27
|
-
holds (56 Go files identical).
|
|
28
|
-
|
|
29
|
-
## The target
|
|
30
|
-
|
|
31
|
-
| | |
|
|
32
|
-
| --- | --- |
|
|
33
|
-
| Upstream | https://github.com/markedjs/marked |
|
|
34
|
-
| Tag | `v18.1.2` (latest when this was written; use it unless the plan pins another) |
|
|
35
|
-
| Commit | `5beecae42b0beb07eaccc3a732560f56867a8301` |
|
|
36
|
-
| Source | `src/*.ts`, 11 files, about 4,070 lines, imports use `.ts` extensions |
|
|
37
|
-
| CLI | `bin/main.js` (JavaScript; imports the built `lib/marked.esm.js`) |
|
|
38
|
-
| License | MIT |
|
|
39
|
-
|
|
40
|
-
Things in the source that will matter:
|
|
41
|
-
|
|
42
|
-
- `src/rules.ts` is a large set of regexes (22 of them, two with lookbehind),
|
|
43
|
-
many composed at run time with `.replace()` on their `.source`. Expect the
|
|
44
|
-
regex translation and the backtracking engine to get a workout.
|
|
45
|
-
- `Lexer` / `Tokenizer` / `Parser` / `Renderer` classes, hooks and
|
|
46
|
-
extensions (`Instance.ts`), with `this`-bound callbacks.
|
|
47
|
-
- `bin/main.js` uses `fs.promises`, `createRequire`, `pathToFileURL`, dynamic
|
|
48
|
-
imports of `child_process` / `url`, and spawns `man` for `--help`.
|
|
49
|
-
|
|
50
|
-
## Deliverables (same rules as round 1)
|
|
51
|
-
|
|
52
|
-
Layout: `examples/marked-cli/`
|
|
53
|
-
|
|
54
|
-
- `vendor/marked/`: `src/` and `LICENSE` copied byte for byte, plus
|
|
55
|
-
`VENDOR.md` with the tag, the commit and the patch list. The target is an
|
|
56
|
-
empty patch list.
|
|
57
|
-
- `main.ts`: a TypeScript port of `bin/main.js`, importing
|
|
58
|
-
`./vendor/marked/src/marked.ts` instead of the built bundle. It must run
|
|
59
|
-
under both `node main.ts` and TypeNative. For `--help`, matching Node's
|
|
60
|
-
behavior (spawning `man`) isn't required for parity; just keep it working.
|
|
61
|
-
- `parity.mjs`: runs every corpus case through Node and the native binary,
|
|
62
|
-
compares stdout, stderr and exit code byte for byte, prints the pass rate
|
|
63
|
-
and writes failures to `.cache/failures/`. Copy yaml-cli's, including its
|
|
64
|
-
`withoutStackFrames()` normalization (Node prints JS stack frames; a native
|
|
65
|
-
binary has none).
|
|
66
|
-
- `bench.mjs`: (a) per-call latency, (b) throughput, alternating Node and
|
|
67
|
-
native runs, checking the outputs are identical.
|
|
68
|
-
- `README.md` in the yaml-cli style. Report losses honestly too: yaml-cli is
|
|
69
|
-
27x faster per call but 3.6x slower on 10 MB, and its README says so.
|
|
70
|
-
|
|
71
|
-
Corpora are fetched into a gitignored `.cache/` (`examples/*/.cache` is
|
|
72
|
-
already ignored), never committed.
|
|
73
|
-
|
|
74
|
-
**Proposed corpus** (confirm against the plan): marked's own spec suites at
|
|
75
|
-
the vendored tag.
|
|
76
|
-
|
|
77
|
-
- `test/specs/commonmark/commonmark.0.31.2.json`: 652 cases.
|
|
78
|
-
- `test/specs/gfm/gfm.0.29.json`: 28 cases.
|
|
79
|
-
- `test/specs/new/*.md`: about 223 cases.
|
|
80
|
-
- `test/specs/original/*.md`: 22 cases.
|
|
81
|
-
- `test/specs/redos/*`: 36 inputs, worth including with the 10 s timeout,
|
|
82
|
-
since they will expose any super-linear regex path.
|
|
83
|
-
|
|
84
|
-
Feed each case's markdown on stdin, in at least the default (GFM) mode and
|
|
85
|
-
with `--no-gfm` if the CLI supports it. Parity means native vs Node, not
|
|
86
|
-
native vs the spec's expected HTML; spec cases marked failing in marked
|
|
87
|
-
don't matter.
|
|
88
|
-
|
|
89
|
-
**Proposed benchmarks**:
|
|
90
|
-
|
|
91
|
-
- (a) A typical README (e.g. marked's own `README.md`) to HTML, 30 runs.
|
|
92
|
-
- (b) About 10 MB of generated markdown (headings, lists, tables, code
|
|
93
|
-
fences, links, emphasis) from a fixed-seed generator, 5 runs.
|
|
94
|
-
|
|
95
|
-
## Hard rules
|
|
96
|
-
|
|
97
|
-
- No patches to upstream code. When a construct doesn't compile or behaves
|
|
98
|
-
differently, fix the transpiler generally. The only exception is something
|
|
99
|
-
`conformance.md` marks 🚫, documented in `VENDOR.md` with the reason.
|
|
100
|
-
- Every fix gets a probe in `conformance/` (it runs under TypeNative with an
|
|
101
|
-
`assert` global) and a row in `conformance.md` (✅ with the probe link; ❌
|
|
102
|
-
rows for gaps you find but don't fix).
|
|
103
|
-
- The self-hosted compiler must keep working: `npm run build:native &&
|
|
104
|
-
npm run bootstrap:check`.
|
|
105
|
-
- Docs per round: a row in `examples/README.md`, a line in the root README's
|
|
106
|
-
Examples section, and a CHANGELOG entry under `[Unreleased]`.
|
|
107
|
-
- Commit trailer, and never put a model name in commits, PRs or code:
|
|
108
|
-
```
|
|
109
|
-
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
|
110
|
-
Claude-Session: https://claude.ai/code/session_012GsG7QUSC36HGJ9rohJ7A7
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
## Verification (run all of it before pushing)
|
|
114
|
-
|
|
115
|
-
1. `npm run build`
|
|
116
|
-
2. Compile the example: `node bin/cli.js --source examples/marked-cli/main.ts --output …`
|
|
117
|
-
3. `cd examples/marked-cli && node parity.mjs` must report 100%.
|
|
118
|
-
4. `node bench.mjs`
|
|
119
|
-
5. `npm run conformance:parallel`
|
|
120
|
-
6. `npm run build:native && npm run bootstrap:check`
|
|
121
|
-
7. `node scripts/conformance.mjs --native`
|
|
122
|
-
|
|
123
|
-
## Environment
|
|
124
|
-
|
|
125
|
-
```bash
|
|
126
|
-
export PATH=/opt/nvm/versions/node/v24.22.2/bin:$PATH
|
|
127
|
-
export GOTOOLCHAIN=go1.26.0
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
Without these you get "TypeNative needs Go 1.26 or newer" or an old Node.
|
|
131
|
-
Timings in this container: conformance:parallel about 7 min,
|
|
132
|
-
`conformance --native` about 5 min, bootstrap:check about 75 s,
|
|
133
|
-
build:native about 3 min.
|
|
134
|
-
|
|
135
|
-
## Lessons from round 1 (read these; they will save hours)
|
|
136
|
-
|
|
137
|
-
**Working method**
|
|
138
|
-
|
|
139
|
-
- Write a small `tn.sh file.ts` that runs a snippet under Node and natively
|
|
140
|
-
and prints both. Most bugs reduce to five lines this way.
|
|
141
|
-
- `node bin/cli.js --source x.ts --emit-go DIR` writes the Go. Strip the
|
|
142
|
-
line directives with `sed 's#/\*line[^*]*\*/##g'` to read it.
|
|
143
|
-
- For a native panic, the recovered error loses the stack. Patch the
|
|
144
|
-
emitted Go's `TnCaught` to print `runtime/debug.Stack()`; import it under
|
|
145
|
-
an alias (`rtdbg`), since vendored code may already have a `debug`.
|
|
146
|
-
- Don't rebuild `bin/` while conformance runs: probes compile with it and
|
|
147
|
-
fail spuriously.
|
|
148
|
-
- Parity flakes are rare. If a parallel conformance job fails once but passes
|
|
149
|
-
alone (fs-watch timing, the big example build under load), rerun it alone
|
|
150
|
-
before chasing it.
|
|
151
|
-
|
|
152
|
-
**Self-hosting traps.** These cost the most time in round 1. The native
|
|
153
|
-
compiler (the transpiler compiled by itself) has known semantic gaps. Code
|
|
154
|
-
you add to `src/transpiler.ts` must avoid them, or `bootstrap:check` fails:
|
|
155
|
-
|
|
156
|
-
- `map.get(k)` on a missing key returns the zero value (`''`, `0`, `false`),
|
|
157
|
-
not `undefined`. So `m.get(k) ?? fallback` and `if (m.get(k) !== undefined)`
|
|
158
|
-
are wrong natively. Use `m.has(k) ? m.get(k) : undefined`. The same goes for
|
|
159
|
-
`Record` lookups (`Object.hasOwn(rec, k) ? rec[k] : undefined`) and for
|
|
160
|
-
`arr.find()`, which returns `''` for no match (use `filter()[0]` with a
|
|
161
|
-
length check).
|
|
162
|
-
- `bool || string` evaluates to a bool, not the string operand. Don't mix
|
|
163
|
-
types in `||` / `&&` value positions.
|
|
164
|
-
- A function returning `string | undefined` can yield `''` where JS yields
|
|
165
|
-
`undefined`; prefer `||` over `??` when `''` is never a valid value (Go
|
|
166
|
-
types never are).
|
|
167
|
-
- Object literals assigned into `any` slots become Go maps; those can now be
|
|
168
|
-
Map/Set keys (by identity), but don't rely on struct identity for them.
|
|
169
|
-
- To find a divergence: emit the same program's Go with both compilers
|
|
170
|
-
(`./native/typenative --emit-go` vs `node bin/cli.js --emit-go`) and diff
|
|
171
|
-
them, after stripping line directives. The first differing line usually
|
|
172
|
-
names the faulty inference rule.
|
|
173
|
-
- Helpers `untypedVariable()`, `declaredMemberType()` and
|
|
174
|
-
`getObjectFieldGoType()` already encode the `has()`-first pattern; reuse
|
|
175
|
-
them.
|
|
176
|
-
|
|
177
|
-
**Transpiler areas you'll likely touch for marked**
|
|
178
|
-
|
|
179
|
-
- Regexes: `TnRegex` (RE2, with a backtracking engine for lookarounds and
|
|
180
|
-
backreferences), sticky/global flags, `$` replacement patterns, replacer
|
|
181
|
-
callbacks (match, groups…, offset, input) and unmatched groups as
|
|
182
|
-
`undefined` all work now. `new RegExp(src, flags)` with `g`/`y` is
|
|
183
|
-
stateful. Composed regexes (`.source` edited with `.replace`) are new
|
|
184
|
-
territory.
|
|
185
|
-
- String positions are code points (UTF-16 units in the BMP), with a cached
|
|
186
|
-
index per long string. Long inputs scanned by regexes were quadratic until
|
|
187
|
-
round 1 fixed the cache eviction; watch for similar hotspots with a
|
|
188
|
-
profiler.
|
|
189
|
-
- Profiling: patch the emitted Go's `main()` to call
|
|
190
|
-
`pprof.StartCPUProfile` and `TnProcessExit` to stop it, then `go tool pprof
|
|
191
|
-
-top`. Round 1's wins were the string index cache, cached struct field
|
|
192
|
-
lookups, and resolving `typeof f` as a func type (direct calls instead of
|
|
193
|
-
reflection).
|
|
194
|
-
|
|
195
|
-
**Known gaps left open (❌ rows)**: a local alias of an array field doesn't
|
|
196
|
-
share pushes; an array read from an `any` object into a variable isn't
|
|
197
|
-
shared; `x?.m()` on an `any` value with a primitive result gives the zero
|
|
198
|
-
value instead of `undefined`; reading a missing `Record` / `Map` key of
|
|
199
|
-
primitives gives the zero value. Fix them if marked needs them, with
|
|
200
|
-
probes.
|