@runtime-type-inspector/repl 3.3.7 → 4.0.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/importmap.js +21 -0
- package/index.js +6 -2
- package/package.json +6 -4
- package/test-add.worker.js +23 -0
- package/test-divide.worker.js +48 -0
package/importmap.js
CHANGED
|
@@ -5,16 +5,37 @@
|
|
|
5
5
|
function importFile(content) {
|
|
6
6
|
return "data:text/javascript;base64," + btoa(content);
|
|
7
7
|
}
|
|
8
|
+
const nodeModules = './node_modules/';
|
|
9
|
+
// For React ESM importmap to work you need React ESM: npm i react-es6
|
|
10
|
+
const react = {
|
|
11
|
+
'prop-types' : nodeModules + 'react-es6/prop-types/index.js',
|
|
12
|
+
'tiny-warning' : nodeModules + 'react-es6/tiny-warning.mjs',
|
|
13
|
+
'tiny-invariant' : nodeModules + 'react-es6/tiny-invariant.mjs',
|
|
14
|
+
'mini-create-react-context': nodeModules + 'react-router/node_modules/mini-create-react-context/dist/esm/index.js',
|
|
15
|
+
'path-to-regexp' : nodeModules + 'react-es6/path-to-regexp.mjs',
|
|
16
|
+
'react-is' : nodeModules + 'react-es6/react-is.mjs',
|
|
17
|
+
'hoist-non-react-statics' : nodeModules + 'react-es6/hoist-non-react-statics.mjs',
|
|
18
|
+
'resolve-pathname' : nodeModules + 'react-es6/resolve-pathname.mjs',
|
|
19
|
+
'isarray' : nodeModules + 'react-es6/isarray.mjs',
|
|
20
|
+
};
|
|
21
|
+
const reactMin = {
|
|
22
|
+
...react,
|
|
23
|
+
'react' : nodeModules + 'react-es6/build/react.min.mjs',
|
|
24
|
+
'react-dom' : nodeModules + 'react-es6/build/react-dom.min.mjs',
|
|
25
|
+
'react-dom/client': nodeModules + 'react-es6/build/react-dom-client.min.mjs',
|
|
26
|
+
};
|
|
8
27
|
const imports = {
|
|
9
28
|
"@runtime-type-inspector/runtime" : '../src-runtime/index.js',
|
|
10
29
|
"@runtime-type-inspector/transpiler": '../src-transpiler/index.js',
|
|
11
30
|
"@babel/parser" : "./babel-parser.js",
|
|
12
31
|
"display-anything" : "./node_modules/display-anything/src/index.js",
|
|
32
|
+
"worker-with-import-map" : "./node_modules/worker-with-import-map/src/index.js",
|
|
13
33
|
"test-import-validation-b" : "../test/typechecking/import-validation/b.js",
|
|
14
34
|
//"@babel/helper-plugin-utils" : "./babel-helper-plugin-utils.js",
|
|
15
35
|
//"@babel/plugin-syntax-typescript" : "./babel-plugin-syntax-typescript.js",
|
|
16
36
|
"fs" : importFile("export default {};"),
|
|
17
37
|
"typescript" : importFile("export default ts;"), // UMD import
|
|
38
|
+
...reactMin,
|
|
18
39
|
};
|
|
19
40
|
if (location.host.includes('runtimetypeinspector.org') || location.port === '7000') {
|
|
20
41
|
imports['@runtime-type-inspector/runtime' ] = './node_modules/@runtime-type-inspector/runtime/index.mjs';
|
package/index.js
CHANGED
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
expandTypeBabelTS,
|
|
7
7
|
expandTypeDepFree,
|
|
8
8
|
code2ast2code,
|
|
9
|
-
ast2jsonForComparison
|
|
9
|
+
ast2jsonForComparison,
|
|
10
|
+
parserOptions,
|
|
10
11
|
} from '@runtime-type-inspector/transpiler';
|
|
11
12
|
import * as ti from '@runtime-type-inspector/transpiler';
|
|
12
13
|
import * as rti from '@runtime-type-inspector/runtime';
|
|
@@ -205,7 +206,7 @@ function getRight() {
|
|
|
205
206
|
return aceEditorRight.getValue();
|
|
206
207
|
}
|
|
207
208
|
function actionAST() {
|
|
208
|
-
const ast = parse(getLeft(),
|
|
209
|
+
const ast = parse(getLeft(), parserOptions);
|
|
209
210
|
const out = JSON.stringify(ast, function (name, val) {
|
|
210
211
|
if (name === "loc" || name === "start" || name === "end") {
|
|
211
212
|
return undefined; // remove
|
|
@@ -438,6 +439,7 @@ const aceEditorLeft = setupAce(
|
|
|
438
439
|
// write result to right editor
|
|
439
440
|
// Tip: open F12/DevTools to see errors and warnings
|
|
440
441
|
// Press Shift-Enter in right editor to eval result.
|
|
442
|
+
import {TypePanel} from '@runtime-type-inspector/runtime';
|
|
441
443
|
/**
|
|
442
444
|
* @param {number} a
|
|
443
445
|
* @param {number} b
|
|
@@ -450,6 +452,8 @@ const arr = [10_20];
|
|
|
450
452
|
const [a, b] = arr;
|
|
451
453
|
const ret = add(a, b);
|
|
452
454
|
console.log("ret", ret);
|
|
455
|
+
const typePanel = new TypePanel();
|
|
456
|
+
Object.assign(window, {add, typePanel});
|
|
453
457
|
`,
|
|
454
458
|
//editor => insertTypes(),
|
|
455
459
|
editor => runAction(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runtime-type-inspector/repl",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "REPL of RuntimeTypeInspector.js",
|
|
5
5
|
"main": "index.html",
|
|
6
6
|
"author": "Hermann Rolfes (kungfooman)",
|
|
@@ -9,9 +9,11 @@
|
|
|
9
9
|
"access": "public"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@runtime-type-inspector/transpiler": "^
|
|
13
|
-
"ace-builds": "^1.
|
|
12
|
+
"@runtime-type-inspector/transpiler": "^4.0.0",
|
|
13
|
+
"ace-builds": "^1.35.2",
|
|
14
14
|
"display-anything": "^1.1.0",
|
|
15
|
-
"express": "^4.18.2"
|
|
15
|
+
"express": "^4.18.2",
|
|
16
|
+
"react-es6": "^1.0.0",
|
|
17
|
+
"worker-with-import-map": "^1.0.4"
|
|
16
18
|
}
|
|
17
19
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {inspectType, youCanAddABreakpointHere} from '@runtime-type-inspector/runtime';
|
|
2
|
+
/**
|
|
3
|
+
* @param {number} a
|
|
4
|
+
* @param {number} b
|
|
5
|
+
*/
|
|
6
|
+
function add(a, b) {
|
|
7
|
+
if (!inspectType(a, "number", 'add', 'a')) {
|
|
8
|
+
youCanAddABreakpointHere();
|
|
9
|
+
}
|
|
10
|
+
if (!inspectType(b, "number", 'add', 'b')) {
|
|
11
|
+
youCanAddABreakpointHere();
|
|
12
|
+
}
|
|
13
|
+
return a + b;
|
|
14
|
+
}
|
|
15
|
+
function f() {
|
|
16
|
+
/** @type {number[]} */
|
|
17
|
+
const arr = [10_20];
|
|
18
|
+
const [a, b] = arr;
|
|
19
|
+
const ret = add(a, b);
|
|
20
|
+
self.postMessage(`ret ${ret}`);
|
|
21
|
+
}
|
|
22
|
+
f();
|
|
23
|
+
setInterval(f, 2000); // Test spam mode
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {inspectType, youCanAddABreakpointHere, validateDivision} from '@runtime-type-inspector/runtime';
|
|
2
|
+
/**
|
|
3
|
+
* @param {number} a
|
|
4
|
+
* @param {number} b
|
|
5
|
+
*/
|
|
6
|
+
function testDivide(a, b) {
|
|
7
|
+
if (!inspectType(a, "number", 'testDivide', 'a')) {
|
|
8
|
+
youCanAddABreakpointHere();
|
|
9
|
+
}
|
|
10
|
+
if (!inspectType(b, "number", 'testDivide', 'b')) {
|
|
11
|
+
youCanAddABreakpointHere();
|
|
12
|
+
}
|
|
13
|
+
return validateDivision(a, b, "testDivide");
|
|
14
|
+
}
|
|
15
|
+
function f() {
|
|
16
|
+
/** @type {number[]} */
|
|
17
|
+
const arr = [10_20];
|
|
18
|
+
const [a, b] = arr;
|
|
19
|
+
const ret = testDivide(a, b);
|
|
20
|
+
self.postMessage(`ret ${ret}`);
|
|
21
|
+
}
|
|
22
|
+
f();
|
|
23
|
+
setInterval(f, 2000); // Test spam mode
|
|
24
|
+
|
|
25
|
+
/*
|
|
26
|
+
import {TypePanel} from '@runtime-type-inspector/runtime';
|
|
27
|
+
import {WorkerWithImportMapViaBedfordsShim} from 'worker-with-import-map';
|
|
28
|
+
// console.log("WorkerWithImportMapViaBedfordsShim", WorkerWithImportMapViaBedfordsShim);
|
|
29
|
+
// const url = './test-add.worker.js';
|
|
30
|
+
const url = './test-divide.worker.js';
|
|
31
|
+
const worker = new WorkerWithImportMapViaBedfordsShim(url, {
|
|
32
|
+
importMap: 'inherit'
|
|
33
|
+
});
|
|
34
|
+
console.log("worker", worker);
|
|
35
|
+
const typePanel = new TypePanel();
|
|
36
|
+
worker.addEventListener('message', (e) => {
|
|
37
|
+
// console.log('addEventListener message', e.data);
|
|
38
|
+
if (e.data.type !== 'rti') {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
e.preventDefault();
|
|
42
|
+
e.stopPropagation();
|
|
43
|
+
// Forward message to window listener:
|
|
44
|
+
// window.postMessage(e.data);
|
|
45
|
+
// Forward event directly to typePanel:
|
|
46
|
+
typePanel.handleEvent(e);
|
|
47
|
+
});
|
|
48
|
+
*/
|