forked from lix-project/lix-website
121 lines
12 KiB
JavaScript
121 lines
12 KiB
JavaScript
'use strict';
|
|
|
|
exports.__esModule = true;
|
|
exports.default = preprocess;
|
|
function indentError(input, l, p) {
|
|
throw input.error('Mixed tabs and spaces are not allowed', l, p + 1);
|
|
}
|
|
|
|
function preprocess(input, lines) {
|
|
var indentType = void 0;
|
|
var prevNumber = 0;
|
|
var parts = lines.map(function (line) {
|
|
var lastComma = false;
|
|
var comment = false;
|
|
var number = prevNumber + 1;
|
|
var atrule = false;
|
|
var indent = '';
|
|
var tokens = [];
|
|
var colon = false;
|
|
|
|
if (line.length > 0) {
|
|
if (line[0][0] === 'space') {
|
|
indent = line[0][1];
|
|
tokens = line.slice(1);
|
|
} else {
|
|
indent = '';
|
|
tokens = line;
|
|
}
|
|
|
|
if (!indentType && indent.length) {
|
|
indentType = indent[0] === ' ' ? 'space' : 'tab';
|
|
}
|
|
if (indentType === 'space') {
|
|
if (indent.indexOf('\t') !== -1) {
|
|
indentError(input, number, indent.indexOf('\t'));
|
|
}
|
|
} else if (indentType === 'tab') {
|
|
if (indent.indexOf(' ') !== -1) {
|
|
indentError(input, number, indent.indexOf(' '));
|
|
}
|
|
}
|
|
|
|
if (tokens.length) {
|
|
for (var i = tokens.length - 1; i >= 0; i--) {
|
|
var type = tokens[i][0];
|
|
if (type === ',') {
|
|
lastComma = true;
|
|
break;
|
|
} else if (type === 'space') {
|
|
continue;
|
|
} else if (type === 'comment') {
|
|
continue;
|
|
} else if (type === 'newline') {
|
|
continue;
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
comment = tokens[0][0] === 'comment';
|
|
atrule = tokens[0][0] === 'at-word';
|
|
|
|
var brackets = 0;
|
|
for (var _i = 0; _i < tokens.length - 1; _i++) {
|
|
var _type = tokens[_i][0];
|
|
var next = tokens[_i + 1][0];
|
|
if (_type === '(') {
|
|
brackets += 1;
|
|
} else if (_type === ')') {
|
|
brackets -= 1;
|
|
} else if (_type === ':' && brackets === 0 && (next === 'space' || next === 'newline')) {
|
|
colon = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
var last = tokens[tokens.length - 1];
|
|
if (last && last[0] === 'newline') prevNumber = last[2];
|
|
}
|
|
|
|
return {
|
|
number: number,
|
|
indent: indent,
|
|
colon: colon,
|
|
tokens: tokens,
|
|
atrule: atrule,
|
|
comment: comment,
|
|
lastComma: lastComma,
|
|
before: ''
|
|
};
|
|
});
|
|
|
|
parts = parts.reduceRight(function (all, i) {
|
|
if (!i.tokens.length || i.tokens.every(function (j) {
|
|
return j[0] === 'newline';
|
|
})) {
|
|
var prev = all[0];
|
|
var before = i.indent + i.tokens.map(function (j) {
|
|
return j[1];
|
|
}).join('');
|
|
prev.before = before + prev.before;
|
|
} else {
|
|
all.unshift(i);
|
|
}
|
|
return all;
|
|
}, [{ end: true, before: '' }]);
|
|
|
|
parts.forEach(function (part, i) {
|
|
if (i === 0) return;
|
|
|
|
var prev = parts[i - 1];
|
|
var last = prev.tokens[prev.tokens.length - 1];
|
|
if (last && last[0] === 'newline') {
|
|
part.before = last[1] + part.before;
|
|
prev.tokens.pop();
|
|
}
|
|
});
|
|
|
|
return parts;
|
|
}
|
|
module.exports = exports['default'];
|
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInByZXByb2Nlc3MuZXM2Il0sIm5hbWVzIjpbInByZXByb2Nlc3MiLCJpbmRlbnRFcnJvciIsImlucHV0IiwibCIsInAiLCJlcnJvciIsImxpbmVzIiwiaW5kZW50VHlwZSIsInByZXZOdW1iZXIiLCJwYXJ0cyIsIm1hcCIsImxhc3RDb21tYSIsImNvbW1lbnQiLCJudW1iZXIiLCJhdHJ1bGUiLCJpbmRlbnQiLCJ0b2tlbnMiLCJjb2xvbiIsImxpbmUiLCJsZW5ndGgiLCJzbGljZSIsImluZGV4T2YiLCJpIiwidHlwZSIsImJyYWNrZXRzIiwibmV4dCIsImxhc3QiLCJiZWZvcmUiLCJyZWR1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cbiAgICAgIH1cbiAgICAgIGlmIChpbmRlbnRUeXBlID09PSAnc3BhY2UnKSB7XG4gICAgICAgIGlmIChpbmRlbnQuaW5kZXhPZignXFx0JykgIT09IC0xKSB7XG4gICAgICAgICAgaW5kZW50RXJyb3IoaW5wdXQsIG51bWJlciwgaW5kZW50LmluZGV4T2YoJ1xcdCcpKVxuICAgICAgICB9XG4gICAgICB9IGVsc2UgaWYgKGluZGVudFR5cGUgPT09ICd0YWInKSB7XG4gICAgICAgIGlmIChpbmRlbnQuaW5kZXhPZignICcpICE9PSAtMSkge1xuICAgICAgICAgIGluZGVudEVycm9yKGlucHV0LCBudW1iZXIsIGluZGVudC5pbmRleE9mKCcgJykpXG4gICAgICAgIH1cbiAgICAgIH1cblxuICAgICAgaWYgKHRva2Vucy5sZW5ndGgpIHtcbiAgICAgICAgZm9yIChsZXQgaSA9IHRva2Vucy5sZW5ndGggLSAxOyBpID49IDA7IGktLSkge1xuICAgICAgICAgIGxldCB0eXBlID0gdG9rZW5zW2ldWzBdXG4gICAgICAgICAgaWYgKHR5cGUgPT09ICcsJykge1xuICAgICAgICAgICAgbGFzdENvbW1hID0gdHJ1ZVxuICAgICAgICAgICAgYnJlYWtcbiAgICAgICAgICB9IGVsc2UgaWYgKHR5cGUgPT09ICdzcGFjZScpIHtcbiAgICAgICAgICAgIGNvbnRpbnVlXG4gICAgICAgICAgfSBlbHNlIGlmICh0eXBlID09PSAnY29tbWVudCcpIHtcbiAgICAgICAgICAgIGNvbnRpbnVlXG4gICAgICAgICAgfSBlbHNlIGlmICh0eXBlID09PSAnbmV3bGluZScpIHtcbiAgICAgICAgICAgIGNvbnRpbnVlXG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGJyZWFrXG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIGNvbW1lbnQgPSB0b2tlbnNbMF1bMF0gPT09ICdjb21tZW50J1xuICAgICAgICBhdHJ1bGUgPSB0b2tlbnNbMF1bMF0gPT09ICdhdC13b3JkJ1xuXG4gICAgICAgIGxldCBicmFja2V0cyA9IDBcbiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCB0b2tlbnMubGVuZ3RoIC0gMTsgaSsrKSB7XG4gICAgICAgICAgbGV0IHR5cGUgPSB0b2tlbnNbaV1bMF1cbiAgICAgICAgICBsZXQgbmV4dCA9IHRva2Vuc1tpICsgMV1bMF1cbiAgICAgICAgICBpZiAodHlwZSA9PT0gJygnKSB7XG4gICAgICAgICAgICBicmFja2V0cyArPSAxXG4gICAgICAgICAgfSBlbHNlIGlmICh0eXBlID09PSAnKScpIHtcbiAgICAgICAgICAgIGJyYWNrZXRzIC09IDFcbiAgICAgICAgICB9IGVsc2UgaWYgKHR5cGUgPT09ICc6JyAmJiBicmFja2V0cyA9PT0gMCAmJlxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChuZXh0ID09PSAnc3BhY2UnIHx8IG5leHQgPT09ICduZXdsaW5lJykpIHtcbiAgICAgICAgICAgIGNvbG9uID0gdHJ1ZVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfVxuXG4gICAgICBsZXQgbGFzdCA9IHRva2Vuc1t0b2tlbnMubGVuZ3RoIC0gMV1cbiAgICAgIGlmIChsYXN0ICYmIGxhc3RbMF0gPT09ICduZXdsaW5lJykgcHJldk51bWJlciA9IGxhc3RbMl1cbiAgICB9XG5cbiAgICByZXR1cm4ge1xuICAgICAgbnVtYmVyLFxuICAgICAgaW5kZW50LFxuICAgICAgY29sb24sXG4gICAgICB0b2tlbnMsXG4gICAgICBhdHJ1bGUsXG4gICAgICBjb21tZW50LFxuICAgICAgbGFzdENvbW1hLFxuICAgICAgYmVmb3JlOiAnJ1xuICAgIH1cbiAgfSlcblxuICBwYXJ0cyA9IHBhcnRzLnJlZHVjZVJpZ2h0KChhbGwsIGkpID0+IHtcbiAgICBpZiAoIWkudG9rZW5zLmxlbmd0aCB8fCBpLnRva2Vucy5ldmVyeShqID0+IGpbMF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