Skip to content

[Bug] : Incorrect calc(...) value crashes cssnano #910

@strarsis

Description

@strarsis

Describe the bug
Using some (specific) incorrect calc(...) values crashes cssnano.

To Reproduce
Use as input:

.test {
  min-height: calc(100vh20 / 80 * 20rem - 1rem);
}

You can try it in the cssnano playground.

On the cssnano playground:

Uncaught (in promise) 
JisonLexerError
hash: {errStr: "Lexical error on line 1: Unrecognized text.↵↵  Erroneous area:↵1: 100vh20 / 80 * 20rem - 1rem↵^..^", recoverable: false, text: "", token: null, line: 0, …}
postcssNode: Declaration {raws: {…}, type: "decl", parent: Rule, source: {…}, prop: "min-height", …}
message: "Lexical error on line 1: Unrecognized text.↵↵  Erroneous area:↵1: 100vh20 / 80 * 20rem - 1rem↵^..^"
name: "JisonLexerError"
stack: "JisonLexerError: Lexical error on line 1: Unrecognized text.↵↵  Erroneous area:↵1: 100vh20 / 80 * 20rem - 1rem↵^..^↵    at <input css 86>:2:3↵    at Object.parseError (https://cssnano.co/phenomic/phenomic.main.22573732.js:131424:15)↵    at Object.lexer_parseError [as parseError] (https://cssnano.co/phenomic/phenomic.main.22573732.js:132557:44)↵    at Object.lexer_next [as next] (https://cssnano.co/phenomic/phenomic.main.22573732.js:133552:22)↵    at Object.lexer_fastLex [as fastLex] (https://cssnano.co/phenomic/phenomic.main.22573732.js:133627:18)↵    at fastLex (https://cssnano.co/phenomic/phenomic.main.22573732.js:131827:27)↵    at Parser.parse (https://cssnano.co/phenomic/phenomic.main.22573732.js:131901:30)↵    at https://cssnano.co/phenomic/phenomic.main.22573732.js:127716:30↵    at walk (https://cssnano.co/phenomic/phenomic.main.22573732.js:76903:7)↵    at ValueParser.walk (https://cssnano.co/phenomic/phenomic.main.22573732.js:417:3)↵    at transformValue (https://cssnano.co/phenomic/phenomic.main.22573732.js:127710:50)"
__proto__: Error

On a node build environment:

Module build failed: ModuleBuildError: Module build failed: TypeError: Cannot assign to read only property 'stack' of object 'JisonParserError: Cannot read property '0' of null'
    at [...]/node_modules/postcss/lib/container.js:141:19
    at Rule.each ([...]/node_modules/postcss/lib/container.js:101:16)
    at Rule.walk ([...]/node_modules/postcss/lib/container.js:131:17)
    at [...]/node_modules/postcss/lib/container.js:148:24
    at Root.each ([...]/node_modules/postcss/lib/container.js:101:16)
    at Root.walk ([...]/node_modules/postcss/lib/container.js:131:17)
    at [...]/node_modules/postcss-calc/dist/index.js:23:9
    at initializePlugin ([...]/node_modules/cssnano/dist/index.js:31:51)
    at <anonymous>
    at runLoaders ([...]/node_modules/webpack/lib/NormalModule.js:195:19)
    at [...]/node_modules/loader-runner/lib/LoaderRunner.js:367:11
    at [...]/node_modules/loader-runner/lib/LoaderRunner.js:233:18
    at context.callback ([...]/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
    at Promise.resolve.then.then.catch ([...]/node_modules/postcss-loader/src/index.js:208:9)
    at <anonymous>

Expected behavior
cssnano either ignores the cals(...) value or handles the error correctly and
prints an explanatory error message, like incorrect calc(...) value: 100vh20 / 80 * 20rem - 1rem.

Desktop (please complete the following information):

  • CSSNANO Version [e.g. 22] v4.1.10
    (as in cssnano playground)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions