Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement transform support for using declarations #15633

Merged
merged 22 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix static block
  • Loading branch information
nicolo-ribaudo committed May 24, 2023
commit f558fe766330c713786ea6f0e4bc6c1583fb6e19
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if (test) {
function fn() {
using x = obj;
doSomethingWith(x);
return doSomethingWith(x);
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function fn() {
if (test) {
using x = obj;
return doSomethingWith(x);
doSomethingWith(x);
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class A {
static {
using x = y;
doSomethingWith(x);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}