@mpxjs/webpack-plugin 2.10.18-beta.1 → 2.10.18-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -91,7 +91,7 @@ function parse(cssString) {
|
|
|
91
91
|
return ast
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
function evaluateCondition(condition, defs) {
|
|
94
|
+
function evaluateCondition(condition, defs, filePath) {
|
|
95
95
|
try {
|
|
96
96
|
const keys = Object.keys(defs)
|
|
97
97
|
const values = keys.map(key => defs[key])
|
|
@@ -99,12 +99,12 @@ function evaluateCondition(condition, defs) {
|
|
|
99
99
|
const func = new Function(...keys, `return (${condition});`)
|
|
100
100
|
return func(...values)
|
|
101
101
|
} catch (e) {
|
|
102
|
-
console.error(`[Mpx style error]:Error evaluating condition: ${condition}`, e)
|
|
102
|
+
console.error(`[Mpx style error] File: ${filePath}, Error evaluating condition: ${condition}`, e)
|
|
103
103
|
return false
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
function traverseAndEvaluate(ast, defs) {
|
|
107
|
+
function traverseAndEvaluate(ast, defs, filePath) {
|
|
108
108
|
let output = ''
|
|
109
109
|
let batchedIf = false
|
|
110
110
|
function traverse(nodes) {
|
|
@@ -114,12 +114,12 @@ function traverseAndEvaluate(ast, defs) {
|
|
|
114
114
|
} else if (node.type === 'If') {
|
|
115
115
|
// 直接判断 If 节点
|
|
116
116
|
batchedIf = false
|
|
117
|
-
if (evaluateCondition(node.condition, defs)) {
|
|
117
|
+
if (evaluateCondition(node.condition, defs, filePath)) {
|
|
118
118
|
traverse(node.children)
|
|
119
119
|
batchedIf = true
|
|
120
120
|
}
|
|
121
121
|
} else if (node.type === 'ElseIf' && !batchedIf) {
|
|
122
|
-
if (evaluateCondition(node.condition, defs)) {
|
|
122
|
+
if (evaluateCondition(node.condition, defs, filePath)) {
|
|
123
123
|
traverse(node.children)
|
|
124
124
|
batchedIf = true
|
|
125
125
|
}
|
|
@@ -136,11 +136,12 @@ function traverseAndEvaluate(ast, defs) {
|
|
|
136
136
|
*
|
|
137
137
|
* @param {string} content
|
|
138
138
|
* @param {Record<string, any>} defs
|
|
139
|
+
* @param {string} [filePath]
|
|
139
140
|
* @returns
|
|
140
141
|
*/
|
|
141
|
-
function stripCondition(content, defs) {
|
|
142
|
+
function stripCondition(content, defs, filePath) {
|
|
142
143
|
const ast = parse(content)
|
|
143
|
-
return traverseAndEvaluate(ast, defs)
|
|
144
|
+
return traverseAndEvaluate(ast, defs, filePath || 'unknown')
|
|
144
145
|
}
|
|
145
146
|
|
|
146
147
|
let proxyReadFileSync
|
|
@@ -185,10 +186,10 @@ function startFSStripForCss(defs) {
|
|
|
185
186
|
if (shouldStrip(path)) {
|
|
186
187
|
try {
|
|
187
188
|
if (typeof content === 'string') {
|
|
188
|
-
return stripCondition(content, defs)
|
|
189
|
+
return stripCondition(content, defs, path)
|
|
189
190
|
} else if (Buffer.isBuffer(content)) {
|
|
190
191
|
const str = content.toString('utf-8')
|
|
191
|
-
const result = stripCondition(str, defs)
|
|
192
|
+
const result = stripCondition(str, defs, path)
|
|
192
193
|
if (result !== str) {
|
|
193
194
|
return Buffer.from(result, 'utf-8')
|
|
194
195
|
}
|
|
@@ -215,11 +216,11 @@ function startFSStripForCss(defs) {
|
|
|
215
216
|
if (shouldStrip(path)) {
|
|
216
217
|
try {
|
|
217
218
|
if (typeof data === 'string') {
|
|
218
|
-
const result = stripCondition(data, defs)
|
|
219
|
+
const result = stripCondition(data, defs, path)
|
|
219
220
|
return callback(null, result)
|
|
220
221
|
} else if (Buffer.isBuffer(data)) {
|
|
221
222
|
const content = data.toString('utf-8')
|
|
222
|
-
const result = stripCondition(content, defs)
|
|
223
|
+
const result = stripCondition(content, defs, path)
|
|
223
224
|
if (result !== content) {
|
|
224
225
|
return callback(null, Buffer.from(result, 'utf-8'))
|
|
225
226
|
}
|