Adding getSource native function

This commit is contained in:
Dustin Swan 2026-02-09 13:54:42 -07:00
parent 767416e30a
commit 0deb8f6307
No known key found for this signature in database
GPG key ID: 30D46587E2100467
2 changed files with 8 additions and 2 deletions

View file

@ -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 = [

View file

@ -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) {