From 3a346a24ee6e0eefd7731d1000825d7ec5ec3fdb Mon Sep 17 00:00:00 2001 From: tom Date: Fri, 10 May 2019 14:48:43 +0800 Subject: [PATCH] Resolve the issue that rules with '*' selector always got removed even if overwritten in replaceTagSelector (see change of index.test.js) --- index.js | 4 ++-- test/index.test.js | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 9445f3e..8b6bd68 100644 --- a/index.js +++ b/index.js @@ -41,7 +41,7 @@ module.exports = postcss.plugin('postcss-mpvue-wxss', function (options) { } } }); - + root.walkRules(rule => { const { selector } = rule || {}; @@ -54,7 +54,7 @@ module.exports = postcss.plugin('postcss-mpvue-wxss', function (options) { selectors.each(function (selector) { selector.each(function (n) { // 转换 tag 选择器 - if (n.type === 'tag') { + if (n.type === 'tag'||n.type === 'universal') { const k = n.value; const v = options.replaceTagSelector[k]; if (v) { diff --git a/test/index.test.js b/test/index.test.js index 13470d5..88b9485 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -139,6 +139,9 @@ it('test replaceTagSelector with options', () => { } bbb { width: 60rpx; + } + * { + box-sizing: border-box; }`; const output = ` ._aaa { @@ -146,11 +149,15 @@ it('test replaceTagSelector with options', () => { } ccc, .ddd { width: 60rpx; + } + view, text { + box-sizing: border-box; }`; const options = { replaceTagSelector: { aaa: 'replaceToClass', - bbb: 'ccc, .ddd' + bbb: 'ccc, .ddd', + '*': 'view, text' } }; return run(input, output, options);