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

Method supportedValue should support !important property. #215

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/supported-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default function supportedValue(property, value) {
// IE can even throw an error in some cases, for e.g. style.content = 'bar'.
try {
// Test value as it is.
el.style[property] = prefixedValue
el.style.setProperty(property, ...prefixedValue.split(/!(?=important$)/))
Copy link
Member

@kof kof Aug 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I think we don't need to pass important for the test at all, because the result for our tests should be the same no matter if there is important or not, we can get rid of spread operator here as well
  2. we need to do some micro benchmarking on esbench to see what's the fastest way to get rid of "important", I would guess str.replace will be much faster than doing the split

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess is this hsould be the fastest: .replace(/!important[\s]*$/, '') - I think supporting accidental whitespace at the end is a good idea

} catch (err) {
// Return false if value not supported.
cache[cacheKey] = false
Expand Down
11 changes: 11 additions & 0 deletions src/supported-value.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,16 @@ describe('css-vendor', () => {
prefix.js === 'ms' && prefix.browser !== 'edge' ? false : value
)
})

it('should support !important property', () => {
expect(supportedValue('border', 'solid 1px indigo !important')).to.be(
'solid 1px indigo !important'
)
expect(supportedValue('font-size', '12px!important')).to.be('12px!important')
})

it('should support content property with the value contains !important string', () => {
expect(supportedValue('content', '!important')).to.be('!important')
})
})
})