Skip to content

Commit 2c32afa

Browse files
committed
Revert "feat: 支持::part元素选择器#0"
This reverts commit f3e96dc.
1 parent 19d985f commit 2c32afa

File tree

2 files changed

+14
-41
lines changed

2 files changed

+14
-41
lines changed

packages/uni-nvue-styler/src/normalize/index.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ function createRuleProcessor(opts: NormalizeOptions = {}) {
4444
if (hasDeepMethod) {
4545
selector = selector.replace(/:deep\(([^)]+)\)/g, '$1')
4646
}
47-
const hasPart = selector.includes('::part')
48-
if (hasPart) {
49-
// 先将:part(xxx) 替换为 -_part__xxx_-, 绕过组合符号限制校验
50-
selector = selector.replace(/::part\(([^)]+)\)/g, '-_part__$1_-')
51-
}
5247
}
5348
// 移除组合符周围的空格,合并多个空格
5449
selector = selector
@@ -62,7 +57,7 @@ function createRuleProcessor(opts: NormalizeOptions = {}) {
6257
rule.warn(
6358
helper.result,
6459
'ERROR: Selector `' +
65-
selector.replace(/-_part__(.+)_-/g, '::part($1)') + // TODO 目前仅还原了part,预处理还原逻辑需要完善
60+
selector +
6661
'` is not supported. ' +
6762
type +
6863
' only support classname selector'

packages/uni-nvue-styler/src/objectifier.ts

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -142,45 +142,23 @@ function transformSelector(
142142
if (!res) {
143143
return
144144
}
145-
146145
let parentSelector = res[1]
147-
let curSelector = res[2]
148-
// 恢复 ::part(xxx)
149-
if (parentSelector.includes('-_part__')) {
150-
parentSelector = parentSelector.replace(/-_part__(.+)_-/g, '::part($1)')
151-
}
152-
if (curSelector.includes('-_part__')) {
153-
curSelector = curSelector.replace(/-_part__(.+)_-/g, '::part($1)')
154-
}
146+
let curSelector = res[2].substring(1)
155147
// .a.b => a.b
156-
const dotIndex = curSelector.lastIndexOf('.')
157-
if (dotIndex > 0) {
158-
parentSelector += curSelector.substring(0, dotIndex)
159-
curSelector = curSelector.substring(dotIndex)
160-
}
161-
if (curSelector.indexOf('.') === 0) {
162-
curSelector = curSelector.substring(1)
148+
const dotIndex = curSelector.indexOf('.')
149+
if (dotIndex > -1) {
150+
parentSelector += curSelector.substring(dotIndex)
151+
curSelector = curSelector.substring(0, dotIndex)
163152
}
164153

165-
const pseudoElementIndex = curSelector.indexOf('::')
166-
if (pseudoElementIndex > -1) {
167-
// TODO 目前仅支持::part作为最后个Selector Component使用
168-
// ::part(xxx).xxx 是否支持?
169-
// ::part(xxx):active 保留原样?
170-
const partSelector = curSelector.slice(pseudoElementIndex)
171-
const baseSelector = curSelector.substring(0, pseudoElementIndex)
172-
curSelector = partSelector
173-
parentSelector += baseSelector
174-
} else {
175-
const pseudoIndex = curSelector.indexOf(':')
176-
if (pseudoIndex > -1) {
177-
const pseudoClass = curSelector.slice(pseudoIndex)
178-
curSelector = curSelector.slice(0, pseudoIndex)
179-
Object.keys(body).forEach(function (name) {
180-
body[name + pseudoClass] = body[name]
181-
delete body[name]
182-
})
183-
}
154+
const pseudoIndex = curSelector.indexOf(':')
155+
if (pseudoIndex > -1) {
156+
const pseudoClass = curSelector.slice(pseudoIndex)
157+
curSelector = curSelector.slice(0, pseudoIndex)
158+
Object.keys(body).forEach(function (name) {
159+
body[name + pseudoClass] = body[name]
160+
delete body[name]
161+
})
184162
}
185163
transition(curSelector, body, context)
186164
if (!Object.keys(body).length) {

0 commit comments

Comments
 (0)