Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小浣熊撸代码
uni-app
提交
7033a52e
U
uni-app
项目概览
小浣熊撸代码
/
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,发现更多精彩内容 >>
提交
7033a52e
编写于
10月 26, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(mp): mp-baidu
上级
c7e4fa0c
变更
40
展开全部
显示空白变更内容
内联
并排
Showing
40 changed file
with
945 addition
and
523 deletion
+945
-523
package.json
package.json
+1
-1
packages/playground/ssr/package.json
packages/playground/ssr/package.json
+1
-1
packages/playground/ssr/yarn.lock
packages/playground/ssr/yarn.lock
+153
-148
packages/uni-cli-shared/src/json/mp/pages.ts
packages/uni-cli-shared/src/json/mp/pages.ts
+5
-1
packages/uni-cli-shared/src/json/mp/types.ts
packages/uni-cli-shared/src/json/mp/types.ts
+1
-0
packages/uni-cli-shared/src/json/mp/utils.ts
packages/uni-cli-shared/src/json/mp/utils.ts
+6
-2
packages/uni-h5/dist/uni-h5.es.js
packages/uni-h5/dist/uni-h5.es.js
+55
-14
packages/uni-mp-baidu/__tests__/testUtils.ts
packages/uni-mp-baidu/__tests__/testUtils.ts
+40
-0
packages/uni-mp-baidu/__tests__/vFor.spec.ts
packages/uni-mp-baidu/__tests__/vFor.spec.ts
+22
-0
packages/uni-mp-baidu/__tests__/vIf.spec.ts
packages/uni-mp-baidu/__tests__/vIf.spec.ts
+13
-0
packages/uni-mp-baidu/build.json
packages/uni-mp-baidu/build.json
+38
-22
packages/uni-mp-baidu/dist/uni.compiler.js
packages/uni-mp-baidu/dist/uni.compiler.js
+114
-0
packages/uni-mp-baidu/dist/uni.mp.esm.js
packages/uni-mp-baidu/dist/uni.mp.esm.js
+1
-1
packages/uni-mp-baidu/package.json
packages/uni-mp-baidu/package.json
+3
-1
packages/uni-mp-baidu/src/plugin/index.ts
packages/uni-mp-baidu/src/plugin/index.ts
+76
-0
packages/uni-mp-baidu/src/plugin/project.swan.json
packages/uni-mp-baidu/src/plugin/project.swan.json
+19
-0
packages/uni-mp-baidu/src/plugin/transforms/vFor.ts
packages/uni-mp-baidu/src/plugin/transforms/vFor.ts
+22
-0
packages/uni-mp-baidu/src/runtime/parseComponentOptions.ts
packages/uni-mp-baidu/src/runtime/parseComponentOptions.ts
+1
-1
packages/uni-mp-compiler/__tests__/class.spec.ts
packages/uni-mp-compiler/__tests__/class.spec.ts
+8
-8
packages/uni-mp-compiler/__tests__/component.spec.ts
packages/uni-mp-compiler/__tests__/component.spec.ts
+8
-8
packages/uni-mp-compiler/__tests__/ref.spec.ts
packages/uni-mp-compiler/__tests__/ref.spec.ts
+17
-12
packages/uni-mp-compiler/__tests__/scopeId.spec.ts
packages/uni-mp-compiler/__tests__/scopeId.spec.ts
+2
-2
packages/uni-mp-compiler/__tests__/vModel.spec.ts
packages/uni-mp-compiler/__tests__/vModel.spec.ts
+2
-2
packages/uni-mp-compiler/__tests__/vSlot.spec.ts
packages/uni-mp-compiler/__tests__/vSlot.spec.ts
+8
-8
packages/uni-mp-compiler/src/index.ts
packages/uni-mp-compiler/src/index.ts
+12
-0
packages/uni-mp-compiler/src/options.ts
packages/uni-mp-compiler/src/options.ts
+7
-7
packages/uni-mp-compiler/src/template/codegen.ts
packages/uni-mp-compiler/src/template/codegen.ts
+5
-5
packages/uni-mp-compiler/src/transform.ts
packages/uni-mp-compiler/src/transform.ts
+1
-1
packages/uni-mp-compiler/src/transforms/transformClass.ts
packages/uni-mp-compiler/src/transforms/transformClass.ts
+9
-3
packages/uni-mp-compiler/src/transforms/transformComponent.ts
...ages/uni-mp-compiler/src/transforms/transformComponent.ts
+5
-1
packages/uni-mp-compiler/src/transforms/transformElement.ts
packages/uni-mp-compiler/src/transforms/transformElement.ts
+1
-1
packages/uni-mp-compiler/src/transforms/vFor.ts
packages/uni-mp-compiler/src/transforms/vFor.ts
+10
-6
packages/uni-mp-qq/dist/uni.compiler.js
packages/uni-mp-qq/dist/uni.compiler.js
+3
-3
packages/uni-mp-qq/src/plugin/index.ts
packages/uni-mp-qq/src/plugin/index.ts
+3
-3
packages/uni-mp-vite/src/plugin/index.ts
packages/uni-mp-vite/src/plugin/index.ts
+2
-1
packages/uni-mp-vite/src/plugin/uni/index.ts
packages/uni-mp-vite/src/plugin/uni/index.ts
+3
-3
packages/uni-mp-vite/src/plugins/entry.ts
packages/uni-mp-vite/src/plugins/entry.ts
+2
-2
packages/uni-stat/dist/uni-stat.cjs.js
packages/uni-stat/dist/uni-stat.cjs.js
+1
-1
packages/uni-stat/dist/uni-stat.es.js
packages/uni-stat/dist/uni-stat.es.js
+1
-1
yarn.lock
yarn.lock
+264
-253
未找到文件。
package.json
浏览文件 @
7033a52e
...
...
@@ -96,7 +96,7 @@
"
semver
"
:
"
^7.3.4
"
,
"
ts-jest
"
:
"
^27.0.3
"
,
"
typescript
"
:
"
^4.4.3
"
,
"
vite
"
:
"
^2.6.1
0
"
,
"
vite
"
:
"
^2.6.1
1
"
,
"
vue
"
:
"
^3.2.20
"
,
"
yorkie
"
:
"
^2.0.0
"
},
...
...
packages/playground/ssr/package.json
浏览文件 @
7033a52e
...
...
@@ -32,6 +32,6 @@
"compression"
:
"^1.7.4"
,
"cypress"
:
"^7.3.0"
,
"serve-static"
:
"^1.14.1"
,
"vite"
:
"^2.6.1
0
"
"vite"
:
"^2.6.1
1
"
}
}
packages/playground/ssr/yarn.lock
浏览文件 @
7033a52e
此差异已折叠。
点击以展开。
packages/uni-cli-shared/src/json/mp/pages.ts
浏览文件 @
7033a52e
...
...
@@ -57,7 +57,11 @@ function parsePagesJson(
)
{
nvuePages
.
push
(
pagePath
)
}
pageJsons
[
pagePath
]
=
parseWindowOptions
(
style
,
platform
,
windowOptionsMap
)
pageJsons
[
pagePath
]
=
parseWindowOptions
(
style
,
platform
,
windowOptionsMap
)
as
PageWindowOptions
}
// pages
validatePages
(
pagesJson
,
jsonStr
)
...
...
packages/uni-cli-shared/src/json/mp/types.ts
浏览文件 @
7033a52e
...
...
@@ -21,6 +21,7 @@ type Style = 'v2' | string
type
RestartStrategy
=
'
homePage
'
|
'
homePageAndLatestPage
'
|
string
export
interface
PageWindowOptions
extends
ShareWindowOptions
{
component
:
true
// 百度小程序页面必须配置component: true
disableScroll
?:
boolean
// false
usingComponents
?:
UsingComponents
initialRenderingCache
?:
'
static
'
|
string
...
...
packages/uni-cli-shared/src/json/mp/utils.ts
浏览文件 @
7033a52e
...
...
@@ -32,11 +32,15 @@ export function parseWindowOptions(
windowOptionsMap
?:
Record
<
string
,
string
>
):
PageWindowOptions
|
AppWindowOptions
{
if
(
!
style
)
{
return
{}
return
{
component
:
true
,
}
}
const
platformStyle
=
style
[
platform
]
||
{}
removePlatformStyle
(
trimJson
(
style
)
as
any
)
const
res
:
PageWindowOptions
|
AppWindowOptions
=
{}
const
res
:
PageWindowOptions
|
AppWindowOptions
=
{
component
:
true
,
}
if
(
windowOptionsMap
)
{
return
extend
(
convert
(
res
,
style
,
windowOptionsMap
),
platformStyle
)
}
...
...
packages/uni-h5/dist/uni-h5.es.js
浏览文件 @
7033a52e
...
...
@@ -187,6 +187,31 @@ const initI18nShowModalMsgsOnce = /* @__PURE__ */ once(() => {
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ["\u53D6\u6D88", "\u78BA\u5B9A"]), false);
}
});
const initI18nChooseFileMsgsOnce = /* @__PURE__ */ once(() => {
const name = "uni.chooseFile.";
const keys = ["notUserActivation"];
if (__UNI_FEATURE_I18N_EN__) {
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, [
"File chooser dialog can only be shown with a user activation"
]), false);
}
if (__UNI_FEATURE_I18N_ES__) {
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, [
"El cuadro de di\xE1logo del selector de archivos solo se puede mostrar con la activaci\xF3n del usuario"
]), false);
}
if (__UNI_FEATURE_I18N_FR__) {
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, [
"La bo\xEEte de dialogue du s\xE9lecteur de fichier ne peut \xEAtre affich\xE9e qu'avec une activation par l'utilisateur"
]), false);
}
if (__UNI_FEATURE_I18N_ZH_HANS__) {
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, ["\u6587\u4EF6\u9009\u62E9\u5668\u5BF9\u8BDD\u6846\u53EA\u80FD\u5728\u7528\u6237\u6FC0\u6D3B\u65F6\u663E\u793A"]), false);
}
if (__UNI_FEATURE_I18N_ZH_HANT__) {
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ["\u6587\u4EF6\u9078\u64C7\u5668\u5C0D\u8A71\u6846\u53EA\u80FD\u5728\u7528\u6236\u6FC0\u6D3B\u6642\u986F\u793A"]), false);
}
});
const initI18nSetClipboardDataMsgsOnce = /* @__PURE__ */ once(() => {
const name = "uni.setClipboardData.";
const keys = ["success", "fail"];
...
...
@@ -8032,7 +8057,8 @@ const passiveOptions$1 = passive(true);
const states = [];
let userInteract = 0;
let inited;
function addInteractListener(vm) {
const setUserAction = (userAction) => states.forEach((vm) => vm.userAction = userAction);
function addInteractListener(vm = { userAction: false }) {
if (!inited) {
const eventNames = [
"touchstart",
...
...
@@ -8043,16 +8069,11 @@ function addInteractListener(vm) {
];
eventNames.forEach((eventName) => {
document.addEventListener(eventName, function() {
states.forEach((vm2) => {
vm2.userAction = true;
!userInteract && setUserAction(true);
userInteract++;
setTimeout(() => {
userInteract--;
if (!userInteract) {
vm2.userAction = false;
}
!--userInteract && setUserAction(false);
}, 0);
});
}, passiveOptions$1);
});
inited = true;
...
...
@@ -8065,6 +8086,7 @@ function removeInteractListener(vm) {
states.splice(index2, 1);
}
}
const getInteractStatus = () => !!userInteract;
function useUserAction() {
const state2 = reactive({
userAction: false
...
...
@@ -16518,6 +16540,7 @@ const MIMEType = {
}
};
const ALL = "all";
addInteractListener();
function isWXEnv() {
const ua2 = window.navigator.userAgent.toLowerCase();
const matchUA = ua2.match(/MicroMessenger/i);
...
...
@@ -16566,6 +16589,8 @@ const chooseFile = /* @__PURE__ */ defineAsyncApi(API_CHOOSE_FILE, ({
type,
extension
}, { resolve, reject }) => {
initI18nChooseFileMsgsOnce();
const { t: t2 } = useI18n();
if (fileInput) {
document.body.removeChild(fileInput);
fileInput = null;
...
...
@@ -16603,7 +16628,11 @@ const chooseFile = /* @__PURE__ */ defineAsyncApi(API_CHOOSE_FILE, ({
};
resolve(res);
});
if (getInteractStatus()) {
fileInput.click();
} else {
reject(t2("uni.chooseFile.notUserActivation"));
}
}, ChooseFileProtocol, ChooseFileOptions);
let imageInput = null;
const chooseImage = /* @__PURE__ */ defineAsyncApi(API_CHOOSE_IMAGE, ({
...
...
@@ -16611,6 +16640,8 @@ const chooseImage = /* @__PURE__ */ defineAsyncApi(API_CHOOSE_IMAGE, ({
sourceType,
extension
}, { resolve, reject }) => {
initI18nChooseFileMsgsOnce();
const { t: t2 } = useI18n();
if (imageInput) {
document.body.removeChild(imageInput);
imageInput = null;
...
...
@@ -16648,7 +16679,11 @@ const chooseImage = /* @__PURE__ */ defineAsyncApi(API_CHOOSE_IMAGE, ({
};
resolve(res);
});
if (getInteractStatus()) {
imageInput.click();
} else {
reject(t2("uni.chooseFile.notUserActivation"));
}
}, ChooseImageProtocol, ChooseImageOptions);
let index$c = 0;
let overflow = "";
...
...
@@ -16881,6 +16916,8 @@ const previewImage = /* @__PURE__ */ defineAsyncApi(API_PREVIEW_IMAGE, (args, {
}, PreviewImageProtocol, PreviewImageOptions);
let videoInput = null;
const chooseVideo = /* @__PURE__ */ defineAsyncApi(API_CHOOSE_VIDEO, ({ sourceType, extension }, { resolve, reject }) => {
initI18nChooseFileMsgsOnce();
const { t: t2 } = useI18n();
if (videoInput) {
document.body.removeChild(videoInput);
videoInput = null;
...
...
@@ -16931,7 +16968,11 @@ const chooseVideo = /* @__PURE__ */ defineAsyncApi(API_CHOOSE_VIDEO, ({ sourceTy
resolve(callbackResult);
}
});
if (getInteractStatus()) {
videoInput.click();
} else {
reject(t2("uni.chooseFile.notUserActivation"));
}
}, ChooseVideoProtocol, ChooseVideoOptions);
const request = /* @__PURE__ */ defineTaskApi(API_REQUEST, ({
url,
...
...
packages/uni-mp-baidu/__tests__/testUtils.ts
0 → 100644
浏览文件 @
7033a52e
import
{
isCustomElement
,
isNativeTag
}
from
'
@dcloudio/uni-shared
'
import
{
compile
,
CompilerOptions
}
from
'
@dcloudio/uni-mp-compiler
'
import
{
transformFor
}
from
'
../src/plugin/transforms/vFor
'
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
:
[
transformFor
],
miniProgram
:
{
slot
:
{
fallback
:
false
,
},
directive
:
'
s-
'
,
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-baidu/__tests__/vFor.spec.ts
0 → 100644
浏览文件 @
7033a52e
import
{
assert
}
from
'
./testUtils
'
describe
(
`mp-baidu: transform v-for`
,
()
=>
{
test
(
`with key`
,
()
=>
{
assert
(
`<view v-for="item in items" :key="item.id"/>`
,
`<view s-for="a trackBy item.id" s-for-item="item"/>`
,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return {}; }) }
}`
)
})
test
(
`without key`
,
()
=>
{
assert
(
`<view v-for="item in items"/>`
,
`<view s-for="{{a}}" s-for-item="item"/>`
,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return {}; }) }
}`
)
})
})
packages/uni-mp-baidu/__tests__/vIf.spec.ts
0 → 100644
浏览文件 @
7033a52e
import
{
assert
}
from
'
./testUtils
'
describe
(
`mp-baidu: transform v-if`
,
()
=>
{
test
(
`basic`
,
()
=>
{
assert
(
`<view v-if="ok"/><view v-else-if="ok1"/><view v-else/>`
,
`<view s-if="{{a}}"/><view s-elif="{{b}}"/><view s-else/>`
,
`(_ctx, _cache) => {
return _e({ a: _ctx.ok }, _ctx.ok ? {} : _ctx.ok1 ? {} : {}, { b: _ctx.ok1 })
}`
)
})
})
packages/uni-mp-baidu/build.json
浏览文件 @
7033a52e
{
[
{
"input"
:
{
"src/plugin/index.ts"
:
"dist/uni.compiler.js"
},
"output"
:
{
"format"
:
"cjs"
},
"external"
:
[
"@dcloudio/uni-cli-shared"
,
"@dcloudio/uni-mp-compiler"
,
"@dcloudio/uni-mp-vite"
,
"@vue/compiler-core"
]
},
{
"input"
:
{
"src/runtime/index.ts"
:
"dist/uni.mp.esm.js"
,
"src/api/index.ts"
:
"dist/uni.api.esm.js"
...
...
@@ -21,4 +36,5 @@
"__PLATFORM_TITLE__"
:
"百度小程序"
},
"external"
:
[
"@dcloudio/uni-i18n"
,
"@vue/shared"
,
"vue"
]
}
}
]
packages/uni-mp-baidu/dist/uni.compiler.js
0 → 100644
浏览文件 @
7033a52e
'
use strict
'
;
var
uniCliShared
=
require
(
'
@dcloudio/uni-cli-shared
'
);
var
initMiniProgramPlugin
=
require
(
'
@dcloudio/uni-mp-vite
'
);
var
uniMpCompiler
=
require
(
'
@dcloudio/uni-mp-compiler
'
);
function
_interopDefaultLegacy
(
e
)
{
return
e
&&
typeof
e
===
'
object
'
&&
'
default
'
in
e
?
e
:
{
'
default
'
:
e
};
}
var
initMiniProgramPlugin__default
=
/*#__PURE__*/
_interopDefaultLegacy
(
initMiniProgramPlugin
);
var
appid
=
""
;
var
host
=
"
baiduboxapp
"
;
var
projectname
=
""
;
var
setting
=
{
autoAudits
:
false
,
urlCheck
:
false
};
var
source
=
{
appid
:
appid
,
"
compilation-args
"
:
{
common
:
{
babelSetting
:
{
ignore
:
[
]
},
enhance
:
true
,
ignorePrefixCss
:
false
},
selected
:
-
3
},
host
:
host
,
projectname
:
projectname
,
setting
:
setting
};
const
transformFor
=
(
node
)
=>
{
if
(
!
uniMpCompiler
.
isForElementNode
(
node
))
{
return
;
}
const
keyProp
=
uniMpCompiler
.
findProp
(
node
,
'
key
'
,
true
);
if
(
keyProp
)
{
const
{
exp
}
=
keyProp
;
if
(
exp
)
{
const
key
=
uniMpCompiler
.
genExpr
(
exp
);
node
.
vFor
.
sourceCode
=
`
${
node
.
vFor
.
sourceAlias
}
trackBy
${
key
}
`
;
node
.
props
.
splice
(
node
.
props
.
indexOf
(
keyProp
),
1
);
}
}
};
const
uniMiniProgramBaiduPlugin
=
{
name
:
'
vite:uni-mp-baidu
'
,
config
()
{
return
{
define
:
{
__VUE_CREATED_DEFERRED__
:
false
,
},
};
},
};
const
projectConfigFilename
=
'
project.swan.json
'
;
const
options
=
{
vite
:
{
inject
:
{
uni
:
[
uniCliShared
.
resolveBuiltIn
(
'
@dcloudio/uni-mp-baidu/dist/uni.api.esm.js
'
),
'
default
'
,
],
},
alias
:
{
'
uni-mp-runtime
'
:
uniCliShared
.
resolveBuiltIn
(
'
@dcloudio/uni-mp-baidu/dist/uni.mp.esm.js
'
),
},
copyOptions
:
{
assets
:
[
'
swancomponents
'
],
},
},
global
:
'
swan
'
,
app
:
{
darkmode
:
false
,
subpackages
:
true
,
},
project
:
{
filename
:
projectConfigFilename
,
source
,
},
template
:
{
filter
:
{
extname
:
'
.swan
'
,
lang
:
'
sjs
'
,
generate
(
filter
,
filename
)
{
if
(
filename
)
{
return
`<import-sjs src="
${
filename
}
.sjs" module="
${
filter
.
name
}
"/>`
;
}
return
`<import-sjs module="
${
filter
.
name
}
">
${
filter
.
code
}
</import-sjs>`
;
},
},
slot
:
{
fallback
:
false
,
},
extname
:
'
.swan
'
,
directive
:
'
s-
'
,
compilerOptions
:
{
nodeTransforms
:
[
transformFor
],
},
},
style
:
{
extname
:
'
.css
'
,
},
};
var
index
=
[
uniMiniProgramBaiduPlugin
,
...
initMiniProgramPlugin__default
[
"
default
"
](
options
)];
module
.
exports
=
index
;
packages/uni-mp-baidu/dist/uni.mp.esm.js
浏览文件 @
7033a52e
...
...
@@ -835,7 +835,7 @@ function parse$1(componentOptions) {
fixSetDataStart
(
this
);
oldAttached
.
call
(
this
);
this
.
pageinstance
.
$vm
=
this
.
$vm
;
this
.
$vm
.
__call_h
ook
(
'
onInit
'
,
query
);
this
.
$vm
.
$callH
ook
(
'
onInit
'
,
query
);
};
lifetimes
.
attached
=
function
attached
()
{
if
(
!
this
.
$vm
)
{
...
...
packages/uni-mp-baidu/package.json
浏览文件 @
7033a52e
...
...
@@ -18,7 +18,9 @@
"license"
:
"Apache-2.0"
,
"uni-app"
:
{
"name"
:
"mp-baidu"
,
"title"
:
"百度小程序"
"title"
:
"百度小程序"
,
"apply"
:
"mp-baidu"
,
"main"
:
"dist/uni.compiler.js"
},
"gitHead"
:
"1efa8efd0a9eddeabdba75c020d015ebf31b8177"
}
packages/uni-mp-baidu/src/plugin/index.ts
0 → 100644
浏览文件 @
7033a52e
import
type
{
Plugin
}
from
'
vite
'
import
{
resolveBuiltIn
}
from
'
@dcloudio/uni-cli-shared
'
import
initMiniProgramPlugin
,
{
UniMiniProgramPluginOptions
,
}
from
'
@dcloudio/uni-mp-vite
'
import
source
from
'
./project.swan.json
'
import
{
transformFor
}
from
'
./transforms/vFor
'
const
uniMiniProgramBaiduPlugin
:
Plugin
=
{
name
:
'
vite:uni-mp-baidu
'
,
config
()
{
return
{
define
:
{
__VUE_CREATED_DEFERRED__
:
false
,
},
}
},
}
const
projectConfigFilename
=
'
project.swan.json
'
const
options
:
UniMiniProgramPluginOptions
=
{
vite
:
{
inject
:
{
uni
:
[
resolveBuiltIn
(
'
@dcloudio/uni-mp-baidu/dist/uni.api.esm.js
'
),
'
default
'
,
],
},
alias
:
{
'
uni-mp-runtime
'
:
resolveBuiltIn
(
'
@dcloudio/uni-mp-baidu/dist/uni.mp.esm.js
'
),
},
copyOptions
:
{
assets
:
[
'
swancomponents
'
],
},
},
global
:
'
swan
'
,
app
:
{
darkmode
:
false
,
subpackages
:
true
,
},
project
:
{
filename
:
projectConfigFilename
,
source
,
},
template
:
{
filter
:
{
extname
:
'
.swan
'
,
lang
:
'
sjs
'
,
generate
(
filter
,
filename
)
{
if
(
filename
)
{
return
`<import-sjs src="
${
filename
}
.sjs" module="
${
filter
.
name
}
"/>`
}
return
`<import-sjs module="
${
filter
.
name
}
">
${
filter
.
code
}
</import-sjs>`
},
},
slot
:
{
fallback
:
false
,
},
extname
:
'
.swan
'
,
directive
:
'
s-
'
,
compilerOptions
:
{
nodeTransforms
:
[
transformFor
],
},
},
style
:
{
extname
:
'
.css
'
,
},
}
export
default
[
uniMiniProgramBaiduPlugin
,
...
initMiniProgramPlugin
(
options
)]
packages/uni-mp-baidu/src/plugin/project.swan.json
0 → 100644
浏览文件 @
7033a52e
{
"appid"
:
""
,
"compilation-args"
:
{
"common"
:
{
"babelSetting"
:
{
"ignore"
:
[]
},
"enhance"
:
true
,
"ignorePrefixCss"
:
false
},
"selected"
:
-3
},
"host"
:
"baiduboxapp"
,
"projectname"
:
""
,
"setting"
:
{
"autoAudits"
:
false
,
"urlCheck"
:
false
}
}
packages/uni-mp-baidu/src/plugin/transforms/vFor.ts
0 → 100644
浏览文件 @
7033a52e
import
{
genExpr
,
findProp
,
isForElementNode
,
DirectiveNode
,
NodeTransform
,
}
from
'
@dcloudio/uni-mp-compiler
'
export
const
transformFor
:
NodeTransform
=
(
node
)
=>
{
if
(
!
isForElementNode
(
node
))
{
return
}
const
keyProp
=
findProp
(
node
,
'
key
'
,
true
)
if
(
keyProp
)
{
const
{
exp
}
=
keyProp
as
DirectiveNode
if
(
exp
)
{
const
key
=
genExpr
(
exp
)
node
.
vFor
.
sourceCode
=
`
${
node
.
vFor
.
sourceAlias
}
trackBy
${
key
}
`
node
.
props
.
splice
(
node
.
props
.
indexOf
(
keyProp
),
1
)
}
}
}
packages/uni-mp-baidu/src/runtime/parseComponentOptions.ts
浏览文件 @
7033a52e
...
...
@@ -48,7 +48,7 @@ export function parse(componentOptions: MPComponentOptions) {
fixSetDataStart
(
this
as
MPComponentInstance
)
oldAttached
.
call
(
this
)
this
.
pageinstance
.
$vm
=
this
.
$vm
this
.
$vm
.
__call_h
ook
(
'
onInit
'
,
query
)
this
.
$vm
.
$callH
ook
(
'
onInit
'
,
query
)
}
lifetimes
.
attached
=
function
attached
(
this
:
MPComponentInstance
)
{
if
(
!
this
.
$vm
)
{
...
...
packages/uni-mp-compiler/__tests__/class.spec.ts
浏览文件 @
7033a52e
...
...
@@ -75,28 +75,28 @@ describe('compiler: transform class', () => {
test
(
'
v-bind:class object syntax + class
'
,
()
=>
{
assert
(
`<view :class="{ red: isRed }" class="foo bar"/>`
,
`<view class="{{[a && 'red', 'foo
bar']}}"/>`
,
`<view class="{{[a && 'red', 'foo
', '
bar']}}"/>`
,
`(_ctx, _cache) => {
return { a: _ctx.isRed ? 1 : 0 }
}`
)
assert
(
`<view class="foo bar" :class="{ red: isRed }"/>`
,
`<view class="{{['foo
bar', a && 'red']}}"/>`
,
`<view class="{{['foo
', '
bar', a && 'red']}}"/>`
,
`(_ctx, _cache) => {
return { a: _ctx.isRed ? 1 : 0 }
}`
)
assert
(
`<view :class="{ a: 1, b: 0, c: true, d: false, e: null, f: undefined, g: ok, h: handle(ok), i: ok>1, j, [k]:1, [l]:m, ...n, ...{a:true}, ...{b:o} }" class="foo bar"/>`
,
`<view class="{{['a', 'c', a && 'g', b && 'h', c && 'i', d && 'j', e, g && f, h, i, j, 'foo
bar']}}"/>`
,
`<view class="{{['a', 'c', a && 'g', b && 'h', c && 'i', d && 'j', e, g && f, h, i, j, 'foo
', '
bar']}}"/>`
,
`(_ctx, _cache) => {
return { a: _ctx.ok ? 1 : 0, b: _ctx.handle(_ctx.ok) ? 1 : 0, c: _ctx.ok > 1 ? 1 : 0, d: _ctx.j ? 1 : 0, e: _ctx.k, f: _ctx.l, g: _ctx.m ? 1 : 0, h: _n(_ctx.n), i: _n({ a: true }), j: _n({ b: _ctx.o }) }
}`
)
assert
(
`<view class="foo bar" :class="{ a: 1, b: 0, c: true, d: false, e: null, f: undefined, g: ok, h: handle(ok), i: ok>1, j, [k]:1, [l]:m, ...n, ...{a:true}, ...{b:o} }"/>`
,
`<view class="{{['foo
bar', 'a', 'c', a && 'g', b && 'h', c && 'i', d && 'j', e, g && f, h, i, j]}}"/>`
,
`<view class="{{['foo
', '
bar', 'a', 'c', a && 'g', b && 'h', c && 'i', d && 'j', e, g && f, h, i, j]}}"/>`
,
`(_ctx, _cache) => {
return { a: _ctx.ok ? 1 : 0, b: _ctx.handle(_ctx.ok) ? 1 : 0, c: _ctx.ok > 1 ? 1 : 0, d: _ctx.j ? 1 : 0, e: _ctx.k, f: _ctx.l, g: _ctx.m ? 1 : 0, h: _n(_ctx.n), i: _n({ a: true }), j: _n({ b: _ctx.o }) }
}`
...
...
@@ -128,28 +128,28 @@ describe('compiler: transform class', () => {
test
(
'
v-bind:class array syntax + class
'
,
()
=>
{
assert
(
`<view :class="[classA, classB]" class="foo bar"/>`
,
`<view class="{{[a, b, 'foo
bar']}}"/>`
,
`<view class="{{[a, b, 'foo
', '
bar']}}"/>`
,
`(_ctx, _cache) => {
return { a: _n(_ctx.classA), b: _n(_ctx.classB) }
}`
)
assert
(
`<view class="foo bar" :class="[classA, classB]"/>`
,
`<view class="{{['foo
bar', a, b]}}"/>`
,
`<view class="{{['foo
', '
bar', a, b]}}"/>`
,
`(_ctx, _cache) => {
return { a: _n(_ctx.classA), b: _n(_ctx.classB) }
}`
)
assert
(
`<view :class="[classA, classB, { classC: isC, classD: isD }, 'classE', isF ? 'classF' : '', isG && 'classG', ...classH, ...[classI,classJ], handle(classK) ]" class="foo bar"/>`
,
`<view class="{{[a, b, c, 'classE', d, e, f, g, h, 'foo
bar']}}"/>`
,
`<view class="{{[a, b, c, 'classE', d, e, f, g, h, 'foo
', '
bar']}}"/>`
,
`(_ctx, _cache) => {
return { a: _n(_ctx.classA), b: _n(_ctx.classB), c: _n({ classC: _ctx.isC, classD: _ctx.isD }), d: _n(_ctx.isF ? 'classF' : ''), e: _n(_ctx.isG && 'classG'), f: _n(_ctx.classH), g: _n([_ctx.classI, _ctx.classJ]), h: _n(_ctx.handle(_ctx.classK)) }
}`
)
assert
(
`<view class="foo bar" :class="[classA, classB, { classC: isC, classD: isD }, 'classE', isF ? 'classF' : '', isG && 'classG', ...classH, ...[classI,classJ], handle(classK) ]"/>`
,
`<view class="{{['foo
bar', a, b, c, 'classE', d, e, f, g, h]}}"/>`
,
`<view class="{{['foo
', '
bar', a, b, c, 'classE', d, e, f, g, h]}}"/>`
,
`(_ctx, _cache) => {
return { a: _n(_ctx.classA), b: _n(_ctx.classB), c: _n({ classC: _ctx.isC, classD: _ctx.isD }), d: _n(_ctx.isF ? 'classF' : ''), e: _n(_ctx.isG && 'classG'), f: _n(_ctx.classH), g: _n([_ctx.classI, _ctx.classJ]), h: _n(_ctx.handle(_ctx.classK)) }
}`
...
...
packages/uni-mp-compiler/__tests__/component.spec.ts
浏览文件 @
7033a52e
...
...
@@ -5,7 +5,7 @@ describe('compiler: transform component', () => {
// test('basic', () => {
// assert(
// `<custom/>`,
// `<custom
class="v-r"
v-i="2a9ec0b0-0" bind:__l="__l"/>`,
// `<custom v-i="2a9ec0b0-0" bind:__l="__l"/>`,
// `(_ctx, _cache) => {
// return {}
// }`,
...
...
@@ -17,7 +17,7 @@ describe('compiler: transform component', () => {
test
(
'
component + component
'
,
()
=>
{
assert
(
`<custom><custom1/></custom>`
,
`<custom
class="v-r" v-s="{{['default']}}" v-i="2a9ec0b0-0" bind:__l="__l"><custom1 class="v-r"
v-i="2a9ec0b0-1,2a9ec0b0-0" bind:__l="__l"/></custom>`
,
`<custom
v-s="{{['default']}}" v-i="2a9ec0b0-0" bind:__l="__l"><custom1
v-i="2a9ec0b0-1,2a9ec0b0-0" bind:__l="__l"/></custom>`
,
`(_ctx, _cache) => {
return {}
}`
,
...
...
@@ -29,7 +29,7 @@ describe('compiler: transform component', () => {
test
(
'
component + component + component
'
,
()
=>
{
assert
(
`<custom><custom1><custom2/><custom2/></custom1></custom>`
,
`<custom
class="v-r" v-s="{{['default']}}" v-i="2a9ec0b0-0" bind:__l="__l"><custom1 class="v-r" v-s="{{['default']}}" v-i="2a9ec0b0-1,2a9ec0b0-0" bind:__l="__l"><custom2 class="v-r" v-i="2a9ec0b0-2,2a9ec0b0-1" bind:__l="__l"/><custom2 class="v-r"
v-i="2a9ec0b0-3,2a9ec0b0-1" bind:__l="__l"/></custom1></custom>`
,
`<custom
v-s="{{['default']}}" v-i="2a9ec0b0-0" bind:__l="__l"><custom1 v-s="{{['default']}}" v-i="2a9ec0b0-1,2a9ec0b0-0" bind:__l="__l"><custom2 v-i="2a9ec0b0-2,2a9ec0b0-1" bind:__l="__l"/><custom2
v-i="2a9ec0b0-3,2a9ec0b0-1" bind:__l="__l"/></custom1></custom>`
,
`(_ctx, _cache) => {
return {}
}`
,
...
...
@@ -41,7 +41,7 @@ describe('compiler: transform component', () => {
test
(
'
component with v-for
'
,
()
=>
{
assert
(
`<custom v-for="item in items"/>`
,
`<custom wx:for="{{a}}" wx:for-item="item"
class="v-r-i-f"
v-i="{{item.a}}" bind:__l="__l"/>`
,
`<custom wx:for="{{a}}" wx:for-item="item" v-i="{{item.a}}" bind:__l="__l"/>`
,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-0' + '-' + i0 }; }) }
}`
,
...
...
@@ -51,7 +51,7 @@ describe('compiler: transform component', () => {
)
assert
(
`<custom v-for="(item,key,index) in items"/>`
,
`<custom wx:for="{{a}}" wx:for-item="item"
class="v-r-i-f"
v-i="{{item.a}}" bind:__l="__l"/>`
,
`<custom wx:for="{{a}}" wx:for-item="item" v-i="{{item.a}}" bind:__l="__l"/>`
,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, key, index) => { return { a: '2a9ec0b0-0' + '-' + index }; }) }
}`
,
...
...
@@ -63,7 +63,7 @@ describe('compiler: transform component', () => {
test
(
'
component + component with v-for
'
,
()
=>
{
assert
(
`<custom><custom1 v-for="item in items"/></custom>`
,
`<custom
class="v-r" v-s="{{['default']}}" v-i="2a9ec0b0-0" bind:__l="__l"><custom1 wx:for="{{a}}" wx:for-item="item" class="v-r-i-f
" v-i="{{item.a}}" bind:__l="__l"/></custom>`
,
`<custom
v-s="{{['default']}}" v-i="2a9ec0b0-0" bind:__l="__l"><custom1 wx:for="{{a}}" wx:for-item="item
" v-i="{{item.a}}" bind:__l="__l"/></custom>`
,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-1' + '-' + i0 + ',' + '2a9ec0b0-0' }; }) }
}`
,
...
...
@@ -75,7 +75,7 @@ describe('compiler: transform component', () => {
test
(
'
component with v-for + component
'
,
()
=>
{
assert
(
`<custom v-for="item in items"><custom1/></custom>`
,
`<custom wx:for="{{a}}" wx:for-item="item"
class="v-r-i-f" v-s="{{['default']}}" v-i="{{item.b}}" bind:__l="__l"><custom1 class="v-r-i-f"
v-i="{{item.a}}" bind:__l="__l"/></custom>`
,
`<custom wx:for="{{a}}" wx:for-item="item"
v-s="{{['default']}}" v-i="{{item.b}}" bind:__l="__l"><custom1
v-i="{{item.a}}" bind:__l="__l"/></custom>`
,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-1' + '-' + i0 + ',' + ('2a9ec0b0-0' + '-' + i0), b: '2a9ec0b0-0' + '-' + i0 }; }) }
}`
,
...
...
@@ -87,7 +87,7 @@ describe('compiler: transform component', () => {
test
(
'
component with v-for + component with v-for
'
,
()
=>
{
assert
(
`<custom v-for="item in items"><custom1 v-for="item1 in item.items"/></custom>`
,
`<custom wx:for="{{a}}" wx:for-item="item"
class="v-r-i-f" v-s="{{['default']}}" v-i="{{item.b}}" bind:__l="__l"><custom1 wx:for="{{item.a}}" wx:for-item="item1" class="v-r-i-f
" v-i="{{item1.a}}" bind:__l="__l"/></custom>`
,
`<custom wx:for="{{a}}" wx:for-item="item"
v-s="{{['default']}}" v-i="{{item.b}}" bind:__l="__l"><custom1 wx:for="{{item.a}}" wx:for-item="item1
" v-i="{{item1.a}}" bind:__l="__l"/></custom>`
,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: _f(item.items, (item1, k1, i1) => { return { a: '2a9ec0b0-1' + '-' + i0 + '-' + i1 + ',' + ('2a9ec0b0-0' + '-' + i0) }; }), b: '2a9ec0b0-0' + '-' + i0 }; }) }
}`
,
...
...
packages/uni-mp-compiler/__tests__/ref.spec.ts
浏览文件 @
7033a52e
import
{
assert
}
from
'
./testUtils
'
describe
(
'
compiler: transform ref
'
,
()
=>
{
test
(
'
v-r
'
,
()
=>
{
test
(
'
without ref
'
,
()
=>
{
assert
(
`<custom/>`
,
`<custom
class="v-r"
v-i="2a9ec0b0-0"/>`
,
`<custom v-i="2a9ec0b0-0"/>`
,
`(_ctx, _cache) => {
return {}
}`
)
assert
(
`<custom/><custom/><custom1/>`
,
`<custom
class="v-r" v-i="2a9ec0b0-0"/><custom class="v-r" v-i="2a9ec0b0-1"/><custom1 class="v-r"
v-i="2a9ec0b0-2"/>`
,
`<custom
v-i="2a9ec0b0-0"/><custom v-i="2a9ec0b0-1"/><custom1
v-i="2a9ec0b0-2"/>`
,
`(_ctx, _cache) => {
return {}
}`
)
})
test
(
'
v-r-i-f
'
,
()
=>
{
assert
(
`<custom v-for="item in items"/>`
,
`<custom wx:for="{{a}}" wx:for-item="item" class="v-r-i-f" v-i="{{item.a}}"/>`
,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-0' + '-' + i0 }; }) }
}`
)
})
...
...
@@ -32,6 +23,13 @@ describe('compiler: transform ref', () => {
`<custom class="v-r" data-ref="custom" v-i="2a9ec0b0-0"/>`
,
`(_ctx, _cache) => {
return {}
}`
)
assert
(
`<custom v-for="item in items" ref="custom"/>`
,
`<custom wx:for="{{a}}" wx:for-item="item" class="v-r-i-f" data-ref="custom" v-i="{{item.a}}"/>`
,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-0' + '-' + i0 }; }) }
}`
)
})
...
...
@@ -41,6 +39,13 @@ describe('compiler: transform ref', () => {
`<custom class="v-r" data-ref="{{a}}" v-i="2a9ec0b0-0"/>`
,
`(_ctx, _cache) => {
return { a: _ctx.custom }
}`
)
assert
(
`<custom v-for="item in items" :ref="custom"/>`
,
`<custom wx:for="{{a}}" wx:for-item="item" class="v-r-i-f" data-ref="{{b}}" v-i="{{item.a}}"/>`
,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-0' + '-' + i0 }; }), b: _ctx.custom }
}`
)
})
...
...
packages/uni-mp-compiler/__tests__/scopeId.spec.ts
浏览文件 @
7033a52e
...
...
@@ -33,7 +33,7 @@ describe('compiler: transform scopeId', () => {
)
assert
(
`<view class="bar" :class="foo"/>`
,
`<view class="{{['bar
data-v-5584ec96', a]}}"/>`
,
`<view class="{{['bar
', '
data-v-5584ec96', a]}}"/>`
,
`(_ctx, _cache) => {
return { a: _n(_ctx.foo) }
}`
,
...
...
@@ -41,7 +41,7 @@ describe('compiler: transform scopeId', () => {
)
assert
(
`<view :class="foo" class="bar"/>`
,
`<view class="{{[a, 'bar
data-v-5584ec96']}}"/>`
,
`<view class="{{[a, 'bar
', '
data-v-5584ec96']}}"/>`
,
`(_ctx, _cache) => {
return { a: _n(_ctx.foo) }
}`
,
...
...
packages/uni-mp-compiler/__tests__/vModel.spec.ts
浏览文件 @
7033a52e
...
...
@@ -4,7 +4,7 @@ describe('compiler: transform v-model', () => {
test
(
`component v-model`
,
()
=>
{
assert
(
`<Comp v-model="model" />`
,
`<comp
class="v-r"
v-i="2a9ec0b0-0" modelValue="{{a}}" bindupdateModelValue="{{b}}"/>`
,
`<comp v-i="2a9ec0b0-0" modelValue="{{a}}" bindupdateModelValue="{{b}}"/>`
,
`(_ctx, _cache) => {
return { a: _ctx.model, b: _o($event => _ctx.model = $event) }
}`
...
...
@@ -13,7 +13,7 @@ describe('compiler: transform v-model', () => {
test
(
`component v-model with cache`
,
()
=>
{
assert
(
`<Comp v-model="model" />`
,
`<comp
class="v-r"
v-i="2a9ec0b0-0" modelValue="{{a}}" bindupdateModelValue="{{b}}"/>`
,
`<comp v-i="2a9ec0b0-0" modelValue="{{a}}" bindupdateModelValue="{{b}}"/>`
,
`(_ctx, _cache) => {
return { a: _ctx.model, b: _o($event => _ctx.model = $event) }
}`
,
...
...
packages/uni-mp-compiler/__tests__/vSlot.spec.ts
浏览文件 @
7033a52e
...
...
@@ -4,14 +4,14 @@ describe('compiler: transform v-slot', () => {
test
(
'
default slot
'
,
()
=>
{
assert
(
`<custom><template v-slot/></custom>`
,
`<custom
class="v-r"
v-s="{{['default']}}" v-i="2a9ec0b0-0"><view /></custom>`
,
`<custom v-s="{{['default']}}" v-i="2a9ec0b0-0"><view /></custom>`
,
`(_ctx, _cache) => {
return {}
}`
)
assert
(
`<custom>test</custom>`
,
`<custom
class="v-r"
v-s="{{['default']}}" v-i="2a9ec0b0-0">test</custom>`
,
`<custom v-s="{{['default']}}" v-i="2a9ec0b0-0">test</custom>`
,
`(_ctx, _cache) => {
return {}
}`
...
...
@@ -20,7 +20,7 @@ describe('compiler: transform v-slot', () => {
test
(
'
named slots
'
,
()
=>
{
assert
(
`<custom><template v-slot:header/><template v-slot:default/><template v-slot:footer/></custom>`
,
`<custom
class="v-r"
v-s="{{['header','default','footer']}}" v-i="2a9ec0b0-0"><view slot="header"/><view slot="default"/><view slot="footer"/></custom>`
,
`<custom v-s="{{['header','default','footer']}}" v-i="2a9ec0b0-0"><view slot="header"/><view slot="default"/><view slot="footer"/></custom>`
,
`(_ctx, _cache) => {
return {}
}`
...
...
@@ -30,7 +30,7 @@ describe('compiler: transform v-slot', () => {
test
(
'
scoped slots
'
,
()
=>
{
assert
(
`<custom><template v-slot:default="slotProps"><view>{{ slotProps.item }}</view></template></custom>`
,
`<custom
class="v-r"
v-s="{{['default']}}" v-i="2a9ec0b0-0"><view slot="default"><block wx:for="{{a}}" wx:for-item="slotProps" wx:key="b"><view>{{slotProps.a}}</view></block></view></custom>`
,
`<custom v-s="{{['default']}}" v-i="2a9ec0b0-0"><view slot="default"><block wx:for="{{a}}" wx:for-item="slotProps" wx:key="b"><view>{{slotProps.a}}</view></block></view></custom>`
,
`(_ctx, _cache) => {
return { a: _w((slotProps, s0, i0) => { return { a: _t(slotProps.item), b: s0 }; }, { name: 'default', vueId: '2a9ec0b0-0' }) }
}`
...
...
@@ -40,7 +40,7 @@ describe('compiler: transform v-slot', () => {
test
(
'
scoped slots + scoped slots
'
,
()
=>
{
assert
(
`<custom><template v-slot:default="slotProps"><custom1><template v-slot:default="slotProps1">{{ slotProps.item }}{{ slotProps1.item }}</template></custom1></template></custom>`
,
`<custom
class="v-r" v-s="{{['default']}}" v-i="2a9ec0b0-0"><view slot="default"><block wx:for="{{a}}" wx:for-item="slotProps" wx:key="d"><custom1 class="v-r"
v-s="{{['default']}}" v-i="{{slotProps.c}}"><view slot="default"><block wx:for="{{slotProps.a}}" wx:for-item="slotProps1" wx:key="b">{{slotProps.b}}{{slotProps1.a}}</block></view></custom1></block></view></custom>`
,
`<custom
v-s="{{['default']}}" v-i="2a9ec0b0-0"><view slot="default"><block wx:for="{{a}}" wx:for-item="slotProps" wx:key="d"><custom1
v-s="{{['default']}}" v-i="{{slotProps.c}}"><view slot="default"><block wx:for="{{slotProps.a}}" wx:for-item="slotProps1" wx:key="b">{{slotProps.b}}{{slotProps1.a}}</block></view></custom1></block></view></custom>`
,
`(_ctx, _cache) => {
return { a: _w((slotProps, s0, i0) => { return { a: _w((slotProps1, s1, i1) => { return { a: _t(slotProps1.item), b: s1 }; }, { name: 'default', vueId: '2a9ec0b0-1' + '-' + i0 + ',' + '2a9ec0b0-0' }), b: _t(slotProps.item), c: '2a9ec0b0-1' + '-' + i0 + ',' + '2a9ec0b0-0', d: s0 }; }, { name: 'default', vueId: '2a9ec0b0-0' }) }
}`
...
...
@@ -50,7 +50,7 @@ describe('compiler: transform v-slot', () => {
test
(
'
v-if + scoped slots
'
,
()
=>
{
assert
(
`<custom><template v-if="ok" v-slot:default="slotProps"><view>{{ slotProps.item }}</view></template></custom>`
,
`<custom
class="v-r"
v-s="{{['default']}}" v-i="2a9ec0b0-0"><view wx:if="{{a}}" slot="default"><block wx:for="{{b}}" wx:for-item="slotProps" wx:key="b"><view>{{slotProps.a}}</view></block></view></custom>`
,
`<custom v-s="{{['default']}}" v-i="2a9ec0b0-0"><view wx:if="{{a}}" slot="default"><block wx:for="{{b}}" wx:for-item="slotProps" wx:key="b"><view>{{slotProps.a}}</view></block></view></custom>`
,
`(_ctx, _cache) => {
return _e({ a: _ctx.ok }, _ctx.ok ? { b: _w((slotProps, s0, i0) => { return { a: _t(slotProps.item), b: s0 }; }, { name: 'default', vueId: '2a9ec0b0-0' }) } : {})
}`
...
...
@@ -60,7 +60,7 @@ describe('compiler: transform v-slot', () => {
test
(
'
v-for + scoped slots
'
,
()
=>
{
assert
(
`<custom v-for="item in items"><template v-slot:default="slotProps"><view>{{ slotProps.item }}</view></template></custom>`
,
`<custom wx:for="{{a}}" wx:for-item="item"
class="v-r-i-f"
v-s="{{['default']}}" v-i="{{item.b}}"><view slot="default"><block wx:for="{{item.a}}" wx:for-item="slotProps" wx:key="b"><view>{{slotProps.a}}</view></block></view></custom>`
,
`<custom wx:for="{{a}}" wx:for-item="item" v-s="{{['default']}}" v-i="{{item.b}}"><view slot="default"><block wx:for="{{item.a}}" wx:for-item="slotProps" wx:key="b"><view>{{slotProps.a}}</view></block></view></custom>`
,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: _w((slotProps, s1, i1) => { return { a: _t(slotProps.item), b: s1 }; }, { name: 'default', vueId: '2a9ec0b0-0' + '-' + i0 }), b: '2a9ec0b0-0' + '-' + i0 }; }) }
}`
...
...
@@ -70,7 +70,7 @@ describe('compiler: transform v-slot', () => {
test
(
'
v-for + v-for + scoped slots
'
,
()
=>
{
assert
(
`<view v-for="item in items"><custom v-for="item1 in item.list" :item="item1"><template v-slot:default="slotProps"><view>{{ slotProps.item }}</view></template></custom></view>`
,
`<view wx:for="{{a}}" wx:for-item="item"><custom wx:for="{{item.a}}" wx:for-item="item1"
class="v-r-i-f"
v-s="{{['default']}}" item="{{item1.b}}" v-i="{{item1.c}}"><view slot="default"><block wx:for="{{item1.a}}" wx:for-item="slotProps" wx:key="b"><view>{{slotProps.a}}</view></block></view></custom></view>`
,
`<view wx:for="{{a}}" wx:for-item="item"><custom wx:for="{{item.a}}" wx:for-item="item1" v-s="{{['default']}}" item="{{item1.b}}" v-i="{{item1.c}}"><view slot="default"><block wx:for="{{item1.a}}" wx:for-item="slotProps" wx:key="b"><view>{{slotProps.a}}</view></block></view></custom></view>`
,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: _f(item.list, (item1, k1, i1) => { return { a: _w((slotProps, s2, i2) => { return { a: _t(slotProps.item), b: s2 }; }, { name: 'default', vueId: '2a9ec0b0-0' + '-' + i0 + '-' + i1 }), b: item1, c: '2a9ec0b0-0' + '-' + i0 + '-' + i1 }; }) }; }) }
}`
...
...
packages/uni-mp-compiler/src/index.ts
浏览文件 @
7033a52e
...
...
@@ -10,6 +10,18 @@ import { baseCompile } from './compile'
import
{
parserOptions
}
from
'
./parserOptions
'
import
{
CompilerOptions
}
from
'
./options
'
export
{
findProp
}
from
'
@vue/compiler-core
'
export
type
{
CompilerOptions
,
DirectiveNode
,
NodeTransform
,
TransformContext
,
SimpleExpressionNode
,
}
from
'
@vue/compiler-core
'
export
{
genExpr
}
from
'
./codegen
'
export
{
isForElementNode
}
from
'
./transforms/vFor
'
export
*
from
'
./runtimeHelpers
'
export
function
parse
(
template
:
string
,
options
:
ParserOptions
=
{}):
RootNode
{
...
...
packages/uni-mp-compiler/src/options.ts
浏览文件 @
7033a52e
...
...
@@ -7,14 +7,14 @@ import {
ObjectProperty
,
SpreadElement
,
}
from
'
@babel/types
'
import
{
NodeTransform
as
VueNodeTransform
,
DirectiveTransform
as
VueDirectiveTransform
,
}
from
'
@vue/compiler-core
'
import
{
MiniProgramCompilerOptions
}
from
'
@dcloudio/uni-cli-shared
'
import
{
BindingMetadata
,
CompilerError
,
RootNode
}
from
'
@vue/compiler-core
'
import
IdentifierGenerator
from
'
./identifier
'
import
{
DirectiveTransform
,
NodeTransform
,
TransformContext
,
}
from
'
./transform
'
import
{
TransformContext
}
from
'
./transform
'
import
{
VForOptions
}
from
'
./transforms/vFor
'
export
interface
CodegenRootNode
extends
RootNode
{
...
...
@@ -58,8 +58,8 @@ export interface TransformOptions
filters
?:
string
[]
renderDataSpread
?:
boolean
cacheHandlers
?:
boolean
nodeTransforms
?:
NodeTransform
[]
directiveTransforms
?:
Record
<
string
,
DirectiveTransform
|
undefined
>
nodeTransforms
?:
Vue
NodeTransform
[]
directiveTransforms
?:
Record
<
string
,
Vue
DirectiveTransform
|
undefined
>
isBuiltInComponent
?:
(
tag
:
string
)
=>
symbol
|
void
isCustomElement
?:
(
tag
:
string
)
=>
boolean
|
void
expressionPlugins
?:
ParserPlugin
[]
...
...
packages/uni-mp-compiler/src/template/codegen.ts
浏览文件 @
7033a52e
...
...
@@ -17,7 +17,7 @@ import {
}
from
'
@vue/compiler-core
'
import
{
TemplateCodegenOptions
}
from
'
../options
'
import
{
genExpr
}
from
'
../codegen
'
import
{
isForElementNode
,
VForOptions
}
from
'
../transforms/vFor
'
import
{
ForElementNode
,
isForElementNode
}
from
'
../transforms/vFor
'
import
{
IfElementNode
,
isIfElementNode
}
from
'
../transforms/vIf
'
import
{
findSlotName
}
from
'
../transforms/vSlot
'
interface
TemplateCodegenContext
{
...
...
@@ -95,11 +95,11 @@ function genVElse({ push, directive }: TemplateCodegenContext) {
}
function
genVFor
(
{
sourceAlias
,
valueAlias
}:
VForOptions
,
node
:
ElementNode
,
node
:
ForElementNode
,
{
push
,
directive
}:
TemplateCodegenContext
)
{
push
(
`
${
directive
}
for="{{
${
sourceAlias
}
}}"`
)
const
{
sourceCode
,
valueAlias
}
=
node
.
vFor
push
(
`
${
directive
}
for="
${
sourceCode
}
"`
)
if
(
valueAlias
)
{
push
(
`
${
directive
}
for-item="
${
valueAlias
}
"`
)
}
...
...
@@ -216,7 +216,7 @@ function genElement(node: ElementNode, context: TemplateCodegenContext) {
}
}
if
(
isForElementNode
(
node
))
{
genVFor
(
node
.
vFor
,
node
,
context
)
genVFor
(
node
,
context
)
}
if
(
props
.
length
)
{
genElementProps
(
node
,
context
)
...
...
packages/uni-mp-compiler/src/transform.ts
浏览文件 @
7033a52e
...
...
@@ -160,7 +160,7 @@ export function traverseNode(
const
{
nodeTransforms
}
=
context
const
exitFns
=
[]
for
(
let
i
=
0
;
i
<
nodeTransforms
.
length
;
i
++
)
{
const
onExit
=
nodeTransforms
[
i
](
node
,
context
)
const
onExit
=
nodeTransforms
[
i
](
node
,
context
as
any
)
if
(
onExit
)
{
if
(
isArray
(
onExit
))
{
exitFns
.
push
(...
onExit
)
...
...
packages/uni-mp-compiler/src/transforms/transformClass.ts
浏览文件 @
7033a52e
...
...
@@ -82,20 +82,26 @@ export function rewriteClass(
if
(
staticClassPropIndex
>
-
1
)
{
const
staticClass
=
(
props
[
staticClassPropIndex
]
as
AttributeNode
).
value
!
.
content
if
(
staticClass
.
trim
()
)
{
if
(
staticClass
)
{
if
(
!
isArrayExpression
(
classBidingExpr
))
{
classBidingExpr
=
arrayExpression
([
classBidingExpr
])
}
const
staticClassLiterals
=
parseStaticClass
(
staticClass
)
if
(
index
>
staticClassPropIndex
)
{
classBidingExpr
.
elements
.
unshift
(
stringLiteral
(
staticClass
)
)
classBidingExpr
.
elements
.
unshift
(
...
staticClassLiterals
)
}
else
{
classBidingExpr
.
elements
.
push
(
stringLiteral
(
staticClass
)
)
classBidingExpr
.
elements
.
push
(
...
staticClassLiterals
)
}
}
}
classBindingProp
.
exp
=
createSimpleExpression
(
genBabelExpr
(
classBidingExpr
))
}
function
parseStaticClass
(
staticClass
:
string
):
StringLiteral
[]
{
// 已经在 parse 阶段格式化了多余空格等
return
staticClass
.
split
(
'
'
).
map
((
clazz
)
=>
stringLiteral
(
clazz
))
}
function
rewriteClassExpression
(
expr
:
ExpressionNode
,
context
:
TransformContext
...
...
packages/uni-mp-compiler/src/transforms/transformComponent.ts
浏览文件 @
7033a52e
import
{
ComponentNode
}
from
'
@vue/compiler-core
'
import
{
ComponentNode
,
findProp
}
from
'
@vue/compiler-core
'
import
{
isVForScope
,
NodeTransform
,
TransformContext
}
from
'
../transform
'
import
{
createAttributeNode
,
createBindDirectiveNode
}
from
'
../ast
'
import
{
addStaticClass
}
from
'
./transformElement
'
...
...
@@ -61,6 +61,10 @@ function addVueId(node: ComponentNode, context: TransformContext) {
}
function
addVueRef
(
node
:
ComponentNode
,
context
:
TransformContext
)
{
// 仅配置了 ref 属性的,才需要增补 vue-ref
if
(
!
findProp
(
node
,
'
ref
'
))
{
return
}
return
addStaticClass
(
node
,
// vue-ref-in-for
...
...
packages/uni-mp-compiler/src/transforms/transformElement.ts
浏览文件 @
7033a52e
...
...
@@ -275,7 +275,7 @@ export function processProps(
const
directiveTransform
=
context
.
directiveTransforms
[
name
]
if
(
directiveTransform
)
{
const
{
props
}
=
directiveTransform
(
prop
,
node
,
context
)
const
{
props
}
=
directiveTransform
(
prop
,
node
,
context
as
any
)
if
(
props
.
length
)
{
prop
.
exp
=
props
[
0
].
value
as
ExpressionNode
}
...
...
packages/uni-mp-compiler/src/transforms/vFor.ts
浏览文件 @
7033a52e
...
...
@@ -44,6 +44,7 @@ import { createVSlotCallExpression, isScopedSlotVFor } from './vSlot'
export
type
VForOptions
=
Omit
<
ForParseResult
,
'
tagType
'
>
&
{
sourceExpr
?:
Expression
sourceAlias
:
string
sourceCode
:
string
valueCode
:
string
valueExpr
:
Identifier
|
Pattern
|
RestElement
valueAlias
:
string
...
...
@@ -103,15 +104,18 @@ export const transformFor = createStructuralDirectiveTransform(
const
indexAlias
=
parseAlias
(
indexExpr
,
indexCode
,
'
i
'
+
scopes
.
vFor
)
// 先占位vFor,后续更新 cloneSourceExpr 为 CallExpression
const
cloneSourceExpr
=
cloneNode
(
sourceExpr
!
,
false
)
const
vForData
:
VForOptions
=
{
source
,
sourceExpr
,
sourceAlias
:
rewriteExpression
(
const
sourceAlias
=
rewriteExpression
(
source
,
context
,
cloneSourceExpr
,
parentScope
).
content
,
).
content
const
sourceCode
=
`{{
${
sourceAlias
}
}}`
const
vForData
:
VForOptions
=
{
source
,
sourceExpr
,
sourceAlias
,
sourceCode
,
value
,
valueCode
,
valueExpr
,
...
...
packages/uni-mp-qq/dist/uni.compiler.js
浏览文件 @
7033a52e
...
...
@@ -82,7 +82,7 @@ function fix2648(bundle) {
catch
(
_a
)
{
}
}
const
uniMiniProgram
Weixin
Plugin
=
{
const
uniMiniProgram
QQ
Plugin
=
{
name
:
'
vite:uni-mp-qq
'
,
config
()
{
return
{
...
...
@@ -120,7 +120,7 @@ const options = {
},
global
:
'
qq
'
,
app
:
{
darkmode
:
tru
e
,
darkmode
:
fals
e
,
subpackages
:
true
,
},
project
:
{
...
...
@@ -153,6 +153,6 @@ ${filter.code}
extname
:
'
.qss
'
,
},
};
var
index
=
[
uniMiniProgram
Weixin
Plugin
,
...
initMiniProgramPlugin__default
[
"
default
"
](
options
)];
var
index
=
[
uniMiniProgram
QQ
Plugin
,
...
initMiniProgramPlugin__default
[
"
default
"
](
options
)];
module
.
exports
=
index
;
packages/uni-mp-qq/src/plugin/index.ts
浏览文件 @
7033a52e
...
...
@@ -7,7 +7,7 @@ import initMiniProgramPlugin, {
import
source
from
'
./project.config.json
'
import
{
fix2648
}
from
'
./fix2648
'
const
uniMiniProgram
Weixin
Plugin
:
Plugin
=
{
const
uniMiniProgram
QQ
Plugin
:
Plugin
=
{
name
:
'
vite:uni-mp-qq
'
,
config
()
{
return
{
...
...
@@ -48,7 +48,7 @@ const options: UniMiniProgramPluginOptions = {
},
global
:
'
qq
'
,
app
:
{
darkmode
:
tru
e
,
darkmode
:
fals
e
,
subpackages
:
true
,
},
project
:
{
...
...
@@ -82,4 +82,4 @@ ${filter.code}
},
}
export
default
[
uniMiniProgram
Weixin
Plugin
,
...
initMiniProgramPlugin
(
options
)]
export
default
[
uniMiniProgram
QQ
Plugin
,
...
initMiniProgramPlugin
(
options
)]
packages/uni-mp-vite/src/plugin/index.ts
浏览文件 @
7033a52e
...
...
@@ -7,7 +7,8 @@ import {
parseManifestJsonOnce
,
findMiniProgramTemplateFiles
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
CompilerOptions
}
from
'
@vue/compiler-core
'
import
type
{
CompilerOptions
}
from
'
@dcloudio/uni-mp-compiler
'
import
{
uniOptions
}
from
'
./uni
'
import
{
buildOptions
}
from
'
./build
'
...
...
packages/uni-mp-vite/src/plugin/uni/index.ts
浏览文件 @
7033a52e
...
...
@@ -5,8 +5,8 @@ import {
UniVitePlugin
,
MiniProgramCompilerOptions
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
CompilerOptions
,
TemplateCompiler
}
from
'
@vue/compiler-sfc
'
import
{
TemplateCompiler
}
from
'
@vue/compiler-sfc
'
import
type
{
CompilerOptions
}
from
'
@dcloudio/uni-mp-compiler
'
import
*
as
compiler
from
'
@dcloudio/uni-mp-compiler
'
export
function
uniOptions
({
...
...
@@ -26,6 +26,6 @@ export function uniOptions({
isNativeTag
,
isCustomElement
,
...
compilerOptions
,
},
}
as
any
,
}
}
packages/uni-mp-vite/src/plugins/entry.ts
浏览文件 @
7033a52e
...
...
@@ -61,8 +61,8 @@ export function uniEntryPlugin({
)
this
.
addWatchFile
(
filepath
)
return
{
code
:
`import Page from '
${
filepath
}
?mpType=page'
${
global
}
.createPage(Page)`
,
code
:
`import
MiniProgram
Page from '
${
filepath
}
?mpType=page'
${
global
}
.createPage(
MiniProgram
Page)`
,
}
}
else
if
(
isUniComponentUrl
(
id
))
{
const
filepath
=
normalizePath
(
...
...
packages/uni-stat/dist/uni-stat.cjs.js
浏览文件 @
7033a52e
'
use strict
'
;
var
version
=
"
3.0.0-alpha-30210202110
12005
"
;
var
version
=
"
3.0.0-alpha-30210202110
25001
"
;
const
STAT_VERSION
=
version
;
const
STAT_URL
=
'
https://tongji.dcloud.io/uni/stat
'
;
...
...
packages/uni-stat/dist/uni-stat.es.js
浏览文件 @
7033a52e
var
version
=
"
3.0.0-alpha-30210202110
12005
"
;
var
version
=
"
3.0.0-alpha-30210202110
25001
"
;
const
STAT_VERSION
=
version
;
const
STAT_URL
=
'
https://tongji.dcloud.io/uni/stat
'
;
...
...
yarn.lock
浏览文件 @
7033a52e
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录