Skip to content

Can not find variable when a variable be created in plugin. #4241

Open
@bestlyg

Description

@bestlyg

To reproduce:

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 tried to fix the code. URL

Current behavior:

Expected behavior:

Environment information:

  • less version:
  • nodejs version:
  • operating system:

Activity

Vijay-948

Vijay-948 commented on Oct 30, 2023

@Vijay-948

can you assign me I will try this

bestlyg

bestlyg commented on Oct 30, 2023

@bestlyg
Author

can you assign me I will try this

I've tried to fix it. URL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @bestlyg@Vijay-948

        Issue actions

          Can not find variable when a variable be created in plugin. · Issue #4241 · less/less.js