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

Deoptimize right side in for-of loops #4949

Merged
merged 1 commit into from Apr 21, 2023
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
3 changes: 2 additions & 1 deletion src/ast/nodes/ForOfStatement.ts
Expand Up @@ -3,7 +3,7 @@ import { NO_SEMICOLON, type RenderOptions } from '../../utils/renderHelpers';
import type { InclusionContext } from '../ExecutionContext';
import BlockScope from '../scopes/BlockScope';
import type Scope from '../scopes/Scope';
import { EMPTY_PATH } from '../utils/PathTracker';
import { EMPTY_PATH, UNKNOWN_PATH } from '../utils/PathTracker';
import type MemberExpression from './MemberExpression';
import type * as NodeType from './NodeType';
import type VariableDeclaration from './VariableDeclaration';
Expand Down Expand Up @@ -60,6 +60,7 @@ export default class ForOfStatement extends StatementBase {
protected applyDeoptimizations(): void {
this.deoptimized = true;
this.left.deoptimizePath(EMPTY_PATH);
this.right.deoptimizePath(UNKNOWN_PATH);
this.context.requestTreeshakingPass();
}
}
3 changes: 3 additions & 0 deletions test/function/samples/deoptimize-loop-element/_config.js
@@ -0,0 +1,3 @@
module.exports = {
description: 'deoptimizes the loop element when it is reassigned'
};
7 changes: 7 additions & 0 deletions test/function/samples/deoptimize-loop-element/main.js
@@ -0,0 +1,7 @@
const foo = [{ value: 1 }];

for (const item of foo) {
item.value = 0;
}

assert.ok(foo[0].value === 0 ? true : false);