| 1 | let source, pos, end;
|
|---|
| 2 | let openTokenDepth,
|
|---|
| 3 | templateDepth,
|
|---|
| 4 | lastTokenPos,
|
|---|
| 5 | lastSlashWasDivision,
|
|---|
| 6 | templateStack,
|
|---|
| 7 | templateStackDepth,
|
|---|
| 8 | openTokenPosStack,
|
|---|
| 9 | openClassPosStack,
|
|---|
| 10 | nextBraceIsClass,
|
|---|
| 11 | starExportMap,
|
|---|
| 12 | lastStarExportSpecifier,
|
|---|
| 13 | _exports,
|
|---|
| 14 | unsafeGetters,
|
|---|
| 15 | reexports;
|
|---|
| 16 |
|
|---|
| 17 | function resetState () {
|
|---|
| 18 | openTokenDepth = 0;
|
|---|
| 19 | templateDepth = -1;
|
|---|
| 20 | lastTokenPos = -1;
|
|---|
| 21 | lastSlashWasDivision = false;
|
|---|
| 22 | templateStack = new Array(1024);
|
|---|
| 23 | templateStackDepth = 0;
|
|---|
| 24 | openTokenPosStack = new Array(1024);
|
|---|
| 25 | openClassPosStack = new Array(1024);
|
|---|
| 26 | nextBraceIsClass = false;
|
|---|
| 27 | starExportMap = Object.create(null);
|
|---|
| 28 | lastStarExportSpecifier = null;
|
|---|
| 29 |
|
|---|
| 30 | _exports = new Set();
|
|---|
| 31 | unsafeGetters = new Set();
|
|---|
| 32 | reexports = new Set();
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | // RequireType
|
|---|
| 36 | const Import = 0;
|
|---|
| 37 | const ExportAssign = 1;
|
|---|
| 38 | const ExportStar = 2;
|
|---|
| 39 |
|
|---|
| 40 | function parseCJS (source, name = '@') {
|
|---|
| 41 | resetState();
|
|---|
| 42 | try {
|
|---|
| 43 | parseSource(source);
|
|---|
| 44 | }
|
|---|
| 45 | catch (e) {
|
|---|
| 46 | e.message += `\n at ${name}:${source.slice(0, pos).split('\n').length}:${pos - source.lastIndexOf('\n', pos - 1)}`;
|
|---|
| 47 | e.loc = pos;
|
|---|
| 48 | throw e;
|
|---|
| 49 | }
|
|---|
| 50 | const result = { exports: [..._exports].filter(expt => expt !== undefined && !unsafeGetters.has(expt)), reexports: [...reexports].filter(reexpt => reexpt !== undefined) };
|
|---|
| 51 | resetState();
|
|---|
| 52 | return result;
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | function decode (str) {
|
|---|
| 56 | if (str[0] === '"' || str[0] === '\'') {
|
|---|
| 57 | try {
|
|---|
| 58 | const decoded = (0, eval)(str);
|
|---|
| 59 | // Filter to exclude non-matching UTF-16 surrogate strings
|
|---|
| 60 | for (let i = 0; i < decoded.length; i++) {
|
|---|
| 61 | const surrogatePrefix = decoded.charCodeAt(i) & 0xFC00;
|
|---|
| 62 | if (surrogatePrefix < 0xD800) {
|
|---|
| 63 | // Not a surrogate
|
|---|
| 64 | continue;
|
|---|
| 65 | }
|
|---|
| 66 | else if (surrogatePrefix === 0xD800) {
|
|---|
| 67 | // Validate surrogate pair
|
|---|
| 68 | if ((decoded.charCodeAt(++i) & 0xFC00) !== 0xDC00)
|
|---|
| 69 | return;
|
|---|
| 70 | }
|
|---|
| 71 | else {
|
|---|
| 72 | // Out-of-range surrogate code (above 0xD800)
|
|---|
| 73 | return;
|
|---|
| 74 | }
|
|---|
| 75 | }
|
|---|
| 76 | return decoded;
|
|---|
| 77 | }
|
|---|
| 78 | catch {}
|
|---|
| 79 | }
|
|---|
| 80 | else {
|
|---|
| 81 | return str;
|
|---|
| 82 | }
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | function parseSource (cjsSource) {
|
|---|
| 86 | source = cjsSource;
|
|---|
| 87 | pos = -1;
|
|---|
| 88 | end = source.length - 1;
|
|---|
| 89 | let ch = 0;
|
|---|
| 90 |
|
|---|
| 91 | // Handle #!
|
|---|
| 92 | if (source.charCodeAt(0) === 35/*#*/ && source.charCodeAt(1) === 33/*!*/) {
|
|---|
| 93 | if (source.length === 2)
|
|---|
| 94 | return true;
|
|---|
| 95 | pos += 2;
|
|---|
| 96 | while (pos++ < end) {
|
|---|
| 97 | ch = source.charCodeAt(pos);
|
|---|
| 98 | if (ch === 10/*\n*/ || ch === 13/*\r*/)
|
|---|
| 99 | break;
|
|---|
| 100 | }
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | while (pos++ < end) {
|
|---|
| 104 | ch = source.charCodeAt(pos);
|
|---|
| 105 |
|
|---|
| 106 | if (ch === 32 || ch < 14 && ch > 8)
|
|---|
| 107 | continue;
|
|---|
| 108 |
|
|---|
| 109 | if (openTokenDepth === 0) {
|
|---|
| 110 | switch (ch) {
|
|---|
| 111 | case 105/*i*/:
|
|---|
| 112 | if (source.startsWith('mport', pos + 1) && keywordStart(pos))
|
|---|
| 113 | throwIfImportStatement();
|
|---|
| 114 | lastTokenPos = pos;
|
|---|
| 115 | continue;
|
|---|
| 116 | case 114/*r*/:
|
|---|
| 117 | const startPos = pos;
|
|---|
| 118 | if (tryParseRequire(Import) && keywordStart(startPos))
|
|---|
| 119 | tryBacktrackAddStarExportBinding(startPos - 1);
|
|---|
| 120 | lastTokenPos = pos;
|
|---|
| 121 | continue;
|
|---|
| 122 | case 95/*_*/:
|
|---|
| 123 | if (source.startsWith('interopRequireWildcard', pos + 1) && (keywordStart(pos) || source.charCodeAt(pos - 1) === 46/*.*/)) {
|
|---|
| 124 | const startPos = pos;
|
|---|
| 125 | pos += 23;
|
|---|
| 126 | if (source.charCodeAt(pos) === 40/*(*/) {
|
|---|
| 127 | pos++;
|
|---|
| 128 | openTokenPosStack[openTokenDepth++] = lastTokenPos;
|
|---|
| 129 | if (tryParseRequire(Import) && keywordStart(startPos)) {
|
|---|
| 130 | tryBacktrackAddStarExportBinding(startPos - 1);
|
|---|
| 131 | }
|
|---|
| 132 | }
|
|---|
| 133 | }
|
|---|
| 134 | else if (source.startsWith('_export', pos + 1) && (keywordStart(pos) || source.charCodeAt(pos - 1) === 46/*.*/)) {
|
|---|
| 135 | pos += 8;
|
|---|
| 136 | if (source.startsWith('Star', pos))
|
|---|
| 137 | pos += 4;
|
|---|
| 138 | if (source.charCodeAt(pos) === 40/*(*/) {
|
|---|
| 139 | openTokenPosStack[openTokenDepth++] = lastTokenPos;
|
|---|
| 140 | if (source.charCodeAt(++pos) === 114/*r*/)
|
|---|
| 141 | tryParseRequire(ExportStar);
|
|---|
| 142 | }
|
|---|
| 143 | }
|
|---|
| 144 | lastTokenPos = pos;
|
|---|
| 145 | continue;
|
|---|
| 146 | }
|
|---|
| 147 | }
|
|---|
| 148 |
|
|---|
| 149 | switch (ch) {
|
|---|
| 150 | case 101/*e*/:
|
|---|
| 151 | if (source.startsWith('xport', pos + 1) && keywordStart(pos)) {
|
|---|
| 152 | if (source.charCodeAt(pos + 6) === 115/*s*/)
|
|---|
| 153 | tryParseExportsDotAssign(false);
|
|---|
| 154 | else if (openTokenDepth === 0)
|
|---|
| 155 | throwIfExportStatement();
|
|---|
| 156 | }
|
|---|
| 157 | break;
|
|---|
| 158 | case 99/*c*/:
|
|---|
| 159 | if (keywordStart(pos) && source.startsWith('lass', pos + 1) && isBrOrWs(source.charCodeAt(pos + 5)))
|
|---|
| 160 | nextBraceIsClass = true;
|
|---|
| 161 | break;
|
|---|
| 162 | case 109/*m*/:
|
|---|
| 163 | if (source.startsWith('odule', pos + 1) && keywordStart(pos))
|
|---|
| 164 | tryParseModuleExportsDotAssign();
|
|---|
| 165 | break;
|
|---|
| 166 | case 79/*O*/:
|
|---|
| 167 | if (source.startsWith('bject', pos + 1) && keywordStart(pos))
|
|---|
| 168 | tryParseObjectDefineOrKeys(openTokenDepth === 0);
|
|---|
| 169 | break;
|
|---|
| 170 | case 40/*(*/:
|
|---|
| 171 | openTokenPosStack[openTokenDepth++] = lastTokenPos;
|
|---|
| 172 | break;
|
|---|
| 173 | case 41/*)*/:
|
|---|
| 174 | if (openTokenDepth === 0)
|
|---|
| 175 | throw new Error('Unexpected closing bracket.');
|
|---|
| 176 | openTokenDepth--;
|
|---|
| 177 | break;
|
|---|
| 178 | case 123/*{*/:
|
|---|
| 179 | openClassPosStack[openTokenDepth] = nextBraceIsClass;
|
|---|
| 180 | nextBraceIsClass = false;
|
|---|
| 181 | openTokenPosStack[openTokenDepth++] = lastTokenPos;
|
|---|
| 182 | break;
|
|---|
| 183 | case 125/*}*/:
|
|---|
| 184 | if (openTokenDepth === 0)
|
|---|
| 185 | throw new Error('Unexpected closing brace.');
|
|---|
| 186 | if (openTokenDepth-- === templateDepth) {
|
|---|
| 187 | templateDepth = templateStack[--templateStackDepth];
|
|---|
| 188 | templateString();
|
|---|
| 189 | }
|
|---|
| 190 | else {
|
|---|
| 191 | if (templateDepth !== -1 && openTokenDepth < templateDepth)
|
|---|
| 192 | throw new Error('Unexpected closing brace.');
|
|---|
| 193 | }
|
|---|
| 194 | break;
|
|---|
| 195 | case 60/*>*/:
|
|---|
| 196 | // TODO: <!-- XML comment support
|
|---|
| 197 | break;
|
|---|
| 198 | case 39/*'*/:
|
|---|
| 199 | case 34/*"*/:
|
|---|
| 200 | stringLiteral(ch);
|
|---|
| 201 | break;
|
|---|
| 202 | case 47/*/*/: {
|
|---|
| 203 | const next_ch = source.charCodeAt(pos + 1);
|
|---|
| 204 | if (next_ch === 47/*/*/) {
|
|---|
| 205 | lineComment();
|
|---|
| 206 | // dont update lastToken
|
|---|
| 207 | continue;
|
|---|
| 208 | }
|
|---|
| 209 | else if (next_ch === 42/***/) {
|
|---|
| 210 | blockComment();
|
|---|
| 211 | // dont update lastToken
|
|---|
| 212 | continue;
|
|---|
| 213 | }
|
|---|
| 214 | else {
|
|---|
| 215 | // Division / regex ambiguity handling based on checking backtrack analysis of:
|
|---|
| 216 | // - what token came previously (lastToken)
|
|---|
| 217 | // - if a closing brace or paren, what token came before the corresponding
|
|---|
| 218 | // opening brace or paren (lastOpenTokenIndex)
|
|---|
| 219 | const lastToken = source.charCodeAt(lastTokenPos);
|
|---|
| 220 | if (isExpressionPunctuator(lastToken) &&
|
|---|
| 221 | !(lastToken === 46/*.*/ && (source.charCodeAt(lastTokenPos - 1) >= 48/*0*/ && source.charCodeAt(lastTokenPos - 1) <= 57/*9*/)) &&
|
|---|
| 222 | !(lastToken === 43/*+*/ && source.charCodeAt(lastTokenPos - 1) === 43/*+*/) && !(lastToken === 45/*-*/ && source.charCodeAt(lastTokenPos - 1) === 45/*-*/) ||
|
|---|
| 223 | lastToken === 41/*)*/ && isParenKeyword(openTokenPosStack[openTokenDepth]) ||
|
|---|
| 224 | lastToken === 125/*}*/ && (isExpressionTerminator(openTokenPosStack[openTokenDepth]) || openClassPosStack[openTokenDepth]) ||
|
|---|
| 225 | lastToken === 47/*/*/ && lastSlashWasDivision ||
|
|---|
| 226 | isExpressionKeyword(lastTokenPos) ||
|
|---|
| 227 | !lastToken) {
|
|---|
| 228 | regularExpression();
|
|---|
| 229 | lastSlashWasDivision = false;
|
|---|
| 230 | }
|
|---|
| 231 | else {
|
|---|
| 232 | lastSlashWasDivision = true;
|
|---|
| 233 | }
|
|---|
| 234 | }
|
|---|
| 235 | break;
|
|---|
| 236 | }
|
|---|
| 237 | case 96/*`*/:
|
|---|
| 238 | templateString();
|
|---|
| 239 | break;
|
|---|
| 240 | }
|
|---|
| 241 | lastTokenPos = pos;
|
|---|
| 242 | }
|
|---|
| 243 |
|
|---|
| 244 | if (templateDepth !== -1)
|
|---|
| 245 | throw new Error('Unterminated template.');
|
|---|
| 246 |
|
|---|
| 247 | if (openTokenDepth)
|
|---|
| 248 | throw new Error('Unterminated braces.');
|
|---|
| 249 | }
|
|---|
| 250 |
|
|---|
| 251 | function tryBacktrackAddStarExportBinding (bPos) {
|
|---|
| 252 | while (source.charCodeAt(bPos) === 32/* */ && bPos >= 0)
|
|---|
| 253 | bPos--;
|
|---|
| 254 | if (source.charCodeAt(bPos) === 61/*=*/) {
|
|---|
| 255 | bPos--;
|
|---|
| 256 | while (source.charCodeAt(bPos) === 32/* */ && bPos >= 0)
|
|---|
| 257 | bPos--;
|
|---|
| 258 | let codePoint;
|
|---|
| 259 | const id_end = bPos;
|
|---|
| 260 | let identifierStart = false;
|
|---|
| 261 | while ((codePoint = codePointAtLast(bPos)) && bPos >= 0) {
|
|---|
| 262 | if (codePoint === 92/*\*/)
|
|---|
| 263 | return;
|
|---|
| 264 | if (!isIdentifierChar(codePoint, true))
|
|---|
| 265 | break;
|
|---|
| 266 | identifierStart = isIdentifierStart(codePoint, true);
|
|---|
| 267 | bPos -= codePointLen(codePoint);
|
|---|
| 268 | }
|
|---|
| 269 | if (identifierStart && source.charCodeAt(bPos) === 32/* */) {
|
|---|
| 270 | const starExportId = source.slice(bPos + 1, id_end + 1);
|
|---|
| 271 | while (source.charCodeAt(bPos) === 32/* */ && bPos >= 0)
|
|---|
| 272 | bPos--;
|
|---|
| 273 | switch (source.charCodeAt(bPos)) {
|
|---|
| 274 | case 114/*r*/:
|
|---|
| 275 | if (!source.startsWith('va', bPos - 2))
|
|---|
| 276 | return;
|
|---|
| 277 | break;
|
|---|
| 278 | case 116/*t*/:
|
|---|
| 279 | if (!source.startsWith('le', bPos - 2) && !source.startsWith('cons', bPos - 4))
|
|---|
| 280 | return;
|
|---|
| 281 | break;
|
|---|
| 282 | default: return;
|
|---|
| 283 | }
|
|---|
| 284 | starExportMap[starExportId] = lastStarExportSpecifier;
|
|---|
| 285 | }
|
|---|
| 286 | }
|
|---|
| 287 | }
|
|---|
| 288 |
|
|---|
| 289 | // `Object.` `prototype.`? hasOwnProperty.call(` IDENTIFIER `, ` IDENTIFIER$2 `)`
|
|---|
| 290 | function tryParseObjectHasOwnProperty (it_id) {
|
|---|
| 291 | ch = commentWhitespace();
|
|---|
| 292 | if (ch !== 79/*O*/ || !source.startsWith('bject', pos + 1)) return false;
|
|---|
| 293 | pos += 6;
|
|---|
| 294 | ch = commentWhitespace();
|
|---|
| 295 | if (ch !== 46/*.*/) return false;
|
|---|
| 296 | pos++;
|
|---|
| 297 | ch = commentWhitespace();
|
|---|
| 298 | if (ch === 112/*p*/) {
|
|---|
| 299 | if (!source.startsWith('rototype', pos + 1)) return false;
|
|---|
| 300 | pos += 9;
|
|---|
| 301 | ch = commentWhitespace();
|
|---|
| 302 | if (ch !== 46/*.*/) return false;
|
|---|
| 303 | pos++;
|
|---|
| 304 | ch = commentWhitespace();
|
|---|
| 305 | }
|
|---|
| 306 | if (ch !== 104/*h*/ || !source.startsWith('asOwnProperty', pos + 1)) return false;
|
|---|
| 307 | pos += 14;
|
|---|
| 308 | ch = commentWhitespace();
|
|---|
| 309 | if (ch !== 46/*.*/) return false;
|
|---|
| 310 | pos++;
|
|---|
| 311 | ch = commentWhitespace();
|
|---|
| 312 | if (ch !== 99/*c*/ || !source.startsWith('all', pos + 1)) return false;
|
|---|
| 313 | pos += 4;
|
|---|
| 314 | ch = commentWhitespace();
|
|---|
| 315 | if (ch !== 40/*(*/) return false;
|
|---|
| 316 | pos++;
|
|---|
| 317 | ch = commentWhitespace();
|
|---|
| 318 | if (!identifier()) return false;
|
|---|
| 319 | ch = commentWhitespace();
|
|---|
| 320 | if (ch !== 44/*,*/) return false;
|
|---|
| 321 | pos++;
|
|---|
| 322 | ch = commentWhitespace();
|
|---|
| 323 | if (!source.startsWith(it_id, pos)) return false;
|
|---|
| 324 | pos += it_id.length;
|
|---|
| 325 | ch = commentWhitespace();
|
|---|
| 326 | if (ch !== 41/*)*/) return false;
|
|---|
| 327 | pos++;
|
|---|
| 328 | return true;
|
|---|
| 329 | }
|
|---|
| 330 |
|
|---|
| 331 | function tryParseObjectDefineOrKeys (keys) {
|
|---|
| 332 | pos += 6;
|
|---|
| 333 | let revertPos = pos - 1;
|
|---|
| 334 | let ch = commentWhitespace();
|
|---|
| 335 | if (ch === 46/*.*/) {
|
|---|
| 336 | pos++;
|
|---|
| 337 | ch = commentWhitespace();
|
|---|
| 338 | if (ch === 100/*d*/ && source.startsWith('efineProperty', pos + 1)) {
|
|---|
| 339 | let expt;
|
|---|
| 340 | while (true) {
|
|---|
| 341 | pos += 14;
|
|---|
| 342 | revertPos = pos - 1;
|
|---|
| 343 | ch = commentWhitespace();
|
|---|
| 344 | if (ch !== 40/*(*/) break;
|
|---|
| 345 | pos++;
|
|---|
| 346 | ch = commentWhitespace();
|
|---|
| 347 | if (!readExportsOrModuleDotExports(ch)) break;
|
|---|
| 348 | ch = commentWhitespace();
|
|---|
| 349 | if (ch !== 44/*,*/) break;
|
|---|
| 350 | pos++;
|
|---|
| 351 | ch = commentWhitespace();
|
|---|
| 352 | if (ch !== 39/*'*/ && ch !== 34/*"*/) break;
|
|---|
| 353 | const exportPos = pos;
|
|---|
| 354 | stringLiteral(ch);
|
|---|
| 355 | expt = source.slice(exportPos, ++pos);
|
|---|
| 356 | ch = commentWhitespace();
|
|---|
| 357 | if (ch !== 44/*,*/) break;
|
|---|
| 358 | pos++;
|
|---|
| 359 | ch = commentWhitespace();
|
|---|
| 360 | if (ch !== 123/*{*/) break;
|
|---|
| 361 | pos++;
|
|---|
| 362 | ch = commentWhitespace();
|
|---|
| 363 | if (ch === 101/*e*/) {
|
|---|
| 364 | if (!source.startsWith('numerable', pos + 1)) break;
|
|---|
| 365 | pos += 10;
|
|---|
| 366 | ch = commentWhitespace();
|
|---|
| 367 | if (ch !== 58/*:*/) break;
|
|---|
| 368 | pos++;
|
|---|
| 369 | ch = commentWhitespace();
|
|---|
| 370 | if (ch !== 116/*t*/ || !source.startsWith('rue', pos + 1)) break;
|
|---|
| 371 | pos += 4;
|
|---|
| 372 | ch = commentWhitespace();
|
|---|
| 373 | if (ch !== 44) break;
|
|---|
| 374 | pos++;
|
|---|
| 375 | ch = commentWhitespace();
|
|---|
| 376 | }
|
|---|
| 377 | if (ch === 118/*v*/) {
|
|---|
| 378 | if (!source.startsWith('alue', pos + 1)) break;
|
|---|
| 379 | pos += 5;
|
|---|
| 380 | ch = commentWhitespace();
|
|---|
| 381 | if (ch !== 58/*:*/) break;
|
|---|
| 382 | _exports.add(decode(expt));
|
|---|
| 383 | pos = revertPos;
|
|---|
| 384 | return;
|
|---|
| 385 | }
|
|---|
| 386 | else if (ch === 103/*g*/) {
|
|---|
| 387 | if (!source.startsWith('et', pos + 1)) break;
|
|---|
| 388 | pos += 3;
|
|---|
| 389 | ch = commentWhitespace();
|
|---|
| 390 | if (ch === 58/*:*/) {
|
|---|
| 391 | pos++;
|
|---|
| 392 | ch = commentWhitespace();
|
|---|
| 393 | if (ch !== 102/*f*/) break;
|
|---|
| 394 | if (!source.startsWith('unction', pos + 1)) break;
|
|---|
| 395 | pos += 8;
|
|---|
| 396 | let lastPos = pos;
|
|---|
| 397 | ch = commentWhitespace();
|
|---|
| 398 | if (ch !== 40 && (lastPos === pos || !identifier())) break;
|
|---|
| 399 | ch = commentWhitespace();
|
|---|
| 400 | }
|
|---|
| 401 | if (ch !== 40/*(*/) break;
|
|---|
| 402 | pos++;
|
|---|
| 403 | ch = commentWhitespace();
|
|---|
| 404 | if (ch !== 41/*)*/) break;
|
|---|
| 405 | pos++;
|
|---|
| 406 | ch = commentWhitespace();
|
|---|
| 407 | if (ch !== 123/*{*/) break;
|
|---|
| 408 | pos++;
|
|---|
| 409 | ch = commentWhitespace();
|
|---|
| 410 | if (ch !== 114/*r*/) break;
|
|---|
| 411 | if (!source.startsWith('eturn', pos + 1)) break;
|
|---|
| 412 | pos += 6;
|
|---|
| 413 | ch = commentWhitespace();
|
|---|
| 414 | if (!identifier()) break;
|
|---|
| 415 | ch = commentWhitespace();
|
|---|
| 416 | if (ch === 46/*.*/) {
|
|---|
| 417 | pos++;
|
|---|
| 418 | commentWhitespace();
|
|---|
| 419 | if (!identifier()) break;
|
|---|
| 420 | ch = commentWhitespace();
|
|---|
| 421 | }
|
|---|
| 422 | else if (ch === 91/*[*/) {
|
|---|
| 423 | pos++;
|
|---|
| 424 | ch = commentWhitespace();
|
|---|
| 425 | if (ch === 39/*'*/ || ch === 34/*"*/) stringLiteral(ch);
|
|---|
| 426 | else break;
|
|---|
| 427 | pos++;
|
|---|
| 428 | ch = commentWhitespace();
|
|---|
| 429 | if (ch !== 93/*]*/) break;
|
|---|
| 430 | pos++;
|
|---|
| 431 | ch = commentWhitespace();
|
|---|
| 432 | }
|
|---|
| 433 | if (ch === 59/*;*/) {
|
|---|
| 434 | pos++;
|
|---|
| 435 | ch = commentWhitespace();
|
|---|
| 436 | }
|
|---|
| 437 | if (ch !== 125/*}*/) break;
|
|---|
| 438 | pos++;
|
|---|
| 439 | ch = commentWhitespace();
|
|---|
| 440 | if (ch === 44/*,*/) {
|
|---|
| 441 | pos++;
|
|---|
| 442 | ch = commentWhitespace();
|
|---|
| 443 | }
|
|---|
| 444 | if (ch !== 125/*}*/) break;
|
|---|
| 445 | pos++;
|
|---|
| 446 | ch = commentWhitespace();
|
|---|
| 447 | if (ch !== 41/*)*/) break;
|
|---|
| 448 | _exports.add(decode(expt));
|
|---|
| 449 | return;
|
|---|
| 450 | }
|
|---|
| 451 | break;
|
|---|
| 452 | }
|
|---|
| 453 | if (expt) {
|
|---|
| 454 | unsafeGetters.add(decode(expt));
|
|---|
| 455 | }
|
|---|
| 456 | }
|
|---|
| 457 | else if (keys && ch === 107/*k*/ && source.startsWith('eys', pos + 1)) {
|
|---|
| 458 | while (true) {
|
|---|
| 459 | pos += 4;
|
|---|
| 460 | revertPos = pos - 1;
|
|---|
| 461 | ch = commentWhitespace();
|
|---|
| 462 | if (ch !== 40/*(*/) break;
|
|---|
| 463 | pos++;
|
|---|
| 464 | ch = commentWhitespace();
|
|---|
| 465 | const id_start = pos;
|
|---|
| 466 | if (!identifier()) break;
|
|---|
| 467 | const id = source.slice(id_start, pos);
|
|---|
| 468 | ch = commentWhitespace();
|
|---|
| 469 | if (ch !== 41/*)*/) break;
|
|---|
| 470 |
|
|---|
| 471 | revertPos = pos++;
|
|---|
| 472 | ch = commentWhitespace();
|
|---|
| 473 | if (ch !== 46/*.*/) break;
|
|---|
| 474 | pos++;
|
|---|
| 475 | ch = commentWhitespace();
|
|---|
| 476 | if (ch !== 102/*f*/ || !source.startsWith('orEach', pos + 1)) break;
|
|---|
| 477 | pos += 7;
|
|---|
| 478 | ch = commentWhitespace();
|
|---|
| 479 | revertPos = pos - 1;
|
|---|
| 480 | if (ch !== 40/*(*/) break;
|
|---|
| 481 | pos++;
|
|---|
| 482 | ch = commentWhitespace();
|
|---|
| 483 | if (ch !== 102/*f*/ || !source.startsWith('unction', pos + 1)) break;
|
|---|
| 484 | pos += 8;
|
|---|
| 485 | ch = commentWhitespace();
|
|---|
| 486 | if (ch !== 40/*(*/) break;
|
|---|
| 487 | pos++;
|
|---|
| 488 | ch = commentWhitespace();
|
|---|
| 489 | const it_id_start = pos;
|
|---|
| 490 | if (!identifier()) break;
|
|---|
| 491 | const it_id = source.slice(it_id_start, pos);
|
|---|
| 492 | ch = commentWhitespace();
|
|---|
| 493 | if (ch !== 41/*)*/) break;
|
|---|
| 494 | pos++;
|
|---|
| 495 | ch = commentWhitespace();
|
|---|
| 496 | if (ch !== 123/*{*/) break;
|
|---|
| 497 | pos++;
|
|---|
| 498 | ch = commentWhitespace();
|
|---|
| 499 | if (ch !== 105/*i*/ || source.charCodeAt(pos + 1) !== 102/*f*/) break;
|
|---|
| 500 | pos += 2;
|
|---|
| 501 | ch = commentWhitespace();
|
|---|
| 502 | if (ch !== 40/*(*/) break;
|
|---|
| 503 | pos++;
|
|---|
| 504 | ch = commentWhitespace();
|
|---|
| 505 | if (!source.startsWith(it_id, pos)) break;
|
|---|
| 506 | pos += it_id.length;
|
|---|
| 507 | ch = commentWhitespace();
|
|---|
| 508 | // `if (` IDENTIFIER$2 `===` ( `'default'` | `"default"` ) `||` IDENTIFIER$2 `===` ( '__esModule' | `"__esModule"` ) `) return` `;`? |
|
|---|
| 509 | if (ch === 61/*=*/) {
|
|---|
| 510 | if (!source.startsWith('==', pos + 1)) break;
|
|---|
| 511 | pos += 3;
|
|---|
| 512 | ch = commentWhitespace();
|
|---|
| 513 | if (ch !== 34/*"*/ && ch !== 39/*'*/) break;
|
|---|
| 514 | let quot = ch;
|
|---|
| 515 | if (!source.startsWith('default', pos + 1)) break;
|
|---|
| 516 | pos += 8;
|
|---|
| 517 | ch = commentWhitespace();
|
|---|
| 518 | if (ch !== quot) break;
|
|---|
| 519 | pos += 1;
|
|---|
| 520 | ch = commentWhitespace();
|
|---|
| 521 | if (ch !== 124/*|*/ || source.charCodeAt(pos + 1) !== 124/*|*/) break;
|
|---|
| 522 | pos += 2;
|
|---|
| 523 | ch = commentWhitespace();
|
|---|
| 524 | if (source.slice(pos, pos + it_id.length) !== it_id) break;
|
|---|
| 525 | pos += it_id.length;
|
|---|
| 526 | ch = commentWhitespace();
|
|---|
| 527 | if (ch !== 61/*=*/ || source.slice(pos + 1, pos + 3) !== '==') break;
|
|---|
| 528 | pos += 3;
|
|---|
| 529 | ch = commentWhitespace();
|
|---|
| 530 | if (ch !== 34/*"*/ && ch !== 39/*'*/) break;
|
|---|
| 531 | quot = ch;
|
|---|
| 532 | if (!source.startsWith('__esModule', pos + 1)) break;
|
|---|
| 533 | pos += 11;
|
|---|
| 534 | ch = commentWhitespace();
|
|---|
| 535 | if (ch !== quot) break;
|
|---|
| 536 | pos += 1;
|
|---|
| 537 | ch = commentWhitespace();
|
|---|
| 538 | if (ch !== 41/*)*/) break;
|
|---|
| 539 | pos += 1;
|
|---|
| 540 | ch = commentWhitespace();
|
|---|
| 541 | if (ch !== 114/*r*/ || !source.startsWith('eturn', pos + 1)) break;
|
|---|
| 542 | pos += 6;
|
|---|
| 543 | ch = commentWhitespace();
|
|---|
| 544 | if (ch === 59/*;*/)
|
|---|
| 545 | pos++;
|
|---|
| 546 | ch = commentWhitespace();
|
|---|
| 547 |
|
|---|
| 548 | // `if (`
|
|---|
| 549 | if (ch === 105/*i*/ && source.charCodeAt(pos + 1) === 102/*f*/) {
|
|---|
| 550 | let inIf = true;
|
|---|
| 551 | pos += 2;
|
|---|
| 552 | ch = commentWhitespace();
|
|---|
| 553 | if (ch !== 40/*(*/) break;
|
|---|
| 554 | pos++;
|
|---|
| 555 | const ifInnerPos = pos;
|
|---|
| 556 | // `Object.prototype.hasOwnProperty.call(` IDENTIFIER `, ` IDENTIFIER$2 `)) return` `;`?
|
|---|
| 557 | if (tryParseObjectHasOwnProperty(it_id)) {
|
|---|
| 558 | ch = commentWhitespace();
|
|---|
| 559 | if (ch !== 41/*)*/) break;
|
|---|
| 560 | pos++;
|
|---|
| 561 | ch = commentWhitespace();
|
|---|
| 562 | if (ch !== 114/*r*/ || !source.startsWith('eturn', pos + 1)) break;
|
|---|
| 563 | pos += 6;
|
|---|
| 564 | ch = commentWhitespace();
|
|---|
| 565 | if (ch === 59/*;*/)
|
|---|
| 566 | pos++;
|
|---|
| 567 | ch = commentWhitespace();
|
|---|
| 568 | // match next if
|
|---|
| 569 | if (ch === 105/*i*/ && source.charCodeAt(pos + 1) === 102/*f*/) {
|
|---|
| 570 | pos += 2;
|
|---|
| 571 | ch = commentWhitespace();
|
|---|
| 572 | if (ch !== 40/*(*/) break;
|
|---|
| 573 | pos++;
|
|---|
| 574 | }
|
|---|
| 575 | else {
|
|---|
| 576 | inIf = false;
|
|---|
| 577 | }
|
|---|
| 578 | }
|
|---|
| 579 | else {
|
|---|
| 580 | pos = ifInnerPos;
|
|---|
| 581 | }
|
|---|
| 582 |
|
|---|
| 583 | // IDENTIFIER$2 `in` EXPORTS_IDENTIFIER `&&` EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] ===` IDENTIFIER$1 `[` IDENTIFIER$2 `]) return` `;`?
|
|---|
| 584 | if (inIf) {
|
|---|
| 585 | if (!source.startsWith(it_id, pos)) break;
|
|---|
| 586 | pos += it_id.length;
|
|---|
| 587 | ch = commentWhitespace();
|
|---|
| 588 | if (ch !== 105/*i*/ || !source.startsWith('n ', pos + 1)) break;
|
|---|
| 589 | pos += 3;
|
|---|
| 590 | ch = commentWhitespace();
|
|---|
| 591 | if (!readExportsOrModuleDotExports(ch)) break;
|
|---|
| 592 | ch = commentWhitespace();
|
|---|
| 593 | if (ch !== 38/*&*/ || source.charCodeAt(pos + 1) !== 38/*&*/) break;
|
|---|
| 594 | pos += 2;
|
|---|
| 595 | ch = commentWhitespace();
|
|---|
| 596 | if (!readExportsOrModuleDotExports(ch)) break;
|
|---|
| 597 | ch = commentWhitespace();
|
|---|
| 598 | if (ch !== 91/*[*/) break;
|
|---|
| 599 | pos++;
|
|---|
| 600 | ch = commentWhitespace();
|
|---|
| 601 | if (!source.startsWith(it_id, pos)) break;
|
|---|
| 602 | pos += it_id.length;
|
|---|
| 603 | ch = commentWhitespace();
|
|---|
| 604 | if (ch !== 93/*]*/) break;
|
|---|
| 605 | pos++;
|
|---|
| 606 | ch = commentWhitespace();
|
|---|
| 607 | if (ch !== 61/*=*/ || !source.startsWith('==', pos + 1)) break;
|
|---|
| 608 | pos += 3;
|
|---|
| 609 | ch = commentWhitespace();
|
|---|
| 610 | if (!source.startsWith(id, pos)) break;
|
|---|
| 611 | pos += id.length;
|
|---|
| 612 | ch = commentWhitespace();
|
|---|
| 613 | if (ch !== 91/*[*/) break;
|
|---|
| 614 | pos++;
|
|---|
| 615 | ch = commentWhitespace();
|
|---|
| 616 | if (!source.startsWith(it_id, pos)) break;
|
|---|
| 617 | pos += it_id.length;
|
|---|
| 618 | ch = commentWhitespace();
|
|---|
| 619 | if (ch !== 93/*]*/) break;
|
|---|
| 620 | pos++;
|
|---|
| 621 | ch = commentWhitespace();
|
|---|
| 622 | if (ch !== 41/*)*/) break;
|
|---|
| 623 | pos++;
|
|---|
| 624 | ch = commentWhitespace();
|
|---|
| 625 | if (ch !== 114/*r*/ || !source.startsWith('eturn', pos + 1)) break;
|
|---|
| 626 | pos += 6;
|
|---|
| 627 | ch = commentWhitespace();
|
|---|
| 628 | if (ch === 59/*;*/)
|
|---|
| 629 | pos++;
|
|---|
| 630 | ch = commentWhitespace();
|
|---|
| 631 | }
|
|---|
| 632 | }
|
|---|
| 633 | }
|
|---|
| 634 | // `if (` IDENTIFIER$2 `!==` ( `'default'` | `"default"` ) (`&& !` IDENTIFIER `.hasOwnProperty(` IDENTIFIER$2 `)` )? `)`
|
|---|
| 635 | else if (ch === 33/*!*/) {
|
|---|
| 636 | if (!source.startsWith('==', pos + 1)) break;
|
|---|
| 637 | pos += 3;
|
|---|
| 638 | ch = commentWhitespace();
|
|---|
| 639 | if (ch !== 34/*"*/ && ch !== 39/*'*/) break;
|
|---|
| 640 | const quot = ch;
|
|---|
| 641 | if (!source.startsWith('default', pos + 1)) break;
|
|---|
| 642 | pos += 8;
|
|---|
| 643 | ch = commentWhitespace();
|
|---|
| 644 | if (ch !== quot) break;
|
|---|
| 645 | pos += 1;
|
|---|
| 646 | ch = commentWhitespace();
|
|---|
| 647 | if (ch === 38/*&*/) {
|
|---|
| 648 | if (source.charCodeAt(pos + 1) !== 38/*&*/) break;
|
|---|
| 649 | pos += 2;
|
|---|
| 650 | ch = commentWhitespace();
|
|---|
| 651 | if (ch !== 33/*!*/) break;
|
|---|
| 652 | pos += 1;
|
|---|
| 653 | ch = commentWhitespace();
|
|---|
| 654 | if (ch === 79/*O*/ && source.startsWith('bject', pos + 1) && source[pos + 6] === '.') {
|
|---|
| 655 | if (!tryParseObjectHasOwnProperty(it_id)) break;
|
|---|
| 656 | }
|
|---|
| 657 | else if (identifier()) {
|
|---|
| 658 | ch = commentWhitespace();
|
|---|
| 659 | if (ch !== 46/*.*/) break;
|
|---|
| 660 | pos++;
|
|---|
| 661 | ch = commentWhitespace();
|
|---|
| 662 | if (ch !== 104/*h*/ || !source.startsWith('asOwnProperty', pos + 1)) break;
|
|---|
| 663 | pos += 14;
|
|---|
| 664 | ch = commentWhitespace();
|
|---|
| 665 | if (ch !== 40/*(*/) break;
|
|---|
| 666 | pos += 1;
|
|---|
| 667 | ch = commentWhitespace();
|
|---|
| 668 | if (!source.startsWith(it_id, pos)) break;
|
|---|
| 669 | pos += it_id.length;
|
|---|
| 670 | ch = commentWhitespace();
|
|---|
| 671 | if (ch !== 41/*)*/) break;
|
|---|
| 672 | pos += 1;
|
|---|
| 673 | }
|
|---|
| 674 | else break;
|
|---|
| 675 | ch = commentWhitespace();
|
|---|
| 676 | }
|
|---|
| 677 | if (ch !== 41/*)*/) break;
|
|---|
| 678 | pos += 1;
|
|---|
| 679 | ch = commentWhitespace();
|
|---|
| 680 | }
|
|---|
| 681 | else break;
|
|---|
| 682 |
|
|---|
| 683 | // EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] =` IDENTIFIER$1 `[` IDENTIFIER$2 `]`
|
|---|
| 684 | if (readExportsOrModuleDotExports(ch)) {
|
|---|
| 685 | ch = commentWhitespace();
|
|---|
| 686 | if (ch !== 91/*[*/) break;
|
|---|
| 687 | pos++;
|
|---|
| 688 | ch = commentWhitespace();
|
|---|
| 689 | if (source.slice(pos, pos + it_id.length) !== it_id) break;
|
|---|
| 690 | pos += it_id.length;
|
|---|
| 691 | ch = commentWhitespace();
|
|---|
| 692 | if (ch !== 93/*]*/) break;
|
|---|
| 693 | pos++;
|
|---|
| 694 | ch = commentWhitespace();
|
|---|
| 695 | if (ch !== 61/*=*/) break;
|
|---|
| 696 | pos++;
|
|---|
| 697 | ch = commentWhitespace();
|
|---|
| 698 | if (source.slice(pos, pos + id.length) !== id) break;
|
|---|
| 699 | pos += id.length;
|
|---|
| 700 | ch = commentWhitespace();
|
|---|
| 701 | if (ch !== 91/*[*/) break;
|
|---|
| 702 | pos++;
|
|---|
| 703 | ch = commentWhitespace();
|
|---|
| 704 | if (source.slice(pos, pos + it_id.length) !== it_id) break;
|
|---|
| 705 | pos += it_id.length;
|
|---|
| 706 | ch = commentWhitespace();
|
|---|
| 707 | if (ch !== 93/*]*/) break;
|
|---|
| 708 | pos++;
|
|---|
| 709 | ch = commentWhitespace();
|
|---|
| 710 | if (ch === 59/*;*/) {
|
|---|
| 711 | pos++;
|
|---|
| 712 | ch = commentWhitespace();
|
|---|
| 713 | }
|
|---|
| 714 | }
|
|---|
| 715 | // `Object.defineProperty(` EXPORTS_IDENTIFIER `, ` IDENTIFIER$2 `, { enumerable: true, get: function () { return ` IDENTIFIER$1 `[` IDENTIFIER$2 `]; } })`
|
|---|
| 716 | else if (ch === 79/*O*/) {
|
|---|
| 717 | if (source.slice(pos + 1, pos + 6) !== 'bject') break;
|
|---|
| 718 | pos += 6;
|
|---|
| 719 | ch = commentWhitespace();
|
|---|
| 720 | if (ch !== 46/*.*/) break;
|
|---|
| 721 | pos++;
|
|---|
| 722 | ch = commentWhitespace();
|
|---|
| 723 | if (ch !== 100/*d*/ || !source.startsWith('efineProperty', pos + 1)) break;
|
|---|
| 724 | pos += 14;
|
|---|
| 725 | ch = commentWhitespace();
|
|---|
| 726 | if (ch !== 40/*(*/) break;
|
|---|
| 727 | pos++;
|
|---|
| 728 | ch = commentWhitespace();
|
|---|
| 729 | if (!readExportsOrModuleDotExports(ch)) break;
|
|---|
| 730 | ch = commentWhitespace();
|
|---|
| 731 | if (ch !== 44/*,*/) break;
|
|---|
| 732 | pos++;
|
|---|
| 733 | ch = commentWhitespace();
|
|---|
| 734 | if (!source.startsWith(it_id, pos)) break;
|
|---|
| 735 | pos += it_id.length;
|
|---|
| 736 | ch = commentWhitespace();
|
|---|
| 737 | if (ch !== 44/*,*/) break;
|
|---|
| 738 | pos++;
|
|---|
| 739 | ch = commentWhitespace();
|
|---|
| 740 | if (ch !== 123/*{*/) break;
|
|---|
| 741 | pos++;
|
|---|
| 742 | ch = commentWhitespace();
|
|---|
| 743 | if (ch !== 101/*e*/ || !source.startsWith('numerable', pos + 1)) break;
|
|---|
| 744 | pos += 10;
|
|---|
| 745 | ch = commentWhitespace();
|
|---|
| 746 | if (ch !== 58/*:*/) break;
|
|---|
| 747 | pos++;
|
|---|
| 748 | ch = commentWhitespace();
|
|---|
| 749 | if (ch !== 116/*t*/ && !source.startsWith('rue', pos + 1)) break;
|
|---|
| 750 | pos += 4;
|
|---|
| 751 | ch = commentWhitespace();
|
|---|
| 752 | if (ch !== 44/*,*/) break;
|
|---|
| 753 | pos++;
|
|---|
| 754 | ch = commentWhitespace();
|
|---|
| 755 | if (ch !== 103/*g*/ || !source.startsWith('et', pos + 1)) break;
|
|---|
| 756 | pos += 3;
|
|---|
| 757 | ch = commentWhitespace();
|
|---|
| 758 | if (ch === 58/*:*/) {
|
|---|
| 759 | pos++;
|
|---|
| 760 | ch = commentWhitespace();
|
|---|
| 761 | if (ch !== 102/*f*/) break;
|
|---|
| 762 | if (!source.startsWith('unction', pos + 1)) break;
|
|---|
| 763 | pos += 8;
|
|---|
| 764 | let lastPos = pos;
|
|---|
| 765 | ch = commentWhitespace();
|
|---|
| 766 | if (ch !== 40 && (lastPos === pos || !identifier())) break;
|
|---|
| 767 | ch = commentWhitespace();
|
|---|
| 768 | }
|
|---|
| 769 | if (ch !== 40/*(*/) break;
|
|---|
| 770 | pos++;
|
|---|
| 771 | ch = commentWhitespace();
|
|---|
| 772 | if (ch !== 41/*)*/) break;
|
|---|
| 773 | pos++;
|
|---|
| 774 | ch = commentWhitespace();
|
|---|
| 775 | if (ch !== 123/*{*/) break;
|
|---|
| 776 | pos++;
|
|---|
| 777 | ch = commentWhitespace();
|
|---|
| 778 | if (ch !== 114/*r*/ || !source.startsWith('eturn', pos + 1)) break;
|
|---|
| 779 | pos += 6;
|
|---|
| 780 | ch = commentWhitespace();
|
|---|
| 781 | if (!source.startsWith(id, pos)) break;
|
|---|
| 782 | pos += id.length;
|
|---|
| 783 | ch = commentWhitespace();
|
|---|
| 784 | if (ch !== 91/*[*/) break;
|
|---|
| 785 | pos++;
|
|---|
| 786 | ch = commentWhitespace();
|
|---|
| 787 | if (!source.startsWith(it_id, pos)) break;
|
|---|
| 788 | pos += it_id.length;
|
|---|
| 789 | ch = commentWhitespace();
|
|---|
| 790 | if (ch !== 93/*]*/) break;
|
|---|
| 791 | pos++;
|
|---|
| 792 | ch = commentWhitespace();
|
|---|
| 793 | if (ch === 59/*;*/) {
|
|---|
| 794 | pos++;
|
|---|
| 795 | ch = commentWhitespace();
|
|---|
| 796 | }
|
|---|
| 797 | if (ch !== 125/*}*/) break;
|
|---|
| 798 | pos++;
|
|---|
| 799 | ch = commentWhitespace();
|
|---|
| 800 | if (ch === 44/*,*/) {
|
|---|
| 801 | pos++;
|
|---|
| 802 | ch = commentWhitespace();
|
|---|
| 803 | }
|
|---|
| 804 | if (ch !== 125/*}*/) break;
|
|---|
| 805 | pos++;
|
|---|
| 806 | ch = commentWhitespace();
|
|---|
| 807 | if (ch !== 41/*)*/) break;
|
|---|
| 808 | pos++;
|
|---|
| 809 | ch = commentWhitespace();
|
|---|
| 810 | if (ch === 59/*;*/) {
|
|---|
| 811 | pos++;
|
|---|
| 812 | ch = commentWhitespace();
|
|---|
| 813 | }
|
|---|
| 814 | }
|
|---|
| 815 | else break;
|
|---|
| 816 |
|
|---|
| 817 | if (ch !== 125/*}*/) break;
|
|---|
| 818 | pos++;
|
|---|
| 819 | ch = commentWhitespace();
|
|---|
| 820 | if (ch !== 41/*)*/) break;
|
|---|
| 821 |
|
|---|
| 822 | const starExportSpecifier = starExportMap[id];
|
|---|
| 823 | if (starExportSpecifier) {
|
|---|
| 824 | reexports.add(decode(starExportSpecifier));
|
|---|
| 825 | pos = revertPos;
|
|---|
| 826 | return;
|
|---|
| 827 | }
|
|---|
| 828 | return;
|
|---|
| 829 | }
|
|---|
| 830 | }
|
|---|
| 831 | }
|
|---|
| 832 | pos = revertPos;
|
|---|
| 833 | }
|
|---|
| 834 |
|
|---|
| 835 | function readExportsOrModuleDotExports (ch) {
|
|---|
| 836 | const revertPos = pos;
|
|---|
| 837 | if (ch === 109/*m*/ && source.startsWith('odule', pos + 1)) {
|
|---|
| 838 | pos += 6;
|
|---|
| 839 | ch = commentWhitespace();
|
|---|
| 840 | if (ch !== 46/*.*/) {
|
|---|
| 841 | pos = revertPos;
|
|---|
| 842 | return false;
|
|---|
| 843 | }
|
|---|
| 844 | pos++;
|
|---|
| 845 | ch = commentWhitespace();
|
|---|
| 846 | }
|
|---|
| 847 | if (ch === 101/*e*/ && source.startsWith('xports', pos + 1)) {
|
|---|
| 848 | pos += 7;
|
|---|
| 849 | return true;
|
|---|
| 850 | }
|
|---|
| 851 | else {
|
|---|
| 852 | pos = revertPos;
|
|---|
| 853 | return false;
|
|---|
| 854 | }
|
|---|
| 855 | }
|
|---|
| 856 |
|
|---|
| 857 | function tryParseModuleExportsDotAssign () {
|
|---|
| 858 | pos += 6;
|
|---|
| 859 | const revertPos = pos - 1;
|
|---|
| 860 | let ch = commentWhitespace();
|
|---|
| 861 | if (ch === 46/*.*/) {
|
|---|
| 862 | pos++;
|
|---|
| 863 | ch = commentWhitespace();
|
|---|
| 864 | if (ch === 101/*e*/ && source.startsWith('xports', pos + 1)) {
|
|---|
| 865 | tryParseExportsDotAssign(true);
|
|---|
| 866 | return;
|
|---|
| 867 | }
|
|---|
| 868 | }
|
|---|
| 869 | pos = revertPos;
|
|---|
| 870 | }
|
|---|
| 871 |
|
|---|
| 872 | function tryParseExportsDotAssign (assign) {
|
|---|
| 873 | pos += 7;
|
|---|
| 874 | const revertPos = pos - 1;
|
|---|
| 875 | let ch = commentWhitespace();
|
|---|
| 876 | switch (ch) {
|
|---|
| 877 | // exports.asdf
|
|---|
| 878 | case 46/*.*/: {
|
|---|
| 879 | pos++;
|
|---|
| 880 | ch = commentWhitespace();
|
|---|
| 881 | const startPos = pos;
|
|---|
| 882 | if (identifier()) {
|
|---|
| 883 | const endPos = pos;
|
|---|
| 884 | ch = commentWhitespace();
|
|---|
| 885 | if (ch === 61/*=*/) {
|
|---|
| 886 | _exports.add(decode(source.slice(startPos, endPos)));
|
|---|
| 887 | return;
|
|---|
| 888 | }
|
|---|
| 889 | }
|
|---|
| 890 | break;
|
|---|
| 891 | }
|
|---|
| 892 | // exports['asdf']
|
|---|
| 893 | case 91/*[*/: {
|
|---|
| 894 | pos++;
|
|---|
| 895 | ch = commentWhitespace();
|
|---|
| 896 | if (ch === 39/*'*/ || ch === 34/*"*/) {
|
|---|
| 897 | const startPos = pos;
|
|---|
| 898 | stringLiteral(ch);
|
|---|
| 899 | const endPos = ++pos;
|
|---|
| 900 | ch = commentWhitespace();
|
|---|
| 901 | if (ch !== 93/*]*/) break;
|
|---|
| 902 | pos++;
|
|---|
| 903 | ch = commentWhitespace();
|
|---|
| 904 | if (ch !== 61/*=*/) break;
|
|---|
| 905 | _exports.add(decode(source.slice(startPos, endPos)));
|
|---|
| 906 | }
|
|---|
| 907 | break;
|
|---|
| 908 | }
|
|---|
| 909 | // module.exports =
|
|---|
| 910 | case 61/*=*/: {
|
|---|
| 911 | if (assign) {
|
|---|
| 912 | if (reexports.size)
|
|---|
| 913 | reexports = new Set();
|
|---|
| 914 | pos++;
|
|---|
| 915 | ch = commentWhitespace();
|
|---|
| 916 | // { ... }
|
|---|
| 917 | if (ch === 123/*{*/) {
|
|---|
| 918 | tryParseLiteralExports();
|
|---|
| 919 | return;
|
|---|
| 920 | }
|
|---|
| 921 |
|
|---|
| 922 | // require('...')
|
|---|
| 923 | if (ch === 114/*r*/)
|
|---|
| 924 | tryParseRequire(ExportAssign);
|
|---|
| 925 | }
|
|---|
| 926 | }
|
|---|
| 927 | }
|
|---|
| 928 | pos = revertPos;
|
|---|
| 929 | }
|
|---|
| 930 |
|
|---|
| 931 | function tryParseRequire (requireType) {
|
|---|
| 932 | // require('...')
|
|---|
| 933 | const revertPos = pos;
|
|---|
| 934 | if (source.startsWith('equire', pos + 1)) {
|
|---|
| 935 | pos += 7;
|
|---|
| 936 | let ch = commentWhitespace();
|
|---|
| 937 | if (ch === 40/*(*/) {
|
|---|
| 938 | pos++;
|
|---|
| 939 | ch = commentWhitespace();
|
|---|
| 940 | const reexportStart = pos;
|
|---|
| 941 | if (ch === 39/*'*/ || ch === 34/*"*/) {
|
|---|
| 942 | stringLiteral(ch);
|
|---|
| 943 | const reexportEnd = ++pos;
|
|---|
| 944 | ch = commentWhitespace();
|
|---|
| 945 | if (ch === 41/*)*/) {
|
|---|
| 946 | switch (requireType) {
|
|---|
| 947 | case ExportAssign:
|
|---|
| 948 | reexports.add(decode(source.slice(reexportStart, reexportEnd)));
|
|---|
| 949 | return true;
|
|---|
| 950 | case ExportStar:
|
|---|
| 951 | reexports.add(decode(source.slice(reexportStart, reexportEnd)));
|
|---|
| 952 | return true;
|
|---|
| 953 | default:
|
|---|
| 954 | lastStarExportSpecifier = decode(source.slice(reexportStart, reexportEnd));
|
|---|
| 955 | return true;
|
|---|
| 956 | }
|
|---|
| 957 | }
|
|---|
| 958 | }
|
|---|
| 959 | }
|
|---|
| 960 | pos = revertPos;
|
|---|
| 961 | }
|
|---|
| 962 | return false;
|
|---|
| 963 | }
|
|---|
| 964 |
|
|---|
| 965 | function tryParseLiteralExports () {
|
|---|
| 966 | const revertPos = pos - 1;
|
|---|
| 967 | while (pos++ < end) {
|
|---|
| 968 | let ch = commentWhitespace();
|
|---|
| 969 | const startPos = pos;
|
|---|
| 970 | if (identifier()) {
|
|---|
| 971 | const endPos = pos;
|
|---|
| 972 | ch = commentWhitespace();
|
|---|
| 973 | if (ch === 58/*:*/) {
|
|---|
| 974 | pos++;
|
|---|
| 975 | ch = commentWhitespace();
|
|---|
| 976 | // nothing more complex than identifier expressions for now
|
|---|
| 977 | if (!identifier()) {
|
|---|
| 978 | pos = revertPos;
|
|---|
| 979 | return;
|
|---|
| 980 | }
|
|---|
| 981 | ch = source.charCodeAt(pos);
|
|---|
| 982 | }
|
|---|
| 983 | _exports.add(decode(source.slice(startPos, endPos)));
|
|---|
| 984 | }
|
|---|
| 985 | else if (ch === 46/*.*/ && source.startsWith('..', pos + 1)) {
|
|---|
| 986 | pos += 3;
|
|---|
| 987 | if (source.charCodeAt(pos) === 114/*r*/ && tryParseRequire(ExportAssign)) {
|
|---|
| 988 | pos++;
|
|---|
| 989 | }
|
|---|
| 990 | else if (!identifier()) {
|
|---|
| 991 | pos = revertPos;
|
|---|
| 992 | return;
|
|---|
| 993 | }
|
|---|
| 994 | ch = commentWhitespace();
|
|---|
| 995 | }
|
|---|
| 996 | else if (ch === 39/*'*/ || ch === 34/*"*/) {
|
|---|
| 997 | const startPos = pos;
|
|---|
| 998 | stringLiteral(ch);
|
|---|
| 999 | const endPos = ++pos;
|
|---|
| 1000 | ch = commentWhitespace();
|
|---|
| 1001 | if (ch === 58/*:*/) {
|
|---|
| 1002 | pos++;
|
|---|
| 1003 | ch = commentWhitespace();
|
|---|
| 1004 | // nothing more complex than identifier expressions for now
|
|---|
| 1005 | if (!identifier()) {
|
|---|
| 1006 | pos = revertPos;
|
|---|
| 1007 | return;
|
|---|
| 1008 | }
|
|---|
| 1009 | ch = source.charCodeAt(pos);
|
|---|
| 1010 | _exports.add(decode(source.slice(startPos, endPos)));
|
|---|
| 1011 | }
|
|---|
| 1012 | }
|
|---|
| 1013 | else {
|
|---|
| 1014 | pos = revertPos;
|
|---|
| 1015 | return;
|
|---|
| 1016 | }
|
|---|
| 1017 |
|
|---|
| 1018 | if (ch === 125/*}*/)
|
|---|
| 1019 | return;
|
|---|
| 1020 |
|
|---|
| 1021 | if (ch !== 44/*,*/) {
|
|---|
| 1022 | pos = revertPos;
|
|---|
| 1023 | return;
|
|---|
| 1024 | }
|
|---|
| 1025 | }
|
|---|
| 1026 | }
|
|---|
| 1027 |
|
|---|
| 1028 | // --- Extracted from AcornJS ---
|
|---|
| 1029 | //(https://github.com/acornjs/acorn/blob/master/acorn/src/identifier.js#L23
|
|---|
| 1030 | //
|
|---|
| 1031 | // MIT License
|
|---|
| 1032 |
|
|---|
| 1033 | // Copyright (C) 2012-2018 by various contributors (see AUTHORS)
|
|---|
| 1034 |
|
|---|
| 1035 | // Permission is hereby granted, free of charge, to any person obtaining a copy
|
|---|
| 1036 | // of this software and associated documentation files (the "Software"), to deal
|
|---|
| 1037 | // in the Software without restriction, including without limitation the rights
|
|---|
| 1038 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|---|
| 1039 | // copies of the Software, and to permit persons to whom the Software is
|
|---|
| 1040 | // furnished to do so, subject to the following conditions:
|
|---|
| 1041 |
|
|---|
| 1042 | // The above copyright notice and this permission notice shall be included in
|
|---|
| 1043 | // all copies or substantial portions of the Software.
|
|---|
| 1044 |
|
|---|
| 1045 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|---|
| 1046 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|---|
| 1047 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|---|
| 1048 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|---|
| 1049 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|---|
| 1050 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|---|
| 1051 | // THE SOFTWARE.
|
|---|
| 1052 |
|
|---|
| 1053 | // ## Character categories
|
|---|
| 1054 |
|
|---|
| 1055 | // Big ugly regular expressions that match characters in the
|
|---|
| 1056 | // whitespace, identifier, and identifier-start categories. These
|
|---|
| 1057 | // are only applied when a character is found to actually have a
|
|---|
| 1058 | // code point above 128.
|
|---|
| 1059 | // Generated by `bin/generate-identifier-regex.js`.
|
|---|
| 1060 | let nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u0860-\u086a\u08a0-\u08b4\u08b6-\u08c7\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u09fc\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d04-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31bf\u31f0-\u31ff\u3400-\u4dbf\u4e00-\u9ffc\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7bf\ua7c2-\ua7ca\ua7f5-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab69\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc"
|
|---|
| 1061 | let nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08d3-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b55-\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d81-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1abf\u1ac0\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf4\u1cf7-\u1cf9\u1dc0-\u1df9\u1dfb-\u1dff\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua82c\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f"
|
|---|
| 1062 |
|
|---|
| 1063 | const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]")
|
|---|
| 1064 | const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]")
|
|---|
| 1065 |
|
|---|
| 1066 | nonASCIIidentifierStartChars = nonASCIIidentifierChars = null
|
|---|
| 1067 |
|
|---|
| 1068 | // These are a run-length and offset encoded representation of the
|
|---|
| 1069 | // >0xffff code points that are a valid part of identifiers. The
|
|---|
| 1070 | // offset starts at 0x10000, and each pair of numbers represents an
|
|---|
| 1071 | // offset to the next range, and then a size of the range. They were
|
|---|
| 1072 | // generated by bin/generate-identifier-regex.js
|
|---|
| 1073 |
|
|---|
| 1074 | // eslint-disable-next-line comma-spacing
|
|---|
| 1075 | const astralIdentifierStartCodes = [0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,14,29,6,37,11,29,3,35,5,7,2,4,43,157,19,35,5,35,5,39,9,51,157,310,10,21,11,7,153,5,3,0,2,43,2,1,4,0,3,22,11,22,10,30,66,18,2,1,11,21,11,25,71,55,7,1,65,0,16,3,2,2,2,28,43,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,14,35,349,41,7,1,79,28,11,0,9,21,107,20,28,22,13,52,76,44,33,24,27,35,30,0,3,0,9,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,85,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,159,52,19,3,21,2,31,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,14,0,72,26,230,43,117,63,32,7,3,0,3,7,2,1,2,23,16,0,2,0,95,7,3,38,17,0,2,0,29,0,11,39,8,0,22,0,12,45,20,0,35,56,264,8,2,36,18,0,50,29,113,6,2,1,2,37,22,0,26,5,2,1,2,31,15,0,328,18,190,0,80,921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,689,63,129,74,6,0,67,12,65,1,2,0,29,6135,9,1237,43,8,8952,286,50,2,18,3,9,395,2309,106,6,12,4,8,8,9,5991,84,2,70,2,1,3,0,3,1,3,3,2,11,2,0,2,6,2,64,2,3,3,7,2,6,2,27,2,3,2,4,2,0,4,6,2,339,3,24,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,7,2357,44,11,6,17,0,370,43,1301,196,60,67,8,0,1205,3,2,26,2,1,2,0,3,0,2,9,2,3,2,0,2,0,7,0,5,0,2,0,2,0,2,2,2,1,2,0,3,0,2,0,2,0,2,0,2,0,2,1,2,0,3,3,2,6,2,3,2,3,2,0,2,9,2,16,6,2,2,4,2,16,4421,42717,35,4148,12,221,3,5761,15,7472,3104,541,1507,4938]
|
|---|
| 1076 |
|
|---|
| 1077 | // eslint-disable-next-line comma-spacing
|
|---|
| 1078 | const astralIdentifierCodes = [509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,574,3,9,9,370,1,154,10,176,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,6,1,45,0,13,2,49,13,9,3,2,11,83,11,7,0,161,11,6,9,7,3,56,1,2,6,3,1,3,2,10,0,11,1,3,6,4,4,193,17,10,9,5,0,82,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,84,14,5,9,243,14,166,9,71,5,2,1,3,3,2,0,2,1,13,9,120,6,3,6,4,0,29,9,41,6,2,3,9,0,10,10,47,15,406,7,2,7,17,9,57,21,2,13,123,5,4,0,2,1,2,6,2,0,9,9,49,4,2,1,2,4,9,9,330,3,19306,9,135,4,60,6,26,9,1014,0,2,54,8,3,82,0,12,1,19628,1,5319,4,4,5,9,7,3,6,31,3,149,2,1418,49,513,54,5,49,9,0,15,0,23,4,2,14,1361,6,2,16,3,6,2,1,2,4,262,6,10,9,419,13,1495,6,110,6,6,9,4759,9,787719,239]
|
|---|
| 1079 |
|
|---|
| 1080 | // This has a complexity linear to the value of the code. The
|
|---|
| 1081 | // assumption is that looking up astral identifier characters is
|
|---|
| 1082 | // rare.
|
|---|
| 1083 | function isInAstralSet(code, set) {
|
|---|
| 1084 | let pos = 0x10000
|
|---|
| 1085 | for (let i = 0; i < set.length; i += 2) {
|
|---|
| 1086 | pos += set[i]
|
|---|
| 1087 | if (pos > code) return false
|
|---|
| 1088 | pos += set[i + 1]
|
|---|
| 1089 | if (pos >= code) return true
|
|---|
| 1090 | }
|
|---|
| 1091 | }
|
|---|
| 1092 |
|
|---|
| 1093 | // Test whether a given character code starts an identifier.
|
|---|
| 1094 |
|
|---|
| 1095 | function isIdentifierStart(code, astral) {
|
|---|
| 1096 | if (code < 65) return code === 36
|
|---|
| 1097 | if (code < 91) return true
|
|---|
| 1098 | if (code < 97) return code === 95
|
|---|
| 1099 | if (code < 123) return true
|
|---|
| 1100 | if (code <= 0xffff) return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code))
|
|---|
| 1101 | if (astral === false) return false
|
|---|
| 1102 | return isInAstralSet(code, astralIdentifierStartCodes)
|
|---|
| 1103 | }
|
|---|
| 1104 |
|
|---|
| 1105 | // Test whether a given character is part of an identifier.
|
|---|
| 1106 |
|
|---|
| 1107 | function isIdentifierChar(code, astral) {
|
|---|
| 1108 | if (code < 48) return code === 36
|
|---|
| 1109 | if (code < 58) return true
|
|---|
| 1110 | if (code < 65) return false
|
|---|
| 1111 | if (code < 91) return true
|
|---|
| 1112 | if (code < 97) return code === 95
|
|---|
| 1113 | if (code < 123) return true
|
|---|
| 1114 | if (code <= 0xffff) return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code))
|
|---|
| 1115 | if (astral === false) return false
|
|---|
| 1116 | return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes)
|
|---|
| 1117 | }
|
|---|
| 1118 |
|
|---|
| 1119 | function identifier () {
|
|---|
| 1120 | let ch = source.codePointAt(pos);
|
|---|
| 1121 | if (!isIdentifierStart(ch, true) || ch === '\\')
|
|---|
| 1122 | return false;
|
|---|
| 1123 | pos += codePointLen(ch);
|
|---|
| 1124 | while (ch = source.codePointAt(pos)) {
|
|---|
| 1125 | if (isIdentifierChar(ch, true)) {
|
|---|
| 1126 | pos += codePointLen(ch);
|
|---|
| 1127 | }
|
|---|
| 1128 | else if (ch === '\\') {
|
|---|
| 1129 | // no identifier escapes support for now
|
|---|
| 1130 | return false;
|
|---|
| 1131 | }
|
|---|
| 1132 | else {
|
|---|
| 1133 | break;
|
|---|
| 1134 | }
|
|---|
| 1135 | }
|
|---|
| 1136 | return true;
|
|---|
| 1137 | }
|
|---|
| 1138 |
|
|---|
| 1139 | function codePointLen (ch) {
|
|---|
| 1140 | if (ch < 0x10000) return 1;
|
|---|
| 1141 | return 2;
|
|---|
| 1142 | }
|
|---|
| 1143 |
|
|---|
| 1144 | function codePointAtLast (bPos) {
|
|---|
| 1145 | // Gives the UTF char for backtracking surrogates
|
|---|
| 1146 | const ch = source.charCodeAt(bPos);
|
|---|
| 1147 | if ((ch & 0xFC00) === 0xDC00)
|
|---|
| 1148 | return (((source.charCodeAt(bPos - 1) & 0x3FF) << 10) | (ch & 0x3FF)) + 0x10000;
|
|---|
| 1149 | return ch;
|
|---|
| 1150 | }
|
|---|
| 1151 |
|
|---|
| 1152 | function esmSyntaxErr (msg) {
|
|---|
| 1153 | return Object.assign(new Error(msg), { code: 'ERR_LEXER_ESM_SYNTAX' });
|
|---|
| 1154 | }
|
|---|
| 1155 |
|
|---|
| 1156 | function throwIfImportStatement () {
|
|---|
| 1157 | const startPos = pos;
|
|---|
| 1158 | pos += 6;
|
|---|
| 1159 | const ch = commentWhitespace();
|
|---|
| 1160 | switch (ch) {
|
|---|
| 1161 | // dynamic import
|
|---|
| 1162 | case 40/*(*/:
|
|---|
| 1163 | openTokenPosStack[openTokenDepth++] = startPos;
|
|---|
| 1164 | return;
|
|---|
| 1165 | // import.meta
|
|---|
| 1166 | case 46/*.*/:
|
|---|
| 1167 | throw esmSyntaxErr('Unexpected import.meta in CJS module.');
|
|---|
| 1168 |
|
|---|
| 1169 | default:
|
|---|
| 1170 | // no space after "import" -> not an import keyword
|
|---|
| 1171 | if (pos === startPos + 6)
|
|---|
| 1172 | break;
|
|---|
| 1173 | case 34/*"*/:
|
|---|
| 1174 | case 39/*'*/:
|
|---|
| 1175 | case 123/*{*/:
|
|---|
| 1176 | case 42/***/:
|
|---|
| 1177 | // import statement only permitted at base-level
|
|---|
| 1178 | if (openTokenDepth !== 0) {
|
|---|
| 1179 | pos--;
|
|---|
| 1180 | return;
|
|---|
| 1181 | }
|
|---|
| 1182 | // import statements are a syntax error in CommonJS
|
|---|
| 1183 | throw esmSyntaxErr('Unexpected import statement in CJS module.');
|
|---|
| 1184 | }
|
|---|
| 1185 | }
|
|---|
| 1186 |
|
|---|
| 1187 | function throwIfExportStatement () {
|
|---|
| 1188 | pos += 6;
|
|---|
| 1189 | const curPos = pos;
|
|---|
| 1190 | const ch = commentWhitespace();
|
|---|
| 1191 | if (pos === curPos && !isPunctuator(ch))
|
|---|
| 1192 | return;
|
|---|
| 1193 | throw esmSyntaxErr('Unexpected export statement in CJS module.');
|
|---|
| 1194 | }
|
|---|
| 1195 |
|
|---|
| 1196 | function commentWhitespace () {
|
|---|
| 1197 | let ch;
|
|---|
| 1198 | do {
|
|---|
| 1199 | ch = source.charCodeAt(pos);
|
|---|
| 1200 | if (ch === 47/*/*/) {
|
|---|
| 1201 | const next_ch = source.charCodeAt(pos + 1);
|
|---|
| 1202 | if (next_ch === 47/*/*/)
|
|---|
| 1203 | lineComment();
|
|---|
| 1204 | else if (next_ch === 42/***/)
|
|---|
| 1205 | blockComment();
|
|---|
| 1206 | else
|
|---|
| 1207 | return ch;
|
|---|
| 1208 | }
|
|---|
| 1209 | else if (!isBrOrWs(ch)) {
|
|---|
| 1210 | return ch;
|
|---|
| 1211 | }
|
|---|
| 1212 | } while (pos++ < end);
|
|---|
| 1213 | return ch;
|
|---|
| 1214 | }
|
|---|
| 1215 |
|
|---|
| 1216 | function templateString () {
|
|---|
| 1217 | while (pos++ < end) {
|
|---|
| 1218 | const ch = source.charCodeAt(pos);
|
|---|
| 1219 | if (ch === 36/*$*/ && source.charCodeAt(pos + 1) === 123/*{*/) {
|
|---|
| 1220 | pos++;
|
|---|
| 1221 | templateStack[templateStackDepth++] = templateDepth;
|
|---|
| 1222 | templateDepth = ++openTokenDepth;
|
|---|
| 1223 | return;
|
|---|
| 1224 | }
|
|---|
| 1225 | if (ch === 96/*`*/)
|
|---|
| 1226 | return;
|
|---|
| 1227 | if (ch === 92/*\*/)
|
|---|
| 1228 | pos++;
|
|---|
| 1229 | }
|
|---|
| 1230 | syntaxError();
|
|---|
| 1231 | }
|
|---|
| 1232 |
|
|---|
| 1233 | function blockComment () {
|
|---|
| 1234 | pos++;
|
|---|
| 1235 | while (pos++ < end) {
|
|---|
| 1236 | const ch = source.charCodeAt(pos);
|
|---|
| 1237 | if (ch === 42/***/ && source.charCodeAt(pos + 1) === 47/*/*/) {
|
|---|
| 1238 | pos++;
|
|---|
| 1239 | return;
|
|---|
| 1240 | }
|
|---|
| 1241 | }
|
|---|
| 1242 | }
|
|---|
| 1243 |
|
|---|
| 1244 | function lineComment () {
|
|---|
| 1245 | while (pos++ < end) {
|
|---|
| 1246 | const ch = source.charCodeAt(pos);
|
|---|
| 1247 | if (ch === 10/*\n*/ || ch === 13/*\r*/)
|
|---|
| 1248 | return;
|
|---|
| 1249 | }
|
|---|
| 1250 | }
|
|---|
| 1251 |
|
|---|
| 1252 | function stringLiteral (quote) {
|
|---|
| 1253 | while (pos++ < end) {
|
|---|
| 1254 | let ch = source.charCodeAt(pos);
|
|---|
| 1255 | if (ch === quote)
|
|---|
| 1256 | return;
|
|---|
| 1257 | if (ch === 92/*\*/) {
|
|---|
| 1258 | ch = source.charCodeAt(++pos);
|
|---|
| 1259 | if (ch === 13/*\r*/ && source.charCodeAt(pos + 1) === 10/*\n*/)
|
|---|
| 1260 | pos++;
|
|---|
| 1261 | }
|
|---|
| 1262 | else if (isBr(ch))
|
|---|
| 1263 | break;
|
|---|
| 1264 | }
|
|---|
| 1265 | throw new Error('Unterminated string.');
|
|---|
| 1266 | }
|
|---|
| 1267 |
|
|---|
| 1268 | function regexCharacterClass () {
|
|---|
| 1269 | while (pos++ < end) {
|
|---|
| 1270 | let ch = source.charCodeAt(pos);
|
|---|
| 1271 | if (ch === 93/*]*/)
|
|---|
| 1272 | return ch;
|
|---|
| 1273 | if (ch === 92/*\*/)
|
|---|
| 1274 | pos++;
|
|---|
| 1275 | else if (ch === 10/*\n*/ || ch === 13/*\r*/)
|
|---|
| 1276 | break;
|
|---|
| 1277 | }
|
|---|
| 1278 | throw new Error('Syntax error reading regular expression class.');
|
|---|
| 1279 | }
|
|---|
| 1280 |
|
|---|
| 1281 | function regularExpression () {
|
|---|
| 1282 | while (pos++ < end) {
|
|---|
| 1283 | let ch = source.charCodeAt(pos);
|
|---|
| 1284 | if (ch === 47/*/*/)
|
|---|
| 1285 | return;
|
|---|
| 1286 | if (ch === 91/*[*/)
|
|---|
| 1287 | ch = regexCharacterClass();
|
|---|
| 1288 | else if (ch === 92/*\*/)
|
|---|
| 1289 | pos++;
|
|---|
| 1290 | else if (ch === 10/*\n*/ || ch === 13/*\r*/)
|
|---|
| 1291 | break;
|
|---|
| 1292 | }
|
|---|
| 1293 | throw new Error('Syntax error reading regular expression.');
|
|---|
| 1294 | }
|
|---|
| 1295 |
|
|---|
| 1296 | // Note: non-asii BR and whitespace checks omitted for perf / footprint
|
|---|
| 1297 | // if there is a significant user need this can be reconsidered
|
|---|
| 1298 | function isBr (c) {
|
|---|
| 1299 | return c === 13/*\r*/ || c === 10/*\n*/;
|
|---|
| 1300 | }
|
|---|
| 1301 |
|
|---|
| 1302 | function isBrOrWs (c) {
|
|---|
| 1303 | return c > 8 && c < 14 || c === 32 || c === 160;
|
|---|
| 1304 | }
|
|---|
| 1305 |
|
|---|
| 1306 | function isBrOrWsOrPunctuatorNotDot (c) {
|
|---|
| 1307 | return c > 8 && c < 14 || c === 32 || c === 160 || isPunctuator(c) && c !== 46/*.*/;
|
|---|
| 1308 | }
|
|---|
| 1309 |
|
|---|
| 1310 | function keywordStart (pos) {
|
|---|
| 1311 | return pos === 0 || isBrOrWsOrPunctuatorNotDot(source.charCodeAt(pos - 1));
|
|---|
| 1312 | }
|
|---|
| 1313 |
|
|---|
| 1314 | function readPrecedingKeyword (pos, match) {
|
|---|
| 1315 | if (pos < match.length - 1)
|
|---|
| 1316 | return false;
|
|---|
| 1317 | return source.startsWith(match, pos - match.length + 1) && (pos === 0 || isBrOrWsOrPunctuatorNotDot(source.charCodeAt(pos - match.length)));
|
|---|
| 1318 | }
|
|---|
| 1319 |
|
|---|
| 1320 | function readPrecedingKeyword1 (pos, ch) {
|
|---|
| 1321 | return source.charCodeAt(pos) === ch && (pos === 0 || isBrOrWsOrPunctuatorNotDot(source.charCodeAt(pos - 1)));
|
|---|
| 1322 | }
|
|---|
| 1323 |
|
|---|
| 1324 | // Detects one of case, debugger, delete, do, else, in, instanceof, new,
|
|---|
| 1325 | // return, throw, typeof, void, yield, await
|
|---|
| 1326 | function isExpressionKeyword (pos) {
|
|---|
| 1327 | switch (source.charCodeAt(pos)) {
|
|---|
| 1328 | case 100/*d*/:
|
|---|
| 1329 | switch (source.charCodeAt(pos - 1)) {
|
|---|
| 1330 | case 105/*i*/:
|
|---|
| 1331 | // void
|
|---|
| 1332 | return readPrecedingKeyword(pos - 2, 'vo');
|
|---|
| 1333 | case 108/*l*/:
|
|---|
| 1334 | // yield
|
|---|
| 1335 | return readPrecedingKeyword(pos - 2, 'yie');
|
|---|
| 1336 | default:
|
|---|
| 1337 | return false;
|
|---|
| 1338 | }
|
|---|
| 1339 | case 101/*e*/:
|
|---|
| 1340 | switch (source.charCodeAt(pos - 1)) {
|
|---|
| 1341 | case 115/*s*/:
|
|---|
| 1342 | switch (source.charCodeAt(pos - 2)) {
|
|---|
| 1343 | case 108/*l*/:
|
|---|
| 1344 | // else
|
|---|
| 1345 | return readPrecedingKeyword1(pos - 3, 101/*e*/);
|
|---|
| 1346 | case 97/*a*/:
|
|---|
| 1347 | // case
|
|---|
| 1348 | return readPrecedingKeyword1(pos - 3, 99/*c*/);
|
|---|
| 1349 | default:
|
|---|
| 1350 | return false;
|
|---|
| 1351 | }
|
|---|
| 1352 | case 116/*t*/:
|
|---|
| 1353 | // delete
|
|---|
| 1354 | return readPrecedingKeyword(pos - 2, 'dele');
|
|---|
| 1355 | default:
|
|---|
| 1356 | return false;
|
|---|
| 1357 | }
|
|---|
| 1358 | case 102/*f*/:
|
|---|
| 1359 | if (source.charCodeAt(pos - 1) !== 111/*o*/ || source.charCodeAt(pos - 2) !== 101/*e*/)
|
|---|
| 1360 | return false;
|
|---|
| 1361 | switch (source.charCodeAt(pos - 3)) {
|
|---|
| 1362 | case 99/*c*/:
|
|---|
| 1363 | // instanceof
|
|---|
| 1364 | return readPrecedingKeyword(pos - 4, 'instan');
|
|---|
| 1365 | case 112/*p*/:
|
|---|
| 1366 | // typeof
|
|---|
| 1367 | return readPrecedingKeyword(pos - 4, 'ty');
|
|---|
| 1368 | default:
|
|---|
| 1369 | return false;
|
|---|
| 1370 | }
|
|---|
| 1371 | case 110/*n*/:
|
|---|
| 1372 | // in, return
|
|---|
| 1373 | return readPrecedingKeyword1(pos - 1, 105/*i*/) || readPrecedingKeyword(pos - 1, 'retur');
|
|---|
| 1374 | case 111/*o*/:
|
|---|
| 1375 | // do
|
|---|
| 1376 | return readPrecedingKeyword1(pos - 1, 100/*d*/);
|
|---|
| 1377 | case 114/*r*/:
|
|---|
| 1378 | // debugger
|
|---|
| 1379 | return readPrecedingKeyword(pos - 1, 'debugge');
|
|---|
| 1380 | case 116/*t*/:
|
|---|
| 1381 | // await
|
|---|
| 1382 | return readPrecedingKeyword(pos - 1, 'awai');
|
|---|
| 1383 | case 119/*w*/:
|
|---|
| 1384 | switch (source.charCodeAt(pos - 1)) {
|
|---|
| 1385 | case 101/*e*/:
|
|---|
| 1386 | // new
|
|---|
| 1387 | return readPrecedingKeyword1(pos - 2, 110/*n*/);
|
|---|
| 1388 | case 111/*o*/:
|
|---|
| 1389 | // throw
|
|---|
| 1390 | return readPrecedingKeyword(pos - 2, 'thr');
|
|---|
| 1391 | default:
|
|---|
| 1392 | return false;
|
|---|
| 1393 | }
|
|---|
| 1394 | }
|
|---|
| 1395 | return false;
|
|---|
| 1396 | }
|
|---|
| 1397 |
|
|---|
| 1398 | function isParenKeyword (curPos) {
|
|---|
| 1399 | return source.charCodeAt(curPos) === 101/*e*/ && source.startsWith('whil', curPos - 4) ||
|
|---|
| 1400 | source.charCodeAt(curPos) === 114/*r*/ && source.startsWith('fo', curPos - 2) ||
|
|---|
| 1401 | source.charCodeAt(curPos - 1) === 105/*i*/ && source.charCodeAt(curPos) === 102/*f*/;
|
|---|
| 1402 | }
|
|---|
| 1403 |
|
|---|
| 1404 | function isPunctuator (ch) {
|
|---|
| 1405 | // 23 possible punctuator endings: !%&()*+,-./:;<=>?[]^{}|~
|
|---|
| 1406 | return ch === 33/*!*/ || ch === 37/*%*/ || ch === 38/*&*/ ||
|
|---|
| 1407 | ch > 39 && ch < 48 || ch > 57 && ch < 64 ||
|
|---|
| 1408 | ch === 91/*[*/ || ch === 93/*]*/ || ch === 94/*^*/ ||
|
|---|
| 1409 | ch > 122 && ch < 127;
|
|---|
| 1410 | }
|
|---|
| 1411 |
|
|---|
| 1412 | function isExpressionPunctuator (ch) {
|
|---|
| 1413 | // 20 possible expression endings: !%&(*+,-.:;<=>?[^{|~
|
|---|
| 1414 | return ch === 33/*!*/ || ch === 37/*%*/ || ch === 38/*&*/ ||
|
|---|
| 1415 | ch > 39 && ch < 47 && ch !== 41 || ch > 57 && ch < 64 ||
|
|---|
| 1416 | ch === 91/*[*/ || ch === 94/*^*/ || ch > 122 && ch < 127 && ch !== 125/*}*/;
|
|---|
| 1417 | }
|
|---|
| 1418 |
|
|---|
| 1419 | function isExpressionTerminator (curPos) {
|
|---|
| 1420 | // detects:
|
|---|
| 1421 | // => ; ) finally catch else
|
|---|
| 1422 | // as all of these followed by a { will indicate a statement brace
|
|---|
| 1423 | switch (source.charCodeAt(curPos)) {
|
|---|
| 1424 | case 62/*>*/:
|
|---|
| 1425 | return source.charCodeAt(curPos - 1) === 61/*=*/;
|
|---|
| 1426 | case 59/*;*/:
|
|---|
| 1427 | case 41/*)*/:
|
|---|
| 1428 | return true;
|
|---|
| 1429 | case 104/*h*/:
|
|---|
| 1430 | return source.startsWith('catc', curPos - 4);
|
|---|
| 1431 | case 121/*y*/:
|
|---|
| 1432 | return source.startsWith('finall', curPos - 6);
|
|---|
| 1433 | case 101/*e*/:
|
|---|
| 1434 | return source.startsWith('els', curPos - 3);
|
|---|
| 1435 | }
|
|---|
| 1436 | return false;
|
|---|
| 1437 | }
|
|---|
| 1438 |
|
|---|
| 1439 | const initPromise = Promise.resolve();
|
|---|
| 1440 |
|
|---|
| 1441 | module.exports.init = () => initPromise;
|
|---|
| 1442 | module.exports.initSync = () => {};
|
|---|
| 1443 | module.exports.parse = parseCJS;
|
|---|