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(babel-preset,shaker): do not delete exported functions even if its body was deleted #1237

Merged
merged 1 commit into from
Apr 24, 2023

Conversation

Anber
Copy link
Collaborator

@Anber Anber commented Apr 24, 2023

Motivation

Linaria currently has a bug that leads to the deletion of exported functions from some modules when their body contains restricted code, such as JSX, React hooks, or browser API. (see #1226)

Summary

This pull request addresses the aforementioned bug by replacing the problematic functions with an empty one instead of deleting them. By doing so, we preserve the exported functions while effectively neutralizing the restricted code within them. This approach maintains the original structure of the module exports without causing any unexpected side effects or errors.

@changeset-bot
Copy link

changeset-bot bot commented Apr 24, 2023

🦋 Changeset detected

Latest commit: c1a3609

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 23 packages
Name Type
@linaria/babel-preset Patch
@linaria/shaker Patch
@linaria/testkit Patch
@linaria/utils Patch
@linaria/cli Patch
@linaria/esbuild Patch
linaria Patch
@linaria/rollup Patch
@linaria/stylelint Patch
@linaria/vite Patch
@linaria/webpack4-loader Patch
@linaria/webpack5-loader Patch
linaria-website Patch
vite-example Patch
@linaria/atomic Patch
@linaria/core Patch
@linaria/griffel Patch
@linaria/react Patch
@linaria/tags Patch
esbuild-example Patch
rollup-example Patch
vpssr-linaria-solid-example Patch
@linaria/webpack-loader Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Anber Anber force-pushed the issue/1226 branch 2 times, most recently from ffbcb34 to 1068f58 Compare April 24, 2023 11:52
@Anber Anber merged commit dbe250b into master Apr 24, 2023
4 checks passed
@Anber Anber deleted the issue/1226 branch April 24, 2023 12:10
/* remove */testFn = arg
)

export default function testDefaultFn(arg) {
Copy link
Contributor

@chentsulin chentsulin Jul 4, 2023

Choose a reason for hiding this comment

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

Hi @Anber, is this export default function got accidentally deleted? Is this correct?

exports[`removeWithRelated should not remove top-level functions with empty bodies 1`] = `
"function testFn() {}
export const testArrow1 = () => {};
const testArrow2 = () => {};"
`;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants