diff --git a/lib/transform.js b/lib/transform.js index e399bd0..bf9d2ca 100644 --- a/lib/transform.js +++ b/lib/transform.js @@ -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; diff --git a/tests/parse-template.js b/tests/parse-template.js index 1d3cc53..1790263 100644 --- a/tests/parse-template.js +++ b/tests/parse-template.js @@ -14,10 +14,4 @@ describe('parseTemplate', () => { assert(err instanceof Error); }); }); - - it('should parse templates with comments inside', done => { - parseTempatePartial('
', '') - .then(() => done()) - .catch(done); - }); }); diff --git a/tests/transform.js b/tests/transform.js index c7c453b..d25eb60 100644 --- a/tests/transform.js +++ b/tests/transform.js @@ -46,6 +46,13 @@ describe('Transform', () => { assert(slotMap.has('default')); }); + it('should put comment tags in default slot', () => { + const childTemplate = ''; + 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 = `