Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('compiles surrogate', function () {
const { instructions, surrogates } = compileWith(
`<template class="h-100"></template>`,
[]
);
verifyInstructions(instructions, []);
verifyInstructions(
surrogates,
[{ toVerify: ['type', 'value', 'to'], type: HTT.setAttribute, value: 'h-100', to: 'class' }]
);
});
it('compiles surrogate', function () {
const { instructions, surrogates } = compileWith(
`<template class="h-100"></template>`,
[]
);
verifyInstructions(instructions, []);
verifyInstructions(surrogates, [
{ toVerify: ['type', 'value', 'to'], type: HTT.setAttribute, value: 'h-100', to: 'class' }
]);
});
eachCartesianJoin(
[
[
TargetedInstructionType.callBinding,
TargetedInstructionType.hydrateAttribute,
TargetedInstructionType.hydrateElement,
TargetedInstructionType.hydrateLetElement,
TargetedInstructionType.hydrateTemplateController,
TargetedInstructionType.interpolation,
TargetedInstructionType.iteratorBinding,
TargetedInstructionType.letBinding,
TargetedInstructionType.propertyBinding,
TargetedInstructionType.refBinding,
TargetedInstructionType.setProperty,
HTMLTargetedInstructionType.listenerBinding,
HTMLTargetedInstructionType.setAttribute,
HTMLTargetedInstructionType.stylePropertyBinding,
HTMLTargetedInstructionType.textBinding
]
],
t => {
it(`understands targeted instruction type=${t}`, function () {
const ctx = TestContext.createHTMLTestContext();
//@ts-ignore
const actual = sut(ctx.dom, tag, { prop: { type: t }});
const instruction = actual['instructions'][0][0] as TargetedInstruction;
const node = actual['node'] as Element;
assert.strictEqual(actual['instructions'].length, 1, `actual['instructions'].length`);
assert.strictEqual(actual['instructions'][0].length, 1, `actual['instructions'][0].length`);
assert.strictEqual(instruction.type, t, `instruction.type`);
const ctx = TestContext.createHTMLTestContext();
const type = createType();
const actual = sut(ctx.dom, type, { title: 'asdf', foo: 'bar' });
const node = actual['node'] as Element;
const instruction = (actual['instructions'][0][0] as any) as HydrateElementInstruction;
assert.strictEqual(node.getAttribute('title'), null, `node.getAttribute('title')`);
assert.strictEqual(node.getAttribute('foo'), null, `node.getAttribute('foo')`);
assert.strictEqual(actual['instructions'].length, 1, `actual['instructions'].length`);
assert.strictEqual(actual['instructions'][0].length, 1, `actual['instructions'][0].length`);
assert.strictEqual(instruction.type, TargetedInstructionType.hydrateElement, `instruction.type`);
assert.strictEqual(instruction.res, type.description.name, `instruction.res`);
assert.strictEqual(instruction.instructions.length, 2, `instruction.instructions.length`);
assert.strictEqual(instruction.instructions[0].type, HTMLTargetedInstructionType.setAttribute, `instruction.instructions[0].type`);
assert.strictEqual(instruction.instructions[0]['to'], 'title', `instruction.instructions[0]['to']`);
assert.strictEqual(instruction.instructions[0]['value'], 'asdf', `instruction.instructions[0]['value']`);
if (type.description.bindables['foo']) {
assert.strictEqual(instruction.instructions[1].type, TargetedInstructionType.setProperty, `instruction.instructions[1].type`);
} else {
assert.strictEqual(instruction.instructions[1].type, HTMLTargetedInstructionType.setAttribute, `instruction.instructions[1].type`);
}
assert.strictEqual(instruction.instructions[1]['to'], 'foo', `instruction.instructions[1]['to']`);
assert.strictEqual(instruction.instructions[1]['value'], 'bar', `instruction.instructions[1]['value']`);
assert.strictEqual(node.getAttribute('class'), 'au', `node.getAttribute('class')`);
});
return 'interpolation';
case TargetedInstructionType.propertyBinding:
return 'propertyBinding';
case TargetedInstructionType.iteratorBinding:
return 'iteratorBinding';
case HTMLTargetedInstructionType.listenerBinding:
return 'listenerBinding';
case TargetedInstructionType.callBinding:
return 'callBinding';
case TargetedInstructionType.refBinding:
return 'refBinding';
case HTMLTargetedInstructionType.stylePropertyBinding:
return 'stylePropertyBinding';
case TargetedInstructionType.setProperty:
return 'setProperty';
case HTMLTargetedInstructionType.setAttribute:
return 'setAttribute';
case TargetedInstructionType.hydrateElement:
return 'hydrateElement';
case TargetedInstructionType.hydrateAttribute:
return 'hydrateAttribute';
case TargetedInstructionType.hydrateTemplateController:
return 'hydrateTemplateController';
case TargetedInstructionType.hydrateLetElement:
return 'hydrateLetElement';
case TargetedInstructionType.letBinding:
return 'letBinding';
default:
return type;
}
}
case HTMLTargetedInstructionType.listenerBinding:
output += 'listenerBinding\n';
break;
case TargetedInstructionType.propertyBinding:
output += 'propertyBinding\n';
break;
case TargetedInstructionType.refBinding:
output += 'refBinding\n';
break;
case HTMLTargetedInstructionType.stylePropertyBinding:
output += 'stylePropertyBinding\n';
break;
case TargetedInstructionType.setProperty:
output += 'setProperty\n';
break;
case HTMLTargetedInstructionType.setAttribute:
output += 'setAttribute\n';
break;
case TargetedInstructionType.interpolation:
output += 'interpolation\n';
break;
case TargetedInstructionType.hydrateLetElement:
output += 'hydrateLetElement\n';
instruction.instructions.forEach(i => {
output += stringifyInstructions(i, depth + 1);
});
break;
case TargetedInstructionType.hydrateAttribute:
output += `hydrateAttribute: ${instruction.res}\n`;
instruction.instructions.forEach(i => {
output += stringifyInstructions(i as HTMLTargetedInstruction, depth + 1);
});
case HTMLTargetedInstructionType.listenerBinding:
output += 'listenerBinding\n';
break;
case TargetedInstructionType.propertyBinding:
output += 'propertyBinding\n';
break;
case TargetedInstructionType.refBinding:
output += 'refBinding\n';
break;
case HTMLTargetedInstructionType.stylePropertyBinding:
output += 'stylePropertyBinding\n';
break;
case TargetedInstructionType.setProperty:
output += 'setProperty\n';
break;
case HTMLTargetedInstructionType.setAttribute:
output += 'setAttribute\n';
break;
case TargetedInstructionType.interpolation:
output += 'interpolation\n';
break;
case TargetedInstructionType.hydrateLetElement:
output += 'hydrateLetElement\n';
instruction.instructions.forEach(i => {
output += stringifyInstructions(i, depth + 1);
});
break;
case TargetedInstructionType.hydrateAttribute:
output += `hydrateAttribute: ${instruction.res}\n`;
instruction.instructions.forEach(i => {
output += stringifyInstructions(i as HTMLTargetedInstruction, depth + 1);
});