rip-lang 3.4.6 → 3.5.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.
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rip-lang",
3
- "version": "3.4.6",
3
+ "version": "3.5.0",
4
4
  "description": "A modern language that compiles to JavaScript",
5
5
  "type": "module",
6
6
  "main": "src/compiler.js",
@@ -67,7 +67,7 @@
67
67
  "author": "Steve Shreeve <steve.shreeve@gmail.com>",
68
68
  "license": "MIT",
69
69
  "devDependencies": {
70
- "@rip-lang/api": "1.1.5",
71
- "@rip-lang/ui": "0.1.3"
70
+ "@rip-lang/api": "workspace:*",
71
+ "@rip-lang/ui": "workspace:*"
72
72
  }
73
73
  }
package/src/browser.js CHANGED
@@ -10,7 +10,14 @@ export const VERSION = "0.0.0";
10
10
  export const BUILD_DATE = "0000-00-00@00:00:00GMT";
11
11
 
12
12
  // Import compileToJS for use in rip() function
13
- import { compileToJS } from './compiler.js';
13
+ import { compileToJS, getReactiveRuntime } from './compiler.js';
14
+
15
+ // Eagerly register Rip's reactive primitives on globalThis so that
16
+ // framework code (ui.rip) can use them directly without the compiler
17
+ // needing to detect reactive operators in the source
18
+ if (typeof globalThis !== 'undefined' && !globalThis.__rip) {
19
+ new Function(getReactiveRuntime())();
20
+ }
14
21
 
15
22
  const dedent = s => {
16
23
  const m = s.match(/^[ \t]*(?=\S)/gm);
@@ -29,8 +36,8 @@ async function processRipScripts() {
29
36
  const ripCode = dedent(script.textContent);
30
37
  const jsCode = compileToJS(ripCode);
31
38
 
32
- // Execute in global scope using indirect eval
33
- (0, eval)(jsCode);
39
+ // Execute as async to support await (importRip!, etc.)
40
+ await (0, eval)(`(async()=>{\n${jsCode}\n})()`);
34
41
 
35
42
  script.setAttribute('data-rip-processed', 'true');
36
43
  } catch (error) {
@@ -51,6 +58,26 @@ if (typeof document !== 'undefined') {
51
58
 
52
59
  export { processRipScripts };
53
60
 
61
+ /**
62
+ * Import a .rip file as an ES module
63
+ * Fetches the URL, compiles Rip→JS, dynamically imports via Blob URL
64
+ * Usage: const { launch } = await importRip('/ui.rip')
65
+ */
66
+ export async function importRip(url) {
67
+ const source = await fetch(url).then(r => {
68
+ if (!r.ok) throw new Error(`importRip: ${url} (${r.status})`);
69
+ return r.text();
70
+ });
71
+ const js = compileToJS(source);
72
+ const blob = new Blob([js], { type: 'application/javascript' });
73
+ const blobUrl = URL.createObjectURL(blob);
74
+ try {
75
+ return await import(blobUrl);
76
+ } finally {
77
+ URL.revokeObjectURL(blobUrl);
78
+ }
79
+ }
80
+
54
81
  /**
55
82
  * Browser Console REPL
56
83
  * Usage: rip('x = 42') → evaluates and returns result
@@ -73,7 +100,9 @@ export function rip(code) {
73
100
  }
74
101
  }
75
102
 
76
- // Make rip() available globally for console use
103
+ // Make key functions available globally for console and <script type="text/rip"> use
77
104
  if (typeof globalThis !== 'undefined') {
78
105
  globalThis.rip = rip;
106
+ globalThis.importRip = importRip;
107
+ globalThis.compileToJS = compileToJS;
79
108
  }