diff --git a/objectifier.js b/objectifier.js index 7663dd7..8298ec3 100644 --- a/objectifier.js +++ b/objectifier.js @@ -54,8 +54,8 @@ function process(node, options = {}) { if (result[child.selector]) { for (let i in body) { let object = result[child.selector]; - if (stringifyImportant && object[i] && object[i].endsWith('!important')) { - if (body[i].endsWith('!important')) { + if (stringifyImportant && typeof object[i] === "string" && object[i].endsWith('!important')) { + if (typeof body[i] === "string" && body[i].endsWith('!important')) { object[i] = body[i] } } else { diff --git a/test/objectifier.test.js b/test/objectifier.test.js index 3d49a1e..39cc9e3 100644 --- a/test/objectifier.test.js +++ b/test/objectifier.test.js @@ -184,5 +184,22 @@ test('keeps last important with priority', () => { }) }) +test('keeps last important with priority', () => { + let root = parse('a { vertical-align: 2px center; };a { vertical-align: 1px center; }') + equal(postcssJS.objectify(root, { stringifyImportant: true }), { + a: { + 'verticalAlign': "1px center" + } + }) +}) + +test('keeps last important with priority', () => { + let root = parse('a { vertical-align: 2px center !important; };a { vertical-align: 1px center; }') + equal(postcssJS.objectify(root, { stringifyImportant: true }), { + a: { + 'verticalAlign': "2px center !important" + } + }) +}) test.run()