Socket
Socket
Sign inDemoInstall

csso

Package Overview
Dependencies
Maintainers
3
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

csso - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

6

HISTORY.md

@@ -0,1 +1,7 @@

## 2.1.0 (May 8, 2016)
- New option `comments` to specify what comments to left: `exclamation`, `first-exclamation` and `none`
- Add `offset` to CSS parse error details
- Fix token `offset` computation
## 2.0.0 (April 5, 2016)

@@ -2,0 +8,0 @@

@@ -176,2 +176,14 @@ var fs = require('fs');

function processCommentsOption(value) {
switch (value) {
case 'exclamation':
case 'first-exclamation':
case 'none':
return value;
}
console.error('Wrong value for `comments` option: %s', value);
process.exit(2);
}
var command = cli.create('csso', '[input] [output]')

@@ -185,2 +197,3 @@ .version(require('../package.json').version)

.option('--restructure-off', 'Turns structure minimization off')
.option('--comments <value>', 'Comments to keep: exclamation (default), first-exclamation or none', 'exclamation')
.option('--stat', 'Output statistics in stderr')

@@ -197,2 +210,3 @@ .option('--debug [level]', 'Output intermediate state of CSS during compression', debugLevel, 0)

var structureOptimisationOff = options.restructureOff;
var comments = processCommentsOption(options.comments);
var debug = options.debug;

@@ -249,2 +263,3 @@ var statistics = options.stat;

restructure: !structureOptimisationOff,
comments: comments,
debug: debug

@@ -251,0 +266,0 @@ });

40

lib/compressor/index.js

@@ -8,3 +8,3 @@ var List = require('../utils/list');

function readBlock(stylesheet) {
function readBlock(stylesheet, specialComments) {
var buffer = new List();

@@ -15,3 +15,8 @@ var nonSpaceTokenInBuffer = false;

stylesheet.rules.nextUntil(stylesheet.rules.head, function(node, item, list) {
if (node.type === 'Comment' && node.value.charAt(0) === '!') {
if (node.type === 'Comment') {
if (!specialComments || node.value.charAt(0) !== '!') {
list.remove(item);
return;
}
if (nonSpaceTokenInBuffer || protectedComment) {

@@ -65,2 +70,20 @@ return true;

function getCommentsOption(options) {
var comments = 'comments' in options ? options.comments : 'exclamation';
if (typeof comments === 'boolean') {
comments = comments ? 'exclamation' : false;
} else if (comments !== 'exclamation' && comments !== 'first-exclamation') {
comments = false;
}
return comments;
}
function getRestructureOption(options) {
return 'restructure' in options ? options.restructure :
'restructuring' in options ? options.restructuring :
true;
}
module.exports = function compress(ast, options) {

@@ -71,6 +94,4 @@ options = options || {};

var logger = typeof options.logger === 'function' ? options.logger : Function();
var restructuring =
'restructure' in options ? options.restructure :
'restructuring' in options ? options.restructuring :
true;
var specialComments = getCommentsOption(options);
var restructuring = getRestructureOption(options);
var result = new List();

@@ -111,4 +132,3 @@ var block;

do {
block = readBlock(ast);
// console.log(JSON.stringify(block.stylesheet, null, 2));
block = readBlock(ast, Boolean(specialComments));
block.stylesheet.firstAtrulesAllowed = firstAtrulesAllowed;

@@ -153,2 +173,6 @@ block.stylesheet = compressBlock(block.stylesheet, usageData, blockNum++, logger);

if (specialComments !== 'exclamation') {
specialComments = false;
}
result.appendList(blockRules);

@@ -155,0 +179,0 @@ } while (!ast.rules.isEmpty());

4

lib/index.js

@@ -6,2 +6,3 @@ var parse = require('./parser');

var walkers = require('./utils/walk');
var List = require('./utils/list');

@@ -111,2 +112,5 @@ function debugOutput(name, options, startTime, data) {

// classes
List: List,
// main methods

@@ -113,0 +117,0 @@ minify: minifyStylesheet,

@@ -47,2 +47,3 @@ 'use strict';

var error = new Error(message);
var offset = 0;
var line = 1;

@@ -53,6 +54,9 @@ var column = 1;

if (scanner.token !== null) {
offset = scanner.token.offset;
line = scanner.token.line;
column = scanner.token.column;
} else if (scanner.prevToken !== null) {
lines = scanner.prevToken.value.trimRight().split(/\n|\r\n?|\f/);
lines = scanner.prevToken.value.trimRight();
offset = scanner.prevToken.offset + lines.length;
lines = lines.split(/\n|\r\n?|\f/);
line = scanner.prevToken.line + lines.length - 1;

@@ -66,2 +70,3 @@ column = lines.length > 1

error.parseError = {
offset: offset,
line: line,

@@ -68,0 +73,0 @@ column: column

@@ -97,3 +97,2 @@ 'use strict';

this.eof = this.pos === this.source.length;
this.lastPos = this.pos;
this.line = typeof initLine === 'undefined' ? 1 : initLine;

@@ -156,3 +155,3 @@ this.lineStartPos = typeof initColumn === 'undefined' ? -1 : -initColumn;

var column = this.pos - this.lineStartPos;
var lastPos;
var offset = this.pos;
var next;

@@ -230,4 +229,2 @@ var type;

lastPos = this.lastPos === 0 ? this.lastPos : this.lastPos - 1;
this.lastPos = this.pos;
this.eof = this.pos === this.source.length;

@@ -239,3 +236,3 @@

offset: lastPos,
offset: offset,
line: line,

@@ -242,0 +239,0 @@ column: column

{
"name": "csso",
"version": "2.0.0",
"version": "2.1.0",
"description": "CSSO (CSS Optimizer) is a CSS minifier with structural optimisations",

@@ -5,0 +5,0 @@ "keywords": [

@@ -26,2 +26,3 @@ [![NPM version](https://img.shields.io/npm/v/csso.svg)](https://www.npmjs.com/package/csso)

- PostCSS: [postcss-csso](https://github.com/lahmatiy/postcss-csso)
- Webpack: [csso-loader](https://github.com/sandark7/csso-loader)

@@ -35,2 +36,3 @@ ### Command line

--comments <value> Comments to keep: exclamation (default), first-exclamation or none
--debug [level] Output intermediate state of CSS during compression

@@ -294,2 +296,6 @@ -h, --help Output usage information

- restructure `Boolean` – do the structure optimisations or not (`true` by default)
- comments `String` or `Boolean` – specify what comments to left
- `'exclamation'` or `true` (default) – left all exclamation comments (i.e. `/*! .. */`)
- `'first-exclamation'` – remove every comments except first one
- `false` – remove every comments
- usage `Object` - usage data for advanced optimisations (see [Usage data](#usage-data) for details)

@@ -296,0 +302,0 @@ - logger `Function` - function to track every step of transformations

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