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

Handle out-of-order binding of identifiers to improve tree-shaking #2803

Merged
merged 1 commit into from Apr 10, 2019
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/Identifier.ts
Expand Up @@ -86,6 +86,7 @@ export default class Identifier extends NodeBase implements PatternNode {
recursionTracker: ImmutableEntityPathTracker,
origin: DeoptimizableEntity
): LiteralValueOrUnknown {
if (!this.bound) this.bind();
if (this.variable !== null) {
return this.variable.getLiteralValueAtPath(path, recursionTracker, origin);
}
Expand All @@ -97,6 +98,7 @@ export default class Identifier extends NodeBase implements PatternNode {
recursionTracker: ImmutableEntityPathTracker,
origin: DeoptimizableEntity
) {
if (!this.bound) this.bind();
if (this.variable !== null) {
return this.variable.getReturnExpressionWhenCalledAtPath(path, recursionTracker, origin);
}
Expand Down
3 changes: 3 additions & 0 deletions test/form/samples/simplify-return-expression/_config.js
@@ -0,0 +1,3 @@
module.exports = {
description: 'Simplifies conditionals in return expression'
};
14 changes: 14 additions & 0 deletions test/form/samples/simplify-return-expression/_expected.js
@@ -0,0 +1,14 @@
const test = () => {
console.log(foo());
console.log(bar());
};

const foo = () => {
return A;
};

const bar = () => {
return A;
};

export { test };
16 changes: 16 additions & 0 deletions test/form/samples/simplify-return-expression/main.js
@@ -0,0 +1,16 @@
export const test = () => {
console.log(foo());
console.log(bar());
};

const foo = () => {
return BUILD ? A : B;
};

const bar = () => {
return getBuild() ? A : B;
};

const getBuild = () => BUILD;

const BUILD = true;