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

Tailor fails to parse template with comments inside #191

Merged
merged 2 commits into from
Oct 20, 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
5 changes: 4 additions & 1 deletion lib/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ module.exports = class Transform {
const slotMap = new Map([['default', []]]);
const nodes = treeAdapter.getChildNodes(root);
nodes.forEach(node => {
if (!treeAdapter.isTextNode(node)) {
if (
!treeAdapter.isTextNode(node) &&
!treeAdapter.isCommentNode(node)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should not be handled in this way..

This fix mean would completely skip comment nodes from child templates which is not the expected output.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, so why do we handle text nodes like?

Tomorrow I will take a look on passing it through.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, so why do we handle text nodes like?

yup, that was a bit puzzling, thus was thinking it's ok to have comments handled the same way

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally forgot why i did it that way. Will update once i remember.

But, with the fix #195, we can even include text nodes(space) as part of child templates.

) {
const { slot = 'default' } = node.attribs;
const slotNodes = slotMap.get(slot) || [];
const updatedSlotNodes = [...slotNodes, node];
Expand Down
6 changes: 6 additions & 0 deletions tests/parse-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ describe('parseTemplate', () => {
assert(err instanceof Error);
});
});

it('should parse templates with comments inside', done => {
parseTempatePartial('<div></div>', '<!-- nice comment -->')
.then(() => done())
.catch(done);
});
});