Skip to content

Commit

Permalink
[feat]optimize selectorQuery.select method
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderXL committed Sep 23, 2024
1 parent 55fe10d commit d8948db
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ export default class SelectorQuery {
if (!this._component) {
warn('Please use SelectorQuery.in method to set context')
}
selector = selector.trim()
// 后续如果要支持这种复杂的选择器,需要按场景拆分这些判断逻辑
if (/>|,|>>>|\+|~|\s+/.test(selector)) {
warn('SelectQuery.select don\'t support combinator selector, it only supports selector like #a or .a or .a.b now.')
return new NodeRef([], this, !all)
}
const refs = this._component && this._component.__selectRef(selector, 'node', all)
return new NodeRef(refs, this, !all)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/platform/builtInMixins/refsMixin.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function getRefsMixin () {
}
},
__selectRef (selector, refType, all = false) {
const splitedSelector = selector.match(/(#|\.)?\w+/g) || []
const splitedSelector = selector.match(/(#|\.)[\w-]+/g) || []
const refsArr = splitedSelector.map(selector => {
const selectorMap = this.__selectorMap?.value[selector] || []
const res = []
Expand Down

0 comments on commit d8948db

Please sign in to comment.