diff --git a/packages/vue-cli-plugin-hbuilderx/packages/weex-styler/index.js b/packages/vue-cli-plugin-hbuilderx/packages/weex-styler/index.js index 957d1a4a2591cd7b1b5c775f4bd9a4faab94130e..d30810cb9c805847830f2a60310ecdd32b7a16da 100644 --- a/packages/vue-cli-plugin-hbuilderx/packages/weex-styler/index.js +++ b/packages/vue-cli-plugin-hbuilderx/packages/weex-styler/index.js @@ -4,7 +4,6 @@ var css = require('css') var util = require('./lib/util') var validateItem = require('./lib/validator').validate var shorthandParser = require('./lib/shorthand-parser') -var importantStr = ' !important' // padding & margin shorthand parsing function convertLengthShorthand (rule, prop) { @@ -101,8 +100,9 @@ function parse (code, done) { name = declaration.property value = declaration.value - var important = value.endsWith(importantStr) - value = value.replace(new RegExp(importantStr, 'g'), '') + var newValue = value.replace(/\s*!important/g, '') + var importantWeight = Number(value !== newValue) + value = newValue // validate declarations and collect them to result camelCasedName = util.hyphenedToCamelCase(name) @@ -110,8 +110,13 @@ function parse (code, done) { /* istanbul ignore else */ if (typeof subResult.value === 'number' || typeof subResult.value === 'string') { - // 增加 important 权重信息 - ruleResult[camelCasedName] = process.env.UNI_USING_NVUE_STYLE_COMPILER ? [subResult.value, Number(important)] : subResult.value + if (process.env.UNI_USING_NVUE_STYLE_COMPILER) { + var oldValue = ruleResult[camelCasedName] + // 增加 important 权重信息 + ruleResult[camelCasedName] = Array.isArray(oldValue) && oldValue[1] > importantWeight ? oldValue : [subResult.value, importantWeight] + } else { + ruleResult[camelCasedName] = subResult.value + } } if (subResult.log) { subResult.log.line = declaration.position.start.line diff --git a/packages/vue-cli-plugin-hbuilderx/packages/weex-styler/lib/shorthand-parser.js b/packages/vue-cli-plugin-hbuilderx/packages/weex-styler/lib/shorthand-parser.js index b20f5aed0540fee94a4dc2c6b6a45bfcf227fbd0..1c504753f98493780187276d2f74f6a27e0b287c 100644 --- a/packages/vue-cli-plugin-hbuilderx/packages/weex-styler/lib/shorthand-parser.js +++ b/packages/vue-cli-plugin-hbuilderx/packages/weex-styler/lib/shorthand-parser.js @@ -8,7 +8,7 @@ function generateDeclaration (property, value, important, position) { } function clearImportant (value) { - var newValue = value.replace(/ !important$/, '') + var newValue = value.replace(/\s*!important/g, '') return { value: newValue, important: value !== newValue