runtime-type-inspector 1.0.0 → 2.0.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 (54) hide show
  1. package/.eslintrc.js +480 -0
  2. package/README.md +12 -4
  3. package/jsconfig.json +10 -0
  4. package/package.json +32 -4
  5. package/plugin-parcel/index.mjs +4 -0
  6. package/plugin-rollup/index.mjs +78 -0
  7. package/plugin-webpack/index.mjs +4 -0
  8. package/rollup.config.mjs +183 -0
  9. package/src-runtime/assertType.mjs +54 -0
  10. package/src-runtime/createDiv.mjs +69 -0
  11. package/src-runtime/index.mjs +21 -0
  12. package/src-runtime/makeJSDoc.mjs +40 -0
  13. package/src-runtime/registerClass.mjs +11 -0
  14. package/src-runtime/registerTypedef.mjs +12 -0
  15. package/src-runtime/typecheckDiv.mjs +3 -0
  16. package/src-runtime/typecheckEvery.mjs +21 -0
  17. package/src-runtime/typecheckOptions.mjs +60 -0
  18. package/src-runtime/typecheckTable.mjs +14 -0
  19. package/src-runtime/typecheckWarn.mjs +23 -0
  20. package/src-runtime/validateArray.mjs +26 -0
  21. package/src-runtime/validateDivision.mjs +31 -0
  22. package/src-runtime/validateMap.mjs +36 -0
  23. package/src-runtime/validateNumber.mjs +29 -0
  24. package/src-runtime/validateObject.mjs +43 -0
  25. package/src-runtime/validateRecord.mjs +31 -0
  26. package/src-runtime/validateSet.mjs +26 -0
  27. package/src-runtime/validateTuple.mjs +28 -0
  28. package/src-runtime/validateType.mjs +214 -0
  29. package/src-runtime/validateTypedef.mjs +18 -0
  30. package/src-runtime/validateUnion.mjs +19 -0
  31. package/src-runtime/youCanAddABreakpointHere.mjs +11 -0
  32. package/src-transpiler/Stringifier.mjs +1268 -0
  33. package/src-transpiler/StringifierWithTypeAssertions.mjs +478 -0
  34. package/src-transpiler/addTypeChecks.mjs +20 -0
  35. package/src-transpiler/ast2json.mjs +13 -0
  36. package/src-transpiler/ast2jsonForComparison.mjs +28 -0
  37. package/src-transpiler/code2ast2code.mjs +16 -0
  38. package/src-transpiler/expandType.mjs +187 -0
  39. package/src-transpiler/expandTypeDepFree.mjs +122 -0
  40. package/src-transpiler/extractNameAndOptionality.mjs +23 -0
  41. package/src-transpiler/index.mjs +13 -0
  42. package/src-transpiler/parseJSDoc.mjs +69 -0
  43. package/src-transpiler/parseJSDocSetter.mjs +16 -0
  44. package/src-transpiler/parseJSDocTypedef.mjs +69 -0
  45. package/src-transpiler/simplifyType.mjs +31 -0
  46. package/src-transpiler/stat.mjs +13 -0
  47. package/ui/babel-core.mjs +5 -0
  48. package/ui/babel-helper-plugin-utils.mjs +7 -0
  49. package/ui/babel-parser.mjs +8 -0
  50. package/ui/babel-plugin-syntax-typescript.mjs +58 -0
  51. package/ui/importmap.js +38 -0
  52. package/ui/index.html +30 -0
  53. package/ui/index.mjs +379 -0
  54. package/src/index.mjs +0 -1
package/.eslintrc.js ADDED
@@ -0,0 +1,480 @@
1
+ module.exports = {
2
+
3
+ "parserOptions": {
4
+ "ecmaVersion": 2022,
5
+ "sourceType": "module",
6
+ "ecmaFeatures": {}
7
+ },
8
+
9
+ // Rules reference: https://eslint.org/docs/rules/
10
+ "rules": {
11
+ // Possible Problems
12
+ "array-callback-return": "error",
13
+ "constructor-super": "error",
14
+ "for-direction": "error",
15
+ "getter-return": "error",
16
+ "no-async-promise-executor": "error",
17
+ "no-await-in-loop": "error",
18
+ "no-class-assign": "error",
19
+ "no-compare-neg-zero": "error",
20
+ "no-cond-assign": "error",
21
+ "no-const-assign": "error",
22
+ "no-constant-binary-expression": "error",
23
+ "no-constant-condition": [
24
+ "error", {
25
+ "checkLoops": false
26
+ }
27
+ ],
28
+ "no-constructor-return": "error",
29
+ "no-control-regex": "error",
30
+ "no-debugger": "error",
31
+ "no-dupe-args": "error",
32
+ "no-dupe-class-members": "error",
33
+ "no-dupe-else-if": "error",
34
+ "no-dupe-keys": "error",
35
+ "no-duplicate-case": "error",
36
+ "no-duplicate-imports": "error",
37
+ "no-empty-character-class": "error",
38
+ "no-empty-pattern": "error",
39
+ "no-ex-assign": "error",
40
+ "no-fallthrough": "error",
41
+ "no-func-assign": "error",
42
+ "no-import-assign": "error",
43
+ "no-inner-declarations": "error",
44
+ "no-invalid-regexp": "error",
45
+ "no-irregular-whitespace": "error",
46
+ "no-loss-of-precision": "error",
47
+ "no-misleading-character-class": "error",
48
+ "no-new-native-nonconstructor": "error",
49
+ "no-new-symbol": "error",
50
+ "no-obj-calls": "error",
51
+ "no-promise-executor-return": "error",
52
+ "no-prototype-builtins": "off",
53
+ "no-self-assign": "error",
54
+ "no-self-compare": "error",
55
+ "no-setter-return": "error",
56
+ "no-sparse-arrays": "error",
57
+ "no-template-curly-in-string": "error",
58
+ "no-this-before-super": "error",
59
+ "no-undef": "error",
60
+ "no-unexpected-multiline": "error",
61
+ "no-unmodified-loop-condition": "error",
62
+ "no-unreachable": "error",
63
+ "no-unreachable-loop": "error",
64
+ "no-unsafe-finally": "error",
65
+ "no-unsafe-negation": "error",
66
+ "no-unsafe-optional-chaining": "error",
67
+ "no-unused-private-class-members": "error",
68
+ "no-unused-vars": [
69
+ "error", {
70
+ "args": "none"
71
+ }
72
+ ],
73
+ "no-use-before-define": [
74
+ "error", {
75
+ "functions": false
76
+ }
77
+ ],
78
+ "no-useless-backreference": "error",
79
+ "require-atomic-updates": "error",
80
+ "use-isnan": "error",
81
+ "valid-typeof": "error",
82
+
83
+ // Suggestions
84
+ "accessor-pairs": "error",
85
+ "arrow-body-style": "off",
86
+ "block-scoped-var": "error",
87
+ "camelcase": "off",
88
+ "capitalized-comments": "off",
89
+ "class-methods-use-this": "off",
90
+ "complexity": "off",
91
+ "consistent-return": "off",
92
+ "consistent-this": "off",
93
+ "curly": "off",
94
+ "default-case": "off",
95
+ "default-case-last": "off",
96
+ "default-param-last": "off",
97
+ "dot-notation": "error",
98
+ "eqeqeq": ["error", "smart"],
99
+ "func-name-matching": "error",
100
+ "func-names": "off",
101
+ "func-style": "off",
102
+ "grouped-accessor-pairs": ["error", "setBeforeGet"],
103
+ "guard-for-in": "off",
104
+ "id-denylist": "off",
105
+ "id-length": "off",
106
+ "id-match": "off",
107
+ "init-declarations": "off",
108
+ "logical-assignment-operators": "off",
109
+ "max-classes-per-file": "off",
110
+ "max-depth": "off",
111
+ "max-lines": "off",
112
+ "max-lines-per-function": "off",
113
+ "max-nested-callbacks": "off",
114
+ "max-params": "off",
115
+ "max-statements": "off",
116
+ "multiline-comment-style": ["warn", "separate-lines"],
117
+ "new-cap": "off",
118
+ "no-alert": "error",
119
+ "no-array-constructor": "error",
120
+ "no-bitwise": "off",
121
+ "no-caller": "error",
122
+ "no-case-declarations": "error",
123
+ "no-confusing-arrow": "error",
124
+ "no-console": "off",
125
+ "no-continue": "off",
126
+ "no-delete-var": "error",
127
+ "no-div-regex": "error",
128
+ "no-else-return": "error",
129
+ "no-empty": [
130
+ "error", {
131
+ "allowEmptyCatch": true
132
+ }
133
+ ],
134
+ "no-empty-function": "off",
135
+ "no-empty-static-block": "error",
136
+ "no-eq-null": "off",
137
+ "no-eval": "error",
138
+ "no-extend-native": "error",
139
+ "no-extra-bind": "error",
140
+ "no-extra-boolean-cast": "off",
141
+ "no-extra-label": "error",
142
+ "no-extra-semi": "error",
143
+ "no-floating-decimal": "error",
144
+ "no-global-assign": "error",
145
+ "no-implicit-coercion": "off",
146
+ "no-implicit-globals": "error",
147
+ "no-implied-eval": "error",
148
+ "no-inline-comments": "off",
149
+ "no-invalid-this": "off",
150
+ "no-iterator": "error",
151
+ "no-label-var": "error",
152
+ "no-labels": "error",
153
+ "no-lone-blocks": "error",
154
+ "no-lonely-if": "off",
155
+ "no-loop-func": "error",
156
+ "no-magic-numbers": "off",
157
+ "no-mixed-operators": "off",
158
+ "no-multi-assign": "off",
159
+ "no-multi-str": "error",
160
+ "no-negated-condition": "off",
161
+ "no-nested-ternary": "off",
162
+ "no-new": "warn",
163
+ "no-new-func": "error",
164
+ "no-new-object": "error",
165
+ "no-new-wrappers": "error",
166
+ "no-nonoctal-decimal-escape": "error",
167
+ "no-octal": "error",
168
+ "no-octal-escape": "error",
169
+ "no-param-reassign": "off",
170
+ "no-plusplus": "off",
171
+ "no-proto": "error",
172
+ "no-redeclare": "error",
173
+ "no-regex-spaces": "error",
174
+ "no-restricted-exports": "error",
175
+ "no-restricted-globals": "off",
176
+ "no-restricted-imports": "error",
177
+ "no-restricted-properties": "off",
178
+ "no-restricted-syntax": "error",
179
+ "no-return-assign": "error",
180
+ "no-script-url": "error",
181
+ "no-sequences": "error",
182
+ "no-shadow": "off",
183
+ "no-shadow-restricted-names": "error",
184
+ "no-ternary": "off",
185
+ "no-throw-literal": "error",
186
+ "no-undef-init": "error",
187
+ "no-undefined": "off",
188
+ "no-underscore-dangle": "off",
189
+ "no-unneeded-ternary": "error",
190
+ "no-unused-expressions": "error",
191
+ "no-unused-labels": "error",
192
+ "no-useless-call": "error",
193
+ "no-useless-catch": "error",
194
+ "no-useless-computed-key": "error",
195
+ "no-useless-concat": "error",
196
+ "no-useless-constructor": "error",
197
+ "no-useless-escape": "off",
198
+ "no-useless-rename": "error",
199
+ "no-useless-return": "error",
200
+ "no-var": "off", // update to error
201
+ "no-void": "error",
202
+ "no-warning-comments": "off",
203
+ "no-with": "error",
204
+ "object-shorthand": "off",
205
+ "one-var": "off",
206
+ "one-var-declaration-per-line": "off",
207
+ "operator-assignment": ["error", "always"],
208
+ "prefer-arrow-callback": "off",
209
+ "prefer-const": "error",
210
+ "prefer-destructuring": "off",
211
+ "prefer-exponentiation-operator": "off",
212
+ "prefer-named-capture-group": "off",
213
+ "prefer-numeric-literals": "error",
214
+ "prefer-object-has-own": "off",
215
+ "prefer-object-spread": "off",
216
+ "prefer-promise-reject-errors": "error",
217
+ "prefer-regex-literals": "off",
218
+ "prefer-rest-params": "off",
219
+ "prefer-spread": "warn",
220
+ "prefer-template": "off",
221
+ "quote-props": "off",
222
+ "radix": "error",
223
+ "require-await": "error",
224
+ "require-unicode-regexp": "off",
225
+ "require-yield": "error",
226
+ "sort-imports": "off",
227
+ "sort-keys": "off",
228
+ "sort-vars": "off",
229
+ "spaced-comment": [
230
+ "error", "always", {
231
+ "exceptions": ["/"]
232
+ }
233
+ ],
234
+ "strict": "error",
235
+ "symbol-description": "error",
236
+ "vars-on-top": "off",
237
+ "yoda": "error",
238
+
239
+ // Layout & Formatting
240
+ "array-bracket-newline": ["error", "consistent"],
241
+ "array-bracket-spacing": ["error", "never"],
242
+ "array-element-newline": "off",
243
+ "arrow-parens": [
244
+ "error", "as-needed", {
245
+ "requireForBlockBody": true
246
+ }
247
+ ],
248
+ "arrow-spacing": "error",
249
+ "block-spacing": "error",
250
+ "brace-style": "error",
251
+ "comma-dangle": ["error", "never"],
252
+ "comma-spacing": [
253
+ "error", {
254
+ "before": false,
255
+ "after": true
256
+ }
257
+ ],
258
+ "comma-style": ["error", "last"],
259
+ "computed-property-spacing": ["error", "never"],
260
+ "dot-location": ["error", "property"],
261
+ "eol-last": ["error", "always"],
262
+ "func-call-spacing": ["error", "never"],
263
+ "function-call-argument-newline": "off",
264
+ "function-paren-newline": "off",
265
+ "generator-star-spacing": "error",
266
+ "implicit-arrow-linebreak": "error",
267
+ "indent": [
268
+ "error", 2, {
269
+ "SwitchCase": 1,
270
+ "CallExpression": {
271
+ "arguments": "first"
272
+ },
273
+ "ignoreComments": true
274
+ }
275
+ ],
276
+ "jsx-quotes": "off",
277
+ "key-spacing": [
278
+ "error", {
279
+ "beforeColon": false,
280
+ "afterColon": true
281
+ }
282
+ ],
283
+ "keyword-spacing": [
284
+ "error", {
285
+ "before": true,
286
+ "after": true
287
+ }
288
+ ],
289
+ "line-comment-position": "off",
290
+ "linebreak-style": "off",
291
+ "lines-around-comment": "off",
292
+ "lines-between-class-members": ["error", "always"],
293
+ "max-len": "off",
294
+ "max-statements-per-line": "off",
295
+ "multiline-ternary": "off",
296
+ "new-parens": "error",
297
+ "newline-per-chained-call": "off",
298
+ "no-extra-parens": ["error", "functions"],
299
+ "no-mixed-spaces-and-tabs": "error",
300
+ "no-multi-spaces": [
301
+ "error", {
302
+ "ignoreEOLComments": true,
303
+ "exceptions": {
304
+ "ArrayExpression": true,
305
+ "AssignmentExpression": true,
306
+ "BinaryExpression": true,
307
+ "IfStatement": true,
308
+ "LogicalExpression": true,
309
+ "SwitchCase": true,
310
+ "VariableDeclarator": true
311
+ }
312
+ }
313
+ ],
314
+ "no-multiple-empty-lines": [
315
+ "error", {
316
+ "max": 2,
317
+ "maxBOF": 0,
318
+ "maxEOF": 0
319
+ }
320
+ ],
321
+ "no-tabs": "error",
322
+ "no-trailing-spaces": "error",
323
+ "no-whitespace-before-property": "error",
324
+ "nonblock-statement-body-position": "off",
325
+ "object-curly-newline": [
326
+ "error", {
327
+ "consistent": true
328
+ }
329
+ ],
330
+ "object-curly-spacing": ["error", "always"],
331
+ "object-property-newline": [
332
+ "error", {
333
+ "allowAllPropertiesOnSameLine": true
334
+ }
335
+ ],
336
+ "operator-linebreak": ["error", "after"],
337
+ "padded-blocks": [
338
+ "error", {
339
+ "classes": "never"
340
+ }
341
+ ],
342
+ "padding-line-between-statements": "off",
343
+ "quotes": ["off", "single"],
344
+ "rest-spread-spacing": "error",
345
+ "semi": ["error", "always"],
346
+ "semi-spacing": [
347
+ "error", {
348
+ "before": false,
349
+ "after": true
350
+ }
351
+ ],
352
+ "semi-style": ["error", "last"],
353
+ "space-before-blocks": "error",
354
+ "space-before-function-paren": [
355
+ "error", {
356
+ "anonymous": "always",
357
+ "named": "never"
358
+ }
359
+ ],
360
+ "space-in-parens": ["error", "never"],
361
+ "space-infix-ops": [
362
+ "error", {
363
+ "int32Hint": false
364
+ }
365
+ ],
366
+ "space-unary-ops": [
367
+ "error", {
368
+ "words": true,
369
+ "nonwords": false,
370
+ "overrides": {
371
+ }
372
+ }],
373
+ "switch-colon-spacing": [
374
+ "error", {
375
+ "after": true,
376
+ "before": false
377
+ }
378
+ ],
379
+ "template-curly-spacing": "error",
380
+ "template-tag-spacing": "error",
381
+ "unicode-bom": ["error", "never"],
382
+ "wrap-iife": "off",
383
+ "wrap-regex": "off",
384
+ "yield-star-spacing": "error",
385
+
386
+ // Import rules
387
+
388
+ // Static analysis
389
+ "import/default": "error",
390
+ "import/named": "error",
391
+ "import/namespace": "error",
392
+ "import/no-unresolved": "error",
393
+
394
+ // Helpful warnings
395
+ "import/export": "error",
396
+ "import/no-named-as-default": "warn",
397
+ "import/no-named-as-default-member": "warn",
398
+
399
+ // Style guide
400
+ "import/extensions": ["error", "always", { "ts": "never", "tsx": "never" }],
401
+ "import/no-duplicates": "warn",
402
+
403
+ // JSDoc rules
404
+ "jsdoc/check-access": "error",
405
+ "jsdoc/check-alignment": "error",
406
+ "jsdoc/check-examples": "off",
407
+ "jsdoc/check-indentation": "off",
408
+ "jsdoc/check-line-alignment": "error",
409
+ "jsdoc/check-param-names": "off",
410
+ "jsdoc/check-property-names": "error",
411
+ "jsdoc/check-syntax": "error",
412
+ "jsdoc/check-tag-names": "error",
413
+ "jsdoc/check-types": "off",
414
+ "jsdoc/check-values": "error",
415
+ "jsdoc/empty-tags": "error",
416
+ "jsdoc/implements-on-classes": "error",
417
+ "jsdoc/informative-docs": "off",
418
+ "jsdoc/match-description": "off",
419
+ "jsdoc/match-name": "off",
420
+ "jsdoc/multiline-blocks": "error",
421
+ "jsdoc/no-bad-blocks": "error",
422
+ "jsdoc/no-blank-block-descriptions": "error",
423
+ "jsdoc/no-blank-blocks": "error",
424
+ "jsdoc/no-defaults": "error",
425
+ "jsdoc/no-missing-syntax": "off",
426
+ "jsdoc/no-multi-asterisks": "error",
427
+ "jsdoc/no-restricted-syntax": "off",
428
+ "jsdoc/no-types": "off",
429
+ "jsdoc/no-undefined-types": "off",
430
+ "jsdoc/require-asterisk-prefix": "error",
431
+ "jsdoc/require-description": "off",
432
+ "jsdoc/require-description-complete-sentence": [
433
+ "off", {
434
+ "abbreviations": ["e.g."]
435
+ }
436
+ ],
437
+ "jsdoc/require-example": "off",
438
+ "jsdoc/require-file-overview": "off",
439
+ "jsdoc/require-hyphen-before-param-description": ["error", "always"],
440
+ "jsdoc/require-jsdoc": "off",
441
+ "jsdoc/require-param": "error",
442
+ "jsdoc/require-param-description": "error",
443
+ "jsdoc/require-param-name": "error",
444
+ "jsdoc/require-param-type": "error",
445
+ "jsdoc/require-property": "error",
446
+ "jsdoc/require-property-description": "error",
447
+ "jsdoc/require-property-name": "error",
448
+ "jsdoc/require-property-type": "error",
449
+ "jsdoc/require-returns": "error",
450
+ "jsdoc/require-returns-check": "error",
451
+ "jsdoc/require-returns-description": "error",
452
+ "jsdoc/require-returns-type": "error",
453
+ "jsdoc/require-throws": "off",
454
+ "jsdoc/require-yields": "error",
455
+ "jsdoc/require-yields-check": "error",
456
+ "jsdoc/sort-tags": "off",
457
+ "jsdoc/tag-lines": "off",
458
+ "jsdoc/text-escaping": "off",
459
+ "jsdoc/valid-types": "off"
460
+ },
461
+
462
+ "plugins": [
463
+ "import",
464
+ "jsdoc"
465
+ ],
466
+
467
+ "settings": {
468
+ "jsdoc": {
469
+ "mode": "typescript"
470
+ }
471
+ },
472
+
473
+ "env": {
474
+ "browser": true,
475
+ "es2022": true,
476
+ "node": true,
477
+ "worker": true
478
+ }
479
+
480
+ };
package/README.md CHANGED
@@ -1,4 +1,7 @@
1
- `RuntimeTypeInspector.js` - your personal type-checking assistant 🕵️🐞🐛
1
+ # `RuntimeTypeInspector.js` - your personal type-checking assistant 🕵️🐞🐛
2
+
3
+ # Status: under construction,
4
+ # preparing for first release 🚧🏗️🧰🚧
2
5
 
3
6
  `RuntimeTypeInspector.js` alongside `JSDoc` is a powerful tool which works in tandem with `Babel.js` and `TypeScript` to generate type-asserting JavaScript files. Assertion code is injected into debug builds to perform runtime type checking of each function and method at runtime - a step which is required beyond pure static typing to help emerge the Incident Management Lifecycle.
4
7
 
@@ -10,12 +13,16 @@ The Incident Management Lifecycle is:
10
13
 
11
14
  `RuntimeTypeInspector.js` is supporting Identify and Respond of the IML.
12
15
 
13
- **Why is this technology critical?**
16
+ # Why is this technology critical?
14
17
 
15
18
  This technology is critical because it provides developers with an organized method to ensure type safety with runtime type issue reports while improving code organization, type safety and documentation - making it easier for other developers to understand the code and enforce good coding standards.
16
19
 
17
20
  RuntimeTypeInspector.js assists the debugging process, since it has a clear definition of what each function expects while issuing warnings, which can act as breakpoints in your source code (as shown in the example debugging session in my showcase video). Finally, good JSDoc can make the entire code base more maintainable, since it's easier for developers to find the specific parts of the code they need to change quickly and easily.
18
21
 
22
+ # Watch our Example Usage Videos!
23
+
24
+ If you want to see how our product works, take a look at the videos we have prepared. They show you exactly how to use our product with ease.
25
+
19
26
  **Presentation hunting down a `NaN` bug in the PlayCanvas engine:**
20
27
 
21
28
  https://www.youtube.com/watch?v=o5ipQe2rVKQ
@@ -24,10 +31,11 @@ https://www.youtube.com/watch?v=o5ipQe2rVKQ
24
31
 
25
32
  **Another demonstration fixing `NaN` bugs in the PlayCanvas Volumetric Video project:**
26
33
 
27
- https://www.youtube.com/watch?v=KdkTLjyoSeg
34
+ https://www.youtube.com/watch?v=xOp3YWU6M1g
28
35
 
29
- [![volumetric video bug fixing](https://img.youtube.com/vi/KdkTLjyoSeg/0.jpg)](https://www.youtube.com/watch?v=KdkTLjyoSeg)
36
+ [![volumetric video bug fixing](https://img.youtube.com/vi/xOp3YWU6M1g/0.jpg)](https://www.youtube.com/watch?v=xOp3YWU6M1g)
30
37
 
38
+ # Installation (project not published yet)
31
39
 
32
40
  ```
33
41
  npm install runtime-type-inspector
package/jsconfig.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "compilerOptions": {
3
+ "checkJs": true,
4
+ "target": "ES2022",
5
+ "strict": true,
6
+ "moduleResolution": "nodenext",
7
+ "noImplicitOverride": true,
8
+ "module": "es2022"
9
+ }
10
+ }
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "runtime-type-inspector",
3
- "version": "1.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Validating JSDoc types at runtime for high-quality types - Trust is good, control is better.",
5
- "main": "src/index.mjs",
5
+ "main": "src-transpiler/index.mjs",
6
6
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
7
+ "build": "rollup -c",
8
+ "build:atBabelCore": "rollup -c --environment target:atBabelCore",
9
+ "lint": "eslint --ext .js,.mjs,.cjs src test"
8
10
  },
9
11
  "repository": {
10
12
  "type": "git",
@@ -15,5 +17,31 @@
15
17
  "bugs": {
16
18
  "url": "https://github.com/kungfooman/RuntimeTypeInspector.js/issues"
17
19
  },
18
- "homepage": "https://github.com/kungfooman/RuntimeTypeInspector.js#readme"
20
+ "homepage": "https://github.com/kungfooman/RuntimeTypeInspector.js#readme",
21
+ "devDependencies": {
22
+ "@babel/preset-env": "^7.22.20",
23
+ "@rollup/plugin-babel": "^6.0.3",
24
+ "@rollup/plugin-commonjs": "^25.0.4",
25
+ "@rollup/plugin-json": "^6.0.0",
26
+ "@rollup/plugin-node-resolve": "^15.2.1",
27
+ "@rollup/plugin-strip": "^3.0.2",
28
+ "@rollup/plugin-terser": "^0.4.3",
29
+ "@rollup/pluginutils": "^5.0.4",
30
+ "ace-builds": "^1.28.0",
31
+ "eslint": "^8.44.0",
32
+ "eslint-plugin-import": "^2.28.1",
33
+ "eslint-plugin-jsdoc": "^46.6.0",
34
+ "rollup": "^3.29.0",
35
+ "rollup-plugin-dts": "^6.0.1",
36
+ "rollup-plugin-jscc": "^2.0.0",
37
+ "rollup-plugin-visualizer": "^5.9.2",
38
+ "to-fast-properties": "^4.0.0",
39
+ "@babel/helper-plugin-utils": "^7.22.5",
40
+ "@babel/parser": "^7.23.0",
41
+ "@babel/plugin-syntax-typescript": "^7.22.5"
42
+ },
43
+ "dependencies": {
44
+ "@babel/core": "^7.2.0",
45
+ "typescript": "^5.1.6"
46
+ }
19
47
  }
@@ -0,0 +1,4 @@
1
+ function runtimeTypeInspector({enable = true, selftest = false, ignoredFiles} = {}) {
2
+ throw "unimplemented";
3
+ }
4
+ export {runtimeTypeInspector};
@@ -0,0 +1,78 @@
1
+ import {createFilter } from '@rollup/pluginutils';
2
+ import {parse } from '@babel/parser';
3
+ import {addTypeChecks } from '../src-transpiler/addTypeChecks.mjs';
4
+ import {expandType } from '../src-transpiler/expandType.mjs';
5
+ import {ast2jsonForComparison} from '../src-transpiler/ast2jsonForComparison.mjs';
6
+ import {code2ast2code } from '../src-transpiler/code2ast2code.mjs';
7
+ /**
8
+ * Alternatively "import * as rti from ..." would also prevent "Unused external imports" warning...
9
+ * or keeping log of every single call during RTI parsing.
10
+ * @param {boolean} validateDivision
11
+ */
12
+ function getHeader(validateDivision) {
13
+ let header = "import { assertType, youCanAddABreakpointHere";
14
+ if (validateDivision) {
15
+ header += ", validateDivision";
16
+ }
17
+ header += ", registerTypedef, registerClass } from 'runtime-type-inspector/src-runtime/index.mjs';\n";
18
+ // Prevent tree-shaking in UMD build so we can always "add a breakpoint here".
19
+ header += "export * from 'runtime-type-inspector/src-runtime/index.mjs';\n";
20
+ return header;
21
+ }
22
+ /**
23
+ * @param {string} left
24
+ * @param {string} right
25
+ */
26
+ function compareAST(left, right) {
27
+ const l = parse(left , {sourceType: 'module'});
28
+ const r = parse(right, {sourceType: 'module'});
29
+ const ljson = ast2jsonForComparison(l);
30
+ const rjson = ast2jsonForComparison(r);
31
+ const test = ljson == rjson;
32
+ if (!test) {
33
+ console.warn(`AST is NOT equal`);
34
+ }
35
+ }
36
+ /**
37
+ * @param {object} [options] - Optional options.
38
+ * @param {boolean} [options.enable] - Enable or disable entire plugin. Defaults to true.
39
+ * @param {boolean} [options.selftest] - Every once in a while Babel changes the AST, so we
40
+ * self-test Stringifier class to ensure its functionanlity.
41
+ * @param {string[]} [options.ignoredFiles] - Ignore certain files which operate in a different
42
+ * context, for example framework/parsers/draco-worker.js operates as WebWorker (without RTI).
43
+ * @returns {import('rollup').Plugin}
44
+ */
45
+ function runtimeTypeInspector({enable = true, selftest = false, ignoredFiles} = {}) {
46
+ const filter = createFilter([
47
+ '**/*.js'
48
+ ], []);
49
+ return {
50
+ name: 'runtime-type-inspector',
51
+ transform(code, id) {
52
+ if (!enable || !filter(id)) {
53
+ return;
54
+ }
55
+ // Ignore files which are supposed to run in e.g. a Worker context without RTI
56
+ if (ignoredFiles?.some(_ => id.includes(_))) {
57
+ return;
58
+ }
59
+ if (selftest) {
60
+ compareAST(code, code2ast2code(code));
61
+ }
62
+ const validateDivision = true;
63
+ code = getHeader(validateDivision) + code;
64
+ // todo expose options to rollup plugin
65
+ code = addTypeChecks(code, {
66
+ validateDivision,
67
+ // ignoreLocations: ['Tensor#constructor'], // todo
68
+ expandType,
69
+ filename: id,
70
+ });
71
+ return {
72
+ code,
73
+ map: null
74
+ };
75
+ }
76
+ };
77
+ }
78
+ export {runtimeTypeInspector};
@@ -0,0 +1,4 @@
1
+ function runtimeTypeInspector({enable = true, selftest = false, ignoredFiles} = {}) {
2
+ throw "unimplemented";
3
+ }
4
+ export {runtimeTypeInspector};