Adding getSource native function

master
Dustin Swan 3 weeks ago
parent 767416e30a
commit 0deb8f6307
Signed by: dustinswan
GPG Key ID: 30D46587E2100467

@ -103,7 +103,7 @@ function sanitize(name: string): string {
if (ops[name]) return ops[name];
const natives = ['measure', 'measureText', 'storeSearch', 'debug', 'len', 'slice', 'str', 'redefine'];
const natives = ['measure', 'measureText', 'storeSearch', 'getSource', 'debug', 'len', 'slice', 'str', 'redefine'];
if (natives.includes(name)) return `_rt.${name}`;
const reserved = [

@ -1,6 +1,7 @@
import { tokenize } from './lexer'
import { Parser } from './parser'
import { recompile } from './compiler'
import { recompile, definitions } from './compiler'
import { prettyPrint } from './ast'
export const store: Record<string, any> = {};
@ -44,6 +45,11 @@ export const _rt = {
}
return results;
},
getSource: (name: string) => {
const ast = definitions.get(name);
if (!ast) return "";
return prettyPrint(ast);
},
rebind: (name: string, pathOrValue: any, maybeValue?: any) => {
if (maybeValue === undefined) {
if (pathOrValue && pathOrValue.ast) {

Loading…
Cancel
Save