Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MuGuiLin
uni-app
提交
8d8f7c7a
U
uni-app
项目概览
MuGuiLin
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8d8f7c7a
编写于
2月 16, 2022
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(app): nvue styler
上级
062fdc23
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
56 addition
and
11 deletion
+56
-11
packages/uni-nvue-styler/__tests__/combinators.spec.ts
packages/uni-nvue-styler/__tests__/combinators.spec.ts
+27
-4
packages/uni-nvue-styler/package.json
packages/uni-nvue-styler/package.json
+1
-0
packages/uni-nvue-styler/src/objectifier.ts
packages/uni-nvue-styler/src/objectifier.ts
+26
-7
pnpm-lock.yaml
pnpm-lock.yaml
+2
-0
未找到文件。
packages/uni-nvue-styler/__tests__/combinators.spec.ts
浏览文件 @
8d8f7c7a
...
...
@@ -14,17 +14,16 @@ async function objectifierRule(input: string) {
describe
(
'
nvue-styler: combinators
'
,
()
=>
{
test
(
'
descendant
'
,
async
()
=>
{
const
{
json
,
messages
}
=
await
objectifierRule
(
` .bar {left:5;}.foo .bar {left: 0
;}.foo .bar{left:5;right:10;
}.bar .bar{left:2}.foo .bar .foobar{left:1}`
` .bar {left:5;}.foo .bar {left: 0
!important;}.foo .bar{left:5;right:5;right:10!important
}.bar .bar{left:2}.foo .bar .foobar{left:1}`
)
console
.
log
(
json
,
messages
)
expect
(
json
).
toEqual
({
bar
:
{
left
:
5
,
},
'
.bar
'
:
{
'
.foo
'
:
{
left
:
5
,
right
:
10
,
'
!left
'
:
0
,
'
!right
'
:
10
,
},
'
.bar
'
:
{
left
:
2
,
...
...
@@ -34,4 +33,28 @@ describe('nvue-styler: combinators', () => {
})
expect
(
messages
.
length
).
toBe
(
0
)
})
test
(
'
other
'
,
async
()
=>
{
const
types
=
[
'
>
'
,
'
+
'
,
'
~
'
]
for
(
const
type
of
types
)
{
const
{
json
,
messages
}
=
await
objectifierRule
(
` .bar {left:5;}.foo
${
type
}
.bar {left: 0;}.foo
${
type
}
.bar{left:5;right:10;}.bar
${
type
}
.bar{left:2}.foo
${
type
}
.bar
${
type
}
.foobar{left:1}`
)
expect
(
json
).
toEqual
({
bar
:
{
left
:
5
,
},
'
.bar
'
:
{
[
`.foo
${
type
}
`
]:
{
left
:
5
,
right
:
10
,
},
[
`.bar
${
type
}
`
]:
{
left
:
2
,
},
},
'
.foobar
'
:
{
[
`.foo
${
type
}
.bar
${
type
}
`
]:
{
left
:
1
}
},
})
expect
(
messages
.
length
).
toBe
(
0
)
}
})
})
packages/uni-nvue-styler/package.json
浏览文件 @
8d8f7c7a
...
...
@@ -17,6 +17,7 @@
},
"license"
:
"Apache-2.0"
,
"dependencies"
:
{
"@vue/shared"
:
"3.2.30"
,
"parse-css-font"
:
"^4.0.0"
,
"postcss"
:
"^8.4.5"
}
...
...
packages/uni-nvue-styler/src/objectifier.ts
浏览文件 @
8d8f7c7a
import
{
Container
,
Root
,
Document
}
from
'
postcss
'
import
{
extend
}
from
'
@vue/shared
'
import
{
extend
,
hasOwn
}
from
'
@vue/shared
'
interface
ObjectifierContext
{
'
FONT-FACE
'
:
Record
<
string
,
unknown
>
[]
...
...
@@ -43,8 +43,16 @@ function transform(
transformSelector
(
selector
,
body
,
result
,
context
)
})
}
else
if
(
child
.
type
===
'
decl
'
)
{
if
(
child
.
important
)
{
result
[
'
!
'
+
child
.
prop
]
=
child
.
value
// !important的值域优先级高,故删除非!important的值域
delete
result
[
child
.
prop
]
}
else
{
if
(
!
hasOwn
(
result
,
'
!
'
+
child
.
prop
))
{
result
[
child
.
prop
]
=
child
.
value
}
}
}
})
return
result
}
...
...
@@ -56,10 +64,8 @@ function transformSelector(
context
:
ObjectifierContext
)
{
let
className
=
selector
.
slice
(
1
)
let
isCombinators
=
false
const
lastDotIndex
=
className
.
lastIndexOf
(
'
.
'
)
if
(
lastDotIndex
>
0
)
{
isCombinators
=
true
className
=
className
.
substring
(
lastDotIndex
+
1
)
}
const
pseudoIndex
=
className
.
indexOf
(
'
:
'
)
...
...
@@ -72,22 +78,35 @@ function transformSelector(
})
}
transition
(
className
,
body
,
context
)
if
(
isCombinators
)
{
if
(
lastDotIndex
>
0
)
{
className
=
'
.
'
+
className
result
=
(
result
[
className
]
||
(
result
[
className
]
=
{}))
as
Record
<
string
,
unknown
>
className
=
selector
.
replace
(
className
,
''
).
trim
()
className
=
selector
.
substring
(
0
,
lastDotIndex
+
1
).
trim
()
}
if
(
result
[
className
])
{
// clone
result
[
className
]
=
extend
({},
result
[
className
],
body
)
result
[
className
]
=
processImportant
(
extend
({},
result
[
className
],
body
)
)
}
else
{
result
[
className
]
=
body
}
}
/**
* 处理 important 属性,如果某个属性是 important,需要将非 important 的该属性移除掉
* @param body
*/
function
processImportant
(
body
:
Record
<
string
,
unknown
>
)
{
Object
.
keys
(
body
).
forEach
((
name
)
=>
{
if
(
name
.
startsWith
(
'
!
'
))
{
delete
body
[
name
.
substring
(
1
)]
}
})
return
body
}
function
transition
(
className
:
string
,
body
:
Record
<
string
,
unknown
>
,
...
...
pnpm-lock.yaml
浏览文件 @
8d8f7c7a
...
...
@@ -660,9 +660,11 @@ importers:
packages/uni-nvue-styler
:
specifiers
:
'
@vue/shared'
:
3.2.30
parse-css-font
:
^4.0.0
postcss
:
^8.4.5
dependencies
:
'
@vue/shared'
:
3.2.30
parse-css-font
:
4.0.0
postcss
:
8.4.6
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录