Adding getSource native function
This commit is contained in:
parent
767416e30a
commit
0deb8f6307
2 changed files with 8 additions and 2 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue