3 exports.__esModule = true;
4 exports.default = tokenize;
6 var _tokenTypes = require('./tokenTypes');
8 var t = _interopRequireWildcard(_tokenTypes);
10 function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
12 var wordEnd = /[ \n\t\r\(\)\*:;!&'"\+\|~>,=$^\[\]\\]|\/(?=\*)/g;
14 function tokenize(input) {
16 var css = input.css.valueOf();
39 function unclosed(what, fix) {
41 // fyi: this is never set to true.
43 next = css.length - 1;
45 throw input.error('Unclosed ' + what, line, start - offset, start);
49 while (start < length) {
50 code = css.charCodeAt(start);
52 if (code === t.newline) {
66 code = css.charCodeAt(next);
67 if (code === t.newline) {
71 } while (code === t.space || code === t.newline || code === t.tab || code === t.cr || code === t.feed);
75 endColumn = start - offset;
86 code = css.charCodeAt(next);
87 } while (code === t.plus || code === t.greaterThan || code === t.tilde || code === t.pipe);
89 tokenType = t.combinator;
91 endColumn = start - offset;
95 // Consume these characters as single tokens.
106 case t.openParenthesis:
107 case t.closeParenthesis:
111 endColumn = start - offset;
117 quote = code === t.singleQuote ? "'" : '"';
121 next = css.indexOf(quote, next + 1);
123 unclosed('quote', quote);
126 while (css.charCodeAt(escapePos - 1) === t.backslash) {
134 endColumn = start - offset;
141 while (css.charCodeAt(next + 1) === t.backslash) {
145 code = css.charCodeAt(next + 1);
146 if (escaped && code !== t.slash && code !== t.space && code !== t.newline && code !== t.tab && code !== t.cr && code !== t.feed) {
152 endColumn = next - offset;
157 if (code === t.slash && css.charCodeAt(start + 1) === t.asterisk) {
158 next = css.indexOf('*/', start + 2) + 1;
160 unclosed('comment', '*/');
163 content = css.slice(start, next + 1);
164 lines = content.split('\n');
165 last = lines.length - 1;
168 nextLine = line + last;
169 nextOffset = next - lines[last].length;
175 tokenType = t.comment;
178 endColumn = next - nextOffset;
180 wordEnd.lastIndex = start + 1;
182 if (wordEnd.lastIndex === 0) {
183 next = css.length - 1;
185 next = wordEnd.lastIndex - 2;
190 endColumn = next - offset;
197 // Ensure that the token structure remains consistent
198 tokens.push([tokenType, // [0] Token type
199 line, // [1] Starting line
200 start - offset, // [2] Starting column
201 endLine, // [3] Ending line
202 endColumn, // [4] Ending column
203 start, // [5] Start position / Source index
204 end] // [6] End position
207 // Reset offset for the next token
218 module.exports = exports['default'];