Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// pos[0] is the context (or `this`)
// pos[1] is the action name or function
// Anything else is an action argument.
let [context, action, ...restArgs] = capturedArgs.references;
// TODO: Is there a better way of doing this?
let debugKey: string | undefined = (action as any).propertyKey;
let target = named.has('target') ? named.get('target') : context;
let processArgs = makeArgsProcessor(named.has('value') && named.get('value'), restArgs);
let fn: Function;
if (typeof action[INVOKE] === 'function') {
fn = makeClosureAction(action, action, action[INVOKE], processArgs, debugKey);
} else if (isConst(target) && isConst(action)) {
fn = makeClosureAction(context.value(), target.value(), action.value(), processArgs, debugKey);
} else {
fn = makeDynamicClosureAction(context.value(), target, action, processArgs, debugKey);
}
fn[ACTION] = true;
return new UnboundReference(fn);
}
toConditionalReference(reference: Reference): Reference {
if (isConst(reference)) {
return PrimitiveReference.create(emberToBool(reference.value()));
}
return new EmberishConditionalReference(reference);
}
APPEND_OPCODES.add(Op.DynamicContent, (vm, { op1: isTrusting }) => {
let reference = vm.stack.pop>();
let value = reference.value();
let content: DynamicContentWrapper;
if (isTrusting) {
content = vm.elements().appendTrustingDynamicContent(value);
} else {
content = vm.elements().appendCautiousDynamicContent(value);
}
if (!isConst(reference)) {
vm.updateWith(new UpdateDynamicContentOpcode(reference, content));
}
});
flush(env: Environment): Option {
let { reference, element } = this;
if (isConstReference(reference)) {
let value = reference.value();
this.attributeManager.setAttribute(env, element, value, this.namespace);
return null;
} else {
let cache = this.cache = new ReferenceCache(reference);
let value = cache.peek();
this.attributeManager.setAttribute(env, element, value, this.namespace);
return new PatchElementOpcode(this);
}
}
}
assert(`The first argument of {{render}} must be quoted, e.g. {{render "sidebar"}}.`, isConst(nameRef));
assert(`The second argument of {{render}} must be a path, e.g. {{render "post" post}}.`, args.positional.length === 1 || !isConst(args.positional.at(1)));
let templateName = nameRef.value();
assert(`You used \`{{render '${templateName}'}}\`, but '${templateName}' can not be found as a template.`, env.owner.hasRegistration(`template:${templateName}`));
let template = env.owner.lookup(`template:${templateName}`);
let controllerName;
if (args.named.has('controller')) {
let controllerNameRef = args.named.get('controller');
assert(`The controller argument for {{render}} must be quoted, e.g. {{render "sidebar" controller="foo"}}.`, isConst(controllerNameRef));
controllerName = controllerNameRef.value();
assert(`The controller name you supplied '${controllerName}' did not resolve to a controller.`, env.owner.hasRegistration(`controller:${controllerName}`));
} else {
controllerName = templateName;
}
if (args.positional.length === 1) {
return new ConstReference(new RenderDefinition(controllerName, template, env, SINGLETON_RENDER_MANAGER));
} else {
return new ConstReference(new RenderDefinition(controllerName, template, env, NON_SINGLETON_RENDER_MANAGER));
}
}
APPEND_OPCODES.add(Op.JumpIf, (vm, { op1: target }) => {
let reference = check(vm.stack.pop(), CheckReference);
if (isConst(reference)) {
if (reference.value()) {
vm.goto(target);
}
} else {
let cache = new ReferenceCache(reference);
if (cache.peek()) {
vm.goto(target);
}
vm.updateWith(new Assert(cache));
}
});
create(
env: Environment,
{ ComponentClass, layout }: InternalDefinitionState,
args: Arguments,
_dynamicScope: DynamicScope,
caller: VersionedPathReference
): InputComponentState {
assert('caller must be const', isConst(caller));
let type = args.named.get('type');
let instance = ComponentClass.create({
caller: caller.value(),
type: type.value(),
});
let state = { env, type, instance };
if (ENV._DEBUG_RENDER_TREE) {
env.debugRenderTree.create(state, {
type: 'component',
name: 'input',
args: args.capture(),
instance,
APPEND_OPCODES.add(Op.PushRemoteElement, vm => {
let elementRef = vm.stack.pop>();
let nextSiblingRef = vm.stack.pop>>();
let element: Simple.Element;
let nextSibling: Option;
if (isConstReference(elementRef)) {
element = elementRef.value();
} else {
let cache = new ReferenceCache(elementRef);
element = cache.peek();
vm.updateWith(new Assert(cache));
}
if (isConstReference(nextSiblingRef)) {
nextSibling = nextSiblingRef.value();
} else {
let cache = new ReferenceCache(nextSiblingRef);
nextSibling = cache.peek();
vm.updateWith(new Assert(cache));
}
vm.elements().pushRemoteElement(element, nextSibling);
});
flush(vm: VM) {
for (let name in this.attributes) {
let attr = this.attributes[name];
let { value: reference, namespace, trusting } = attr;
if (name === 'class') {
reference = new ClassListReference(this.classes);
}
let attribute = vm.elements().setDynamicAttribute(name, reference.value(), trusting, namespace);
if (!isConst(reference)) {
vm.updateWith(new UpdateDynamicAttributeOpcode(reference, attribute));
}
}
}
}
static create(
sourceReference: VersionedPathReference,
pathReference: PathReference
) {
if (isConst(pathReference)) {
let path = pathReference.value();
return referenceFromPath(sourceReference, path);
} else {
return new GetHelperReference(sourceReference, pathReference);
}
}