AleshaOleg/postcss-sass

Missing source reference for comments

aldhsu opened this issue ยท 3 comments

Expected

Comments always have source

From postcss-scss parser

Comment {
        raws: { before: '\n', inline: true, left: ' ', right: ' ', text: 'a' },
        type: 'comment',
        parent:
         Root {
           raws: { semicolon: false, after: '' },
           type: 'root',
           nodes: [ [Circular], [Object] ],
           source: { input: [Object], start: [Object] } },
        source:
         { start: { line: 2, column: 1 },
           input: Input { css: '\n// a \n/* b */', id: '<input css 4>' },
           end: { line: 2, column: 5 } },
        text: 'a' }

Actual

Comments do not have source

From snapshot:

{
\\"raws\\": {
\\"before\\": \\"\\\\n \\",
\\"left\\": \\" \\",
\\"right\\": \\"\\",
\\"inline\\": true
},
\\"type\\": \\"comment\\",
\\"text\\": \\"Comment1\\"
},

Potential Problem

http://api.postcss.org/global.html#source

If you create a node manually (e.g., with postcss.decl()), that node will not have a source property and will be absent from the source map.

postcss-sass/parser.es6

Lines 343 to 351 in 0e6edad

let comment = Object.assign(postcss.comment(), {
text: text[2],
raws: {
before: this.raws.before || DEFAULT_COMMENT_DECL.before,
left: text[1],
right: text[3],
inline
}
})

This is addressed in the other ndoe types but not in comments.

Hey @aldhsu. Thanks for reporting, I'll try to fix this today.

@aldhsu, @Grawl fixed in postcss-sass@0.3.5