mirror of
https://github.com/thangisme/notes.git
synced 2024-11-01 01:37:37 -04:00
121 lines
13 KiB
JavaScript
121 lines
13 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;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInByZXByb2Nlc3MuZXM2Il0sIm5hbWVzIjpbInByZXByb2Nlc3MiLCJpbmRlbnRFcnJvciIsImlucHV0IiwibCIsInA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