Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
tomleePHP
uni-app
提交
10c4a910
U
uni-app
项目概览
tomleePHP
/
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,发现更多精彩内容 >>
提交
10c4a910
编写于
11月 05, 2019
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(v3): uni-migration
上级
22e7f76d
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
182 addition
and
3 deletion
+182
-3
packages/uni-migration/lib/index.js
packages/uni-migration/lib/index.js
+2
-1
packages/uni-migration/lib/mp-weixin/transform/wxml-transformer/index.js
...gration/lib/mp-weixin/transform/wxml-transformer/index.js
+3
-1
packages/uni-migration/lib/mp-weixin/transform/wxml-transformer/parser.js
...ration/lib/mp-weixin/transform/wxml-transformer/parser.js
+21
-0
packages/uni-migration/lib/mp-weixin/transform/wxml-transformer/transform/generate.js
...p-weixin/transform/wxml-transformer/transform/generate.js
+41
-0
packages/uni-migration/lib/mp-weixin/transform/wxml-transformer/transform/index.js
...b/mp-weixin/transform/wxml-transformer/transform/index.js
+9
-0
packages/uni-migration/lib/mp-weixin/transform/wxml-transformer/transform/traverse.js
...p-weixin/transform/wxml-transformer/transform/traverse.js
+101
-0
packages/uni-migration/package.json
packages/uni-migration/package.json
+5
-1
未找到文件。
packages/uni-migration/lib/index.js
浏览文件 @
10c4a910
...
...
@@ -17,6 +17,7 @@ module.exports = function migrate(input, out, options = {
}
migrater
.
transform
(
input
,
out
,
options
).
forEach
(
file
=>
{
console
.
log
(
`写入:
${
file
.
path
}
`
)
fs
.
outputFileSync
(
file
.
path
,
file
.
content
)
console
.
log
(
`
${
file
.
content
}
`
)
// fs.outputFileSync(file.path, file.content)
})
}
packages/uni-migration/lib/mp-weixin/transform/wxml-transformer/index.js
浏览文件 @
10c4a910
const
fs
=
require
(
'
fs
'
)
const
path
=
require
(
'
path
'
)
const
parse
=
require
(
'
./parser
'
)
const
transform
=
require
(
'
./transform
'
)
module
.
exports
=
function
transformWxml
(
filepath
)
{
return
[
fs
.
readFileSync
(
filepath
,
'
utf8
'
)]
return
transform
(
parse
(
fs
.
readFileSync
(
filepath
,
'
utf8
'
)))
}
packages/uni-migration/lib/mp-weixin/transform/wxml-transformer/parser.js
0 → 100644
浏览文件 @
10c4a910
const
{
Parser
,
DomHandler
}
=
require
(
'
stricter-htmlparser2
'
)
module
.
exports
=
function
parse
(
sourceCode
)
{
const
handler
=
new
DomHandler
()
new
Parser
(
handler
,
{
xmlMode
:
false
,
lowerCaseAttributeNames
:
false
,
recognizeSelfClosing
:
true
,
lowerCaseTags
:
false
}).
end
(
sourceCode
)
return
{
type
:
'
tag
'
,
name
:
'
root
'
,
attribs
:
{},
children
:
Array
.
isArray
(
handler
.
dom
)
?
handler
.
dom
:
[
handler
.
dom
]
}
}
packages/uni-migration/lib/mp-weixin/transform/wxml-transformer/transform/generate.js
0 → 100644
浏览文件 @
10c4a910
function
genAttrs
(
node
)
{
const
attribs
=
node
.
attribs
const
attribsArr
=
Object
.
keys
(
attribs
).
map
(
name
=>
`
${
name
}
="
${
attribs
[
name
]}
"`
)
if
(
!
attribsArr
.
length
)
{
return
''
}
return
'
'
+
attribsArr
.
join
(
'
'
)
}
function
genChildren
(
node
)
{
if
(
!
node
.
children
)
{
return
''
}
return
node
.
children
.
map
(
childNode
=>
genElement
(
childNode
)).
join
(
''
)
}
function
genElement
(
node
)
{
if
(
node
.
type
===
'
text
'
)
{
return
node
.
data
}
else
if
(
node
.
type
===
'
tag
'
)
{
const
name
=
node
.
name
return
`<
${
name
}${
genAttrs
(
node
)}
>
${
genChildren
(
node
)}
</
${
name
}
>`
}
return
''
}
function
genWxs
(
wxs
)
{
return
wxs
.
map
(
wxsNode
=>
genElement
(
wxsNode
)).
join
(
''
)
}
module
.
exports
=
function
generate
(
node
,
state
)
{
if
(
node
.
children
.
length
>
1
)
{
return
[
genChildren
({
type
:
'
tag
'
,
name
:
'
view
'
,
attribs
:
{},
children
:
node
.
children
}),
genWxs
(
state
.
wxs
)]
}
return
[
genChildren
(
node
),
genWxs
(
state
.
wxs
)]
}
packages/uni-migration/lib/mp-weixin/transform/wxml-transformer/transform/index.js
0 → 100644
浏览文件 @
10c4a910
const
traverse
=
require
(
'
./traverse
'
)
const
generate
=
require
(
'
./generate
'
)
module
.
exports
=
function
transform
(
ast
)
{
const
state
=
{
wxs
:
[]
}
return
generate
(
traverse
(
ast
,
state
),
state
)
}
packages/uni-migration/lib/mp-weixin/transform/wxml-transformer/transform/traverse.js
0 → 100644
浏览文件 @
10c4a910
const
{
parse
}
=
require
(
'
mustache
'
)
const
ATTRS
=
{
'
wx:if
'
:
'
v-if
'
,
'
wx:elif
'
:
'
v-else-if
'
,
'
wx:else
'
:
'
v-else
'
}
function
parseMustache
(
expr
)
{
const
tokens
=
parse
(
expr
)
const
isIdentifier
=
tokens
.
length
===
1
return
tokens
.
map
(
token
=>
{
if
(
token
[
0
]
===
'
text
'
)
{
return
`'
${
token
[
1
]}
'`
}
else
if
(
token
[
0
]
===
'
name
'
)
{
if
(
isIdentifier
)
{
return
token
[
1
]
}
return
`(
${
token
[
1
]}
)`
}
}).
join
(
'
+
'
)
}
function
transformDirective
(
name
,
value
,
attribs
)
{
if
(
ATTRS
[
name
])
{
attribs
[
ATTRS
[
name
]]
=
parseMustache
(
value
)
return
true
}
}
const
bindRE
=
/bind:
?
/
const
catchRE
=
/catch:
?
/
const
captureBindRE
=
/capture-bind:
?
/
const
captureCatchRE
=
/capture-catch:
?
/
function
transformEvent
(
name
,
value
,
attribs
)
{
let
event
=
name
if
(
name
.
indexOf
(
'
bind
'
)
===
0
)
{
event
=
name
.
replace
(
bindRE
,
'
@
'
)
}
else
if
(
name
.
indexOf
(
'
catch
'
)
===
0
)
{
event
=
name
.
replace
(
catchRE
,
'
@
'
)
+
'
.stop
'
}
else
if
(
name
.
indexOf
(
'
capture-bind
'
)
===
0
)
{
event
=
name
.
replace
(
captureBindRE
,
'
@
'
)
+
'
.capture
'
}
else
if
(
name
.
indexOf
(
'
capture-catch
'
)
===
0
)
{
event
=
name
.
replace
(
captureCatchRE
,
'
@
'
)
+
'
.stop.capture
'
}
if
(
event
!==
name
)
{
attribs
[
event
]
=
value
return
true
}
}
function
transformAttr
(
name
,
value
,
attribs
)
{
delete
attribs
[
name
]
if
(
transformDirective
(
name
,
value
,
attribs
))
{
return
}
if
(
transformEvent
(
name
,
value
,
attribs
))
{
return
}
if
(
value
.
indexOf
(
'
{{
'
)
===
-
1
)
{
attribs
[
name
]
=
value
return
}
attribs
[
'
:
'
+
name
]
=
parseMustache
(
value
)
}
function
transformAttrs
(
node
,
state
)
{
const
attribs
=
node
.
attribs
if
(
!
attribs
)
{
return
}
Object
.
keys
(
attribs
).
forEach
(
name
=>
{
transformAttr
(
name
,
attribs
[
name
],
attribs
)
})
}
function
transformChildren
(
node
,
state
)
{
node
.
children
=
node
.
children
.
filter
(
childNode
=>
transformNode
(
childNode
,
state
))
}
function
transformNode
(
node
,
state
)
{
if
(
node
.
name
===
'
wxs
'
)
{
state
.
wxs
.
push
(
node
)
return
false
}
if
(
node
.
type
===
'
tag
'
)
{
transformAttrs
(
node
,
state
)
transformChildren
(
node
,
state
)
}
return
true
}
module
.
exports
=
function
traverse
(
node
,
state
)
{
transformNode
(
node
,
state
)
return
node
}
packages/uni-migration/package.json
浏览文件 @
10c4a910
...
...
@@ -16,5 +16,9 @@
},
"author"
:
"fxy060608"
,
"license"
:
"Apache-2.0"
,
"gitHead"
:
"6b0d55e296028761e3de4b561c1ad7c5fb7a23e2"
"gitHead"
:
"6b0d55e296028761e3de4b561c1ad7c5fb7a23e2"
,
"dependencies"
:
{
"mustache"
:
"^3.1.0"
,
"stricter-htmlparser2"
:
"^3.9.6"
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录