From 0deb8f6307d99b9ed266f46764138138bb003dcb Mon Sep 17 00:00:00 2001 From: Dustin Swan Date: Mon, 9 Feb 2026 13:54:42 -0700 Subject: [PATCH] Adding getSource native function --- src/compiler.ts | 2 +- src/runtime-js.ts | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 11e5204..0d7402a 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -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 = [ diff --git a/src/runtime-js.ts b/src/runtime-js.ts index 4a4cd59..7ca1411 100644 --- a/src/runtime-js.ts +++ b/src/runtime-js.ts @@ -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 = {}; @@ -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) {