diff --git a/packages/uni-app-plus/lib/uni.config.js b/packages/uni-app-plus/lib/uni.config.js
index 51afa9168f47e88bbde99b88ef32c22ab361d981..4b6e332fb9e16f9f99606399a04a766039bb6813 100644
--- a/packages/uni-app-plus/lib/uni.config.js
+++ b/packages/uni-app-plus/lib/uni.config.js
@@ -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 {
diff --git a/packages/uni-cli-shared/__tests__/pages.spec.js b/packages/uni-cli-shared/__tests__/pages.spec.js
index 77f7754ab8b4df839ab5dcf3d6c3d58f2ed40ce7..5d7952048a10ef197f589f558f1ed564beb9fdd3 100644
--- a/packages/uni-cli-shared/__tests__/pages.spec.js
+++ b/packages/uni-cli-shared/__tests__/pages.spec.js
@@ -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);'
)
})
})
diff --git a/packages/uni-cli-shared/components/navigation-bar.vue b/packages/uni-cli-shared/components/navigation-bar.vue
index 15ece9737c1a124f9b3adea9204e478d2cfbd4bb..c78bc53acf1dd705f08559135222fe247538613f 100644
--- a/packages/uni-cli-shared/components/navigation-bar.vue
+++ b/packages/uni-cli-shared/components/navigation-bar.vue
@@ -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)
})
diff --git a/packages/uni-cli-shared/lib/cache.js b/packages/uni-cli-shared/lib/cache.js
index cbef08cd16519e43d70a689a50345954eda53c2a..ef8e2969464c5c2f7beab77959a33eb228f8d881 100644
--- a/packages/uni-cli-shared/lib/cache.js
+++ b/packages/uni-cli-shared/lib/cache.js
@@ -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
diff --git a/packages/uni-cli-shared/lib/manifest.js b/packages/uni-cli-shared/lib/manifest.js
index 854c49cbf80e068ceef75c8ae596db7a75c02366..cbec364db688833f920011748ec3292c7a8eea53 100644
--- a/packages/uni-cli-shared/lib/manifest.js
+++ b/packages/uni-cli-shared/lib/manifest.js
@@ -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
diff --git a/packages/uni-cli-shared/lib/package.js b/packages/uni-cli-shared/lib/package.js
index 4608142e968166bd05b0da7d431924eccc90e3b8..4e053745f101d51bfe6566d7884ba7476994b7b8 100644
--- a/packages/uni-cli-shared/lib/package.js
+++ b/packages/uni-cli-shared/lib/package.js
@@ -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) {
diff --git a/packages/uni-cli-shared/lib/platform.js b/packages/uni-cli-shared/lib/platform.js
index 60e331fa78331f6ecead0217e769fd26cea3ef07..7b3a26b1faa70779bc3fb4cc68baf948b8b2b66d 100644
--- a/packages/uni-cli-shared/lib/platform.js
+++ b/packages/uni-cli-shared/lib/platform.js
@@ -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'
diff --git a/packages/uni-cli-shared/lib/plugin.js b/packages/uni-cli-shared/lib/plugin.js
index 6a72552be468ea3b3f2018d2ec4a1eeb64cb59b7..df4df1b02e72df0180255851e6c7491ce37eb7c8 100644
--- a/packages/uni-cli-shared/lib/plugin.js
+++ b/packages/uni-cli-shared/lib/plugin.js
@@ -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)
diff --git a/packages/uni-cli-shared/lib/preprocess.js b/packages/uni-cli-shared/lib/preprocess.js
index d90a990d6fcb3cbe7b059883ddf8b91bca969749..2102f3c5c5736aaa48d753af5ef474650743aabf 100644
--- a/packages/uni-cli-shared/lib/preprocess.js
+++ b/packages/uni-cli-shared/lib/preprocess.js
@@ -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 => {
diff --git a/packages/uni-cli-shared/lib/tags.js b/packages/uni-cli-shared/lib/tags.js
index e0f54554732c71752b9b07d3a0d240e72564aa56..26dafc56d88ce12590384b380f610068f538fca4 100644
--- a/packages/uni-cli-shared/lib/tags.js
+++ b/packages/uni-cli-shared/lib/tags.js
@@ -1,44 +1,44 @@
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']
}
diff --git a/packages/uni-cli-shared/lib/util.js b/packages/uni-cli-shared/lib/util.js
index 9ec87b30ad58d93c474e47f1dee2abb4ea87dd9b..4882f24a90f100d7b73f07799bfecc2f4fa35574 100644
--- a/packages/uni-cli-shared/lib/util.js
+++ b/packages/uni-cli-shared/lib/util.js
@@ -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 = {}) {
diff --git a/packages/uni-migration/lib/vant.js b/packages/uni-migration/lib/vant.js
index 8d14969b5fff2a18aa0c69a1e0ff07d3f9078c82..f9fea0fb4481fabe4c4031050d120a3c727e7ee4 100644
--- a/packages/uni-migration/lib/vant.js
+++ b/packages/uni-migration/lib/vant.js
@@ -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)
}
}
diff --git a/packages/uni-mp-alipay/lib/uni.compiler.js b/packages/uni-mp-alipay/lib/uni.compiler.js
index 6978b07c4e8a2199ab180da6185cc7798b9e8049..0db40cba09dfc6652ab0ccde4f3799f1ce06001a 100644
--- a/packages/uni-mp-alipay/lib/uni.compiler.js
+++ b/packages/uni-mp-alipay/lib/uni.compiler.js
@@ -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, {
diff --git a/packages/uni-mp-weixin/lib/uni.compiler.js b/packages/uni-mp-weixin/lib/uni.compiler.js
index f6aa4d3b4e585c6b925f0e401ebe98901acb4ca4..d70bf8b49df78977e4d80123658bb6ec8040bf86 100644
--- a/packages/uni-mp-weixin/lib/uni.compiler.js
+++ b/packages/uni-mp-weixin/lib/uni.compiler.js
@@ -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]) {
diff --git a/packages/uni-quickapp-vue/lib/validate.js b/packages/uni-quickapp-vue/lib/validate.js
index d19bdfb984625f14e5b58a38a84aa5ede5cc8fbc..fc83313ab041a61e6cc1b7ef089328b38d5678a8 100644
--- a/packages/uni-quickapp-vue/lib/validate.js
+++ b/packages/uni-quickapp-vue/lib/validate.js
@@ -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')
diff --git a/packages/uni-template-compiler/__tests__/compiler-extra.spec.js b/packages/uni-template-compiler/__tests__/compiler-extra.spec.js
index 814fe3769bb3126508afb025590bd051889fad36..ce108281acf5ec2853d041219cf7cbd8c35b516e 100644
--- a/packages/uni-template-compiler/__tests__/compiler-extra.spec.js
+++ b/packages/uni-template-compiler/__tests__/compiler-extra.spec.js
@@ -1,6 +1,6 @@
const compiler = require('../lib')
-function assertCodegen (template, templateCode, renderCode = `with(this){}`, options = {}, mpOptions = {}) {
+function assertCodegen (template, templateCode, renderCode = 'with(this){}', options = {}, mpOptions = {}) {
const res = compiler.compile(template, Object.assign({
resourcePath: 'test.wxml',
mp: Object.assign({
@@ -18,8 +18,8 @@ describe('mp:compiler-extra', () => {
it('generate mp filter ', () => {
assertCodegen(
/* eslint-disable no-template-curly-in-string */
- `{{t.a}}{{t['a']}}{{t.a(b)}}{{t['a'](b)}}{{u.t.a(b)}}{{u.t.a}}`,
- `{{t.a+t['a']+t.a(b)+t['a'](b)+$root.g0+u.t.a}}`,
+ '{{t.a}}{{t[\'a\']}}{{t.a(b)}}{{t[\'a\'](b)}}{{u.t.a(b)}}{{u.t.a}}',
+ '{{t.a+t[\'a\']+t.a(b)+t[\'a\'](b)+$root.g0+u.t.a}}',
'with(this){var g0=u.t.a(b);$mp.data=Object.assign({},{$root:{g0:g0}})}', {
filterModules: {
t: {},
@@ -32,42 +32,42 @@ describe('mp:compiler-extra', () => {
it('generate scopeId', () => {
assertCodegen(
'',
- ``,
+ '',
undefined, {
scopeId: 'data-v-1'
}
)
assertCodegen(
'',
- ``,
+ '',
undefined, {
scopeId: 'data-v-2'
}
)
assertCodegen(
'',
- ``,
+ '',
undefined, {
scopeId: 'data-v-3'
}
)
assertCodegen(
'',
- ``,
+ '',
undefined, {
scopeId: 'data-v-4'
}
)
assertCodegen(
'',
- ``,
+ '',
undefined, {
scopeId: 'data-v-5'
}
)
assertCodegen(
'',
- ``,
+ '',
undefined, {
scopeId: 'data-v-6'
}
@@ -81,7 +81,7 @@ describe('mp:compiler-extra', () => {
// )
assertCodegen(
'',
- ``,
+ '',
undefined, {
scopeId: 'data-v-7'
}
@@ -98,19 +98,19 @@ describe('mp:compiler-extra', () => {
it('generate staticStyle upx and px', () => {
assertCodegen(
'text',
- `text`
+ 'text'
)
assertCodegen(
'text',
- `text`
+ 'text'
)
assertCodegen(
'text',
- `text`
+ 'text'
)
assertCodegen(
'text',
- `text`,
+ 'text',
undefined,
undefined, {
transformPx: true
@@ -121,49 +121,49 @@ describe('mp:compiler-extra', () => {
it('generate text trim', () => {
assertCodegen(
'text',
- `text`
+ 'text'
)
assertCodegen(
' text ',
- `text`
+ 'text'
)
assertCodegen(
- `{{line_one_cn+' '}}`,
- `{{line_one_cn+' '}}`
+ '{{line_one_cn+\' \'}}',
+ '{{line_one_cn+\' \'}}'
)
assertCodegen(
- `{{" "+line_one_cn}}`,
- `{{" "+line_one_cn}}`
+ '{{" "+line_one_cn}}',
+ '{{" "+line_one_cn}}'
)
assertCodegen(
'\nN: {{title}}\n′',
- `{{'N: '+title+"\\n′"}}`
+ '{{\'N: \'+title+"\\n′"}}'
)
assertCodegen(
'我是第一行\n我的第二行',
- `我是第一行\n我的第二行`
+ '我是第一行\n我的第二行'
)
assertCodegen(
'我是第一行\n我的第二行1{{title}}',
- `{{"我是第一行\\n我的第二行1"+title}}`
+ '{{"我是第一行\\n我的第二行1"+title}}'
)
assertCodegen(
`我是第一行
我的第二行2{{title}}`,
- `{{"我是第一行\\n我的第二行2"+title}}`
+ '{{"我是第一行\\n我的第二行2"+title}}'
)
assertCodegen(
' text text ',
- `text text`
+ 'text text'
)
assertCodegen(
'text {{text}} text',
- `{{"text "+text+" text"}}`
+ '{{"text "+text+" text"}}'
)
// assertCodegen(
// 'text {{text}} \ntext',
@@ -171,71 +171,71 @@ describe('mp:compiler-extra', () => {
// )
assertCodegen(
' text {{text}} 文本 ',
- `{{'text '+text+' 文本'}}`
+ '{{\'text \'+text+\' 文本\'}}'
)
assertCodegen(
'{{text}} text text ',
- `{{text+' text text'}}`
+ '{{text+\' text text\'}}'
)
assertCodegen(
' {{text}} text text ',
- `{{''+text+' text text'}}`
+ '{{\'\'+text+\' text text\'}}'
)
assertCodegen(
'{{text}} text text {{text}}',
- `{{text+" text text "+text}}`
+ '{{text+" text text "+text}}'
)
assertCodegen(
' {{text}} text text {{text}} ',
- `{{''+text+" text text "+text+''}}`
+ '{{\'\'+text+" text text "+text+\'\'}}'
)
})
it('generate default slot', () => {
assertCodegen(
'text',
- `text`
+ 'text'
)
assertCodegen(
'text123213',
- `text123213`
+ 'text123213'
)
assertCodegen(
'text',
- `text`
+ 'text'
)
})
it('generate input value', () => {
assertCodegen(
'',
- ``
+ ''
)
})
it('generate v-slot', () => {
assertCodegen(
'',
- ``
+ ''
)
assertCodegen(
'fc默认',
- `fc默认`
+ 'fc默认'
)
assertCodegen(
'text',
- `text`
+ 'text'
)
assertCodegen(
'text123213',
- `text123213`
+ 'text123213'
)
assertCodegen(
'',
- ``
+ ''
)
assertCodegen(
`
@@ -247,49 +247,49 @@ describe('mp:compiler-extra', () => {
Here's some contact info
`,
- `Here might be a page titleHere's some contact infoA paragraph for the main content.`
+ 'Here might be a page titleHere\'s some contact infoA paragraph for the main content.'
)
})
it('generate events inside v-for', () => {
assertCodegen(
- ``,
- ``
+ '',
+ ''
)
// TODO vue的数字 item 是从1,小程序是从0,后续考虑抹平差异
assertCodegen(
- `1count++">`,
- `1`,
- `with(this){if(!_isMounted){e0=e=>count++}}`
+ '1count++">',
+ '1',
+ 'with(this){if(!_isMounted){e0=e=>count++}}'
)
assertCodegen(
- `2count++">`,
- `2`,
- `with(this){if(!_isMounted){e0=e=>count++}}`
+ '2count++">',
+ '2',
+ 'with(this){if(!_isMounted){e0=e=>count++}}'
)
assertCodegen(
- `3`,
- `3`
+ '3',
+ '3'
)
assertCodegen(
- `33`,
- `33`
+ '33',
+ '33'
)
assertCodegen(
- `4`,
- `4`
+ '4',
+ '4'
)
assertCodegen(
- `5`,
- `5`
+ '5',
+ '5'
)
assertCodegen(
- `6`,
- `6`
+ '6',
+ '6'
)
assertCodegen(
- `7`,
- `7`
+ '7',
+ '7'
)
assertCodegen(
`
@@ -297,19 +297,19 @@ describe('mp:compiler-extra', () => {
`,
- `,`
+ ','
)
assertCodegen(
- `9`,
- `9`
+ '9',
+ '9'
)
assertCodegen(
- ``,
- ``
+ '',
+ ''
)
assertCodegen(
- ``,
- ``
+ '',
+ ''
)
assertCodegen(
`
@@ -317,38 +317,38 @@ describe('mp:compiler-extra', () => {
`,
- ``
+ ''
)
})
it('generate class binding', () => {
assertCodegen(
- `
1
`,
- `1`
+ '1
',
+ '1'
)
assertCodegen(
'1
',
- `1`
+ '1'
)
assertCodegen(
- `2
`,
- `2`
+ '2
',
+ '2'
)
assertCodegen(
'3
',
- `3`
+ '3'
)
assertCodegen(
- `4
`,
- `4`
+ '4
',
+ '4'
)
assertCodegen(
- `5
`,
- `5`
+ '5
',
+ '5'
)
assertCodegen(
- `6
`,
- `6`
+ '6
',
+ '6'
)
// assertCodegen(
// `6
`,
@@ -356,56 +356,56 @@ describe('mp:compiler-extra', () => {
// `with(this){var c0=__get_class(computedClassObject,"container");$mp.data=Object.assign({},{$root:{c0:c0}})}`
// )
assertCodegen(
- `7
`,
- `7`
+ '7
',
+ '7'
)
assertCodegen(
- `8
`,
- `8`
+ '8
',
+ '8'
)
assertCodegen(
- `9
`,
- `9`
+ '9
',
+ '9'
)
})
it('generate style binding', () => {
assertCodegen(
- `1
`,
- `1`
+ '1
',
+ '1'
)
assertCodegen(
- `1
`,
- `1`
+ '1
',
+ '1'
)
assertCodegen(
- `1
`,
- `1`
+ '1
',
+ '1'
)
assertCodegen(
- `2
`,
- `2`
+ '2
',
+ '2'
)
assertCodegen(
- `3
`,
- `3`
+ '3
',
+ '3'
)
assertCodegen(
- `4
`,
- `4`
+ '4
',
+ '4'
)
assertCodegen(
- `5
`,
- `5`
+ '5
',
+ '5'
)
assertCodegen(
- `6
`,
- `6`,
- `with(this){var s0=__get_style([baseStyles,overridingStyles]);$mp.data=Object.assign({},{$root:{s0:s0}})}`
+ '6
',
+ '6',
+ 'with(this){var s0=__get_style([baseStyles,overridingStyles]);$mp.data=Object.assign({},{$root:{s0:s0}})}'
)
assertCodegen(
- `7
`,
- `7`
+ '7
',
+ '7'
)
// assertCodegen(
// `7
`,
@@ -413,170 +413,170 @@ describe('mp:compiler-extra', () => {
// `with(this){var s0=__get_style(styleObject);$mp.data=Object.assign({},{$root:{s0:s0}})}`
// )
assertCodegen(
- `8
`,
- `8`
+ '8
',
+ '8'
)
assertCodegen(
- `9
`,
- `9`
+ '9
',
+ '9'
)
assertCodegen(
- `10
`,
- `10`
+ '10
',
+ '10'
)
})
it('generate events with v-on directive on custom component', () => {
assertCodegen(
'',
- ``
+ ''
)
assertCodegen(
'',
- ``
+ ''
)
})
it('generate v-model directive on custom component', () => {
assertCodegen(
'1',
- `1`
+ '1'
)
assertCodegen(
'2',
- `2`
+ '2'
)
assertCodegen(
'3',
- `3`
+ '3'
)
assertCodegen(
'4',
- `4`
+ '4'
)
assertCodegen(
'4',
- `4`
+ '4'
)
})
it('generate object property on custom component', () => {
assertCodegen(
'',
- ``
+ ''
)
})
it('generate v-text directive', () => {
assertCodegen(
'',
- `{{aaa1}}`
+ '{{aaa1}}'
)
assertCodegen(
'',
- `{{aaa1+1}}`
+ '{{aaa1+1}}'
)
assertCodegen(
- ``,
- `aaa2`
+ '',
+ 'aaa2'
)
})
it('generate v-html directive', () => {
assertCodegen(
'',
- ``
+ ''
)
})
it('generate v-bind directive with sync modifier', () => {
assertCodegen(
'',
- ``
+ ''
)
assertCodegen(
'',
- ``
+ ''
)
assertCodegen(
'',
- ``
+ ''
)
assertCodegen(
'',
- ``
+ ''
)
assertCodegen(
'',
- ``
+ ''
)
})
it('generate v-model directive with generic modifiers', () => {
assertCodegen(
'',
- ``
+ ''
)
assertCodegen(
'',
- ``
+ ''
)
assertCodegen(
'',
- ``
+ ''
)
assertCodegen(
'',
- ``
+ ''
)
assertCodegen(
'',
- ``
+ ''
)
assertCodegen(
'',
- ``
+ ''
)
assertCodegen(
'',
- ``
+ ''
)
})
it('generate v-for', () => {
assertCodegen(
- `{{handle(item)}}`,
- `{{item.m0}}`,
- `with(this){var l0=__map(list,function(item,index){var m0=handle(item);return{$orig:__get_orig(item),m0:m0}});$mp.data=Object.assign({},{$root:{l0:l0}})}`
+ '{{handle(item)}}',
+ '{{item.m0}}',
+ 'with(this){var l0=__map(list,function(item,index){var m0=handle(item);return{$orig:__get_orig(item),m0:m0}});$mp.data=Object.assign({},{$root:{l0:l0}})}'
)
assertCodegen(
- `{{handle(item)}}{{item.title}}`,
- `{{item.m0+item.$orig.title}}`,
- `with(this){var l0=__map(list,function(item,index){var m0=handle(item);return{$orig:__get_orig(item),m0:m0}});$mp.data=Object.assign({},{$root:{l0:l0}})}`
+ '{{handle(item)}}{{item.title}}',
+ '{{item.m0+item.$orig.title}}',
+ 'with(this){var l0=__map(list,function(item,index){var m0=handle(item);return{$orig:__get_orig(item),m0:m0}});$mp.data=Object.assign({},{$root:{l0:l0}})}'
)
assertCodegen(
- `{{handle(item1)}}{{item1.title}}`,
- `{{item1.m0+item1.$orig.title}}`,
- `with(this){var l1=__map(list,function(item,index){var l0=__map(list1,function(item1,index1){var m0=handle(item1);return{$orig:__get_orig(item1),m0:m0}});return{$orig:__get_orig(item),l0:l0}});$mp.data=Object.assign({},{$root:{l1:l1}})}`
+ '{{handle(item1)}}{{item1.title}}',
+ '{{item1.m0+item1.$orig.title}}',
+ 'with(this){var l1=__map(list,function(item,index){var l0=__map(list1,function(item1,index1){var m0=handle(item1);return{$orig:__get_orig(item1),m0:m0}});return{$orig:__get_orig(item),l0:l0}});$mp.data=Object.assign({},{$root:{l1:l1}})}'
)
assertCodegen(
- `title: {{ section.title|prefix }}{{ sub_titles|prefix }}`,
- `{{"title: "+section.f0}}{{sub_titles.f1}}`,
- `with(this){var l1=__map(sections,function(section,index){var f0=_f("prefix")(section.title);var l0=__map(section.sub_titles,function(sub_titles,_index){var f1=_f("prefix")(sub_titles);return{$orig:__get_orig(sub_titles),f1:f1}});return{$orig:__get_orig(section),f0:f0,l0:l0}});$mp.data=Object.assign({},{$root:{l1:l1}})}`
+ 'title: {{ section.title|prefix }}{{ sub_titles|prefix }}',
+ '{{"title: "+section.f0}}{{sub_titles.f1}}',
+ 'with(this){var l1=__map(sections,function(section,index){var f0=_f("prefix")(section.title);var l0=__map(section.sub_titles,function(sub_titles,_index){var f1=_f("prefix")(sub_titles);return{$orig:__get_orig(sub_titles),f1:f1}});return{$orig:__get_orig(section),f0:f0,l0:l0}});$mp.data=Object.assign({},{$root:{l1:l1}})}'
)
assertCodegen(
- `{{aaa.item.id | test | test1}}`,
- `{{$root.f0}}`,
- `with(this){var f0=_f("test1")(_f("test")(aaa.item.id));$mp.data=Object.assign({},{$root:{f0:f0}})}`
+ '{{aaa.item.id | test | test1}}',
+ '{{$root.f0}}',
+ 'with(this){var f0=_f("test1")(_f("test")(aaa.item.id));$mp.data=Object.assign({},{$root:{f0:f0}})}'
)
assertCodegen(
- `{{item.item.id | test | test1}}`,
- `{{item.f0}}`,
- `with(this){var l0=__map(list,function(item,index){var f0=_f("test1")(_f("test")(item.item.id));return{$orig:__get_orig(item),f0:f0}});$mp.data=Object.assign({},{$root:{l0:l0}})}`
+ '{{item.item.id | test | test1}}',
+ '{{item.f0}}',
+ 'with(this){var l0=__map(list,function(item,index){var f0=_f("test1")(_f("test")(item.item.id));return{$orig:__get_orig(item),f0:f0}});$mp.data=Object.assign({},{$root:{l0:l0}})}'
)
assertCodegen(
- `{{ item.split('').join(' ') }}`,
- `{{item.g0}}`,
- `with(this){var l0=__map(list,function(item,i){var g0=item.split("").join(" ");return{$orig:__get_orig(item),g0:g0}});$mp.data=Object.assign({},{$root:{l0:l0}})}`
+ '{{ item.split(\'\').join(\' \') }}',
+ '{{item.g0}}',
+ 'with(this){var l0=__map(list,function(item,i){var g0=item.split("").join(" ");return{$orig:__get_orig(item),g0:g0}});$mp.data=Object.assign({},{$root:{l0:l0}})}'
)
})
@@ -584,67 +584,67 @@ describe('mp:compiler-extra', () => {
assertCodegen(
/* eslint-disable no-template-curly-in-string */
'',
- ``
+ ''
)
assertCodegen(
/* eslint-disable no-template-curly-in-string */
'',
- ``
+ ''
)
})
it('generate event ', () => {
assertCodegen(
- ``,
- ``
+ '',
+ ''
)
assertCodegen(
- `{{item.title}}`,
- `{{item.title}}`
+ '{{item.title}}',
+ '{{item.title}}'
)
assertCodegen(
- `1`,
- `1`
+ '1',
+ '1'
)
assertCodegen(
- `2`,
- `2`
+ '2',
+ '2'
)
assertCodegen(
- `3`,
- `3`
+ '3',
+ '3'
)
assertCodegen(
- ``,
- ``
+ '',
+ ''
)
assertCodegen(
- ``,
- ``
+ '',
+ ''
)
assertCodegen(
- `{{item.title}}`,
- `{{item.title}}`
+ '{{item.title}}',
+ '{{item.title}}'
)
assertCodegen(
- `{{item.title}}`,
- `{{item.title}}`
+ '{{item.title}}',
+ '{{item.title}}'
)
assertCodegen(
- ``,
- ``
+ '',
+ ''
)
assertCodegen(
- ``,
- ``
+ '',
+ ''
)
assertCodegen(
- ``,
- ``
+ '',
+ ''
)
assertCodegen(
- `{{ item }}`,
- `{{item}}`
+ '{{ item }}',
+ '{{item}}'
)
})
})
diff --git a/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js b/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js
index 26d12f14e8288a9a7ac59a75bc29e833f1ea3a3f..f5d51163381c34391a3d0a49eb5487cd504d1411 100644
--- a/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js
+++ b/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js
@@ -1,6 +1,6 @@
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(
'',
- ``
+ ''
)
})
it('generate v-else-if with v-else directive', () => {
assertCodegen(
'helloworldbye',
- `helloworldbye`
+ 'helloworldbye'
)
})
it('generate ref', () => {
assertCodegen(
'text',
- `text`
+ 'text'
)
assertCodegen(
'text123213',
- `text123213`
+ 'text123213'
)
assertCodegen(
'',
- ``
+ ''
)
assertCodegen(
'',
- ``
+ ''
)
})
it('generate default slot', () => {
assertCodegen(
'text',
- `text`
+ 'text'
)
assertCodegen(
'text123213',
- `text123213`
+ 'text123213'
)
assertCodegen(
'text',
- `text`
+ 'text'
)
})
it('generate class binding', () => {
assertCodegen(
'1
',
- `1`
+ '1'
)
assertCodegen(
- `2
`,
- `2`
+ '2
',
+ '2'
)
assertCodegen(
'3
',
- `3`
+ '3'
)
assertCodegen(
- `4
`,
- `4`
+ '4
',
+ '4'
)
assertCodegen(
- `5
`,
- `5`
+ '5
',
+ '5'
)
assertCodegen(
- `6
`,
- `6`
+ '6
',
+ '6'
)
// assertCodegen(
// `6
`,
@@ -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(
- `7
`,
- `7`
+ '7
',
+ '7'
)
assertCodegen(
- `8
`,
- `8`
+ '8
',
+ '8'
)
assertCodegen(
- `9
`,
- `9`
+ '9
',
+ '9'
)
})
it('generate getPhoneNumber', () => {
assertCodegen(
'',
- ``
+ ''
)
})
it('generate events with v-on directive', () => {
assertCodegen(
- ``,
- ``,
- `with(this){var a0={color:"#4cd964",size:"22",type:"spinner"};$mp.data=Object.assign({},{$root:{a0:a0}})}`
+ '',
+ '',
+ 'with(this){var a0={color:"#4cd964",size:"22",type:"spinner"};$mp.data=Object.assign({},{$root:{a0:a0}})}'
)
assertCodegen(
- ``,
- ``
+ '',
+ ''
)
assertCodegen(
- ``,
- ``
+ '',
+ ''
)
assertCodegen(
- ``,
- ``
+ '',
+ ''
)
assertCodegen(
- ``,
- ``
+ '',
+ ''
)
assertCodegen(
- ``,
- ``
+ '',
+ ''
)
assertCodegen(
- ``,
- ``
+ '',
+ ''
)
})
})
diff --git a/packages/uni-template-compiler/__tests__/compiler-mp-baidu.spec.js b/packages/uni-template-compiler/__tests__/compiler-mp-baidu.spec.js
index 5540e69bebc82e65dc657160d06c01e4b7b7c9de..42116261bc10292ff339bccea91b831b82f68d83 100644
--- a/packages/uni-template-compiler/__tests__/compiler-mp-baidu.spec.js
+++ b/packages/uni-template-compiler/__tests__/compiler-mp-baidu.spec.js
@@ -1,6 +1,6 @@
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(
'',
- ``
+ ''
)
})
it('generate scoped slot', () => {
assertCodegen(
'{{ bar.foo }}',
- `{{foo}}`
+ '{{foo}}'
)
assertCodegen(
'{{ bar.foo }}',
- `{{foo}}`
+ '{{foo}}'
)
})
it('generate named scoped slot', () => {
assertCodegen(
'{{ bar.foo }}',
- `{{foo}}`
+ '{{foo}}'
)
assertCodegen(
'{{ bar.foo }}',
- `{{foo}}`
+ '{{foo}}'
)
})
it('generate scoped slot with multiline v-if', () => {
assertCodegen(
'{{ bar.foo }}',
- `{{foo}}`
+ '{{foo}}'
)
assertCodegen(
'{{ bar.foo }}',
- `{{foo}}`
+ '{{foo}}'
)
})
it('generate scoped slot', () => {
assertCodegen(
'{{ user.lastName }}',
- ``
+ ''
)
assertCodegen(
'{{ user.lastName }}',
- ``
+ ''
)
})
it('generate vue id', () => {
assertCodegen(
'',
- ``
+ ''
)
assertCodegen(
'',
- ``
+ ''
)
assertCodegen(
'',
- ``
+ ''
)
assertCodegen(
'',
- ``
+ ''
)
assertCodegen(
'',
- ``
+ ''
)
})
it('generate text trim', () => {
assertCodegen(
'\nN: {{title}}\n′',
- `{{'N: '+title+"\\\\n′"}}`
+ '{{\'N: \'+title+"\\\\n′"}}'
)
assertCodegen(
'我是第一行1\n我的第二行',
- `我是第一行1\n我的第二行`
+ '我是第一行1\n我的第二行'
)
assertCodegen(
'我是第一行2\n我的第二行1{{title}}',
- `{{"我是第一行2\\\\n我的第二行1"+title}}`
+ '{{"我是第一行2\\\\n我的第二行1"+title}}'
)
assertCodegen(
`我是第一行3
我的第二行2{{title}}`,
- `{{"我是第一行3\\\\n 我的第二行2"+title}}`
+ '{{"我是第一行3\\\\n 我的第二行2"+title}}'
)
})
})
diff --git a/packages/uni-template-compiler/__tests__/compiler-mp-qq.spec.js b/packages/uni-template-compiler/__tests__/compiler-mp-qq.spec.js
index ab22dcb02b4c6abf118a4c882877a790aca0f0e1..30de6ee858874a6067cd848b53dc50aead96466b 100644
--- a/packages/uni-template-compiler/__tests__/compiler-mp-qq.spec.js
+++ b/packages/uni-template-compiler/__tests__/compiler-mp-qq.spec.js
@@ -1,6 +1,6 @@
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(
'\nN: {{title}}\n′',
- `{{'N: '+title+"\\\\n′"}}`
+ '{{\'N: \'+title+"\\\\n′"}}'
)
assertCodegen(
'我是第一行1\n我的第二行',
- `我是第一行1\n我的第二行`
+ '我是第一行1\n我的第二行'
)
assertCodegen(
'我是第一行2\n我的第二行1{{title}}',
- `{{"我是第一行2\\\\n我的第二行1"+title}}`
+ '{{"我是第一行2\\\\n我的第二行1"+title}}'
)
assertCodegen(
`我是第一行3
我的第二行2{{title}}`,
- `{{"我是第一行3\\\\n 我的第二行2"+title}}`
+ '{{"我是第一行3\\\\n 我的第二行2"+title}}'
)
})
})
diff --git a/packages/uni-template-compiler/__tests__/compiler-mp-toutiao.spec.js b/packages/uni-template-compiler/__tests__/compiler-mp-toutiao.spec.js
index 0fdd0ea9d732febb4680ec8cadc6a018a2d3bb90..38b54dfc2a12a5af99e81ace41551c0a574491ba 100644
--- a/packages/uni-template-compiler/__tests__/compiler-mp-toutiao.spec.js
+++ b/packages/uni-template-compiler/__tests__/compiler-mp-toutiao.spec.js
@@ -1,6 +1,6 @@
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(
'',
- ``
+ ''
)
})
it('generate ref', () => {
assertCodegen(
'',
- ``
+ ''
)
})
it('generate class binding', () => {
assertCodegen(
'1
',
- `1`
+ '1'
)
assertCodegen(
- `2
`,
- `2`
+ '2
',
+ '2'
)
assertCodegen(
'3
',
- `3`
+ '3'
)
assertCodegen(
- `4
`,
- `4`
+ '4
',
+ '4'
)
assertCodegen(
- `5
`,
- `5`
+ '5
',
+ '5'
)
assertCodegen(
- `6
`,
- `6`
+ '6
',
+ '6'
)
// assertCodegen(
// `6
`,
@@ -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(
- `7
`,
- `7`
+ '7
',
+ '7'
)
assertCodegen(
- `8
`,
- `8`
+ '8
',
+ '8'
)
assertCodegen(
- `9
`,
- `9`
+ '9
',
+ '9'
)
})
})
diff --git a/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js b/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js
index 135de1667a4eddd4fd0e7022061e55d5d89e405f..d8956d8ab28fc717835819bf84ca1bb07285ce34 100644
--- a/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js
+++ b/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js
@@ -1,6 +1,6 @@
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(
'{{ bar.foo }}',
- ``,
+ '',
function (res) {
expect(res.generic[0]).toBe('test-foo-default')
}
)
assertCodegen(
'{{ bar.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(
'{{ bar.foo }}',
- ``,
+ '',
function (res) {
expect(res.generic[0]).toBe('test-foo-foo')
}
)
assertCodegen(
'{{ bar.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(
'{{ bar.foo }}',
- ``,
+ '',
function (res) {
expect(res.generic[0]).toBe('test-foo-default')
}
)
assertCodegen(
'{{ bar.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
'{{ user.lastName }}',
- ``,
+ '',
function (res) {
expect(res.componentGenerics['scoped-slots-default']).toBe(true)
}
)
assertCodegen(
'{{ user.lastName }}',
- ``,
+ '',
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
'',
- ``
+ ''
)
})
})
diff --git a/packages/uni-template-compiler/__tests__/compiler-quickapp-light.spec.js b/packages/uni-template-compiler/__tests__/compiler-quickapp-light.spec.js
index 52cf6d376f97084eae7702c61be6704a7f34f680..e187c8a844058eab243de2622db3c1559559d457 100644
--- a/packages/uni-template-compiler/__tests__/compiler-quickapp-light.spec.js
+++ b/packages/uni-template-compiler/__tests__/compiler-quickapp-light.spec.js
@@ -1,6 +1,6 @@
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(
'',
- ``
+ ''
)
})
it('generate v-else-if with v-else directive', () => {
assertCodegen(
'helloworldbye',
- `helloworldbye`
+ 'helloworldbye'
)
})
})
diff --git a/packages/uni-template-compiler/__tests__/compiler.spec.js b/packages/uni-template-compiler/__tests__/compiler.spec.js
index 418a276707cf732e2cc6383321b6056c0ffad71d..0693d7d93c26a950e942b04d3ddaffb00fa56510 100644
--- a/packages/uni-template-compiler/__tests__/compiler.spec.js
+++ b/packages/uni-template-compiler/__tests__/compiler.spec.js
@@ -1,6 +1,6 @@
const compiler = require('../lib')
-function assertCodegen (template, templateCode, renderCode = `with(this){}`) {
+function assertCodegen (template, templateCode, renderCode = 'with(this){}') {
const res = compiler.compile(template, {
resourcePath: 'test.wxml',
mp: {
@@ -26,28 +26,28 @@ describe('mp:compiler', () => {
it('generate filters', () => {
assertCodegen(
'text {{ d | e | f }} text',
- `{{"text "+$root.f1+" text"}}`,
- `with(this){var f0=_f("c")(_f("b")(a));var f1=_f("f")(_f("e")(d));$mp.data=Object.assign({},{$root:{f0:f0,f1:f1}})}`
+ '{{"text "+$root.f1+" text"}}',
+ 'with(this){var f0=_f("c")(_f("b")(a));var f1=_f("f")(_f("e")(d));$mp.data=Object.assign({},{$root:{f0:f0,f1:f1}})}'
)
})
it('generate filters with no arguments', () => {
assertCodegen(
'{{ d | e() }}',
- `{{$root.f0}}`,
- `with(this){var f0=_f("e")(d);$mp.data=Object.assign({},{$root:{f0:f0}})}`
+ '{{$root.f0}}',
+ 'with(this){var f0=_f("e")(d);$mp.data=Object.assign({},{$root:{f0:f0}})}'
)
})
it('generate v-for directive', () => {
assertCodegen(
'',
- ``
+ ''
)
// iterator syntax
assertCodegen(
'',
- ``
+ ''
)
// TODO
// assertCodegen(
@@ -68,42 +68,42 @@ describe('mp:compiler', () => {
// v-for with extra element
assertCodegen(
'',
- ``
+ ''
)
})
it('generate v-if directive', () => {
assertCodegen(
'hello',
- `hello`
+ 'hello'
)
})
it('generate v-else directive', () => {
assertCodegen(
'helloworld',
- `helloworld`
+ 'helloworld'
)
})
it('generate v-else-if directive', () => {
assertCodegen(
'helloworld',
- `helloworld`
+ 'helloworld'
)
})
it('generate v-else-if with v-else directive', () => {
assertCodegen(
'helloworldbye',
- `helloworldbye`
+ 'helloworldbye'
)
})
it('generate multi v-else-if with v-else directive', () => {
assertCodegen(
'helloworldelseifbye',
- `helloworldelseifbye`
+ 'helloworldelseifbye'
)
})
@@ -117,7 +117,7 @@ describe('mp:compiler', () => {
it('generate ref on v-for', () => {
assertCodegen(
'',
- ``
+ ''
)
})
@@ -145,39 +145,39 @@ describe('mp:compiler', () => {
it('generate v-model directive', () => {
assertCodegen(
'',
- ``
+ ''
)
})
it('generate multiline v-model directive', () => {
assertCodegen(
'',
- ``
+ ''
)
})
it('generate multiline v-model directive on custom component', () => {
assertCodegen(
'',
- ``
+ ''
)
})
it('generate template tag', () => {
assertCodegen(
'{{hello}}',
- `{{hello}}`
+ '{{hello}}'
)
})
it('generate single slot', () => {
- assertCodegen('', ``)
+ assertCodegen('', '')
})
it('generate named slot', () => {
assertCodegen(
'',
- ``
+ ''
)
})
@@ -191,7 +191,7 @@ describe('mp:compiler', () => {
it('generate slot target', () => {
assertCodegen(
'hello world',
- `hello world`
+ 'hello world'
)
})
@@ -232,12 +232,12 @@ describe('mp:compiler', () => {
// static
assertCodegen(
'hello world',
- `hello world`
+ 'hello world'
)
// dynamic
assertCodegen(
'hello world',
- `hello world`
+ 'hello world'
)
// assertCodegen(
// 'hello world',
@@ -249,14 +249,14 @@ describe('mp:compiler', () => {
it('generate staticStyle', () => {
assertCodegen(
'hello world',
- `hello world`
+ 'hello world'
)
})
it('generate style binding', () => {
assertCodegen(
'hello world',
- `hello world`
+ 'hello world'
)
// assertCodegen(
// 'hello world',
@@ -268,56 +268,56 @@ describe('mp:compiler', () => {
it('generate v-show directive', () => {
assertCodegen(
'hello world',
- `hello world`
+ 'hello world'
)
})
it('generate DOM props with v-bind directive', () => {
// input + value
- assertCodegen('', ``)
+ assertCodegen('', '')
// non input
- assertCodegen('', ``)
+ assertCodegen('', '')
})
it('generate attrs with v-bind directive', () => {
- assertCodegen('', ``)
+ assertCodegen('', '')
})
it('generate static attrs', () => {
- assertCodegen('', ``)
+ assertCodegen('', '')
})
it('generate events with v-on directive', () => {
assertCodegen(
'',
- ``
+ ''
)
})
it('generate events with method call', () => {
assertCodegen(
'',
- ``
+ ''
)
// empty arguments
assertCodegen(
'',
- ``
+ ''
)
// without semicolon
assertCodegen(
'',
- ``
+ ''
)
// multiple args
assertCodegen(
'',
- ``
+ ''
)
// expression in args
assertCodegen(
'',
- ``
+ ''
)
// tricky symbols in args
// assertCodegen(
@@ -382,15 +382,15 @@ describe('mp:compiler', () => {
it('generate events with generic modifiers', () => {
assertCodegen(
'',
- ``
+ ''
)
assertCodegen(
'',
- ``
+ ''
)
assertCodegen(
'',
- ``
+ ''
)
})
@@ -398,82 +398,82 @@ describe('mp:compiler', () => {
it('generate events with generic modifiers and keycode correct order', () => {
assertCodegen(
'',
- ``
+ ''
)
assertCodegen(
'',
- ``
+ ''
)
})
it('generate events with mouse event modifiers', () => {
assertCodegen(
'',
- ``
+ ''
)
assertCodegen(
'',
- ``
+ ''
)
assertCodegen(
'',
- ``
+ ''
)
assertCodegen(
'',
- ``
+ ''
)
assertCodegen(
'',
- ``
+ ''
)
assertCodegen(
'',
- ``
+ ''
)
})
it('generate events with multiple modifiers', () => {
assertCodegen(
'',
- ``
+ ''
)
})
it('generate events with capture modifier', () => {
assertCodegen(
'',
- ``
+ ''
)
})
it('generate events with once modifier', () => {
assertCodegen(
'',
- ``
+ ''
)
})
it('generate events with capture and once modifier', () => {
assertCodegen(
'',
- ``
+ ''
)
})
it('generate events with once and capture modifier', () => {
assertCodegen(
'',
- ``
+ ''
)
})
it('generate events with inline statement', () => {
assertCodegen(
'',
- ``,
- `with(this){if(!_isMounted){e0=function($event){current++}}}`
+ '',
+ 'with(this){if(!_isMounted){e0=function($event){current++}}}'
)
})
@@ -481,51 +481,51 @@ describe('mp:compiler', () => {
// normal function
assertCodegen(
'',
- ``,
- `with(this){if(!_isMounted){e0=function(){current++}}}`
+ '',
+ 'with(this){if(!_isMounted){e0=function(){current++}}}'
)
// normal named function
assertCodegen(
'',
- ``,
- `with(this){if(!_isMounted){e0=function fn(){current++}}}`
+ '',
+ 'with(this){if(!_isMounted){e0=function fn(){current++}}}'
)
// arrow with no args
assertCodegen(
'current++">',
- ``,
- `with(this){if(!_isMounted){e0=()=>current++}}`
+ '',
+ 'with(this){if(!_isMounted){e0=()=>current++}}'
)
// arrow with parens, single arg
assertCodegen(
' current++">',
- ``,
- `with(this){if(!_isMounted){e0=e=>current++}}`
+ '',
+ 'with(this){if(!_isMounted){e0=e=>current++}}'
)
// arrow with parens, multi args
assertCodegen(
' current++">',
- ``,
- `with(this){if(!_isMounted){e0=(a,b,c)=>current++}}`
+ '',
+ 'with(this){if(!_isMounted){e0=(a,b,c)=>current++}}'
)
// arrow with destructuring
assertCodegen(
' current++">',
- ``,
- `with(this){if(!_isMounted){e0=({a,b})=>current++}}`
+ '',
+ 'with(this){if(!_isMounted){e0=({a,b})=>current++}}'
)
// arrow single arg no parens
assertCodegen(
'current++">',
- ``,
- `with(this){if(!_isMounted){e0=e=>current++}}`
+ '',
+ 'with(this){if(!_isMounted){e0=e=>current++}}'
)
// with modifiers
assertCodegen(
- `current++">`,
- ``,
- `with(this){if(!_isMounted){e0=function($event){$event.stopPropagation();return(e=>current++)($event)}}}`
+ 'current++">',
+ '',
+ 'with(this){if(!_isMounted){e0=function($event){$event.stopPropagation();return(e=>current++)($event)}}}'
)
})
@@ -533,7 +533,7 @@ describe('mp:compiler', () => {
it('should not treat handler with unexpected whitespace as inline statement', () => {
assertCodegen(
'',
- ``
+ ''
)
})
@@ -558,7 +558,7 @@ describe('mp:compiler', () => {
it('generate component', () => {
assertCodegen(
'hi
',
- `hi`
+ 'hi'
// `with(this){if(!$mp.events){$mp.events=__get_event({"e0":{on:{"notify":onNotify},component:true}})}}`
)
})
@@ -610,8 +610,8 @@ describe('mp:compiler', () => {
it('generate static trees inside v-for', () => {
// TODO vue的数字 item 是从1,小程序是从0,后续考虑抹平差异
assertCodegen(
- ``,
- ``
+ '',
+ ''
)
})
@@ -619,50 +619,50 @@ describe('mp:compiler', () => {
// normalize type: 2
assertCodegen(
'{{ item }}
',
- `{{item}}`
+ '{{item}}'
)
})
it('generate component with comment', () => {
assertCodegen(
'',
- ``
+ ''
)
})
// #6150
it('generate comments with special characters', () => {
assertCodegen(
'',
- ``
+ ''
)
})
// #8041
it('does not squash templates inside v-pre', () => {
assertCodegen(
'',
- `{{msg}}`
+ '{{msg}}'
)
})
it('not specified ast type', () => {
assertCodegen(
'',
- ``
+ ''
)
})
it('not specified directives option', () => {
assertCodegen(
'hello world
',
- `hello world`
+ 'hello world'
)
})
// #9142
it('should compile single v-for component inside template', () => {
assertCodegen(
- `
`,
- ``
+ '
',
+ ''
)
})
})
diff --git a/packages/uni-template-compiler/lib/app/optimizer.js b/packages/uni-template-compiler/lib/app/optimizer.js
index a65719a627a42120ecf9f4bfd6e3aeaba0252f38..030cc1a0e0d323e2ab609b141f59d26a950be5c1 100644
--- a/packages/uni-template-compiler/lib/app/optimizer.js
+++ b/packages/uni-template-compiler/lib/app/optimizer.js
@@ -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
}
}
diff --git a/packages/uni-template-compiler/lib/app/parser/event-parser.js b/packages/uni-template-compiler/lib/app/parser/event-parser.js
index ad0d5646b4eab715c54e4b3396c9d33e31d3954f..c37603785baf42256f8fd46a37c87ea12fd2f2c7 100644
--- a/packages/uni-template-compiler/lib/app/parser/event-parser.js
+++ b/packages/uni-template-compiler/lib/app/parser/event-parser.js
@@ -1,7 +1,7 @@
const deprecated = {
events: {
- 'tap': 'click',
- 'longtap': 'longpress'
+ tap: 'click',
+ longtap: 'longpress'
}
}
module.exports = function parseEvent (el) {
diff --git a/packages/uni-template-compiler/lib/app/view.js b/packages/uni-template-compiler/lib/app/view.js
index 89818ce9df4c19471a034a693d3c87f5e8291f84..319613bfc7fb72df2dfac5bac27ab492011c9567 100644
--- a/packages/uni-template-compiler/lib/app/view.js
+++ b/packages/uni-template-compiler/lib/app/view.js
@@ -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(){}'
}
}
}
diff --git a/packages/uni-template-compiler/lib/asset-url.js b/packages/uni-template-compiler/lib/asset-url.js
index a5c572af6c44cabe901fd726e17376963d324681..e689fd88ff3fca10b725ee42b0af62335fadf818 100644
--- a/packages/uni-template-compiler/lib/asset-url.js
+++ b/packages/uni-template-compiler/lib/asset-url.js
@@ -1,10 +1,10 @@
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
}
}
diff --git a/packages/uni-template-compiler/lib/codeframe.js b/packages/uni-template-compiler/lib/codeframe.js
index 1ae0759eb7cb730fd46dcd2ca5c8a88aa1fc7dad..4a87f665397d287d87a1d5137d0c8a0fca7a5648 100644
--- a/packages/uni-template-compiler/lib/codeframe.js
+++ b/packages/uni-template-compiler/lib/codeframe.js
@@ -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
diff --git a/packages/uni-template-compiler/lib/module-alipay.js b/packages/uni-template-compiler/lib/module-alipay.js
index 91cfdfab5af18761af19cf426ea872bf9d9cc614..b45cc91f795291d27f18d6a317c45d91737e94a7 100644
--- a/packages/uni-template-compiler/lib/module-alipay.js
+++ b/packages/uni-template-compiler/lib/module-alipay.js
@@ -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)'
}
}
diff --git a/packages/uni-template-compiler/lib/module.js b/packages/uni-template-compiler/lib/module.js
index 78d2808e9b5c6a0e7bee0296bc7d0a8388356580..ef883e7c64db5547a32a77996c2facb32e6e3490 100644
--- a/packages/uni-template-compiler/lib/module.js
+++ b/packages/uni-template-compiler/lib/module.js
@@ -1,7 +1,11 @@
+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平台, 组件暂不支持非 V3 编译, 详见: https://ask.dcloud.net.cn/article/36599')
+ }) {
+ if (process.env.UNI_PLATFORM === 'app-plus' && el.tag === 'ad') {
+ warn('app-vue平台, 组件暂不支持非 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', '')
diff --git a/packages/uni-template-compiler/lib/script/traverse/data/attrs.js b/packages/uni-template-compiler/lib/script/traverse/data/attrs.js
index f993cd5cd862ff07dcbb80fa486d1c5134d5aa18..99bff684b37355381638c7995e6f23d27f6440fa 100644
--- a/packages/uni-template-compiler/lib/script/traverse/data/attrs.js
+++ b/packages/uni-template-compiler/lib/script/traverse/data/attrs.js
@@ -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')
diff --git a/packages/uni-template-compiler/lib/script/traverse/data/class.js b/packages/uni-template-compiler/lib/script/traverse/data/class.js
index 32f97b5f7850f719ad44359acb23d4f1f82ddedb..c9d6b8eb81f28f02c1c55844c23b78b405b50c64 100644
--- a/packages/uni-template-compiler/lib/script/traverse/data/class.js
+++ b/packages/uni-template-compiler/lib/script/traverse/data/class.js
@@ -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
diff --git a/packages/uni-template-compiler/lib/script/traverse/data/directives.js b/packages/uni-template-compiler/lib/script/traverse/data/directives.js
index 73c5f6f98ae2648a7469e395a6de1b476d948972..0c3ed0bad34ac1725eb4533b82b9889b39499547 100644
--- a/packages/uni-template-compiler/lib/script/traverse/data/directives.js
+++ b/packages/uni-template-compiler/lib/script/traverse/data/directives.js
@@ -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'
diff --git a/packages/uni-template-compiler/lib/script/traverse/data/event.js b/packages/uni-template-compiler/lib/script/traverse/data/event.js
index 49a26e358415a0980d4cecb5bf11bc34e9df5cb3..c1dccb98a83d8847ea38ad9d033dca8a95953264 100644
--- a/packages/uni-template-compiler/lib/script/traverse/data/event.js
+++ b/packages/uni-template-compiler/lib/script/traverse/data/event.js
@@ -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 = []
diff --git a/packages/uni-template-compiler/lib/script/traverse/data/index.js b/packages/uni-template-compiler/lib/script/traverse/data/index.js
index c4d34c28cf208eb62dbef9206a324636aaa5b9d4..2999c6ba7ce7205d7a2be750a8a5903bb6fa50e5 100644
--- a/packages/uni-template-compiler/lib/script/traverse/data/index.js
+++ b/packages/uni-template-compiler/lib/script/traverse/data/index.js
@@ -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 {
diff --git a/packages/uni-template-compiler/lib/script/traverse/data/model.js b/packages/uni-template-compiler/lib/script/traverse/data/model.js
index bbf647ca386fa8572758884b3702e5b23787409c..fa109624a3c0255b86b6ead763d52a481b2b555b 100644
--- a/packages/uni-template-compiler/lib/script/traverse/data/model.js
+++ b/packages/uni-template-compiler/lib/script/traverse/data/model.js
@@ -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 {
diff --git a/packages/uni-template-compiler/lib/script/traverse/data/ref.js b/packages/uni-template-compiler/lib/script/traverse/data/ref.js
index 6ba77046ed0155718c6e62831a112286f8de7c68..27402f5f5093d66d4771c6aaec9d1b636f15abed 100644
--- a/packages/uni-template-compiler/lib/script/traverse/data/ref.js
+++ b/packages/uni-template-compiler/lib/script/traverse/data/ref.js
@@ -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'
)
}
diff --git a/packages/uni-template-compiler/lib/script/traverse/data/style.js b/packages/uni-template-compiler/lib/script/traverse/data/style.js
index f112fd09fae88c0862ac69d8953992a163982ca1..923a988d56811c888937d2387000d3bf0b68c7f0 100644
--- a/packages/uni-template-compiler/lib/script/traverse/data/style.js
+++ b/packages/uni-template-compiler/lib/script/traverse/data/style.js
@@ -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()) {
diff --git a/packages/uni-template-compiler/lib/script/traverse/filter.js b/packages/uni-template-compiler/lib/script/traverse/filter.js
index 6154121fa69725e8899e265981584df0f3329582..7045ea01c9b8352489d1ff84ad967e7a7c3a45c9 100644
--- a/packages/uni-template-compiler/lib/script/traverse/filter.js
+++ b/packages/uni-template-compiler/lib/script/traverse/filter.js
@@ -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'
]
diff --git a/packages/uni-template-compiler/lib/script/traverse/render-list.js b/packages/uni-template-compiler/lib/script/traverse/render-list.js
index 6b5af24bc68c9af1bb10bb3a783d084ae167aaf4..4827fc311c0a0c2ff61da11dd1056f32a3ac3621 100644
--- a/packages/uni-template-compiler/lib/script/traverse/render-list.js
+++ b/packages/uni-template-compiler/lib/script/traverse/render-list.js
@@ -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++)
diff --git a/packages/uni-template-compiler/lib/script/traverse/visitor.js b/packages/uni-template-compiler/lib/script/traverse/visitor.js
index 6da1f3fc75c7d4bb6c2d4a9ff1052d17e070d4f7..5a81060f39a7e20260f23a87d92fa04569d17cff 100644
--- a/packages/uni-template-compiler/lib/script/traverse/visitor.js
+++ b/packages/uni-template-compiler/lib/script/traverse/visitor.js
@@ -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)
diff --git a/packages/uni-template-compiler/lib/template/generate.js b/packages/uni-template-compiler/lib/template/generate.js
index 6d8670e2319a11e01ebb597bd0379db33db6398d..987130f1a7344f69067b58deff146d88e6049952 100644
--- a/packages/uni-template-compiler/lib/template/generate.js
+++ b/packages/uni-template-compiler/lib/template/generate.js
@@ -1,3 +1,7 @@
+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
//
- 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)) {
diff --git a/packages/uni-template-compiler/lib/template/traverse.js b/packages/uni-template-compiler/lib/template/traverse.js
index a2007afe94c8a9d04c468f18613746f0742cbf46..fcc98428c92303a096dbccf5d59f1782c0f84614 100644
--- a/packages/uni-template-compiler/lib/template/traverse.js
+++ b/packages/uni-template-compiler/lib/template/traverse.js
@@ -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),
diff --git a/packages/uni-template-compiler/lib/util.js b/packages/uni-template-compiler/lib/util.js
index e8815049a03a7cdec188e91741ef01f44b1081ff..a82eaba52c9037e2e902b4d17f020f3159786ba7 100644
--- a/packages/uni-template-compiler/lib/util.js
+++ b/packages/uni-template-compiler/lib/util.js
@@ -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'
diff --git a/packages/vue-cli-plugin-hbuilderx/__tests__/console.spec.js b/packages/vue-cli-plugin-hbuilderx/__tests__/console.spec.js
index e06a4362efd62c8b07fb952b6e62925d6c600adb..2eebff97c404e0f116635c95e9ea085a71337518 100644
--- a/packages/vue-cli-plugin-hbuilderx/__tests__/console.spec.js
+++ b/packages/vue-cli-plugin-hbuilderx/__tests__/console.spec.js
@@ -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");')
})
})
diff --git a/packages/vue-cli-plugin-hbuilderx/__tests__/demo.js b/packages/vue-cli-plugin-hbuilderx/__tests__/demo.js
index a54bd76cf85faed53b1a2b5951584d21f429ccba..5cffaa6ec5f933341d640108c36d927d5f462239 100644
--- a/packages/vue-cli-plugin-hbuilderx/__tests__/demo.js
+++ b/packages/vue-cli-plugin-hbuilderx/__tests__/demo.js
@@ -4,7 +4,7 @@ const {
transform
} = require('@babel/core')
-transform(`console.log('123')`, {
+transform('console.log(\'123\')', {
filename: '/index.vue',
configFile: false,
minified: true,
diff --git a/packages/vue-cli-plugin-hbuilderx/build/css-loader.conf.js b/packages/vue-cli-plugin-hbuilderx/build/css-loader.conf.js
index 87cfac9e364f7c50beb8e1e7f6061f425652f93a..e2719ddfef884668ee44cdab616160c8843b2ff9 100644
--- a/packages/vue-cli-plugin-hbuilderx/build/css-loader.conf.js
+++ b/packages/vue-cli-plugin-hbuilderx/build/css-loader.conf.js
@@ -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";`
diff --git a/packages/vue-cli-plugin-hbuilderx/build/vue-loader.conf.js b/packages/vue-cli-plugin-hbuilderx/build/vue-loader.conf.js
index 8cf218c8616ae7a5546a03edc9445bffd671fa89..4b885abb0668d631cc377ea54942bb8fec4eaaaf 100644
--- a/packages/vue-cli-plugin-hbuilderx/build/vue-loader.conf.js
+++ b/packages/vue-cli-plugin-hbuilderx/build/vue-loader.conf.js
@@ -22,7 +22,7 @@ const modules = []
const deprecated = {
events: {
- 'tap': 'click'
+ tap: 'click'
}
}
diff --git a/packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js b/packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js
index ee981496457eed156c466ce7419ac633b852d64a..e5366c26e410c008a4490acfb91aac42de24e7bd 100644
--- a/packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js
+++ b/packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js
@@ -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
diff --git a/packages/vue-cli-plugin-uni-optimize/index.js b/packages/vue-cli-plugin-uni-optimize/index.js
index 33a66e3d765bb51f82c543922fe7ae161040db1c..59efcc49015ad5adcdac7f8d51db090d0f732639 100644
--- a/packages/vue-cli-plugin-uni-optimize/index.js
+++ b/packages/vue-cli-plugin-uni-optimize/index.js
@@ -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')]
})
]
}
diff --git a/packages/vue-cli-plugin-uni/commands/build.js b/packages/vue-cli-plugin-uni/commands/build.js
index 616c9c71a579548bc61e1d2d9b7d99dbd2787fcd..d9a28a74b2c5cb938e0271bf3862873125afb545 100644
--- a/packages/vue-cli-plugin-uni/commands/build.js
+++ b/packages/vue-cli-plugin-uni/commands/build.js
@@ -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') {
diff --git a/packages/vue-cli-plugin-uni/commands/info.js b/packages/vue-cli-plugin-uni/commands/info.js
index c2b5983c02f51fc43f3fd0fe46320264e765b91b..95613f09141b42c9936ec3df71aabc8eced3bb89 100644
--- a/packages/vue-cli-plugin-uni/commands/info.js
+++ b/packages/vue-cli-plugin-uni/commands/info.js
@@ -1,4 +1,4 @@
-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({
diff --git a/packages/vue-cli-plugin-uni/commands/serve.js b/packages/vue-cli-plugin-uni/commands/serve.js
index bbf8e67c822ee493633a36f405768832b9978a93..45191829e52a2fa08c54de35b5da5bccda9a87e1 100644
--- a/packages/vue-cli-plugin-uni/commands/serve.js
+++ b/packages/vue-cli-plugin-uni/commands/serve.js
@@ -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)
}
}
diff --git a/packages/vue-cli-plugin-uni/generator.js b/packages/vue-cli-plugin-uni/generator.js
index e4d2985e7b70cb9690499ff09f76b2879f508927..144d93b10ba7371e632a09b2208aa838d80432eb 100644
--- a/packages/vue-cli-plugin-uni/generator.js
+++ b/packages/vue-cli-plugin-uni/generator.js
@@ -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,
diff --git a/packages/vue-cli-plugin-uni/lib/app-plus/index.js b/packages/vue-cli-plugin-uni/lib/app-plus/index.js
index aabf9fd802ab7766ec2b356c94513b61dd0af8d3..ec47a78e24d21706a86267195e240c21b28e4b65 100644
--- a/packages/vue-cli-plugin-uni/lib/app-plus/index.js
+++ b/packages/vue-cli-plugin-uni/lib/app-plus/index.js
@@ -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,
diff --git a/packages/vue-cli-plugin-uni/lib/cache-loader.js b/packages/vue-cli-plugin-uni/lib/cache-loader.js
index af1941c8bb3aedd2760fdcf64cc0cf83b2cb642b..9b029854b833a661f1974401d6b17c8ca74df68f 100644
--- a/packages/vue-cli-plugin-uni/lib/cache-loader.js
+++ b/packages/vue-cli-plugin-uni/lib/cache-loader.js
@@ -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')
diff --git a/packages/vue-cli-plugin-uni/lib/chain-webpack.js b/packages/vue-cli-plugin-uni/lib/chain-webpack.js
index 8feb8fe0fe0d375cb2cd3f3536b1eecdfa03aeae..ede789c34adb11e6e8fc803cd645a53d5f5bb8e3 100644
--- a/packages/vue-cli-plugin-uni/lib/chain-webpack.js
+++ b/packages/vue-cli-plugin-uni/lib/chain-webpack.js
@@ -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)
diff --git a/packages/vue-cli-plugin-uni/lib/commands/custom.js b/packages/vue-cli-plugin-uni/lib/commands/custom.js
index 7f88b54ddde0a18cbba19122471403cf4baf8cf5..2d4b20bdefe8dd380e1aa0b733db848f98f6f9d6 100644
--- a/packages/vue-cli-plugin-uni/lib/commands/custom.js
+++ b/packages/vue-cli-plugin-uni/lib/commands/custom.js
@@ -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)
}
diff --git a/packages/vue-cli-plugin-uni/lib/commands/invoke.js b/packages/vue-cli-plugin-uni/lib/commands/invoke.js
index 2c2690ce5cd2855f65f256ee07e997067dfc7285..9d58d42fe6f31dd3eafcfc324364995eda82b097 100644
--- a/packages/vue-cli-plugin-uni/lib/commands/invoke.js
+++ b/packages/vue-cli-plugin-uni/lib/commands/invoke.js
@@ -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 || {
diff --git a/packages/vue-cli-plugin-uni/lib/configure-webpack.js b/packages/vue-cli-plugin-uni/lib/configure-webpack.js
index 053bb5dcb5a337f7dfbec0d3f5f7509e7ecd0508..941b50423fe4ab2cc09b8c0c3f26f9fdcb210063 100644
--- a/packages/vue-cli-plugin-uni/lib/configure-webpack.js
+++ b/packages/vue-cli-plugin-uni/lib/configure-webpack.js
@@ -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') +
diff --git a/packages/vue-cli-plugin-uni/lib/env.js b/packages/vue-cli-plugin-uni/lib/env.js
index 3c356436078095930babc9c14bf3e1ddaad95f04..bb288bd38b5406e4e8d281d27d7c9d84a783af9f 100644
--- a/packages/vue-cli-plugin-uni/lib/env.js
+++ b/packages/vue-cli-plugin-uni/lib/env.js
@@ -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
diff --git a/packages/vue-cli-plugin-uni/lib/format-log.js b/packages/vue-cli-plugin-uni/lib/format-log.js
index cc3c89bac6553f8eea96faba1d19064ce415e722..c4c97101eacbb332efe94c6883ff5a84b20067e4 100644
--- a/packages/vue-cli-plugin-uni/lib/format-log.js
+++ b/packages/vue-cli-plugin-uni/lib/format-log.js
@@ -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) {
diff --git a/packages/vue-cli-plugin-uni/lib/format-text.js b/packages/vue-cli-plugin-uni/lib/format-text.js
index 8f9a344112e8f059deec7377c77c5b8c473c7f99..8d117883e7fbd6e887881cb3c1982334896e6aaa 100644
--- a/packages/vue-cli-plugin-uni/lib/format-text.js
+++ b/packages/vue-cli-plugin-uni/lib/format-text.js
@@ -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--) {
diff --git a/packages/vue-cli-plugin-uni/lib/h5/compiler-options.js b/packages/vue-cli-plugin-uni/lib/h5/compiler-options.js
index 9da1b0e59a50f79647fcffc6a0441fda942ef00e..222138068f0dbcf3f059ef22283f3c66920e1789 100644
--- a/packages/vue-cli-plugin-uni/lib/h5/compiler-options.js
+++ b/packages/vue-cli-plugin-uni/lib/h5/compiler-options.js
@@ -28,8 +28,8 @@ function hasOwn (obj, key) {
const deprecated = {
events: {
- 'tap': 'click',
- 'longtap': 'longpress'
+ tap: 'click',
+ longtap: 'longpress'
}
}
diff --git a/packages/vue-cli-plugin-uni/lib/h5/index.js b/packages/vue-cli-plugin-uni/lib/h5/index.js
index 6f3c291a62d95bba94a900d6f10608bb1dd98552..020a51b11281060af5388b10ca0020501cc8cdca 100644
--- a/packages/vue-cli-plugin-uni/lib/h5/index.js
+++ b/packages/vue-cli-plugin-uni/lib/h5/index.js
@@ -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: [``]
+ before: ['']
}
}
}, { // 解析组件,css 等
diff --git a/packages/vue-cli-plugin-uni/lib/mp/index.js b/packages/vue-cli-plugin-uni/lib/mp/index.js
index e6100997a7dffcfd9f907a2cb5338559d832f398..f3a3efcd836b67bc5154596630feaf6a8a8961fc 100644
--- a/packages/vue-cli-plugin-uni/lib/mp/index.js
+++ b/packages/vue-cli-plugin-uni/lib/mp/index.js
@@ -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',
diff --git a/packages/vue-cli-plugin-uni/lib/options.js b/packages/vue-cli-plugin-uni/lib/options.js
index 7424e1a8bd0a46bf3ed31047cb848f5665a44de5..98a1235515b7eb4bc7a4be2a036928615fd3094f 100644
--- a/packages/vue-cli-plugin-uni/lib/options.js
+++ b/packages/vue-cli-plugin-uni/lib/options.js
@@ -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 {
diff --git a/packages/vue-cli-plugin-uni/lib/util.js b/packages/vue-cli-plugin-uni/lib/util.js
index 06bccc219d3683b5052330347af6c9d6271e40e4..33adcb2bd2e512972122aed3b3b6edeba1f2fbb4 100644
--- a/packages/vue-cli-plugin-uni/lib/util.js
+++ b/packages/vue-cli-plugin-uni/lib/util.js
@@ -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) {
diff --git a/packages/vue-cli-plugin-uni/ui.js b/packages/vue-cli-plugin-uni/ui.js
index cb4f81356ec769c0639436acd5d144c7d9e3c660..c5d8480243d55bc67716554504f4b1531ebd5f25 100644
--- a/packages/vue-cli-plugin-uni/ui.js
+++ b/packages/vue-cli-plugin-uni/ui.js
@@ -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
}
}
diff --git a/packages/webpack-uni-mp-loader/__tests__/components.spec.js b/packages/webpack-uni-mp-loader/__tests__/components.spec.js
index 66957d9714d17d23fa12a07625ee1939e8979ac5..2bb8e4319a794d6dbcfd64be08537b2a7de9f673 100644
--- a/packages/webpack-uni-mp-loader/__tests__/components.spec.js
+++ b/packages/webpack-uni-mp-loader/__tests__/components.spec.js
@@ -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)
})
})
diff --git a/packages/webpack-uni-mp-loader/lib/babel/plugin-dynamic-import.js b/packages/webpack-uni-mp-loader/lib/babel/plugin-dynamic-import.js
index 79bc3155de85fd448dc494c311a6baf25e2d5bcf..63de1b62f185001f1151ab53cb1fa3387dd94eb0 100644
--- a/packages/webpack-uni-mp-loader/lib/babel/plugin-dynamic-import.js
+++ b/packages/webpack-uni-mp-loader/lib/babel/plugin-dynamic-import.js
@@ -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) {
diff --git a/packages/webpack-uni-mp-loader/lib/babel/util.js b/packages/webpack-uni-mp-loader/lib/babel/util.js
index a17f787270e3a4725675ff754e07c84c19995b44..e9e172414e29de175b8efad90e9a8e7d0d2d1bd4 100644
--- a/packages/webpack-uni-mp-loader/lib/babel/util.js
+++ b/packages/webpack-uni-mp-loader/lib/babel/util.js
@@ -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)
diff --git a/packages/webpack-uni-mp-loader/lib/main.js b/packages/webpack-uni-mp-loader/lib/main.js
index 20ac59a5b2ead9debda348b1814ce5ad74a54168..ead6d77ee0385ee6d45f875d960a06975c6f0f12 100644
--- a/packages/webpack-uni-mp-loader/lib/main.js
+++ b/packages/webpack-uni-mp-loader/lib/main.js
@@ -56,7 +56,7 @@ module.exports = function (content) {
plugins.push([
'@babel/plugin-proposal-decorators',
{
- 'legacy': true
+ legacy: true
}
])
}
diff --git a/packages/webpack-uni-mp-loader/lib/plugin/generate-component.js b/packages/webpack-uni-mp-loader/lib/plugin/generate-component.js
index 3894dbbe531784e3fd11a889997e3d5ddb14f7c9..c77a570f86b36d998cc011cfa8548b1073badaf3 100644
--- a/packages/webpack-uni-mp-loader/lib/plugin/generate-component.js
+++ b/packages/webpack-uni-mp-loader/lib/plugin/generate-component.js
@@ -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 = ''
diff --git a/packages/webpack-uni-mp-loader/lib/plugin/generate-json.js b/packages/webpack-uni-mp-loader/lib/plugin/generate-json.js
index f7193fce7d89fee3ab729d1de3a58e5b31c502da..7393a783b7dff65d0f2724d998e34ef9b31de38d 100644
--- a/packages/webpack-uni-mp-loader/lib/plugin/generate-json.js
+++ b/packages/webpack-uni-mp-loader/lib/plugin/generate-json.js
@@ -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 || {}
diff --git a/packages/webpack-uni-mp-loader/lib/script.js b/packages/webpack-uni-mp-loader/lib/script.js
index a76a3b2189b7543313e241365a5ff33815dadd5c..92bb6ad2ba3983228b90e333a22c9f0823101c85 100644
--- a/packages/webpack-uni-mp-loader/lib/script.js
+++ b/packages/webpack-uni-mp-loader/lib/script.js
@@ -30,7 +30,7 @@ module.exports = function (content, map) {
plugins.push([
'@babel/plugin-proposal-decorators',
{
- 'legacy': true
+ legacy: true
}
])
}
diff --git a/packages/webpack-uni-mp-loader/lib/style.js b/packages/webpack-uni-mp-loader/lib/style.js
index 94a26e47d7185ac70377818685e1e50a5947b446..310d7f1a0b603bf49a02baa99d62d5f5f628dcb4 100644
--- a/packages/webpack-uni-mp-loader/lib/style.js
+++ b/packages/webpack-uni-mp-loader/lib/style.js
@@ -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))
)
diff --git a/packages/webpack-uni-pages-loader/lib/platforms/app-plus/index.js b/packages/webpack-uni-pages-loader/lib/platforms/app-plus/index.js
index 847124bc552e570d63aeb524a718448112829aa1..9d2b954037fde8076541961299652e5f802d06c4 100644
--- a/packages/webpack-uni-pages-loader/lib/platforms/app-plus/index.js
+++ b/packages/webpack-uni-pages-loader/lib/platforms/app-plus/index.js
@@ -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'
diff --git a/packages/webpack-uni-pages-loader/lib/platforms/app-plus/index.v3.js b/packages/webpack-uni-pages-loader/lib/platforms/app-plus/index.v3.js
index 0f127fbde8e261150796d56f0795999a44b29ddc..b94bbd7017c9c8100fd15219059eaa9acfc61c1e 100644
--- a/packages/webpack-uni-pages-loader/lib/platforms/app-plus/index.v3.js
+++ b/packages/webpack-uni-pages-loader/lib/platforms/app-plus/index.v3.js
@@ -75,7 +75,7 @@ module.exports = function (appJson, manifestJson, {
})
// nvue 权限
manifestJson.permissions.UniNView = {
- 'description': 'UniNView原生渲染'
+ description: 'UniNView原生渲染'
}
manifestJson.plus.launchwebview.id = '1' // 首页 id 固定 为 1
diff --git a/packages/webpack-uni-pages-loader/lib/platforms/h5.js b/packages/webpack-uni-pages-loader/lib/platforms/h5.js
index d2b606faa74972c68a2e87a92fbe2d94d89a1160..defc200ad394f46c15072b13eef38e0a212ec94f 100644
--- a/packages/webpack-uni-pages-loader/lib/platforms/h5.js
+++ b/packages/webpack-uni-pages-loader/lib/platforms/h5.js
@@ -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)};
diff --git a/packages/webpack-uni-pages-loader/lib/platforms/mp-alipay.js b/packages/webpack-uni-pages-loader/lib/platforms/mp-alipay.js
index a0872822dc0d82dd5691868198895259e35f3b0c..e3eaa5fa15d43b7b5e1bcc78eca1868d7e472ef6 100644
--- a/packages/webpack-uni-pages-loader/lib/platforms/mp-alipay.js
+++ b/packages/webpack-uni-pages-loader/lib/platforms/mp-alipay.js
@@ -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)
}
}
diff --git a/packages/webpack-uni-pages-loader/lib/platforms/mp.js b/packages/webpack-uni-pages-loader/lib/platforms/mp.js
index ca6c603fbed162472945dc2d2f997e207874ca7d..2e138319c754aeeee5befde45347ff335208c4ac 100644
--- a/packages/webpack-uni-pages-loader/lib/platforms/mp.js
+++ b/packages/webpack-uni-pages-loader/lib/platforms/mp.js
@@ -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
}
diff --git a/packages/webpack-uni-pages-loader/lib/util.js b/packages/webpack-uni-pages-loader/lib/util.js
index 2e8a479568b4a4b4a2185a59fae8fc7840644df6..8598d2c4b30d969d58982b7dbcb1b0036439b147 100644
--- a/packages/webpack-uni-pages-loader/lib/util.js
+++ b/packages/webpack-uni-pages-loader/lib/util.js
@@ -1,47 +1,49 @@
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 = {}