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

Correctly handle early bind for member expressions #2900

Merged
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: 2 additions & 0 deletions src/ast/nodes/MemberExpression.ts
Expand Up @@ -136,6 +136,7 @@ export default class MemberExpression extends NodeBase implements DeoptimizableE
recursionTracker: ImmutableEntityPathTracker,
origin: DeoptimizableEntity
): LiteralValueOrUnknown {
if (!this.bound) this.bind();
if (this.variable !== null) {
return this.variable.getLiteralValueAtPath(path, recursionTracker, origin);
}
Expand All @@ -153,6 +154,7 @@ export default class MemberExpression extends NodeBase implements DeoptimizableE
recursionTracker: ImmutableEntityPathTracker,
origin: DeoptimizableEntity
) {
if (!this.bound) this.bind();
if (this.variable !== null) {
return this.variable.getReturnExpressionWhenCalledAtPath(path, recursionTracker, origin);
}
Expand Down
4 changes: 4 additions & 0 deletions test/form/samples/early-bind-member-expressions/_config.js
@@ -0,0 +1,4 @@
module.exports = {
description: 'correctly resolves namespace members when accessed early (#2895)',
options: { external: 'external' }
};
3 changes: 3 additions & 0 deletions test/form/samples/early-bind-member-expressions/_expected.js
@@ -0,0 +1,3 @@
import { y } from 'external';

const {x} = y();
3 changes: 3 additions & 0 deletions test/form/samples/early-bind-member-expressions/main.js
@@ -0,0 +1,3 @@
import * as stuff from 'external'

const {x} = stuff.y();