Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
genary
uni-app
提交
ef2890c5
U
uni-app
项目概览
genary
/
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,发现更多精彩内容 >>
提交
ef2890c5
编写于
3月 08, 2022
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mp): normalize style (#3320)
上级
bfb5d4f3
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
52 addition
and
6 deletion
+52
-6
packages/uni-cli-shared/src/vite/utils/ast.ts
packages/uni-cli-shared/src/vite/utils/ast.ts
+5
-0
packages/uni-mp-compiler/__tests__/class.spec.ts
packages/uni-mp-compiler/__tests__/class.spec.ts
+9
-0
packages/uni-mp-compiler/__tests__/component.spec.ts
packages/uni-mp-compiler/__tests__/component.spec.ts
+2
-2
packages/uni-mp-compiler/__tests__/style.spec.ts
packages/uni-mp-compiler/__tests__/style.spec.ts
+14
-4
packages/uni-mp-compiler/src/compile.ts
packages/uni-mp-compiler/src/compile.ts
+2
-0
packages/uni-mp-compiler/src/transforms/transformAttr.ts
packages/uni-mp-compiler/src/transforms/transformAttr.ts
+20
-0
未找到文件。
packages/uni-cli-shared/src/vite/utils/ast.ts
浏览文件 @
ef2890c5
...
...
@@ -17,6 +17,7 @@ import {
ElementNode
,
DirectiveNode
,
SimpleExpressionNode
,
AttributeNode
,
}
from
'
@vue/compiler-core
'
import
{
parse
}
from
'
@vue/compiler-dom
'
...
...
@@ -98,6 +99,10 @@ export function isElementNode(node: Node): node is ElementNode {
return
node
.
type
===
NodeTypes
.
ELEMENT
}
export
function
isAttributeNode
(
node
:
Node
):
node
is
AttributeNode
{
return
node
.
type
===
NodeTypes
.
ATTRIBUTE
}
export
function
isDirectiveNode
(
node
:
Node
):
node
is
DirectiveNode
{
return
node
.
type
===
NodeTypes
.
DIRECTIVE
}
...
...
packages/uni-mp-compiler/__tests__/class.spec.ts
浏览文件 @
ef2890c5
...
...
@@ -21,6 +21,15 @@ describe('compiler: transform class', () => {
`<view class="foo bar"/>`
,
`(_ctx, _cache) => {
return {}
}`
)
assert
(
`<view class="foo
bar
"/>`
,
`<view class="foo bar"/>`
,
`(_ctx, _cache) => {
return {}
}`
)
})
...
...
packages/uni-mp-compiler/__tests__/component.spec.ts
浏览文件 @
ef2890c5
...
...
@@ -100,8 +100,8 @@ describe('compiler: transform component', () => {
})
test
(
`component with props`
,
()
=>
{
assert
(
`<uni-collapse id="id" ref="a" :ref="b" slot="c" :slot="d" class="e" :class="f" style="g" :style="h" @click="i" v-model:first="j" v-model:last="k" prop-a="l" :prop-b="m" data-a="n" :data-b="o" key="p" :key="r" is="s" :is="t"/>`
,
`<uni-collapse id="id" ref="a" ref="{{a}}" slot="c" slot="{{b}}" class="{{['e', c]}}" style="{{'g' + ';' + d}}" bindclick="{{e}}" data-a="n" data-b="{{f}}" key="p" key="{{g}}" is="s" is="{{h}}" u-i="2a9ec0b0-0" bindupdateFirst="{{i}}" bindupdateLast="{{j}}" u-p="{{k}}"/>`
,
`<uni-collapse id="id" ref="a" :ref="b" slot="c" :slot="d" class="e" :class="f" style="g
:g;
" :style="h" @click="i" v-model:first="j" v-model:last="k" prop-a="l" :prop-b="m" data-a="n" :data-b="o" key="p" :key="r" is="s" :is="t"/>`
,
`<uni-collapse id="id" ref="a" ref="{{a}}" slot="c" slot="{{b}}" class="{{['e', c]}}" style="{{'g
:g
' + ';' + d}}" bindclick="{{e}}" data-a="n" data-b="{{f}}" key="p" key="{{g}}" is="s" is="{{h}}" u-i="2a9ec0b0-0" bindupdateFirst="{{i}}" bindupdateLast="{{j}}" u-p="{{k}}"/>`
,
`(_ctx, _cache) => {
return { a: _ctx.b, b: _ctx.d, c: _n(_ctx.f), d: _s(_ctx.h), e: _o(_ctx.i), f: _ctx.o, g: _ctx.r, h: _ctx.t, i: _o($event => _ctx.j = $event), j: _o($event => _ctx.k = $event), k: _p({ ['prop-a']: 'l', ['prop-b']: _ctx.m, first: _ctx.j, last: _ctx.k }) }
}`
...
...
packages/uni-mp-compiler/__tests__/style.spec.ts
浏览文件 @
ef2890c5
...
...
@@ -4,14 +4,24 @@ describe('compiler: transform style', () => {
test
(
`static style`
,
()
=>
{
assert
(
`<view style="color: green"/>`
,
`<view style="color:
green"/>`
,
`<view style="color:green"/>`
,
`(_ctx, _cache) => {
return {}
}`
)
assert
(
`<view style="color: green;font-size: 15px"/>`
,
`<view style="color: green;font-size: 15px"/>`
,
`<view style="color:green;font-size:15px"/>`
,
`(_ctx, _cache) => {
return {}
}`
)
assert
(
`<view style="
color: green;
font-size: 15px;
"/>`
,
`<view style="color:green;font-size:15px"/>`
,
`(_ctx, _cache) => {
return {}
}`
...
...
@@ -36,14 +46,14 @@ describe('compiler: transform style', () => {
test
(
'
v-bind:style basic + style
'
,
()
=>
{
assert
(
`<view :style="foo" style="color:green;"/>`
,
`<view style="{{a + ';' + 'color:green
;
'}}"/>`
,
`<view style="{{a + ';' + 'color:green'}}"/>`
,
`(_ctx, _cache) => {
return { a: _s(_ctx.foo) }
}`
)
assert
(
`<view style="color:green;" :style="foo"/>`
,
`<view style="{{'color:green
;
' + ';' + a}}"/>`
,
`<view style="{{'color:green' + ';' + a}}"/>`
,
`(_ctx, _cache) => {
return { a: _s(_ctx.foo) }
}`
...
...
packages/uni-mp-compiler/src/compile.ts
浏览文件 @
ef2890c5
...
...
@@ -18,6 +18,7 @@ import { transformSlot } from './transforms/vSlot'
import
{
transformRoot
}
from
'
./transforms/transformRoot
'
import
{
transformTag
}
from
'
./transforms/transformTag
'
import
{
transformHtml
}
from
'
./transforms/vHtml
'
import
{
transformAttr
}
from
'
./transforms/transformAttr
'
export
type
TransformPreset
=
[
NodeTransform
[],
...
...
@@ -34,6 +35,7 @@ export function getBaseTransformPreset({
// order is important
const
nodeTransforms
=
[
transformRoot
,
transformAttr
,
transformTag
,
transformHtml
,
transformIf
,
...
...
packages/uni-mp-compiler/src/transforms/transformAttr.ts
0 → 100644
浏览文件 @
ef2890c5
import
{
isAttributeNode
,
isElementNode
}
from
'
@dcloudio/uni-cli-shared
'
import
{
parseStringStyle
,
stringifyStyle
}
from
'
@vue/shared
'
import
{
NodeTransform
}
from
'
../transform
'
export
const
transformAttr
:
NodeTransform
=
(
node
,
_
)
=>
{
if
(
!
isElementNode
(
node
))
{
return
}
node
.
props
.
forEach
((
prop
)
=>
{
if
(
isAttributeNode
(
prop
)
&&
prop
.
value
)
{
switch
(
prop
.
name
)
{
case
'
style
'
:
prop
.
value
.
content
=
stringifyStyle
(
parseStringStyle
(
prop
.
value
.
content
)
).
slice
(
0
,
-
1
)
// 移除最后一个分号,省点大小吧
break
}
}
})
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录