@runtime-type-inspector/repl 4.0.0 → 4.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.
@@ -0,0 +1,4 @@
1
+ const generate = (await import("@babel/generator")).default;
2
+ const ast = parse(getLeft(), {sourceType: "module"});
3
+ setRight(generate(ast).code);
4
+
@@ -0,0 +1,99 @@
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/importmap.js CHANGED
@@ -5,7 +5,7 @@
5
5
  function importFile(content) {
6
6
  return "data:text/javascript;base64," + btoa(content);
7
7
  }
8
- const nodeModules = './node_modules/';
8
+ const nodeModules = location.href + './node_modules/';
9
9
  // For React ESM importmap to work you need React ESM: npm i react-es6
10
10
  const react = {
11
11
  'prop-types' : nodeModules + 'react-es6/prop-types/index.js',
@@ -27,14 +27,24 @@ const reactMin = {
27
27
  const imports = {
28
28
  "@runtime-type-inspector/runtime" : '../src-runtime/index.js',
29
29
  "@runtime-type-inspector/transpiler": '../src-transpiler/index.js',
30
- "@babel/parser" : "./babel-parser.js",
31
- "display-anything" : "./node_modules/display-anything/src/index.js",
32
- "worker-with-import-map" : "./node_modules/worker-with-import-map/src/index.js",
33
- "test-import-validation-b" : "../test/typechecking/import-validation/b.js",
34
- //"@babel/helper-plugin-utils" : "./babel-helper-plugin-utils.js",
35
- //"@babel/plugin-syntax-typescript" : "./babel-plugin-syntax-typescript.js",
30
+ "@babel/parser" : nodeModules + '@babel/parser/lib/index.js',
31
+ "display-anything" : nodeModules + 'display-anything/src/index.js',
32
+ "worker-with-import-map" : nodeModules + 'worker-with-import-map/src/index.js',
33
+ "test-import-validation-b" : '../test/typechecking/import-validation/b.js',
34
+ //"@babel/helper-plugin-utils" : './babel-helper-plugin-utils.js',
35
+ //"@babel/plugin-syntax-typescript" : './babel-plugin-syntax-typescript.js',
36
36
  "fs" : importFile("export default {};"),
37
- "typescript" : importFile("export default ts;"), // UMD import
37
+ "typescript" : importFile(`
38
+ globalThis.module = {exports: {}};
39
+ await import("${nodeModules}typescript/lib/typescript.js");
40
+ export default globalThis.module.exports;
41
+ `),
42
+ "ace-builds": importFile(`
43
+ await import("${nodeModules}ace-builds/src/ace.js");
44
+ window.ace.config.set('basePath', "${nodeModules}ace-builds/src");
45
+ const {ace} = window;
46
+ export {ace};
47
+ `),
38
48
  ...reactMin,
39
49
  };
40
50
  if (location.host.includes('runtimetypeinspector.org') || location.port === '7000') {
package/index.html CHANGED
@@ -1,8 +1,6 @@
1
1
  <html>
2
2
  <head>
3
3
  <script src="importmap.js"></script>
4
- <script src="node_modules/ace-builds/src/ace.js"></script>
5
- <script src="node_modules/typescript/lib/typescript.js"></script>
6
4
  <link rel="stylesheet" href="./node_modules/display-anything/src/DisplayAnything.css"></link>
7
5
  </head>
8
6
  <body>
package/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import {parse} from '@babel/parser';
2
+ import {ace} from 'ace-builds';
3
+ import ts from 'typescript';
2
4
  import {
3
5
  parseJSDoc,
4
6
  addTypeChecks,
@@ -170,6 +172,7 @@ function activateREPLRuntime() {
170
172
  buttonREPL.onclick = activateREPL;
171
173
  Object.assign(window, {
172
174
  parse,
175
+ ts,
173
176
  ti, ...ti,
174
177
  rti, ...rti,
175
178
  });
@@ -0,0 +1,21 @@
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runtime-type-inspector/repl",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "REPL of RuntimeTypeInspector.js",
5
5
  "main": "index.html",
6
6
  "author": "Hermann Rolfes (kungfooman)",
@@ -9,7 +9,8 @@
9
9
  "access": "public"
10
10
  },
11
11
  "dependencies": {
12
- "@runtime-type-inspector/transpiler": "^4.0.0",
12
+ "@babel/parser": "^8.0.0-alpha.12",
13
+ "@runtime-type-inspector/transpiler": "^4.0.1",
13
14
  "ace-builds": "^1.35.2",
14
15
  "display-anything": "^1.1.0",
15
16
  "express": "^4.18.2",