提交 81b293e1 编写于 作者: Q qiang

Merge branch 'v3' of github.com:dcloudio/uni-app into v3

...@@ -12088,7 +12088,30 @@ var serviceContext = (function () { ...@@ -12088,7 +12088,30 @@ var serviceContext = (function () {
// } // }
} }
// TODO 临时通过序列化,反序列化传递dataset,后续可以全部保留在service,不做传递
function parseDataset$1 (dataset) {
const ret = Object.create(null);
Object.keys(dataset).forEach(name => {
try {
ret[name] = JSON.parse(dataset[name]);
} catch (e) {}
});
return ret
}
function parseTargets (event) {
const targetDataset = event.target && event.target.dataset;
if (targetDataset) {
event.target.dataset = parseDataset$1(targetDataset);
}
const currentTargetDataset = event.currentTarget && event.currentTarget.dataset;
if (currentTargetDataset) {
event.currentTarget.dataset = parseDataset$1(currentTargetDataset);
}
}
function wrapperEvent (event) { function wrapperEvent (event) {
parseTargets(event);
event.preventDefault = noop; event.preventDefault = noop;
event.stopPropagation = noop; event.stopPropagation = noop;
event.mp = event; event.mp = event;
......
此差异已折叠。
因为 它太大了无法显示 source diff 。你可以改为 查看blob
...@@ -7,13 +7,13 @@ migrate('/Users/fxy/Downloads/wa-vantui_1.1') ...@@ -7,13 +7,13 @@ migrate('/Users/fxy/Downloads/wa-vantui_1.1')
// const { // const {
// parse // parse
// } = require('mustache') // } = require('mustache')
// console.log(parse('{{ { enter: 300, leave: 1000 } }}')) // console.log(parse("van-notice-bar__content {{ !scrollable && !wrapable ? 'van-ellipsis' : '' }}"))
// const { // const {
// transformTemplate // transformTemplate
// } = require('../lib/mp-weixin/transform/template-transformer') // } = require('../lib/mp-weixin/transform/template-transformer')
// console.log(transformTemplate( // console.log(transformTemplate(
// `<view wx:for="{{ columns }}" wx:for-item="item1" wx:key="item1"/>`, { // `<view class="van-notice-bar__content {{ !scrollable && !wrapable ? 'van-ellipsis' : '' }}"></view>`, {
// filename: 'index' // filename: 'index'
// } // }
// )) // ))
...@@ -11,11 +11,17 @@ describe('wxml:compiler', () => { ...@@ -11,11 +11,17 @@ describe('wxml:compiler', () => {
`<view bindtouchstart="startDrag" catchtouchmove="{{ catchMove ? 'noop' : '' }}"/>`, `<view bindtouchstart="startDrag" catchtouchmove="{{ catchMove ? 'noop' : '' }}"/>`,
`<view @touchstart="startDrag" @touchmove.stop="catchMove ? 'noop' : ''"></view>` `<view @touchstart="startDrag" @touchmove.stop="catchMove ? 'noop' : ''"></view>`
) )
})
it('generate class', () => {
assertCodegen(
`<view class="van-notice-bar__content {{ !scrollable && !wrapable ? 'van-ellipsis' : '' }}"></view>`,
`<view :class="'van-notice-bar__content '+(!scrollable && !wrapable ? 'van-ellipsis' : '')"></view>`
)
}) })
it('generate v-if', () => { it('generate v-if', () => {
assertCodegen( assertCodegen(
'<block wx:if="{{ !loading }}" loading loading-text="">{{ item.name }}</block>', '<block wx:if="{{ !loading }}" loading loading-text="">{{ item.name }}</block>',
`<block v-if="!loading" loading loading-text>{{ item.name }}</block>` `<block v-if="(!loading)" loading loading-text>{{ item.name }}</block>`
) )
}) })
it('generate v-for', () => { it('generate v-for', () => {
...@@ -35,7 +41,7 @@ describe('wxml:compiler', () => { ...@@ -35,7 +41,7 @@ describe('wxml:compiler', () => {
it('generate root element', () => { it('generate root element', () => {
assertCodegen( assertCodegen(
'<view></view><view></view>', '<view></view><view></view>',
`<view><view></view><view></view></view>` `<uni-shadow-root><view></view><view></view></uni-shadow-root>`
) )
assertCodegen( assertCodegen(
...@@ -47,7 +53,7 @@ describe('wxml:compiler', () => { ...@@ -47,7 +53,7 @@ describe('wxml:compiler', () => {
assertCodegen( assertCodegen(
'<slot></slot>', '<slot></slot>',
`<view><slot></slot></view>` `<uni-shadow-root><slot></slot></uni-shadow-root>`
) )
}) })
}) })
const patch = require('./patch')
module.exports = { module.exports = {
options: { options: {
extname: { extname: {
template: '.wxml', template: '.wxml',
style: '.wxss' style: '.wxss'
},
shouldWrapper(filepath) {
return patch.wrapper(filepath)
} }
}, },
transform: require('./transform'), transform: require('./transform'),
patch: require('./patch') patch
} }
...@@ -26,7 +26,7 @@ const VANT_VUES = [{ ...@@ -26,7 +26,7 @@ const VANT_VUES = [{
return code.replace(/onLoad/g, 'onImageLoad') return code.replace(/onLoad/g, 'onImageLoad')
.replace(/onError/g, 'onImageError') .replace(/onError/g, 'onImageError')
} }
}] }]
const PATCH_VUES = [ const PATCH_VUES = [
...VANT_VUES ...VANT_VUES
...@@ -49,7 +49,26 @@ function patchVue(file) { ...@@ -49,7 +49,26 @@ function patchVue(file) {
} }
} }
const VANT_WRAPPERS = [
function test(filepath) {
return filepath.indexOf('/cell/index') !== -1
},
function test(filepath) {
return filepath.indexOf('/sticky/index') !== -1
}
]
const PATCH_WRAPPERS = [
...VANT_WRAPPERS
]
function patchWrapper(filepath) {
filepath = normalizePath(filepath)
return !!PATCH_WRAPPERS.find(test => test(filepath))
}
module.exports = { module.exports = {
vue: patchVue, vue: patchVue,
asset: patchAsset asset: patchAsset,
wrapper: patchWrapper
} }
...@@ -25,11 +25,13 @@ module.exports = function transformFile(input, options) { ...@@ -25,11 +25,13 @@ module.exports = function transformFile(input, options) {
filepath + templateExtname filepath + templateExtname
] ]
const [jsCode] = transformJsonFile(filepath + '.json', deps) const [jsCode, isComponent] = transformJsonFile(filepath + '.json', deps)
const [templateCode, wxsCode = '', wxsFiles = []] = transformTemplateFile(filepath + templateExtname, { options.isComponent = isComponent
filename: path.basename(filepath) options.filepath = filepath
}) options.filename = path.basename(filepath)
const [templateCode, wxsCode = '', wxsFiles = []] = transformTemplateFile(filepath + templateExtname, options)
const styleCode = transformStyleFile(filepath + styleExtname, options, deps) || '' const styleCode = transformStyleFile(filepath + styleExtname, options, deps) || ''
const scriptCode = transformScriptFile(filepath + '.js', jsCode, options, deps) const scriptCode = transformScriptFile(filepath + '.js', jsCode, options, deps)
......
...@@ -7,6 +7,7 @@ const { ...@@ -7,6 +7,7 @@ const {
function transformJson(content) { function transformJson(content) {
const { const {
component,
usingComponents usingComponents
} = JSON.parse(content) } = JSON.parse(content)
if (!usingComponents) { if (!usingComponents) {
...@@ -22,7 +23,7 @@ function transformJson(content) { ...@@ -22,7 +23,7 @@ function transformJson(content) {
return [`${importCode.join('\n')} return [`${importCode.join('\n')}
global['__wxVueOptions'] = {components:{${componentsCode.join(',')}}} global['__wxVueOptions'] = {components:{${componentsCode.join(',')}}}
`] `, component]
} }
module.exports = { module.exports = {
......
...@@ -57,7 +57,10 @@ function genWxs(wxs, state) { ...@@ -57,7 +57,10 @@ function genWxs(wxs, state) {
return [wxsCode.join('').trim(), wxsFiles] return [wxsCode.join('').trim(), wxsFiles]
} }
function shouldWrapper(node) { function shouldWrapper(node, state) {
if (state.shouldWrapper(state.filepath)) {
return true
}
node.children = node.children.filter(child => { // remove \n node.children = node.children.filter(child => { // remove \n
if (child.type === 'text' && !child.data.trim()) { if (child.type === 'text' && !child.data.trim()) {
return false return false
...@@ -75,8 +78,9 @@ function shouldWrapper(node) { ...@@ -75,8 +78,9 @@ function shouldWrapper(node) {
} }
module.exports = function generate(node, state) { module.exports = function generate(node, state) {
if (shouldWrapper(node)) { // [`<uni-shadow-root>${genChildren(node).trim()}</uni-shadow-root>`, ...genWxs(state.wxs, state)]
return [`<view>${genChildren(node).trim()}</view>`, ...genWxs(state.wxs, state)] if (shouldWrapper(node, state)) {
return [`<uni-shadow-root>${genChildren(node).trim()}</uni-shadow-root>`, ...genWxs(state.wxs, state)]
} }
return [genChildren(node).trim(), ...genWxs(state.wxs, state)] return [genChildren(node).trim(), ...genWxs(state.wxs, state)]
} }
...@@ -2,9 +2,7 @@ const traverse = require('./traverse') ...@@ -2,9 +2,7 @@ const traverse = require('./traverse')
const generate = require('./generate') const generate = require('./generate')
module.exports = function transform(ast, options) { module.exports = function transform(ast, options) {
const state = { options.wxs = []
wxs: [], options.shouldWrapper = options.shouldWrapper || function noop() {}
filename: options.filename return generate(traverse(ast, options), options)
}
return generate(traverse(ast, state), state)
} }
...@@ -34,7 +34,7 @@ function parseMustache(expr, identifier = false) { ...@@ -34,7 +34,7 @@ function parseMustache(expr, identifier = false) {
} }
return `'${token[1]}'` return `'${token[1]}'`
} else if (token[0] === '!') { // {{ !loading }} } else if (token[0] === '!') { // {{ !loading }}
return `!${token[1]}` return `(!${token[1]})`
} else if (token[0] === 'name') { } else if (token[0] === 'name') {
if (isIdentifier) { if (isIdentifier) {
return token[1] return token[1]
......
...@@ -2,7 +2,7 @@ const fs = require('fs') ...@@ -2,7 +2,7 @@ const fs = require('fs')
const path = require('path') const path = require('path')
const migraters = { const migraters = {
'mp-weixin': require('./mp-weixin').options 'mp-weixin': require('./mp-weixin')
} }
module.exports = function validate(input, out, options) { module.exports = function validate(input, out, options) {
...@@ -10,10 +10,8 @@ module.exports = function validate(input, out, options) { ...@@ -10,10 +10,8 @@ module.exports = function validate(input, out, options) {
if (!fs.existsSync(input)) { if (!fs.existsSync(input)) {
return console.error(`错误: '${input}' 不存在`) return console.error(`错误: '${input}' 不存在`)
} }
Object.assign(options, migraters[options.platform].options)
const platformOptions = migraters[options.platform] const templateExtname = options.extname.template
options.extname = platformOptions.extname
const templateExtname = options.extname.template
const stat = fs.lstatSync(input) const stat = fs.lstatSync(input)
if (stat.isFile()) { if (stat.isFile()) {
......
...@@ -532,11 +532,11 @@ const PROP_DEFAULT_VALUES = { ...@@ -532,11 +532,11 @@ const PROP_DEFAULT_VALUES = {
null: null null: null
}; };
const PROP_DEFAULT_KEYS = Object.keys(PROP_DEFAULT_VALUES); const PROP_DEFAULT_KEY_RE = Object.keys(PROP_DEFAULT_VALUES).map(type => new RegExp(type));
function getDefaultVal (type) { function getDefaultVal (propType) {
return PROP_DEFAULT_KEYS return PROP_DEFAULT_KEY_RE
.filter(type => new RegExp(type).test(type + '')) .filter(regex => regex.test(String(propType)))
.map(type => PROP_DEFAULT_VALUES[type])[0] .map(type => PROP_DEFAULT_VALUES[type])[0]
} }
...@@ -547,7 +547,7 @@ function getPropertyVal (options) { ...@@ -547,7 +547,7 @@ function getPropertyVal (options) {
} }
return getDefaultVal(options.type) return getDefaultVal(options.type)
} }
return getDefaultVal() return getDefaultVal(options)
} }
function getType (propOptions) { function getType (propOptions) {
...@@ -672,11 +672,16 @@ function initMethods (vm) { ...@@ -672,11 +672,16 @@ function initMethods (vm) {
const target = { const target = {
dataset: vm.$el.dataset dataset: vm.$el.dataset
}; };
oldEmit.call(vm, eventName, {
const event = {
target, target,
currentTarget: target, currentTarget: target,
detail detail,
}); preventDefault: noop,
stopPropagation: noop
};
oldEmit.call(vm, eventName, event);
}; };
// 主要是Vant 自己封装了 $emit,放到 methods 中会触发 Vue 的警告,索性,框架直接重写该方法 // 主要是Vant 自己封装了 $emit,放到 methods 中会触发 Vue 的警告,索性,框架直接重写该方法
vm.$emit = (...args) => { vm.$emit = (...args) => {
......
const compiler = require('../lib') const compiler = require('../lib')
const res = compiler.compile( const res = compiler.compile(
` `
<view data-a="1" :data-b="b"></view> <view>
<view v-for="(item, index) in dataList" :key="item.id">
<view v-if="dataType === 2">
</view>
<view v-else>
{{ item.text }}
</view>
</view>
</view>
`, { `, {
miniprogram: true, miniprogram: true,
resourcePath: '/User/fxy/Documents/test.wxml', resourcePath: '/User/fxy/Documents/test.wxml',
......
...@@ -60,6 +60,9 @@ function updateEleId (el, it, state) { ...@@ -60,6 +60,9 @@ function updateEleId (el, it, state) {
child.forId = `${child.forId}+'-'+${it}` child.forId = `${child.forId}+'-'+${it}`
} }
}) })
el.ifConditions && el.ifConditions.forEach((con, index) => {
index !== 0 && updateEleId(con.block, it, state)
})
} }
function getBindingAttr (el, name) { function getBindingAttr (el, name) {
...@@ -244,7 +247,7 @@ module.exports = { ...@@ -244,7 +247,7 @@ module.exports = {
V_ELSE_IF, V_ELSE_IF,
ID, ID,
SET_DATA, SET_DATA,
GET_DATA, GET_DATA,
SET_MP_CLASS, SET_MP_CLASS,
GET_CHANGE_DATA, GET_CHANGE_DATA,
isVar, isVar,
......
import {
noop
} from 'uni-shared'
import { import {
updateProperties updateProperties
} from './state/properties' } from './state/properties'
...@@ -8,11 +12,16 @@ export function initMethods (vm) { ...@@ -8,11 +12,16 @@ export function initMethods (vm) {
const target = { const target = {
dataset: vm.$el.dataset dataset: vm.$el.dataset
} }
oldEmit.call(vm, eventName, {
const event = {
target, target,
currentTarget: target, currentTarget: target,
detail detail,
}) preventDefault: noop,
stopPropagation: noop
}
oldEmit.call(vm, eventName, event)
} }
// 主要是Vant 自己封装了 $emit,放到 methods 中会触发 Vue 的警告,索性,框架直接重写该方法 // 主要是Vant 自己封装了 $emit,放到 methods 中会触发 Vue 的警告,索性,框架直接重写该方法
vm.$emit = (...args) => { vm.$emit = (...args) => {
......
...@@ -12,11 +12,11 @@ const PROP_DEFAULT_VALUES = { ...@@ -12,11 +12,11 @@ const PROP_DEFAULT_VALUES = {
null: null null: null
} }
const PROP_DEFAULT_KEYS = Object.keys(PROP_DEFAULT_VALUES) const PROP_DEFAULT_KEY_RE = Object.keys(PROP_DEFAULT_VALUES).map(type => new RegExp(type))
function getDefaultVal (type) { function getDefaultVal (propType) {
return PROP_DEFAULT_KEYS return PROP_DEFAULT_KEY_RE
.filter(type => new RegExp(type).test(type + '')) .filter(regex => regex.test(String(propType)))
.map(type => PROP_DEFAULT_VALUES[type])[0] .map(type => PROP_DEFAULT_VALUES[type])[0]
} }
......
...@@ -27,7 +27,30 @@ import { ...@@ -27,7 +27,30 @@ import {
import parseComponentCreateOptions from './parse-component-create-options' import parseComponentCreateOptions from './parse-component-create-options'
// TODO 临时通过序列化,反序列化传递dataset,后续可以全部保留在service,不做传递
function parseDataset (dataset) {
const ret = Object.create(null)
Object.keys(dataset).forEach(name => {
try {
ret[name] = JSON.parse(dataset[name])
} catch (e) {}
})
return ret
}
function parseTargets (event) {
const targetDataset = event.target && event.target.dataset
if (targetDataset) {
event.target.dataset = parseDataset(targetDataset)
}
const currentTargetDataset = event.currentTarget && event.currentTarget.dataset
if (currentTargetDataset) {
event.currentTarget.dataset = parseDataset(currentTargetDataset)
}
}
function wrapperEvent (event) { function wrapperEvent (event) {
parseTargets(event)
event.preventDefault = noop event.preventDefault = noop
event.stopPropagation = noop event.stopPropagation = noop
event.mp = event event.mp = event
......
...@@ -103,9 +103,6 @@ function vdSync ({ ...@@ -103,9 +103,6 @@ function vdSync ({
function getData (id, name) { function getData (id, name) {
try { try {
if (name.indexOf('a-data-') === 0) { // TODO 临时方案序列化,反序列化dataset,后续应该将dataset保留在service层
return JSON.parse(this.$r[id][name])
}
return this.$r[id][name] return this.$r[id][name]
} catch (e) { } catch (e) {
console.error(this.$options.__file + `:[${this._$id}]$r[${id}][${name}] is undefined`) console.error(this.$options.__file + `:[${this._$id}]$r[${id}][${name}] is undefined`)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册