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(es/minifier): Fix analysis of var declaration after usage #6043

Merged
merged 11 commits into from Oct 6, 2022

Conversation

kdy1
Copy link
Member

@kdy1 kdy1 commented Oct 5, 2022

Description:

var_initialized should be true even if the declaration of variable comes after its usage.

Related issue:

@kdy1 kdy1 added this to the Planned milestone Oct 5, 2022
@kdy1 kdy1 self-assigned this Oct 5, 2022
@kdy1 kdy1 marked this pull request as ready for review October 5, 2022 06:02
@kdy1 kdy1 enabled auto-merge (squash) October 5, 2022 06:02
kodiakhq[bot]
kodiakhq bot previously approved these changes Oct 5, 2022
@kdy1 kdy1 marked this pull request as draft October 5, 2022 06:05
auto-merge was automatically disabled October 5, 2022 06:05

Pull request was converted to draft

@kdy1 kdy1 changed the title test(es/minifier): Add a test for a fixed issue fix(es/minifier): Fix a bug Oct 5, 2022
@kdy1 kdy1 changed the title fix(es/minifier): Fix a bug fix(es/minifier): Fix analysis of reassignments Oct 5, 2022
@kdy1 kdy1 changed the title fix(es/minifier): Fix analysis of reassignments fix(es/minifier): Fix analysis of var declaration after usage Oct 5, 2022
Copy link
Member Author

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swc-bump:

  • swc_ecma_minifier

tracing::debug!("Scanning: `{}` with delta {}", considered, delta);
}
}
// #[cfg(feature = "debug")]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I commented this out as this disturbs debugging

@@ -34,6 +34,23 @@ impl VisitMut for PrecompressOptimizer {
}
}

fn visit_mut_pat_or_expr(&mut self, n: &mut PatOrExpr) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a small normalization to reduce possibility of bugs

@kdy1 kdy1 requested a review from jridgewell October 5, 2022 06:55
@kdy1 kdy1 marked this pull request as ready for review October 5, 2022 07:04
kodiakhq[bot]
kodiakhq bot previously approved these changes Oct 5, 2022
Copy link
Contributor

@jridgewell jridgewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused by you're wording in the OP. Everything appears to be declared before use, when does an item get inserted into vars?

@kdy1
Copy link
Member Author

kdy1 commented Oct 6, 2022

I meant

function foo() {
    console.log(a)
}

var a = 1

before here means the order of visit

@kdy1
Copy link
Member Author

kdy1 commented Oct 6, 2022

Anyway, thank you!

@kdy1 kdy1 enabled auto-merge (squash) October 6, 2022 01:32
Copy link
Collaborator

@swc-bot swc-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review comment generated by auto-rebase script

@kdy1 kdy1 merged commit 36d467e into swc-project:main Oct 6, 2022
@kdy1 kdy1 deleted the issue-6039 branch October 6, 2022 02:09
@kdy1 kdy1 modified the milestones: Planned, v1.3.5 Oct 6, 2022
@swc-project swc-project locked as resolved and limited conversation to collaborators Nov 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Faulty compression leads to arrays with holes / Removes assignments passed by value
3 participants