rollup-plugin-concurrent-top-level-await 0.0.7 → 0.0.9
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/README.md +0 -12
- package/dist/index.mjs +24 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -97,18 +97,6 @@ can lead to `const` variables being assignable at runtime instead of throwing an
|
|
|
97
97
|
|
|
98
98
|
Additionally, variable declarations may be hoisted, which removes temporal dead zone (TDZ) checks.
|
|
99
99
|
|
|
100
|
-
### Exporting var
|
|
101
|
-
|
|
102
|
-
The plugin only checks the very top level of a module for potentially exported variables. This means that if a `var`
|
|
103
|
-
variable is declared inside a block but exported, the variable might not get handled correctly.
|
|
104
|
-
|
|
105
|
-
```js
|
|
106
|
-
if (something) {
|
|
107
|
-
var myValue = 42;
|
|
108
|
-
}
|
|
109
|
-
export default myValue;
|
|
110
|
-
```
|
|
111
|
-
|
|
112
100
|
### Class Decorators
|
|
113
101
|
|
|
114
102
|
Class declarations still get evaluated before any top level await expressions. This means that if a class decorator
|
package/dist/index.mjs
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
import { createFilter } from "@rollup/pluginutils";
|
|
2
2
|
import MagicString from "magic-string";
|
|
3
3
|
|
|
4
|
-
//#region src/
|
|
4
|
+
//#region 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
|
}
|
|
8
|
+
function visitScope(node, cb) {
|
|
9
|
+
if (node?.type == null) return false;
|
|
10
|
+
if (cb(node)) return true;
|
|
11
|
+
if (isFunctionNode(node)) return false;
|
|
12
|
+
return Object.values(node).flat().some((n) => visitScope(n, cb));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/hasTopLevelAwait.ts
|
|
8
17
|
function isAwaitNode(node) {
|
|
9
18
|
return node.type === "AwaitExpression" || node.type === "ForOfStatement" && node.await || node.type === "VariableDeclaration" && node.kind === "await using";
|
|
10
19
|
}
|
|
11
|
-
function hasTopLevelAwait(
|
|
12
|
-
|
|
13
|
-
if (isAwaitNode(ast)) return true;
|
|
14
|
-
if (isFunctionNode(ast)) return false;
|
|
15
|
-
return Object.values(ast).flat().some(hasTopLevelAwait);
|
|
20
|
+
function hasTopLevelAwait(node) {
|
|
21
|
+
return visitScope(node, isAwaitNode);
|
|
16
22
|
}
|
|
17
23
|
|
|
18
24
|
//#endregion
|
|
@@ -161,10 +167,19 @@ function tansformAndMoveDeclarationsToModuleScope(s, ast, asyncImports) {
|
|
|
161
167
|
s = s.remove(node.start, node.declaration.start);
|
|
162
168
|
s = moveVariableDeclarationToModuleScope(s, node.declaration, moduleScopeEnd);
|
|
163
169
|
}
|
|
164
|
-
}
|
|
165
|
-
if (node.type === "VariableDeclaration") if (node.kind.endsWith("using")) s = moveVariableDeclarationWithUsingToModuleScope(s, node, moduleScopeEnd);
|
|
170
|
+
} else if (node.type === "VariableDeclaration") if (node.kind.endsWith("using")) s = moveVariableDeclarationWithUsingToModuleScope(s, node, moduleScopeEnd);
|
|
166
171
|
else s = moveVariableDeclarationToModuleScope(s, node, moduleScopeEnd);
|
|
167
|
-
|
|
172
|
+
else visitScope(node, (n) => {
|
|
173
|
+
if (n.type === "VariableDeclaration" && n.kind === "var") s = moveVariableDeclarationToModuleScope(s, n, moduleScopeEnd);
|
|
174
|
+
return false;
|
|
175
|
+
});
|
|
176
|
+
if (node.type === "ExportDefaultDeclaration" && !isDeclaration(node.declaration.type)) {
|
|
177
|
+
s = s.appendLeft(moduleScopeEnd, "let __tla_default;\nexport { __tla_default as default };\n");
|
|
178
|
+
s = s.remove(node.start, node.declaration.start);
|
|
179
|
+
s = s.appendRight(node.declaration.start, ";__tla_default = (");
|
|
180
|
+
s = s.appendLeft(node.declaration.end, ");");
|
|
181
|
+
}
|
|
182
|
+
if (isDeclaration(node.type) || node.type === "ImportDeclaration" || node.type === "ExportDefaultDeclaration" && isDeclaration(node.declaration.type) || node.type === "ExportNamedDeclaration" && isDeclaration(node.declaration?.type) || node.type === "ExportNamedDeclaration" && node.declaration == null || node.type === "ExportAllDeclaration") if (node.start > moduleScopeEnd) {
|
|
168
183
|
s = s.appendRight(node.start, ";\n");
|
|
169
184
|
s = s.move(node.start, node.end, moduleScopeEnd);
|
|
170
185
|
} else moduleScopeEnd = node.end;
|
package/package.json
CHANGED