Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function hoist(
const vars: Record<string, t.Identifier> = { __proto__: null };

function varDeclToExpr(
{ node: vdec, scope }: NodePath,
{ node: vdec }: NodePath,
includeIdentifiers: boolean,
) {
t.assertVariableDeclaration(vdec);
Expand All @@ -27,10 +27,6 @@ export function hoist(
// have the same 'loc' value, since that can make sourcemaps and retainLines behave poorly.
vars[dec.id.name] = t.identifier(dec.id.name);

// Remove the binding, to avoid "duplicate declaration" errors when it will
// be injected again.
scope.removeBinding(dec.id.name);

if (dec.init) {
exprs.push(t.assignmentExpression("=", dec.id, dec.init));
} else if (includeIdentifiers) {
Expand All @@ -52,6 +48,12 @@ export function hoist(
if (expr === null) {
path.remove();
} else {
for (const name of Object.keys(vars)) {
// Remove the binding, to avoid "duplicate declaration" errors when it will
// be injected again.
path.scope.removeBinding(name);
}

// We don't need to traverse this expression any further because
// there can't be any new declarations inside an expression.
path.replaceWith(t.expressionStatement(expr));
Expand Down Expand Up @@ -113,11 +115,11 @@ export function hoist(
// replace the declaration with the equivalent assignment form
// without worrying about hoisting it.
path.replaceWith(assignment);
}

// Remove the binding, to avoid "duplicate declaration" errors when it will
// be injected again.
path.scope.removeBinding(node.id.name);
// Remove the binding, to avoid "duplicate declaration" errors when it will
// be injected again.
path.scope.removeBinding(node.id.name);
}

// Don't hoist variables out of inner functions.
path.skip();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {useLayoutEffect as n} from "react";

function Ki(i, n) {
return i(async () => {
var n;
}, n); // This n is the one from the Ki function, not from the import statement
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["transform-modules-commonjs", "transform-regenerator"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use strict";

var _react = require("react");
function Ki(i, n) {
return i(() => {
var n;
return babelHelpers.regeneratorAsync(function (_context) {
while (1) switch (_context.n) {
case 0:
return _context.a(2);
}
}, null, null, null, Promise);
}, n); // This n is the one from the Ki function, not from the import statement
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {useLayoutEffect as n} from "react";

function Ki(i, n) {
return i(async () => {
function n() {}
}, n); // This n is the one from the Ki function, not from the import statement
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["transform-modules-commonjs", "transform-regenerator"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"use strict";

var _react = require("react");
function Ki(i, n) {
return i(() => {
var n;
return babelHelpers.regeneratorAsync(function (_context) {
while (1) switch (_context.n) {
case 0:
n = function _n() {};
case 1:
return _context.a(2);
}
}, null, null, null, Promise);
}, n); // This n is the one from the Ki function, not from the import statement
}