(script: Script)
| 25 | * and the text allows conversion from/to line/column numbers. |
| 26 | */ |
| 27 | export function scopeTreeForScript(script: Script): Promise<{scopeTree: ScopeTreeNode, text: Text}|null> { |
| 28 | if (script.isWasm()) { |
| 29 | return Promise.resolve(null); |
| 30 | } |
| 31 | |
| 32 | let promise = scopeTrees.get(script); |
| 33 | if (promise === undefined) { |
| 34 | promise = script.requestContentData().then(content => { |
| 35 | if (TextUtils.ContentData.ContentData.isError(content)) { |
| 36 | return null; |
| 37 | } |
| 38 | |
| 39 | const sourceType = script.isModule ? 'module' : 'script'; |
| 40 | return Formatter.FormatterWorkerPool.formatterWorkerPool() |
| 41 | .javaScriptScopeTree(content.text, sourceType) |
| 42 | .then(scopeTree => scopeTree ? ({scopeTree, text: content.textObj}) : null) |
| 43 | .catch(() => null); |
| 44 | }); |
| 45 | scopeTrees.set(script, promise); |
| 46 | } |
| 47 | // We intentionally return `null` here if the script already failed to parse once. |
| 48 | return promise; |
| 49 | } |
no test coverage detected