typenative 0.5.0 → 0.6.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 (149) hide show
  1. package/.github/workflows/ci.yml +2 -2
  2. package/.github/workflows/npm-publish-github-packages.yml +2 -2
  3. package/CHANGELOG.md +339 -0
  4. package/CONTRIBUTION.md +2 -1
  5. package/README.md +16 -7
  6. package/bin/cli.js +1 -0
  7. package/bin/index.js +62 -3
  8. package/bin/main.js +1 -0
  9. package/bin/node/core.js +46 -0
  10. package/bin/node/events.js +154 -15
  11. package/bin/node/http.js +1265 -127
  12. package/bin/node/process.js +13 -0
  13. package/bin/node/punycode.js +2 -2
  14. package/bin/node/stream.js +56 -7
  15. package/bin/node/stream_web.js +2 -2
  16. package/bin/node/timers.js +4 -2
  17. package/bin/node/url.js +28 -3
  18. package/bin/parse-node.js +2 -2
  19. package/bin/regex_vm.js +2105 -0
  20. package/bin/transpiler.js +17970 -4419
  21. package/bin/typecheck-node.js +2 -1
  22. package/bin/version.js +1 -1
  23. package/conformance.md +57 -15
  24. package/examples/README.md +50 -28
  25. package/examples/angular-templates/README.md +141 -0
  26. package/examples/angular-templates/bench.mjs +173 -0
  27. package/examples/angular-templates/dom-type-globals.d.ts +21 -0
  28. package/examples/angular-templates/dom-type-stubs.ts +21 -0
  29. package/examples/angular-templates/main.ts +135 -0
  30. package/examples/angular-templates/parity.mjs +157 -0
  31. package/examples/angular-templates/run-node.mjs +69 -0
  32. package/examples/angular-templates/vendor/angular/compiler/LICENSE +21 -0
  33. package/examples/desktop-notes/README.md +11 -13
  34. package/examples/dupe-finder/README.md +7 -5
  35. package/examples/fibonacci/README.md +7 -7
  36. package/examples/hello-world/README.md +6 -6
  37. package/examples/json-server/README.md +22 -18
  38. package/examples/mandelbrot-png/README.md +11 -13
  39. package/examples/marked-cli/README.md +60 -44
  40. package/examples/marked-cli/main.ts +122 -4
  41. package/examples/openai-chat/README.md +148 -0
  42. package/examples/openai-chat/bench.mjs +175 -0
  43. package/examples/openai-chat/main.ts +488 -0
  44. package/examples/react-compiler/README.md +185 -0
  45. package/examples/react-compiler/bench.mjs +181 -0
  46. package/examples/react-compiler/main.ts +324 -0
  47. package/examples/react-compiler/parity.mjs +362 -0
  48. package/examples/react-compiler/run-node.mjs +90 -0
  49. package/examples/react-compiler/vendor/babel/LICENSE +22 -0
  50. package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-lower.json +15 -0
  51. package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-upper.json +51 -0
  52. package/examples/react-compiler/vendor/charcodes/package.json +25 -0
  53. package/examples/react-compiler/vendor/invariant/LICENSE +21 -0
  54. package/examples/react-compiler/vendor/invariant/invariant.cjs +51 -0
  55. package/examples/react-compiler/vendor/invariant/invariant.d.cts +11 -0
  56. package/examples/react-compiler/vendor/invariant/types/LICENSE +21 -0
  57. package/examples/react-compiler/vendor/jridgewell/gen-mapping/LICENSE +19 -0
  58. package/examples/react-compiler/vendor/jridgewell/resolve-uri/LICENSE +19 -0
  59. package/examples/react-compiler/vendor/jridgewell/sourcemap-codec/LICENSE +19 -0
  60. package/examples/react-compiler/vendor/jridgewell/trace-mapping/LICENSE +19 -0
  61. package/examples/react-compiler/vendor/js-tokens/LICENSE +21 -0
  62. package/examples/react-compiler/vendor/js-tokens/index.cjs +23 -0
  63. package/examples/react-compiler/vendor/js-tokens/index.d.cts +13 -0
  64. package/examples/react-compiler/vendor/jsesc/LICENSE-MIT.txt +20 -0
  65. package/examples/react-compiler/vendor/jsesc/jsesc.cjs +337 -0
  66. package/examples/react-compiler/vendor/jsesc/jsesc.d.cts +384 -0
  67. package/examples/react-compiler/vendor/jsesc/types/LICENSE +21 -0
  68. package/examples/react-compiler/vendor/picocolors/LICENSE +15 -0
  69. package/examples/react-compiler/vendor/picocolors/picocolors.cjs +75 -0
  70. package/examples/react-compiler/vendor/picocolors/picocolors.d.cts +5 -0
  71. package/examples/react-compiler/vendor/picocolors/types.d.ts +51 -0
  72. package/examples/react-compiler/vendor/react-compiler/LICENSE +21 -0
  73. package/examples/react-compiler/vendor/stubs/babel-core.ts +31 -0
  74. package/examples/react-compiler/vendor/stubs/debug.ts +18 -0
  75. package/examples/react-compiler/vendor/stubs/js-tokens.d.ts +13 -0
  76. package/examples/react-compiler/vendor/stubs/pretty-format.ts +18 -0
  77. package/examples/react-compiler/vendor/zod/LICENSE +21 -0
  78. package/examples/react-compiler/vendor/zod-validation-error/LICENSE +9 -0
  79. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/NonEmptyArray.ts +5 -0
  80. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinPath.ts +49 -0
  81. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinValues.ts +48 -0
  82. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/stringify.ts +50 -0
  83. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/titleCase.ts +6 -0
  84. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/MessageBuilder.ts +126 -0
  85. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/ValidationError.ts +39 -0
  86. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/custom.ts +12 -0
  87. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/errorMap.ts +78 -0
  88. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/index.ts +2 -0
  89. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidElement.ts +12 -0
  90. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidKey.ts +12 -0
  91. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidStringFormat.ts +131 -0
  92. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidType.ts +54 -0
  93. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidUnion.ts +12 -0
  94. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidValue.ts +40 -0
  95. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/notMultipleOf.ts +12 -0
  96. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooBig.ts +76 -0
  97. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooSmall.ts +76 -0
  98. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/types.ts +27 -0
  99. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/unrecognizedKeys.ts +27 -0
  100. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromError.ts +13 -0
  101. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodError.ts +61 -0
  102. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodIssue.ts +38 -0
  103. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/index.ts +20 -0
  104. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationError.ts +5 -0
  105. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationErrorLike.ts +8 -0
  106. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isZodErrorLike.ts +11 -0
  107. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/toValidationError.ts +20 -0
  108. package/examples/react-compiler/vendor.mjs +688 -0
  109. package/examples/todo-cli/README.md +9 -9
  110. package/examples/yaml-cli/README.md +50 -34
  111. package/examples/yaml-cli/main.ts +236 -14
  112. package/package.json +8 -5
  113. package/performance/README.md +196 -0
  114. package/performance/any-dynamic.ts +21 -0
  115. package/performance/any-record-view.ts +20 -0
  116. package/performance/arr-hof.ts +21 -0
  117. package/performance/arr-push-index.ts +15 -0
  118. package/performance/arr-sort.ts +21 -0
  119. package/performance/async-await.ts +24 -0
  120. package/performance/class-dispatch.ts +52 -0
  121. package/performance/events-emit.ts +27 -0
  122. package/performance/exc-throw-rare.ts +25 -0
  123. package/performance/exc-try-catch.ts +26 -0
  124. package/performance/fn-closures.ts +29 -0
  125. package/performance/fn-recursion-tree.ts +31 -0
  126. package/performance/gen-for-of.ts +46 -0
  127. package/performance/json-roundtrip.ts +27 -0
  128. package/performance/map-delete.ts +24 -0
  129. package/performance/map-string-keys.ts +22 -0
  130. package/performance/num-arith-loop.ts +14 -0
  131. package/performance/num-bitwise.ts +21 -0
  132. package/performance/num-mod-int.ts +16 -0
  133. package/performance/num-to-string.ts +16 -0
  134. package/performance/obj-alloc.ts +32 -0
  135. package/performance/regex-exec.ts +29 -0
  136. package/performance/regex-site.ts +28 -0
  137. package/performance/set-ops.ts +20 -0
  138. package/performance/str-char-scan.ts +35 -0
  139. package/performance/str-concat-plus.ts +18 -0
  140. package/performance/str-concat.ts +24 -0
  141. package/performance/str-short-scan.ts +26 -0
  142. package/performance/str-split-join.ts +23 -0
  143. package/performance/str-template.ts +16 -0
  144. package/performance/union-switch.ts +57 -0
  145. package/tsparser/check.go +2 -1
  146. package/tsparser/main.go +1 -0
  147. package/types/typenative-npm.d.ts +3 -2
  148. package/types/typenative.d.ts +42 -12
  149. package/ROUND2-HANDOFF.md +0 -200
@@ -0,0 +1,337 @@
1
+ 'use strict';
2
+
3
+ const object = {};
4
+ const hasOwnProperty = object.hasOwnProperty;
5
+ const forOwn = (object, callback) => {
6
+ for (const key in object) {
7
+ if (hasOwnProperty.call(object, key)) {
8
+ callback(key, object[key]);
9
+ }
10
+ }
11
+ };
12
+
13
+ const extend = (destination, source) => {
14
+ if (!source) {
15
+ return destination;
16
+ }
17
+ forOwn(source, (key, value) => {
18
+ destination[key] = value;
19
+ });
20
+ return destination;
21
+ };
22
+
23
+ const forEach = (array, callback) => {
24
+ const length = array.length;
25
+ let index = -1;
26
+ while (++index < length) {
27
+ callback(array[index]);
28
+ }
29
+ };
30
+
31
+ const fourHexEscape = (hex) => {
32
+ return '\\u' + ('0000' + hex).slice(-4);
33
+ }
34
+
35
+ const hexadecimal = (code, lowercase) => {
36
+ let hexadecimal = code.toString(16);
37
+ if (lowercase) return hexadecimal;
38
+ return hexadecimal.toUpperCase();
39
+ };
40
+
41
+ const toString = object.toString;
42
+ const isArray = Array.isArray;
43
+ const isBuffer = (value) => {
44
+ return typeof Buffer === 'function' && Buffer.isBuffer(value);
45
+ };
46
+ const isObject = (value) => {
47
+ // This is a very simple check, but it’s good enough for what we need.
48
+ return toString.call(value) == '[object Object]';
49
+ };
50
+ const isString = (value) => {
51
+ return typeof value == 'string' ||
52
+ toString.call(value) == '[object String]';
53
+ };
54
+ const isNumber = (value) => {
55
+ return typeof value == 'number' ||
56
+ toString.call(value) == '[object Number]';
57
+ };
58
+ const isBigInt = (value) => {
59
+ return typeof value == 'bigint';
60
+ };
61
+ const isFunction = (value) => {
62
+ return typeof value == 'function';
63
+ };
64
+ const isMap = (value) => {
65
+ return toString.call(value) == '[object Map]';
66
+ };
67
+ const isSet = (value) => {
68
+ return toString.call(value) == '[object Set]';
69
+ };
70
+
71
+ /*--------------------------------------------------------------------------*/
72
+
73
+ // https://mathiasbynens.be/notes/javascript-escapes#single
74
+ const singleEscapes = {
75
+ '\\': '\\\\',
76
+ '\b': '\\b',
77
+ '\f': '\\f',
78
+ '\n': '\\n',
79
+ '\r': '\\r',
80
+ '\t': '\\t'
81
+ // `\v` is omitted intentionally, because in IE < 9, '\v' == 'v'.
82
+ // '\v': '\\x0B'
83
+ };
84
+ const regexSingleEscape = /[\\\b\f\n\r\t]/;
85
+
86
+ const regexDigit = /[0-9]/;
87
+ const regexWhitespace = /[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000]/;
88
+
89
+ const escapeEverythingRegex = /([\uD800-\uDBFF][\uDC00-\uDFFF])|([\uD800-\uDFFF])|(['"`])|[^]/g;
90
+ const escapeNonAsciiRegex = /([\uD800-\uDBFF][\uDC00-\uDFFF])|([\uD800-\uDFFF])|(['"`])|[^ !#-&\(-\[\]-_a-~]/g;
91
+
92
+ const jsesc = (argument, options) => {
93
+ const increaseIndentation = () => {
94
+ oldIndent = indent;
95
+ ++options.indentLevel;
96
+ indent = options.indent.repeat(options.indentLevel)
97
+ };
98
+ // Handle options
99
+ const defaults = {
100
+ 'escapeEverything': false,
101
+ 'minimal': false,
102
+ 'isScriptContext': false,
103
+ 'quotes': 'single',
104
+ 'wrap': false,
105
+ 'es6': false,
106
+ 'json': false,
107
+ 'compact': true,
108
+ 'lowercaseHex': false,
109
+ 'numbers': 'decimal',
110
+ 'indent': '\t',
111
+ 'indentLevel': 0,
112
+ '__inline1__': false,
113
+ '__inline2__': false
114
+ };
115
+ const json = options && options.json;
116
+ if (json) {
117
+ defaults.quotes = 'double';
118
+ defaults.wrap = true;
119
+ }
120
+ options = extend(defaults, options);
121
+ if (
122
+ options.quotes != 'single' &&
123
+ options.quotes != 'double' &&
124
+ options.quotes != 'backtick'
125
+ ) {
126
+ options.quotes = 'single';
127
+ }
128
+ const quote = options.quotes == 'double' ?
129
+ '"' :
130
+ (options.quotes == 'backtick' ?
131
+ '`' :
132
+ '\''
133
+ );
134
+ const compact = options.compact;
135
+ const lowercaseHex = options.lowercaseHex;
136
+ let indent = options.indent.repeat(options.indentLevel);
137
+ let oldIndent = '';
138
+ const inline1 = options.__inline1__;
139
+ const inline2 = options.__inline2__;
140
+ const newLine = compact ? '' : '\n';
141
+ let result;
142
+ let isEmpty = true;
143
+ const useBinNumbers = options.numbers == 'binary';
144
+ const useOctNumbers = options.numbers == 'octal';
145
+ const useDecNumbers = options.numbers == 'decimal';
146
+ const useHexNumbers = options.numbers == 'hexadecimal';
147
+
148
+ if (json && argument && isFunction(argument.toJSON)) {
149
+ argument = argument.toJSON();
150
+ }
151
+
152
+ if (!isString(argument)) {
153
+ if (isMap(argument)) {
154
+ if (argument.size == 0) {
155
+ return 'new Map()';
156
+ }
157
+ if (!compact) {
158
+ options.__inline1__ = true;
159
+ options.__inline2__ = false;
160
+ }
161
+ return 'new Map(' + jsesc(Array.from(argument), options) + ')';
162
+ }
163
+ if (isSet(argument)) {
164
+ if (argument.size == 0) {
165
+ return 'new Set()';
166
+ }
167
+ return 'new Set(' + jsesc(Array.from(argument), options) + ')';
168
+ }
169
+ if (isBuffer(argument)) {
170
+ if (argument.length == 0) {
171
+ return 'Buffer.from([])';
172
+ }
173
+ return 'Buffer.from(' + jsesc(Array.from(argument), options) + ')';
174
+ }
175
+ if (isArray(argument)) {
176
+ result = [];
177
+ options.wrap = true;
178
+ if (inline1) {
179
+ options.__inline1__ = false;
180
+ options.__inline2__ = true;
181
+ }
182
+ if (!inline2) {
183
+ increaseIndentation();
184
+ }
185
+ forEach(argument, (value) => {
186
+ isEmpty = false;
187
+ if (inline2) {
188
+ options.__inline2__ = false;
189
+ }
190
+ result.push(
191
+ (compact || inline2 ? '' : indent) +
192
+ jsesc(value, options)
193
+ );
194
+ });
195
+ if (isEmpty) {
196
+ return '[]';
197
+ }
198
+ if (inline2) {
199
+ return '[' + result.join(', ') + ']';
200
+ }
201
+ return '[' + newLine + result.join(',' + newLine) + newLine +
202
+ (compact ? '' : oldIndent) + ']';
203
+ } else if (isNumber(argument) || isBigInt(argument)) {
204
+ if (json) {
205
+ // Some number values (e.g. `Infinity`) cannot be represented in JSON.
206
+ // `BigInt` values less than `-Number.MAX_VALUE` or greater than
207
+ // `Number.MAX_VALUE` cannot be represented in JSON so they will become
208
+ // `-Infinity` or `Infinity`, respectively, and then become `null` when
209
+ // stringified.
210
+ return JSON.stringify(Number(argument));
211
+ }
212
+
213
+ let result;
214
+ if (useDecNumbers) {
215
+ result = String(argument);
216
+ } else if (useHexNumbers) {
217
+ let hexadecimal = argument.toString(16);
218
+ if (!lowercaseHex) {
219
+ hexadecimal = hexadecimal.toUpperCase();
220
+ }
221
+ result = '0x' + hexadecimal;
222
+ } else if (useBinNumbers) {
223
+ result = '0b' + argument.toString(2);
224
+ } else if (useOctNumbers) {
225
+ result = '0o' + argument.toString(8);
226
+ }
227
+
228
+ if (isBigInt(argument)) {
229
+ return result + 'n';
230
+ }
231
+ return result;
232
+ } else if (isBigInt(argument)) {
233
+ if (json) {
234
+ // `BigInt` values less than `-Number.MAX_VALUE` or greater than
235
+ // `Number.MAX_VALUE` will become `-Infinity` or `Infinity`,
236
+ // respectively, and cannot be represented in JSON.
237
+ return JSON.stringify(Number(argument));
238
+ }
239
+ return argument + 'n';
240
+ } else if (!isObject(argument)) {
241
+ if (json) {
242
+ // For some values (e.g. `undefined`, `function` objects),
243
+ // `JSON.stringify(value)` returns `undefined` (which isn’t valid
244
+ // JSON) instead of `'null'`.
245
+ return JSON.stringify(argument) || 'null';
246
+ }
247
+ return String(argument);
248
+ } else { // it’s an object
249
+ result = [];
250
+ options.wrap = true;
251
+ increaseIndentation();
252
+ forOwn(argument, (key, value) => {
253
+ isEmpty = false;
254
+ result.push(
255
+ (compact ? '' : indent) +
256
+ jsesc(key, options) + ':' +
257
+ (compact ? '' : ' ') +
258
+ jsesc(value, options)
259
+ );
260
+ });
261
+ if (isEmpty) {
262
+ return '{}';
263
+ }
264
+ return '{' + newLine + result.join(',' + newLine) + newLine +
265
+ (compact ? '' : oldIndent) + '}';
266
+ }
267
+ }
268
+
269
+ const regex = options.escapeEverything ? escapeEverythingRegex : escapeNonAsciiRegex;
270
+ result = argument.replace(regex, (char, pair, lone, quoteChar, index, string) => {
271
+ if (pair) {
272
+ if (options.minimal) return pair;
273
+ const first = pair.charCodeAt(0);
274
+ const second = pair.charCodeAt(1);
275
+ if (options.es6) {
276
+ // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
277
+ const codePoint = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
278
+ const hex = hexadecimal(codePoint, lowercaseHex);
279
+ return '\\u{' + hex + '}';
280
+ }
281
+ return fourHexEscape(hexadecimal(first, lowercaseHex)) + fourHexEscape(hexadecimal(second, lowercaseHex));
282
+ }
283
+
284
+ if (lone) {
285
+ return fourHexEscape(hexadecimal(lone.charCodeAt(0), lowercaseHex));
286
+ }
287
+
288
+ if (
289
+ char == '\0' &&
290
+ !json &&
291
+ !regexDigit.test(string.charAt(index + 1))
292
+ ) {
293
+ return '\\0';
294
+ }
295
+
296
+ if (quoteChar) {
297
+ if (quoteChar == quote || options.escapeEverything) {
298
+ return '\\' + quoteChar;
299
+ }
300
+ return quoteChar;
301
+ }
302
+
303
+ if (regexSingleEscape.test(char)) {
304
+ // no need for a `hasOwnProperty` check here
305
+ return singleEscapes[char];
306
+ }
307
+
308
+ if (options.minimal && !regexWhitespace.test(char)) {
309
+ return char;
310
+ }
311
+
312
+ const hex = hexadecimal(char.charCodeAt(0), lowercaseHex);
313
+ if (json || hex.length > 2) {
314
+ return fourHexEscape(hex);
315
+ }
316
+
317
+ return '\\x' + ('00' + hex).slice(-2);
318
+ });
319
+
320
+ if (quote == '`') {
321
+ result = result.replace(/\$\{/g, '\\${');
322
+ }
323
+ if (options.isScriptContext) {
324
+ // https://mathiasbynens.be/notes/etago
325
+ result = result
326
+ .replace(/<\/(script|style)/gi, '<\\/$1')
327
+ .replace(/<!--/g, json ? '\\u003C!--' : '\\x3C!--');
328
+ }
329
+ if (options.wrap) {
330
+ result = quote + result + quote;
331
+ }
332
+ return result;
333
+ };
334
+
335
+ jsesc.version = '3.0.2';
336
+
337
+ module.exports = jsesc;