eslint-plugin-mpx 0.2.30 → 0.2.31

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.
@@ -128,6 +128,7 @@ module.exports = {
128
128
  }
129
129
  },
130
130
  create(context) {
131
+ const sourceCode = context.getSourceCode()
131
132
  // 收集一下initData的属性
132
133
  const propsSet = new Set([])
133
134
  // 收集computed属性
@@ -186,13 +187,25 @@ module.exports = {
186
187
  node.value.value &&
187
188
  node.value.value.startsWith('{{')
188
189
  if (isattr) {
189
- const reg = /(?<={{).*?(?=}})/
190
+ // 使用 sourceCode.getText() 获取完整的属性值文本,支持多行
191
+ const text = sourceCode.getText(node.value)
192
+ const reg = /(?<={{).*?(?=}})/s // 添加 s flag 支持多行匹配
193
+ const match = text.match(reg)
194
+
195
+ // 如果无法匹配到有效的表达式,跳过检查
196
+ if (!match) {
197
+ return
198
+ }
199
+
200
+ // 提取表达式内容并去除多余的空白字符
201
+ const expression = match[0].trim()
202
+
190
203
  checkInInitData(
191
204
  computedSet,
192
205
  propsSet,
193
206
  context,
194
207
  node,
195
- node.value.value.match(reg)?.[0],
208
+ expression,
196
209
  hasInitData
197
210
  )
198
211
  checkInitData(
@@ -201,7 +214,7 @@ module.exports = {
201
214
  hasInitData,
202
215
  context,
203
216
  node,
204
- node.value.value.match(reg)?.[0]
217
+ expression
205
218
  )
206
219
  }
207
220
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-mpx",
3
- "version": "0.2.30",
3
+ "version": "0.2.31",
4
4
  "description": "Official ESLint plugin for Mpx.js",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",