3 exports.__esModule = true;
4 exports.default = tokenize;
14 var OPEN_PARENTHESES = 40;
15 var CLOSE_PARENTHESES = 41;
17 var CLOSE_CURLY = 125;
23 var RE_AT_END = /[ \n\t\r\f\{\(\)'"\\;/]/g;
24 var RE_WORD_END = /[ \n\t\r\f\(\)\{\}:;@!'"\\]|\/(?=\*)/g;
25 var RE_BAD_BRACKET = /.[\\\/\("'\n]/;
27 function tokenize(input) {
29 var css = input.css.valueOf();
45 var length = css.length;
50 function unclosed(what) {
51 throw input.error('Unclosed ' + what, line, pos - offset);
54 while (pos < length) {
55 code = css.charCodeAt(pos);
57 if (code === NEWLINE || code === FEED || code === CR && css.charCodeAt(pos + 1) !== NEWLINE) {
71 code = css.charCodeAt(next);
72 if (code === NEWLINE) {
76 } while (code === SPACE || code === NEWLINE || code === TAB || code === CR || code === FEED);
78 tokens.push(['space', css.slice(pos, next)]);
83 tokens.push(['{', '{', line, pos - offset]);
87 tokens.push(['}', '}', line, pos - offset]);
91 tokens.push([':', ':', line, pos - offset]);
95 tokens.push([';', ';', line, pos - offset]);
98 case OPEN_PARENTHESES:
99 prev = tokens.length ? tokens[tokens.length - 1][1] : '';
100 n = css.charCodeAt(pos + 1);
101 if (prev === 'url' && n !== SINGLE_QUOTE && n !== DOUBLE_QUOTE && n !== SPACE && n !== NEWLINE && n !== TAB && n !== FEED && n !== CR) {
105 next = css.indexOf(')', next + 1);
106 if (next === -1) unclosed('bracket');
108 while (css.charCodeAt(escapePos - 1) === BACKSLASH) {
114 tokens.push(['brackets', css.slice(pos, next + 1), line, pos - offset, line, next - offset]);
117 next = css.indexOf(')', pos + 1);
118 content = css.slice(pos, next + 1);
120 if (next === -1 || RE_BAD_BRACKET.test(content)) {
121 tokens.push(['(', '(', line, pos - offset]);
123 tokens.push(['brackets', content, line, pos - offset, line, next - offset]);
130 case CLOSE_PARENTHESES:
131 tokens.push([')', ')', line, pos - offset]);
136 quote = code === SINGLE_QUOTE ? '\'' : '"';
140 next = css.indexOf(quote, next + 1);
141 if (next === -1) unclosed('quote');
143 while (css.charCodeAt(escapePos - 1) === BACKSLASH) {
149 content = css.slice(pos, next + 1);
150 lines = content.split('\n');
151 last = lines.length - 1;
154 nextLine = line + last;
155 nextOffset = next - lines[last].length;
161 tokens.push(['string', css.slice(pos, next + 1), line, pos - offset, nextLine, next - nextOffset]);
169 RE_AT_END.lastIndex = pos + 1;
171 if (RE_AT_END.lastIndex === 0) {
172 next = css.length - 1;
174 next = RE_AT_END.lastIndex - 2;
176 tokens.push(['at-word', css.slice(pos, next + 1), line, pos - offset, line, next - offset]);
183 while (css.charCodeAt(next + 1) === BACKSLASH) {
187 code = css.charCodeAt(next + 1);
188 if (escape && code !== SLASH && code !== SPACE && code !== NEWLINE && code !== TAB && code !== CR && code !== FEED) {
191 tokens.push(['word', css.slice(pos, next + 1), line, pos - offset, line, next - offset]);
196 if (code === SLASH && css.charCodeAt(pos + 1) === ASTERICK) {
197 next = css.indexOf('*/', pos + 2) + 1;
198 if (next === 0) unclosed('comment');
200 content = css.slice(pos, next + 1);
201 lines = content.split('\n');
202 last = lines.length - 1;
205 nextLine = line + last;
206 nextOffset = next - lines[last].length;
212 tokens.push(['comment', content, line, pos - offset, nextLine, next - nextOffset]);
218 RE_WORD_END.lastIndex = pos + 1;
219 RE_WORD_END.test(css);
220 if (RE_WORD_END.lastIndex === 0) {
221 next = css.length - 1;
223 next = RE_WORD_END.lastIndex - 2;
226 tokens.push(['word', css.slice(pos, next + 1), line, pos - offset, line, next - offset]);
238 module.exports = exports['default'];