Skip to content

Compress will break calc when use 0px #3318

Description

@NE-SmallTown

Hi, I'm using a loader which would set the compress option in production mode. But in the production mode, less will do this:

https://github.com/less/less.js/blob/b8140d4baad18ba732e2b322d8891a9b0ff065d5/lib/less/tree/dimension.js#L43-L54

if (context && context.compress) {
    // Zero values doesn't need a unit
    if (value === 0 && this.unit.isLength()) {   //    <<<<<<<<<<<------ see here
        output.add(strValue);
        return;
    }

    // Float values doesn't need a leading zero
    if (value > 0 && value < 1) {
        strValue = (strValue).substr(1);
    }
}

So, if I use something like:
calc(0px + 1rem + 2rem)
it will output:
calc(0 + 1rem + 2rem)
which will make the css broken in production mode.

Yea, why I don't just use calc(1rem + 2rem)? That's because this is just an example, actually I use calc(@offset - env(safe-area-inset-bottom)) in my less file(@offset will be 0 sometimes).

So, is this a bug? IMO, we could don't remove the unit(i.e. 'px') when in the calc expression but I'm not familiar with the less codebase.

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

    Issue actions