Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
genary
uni-app
提交
114561e5
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,发现更多精彩内容 >>
提交
114561e5
编写于
10月 15, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(mp): scope
上级
5b70a108
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
29 addition
and
28 deletion
+29
-28
packages/uni-mp-compiler/__tests__/scope.spec.ts
packages/uni-mp-compiler/__tests__/scope.spec.ts
+7
-0
packages/uni-mp-compiler/__tests__/test.spec.ts
packages/uni-mp-compiler/__tests__/test.spec.ts
+4
-4
packages/uni-mp-compiler/__tests__/vFor.spec.ts
packages/uni-mp-compiler/__tests__/vFor.spec.ts
+5
-5
packages/uni-mp-compiler/src/ast.ts
packages/uni-mp-compiler/src/ast.ts
+12
-14
packages/uni-mp-compiler/src/template/codegen.ts
packages/uni-mp-compiler/src/template/codegen.ts
+0
-3
packages/uni-mp-compiler/src/transforms/utils.ts
packages/uni-mp-compiler/src/transforms/utils.ts
+1
-2
未找到文件。
packages/uni-mp-compiler/__tests__/scope.spec.ts
浏览文件 @
114561e5
...
...
@@ -23,6 +23,13 @@ describe('compiler: scope', () => {
`<view wx:for="{{a}}" wx:for-item="item"><view wx:for="{{b}}" wx:for-item="item1" data-id="{{item.a}}" data-title="{{item1.a}}"/></view>`
,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, item => { return { a: item.id }; }), b: _vFor(_ctx.item1, item1 => { return { a: item1.title }; }) }
}`
)
assert
(
`<view v-for="(item,weekIndex) in weeks" :key="weekIndex" :data-id="item.id"><view v-for="(weeks,weeksIndex) in item" :key="weeksIndex" :data-id="weeks.id"/></view>`
,
`<view wx:for="{{a}}" wx:for-item="item" wx:key="b" data-id="{{item.c}}"><view wx:for="{{item.a}}" wx:for-item="weeks" wx:key="a" data-id="{{weeks.b}}"/></view>`
,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.weeks, (item, weekIndex) => { return { a: _vFor(item, (weeks, weeksIndex) => { return { a: weeksIndex, b: weeks.id }; }), b: weekIndex, c: item.id }; }) }
}`
)
})
...
...
packages/uni-mp-compiler/__tests__/test.spec.ts
浏览文件 @
114561e5
...
...
@@ -26,7 +26,7 @@ function assert(
// expect(res.template).toBe(templateCode)
// expect(res.code).toBe(renderCode)
// console.log(require('util').inspect(res.code, { colors: true, depth: null }))
console
.
log
(
require
(
'
util
'
).
inspect
(
res
,
{
colors
:
true
,
depth
:
null
}))
//
console.log(require('util').inspect(res, { colors: true, depth: null }))
console
.
log
(
res
.
code
)
expect
(
res
.
code
).
toBe
(
renderCode
)
}
...
...
@@ -34,10 +34,10 @@ function assert(
describe
(
'
compiler
'
,
()
=>
{
test
(
'
scope
'
,
()
=>
{
assert
(
`<view v-for="
item in items"><view v-for="item1 in item1" :data-id="item.id" :data-title="item1.title
"/></view>`
,
`<view wx:for="{{a}}" wx:for-item="item"
><view wx:for="{{b}}" wx:for-item="item1" data-id="{{item.a}}" data-title="{{item1.a
}}"/></view>`
,
`<view v-for="
(item,weekIndex) in weeks" :key="weekIndex" :data-id="item.id"><view v-for="(weeks,weeksIndex) in item" :key="weeksIndex" :data-id="weeks.id
"/></view>`
,
`<view wx:for="{{a}}" wx:for-item="item"
wx:key="b" data-id="{{item.c}}"><view wx:for="{{item.a}}" wx:for-item="weeks" wx:key="a" data-id="{{weeks.b
}}"/></view>`
,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.
items, item => { return { a: item.id }; }), b: _vFor(_ctx.item1, item1 => { return { a: item1.title
}; }) }
return { a: _vFor(_ctx.
weeks, (item, weekIndex) => { return { a: _vFor(item, (weeks, weeksIndex) => { return { a: weeksIndex, b: weeks.id }; }), b: weekIndex, c: item.id
}; }) }
}`
)
})
...
...
packages/uni-mp-compiler/__tests__/vFor.spec.ts
浏览文件 @
114561e5
...
...
@@ -29,7 +29,7 @@ describe(`compiler: v-for`, () => {
`<view v-for="index in 5" />`
,
`<view wx:for="{{a}}" wx:for-item="index"/>`
,
`(_ctx, _cache) => {
return { a: _vFor(
[1, 2, 3, 4, 5]
, index => { return {}; }) }
return { a: _vFor(
5
, index => { return {}; }) }
}`
)
})
...
...
@@ -63,7 +63,7 @@ describe(`compiler: v-for`, () => {
test
(
`value and key`
,
()
=>
{
assert
(
`<view v-for="(item, key) in items" />`
,
`<view wx:for="{{a}}" wx:for-item="item"
wx:for-index="key"
/>`
,
`<view wx:for="{{a}}" wx:for-item="item"/>`
,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, key) => { return {}; }) }
}`
...
...
@@ -72,7 +72,7 @@ describe(`compiler: v-for`, () => {
test
(
`value, key and index`
,
()
=>
{
assert
(
`<view v-for="(item, key, index) in items" />`
,
`<view wx:for="{{a}}" wx:for-item="item"
wx:for-index="key"
/>`
,
`<view wx:for="{{a}}" wx:for-item="item"/>`
,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, key, index) => { return {}; }) }
}`
...
...
@@ -108,7 +108,7 @@ describe(`compiler: v-for`, () => {
test
(
`unbracketed value and key`
,
()
=>
{
assert
(
`<view v-for="item, key in items" />`
,
`<view wx:for="{{a}}" wx:for-item="item"
wx:for-index="key"
/>`
,
`<view wx:for="{{a}}" wx:for-item="item"/>`
,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, key) => { return {}; }) }
}`
...
...
@@ -117,7 +117,7 @@ describe(`compiler: v-for`, () => {
test
(
`unbracketed value, key and index`
,
()
=>
{
assert
(
`<view v-for="value, key, index in items" />`
,
`<view wx:for="{{a}}" wx:for-item="value"
wx:for-index="key"
/>`
,
`<view wx:for="{{a}}" wx:for-item="value"/>`
,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (value, key, index) => { return {}; }) }
}`
...
...
packages/uni-mp-compiler/src/ast.ts
浏览文件 @
114561e5
...
...
@@ -16,9 +16,7 @@ import {
Identifier
,
returnStatement
,
conditionalExpression
,
arrayExpression
,
NumericLiteral
,
numericLiteral
,
isNumericLiteral
,
Pattern
,
RestElement
,
...
...
@@ -80,24 +78,24 @@ export function createVIfSpreadElement(vIfScope: CodegenVIfScope) {
return
spreadElement
(
createVIfConditionalExpression
(
vIfScope
))
}
function
numericLiteralToArrayExpr
(
num
:
number
)
{
const
elements
:
NumericLiteral
[]
=
[]
for
(
let
i
=
0
;
i
<
num
;
i
++
)
{
elements
.
push
(
numericLiteral
(
i
+
1
))
}
return
arrayExpression
(
elements
)
}
//
function numericLiteralToArrayExpr(num: number) {
//
const elements: NumericLiteral[] = []
//
for (let i = 0; i < num; i++) {
//
elements.push(numericLiteral(i + 1))
//
}
//
return arrayExpression(elements)
//
}
export
function
createVForCallExpression
(
vForScope
:
CodegenVForScope
,
context
:
TransformContext
)
{
let
sourceExpr
:
Expression
=
vForScope
.
sourceExpr
!
if
(
isNumericLiteral
(
sourceExpr
))
{
sourceExpr
=
numericLiteralToArrayExpr
((
sourceExpr
as
NumericLiteral
).
value
)
}
//
let sourceExpr: Expression = vForScope.sourceExpr!
//
if (isNumericLiteral(sourceExpr)) {
//
sourceExpr = numericLiteralToArrayExpr((sourceExpr as NumericLiteral).value)
//
}
return
callExpression
(
identifier
(
context
.
helperString
(
V_FOR
)),
[
sourceExpr
,
vForScope
.
sourceExpr
!
,
createVForArrowFunctionExpression
(
vForScope
),
])
}
...
...
packages/uni-mp-compiler/src/template/codegen.ts
浏览文件 @
114561e5
...
...
@@ -83,9 +83,6 @@ function genVFor(
if
(
valueAlias
)
{
push
(
`
${
directive
}
for-item="
${
valueAlias
}
"`
)
}
if
(
keyAlias
)
{
push
(
`
${
directive
}
for-index="
${
keyAlias
}
"`
)
}
const
keyProp
=
findProp
(
node
,
'
key
'
,
true
)
if
(
keyProp
)
{
const
key
=
((
keyProp
as
DirectiveNode
).
exp
as
SimpleExpressionNode
).
content
...
...
packages/uni-mp-compiler/src/transforms/utils.ts
浏览文件 @
114561e5
...
...
@@ -116,9 +116,8 @@ function isReferencedScope(node: Expression, scope: CodegenVForScope) {
return
}
if
(
parent
&&
knownIds
.
includes
(
node
.
name
)
&&
isReferenced
(
node
,
parent
as
any
)
(
!
parent
||
isReferenced
(
node
,
parent
as
any
)
)
)
{
referenced
=
true
return
this
.
skip
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录