Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gonzales-pe

Package Overview
Dependencies
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gonzales-pe - npm Package Compare versions

Comparing version 3.0.0-10 to 3.0.0-11

34

lib/css/stringify.js

@@ -5,2 +5,4 @@ module.exports = function stringify(tree) {

var hasInfo = typeof tree[0] === 'object';
var _m_simple = {

@@ -22,3 +24,3 @@ 'attrselector': 1, 'combinator': 1, 'nth': 1, 'number': 1,

function _t(tree) {
var t = tree[0];
var t = tree[hasInfo ? 1 : 0];
if (t in _m_primitive) return _m_primitive[t];

@@ -32,3 +34,3 @@ else if (t in _m_simple) return _simple(tree);

var s = '';
i = i === undefined ? 1 : i;
i = i === undefined ? (hasInfo ? 2 : 1) : i;
for (; i < t.length; i++) s += typeof t[i] === 'string' ? t[i] : _t(t[i]);

@@ -39,3 +41,3 @@ return s;

function _simple(t) {
return t[1];
return t[hasInfo ? 2 : 1];
}

@@ -48,6 +50,6 @@

'atkeyword': function(t) {
return '@' + _t(t[1]);
return '@' + _t(t[hasInfo ? 2 : 1]);
},
'atruler': function(t) {
return _t(t[1]) + _t(t[2]) + '{' + _t(t[3]) + '}';
return _t(t[hasInfo ? 2 : 1]) + _t(t[hasInfo ? 3 : 2]) + '{' + _t(t[hasInfo ? 4 : 3]) + '}';
},

@@ -61,15 +63,15 @@ 'attrib': function(t) {

'braces': function(t) {
return t[1] + _composite(t, 3) + t[2];
return t[hasInfo ? 2 : 1] + _composite(t, hasInfo ? 4 : 3) + t[hasInfo ? 3 : 2];
},
'class': function(t) {
return '.' + _t(t[1]);
return '.' + _t(t[hasInfo ? 2 : 1]);
},
'commentML': function (t) {
return '/*' + t[1] + '*/';
return '/*' + t[hasInfo ? 2 : 1] + '*/';
},
'filter': function(t) {
return _t(t[1]) + ':' + _t(t[2]);
return _t(t[hasInfo ? 2 : 1]) + ':' + _t(t[hasInfo ? 3 : 2]);
},
'functionExpression': function(t) {
return 'expression(' + t[1] + ')';
return 'expression(' + t[hasInfo ? 2 : 1] + ')';
},

@@ -80,15 +82,15 @@ 'important': function(t) {

'nthselector': function(t) {
return ':' + _simple(t[1]) + '(' + _composite(t, 2) + ')';
return ':' + _simple(t[hasInfo ? 2 : 1]) + '(' + _composite(t, hasInfo ? 3 : 2) + ')';
},
'percentage': function(t) {
return _t(t[1]) + '%';
return _t(t[hasInfo ? 2 : 1]) + '%';
},
'pseudoc': function(t) {
return ':' + _t(t[1]);
return ':' + _t(t[hasInfo ? 2 : 1]);
},
'pseudoe': function(t) {
return '::' + _t(t[1]);
return '::' + _t(t[hasInfo ? 2 : 1]);
},
'shash': function (t) {
return '#' + t[1];
return '#' + t[hasInfo ? 2 : 1];
},

@@ -99,3 +101,3 @@ 'uri': function(t) {

'vhash': function(t) {
return '#' + t[1];
return '#' + t[hasInfo ? 2 : 1];
}

@@ -102,0 +104,0 @@ };

@@ -11,3 +11,4 @@ module.exports = function(css) {

tn = 0,
ln = 1;
ln = 1,
col = 1;

@@ -52,2 +53,18 @@ var Punctuation = {

/**
* Shift position right
* @param {number} [number]
*/
function shiftRight(number) {
number = number || 1;
col += number;
pos += number;
}
/**
* Shift position left
*/
function shiftLeft() {
col--;
pos--;
}
/**
* Add a token to the token list

@@ -57,4 +74,4 @@ * @param {string} type

*/
function pushToken(type, value) {
tokens.push({ tn: tn++, ln: ln, type: type, value: value });
function pushToken(type, value, column) {
tokens.push({ tn: tn++, ln: ln, col: column, type: type, value: value });
}

@@ -76,6 +93,7 @@

function parseSpaces(css) {
var start = pos;
var start = pos,
startCol = col;
// Read the string until we meet a non-space character:
for (; pos < css.length; pos++) {
for (; pos < css.length; shiftRight()) {
if (css.charAt(pos) !== ' ') break;

@@ -85,4 +103,4 @@ }

// Add a substring containing only spaces to tokens:
pushToken(TokenType.Space, css.substring(start, pos));
pos--;
pushToken(TokenType.Space, css.substring(start, pos), startCol);
shiftLeft();
}

@@ -96,8 +114,9 @@

function parseString(css, q) {
var start = pos;
var start = pos,
startCol = col;
// Read the string until we meet a matching quote:
for (pos = pos + 1; pos < css.length; pos++) {
for (shiftRight(); pos < css.length; shiftRight()) {
// Skip escaped quotes:
if (css.charAt(pos) === '\\') pos++;
if (css.charAt(pos) === '\\') shiftRight();
else if (css.charAt(pos) === q) break;

@@ -107,3 +126,3 @@ }

// Add the string (including quotes) to tokens:
pushToken(q === '"' ? TokenType.StringDQ : TokenType.StringSQ, css.substring(start, pos + 1));
pushToken(q === '"' ? TokenType.StringDQ : TokenType.StringSQ, css.substring(start, pos + 1), startCol);
}

@@ -116,6 +135,7 @@

function parseDecimalNumber(css) {
var start = pos;
var start = pos,
startCol = col;
// Read the string until we meet a character that's not a digit:
for (; pos < css.length; pos++) {
for (; pos < css.length; shiftRight()) {
if (!isDecimalDigit(css.charAt(pos))) break;

@@ -125,4 +145,4 @@ }

// Add the number to tokens:
pushToken(TokenType.DecimalNumber, css.substring(start, pos));
pos--;
pushToken(TokenType.DecimalNumber, css.substring(start, pos), startCol);
shiftLeft();
}

@@ -135,11 +155,12 @@

function parseIdentifier(css) {
var start = pos;
var start = pos,
startCol = col;
// Skip all opening slashes:
while (css.charAt(pos) === '/') pos++;
while (css.charAt(pos) === '/') shiftRight();
// Read the string until we meet a punctuation mark:
for (; pos < css.length; pos++) {
for (; pos < css.length; shiftRight()) {
// Skip all '\':
if (css.charAt(pos) === '\\') pos++;
if (css.charAt(pos) === '\\') shiftRight();
else if (css.charAt(pos) in Punctuation) break;

@@ -154,4 +175,4 @@ }

// Add identifier to tokens:
pushToken(TokenType.Identifier, ident);
pos--;
pushToken(TokenType.Identifier, ident, startCol);
shiftLeft();
}

@@ -164,3 +185,4 @@

function parseMLComment(css) {
var start = pos;
var start = pos,
startCol = col;

@@ -170,5 +192,5 @@ // Read the string until we meet `*/`.

// from `pos + 2`:
for (pos = pos + 2; pos < css.length; pos++) {
for (pos = pos + 2; pos < css.length; shiftRight()) {
if (css.charAt(pos) === '*' && css.charAt(pos + 1) === '/') {
pos++;
shiftRight();
break;

@@ -179,7 +201,8 @@ }

// Add full comment (including `/*` and `*/`) to the list of tokens:
pushToken(TokenType.CommentML, css.substring(start, pos + 1));
pushToken(TokenType.CommentML, css.substring(start, pos + 1), startCol);
}
function parseSLComment(css) {
var start = pos;
var start = pos,
startCol = col;

@@ -189,3 +212,3 @@ // Read the string until we meet line break.

// from `pos + 2`:
for (pos = pos + 2; pos < css.length; pos++) {
for (shiftRight(2); pos < css.length; shiftRight()) {
if (css.charAt(pos) === '\n' || css.charAt(pos) === '\r') {

@@ -197,4 +220,4 @@ break;

// Add comment (including `//` and line break) to the list of tokens:
pushToken(TokenType.CommentSL, css.substring(start, pos));
pos--;
pushToken(TokenType.CommentSL, css.substring(start, pos), startCol);
shiftLeft();
}

@@ -210,3 +233,3 @@

// Parse string, character by character:
for (pos = 0; pos < css.length; pos++) {
for (pos = 0; pos < css.length; shiftRight()) {
c = css.charAt(pos);

@@ -238,3 +261,3 @@ cn = css.charAt(pos + 1);

else if (c === ' ') {
parseSpaces(css)
parseSpaces(css);
}

@@ -245,4 +268,7 @@

// Add it to the list of tokens:
pushToken(Punctuation[c], c);
if (c === '\n' || c === '\r') ln++; // Go to next line
pushToken(Punctuation[c], c, col);
if (c === '\n' || c === '\r') {
ln++;
col = 0;
} // Go to next line
if (c === ')') urlMode = false; // exit url mode

@@ -249,0 +275,0 @@ if (c === '{') blockMode++; // enter a block

@@ -5,3 +5,3 @@ var TokenType = require('../token-types');

module.exports = (function() {
var tokens, tokensLength, pos;
var tokens, tokensLength, pos, needInfo;

@@ -74,3 +74,21 @@ var rules = {

/**
* Get info object
* @param {Number} i Token's index number
* @returns {{ln: {Number}, col: {Number}}}
*/
function getInfo(i) {
return { ln: tokens[i].ln, col: tokens[i].col };
}
/**
* Get node
* @param {Number} i Token's index number
* @param {Array} value
* @returns {Array}
*/
function getNode(i, value) {
return needInfo ? [].concat(getInfo(i), value) : value;
}
/////////////////////////////////////

@@ -103,3 +121,3 @@ /////////////////////////////////////

return x;
return getNode(startPos, x);
}

@@ -152,3 +170,3 @@

// TODO: `getIdent`:
x.push(['ident', tokens[pos].value]);
x.push(getNode(pos, ['ident', tokens[pos].value]));
pos++;

@@ -164,3 +182,3 @@

return x;
return getNode(startPos, x);
}

@@ -189,3 +207,3 @@

return x;
return getNode(startPos, x);
}

@@ -222,3 +240,3 @@

return x;
return getNode(startPos, x);
}

@@ -248,3 +266,3 @@

return x;
return getNode(startPos, x);
}

@@ -279,7 +297,8 @@

return x;
return getNode(startPos, x);
}
return function(_tokens, rule) {
return function(_tokens, rule, _needInfo) {
tokens = _tokens;
needInfo = _needInfo;
tokensLength = tokens.length;

@@ -286,0 +305,0 @@ pos = 0;

@@ -5,2 +5,4 @@ module.exports = function stringify(tree) {

var hasInfo = typeof tree[0] === 'object';
var _m_simple = {

@@ -12,3 +14,3 @@ 'ident': 1,

_m_composite = {
'program': 1,
'program': 1
},

@@ -19,3 +21,3 @@ _m_primitive = {

function _t(tree) {
var t = tree[0];
var t = tree[hasInfo ? 1 : 0];
if (t in _m_primitive) return _m_primitive[t];

@@ -29,3 +31,3 @@ else if (t in _m_simple) return _simple(tree);

var s = '';
i = i === undefined ? 1 : i;
i = i === undefined ? (hasInfo ? 2 : 1) : i;
for (; i < t.length; i++) s += typeof t[i] === 'string' ? t[i] : _t(t[i]);

@@ -36,3 +38,3 @@ return s;

function _simple(t) {
return t[1];
return t[hasInfo ? 2 : 1];
}

@@ -42,3 +44,3 @@

'functionBody': function(t) {
return '{' + t[1] + '}';
return '{' + t[hasInfo ? 2 : 1] + '}';
},

@@ -49,3 +51,3 @@ 'functionDeclaration': function(t) {

'params': function(t) {
return '(' + t[1] + ')';
return '(' + t[hasInfo ? 2 : 1] + ')';
}

@@ -52,0 +54,0 @@ };

@@ -11,3 +11,4 @@ module.exports = function(js) {

tn = 0,
ln = 1;
ln = 1,
col = 1;

@@ -52,2 +53,18 @@ var Punctuation = {

/**
* Shift position right
* @param {number} [number]
*/
function shiftRight(number) {
number = number || 1;
col += number;
pos += number;
}
/**
* Shift position left
*/
function shiftLeft() {
col--;
pos--;
}
/**
* Add a token to the token list

@@ -57,4 +74,4 @@ * @param {string} type

*/
function pushToken(type, value) {
tokens.push({ tn: tn++, ln: ln, type: type, value: value });
function pushToken(type, value, column) {
tokens.push({ tn: tn++, ln: ln, col: column, type: type, value: value });
}

@@ -76,6 +93,7 @@

function parseSpaces(js) {
var start = pos;
var start = pos,
startCol = col;
// Read the string until we meet a non-space character:
for (; pos < js.length; pos++) {
for (; pos < js.length; shiftRight()) {
if (js.charAt(pos) !== ' ') break;

@@ -85,4 +103,4 @@ }

// Add a substring containing only spaces to tokens:
pushToken(TokenType.Space, js.substring(start, pos));
pos--;
pushToken(TokenType.Space, js.substring(start, pos), startCol);
shiftLeft();
}

@@ -96,8 +114,9 @@

function parseString(js, q) {
var start = pos;
var start = pos,
startCol = col;
// Read the string until we meet a matching quote:
for (pos = pos + 1; pos < js.length; pos++) {
for (shiftRight(); pos < js.length; shiftRight()) {
// Skip escaped quotes:
if (js.charAt(pos) === '\\') pos++;
if (js.charAt(pos) === '\\') shiftRight();
else if (js.charAt(pos) === q) break;

@@ -107,3 +126,3 @@ }

// Add the string (including quotes) to tokens:
pushToken(q === '"' ? TokenType.StringDQ : TokenType.StringSQ, js.substring(start, pos + 1));
pushToken(q === '"' ? TokenType.StringDQ : TokenType.StringSQ, js.substring(start, pos + 1), startCol);
}

@@ -116,6 +135,7 @@

function parseDecimalNumber(js) {
var start = pos;
var start = pos,
startCol = col;
// Read the string until we meet a character that's not a digit:
for (; pos < js.length; pos++) {
for (; pos < js.length; shiftRight()) {
if (!isDecimalDigit(js.charAt(pos))) break;

@@ -125,4 +145,4 @@ }

// Add the number to tokens:
pushToken(TokenType.DecimalNumber, js.substring(start, pos));
pos--;
pushToken(TokenType.DecimalNumber, js.substring(start, pos), startCol);
shiftLeft();
}

@@ -135,11 +155,12 @@

function parseIdentifier(js) {
var start = pos;
var start = pos,
startCol = col;
// Skip all opening slashes:
while (js.charAt(pos) === '/') pos++;
while (js.charAt(pos) === '/') shiftRight();
// Read the string until we meet a punctuation mark:
for (; pos < js.length; pos++) {
for (; pos < js.length; shiftRight()) {
// Skip all '\':
if (js.charAt(pos) === '\\') pos++;
if (js.charAt(pos) === '\\') shiftRight();
else if (js.charAt(pos) in Punctuation) break;

@@ -154,4 +175,4 @@ }

// Add identifier to tokens:
pushToken(TokenType.Identifier, ident);
pos--;
pushToken(TokenType.Identifier, ident, startCol);
shiftLeft();
}

@@ -164,3 +185,4 @@

function parseMLComment(js) {
var start = pos;
var start = pos,
startCol = col;

@@ -170,5 +192,5 @@ // Read the string until we meet `*/`.

// from `pos + 2`:
for (pos = pos + 2; pos < js.length; pos++) {
for (shiftRight(2); pos < js.length; shiftRight()) {
if (js.charAt(pos) === '*' && js.charAt(pos + 1) === '/') {
pos++;
shiftRight();
break;

@@ -179,7 +201,8 @@ }

// Add full comment (including `/*` and `*/`) to the list of tokens:
pushToken(TokenType.CommentML, js.substring(start, pos + 1));
pushToken(TokenType.CommentML, js.substring(start, pos + 1), startCol);
}
function parseSLComment(js) {
var start = pos;
var start = pos,
startCol = col;

@@ -189,3 +212,3 @@ // Read the string until we meet line break.

// from `pos + 2`:
for (pos = pos + 2; pos < js.length; pos++) {
for (shiftRight(2); pos < js.length; shiftRight()) {
if (js.charAt(pos) === '\n' || js.charAt(pos) === '\r') {

@@ -197,4 +220,4 @@ break;

// Add comment (including `//` and line break) to the list of tokens:
pushToken(TokenType.CommentSL, js.substring(start, pos));
pos--;
pushToken(TokenType.CommentSL, js.substring(start, pos), startCol);
shiftLeft();
}

@@ -210,3 +233,3 @@

// Parse string, character by character:
for (pos = 0; pos < js.length; pos++) {
for (pos = 0; pos < js.length; shiftRight()) {
c = js.charAt(pos);

@@ -238,3 +261,3 @@ cn = js.charAt(pos + 1);

else if (c === ' ') {
parseSpaces(js)
parseSpaces(js);
}

@@ -245,4 +268,7 @@

// Add it to the list of tokens:
pushToken(Punctuation[c], c);
if (c === '\n' || c === '\r') ln++; // Go to next line
pushToken(Punctuation[c], c, col);
if (c === '\n' || c === '\r') {
ln++;
col = 0;
} // Go to next line
if (c === ')') urlMode = false; // exit url mode

@@ -249,0 +275,0 @@ if (c === '{') blockMode++; // enter a block

@@ -5,2 +5,4 @@ module.exports = function stringify(tree) {

var hasInfo = typeof tree[0] === 'object';
var _m_simple = {

@@ -23,3 +25,3 @@ 'attrselector': 1, 'combinator': 1, 'nth': 1, 'number': 1,

function _t(tree) {
var t = tree[0];
var t = tree[hasInfo ? 1 : 0];
if (t in _m_primitive) return _m_primitive[t];

@@ -33,3 +35,3 @@ else if (t in _m_simple) return _simple(tree);

var s = '';
i = i === undefined ? 1 : i;
i = i === undefined ? (hasInfo ? 2 : 1) : i;
for (; i < t.length; i++) s += typeof t[i] === 'string' ? t[i] : _t(t[i]);

@@ -40,3 +42,3 @@ return s;

function _simple(t) {
return t[1];
return t[hasInfo ? 2 : 1];
}

@@ -49,6 +51,6 @@

'atkeyword': function(t) {
return '@' + _t(t[1]);
return '@' + _t(t[hasInfo ? 2 : 1]);
},
'atruler': function(t) {
return _t(t[1]) + _t(t[2]) + '{' + _t(t[3]) + '}';
return _t(t[hasInfo ? 2 : 1]) + _t(t[hasInfo ? 3 : 2]) + '{' + _t(t[hasInfo ? 4 : 3]) + '}';
},

@@ -62,21 +64,21 @@ 'attrib': function(t) {

'braces': function(t) {
return t[1] + _composite(t, 3) + t[2];
return t[hasInfo ? 2 : 1] + _composite(t, hasInfo ? 4 : 3) + t[hasInfo ? 3 : 2];
},
'class': function(t) {
return '.' + _t(t[1]);
return '.' + _t(t[hasInfo ? 2 : 1]);
},
'commentML': function (t) {
return '/*' + t[1] + '*/';
return '/*' + t[hasInfo ? 2 : 1] + '*/';
},
'commentSL': function (t) {
return '/' + '/' + t[1];
return '/' + '/' + t[hasInfo ? 2 : 1];
},
'escapedString': function(t) {
return '~' + t[1];
return '~' + t[hasInfo ? 2 : 1];
},
'filter': function(t) {
return _t(t[1]) + ':' + _t(t[2]);
return _t(t[hasInfo ? 2 : 1]) + ':' + _t(t[hasInfo ? 3 : 2]);
},
'functionExpression': function(t) {
return 'expression(' + t[1] + ')';
return 'expression(' + t[hasInfo ? 2 : 1] + ')';
},

@@ -87,18 +89,18 @@ 'important': function(t) {

'interpolatedVariable': function(t) {
return '@{' + _t(t[1]) + '}';
return '@{' + _t(t[hasInfo ? 2 : 1]) + '}';
},
'nthselector': function(t) {
return ':' + _simple(t[1]) + '(' + _composite(t, 2) + ')';
return ':' + _simple(t[hasInfo ? 2 : 1]) + '(' + _composite(t, hasInfo ? 3 : 2) + ')';
},
'percentage': function(t) {
return _t(t[1]) + '%';
return _t(t[hasInfo ? 2 : 1]) + '%';
},
'pseudoc': function(t) {
return ':' + _t(t[1]);
return ':' + _t(t[hasInfo ? 2 : 1]);
},
'pseudoe': function(t) {
return '::' + _t(t[1]);
return '::' + _t(t[hasInfo ? 2 : 1]);
},
'shash': function (t) {
return '#' + t[1];
return '#' + t[hasInfo ? 2 : 1];
},

@@ -109,9 +111,9 @@ 'uri': function(t) {

'variable': function(t) {
return '@' + _t(t[1]);
return '@' + _t(t[hasInfo ? 2 : 1]);
},
'variableslist': function(t) {
return _t(t[1]) + '...';
return _t(t[hasInfo ? 2 : 1]) + '...';
},
'vhash': function(t) {
return '#' + t[1];
return '#' + t[hasInfo ? 2 : 1];
}

@@ -118,0 +120,0 @@ };

@@ -11,3 +11,4 @@ module.exports = function(css) {

tn = 0,
ln = 1;
ln = 1,
col = 1;

@@ -52,2 +53,18 @@ var Punctuation = {

/**
* Shift position right
* @param {number} [number]
*/
function shiftRight(number) {
number = number || 1;
col += number;
pos += number;
}
/**
* Shift position left
*/
function shiftLeft() {
col--;
pos--;
}
/**
* Add a token to the token list

@@ -57,4 +74,4 @@ * @param {string} type

*/
function pushToken(type, value) {
tokens.push({ tn: tn++, ln: ln, type: type, value: value });
function pushToken(type, value, column) {
tokens.push({ tn: tn++, ln: ln, col: column, type: type, value: value });
}

@@ -76,6 +93,7 @@

function parseSpaces(css) {
var start = pos;
var start = pos,
startCol = col;
// Read the string until we meet a non-space character:
for (; pos < css.length; pos++) {
for (; pos < css.length; shiftRight()) {
if (css.charAt(pos) !== ' ') break;

@@ -85,4 +103,4 @@ }

// Add a substring containing only spaces to tokens:
pushToken(TokenType.Space, css.substring(start, pos));
pos--;
pushToken(TokenType.Space, css.substring(start, pos), startCol);
shiftLeft();
}

@@ -96,8 +114,9 @@

function parseString(css, q) {
var start = pos;
var start = pos,
startCol = col;
// Read the string until we meet a matching quote:
for (pos = pos + 1; pos < css.length; pos++) {
for (shiftRight(); pos < css.length; shiftRight()) {
// Skip escaped quotes:
if (css.charAt(pos) === '\\') pos++;
if (css.charAt(pos) === '\\') shiftRight();
else if (css.charAt(pos) === q) break;

@@ -107,3 +126,3 @@ }

// Add the string (including quotes) to tokens:
pushToken(q === '"' ? TokenType.StringDQ : TokenType.StringSQ, css.substring(start, pos + 1));
pushToken(q === '"' ? TokenType.StringDQ : TokenType.StringSQ, css.substring(start, pos + 1), startCol);
}

@@ -116,6 +135,7 @@

function parseDecimalNumber(css) {
var start = pos;
var start = pos,
startCol = col;
// Read the string until we meet a character that's not a digit:
for (; pos < css.length; pos++) {
for (; pos < css.length; shiftRight()) {
if (!isDecimalDigit(css.charAt(pos))) break;

@@ -125,4 +145,4 @@ }

// Add the number to tokens:
pushToken(TokenType.DecimalNumber, css.substring(start, pos));
pos--;
pushToken(TokenType.DecimalNumber, css.substring(start, pos), startCol);
shiftLeft();
}

@@ -135,11 +155,12 @@

function parseIdentifier(css) {
var start = pos;
var start = pos,
startCol = col;
// Skip all opening slashes:
while (css.charAt(pos) === '/') pos++;
while (css.charAt(pos) === '/') shiftRight();
// Read the string until we meet a punctuation mark:
for (; pos < css.length; pos++) {
for (; pos < css.length; shiftRight()) {
// Skip all '\':
if (css.charAt(pos) === '\\') pos++;
if (css.charAt(pos) === '\\') shiftRight();
else if (css.charAt(pos) in Punctuation) break;

@@ -154,4 +175,4 @@ }

// Add identifier to tokens:
pushToken(TokenType.Identifier, ident);
pos--;
pushToken(TokenType.Identifier, ident, startCol);
shiftLeft();
}

@@ -164,3 +185,4 @@

function parseMLComment(css) {
var start = pos;
var start = pos,
startCol = col;

@@ -170,5 +192,5 @@ // Read the string until we meet `*/`.

// from `pos + 2`:
for (pos = pos + 2; pos < css.length; pos++) {
for (shiftRight(2); pos < css.length; shiftRight()) {
if (css.charAt(pos) === '*' && css.charAt(pos + 1) === '/') {
pos++;
shiftRight();
break;

@@ -179,3 +201,3 @@ }

// Add full comment (including `/*` and `*/`) to the list of tokens:
pushToken(TokenType.CommentML, css.substring(start, pos + 1));
pushToken(TokenType.CommentML, css.substring(start, pos + 1), col);
}

@@ -188,3 +210,4 @@

function parseSLComment(css) {
var start = pos;
var start = pos,
startCol = col;

@@ -194,3 +217,3 @@ // Read the string until we meet line break.

// from `pos + 2`:
for (pos = pos + 2; pos < css.length; pos++) {
for (shiftRight(2); pos < css.length; shiftRight()) {
if (css.charAt(pos) === '\n' || css.charAt(pos) === '\r') {

@@ -202,4 +225,4 @@ break;

// Add comment (including `//` and line break) to the list of tokens:
pushToken(TokenType.CommentSL, css.substring(start, pos));
pos--;
pushToken(TokenType.CommentSL, css.substring(start, pos), startCol);
shiftLeft();
}

@@ -215,3 +238,3 @@

// Parse string, character by character:
for (pos = 0; pos < css.length; pos++) {
for (pos = 0; pos < css.length; shiftRight()) {
c = css.charAt(pos);

@@ -242,3 +265,3 @@ cn = css.charAt(pos + 1);

else if (c === ' ') {
parseSpaces(css)
parseSpaces(css);
}

@@ -249,4 +272,7 @@

// Add it to the list of tokens:
pushToken(Punctuation[c], c);
if (c === '\n' || c === '\r') ln++; // Go to next line
pushToken(Punctuation[c], c, col);
if (c === '\n' || c === '\r') {
ln++;
col = 0;
} // Go to next line
if (c === ')') urlMode = false; // exit url mode

@@ -253,0 +279,0 @@ if (c === '{') blockMode++; // enter a block

@@ -5,2 +5,4 @@ module.exports = function stringify(tree) {

var hasInfo = typeof tree[0] === 'object';
var _m_simple = {

@@ -24,3 +26,3 @@ 'attrselector': 1, 'combinator': 1, 'nth': 1, 'number': 1,

function _t(tree) {
var t = tree[0];
var t = tree[hasInfo ? 1 : 0];
if (t in _m_primitive) return _m_primitive[t];

@@ -34,3 +36,3 @@ else if (t in _m_simple) return _simple(tree);

var s = '';
i = i === undefined ? 1 : i;
i = i === undefined ? (hasInfo ? 2 : 1) : i;
for (; i < t.length; i++) s += typeof t[i] === 'string' ? t[i] : _t(t[i]);

@@ -41,3 +43,3 @@ return s;

function _simple(t) {
return t[1];
return t[hasInfo ? 2 : 1];
}

@@ -50,6 +52,6 @@

'atkeyword': function(t) {
return '@' + _t(t[1]);
return '@' + _t(t[hasInfo ? 2 : 1]);
},
'atruler': function(t) {
return _t(t[1]) + _t(t[2]) + '{' + _t(t[3]) + '}';
return _t(t[hasInfo ? 2 : 1]) + _t(t[hasInfo ? 3 : 2]) + '{' + _t(t[hasInfo ? 4 : 3]) + '}';
},

@@ -63,12 +65,12 @@ 'attrib': function(t) {

'braces': function(t) {
return t[1] + _composite(t, 3) + t[2];
return t[hasInfo ? 2 : 1] + _composite(t, hasInfo ? 4 : 3) + t[hasInfo ? 3 : 2];
},
'class': function(t) {
return '.' + _t(t[1]);
return '.' + _t(t[hasInfo ? 2 : 1]);
},
'commentML': function (t) {
return '/*' + t[1];
return '/*' + t[hasInfo ? 2 : 1];
},
'commentSL': function (t) {
return '/' + '/' + t[1];
return '/' + '/' + t[hasInfo ? 2 : 1];
},

@@ -79,6 +81,6 @@ 'default': function(t) {

'filter': function(t) {
return _t(t[1]) + ':' + _t(t[2]);
return _t(t[hasInfo ? 2 : 1]) + ':' + _t(t[hasInfo ? 3 : 2]);
},
'functionExpression': function(t) {
return 'expression(' + t[1] + ')';
return 'expression(' + t[hasInfo ? 2 : 1] + ')';
},

@@ -89,21 +91,21 @@ 'important': function(t) {

'interpolation': function(t) {
return '#{' + _t(t[1]) + '}';
return '#{' + _t(t[hasInfo ? 2 : 1]) + '}';
},
'nthselector': function(t) {
return ':' + _simple(t[1]) + '(' + _composite(t, 2) + ')';
return ':' + _simple(t[hasInfo ? 2 : 1]) + '(' + _composite(t, hasInfo ? 3 : 2) + ')';
},
'percentage': function(t) {
return _t(t[1]) + '%';
return _t(t[hasInfo ? 2 : 1]) + '%';
},
'placeholder': function(t) {
return '%' + _t(t[1]);
return '%' + _t(t[hasInfo ? 2 : 1]);
},
'pseudoc': function(t) {
return ':' + _t(t[1]);
return ':' + _t(t[hasInfo ? 2 : 1]);
},
'pseudoe': function(t) {
return '::' + _t(t[1]);
return '::' + _t(t[hasInfo ? 2 : 1]);
},
'shash': function (t) {
return '#' + t[1];
return '#' + t[hasInfo ? 2 : 1];
},

@@ -114,9 +116,9 @@ 'uri': function(t) {

'variable': function(t) {
return '$' + _t(t[1]);
return '$' + _t(t[hasInfo ? 2 : 1]);
},
'variableslist': function(t) {
return _t(t[1]) + '...';
return _t(t[hasInfo ? 2 : 1]) + '...';
},
'vhash': function(t) {
return '#' + t[1];
return '#' + t[hasInfo ? 2 : 1];
}

@@ -123,0 +125,0 @@ };

@@ -11,3 +11,4 @@ module.exports = function(css) {

tn = 0,
ln = 1;
ln = 1,
col = 1;

@@ -52,2 +53,18 @@ var Punctuation = {

/**
* Shift position right
* @param {number} [number]
*/
function shiftRight(number) {
number = number || 1;
col += number;
pos += number;
}
/**
* Shift position left
*/
function shiftLeft() {
col--;
pos--;
}
/**
* Add a token to the token list

@@ -57,4 +74,4 @@ * @param {string} type

*/
function pushToken(type, value) {
tokens.push({ tn: tn++, ln: ln, type: type, value: value });
function pushToken(type, value, column) {
tokens.push({ tn: tn++, ln: ln, col: column, type: type, value: value });
}

@@ -76,6 +93,7 @@

function parseSpaces(css) {
var start = pos;
var start = pos,
startCol = col;
// Read the string until we meet a non-space character:
for (; pos < css.length; pos++) {
for (; pos < css.length; shiftRight()) {
if (css.charAt(pos) !== ' ') break;

@@ -85,4 +103,4 @@ }

// Add a substring containing only spaces to tokens:
pushToken(TokenType.Space, css.substring(start, pos));
pos--;
pushToken(TokenType.Space, css.substring(start, pos), pos);
shiftLeft();
}

@@ -96,8 +114,9 @@

function parseString(css, q) {
var start = pos;
var start = pos,
startCol = col;
// Read the string until we meet a matching quote:
for (pos = pos + 1; pos < css.length; pos++) {
for (shiftRight(); pos < css.length; shiftRight()) {
// Skip escaped quotes:
if (css.charAt(pos) === '\\') pos++;
if (css.charAt(pos) === '\\') shiftRight();
else if (css.charAt(pos) === q) break;

@@ -107,3 +126,3 @@ }

// Add the string (including quotes) to tokens:
pushToken(q === '"' ? TokenType.StringDQ : TokenType.StringSQ, css.substring(start, pos + 1));
pushToken(q === '"' ? TokenType.StringDQ : TokenType.StringSQ, css.substring(start, pos + 1), startCol);
}

@@ -116,6 +135,7 @@

function parseDecimalNumber(css) {
var start = pos;
var start = pos,
startCol = col;
// Read the string until we meet a character that's not a digit:
for (; pos < css.length; pos++) {
for (; pos < css.length; shiftRight()) {
if (!isDecimalDigit(css.charAt(pos))) break;

@@ -125,4 +145,4 @@ }

// Add the number to tokens:
pushToken(TokenType.DecimalNumber, css.substring(start, pos));
pos--;
pushToken(TokenType.DecimalNumber, css.substring(start, pos), startCol);
shiftLeft();
}

@@ -135,11 +155,12 @@

function parseIdentifier(css) {
var start = pos;
var start = pos,
startCol = col;
// Skip all opening slashes:
while (css.charAt(pos) === '/') pos++;
while (css.charAt(pos) === '/') shiftRight();
// Read the string until we meet a punctuation mark:
for (; pos < css.length; pos++) {
for (; pos < css.length; shiftRight()) {
// Skip all '\':
if (css.charAt(pos) === '\\') pos++;
if (css.charAt(pos) === '\\') shiftRight();
else if (css.charAt(pos) in Punctuation) break;

@@ -154,4 +175,4 @@ }

// Add identifier to tokens:
pushToken(TokenType.Identifier, ident);
pos--;
pushToken(TokenType.Identifier, ident, startCol);
shiftLeft();
}

@@ -164,3 +185,4 @@

function parseMLComment(css) {
var start = pos;
var start = pos,
startCol = col;

@@ -175,3 +197,3 @@ // Get current indent level:

for (pos = pos + 2; pos < css.length; pos++) {
for (shiftRight(2); pos < css.length; shiftRight()) {
if (css.charAt(pos) === '\n') {

@@ -186,3 +208,4 @@ // Get new line's indent level:

if (_il > il) {
pos = _pos;
col = 0;
shiftRight(_pos - pos);
} else break;

@@ -193,3 +216,3 @@ }

// Add full comment (including `/*`) to the list of tokens:
pushToken(TokenType.CommentML, css.substring(start, pos + 1));
pushToken(TokenType.CommentML, css.substring(start, pos + 1), startCol);
}

@@ -202,3 +225,4 @@

function parseSLComment(css) {
var start = pos;
var start = pos,
startCol = col;

@@ -223,3 +247,3 @@ // Check if comment is the only token on the line, and if so,

if (!onlyToken) {
for (pos = pos + 2; pos < css.length; pos++) {
for (shiftRight(2); pos < css.length; shiftRight()) {
if (css.charAt(pos) === '\n' || css.charAt(pos) === '\r') {

@@ -230,3 +254,3 @@ break;

} else {
for (pos = pos + 2; pos < css.length; pos++) {
for (shiftRight(2); pos < css.length; shiftRight()) {
if (css.charAt(pos) === '\n') {

@@ -241,3 +265,4 @@ // Get new line's indent level:

if (_il > il) {
pos = _pos;
col = 0;
shiftRight(_pos - pos);
} else break;

@@ -249,4 +274,4 @@ }

// Add comment (including `//` and line break) to the list of tokens:
pushToken(TokenType.CommentSL, css.substring(start, pos));
pos--;
pushToken(TokenType.CommentSL, css.substring(start, pos), startCol);
shiftLeft();
}

@@ -262,3 +287,3 @@

// Parse string, character by character:
for (pos = 0; pos < css.length; pos++) {
for (pos = 0; pos < css.length; shiftRight()) {
c = css.charAt(pos);

@@ -289,3 +314,3 @@ cn = css.charAt(pos + 1);

else if (c === ' ') {
parseSpaces(css)
parseSpaces(css);
}

@@ -296,4 +321,7 @@

// Add it to the list of tokens:
pushToken(Punctuation[c], c);
if (c === '\n' || c === '\r') ln++; // Go to next line
pushToken(Punctuation[c], c, col);
if (c === '\n' || c === '\r') {
ln++;
col = 0;
} // Go to next line
if (c === ')') urlMode = false; // exit url mode

@@ -300,0 +328,0 @@ if (c === '{') blockMode++; // enter a block

@@ -5,2 +5,4 @@ module.exports = function stringify(tree) {

var hasInfo = typeof tree[0] === 'object';
var _m_simple = {

@@ -24,3 +26,4 @@ 'attrselector': 1, 'combinator': 1, 'nth': 1, 'number': 1,

function _t(tree) {
var t = tree[0];
var t = tree[hasInfo ? 1 : 0];
if (t in _m_primitive) return _m_primitive[t];

@@ -34,3 +37,3 @@ else if (t in _m_simple) return _simple(tree);

var s = '';
i = i === undefined ? 1 : i;
i = i === undefined ? (hasInfo ? 2 : 1) : i;
for (; i < t.length; i++) s += typeof t[i] === 'string' ? t[i] : _t(t[i]);

@@ -41,3 +44,3 @@ return s;

function _simple(t) {
return t[1];
return t[hasInfo ? 2 : 1];
}

@@ -50,6 +53,6 @@

'atkeyword': function(t) {
return '@' + _t(t[1]);
return '@' + _t(t[hasInfo ? 2 : 1]);
},
'atruler': function(t) {
return _t(t[1]) + _t(t[2]) + '{' + _t(t[3]) + '}';
return _t(t[hasInfo ? 2 : 1]) + _t(t[hasInfo ? 3 : 2]) + '{' + _t(t[hasInfo ? 4 : 3]) + '}';
},

@@ -63,12 +66,12 @@ 'attrib': function(t) {

'braces': function(t) {
return t[1] + _composite(t, 3) + t[2];
return t[hasInfo ? 2 : 1] + _composite(t, hasInfo ? 4 : 3) + t[hasInfo ? 3 : 2];
},
'class': function(t) {
return '.' + _t(t[1]);
return '.' + _t(t[hasInfo ? 2 : 1]);
},
'commentML': function (t) {
return '/*' + t[1] + '*/';
return '/*' + t[hasInfo ? 2 : 1] + '*/';
},
'commentSL': function (t) {
return '/' + '/' + t[1];
return '/' + '/' + t[hasInfo ? 2 : 1];
},

@@ -79,6 +82,6 @@ 'default': function(t) {

'filter': function(t) {
return _t(t[1]) + ':' + _t(t[2]);
return _t(t[hasInfo ? 2 : 1]) + ':' + _t(t[hasInfo ? 3 : 2]);
},
'functionExpression': function(t) {
return 'expression(' + t[1] + ')';
return 'expression(' + t[hasInfo ? 2 : 1] + ')';
},

@@ -89,21 +92,21 @@ 'important': function(t) {

'interpolation': function(t) {
return '#{' + _t(t[1]) + '}';
return '#{' + _t(t[hasInfo ? 2 : 1]) + '}';
},
'nthselector': function(t) {
return ':' + _simple(t[1]) + '(' + _composite(t, 2) + ')';
return ':' + _simple(t[hasInfo ? 2 : 1]) + '(' + _composite(t, hasInfo ? 3 : 2) + ')';
},
'percentage': function(t) {
return _t(t[1]) + '%';
return _t(t[hasInfo ? 2 : 1]) + '%';
},
'placeholder': function(t) {
return '%' + _t(t[1]);
return '%' + _t(t[hasInfo ? 2 : 1]);
},
'pseudoc': function(t) {
return ':' + _t(t[1]);
return ':' + _t(t[hasInfo ? 2 : 1]);
},
'pseudoe': function(t) {
return '::' + _t(t[1]);
return '::' + _t(t[hasInfo ? 2 : 1]);
},
'shash': function (t) {
return '#' + t[1];
return '#' + t[hasInfo ? 2 : 1];
},

@@ -114,9 +117,9 @@ 'uri': function(t) {

'variable': function(t) {
return '$' + _t(t[1]);
return '$' + _t(t[hasInfo ? 2 : 1]);
},
'variableslist': function(t) {
return _t(t[1]) + '...';
return _t(t[hasInfo ? 2 : 1]) + '...';
},
'vhash': function(t) {
return '#' + t[1];
return '#' + t[hasInfo ? 2 : 1];
}

@@ -123,0 +126,0 @@ };

@@ -11,3 +11,4 @@ module.exports = function(css) {

tn = 0,
ln = 1;
ln = 1,
col = 1;

@@ -52,2 +53,18 @@ var Punctuation = {

/**
* Shift position right
* @param {number} [number]
*/
function shiftRight(number) {
number = number || 1;
col += number;
pos += number;
}
/**
* Shift position left
*/
function shiftLeft() {
col--;
pos--;
}
/**
* Add a token to the token list

@@ -57,4 +74,4 @@ * @param {string} type

*/
function pushToken(type, value) {
tokens.push({ tn: tn++, ln: ln, type: type, value: value });
function pushToken(type, value, column) {
tokens.push({ tn: tn++, ln: ln, col: column, type: type, value: value });
}

@@ -76,6 +93,7 @@

function parseSpaces(css) {
var start = pos;
var start = pos,
startCol = col;
// Read the string until we meet a non-space character:
for (; pos < css.length; pos++) {
for (; pos < css.length; shiftRight()) {
if (css.charAt(pos) !== ' ') break;

@@ -85,4 +103,4 @@ }

// Add a substring containing only spaces to tokens:
pushToken(TokenType.Space, css.substring(start, pos));
pos--;
pushToken(TokenType.Space, css.substring(start, pos), startCol);
shiftLeft();
}

@@ -96,8 +114,9 @@

function parseString(css, q) {
var start = pos;
var start = pos,
startCol = col;
// Read the string until we meet a matching quote:
for (pos = pos + 1; pos < css.length; pos++) {
for (shiftRight(); pos < css.length; shiftRight()) {
// Skip escaped quotes:
if (css.charAt(pos) === '\\') pos++;
if (css.charAt(pos) === '\\') shiftRight();
else if (css.charAt(pos) === q) break;

@@ -107,3 +126,3 @@ }

// Add the string (including quotes) to tokens:
pushToken(q === '"' ? TokenType.StringDQ : TokenType.StringSQ, css.substring(start, pos + 1));
pushToken(q === '"' ? TokenType.StringDQ : TokenType.StringSQ, css.substring(start, pos + 1), startCol);
}

@@ -116,6 +135,7 @@

function parseDecimalNumber(css) {
var start = pos;
var start = pos,
startCol = col;
// Read the string until we meet a character that's not a digit:
for (; pos < css.length; pos++) {
for (; pos < css.length; shiftRight()) {
if (!isDecimalDigit(css.charAt(pos))) break;

@@ -125,4 +145,4 @@ }

// Add the number to tokens:
pushToken(TokenType.DecimalNumber, css.substring(start, pos));
pos--;
pushToken(TokenType.DecimalNumber, css.substring(start, pos), startCol);
shiftLeft();
}

@@ -135,11 +155,12 @@

function parseIdentifier(css) {
var start = pos;
var start = pos,
startCol = col;
// Skip all opening slashes:
while (css.charAt(pos) === '/') pos++;
while (css.charAt(pos) === '/') shiftRight();
// Read the string until we meet a punctuation mark:
for (; pos < css.length; pos++) {
for (; pos < css.length; shiftRight()) {
// Skip all '\':
if (css.charAt(pos) === '\\') pos++;
if (css.charAt(pos) === '\\') shiftRight();
else if (css.charAt(pos) in Punctuation) break;

@@ -154,4 +175,4 @@ }

// Add identifier to tokens:
pushToken(TokenType.Identifier, ident);
pos--;
pushToken(TokenType.Identifier, ident, startCol);
shiftLeft();
}

@@ -164,3 +185,4 @@

function parseMLComment(css) {
var start = pos;
var start = pos,
startCol = col;

@@ -170,5 +192,5 @@ // Read the string until we meet `*/`.

// from `pos + 2`:
for (pos = pos + 2; pos < css.length; pos++) {
for (shiftRight(2); pos < css.length; shiftRight()) {
if (css.charAt(pos) === '*' && css.charAt(pos + 1) === '/') {
pos++;
shiftRight();
break;

@@ -179,3 +201,3 @@ }

// Add full comment (including `/*` and `*/`) to the list of tokens:
pushToken(TokenType.CommentML, css.substring(start, pos + 1));
pushToken(TokenType.CommentML, css.substring(start, pos + 1), startCol);
}

@@ -188,3 +210,4 @@

function parseSLComment(css) {
var start = pos;
var start = pos,
startCol = col;

@@ -194,3 +217,3 @@ // Read the string until we meet line break.

// from `pos + 2`:
for (pos = pos + 2; pos < css.length; pos++) {
for (shiftRight(2); pos < css.length; shiftRight()) {
if (css.charAt(pos) === '\n' || css.charAt(pos) === '\r') {

@@ -202,4 +225,4 @@ break;

// Add comment (including `//` and line break) to the list of tokens:
pushToken(TokenType.CommentSL, css.substring(start, pos));
pos--;
pushToken(TokenType.CommentSL, css.substring(start, pos), startCol);
shiftLeft();
}

@@ -215,3 +238,3 @@

// Parse string, character by character:
for (pos = 0; pos < css.length; pos++) {
for (pos = 0; pos < css.length; shiftRight()) {
c = css.charAt(pos);

@@ -242,3 +265,3 @@ cn = css.charAt(pos + 1);

else if (c === ' ') {
parseSpaces(css)
parseSpaces(css);
}

@@ -249,4 +272,7 @@

// Add it to the list of tokens:
pushToken(Punctuation[c], c);
if (c === '\n' || c === '\r') ln++; // Go to next line
pushToken(Punctuation[c], c, col);
if (c === '\n' || c === '\r') {
ln++;
col = 0;
} // Go to next line
if (c === ')') urlMode = false; // exit url mode

@@ -253,0 +279,0 @@ if (c === '{') blockMode++; // enter a block

@@ -48,3 +48,3 @@ module.exports = (function() {

return function(options) {
var src, rule, syntax, getTokens, mark, rules, tokens, ast;
var src, rule, syntax, getTokens, mark, rules, tokens, ast, needInfo;

@@ -55,2 +55,3 @@ if (!options || !options.src) throw new Error('Please, pass a string to parse');

syntax = options.syntax || 'css';
needInfo = options.needInfo || false;
rule = options.rule || (syntax === 'js' ? 'program' : 'stylesheet');

@@ -70,3 +71,3 @@

try {
ast = rules(tokens, rule);
ast = rules(tokens, rule, needInfo);
} catch (e) {

@@ -73,0 +74,0 @@ throwError(e, src);

{
"name": "gonzales-pe",
"description": "Gonzales Preprocessor Edition (fast CSS parser)",
"version": "3.0.0-10",
"version": "3.0.0-11",
"homepage": "http://github.com/tonyganch/gonzales-pe",

@@ -6,0 +6,0 @@ "bugs": "http://github.com/tonyganch/gonzales-pe/issues",

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

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc