rip-lang 3.5.0 → 3.6.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.
Binary file
package/docs/index.html CHANGED
@@ -1551,7 +1551,7 @@ console.log "Domain:", domain`;
1551
1551
  });
1552
1552
 
1553
1553
  // Run button - executes the Rip code and outputs to console
1554
- function runCode() {
1554
+ async function runCode() {
1555
1555
  try {
1556
1556
  const source = monacoEditor.getValue();
1557
1557
  const result = compile(source);
@@ -1560,7 +1560,7 @@ console.log "Domain:", domain`;
1560
1560
  // Execute the compiled JavaScript and log to console
1561
1561
  console.clear();
1562
1562
  console.log('%c=== Rip Code Execution ===', 'color: #007acc; font-weight: bold');
1563
- eval(js);
1563
+ await (0, eval)(`(async()=>{\n${js}\n})()`);
1564
1564
  console.log('%c=== Execution Complete ===', 'color: #4ec9b0; font-weight: bold');
1565
1565
  } catch (error) {
1566
1566
  console.error('Execution Error:', error);
@@ -1569,9 +1569,12 @@ console.log "Domain:", domain`;
1569
1569
 
1570
1570
  document.getElementById('run-btn').addEventListener('click', runCode);
1571
1571
 
1572
- // Keyboard shortcuts: F5, Cmd+Enter (Mac), Ctrl+Enter (Windows/Linux)
1572
+ // Keyboard shortcuts: Cmd+Enter (Mac), Ctrl+Enter (Windows/Linux)
1573
+ monacoEditor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter, runCode);
1574
+
1575
+ // F5 runs code from anywhere on the page
1573
1576
  document.addEventListener('keydown', (e) => {
1574
- if (e.key === 'F5' || (e.key === 'Enter' && (e.metaKey || e.ctrlKey))) {
1577
+ if (e.key === 'F5') {
1575
1578
  e.preventDefault();
1576
1579
  runCode();
1577
1580
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rip-lang",
3
- "version": "3.5.0",
3
+ "version": "3.6.1",
4
4
  "description": "A modern language that compiles to JavaScript",
5
5
  "type": "module",
6
6
  "main": "src/compiler.js",
package/src/browser.js CHANGED
@@ -84,13 +84,24 @@ export async function importRip(url) {
84
84
  */
85
85
  export function rip(code) {
86
86
  try {
87
- const js = compileToJS(code);
88
-
89
- // Strip let/const declarations so variables become implicit globals
90
- let persistentJs = js.replace(/^let\s+[^;]+;\s*\n\s*/m, '');
91
- persistentJs = persistentJs.replace(/^const\s+/gm, 'var ');
92
-
93
- const result = (1, eval)(persistentJs);
87
+ // Wrap in a do block so Rip handles implicit return and auto-async
88
+ const indented = code.replace(/^/gm, ' ');
89
+ const wrapped = compileToJS(`do ->\n${indented}`);
90
+
91
+ // Strip let declarations so variables become implicit globals
92
+ let js = wrapped.replace(/^let\s+[^;]+;\s*\n\s*/m, '');
93
+ js = js.replace(/^const\s+(\w+)\s*=/gm, 'globalThis.$1 =');
94
+
95
+ // Eval — the do block compiles to an IIFE (async if code uses !)
96
+ const result = (0, eval)(js);
97
+
98
+ // If async (returns a Promise), persist the resolved value
99
+ if (result && typeof result.then === 'function') {
100
+ return result.then(v => {
101
+ if (v !== undefined) globalThis._ = v;
102
+ return v;
103
+ });
104
+ }
94
105
 
95
106
  if (result !== undefined) globalThis._ = result;
96
107
  return result;