提交 6288bb20 编写于 作者: fxy060608's avatar fxy060608

feat(v3): uni-migration :host

上级 e967ae6a
......@@ -13,7 +13,7 @@ migrate('/Users/fxy/Downloads/wa-vantui_1.1')
// transformTemplate
// } = require('../lib/mp-weixin/transform/template-transformer')
// console.log(transformTemplate(
// `<uni-transition bind:click="click" bindtouchstart="startDrag" catchtouchmove="{{ catchMove ? 'noop' : '' }}"/>`, {
// `<view wx:for="{{ columns }}" wx:for-item="item" wx:key="{{item.value}}"/>`, {
// filename: 'index'
// }
// ))
......@@ -40,6 +40,10 @@ describe('wxml:compiler', () => {
assertCodegen(
'<view wx:for="{{ columns }}" wx:for-item="index" wx:key="*this"/>',
`<uni-shadow-root><view v-for="(index,___i___) in (columns)" :key="index"></view></uni-shadow-root>`
)
assertCodegen(
'<view wx:for="{{ columns }}" wx:for-item="item" wx:key="{{item.value}}"/>',
`<uni-shadow-root><view v-for="(item,index) in (columns)" :key="item.value"></view></uni-shadow-root>`
)
})
it('generate root element', () => {
......
......@@ -13,6 +13,10 @@ const {
transformScriptFile
} = require('./script-transformer')
const {
normalizePath
} = require('../../util')
const pkg = require('../../../package.json')
module.exports = function transformFile(input, options) {
......@@ -32,6 +36,12 @@ module.exports = function transformFile(input, options) {
options.isComponent = isComponent
options.filepath = filepath
options.filename = path.basename(filepath)
if (options.base) {
options.route = normalizePath(path.relative(options.base, filepath))
} else {
options.route = options.filename
}
options.shadowRootHost = options.route.replace(/\//g, '-')
const [templateCode, wxsCode = '', wxsFiles = []] = transformTemplateFile(filepath + templateExtname, options)
......@@ -39,7 +49,7 @@ module.exports = function transformFile(input, options) {
const scriptCode = transformScriptFile(filepath + '.js', jsCode, options, deps)
return [
`<!-- @dcloudio/uni-migration@${pkg.version} -->
`<!-- @dcloudio/uni-migration@${pkg.version} -->
<!-- ${new Date().toLocaleString()} -->
<template>
${templateCode}
......
const fs = require('fs')
const path = require('path')
const {
normalizePath
} = require('../../util')
function transformScript(content, route, code) {
return `${code}
......@@ -24,11 +19,6 @@ Component({})
content = fs.readFileSync(filepath, 'utf8').toString().trim()
deps.push(filepath)
}
let route = normalizePath(filepath)
if (options.base) {
route = normalizePath(path.relative(options.base, filepath))
}
route = route.replace('.js', '')
return transformScript(content, route, code, options)
return transformScript(content, options.route, code, options)
}
}
......@@ -2,6 +2,7 @@ const fs = require('fs')
function transformStyle(content, options) {
return content.replace(new RegExp(`\\${options.extname.style}`, 'g'), '.css')
.replace(':host', '.' + options.shadowRootHost)
}
module.exports = {
......
......@@ -58,5 +58,8 @@ function genWxs(wxs, state) {
}
module.exports = function generate(node, state) {
return [`<uni-shadow-root>${genChildren(node).trim()}</uni-shadow-root>`, ...genWxs(state.wxs, state)]
return [
`<uni-shadow-root class="${state.shadowRootHost}">${genChildren(node).trim()}</uni-shadow-root>`,
...genWxs(state.wxs, state)
]
}
......@@ -127,7 +127,7 @@ function transformFor(attribs) {
if (vKey) {
if (vKey === '*this') {
vKey = vItem
} else if (vKey !== vItem) {
} else if (vKey !== vItem && vKey.indexOf('.')===-1) {// wx:for-key="{{item.value}}"
vKey = vItem + '.' + vKey
}
attribs[':key'] = vKey
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册