[6a3a178] | 1 | // Copyright 2014, 2015, 2016, 2017, 2018 Simon Lydell
|
---|
| 2 | // License: MIT. (See LICENSE.)
|
---|
| 3 |
|
---|
| 4 | Object.defineProperty(exports, "__esModule", {
|
---|
| 5 | value: true
|
---|
| 6 | })
|
---|
| 7 |
|
---|
| 8 | // This regex comes from regex.coffee, and is inserted here by generate-index.js
|
---|
| 9 | // (run `npm run build`).
|
---|
| 10 | exports.default = /((['"])(?:(?!\2|\\).|\\(?:\r\n|[\s\S]))*(\2)?|`(?:[^`\\$]|\\[\s\S]|\$(?!\{)|\$\{(?:[^{}]|\{[^}]*\}?)*\}?)*(`)?)|(\/\/.*)|(\/\*(?:[^*]|\*(?!\/))*(\*\/)?)|(\/(?!\*)(?:\[(?:(?![\]\\]).|\\.)*\]|(?![\/\]\\]).|\\.)+\/(?:(?!\s*(?:\b|[\u0080-\uFFFF$\\'"~({]|[+\-!](?!=)|\.?\d))|[gmiyus]{1,6}\b(?![\u0080-\uFFFF$\\]|\s*(?:[+\-*%&|^<>!=?({]|\/(?![\/*])))))|(0[xX][\da-fA-F]+|0[oO][0-7]+|0[bB][01]+|(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?)|((?!\d)(?:(?!\s)[$\w\u0080-\uFFFF]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+)|(--|\+\+|&&|\|\||=>|\.{3}|(?:[+\-\/%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2})=?|[?~.,:;[\](){}])|(\s+)|(^$|[\s\S])/g
|
---|
| 11 |
|
---|
| 12 | exports.matchToToken = function(match) {
|
---|
| 13 | var token = {type: "invalid", value: match[0], closed: undefined}
|
---|
| 14 | if (match[ 1]) token.type = "string" , token.closed = !!(match[3] || match[4])
|
---|
| 15 | else if (match[ 5]) token.type = "comment"
|
---|
| 16 | else if (match[ 6]) token.type = "comment", token.closed = !!match[7]
|
---|
| 17 | else if (match[ 8]) token.type = "regex"
|
---|
| 18 | else if (match[ 9]) token.type = "number"
|
---|
| 19 | else if (match[10]) token.type = "name"
|
---|
| 20 | else if (match[11]) token.type = "punctuator"
|
---|
| 21 | else if (match[12]) token.type = "whitespace"
|
---|
| 22 | return token
|
---|
| 23 | }
|
---|