rip-lang 3.6.1 → 3.7.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/CHANGELOG.md +27 -1
- package/README.md +42 -17
- package/docs/NOTES.md +93 -0
- package/docs/RIP-GUIDE.md +39 -1
- package/docs/RIP-INTERNALS.md +9 -9
- package/docs/RIP-LANG.md +213 -2
- package/docs/RIP-TYPES.md +98 -0
- package/docs/dist/rip.browser.js +976 -508
- package/docs/dist/rip.browser.min.js +215 -215
- package/docs/dist/rip.browser.min.js.br +0 -0
- package/docs/index.html +52 -31
- package/package.json +3 -3
- package/src/compiler.js +238 -151
- package/src/components.js +167 -169
- package/src/grammar/grammar.rip +12 -2
- package/src/lexer.js +77 -5
- package/src/parser.js +123 -120
- package/src/repl.js +4 -128
- package/src/types.js +416 -35
package/src/repl.js
CHANGED
|
@@ -17,7 +17,7 @@ import * as fs from 'fs';
|
|
|
17
17
|
import * as path from 'path';
|
|
18
18
|
import * as os from 'os';
|
|
19
19
|
import * as vm from 'vm';
|
|
20
|
-
import { Compiler, compileToJS } from './compiler.js';
|
|
20
|
+
import { Compiler, compileToJS, getReactiveRuntime, getComponentRuntime } from './compiler.js';
|
|
21
21
|
import packageJson from '../package.json' with { type: 'json' };
|
|
22
22
|
|
|
23
23
|
const VERSION = packageJson.version;
|
|
@@ -114,134 +114,11 @@ export class RipREPL {
|
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
injectReactiveRuntime() {
|
|
117
|
-
|
|
118
|
-
const ctx = this.vmContext;
|
|
119
|
-
|
|
120
|
-
ctx.__currentEffect = null;
|
|
121
|
-
ctx.__pendingEffects = new Set();
|
|
122
|
-
|
|
123
|
-
ctx.__state = function(v) {
|
|
124
|
-
const subs = new Set();
|
|
125
|
-
let notifying = false, locked = false, dead = false;
|
|
126
|
-
const s = {
|
|
127
|
-
get value() { if (dead) return v; if (ctx.__currentEffect) { subs.add(ctx.__currentEffect); ctx.__currentEffect.dependencies.add(subs); } return v; },
|
|
128
|
-
set value(n) {
|
|
129
|
-
if (dead || locked || n === v || notifying) return;
|
|
130
|
-
v = n;
|
|
131
|
-
notifying = true;
|
|
132
|
-
for (const sub of subs) if (sub.markDirty) sub.markDirty();
|
|
133
|
-
for (const sub of subs) if (!sub.markDirty) ctx.__pendingEffects.add(sub);
|
|
134
|
-
const fx = [...ctx.__pendingEffects]; ctx.__pendingEffects.clear();
|
|
135
|
-
for (const e of fx) e.run();
|
|
136
|
-
notifying = false;
|
|
137
|
-
},
|
|
138
|
-
read() { return v; },
|
|
139
|
-
lock() { locked = true; return s; },
|
|
140
|
-
free() { subs.clear(); return s; },
|
|
141
|
-
kill() { dead = true; subs.clear(); return v; },
|
|
142
|
-
valueOf() { return this.value; },
|
|
143
|
-
toString() { return String(this.value); },
|
|
144
|
-
[Symbol.toPrimitive](hint) { return hint === 'string' ? this.toString() : this.valueOf(); }
|
|
145
|
-
};
|
|
146
|
-
return s;
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
ctx.__computed = function(fn) {
|
|
150
|
-
let v, dirty = true, locked = false, dead = false;
|
|
151
|
-
const subs = new Set();
|
|
152
|
-
const c = {
|
|
153
|
-
dependencies: new Set(),
|
|
154
|
-
markDirty() {
|
|
155
|
-
if (!dead && !locked && !dirty) { dirty = true; for (const s of subs) if (s.markDirty) s.markDirty(); for (const s of subs) if (!s.markDirty) ctx.__pendingEffects.add(s); }
|
|
156
|
-
},
|
|
157
|
-
get value() {
|
|
158
|
-
if (dead) return v;
|
|
159
|
-
if (ctx.__currentEffect) { subs.add(ctx.__currentEffect); ctx.__currentEffect.dependencies.add(subs); }
|
|
160
|
-
if (dirty && !locked) {
|
|
161
|
-
for (const d of c.dependencies) d.delete(c); c.dependencies.clear();
|
|
162
|
-
const prev = ctx.__currentEffect; ctx.__currentEffect = c;
|
|
163
|
-
try { v = fn(); } finally { ctx.__currentEffect = prev; }
|
|
164
|
-
dirty = false;
|
|
165
|
-
}
|
|
166
|
-
return v;
|
|
167
|
-
},
|
|
168
|
-
read() { return dead ? v : c.value; },
|
|
169
|
-
lock() { locked = true; c.value; return c; },
|
|
170
|
-
free() { for (const d of c.dependencies) d.delete(c); c.dependencies.clear(); subs.clear(); return c; },
|
|
171
|
-
kill() { dead = true; const result = v; c.free(); return result; },
|
|
172
|
-
valueOf() { return this.value; },
|
|
173
|
-
toString() { return String(this.value); },
|
|
174
|
-
[Symbol.toPrimitive](hint) { return hint === 'string' ? this.toString() : this.valueOf(); }
|
|
175
|
-
};
|
|
176
|
-
return c;
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
ctx.__effect = function(fn) {
|
|
180
|
-
const e = {
|
|
181
|
-
dependencies: new Set(),
|
|
182
|
-
run() {
|
|
183
|
-
for (const d of e.dependencies) d.delete(e); e.dependencies.clear();
|
|
184
|
-
const prev = ctx.__currentEffect; ctx.__currentEffect = e;
|
|
185
|
-
try { fn(); } finally { ctx.__currentEffect = prev; }
|
|
186
|
-
},
|
|
187
|
-
free() { for (const d of e.dependencies) d.delete(e); e.dependencies.clear(); }
|
|
188
|
-
};
|
|
189
|
-
e.run();
|
|
190
|
-
return () => e.free();
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
ctx.__batch = function(fn) { fn(); };
|
|
194
|
-
ctx.__readonly = function(v) { return Object.freeze({ value: v }); };
|
|
117
|
+
vm.runInContext(getReactiveRuntime(), this.vmContext);
|
|
195
118
|
}
|
|
196
119
|
|
|
197
120
|
injectComponentRuntime() {
|
|
198
|
-
|
|
199
|
-
const ctx = this.vmContext;
|
|
200
|
-
|
|
201
|
-
let __currentComponent = null;
|
|
202
|
-
|
|
203
|
-
ctx.__pushComponent = function(component) {
|
|
204
|
-
component._parent = __currentComponent;
|
|
205
|
-
const prev = __currentComponent;
|
|
206
|
-
__currentComponent = component;
|
|
207
|
-
return prev;
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
ctx.__popComponent = function(prev) {
|
|
211
|
-
__currentComponent = prev;
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
ctx.isSignal = function(v) {
|
|
215
|
-
return v != null && typeof v === 'object' && typeof v.read === 'function';
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
ctx.setContext = function(key, value) {
|
|
219
|
-
if (!__currentComponent) throw new Error('setContext must be called during component initialization');
|
|
220
|
-
if (!__currentComponent._context) __currentComponent._context = new Map();
|
|
221
|
-
__currentComponent._context.set(key, value);
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
ctx.getContext = function(key) {
|
|
225
|
-
let component = __currentComponent;
|
|
226
|
-
while (component) {
|
|
227
|
-
if (component._context && component._context.has(key)) return component._context.get(key);
|
|
228
|
-
component = component._parent;
|
|
229
|
-
}
|
|
230
|
-
return undefined;
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
ctx.hasContext = function(key) {
|
|
234
|
-
let component = __currentComponent;
|
|
235
|
-
while (component) {
|
|
236
|
-
if (component._context && component._context.has(key)) return true;
|
|
237
|
-
component = component._parent;
|
|
238
|
-
}
|
|
239
|
-
return false;
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
ctx.__cx__ = function(...args) {
|
|
243
|
-
return args.filter(Boolean).join(' ');
|
|
244
|
-
};
|
|
121
|
+
vm.runInContext(getComponentRuntime(), this.vmContext);
|
|
245
122
|
}
|
|
246
123
|
|
|
247
124
|
async handleLine(line) {
|
|
@@ -329,8 +206,7 @@ export class RipREPL {
|
|
|
329
206
|
const compiler = new Compiler({
|
|
330
207
|
showTokens: this.showTokens,
|
|
331
208
|
showSExpr: this.showSExp,
|
|
332
|
-
|
|
333
|
-
skipComponentRuntime: true,
|
|
209
|
+
skipPreamble: true,
|
|
334
210
|
reactiveVars: this.reactiveVars
|
|
335
211
|
});
|
|
336
212
|
const result = compiler.compile(code);
|