提交 34841284 编写于 作者: Q qiang

fix(App): 修复 nvue 样式中 !important 前不含空格时报错的问题 question/117212

上级 8bdc5107
......@@ -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
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册