Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return undefined loc if declaration missing source #7079

Merged
merged 8 commits into from
Oct 24, 2021
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.index {
}
Original file line number Diff line number Diff line change
@@ -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)
},
}
]
}
10 changes: 10 additions & 0 deletions packages/core/integration-tests/test/postcss.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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