rollup-plugin-concurrent-top-level-await 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +10 -20
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -2,27 +2,17 @@ import { createFilter } from "@rollup/pluginutils";
|
|
|
2
2
|
import MagicString from "magic-string";
|
|
3
3
|
|
|
4
4
|
//#region src/hasTopLevelAwait.ts
|
|
5
|
+
function isFunctionNode(node) {
|
|
6
|
+
return node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression" || node.type === "MethodDefinition" || node.type === "Property" && node.value.type === "FunctionExpression";
|
|
7
|
+
}
|
|
8
|
+
function isAwaitNode(node) {
|
|
9
|
+
return node.type === "AwaitExpression" || node.type === "ForOfStatement" && node.await || node.type === "VariableDeclaration" && node.kind === "await using";
|
|
10
|
+
}
|
|
5
11
|
function hasTopLevelAwait(ast) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
function walk(node, functionDepth = 0) {
|
|
12
|
-
if (!node || found) return;
|
|
13
|
-
if (node.type === "AwaitExpression" && functionDepth === 0) {
|
|
14
|
-
found = true;
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
const nextDepth = functionDepth + (isFunctionNode(node) ? 1 : 0);
|
|
18
|
-
for (const key of Object.keys(node)) {
|
|
19
|
-
const child = node[key];
|
|
20
|
-
if (Array.isArray(child)) for (const c of child) walk(c, nextDepth);
|
|
21
|
-
else if (child && typeof child.type === "string") walk(child, nextDepth);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
walk(ast, 0);
|
|
25
|
-
return found;
|
|
12
|
+
if (ast?.type == null) return false;
|
|
13
|
+
if (isAwaitNode(ast)) return true;
|
|
14
|
+
if (isFunctionNode(ast)) return false;
|
|
15
|
+
return Object.values(ast).flat().some(hasTopLevelAwait);
|
|
26
16
|
}
|
|
27
17
|
|
|
28
18
|
//#endregion
|
package/package.json
CHANGED