eslint-plugin-css-modules
Version:
Checks that you are using the existent css/scss/less classes, no more no less
1,991 lines (1,664 loc) • 442 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["gonzales-primitives"] = factory();
else
root["gonzales-primitives"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
var Node = __webpack_require__(1);
var parse = __webpack_require__(7);
module.exports = {
createNode: function (options) {
return new Node(options);
},
parse: parse
};
/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
/**
* @param {string} type
* @param {array|string} content
* @param {number} line
* @param {number} column
* @constructor
*/
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var Node = (function () {
function Node(options) {
_classCallCheck(this, Node);
this.type = options.type;
this.content = options.content;
this.syntax = options.syntax;
if (options.start) this.start = options.start;
if (options.end) this.end = options.end;
}
/**
* @param {String} type Node type
* @return {Boolean} Whether there is a child node of given type
*/
Node.prototype.contains = function contains(type) {
return this.content.some(function (node) {
return node.type === type;
});
};
/**
* @param {String} type Node type
* @param {Function} callback Function to call for every found node
*/
Node.prototype.eachFor = function eachFor(type, callback) {
if (!Array.isArray(this.content)) return;
if (typeof type !== 'string') {
callback = type;
type = null;
}
var l = this.content.length;
var breakLoop;
for (var i = l; i--;) {
if (breakLoop === null) break;
if (!type || this.content[i] && this.content[i].type === type) breakLoop = callback(this.content[i], i, this);
}
if (breakLoop === null) return null;
};
/**
* @param {String} type
* @return {?Node} First child node or `null` if nothing's been found.
*/
Node.prototype.first = function first(type) {
if (!Array.isArray(this.content)) return null;
if (!type) return this.content[0];
var i = 0;
var l = this.content.length;
for (; i < l; i++) {
if (this.content[i].type === type) return this.content[i];
}
return null;
};
/**
* @param {String} type Node type
* @param {Function} callback Function to call for every found node
*/
Node.prototype.forEach = function forEach(type, callback) {
if (!Array.isArray(this.content)) return;
if (typeof type !== 'string') {
callback = type;
type = null;
}
var i = 0;
var l = this.content.length;
var breakLoop;
for (; i < l; i++) {
if (breakLoop === null) break;
if (!type || this.content[i] && this.content[i].type === type) breakLoop = callback(this.content[i], i, this);
}
if (breakLoop === null) return null;
};
/**
* @param {Number} index
* @return {?Node}
*/
Node.prototype.get = function get(index) {
if (!Array.isArray(this.content)) return null;
var node = this.content[index];
return node ? node : null;
};
/**
* @param {Number} index
* @param {Node} node
*/
Node.prototype.insert = function insert(index, node) {
if (!Array.isArray(this.content)) return;
this.content.splice(index, 0, node);
};
/**
* @param {String} type
* @return {Boolean} Whether the node is of given type
*/
Node.prototype.is = function is(type) {
return this.type === type;
};
/**
* @param {String} type
* @return {?Node} Last child node or `null` if nothing's been found.
*/
Node.prototype.last = function last(type) {
if (!Array.isArray(this.content)) return null;
var i = this.content.length - 1;
if (!type) return this.content[i];
for (;; i--) {
if (this.content[i].type === type) return this.content[i];
}
return null;
};
/**
* Number of child nodes.
* @type {number}
*/
/**
* @param {Number} index
* @return {Node}
*/
Node.prototype.removeChild = function removeChild(index) {
if (!Array.isArray(this.content)) return;
var removedChild = this.content.splice(index, 1);
return removedChild;
};
Node.prototype.toJson = function toJson() {
return JSON.stringify(this, false, 2);
};
Node.prototype.toString = function toString() {
var stringify = undefined;
try {
stringify = __webpack_require__(2)("./" + this.syntax + '/stringify');
} catch (e) {
var message = 'Syntax "' + this.syntax + '" is not supported yet, sorry';
return console.error(message);
}
return stringify(this);
};
/**
* @param {Function} callback
*/
Node.prototype.traverse = function traverse(callback, index) {
var level = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2];
var parent = arguments.length <= 3 || arguments[3] === undefined ? null : arguments[3];
var breakLoop;
var x;
level++;
callback(this, index, parent, level);
if (!Array.isArray(this.content)) return;
for (var i = 0, l = this.content.length; i < l; i++) {
breakLoop = this.content[i].traverse(callback, i, level, this);
if (breakLoop === null) break;
// If some nodes were removed or added:
if (x = this.content.length - l) {
l += x;
i += x;
}
}
if (breakLoop === null) return null;
};
Node.prototype.traverseByType = function traverseByType(type, callback) {
this.traverse(function (node) {
if (node.type === type) callback.apply(node, arguments);
});
};
Node.prototype.traverseByTypes = function traverseByTypes(types, callback) {
this.traverse(function (node) {
if (types.indexOf(node.type) !== -1) callback.apply(node, arguments);
});
};
_createClass(Node, [{
key: 'length',
get: function () {
if (!Array.isArray(this.content)) return 0;
return this.content.length;
}
}]);
return Node;
})();
module.exports = Node;
/***/ },
/* 2 */
/***/ function(module, exports, __webpack_require__) {
var map = {
"./css/stringify": 3,
"./less/stringify": 4,
"./sass/stringify": 5,
"./scss/stringify": 6
};
function webpackContext(req) {
return __webpack_require__(webpackContextResolve(req));
};
function webpackContextResolve(req) {
return map[req] || (function() { throw new Error("Cannot find module '" + req + "'.") }());
};
webpackContext.keys = function webpackContextKeys() {
return Object.keys(map);
};
webpackContext.resolve = webpackContextResolve;
module.exports = webpackContext;
webpackContext.id = 2;
/***/ },
/* 3 */
/***/ function(module, exports) {
// jscs:disable maximumLineLength
'use strict';
module.exports = function stringify(tree) {
// TODO: Better error message
if (!tree) throw new Error('We need tree to translate');
function _t(tree) {
var type = tree.type;
if (_unique[type]) return _unique[type](tree);
if (typeof tree.content === 'string') return tree.content;
if (Array.isArray(tree.content)) return _composite(tree.content);
return '';
}
function _composite(t, i) {
if (!t) return '';
var s = '';
i = i || 0;
for (; i < t.length; i++) s += _t(t[i]);
return s;
}
var _unique = {
'arguments': function (t) {
return '(' + _composite(t.content) + ')';
},
'atkeyword': function (t) {
return '@' + _composite(t.content);
},
'attributeSelector': function (t) {
return '[' + _composite(t.content) + ']';
},
'block': function (t) {
return '{' + _composite(t.content) + '}';
},
'brackets': function (t) {
return '[' + _composite(t.content) + ']';
},
'class': function (t) {
return '.' + _composite(t.content);
},
'color': function (t) {
return '#' + t.content;
},
'expression': function (t) {
return 'expression(' + t.content + ')';
},
'id': function (t) {
return '#' + _composite(t.content);
},
'multilineComment': function (t) {
return '/*' + t.content + '*/';
},
'nthSelector': function (t) {
return ':' + _t(t.content[0]) + '(' + _composite(t.content.slice(1)) + ')';
},
'parentheses': function (t) {
return '(' + _composite(t.content) + ')';
},
'percentage': function (t) {
return _composite(t.content) + '%';
},
'pseudoClass': function (t) {
return ':' + _composite(t.content);
},
'pseudoElement': function (t) {
return '::' + _composite(t.content);
},
'uri': function (t) {
return 'url(' + _composite(t.content) + ')';
}
};
return _t(tree);
};
/***/ },
/* 4 */
/***/ function(module, exports) {
// jscs:disable maximumLineLength
'use strict';
module.exports = function stringify(tree) {
// TODO: Better error message
if (!tree) throw new Error('We need tree to translate');
function _t(tree) {
var type = tree.type;
if (_unique[type]) return _unique[type](tree);
if (typeof tree.content === 'string') return tree.content;
if (Array.isArray(tree.content)) return _composite(tree.content);
return '';
}
function _composite(t, i) {
if (!t) return '';
var s = '';
i = i || 0;
for (; i < t.length; i++) s += _t(t[i]);
return s;
}
var _unique = {
'arguments': function (t) {
return '(' + _composite(t.content) + ')';
},
'atkeyword': function (t) {
return '@' + _composite(t.content);
},
'attributeSelector': function (t) {
return '[' + _composite(t.content) + ']';
},
'block': function (t) {
return '{' + _composite(t.content) + '}';
},
'brackets': function (t) {
return '[' + _composite(t.content) + ']';
},
'class': function (t) {
return '.' + _composite(t.content);
},
'color': function (t) {
return '#' + t.content;
},
'escapedString': function (t) {
return '~' + t.content;
},
'expression': function (t) {
return 'expression(' + t.content + ')';
},
'id': function (t) {
return '#' + _composite(t.content);
},
'interpolatedVariable': function (t) {
return '@{' + _composite(t.content) + '}';
},
'multilineComment': function (t) {
return '/*' + t.content + '*/';
},
'nthSelector': function (t) {
return ':' + _t(t.content[0]) + '(' + _composite(t.content.slice(1)) + ')';
},
'parentheses': function (t) {
return '(' + _composite(t.content) + ')';
},
'percentage': function (t) {
return _composite(t.content) + '%';
},
'pseudoClass': function (t) {
return ':' + _composite(t.content);
},
'pseudoElement': function (t) {
return '::' + _composite(t.content);
},
'singlelineComment': function (t) {
return '/' + '/' + t.content;
},
'uri': function (t) {
return 'url(' + _composite(t.content) + ')';
},
'variable': function (t) {
return '@' + _composite(t.content);
},
'variablesList': function (t) {
return _composite(t.content) + '...';
}
};
return _t(tree);
};
/***/ },
/* 5 */
/***/ function(module, exports) {
// jscs:disable maximumLineLength
'use strict';
module.exports = function stringify(tree) {
// TODO: Better error message
if (!tree) throw new Error('We need tree to translate');
function _t(tree) {
var type = tree.type;
if (_unique[type]) return _unique[type](tree);
if (typeof tree.content === 'string') return tree.content;
if (Array.isArray(tree.content)) return _composite(tree.content);
return '';
}
function _composite(t, i) {
if (!t) return '';
var s = '';
i = i || 0;
for (; i < t.length; i++) s += _t(t[i]);
return s;
}
var _unique = {
'arguments': function (t) {
return '(' + _composite(t.content) + ')';
},
'atkeyword': function (t) {
return '@' + _composite(t.content);
},
'attributeSelector': function (t) {
return '[' + _composite(t.content) + ']';
},
'block': function (t) {
return _composite(t.content);
},
'brackets': function (t) {
return '[' + _composite(t.content) + ']';
},
'class': function (t) {
return '.' + _composite(t.content);
},
'color': function (t) {
return '#' + t.content;
},
'expression': function (t) {
return 'expression(' + t.content + ')';
},
'id': function (t) {
return '#' + _composite(t.content);
},
'interpolation': function (t) {
return '#{' + _composite(t.content) + '}';
},
'multilineComment': function (t) {
return '/*' + t.content;
},
'nthSelector': function (t) {
return ':' + _t(t.content[0]) + '(' + _composite(t.content.slice(1)) + ')';
},
'parentheses': function (t) {
return '(' + _composite(t.content) + ')';
},
'percentage': function (t) {
return _composite(t.content) + '%';
},
'placeholder': function (t) {
return '%' + _composite(t.content);
},
'pseudoClass': function (t) {
return ':' + _composite(t.content);
},
'pseudoElement': function (t) {
return '::' + _composite(t.content);
},
'singlelineComment': function (t) {
return '/' + '/' + t.content;
},
'uri': function (t) {
return 'url(' + _composite(t.content) + ')';
},
'variable': function (t) {
return '$' + _composite(t.content);
},
'variablesList': function (t) {
return _composite(t.content) + '...';
}
};
return _t(tree);
};
/***/ },
/* 6 */
/***/ function(module, exports) {
// jscs:disable maximumLineLength
'use strict';
module.exports = function stringify(tree) {
// TODO: Better error message
if (!tree) throw new Error('We need tree to translate');
function _t(tree) {
var type = tree.type;
if (_unique[type]) return _unique[type](tree);
if (typeof tree.content === 'string') return tree.content;
if (Array.isArray(tree.content)) return _composite(tree.content);
return '';
}
function _composite(t, i) {
if (!t) return '';
var s = '';
i = i || 0;
for (; i < t.length; i++) s += _t(t[i]);
return s;
}
var _unique = {
'arguments': function (t) {
return '(' + _composite(t.content) + ')';
},
'atkeyword': function (t) {
return '@' + _composite(t.content);
},
'attributeSelector': function (t) {
return '[' + _composite(t.content) + ']';
},
'block': function (t) {
return '{' + _composite(t.content) + '}';
},
'brackets': function (t) {
return '[' + _composite(t.content) + ']';
},
'class': function (t) {
return '.' + _composite(t.content);
},
'color': function (t) {
return '#' + t.content;
},
'expression': function (t) {
return 'expression(' + t.content + ')';
},
'id': function (t) {
return '#' + _composite(t.content);
},
'interpolation': function (t) {
return '#{' + _composite(t.content) + '}';
},
'multilineComment': function (t) {
return '/*' + t.content + '*/';
},
'nthSelector': function (t) {
return ':' + _t(t.content[0]) + '(' + _composite(t.content.slice(1)) + ')';
},
'parentheses': function (t) {
return '(' + _composite(t.content) + ')';
},
'percentage': function (t) {
return _composite(t.content) + '%';
},
'placeholder': function (t) {
return '%' + _composite(t.content);
},
'pseudoClass': function (t) {
return ':' + _composite(t.content);
},
'pseudoElement': function (t) {
return '::' + _composite(t.content);
},
'singlelineComment': function (t) {
return '/' + '/' + t.content;
},
'uri': function (t) {
return 'url(' + _composite(t.content) + ')';
},
'variable': function (t) {
return '$' + _composite(t.content);
},
'variablesList': function (t) {
return _composite(t.content) + '...';
}
};
return _t(tree);
};
/***/ },
/* 7 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
var ParsingError = __webpack_require__(8);
var syntaxes = __webpack_require__(10);
var isInteger = Number.isInteger || function (value) {
return typeof value === 'number' && Math.floor(value) === value;
};
/**
* @param {String} css
* @param {Object} options
* @return {Object} AST
*/
function parser(css, options) {
if (typeof css !== 'string') throw new Error('Please, pass a string to parse');else if (!css) return __webpack_require__(29)();
var syntax = options && options.syntax || 'css';
var context = options && options.context || 'stylesheet';
var tabSize = options && options.tabSize;
if (!isInteger(tabSize) || tabSize < 1) tabSize = 1;
var syntaxParser = undefined;
if (syntaxes[syntax]) {
syntaxParser = syntaxes[syntax];
} else {
syntaxParser = syntaxes;
}
if (!syntaxParser) {
var message = 'Syntax "' + syntax + '" is not supported yet, sorry';
return console.error(message);
}
var getTokens = syntaxParser.tokenizer;
var mark = syntaxParser.mark;
var parse = syntaxParser.parse;
var tokens = getTokens(css, tabSize);
mark(tokens);
var ast;
try {
ast = parse(tokens, context);
} catch (e) {
if (!e.syntax) throw e;
throw new ParsingError(e, css);
}
return ast;
}
module.exports = parser;
/***/ },
/* 8 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
var parserPackage = __webpack_require__(9);
/**
* @param {Error} e
* @param {String} css
*/
function ParsingError(e, css) {
this.line = e.line;
this.syntax = e.syntax;
this.css_ = css;
}
ParsingError.prototype = Object.defineProperties({
/**
* @type {String}
* @private
*/
customMessage_: '',
/**
* @type {Number}
*/
line: null,
/**
* @type {String}
*/
name: 'Parsing error',
/**
* @type {String}
*/
syntax: null,
/**
* @type {String}
*/
version: parserPackage.version,
/**
* @return {String}
*/
toString: function () {
return [this.name + ': ' + this.message, '', this.context, '', 'Syntax: ' + this.syntax, 'Gonzales PE version: ' + this.version].join('\n');
}
}, {
context: { /**
* @type {String}
*/
get: function () {
var LINES_AROUND = 2;
var result = [];
var currentLineNumber = this.line;
var start = currentLineNumber - 1 - LINES_AROUND;
var end = currentLineNumber + LINES_AROUND;
var lines = this.css_.split(/\r\n|\r|\n/);
for (var i = start; i < end; i++) {
var line = lines[i];
if (!line) continue;
var ln = i + 1;
var mark = ln === currentLineNumber ? '*' : ' ';
result.push(ln + mark + '| ' + line);
}
return result.join('\n');
},
configurable: true,
enumerable: true
},
message: {
/**
* @type {String}
*/
get: function () {
if (this.customMessage_) {
return this.customMessage_;
} else {
var message = 'Please check validity of the block';
if (typeof this.line === 'number') message += ' starting from line #' + this.line;
return message;
}
},
set: function (message) {
this.customMessage_ = message;
},
configurable: true,
enumerable: true
}
});
module.exports = ParsingError;
/***/ },
/* 9 */
/***/ function(module, exports) {
module.exports = {
"name": "gonzales-pe",
"description": "Gonzales Preprocessor Edition (fast CSS parser)",
"version": "3.3.0",
"homepage": "http://github.com/tonyganch/gonzales-pe",
"bugs": "http://github.com/tonyganch/gonzales-pe/issues",
"license": "MIT",
"author": {
"name": "Tony Ganch",
"email": "tonyganch+github@gmail.com",
"url": "http://tonyganch.com"
},
"main": "./lib/gonzales",
"repository": {
"type": "git",
"url": "http://github.com/tonyganch/gonzales-pe.git"
},
"scripts": {
"autofix-tests": "./scripts/build.sh && ./scripts/autofix-tests.sh",
"build": "./scripts/build.sh",
"init": "./scripts/init.sh",
"log": "./scripts/log.sh",
"prepublish": "./scripts/prepublish.sh",
"postpublish": "./scripts/postpublish.sh",
"test": "./scripts/build.sh && ./scripts/test.sh",
"watch": "./scripts/watch.sh"
},
"bin": {
"gonzales": "./bin/gonzales.js"
},
"dependencies": {
"minimist": "1.1.x"
},
"devDependencies": {
"babel-loader": "^5.3.2",
"coffee-script": "~1.7.1",
"jscs": "2.1.0",
"jshint": "2.8.0",
"json-loader": "^0.5.3",
"mocha": "2.2.x",
"webpack": "^1.12.2"
},
"engines": {
"node": ">=0.6.0"
}
};
/***/ },
/* 10 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
module.exports = {
css: __webpack_require__(11),
less: __webpack_require__(16),
sass: __webpack_require__(21),
scss: __webpack_require__(25)
};
/***/ },
/* 11 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
exports['default'] = {
mark: __webpack_require__(12),
parse: __webpack_require__(14),
stringify: __webpack_require__(3),
tokenizer: __webpack_require__(15)
};
module.exports = exports['default'];
/***/ },
/* 12 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
var NodeType = __webpack_require__(13);
/**
* Mark whitespaces and comments
* @param {Array} tokens
*/
function markSpacesAndComments(tokens) {
var tokensLength = tokens.length;
var spaces = [-1, -1];
var type; // Current token's type
// For every token in the token list, mark spaces and line breaks
// as spaces (set both `ws` and `sc` flags). Mark multiline comments
// with `sc` flag.
// If there are several spaces or tabs or line breaks or multiline
// comments in a row, group them: take the last one's index number
// and save it to the first token in the group as a reference:
// e.g., `ws_last = 7` for a group of whitespaces or `sc_last = 9`
// for a group of whitespaces and comments.
for (var i = 0; i < tokensLength; i++) {
type = tokens[i].type;
if (type === NodeType.SPACE) {
markSpace(tokens, i, spaces);
} else if (type === NodeType.MULTILINE_COMMENT) {
markComment(tokens, i, spaces);
} else {
markEndOfSpacesAndComments(tokens, i, spaces);
}
}
markEndOfSpacesAndComments(tokens, i, spaces);
}
function markSpace(tokens, i, spaces) {
var token = tokens[i];
token.ws = true;
token.sc = true;
if (spaces[0] === -1) spaces[0] = i;
if (spaces[1] === -1) spaces[1] = i;
}
function markComment(tokens, i, spaces) {
var ws = spaces[0];
tokens[i].sc = true;
if (ws !== -1) {
tokens[ws].ws_last = i - 1;
spaces[0] = -1;
}
}
function markEndOfSpacesAndComments(tokens, i, spaces) {
var ws = spaces[0];
var sc = spaces[1];
if (ws !== -1) {
tokens[ws].ws_last = i - 1;
spaces[0] = -1;
}
if (sc !== -1) {
tokens[sc].sc_last = i - 1;
spaces[1] = -1;
}
}
/**
* Pair brackets
* @param {Array} tokens
*/
function markBrackets(tokens) {
var tokensLength = tokens.length;
var ps = []; // Parentheses
var sbs = []; // Square brackets
var cbs = []; // Curly brackets
var t = undefined; // Current token
// For every token in the token list, if we meet an opening (left)
// bracket, push its index number to a corresponding array.
// If we then meet a closing (right) bracket, look at the corresponding
// array. If there are any elements (records about previously met
// left brackets), take a token of the last left bracket (take
// the last index number from the array and find a token with
// this index number) and save right bracket's index as a reference:
for (var i = 0; i < tokensLength; i++) {
t = tokens[i];
var type = t.type;
if (type === NodeType.LEFT_PARENTHESIS) {
ps.push(i);
} else if (type === NodeType.RIGHT_PARENTHESIS) {
if (ps.length) {
t.left = ps.pop();
tokens[t.left].right = i;
}
} else if (type === NodeType.LEFT_SQUARE_BRACKET) {
sbs.push(i);
} else if (type === NodeType.RIGHT_SQUARE_BRACKET) {
if (sbs.length) {
t.left = sbs.pop();
tokens[t.left].right = i;
}
} else if (type === NodeType.LEFT_CURLY_BRACKET) {
cbs.push(i);
} else if (type === NodeType.RIGHT_CURLY_BRACKET) {
if (cbs.length) {
t.left = cbs.pop();
tokens[t.left].right = i;
}
}
}
}
/**
* @param {Array} tokens
*/
function markTokens(tokens) {
// Mark paired brackets:
markBrackets(tokens);
// Mark whitespaces and comments:
markSpacesAndComments(tokens);
}
module.exports = markTokens;
/***/ },
/* 13 */
/***/ function(module, exports) {
'use strict';
/**
* List of all possible node types for all syntaxes.
* @enum {string}
*/
var NodeType = {
// Primitive nodes, can't be divided into smaller parts.
AMPERSAND: 'ampersand',
APOSTROPHE: 'apostrophe',
ASTERISK: 'asterisk',
CHARACTER: 'character',
CIRCUMFLEX_ACCENT: 'circumflexAccent',
COLON: 'colon',
COMMA: 'comma',
COMMERCIAL_AT: 'commercialAt',
DIGIT: 'digit',
EQUALS_SIGN: 'equalsSign',
EXCLAMATION_MARK: 'exclamationMark',
FULL_STOP: 'fullStop',
GREATER_THAN_SIGN: 'greaterThanSign',
HYPHEN_MINUS: 'hyphenMinus',
LEFT_CURLY_BRACKET: 'leftCurlyBracket',
LEFT_PARENTHESIS: 'leftParenthesis',
LEFT_SQUARE_BRACKET: 'leftSquareBracket',
LESS_THAN_SIGN: 'lessThanSign',
LOW_LINE: 'lowLine',
MULTILINE_COMMENT: 'multilineComment',
NEWLINE: 'newline',
NUMBER: 'number',
NUMBER_SIGN: 'numberSign',
PERCENT_SIGN: 'percentSign',
PLUS_SIGN: 'plusSign',
QUESTION_MARK: 'questionMark',
QUOTATION_MARK: 'quotationMark',
REVERSE_SOLIDUS: 'reverseSolidus',
RIGHT_CURLY_BRACKET: 'rightCurlyBracket',
RIGHT_PARENTHESIS: 'rightParenthesis',
RIGHT_SQUARE_BRACKET: 'rightSquareBracket',
SEMICOLON: 'semicolon',
SINGLELINE_COMMENT: 'singlelineComment',
SOLIDUS: 'solidus',
SPACE: 'space',
TILDE: 'tilde',
VERTICAL_LINE: 'verticalLine',
// Paired nodes, grouped by some trait.
BRACES: 'braces',
BRACKETS: 'brackets',
PARENTHESES: 'parentheses',
STRING: 'string',
// Compound nodes.
ARGUMENTS: 'arguments',
ATKEYWORD: 'atkeyword',
ATRULE: 'atrule',
ATTRIBUTE_SELECTOR: 'attributeSelector',
ATTRIBUTE_NAME: 'attributeName',
ATTRIBUTE_FLAGS: 'attributeFlags',
ATTRIBUTE_MATCH: 'attributeMatch',
ATTRIBUTE_VALUE: 'attributeValue',
BLOCK: 'block',
CLASS: 'class',
COLOR: 'color',
COMBINATOR: 'combinator',
CONDITION: 'condition',
CONDITIONAL_STATEMENT: 'conditionalStatement',
DECLARATION: 'declaration',
DECLARATION_DELIMITER: 'declarationDelimiter',
DEFAULT: 'default',
DELIMITER: 'delimiter',
DIMENSION: 'dimension',
ESCAPED_STRING: 'escapedString',
EXTEND: 'extend',
EXPRESSION: 'expression',
FUNCTION: 'function',
GLOBAL: 'global',
ID: 'id',
IDENT: 'ident',
IMPORTANT: 'important',
INCLUDE: 'include',
INTERPOLATION: 'interpolation',
INTERPOLATED_VARIABLE: 'interpolatedVariable',
KEYFRAMES_SELECTOR: 'keyframesSelector',
LOOP: 'loop',
MIXIN: 'mixin',
NAME_PREFIX: 'namePrefix',
NAMESPACE_PREFIX: 'namespacePrefix',
NAMESPACE_SEPARATOR: 'namespaceSeparator',
OPERATOR: 'operator',
OPTIONAL: 'optional',
PARENT_SELECTOR: 'parentSelector',
PARENT_SELECTOR_EXTENSION: 'parentSelectorExtension',
PERCENTAGE: 'percentage',
PLACEHOLDER: 'placeholder',
PROGID: 'progid',
PROPERTY: 'property',
PROPERTY_DELIMITER: 'propertyDelimiter',
PSEUDO_CLASS: 'pseudoClass',
PSEUDO_ELEMENT: 'pseudoElement',
RAW: 'raw',
RULESET: 'ruleset',
SELECTOR: 'selector',
STYLESHEET: 'stylesheet',
TYPE_SELECTOR: 'typeSelector',
URI: 'uri',
VALUE: 'value',
VARIABLE: 'variable',
VARIABLES_LIST: 'variablesList'
};
module.exports = NodeType;
/***/ },
/* 14 */
/***/ function(module, exports, __webpack_require__) {
// jscs:disable maximumLineLength
'use strict';
var Node = __webpack_require__(1);
var NodeType = __webpack_require__(13);
/**
* @type {Array}
*/
var tokens;
/**
* @type {Number}
*/
var tokensLength;
/**
* @type {Number}
*/
var pos;
var contexts = {
'atkeyword': function () {
return checkAtkeyword(pos) && getAtkeyword();
},
'atrule': function () {
return checkAtrule(pos) && getAtrule();
},
'block': function () {
return checkBlock(pos) && getBlock();
},
'brackets': function () {
return checkBrackets(pos) && getBrackets();
},
'combinator': function () {
return checkCombinator(pos) && getCombinator();
},
'commentML': function () {
return checkCommentML(pos) && getCommentML();
},
'declaration': function () {
return checkDeclaration(pos) && getDeclaration();
},
'declDelim': function () {
return checkDeclDelim(pos) && getDeclDelim();
},
'delim': function () {
return checkDelim(pos) && getDelim();
},
'dimension': function () {
return checkDimension(pos) && getDimension();
},
'expression': function () {
return checkExpression(pos) && getExpression();
},
'function': function () {
return checkFunction(pos) && getFunction();
},
'ident': function () {
return checkIdent(pos) && getIdent();
},
'important': function () {
return checkImportant(pos) && getImportant();
},
'namespace': function () {
return checkNamespace(pos) && getNamespace();
},
'number': function () {
return checkNumber(pos) && getNumber();
},
'operator': function () {
return checkOperator(pos) && getOperator();
},
'parentheses': function () {
return checkParentheses(pos) && getParentheses();
},
'percentage': function () {
return checkPercentage(pos) && getPercentage();
},
'progid': function () {
return checkProgid(pos) && getProgid();
},
'property': function () {
return checkProperty(pos) && getProperty();
},
'propertyDelim': function () {
return checkPropertyDelim(pos) && getPropertyDelim();
},
'pseudoc': function () {
return checkPseudoc(pos) && getPseudoc();
},
'pseudoe': function () {
return checkPseudoe(pos) && getPseudoe();
},
'ruleset': function () {
return checkRuleset(pos) && getRuleset();
},
's': function () {
return checkS(pos) && getS();
},
'selector': function () {
return checkSelector(pos) && getSelector();
},
'shash': function () {
return checkShash(pos) && getShash();
},
'string': function () {
return checkString(pos) && getString();
},
'stylesheet': function () {
return checkStylesheet(pos) && getStylesheet();
},
'unary': function () {
return checkUnary(pos) && getUnary();
},
'uri': function () {
return checkUri(pos) && getUri();
},
'value': function () {
return checkValue(pos) && getValue();
},
'vhash': function () {
return checkVhash(pos) && getVhash();
}
};
/**
* @param {Object} exclude
* @param {Number} i Token's index number
* @return {Number}
*/
function checkExcluding(exclude, i) {
var start = i;
while (i < tokensLength) {
if (exclude[tokens[i++].type]) break;
}
return i - start - 2;
}
/**
* @param {Number} start
* @param {Number} finish
* @return {String}
*/
function joinValues(start, finish) {
var s = '';
for (var i = start; i < finish + 1; i++) {
s += tokens[i].toString();
}
return s;
}
/**
* @param {Number} start
* @param {Number} num
* @return {String}
*/
function joinValues2(start, num) {
if (start + num - 1 >= tokensLength) return;
var s = '';
for (var i = 0; i < num; i++) {
s += tokens[start + i].toString();
}
return s;
}
function getLastPosition(content, line, column, colOffset) {
return typeof content === 'string' ? getLastPositionForString(content, line, column, colOffset) : getLastPositionForArray(content, line, column, colOffset);
}
function getLastPositionForString(content, line, column, colOffset) {
var position = [];
if (!content) {
position = [line, column];
if (colOffset) position[1] += colOffset - 1;
return position;
}
var lastLinebreak = content.lastIndexOf('\n');
var endsWithLinebreak = lastLinebreak === content.length - 1;
var splitContent = content.split('\n');
var linebreaksCount = splitContent.length - 1;
var prevLinebreak = linebreaksCount === 0 || linebreaksCount === 1 ? -1 : content.length - splitContent[linebreaksCount - 1].length - 2;
// Line:
var offset = endsWithLinebreak ? linebreaksCount - 1 : linebreaksCount;
position[0] = line + offset;
// Column:
if (endsWithLinebreak) {
offset = prevLinebreak !== -1 ? content.length - prevLinebreak : content.length - 1;
} else {
offset = linebreaksCount !== 0 ? content.length - lastLinebreak - column - 1 : content.length - 1;
}
position[1] = column + offset;
if (!colOffset) return position;
if (endsWithLinebreak) {
position[0]++;
position[1] = colOffset;
} else {
position[1] += colOffset;
}
return position;
}
function getLastPositionForArray(content, line, column, colOffset) {
var position;
if (content.length === 0) {
position = [line, column];
} else {
var c = content[content.length - 1];
if (c.hasOwnProperty('end')) {
position = [c.end.line, c.end.column];
} else {
position = getLastPosition(c.content, line, column);
}
}
if (!colOffset) return position;
if (tokens[pos - 1].type !== 'Newline') {
position[1] += colOffset;
} else {
position[0]++;
position[1] = 1;
}
return position;
}
function newNode(type, content, line, column, end) {
if (!end) end = getLastPosition(content, line, column);
return new Node({
type: type,
content: content,
start: {
line: line,
column: column
},
end: {
line: end[0],
column: end[1]
},
syntax: 'css'
});
}
/**
* @param {Number} i Token's index number
* @return {Number}
*/
function checkAny(i) {
var l;
if (l = checkBrackets(i)) tokens[i].any_child = 1;else if (l = checkParentheses(i)) tokens[i].any_child = 2;else if (l = checkString(i)) tokens[i].any_child = 3;else if (l = checkPercentage(i)) tokens[i].any_child = 4;else if (l = checkDimension(i)) tokens[i].any_child = 5;else if (l = checkNumber(i)) tokens[i].any_child = 6;else if (l = checkUri(i)) tokens[i].any_child = 7;else if (l = checkExpression(i)) tokens[i].any_child = 8;else if (l = checkFunction(i)) tokens[i].any_child = 9;else if (l = checkIdent(i)) tokens[i].any_child = 10;else if (l = checkClass(i)) tokens[i].any_child = 11;else if (l = checkUnary(i)) tokens[i].any_child = 12;
return l;
}
/**
* @return {Node}
*/
function getAny() {
var childType = tokens[pos].any_child;
if (childType === 1) return getBrackets();else if (childType === 2) return getParentheses();else if (childType === 3) return getString();else if (childType === 4) return getPercentage();else if (childType === 5) return getDimension();else if (childType === 6) return getNumber();else if (childType === 7) return getUri();else if (childType === 8) return getExpression();else if (childType === 9) return getFunction();else if (childType === 10) return getIdent();else if (childType === 11) return getClass();else if (childType === 12) return getUnary();
}
/**
* Check if token is part of an @-word (e.g. `@import`, `@include`)
* @param {Number} i Token's index number
* @return {Number}
*/
function checkAtkeyword(i) {
var l;
// Check that token is `@`:
if (i >= tokensLength || tokens[i++].type !== NodeType.COMMERCIAL_AT) return 0;
return (l = checkIdent(i)) ? l + 1 : 0;
}
/**
* Get node with @-word
* @return {Node}
*/
function getAtkeyword() {
var type = NodeType.ATKEYWORD;
var token = tokens[pos];
var line = token.start.line;
var column = token.start.column;
var content = [];
pos++;
content.push(getIdent());
return newNode(type, content, line, column);
}
/**
* Check if token is a part of an @-rule
* @param {Number} i Token's index number
* @return {Number} Length of @-rule
*/
function checkAtrule(i) {
var l;
if (i >= tokensLength) return 0;
// If token already has a record of being part of an @-rule,
// return the @-rule's length:
if (tokens[i].atrule_l !== undefined) return tokens[i].atrule_l;
// If token is part of an @-rule, save the rule's type to token:
if (l = checkKeyframesRule(i)) tokens[i].atrule_type = 4;else if (l = checkAtruler(i)) tokens[i].atrule_type = 1; // @-rule with ruleset
else if (l = checkAtruleb(i)) tokens[i].atrule_type = 2; // Block @-rule
else if (l = checkAtrules(i)) tokens[i].atrule_type = 3; // Single-line @-rule
else return 0;
// If token is part of an @-rule, save the rule's length to token:
tokens[i].atrule_l = l;
return l;
}
/**
* Get node with @-rule
* @return {Node}
*/
function getAtrule() {
switch (tokens[pos].atrule_type) {
case 1:
return getAtruler(); // @-rule with ruleset
case 2:
return getAtruleb(); // Block @-rule
case 3:
return getAtrules(); // Single-line @-rule
case 4:
return getKeyframesRule();
}
}
/**
* Check if token is part of a block @-rule
* @param {Number} i Token's index number
* @return {Number} Length of the @-rule
*/
function checkAtruleb(i) {
var start = i;
var l = undefined;
if (i >= tokensLength) return 0;
if (l = checkAtkeyword(i)) i += l;else return 0;
if (l = checkTsets(i)) i += l;
if (l = checkBlock(i)) i += l;else return 0;
return i - start;
}
/**
* Get node with a block @-rule
* @return {Node}
*/
function getAtruleb() {
var type = NodeType.ATRULE;
var token = tokens[pos];
var line = token.start.line;
var column = token.start.column;
var content = [getAtkeyword()].concat(getTsets()).concat([getBlock()]);
return newNode(type, content, line, column);
}
/**
* Check if token is part of an @-rule with ruleset
* @param {Number} i Token's index number
* @return {Number} Length of the @-rule
*/
function checkAtruler(i) {
var start = i;
var l = undefined;
if (i >= tokensLength) return 0;
if (l = checkAtkeyword(i)) i += l;else return 0;
if (l = checkTsets(i)) i += l;
if (i < tokensLength && tokens[i].type === NodeType.LEFT_CURLY_BRACKET) i++;else return 0;
if (l = checkAtrulers(i)) i += l;
if (i < tokensLength && tokens[i].type === NodeType.RIGHT_CURLY_BRACKET) i++;else return 0;
return i - start;
}
/**
* Get node with an @-rule with ruleset
* @return {Node}
*/
function getAtruler() {
var type = NodeType.ATRULE;
var token = tokens[pos];
var line = token.start.line;
var column = token.start.column;
var content = [getAtkeyword()];
content = content.concat(getTsets());
content.push(getAtrulers());
return newNode(type, content, line, column);
}
/**
* @param {Number} i Token's index number
* @return {Number}
*/
function checkAtrulers(i) {
var start = i;
var l = undefined;
if (i >= tokensLength) return 0;
if (l = checkSC(i)) i += l;
while (i < tokensLength) {
if (l = checkSC(i)) tokens[i].atrulers_child = 1;else if (l = checkAtrule(i)) tokens[i].atrulers_child = 2;else if (l = checkRuleset(i)) tokens[i].atrulers_child = 3;else break;
i += l;
}
tokens[i].atrulers_end = 1;
if (l = checkSC(i)) i += l;
return i - start;
}
/**
* @return {Node}
*/
function getAtrulers() {
var type = NodeType.BLOCK;
var token = tokens[pos++];
var line = token.start.line;
var column = token.start.column;
var content = getSC();
while (!tokens[pos].atrulers_end) {
var childType = tokens[pos].atrulers_child;
if (childType === 1) content = content.concat(getSC());else if (childType === 2) content.push(getAtrule());else if (childType === 3) content.push(getRuleset());
}
content = content.concat(getSC());
var end = getLastPosition(content, line, column, 1);
pos++;
return newNode(type, content, line, column, end);
}
/**
* @param {Number} i Token's index number
* @return {Number}
*/
function checkAtrules(i) {
var start = i;
var l = undefined;
if (i >= tokensLength) return 0;
if (l = checkAtkeyword(i)) i += l;else return 0;
if (l = checkTsets(i)) i += l;
return i - start;
}
/**
* @return {Node}
*/
function getAtrules() {
var type = NodeType.ATRULE;
var token = tokens[pos];
var line = token.start.line;
var column = token.start.column;
var content = [getAtkeyword()].concat(getTsets());
return newNode(type, content, line, column);
}
/**
* Check if token is part of a block (e.g. `{...}`).
* @param {Number} i Token's index number
* @return {Number} Length of the block
*/
function checkBlock(i) {
return i < tokensLength && tokens[i].type === NodeType.LEFT_CURLY_BRACKET ? tokens[i].right - i + 1 : 0;
}
/**
* Get node with a block
* @return {Node}
*/
function getBlock() {
var type = NodeType.BLOCK;
var token = tokens[pos];
var line = token.start.line;
var column = token.start.column;
var end = tokens[pos++].right;
var content = [];
while (pos < end) {
if (checkBlockdecl(pos)) content = content.concat(getBlockdecl());else content.push(tokens[pos++]);
}
var end_ = getLastPosition(content, line, column, 1);
pos = end + 1;
return newNode(type, content, line, column, end_);
}
/**
* Check if token is part of a declaration (property-value pair)
* @param {Number} i Token's index number
* @return {Number} Length of the declaration
*/
function checkBlockdecl(i) {
var l;
if (i >= tokensLength) return 0;
if (l = checkBlockdecl1(i)) tokens[i].bd_type = 1;else if (l = checkBlockdecl2(i)) tokens[i].bd_type = 2;else if (l = checkBlockdecl3(i)) tokens[i].bd_type = 3;else if (l = checkBlockdecl4(i)) tokens[i].bd_type = 4;else return 0;
return l;
}
/**
* @return {Array}
*/
function getBlockdecl() {
switch (tokens[pos].bd_type) {
case 1:
return getBlockdecl1();
case 2:
return getBlockdecl2();
case 3:
return getBlockdecl3();
case 4:
return getBlockdecl4();
}
}
/**
* @param {Number} i Token's index number
* @return {Number}
*/
function checkBlockdecl1(i) {
var start = i;
var l = undefined;
if (l = checkSC(i)) i += l;
if (l = checkDeclaration(i)) tokens[i].bd_kind = 1;else if (l = checkAtrule(i)) tokens[i].bd_kind = 2;else return 0;
i += l;
if (l = checkSC(i)) i += l;
if (i < tokensLength && (l = checkDeclDelim(i))) i += l;else return 0;
if (l = checkSC(i)) i += l;else return 0;
return i - start;
}
/**
* @return {Array}
*/
function getBlockdecl1() {
var sc = getSC();
var x = undefined;
switch (tokens[pos].bd_kind) {
case 1:
x = getDeclaration();
break;
case 2:
x = getAtrule();
break;
}
return sc.concat([x]).concat(getSC()).concat([getDeclDelim()]).concat(getSC());
}
/**
* @param {Number} i Token's index number
* @return {Number}
*/
function checkBlockdecl2(i) {
var start = i;
var l = undefined;
if (l = checkSC(i)) i += l;
if (l = checkDeclaration(i)) tokens[i].bd_kind = 1;else if (l = checkAtrule(i)) tokens[i].bd_kind = 2;else return 0;
i += l;
if (l = checkSC(i)) i += l;
return i - start;
}
/**
* @return {Array}
*/
function getBlockdecl2() {
var sc = getSC();
var x = undefined;
switch (tokens[pos].bd_kind) {
case 1:
x = getDeclaration();
break;
case 2:
x = getAtrule();
break;
}
return sc.concat([x]).concat(getSC());
}
/**
* @param {Number} i Token's index number
* @return {Number}
*/
function checkBlockdecl3(i) {
var start = i;
var l = undefined;
if (l = checkSC(i)) i += l;
if (l = checkDeclDelim(i)) i += l;else return 0;
if (l = checkSC(i)) i += l;
return i - start;
}
/**
* @return {Array}
*/
function getBlockdecl3() {
return getSC().concat([getDeclDelim()]).concat(getSC());
}
/**
* @param {Number} i Token's index number
* @return {Number}
*/
function checkBlockdecl4(i) {
return checkSC(i);
}
/**
* @return {Array}
*/
function getBlockdecl4() {
return getSC();
}
/**
* Check if token is part of text inside square brackets, e.g. `[1]`
* @param {Number} i Token's index number
* @return {Number}
*/
function checkBrackets(i) {
if (i >= tokensLength || tokens[i].type !== NodeType.LEFT_SQUARE_BRACKET) return 0;
return tokens[i].right - i + 1;
}
/**
* Get node with text inside square brackets, e.g. `[1]`
* @return {Node}
*/
function getBrackets() {
var type = NodeType.BRACKETS;
var token = tokens[pos];
var line = token.start.line;
var column = token.start.column;
pos++;
var tsets = getTsets();
var end = getLastPosition(tsets, line, column, 1);
pos++;
return newNode(type, tsets, line, column, end);
}
/**
* Check if token is part of a class selector (e.g. `.abc`)
* @param {Number} i Token's index number
* @return {Number} Length of the class selector
*/
function checkClass(i) {
var l;
if (i >= tokensLength) return 0;
if (tokens[i].class_l) return tokens[i].class_l;
if (tokens[i++].type === NodeType.FULL_STOP && (l = checkIdent(i))) {
tokens[i].class_l = l + 1;
return l + 1;
}
return 0;
}
/**
* Get node with a class selector
* @return {Node}
*/
function getClass() {
var type = NodeType.CLASS;
var token = tokens[pos++];
var line = token.start.line;
var column = token.start.column;
var content = [getIdent()];
return newNode(type, content, line, column);
}
function checkCombinator(i) {
if (i >= tokensLength) return 0;
var l = undefined;
if (l = checkCombinator1(i)) tokens[i].combinatorType = 1;else if (l = checkCombinator2(i)) tokens[i].combinatorType = 2;else if (l = checkCombinator3(i)) tokens[i].combinatorType = 3;
return l;
}
function getCombinator() {
var type = tokens[pos].combinatorType;
if (type === 1) return getCombinator1();
if (type === 2) return getCombinator2();
if (type === 3) return getCombinator3();
}
/**
* (1) `||`
*/
function checkCombinator1(i) {
if (tokens[i].type === NodeType.VERTICAL_LINE && tokens[i + 1].type === NodeType.VERTICAL_LINE) return 2;else return 0;
}
function getCombinator1()