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

!important without whitespace considered invalid in some cases #155

Closed
ArgonAlex opened this issue Mar 25, 2021 · 7 comments
Closed

!important without whitespace considered invalid in some cases #155

ArgonAlex opened this issue Mar 25, 2021 · 7 comments

Comments

@ArgonAlex
Copy link

It seems like !important immediately preceded by a ) is being considered an invalid value. e.g:

width:calc(100% - 10px)!important;
color:rgb(0,0,0)!important;
@lahmatiy
Copy link
Member

Considered by whom? I know nothing about issues with this.

@ArgonAlex
Copy link
Author

By csstree. I think it's a bug.

console.log(require('css-tree').lexer.matchProperty('width', 'calc(33.33333% - 10px)!important;').error);
SyntaxError [SyntaxMatchError]: Mismatch
    at matchSyntax (node_modules\css-tree\lib\lexer\Lexer.js:87:17)
    at Lexer.matchProperty (node_modules\css-tree\lib\lexer\Lexer.js:331:16)
  message: 'Mismatch\n' +
    '  syntax: auto | <length> | <percentage> | min-content | max-content | fit-content( <length-percentage> )\n' +
    '   value: calc(33.33333% - 10px)!important;\n' +
    '  ------------------------------^',
  rawMessage: 'Mismatch',
  syntax: 'auto | <length> | <percentage> | min-content | max-content | fit-content( <length-percentage> )',
  css: 'calc(33.33333% - 10px)!important;',
  mismatchOffset: 22,
  mismatchLength: 1,
  offset: 22,
  line: 1,
  column: 23,
  loc: {
    source: '<unknown>',
    start: { offset: 22, line: 1, column: 23 },
    end: { offset: 23, line: 1, column: 24 }
  }
}

@lahmatiy
Copy link
Member

lahmatiy commented Mar 30, 2021

Thank you for clarification.
That's not a bug, since lexer.matchProperty() tests a property name and a value against a definition syntax. !important is not a part of a value, but a declaration:

image

So, you need to discard !important somehow before using matchProperty(). Another option is to use matchDeclaration() e.g.:

const { lexer, parse } = require('css-tree');
console.log(lexer.matchDeclaration(parse('width: calc(33.33333% - 10px)!important', { context: 'declaration' })));

@ArgonAlex
Copy link
Author

Ah ok thanks for the explanation. I might have encountered a bug in csstree-validator then, since it's using matchProperty() to validate declarations.

@lahmatiy
Copy link
Member

As mentioned in csstree/validator#18, CSSTree's parser has a bug when parseValue option is set to false. In this case !important is included into a value but must not. I found it happens only when parentheses (functions) or brackets are used in a value.

lahmatiy added a commit that referenced this issue Mar 30, 2021
…ns parentheses or brackets, in that case `!important` was included into a value (fixes #155)
@lahmatiy
Copy link
Member

Will be available in next release today.

lahmatiy added a commit that referenced this issue Mar 30, 2021
…arentheses or brackets when `parseValue` is set to `false`, in that case `!important` was included into a value. No changes in the source since it's already fixed in 2.0 (#155)
@lahmatiy
Copy link
Member

Fixed in 1.1.3

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

No branches or pull requests

2 participants