@runtime-type-inspector/repl 4.0.6 → 5.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.
- package/ast2wat.js +6 -0
- package/importmap.js +4 -2
- package/index.html +3 -0
- package/index.js +42 -5
- package/package.json +2 -2
- package/wat.html +98 -0
- package/generator test devtools.js +0 -4
- package/importmap (generator).js +0 -99
- package/package (generator).json +0 -21
package/ast2wat.js
ADDED
package/importmap.js
CHANGED
|
@@ -49,8 +49,10 @@ const imports = {
|
|
|
49
49
|
...reactMin,
|
|
50
50
|
};
|
|
51
51
|
if (location.host.includes('runtimetypeinspector.org') || location.port === '7000') {
|
|
52
|
-
imports['@runtime-type-inspector/runtime' ] = './node_modules/@runtime-type-inspector/runtime/index.mjs';
|
|
53
|
-
imports['@runtime-type-inspector/transpiler'] = './node_modules/@runtime-type-inspector/transpiler/index.mjs';
|
|
52
|
+
//imports['@runtime-type-inspector/runtime' ] = './node_modules/@runtime-type-inspector/runtime/index.mjs';
|
|
53
|
+
//imports['@runtime-type-inspector/transpiler'] = './node_modules/@runtime-type-inspector/transpiler/index.mjs';
|
|
54
|
+
imports['@runtime-type-inspector/runtime' ] = '//repo.runtimetypeinspector.org/src-runtime/index.js';
|
|
55
|
+
imports['@runtime-type-inspector/transpiler'] = '//repo.runtimetypeinspector.org/src-transpiler/index.js';
|
|
54
56
|
}
|
|
55
57
|
const importmap = document.createElement("script");
|
|
56
58
|
importmap.type = "importmap";
|
package/index.html
CHANGED
|
@@ -14,11 +14,14 @@
|
|
|
14
14
|
<option value="typechecking">Add full typechecking</option>
|
|
15
15
|
<option value="code2ast2code">code2ast2code (testing Stringifier class)</option>
|
|
16
16
|
<option value="ast">Show AST from JS</option>
|
|
17
|
+
<option value="ast-annotator">Show AST from annotated JS</option>
|
|
17
18
|
<option value="ast-ts">Show AST from TS</option>
|
|
18
19
|
<option value="ast-babel-ts">Show AST from Babel-TS</option>
|
|
19
20
|
<option value="jsdoc">Show parsed JSDoc</option>
|
|
21
|
+
<option value="ts2js">TypeScript to JavaScript + JSDoc</option>
|
|
20
22
|
<option value="expand-type">expandType</option>
|
|
21
23
|
<option value="eval">Eval</option>
|
|
24
|
+
<option value="ast2wat">AST 2 WAT</option>
|
|
22
25
|
</select>
|
|
23
26
|
<button onclick="runAction()">Run action</button>
|
|
24
27
|
<select id="preferred-expand-type">
|
package/index.js
CHANGED
|
@@ -10,9 +10,13 @@ import {
|
|
|
10
10
|
code2ast2code,
|
|
11
11
|
ast2jsonForComparison,
|
|
12
12
|
parserOptions,
|
|
13
|
+
JSDocAnnotator,
|
|
14
|
+
ts2js,
|
|
13
15
|
} from '@runtime-type-inspector/transpiler';
|
|
14
16
|
import * as ti from '@runtime-type-inspector/transpiler';
|
|
15
17
|
import * as rti from '@runtime-type-inspector/runtime';
|
|
18
|
+
import {decodeBase64, encodeBase64} from '@runtime-type-inspector/runtime';
|
|
19
|
+
import {ast2wat} from './ast2wat.js';
|
|
16
20
|
const hashvars = new Map(location.hash.slice(1).split('&').map(_ => _.split('=')));
|
|
17
21
|
if (!hashvars.get('action')) {
|
|
18
22
|
hashvars.set('action', 'typechecking');
|
|
@@ -27,8 +31,8 @@ if (!(selectPreferredExpandType instanceof HTMLSelectElement)) {
|
|
|
27
31
|
throw new Error('This module requires a <select id="action" ...');
|
|
28
32
|
}
|
|
29
33
|
function setHash() {
|
|
30
|
-
const left =
|
|
31
|
-
const right =
|
|
34
|
+
const left = encodeBase64(getLeft());
|
|
35
|
+
const right = encodeBase64(getRight());
|
|
32
36
|
location.hash = `action=${selectAction.value}&left=${left}&right=${right}`;
|
|
33
37
|
}
|
|
34
38
|
// selectPreferredExpandType.value;
|
|
@@ -98,6 +102,10 @@ function getCodeForAction() {
|
|
|
98
102
|
return "const ret = parseJSDoc(jsdoc);\nsetRight(JSON.stringify(ret, null, 2));";
|
|
99
103
|
case 'code2ast2code':
|
|
100
104
|
return "const ret = code2ast2code(jsdoc);\nsetRight(ret);";
|
|
105
|
+
case 'ts2js':
|
|
106
|
+
return "const ret = ts2js(jsdoc);\nsetRight(ret);";
|
|
107
|
+
case 'ast2wat':
|
|
108
|
+
return 'setRight(ast2wat(parse(getLeft())));';
|
|
101
109
|
case 'expand-type':
|
|
102
110
|
return 'setRight(expandTypeAll(jsdoc));';
|
|
103
111
|
}
|
|
@@ -218,6 +226,17 @@ function actionAST() {
|
|
|
218
226
|
}, 2);
|
|
219
227
|
setRight(out);
|
|
220
228
|
}
|
|
229
|
+
function actionAST_Annotator() {
|
|
230
|
+
const ast = parse(getLeft(), parserOptions);
|
|
231
|
+
new JSDocAnnotator().annotate(ast);
|
|
232
|
+
const out = JSON.stringify(ast, function (name, val) {
|
|
233
|
+
if (name === "loc" || name === "start" || name === "end") {
|
|
234
|
+
return undefined; // remove
|
|
235
|
+
}
|
|
236
|
+
return val; // keep
|
|
237
|
+
}, 2);
|
|
238
|
+
setRight(out);
|
|
239
|
+
}
|
|
221
240
|
function actionAST_TS() {
|
|
222
241
|
const str = getLeft();
|
|
223
242
|
const ast = ts.createSourceFile('repl.ts', str, ts.ScriptTarget.Latest, false /*setParentNodes*/);
|
|
@@ -312,12 +331,24 @@ function actionCode2Ast2Code() {
|
|
|
312
331
|
setRight(out);
|
|
313
332
|
// compareAST(content, out);
|
|
314
333
|
}
|
|
334
|
+
function actionTS2JS() {
|
|
335
|
+
setRight(ts2js(getLeft()));
|
|
336
|
+
}
|
|
337
|
+
function actionAST2WAT() {
|
|
338
|
+
const content = getLeft();
|
|
339
|
+
const ast = parse(content, {sourceType: 'module'});
|
|
340
|
+
const out = ast2wat(ast);
|
|
341
|
+
setRight(out);
|
|
342
|
+
}
|
|
315
343
|
async function runAction() {
|
|
316
344
|
const action = getAction();
|
|
317
345
|
switch (action) {
|
|
318
346
|
case 'ast':
|
|
319
347
|
await actionAST();
|
|
320
348
|
break;
|
|
349
|
+
case 'ast-annotator':
|
|
350
|
+
await actionAST_Annotator();
|
|
351
|
+
break;
|
|
321
352
|
case 'ast-ts':
|
|
322
353
|
await actionAST_TS();
|
|
323
354
|
break;
|
|
@@ -333,6 +364,12 @@ async function runAction() {
|
|
|
333
364
|
case 'code2ast2code':
|
|
334
365
|
await actionCode2Ast2Code();
|
|
335
366
|
break;
|
|
367
|
+
case 'ts2js':
|
|
368
|
+
await actionTS2JS();
|
|
369
|
+
break;
|
|
370
|
+
case 'ast2wat':
|
|
371
|
+
await actionAST2WAT();
|
|
372
|
+
break;
|
|
336
373
|
case 'eval':
|
|
337
374
|
eval(aceEditorLeft.getValue());
|
|
338
375
|
break;
|
|
@@ -363,7 +400,7 @@ async function insertTypes() {
|
|
|
363
400
|
aceEditorRight.clearSelection(); // setValue() selects everything, so unselect it now
|
|
364
401
|
}
|
|
365
402
|
/**
|
|
366
|
-
* @typedef {'typechecking'|'code2ast2code'|'ast'|'ast-ts'|'jsdoc'|'eval'|'expand-type'} Action
|
|
403
|
+
* @typedef {'typechecking'|'code2ast2code'|'ast'|'ast-annotator'|'ast-ts'|'jsdoc'|'eval'|'expand-type'|'ast2wat'} Action
|
|
367
404
|
*/
|
|
368
405
|
/** @returns {Action} */
|
|
369
406
|
const getAction = () => selectAction.value;
|
|
@@ -480,10 +517,10 @@ function runRightEditor() {
|
|
|
480
517
|
eval(src);
|
|
481
518
|
}
|
|
482
519
|
if (hashvars.get('left')) {
|
|
483
|
-
setLeft(
|
|
520
|
+
setLeft(decodeBase64(hashvars.get('left')));
|
|
484
521
|
}
|
|
485
522
|
if (hashvars.get('right')) {
|
|
486
|
-
setRight(
|
|
523
|
+
setRight(decodeBase64(hashvars.get('right')));
|
|
487
524
|
}
|
|
488
525
|
export {
|
|
489
526
|
setHash,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runtime-type-inspector/repl",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "REPL of RuntimeTypeInspector.js",
|
|
5
5
|
"main": "index.html",
|
|
6
6
|
"author": "Hermann Rolfes (kungfooman)",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@babel/parser": "^8.0.0-alpha.12",
|
|
13
|
-
"@runtime-type-inspector/transpiler": "^
|
|
13
|
+
"@runtime-type-inspector/transpiler": "^5.0.1",
|
|
14
14
|
"ace-builds": "^1.35.2",
|
|
15
15
|
"ace-diff": "^3.0.3",
|
|
16
16
|
"display-anything": "^1.1.0",
|
package/wat.html
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>WAT Code Runner</title>
|
|
7
|
+
<style>
|
|
8
|
+
body {
|
|
9
|
+
font-family: Arial, sans-serif;
|
|
10
|
+
margin: 20px;
|
|
11
|
+
max-width: 800px;
|
|
12
|
+
margin-left: auto;
|
|
13
|
+
margin-right: auto;
|
|
14
|
+
}
|
|
15
|
+
textarea {
|
|
16
|
+
width: 100%;
|
|
17
|
+
height: 200px;
|
|
18
|
+
font-family: 'Courier New', Courier, monospace;
|
|
19
|
+
font-size: 14px;
|
|
20
|
+
resize: vertical;
|
|
21
|
+
margin-bottom: 10px;
|
|
22
|
+
}
|
|
23
|
+
button {
|
|
24
|
+
padding: 10px 20px;
|
|
25
|
+
font-size: 16px;
|
|
26
|
+
cursor: pointer;
|
|
27
|
+
background-color: #4CAF50;
|
|
28
|
+
color: white;
|
|
29
|
+
border: none;
|
|
30
|
+
border-radius: 4px;
|
|
31
|
+
}
|
|
32
|
+
button:hover {
|
|
33
|
+
background-color: #45a049;
|
|
34
|
+
}
|
|
35
|
+
#output {
|
|
36
|
+
margin-top: 20px;
|
|
37
|
+
padding: 10px;
|
|
38
|
+
border: 1px solid #ccc;
|
|
39
|
+
min-height: 100px;
|
|
40
|
+
font-family: 'Courier New', Courier, monospace;
|
|
41
|
+
white-space: pre-wrap;
|
|
42
|
+
}
|
|
43
|
+
label {
|
|
44
|
+
display: block;
|
|
45
|
+
margin-top: 10px;
|
|
46
|
+
font-weight: bold;
|
|
47
|
+
}
|
|
48
|
+
</style>
|
|
49
|
+
</head>
|
|
50
|
+
<body>
|
|
51
|
+
<h1>WAT Code Runner</h1>
|
|
52
|
+
<label for="watCode">WAT Code:</label>
|
|
53
|
+
<textarea id="watCode" placeholder="Paste your WAT code here...">
|
|
54
|
+
(module
|
|
55
|
+
(func $add (param $a i32) (param $b i32) (result i32)
|
|
56
|
+
local.get $a
|
|
57
|
+
local.get $b
|
|
58
|
+
i32.add)
|
|
59
|
+
(export "add" (func $add)))
|
|
60
|
+
</textarea>
|
|
61
|
+
<label for="jsCode">JavaScript Test Code:</label>
|
|
62
|
+
<textarea id="jsCode" placeholder="Write JavaScript to test the WebAssembly exports...">
|
|
63
|
+
const {add} = instance.exports;
|
|
64
|
+
const result = instance.exports.add(552, 3);
|
|
65
|
+
output.textContent = `Result: ${result}`;
|
|
66
|
+
</textarea>
|
|
67
|
+
<br>
|
|
68
|
+
<button onclick="runWAT()">Run WAT Code</button>
|
|
69
|
+
<div id="output"></div>
|
|
70
|
+
<script src="https://unpkg.com/wabt@1.0.24/index.js"></script>
|
|
71
|
+
<script>
|
|
72
|
+
async function runWAT() {
|
|
73
|
+
const output = document.getElementById('output');
|
|
74
|
+
output.textContent = 'Running...';
|
|
75
|
+
try {
|
|
76
|
+
const watCode = document.getElementById('watCode').value;
|
|
77
|
+
const jsCode = document.getElementById('jsCode').value;
|
|
78
|
+
// Initialize WABT
|
|
79
|
+
const wabt = await WabtModule();
|
|
80
|
+
// Parse WAT and compile to WASM binary
|
|
81
|
+
const module = wabt.parseWat('inline', watCode);
|
|
82
|
+
const binary = module.toBinary({write_debug_names: false}).buffer;
|
|
83
|
+
// Compile WASM binary to WebAssembly module
|
|
84
|
+
const wasmModule = await WebAssembly.compile(binary);
|
|
85
|
+
const instance = await WebAssembly.instantiate(wasmModule, {});
|
|
86
|
+
// Create a function from the user-provided JS code
|
|
87
|
+
const testExports = new Function('instance', 'output', jsCode);
|
|
88
|
+
// Execute the user-provided JS code
|
|
89
|
+
testExports(instance, output);
|
|
90
|
+
// Clean up
|
|
91
|
+
module.destroy();
|
|
92
|
+
} catch (error) {
|
|
93
|
+
output.textContent = `Error: ${error.message}`;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
</script>
|
|
97
|
+
</body>
|
|
98
|
+
</html>
|
package/importmap (generator).js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param {string} content - The content.
|
|
3
|
-
* @returns {string} data:text string
|
|
4
|
-
*/
|
|
5
|
-
function importFile(content) {
|
|
6
|
-
return "data:text/javascript;base64," + btoa(content);
|
|
7
|
-
}
|
|
8
|
-
const nodeModules = location.href + './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
|
-
};
|
|
27
|
-
window.process = {
|
|
28
|
-
env: {
|
|
29
|
-
BABEL_TYPES_8_BREAKING: true,
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
const imports = {
|
|
33
|
-
"@runtime-type-inspector/runtime" : '../src-runtime/index.js',
|
|
34
|
-
"@runtime-type-inspector/transpiler": '../src-transpiler/index.js',
|
|
35
|
-
"@babel/parser" : nodeModules + '@babel/parser/lib/index.js',
|
|
36
|
-
// All needed for generator:
|
|
37
|
-
"@babel/generator" : nodeModules + '@babel/generator/lib/index.js',
|
|
38
|
-
"@babel/types" : nodeModules + '@babel/types/lib/index.js',
|
|
39
|
-
"@babel/helper-validator-identifier": nodeModules + '@babel/helper-validator-identifier/lib/index.js',
|
|
40
|
-
"@babel/helper-string-parser" : nodeModules + '@babel/helper-string-parser/lib/index.js',
|
|
41
|
-
"@jridgewell/gen-mapping" : importFile(`
|
|
42
|
-
export function GenMapping() {
|
|
43
|
-
throw Error("GenMapping not implemented");
|
|
44
|
-
}
|
|
45
|
-
export function toEncodedMap() {
|
|
46
|
-
throw Error("toEncodedMap not implemented");
|
|
47
|
-
}
|
|
48
|
-
export function setSourceContent() {
|
|
49
|
-
throw Error("setSourceContent not implemented");
|
|
50
|
-
}
|
|
51
|
-
export function toDecodedMap() {
|
|
52
|
-
throw Error("toDecodedMap not implemented");
|
|
53
|
-
}
|
|
54
|
-
export function allMappings() {
|
|
55
|
-
throw Error("allMappings not implemented");
|
|
56
|
-
}
|
|
57
|
-
export function maybeAddMapping() {
|
|
58
|
-
throw Error("maybeAddMapping not implemented");
|
|
59
|
-
}
|
|
60
|
-
export default {}`),
|
|
61
|
-
"@jridgewell/trace-mapping" : importFile(`
|
|
62
|
-
export function originalPositionFor() {}
|
|
63
|
-
export function TraceMap() {}
|
|
64
|
-
export default {}
|
|
65
|
-
`),
|
|
66
|
-
"jsesc" : importFile('export default {}'),
|
|
67
|
-
"process" : importFile("export default {};"),
|
|
68
|
-
// </for generator>
|
|
69
|
-
"display-anything" : nodeModules + 'display-anything/src/index.js',
|
|
70
|
-
"worker-with-import-map" : nodeModules + 'worker-with-import-map/src/index.js',
|
|
71
|
-
"test-import-validation-b" : '../test/typechecking/import-validation/b.js',
|
|
72
|
-
//"@babel/helper-plugin-utils" : './babel-helper-plugin-utils.js',
|
|
73
|
-
//"@babel/plugin-syntax-typescript" : './babel-plugin-syntax-typescript.js',
|
|
74
|
-
"fs" : importFile("export default {};"),
|
|
75
|
-
"typescript" : importFile(`
|
|
76
|
-
globalThis.module = {exports: {}};
|
|
77
|
-
await import("${nodeModules}typescript/lib/typescript.js");
|
|
78
|
-
export default globalThis.module.exports;
|
|
79
|
-
`),
|
|
80
|
-
"ace-builds": importFile(`
|
|
81
|
-
await import("${nodeModules}ace-builds/src/ace.js");
|
|
82
|
-
window.ace.config.set('basePath', "${nodeModules}ace-builds/src");
|
|
83
|
-
const {ace} = window;
|
|
84
|
-
export {ace};
|
|
85
|
-
`),
|
|
86
|
-
...reactMin,
|
|
87
|
-
};
|
|
88
|
-
if (location.host.includes('runtimetypeinspector.org') || location.port === '7000') {
|
|
89
|
-
imports['@runtime-type-inspector/runtime' ] = './node_modules/@runtime-type-inspector/runtime/index.mjs';
|
|
90
|
-
imports['@runtime-type-inspector/transpiler'] = './node_modules/@runtime-type-inspector/transpiler/index.mjs';
|
|
91
|
-
}
|
|
92
|
-
const importmap = document.createElement("script");
|
|
93
|
-
importmap.type = "importmap";
|
|
94
|
-
importmap.textContent = JSON.stringify({imports});
|
|
95
|
-
const dom = document.body || document.head;
|
|
96
|
-
if (!dom) {
|
|
97
|
-
throw new Error("neither <body> nor <head> available to append importmap");
|
|
98
|
-
}
|
|
99
|
-
dom.append(importmap);
|
package/package (generator).json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@runtime-type-inspector/repl",
|
|
3
|
-
"version": "4.0.0",
|
|
4
|
-
"description": "REPL of RuntimeTypeInspector.js",
|
|
5
|
-
"main": "index.html",
|
|
6
|
-
"author": "Hermann Rolfes (kungfooman)",
|
|
7
|
-
"license": "MIT",
|
|
8
|
-
"publishConfig": {
|
|
9
|
-
"access": "public"
|
|
10
|
-
},
|
|
11
|
-
"dependencies": {
|
|
12
|
-
"@babel/parser": "^8.0.0-alpha.12",
|
|
13
|
-
"@babel/generator": "^8.0.0-alpha.12",
|
|
14
|
-
"@runtime-type-inspector/transpiler": "^4.0.0",
|
|
15
|
-
"ace-builds": "^1.35.2",
|
|
16
|
-
"display-anything": "^1.1.0",
|
|
17
|
-
"express": "^4.18.2",
|
|
18
|
-
"react-es6": "^1.0.0",
|
|
19
|
-
"worker-with-import-map": "^1.0.4"
|
|
20
|
-
}
|
|
21
|
-
}
|