Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function fixSVG(parent: Element, div: HTMLElement, html: string, reference: Node): Bounds {
assert(html !== '', 'html cannot be empty');
let source: Node;
// This is important, because decendants of the
APPEND_OPCODES.add(Op.HasBlockParams, vm => {
// FIXME(mmun): should only need to push the symbol table
let block = vm.stack.pop();
let scope = vm.stack.pop();
check(block, CheckOption(CheckOr(CheckHandle, CheckCompilableBlock)));
check(scope, CheckOption(CheckScope));
let table = check(vm.stack.pop(), CheckOption(CheckBlockSymbolTable));
assert(
table === null || (table && typeof table === 'object' && Array.isArray(table.parameters)),
stackAssert('Option', table)
);
let hasBlockParams = table && table.parameters.length;
vm.stack.push(hasBlockParams ? TRUE_REFERENCE : FALSE_REFERENCE);
});
register(name: string, type: ModuleType, value: Dict) {
assert(name.indexOf('ui/components/ui') === -1, `BUG: ui/components/ui shouldn't be a prefix`);
assert(!name.match(/^[A-Z]/), 'BUG: Components should be nested under ui/components');
this.registry[name] = new Module(value, type);
}
openAttribute(pos: number): void {
assert(this.maybeAttribute === null, `cannot open an attribute if one is already open`);
this.maybeAttribute = new ConstructingAttribute(pos);
}
resolveHandle(s: number): T {
assert(typeof s === 'number', 'Cannot resolve undefined as a handle');
return ({ handle: s } as any) as T;
}
case 'nothing':
assert(
this.tokenLen === 0,
'you can only do nothing when there are no accumulated characters'
);
this.action(accum.action);
return { type: 'continue' };
case 'continue':
this.action(accum.action);
return { type: 'continue' };
case 'skip':
assert(
this.tokenLen === 0,
'you can only skip when there are no accumulated characters yet'
);
this.action(accum.action);
this.startPos += this.tokenLen;
this.tokenLen = 0;
return { type: 'continue' };
case 'emit':
let { before, token } = accum;
if (before !== undefined) {
this.action(before);
}
inlines.add('component', (_name, _params, hash, builder) => {
assert(_params && _params.length, 'SYNTAX ERROR: component helper requires at least one argument');
let [definition, ...params] = _params!;
builder.dynamicComponent(definition, params, hash, true, null, null);
return true;
});
finalize(pos: number): hbs.Root {
assert(
this.elements.length === 1,
`must have exactly one element in the stack to finalize (TODO: error recovery)`
);
let frag = this.elements[0] as ConstructingFragment;
return {
type: 'Root',
span: { start: 0, end: pos },
body: frag.body,
};
}
prepareParams(params: AST.Expression[]) {
if (!params.length) {
this.opcode(['literal', null], null);
return;
}
for (let i = params.length - 1; i >= 0; i--) {
let param = params[i];
assert(this[param.type], `Unimplemented ${param.type} on TemplateCompiler`);
this[param.type](param as any);
}
this.opcode(['prepareArray', params.length], null);
}
closeElement() {
assert(false, 'Cannot closeElement directly inside a block list');
}