* Returns a valid variable name regex; * taken from https://gist.github.com/mathiasbynens/6334847
()
| 48 | * taken from https://gist.github.com/mathiasbynens/6334847 |
| 49 | */ |
| 50 | function generateValidRegex() { |
| 51 | const get = function (what) { |
| 52 | return require('@unicode/unicode-10.0.0/' + what + '/code-points.js'); |
| 53 | }; |
| 54 | const idStart = get('Binary_Property/ID_Start'); |
| 55 | const idContinue = get('Binary_Property/ID_Continue'); |
| 56 | const compileRegex = _.template( |
| 57 | '^(?:<%= identifierStart %>)(?:<%= identifierPart %>)*$', |
| 58 | ); |
| 59 | const identifierStart = regenerate(idStart).add('$', '_'); |
| 60 | const identifierPart = regenerate(idContinue).add( |
| 61 | '$', |
| 62 | '_', |
| 63 | '\u200C', |
| 64 | '\u200D', |
| 65 | ); |
| 66 | const regex = compileRegex({ |
| 67 | identifierStart: identifierStart.toString(), |
| 68 | identifierPart: identifierPart.toString(), |
| 69 | }); |
| 70 | return new RegExp(regex); |
| 71 | } |
| 72 | const validRegex = generateValidRegex(); |
| 73 | exports.validRegex = validRegex; |
| 74 |