Skip to content

Instantly share code, notes, and snippets.

@thysultan
Last active October 6, 2017 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thysultan/2189897d4f3e0461b1ed98fabdd05e2f to your computer and use it in GitHub Desktop.
Save thysultan/2189897d4f3e0461b1ed98fabdd05e2f to your computer and use it in GitHub Desktop.
function Stack () {
this.next = this
this.prev = this
this.length = 0
}
Stack.prototype = {
/**
* @param {Object} node
* @param {Object} before
* @return {Object}
*/
push: function push (node) {
node.next = this
node.prev = this.prev
this.prev.next = node
this.prev = node
this.length++
return node
},
/**
* @param {Object} node
* @return {Object}
*/
pop: function pop () {
if (this.length === 0)
return
this.next.prev = this.prev
this.prev.next = this.next
this.length--
return this.prev
},
/**
* @param {function} callback
*/
forEach: function forEach (callback) {
for (var i = 0, node = this; i < this.length; ++i)
callback(node = node.next, i)
}
}
var children = new Stack
var stack = new Stack
function Node (rule, body) {
this.rule = rule
this.body = body
this.children = null
this.next = null
this.prev = null
}
function plugin (context, content, selectors, parents, line, column, length, id) {
var selector = selectors.join(',')
switch (context) {
case 1:
if (content.charCodeAt(0) !== 64)
return
case 2:
case 3:
switch (id) {
// @font
// @keyframe
case 102:
case 107:
// @media
case 109:
// @at-rule body
if (selector.charCodeAt(0) !== 64)
return
}
var node = new Node(selector, content)
if (parents.join(',').length === 0) {
stack.push(node).children = children
children = new Stack
} else {
children.push(node)
}
break
case -2:
return stack
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment