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

Adds @layer support #169

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
.DS_Store
39 changes: 38 additions & 1 deletion lib/parse/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,42 @@ module.exports = function(css, options){
});
}


/**
* Parse layer.
*/

function atlayer() {
const pos = position()
const m = match(/^@layer *([^{;@]+)/)

if (!m) {
return
}
const layer = trim(m[1])

if (!open()) {
match(/^[;\s]*/)
return pos({
type: 'layer',
layer: layer
})
}

const style = comments().concat(rules())

if (!close()) {
return error("@layer missing '}'")
}

return pos({
type: 'layer',
layer: layer,
rules: style
})
}


/**
* Parse import
*/
Expand Down Expand Up @@ -541,7 +577,8 @@ module.exports = function(css, options){
|| atdocument()
|| atpage()
|| athost()
|| atfontface();
|| atfontface()
|| atlayer();
}

/**
Expand Down
14 changes: 14 additions & 0 deletions lib/stringify/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,17 @@ Compiler.prototype.declaration = function(node){
return this.emit(node.property + ':' + node.value, node.position) + this.emit(';');
};

/**
* Visit layer node.
*/

Compiler.prototype.layer = function(node) {
return (
this.emit('@layer ' + node.layer, node.position) +
(node.rules
? this.emit('{') +
this.mapVisit(node.rules) +
this.emit('}')
: ';')
);
};
15 changes: 15 additions & 0 deletions lib/stringify/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,21 @@ Compiler.prototype.declaration = function(node){
+ this.emit(';');
};

/**
* Visit layer node.
*/

Compiler.prototype.layer = function(node) {
return (
this.emit(this.indent() + '@layer ' + node.layer, node.position) +
(node.rules
? this.emit(' {\n' + this.indent(1)) +
this.mapVisit(node.rules, '\n\n') +
this.emit('\n' + this.indent(-1) + this.indent() + '}')
: ';')
);
};

/**
* Increase, decrease or return current indentation.
*/
Expand Down
Loading