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

Fix reassignment tracking #4486

Merged
merged 1 commit into from May 5, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ast/variables/LocalVariable.ts
Expand Up @@ -155,7 +155,7 @@ export default class LocalVariable extends Variable {
if (path.length === 0) return false;
if (this.isReassigned) return true;
return (this.init &&
!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
!context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
this.init.hasEffectsWhenAssignedAtPath(path, context))!;
}

Expand Down
3 changes: 3 additions & 0 deletions test/function/samples/track-reassignments/_config.js
@@ -0,0 +1,3 @@
module.exports = {
description: 'properly track reassignments (#4468)'
};
15 changes: 15 additions & 0 deletions test/function/samples/track-reassignments/main.js
@@ -0,0 +1,15 @@
import { patchEventTarget } from './patchEventTarget.js';

class EventTarget {
addEventListener(callback) {
callback();
}
}
global.window = { EventTarget };

let patchCalled = false;
patchEventTarget(() => (patchCalled = true));
const target = new EventTarget();
target.addEventListener()

assert.ok(patchCalled, 'patch');
10 changes: 10 additions & 0 deletions test/function/samples/track-reassignments/patchEventTarget.js
@@ -0,0 +1,10 @@
export function patchEventTarget(callback) {
var proto = window.EventTarget.prototype;
var nativeAddEventListener = proto.addEventListener;

proto.addEventListener = function () {
return nativeAddEventListener(callback);
};

return proto;
}