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

chore: npm run lint:cli

上级 05848605
......@@ -45,7 +45,7 @@ module.exports = {
let devtool = false
if (process.env.NODE_ENV !== 'production') {
if (process.env.UNI_USING_V3) {
if (vueOptions.pluginOptions['uni-app-plus']['service']) {
if (vueOptions.pluginOptions['uni-app-plus'].service) {
devtool = 'eval-source-map'
}
} else {
......
......@@ -10,7 +10,7 @@ describe('shared:pages', () => {
'van-button': '/wxcomponents/vant/button/index',
'van-card': '../../wxcomponents/vant/card/index'
})).toBe(
`;import VanButton from '@/wxcomponents/vant/button/index.vue';import VanCard from '../../wxcomponents/vant/card/index.vue';exports.default.components=Object.assign({'van-button':VanButton,'van-card':VanCard},exports.default.components||{});`
';import VanButton from \'@/wxcomponents/vant/button/index.vue\';import VanCard from \'../../wxcomponents/vant/card/index.vue\';exports.default.components=Object.assign({\'van-button\':VanButton,\'van-card\':VanCard},exports.default.components||{});'
)
})
it('generate global usingComponents', () => {
......@@ -21,7 +21,7 @@ describe('shared:pages', () => {
'van-cell': 'wxcomponents/vant/cell/index',
'van-cell-group': './wxcomponents/vant/cell-group/index'
})).toBe(
`import VanButton from '@/wxcomponents/vant/button/index.vue';import VanCell from './wxcomponents/vant/cell/index.vue';import VanCellGroup from './wxcomponents/vant/cell-group/index.vue';Vue.component('van-button',VanButton);Vue.component('van-cell',VanCell);Vue.component('van-cell-group',VanCellGroup);`
'import VanButton from \'@/wxcomponents/vant/button/index.vue\';import VanCell from \'./wxcomponents/vant/cell/index.vue\';import VanCellGroup from \'./wxcomponents/vant/cell-group/index.vue\';Vue.component(\'van-button\',VanButton);Vue.component(\'van-cell\',VanCell);Vue.component(\'van-cell-group\',VanCellGroup);'
)
})
})
......@@ -83,8 +83,8 @@ export default {
}
},
created () {
let pages = getCurrentPages()
let page = pages[pages.length - 1]
const pages = getCurrentPages()
const page = pages[pages.length - 1]
this.$watch('title', () => {
this.setNavigationBarTitle()
})
......@@ -103,13 +103,13 @@ export default {
// #ifdef APP-PLUS
this._webview = page.$getAppWebview()
attrs.forEach(key => {
let titleNView = {}
const titleNView = {}
if (this[key] || this[key].length > 0) {
titleNView[key] = this[key]
}
this.setTitleNView(titleNView)
this.$watch(key, (val) => {
let titleStyle = {}
const titleStyle = {}
titleStyle[key] = val
this.setTitleNView(titleStyle)
})
......
......@@ -24,13 +24,13 @@ function getPagesJson () {
const pagesJson = {
pages: {}
}
for (let name of pageSet.values()) {
for (const name of pageSet.values()) {
const style = JSON.parse(getJsonFile(name) || '{}')
delete style.customUsingComponents
pagesJson.pages[name] = style
}
const appJson = JSON.parse(getJsonFile('app') || '{}')
pagesJson.globalStyle = appJson['window'] || {}
pagesJson.globalStyle = appJson.window || {}
return pagesJson
}
......@@ -48,7 +48,7 @@ function getJsonFile (name) {
function getChangedJsonFileMap (clear = true) {
const changedJsonFileMap = new Map()
for (let name of changedJsonFileSet.values()) {
for (const name of changedJsonFileSet.values()) {
changedJsonFileMap.set(name + '.json', jsonFileMap.get(name))
}
clear && changedJsonFileSet.clear()
......@@ -328,7 +328,7 @@ module.exports = {
globalUsingComponents = jsonCache.globalUsingComponents
appJsonUsingComponents = jsonCache.appJsonUsingComponents
// restore 时,所有 file 均触发 change
for (let name of jsonFileMap.keys()) {
for (const name of jsonFileMap.keys()) {
changedJsonFileSet.add(name)
}
return true
......
......@@ -52,7 +52,7 @@ function getH5Options (manifestJson) {
h5.router = Object.assign({}, defaultRouter, h5.router || {})
h5['async'] = Object.assign({}, defaultAsync, h5['async'] || {})
h5.async = Object.assign({}, defaultAsync, h5.async || {})
let base = h5.router.base
......
......@@ -15,8 +15,8 @@ module.exports = {
let scriptOptions = false
if (uniAppOptions && uniAppOptions['scripts']) {
scriptOptions = uniAppOptions['scripts'][name]
if (uniAppOptions && uniAppOptions.scripts) {
scriptOptions = uniAppOptions.scripts[name]
}
if (!scriptOptions) {
......
......@@ -37,8 +37,8 @@ module.exports = {
runByHBuilderX: isInHBuilderX || fs.existsSync(path.resolve(process.env.UNI_HBUILDERX_PLUGINS || '', 'weapp-tools')),
getFlexDirection (json) {
let flexDir = 'column'
if (json && json['nvue'] && json['nvue']['flex-direction']) {
flexDir = json['nvue']['flex-direction']
if (json && json.nvue && json.nvue['flex-direction']) {
flexDir = json.nvue['flex-direction']
const flexDirs = ['row', 'row-reverse', 'column', 'column-reverse']
if (flexDirs.indexOf(flexDir) === -1) {
flexDir = 'column'
......
......@@ -67,10 +67,10 @@ function resolvePlugins () {
}
function initExtends (name, plugin, plugins) {
const extendsPlatform = plugin.config['extends']
const extendsPlatform = plugin.config.extends
if (extendsPlatform) {
if (extendsPlatform !== 'h5') {
console.error(`目前仅支持基于 h5 平台做扩展`)
console.error('目前仅支持基于 h5 平台做扩展')
process.exit(0)
}
const extendsPlugin = plugins.find(plugin => plugin.name === extendsPlatform)
......
......@@ -28,19 +28,19 @@ module.exports = function initPreprocess (name, platforms, userDefines = {}) {
vueContext[normalize(name)] = true
if (name === 'app-plus') {
vueContext['APP_VUE'] = true
vueContext.APP_VUE = true
nvueContext['APP_PLUS'] = true
nvueContext['APP_NVUE'] = true
nvueContext['APP_PLUS_NVUE'] = true
nvueContext.APP_PLUS = true
nvueContext.APP_NVUE = true
nvueContext.APP_PLUS_NVUE = true
}
if (name.startsWith('mp-')) {
vueContext['MP'] = true
vueContext.MP = true
}
if (name.startsWith('app-')) {
vueContext['APP'] = true
vueContext.APP = true
}
userDefineKeys.forEach(name => {
......
module.exports = {
'resize-sensor': ['h5'],
'ad': ['mp-weixin'],
'audio': ['app-plus', 'mp-weixin', 'h5'],
'button': ['app-plus', 'mp-weixin', 'h5'],
'camera': ['mp-weixin'],
'canvas': ['app-plus', 'mp-weixin'],
'checkbox': ['app-plus', 'mp-weixin', 'h5'],
ad: ['mp-weixin'],
audio: ['app-plus', 'mp-weixin', 'h5'],
button: ['app-plus', 'mp-weixin', 'h5'],
camera: ['mp-weixin'],
canvas: ['app-plus', 'mp-weixin'],
checkbox: ['app-plus', 'mp-weixin', 'h5'],
'checkbox-group': ['app-plus', 'mp-weixin', 'h5'],
'cover-image': ['app-plus', 'mp-weixin'],
'cover-view': ['app-plus', 'mp-weixin'],
'editor': ['app-plus', 'mp-weixin', 'h5'],
'form': ['app-plus', 'mp-weixin', 'h5'],
editor: ['app-plus', 'mp-weixin', 'h5'],
form: ['app-plus', 'mp-weixin', 'h5'],
'functional-page-navigator': ['mp-weixin'],
'icon': ['app-plus', 'mp-weixin'],
'image': ['app-plus', 'mp-weixin', 'h5'],
'input': ['app-plus', 'mp-weixin', 'h5'],
'label': ['app-plus', 'mp-weixin', 'h5'],
icon: ['app-plus', 'mp-weixin'],
image: ['app-plus', 'mp-weixin', 'h5'],
input: ['app-plus', 'mp-weixin', 'h5'],
label: ['app-plus', 'mp-weixin', 'h5'],
'live-player': ['mp-weixin'],
'live-pusher': ['mp-weixin'],
'map': ['app-plus', 'mp-weixin', 'h5'],
map: ['app-plus', 'mp-weixin', 'h5'],
'movable-area': ['app-plus', 'mp-weixin'],
'movable-view': ['app-plus', 'mp-weixin'],
'navigator': ['app-plus', 'mp-weixin', 'h5'],
navigator: ['app-plus', 'mp-weixin', 'h5'],
'official-account': ['mp-weixin'],
'open-data': ['mp-weixin'],
'picker': ['app-plus', 'mp-weixin', 'h5'],
picker: ['app-plus', 'mp-weixin', 'h5'],
'picker-view': ['app-plus', 'mp-weixin', 'h5'],
'picker-view-column': ['app-plus', 'mp-weixin', 'h5'],
'progress': ['app-plus', 'mp-weixin', 'h5'],
'radio': ['app-plus', 'mp-weixin', 'h5'],
progress: ['app-plus', 'mp-weixin', 'h5'],
radio: ['app-plus', 'mp-weixin', 'h5'],
'radio-group': ['app-plus', 'mp-weixin', 'h5'],
'rich-text': ['app-plus', 'mp-weixin', 'h5'],
'scroll-view': ['app-plus', 'mp-weixin', 'h5'],
'slider': ['app-plus', 'mp-weixin', 'h5'],
'swiper': ['app-plus', 'mp-weixin', 'h5'],
slider: ['app-plus', 'mp-weixin', 'h5'],
swiper: ['app-plus', 'mp-weixin', 'h5'],
'swiper-item': ['app-plus', 'mp-weixin', 'h5'],
'switch': ['app-plus', 'mp-weixin', 'h5'],
'text': ['app-plus', 'mp-weixin', 'h5'],
'textarea': ['app-plus', 'mp-weixin', 'h5'],
'video': ['app-plus', 'mp-weixin', 'h5'],
'view': ['app-plus', 'mp-weixin', 'h5'],
switch: ['app-plus', 'mp-weixin', 'h5'],
text: ['app-plus', 'mp-weixin', 'h5'],
textarea: ['app-plus', 'mp-weixin', 'h5'],
video: ['app-plus', 'mp-weixin', 'h5'],
view: ['app-plus', 'mp-weixin', 'h5'],
'web-view': ['app-plus', 'mp-weixin']
}
......@@ -98,13 +98,15 @@ function normalizeNodeModules (str) {
return str
}
const _hasOwnProperty = Object.prototype.hasOwnProperty
module.exports = {
isInHBuilderX,
isInHBuilderXAlpha,
normalizeNodeModules,
md5,
hasOwn (obj, key) {
return hasOwnProperty.call(obj, key)
return _hasOwnProperty.call(obj, key)
},
hasModule,
parseStyle (style = {}) {
......
......@@ -19,7 +19,7 @@ module.exports = function patchVant (files, assets, out) {
} else if (filepath.indexOf('/notify/index.vue') !== -1) {
changed = true
// notify show方法与show属性冲突
file.content = file.content.replace(`show()`, 'showNotify()')
file.content = file.content.replace('show()', 'showNotify()')
}
changed && fs.outputFileSync(file.path, file.content)
})
......@@ -29,13 +29,13 @@ module.exports = function patchVant (files, assets, out) {
if (dest.indexOf('array.wxs') !== -1) {
// 兼容 Array.isArray
const content = fs.readFileSync(dest, 'utf8').toString()
.replace(`array && array.constructor === 'Array'`,
`array && (array.constructor === 'Array' || (typeof Array !== 'undefined' && Array.isArray(array)))`)
.replace('array && array.constructor === \'Array\'',
'array && (array.constructor === \'Array\' || (typeof Array !== \'undefined\' && Array.isArray(array)))')
fs.outputFileSync(dest, content)
} else if (dest.indexOf('notify/notify.js') !== -1) {
// notify.js show 方法与 show 属性冲突
const content = fs.readFileSync(dest, 'utf8').toString()
.replace(`show()`, 'showNotify()')
.replace('show()', 'showNotify()')
fs.outputFileSync(dest, content)
}
}
......
......@@ -11,41 +11,41 @@ const capitalize = cached(str => {
})
const EVENTS = {
'click': 'tap',
'touchstart': 'touchStart',
'touchmove': 'touchMove',
'touchend': 'touchEnd',
'touchcancel': 'touchCancel',
'longtap': 'longTap',
'longpress': 'longTap',
'transitionend': 'transitionEnd',
'animationstart': 'animationStart',
'animationiteration': 'animationIteration',
'animationend': 'animationEnd',
'firstappear': 'firstAppear',
click: 'tap',
touchstart: 'touchStart',
touchmove: 'touchMove',
touchend: 'touchEnd',
touchcancel: 'touchCancel',
longtap: 'longTap',
longpress: 'longTap',
transitionend: 'transitionEnd',
animationstart: 'animationStart',
animationiteration: 'animationIteration',
animationend: 'animationEnd',
firstappear: 'firstAppear',
// map
'markertap': 'markerTap',
'callouttap': 'calloutTap',
'controltap': 'controlTap',
'regionchange': 'regionChange',
markertap: 'markerTap',
callouttap: 'calloutTap',
controltap: 'controlTap',
regionchange: 'regionChange',
// scroll-view
'scrolltoupper': 'scrollToUpper',
'scrolltolower': 'scrollToLower',
scrolltoupper: 'scrollToUpper',
scrolltolower: 'scrollToLower',
// movable-view
'changeend': 'changeEnd'
changeend: 'changeEnd'
}
module.exports = {
directive: 'a:',
specialEvents: {
'form': {
'reset': 'onReset'
form: {
reset: 'onReset'
},
'map': {
'markertap': 'onMarkerTap',
'controltap': 'onControlTap',
'callouttap': 'onCalloutTap',
'regionchange': 'onRegionChange'
map: {
markertap: 'onMarkerTap',
controltap: 'onControlTap',
callouttap: 'onCalloutTap',
regionchange: 'onRegionChange'
}
},
createFilterTag (filterTag, {
......
......@@ -12,6 +12,10 @@ wx.createComponent({
`
}
function hasOwn (obj, key) {
return Object.prototype.hasOwnProperty.call(obj, key)
}
module.exports = {
directive: 'wx:',
createScopedSlots (slotName, props, state) {
......@@ -43,7 +47,7 @@ module.exports = {
state.scopedSlots = {}
}
let componentName = `${ownerName}-${parentName}-${slotName}`
if (!state.scopedSlots.hasOwnProperty(componentName)) {
if (!hasOwn(state.scopedSlots, componentName)) {
state.scopedSlots[componentName] = 0
}
if (state.scopedSlots[componentName]) {
......
......@@ -5,7 +5,7 @@ module.exports = function () {
const manifest = global.framework.manifest
if (manifest.package === 'Bundle') {
console.error(`> 建议配置 manifest.json->quickapp-vue->package 应用包名`)
console.error('> 建议配置 manifest.json->quickapp-vue->package 应用包名')
}
const signPath = './sign/' + (process.env.NODE_ENV === 'production' ? 'release' : 'debug')
......
const compiler = require('../lib')
function assertCodegen (template, templateCode, renderCode = `with(this){}`, options = {}) {
function assertCodegen (template, templateCode, renderCode = 'with(this){}', options = {}) {
const res = compiler.compile(template, {
resourcePath: 'test.wxml',
mp: Object.assign({
......@@ -18,72 +18,72 @@ describe('mp:compiler-mp-alipay', () => {
it('generate v-for directive', () => {
assertCodegen(
'<view><view v-for="(item,index) in items" :key="index"></view></view>',
`<view><block a:for="{{items}}" a:for-item="item" a:for-index="index" a:key="index"><view></view></block></view>`
'<view><block a:for="{{items}}" a:for-item="item" a:for-index="index" a:key="index"><view></view></block></view>'
)
})
it('generate v-else-if with v-else directive', () => {
assertCodegen(
'<view><view v-if="show">hello</view><view v-else-if="hide">world</view><view v-else>bye</view></view>',
`<view><block a:if="{{show}}"><view>hello</view></block><block a:else><block a:if="{{hide}}"><view>world</view></block><block a:else><view>bye</view></block></block></view>`
'<view><block a:if="{{show}}"><view>hello</view></block><block a:else><block a:if="{{hide}}"><view>world</view></block><block a:else><view>bye</view></block></block></view>'
)
})
it('generate ref', () => {
assertCodegen(
'<component1 ref="c1">text</component1>',
`<component1 vue-id="551070e6-1" ref="__r" data-ref="c1" onVueInit="__l">text</component1>`
'<component1 vue-id="551070e6-1" ref="__r" data-ref="c1" onVueInit="__l">text</component1>'
)
assertCodegen(
'<component1 :ref="c2">text<text>123213</text></component1>',
`<component1 vue-id="551070e6-1" ref="__r" data-ref="{{c2}}" onVueInit="__l">text<text>123213</text></component1>`
'<component1 vue-id="551070e6-1" ref="__r" data-ref="{{c2}}" onVueInit="__l">text<text>123213</text></component1>'
)
assertCodegen(
'<component1 v-for="item in items" ref="c3"></component1>',
`<block a:for="{{items}}" a:for-item="item" a:for-index="__i0__"><component1 vue-id="{{'551070e6-1-'+__i0__}}" ref="__r" data-ref-in-for="c3" onVueInit="__l"></component1></block>`
'<block a:for="{{items}}" a:for-item="item" a:for-index="__i0__"><component1 vue-id="{{\'551070e6-1-\'+__i0__}}" ref="__r" data-ref-in-for="c3" onVueInit="__l"></component1></block>'
)
assertCodegen(
'<component1 v-for="item in items" :ref="c4"></component1>',
`<block a:for="{{items}}" a:for-item="item" a:for-index="__i0__"><component1 vue-id="{{'551070e6-1-'+__i0__}}" ref="__r" data-ref-in-for="{{c4}}" onVueInit="__l"></component1></block>`
'<block a:for="{{items}}" a:for-item="item" a:for-index="__i0__"><component1 vue-id="{{\'551070e6-1-\'+__i0__}}" ref="__r" data-ref-in-for="{{c4}}" onVueInit="__l"></component1></block>'
)
})
it('generate default slot', () => {
assertCodegen(
'<component1>text</component1>',
`<component1 vue-id="551070e6-1" onVueInit="__l">text</component1>`
'<component1 vue-id="551070e6-1" onVueInit="__l">text</component1>'
)
assertCodegen(
'<component1>text<text>123213</text></component1>',
`<component1 vue-id="551070e6-1" onVueInit="__l">text<text>123213</text></component1>`
'<component1 vue-id="551070e6-1" onVueInit="__l">text<text>123213</text></component1>'
)
assertCodegen(
'<component1>text<block slot="right"></block></component1>',
`<component1 vue-id="551070e6-1" onVueInit="__l">text<view slot="right"></view></component1>`
'<component1 vue-id="551070e6-1" onVueInit="__l">text<view slot="right"></view></component1>'
)
})
it('generate class binding', () => {
assertCodegen(
'<div :class="{ active: isActive }">1</div>',
`<view class="{{(('_div')+' '+((isActive)?'active':''))}}">1</view>`
'<view class="{{((\'_div\')+\' \'+((isActive)?\'active\':\'\'))}}">1</view>'
)
assertCodegen(
`<p class="static" :class="{ active: isActive, 'text-danger': hasError }">2</p>`,
`<view class="{{((('static _p')+' '+((isActive)?'active':''))+' '+((hasError)?'text-danger':''))}}">2</view>`
'<p class="static" :class="{ active: isActive, \'text-danger\': hasError }">2</p>',
'<view class="{{(((\'static _p\')+\' \'+((isActive)?\'active\':\'\'))+\' \'+((hasError)?\'text-danger\':\'\'))}}">2</view>'
)
assertCodegen(
'<p class="static" :class="[activeClass, errorClass]">3</p>',
`<view class="{{((('static _p')+' '+activeClass)+' '+errorClass)}}">3</view>`
'<view class="{{(((\'static _p\')+\' \'+activeClass)+\' \'+errorClass)}}">3</view>'
)
assertCodegen(
`<p class="static" :class="[isActive ? activeClass : '', errorClass]">4</p>`,
`<view class="{{((('static _p')+' '+(isActive?activeClass:''))+' '+errorClass)}}">4</view>`
'<p class="static" :class="[isActive ? activeClass : \'\', errorClass]">4</p>',
'<view class="{{(((\'static _p\')+\' \'+(isActive?activeClass:\'\'))+\' \'+errorClass)}}">4</view>'
)
assertCodegen(
`<p class="static" :class="[{ active: isActive }, errorClass]">5</p>`,
`<view class="{{((('static _p')+' '+[(isActive)?'active':''])+' '+errorClass)}}">5</view>`
'<p class="static" :class="[{ active: isActive }, errorClass]">5</p>',
'<view class="{{(((\'static _p\')+\' \'+[(isActive)?\'active\':\'\'])+\' \'+errorClass)}}">5</view>'
)
assertCodegen(
`<div class="container" :class="computedClassObject">6</div>`,
`<view class="{{(('container _div')+' '+computedClassObject)}}">6</view>`
'<div class="container" :class="computedClassObject">6</div>',
'<view class="{{((\'container _div\')+\' \'+computedClassObject)}}">6</view>'
)
// assertCodegen(
// `<div class="container" :class="computedClassObject">6</div>`,
......@@ -91,61 +91,61 @@ describe('mp:compiler-mp-alipay', () => {
// `with(this){var c0=__get_class(computedClassObject,"container");$mp.data=Object.assign({},{$root:{c0:c0}})}`
// )
assertCodegen(
`<p :class="index === currentIndex ? activeClass : itemClass">7</p>`,
`<view class="{{(('_p')+' '+(index===currentIndex?activeClass:itemClass))}}">7</view>`
'<p :class="index === currentIndex ? activeClass : itemClass">7</p>',
'<view class="{{((\'_p\')+\' \'+(index===currentIndex?activeClass:itemClass))}}">7</view>'
)
assertCodegen(
`<p :class="'m-content-head-'+message.user">8</p>`,
`<view class="{{(('_p')+' '+('m-content-head-'+message.user))}}">8</view>`
'<p :class="\'m-content-head-\'+message.user">8</p>',
'<view class="{{((\'_p\')+\' \'+(\'m-content-head-\'+message.user))}}">8</view>'
)
assertCodegen(
`<p :class="classStr1 || classStr2" class="bg">9</p>`,
`<view class="{{(('bg _p')+' '+(classStr1||classStr2))}}">9</view>`
'<p :class="classStr1 || classStr2" class="bg">9</p>',
'<view class="{{((\'bg _p\')+\' \'+(classStr1||classStr2))}}">9</view>'
)
})
it('generate getPhoneNumber', () => {
assertCodegen(
'<button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">获取手机号</button>',
`<button open-type="getAuthorize" scope="phoneNumber" data-event-opts="{{[['getAuthorize',[['$onAliGetAuthorize',['getPhoneNumber','$event']]]],['error',[['$onAliAuthError',['getPhoneNumber','$event']]]]]}}" onGetAuthorize="__e" onError="__e">获取手机号</button>`
'<button open-type="getAuthorize" scope="phoneNumber" data-event-opts="{{[[\'getAuthorize\',[[\'$onAliGetAuthorize\',[\'getPhoneNumber\',\'$event\']]]],[\'error\',[[\'$onAliAuthError\',[\'getPhoneNumber\',\'$event\']]]]]}}" onGetAuthorize="__e" onError="__e">获取手机号</button>'
)
})
it('generate events with v-on directive', () => {
assertCodegen(
`<uni-list-item title="标题文字" note="描述信息" show-extra-icon="true" :extra-icon="{color: '#4cd964',size: '22',type: 'spinner'}"></uni-list-item>`,
`<uni-list-item vue-id="551070e6-1" title="标题文字" note="描述信息" show-extra-icon="true" extra-icon="{{$root.a0}}" onVueInit="__l"></uni-list-item>`,
`with(this){var a0={color:"#4cd964",size:"22",type:"spinner"};$mp.data=Object.assign({},{$root:{a0:a0}})}`
'<uni-list-item title="标题文字" note="描述信息" show-extra-icon="true" :extra-icon="{color: \'#4cd964\',size: \'22\',type: \'spinner\'}"></uni-list-item>',
'<uni-list-item vue-id="551070e6-1" title="标题文字" note="描述信息" show-extra-icon="true" extra-icon="{{$root.a0}}" onVueInit="__l"></uni-list-item>',
'with(this){var a0={color:"#4cd964",size:"22",type:"spinner"};$mp.data=Object.assign({},{$root:{a0:a0}})}'
)
assertCodegen(
`<view @click="onClick" @touchstart="onTouchStart" @touchmove="onTouchMove" @touchend="onTouchEnd" @touchcancel="onTouchCancel" @longtap="onLongTap" @longpress="onLongPress"></view>`,
`<view data-event-opts="{{[['tap',[['onClick',['$event']]]],['touchStart',[['onTouchStart',['$event']]]],['touchMove',[['onTouchMove',['$event']]]],['touchEnd',[['onTouchEnd',['$event']]]],['touchCancel',[['onTouchCancel',['$event']]]],['longTap',[['onLongTap',['$event']]]],['longTap',[['onLongPress',['$event']]]]]}}" onTap="__e" onTouchStart="__e" onTouchMove="__e" onTouchEnd="__e" onTouchCancel="__e" onLongTap="__e"></view>`
'<view @click="onClick" @touchstart="onTouchStart" @touchmove="onTouchMove" @touchend="onTouchEnd" @touchcancel="onTouchCancel" @longtap="onLongTap" @longpress="onLongPress"></view>',
'<view data-event-opts="{{[[\'tap\',[[\'onClick\',[\'$event\']]]],[\'touchStart\',[[\'onTouchStart\',[\'$event\']]]],[\'touchMove\',[[\'onTouchMove\',[\'$event\']]]],[\'touchEnd\',[[\'onTouchEnd\',[\'$event\']]]],[\'touchCancel\',[[\'onTouchCancel\',[\'$event\']]]],[\'longTap\',[[\'onLongTap\',[\'$event\']]]],[\'longTap\',[[\'onLongPress\',[\'$event\']]]]]}}" onTap="__e" onTouchStart="__e" onTouchMove="__e" onTouchEnd="__e" onTouchCancel="__e" onLongTap="__e"></view>'
)
assertCodegen(
`<form @submit="formSubmit" @reset="formReset"/>`,
`<form data-event-opts="{{[['submit',[['formSubmit',['$event']]]]]}}" onSubmit="__e" onReset="formReset"></form>`
'<form @submit="formSubmit" @reset="formReset"/>',
'<form data-event-opts="{{[[\'submit\',[[\'formSubmit\',[\'$event\']]]]]}}" onSubmit="__e" onReset="formReset"></form>'
)
assertCodegen(
`<map @callouttap="calloutTap" @controltap="controlTap" @markertap="markerTap" @regionchange="regionChange" @tap="tap"/>`,
`<map data-event-opts="{{[['tap',[['tap',['$event']]]]]}}" onCalloutTap="calloutTap" onControlTap="controlTap" onMarkerTap="markerTap" onRegionChange="regionChange" onTap="__e"></map>`
'<map @callouttap="calloutTap" @controltap="controlTap" @markertap="markerTap" @regionchange="regionChange" @tap="tap"/>',
'<map data-event-opts="{{[[\'tap\',[[\'tap\',[\'$event\']]]]]}}" onCalloutTap="calloutTap" onControlTap="controlTap" onMarkerTap="markerTap" onRegionChange="regionChange" onTap="__e"></map>'
)
assertCodegen(
`<view @transitionend="transitionEnd" @animationstart="animationStart" @animationiteration="animationIteration" @animationend="animationEnd" @firstappear="firstAppear"/>`,
`<view data-event-opts="{{[['transitionEnd',[['transitionEnd',['$event']]]],['animationStart',[['animationStart',['$event']]]],['animationIteration',[['animationIteration',['$event']]]],['animationEnd',[['animationEnd',['$event']]]],['firstAppear',[['firstAppear',['$event']]]]]}}" onTransitionEnd="__e" onAnimationStart="__e" onAnimationIteration="__e" onAnimationEnd="__e" onFirstAppear="__e"></view>`
'<view @transitionend="transitionEnd" @animationstart="animationStart" @animationiteration="animationIteration" @animationend="animationEnd" @firstappear="firstAppear"/>',
'<view data-event-opts="{{[[\'transitionEnd\',[[\'transitionEnd\',[\'$event\']]]],[\'animationStart\',[[\'animationStart\',[\'$event\']]]],[\'animationIteration\',[[\'animationIteration\',[\'$event\']]]],[\'animationEnd\',[[\'animationEnd\',[\'$event\']]]],[\'firstAppear\',[[\'firstAppear\',[\'$event\']]]]]}}" onTransitionEnd="__e" onAnimationStart="__e" onAnimationIteration="__e" onAnimationEnd="__e" onFirstAppear="__e"></view>'
)
assertCodegen(
`<scroll-view @scrolltoupper="scrollToUpper" @scrolltolower="scrollToLower"/>`,
`<scroll-view data-event-opts="{{[['scrollToUpper',[['scrollToUpper',['$event']]]],['scrollToLower',[['scrollToLower',['$event']]]]]}}" onScrollToUpper="__e" onScrollToLower="__e"></scroll-view>`
'<scroll-view @scrolltoupper="scrollToUpper" @scrolltolower="scrollToLower"/>',
'<scroll-view data-event-opts="{{[[\'scrollToUpper\',[[\'scrollToUpper\',[\'$event\']]]],[\'scrollToLower\',[[\'scrollToLower\',[\'$event\']]]]]}}" onScrollToUpper="__e" onScrollToLower="__e"></scroll-view>'
)
assertCodegen(
`<movable-view @changeend="changeEnd"/>`,
`<movable-view data-event-opts="{{[['changeEnd',[['changeEnd',['$event']]]]]}}" onChangeEnd="__e"></movable-view>`
'<movable-view @changeend="changeEnd"/>',
'<movable-view data-event-opts="{{[[\'changeEnd\',[[\'changeEnd\',[\'$event\']]]]]}}" onChangeEnd="__e"></movable-view>'
)
})
})
const compiler = require('../lib')
function assertCodegen (template, templateCode, renderCode = `with(this){}`, options = {}) {
function assertCodegen (template, templateCode, renderCode = 'with(this){}', options = {}) {
const res = compiler.compile(template, {
resourcePath: 'test.wxml',
mp: Object.assign({
......@@ -18,93 +18,93 @@ describe('mp:compiler-mp-baidu', () => {
it('generate v-for directive', () => {
assertCodegen(
'<view><view v-for="(item,index) in items" :key="index"></view></view>',
`<view><block s-for="{{items}}" s-for-item="item" s-for-index="index" s-key="index"><view></view></block></view>`
'<view><block s-for="{{items}}" s-for-item="item" s-for-index="index" s-key="index"><view></view></block></view>'
)
})
it('generate scoped slot', () => {
assertCodegen(
'<foo><template slot-scope="bar">{{ bar.foo }}</template></foo>',
`<foo vue-id="551070e6-1" vue-slots="{{['default']}}"><view slot="default">{{foo}}</view></foo>`
'<foo vue-id="551070e6-1" vue-slots="{{[\'default\']}}"><view slot="default">{{foo}}</view></foo>'
)
assertCodegen(
'<foo><view slot-scope="bar">{{ bar.foo }}</view></foo>',
`<foo vue-id="551070e6-1" vue-slots="{{['default']}}"><view slot="default"><view>{{foo}}</view></view></foo>`
'<foo vue-id="551070e6-1" vue-slots="{{[\'default\']}}"><view slot="default"><view>{{foo}}</view></view></foo>'
)
})
it('generate named scoped slot', () => {
assertCodegen(
'<foo><template slot="foo" slot-scope="bar">{{ bar.foo }}</template></foo>',
`<foo vue-id="551070e6-1" vue-slots="{{['foo']}}"><view slot="foo">{{foo}}</view></foo>`
'<foo vue-id="551070e6-1" vue-slots="{{[\'foo\']}}"><view slot="foo">{{foo}}</view></foo>'
)
assertCodegen(
'<foo><view slot="foo" slot-scope="bar">{{ bar.foo }}</view></foo>',
`<foo vue-id="551070e6-1" vue-slots="{{['foo']}}"><view slot="foo"><view>{{foo}}</view></view></foo>`
'<foo vue-id="551070e6-1" vue-slots="{{[\'foo\']}}"><view slot="foo"><view>{{foo}}</view></view></foo>'
)
})
it('generate scoped slot with multiline v-if', () => {
assertCodegen(
'<foo><template v-if="\nshow\n" slot-scope="bar">{{ bar.foo }}</template></foo>',
`<foo vue-id="551070e6-1" vue-slots="{{['default']}}"><view slot="default"><block s-if="{{show}}">{{foo}}</block><block s-else><block></block></block></view></foo>`
'<foo vue-id="551070e6-1" vue-slots="{{[\'default\']}}"><view slot="default"><block s-if="{{show}}">{{foo}}</block><block s-else><block></block></block></view></foo>'
)
assertCodegen(
'<foo><view v-if="\nshow\n" slot="foo" slot-scope="bar">{{ bar.foo }}</view></foo>',
`<foo vue-id="551070e6-1" vue-slots="{{['foo']}}"><view slot="foo"><block s-if="{{show}}"><view>{{foo}}</view></block></view></foo>`
'<foo vue-id="551070e6-1" vue-slots="{{[\'foo\']}}"><view slot="foo"><block s-if="{{show}}"><view>{{foo}}</view></block></view></foo>'
)
})
it('generate scoped slot', () => {
assertCodegen(
'<span><slot v-bind:user="user">{{ user.lastName }}</slot></span>',
`<label class="_span"><block s-if="{{$slots.default}}"><slot name="default" var-user="user"></slot></block><block s-else>{{user.lastName}}</block></label>`
'<label class="_span"><block s-if="{{$slots.default}}"><slot name="default" var-user="user"></slot></block><block s-else>{{user.lastName}}</block></label>'
)
assertCodegen(
'<span><slot name="header" v-bind:user="user">{{ user.lastName }}</slot></span>',
`<label class="_span"><block s-if="{{$slots.header}}"><slot name="header" var-user="user"></slot></block><block s-else>{{user.lastName}}</block></label>`
'<label class="_span"><block s-if="{{$slots.header}}"><slot name="header" var-user="user"></slot></block><block s-else>{{user.lastName}}</block></label>'
)
})
it('generate vue id', () => {
assertCodegen(
'<Test/>',
`<test vue-id="551070e6-1"></test>`
'<test vue-id="551070e6-1"></test>'
)
assertCodegen(
'<Test a="a">',
`<test vue-id="551070e6-1" a="a"></test>`
'<test vue-id="551070e6-1" a="a"></test>'
)
assertCodegen(
'<view><Test v-for="item in items" :key="item"/></view>',
`<view><block s-for="{{items}}" s-for-item="item" s-for-index="__i0__" s-key="*this"><test vue-id="{{'551070e6-1-'+__i0__}}"></test></block></view>`
'<view><block s-for="{{items}}" s-for-item="item" s-for-index="__i0__" s-key="*this"><test vue-id="{{\'551070e6-1-\'+__i0__}}"></test></block></view>'
)
assertCodegen(
'<view><Test v-for="item in items" :key="item"><Test v-for="item in item.items" :key="item"></Test></Test></view>',
`<view><block s-for="{{items}}" s-for-item="item" s-for-index="__i0__" s-key="*this"><test vue-id="{{'551070e6-1-'+__i0__}}" vue-slots="{{['default']}}"><block s-for="{{item.items}}" s-for-item="item" s-for-index="__i1__" s-key="*this"><test vue-id="{{('551070e6-2-'+__i0__+'-'+__i1__)+','+('551070e6-1-'+__i0__)}}"></test></block></test></block></view>`
'<view><block s-for="{{items}}" s-for-item="item" s-for-index="__i0__" s-key="*this"><test vue-id="{{\'551070e6-1-\'+__i0__}}" vue-slots="{{[\'default\']}}"><block s-for="{{item.items}}" s-for-item="item" s-for-index="__i1__" s-key="*this"><test vue-id="{{(\'551070e6-2-\'+__i0__+\'-\'+__i1__)+\',\'+(\'551070e6-1-\'+__i0__)}}"></test></block></test></block></view>'
)
assertCodegen(
'<view><Test v-for="(item,index) in items" :key="item"><Test v-for="(item,index1) in item.items" :key="item"></Test></Test></view>',
`<view><block s-for="{{items}}" s-for-item="item" s-for-index="index" s-key="*this"><test vue-id="{{'551070e6-1-'+index}}" vue-slots="{{['default']}}"><block s-for="{{item.items}}" s-for-item="item" s-for-index="index1" s-key="*this"><test vue-id="{{('551070e6-2-'+index+'-'+index1)+','+('551070e6-1-'+index)}}"></test></block></test></block></view>`
'<view><block s-for="{{items}}" s-for-item="item" s-for-index="index" s-key="*this"><test vue-id="{{\'551070e6-1-\'+index}}" vue-slots="{{[\'default\']}}"><block s-for="{{item.items}}" s-for-item="item" s-for-index="index1" s-key="*this"><test vue-id="{{(\'551070e6-2-\'+index+\'-\'+index1)+\',\'+(\'551070e6-1-\'+index)}}"></test></block></test></block></view>'
)
})
it('generate text trim', () => {
assertCodegen(
'<text>\nN: {{title}}\n′</text>',
`<text>{{'N: '+title+"\\\\n′"}}</text>`
'<text>{{\'N: \'+title+"\\\\n′"}}</text>'
)
assertCodegen(
'<text>我是第一行1\n我的第二行</text>',
`<text>我是第一行1\n我的第二行</text>`
'<text>我是第一行1\n我的第二行</text>'
)
assertCodegen(
'<text>我是第一行2\n我的第二行1{{title}}</text>',
`<text>{{"我是第一行2\\\\n我的第二行1"+title}}</text>`
'<text>{{"我是第一行2\\\\n我的第二行1"+title}}</text>'
)
assertCodegen(
`<text>我是第一行3
我的第二行2{{title}}</text>`,
`<text>{{"我是第一行3\\\\n 我的第二行2"+title}}</text>`
'<text>{{"我是第一行3\\\\n 我的第二行2"+title}}</text>'
)
})
})
const compiler = require('../lib')
function assertCodegen (template, templateCode, renderCode = `with(this){}`, options = {}) {
function assertCodegen (template, templateCode, renderCode = 'with(this){}', options = {}) {
const res = compiler.compile(template, {
resourcePath: 'test.wxml',
mp: Object.assign({
......@@ -18,20 +18,20 @@ describe('mp:compiler-mp-qq', () => {
it('generate text trim', () => {
assertCodegen(
'<text>\nN: {{title}}\n′</text>',
`<text>{{'N: '+title+"\\\\n′"}}</text>`
'<text>{{\'N: \'+title+"\\\\n′"}}</text>'
)
assertCodegen(
'<text>我是第一行1\n我的第二行</text>',
`<text>我是第一行1\n我的第二行</text>`
'<text>我是第一行1\n我的第二行</text>'
)
assertCodegen(
'<text>我是第一行2\n我的第二行1{{title}}</text>',
`<text>{{"我是第一行2\\\\n我的第二行1"+title}}</text>`
'<text>{{"我是第一行2\\\\n我的第二行1"+title}}</text>'
)
assertCodegen(
`<text>我是第一行3
我的第二行2{{title}}</text>`,
`<text>{{"我是第一行3\\\\n 我的第二行2"+title}}</text>`
'<text>{{"我是第一行3\\\\n 我的第二行2"+title}}</text>'
)
})
})
const compiler = require('../lib')
function assertCodegen (template, templateCode, renderCode = `with(this){}`, options = {}) {
function assertCodegen (template, templateCode, renderCode = 'with(this){}', options = {}) {
const res = compiler.compile(template, {
resourcePath: 'test.wxml',
mp: Object.assign({
......@@ -18,41 +18,41 @@ describe('mp:compiler-mp-toutiao', () => {
it('generate v-for directive', () => {
assertCodegen(
'<view><view v-for="(item,index) in items" :key="index"></view></view>',
`<view><block tt:for="{{items}}" tt:for-item="item" tt:for-index="index" tt:key="index"><view></view></block></view>`
'<view><block tt:for="{{items}}" tt:for-item="item" tt:for-index="index" tt:key="index"><view></view></block></view>'
)
})
it('generate ref', () => {
assertCodegen(
'<my-component ref="ref"></my-component>',
`<my-component class="vue-ref" vue-id="551070e6-1" data-ref="ref" bind:__l="__l"></my-component>`
'<my-component class="vue-ref" vue-id="551070e6-1" data-ref="ref" bind:__l="__l"></my-component>'
)
})
it('generate class binding', () => {
assertCodegen(
'<div :class="{ active: isActive }">1</div>',
`<view class="{{(('_div')+' '+((isActive)?'active':''))}}">1</view>`
'<view class="{{((\'_div\')+\' \'+((isActive)?\'active\':\'\'))}}">1</view>'
)
assertCodegen(
`<p class="static" :class="{ active: isActive, 'text-danger': hasError }">2</p>`,
`<view class="{{((('static _p')+' '+((isActive)?'active':''))+' '+((hasError)?'text-danger':''))}}">2</view>`
'<p class="static" :class="{ active: isActive, \'text-danger\': hasError }">2</p>',
'<view class="{{(((\'static _p\')+\' \'+((isActive)?\'active\':\'\'))+\' \'+((hasError)?\'text-danger\':\'\'))}}">2</view>'
)
assertCodegen(
'<p class="static" :class="[activeClass, errorClass]">3</p>',
`<view class="{{((('static _p')+' '+activeClass)+' '+errorClass)}}">3</view>`
'<view class="{{(((\'static _p\')+\' \'+activeClass)+\' \'+errorClass)}}">3</view>'
)
assertCodegen(
`<p class="static" :class="[isActive ? activeClass : '', errorClass]">4</p>`,
`<view class="{{((('static _p')+' '+(isActive?activeClass:''))+' '+errorClass)}}">4</view>`
'<p class="static" :class="[isActive ? activeClass : \'\', errorClass]">4</p>',
'<view class="{{(((\'static _p\')+\' \'+(isActive?activeClass:\'\'))+\' \'+errorClass)}}">4</view>'
)
assertCodegen(
`<p class="static" :class="[{ active: isActive }, errorClass]">5</p>`,
`<view class="{{((('static _p')+' '+[(isActive)?'active':''])+' '+errorClass)}}">5</view>`
'<p class="static" :class="[{ active: isActive }, errorClass]">5</p>',
'<view class="{{(((\'static _p\')+\' \'+[(isActive)?\'active\':\'\'])+\' \'+errorClass)}}">5</view>'
)
assertCodegen(
`<div class="container" :class="computedClassObject">6</div>`,
`<view class="{{(('container _div')+' '+computedClassObject)}}">6</view>`
'<div class="container" :class="computedClassObject">6</div>',
'<view class="{{((\'container _div\')+\' \'+computedClassObject)}}">6</view>'
)
// assertCodegen(
// `<div class="container" :class="computedClassObject">6</div>`,
......@@ -60,16 +60,16 @@ describe('mp:compiler-mp-toutiao', () => {
// `with(this){var c0=__get_class(computedClassObject,"container");$mp.data=Object.assign({},{$root:{c0:c0}})}`
// )
assertCodegen(
`<p :class="index === currentIndex ? activeClass : itemClass">7</p>`,
`<view class="{{(('_p')+' '+(index===currentIndex?activeClass:itemClass))}}">7</view>`
'<p :class="index === currentIndex ? activeClass : itemClass">7</p>',
'<view class="{{((\'_p\')+\' \'+(index===currentIndex?activeClass:itemClass))}}">7</view>'
)
assertCodegen(
`<p :class="'m-content-head-'+message.user">8</p>`,
`<view class="{{(('_p')+' '+('m-content-head-'+message.user))}}">8</view>`
'<p :class="\'m-content-head-\'+message.user">8</p>',
'<view class="{{((\'_p\')+\' \'+(\'m-content-head-\'+message.user))}}">8</view>'
)
assertCodegen(
`<p :class="classStr1 || classStr2" class="bg">9</p>`,
`<view class="{{(('bg _p')+' '+(classStr1||classStr2))}}">9</view>`
'<p :class="classStr1 || classStr2" class="bg">9</p>',
'<view class="{{((\'bg _p\')+\' \'+(classStr1||classStr2))}}">9</view>'
)
})
})
const compiler = require('../lib')
function assertCodegen (template, templateCode, renderCode = `with(this){}`, options = {}) {
function assertCodegen (template, templateCode, renderCode = 'with(this){}', options = {}) {
const res = compiler.compile(template, {
resourcePath: 'test.wxml',
mp: Object.assign({
......@@ -23,14 +23,14 @@ describe('mp:compiler-mp-weixin', () => {
it('generate scoped slot', () => {
assertCodegen(
'<foo><template slot-scope="{bar}">{{ bar.foo }}</template></foo>',
`<foo generic:scoped-slots-default="test-foo-default" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['default']}}"></foo>`,
'<foo generic:scoped-slots-default="test-foo-default" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'default\']}}"></foo>',
function (res) {
expect(res.generic[0]).toBe('test-foo-default')
}
)
assertCodegen(
'<foo><view slot-scope="{bar}">{{ bar.foo }}</view></foo>',
`<foo generic:scoped-slots-default="test-foo-default" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['default']}}"></foo>`,
'<foo generic:scoped-slots-default="test-foo-default" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'default\']}}"></foo>',
function (res) {
expect(res.generic[0]).toBe('test-foo-default')
}
......@@ -40,14 +40,14 @@ describe('mp:compiler-mp-weixin', () => {
it('generate named scoped slot', () => {
assertCodegen(
'<foo><template slot="foo" slot-scope="{bar}">{{ bar.foo }}</template></foo>',
`<foo generic:scoped-slots-foo="test-foo-foo" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['foo']}}"></foo>`,
'<foo generic:scoped-slots-foo="test-foo-foo" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'foo\']}}"></foo>',
function (res) {
expect(res.generic[0]).toBe('test-foo-foo')
}
)
assertCodegen(
'<foo><view slot="foo" slot-scope="{bar}">{{ bar.foo }}</view></foo>',
`<foo generic:scoped-slots-foo="test-foo-foo" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['foo']}}"></foo>`,
'<foo generic:scoped-slots-foo="test-foo-foo" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'foo\']}}"></foo>',
function (res) {
expect(res.generic[0]).toBe('test-foo-foo')
}
......@@ -57,14 +57,14 @@ describe('mp:compiler-mp-weixin', () => {
it('generate scoped slot with multiline v-if', () => {
assertCodegen(
'<foo><template v-if="\nshow\n" slot-scope="{bar}">{{ bar.foo }}</template></foo>',
`<foo generic:scoped-slots-default="test-foo-default" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['default']}}"></foo>`,
'<foo generic:scoped-slots-default="test-foo-default" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'default\']}}"></foo>',
function (res) {
expect(res.generic[0]).toBe('test-foo-default')
}
)
assertCodegen(
'<foo><view v-if="\nshow\n" slot="foo" slot-scope="{bar}">{{ bar.foo }}</view></foo>',
`<foo generic:scoped-slots-foo="test-foo-foo" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['foo']}}"></foo>`,
'<foo generic:scoped-slots-foo="test-foo-foo" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'foo\']}}"></foo>',
function (res) {
expect(res.generic[0]).toBe('test-foo-foo')
}
......@@ -74,14 +74,14 @@ describe('mp:compiler-mp-weixin', () => {
it('generate scoped slot', () => {
assertCodegen(// TODO vue-id
'<span><slot v-bind:user="user">{{ user.lastName }}</slot></span>',
`<label class="_span"><block wx:if="{{$slots.default}}"><scoped-slots-default user="{{user}}" bind:__l="__l"></scoped-slots-default></block><block wx:else>{{user.lastName}}</block></label>`,
'<label class="_span"><block wx:if="{{$slots.default}}"><scoped-slots-default user="{{user}}" bind:__l="__l"></scoped-slots-default></block><block wx:else>{{user.lastName}}</block></label>',
function (res) {
expect(res.componentGenerics['scoped-slots-default']).toBe(true)
}
)
assertCodegen(
'<span><slot name="header" v-bind:user="user">{{ user.lastName }}</slot></span>',
`<label class="_span"><block wx:if="{{$slots.header}}"><scoped-slots-header user="{{user}}" bind:__l="__l"></scoped-slots-header></block><block wx:else>{{user.lastName}}</block></label>`,
'<label class="_span"><block wx:if="{{$slots.header}}"><scoped-slots-header user="{{user}}" bind:__l="__l"></scoped-slots-header></block><block wx:else>{{user.lastName}}</block></label>',
function (res) {
expect(res.componentGenerics['scoped-slots-header']).toBe(true)
}
......@@ -90,7 +90,7 @@ describe('mp:compiler-mp-weixin', () => {
it('generate page-meta', () => {
assertCodegen(// TODO vue-id
'<view><page-meta/><view><button></button></view></view>',
`<page-meta vue-id="551070e6-1" bind:__l="__l"></page-meta><view><button></button></view>`
'<page-meta vue-id="551070e6-1" bind:__l="__l"></page-meta><view><button></button></view>'
)
})
})
const compiler = require('../lib')
function assertCodegen (template, templateCode, renderCode = `with(this){}`, options = {}) {
function assertCodegen (template, templateCode, renderCode = 'with(this){}', options = {}) {
const res = compiler.compile(template, {
resourcePath: 'test.qxml',
mp: Object.assign({
......@@ -18,14 +18,14 @@ describe('mp:compiler-quickapp-light', () => {
it('generate v-for directive', () => {
assertCodegen(
'<view><view v-for="(item,index) in items" :key="index"></view></view>',
`<view><block qa:for="{{items}}" qa:for-item="item" qa:for-index="index" qa:key="index"><view></view></block></view>`
'<view><block qa:for="{{items}}" qa:for-item="item" qa:for-index="index" qa:key="index"><view></view></block></view>'
)
})
it('generate v-else-if with v-else directive', () => {
assertCodegen(
'<view><view v-if="show">hello</view><view v-else-if="hide">world</view><view v-else>bye</view></view>',
`<view><block qa:if="{{show}}"><view>hello</view></block><block qa:else><block qa:if="{{hide}}"><view>world</view></block><block qa:else><view>bye</view></block></block></view>`
'<view><block qa:if="{{show}}"><view>hello</view></block><block qa:else><block qa:if="{{hide}}"><view>world</view></block><block qa:else><view>bye</view></block></block></view>'
)
})
})
......@@ -51,7 +51,7 @@ function markStatic (node) {
) {
node.plain = true
}
if (!node.attrsMap || !node.attrsMap['id']) { // 保留 id 属性, selectComponent 需要使用
if (!node.attrsMap || !node.attrsMap.id) { // 保留 id 属性, selectComponent 需要使用
delete node.attrs
}
}
......
const deprecated = {
events: {
'tap': 'click',
'longtap': 'longpress'
tap: 'click',
longtap: 'longpress'
}
}
module.exports = function parseEvent (el) {
......
......@@ -208,7 +208,7 @@ function handleViewEvents (events) {
}
} else {
events[name] = {
value: `$handleViewEvent($event)`
value: '$handleViewEvent($event)'
}
}
})
......@@ -220,7 +220,7 @@ function genVModel (el, isScopedSlot) {
if ((el.tag === 'v-uni-input' || el.tag === 'v-uni-textarea') && !(el.events && el.events.input)) {
el.model.callback = `function($$v){$handleVModelEvent(${el.attrsMap[ID]},$$v)}`
} else {
el.model.callback = `function(){}`
el.model.callback = 'function(){}'
}
}
}
......
const url = require('url')
const transformAssetUrls = {
'audio': 'src',
'video': ['src', 'poster'],
'img': 'src',
'image': 'src',
audio: 'src',
video: ['src', 'poster'],
img: 'src',
image: 'src',
'cover-image': 'src',
// h5
'v-uni-audio': 'src',
......@@ -43,13 +43,15 @@ function urlToRequire (url) {
* @param urlString an url as a string
*/
function parseUriParts (urlString) {
// initialize return value
// initialize return value
/* eslint-disable node/no-deprecated-api */
const returnValue = url.parse('')
if (urlString) {
// A TypeError is thrown if urlString is not a string
// @see https://nodejs.org/api/url.html#url_url_parse_urlstring_parsequerystring_slashesdenotehost
if (typeof urlString === 'string') {
// check is an uri
// check is an uri
/* eslint-disable node/no-deprecated-api */
return url.parse(urlString) // take apart the uri
}
}
......
......@@ -5,7 +5,8 @@ function generateCodeFrame (
start,
end
) {
source = source.replace(/\r\n/g, '\n') // 替换\r\n 为 \n
source = source.replace(/\r\n/g, '\n') // 替换\r\n 为 \n
/* eslint-disable no-void */
if (start === void 0) start = 0
if (end === void 0) end = source.length
......
......@@ -15,11 +15,11 @@ module.exports = {
value: '"phoneNumber"'
})
delete el.events['getphonenumber']
el.events['getAuthorize'] = {
delete el.events.getphonenumber
el.events.getAuthorize = {
value: '$onAliGetAuthorize(\'' + getPhoneNumberValue + '\',$event)'
}
el.events['error'] = {
el.events.error = {
value: '$onAliAuthError(\'' + getPhoneNumberValue + '\',$event)'
}
}
......
const {
hasOwn
} = require('./util')
const onRE = /^@|^v-on:/
function removeAttr (el, name) {
if (el.attrsMap.hasOwnProperty(name)) {
if (hasOwn(el.attrsMap, name)) {
delete el.attrsMap[name]
el.attrsList.splice(el.attrsList.findIndex(attr => attr.name === name), 1)
return true
......@@ -10,22 +14,22 @@ function removeAttr (el, name) {
module.exports = {
preTransformNode (el, {
warn
}) {
if (process.env.UNI_PLATFORM === 'app-plus' && el.tag === 'ad') {
warn('app-vue平台, <ad> 组件暂不支持非 V3 编译, 详见: https://ask.dcloud.net.cn/article/36599')
}) {
if (process.env.UNI_PLATFORM === 'app-plus' && el.tag === 'ad') {
warn('app-vue平台, <ad> 组件暂不支持非 V3 编译, 详见: https://ask.dcloud.net.cn/article/36599')
}
if (el.tag === 'slot' && !el.attrsMap['name']) {
if (el.tag === 'slot' && !el.attrsMap.name) {
el.attrsList.push({
name: 'SLOT_DEFAULT',
value: true
})
el.attrsMap['SLOT_DEFAULT'] = true
el.attrsMap.SLOT_DEFAULT = true
}
// 处理 attr
el.attrsList.forEach(attr => {
if (
attr.name.indexOf('v-model') === 0 &&
attr.name.indexOf('.lazy') !== -1
attr.name.indexOf('.lazy') !== -1
) {
const origName = attr.name
const newName = origName.replace('.lazy', '')
......
......@@ -5,7 +5,7 @@ const {
const getMemberExpr = require('../member-expr')
module.exports = function processAttrs (paths, path, state, isComponent, tagName) {
const attrsPath = paths['attrs']
const attrsPath = paths.attrs
if (attrsPath) {
attrsPath.get('value.properties').forEach(propertyPath => {
const valuePath = propertyPath.get('value')
......
......@@ -70,8 +70,8 @@ function processClassArrayExpression (classValuePath) {
}
module.exports = function processClass (paths, path, state) {
const classPath = paths['class']
const staticClassPath = paths['staticClass']
const classPath = paths.class
const staticClassPath = paths.staticClass
if (classPath) {
const classValuePath = classPath.get('value')
if (classValuePath.isObjectExpression()) { // object
......
......@@ -5,7 +5,7 @@ const {
} = require('./util')
module.exports = function processDir (paths, path, state) {
const directivesPath = paths['directives']
const directivesPath = paths.directives
if (directivesPath) {
/**
* directives: [{
......@@ -30,7 +30,7 @@ module.exports = function processDir (paths, path, state) {
return property.key.name === 'modifiers'
})
if (exprProperty) {
const onPath = paths['on']
const onPath = paths.on
const existingInput = onPath.node.value.properties.find(
property => property.key.value === 'input'
......
......@@ -211,7 +211,7 @@ function parseEvent (keyPath, valuePath, state, isComponent, isNativeOn = false,
let isPassive = false
let isOnce = false
let methods = []
const methods = []
if (type) {
isPassive = type.charAt(0) === VUE_EVENT_MODIFIERS.passive
......@@ -416,8 +416,8 @@ function _processEvent (path, state, isComponent, isNativeOn = false, tagName, r
return opts
}
module.exports = function processEvent (paths, path, state, isComponent, tagName) {
const onPath = paths['on']
const nativeOnPath = paths['nativeOn']
const onPath = paths.on
const nativeOnPath = paths.nativeOn
const ret = []
......
......@@ -47,7 +47,7 @@ module.exports = function traverseData (path, state, tagName) {
}
if (addAttrProperties.length) {
const attrsPath = paths['attrs']
const attrsPath = paths.attrs
if (attrsPath) {
attrsPath.node.value.properties = attrsPath.node.value.properties.concat(addAttrProperties)
} else {
......
......@@ -5,7 +5,7 @@ const {
} = require('./util')
module.exports = function processRef (paths, path, state) {
const modelPath = paths['model']
const modelPath = paths.model
if (modelPath) {
const callbackProperty = modelPath.node.value.properties.find(property => {
return property.key.name === 'callback'
......@@ -17,7 +17,7 @@ module.exports = function processRef (paths, path, state) {
const prop = exprProperty.value.value.trim()
const onPath = paths['on']
const onPath = paths.on
// on:{'input':__m('msg',$event)}
if (!onPath) {
......@@ -32,7 +32,7 @@ module.exports = function processRef (paths, path, state) {
)
]))
)
paths['on'] = path.get('properties').find(
paths.on = path.get('properties').find(
propertyPath => propertyPath.node.key.name === 'on'
)
} else {
......
......@@ -6,7 +6,7 @@ const {
} = require('../../../constants')
module.exports = function processRef (paths, path, state) {
const refPath = paths['ref']
const refPath = paths.ref
if (refPath) {
if (state.options.platform.name === 'mp-alipay') {
return [
......@@ -21,14 +21,14 @@ module.exports = function processRef (paths, path, state) {
]
}
const refClass = state.inFor ? CLASS_REF_IN_FOR : CLASS_REF
const staticClassPath = paths['staticClass']
const staticClassPath = paths.staticClass
if (staticClassPath) { // append
staticClassPath.node.value.value = staticClassPath.node.value.value + ' ' + refClass
} else { // add staticClass
path.node.properties.unshift(
t.objectProperty(t.identifier('staticClass'), t.stringLiteral(refClass))
)
paths['staticClass'] = path.get('properties').find(
paths.staticClass = path.get('properties').find(
propertyPath => propertyPath.node.key.name === 'staticClass'
)
}
......
......@@ -118,8 +118,8 @@ function generateGetStyle (stylePath, styleValuePath, staticStylePath, state) {
}
module.exports = function processStyle (paths, path, state) {
const stylePath = paths['style']
const staticStylePath = paths['staticStyle']
const stylePath = paths.style
const staticStylePath = paths.staticStyle
if (stylePath) {
const styleValuePath = stylePath.get('value')
if (styleValuePath.isObjectExpression()) {
......
......@@ -16,7 +16,7 @@ const GLOBAL_METHODS = [
]
const GLOBAL_OBJECTS = {
'Math': [
Math: [
'abs',
'acos',
'asin',
......@@ -36,7 +36,7 @@ const GLOBAL_OBJECTS = {
'sqrt',
'tan'
],
'JSON': [
JSON: [
'stringify',
'parse'
]
......
......@@ -10,7 +10,8 @@ const {
getMapCallExpression
} = require('./statements')
const {
const {
hasOwn,
genCode,
traverseKey,
processMemberExpression,
......@@ -63,7 +64,7 @@ function getForExtra (forItem, forIndex, path, state) {
let forCode = genCode(processMemberExpression(path.node.arguments[0], state), true)
const forKey = traverseKey(path.node)
let origForKeyCode = t.isIdentifier(forKey) && forKey.name
const origForKeyCode = t.isIdentifier(forKey) && forKey.name
let forKeyCode = ''
if (forKey) {
forKeyCode = genCode(processMemberExpression(forKey, state), true)
......@@ -110,7 +111,7 @@ module.exports = function traverseRenderList (path, state) {
let forIndex = params.length > 1 && params[1].name
if (!forIndex) {
if (!state.options.hasOwnProperty('$forIndexId')) {
if (!hasOwn(state.options, '$forIndexId')) {
state.options.$forIndexId = 0
}
forIndex = getForIndexIdentifier(state.options.$forIndexId++)
......
......@@ -15,7 +15,8 @@ const {
getTagName
} = require('../../h5')
const {
const {
hasOwn,
hyphenate,
traverseFilter,
getComponentName
......@@ -55,7 +56,7 @@ function addVueId (path, state) {
// ) {
// return
// }
if (!state.options.hasOwnProperty('$vueId')) {
if (!hasOwn(state.options, '$vueId')) {
state.options.$vueId = 1
}
const hashId = state.options.hashId
......@@ -64,8 +65,8 @@ function addVueId (path, state) {
let value
if (state.scoped.length) {
let scopeds = state.scoped
let len = scopeds.length
const scopeds = state.scoped
const len = scopeds.length
if (len > 1) { // v-for 嵌套,forIndex 不允许重复
const forIndexSet = new Set()
for (let i = 0; i < len; i++) {
......@@ -148,38 +149,42 @@ module.exports = {
const methodName = callee.name
switch (methodName) {
case METHOD_CREATE_ELEMENT:
const tagNode = path.node.arguments[0]
if (t.isStringLiteral(tagNode)) {
// 需要把标签增加到 class 样式中
const tagName = getTagName(tagNode.value)
if (tagName !== tagNode.value) {
addStaticClass(path, '_' + tagNode.value)
}
tagNode.value = getComponentName(hyphenate(tagName))
// 组件增加 vueId
if (this.options.platform.isComponent(tagNode.value)) {
addVueId(path, this)
}
// 查找全局组件
checkUsingGlobalComponents(
tagNode.value,
this.options.globalUsingComponents,
this
)
}
if (this.options.scopeId) {
addStaticClass(path, this.options.scopeId)
{
const tagNode = path.node.arguments[0]
if (t.isStringLiteral(tagNode)) {
// 需要把标签增加到 class 样式中
const tagName = getTagName(tagNode.value)
if (tagName !== tagNode.value) {
addStaticClass(path, '_' + tagNode.value)
}
tagNode.value = getComponentName(hyphenate(tagName))
// 组件增加 vueId
if (this.options.platform.isComponent(tagNode.value)) {
addVueId(path, this)
}
// 查找全局组件
checkUsingGlobalComponents(
tagNode.value,
this.options.globalUsingComponents,
this
)
}
if (this.options.scopeId) {
addStaticClass(path, this.options.scopeId)
}
const dataPath = path.get('arguments.1')
dataPath && dataPath.isObjectExpression() && traverseData(dataPath, this, tagNode.value)
}
const dataPath = path.get('arguments.1')
dataPath && dataPath.isObjectExpression() && traverseData(dataPath, this, tagNode.value)
break
case METHOD_TO_STRING:
const stringNodes = path.node.arguments[0]
stringNodes.$toString = true
path.replaceWith(stringNodes)
{
const stringNodes = path.node.arguments[0]
stringNodes.$toString = true
path.replaceWith(stringNodes)
}
break
case METHOD_RENDER_LIST:
traverseRenderList(path, this)
......
const {
hasOwn
} = require('../util')
const {
SELF_CLOSING_TAGS,
INTERNAL_EVENT_LINK
......@@ -6,27 +10,27 @@ const {
function processElement (ast, state, isRoot) {
const platformName = state.options.platform.name
// <template slot="f"></template>
if (ast.type === 'template' && ast.attr.hasOwnProperty('slot')) {
if (ast.type === 'template' && hasOwn(ast.attr, 'slot')) {
ast.type = 'view'
}
if (ast.attr.hasOwnProperty('textContent')) {
ast.children = [ast.attr['textContent']]
delete ast.attr['textContent']
if (hasOwn(ast.attr, 'textContent')) {
ast.children = [ast.attr.textContent]
delete ast.attr.textContent
}
if (ast.attr.hasOwnProperty('innerHTML')) {
if (hasOwn(ast.attr, 'innerHTML')) {
ast.children = [{
type: 'rich-text',
attr: {
nodes: ast.attr['innerHTML']
nodes: ast.attr.innerHTML
},
children: []
}]
delete ast.attr['innerHTML']
delete ast.attr.innerHTML
}
if (state.options.platform.isComponent(ast.type)) {
if (platformName === 'mp-alipay') {
ast.attr['onVueInit'] = INTERNAL_EVENT_LINK
ast.attr.onVueInit = INTERNAL_EVENT_LINK
} else if (platformName !== 'mp-baidu') {
ast.attr['bind:' + INTERNAL_EVENT_LINK] = INTERNAL_EVENT_LINK
}
......@@ -59,10 +63,10 @@ function processElement (ast, state, isRoot) {
if (slots.length && platformName !== 'mp-alipay') { // 标记 slots
ast.attr['vue-slots'] = '{{[' + slots.reverse().map(slotName => `'${slotName}'`).join(',') + ']}}'
}
if (ast.attr['id'] && ast.attr['id'].indexOf('{{') === 0) {
if (ast.attr.id && ast.attr.id.indexOf('{{') === 0) {
state.tips.add(`id 作为属性保留名,不允许在自定义组件 ${ast.type} 中定义为 props`)
}
if (ast.attr.hasOwnProperty('data')) { // 百度中会出现异常情况
if (hasOwn(ast.attr, 'data')) { // 百度中会出现异常情况
state.tips.add(`data 作为属性保留名,不允许在自定义组件 ${ast.type} 中定义为 props`)
}
}
......@@ -124,7 +128,7 @@ function parsePageMeta (ast, state) {
return ast
}
module.exports = function generate (ast, state) {
module.exports = function generate (ast, state) {
ast = parsePageMeta(ast, state)
if (!Array.isArray(ast)) {
......
......@@ -176,7 +176,7 @@ function traverseDataNode (dataNode, state, node) {
dataNode.properties.forEach(property => {
switch (property.key.name) {
case 'slot':
ret['slot'] = genCode(property.value)
ret.slot = genCode(property.value)
break
case 'scopedSlots': // Vue 2.6
property.value.$node = node
......@@ -203,11 +203,11 @@ function traverseDataNode (dataNode, state, node) {
break
case 'class':
case 'staticClass':
ret['class'] = genCode(property.value)
ret.class = genCode(property.value)
break
case 'style':
case 'staticStyle':
ret['style'] = genCode(property.value)
ret.style = genCode(property.value)
break
case 'directives':
property.value.elements.find(objectExpression => {
......@@ -222,7 +222,7 @@ function traverseDataNode (dataNode, state, node) {
objectExpression.properties.find(valueProperty => {
const isValue = valueProperty.key.name === 'value'
if (isValue) {
ret['hidden'] = genCode(valueProperty.value, false, true)
ret.hidden = genCode(valueProperty.value, false, true)
}
return isValue
})
......@@ -278,7 +278,7 @@ function genSlotNode (slotName, slotNode, fallbackNodes, state) {
function traverseRenderSlot (callExprNode, state) {
if (!t.isStringLiteral(callExprNode.arguments[0])) {
state.errors.add(`v-slot 不支持动态插槽名`)
state.errors.add('v-slot 不支持动态插槽名')
return
}
......@@ -290,9 +290,9 @@ function traverseRenderSlot (callExprNode, state) {
callExprNode.arguments[2].properties.forEach(property => {
props[property.key.value] = genCode(property.value)
})
deleteSlotName = props['SLOT_DEFAULT'] && Object.keys(props).length === 1
deleteSlotName = props.SLOT_DEFAULT && Object.keys(props).length === 1
if (!deleteSlotName) {
delete props['SLOT_DEFAULT']
delete props.SLOT_DEFAULT
return genSlotNode(
slotName,
state.options.platform.createScopedSlots(slotName, props, state),
......
......@@ -127,7 +127,7 @@ function processMemberProperty (node, state) {
if (t.isNumericLiteral(property)) {
node.property = t.identifier('__$n' + property.value)
} else if (!t.isStringLiteral(property)) {
if (!state.options.hasOwnProperty('__m__')) {
if (!hasOwn(state.options, '__m__')) {
state.options.__m__ = 0
state.options.replaceCodes = {}
}
......@@ -173,7 +173,7 @@ function processMemberExpression (element, state) {
}
function hasOwn (obj, key) {
return hasOwnProperty.call(obj, key)
return Object.prototype.hasOwnProperty.call(obj, key)
}
const tags = require('@dcloudio/uni-cli-shared/lib/tags')
......@@ -211,6 +211,7 @@ function makeMap (str, expectsLowerCase) {
: val => map[val]
}
module.exports = {
hasOwn,
isUnaryTag: makeMap(
'image,area,base,br,col,embed,frame,hr,img,input,isindex,keygen,' +
'link,meta,param,source,track,wbr'
......
......@@ -13,37 +13,37 @@ const options = {
describe('console', () => {
it('log', () => {
expect(transformSync(`console.log('123')`, options).code)
.toBe(`__f__("log","123"," at /index.vue:1");`)
expect(transformSync(`console.log('123',a,{a:1,b:2})`, options).code)
.toBe(`__f__("log","123",a,{a:1,b:2}," at /index.vue:1");`)
expect(transformSync('console.log(\'123\')', options).code)
.toBe('__f__("log","123"," at /index.vue:1");')
expect(transformSync('console.log(\'123\',a,{a:1,b:2})', options).code)
.toBe('__f__("log","123",a,{a:1,b:2}," at /index.vue:1");')
})
it('debug', () => {
expect(transformSync(`console.log('123')`, options).code)
.toBe(`__f__("log","123"," at /index.vue:1");`)
expect(transformSync(`console.log('123',a,{a:1,b:2})`, options).code)
.toBe(`__f__("log","123",a,{a:1,b:2}," at /index.vue:1");`)
expect(transformSync('console.log(\'123\')', options).code)
.toBe('__f__("log","123"," at /index.vue:1");')
expect(transformSync('console.log(\'123\',a,{a:1,b:2})', options).code)
.toBe('__f__("log","123",a,{a:1,b:2}," at /index.vue:1");')
})
it('info', () => {
expect(transformSync(`console.info('123')`, options).code)
.toBe(`__f__("info","123"," at /index.vue:1");`)
expect(transformSync(`console.info('123',a,{a:1,b:2})`, options).code)
.toBe(`__f__("info","123",a,{a:1,b:2}," at /index.vue:1");`)
expect(transformSync('console.info(\'123\')', options).code)
.toBe('__f__("info","123"," at /index.vue:1");')
expect(transformSync('console.info(\'123\',a,{a:1,b:2})', options).code)
.toBe('__f__("info","123",a,{a:1,b:2}," at /index.vue:1");')
})
it('warn', () => {
expect(transformSync(`console.warn('123')`, options).code)
.toBe(`__f__("warn","123"," at /index.vue:1");`)
expect(transformSync(`console.warn('123',a,{a:1,b:2})`, options).code)
.toBe(`__f__("warn","123",a,{a:1,b:2}," at /index.vue:1");`)
expect(transformSync('console.warn(\'123\')', options).code)
.toBe('__f__("warn","123"," at /index.vue:1");')
expect(transformSync('console.warn(\'123\',a,{a:1,b:2})', options).code)
.toBe('__f__("warn","123",a,{a:1,b:2}," at /index.vue:1");')
})
it('error', () => {
expect(transformSync(`console.error('123')`, options).code)
.toBe(`__f__("error","123"," at /index.vue:1");`)
expect(transformSync(`console.error('123',a,{a:1,b:2})`, options).code)
.toBe(`__f__("error","123",a,{a:1,b:2}," at /index.vue:1");`)
expect(transformSync('console.error(\'123\')', options).code)
.toBe('__f__("error","123"," at /index.vue:1");')
expect(transformSync('console.error(\'123\',a,{a:1,b:2})', options).code)
.toBe('__f__("error","123",a,{a:1,b:2}," at /index.vue:1");')
})
})
......@@ -4,7 +4,7 @@ const {
transform
} = require('@babel/core')
transform(`console.log('123')`, {
transform('console.log(\'123\')', {
filename: '/index.vue',
configFile: false,
minified: true,
......
......@@ -49,7 +49,7 @@ const isScss = fs.existsSync(path.resolve(process.env.UNI_INPUT_DIR, 'uni.scss')
let sassData = isSass ? getPlatformSass() : getPlatformScss()
if (isSass) {
sassData = `@import "@/uni.sass"`
sassData = '@import "@/uni.sass"'
} else if (isScss) {
sassData = `${sassData}
@import "@/uni.scss";`
......
......@@ -22,7 +22,7 @@ const modules = []
const deprecated = {
events: {
'tap': 'click'
tap: 'click'
}
}
......
......@@ -45,7 +45,7 @@ const uniPath = process.env.UNI_USING_V8
const uniCloudPath = require.resolve('@dcloudio/vue-cli-plugin-uni/packages/uni-cloud/dist/index.js')
const provide = {
'uniCloud': [uniCloudPath, 'default']
uniCloud: [uniCloudPath, 'default']
}
if (
......@@ -61,11 +61,11 @@ if (
if (!process.env.UNI_USING_V3 && !process.env.UNI_USING_V3_NATIVE) {
if (!process.env.UNI_USING_NATIVE) {
provide['uni'] = [path.resolve(__dirname, uniPath), 'default']
provide.uni = [path.resolve(__dirname, uniPath), 'default']
}
if (process.env.UNI_USING_V8) {
provide['plus'] = [path.resolve(__dirname, uniPath), 'weexPlus']
provide.plus = [path.resolve(__dirname, uniPath), 'weexPlus']
}
}
......@@ -73,18 +73,18 @@ if (
process.env.UNI_PLATFORM === 'app-plus' &&
process.env.UNI_USING_V8
) {
provide['__f__'] = [require.resolve('@dcloudio/vue-cli-plugin-uni/lib/format-log.js'), 'default']
provide['crypto'] = [require.resolve('@dcloudio/vue-cli-plugin-uni/lib/crypto.js'), 'default']
provide.__f__ = [require.resolve('@dcloudio/vue-cli-plugin-uni/lib/format-log.js'), 'default']
provide.crypto = [require.resolve('@dcloudio/vue-cli-plugin-uni/lib/crypto.js'), 'default']
}
const plugins = [
new VueLoaderPlugin(),
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'VUE_APP_PLATFORM': JSON.stringify(process.env.UNI_PLATFORM),
'UNI_CLOUD_PROVIDER': process.env.UNI_CLOUD_PROVIDER,
'HBX_USER_TOKEN': JSON.stringify(process.env.HBX_USER_TOKEN || '')
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
VUE_APP_PLATFORM: JSON.stringify(process.env.UNI_PLATFORM),
UNI_CLOUD_PROVIDER: process.env.UNI_CLOUD_PROVIDER,
HBX_USER_TOKEN: JSON.stringify(process.env.HBX_USER_TOKEN || '')
}
}),
new webpack.BannerPlugin({
......@@ -227,7 +227,7 @@ module.exports = function () {
return process.UNI_NVUE_ENTRY
},
externals: {
'vue': 'Vue'
vue: 'Vue'
},
performance: {
hints: false
......
......@@ -67,9 +67,9 @@ module.exports = (api, options) => {
__PLATFORM__: JSON.stringify(process.env.UNI_PLATFORM)
}),
new webpack.ProvidePlugin({
'console': [path.join(src, 'core/helpers/console'), 'default'],
'UniViewJSBridge': [path.join(src, 'core/view/bridge/index')],
'UniServiceJSBridge': [path.join(src, 'core/service/bridge/index')]
console: [path.join(src, 'core/helpers/console'), 'default'],
UniViewJSBridge: [path.join(src, 'core/view/bridge/index')],
UniServiceJSBridge: [path.join(src, 'core/service/bridge/index')]
})
]
}
......
......@@ -23,8 +23,8 @@ module.exports = (api, options) => {
description: 'build for production',
usage: 'vue-cli-service uni-build [options]',
options: {
'--watch': `watch for changes`,
'--minimize': `Tell webpack to minimize the bundle using the TerserPlugin.`
'--watch': 'watch for changes',
'--minimize': 'Tell webpack to minimize the bundle using the TerserPlugin.'
}
}, async (args) => {
for (const key in defaults) {
......@@ -83,8 +83,8 @@ function getWebpackConfigs (api, args, options) {
}
options.publicPath = '/'
const serviceWebpackConfig = getWebpackConfig(api, args, options)
delete pluginOptions['uni-app-plus']['service']
pluginOptions['uni-app-plus']['view'] = true
delete pluginOptions['uni-app-plus'].service
pluginOptions['uni-app-plus'].view = true
options.publicPath = './'
const viewWebpackConfig = getWebpackConfig(api, args, options)
return [serviceWebpackConfig, viewWebpackConfig]
......@@ -147,7 +147,7 @@ async function build (args, api, options) {
if (stats.hasErrors()) {
/* eslint-disable prefer-promise-reject-errors */
return reject(`Build failed with errors.`)
return reject('Build failed with errors.')
}
if (!args.silent && process.env.UNI_PLATFORM !== 'app-plus') {
......
console.log('uni-app v' + require('@dcloudio/webpack-uni-pages-loader/package.json')['uni-app']['compilerVersion'])
console.log('uni-app v' + require('@dcloudio/webpack-uni-pages-loader/package.json')['uni-app'].compilerVersion)
console.log('uni-app cli v' + require('../package.json').version)
console.log(require('chalk').bold('\nEnvironment Info:'))
require('envinfo').run({
......
......@@ -15,13 +15,13 @@ module.exports = (api, options) => {
description: 'start development server',
usage: 'vue-cli-service uni-serve [options] [entry]',
options: {
'--open': `open browser on server start`,
'--copy': `copy url to clipboard on server start`,
'--mode': `specify env mode (default: development)`,
'--open': 'open browser on server start',
'--copy': 'copy url to clipboard on server start',
'--mode': 'specify env mode (default: development)',
'--host': `specify host (default: ${defaults.host})`,
'--port': `specify port (default: ${defaults.port})`,
'--https': `use https (default: ${defaults.https})`,
'--public': `specify the public network URL for the HMR client`
'--public': 'specify the public network URL for the HMR client'
}
}, async function serve (args) {
info('Starting development server...')
......@@ -106,9 +106,9 @@ module.exports = (api, options) => {
: isInContainer
// can't infer public netowrk url if inside a container...
// use client-side inference (note this would break with non-root publicPath)
? ``
? ''
// otherwise infer the url
: `?` + url.format({
: '?' + url.format({
protocol,
port,
hostname: urls.lanUrlForConfig || 'localhost',
......@@ -116,7 +116,7 @@ module.exports = (api, options) => {
})
const devClients = [
// dev server client
require.resolve(`webpack-dev-server/client`) + sockjsUrl,
require.resolve('webpack-dev-server/client') + sockjsUrl,
// hmr client
require.resolve(projectDevServerOptions.hotOnly
? 'webpack/hot/only-dev-server'
......@@ -125,7 +125,7 @@ module.exports = (api, options) => {
// `@vue/cli-overlay/dist/client`
]
if (process.env.APPVEYOR) {
devClients.push(`webpack/hot/poll?500`)
devClients.push('webpack/hot/poll?500')
}
// inject dev/hot client
addDevClientToEntry(webpackConfig, devClients)
......@@ -162,8 +162,8 @@ module.exports = (api, options) => {
// launch editor support.
// this works with vue-devtools & @vue/cli-overlay
app.use('/__open-in-editor', launchEditorMiddleware(() => console.log(
`To specify an editor, sepcify the EDITOR env variable or ` +
`add "editor" field to your Vue project config.\n`
'To specify an editor, sepcify the EDITOR env variable or ' +
'add "editor" field to your Vue project config.\n'
)))
// allow other plugins to register middlewares, e.g. PWA
api.service.devServerConfigFns.forEach(fn => fn(app, server))
......@@ -217,30 +217,30 @@ module.exports = (api, options) => {
: urls.lanUrlForTerminal
const printRunningAt = !runByHBuilderX || (runByHBuilderX && isFirstCompile)
printRunningAt && console.log()
printRunningAt && console.log(` App running at:`)
printRunningAt && console.log(' App running at:')
printRunningAt && console.log(
` - Local: ${chalk.cyan(urls.localUrlForTerminal)} ${copied}`
)
if (!printRunningAt) {
console.log(`Build complete. Watching for changes...`)
console.log('Build complete. Watching for changes...')
}
if (!isInContainer) {
printRunningAt && console.log(` - Network: ${chalk.cyan(networkUrl)}`)
} else {
console.log()
console.log(chalk.yellow(
` It seems you are running Vue CLI inside a container.`
' It seems you are running Vue CLI inside a container.'
))
if (!publicUrl && options.publicPath && options.publicPath !== '/') {
console.log()
console.log(chalk.yellow(
` Since you are using a non-root publicPath, the hot-reload socket`
' Since you are using a non-root publicPath, the hot-reload socket'
))
console.log(chalk.yellow(
` will not be able to infer the correct URL to connect. You should`
' will not be able to infer the correct URL to connect. You should'
))
console.log(chalk.yellow(
` explicitly specify the URL via ${chalk.blue(`devServer.public`)}.`
` explicitly specify the URL via ${chalk.blue('devServer.public')}.`
))
console.log()
}
......@@ -258,15 +258,15 @@ module.exports = (api, options) => {
if (!isProduction) {
if (process.UNI_CLOUD) {
console.warn(
`当前项目使用了uniCloud,为避免云函数调用跨域问题,建议在HBuilderX内置浏览器里调试,如使用外部浏览器需处理跨域,详见:https://uniapp.dcloud.io/uniCloud/quickstart?id=useinh5`
'当前项目使用了uniCloud,为避免云函数调用跨域问题,建议在HBuilderX内置浏览器里调试,如使用外部浏览器需处理跨域,详见:https://uniapp.dcloud.io/uniCloud/quickstart?id=useinh5'
)
}
// const buildCommand = hasProjectYarn(api.getCwd()) ? `yarn build` : `npm run build`
// console.log(` Note that the development build is not optimized.`)
// console.log(` To create a production build, run ${chalk.cyan(buildCommand)}.`)
} else {
console.log(` App is served in production mode.`)
console.log(` Note this is for preview or E2E testing only.`)
console.log(' App is served in production mode.')
console.log(' Note this is for preview or E2E testing only.')
}
console.log()
......@@ -331,8 +331,8 @@ function addDevClientToEntry (config, devClient) {
// https://stackoverflow.com/a/20012536
function checkInContainer () {
const fs = require('fs')
if (fs.existsSync(`/proc/1/cgroup`)) {
const content = fs.readFileSync(`/proc/1/cgroup`, 'utf-8')
if (fs.existsSync('/proc/1/cgroup')) {
const content = fs.readFileSync('/proc/1/cgroup', 'utf-8')
return /:\/(lxc|docker|kubepods)\//.test(content)
}
}
......
......@@ -6,9 +6,9 @@ module.exports = (api, options, rootOptions) => {
delete pkg.browserslist
return {
scripts: {
'info': 'node node_modules/@dcloudio/vue-cli-plugin-uni/commands/info.js',
'serve': 'npm run dev:h5',
'build': 'npm run build:h5',
info: 'node node_modules/@dcloudio/vue-cli-plugin-uni/commands/info.js',
serve: 'npm run dev:h5',
build: 'npm run build:h5',
'serve:quickapp-vue': 'node node_modules/@dcloudio/uni-quickapp-vue/bin/serve.js',
'dev:h5': 'cross-env NODE_ENV=development UNI_PLATFORM=h5 vue-cli-service uni-serve',
'dev:mp-qq': 'cross-env NODE_ENV=development UNI_PLATFORM=mp-qq vue-cli-service uni-build --watch',
......@@ -30,7 +30,7 @@ module.exports = (api, options, rootOptions) => {
'build:custom': 'cross-env NODE_ENV=production uniapp-cli custom'
},
'uni-app': {
'scripts': {}
scripts: {}
},
dependencies: {
'@dcloudio/uni-app-plus': version,
......@@ -43,8 +43,8 @@ module.exports = (api, options, rootOptions) => {
'@dcloudio/uni-quickapp-light': version,
'@dcloudio/uni-quickapp-vue': version,
'@dcloudio/uni-stat': version,
'flyio': '^0.6.2',
'vuex': '^3.0.1'
flyio: '^0.6.2',
vuex: '^3.0.1'
},
devDependencies: {
'@dcloudio/uni-cli-shared': version,
......
......@@ -29,24 +29,24 @@ const cryptoPath = path.resolve(__dirname, '../crypto.js')
function getProvides (isAppService) {
if (isAppService) {
return { // app-service
'__f__': [path.resolve(__dirname, '../format-log.js'), 'default'],
'wx': [runtimePath, 'default'],
__f__: [path.resolve(__dirname, '../format-log.js'), 'default'],
wx: [runtimePath, 'default'],
'wx.nextTick': [runtimePath, 'nextTick'],
'Page': [runtimePath, 'Page'],
'Component': [runtimePath, 'Component'],
'Behavior': [runtimePath, 'Behavior'],
'getDate': [wxsPath, 'getDate'],
'getRegExp': [wxsPath, 'getRegExp'],
'uniCloud': [uniCloudPath, 'default'],
'crypto': [cryptoPath, 'default'],
Page: [runtimePath, 'Page'],
Component: [runtimePath, 'Component'],
Behavior: [runtimePath, 'Behavior'],
getDate: [wxsPath, 'getDate'],
getRegExp: [wxsPath, 'getRegExp'],
uniCloud: [uniCloudPath, 'default'],
crypto: [cryptoPath, 'default'],
'window.crypto': [cryptoPath, 'default'],
'global.crypto': [cryptoPath, 'default']
}
}
return { // app-view
'__f__': [path.resolve(__dirname, '../format-log.js'), 'default'],
'getDate': [wxsPath, 'getDate'],
'getRegExp': [wxsPath, 'getRegExp']
__f__: [path.resolve(__dirname, '../format-log.js'), 'default'],
getDate: [wxsPath, 'getDate'],
getRegExp: [wxsPath, 'getRegExp']
}
}
......@@ -55,12 +55,12 @@ const v3 = {
parallel: false
},
webpackConfig (webpackConfig, vueOptions, api) {
const isAppService = !!vueOptions.pluginOptions['uni-app-plus']['service']
const isAppView = !!vueOptions.pluginOptions['uni-app-plus']['view']
const isAppService = !!vueOptions.pluginOptions['uni-app-plus'].service
const isAppView = !!vueOptions.pluginOptions['uni-app-plus'].view
const statCode = process.env.UNI_USING_STAT ? `import '@dcloudio/uni-stat';` : ''
const statCode = process.env.UNI_USING_STAT ? 'import \'@dcloudio/uni-stat\';' : ''
const beforeCode = `import 'uni-pages';`
const beforeCode = 'import \'uni-pages\';'
if (!webpackConfig.optimization) {
webpackConfig.optimization = {}
......@@ -186,8 +186,8 @@ const v3 = {
chainWebpack (webpackConfig, vueOptions, api) {
webpackConfig.entryPoints.delete('app')
const isAppService = !!vueOptions.pluginOptions['uni-app-plus']['service']
const isAppView = !!vueOptions.pluginOptions['uni-app-plus']['view']
const isAppService = !!vueOptions.pluginOptions['uni-app-plus'].service
const isAppView = !!vueOptions.pluginOptions['uni-app-plus'].view
const cacheConfig = {
cacheDirectory: false,
......
......@@ -16,7 +16,7 @@ function write (key, data, callback) {
data.remainingRequest.indexOf('vue&type=template') !== -1 &&
process.UNI_CACHE_TEMPLATES
) {
data['mpTemplates'] = process.UNI_CACHE_TEMPLATES
data.mpTemplates = process.UNI_CACHE_TEMPLATES
delete process.UNI_CACHE_TEMPLATES
}
......@@ -48,7 +48,7 @@ function read (key, callback) {
try {
const data = BJSON.parse(content)
const mpTemplates = data['mpTemplates']
const mpTemplates = data.mpTemplates
if (mpTemplates) {
Object.keys(mpTemplates).forEach(name => {
fs.writeFileSync(name, mpTemplates[name], 'utf-8')
......
......@@ -32,10 +32,10 @@ module.exports = function chainWebpack (platformOptions, vueOptions, api) {
// 条件编译 vue 文件统一直接过滤html,js,css三种类型,单独资源文件引用各自过滤
const loaders = {
'scss': 'sass-loader',
'sass': 'sass-loader',
'less': 'less-loader',
'stylus': 'stylus-loader'
scss: 'sass-loader',
sass: 'sass-loader',
less: 'less-loader',
stylus: 'stylus-loader'
}
// 独立css,postcss,scss,sass,less,stylus
const cssLang = ['css', 'postcss', 'scss', 'sass', 'less', 'stylus']
......@@ -48,7 +48,7 @@ module.exports = function chainWebpack (platformOptions, vueOptions, api) {
cssTypes.forEach(type => {
if (process.env.UNI_USING_CACHE) {
langRule.oneOf(type)
.use(`uniapp-cache-css`)
.use('uniapp-cache-css')
.loader('cache-loader')
.options(api.genCacheConfig(
'css-loader/' + process.env.UNI_PLATFORM,
......@@ -57,14 +57,14 @@ module.exports = function chainWebpack (platformOptions, vueOptions, api) {
.before('css-loader')
}
langRule.oneOf(type)
.use(`uniapp-preprocss`)
.use('uniapp-preprocss')
.loader(resolve('packages/webpack-preprocess-loader'))
.options(cssPreprocessOptions)
.after('css-loader') // 在 css-loader 之前条件编译一次
if (loader) { // 在 scss,less,stylus 之前先条件编译一次(似乎没有必要了,保证css-loader处理一次即可,前提是条件编译注释都还存在)
langRule.oneOf(type)
.use(`uniapp-preprocss-` + lang)
.use('uniapp-preprocss-' + lang)
.loader(resolve('packages/webpack-preprocess-loader'))
.options(cssPreprocessOptions)
.after(loader)
......
......@@ -9,7 +9,7 @@ const {
module.exports = function custom (argv) {
const script = argv._[1]
if (!script) {
console.error(`请指定 package.json->uni-app->scripts 下的 script 名称`)
console.error('请指定 package.json->uni-app->scripts 下的 script 名称')
process.exit(0)
}
......
......@@ -4,18 +4,18 @@ const path = require('path')
module.exports = async function add (argv) {
const pluginName = argv._[1]
if (!pluginName) {
console.error(`请指定插件名称`)
console.error('请指定插件名称')
process.exit(0)
}
const pluginPkg = require(pluginName + '/package.json')
const options = pluginPkg['uni-app']
if (!options) {
console.error(`插件不合法`)
console.error('插件不合法')
process.exit(0)
}
const name = options.name
if (!name) {
console.error(`插件名称不存在`)
console.error('插件名称不存在')
process.exit(0)
}
const scripts = options.scripts || {
......
......@@ -84,10 +84,10 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
'@/*': [
path.join(process.env.UNI_INPUT_DIR, '*')
],
'vue': [
vue: [
resolveModule('vue')
],
'vuex': [
vuex: [
resolveModule('vuex')
],
'vue-class-component': [
......@@ -96,7 +96,7 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
'vue-property-decorator': [
resolveModule('vue-property-decorator')
],
'tslib': [
tslib: [
resolveModule('tslib')
],
'mpvue-page-factory': [
......@@ -109,7 +109,7 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
const filePath = path.relative(process.env.UNI_INPUT_DIR, error.file).replace('.vue.ts', '.vue')
if (error.code === 2307 && error.content.includes('.vue')) {
error.content = error.content.replace('Cannot find module ', '') +
` script 节点必须使用 lang="ts",文档参考地址:https://uniapp.dcloud.io/frame?id=vue-ts`
' script 节点必须使用 lang="ts",文档参考地址:https://uniapp.dcloud.io/frame?id=vue-ts'
}
return messageColor(
`[tsl] ERROR at ${filePath}:${error.line}
......@@ -192,7 +192,7 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
const isAppView = process.env.UNI_PLATFORM === 'app-plus' &&
vueOptions.pluginOptions &&
vueOptions.pluginOptions['uni-app-plus'] &&
vueOptions.pluginOptions['uni-app-plus']['view']
vueOptions.pluginOptions['uni-app-plus'].view
if (!isAppView) { // app-plus view不需要copy
plugins.push(new CopyWebpackPlugin(getCopyWebpackPluginOptions(manifestPlatformOptions, vueOptions)))
......@@ -250,7 +250,7 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
alias: {
'@': path.resolve(process.env.UNI_INPUT_DIR),
'./@': path.resolve(process.env.UNI_INPUT_DIR), // css中的'@/static/logo.png'会被转换成'./@/static/logo.png'加载
'vue$': getPlatformVue(vueOptions),
vue$: getPlatformVue(vueOptions),
'uni-pages': path.resolve(process.env.UNI_INPUT_DIR, 'pages.json'),
'@dcloudio/uni-stat': require.resolve('@dcloudio/uni-stat'),
'uni-stat-config': path.resolve(process.env.UNI_INPUT_DIR, 'pages.json') +
......
......@@ -68,7 +68,7 @@ if (
process.env.UNI_PLATFORM === 'h5' &&
process.env.NODE_ENV === 'production'
) {
console.warn(`发布H5,需要在uniCloud后台操作,绑定安全域名,否则会因为跨域问题而无法访问。教程参考:https://uniapp.dcloud.io/uniCloud/quickstart-H5`)
console.warn('发布H5,需要在uniCloud后台操作,绑定安全域名,否则会因为跨域问题而无法访问。教程参考:https://uniapp.dcloud.io/uniCloud/quickstart-H5')
}
// 初始化环境变量
......@@ -225,7 +225,7 @@ if (process.env.UNI_PLATFORM === 'app-plus') {
} else { // 其他平台,待确认配置方案
if (
manifestJsonObj['app-plus'] &&
manifestJsonObj['app-plus']['nvueCompiler'] === 'weex'
manifestJsonObj['app-plus'].nvueCompiler === 'weex'
) {
isNVueCompiler = false
}
......@@ -257,7 +257,7 @@ if (
process.env.UNI_USING_STAT = true
if (!process.UNI_STAT_CONFIG.appid && process.env.NODE_ENV === 'production') {
console.log()
console.warn(`当前应用未配置Appid,无法使用uni统计,详情参考:https://ask.dcloud.net.cn/article/36303`)
console.warn('当前应用未配置Appid,无法使用uni统计,详情参考:https://ask.dcloud.net.cn/article/36303')
console.log()
}
}
......@@ -277,8 +277,8 @@ if (process.env.UNI_USING_COMPONENTS) { // 是否启用分包优化
const warningMsg =
usingComponentsAbsent
? `该应用之前可能是非自定义组件模式,目前以自定义组件模式运行。非自定义组件已于2019年11月1日起停止支持。详见:https://ask.dcloud.net.cn/article/36385`
: `uni-app已于2019年11月1日起停止支持非自定义组件模式 [详情](https://ask.dcloud.net.cn/article/36385)`
? '该应用之前可能是非自定义组件模式,目前以自定义组件模式运行。非自定义组件已于2019年11月1日起停止支持。详见:https://ask.dcloud.net.cn/article/36385'
: 'uni-app已于2019年11月1日起停止支持非自定义组件模式 [详情](https://ask.dcloud.net.cn/article/36385)'
const needWarning = !platformOptions.usingComponents || usingComponentsAbsent
let hasNVue = false
......@@ -293,8 +293,8 @@ if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) {
if (process.env.UNI_PLATFORM === 'app-plus') {
const pagesPkg = require('@dcloudio/webpack-uni-pages-loader/package.json')
if (pagesPkg) {
const v3Tips = `(v3)详见:https://ask.dcloud.net.cn/article/36599。`
info = '编译器版本:' + pagesPkg['uni-app']['compilerVersion'] + (process.env.UNI_USING_V3 ? v3Tips : '')
const v3Tips = '(v3)详见:https://ask.dcloud.net.cn/article/36599。'
info = '编译器版本:' + pagesPkg['uni-app'].compilerVersion + (process.env.UNI_USING_V3 ? v3Tips : '')
}
if (process.env.UNI_USING_V3) {
console.log(info)
......@@ -325,11 +325,11 @@ if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) {
} catch (e) {}
}
if (process.env.NODE_ENV !== 'production') { // 运行模式性能提示
let perfMsg = `请注意运行模式下,因日志输出、sourcemap以及未压缩源码等原因,性能和包体积,均不及发行模式。`
let perfMsg = '请注意运行模式下,因日志输出、sourcemap以及未压缩源码等原因,性能和包体积,均不及发行模式。'
if (hasNVue) { // app-nvue
perfMsg = perfMsg + `尤其是app-nvue的sourcemap影响较大`
perfMsg = perfMsg + '尤其是app-nvue的sourcemap影响较大'
} else if (process.env.UNI_PLATFORM.indexOf('mp-') === 0) { // 小程序
perfMsg = perfMsg + `若要正式发布,请点击发行菜单或使用cli发布命令进行发布`
perfMsg = perfMsg + '若要正式发布,请点击发行菜单或使用cli发布命令进行发布'
}
console.log(perfMsg)
}
......@@ -408,7 +408,7 @@ global.uniPlugin.configureEnv.forEach(configureEnv => {
configureEnv()
})
runByHBuilderX && console.log(`正在编译中...`)
runByHBuilderX && console.log('正在编译中...')
module.exports = {
manifestPlatformOptions: platformOptions
......
......@@ -22,7 +22,7 @@ export default function formatLog () {
var type = args.shift()
if (isDebugMode()) {
args.push(args.pop().replace('at ', 'uni-app:///'))
return console[type]['apply'](console, args)
return console[type].apply(console, args)
}
var msgs = args.map(function (v) {
......
......@@ -74,7 +74,8 @@ function parseFilters (exp) {
break // }
}
if (c === 0x2f) { // /
var j = i - 1
var j = i - 1
/* eslint-disable no-void */
var p = (void 0)
// find first non-whitespace prev char
for (; j >= 0; j--) {
......
......@@ -28,8 +28,8 @@ function hasOwn (obj, key) {
const deprecated = {
events: {
'tap': 'click',
'longtap': 'longpress'
tap: 'click',
longtap: 'longpress'
}
}
......
......@@ -34,14 +34,14 @@ const uniCloudPath = path.resolve(__dirname, '../../packages/uni-cloud/dist/inde
function getProvides () {
return {
'__f__': [path.resolve(__dirname, '../format-log.js'), 'log'],
'uniCloud': [uniCloudPath, 'default'],
__f__: [path.resolve(__dirname, '../format-log.js'), 'log'],
uniCloud: [uniCloudPath, 'default'],
'wx.nextTick': [runtimePath, 'nextTick'],
'Page': [runtimePath, 'Page'],
'Component': [runtimePath, 'Component'],
'Behavior': [runtimePath, 'Behavior'],
'getDate': [wxsPath, 'getDate'],
'getRegExp': [wxsPath, 'getRegExp']
Page: [runtimePath, 'Page'],
Component: [runtimePath, 'Component'],
Behavior: [runtimePath, 'Behavior'],
getDate: [wxsPath, 'getDate'],
getRegExp: [wxsPath, 'getRegExp']
}
}
......@@ -91,14 +91,14 @@ module.exports = {
webpackConfig (webpackConfig) {
let useBuiltIns = 'usage'
const statCode = process.env.UNI_USING_STAT ? `import '@dcloudio/uni-stat';` : ''
const statCode = process.env.UNI_USING_STAT ? 'import \'@dcloudio/uni-stat\';' : ''
try {
const babelConfig = require(path.resolve(process.env.UNI_CLI_CONTEXT, 'babel.config.js'))
useBuiltIns = babelConfig.presets[0][1].useBuiltIns
} catch (e) {}
const beforeCode = (useBuiltIns === 'entry' ? `import '@babel/polyfill';` : '') +
const beforeCode = (useBuiltIns === 'entry' ? 'import \'@babel/polyfill\';' : '') +
`import 'uni-pages';import 'uni-${process.env.UNI_PLATFORM}';`
return {
......@@ -125,7 +125,7 @@ module.exports = {
use: {
loader: path.resolve(__dirname, '../../packages/wrap-loader'),
options: {
before: [`<template><App :keepAliveInclude="keepAliveInclude"/></template>`]
before: ['<template><App :keepAliveInclude="keepAliveInclude"/></template>']
}
}
}, { // 解析组件,css 等
......
......@@ -25,24 +25,24 @@ function getProvides () {
const uniPath = require.resolve('@dcloudio/uni-' + process.env.UNI_PLATFORM)
const uniCloudPath = path.resolve(__dirname, '../../packages/uni-cloud/dist/index.js')
const provides = {
'uni': [uniPath, 'default'],
'uniCloud': [uniCloudPath, 'default']
uni: [uniPath, 'default'],
uniCloud: [uniCloudPath, 'default']
}
if (process.env.UNI_USING_COMPONENTS) {
provides['createApp'] = [uniPath, 'createApp']
provides['createPage'] = [uniPath, 'createPage']
provides['createComponent'] = [uniPath, 'createComponent']
provides.createApp = [uniPath, 'createApp']
provides.createPage = [uniPath, 'createPage']
provides.createComponent = [uniPath, 'createComponent']
}
if (
process.env.UNI_PLATFORM === 'app-plus' &&
process.env.UNI_USING_V8
) {
provides['__f__'] = [path.resolve(__dirname, '../format-log.js'), 'default']
provides.__f__ = [path.resolve(__dirname, '../format-log.js'), 'default']
const cryptoProvide = [path.resolve(__dirname, '../crypto.js'), 'default']
provides['crypto'] = cryptoProvide
provides.crypto = cryptoProvide
provides['window.crypto'] = cryptoProvide
provides['global.crypto'] = cryptoProvide
}
......@@ -53,7 +53,7 @@ function getProvides () {
process.env.UNI_PLATFORM !== 'mp-weixin' &&
process.env.UNI_PLATFORM !== 'app-plus'
) { // 非微信小程序,自动注入 wx 对象
provides['wx'] = provides['uni']
provides.wx = provides.uni
}
return provides
}
......@@ -77,9 +77,9 @@ module.exports = {
parseEntry()
const statCode = process.env.UNI_USING_STAT ? `import '@dcloudio/uni-stat';` : ''
const statCode = process.env.UNI_USING_STAT ? 'import \'@dcloudio/uni-stat\';' : ''
const beforeCode = `import 'uni-pages';`
const beforeCode = 'import \'uni-pages\';'
return {
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
......
......@@ -67,7 +67,7 @@ module.exports = function initOptions (options) {
let sassData = isSass ? getPlatformSass() : getPlatformScss()
if (isSass) {
sassData = `@import "@/uni.sass"`
sassData = '@import "@/uni.sass"'
} else if (isScss) {
sassData = `${sassData}
@import "@/uni.scss";`
......@@ -88,7 +88,7 @@ module.exports = function initOptions (options) {
options.css.loaderOptions.sass.prependData = sassData
}
let userPostcssConfigPath = path.resolve(process.env.UNI_INPUT_DIR, 'postcss.config.js')
const userPostcssConfigPath = path.resolve(process.env.UNI_INPUT_DIR, 'postcss.config.js')
if (fs.existsSync(userPostcssConfigPath)) {
options.css.loaderOptions.postcss.config.path = userPostcssConfigPath
} else {
......
......@@ -3,7 +3,7 @@ module.exports = {
getPartialIdentifier () {
if (!partialIdentifier) {
partialIdentifier = {
'UNI_COMPILER_VERSION': require('../package.json').version
UNI_COMPILER_VERSION: require('../package.json').version
}
Object.keys(process.env).forEach(name => {
if (name.indexOf('UNI_') === 0) {
......
......@@ -38,7 +38,7 @@ module.exports = api => {
default: '/',
value: h5.router && h5.router.base,
message: 'Base Url',
description: `应用的部署地址,如 '/my-app/'。如果留空,所有资源将使用相对路径。`,
description: '应用的部署地址,如 \'/my-app/\'。如果留空,所有资源将使用相对路径。',
group: '基础设置',
link: 'https://uniapp.dcloud.io/collocation/manifest?id=h5'
}, {
......@@ -64,7 +64,7 @@ module.exports = api => {
name: 'loading',
type: 'input',
default: 'AsyncLoading',
value: h5['async'] && h5['async'].loading,
value: h5.async && h5.async.loading,
message: '加载组件',
description: '页面按需加载时显示的组件(需注册为全局组件)',
group: '页面按需加载配置',
......@@ -74,7 +74,7 @@ module.exports = api => {
name: 'error',
type: 'input',
default: 'AsyncError',
value: h5['async'] && h5['async'].error,
value: h5.async && h5.async.error,
message: '错误组件',
description: '页面按需加载失败时显示的组件(需注册为全局组件)',
group: '页面按需加载配置',
......@@ -84,7 +84,7 @@ module.exports = api => {
name: 'delay',
type: 'input',
default: 200,
value: h5['async'] && h5['async'].delay,
value: h5.async && h5.async.delay,
message: '延迟时间',
description: '页面按需加载展示 loading 组件的延迟时间(页面 js 若在 delay 时间内加载完成,则不会显示 loading 组件)',
group: '页面按需加载配置',
......@@ -94,7 +94,7 @@ module.exports = api => {
name: 'timeout',
type: 'input',
default: 3000,
value: h5['async'] && h5['async'].timeout,
value: h5.async && h5.async.timeout,
message: '超时时间',
description: '页面按需加载超时时间(超时后展示 error 对应的组件)',
group: '页面按需加载配置',
......@@ -132,18 +132,18 @@ module.exports = api => {
const delay = await api.getAnswer('delay')
const timeout = await api.getAnswer('timeout')
if (isDef(loading) || isDef(error) || isDef(delay) || isDef(timeout)) {
h5['async'] = {}
h5.async = {}
if (isDef(loading)) {
h5['async'].loading = loading
h5.async.loading = loading
}
if (isDef(error)) {
h5['async'].error = error
h5.async.error = error
}
if (isDef(delay)) {
h5['async'].delay = delay
h5.async.delay = delay
}
if (isDef(timeout)) {
h5['async'].timeout = timeout
h5.async.timeout = timeout
}
}
......
......@@ -36,13 +36,13 @@ export default {
}
`,
[{
'name': 'mediaList',
'value': 'mediaList',
'source': '@/components/tab-nvue/mediaList.vue'
name: 'mediaList',
value: 'mediaList',
source: '@/components/tab-nvue/mediaList.vue'
}, {
'name': 'uniLoadMore',
'value': 'uniLoadMore',
'source': '@/components/uni-load-more.vue'
name: 'uniLoadMore',
value: 'uniLoadMore',
source: '@/components/uni-load-more.vue'
}])
assertCodegen(
......@@ -56,13 +56,13 @@ export default {
}
`,
[{
'name': 'uni-badge',
'value': 'uniBadge',
'source': '@dcloudio/uni-ui/lib/uni-badge/uni-badge'
name: 'uni-badge',
value: 'uniBadge',
source: '@dcloudio/uni-ui/lib/uni-badge/uni-badge'
}, {
'name': 'uni-card',
'value': 'uniCard',
'source': '@dcloudio/uni-ui/lib/uni-card/uni-card'
name: 'uni-card',
value: 'uniCard',
source: '@dcloudio/uni-ui/lib/uni-card/uni-card'
}])
assertCodegen(
......@@ -134,17 +134,17 @@ global['__wxVueOptions'] = {
Vue.component('media-list',mediaList)
`,
[{
'name': 'uni-badge',
'value': 'uniBadge',
'source': '@dcloudio/uni-ui/lib/uni-badge/uni-badge'
name: 'uni-badge',
value: 'uniBadge',
source: '@dcloudio/uni-ui/lib/uni-badge/uni-badge'
}, {
'name': 'uni-card',
'value': 'uniCard',
'source': '@dcloudio/uni-ui/lib/uni-card/uni-card'
name: 'uni-card',
value: 'uniCard',
source: '@dcloudio/uni-ui/lib/uni-card/uni-card'
}, {
'name': 'media-list',
'value': 'mediaList',
'source': '@/components/tab-nvue/mediaList.vue'
name: 'media-list',
value: 'mediaList',
source: '@/components/tab-nvue/mediaList.vue'
}], false)
})
})
......@@ -23,7 +23,7 @@ const babelTemplate = require('@babel/template').default
// }
// var test = function(resolve) {require.ensure([], () => resolve(require('../../components/test')),'components/test')}
const buildRequireEnsure = babelTemplate(
`var IMPORT_NAME = function(){require.ensure([],()=>resolve(require(IMPORT_SOURCE)),CHUNK_NAME)}`
'var IMPORT_NAME = function(){require.ensure([],()=>resolve(require(IMPORT_SOURCE)),CHUNK_NAME)}'
)
function getRequireEnsure (name, source, chunkName) {
......
......@@ -51,7 +51,7 @@ function parseComponents (names, bindings, path) {
})
const importDeclarations = dynamicImportMap.keys()
for (let importDeclaration of importDeclarations) {
for (const importDeclaration of importDeclarations) {
const dynamicImportArray = dynamicImportMap.get(importDeclaration)
dynamicImportArray.forEach((dynamicImport) => {
components.push(dynamicImport)
......
......@@ -56,7 +56,7 @@ module.exports = function (content) {
plugins.push([
'@babel/plugin-proposal-decorators',
{
'legacy': true
legacy: true
}
])
}
......
......@@ -76,7 +76,7 @@ module.exports = function generateComponent (compilation) {
}
const origSource = assets[name].source()
if (origSource.length !== `Component({})`.length) { // 不是空组件
if (origSource.length !== 'Component({})'.length) { // 不是空组件
const globalVar = process.env.UNI_PLATFORM === 'mp-alipay' ? 'my' : 'global'
// 主要是为了解决支付宝旧版本, Component 方法只在组件 js 里有,需要挂在 my.defineComponent
let beforeCode = ''
......
......@@ -11,7 +11,7 @@ const {
} = require('@dcloudio/uni-cli-shared/lib/cache')
// 主要解决 extends 且未实际引用的组件
const EMPTY_COMPONENT = `Component({})`
const EMPTY_COMPONENT = 'Component({})'
const usingComponentsMap = {}
......@@ -23,7 +23,7 @@ function analyzeUsingComponents () {
const jsonFileMap = getJsonFileMap()
// 生成所有组件引用关系
for (let name of jsonFileMap.keys()) {
for (const name of jsonFileMap.keys()) {
const jsonObj = JSON.parse(jsonFileMap.get(name))
const usingComponents = jsonObj.usingComponents
if (!usingComponents || !pageSet.has(name)) {
......@@ -89,7 +89,7 @@ module.exports = function generateJson (compilation) {
analyzeUsingComponents()
const jsonFileMap = getChangedJsonFileMap()
for (let name of jsonFileMap.keys()) {
for (const name of jsonFileMap.keys()) {
const jsonObj = JSON.parse(jsonFileMap.get(name))
if (process.env.UNI_PLATFORM === 'app-plus') { // App平台默认增加usingComponents,激活__wxAppCode__
jsonObj.usingComponents = jsonObj.usingComponents || {}
......
......@@ -30,7 +30,7 @@ module.exports = function (content, map) {
plugins.push([
'@babel/plugin-proposal-decorators',
{
'legacy': true
legacy: true
}
])
}
......
......@@ -21,7 +21,7 @@ module.exports = function (content) {
if (path.extname(this.resourcePath) !== '.nvue') {
return content
}
let resourcePath = normalizeNodeModules(
const resourcePath = normalizeNodeModules(
removeExt(
normalizePath(path.relative(process.env.UNI_INPUT_DIR, this.resourcePath))
)
......
......@@ -9,6 +9,7 @@ const {
} = require('@dcloudio/uni-cli-shared')
const {
hasOwn,
parseStyle
} = require('../../util')
......@@ -104,7 +105,7 @@ module.exports = function (pagesJson, userManifestJson) {
const {
navigationBarTextStyle = 'white',
navigationBarBackgroundColor = '#000000'
} = appJson['window'] || {}
} = appJson.window || {}
const TABBAR_HEIGHT = 50
......@@ -132,10 +133,9 @@ module.exports = function (pagesJson, userManifestJson) {
}
)
const splashscreenOptions = userManifestJson['app-plus'] && userManifestJson['app-plus']['splashscreen']
const splashscreenOptions = userManifestJson['app-plus'] && userManifestJson['app-plus'].splashscreen
const hasAlwaysShowBeforeRender = splashscreenOptions && splashscreenOptions.hasOwnProperty(
'alwaysShowBeforeRender')
const hasAlwaysShowBeforeRender = splashscreenOptions && hasOwn(splashscreenOptions, 'alwaysShowBeforeRender')
// 转换为老版本配置
if (manifestJson.plus.modules) {
......@@ -189,8 +189,8 @@ module.exports = function (pagesJson, userManifestJson) {
style
}) => {
pages[path] = {
'window': parseStyle(style),
'nvue': true
window: parseStyle(style),
nvue: true
}
})
......@@ -203,12 +203,12 @@ module.exports = function (pagesJson, userManifestJson) {
}
// nvue 权限
manifestJson.permissions.UniNView = {
'description': 'UniNView原生渲染'
description: 'UniNView原生渲染'
}
} else if (process.env.UNI_USING_V8) {
// nvue 权限
manifestJson.permissions.UniNView = {
'description': 'UniNView原生渲染'
description: 'UniNView原生渲染'
}
}
......@@ -235,7 +235,7 @@ module.exports = function (pagesJson, userManifestJson) {
// "render": "always"
if (!manifestJson.plus.launchwebview) {
manifestJson.plus.launchwebview = {
'render': 'always'
render: 'always'
}
} else if (!manifestJson.plus.launchwebview.render) {
manifestJson.plus.launchwebview.render = 'always'
......
......@@ -75,7 +75,7 @@ module.exports = function (appJson, manifestJson, {
})
// nvue 权限
manifestJson.permissions.UniNView = {
'description': 'UniNView原生渲染'
description: 'UniNView原生渲染'
}
manifestJson.plus.launchwebview.id = '1' // 首页 id 固定 为 1
......
......@@ -2,6 +2,7 @@ const fs = require('fs')
const path = require('path')
const {
hasOwn,
getPlatforms,
getH5Options,
getFlexDirection,
......@@ -63,7 +64,7 @@ const getPageComponents = function (inputDir, pagesJson) {
Object.assign(
globalStyle,
globalStyle['app-plus'] || {},
globalStyle['h5'] || {}
globalStyle.h5 || {}
)
if (process.env.UNI_SUB_PLATFORM) {
......@@ -92,7 +93,7 @@ const getPageComponents = function (inputDir, pagesJson) {
}
}
// 解析 titleNView,pullToRefresh
const h5Options = Object.assign({}, props['app-plus'] || {}, props['h5'] || {})
const h5Options = Object.assign({}, props['app-plus'] || {}, props.h5 || {})
if (process.env.UNI_SUB_PLATFORM) {
Object.assign(h5Options, props[process.env.UNI_SUB_PLATFORM] || {})
......@@ -101,19 +102,19 @@ const getPageComponents = function (inputDir, pagesJson) {
removePlatformStyle(h5Options)
if (h5Options.hasOwnProperty('titleNView')) {
if (hasOwn(h5Options, 'titleNView')) {
props.titleNView = h5Options.titleNView
}
if (h5Options.hasOwnProperty('pullToRefresh')) {
if (hasOwn(h5Options, 'pullToRefresh')) {
props.pullToRefresh = h5Options.pullToRefresh
}
let windowTop = 44
const pageStyle = Object.assign({}, globalStyle, props)
const titleNViewTypeList = {
'none': 'default',
'auto': 'transparent',
'always': 'float'
none: 'default',
auto: 'transparent',
always: 'float'
}
let titleNView = pageStyle.titleNView
titleNView = Object.assign({}, {
......@@ -130,7 +131,7 @@ const getPageComponents = function (inputDir, pagesJson) {
// 删除 app-plus 平台配置
delete props['app-plus']
delete props['h5']
delete props.h5
if (process.env.UNI_SUB_PLATFORM) {
delete props[process.env.UNI_SUB_PLATFORM]
......@@ -355,9 +356,9 @@ import Vue from 'vue'
global['____${h5.appid}____'] = true;
delete global['____${h5.appid}____'];
global.__uniConfig = ${JSON.stringify(pagesJson)};
global.__uniConfig.router = ${JSON.stringify(h5.router)};
global.__uniConfig.router = ${JSON.stringify(h5.router)};
global.__uniConfig.publicPath = ${JSON.stringify(h5.publicPath)};
global.__uniConfig['async'] = ${JSON.stringify(h5['async'])};
global.__uniConfig['async'] = ${JSON.stringify(h5.async)};
global.__uniConfig.debug = ${manifestJson.debug === true};
global.__uniConfig.networkTimeout = ${JSON.stringify(networkTimeoutConfig)};
global.__uniConfig.sdkConfigs = ${JSON.stringify(sdkConfigs)};
......
......@@ -13,15 +13,15 @@ const {
} = require('../util')
const pagesJson2AppJson = {
'globalStyle': function (name, value, json) {
json['window'] = parseStyle(value)
if (json['window'].usingComponents) {
json['usingComponents'] = json['window'].usingComponents
delete json['window']['usingComponents']
globalStyle: function (name, value, json) {
json.window = parseStyle(value)
if (json.window.usingComponents) {
json.usingComponents = json.window.usingComponents
delete json.window.usingComponents
}
},
'tabBar': function (name, value, json) {
json['tabBar'] = parseTabBar(value)
tabBar: function (name, value, json) {
json.tabBar = parseTabBar(value)
}
}
......
......@@ -22,19 +22,19 @@ function defaultCopy (name, value, json) {
}
const pagesJson2AppJson = {
'globalStyle': function (name, value, json) {
json['window'] = parseStyle(value)
if (json['window'].usingComponents) {
json['usingComponents'] = json['window'].usingComponents
delete json['window']['usingComponents']
globalStyle: function (name, value, json) {
json.window = parseStyle(value)
if (json.window.usingComponents) {
json.usingComponents = json.window.usingComponents
delete json.window.usingComponents
} else {
json['usingComponents'] = {}
json.usingComponents = {}
}
},
'tabBar': function (name, value, json, fromJson) {
tabBar: function (name, value, json, fromJson) {
if (value && value.list && value.list.length) {
if (value.list.length < 2) {
console.error(`tabBar.list 需至少包含2项`)
console.error('tabBar.list 需至少包含2项')
}
const pages = json.pages
value.list.forEach((page, index) => {
......@@ -58,13 +58,13 @@ const pagesJson2AppJson = {
}
json[name] = value
},
'preloadRule': defaultCopy,
'workers': defaultCopy
preloadRule: defaultCopy,
workers: defaultCopy
}
const manifestJson2AppJson = {
'networkTimeout': defaultCopy,
'debug': defaultCopy
networkTimeout: defaultCopy,
debug: defaultCopy
}
function parseCondition (projectJson, pagesJson) {
......@@ -84,30 +84,30 @@ const pagesJson2ProjectJson = {}
const manifestJson2ProjectJson = {
'name': function (name, value, json) {
name: function (name, value, json) {
if (!value) {
value = path.basename(process.env.UNI_INPUT_DIR)
if (value === 'src') {
value = path.basename(path.dirname(process.env.UNI_INPUT_DIR))
}
}
json['projectname'] = value
json.projectname = value
}
}
const platformJson2ProjectJson = {
'appid': defaultCopy,
'setting': defaultCopy,
'miniprogramRoot': defaultCopy,
'cloudfunctionRoot': defaultCopy,
'qcloudRoot': defaultCopy,
'pluginRoot': defaultCopy,
'compileType': defaultCopy,
'libVersion': defaultCopy,
'projectname': defaultCopy,
'packOptions': defaultCopy,
'debugOptions': defaultCopy,
'scripts': defaultCopy
appid: defaultCopy,
setting: defaultCopy,
miniprogramRoot: defaultCopy,
cloudfunctionRoot: defaultCopy,
qcloudRoot: defaultCopy,
pluginRoot: defaultCopy,
compileType: defaultCopy,
libVersion: defaultCopy,
projectname: defaultCopy,
packOptions: defaultCopy,
debugOptions: defaultCopy,
scripts: defaultCopy
}
function copyToJson (json, fromJson, options) {
......@@ -124,10 +124,10 @@ function getCondition (pagesJson) {
const launchPageQuery = process.env.UNI_CLI_LAUNCH_PAGE_QUERY || ''
const launchPageOptions = {
'id': 0,
'name': launchPagePath, // 模式名称
'pathName': launchPagePath, // 启动页面,必选
'query': launchPageQuery // 启动参数,在页面的onLoad函数里面得到。
id: 0,
name: launchPagePath, // 模式名称
pathName: launchPagePath, // 启动页面,必选
query: launchPageQuery // 启动参数,在页面的onLoad函数里面得到。
}
if (condition) {
let current = -1
......@@ -159,8 +159,8 @@ function getCondition (pagesJson) {
}
if (launchPagePath) {
pagesJson.condition = {
'current': 0,
'list': [launchPageOptions]
current: 0,
list: [launchPageOptions]
}
return pagesJson.condition
}
......
const path = require('path')
const {
const {
getPlatforms,
normalizePath
} = require('@dcloudio/uni-cli-shared')
const PLATFORMS = getPlatforms()
const PLATFORMS = getPlatforms()
const alipayWindowMap = {
'defaultTitle': 'navigationBarTitleText',
'pullRefresh': 'enablePullDownRefresh',
'allowsBounceVertical': 'allowsBounceVertical',
'titleBarColor': 'navigationBarBackgroundColor',
'optionMenu': 'optionMenu',
'backgroundColor': 'backgroundColor',
'usingComponents': 'usingComponents',
'navigationBarShadow': 'navigationBarShadow',
'titleImage': 'titleImage',
'transparentTitle': 'transparentTitle',
'titlePenetrate': 'titlePenetrate'
defaultTitle: 'navigationBarTitleText',
pullRefresh: 'enablePullDownRefresh',
allowsBounceVertical: 'allowsBounceVertical',
titleBarColor: 'navigationBarBackgroundColor',
optionMenu: 'optionMenu',
backgroundColor: 'backgroundColor',
usingComponents: 'usingComponents',
navigationBarShadow: 'navigationBarShadow',
titleImage: 'titleImage',
transparentTitle: 'transparentTitle',
titlePenetrate: 'titlePenetrate'
}
const alipayTabBarMap = {
'textColor': 'color',
'selectedColor': 'selectedColor',
'backgroundColor': 'backgroundColor',
'items': 'list'
textColor: 'color',
selectedColor: 'selectedColor',
backgroundColor: 'backgroundColor',
items: 'list'
}
const alipayTabBarItemMap = {
'pagePath': 'pagePath',
'name': 'text',
'icon': 'iconPath',
'activeIcon': 'selectedIconPath'
pagePath: 'pagePath',
name: 'text',
icon: 'iconPath',
activeIcon: 'selectedIconPath'
}
const _hasOwnProperty = Object.prototype.hasOwnProperty
function hasOwn (obj, key) {
return hasOwnProperty.call(obj, key)
return _hasOwnProperty.call(obj, key)
}
function parseStyle (style = {}, root = '') {
// TODO pages.json 触发了两次,需要排查
style = JSON.parse(JSON.stringify(style))
function parseStyle (style = {}, root = '') {
// TODO pages.json 触发了两次,需要排查
style = JSON.parse(JSON.stringify(style))
let platformStyle = {}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册