UNPKG

ember-legacy-class-transform

Version:
54 lines 1.78 kB
import { dict } from '@glimmer/util'; import { APPEND_OPCODES } from '../../opcodes'; /* tslint:disable */ function debugCallback(context, get) { console.info('Use `context`, and `get(<path>)` to debug this template.'); // for example... context === get('this'); debugger; } /* tslint:enable */ let callback = debugCallback; // For testing purposes export function setDebuggerCallback(cb) { callback = cb; } export function resetDebuggerCallback() { callback = debugCallback; } class ScopeInspector { constructor(scope, symbols, evalInfo) { this.scope = scope; this.locals = dict(); for (let i = 0; i < evalInfo.length; i++) { let slot = evalInfo[i]; let name = symbols[slot - 1]; let ref = scope.getSymbol(slot); this.locals[name] = ref; } } get(path) { let { scope, locals } = this; let parts = path.split('.'); let [head, ...tail] = path.split('.'); let evalScope = scope.getEvalScope(); let ref; if (head === 'this') { ref = scope.getSelf(); } else if (locals[head]) { ref = locals[head]; } else if (head.indexOf('@') === 0 && evalScope[head]) { ref = evalScope[head]; } else { ref = this.scope.getSelf(); tail = parts; } return tail.reduce((r, part) => r.get(part), ref); } } APPEND_OPCODES.add(71 /* Debugger */, (vm, { op1: _symbols, op2: _evalInfo }) => { let symbols = vm.constants.getOther(_symbols); let evalInfo = vm.constants.getArray(_evalInfo); let inspector = new ScopeInspector(vm.scope(), symbols, evalInfo); callback(vm.getSelf().value(), path => inspector.get(path).value()); });