Skip to content
This repository has been archived by the owner on Dec 5, 2022. It is now read-only.

parse comment tags without error in child templates #195

Merged
merged 1 commit into from
Dec 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
parse comment tags without error in child templates
  • Loading branch information
vigneshshanmugam committed Oct 27, 2017
commit 84ec0f174a7bef04cd14853f5f8a486803b60eaf
9 changes: 3 additions & 6 deletions lib/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,13 @@ module.exports = class Transform {
const slotMap = new Map([['default', []]]);
const nodes = treeAdapter.getChildNodes(root);
nodes.forEach(node => {
if (
!treeAdapter.isTextNode(node) &&
!treeAdapter.isCommentNode(node)
) {
const { slot = 'default' } = node.attribs;
if (!treeAdapter.isTextNode(node)) {
const { slot = 'default' } = node.attribs || {};
const slotNodes = slotMap.get(slot) || [];
const updatedSlotNodes = [...slotNodes, node];
slotMap.set(slot, updatedSlotNodes);
this._pushText(node.next, updatedSlotNodes);
delete node.attribs.slot;
node.attribs && delete node.attribs.slot;
}
});
return slotMap;
Expand Down
6 changes: 0 additions & 6 deletions tests/parse-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,4 @@ describe('parseTemplate', () => {
assert(err instanceof Error);
});
});

it('should parse templates with comments inside', done => {
parseTempatePartial('<div></div>', '<!-- nice comment -->')
.then(() => done())
.catch(done);
});
});
7 changes: 7 additions & 0 deletions tests/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ describe('Transform', () => {
assert(slotMap.has('default'));
});

it('should put comment tags in default slot', () => {
const childTemplate = '<!-- nice comment -->';
transformInstance.applyTransforms('', childTemplate);
const slotMap = mockSerializer.args[0][1].slotMap;
assert(slotMap.has('default'));
});

it('should group slots based on slot types for child Templates', () => {
const childTemplate = `
<meta slot="head">
Expand Down