Comparing version 1.4.0 to 1.4.1
@@ -0,1 +1,12 @@ | ||
## 1.4.1 (October 20, 2015) | ||
- allow merge for `display` property (#167, #244) | ||
- more accurate `rect` (`clip` property value) merge | ||
- fix typo when specifying options in cli (thanks to @Taritsyn) | ||
- fix safe unit values merge with keyword values (#244) | ||
- fix wrong descendant combinator removal (#246) | ||
- build browser version on `prepublish` (thanks to @silentroach) | ||
- parser: store whitespaces as single token (performance and reduce memory consumption) | ||
- rearrange compress tests layout | ||
## 1.4 (October 16, 2015) | ||
@@ -2,0 +13,0 @@ |
@@ -39,3 +39,3 @@ var fs = require('fs'); | ||
var result = csso.minify(source, { | ||
restruturing: !structureOptimisationOff, | ||
restructuring: !structureOptimisationOff, | ||
debug: debug | ||
@@ -42,0 +42,0 @@ }); |
@@ -202,5 +202,3 @@ exports.nonLengthUnits = { | ||
exports.dontRestructure = { | ||
'src': 1, // https://github.com/afelix/csso/issues/50 | ||
'clip': 1, // https://github.com/afelix/csso/issues/57 | ||
'display': 1 // https://github.com/afelix/csso/issues/71 | ||
'src': 1 // https://github.com/afelix/csso/issues/50 | ||
}; | ||
@@ -207,0 +205,0 @@ |
@@ -416,3 +416,8 @@ var translate = require('../utils/translate'); | ||
} else { | ||
if ((parentType !== 'atrulerq' || prevType) && | ||
if (parentType === 'simpleselector') { | ||
if (!prevType || prevType === 'combinator' || | ||
!nextType || nextType === 'combinator') { | ||
return null; | ||
} | ||
} else if ((parentType !== 'atrulerq' || prevType) && | ||
!this.issue16(prevType, nextType) && | ||
@@ -916,3 +921,17 @@ !this.issue165(parent, prevType, nextType) && | ||
case 'funktion': | ||
functions[value[i][2][2]] = true; | ||
var name = value[i][2][2]; | ||
if (name === 'rect') { | ||
// there are 2 forms of rect: | ||
// rect(<top>, <right>, <bottom>, <left>) - standart | ||
// rect(<top> <right> <bottom> <left>) – backwards compatible syntax | ||
// only the same form values can be merged | ||
if (value[i][3].slice(2).some(function(token) { | ||
return token[1] === 'operator' && token[2] === ','; | ||
})) { | ||
name = 'rect-backward'; | ||
} | ||
} | ||
functions[name] = true; | ||
break; | ||
@@ -935,6 +954,2 @@ | ||
break; | ||
default: | ||
// regular units | ||
units.safe = true; | ||
} | ||
@@ -941,0 +956,0 @@ break; |
@@ -1570,3 +1570,5 @@ var TokenType = require('./const.js'); | ||
function checkS(_i) { | ||
if (tokens[_i].ws) return tokens[_i].ws_last - _i + 1; | ||
if (tokens[_i].type === TokenType.Space) { | ||
return 1; | ||
} | ||
@@ -1578,5 +1580,5 @@ return fail(tokens[_i]); | ||
var startPos = pos, | ||
s = joinValues(pos, tokens[pos].ws_last); | ||
s = tokens[pos].value; | ||
pos = tokens[pos].ws_last + 1; | ||
pos++; | ||
@@ -2032,4 +2034,2 @@ return needInfo? [getInfo(startPos), NodeType.SType, s] : [NodeType.SType, s]; | ||
if (type === TokenType.Space || | ||
type === TokenType.Tab || | ||
type === TokenType.Newline || | ||
type === TokenType.LeftParenthesis || | ||
@@ -2068,46 +2068,2 @@ type === TokenType.RightParenthesis) { | ||
function markSC() { | ||
var ws = -1, // whitespaces | ||
sc = -1, // ws and comments | ||
t; | ||
for (var i = 0; i < tokens.length; i++) { | ||
t = tokens[i]; | ||
switch (t.type) { | ||
case TokenType.Space: | ||
case TokenType.Tab: | ||
case TokenType.Newline: | ||
t.ws = true; | ||
t.sc = true; | ||
if (ws === -1) ws = i; | ||
if (sc === -1) sc = i; | ||
break; | ||
case TokenType.CommentML: | ||
if (ws !== -1) { | ||
tokens[ws].ws_last = i - 1; | ||
ws = -1; | ||
} | ||
t.sc = true; | ||
break; | ||
default: | ||
if (ws !== -1) { | ||
tokens[ws].ws_last = i - 1; | ||
ws = -1; | ||
} | ||
if (sc !== -1) { | ||
tokens[sc].sc_last = i - 1; | ||
sc = -1; | ||
} | ||
} | ||
} | ||
if (ws !== -1) tokens[ws].ws_last = i - 1; | ||
if (sc !== -1) tokens[sc].sc_last = i - 1; | ||
} | ||
module.exports = function parse(source, rule, _needInfo) { | ||
@@ -2120,5 +2076,5 @@ tokens = tokenize(source); | ||
markSC(); | ||
return CSSPRules[rule](); | ||
var ast = CSSPRules[rule](); | ||
//console.log(require('../utils/stringify.js')(require('../utils/cleanInfo.js')(ast), true)); | ||
return ast; | ||
}; |
var TokenType = require('./const.js'); | ||
var Punctuation; | ||
var urlMode; | ||
var source; | ||
var tokens; | ||
var pos; | ||
var lastPos; | ||
var lineStartPos; | ||
var ln; | ||
Punctuation = { | ||
var Punctuation = { | ||
' ': TokenType.Space, | ||
@@ -49,6 +44,19 @@ '\n': TokenType.Newline, | ||
function isDecimalDigit(c) { | ||
return '0123456789'.indexOf(c) >= 0; | ||
return '0123456789'.indexOf(c) !== -1; | ||
} | ||
function tokenize(s) { | ||
function pushToken(type, ln, column, value) { | ||
tokens.push(x = { | ||
type: type, | ||
value: value, | ||
offset: lastPos, | ||
line: ln, | ||
column: column | ||
}); | ||
lastPos = pos; | ||
} | ||
if (!s) { | ||
@@ -58,11 +66,10 @@ return []; | ||
source = s; | ||
tokens = []; | ||
ln = 1; | ||
urlMode = false; | ||
var tokens = []; | ||
var urlMode = false; | ||
// ignore first char if it is byte order marker (UTF-8 BOM) | ||
pos = s.charCodeAt(0) === 0xFEFF ? 1 : 0; | ||
lastPos = pos; | ||
lineStartPos = 0; | ||
var lastPos = pos; | ||
ln = 1; | ||
lineStartPos = -1; | ||
@@ -72,2 +79,3 @@ var blockMode = 0; | ||
var cn; | ||
var ident; | ||
@@ -79,22 +87,19 @@ for (; pos < s.length; pos++) { | ||
if (c === '/' && cn === '*') { | ||
parseMLComment(s); | ||
pushToken(TokenType.CommentML, ln, pos - lineStartPos, parseMLComment(s)); | ||
} else if (!urlMode && c === '/' && s.substr(pos + 1, 5) === 'deep/') { | ||
pushToken(TokenType.Deep, '/deep/'); | ||
pushToken(TokenType.Deep, ln, pos - lineStartPos, '/deep/'); | ||
pos += 5; | ||
} else if (!urlMode && c === '/' && cn === '/') { | ||
if (blockMode > 0) { | ||
parseIdentifier(s); | ||
pushToken(TokenType.Identifier, ln, pos - lineStartPos, ident = parseIdentifier(s)); | ||
urlMode = urlMode || ident === 'url'; | ||
} else { | ||
parseSLComment(s); | ||
pushToken(TokenType.CommentSL, ln, pos - lineStartPos, parseSLComment(s)); | ||
} | ||
} else if (c === '"' || c === "'") { | ||
parseString(s, c); | ||
} else if (c === ' ') { | ||
parseSpaces(s); | ||
pushToken(c === '"' ? TokenType.StringDQ : TokenType.StringSQ, ln, pos - lineStartPos, parseString(s, c)); | ||
} else if (c === ' ' || c === '\n' || c === '\r' || c === '\t') { | ||
pushToken(TokenType.Space, ln, pos - lineStartPos, parseSpaces(s)); | ||
} else if (c in Punctuation) { | ||
pushToken(Punctuation[c], c); | ||
if (c === '\n') { | ||
ln++; | ||
lineStartPos = pos; | ||
} | ||
pushToken(Punctuation[c], ln, pos - lineStartPos, c); | ||
if (c === ')') { | ||
@@ -110,9 +115,10 @@ urlMode = false; | ||
} else if (isDecimalDigit(c)) { | ||
parseDecimalNumber(s); | ||
pushToken(TokenType.DecimalNumber, ln, pos - lineStartPos, parseDecimalNumber(s)); | ||
} else { | ||
parseIdentifier(s); | ||
pushToken(TokenType.Identifier, ln, pos - lineStartPos, ident = parseIdentifier(s)); | ||
urlMode = urlMode || ident === 'url'; | ||
} | ||
} | ||
mark(); | ||
mark(tokens); | ||
@@ -122,15 +128,2 @@ return tokens; | ||
function pushToken(type, value) { | ||
tokens.push({ | ||
type: type, | ||
value: value, | ||
offset: lastPos, | ||
line: ln, | ||
column: lastPos - lineStartPos + 1 | ||
}); | ||
lastPos += value.length; | ||
} | ||
function parseSpaces(s) { | ||
@@ -140,3 +133,7 @@ var start = pos; | ||
for (; pos < s.length; pos++) { | ||
if (s.charAt(pos) !== ' ') { | ||
var c = s.charAt(pos); | ||
if (c === '\n') { | ||
ln++; | ||
lineStartPos = pos; | ||
} else if (c !== ' ' && c !== '\r' && c !== '\t') { | ||
break; | ||
@@ -146,4 +143,4 @@ } | ||
pushToken(TokenType.Space, s.substring(start, pos)); | ||
pos--; | ||
return s.substring(start, pos + 1); | ||
} | ||
@@ -167,3 +164,3 @@ | ||
pushToken(TokenType.CommentML, s.substring(start, pos + 1)); | ||
return s.substring(start, pos + 1); | ||
} | ||
@@ -181,4 +178,4 @@ | ||
pushToken(TokenType.CommentSL, s.substring(start, pos)); | ||
pos--; | ||
return s.substring(start, pos + 1); | ||
} | ||
@@ -197,3 +194,3 @@ | ||
pushToken(q === '"' ? TokenType.StringDQ : TokenType.StringSQ, s.substring(start, pos + 1)); | ||
return s.substring(start, pos + 1); | ||
} | ||
@@ -210,4 +207,4 @@ | ||
pushToken(TokenType.DecimalNumber, s.substring(start, pos)); | ||
pos--; | ||
return s.substring(start, pos + 1); | ||
} | ||
@@ -223,5 +220,6 @@ | ||
for (; pos < s.length; pos++) { | ||
if (s.charAt(pos) === '\\') { | ||
c = s.charAt(pos); | ||
if (c === '\\') { | ||
pos++; | ||
} else if (s.charAt(pos) in Punctuation) { | ||
} else if (c in Punctuation && c !== '_') { | ||
break; | ||
@@ -231,8 +229,5 @@ } | ||
var ident = s.substring(start, pos); | ||
pos--; | ||
urlMode = urlMode || ident === 'url'; | ||
pushToken(TokenType.Identifier, ident); | ||
pos--; | ||
return s.substring(start, pos + 1); | ||
} | ||
@@ -244,9 +239,8 @@ | ||
function mark() { | ||
function mark(tokens) { | ||
var ps = []; // Parenthesis | ||
var sbs = []; // SquareBracket | ||
var cbs = []; // CurlyBracket | ||
var t; | ||
for (var i = 0; i < tokens.length; i++) { | ||
for (var i = 0, t; i < tokens.length; i++) { | ||
t = tokens[i]; | ||
@@ -259,4 +253,3 @@ switch (t.type) { | ||
if (ps.length) { | ||
t.left = ps.pop(); | ||
tokens[t.left].right = i; | ||
tokens[ps.pop()].right = i; | ||
} | ||
@@ -269,4 +262,3 @@ break; | ||
if (sbs.length) { | ||
t.left = sbs.pop(); | ||
tokens[t.left].right = i; | ||
tokens[sbs.pop()].right = i; | ||
} | ||
@@ -279,4 +271,3 @@ break; | ||
if (cbs.length) { | ||
t.left = cbs.pop(); | ||
tokens[t.left].right = i; | ||
tokens[cbs.pop()].right = i; | ||
} | ||
@@ -283,0 +274,0 @@ break; |
{ | ||
"name": "csso", | ||
"description": "CSSO — CSS optimizer", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"homepage": "https://github.com/css/csso", | ||
@@ -19,3 +19,4 @@ "author": "Sergey Kryzhanovsky <skryzhanovsky@ya.ru> (https://github.com/afelix)", | ||
"browserify": "browserify --standalone csso lib/index.js | uglifyjs --compress --mangle -o dist/csso-browser.js", | ||
"gh-pages": "git clone -b gh-pages https://github.com/css/csso.git .gh-pages && npm run browserify && cp dist/csso-browser.js .gh-pages/ && cd .gh-pages && git commit -am \"update\" && git push && cd .. && rm -rf .gh-pages" | ||
"gh-pages": "git clone -b gh-pages https://github.com/css/csso.git .gh-pages && npm run browserify && cp dist/csso-browser.js .gh-pages/ && cd .gh-pages && git commit -am \"update\" && git push && cd .. && rm -rf .gh-pages", | ||
"prepublish": "npm run browserify" | ||
}, | ||
@@ -36,3 +37,3 @@ "dependencies": { | ||
"bin", | ||
"dist", | ||
"dist/csso-browser.js", | ||
"lib", | ||
@@ -39,0 +40,0 @@ "HISTORY.md", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
0
2
0
143542
20
4119