Skip to content

Commit

Permalink
Integrate Input#document (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
romainmenke authored Jan 16, 2025
1 parent 7d8fdc1 commit aa1405d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
40 changes: 40 additions & 0 deletions lib/__tests__/parse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ describe('no interpolations', () => {
line: 1,
column: 38,
});
expect(decl.rangeBy({})).toEqual({
start: {
column: 28,
line: 1,
},
end: {
column: 39,
line: 1,
},
});
expect(decl.rangeBy({ word: 'red' })).toEqual({
start: {
column: 35,
line: 1,
},
end: {
column: 38,
line: 1,
},
});
});

test('two components', () => {
Expand Down Expand Up @@ -111,6 +131,26 @@ describe('no interpolations', () => {
line: 2,
column: 45,
});
expect(secondComponent.rangeBy({})).toEqual({
start: {
column: 28,
line: 2,
},
end: {
column: 47,
line: 2,
},
});
expect(secondComponent.rangeBy({ word: 'blue' })).toEqual({
start: {
column: 42,
line: 2,
},
end: {
column: 46,
line: 2,
},
});
});

test('empty component', () => {
Expand Down
8 changes: 6 additions & 2 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ const { parseJs } = require('./parseJs');
module.exports = function parse(css, opts) {
let inputCode = typeof css === 'string' ? css : css.toString();

let options = opts ?? {};

options.document = inputCode;

let document = new postcss.Document({
source: {
input: new postcss.Input(inputCode, opts),
input: new postcss.Input(inputCode, options),
start: { offset: 0, line: 1, column: 1 },
},
});
Expand All @@ -27,7 +31,7 @@ module.exports = function parse(css, opts) {
/** @type {postcss.Root} */
let parsedNode;

let input = new postcss.Input(node.css, opts);
let input = new postcss.Input(node.css, options);

let interpolationsRanges = node.interpolationRanges.map((range) => {
return {
Expand Down

0 comments on commit aa1405d

Please sign in to comment.