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

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

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