handle unknown at-rules that are declaration-like — fixes #871

pull/874/head
Rich Harris 7 years ago
parent 30f223b54c
commit 86a11b547b

@ -120,7 +120,7 @@ class Declaration {
} }
transform(code: MagicString, keyframes: Map<string, string>) { transform(code: MagicString, keyframes: Map<string, string>) {
const property = this.node.property.toLowerCase(); const property = this.node.property && this.node.property.toLowerCase();
if (property === 'animation' || property === 'animation-name') { if (property === 'animation' || property === 'animation-name') {
this.node.value.children.forEach((block: Node) => { this.node.value.children.forEach((block: Node) => {
if (block.type === 'Identifier') { if (block.type === 'Identifier') {
@ -134,6 +134,8 @@ class Declaration {
} }
minify(code: MagicString) { minify(code: MagicString) {
if (!this.node.property) return; // @apply, and possibly other weird cases?
const c = this.node.start + this.node.property.length; const c = this.node.start + this.node.property.length;
const first = this.node.value.children ? const first = this.node.value.children ?
this.node.value.children[0] : this.node.value.children[0] :
@ -274,15 +276,21 @@ export default class Stylesheet {
if (parsed.css && parsed.css.children.length) { if (parsed.css && parsed.css.children.length) {
this.hasStyles = true; this.hasStyles = true;
const stack: Atrule[] = []; const stack: (Rule | Atrule)[] = [];
let currentAtrule: Atrule = null; let currentAtrule: Atrule = null;
walk(this.parsed.css, { walk(this.parsed.css, {
enter: (node: Node) => { enter: (node: Node) => {
if (node.type === 'Atrule') { if (node.type === 'Atrule') {
const last = stack[stack.length - 1];
const atrule = new Atrule(node); const atrule = new Atrule(node);
stack.push(atrule); stack.push(atrule);
// this is an awkward special case — @apply (and
// possibly other future constructs)
if (last && !(last instanceof Atrule)) return;
if (currentAtrule) { if (currentAtrule) {
currentAtrule.children.push(atrule); currentAtrule.children.push(atrule);
} else { } else {
@ -302,6 +310,7 @@ export default class Stylesheet {
if (node.type === 'Rule') { if (node.type === 'Rule') {
const rule = new Rule(node, currentAtrule); const rule = new Rule(node, currentAtrule);
stack.push(rule);
if (currentAtrule) { if (currentAtrule) {
currentAtrule.children.push(rule); currentAtrule.children.push(rule);
@ -312,10 +321,8 @@ export default class Stylesheet {
}, },
leave: (node: Node) => { leave: (node: Node) => {
if (node.type === 'Atrule') { if (node.type === 'Rule' || node.type === 'Atrule') stack.pop();
stack.pop(); if (node.type === 'Atrule') currentAtrule = stack[stack.length - 1];
currentAtrule = stack[stack.length - 1];
}
} }
}); });
} else { } else {

@ -0,0 +1 @@
div[svelte-xyz],[svelte-xyz] div{@apply --funky-div;}

@ -0,0 +1,7 @@
<div></div>
<style>
div {
@apply --funky-div;
}
</style>
Loading…
Cancel
Save