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 CHANGED
@@ -7,7 +7,7 @@ declare function concurrentTopLevelAwait(options?: {
7
7
  exclude?: FilterPattern;
8
8
  }): {
9
9
  name: string;
10
- apply: string;
10
+ apply: "build";
11
11
  transform: {
12
12
  handler(this: rollup0.TransformPluginContext, code: string, id: string): Promise<{
13
13
  code: string;
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
- let found = false;
7
- function isFunctionNode(node) {
8
- if (!node || typeof node.type !== "string") return false;
9
- return node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression" || node.type === "ClassPrivateMethod" || node.type === "MethodDefinition";
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rollup-plugin-concurrent-top-level-await",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Rollup (and Vite) plugin enabling concurrent execution of modules that contain top level await.",
5
5
  "keywords": [
6
6
  "rollup-plugin",