1
0
mirror of https://github.com/thangisme/notes.git synced 2024-11-01 03:27:29 -04:00
notes/node_modules/postcss-scss/lib/scss-parser.js

198 lines
20 KiB
JavaScript
Raw Normal View History

2017-03-09 13:16:08 -05:00
'use strict';
exports.__esModule = true;
var _comment = require('postcss/lib/comment');
var _comment2 = _interopRequireDefault(_comment);
var _parser = require('postcss/lib/parser');
var _parser2 = _interopRequireDefault(_parser);
var _nestedDeclaration = require('./nested-declaration');
var _nestedDeclaration2 = _interopRequireDefault(_nestedDeclaration);
var _scssTokenize = require('./scss-tokenize');
var _scssTokenize2 = _interopRequireDefault(_scssTokenize);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var ScssParser = function (_Parser) {
_inherits(ScssParser, _Parser);
function ScssParser() {
_classCallCheck(this, ScssParser);
return _possibleConstructorReturn(this, _Parser.apply(this, arguments));
}
ScssParser.prototype.tokenize = function tokenize() {
this.tokens = (0, _scssTokenize2.default)(this.input);
};
ScssParser.prototype.rule = function rule(tokens) {
var withColon = false;
var brackets = 0;
var value = '';
for (var _iterator = tokens, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var _i2 = _ref;
if (withColon) {
if (_i2[0] !== 'comment' && _i2[0] !== '{') {
value += _i2[1];
}
} else if (_i2[0] === 'space' && _i2[1].indexOf('\n') !== -1) {
break;
} else if (_i2[0] === '(') {
brackets += 1;
} else if (_i2[0] === ')') {
brackets -= 1;
} else if (brackets === 0 && _i2[0] === ':') {
withColon = true;
}
}
if (!withColon || value.trim() === '' || /^[a-zA-Z-:#]/.test(value)) {
_Parser.prototype.rule.call(this, tokens);
} else {
tokens.pop();
var node = new _nestedDeclaration2.default();
this.init(node);
var last = tokens[tokens.length - 1];
if (last[4]) {
node.source.end = { line: last[4], column: last[5] };
} else {
node.source.end = { line: last[2], column: last[3] };
}
while (tokens[0][0] !== 'word') {
node.raws.before += tokens.shift()[1];
}
node.source.start = { line: tokens[0][2], column: tokens[0][3] };
node.prop = '';
while (tokens.length) {
var type = tokens[0][0];
if (type === ':' || type === 'space' || type === 'comment') {
break;
}
node.prop += tokens.shift()[1];
}
node.raws.between = '';
var token = void 0;
while (tokens.length) {
token = tokens.shift();
if (token[0] === ':') {
node.raws.between += token[1];
break;
} else {
node.raws.between += token[1];
}
}
if (node.prop[0] === '_' || node.prop[0] === '*') {
node.raws.before += node.prop[0];
node.prop = node.prop.slice(1);
}
node.raws.between += this.spacesAndCommentsFromStart(tokens);
this.precheckMissedSemicolon(tokens);
for (var i = tokens.length - 1; i > 0; i--) {
token = tokens[i];
if (token[1] === '!important') {
node.important = true;
var string = this.stringFrom(tokens, i);
string = this.spacesFromEnd(tokens) + string;
if (string !== ' !important') {
node.raws.important = string;
}
break;
} else if (token[1] === 'important') {
var cache = tokens.slice(0);
var str = '';
for (var j = i; j > 0; j--) {
var _type = cache[j][0];
if (str.trim().indexOf('!') === 0 && _type !== 'space') {
break;
}
str = cache.pop()[1] + str;
}
if (str.trim().indexOf('!') === 0) {
node.important = true;
node.raws.important = str;
tokens = cache;
}
}
if (token[0] !== 'space' && token[0] !== 'comment') {
break;
}
}
this.raw(node, 'value', tokens);
if (node.value.indexOf(':') !== -1) {
this.checkMissedSemicolon(tokens);
}
this.current = node;
}
};
ScssParser.prototype.comment = function comment(token) {
if (token[6] === 'inline') {
var node = new _comment2.default();
this.init(node, token[2], token[3]);
node.raws.inline = true;
node.source.end = { line: token[4], column: token[5] };
var text = token[1].slice(2);
if (/^\s*$/.test(text)) {
node.text = '';
node.raws.left = text;
node.raws.right = '';
} else {
var match = text.match(/^(\s*)([^]*[^\s])(\s*)$/);
var fixed = match[2].replace(/(\*\/|\/\*)/g, '*//*');
node.text = fixed;
node.raws.left = match[1];
node.raws.right = match[3];
node.raws.text = match[2];
}
} else {
_Parser.prototype.comment.call(this, token);
}
};
return ScssParser;
}(_parser2.default);
exports.default = ScssParser;
module.exports = exports['default'];
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjc3MtcGFyc2VyLmVzNiJdLCJuYW1lcyI6WyJTY3NzUGFyc2VyIiwidG9rZW5pemUiLCJ0b2tlbnMiLCJpbnB1dCIsInJ1bGUiLCJ3aXRoQ29sb24iLCJicmFja2V0cyIsInZhbHVlIiwiaSIsImluZGV4T2YiLCJ0cmltIiwidGVzdCIsInBvcCIsIm5vZGUiLCJpbml0IiwibGFzdCIsImxlbmd0aCIsInNvdXJjZSIsImVuZCIsImxpbmUiLCJjb2x1bW4iLCJyYXdzIiwiYmVmb3JlIiwic2hpZnQiLCJzdGFydCIsInByb3AiLCJ0eXBlIiwiYmV0d2VlbiIsInRva2VuIiwic2xpY2UiLCJzcGFjZXNBbmRDb21tZW50c0Zyb21TdGFydCIsInByZWNoZWNrTWlzc2VkU2VtaWNvbG9uIiwiaW1wb3J0YW50Iiwic3RyaW5nIiwic3RyaW5nRnJvbSIsInNwYWNlc0Zyb21FbmQiLCJjYWNoZSIsInN0ciIsImoiLCJyYXciLCJjaGVja01pc3NlZFNlbWljb2xvbiIsImN1cnJlbnQiLCJjb21tZW50IiwiaW5saW5lIiwidGV4dCIsImxlZn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