Skip to content

Commit

Permalink
fix: Capture let when the for body is not a block (#16368)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Mar 20, 2024
1 parent 9f2cbc4 commit 3956c75
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 6 deletions.
11 changes: 5 additions & 6 deletions packages/babel-plugin-transform-block-scoping/src/index.ts
Expand Up @@ -57,12 +57,11 @@ export default declare((api, opts: Options) => {
let bodyScope: Scope | null;
if (body.isBlockStatement()) {
bodyScope = body.scope;

const bindings = getLoopBodyBindings(path);
for (const binding of bindings) {
const { capturedInClosure } = getUsageInBody(binding, path);
if (capturedInClosure) markNeedsBodyWrap();
}
}
const bindings = getLoopBodyBindings(path);
for (const binding of bindings) {
const { capturedInClosure } = getUsageInBody(binding, path);
if (capturedInClosure) markNeedsBodyWrap();
}

const captured: string[] = [];
Expand Down
@@ -0,0 +1,18 @@
function proxyObserver(properties) {
for (let key in properties)
if (properties[key].observer) {
let base = properties[key].observer;
properties[key].observer = () => {
return base.apply(this);
};
}

return properties;
}

const results = proxyObserver([
{ observer: () => 1 },
{ observer: () => 2 },
])
expect(results[0].observer()).toBe(1)
expect(results[1].observer()).toBe(2)
@@ -0,0 +1,23 @@
function proxyObserver(component) {
for (let key in component.properties)
if (component.properties[key].observer) {
let base = component.properties[key].observer;
component.properties[key].observer = () => {
base.apply(this);
};
}

return component;
}

function proxyObserver2(component) {
for (let key of component.properties)
while (1) {
let base = component.properties[key].observer;
component.properties[key].observer = () => {
base.apply(this);
};
}

return component;
}
@@ -0,0 +1,30 @@
function proxyObserver(component) {
var _this = this;
var _loop = function () {
if (component.properties[key].observer) {
var base = component.properties[key].observer;
component.properties[key].observer = function () {
base.apply(_this);
};
}
};
for (var key in component.properties) {
_loop();
}
return component;
}
function proxyObserver2(component) {
var _this2 = this;
for (var key of component.properties) {
var _loop2 = function () {
var base = component.properties[key].observer;
component.properties[key].observer = function () {
base.apply(_this2);
};
};
while (1) {
_loop2();
}
}
return component;
}

0 comments on commit 3956c75

Please sign in to comment.