source: frontend/node_modules/sucrase/dist/util/isAsyncOperation.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.3 KB
Line 
1"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _keywords = require('../parser/tokenizer/keywords');
2
3
4/**
5 * Determine whether this optional chain or nullish coalescing operation has any await statements in
6 * it. If so, we'll need to transpile to an async operation.
7 *
8 * We compute this by walking the length of the operation and returning true if we see an await
9 * keyword used as a real await (rather than an object key or property access). Nested optional
10 * chain/nullish operations need to be tracked but don't silence await, but a nested async function
11 * (or any other nested scope) will make the await not count.
12 */
13 function isAsyncOperation(tokens) {
14 let index = tokens.currentIndex();
15 let depth = 0;
16 const startToken = tokens.currentToken();
17 do {
18 const token = tokens.tokens[index];
19 if (token.isOptionalChainStart) {
20 depth++;
21 }
22 if (token.isOptionalChainEnd) {
23 depth--;
24 }
25 depth += token.numNullishCoalesceStarts;
26 depth -= token.numNullishCoalesceEnds;
27
28 if (
29 token.contextualKeyword === _keywords.ContextualKeyword._await &&
30 token.identifierRole == null &&
31 token.scopeDepth === startToken.scopeDepth
32 ) {
33 return true;
34 }
35 index += 1;
36 } while (depth > 0 && index < tokens.tokens.length);
37 return false;
38} exports.default = isAsyncOperation;
Note: See TracBrowser for help on using the repository browser.