Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
菜鸟程序猿_c
uni-app
提交
e25ca33e
U
uni-app
项目概览
菜鸟程序猿_c
/
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,发现更多精彩内容 >>
提交
e25ca33e
编写于
10月 29, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(mp): mp-toutiao
上级
4a2b4ca4
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
205 addition
and
30 deletion
+205
-30
packages/uni-mp-toutiao/__tests__/swiper.spec.ts
packages/uni-mp-toutiao/__tests__/swiper.spec.ts
+43
-0
packages/uni-mp-toutiao/__tests__/testUtils.ts
packages/uni-mp-toutiao/__tests__/testUtils.ts
+38
-0
packages/uni-mp-toutiao/build.json
packages/uni-mp-toutiao/build.json
+6
-1
packages/uni-mp-toutiao/dist/uni.compiler.js
packages/uni-mp-toutiao/dist/uni.compiler.js
+50
-18
packages/uni-mp-toutiao/src/compiler/options.ts
packages/uni-mp-toutiao/src/compiler/options.ts
+20
-11
packages/uni-mp-toutiao/src/compiler/transforms/transformSwiper.ts
...uni-mp-toutiao/src/compiler/transforms/transformSwiper.ts
+48
-0
未找到文件。
packages/uni-mp-toutiao/__tests__/swiper.spec.ts
0 → 100644
浏览文件 @
e25ca33e
import
{
assert
}
from
'
./testUtils
'
describe
(
'
mp-toutiao: transform swiper
'
,
()
=>
{
// test(`attribute disable-touch`, () => {
// assert(
// `<swiper disable-touch/>`,
// `<swiper touchable="{{false}}"/>`,
// `(_ctx, _cache) => {
// return {}
// }`
// )
// assert(
// `<swiper disable-touch="false"/>`,
// `<swiper touchable="{{false}}"/>`,
// `(_ctx, _cache) => {
// return {}
// }`
// )
// })
test
(
`v-bind disable-touch`
,
()
=>
{
assert
(
`<swiper :disable-touch="true"/>`
,
`<swiper touchable="{{false}}"/>`
,
`(_ctx, _cache) => {
return {}
}`
)
assert
(
`<swiper :disable-touch="false"/>`
,
`<swiper touchable="{{true}}"/>`
,
`(_ctx, _cache) => {
return {}
}`
)
assert
(
`<swiper :disable-touch="disableTouch"/>`
,
`<swiper touchable="{{a}}"/>`
,
`(_ctx, _cache) => {
return { a: !_ctx.disableTouch }
}`
)
})
})
packages/uni-mp-toutiao/__tests__/testUtils.ts
0 → 100644
浏览文件 @
e25ca33e
import
{
isCustomElement
,
isNativeTag
}
from
'
@dcloudio/uni-shared
'
import
{
compile
,
CompilerOptions
}
from
'
@dcloudio/uni-mp-compiler
'
import
{
miniProgram
,
nodeTransforms
}
from
'
../src/compiler/options
'
export
function
assert
(
template
:
string
,
templateCode
:
string
,
renderCode
:
string
,
options
:
CompilerOptions
=
{}
)
{
const
res
=
compile
(
template
,
{
mode
:
'
module
'
,
filename
:
'
foo.vue
'
,
prefixIdentifiers
:
true
,
inline
:
true
,
isNativeTag
,
isCustomElement
,
generatorOpts
:
{
concise
:
true
,
},
nodeTransforms
,
miniProgram
:
{
...
miniProgram
,
emitFile
({
source
})
{
// console.log(source)
if
(
!
options
.
onError
)
{
expect
(
source
).
toBe
(
templateCode
)
}
return
''
},
},
...
options
,
})
if
(
!
options
.
onError
)
{
expect
(
res
.
code
).
toBe
(
renderCode
)
}
}
packages/uni-mp-toutiao/build.json
浏览文件 @
e25ca33e
...
@@ -6,7 +6,12 @@
...
@@ -6,7 +6,12 @@
"output"
:
{
"output"
:
{
"format"
:
"cjs"
"format"
:
"cjs"
},
},
"external"
:
[
"@dcloudio/uni-cli-shared"
,
"@dcloudio/uni-mp-vite"
]
"external"
:
[
"@vue/compiler-core"
,
"@dcloudio/uni-cli-shared"
,
"@dcloudio/uni-mp-vite"
,
"@dcloudio/uni-mp-compiler"
]
},
},
{
{
"input"
:
{
"input"
:
{
...
...
packages/uni-mp-toutiao/dist/uni.compiler.js
浏览文件 @
e25ca33e
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
var
initMiniProgramPlugin
=
require
(
'
@dcloudio/uni-mp-vite
'
);
var
initMiniProgramPlugin
=
require
(
'
@dcloudio/uni-mp-vite
'
);
var
path
=
require
(
'
path
'
);
var
path
=
require
(
'
path
'
);
var
uniCliShared
=
require
(
'
@dcloudio/uni-cli-shared
'
);
var
uniCliShared
=
require
(
'
@dcloudio/uni-cli-shared
'
);
var
uniMpCompiler
=
require
(
'
@dcloudio/uni-mp-compiler
'
);
var
compilerCore
=
require
(
'
@vue/compiler-core
'
);
function
_interopDefaultLegacy
(
e
)
{
return
e
&&
typeof
e
===
'
object
'
&&
'
default
'
in
e
?
e
:
{
'
default
'
:
e
};
}
function
_interopDefaultLegacy
(
e
)
{
return
e
&&
typeof
e
===
'
object
'
&&
'
default
'
in
e
?
e
:
{
'
default
'
:
e
};
}
...
@@ -30,7 +32,51 @@ var source = {
...
@@ -30,7 +32,51 @@ var source = {
condition
:
condition
condition
:
condition
};
};
function
transformSwiper
(
node
)
{
if
(
node
.
type
!==
1
/* ELEMENT */
||
node
.
tag
!==
'
swiper
'
)
{
return
;
}
const
disableTouchProp
=
compilerCore
.
findProp
(
node
,
'
disable-touch
'
,
false
,
true
);
if
(
!
disableTouchProp
)
{
return
;
}
const
{
props
}
=
node
;
if
(
disableTouchProp
.
type
===
6
/* ATTRIBUTE */
)
{
// <swiper disable-touch/> => <swiper :touchable="false"/>
props
.
splice
(
props
.
indexOf
(
disableTouchProp
),
1
,
uniCliShared
.
createBindDirectiveNode
(
'
touchable
'
,
'
false
'
));
}
else
{
if
(
disableTouchProp
.
exp
)
{
// <swiper :disable-touch="true"/> => <swiper :touchable="!(true)"/>
let
touchable
=
''
;
if
(
disableTouchProp
.
exp
.
type
===
4
/* SIMPLE_EXPRESSION */
)
{
if
(
disableTouchProp
.
exp
.
content
===
'
true
'
)
{
touchable
=
'
false
'
;
}
else
if
(
disableTouchProp
.
exp
.
content
===
'
false
'
)
{
touchable
=
'
true
'
;
}
}
props
.
splice
(
props
.
indexOf
(
disableTouchProp
),
1
,
uniCliShared
.
createBindDirectiveNode
(
'
touchable
'
,
touchable
||
`!(
${
uniMpCompiler
.
genExpr
(
disableTouchProp
.
exp
)}
)`
));
}
}
}
const
projectConfigFilename
=
'
project.config.json
'
;
const
projectConfigFilename
=
'
project.config.json
'
;
const
nodeTransforms
=
[
uniCliShared
.
transformRef
,
transformSwiper
,
uniCliShared
.
createTransformComponentLink
(
uniCliShared
.
COMPONENT_BIND_LINK
),
];
const
miniProgram
=
{
class
:
{
array
:
false
,
},
slot
:
{
fallback
:
true
,
},
directive
:
'
tt:
'
,
};
const
options
=
{
const
options
=
{
vite
:
{
vite
:
{
inject
:
{
inject
:
{
...
@@ -52,11 +98,7 @@ const options = {
...
@@ -52,11 +98,7 @@ const options = {
filename
:
projectConfigFilename
,
filename
:
projectConfigFilename
,
source
,
source
,
},
},
template
:
{
template
:
Object
.
assign
(
Object
.
assign
({},
miniProgram
),
{
filter
:
{
class
:
{
array
:
false
,
},
filter
:
{
extname
:
'
.sjs
'
,
extname
:
'
.sjs
'
,
lang
:
'
sjs
'
,
lang
:
'
sjs
'
,
generate
(
filter
,
filename
)
{
generate
(
filter
,
filename
)
{
...
@@ -67,19 +109,9 @@ const options = {
...
@@ -67,19 +109,9 @@ const options = {
${
filter
.
code
}
${
filter
.
code
}
</sjs>`
;
</sjs>`
;
},
},
},
},
extname
:
'
.ttml
'
,
compilerOptions
:
{
slot
:
{
nodeTransforms
,
fallback
:
true
,
}
}),
},
extname
:
'
.ttml
'
,
directive
:
'
tt:
'
,
compilerOptions
:
{
nodeTransforms
:
[
uniCliShared
.
transformRef
,
uniCliShared
.
createTransformComponentLink
(
uniCliShared
.
COMPONENT_BIND_LINK
),
],
},
},
style
:
{
style
:
{
extname
:
'
.ttss
'
,
extname
:
'
.ttss
'
,
},
},
...
...
packages/uni-mp-toutiao/src/compiler/options.ts
浏览文件 @
e25ca33e
...
@@ -2,14 +2,31 @@ import path from 'path'
...
@@ -2,14 +2,31 @@ import path from 'path'
import
{
import
{
COMPONENT_BIND_LINK
,
COMPONENT_BIND_LINK
,
createTransformComponentLink
,
createTransformComponentLink
,
MiniProgramCompilerOptions
,
transformRef
,
transformRef
,
}
from
'
@dcloudio/uni-cli-shared
'
}
from
'
@dcloudio/uni-cli-shared
'
import
{
UniMiniProgramPluginOptions
}
from
'
@dcloudio/uni-mp-vite
'
import
{
UniMiniProgramPluginOptions
}
from
'
@dcloudio/uni-mp-vite
'
import
source
from
'
./project.config.json
'
import
source
from
'
./project.config.json
'
import
{
transformSwiper
}
from
'
./transforms/transformSwiper
'
const
projectConfigFilename
=
'
project.config.json
'
const
projectConfigFilename
=
'
project.config.json
'
export
const
nodeTransforms
=
[
transformRef
,
transformSwiper
,
createTransformComponentLink
(
COMPONENT_BIND_LINK
),
]
export
const
miniProgram
:
MiniProgramCompilerOptions
=
{
class
:
{
array
:
false
,
},
slot
:
{
fallback
:
true
,
},
directive
:
'
tt:
'
,
}
export
const
options
:
UniMiniProgramPluginOptions
=
{
export
const
options
:
UniMiniProgramPluginOptions
=
{
vite
:
{
vite
:
{
inject
:
{
inject
:
{
...
@@ -32,9 +49,8 @@ export const options: UniMiniProgramPluginOptions = {
...
@@ -32,9 +49,8 @@ export const options: UniMiniProgramPluginOptions = {
source
,
source
,
},
},
template
:
{
template
:
{
class
:
{
/* eslint-disable no-restricted-syntax */
array
:
false
,
...
miniProgram
,
},
filter
:
{
filter
:
{
extname
:
'
.sjs
'
,
extname
:
'
.sjs
'
,
lang
:
'
sjs
'
,
lang
:
'
sjs
'
,
...
@@ -47,16 +63,9 @@ ${filter.code}
...
@@ -47,16 +63,9 @@ ${filter.code}
</sjs>`
</sjs>`
},
},
},
},
slot
:
{
fallback
:
true
,
},
extname
:
'
.ttml
'
,
extname
:
'
.ttml
'
,
directive
:
'
tt:
'
,
compilerOptions
:
{
compilerOptions
:
{
nodeTransforms
:
[
nodeTransforms
,
transformRef
,
createTransformComponentLink
(
COMPONENT_BIND_LINK
),
],
},
},
},
},
style
:
{
style
:
{
...
...
packages/uni-mp-toutiao/src/compiler/transforms/transformSwiper.ts
0 → 100644
浏览文件 @
e25ca33e
import
{
createBindDirectiveNode
}
from
'
@dcloudio/uni-cli-shared
'
import
{
genExpr
}
from
'
@dcloudio/uni-mp-compiler
'
import
{
findProp
,
NodeTypes
,
RootNode
,
TemplateChildNode
,
}
from
'
@vue/compiler-core
'
export
function
transformSwiper
(
node
:
RootNode
|
TemplateChildNode
)
{
if
(
node
.
type
!==
NodeTypes
.
ELEMENT
||
node
.
tag
!==
'
swiper
'
)
{
return
}
const
disableTouchProp
=
findProp
(
node
,
'
disable-touch
'
,
false
,
true
)
if
(
!
disableTouchProp
)
{
return
}
const
{
props
}
=
node
if
(
disableTouchProp
.
type
===
NodeTypes
.
ATTRIBUTE
)
{
// <swiper disable-touch/> => <swiper :touchable="false"/>
props
.
splice
(
props
.
indexOf
(
disableTouchProp
),
1
,
createBindDirectiveNode
(
'
touchable
'
,
'
false
'
)
)
}
else
{
if
(
disableTouchProp
.
exp
)
{
// <swiper :disable-touch="true"/> => <swiper :touchable="!(true)"/>
let
touchable
=
''
if
(
disableTouchProp
.
exp
.
type
===
NodeTypes
.
SIMPLE_EXPRESSION
)
{
if
(
disableTouchProp
.
exp
.
content
===
'
true
'
)
{
touchable
=
'
false
'
}
else
if
(
disableTouchProp
.
exp
.
content
===
'
false
'
)
{
touchable
=
'
true
'
}
}
props
.
splice
(
props
.
indexOf
(
disableTouchProp
),
1
,
createBindDirectiveNode
(
'
touchable
'
,
touchable
||
`!(
${
genExpr
(
disableTouchProp
.
exp
)}
)`
)
)
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录