Skip to content

Commit

Permalink
[babel 8] Do not skip requeued paths (#13291)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed May 11, 2021
1 parent b2d9156 commit 875fc8e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 6 additions & 2 deletions packages/babel-plugin-transform-block-scoping/src/tdz.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ function isReference(node, scope, state) {
return scope.getBindingIdentifier(node.name) === declared;
}

const visitedMaybeTDZNodes = new WeakSet();

export const visitor = {
ReferencedIdentifier(path, state) {
if (!state.tdzEnabled) return;
Expand All @@ -44,13 +46,15 @@ export const visitor = {
if (status === "outside") return;

if (status === "maybe") {
if (visitedMaybeTDZNodes.has(node)) {
return;
}
visitedMaybeTDZNodes.add(node);
const assert = buildTDZAssert(node, state);

// add tdzThis to parent variable declarator so it's exploded
bindingPath.parent._tdzThis = true;

path.skip();

if (path.parentPath.isUpdateExpression()) {
if (parent._ignoreBlockScopingTDZ) return;
path.parentPath.replaceWith(t.sequenceExpression([assert, parent]));
Expand Down
10 changes: 4 additions & 6 deletions packages/babel-traverse/src/path/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,11 @@ export function setKey(this: NodePath, key) {
export function requeue(this: NodePath, pathToQueue = this) {
if (pathToQueue.removed) return;

// TODO: Uncomment in Babel 8. If a path is skipped, and then replaced with a
// If a path is skipped, and then replaced with a
// new one, the new one shouldn't probably be skipped.
// Note that this currently causes an infinite loop because of
// packages/babel-plugin-transform-block-scoping/src/tdz.js#L52-L59
// (b5b8055cc00756f94bf71deb45f288738520ee3c)
//
// pathToQueue.shouldSkip = false;
if (process.env.BABEL_8_BREAKING) {
pathToQueue.shouldSkip = false;
}

// TODO(loganfsmyth): This should be switched back to queue in parent contexts
// automatically once #2892 and #4135 have been resolved. See #4140.
Expand Down

0 comments on commit 875fc8e

Please sign in to comment.