diff --git a/packages/uni-template-compiler/__tests__/compiler-extra.spec.js b/packages/uni-template-compiler/__tests__/compiler-extra.spec.js
index 11add830b291bbb680a7524abcba5b0f9e932f27..e8bc904d73bea5b90344c29c066c39eed5fe629c 100644
--- a/packages/uni-template-compiler/__tests__/compiler-extra.spec.js
+++ b/packages/uni-template-compiler/__tests__/compiler-extra.spec.js
@@ -226,12 +226,12 @@ describe('mp:compiler-extra', () => {
assertCodegen(
'text',
- 'text'
+ 'text'
)
assertCodegen(
'text123213',
- 'text123213'
+ 'text123213'
)
assertCodegen(
'',
@@ -676,4 +676,4 @@ describe('mp:compiler-extra', () => {
''
)
})
-})
+})
diff --git a/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js b/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js
index 83828d9692174945ca4de1096dd5ebe0db9fb84d..f1741249d5d2dc2f310517c6d93f5c54dda1cce5 100644
--- a/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js
+++ b/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js
@@ -64,11 +64,11 @@ describe('mp:compiler-mp-alipay', () => {
it('generate scoped slot', () => {
assertCodegen(
'{{props.text}}',
- '{{props.text}}'
+ '{{props.text}}'
)
assertCodegen(
'{{text}}',
- '{{__SCOPED__.text}}'
+ '{{__SCOPED__.text}}'
)
})
diff --git a/packages/uni-template-compiler/__tests__/compiler-mp-baidu.spec.js b/packages/uni-template-compiler/__tests__/compiler-mp-baidu.spec.js
index 42116261bc10292ff339bccea91b831b82f68d83..addfc54e7206accfa1dfb68c85ea3f039444f813 100644
--- a/packages/uni-template-compiler/__tests__/compiler-mp-baidu.spec.js
+++ b/packages/uni-template-compiler/__tests__/compiler-mp-baidu.spec.js
@@ -1,7 +1,7 @@
const compiler = require('../lib')
function assertCodegen (template, templateCode, renderCode = 'with(this){}', options = {}) {
- const res = compiler.compile(template, {
+ const res = compiler.compile(template, {
resourcePath: 'test.wxml',
mp: Object.assign({
minified: true,
@@ -24,11 +24,11 @@ describe('mp:compiler-mp-baidu', () => {
it('generate scoped slot', () => {
assertCodegen(
'{{ bar.foo }}',
- '{{foo}}'
+ '{{foo}}'
)
assertCodegen(
'{{ bar.foo }}',
- '{{foo}}'
+ '{{foo}}'
)
})
@@ -46,7 +46,7 @@ describe('mp:compiler-mp-baidu', () => {
it('generate scoped slot with multiline v-if', () => {
assertCodegen(
'{{ bar.foo }}',
- '{{foo}}'
+ '{{foo}}'
)
assertCodegen(
'{{ bar.foo }}',
@@ -57,54 +57,54 @@ describe('mp:compiler-mp-baidu', () => {
it('generate scoped slot', () => {
assertCodegen(
'{{ user.lastName }}',
- ''
+ ''
)
assertCodegen(
'{{ user.lastName }}',
''
)
- })
-
- it('generate vue id', () => {
- assertCodegen(
- '',
- ''
- )
- assertCodegen(
- '',
- ''
- )
- assertCodegen(
- '',
- ''
- )
- assertCodegen(
- '',
- ''
- )
- assertCodegen(
- '',
- ''
- )
- })
-
- it('generate text trim', () => {
- assertCodegen(
- '\nN: {{title}}\n′',
- '{{\'N: \'+title+"\\\\n′"}}'
- )
- assertCodegen(
- '我是第一行1\n我的第二行',
- '我是第一行1\n我的第二行'
- )
- assertCodegen(
- '我是第一行2\n我的第二行1{{title}}',
- '{{"我是第一行2\\\\n我的第二行1"+title}}'
- )
- assertCodegen(
- `我是第一行3
- 我的第二行2{{title}}`,
- '{{"我是第一行3\\\\n 我的第二行2"+title}}'
- )
})
-})
+
+ it('generate vue id', () => {
+ assertCodegen(
+ '',
+ ''
+ )
+ assertCodegen(
+ '',
+ ''
+ )
+ assertCodegen(
+ '',
+ ''
+ )
+ assertCodegen(
+ '',
+ ''
+ )
+ assertCodegen(
+ '',
+ ''
+ )
+ })
+
+ it('generate text trim', () => {
+ assertCodegen(
+ '\nN: {{title}}\n′',
+ '{{\'N: \'+title+"\\\\n′"}}'
+ )
+ assertCodegen(
+ '我是第一行1\n我的第二行',
+ '我是第一行1\n我的第二行'
+ )
+ assertCodegen(
+ '我是第一行2\n我的第二行1{{title}}',
+ '{{"我是第一行2\\\\n我的第二行1"+title}}'
+ )
+ assertCodegen(
+ `我是第一行3
+ 我的第二行2{{title}}`,
+ '{{"我是第一行3\\\\n 我的第二行2"+title}}'
+ )
+ })
+})
diff --git a/packages/uni-template-compiler/__tests__/compiler.spec.js b/packages/uni-template-compiler/__tests__/compiler.spec.js
index 0693d7d93c26a950e942b04d3ddaffb00fa56510..cccdc17a8b8fad12e4f5ea044a8d34206ae591c6 100644
--- a/packages/uni-template-compiler/__tests__/compiler.spec.js
+++ b/packages/uni-template-compiler/__tests__/compiler.spec.js
@@ -1,7 +1,7 @@
const compiler = require('../lib')
function assertCodegen (template, templateCode, renderCode = 'with(this){}') {
- const res = compiler.compile(template, {
+ const res = compiler.compile(template, {
resourcePath: 'test.wxml',
mp: {
minified: true,
@@ -172,6 +172,7 @@ describe('mp:compiler', () => {
it('generate single slot', () => {
assertCodegen('', '')
+ assertCodegen('', '')
})
it('generate named slot', () => {
@@ -193,6 +194,10 @@ describe('mp:compiler', () => {
'hello world',
'hello world'
)
+ assertCodegen(
+ 'hello world',
+ 'hello world'
+ )
})
// it('generate scoped slot', () => {
@@ -486,7 +491,7 @@ describe('mp:compiler', () => {
)
// normal named function
assertCodegen(
- '',
+ '',
'',
'with(this){if(!_isMounted){e0=function fn(){current++}}}'
)
@@ -665,4 +670,4 @@ describe('mp:compiler', () => {
''
)
})
-})
+})
diff --git a/packages/uni-template-compiler/lib/template/generate.js b/packages/uni-template-compiler/lib/template/generate.js
index 987130f1a7344f69067b58deff146d88e6049952..f78e04ee0b06af9e6a63e80c910c0307e1f504bb 100644
--- a/packages/uni-template-compiler/lib/template/generate.js
+++ b/packages/uni-template-compiler/lib/template/generate.js
@@ -14,6 +14,13 @@ function processElement (ast, state, isRoot) {
ast.type = 'view'
}
+ // 由于小程序端 default 不等同于默认插槽,统一移除 default 命名
+ if (ast.type === 'slot' && hasOwn(ast.attr, 'name') && ast.attr.name === 'default') {
+ delete ast.attr.name
+ } else if (hasOwn(ast.attr, 'slot') && ast.attr.slot === 'default') {
+ delete ast.attr.slot
+ }
+
if (hasOwn(ast.attr, 'textContent')) {
ast.children = [ast.attr.textContent]
delete ast.attr.textContent
@@ -145,4 +152,4 @@ module.exports = function generate (ast, state) {
}
return code
-}
+}