diff --git a/lib/scss-parser.es6 b/lib/scss-parser.es6 index 8a330df..fd7011f 100644 --- a/lib/scss-parser.es6 +++ b/lib/scss-parser.es6 @@ -150,4 +150,22 @@ export default class ScssParser extends Parser { } } + raw(node, prop, tokens) { + super.raw(node, prop, tokens); + if ( node.raws[prop] ) { + let scss = node.raws[prop].raw; + node.raws[prop].raw = tokens.reduce( (all, i) => { + if ( i[0] === 'comment' && i[6] === 'inline' ) { + let text = i[1].slice(2).replace(/(\*\/|\/\*)/g, '*//*'); + return all + '/*' + text + '*/'; + } else { + return all + i[1]; + } + }, ''); + if ( scss !== node.raws[prop].raw ) { + node.raws[prop].scss = scss; + } + } + } + } diff --git a/lib/scss-stringifier.es6 b/lib/scss-stringifier.es6 index dbe7f5b..36d2316 100644 --- a/lib/scss-stringifier.es6 +++ b/lib/scss-stringifier.es6 @@ -39,4 +39,14 @@ export default class ScssStringifier extends Stringifier { } } + rawValue(node, prop) { + let value = node[prop]; + let raw = node.raws[prop]; + if ( raw && raw.value === value ) { + return raw.scss ? raw.scss : raw.raw; + } else { + return value; + } + } + } diff --git a/test/parse.test.js b/test/parse.test.js index 072e088..736a6fd 100644 --- a/test/parse.test.js +++ b/test/parse.test.js @@ -57,6 +57,12 @@ it('parses empty inline comments', () => { }); }); +it('parses inline comments inside selector', () => { + let root = parse('a\n// c/**/\nb { }'); + expect(root.first.raws.selector.scss).toEqual('a\n// c/**/\nb'); + expect(root.first.raws.selector.raw).toEqual('a\n/* c*//**//**/\nb'); +}); + it('does not parse comments inside brakets', () => { let root = parse('a { cursor: url(http://ya.ru) }'); expect(root.first.first.value).toEqual('url(http://ya.ru)'); diff --git a/test/stringify.test.js b/test/stringify.test.js index 09b5091..50c0cb8 100644 --- a/test/stringify.test.js +++ b/test/stringify.test.js @@ -34,6 +34,15 @@ it('stringifies inline comment with comments inside', () => { expect(result).toEqual('// a/*b*/c\na {}'); }); +it('stringifies inline comment inside selectors', () => { + let root = parse('a\n// comment\nb {}'); + let result = ''; + stringify(root, i => { + result += i; + }); + expect(result).toEqual('a\n// comment\nb {}'); +}); + it('stringifies inline comment in the end of file', () => { let root = parse('// comment'); let result = '';