Skip to content
This repository was archived by the owner on Feb 9, 2024. It is now read-only.
Open
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
7 changes: 5 additions & 2 deletions src/streamReaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ const REGEXES = {
* @returns {CommentToken}
*/
export function comment(stream) {
const index = stream.indexOf('-->');
const endNeedle = '-->';
const index = stream.indexOf(endNeedle);
const startIndex = String('<!--').length;
const endIndex = index + endNeedle.length;
if (index >= 0) {
return new CommentToken(stream.substr(4, index - 1), index + 3);
return new CommentToken(stream.substring(startIndex, endIndex), endIndex);
}
}

Expand Down
7 changes: 7 additions & 0 deletions test/unit/streamReaders.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ describe('streamReaders', () => {
expect(tok).not.to.be.ok();
});
});

describe('comments on ScriptTag #atomicTag', () => {
it('keep comments on a ScriptTag', () => {
const tok = streamReaders.atomicTag('<script>/* lala */</script>');
expect(tok).to.have.property('content', '/* lala */');
});
});

describe('#startTag', () => {
it('reads a start tag', () => {
Expand Down