Skip to content

Commit

Permalink
Return undefined loc if declaration missing source (#7079)
Browse files Browse the repository at this point in the history
Co-authored-by: Jasper De Moor <jasperdemoor@gmail.com>
Co-authored-by: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com>
  • Loading branch information
3 people committed Oct 24, 2021
1 parent daed0c3 commit 530e06a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
@@ -0,0 +1,2 @@
.index {
}
@@ -0,0 +1,11 @@
module.exports = {
"plugins": [
{
postcssPlugin: 'PLUGIN NAME',
Rule: (rule, { Declaration }) => {
const decl = new Declaration({ prop: 'background-image', value: 'url("data:image/gif;base64,quotes")' })
rule.append(decl)
},
}
]
}
Empty file.
10 changes: 10 additions & 0 deletions packages/core/integration-tests/test/postcss.js
Expand Up @@ -251,6 +251,16 @@ describe('postcss', () => {
assert.equal(run1(), run2());
});

it('should support transforming declarations with missing source', async () => {
await bundle(
path.join(__dirname, '/integration/postcss-plugins-decl/index.css'),
);

let css = await outputFS.readFile(path.join(distDir, 'index.css'), 'utf8');

assert(css.includes('url("data:image/gif;base64,quotes")'));
});

it('should support postcss composes imports', async () => {
let b = await bundle(
path.join(__dirname, '/integration/postcss-composes/index.js'),
Expand Down
15 changes: 9 additions & 6 deletions packages/transformers/css/src/CSSTransformer.js
Expand Up @@ -143,12 +143,15 @@ export default (new Transformer({
!node.nodes[0].value.startsWith('#') // IE's `behavior: url(#default#VML)`
) {
let url = asset.addURLDependency(node.nodes[0].value, {
loc: createLoc(
nullthrows(decl.source.start),
node.nodes[0].value,
0,
node.nodes[0].sourceIndex,
),
loc:
decl.source &&
decl.source.start &&
createLoc(
decl.source.start,
node.nodes[0].value,
0,
node.nodes[0].sourceIndex,
),
});
isDeclDirty = node.nodes[0].value !== url;
node.nodes[0].value = url;
Expand Down

0 comments on commit 530e06a

Please sign in to comment.