Skip to content

Commit

Permalink
Be sure that Declaration#value is a string
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Jul 22, 2020
1 parent 10d974f commit 57c81be
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/declaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ let Node = require('./node')

class Declaration extends Node {
constructor (defaults) {
if (
defaults &&
typeof defaults.value !== 'undefined' &&
typeof defaults.value !== 'string'
) {
defaults = { ...defaults, value: String(defaults.value) }
}
super(defaults)
this.type = 'decl'
}
Expand Down
6 changes: 6 additions & 0 deletions test/declaration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ it('clones spaces from another declaration', () => {
rule.append(decl)
expect(root.toString()).toEqual('a{color:black;margin:0}')
})

it('converts value to string', () => {
// @ts-expect-error
let decl = new Declaration({ prop: 'color', value: 1 })
expect(decl.value).toEqual('1')
})

0 comments on commit 57c81be

Please sign in to comment.