gonzales-pe
Advanced tools
Comparing version 3.0.0-16 to 3.0.0-26
var Node = require('../node'); | ||
var NodeType = require('./node-types'); | ||
var NodeType = require('../node-types'); | ||
var TokenType = require('../token-types'); | ||
@@ -2656,7 +2656,7 @@ | ||
column = token.col, | ||
content = []; | ||
content; | ||
pos++; | ||
content.push(getNmName2()); | ||
content = getNmName2(); | ||
return new Node(type, content, line, column); | ||
@@ -2663,0 +2663,0 @@ } |
@@ -32,3 +32,3 @@ module.exports = function stringify(tree) { | ||
}, | ||
'attrib': function(t) { | ||
'attribute': function(t) { | ||
return '[' + _composite(t.content) + ']'; | ||
@@ -45,4 +45,4 @@ }, | ||
}, | ||
'commentML': function(t) { | ||
return '/*' + t.content + '*/'; | ||
'color': function(t) { | ||
return '#' + t.content; | ||
}, | ||
@@ -55,6 +55,12 @@ 'filter': function(t) { | ||
}, | ||
'id': function (t) { | ||
return '#' + t.content; | ||
}, | ||
'important': function(t) { | ||
return '!' + _composite(t.content) + 'important'; | ||
}, | ||
'nthselector': function(t) { | ||
'multilineComment': function(t) { | ||
return '/*' + t.content + '*/'; | ||
}, | ||
'nthSelector': function(t) { | ||
return ':' + _t(t.content[0]) + '(' + _composite(t.content.slice(1)) + ')'; | ||
@@ -65,16 +71,10 @@ }, | ||
}, | ||
'pseudoc': function(t) { | ||
'pseudoClass': function(t) { | ||
return ':' + _composite(t.content); | ||
}, | ||
'pseudoe': function(t) { | ||
'pseudoElement': function(t) { | ||
return '::' + _composite(t.content); | ||
}, | ||
'shash': function (t) { | ||
return '#' + t.content; | ||
}, | ||
'uri': function(t) { | ||
return 'url(' + _composite(t.content) + ')'; | ||
}, | ||
'vhash': function(t) { | ||
return '#' + t.content; | ||
} | ||
@@ -81,0 +81,0 @@ }; |
@@ -32,3 +32,3 @@ module.exports = function stringify(tree) { | ||
}, | ||
'attrib': function(t) { | ||
'attribute': function(t) { | ||
return '[' + _composite(t.content) + ']'; | ||
@@ -45,8 +45,5 @@ }, | ||
}, | ||
'commentML': function (t) { | ||
return '/*' + t.content + '*/'; | ||
'color': function(t) { | ||
return '#' + t.content; | ||
}, | ||
'commentSL': function (t) { | ||
return '/' + '/' + t.content; | ||
}, | ||
'escapedString': function(t) { | ||
@@ -61,2 +58,5 @@ return '~' + t.content; | ||
}, | ||
'id': function (t) { | ||
return '#' + t.content; | ||
}, | ||
'important': function(t) { | ||
@@ -68,3 +68,6 @@ return '!' + _composite(t.content) + 'important'; | ||
}, | ||
'nthselector': function(t) { | ||
'multilineComment': function (t) { | ||
return '/*' + t.content + '*/'; | ||
}, | ||
'nthSelector': function(t) { | ||
return ':' + _t(t.content[0]) + '(' + _composite(t.content.slice(1)) + ')'; | ||
@@ -75,10 +78,10 @@ }, | ||
}, | ||
'pseudoc': function(t) { | ||
'pseudoClass': function(t) { | ||
return ':' + _composite(t.content); | ||
}, | ||
'pseudoe': function(t) { | ||
'pseudoElement': function(t) { | ||
return '::' + _composite(t.content); | ||
}, | ||
'shash': function (t) { | ||
return '#' + t.content; | ||
'singlelineComment': function (t) { | ||
return '/' + '/' + t.content; | ||
}, | ||
@@ -91,7 +94,4 @@ 'uri': function(t) { | ||
}, | ||
'variableslist': function(t) { | ||
'variablesList': function(t) { | ||
return _composite(t.content) + '...'; | ||
}, | ||
'vhash': function(t) { | ||
return '#' + t.content; | ||
} | ||
@@ -98,0 +98,0 @@ }; |
@@ -25,13 +25,24 @@ /** | ||
/** | ||
* @param {Function} callback | ||
* @param {String} type Node type | ||
* @return {Boolean} Whether there is a child node of given type | ||
*/ | ||
map: function(callback) { | ||
callback(this); | ||
contains: function(type) { | ||
return this.content.some(function(node) { | ||
return node.type === type; | ||
}); | ||
}, | ||
if (!Array.isArray(this.content)) return; | ||
/** | ||
* @param {String} type | ||
* @return {Node} First child node | ||
*/ | ||
first: function(type) { | ||
if (!type || !Array.isArray(this.content)) return this.content[0]; | ||
this.content.forEach(function(node) { | ||
if (node instanceof Node) | ||
node.map(callback); | ||
}); | ||
var i = 0; | ||
var l = this.content.length; | ||
for (; i < l; i++) { | ||
if (this.content[i].type === type) return this.content[i]; | ||
} | ||
}, | ||
@@ -44,2 +55,6 @@ | ||
forEach: function(type, callback) { | ||
if (!Array.isArray(this.content)) return; | ||
if (typeof type !== 'string') callback = type, type = null; | ||
var i = 0; | ||
@@ -49,3 +64,4 @@ var l = this.content.length; | ||
for (; i < l; i++) { | ||
if (this.content[i].type === type) callback(this.content[i]); | ||
if (!type || this.content[i] && this.content[i].type === type) | ||
callback(this.content[i], i); | ||
} | ||
@@ -55,10 +71,37 @@ }, | ||
/** | ||
* @param {String} type Node type | ||
* @return {Node} First found child node of given type | ||
* @param {Number} index | ||
* @return {Node} | ||
*/ | ||
find: function(type) { | ||
var i = 0; | ||
var l = this.content.length; | ||
get: function(index) { | ||
return Array.isArray(this.content) && this.content[index]; | ||
}, | ||
for (; i < l; i++) { | ||
/** | ||
* @param {Number} index | ||
* @param {Node} node | ||
*/ | ||
insert: function(index, node) { | ||
Array.isArray(this.content) && this.content.splice(index, 0, node); | ||
}, | ||
/** | ||
* @param {String} type | ||
* @return {Boolean} Whether the node is of given type | ||
*/ | ||
is: function(type) { | ||
return this.type === type; | ||
}, | ||
/** | ||
* @param {String} type | ||
* @return {Node} Last child node | ||
*/ | ||
last: function(type) { | ||
var i = this.content.length - 1; | ||
if (!type || !Array.isArray(this.content)) | ||
return this.content[i]; | ||
for (;;i--) { | ||
if (this.content[i].type === type) return this.content[i]; | ||
@@ -69,11 +112,26 @@ } | ||
/** | ||
* @param {String} type Node type | ||
* @return {Boolean} Whether there is a child node of given type | ||
* @param {Function} callback | ||
*/ | ||
contains: function(type) { | ||
return this.content.some(function(node) { | ||
return node.type === type; | ||
map: function(callback) { | ||
callback(this); | ||
if (!Array.isArray(this.content)) return; | ||
this.content.forEach(function(node) { | ||
if (node instanceof Node) | ||
node.map(callback); | ||
}); | ||
}, | ||
/** | ||
* @param {Number} index | ||
*/ | ||
remove: function(index) { | ||
Array.isArray(this.content) && this.content.splice(index, 1); | ||
}, | ||
get length() { | ||
return this.content.length; | ||
}, | ||
toString: function() { | ||
@@ -80,0 +138,0 @@ return JSON.stringify(this, false, 2); |
@@ -32,3 +32,3 @@ module.exports = function stringify(tree) { | ||
}, | ||
'attrib': function(t) { | ||
'attribute': function(t) { | ||
return '[' + _composite(t.content) + ']'; | ||
@@ -45,8 +45,5 @@ }, | ||
}, | ||
'commentML': function (t) { | ||
return '/*' + t.content; | ||
'color': function(t) { | ||
return '#' + t.content; | ||
}, | ||
'commentSL': function (t) { | ||
return '/' + '/' + t.content; | ||
}, | ||
'default': function(t) { | ||
@@ -61,2 +58,5 @@ return '!' + _composite(t.content) + 'default'; | ||
}, | ||
'id': function (t) { | ||
return '#' + t.content; | ||
}, | ||
'important': function(t) { | ||
@@ -68,3 +68,6 @@ return '!' + _composite(t.content) + 'important'; | ||
}, | ||
'nthselector': function(t) { | ||
'multilineComment': function (t) { | ||
return '/*' + t.content; | ||
}, | ||
'nthSelector': function(t) { | ||
return ':' + _t(t.content[0]) + '(' + _composite(t.content.slice(1)) + ')'; | ||
@@ -78,10 +81,10 @@ }, | ||
}, | ||
'pseudoc': function(t) { | ||
'pseudoClass': function(t) { | ||
return ':' + _composite(t.content); | ||
}, | ||
'pseudoe': function(t) { | ||
'pseudoElement': function(t) { | ||
return '::' + _composite(t.content); | ||
}, | ||
'shash': function (t) { | ||
return '#' + t.content; | ||
'singlelineComment': function (t) { | ||
return '/' + '/' + t.content; | ||
}, | ||
@@ -94,7 +97,4 @@ 'uri': function(t) { | ||
}, | ||
'variableslist': function(t) { | ||
'variablesList': function(t) { | ||
return _composite(t.content) + '...'; | ||
}, | ||
'vhash': function(t) { | ||
return '#' + t.content; | ||
} | ||
@@ -101,0 +101,0 @@ }; |
@@ -32,3 +32,3 @@ module.exports = function stringify(tree) { | ||
}, | ||
'attrib': function(t) { | ||
'attribute': function(t) { | ||
return '[' + _composite(t.content) + ']'; | ||
@@ -45,8 +45,5 @@ }, | ||
}, | ||
'commentML': function (t) { | ||
return '/*' + t.content + '*/'; | ||
'color': function(t) { | ||
return '#' + t.content; | ||
}, | ||
'commentSL': function (t) { | ||
return '/' + '/' + t.content; | ||
}, | ||
'default': function(t) { | ||
@@ -61,2 +58,5 @@ return '!' + _composite(t.content) + 'default'; | ||
}, | ||
'id': function (t) { | ||
return '#' + t.content; | ||
}, | ||
'important': function(t) { | ||
@@ -68,3 +68,6 @@ return '!' + _composite(t.content) + 'important'; | ||
}, | ||
'nthselector': function(t) { | ||
'multilineComment': function (t) { | ||
return '/*' + t.content + '*/'; | ||
}, | ||
'nthSelector': function(t) { | ||
return ':' + _t(t.content[0]) + '(' + _composite(t.content.slice(1)) + ')'; | ||
@@ -78,10 +81,10 @@ }, | ||
}, | ||
'pseudoc': function(t) { | ||
'pseudoClass': function(t) { | ||
return ':' + _composite(t.content); | ||
}, | ||
'pseudoe': function(t) { | ||
'pseudoElement': function(t) { | ||
return '::' + _composite(t.content); | ||
}, | ||
'shash': function (t) { | ||
return '#' + t.content; | ||
'singlelineComment': function (t) { | ||
return '/' + '/' + t.content; | ||
}, | ||
@@ -94,7 +97,4 @@ 'uri': function(t) { | ||
}, | ||
'variableslist': function(t) { | ||
'variablesList': function(t) { | ||
return _composite(t.content) + '...'; | ||
}, | ||
'vhash': function(t) { | ||
return '#' + t.content; | ||
} | ||
@@ -101,0 +101,0 @@ }; |
{ | ||
"name": "gonzales-pe", | ||
"description": "Gonzales Preprocessor Edition (fast CSS parser)", | ||
"version": "3.0.0-16", | ||
"version": "3.0.0-26", | ||
"homepage": "http://github.com/tonyganch/gonzales-pe", | ||
@@ -6,0 +6,0 @@ "bugs": "http://github.com/tonyganch/gonzales-pe/issues", |
@@ -54,2 +54,4 @@ ## API | ||
### ast.length | ||
### ast.toString() | ||
@@ -74,18 +76,44 @@ | ||
``` | ||
### ast.contains(type) | ||
### ast.map(function) | ||
Checks whether there is a child node of given type. | ||
Calls the function for every node in a tree. Modifies the tree! | ||
Parameters: | ||
* `{String} type` | ||
Returns: | ||
* `{Boolean}` | ||
Example: | ||
```js | ||
if (ast.contains('panda')) | ||
doSomething(); | ||
``` | ||
### ast.first(type) | ||
Returns the first child node of given type. | ||
Parameters: | ||
* `{Function} function` | ||
* `{String=} type` | ||
Returns: | ||
* `{Node} node` | ||
Example: | ||
```js | ||
ast.map(function(node) { | ||
if (node.type === 'commentML') node.content = 'panda'; | ||
}); | ||
var node = ast.first(); | ||
node.content = 'panda'; | ||
``` | ||
Example: | ||
```js | ||
var node = ast.first('commentML'); | ||
node.content = 'panda'; | ||
``` | ||
### ast.forEach(type, function) | ||
@@ -97,3 +125,3 @@ | ||
* `{String} type` | ||
* `{String=} type` | ||
* `{Function} function` | ||
@@ -108,6 +136,10 @@ | ||
### ast.find(type) | ||
### ast.get(index) | ||
Returns the first child node of given type. | ||
### ast.insert(index, node) | ||
### ast.is(type) | ||
Checks whether the node is of given type. | ||
Parameters: | ||
@@ -119,28 +151,50 @@ | ||
* `{Node} node` | ||
* `{Boolean}` | ||
Example: | ||
```js | ||
var node = ast.find('commentML'); | ||
node.content = 'panda'; | ||
if (ast.is('s')) | ||
ast.content = ''; | ||
``` | ||
### ast.contains(type) | ||
### ast.last(type) | ||
Checks whether there is a child node of given type. | ||
Returns the last child node of given type. | ||
Parameters: | ||
* `{String} type` | ||
* `{String=} type` | ||
Returns: | ||
* `{Boolean}` | ||
* `{Node} node` | ||
Example: | ||
```js | ||
if (ast.contains('panda')) | ||
doSomething(); | ||
var node = ast.last() | ||
node.content = 'panda'; | ||
``` | ||
Example: | ||
```js | ||
var node = ast.last('commentML'); | ||
node.content = 'panda'; | ||
``` | ||
### ast.map(function) | ||
Calls the function for every node in a tree. Modifies the tree! | ||
Parameters: | ||
* `{Function} function` | ||
Example: | ||
```js | ||
ast.map(function(node) { | ||
if (node.type === 'commentML') node.content = 'panda'; | ||
}); | ||
``` | ||
## Test | ||
@@ -147,0 +201,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
228
455841
33
12757