123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- "use strict";
- function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
- var tokenizer = require('postcss/lib/tokenize');
- var Comment = require('postcss/lib/comment');
- var Parser = require('postcss/lib/parser');
- var SafeParser =
- function (_Parser) {
- _inheritsLoose(SafeParser, _Parser);
- function SafeParser() {
- return _Parser.apply(this, arguments) || this;
- }
- var _proto = SafeParser.prototype;
- _proto.createTokenizer = function createTokenizer() {
- this.tokenizer = tokenizer(this.input, {
- ignoreErrors: true
- });
- };
- _proto.comment = function comment(token) {
- var node = new Comment();
- this.init(node, token[2], token[3]);
- node.source.end = {
- line: token[4],
- column: token[5]
- };
- var text = token[1].slice(2);
- if (text.slice(-2) === '*/') text = text.slice(0, -2);
- if (/^\s*$/.test(text)) {
- node.text = '';
- node.raws.left = text;
- node.raws.right = '';
- } else {
- var match = text.match(/^(\s*)([^]*\S)(\s*)$/);
- node.text = match[2];
- node.raws.left = match[1];
- node.raws.right = match[3];
- }
- };
- _proto.decl = function decl(tokens) {
- if (tokens.length > 1 && tokens.some(function (i) {
- return i[0] === 'word';
- })) {
- _Parser.prototype.decl.call(this, tokens);
- }
- };
- _proto.unclosedBracket = function unclosedBracket() {};
- _proto.unknownWord = function unknownWord(tokens) {
- this.spaces += tokens.map(function (i) {
- return i[1];
- }).join('');
- };
- _proto.unexpectedClose = function unexpectedClose() {
- this.current.raws.after += '}';
- };
- _proto.doubleColon = function doubleColon() {};
- _proto.unnamedAtrule = function unnamedAtrule(node) {
- node.name = '';
- };
- _proto.precheckMissedSemicolon = function precheckMissedSemicolon(tokens) {
- var colon = this.colon(tokens);
- if (colon === false) return;
- var split;
- for (split = colon - 1; split >= 0; split--) {
- if (tokens[split][0] === 'word') break;
- }
- for (split -= 1; split >= 0; split--) {
- if (tokens[split][0] !== 'space') {
- split += 1;
- break;
- }
- }
- var other = tokens.splice(split, tokens.length - split);
- this.decl(other);
- };
- _proto.checkMissedSemicolon = function checkMissedSemicolon() {};
- _proto.endFile = function endFile() {
- if (this.current.nodes && this.current.nodes.length) {
- this.current.raws.semicolon = this.semicolon;
- }
- this.current.raws.after = (this.current.raws.after || '') + this.spaces;
- while (this.current.parent) {
- this.current = this.current.parent;
- this.current.raws.after = '';
- }
- };
- return SafeParser;
- }(Parser);
- module.exports = SafeParser;
|