| | |
| | | after = token; |
| | | } else if (prev && prev.type === "div") { |
| | | prev.after = token; |
| | | prev.sourceEndIndex += token.length; |
| | | } else if ( |
| | | code === comma || |
| | | code === colon || |
| | |
| | | tokens.push({ |
| | | type: "space", |
| | | sourceIndex: pos, |
| | | sourceEndIndex: next, |
| | | value: token |
| | | }); |
| | | } |
| | |
| | | } |
| | | } while (escape); |
| | | token.value = value.slice(pos + 1, next); |
| | | |
| | | token.sourceEndIndex = token.unclosed ? next : next + 1; |
| | | tokens.push(token); |
| | | pos = next + 1; |
| | | code = value.charCodeAt(pos); |
| | | |
| | | // Comments |
| | | } else if (code === slash && value.charCodeAt(pos + 1) === star) { |
| | | next = value.indexOf("*/", pos); |
| | | |
| | | token = { |
| | | type: "comment", |
| | | sourceIndex: pos |
| | | sourceIndex: pos, |
| | | sourceEndIndex: next + 2 |
| | | }; |
| | | |
| | | next = value.indexOf("*/", pos); |
| | | if (next === -1) { |
| | | token.unclosed = true; |
| | | next = value.length; |
| | | token.sourceEndIndex = next; |
| | | } |
| | | |
| | | token.value = value.slice(pos + 2, next); |
| | |
| | | tokens.push({ |
| | | type: "word", |
| | | sourceIndex: pos - before.length, |
| | | sourceEndIndex: pos + token.length, |
| | | value: token |
| | | }); |
| | | pos += 1; |
| | |
| | | tokens.push({ |
| | | type: "div", |
| | | sourceIndex: pos - before.length, |
| | | sourceEndIndex: pos + token.length, |
| | | value: token, |
| | | before: before, |
| | | after: "" |
| | |
| | | { |
| | | type: "word", |
| | | sourceIndex: pos, |
| | | sourceEndIndex: whitespacePos + 1, |
| | | value: value.slice(pos, whitespacePos + 1) |
| | | } |
| | | ]; |
| | |
| | | token.nodes.push({ |
| | | type: "space", |
| | | sourceIndex: whitespacePos + 1, |
| | | sourceEndIndex: next, |
| | | value: value.slice(whitespacePos + 1, next) |
| | | }); |
| | | } else { |
| | | token.after = value.slice(whitespacePos + 1, next); |
| | | token.sourceEndIndex = next; |
| | | } |
| | | } else { |
| | | token.after = ""; |
| | | token.nodes = []; |
| | | } |
| | | pos = next + 1; |
| | | token.sourceEndIndex = token.unclosed ? next : pos; |
| | | code = value.charCodeAt(pos); |
| | | tokens.push(token); |
| | | } else { |
| | | balanced += 1; |
| | | token.after = ""; |
| | | token.sourceEndIndex = pos + 1; |
| | | tokens.push(token); |
| | | stack.push(token); |
| | | tokens = token.nodes = []; |
| | |
| | | code = value.charCodeAt(pos); |
| | | |
| | | parent.after = after; |
| | | parent.sourceEndIndex += after.length; |
| | | after = ""; |
| | | balanced -= 1; |
| | | stack[stack.length - 1].sourceEndIndex = pos; |
| | | stack.pop(); |
| | | parent = stack[balanced]; |
| | | tokens = parent.nodes; |
| | |
| | | tokens.push({ |
| | | type: "unicode-range", |
| | | sourceIndex: pos, |
| | | sourceEndIndex: next, |
| | | value: token |
| | | }); |
| | | } else { |
| | | tokens.push({ |
| | | type: "word", |
| | | sourceIndex: pos, |
| | | sourceEndIndex: next, |
| | | value: token |
| | | }); |
| | | } |
| | |
| | | |
| | | for (pos = stack.length - 1; pos; pos -= 1) { |
| | | stack[pos].unclosed = true; |
| | | stack[pos].sourceEndIndex = value.length; |
| | | } |
| | | |
| | | return stack[0].nodes; |