Skip to content
Merged
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
5 changes: 2 additions & 3 deletions lib/LessParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ module.exports = class LessParser extends Parser {
const node = new Comment();
const text = token[1].slice(2);

this.init(node, token[2], token[3]);

node.source.end = { line: token[4], column: token[5] };
this.init(node, token[2]);
node.source.end = this.getPosition(token[3] || token[2]);
node.inline = true;
node.raws.begin = '//';

Expand Down
2 changes: 1 addition & 1 deletion lib/nodes/inline-comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = {
token = this.tokenizer.nextToken({ ignoreUnclosed: true });
}

const newToken = ['comment', bits.join(''), first[2], first[3], last[2], last[3]];
const newToken = ['comment', bits.join(''), first[2], last[2]];
this.inlineComment(newToken);

// Replace tokenizer to retokenize the rest of the string
Expand Down
4 changes: 1 addition & 3 deletions lib/nodes/interpolation.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ module.exports = {
const words = tokens.map((tokn) => tokn[1]);
[first] = tokens;
const last = tokens.pop();
const start = [first[2], first[3]];
const end = [last[4] || last[2], last[5] || last[3]];
const newToken = ['word', words.join('')].concat(start, end);
const newToken = ['word', words.join(''), first[2], last[2]];

this.tokenizer.back(token);
this.tokenizer.back(newToken);
Expand Down
46 changes: 46 additions & 0 deletions test/map.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const { readFileSync } = require('fs');

const { join } = require('path');

const test = require('ava');
const postcss = require('postcss');

const syntax = require('../lib');

const { parser } = syntax;

// silence the rediculously verbose "You did not set any plugins, parser, or
// stringifier" warnings in PostCSS.
console.warn = () => {}; // eslint-disable-line no-console

test('should parse LESS integration syntax and generate a source map', async (t) => {
const less = readFileSync(join(__dirname, './integration/ext.cx.dashboard.less'), 'utf-8');
const result = await postcss().process(less, {
syntax,
parser,
map: { inline: false, annotation: false, sourcesContent: true }
});

t.truthy(result);
t.is(result.css, less);
t.is(result.content, less);
t.truthy(result.map);
});

test('should parse LESS inline comment syntax and generate a source map', async (t) => {
const less = `
a {
//background-color: red;
}
`;
const result = await postcss().process(less, {
syntax,
parser,
map: { inline: false, annotation: false, sourcesContent: true }
});

t.truthy(result);
t.is(result.css, less);
t.is(result.content, less);
t.truthy(result.map);
});