Permalink
Browse files

fix(Let): mark as target after creating instrutions

  • Loading branch information...
bigopon authored and EisenbergEffect committed Oct 12, 2018
1 parent 8452a66 commit 93fa9cc7ac3f51cff47fb9353110f26bdf20cea2
Showing with 23 additions and 1 deletion.
  1. +1 −1 src/view-compiler.js
  2. +22 −0 test/view-compiler.spec.js
@@ -320,13 +320,13 @@ export class ViewCompiler {
// and the binding language has an implementation for it
// This is an backward compat move
if (tagName === 'let' && !type && bindingLanguage.createLetExpressions !== defaultLetHandler) {
auTargetID = makeIntoInstructionTarget(node);
instructions[auTargetID] = TargetInstruction.letElement(
bindingLanguage.createLetExpressions(
resources,
node
)
);
auTargetID = makeIntoInstructionTarget(node);
return node.nextSibling;
}
if (type) {
@@ -150,6 +150,28 @@ describe('ViewCompiler', () => {
expect(viewCompiler.bindingLanguage.createLetExpressions).toHaveBeenCalled();
});
it('marks as target instruction after creating expressions', () => {
const fragment = createFragment('<div><let>');
let instructions = { };
let count = 0;
viewCompiler.bindingLanguage.createLetExpressions = function(resources, letElement) {
count++;
expect(letElement.tagName).toBe('LET');
expect(letElement.classList.contains('au-target')).toBe(false, 'It should not have had .au-target');
expect(letElement.hasAttribute('au-target-id')).toBe(false, 'It should not have had [au-target-id]');
return {};
};
spyOn(viewCompiler.bindingLanguage, 'createLetExpressions').and.callThrough();
viewCompiler._compileNode(fragment, resources, instructions, null, 'root', true);
expect(Object.keys(instructions).length).toBe(1, 'It should have had 1 instruction');
expect(viewCompiler.bindingLanguage.createLetExpressions).toHaveBeenCalled();
const $letEl =fragment.querySelector('let');
expect(count).toBe(1, 'It should have had called the right fn');
expect($letEl).not.toBeNull();
expect($letEl.classList.contains('au-target')).toBe(true, 'It should have had .au-target');
expect($letEl.hasAttribute('au-target-id')).toBe(true, 'It should have had [au-target-id]');
});
describe('backward compat', () => {
it('does nothing if there is custom <let/> element', () => {
let instructions = { };

0 comments on commit 93fa9cc

Please sign in to comment.