rollup-plugin-concurrent-top-level-await 0.3.1 → 0.3.2
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.mjs +10 -9
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createFilter } from "@rollup/pluginutils";
|
|
2
2
|
import MagicString from "magic-string";
|
|
3
3
|
|
|
4
|
-
//#region src/ast.ts
|
|
4
|
+
//#region ../shared/src/ast.ts
|
|
5
5
|
function isFunctionNode(node) {
|
|
6
6
|
return node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression" || node.type === "MethodDefinition" || node.type === "Property" && node.value.type === "FunctionExpression";
|
|
7
7
|
}
|
|
@@ -13,7 +13,7 @@ function visitScope(node, cb) {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
//#endregion
|
|
16
|
-
//#region src/hasTopLevelAwait.ts
|
|
16
|
+
//#region ../shared/src/hasTopLevelAwait.ts
|
|
17
17
|
function isAwaitNode(node) {
|
|
18
18
|
return node.type === "AwaitExpression" || node.type === "ForOfStatement" && node.await || node.type === "VariableDeclaration" && node.kind === "await using";
|
|
19
19
|
}
|
|
@@ -22,7 +22,7 @@ function hasTopLevelAwait(node) {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
//#endregion
|
|
25
|
-
//#region src/polyfills/promise.ts
|
|
25
|
+
//#region ../shared/src/polyfills/promise.ts
|
|
26
26
|
function withResolvers() {
|
|
27
27
|
let resolve;
|
|
28
28
|
let reject;
|
|
@@ -37,7 +37,7 @@ function withResolvers() {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
//#endregion
|
|
40
|
-
//#region src/AsyncModuleTracker.ts
|
|
40
|
+
//#region ../shared/src/AsyncModuleTracker.ts
|
|
41
41
|
var AwaitableCache = class {
|
|
42
42
|
#store = /* @__PURE__ */ new Map();
|
|
43
43
|
#getPromise(key) {
|
|
@@ -127,7 +127,7 @@ var AsyncModuleTracker = class {
|
|
|
127
127
|
};
|
|
128
128
|
|
|
129
129
|
//#endregion
|
|
130
|
-
//#region src/transform.ts
|
|
130
|
+
//#region ../shared/src/transform.ts
|
|
131
131
|
function transform(s, ast, registerModuleSource, asyncImports, hasAwait, variablePrefix) {
|
|
132
132
|
const declarationsEnd = transformAndMoveDeclarationsToModuleScope(s, ast, asyncImports, variablePrefix);
|
|
133
133
|
s.appendRight(declarationsEnd, `${hasAwait ? "async " : ""}function ${variablePrefix}_initModuleExports() {\n`);
|
|
@@ -135,7 +135,6 @@ function transform(s, ast, registerModuleSource, asyncImports, hasAwait, variabl
|
|
|
135
135
|
s.prepend(`import ${variablePrefix}_register from ${JSON.stringify(registerModuleSource)};\n`);
|
|
136
136
|
const asyncDeps = `[${asyncImports.map((_, i) => `() => ${variablePrefix}${i}`).join(", ")}]`;
|
|
137
137
|
s.append(`export const ${variablePrefix}_access = ${variablePrefix}_register(${variablePrefix}_initModuleExports, ${asyncDeps});\n`);
|
|
138
|
-
s.append(`if (import.meta.useTla) await new Promise(${variablePrefix}_access);\n`);
|
|
139
138
|
}
|
|
140
139
|
function transformAndMoveDeclarationsToModuleScope(s, ast, asyncImports, variablePrefix) {
|
|
141
140
|
let moduleScopeEnd = 0;
|
|
@@ -187,7 +186,7 @@ function isFunctionDeclaration(type) {
|
|
|
187
186
|
return type === "FunctionDeclaration";
|
|
188
187
|
}
|
|
189
188
|
function getClassDeclarationStart(node) {
|
|
190
|
-
return node.decorators[0]?.start ?? node.start;
|
|
189
|
+
return node.decorators?.[0]?.start ?? node.start;
|
|
191
190
|
}
|
|
192
191
|
function moveVariableDeclarationToModuleScope(s, node, declarationsEnd) {
|
|
193
192
|
const kind = replaceConstWithLet(node.kind);
|
|
@@ -321,7 +320,8 @@ const tlaModule = `export default function register(fn, evaluate_accesses) {
|
|
|
321
320
|
`;
|
|
322
321
|
function concurrentTopLevelAwait(options = {}) {
|
|
323
322
|
const filter = createFilter(options.include, options.exclude);
|
|
324
|
-
const
|
|
323
|
+
const generatedVariablePrefix = options.generatedVariablePrefix ?? "__tla";
|
|
324
|
+
const registerModuleSource = `\0${generatedVariablePrefix}Register`;
|
|
325
325
|
const asyncTracker = new AsyncModuleTracker();
|
|
326
326
|
return {
|
|
327
327
|
name: "rollup-plugin-concurrent-tla-plugin",
|
|
@@ -355,7 +355,8 @@ function concurrentTopLevelAwait(options = {}) {
|
|
|
355
355
|
}))).filter(Boolean);
|
|
356
356
|
if (!(asyncImports.length > 0 || hasAwait)) return;
|
|
357
357
|
const s = new MagicString(code);
|
|
358
|
-
transform(s, ast, registerModuleSource, asyncImports, hasAwait,
|
|
358
|
+
transform(s, ast, registerModuleSource, asyncImports, hasAwait, generatedVariablePrefix);
|
|
359
|
+
s.append(`if (import.meta.useTla) await new Promise(${generatedVariablePrefix}_access);\n`);
|
|
359
360
|
return {
|
|
360
361
|
code: s.toString(),
|
|
361
362
|
map: options.sourceMap !== false ? s.generateMap({ hires: true }) : null
|
package/package.json
CHANGED