diff --git a/compiler/parse/state/tag.js b/compiler/parse/state/tag.js index aeb58004a7..cb2178e30d 100644 --- a/compiler/parse/state/tag.js +++ b/compiler/parse/state/tag.js @@ -22,6 +22,20 @@ const specials = { export default function tag ( parser ) { const start = parser.index++; + if ( parser.eat( '!--' ) ) { + const data = parser.readUntil( /-->/ ); + parser.eat( '-->' ); + + parser.current().children.push({ + start, + end: parser.index, + type: 'Comment', + data + }); + + return null; + } + const isClosingTag = parser.eat( '/' ); // TODO handle cases like <li>one<li>two diff --git a/test/parser/comment/input.svelte b/test/parser/comment/input.svelte new file mode 100644 index 0000000000..b35c49dac8 --- /dev/null +++ b/test/parser/comment/input.svelte @@ -0,0 +1 @@ +<!-- a comment --> diff --git a/test/parser/comment/output.json b/test/parser/comment/output.json new file mode 100644 index 0000000000..635c0fc2e0 --- /dev/null +++ b/test/parser/comment/output.json @@ -0,0 +1,17 @@ +{ + "html": { + "start": 0, + "end": 18, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 18, + "type": "Comment", + "data": " a comment " + } + ] + }, + "css": null, + "js": null +}