Skip to content

Commit

Permalink
Fix static block
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed May 23, 2023
1 parent ec6e079 commit 41314f8
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 27 deletions.
Expand Up @@ -37,7 +37,10 @@ export default declare(api => {
]),
);
},
BlockStatement(path, state) {
"BlockStatement|StaticBlock"(
path: NodePath<t.BlockStatement | t.StaticBlock>,
state,
) {
let stackId: t.Identifier | null = null;
let needsAwait = false;

Expand Down Expand Up @@ -97,10 +100,11 @@ export default declare(api => {
if (
parentPath.isFunction() ||
parentPath.isTryStatement() ||
parentPath.isCatchClause() ||
parentPath.isStaticBlock()
parentPath.isCatchClause()
) {
path.replaceWith(t.blockStatement([replacement]));
} else if (path.isStaticBlock()) {
path.node.body = [replacement];
} else {
path.replaceWith(replacement);
}
Expand Down
@@ -1,4 +1,4 @@
if (test) {
function fn() {
using x = obj;
doSomethingWith(x);
return doSomethingWith(x);
}
@@ -1,10 +1,12 @@
if (test) try {
var _stack = [];
const x = babelHelpers.using(_stack, obj);
doSomethingWith(x);
} catch (_) {
var _error = _;
var _hasError = true;
} finally {
babelHelpers.dispose(_stack, _error, _hasError, typeof SuppressedError !== "undefined" && SuppressedError);
function fn() {
try {
var _stack = [];
const x = babelHelpers.using(_stack, obj);
return doSomethingWith(x);
} catch (_) {
var _error = _;
var _hasError = true;
} finally {
babelHelpers.dispose(_stack, _error, _hasError, typeof SuppressedError !== "undefined" && SuppressedError);
}
}
@@ -1,4 +1,4 @@
function fn() {
if (test) {
using x = obj;
return doSomethingWith(x);
doSomethingWith(x);
}
@@ -1,12 +1,10 @@
function fn() {
try {
var _stack = [];
const x = babelHelpers.using(_stack, obj);
return doSomethingWith(x);
} catch (_) {
var _error = _;
var _hasError = true;
} finally {
babelHelpers.dispose(_stack, _error, _hasError, typeof SuppressedError !== "undefined" && SuppressedError);
}
if (test) try {
var _stack = [];
const x = babelHelpers.using(_stack, obj);
doSomethingWith(x);
} catch (_) {
var _error = _;
var _hasError = true;
} finally {
babelHelpers.dispose(_stack, _error, _hasError, typeof SuppressedError !== "undefined" && SuppressedError);
}
@@ -0,0 +1,6 @@
class A {
static {
using x = y;
doSomethingWith(x);
}
}
@@ -0,0 +1,14 @@
class A {
static {
try {
var _stack = [];
const x = babelHelpers.using(_stack, y);
doSomethingWith(x);
} catch (_) {
var _error = _;
var _hasError = true;
} finally {
babelHelpers.dispose(_stack, _error, _hasError, typeof SuppressedError !== "undefined" && SuppressedError);
}
}
}

0 comments on commit 41314f8

Please sign in to comment.