From b60edba65649a3075c4b852349df7ae9a115080f Mon Sep 17 00:00:00 2001 From: Jonathan Wilsson Date: Sat, 22 Sep 2018 16:58:50 +0200 Subject: [PATCH] fix: crash on inline comments. Closes #114 (#115) * Fix crash on inline comments. Closes #114 * chore: use slice for consistency --- lib/nodes/inline-comment.js | 2 +- test/parser/comments.test.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/nodes/inline-comment.js b/lib/nodes/inline-comment.js index a1ec561..f0b92b6 100644 --- a/lib/nodes/inline-comment.js +++ b/lib/nodes/inline-comment.js @@ -1,6 +1,6 @@ module.exports = { isInlineComment(token) { - if (token[0] === 'word' && token[1] === '//') { + if (token[0] === 'word' && token[1].slice(0, 2) === '//') { const first = token; const bits = []; let last; diff --git a/test/parser/comments.test.js b/test/parser/comments.test.js index 2a3a177..773580d 100644 --- a/test/parser/comments.test.js +++ b/test/parser/comments.test.js @@ -15,6 +15,18 @@ test('inline comment', (t) => { t.is(nodeToString(root), less); }); +test('inline comment without leading space', (t) => { + const less = '//batman'; + const root = parse(less); + const { first } = root; + + t.truthy(root); + t.true(first instanceof Comment); + t.true(first.inline); + t.is(first.text, 'batman'); + t.is(nodeToString(root), less); +}); + test('close empty', (t) => { const less = '// \n//'; const root = parse(less);