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: can not find the variable that be created in plugin. #4240

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bestlyg
Copy link

@bestlyg bestlyg commented Oct 29, 2023

What: clear cache when the type of Declaration be returned.

Why:
I want to define a variable in plugin. It will insert @x: 33px to current scope.

module.exports = class LessPluginBestMixin {
    install(less, pluginManager, functions) {
        functions.add("x", () => {
            return new less.tree.Declaration(
                "@x",
                new less.tree.Value(new less.tree.Keyword("33px"))
            );
        });
        functions.add("define_var", (key) => {});
    }
};

When I write the code to a less file:

@plugin "the-plugin-path";

div {
    x();
    width: @x;
}

It works and return the css code:

div {
    width: 33px;
}

But when I write the code to a less file:

@plugin "the-plugin-path";

@a: 1px;

div {
    height: @a;
    x();
    width: @x;
}

It not works and return a error cause can not find the variable of @x.

I had tried debug the source code of less and I found the code:
image
The height need read this variable and execute the function of variable and be cached.
It lead to the function of variable can not run again when the width read the @x.

I changed the code that will clear the cache when the function return a Declaration.

I added a issue. URL

Please check this PR.

Checklist:

  • Documentation
  • Added/updated unit tests
  • Code complete

@bestlyg
Copy link
Author

bestlyg commented Nov 3, 2023

@matthew-dean hi can you help check this PR? I need use it in my project. I had added unit test.

@iChenLei
Copy link
Member

iChenLei commented Nov 3, 2023

@matthew-dean hi can you help check this PR? I need use it in my project. I had added unit test.

If you're in a hurry, you don't need to wait for code merging and the release of a new version. You can use libraries like patch-package(or pnpm patch) to apply patches to less npm package, temporarily resolving your issue.

@bestlyg
Copy link
Author

bestlyg commented Nov 3, 2023

@matthew-dean hi can you help check this PR? I need use it in my project. I had added unit test.

If you're in a hurry, you don't need to wait for code merging and the release of a new version. You can use libraries like patch-package(or pnpm patch) to apply patches to less npm package, temporarily resolving your issue.

Thank you. It was able to solve my problem temporarily. Please check this PR when you have time.

@matthew-dean
Copy link
Member

Looks fine, thanks!

@bestlyg
Copy link
Author

bestlyg commented Dec 6, 2023

Hi, I found the pr is approved. May I ask when the pr merge in main branch. Because now I need use the feature in other repo.And I can’t use pnpm patch in each repo.Thanks.

@bestlyg
Copy link
Author

bestlyg commented Jan 25, 2024

@iChenLei @matthew-dean May I ask when the pr merge in main branch. I need use it in other repo.

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.

3 participants