diff --git a/packages/uni-app-plus/dist/index.v3.js b/packages/uni-app-plus/dist/index.v3.js index 415ac4f3862e7bf55d6fc4edee65b6f403339d2f..3ecdc6d24b50d5ebc46c8b810999ddb494111668 100644 --- a/packages/uni-app-plus/dist/index.v3.js +++ b/packages/uni-app-plus/dist/index.v3.js @@ -6482,8 +6482,9 @@ var serviceContext = (function () { timestamp: Date.now() } }, [pageId]); - - createPage(route, pageId, query, pageInstance).$mount(); + try { + createPage(route, pageId, query, pageInstance).$mount(); + } catch (e) {} } } @@ -8571,9 +8572,6 @@ var serviceContext = (function () { }); function optimize (k, v) { - if (typeof v === 'undefined') { - return '' - } if ( k === V_IF || k === V_ELSE_IF || diff --git a/packages/uni-app-plus/dist/view.umd.js b/packages/uni-app-plus/dist/view.umd.js index b0a2a2baeb107475762b25a34417c6aee874907c..1057a270a08506e290eba638344f6f81d98e4a75 100644 --- a/packages/uni-app-plus/dist/view.umd.js +++ b/packages/uni-app-plus/dist/view.umd.js @@ -201,6 +201,105 @@ function normalizeComponent ( "use strict"; +// CONCATENATED MODULE: ./src/core/view/mixins/emitter.js +// 暂不提供通知所有 +// function broadcast (componentName, eventName, ...params) { +// this.$children.forEach(child => { +// const name = child.$options.name && child.$options.name.substr(1) +// if (~componentName.indexOf(name)) { +// child.$emit.apply(child, [eventName].concat(params)) +// } else { +// broadcast.apply(child, [componentName, eventName].concat([params])) +// } +// }) +// } +function broadcast(componentName, eventName) { + var children = this.$children; + var len = children.length; + + for (var _len = arguments.length, params = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { + params[_key - 2] = arguments[_key]; + } + + for (var i = 0; i < len; i++) { + var child = children[i]; + var name = child.$options.name && child.$options.name.substr(4); + + if (~componentName.indexOf(name)) { + child.$emit.apply(child, [eventName].concat(params)); + return false; + } else { + if (broadcast.apply(child, [componentName, eventName].concat([params])) === false) { + return false; + } + } + } +} + +/* harmony default export */ var emitter = ({ + methods: { + $dispatch: function $dispatch(componentName, eventName) { + if (typeof componentName === 'string') { + componentName = [componentName]; + } + + var parent = this.$parent || this.$root; + var name = parent.$options.name && parent.$options.name.substr(4); + + while (parent && (!name || !~componentName.indexOf(name))) { + parent = parent.$parent; + + if (parent) { + name = parent.$options.name && parent.$options.name.substr(4); + } + } + + if (parent) { + for (var _len2 = arguments.length, params = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) { + params[_key2 - 2] = arguments[_key2]; + } + + parent.$emit.apply(parent, [eventName].concat(params)); + } + }, + $broadcast: function $broadcast(componentName, eventName) { + if (typeof componentName === 'string') { + componentName = [componentName]; + } + + for (var _len3 = arguments.length, params = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) { + params[_key3 - 2] = arguments[_key3]; + } + + broadcast.apply(this, [componentName, eventName].concat(params)); + } + } +}); +// EXTERNAL MODULE: ./src/core/view/mixins/listeners.js +var listeners = __webpack_require__(49); + +// EXTERNAL MODULE: ./src/core/view/mixins/hover.js +var hover = __webpack_require__(12); + +// EXTERNAL MODULE: ./src/core/view/mixins/subscriber.js +var subscriber = __webpack_require__(50); + +// CONCATENATED MODULE: ./src/core/view/mixins/index.js +/* concated harmony reexport emitter */__webpack_require__.d(__webpack_exports__, "a", function() { return emitter; }); +/* concated harmony reexport listeners */__webpack_require__.d(__webpack_exports__, "c", function() { return listeners["a" /* default */]; }); +/* concated harmony reexport hover */__webpack_require__.d(__webpack_exports__, "b", function() { return hover["a" /* default */]; }); +/* concated harmony reexport subscriber */__webpack_require__.d(__webpack_exports__, "d", function() { return subscriber["a" /* default */]; }); + + + + + +/***/ }), +/* 2 */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; + // CONCATENATED MODULE: ./src/shared/env.js var supportsPassive = false; @@ -429,105 +528,6 @@ function stringifyQuery(obj) { -/***/ }), -/* 2 */ -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; - -// CONCATENATED MODULE: ./src/core/view/mixins/emitter.js -// 暂不提供通知所有 -// function broadcast (componentName, eventName, ...params) { -// this.$children.forEach(child => { -// const name = child.$options.name && child.$options.name.substr(1) -// if (~componentName.indexOf(name)) { -// child.$emit.apply(child, [eventName].concat(params)) -// } else { -// broadcast.apply(child, [componentName, eventName].concat([params])) -// } -// }) -// } -function broadcast(componentName, eventName) { - var children = this.$children; - var len = children.length; - - for (var _len = arguments.length, params = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { - params[_key - 2] = arguments[_key]; - } - - for (var i = 0; i < len; i++) { - var child = children[i]; - var name = child.$options.name && child.$options.name.substr(4); - - if (~componentName.indexOf(name)) { - child.$emit.apply(child, [eventName].concat(params)); - return false; - } else { - if (broadcast.apply(child, [componentName, eventName].concat([params])) === false) { - return false; - } - } - } -} - -/* harmony default export */ var emitter = ({ - methods: { - $dispatch: function $dispatch(componentName, eventName) { - if (typeof componentName === 'string') { - componentName = [componentName]; - } - - var parent = this.$parent || this.$root; - var name = parent.$options.name && parent.$options.name.substr(4); - - while (parent && (!name || !~componentName.indexOf(name))) { - parent = parent.$parent; - - if (parent) { - name = parent.$options.name && parent.$options.name.substr(4); - } - } - - if (parent) { - for (var _len2 = arguments.length, params = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) { - params[_key2 - 2] = arguments[_key2]; - } - - parent.$emit.apply(parent, [eventName].concat(params)); - } - }, - $broadcast: function $broadcast(componentName, eventName) { - if (typeof componentName === 'string') { - componentName = [componentName]; - } - - for (var _len3 = arguments.length, params = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) { - params[_key3 - 2] = arguments[_key3]; - } - - broadcast.apply(this, [componentName, eventName].concat(params)); - } - } -}); -// EXTERNAL MODULE: ./src/core/view/mixins/listeners.js -var listeners = __webpack_require__(49); - -// EXTERNAL MODULE: ./src/core/view/mixins/hover.js -var hover = __webpack_require__(12); - -// EXTERNAL MODULE: ./src/core/view/mixins/subscriber.js -var subscriber = __webpack_require__(50); - -// CONCATENATED MODULE: ./src/core/view/mixins/index.js -/* concated harmony reexport emitter */__webpack_require__.d(__webpack_exports__, "a", function() { return emitter; }); -/* concated harmony reexport listeners */__webpack_require__.d(__webpack_exports__, "c", function() { return listeners["a" /* default */]; }); -/* concated harmony reexport hover */__webpack_require__.d(__webpack_exports__, "b", function() { return hover["a" /* default */]; }); -/* concated harmony reexport subscriber */__webpack_require__.d(__webpack_exports__, "d", function() { return subscriber["a" /* default */]; }); - - - - - /***/ }), /* 3 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { @@ -539,7 +539,7 @@ __webpack_require__.r(__webpack_exports__); var view_runtime_esm = __webpack_require__(6); // EXTERNAL MODULE: ./src/shared/index.js + 4 modules -var shared = __webpack_require__(1); +var shared = __webpack_require__(2); // EXTERNAL MODULE: ./src/core/helpers/index.js var helpers = __webpack_require__(5); @@ -9473,7 +9473,7 @@ function getWindowOffset() { "use strict"; // EXTERNAL MODULE: ./src/shared/index.js + 4 modules -var shared = __webpack_require__(1); +var shared = __webpack_require__(2); // EXTERNAL MODULE: ./src/core/helpers/index.js var helpers = __webpack_require__(5); @@ -9859,7 +9859,7 @@ function publishHandler(event) { /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -/* WEBPACK VAR INJECTION */(function(UniViewJSBridge) {/* harmony import */ var uni_mixins__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2); +/* WEBPACK VAR INJECTION */(function(UniViewJSBridge) {/* harmony import */ var uni_mixins__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); /* harmony import */ var uni_helpers_hidpi__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(44); function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } @@ -10454,7 +10454,7 @@ function processTouches(target, touches) { /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -/* WEBPACK VAR INJECTION */(function(UniViewJSBridge) {/* harmony import */ var uni_mixins__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2); +/* WEBPACK VAR INJECTION */(function(UniViewJSBridge) {/* harmony import */ var uni_mixins__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); // // // @@ -10638,7 +10638,7 @@ function processTouches(target, touches) { /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return definePage; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return getPageVueComponent; }); /* unused harmony export createPage */ -/* harmony import */ var uni_shared__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); +/* harmony import */ var uni_shared__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2); var pageFactory = Object.create(null); function definePage(name, createPageVueComponent) { @@ -11871,7 +11871,7 @@ __webpack_require__(100); /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -/* WEBPACK VAR INJECTION */(function(UniViewJSBridge) {/* harmony import */ var uni_shared__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); +/* WEBPACK VAR INJECTION */(function(UniViewJSBridge) {/* harmony import */ var uni_shared__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2); /* harmony default export */ __webpack_exports__["a"] = ({ props: { @@ -11985,7 +11985,7 @@ __webpack_require__(100); /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -/* WEBPACK VAR INJECTION */(function(UniViewJSBridge) {/* harmony import */ var uni_shared__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); +/* WEBPACK VAR INJECTION */(function(UniViewJSBridge) {/* harmony import */ var uni_shared__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2); /* harmony default export */ __webpack_exports__["a"] = ({ // 取消id的定义,某些组件(canvas)内不在props内定义id @@ -12626,7 +12626,7 @@ function pageMounted() { "use strict"; /* WEBPACK VAR INJECTION */(function(global) {/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return createComponentDescriptor; }); -/* harmony import */ var uni_shared__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); +/* harmony import */ var uni_shared__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } @@ -12845,11 +12845,10 @@ function createComponentDescriptor(vm) { "use strict"; /* WEBPACK VAR INJECTION */(function(UniViewJSBridge) {/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return initData; }); /* harmony import */ var vue__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6); -/* harmony import */ var uni_shared__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1); -/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(4); -/* harmony import */ var _vdom_sync__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(57); -/* harmony import */ var _page__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(40); -/* harmony import */ var _page_factory__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(39); +/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(4); +/* harmony import */ var _vdom_sync__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(57); +/* harmony import */ var _page__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(40); +/* harmony import */ var _page_factory__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(39); var _handleData; function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } @@ -12867,26 +12866,25 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } - var vd; var PageVueComponent; -var handleData = (_handleData = {}, _defineProperty(_handleData, _constants__WEBPACK_IMPORTED_MODULE_2__[/* PAGE_CREATE */ "c"], function onPageCreate(data) { +var handleData = (_handleData = {}, _defineProperty(_handleData, _constants__WEBPACK_IMPORTED_MODULE_1__[/* PAGE_CREATE */ "c"], function onPageCreate(data) { var _data = _slicedToArray(data, 2), pageId = _data[0], pagePath = _data[1]; document.title = "".concat(pagePath, "[").concat(pageId, "]"); // 设置当前页面伪对象,方便其他地方使用 getCurrentPages 获取当前页面 id,route - Object(_page__WEBPACK_IMPORTED_MODULE_4__[/* setCurrentPage */ "b"])(pageId, pagePath); // 初始化当前页面 VueComponent(生成页面样式代码) + Object(_page__WEBPACK_IMPORTED_MODULE_3__[/* setCurrentPage */ "b"])(pageId, pagePath); // 初始化当前页面 VueComponent(生成页面样式代码) - PageVueComponent = Object(_page_factory__WEBPACK_IMPORTED_MODULE_5__[/* getPageVueComponent */ "b"])(pagePath); // 生成当前页面 vd + PageVueComponent = Object(_page_factory__WEBPACK_IMPORTED_MODULE_4__[/* getPageVueComponent */ "b"])(pagePath); // 生成当前页面 vd - vd = new _vdom_sync__WEBPACK_IMPORTED_MODULE_3__[/* VDomSync */ "a"](pageId); -}), _defineProperty(_handleData, _constants__WEBPACK_IMPORTED_MODULE_2__[/* MOUNTED_DATA */ "b"], function onMounted(data) { + vd = new _vdom_sync__WEBPACK_IMPORTED_MODULE_2__[/* VDomSync */ "a"](pageId); +}), _defineProperty(_handleData, _constants__WEBPACK_IMPORTED_MODULE_1__[/* MOUNTED_DATA */ "b"], function onMounted(data) { vd.addVData.apply(vd, data); -}), _defineProperty(_handleData, _constants__WEBPACK_IMPORTED_MODULE_2__[/* UPDATED_DATA */ "e"], function onUpdated(data) { +}), _defineProperty(_handleData, _constants__WEBPACK_IMPORTED_MODULE_1__[/* UPDATED_DATA */ "e"], function onUpdated(data) { vd.updateVData.apply(vd, data); -}), _defineProperty(_handleData, _constants__WEBPACK_IMPORTED_MODULE_2__[/* PAGE_CREATED */ "d"], function onPageCreated(data) { +}), _defineProperty(_handleData, _constants__WEBPACK_IMPORTED_MODULE_1__[/* PAGE_CREATED */ "d"], function onPageCreated(data) { var _data2 = _slicedToArray(data, 2), pageId = _data2[0], pagePath = _data2[1]; @@ -12903,7 +12901,7 @@ function vdSync(_ref) { options = _ref.options; var isVdCallback = true; data.forEach(function (data) { - if (data[0] === _constants__WEBPACK_IMPORTED_MODULE_2__[/* PAGE_CREATE */ "c"]) { + if (data[0] === _constants__WEBPACK_IMPORTED_MODULE_1__[/* PAGE_CREATE */ "c"]) { // 页面创建无需触发 callback isVdCallback = false; } @@ -12912,24 +12910,17 @@ function vdSync(_ref) { }); vd.flush(); isVdCallback && vue__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"].nextTick(function () { - UniViewJSBridge.publishHandler(_constants__WEBPACK_IMPORTED_MODULE_2__[/* VD_SYNC_CALLBACK */ "f"]); + UniViewJSBridge.publishHandler(_constants__WEBPACK_IMPORTED_MODULE_1__[/* VD_SYNC_CALLBACK */ "f"]); }); } function getData(id, name) { var isFallbackContent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; - var root = this.$r; - if (Object(uni_shared__WEBPACK_IMPORTED_MODULE_1__[/* hasOwn */ "c"])(root, id)) { - var vNodeData = root[id]; - - if (Object(uni_shared__WEBPACK_IMPORTED_MODULE_1__[/* hasOwn */ "c"])(vNodeData, name)) { - return vNodeData[name]; - } else { - !isFallbackContent && console.error(this.$options.__file + ":[".concat(this._$id, "]$r[").concat(id, "][").concat(name, "] is undefined")); - } - } else { - !isFallbackContent && console.error(this.$options.__file + ":[".concat(this._$id, "]$r[").concat(id, "] is undefined")); + try { + return this.$r[id][name]; + } catch (e) { + !isFallbackContent && console.error(this.$options.__file + ":[".concat(this._$id, "]$r[").concat(id, "][").concat(name, "] is undefined")); } } @@ -12963,7 +12954,7 @@ function initData(Vue) { "use strict"; /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return VDomSync; }); -/* harmony import */ var uni_shared__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); +/* harmony import */ var uni_shared__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2); function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } @@ -13093,10 +13084,10 @@ function initEvent(Vue) { "use strict"; // EXTERNAL MODULE: ./src/shared/index.js + 4 modules -var shared = __webpack_require__(1); +var shared = __webpack_require__(2); // EXTERNAL MODULE: ./src/core/view/mixins/index.js + 1 modules -var mixins = __webpack_require__(2); +var mixins = __webpack_require__(1); // CONCATENATED MODULE: ./src/core/view/plugins/behaviors/form-field.js /** @@ -14754,7 +14745,7 @@ function parseHtml(html) { return results.children; } // EXTERNAL MODULE: ./src/shared/index.js + 4 modules -var shared = __webpack_require__(1); +var shared = __webpack_require__(2); // CONCATENATED MODULE: ./src/core/view/components/rich-text/nodes-parser.js @@ -16165,7 +16156,7 @@ render._withStripped = true // CONCATENATED MODULE: ./src/core/view/components/radio-group/index.vue?vue&type=template&id=17be8d0a& // EXTERNAL MODULE: ./src/core/view/mixins/index.js + 1 modules -var mixins = __webpack_require__(2); +var mixins = __webpack_require__(1); // CONCATENATED MODULE: ./node_modules/@vue/cli-service/node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/@vue/cli-plugin-babel/node_modules/babel-loader/lib!./node_modules/@vue/cli-service/node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/@vue/cli-service/node_modules/vue-loader/lib??vue-loader-options!./src/core/view/components/radio-group/index.vue?vue&type=script&lang=js& // @@ -16357,7 +16348,7 @@ render._withStripped = true // CONCATENATED MODULE: ./src/core/view/components/switch/index.vue?vue&type=template&id=04951fe6& // EXTERNAL MODULE: ./src/core/view/mixins/index.js + 1 modules -var mixins = __webpack_require__(2); +var mixins = __webpack_require__(1); // CONCATENATED MODULE: ./node_modules/@vue/cli-service/node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/@vue/cli-plugin-babel/node_modules/babel-loader/lib!./node_modules/@vue/cli-service/node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/@vue/cli-service/node_modules/vue-loader/lib??vue-loader-options!./src/core/view/components/switch/index.vue?vue&type=script&lang=js& // @@ -16730,7 +16721,7 @@ render._withStripped = true // CONCATENATED MODULE: ./src/core/view/components/radio/index.vue?vue&type=template&id=4b562a50& // EXTERNAL MODULE: ./src/core/view/mixins/index.js + 1 modules -var mixins = __webpack_require__(2); +var mixins = __webpack_require__(1); // CONCATENATED MODULE: ./node_modules/@vue/cli-service/node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/@vue/cli-plugin-babel/node_modules/babel-loader/lib!./node_modules/@vue/cli-service/node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/@vue/cli-service/node_modules/vue-loader/lib??vue-loader-options!./src/core/view/components/radio/index.vue?vue&type=script&lang=js& // @@ -16901,7 +16892,7 @@ render._withStripped = true var scroller = __webpack_require__(43); // EXTERNAL MODULE: ./src/shared/index.js + 4 modules -var shared = __webpack_require__(1); +var shared = __webpack_require__(2); // CONCATENATED MODULE: ./node_modules/@vue/cli-service/node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/@vue/cli-plugin-babel/node_modules/babel-loader/lib!./node_modules/@vue/cli-service/node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/@vue/cli-service/node_modules/vue-loader/lib??vue-loader-options!./src/core/view/components/scroll-view/index.vue?vue&type=script&lang=js& // @@ -17474,7 +17465,7 @@ render._withStripped = true // CONCATENATED MODULE: ./src/core/view/components/checkbox-group/index.vue?vue&type=template&id=37cde58e& // EXTERNAL MODULE: ./src/core/view/mixins/index.js + 1 modules -var mixins = __webpack_require__(2); +var mixins = __webpack_require__(1); // CONCATENATED MODULE: ./node_modules/@vue/cli-service/node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/@vue/cli-plugin-babel/node_modules/babel-loader/lib!./node_modules/@vue/cli-service/node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/@vue/cli-service/node_modules/vue-loader/lib??vue-loader-options!./src/core/view/components/checkbox-group/index.vue?vue&type=script&lang=js& // @@ -17710,7 +17701,7 @@ render._withStripped = true // CONCATENATED MODULE: ./src/core/view/components/textarea/index.vue?vue&type=template&id=33f82dda& // EXTERNAL MODULE: ./src/core/view/mixins/index.js + 1 modules -var mixins = __webpack_require__(2); +var mixins = __webpack_require__(1); // CONCATENATED MODULE: ./node_modules/@vue/cli-service/node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/@vue/cli-plugin-babel/node_modules/babel-loader/lib!./node_modules/@vue/cli-service/node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/@vue/cli-service/node_modules/vue-loader/lib??vue-loader-options!./src/core/view/components/textarea/index.vue?vue&type=script&lang=js& // @@ -18283,7 +18274,7 @@ render._withStripped = true // CONCATENATED MODULE: ./src/core/view/components/form/index.vue?vue&type=template&id=7735a91d& // EXTERNAL MODULE: ./src/core/view/mixins/index.js + 1 modules -var mixins = __webpack_require__(2); +var mixins = __webpack_require__(1); // CONCATENATED MODULE: ./node_modules/@vue/cli-service/node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/@vue/cli-plugin-babel/node_modules/babel-loader/lib!./node_modules/@vue/cli-service/node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/@vue/cli-service/node_modules/vue-loader/lib??vue-loader-options!./src/core/view/components/form/index.vue?vue&type=script&lang=js& // @@ -18509,7 +18500,7 @@ render._withStripped = true // CONCATENATED MODULE: ./src/core/view/components/navigator/index.vue?vue&type=template&id=c893a598& // EXTERNAL MODULE: ./src/core/view/mixins/index.js + 1 modules -var mixins = __webpack_require__(2); +var mixins = __webpack_require__(1); // CONCATENATED MODULE: ./node_modules/@vue/cli-service/node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/@vue/cli-plugin-babel/node_modules/babel-loader/lib!./node_modules/@vue/cli-service/node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/@vue/cli-service/node_modules/vue-loader/lib??vue-loader-options!./src/core/view/components/navigator/index.vue?vue&type=script&lang=js& // @@ -18834,7 +18825,7 @@ render._withStripped = true // CONCATENATED MODULE: ./src/core/view/components/input/index.vue?vue&type=template&id=c65e1032& // EXTERNAL MODULE: ./src/core/view/mixins/index.js + 1 modules -var mixins = __webpack_require__(2); +var mixins = __webpack_require__(1); // CONCATENATED MODULE: ./node_modules/@vue/cli-service/node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/@vue/cli-plugin-babel/node_modules/babel-loader/lib!./node_modules/@vue/cli-service/node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/@vue/cli-service/node_modules/vue-loader/lib??vue-loader-options!./src/core/view/components/input/index.vue?vue&type=script&lang=js& // @@ -19287,7 +19278,7 @@ render._withStripped = true // CONCATENATED MODULE: ./src/core/view/components/slider/index.vue?vue&type=template&id=1969bd7a& // EXTERNAL MODULE: ./src/core/view/mixins/index.js + 1 modules -var mixins = __webpack_require__(2); +var mixins = __webpack_require__(1); // EXTERNAL MODULE: ./src/core/view/mixins/touchtrack.js var touchtrack = __webpack_require__(8); @@ -19820,7 +19811,7 @@ render._withStripped = true // CONCATENATED MODULE: ./src/core/view/components/checkbox/index.vue?vue&type=template&id=a63c1348& // EXTERNAL MODULE: ./src/core/view/mixins/index.js + 1 modules -var mixins = __webpack_require__(2); +var mixins = __webpack_require__(1); // CONCATENATED MODULE: ./node_modules/@vue/cli-service/node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/@vue/cli-plugin-babel/node_modules/babel-loader/lib!./node_modules/@vue/cli-service/node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/@vue/cli-service/node_modules/vue-loader/lib??vue-loader-options!./src/core/view/components/checkbox/index.vue?vue&type=script&lang=js& // @@ -21195,7 +21186,7 @@ component.options.__file = "src/core/view/components/text/index.vue" __webpack_require__.r(__webpack_exports__); // EXTERNAL MODULE: ./src/core/view/mixins/index.js + 1 modules -var mixins = __webpack_require__(2); +var mixins = __webpack_require__(1); // CONCATENATED MODULE: ./node_modules/@vue/cli-service/node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/@vue/cli-plugin-babel/node_modules/babel-loader/lib!./node_modules/@vue/cli-service/node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/@vue/cli-service/node_modules/vue-loader/lib??vue-loader-options!./src/core/view/components/button/index.vue?vue&type=script&lang=js& diff --git a/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.service.spec.js b/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.service.spec.js index 2b1366a1a6a77234a3906f03941fb06e00c9f85e..c6560982a3c3efbc7e7d9fab04e74a07659682e7 100644 --- a/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.service.spec.js +++ b/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.service.spec.js @@ -19,11 +19,11 @@ describe('codegen', () => { ) assertCodegen( '
', - `with(this){return _c('div',{attrs:{"_i":0}},[_l((_$f(1,{forItems:items})),function(item,$10,$20,$30){return [_c('div',{key:_$f(1,{forIndex:$20,keyIndex:0,key:1+'-0'+$30}),attrs:{"_i":("2-"+$30)}}),_c('div',{key:_$f(1,{forIndex:$20,keyIndex:1,key:1+'-1'+$30}),attrs:{"_i":("3-"+$30)}})]})],2)}` + `with(this){return _c('div',[_l((_$f(1,{forItems:items})),function(item,$10,$20,$30){return [_c('div',{key:_$f(1,{forIndex:$20,keyIndex:0,key:1+'-0'+$30})}),_c('div',{key:_$f(1,{forIndex:$20,keyIndex:1,key:1+'-1'+$30})})]})],2)}` ) assertCodegen( '
', - `with(this){return _c('div',{attrs:{"_i":0}},[_l((_$f(1,{forItems:items})),function(item,$10,$20,$30){return [_c('div',{key:_$f(1,{forIndex:$20,keyIndex:0,key:item.id+'_0'}),attrs:{"_i":("2-"+$30)}}),_c('div',{key:_$f(1,{forIndex:$20,keyIndex:1,key:item.id+'_1'}),attrs:{"_i":("3-"+$30)}})]})],2)}` + `with(this){return _c('div',[_l((_$f(1,{forItems:items})),function(item,$10,$20,$30){return [_c('div',{key:_$f(1,{forIndex:$20,keyIndex:0,key:item.id+'_0'})}),_c('div',{key:_$f(1,{forIndex:$20,keyIndex:1,key:item.id+'_1'})})]})],2)}` ) }) it('generate directive', () => { @@ -35,33 +35,33 @@ describe('codegen', () => { it('generate v-for directive', () => { assertCodegen( '
', - `with(this){return _c('div',{attrs:{"_i":0}},[_l((_$f(1,{forItems:items})),function(item,$10,$20,$30){return [_c('div',{key:_$f(1,{forIndex:$20,keyIndex:0,key:1+'-0'+$30}),attrs:{"_i":("2-"+$30)}}),_c('div',{key:_$f(1,{forIndex:$20,keyIndex:1,key:1+'-1'+$30}),attrs:{"_i":("3-"+$30)}})]})],2)}` + `with(this){return _c('div',[_l((_$f(1,{forItems:items})),function(item,$10,$20,$30){return [_c('div',{key:_$f(1,{forIndex:$20,keyIndex:0,key:1+'-0'+$30})}),_c('div',{key:_$f(1,{forIndex:$20,keyIndex:1,key:1+'-1'+$30})})]})],2)}` ) assertCodegen( '
', - `with(this){return _c('div',{attrs:{"_i":0}},[_l((_$f(1,{forItems:items})),function(item,$10,$20,$30){return [_c('text',{key:_$f(1,{forIndex:$20,keyIndex:0,key:1+'-0'+$30}),attrs:{"_i":("1-"+$30)}})]})],2)}` + `with(this){return _c('div',[_l((_$f(1,{forItems:items})),function(item,$10,$20,$30){return [_c('text',{key:_$f(1,{forIndex:$20,keyIndex:0,key:1+'-0'+$30}),attrs:{"_i":("1-"+$30)}})]})],2)}` ) assertCodegen( '
', - `with(this){return _c('div',{attrs:{"_i":0}},[_l((_$f(1,{forItems:items})),function(item,$10,$20,$30){return [_c('text',{key:_$f(1,{forIndex:$20,keyIndex:0,key:1+'-0'+$30}),extras:{t0:_s(text)},attrs:{"_i":("1-"+$30)}})]})],2)}` + `with(this){return _c('div',[_l((_$f(1,{forItems:items})),function(item,$10,$20,$30){return [_c('text',{key:_$f(1,{forIndex:$20,keyIndex:0,key:1+'-0'+$30}),extras:{t0:_s(text)},attrs:{"_i":("1-"+$30)}})]})],2)}` ) assertCodegen( '
', - `with(this){return _c('div',{attrs:{"_i":0}},[_l((_$f(1,{forItems:items})),function(item,$10,$20,$30){return [_c('span',{key:_$f(1,{forIndex:$20,keyIndex:0,key:1+'-0'+$30}),attrs:{"_i":("2-"+$30)}}),_c('text',{extras:{t0:_s(text)},attrs:{"_i":("1-"+$30)}})]})],2)}` + `with(this){return _c('div',[_l((_$f(1,{forItems:items})),function(item,$10,$20,$30){return [_c('span',{key:_$f(1,{forIndex:$20,keyIndex:0,key:1+'-0'+$30})}),_c('text',{extras:{t0:_s(text)},attrs:{"_i":("1-"+$30)}})]})],2)}` ) assertCodegen( '
', - `with(this){return _c('div',{attrs:{"_i":0}},[_l((_$f(1,{forItems:items})),function(item,$10,$20,$30){return [_c('text',{key:_$f(1,{forIndex:$20,keyIndex:0,key:1+'-0'+$30}),extras:{t0:_s(text1),t1:_s(text2)},attrs:{"_i":("1-"+$30)}})]})],2)}` + `with(this){return _c('div',[_l((_$f(1,{forItems:items})),function(item,$10,$20,$30){return [_c('text',{key:_$f(1,{forIndex:$20,keyIndex:0,key:1+'-0'+$30}),extras:{t0:_s(text1),t1:_s(text2)},attrs:{"_i":("1-"+$30)}})]})],2)}` ) assertCodegen( '
', - `with(this){return _c('div',{attrs:{"_i":0}},[_l((_$f(1,{forItems:items})),function(item,$10,$20,$30){return [(_$i(("2-"+$30),item.sub))?_c('span',{key:_$f(1,{forIndex:$20,keyIndex:0,key:1+'-0'+$30}),attrs:{"_i":("2-"+$30)}}):_e()]})],2)}` + `with(this){return _c('div',[_l((_$f(1,{forItems:items})),function(item,$10,$20,$30){return [(_$i(("2-"+$30),item.sub))?_c('span',{key:_$f(1,{forIndex:$20,keyIndex:0,key:1+'-0'+$30})}):_e()]})],2)}` ) }) it('generate text with multiple statements', () => { assertCodegen( '
A{{ d | e | f }}B{{text}}C
', - `with(this){return _c('div',{attrs:{"_i":0}},[_c('text',{extras:{t0:_s(_f("f")(_f("e")(d))),t1:_s(text)},attrs:{"_i":0}})])}` + `with(this){return _c('div',[_c('text',{extras:{t0:_s(_f("f")(_f("e")(d))),t1:_s(text)},attrs:{"_i":0}})])}` ) }) }) diff --git a/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.view.spec.js b/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.view.spec.js index 588c9cebda96bdf70bd0b0d1562587d3a36c562d..f73896befcac72f8decf27dc23e806dd531af397 100644 --- a/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.view.spec.js +++ b/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.view.spec.js @@ -17,28 +17,28 @@ describe('codegen', () => { '

', `with(this){return _c('v-uni-view',{directives:[{name:"custom1",rawName:"v-custom1:[arg1].modifier",value:(_$g(0,'v-custom1')),expression:"_$g(0,'v-custom1')",arg:_$g(0,'v-custom1-arg'),modifiers:{"modifier":true}},{name:"custom2",rawName:"v-custom2"}],attrs:{"_i":0}})}` ) - }) - it('generate v-for directive', () => { - assertCodegen( - '
', - `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_l((_$g(1,'f')),function(item,$10,$20,$30){return [_c('v-uni-view',{key:item['k0'],attrs:{"_i":("2-"+$30)}}),_c('v-uni-view',{key:item['k1'],attrs:{"_i":("3-"+$30)}})]})],2)}` - ) - assertCodegen( - '
', - `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_l((_$g(1,'f')),function(item,$10,$20,$30){return [(_$g(("2-"+$30),'i'))?_c('v-uni-label',{key:item['k0'],attrs:{"_i":("2-"+$30)}}):_e()]})],2)}` - ) - }) - it('generate events with multiple statements', () => { - assertCodegen( - '
A{{ d | e | f }}B{{text}}C
', - `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_v("A"+(_$g(0,'t0'))+"B"+(_$g(0,'t1'))+"C")])}` - ) - }) - it('generate slot fallback content', () => { - assertCodegen( - '
{{hi}}
', - `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_t("default",[_c('v-uni-view',{attrs:{"_i":2}},[_v((_$g(2,'t0',1)))])],{"_i":1})],2)}` - ) + }) + it('generate v-for directive', () => { + assertCodegen( + '
', + `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_l((_$g(1,'f')),function(item,$10,$20,$30){return [_c('v-uni-view',{key:item['k0'],attrs:{"_i":("2-"+$30)}}),_c('v-uni-view',{key:item['k1'],attrs:{"_i":("3-"+$30)}})]})],2)}` + ) + assertCodegen( + '
', + `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_l((_$g(1,'f')),function(item,$10,$20,$30){return [(_$g(("2-"+$30),'i'))?_c('v-uni-label',{key:item['k0'],attrs:{"_i":("2-"+$30)}}):_e()]})],2)}` + ) + }) + it('generate events with multiple statements', () => { + assertCodegen( + '
A{{ d | e | f }}B{{text}}C
', + `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_v("A"+(_$g(0,'t0'))+"B"+(_$g(0,'t1'))+"C")])}` + ) + }) + it('generate slot fallback content', () => { + assertCodegen( + '
{{hi}}
', + `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_t("default",[_c('v-uni-view',{attrs:{"_i":2}},[_v((_$g(2,'t0',1)))])],{"_i":1})],2)}` + ) }) }) -/* eslint-enable quotes */ +/* eslint-enable quotes */ diff --git a/packages/uni-template-compiler/__tests__/compiler-app-plus.service.spec.js b/packages/uni-template-compiler/__tests__/compiler-app-plus.service.spec.js index 8b8e5af9834601bac05ad395bc66547ea72840cb..2fd1a712e1197f497efada6dffe86385e5395913 100644 --- a/packages/uni-template-compiler/__tests__/compiler-app-plus.service.spec.js +++ b/packages/uni-template-compiler/__tests__/compiler-app-plus.service.spec.js @@ -34,86 +34,86 @@ describe('codegen', () => { it('generate filters with no arguments', () => { assertCodegen( '
{{ d | e() }}
', - `with(this){return _c('div',{attrs:{"_i":0}},[_c('text',{extras:{t0:_s(_f("e")(d))},attrs:{"_i":0}})])}` + `with(this){return _c('div',[_c('text',{extras:{t0:_s(_f("e")(d))},attrs:{"_i":0}})])}` ) }) it('generate v-for directive', () => { assertCodegen( '
  • ', - `with(this){return _c('div',{attrs:{"_i":0}},_l((_$f(1,{forItems:items})),function(item,$10,$20,$30){return _c('li',{key:_$f(1,{forIndex:$20,key:item.uid}),attrs:{"_i":("1-"+$30)}})}),0)}` + `with(this){return _c('div',_l((_$f(1,{forItems:items})),function(item,$10,$20,$30){return _c('li',{key:_$f(1,{forIndex:$20,key:item.uid})})}),0)}` ) // iterator syntax assertCodegen( '
  • ', - `with(this){return _c('div',{attrs:{"_i":0}},_l((_$f(1,{forItems:items})),function(item,i,$20,$30){return _c('li',{key:_$f(1,{forIndex:$20,key:1+'-'+$30}),attrs:{"_i":("1-"+$30)}})}),0)}` + `with(this){return _c('div',_l((_$f(1,{forItems:items})),function(item,i,$20,$30){return _c('li',{key:_$f(1,{forIndex:$20,key:1+'-'+$30})})}),0)}` ) assertCodegen( '
  • ', - `with(this){return _c('div',{attrs:{"_i":0}},_l((_$f(1,{forItems:items})),function(item,key,index,$30){return _c('li',{key:_$f(1,{forIndex:index,key:1+'-'+$30}),attrs:{"_i":("1-"+$30)}})}),0)}` + `with(this){return _c('div',_l((_$f(1,{forItems:items})),function(item,key,index,$30){return _c('li',{key:_$f(1,{forIndex:index,key:1+'-'+$30})})}),0)}` ) // destructuring assertCodegen( '
  • ', - `with(this){return _c('div',{attrs:{"_i":0}},_l((_$f(1,{forItems:items})),function({ a, b },$10,$20,$30){return _c('li',{key:_$f(1,{forIndex:$20,key:1+'-'+$30}),attrs:{"_i":("1-"+$30)}})}),0)}` + `with(this){return _c('div',_l((_$f(1,{forItems:items})),function({ a, b },$10,$20,$30){return _c('li',{key:_$f(1,{forIndex:$20,key:1+'-'+$30})})}),0)}` ) assertCodegen( '
  • ', - `with(this){return _c('div',{attrs:{"_i":0}},_l((_$f(1,{forItems:items})),function({ a, b },key,index,$30){return _c('li',{key:_$f(1,{forIndex:index,key:1+'-'+$30}),attrs:{"_i":("1-"+$30)}})}),0)}` + `with(this){return _c('div',_l((_$f(1,{forItems:items})),function({ a, b },key,index,$30){return _c('li',{key:_$f(1,{forIndex:index,key:1+'-'+$30})})}),0)}` ) // v-for with extra element assertCodegen( '

  • ', - `with(this){return _c('div',{attrs:{"_i":0}},[_c('p',{attrs:{"_i":1}}),_l((_$f(2,{forItems:items})),function(item,$10,$20,$30){return _c('li',{key:_$f(2,{forIndex:$20,key:2+'-'+$30}),attrs:{"_i":("2-"+$30)}})})],2)}` + `with(this){return _c('div',[_c('p'),_l((_$f(2,{forItems:items})),function(item,$10,$20,$30){return _c('li',{key:_$f(2,{forIndex:$20,key:2+'-'+$30})})})],2)}` ) }) it('generate v-if directive', () => { assertCodegen( '

    hello

    ', - `with(this){return (_$i(0,show))?_c('p',{attrs:{"_i":0}}):_e()}` + `with(this){return (_$i(0,show))?_c('p'):_e()}` ) }) it('generate v-else directive', () => { assertCodegen( '

    hello

    world

    ', - `with(this){return _c('div',{attrs:{"_i":0}},[(_$i(1,show))?_c('p',{attrs:{"_i":1}}):_c('p',{attrs:{"_i":2}})])}` + `with(this){return _c('div',[(_$i(1,show))?_c('p'):_c('p')])}` ) }) it('generate v-else-if directive', () => { assertCodegen( '

    hello

    world

    ', - `with(this){return _c('div',{attrs:{"_i":0}},[(_$i(1,show))?_c('p',{attrs:{"_i":1}}):(_$e(2,hide))?_c('p',{attrs:{"_i":2}}):_e()])}` + `with(this){return _c('div',[(_$i(1,show))?_c('p'):(_$e(2,hide))?_c('p'):_e()])}` ) }) it('generate v-else-if with v-else directive', () => { assertCodegen( '

    hello

    world

    bye

    ', - `with(this){return _c('div',{attrs:{"_i":0}},[(_$i(1,show))?_c('p',{attrs:{"_i":1}}):(_$e(2,hide))?_c('p',{attrs:{"_i":2}}):_c('p',{attrs:{"_i":3}})])}` + `with(this){return _c('div',[(_$i(1,show))?_c('p'):(_$e(2,hide))?_c('p'):_c('p')])}` ) }) it('generate multi v-else-if with v-else directive', () => { assertCodegen( '

    hello

    world

    elseif

    bye

    ', - `with(this){return _c('div',{attrs:{"_i":0}},[(_$i(1,show))?_c('p',{attrs:{"_i":1}}):(_$e(2,hide))?_c('p',{attrs:{"_i":2}}):(3)?_c('p',{attrs:{"_i":3}}):_c('p',{attrs:{"_i":4}})])}` + `with(this){return _c('div',[(_$i(1,show))?_c('p'):(_$e(2,hide))?_c('p'):(3)?_c('p'):_c('p')])}` ) }) it('generate ref', () => { assertCodegen( '

    ', - `with(this){return _c('p',{ref:"component1",attrs:{"_i":0}})}` + `with(this){return _c('p',{ref:"component1"})}` ) }) it('generate ref on v-for', () => { assertCodegen( '', - `with(this){return _c('ul',{attrs:{"_i":0}},_l((_$f(1,{forItems:items})),function(item,$10,$20,$30){return _c('li',{key:_$f(1,{forIndex:$20,key:1+'-'+$30}),ref:"component1",refInFor:true,attrs:{"_i":("1-"+$30)}})}),0)}` + `with(this){return _c('ul',_l((_$f(1,{forItems:items})),function(item,$10,$20,$30){return _c('li',{key:_$f(1,{forIndex:$20,key:1+'-'+$30}),ref:"component1",refInFor:true})}),0)}` ) }) @@ -162,35 +162,35 @@ describe('codegen', () => { it('generate template tag', () => { assertCodegen( '
    ', - `with(this){return _c('div',{attrs:{"_i":0}},[[_c('p',{attrs:{"_i":2}},[_c('text',{extras:{t0:_s(hello)},attrs:{"_i":2}})])]],2)}` + `with(this){return _c('div',[[_c('p',[_c('text',{extras:{t0:_s(hello)},attrs:{"_i":2}})])]],2)}` ) }) it('generate single slot', () => { assertCodegen( '
    ', - `with(this){return _c('div',{attrs:{"_i":0}},[_t("default",null,{"_i":1})],2)}` + `with(this){return _c('div',[_t("default",null,{"_i":1})],2)}` ) }) it('generate named slot', () => { assertCodegen( '
    ', - `with(this){return _c('div',{attrs:{"_i":0}},[_t("one",null,{"_i":1})],2)}` + `with(this){return _c('div',[_t("one",null,{"_i":1})],2)}` ) }) it('generate slot fallback content', () => { assertCodegen( '
    hi
    ', - `with(this){return _c('div',{attrs:{"_i":0}},[_t("default",[_c('div',{attrs:{"_i":2}})],{"_i":1})],2)}` + `with(this){return _c('div',[_t("default",[_c('div')],{"_i":1})],2)}` ) }) it('generate slot target', () => { assertCodegen( '

    hello world

    ', - `with(this){return _c('p',{attrs:{"_i":0},slot:"one"})}` + `with(this){return _c('p',{slot:"one"})}` ) }) @@ -245,7 +245,7 @@ describe('codegen', () => { // static assertCodegen( '

    hello world

    ', - `with(this){return _c('p',{attrs:{"_i":0}})}` + `with(this){return _c('p')}` ) // dynamic assertCodegen( @@ -291,7 +291,7 @@ describe('codegen', () => { it('generate static attrs', () => { assertCodegen( '', - `with(this){return _c('input',{attrs:{"_i":0}})}` + `with(this){return _c('input')}` ) }) @@ -558,7 +558,7 @@ describe('codegen', () => { it('generate component', () => { assertCodegen( '
    hi
    ', - `with(this){return _c('my-component',{attrs:{"name":"mycomponent1","msg":msg,"_i":0},on:{"notify":onNotify}},[_c('div',{attrs:{"_i":1}})])}` + `with(this){return _c('my-component',{attrs:{"name":"mycomponent1","msg":msg,"_i":0},on:{"notify":onNotify}},[_c('div')])}` ) }) @@ -572,16 +572,16 @@ describe('codegen', () => { it('generate is attribute', () => { assertCodegen( '
    ', - `with(this){return _c("component1",{tag:"div",attrs:{"_i":0}})}` + `with(this){return _c("component1",{tag:"div"})}` ) assertCodegen( '
    ', - `with(this){return _c(component1,{tag:"div",attrs:{"_i":0}})}` + `with(this){return _c(component1,{tag:"div"})}` ) // maybe a component and normalize type should be 1 assertCodegen( '
    ', - `with(this){return _c('div',{attrs:{"_i":0}},[_c("component1",{tag:"div",attrs:{"_i":1}})],1)}` + `with(this){return _c('div',[_c("component1",{tag:"div"})],1)}` ) }) @@ -589,12 +589,12 @@ describe('codegen', () => { // have "inline-template'" assertCodegen( '

    hello world

    ', - `with(this){return _c('my-component',{attrs:{"_i":0},inlineTemplate:{render:function(){with(this){return _m(0)}},staticRenderFns:[function(){with(this){return _c('p',{attrs:{"_i":1}},[_c('span',{attrs:{"_i":2}})])}}]}})}` + `with(this){return _c('my-component',{attrs:{"_i":0},inlineTemplate:{render:function(){with(this){return _m(0)}},staticRenderFns:[function(){with(this){return _c('p',[_c('span')])}}]}})}` ) // "have inline-template attrs, but not having exactly one child element assertCodegen( '

    ', - `with(this){return _c('my-component',{attrs:{"_i":0},inlineTemplate:{render:function(){with(this){return _c('hr',{attrs:{"_i":1}})}},staticRenderFns:[]}})}` + `with(this){return _c('my-component',{attrs:{"_i":0},inlineTemplate:{render:function(){with(this){return _c('hr')}},staticRenderFns:[]}})}` ) assertCodegen( '', @@ -603,11 +603,11 @@ describe('codegen', () => { // have "is" attribute assertCodegen( '
    ', - `with(this){return _c("myComponent",{tag:"div",attrs:{"_i":0},inlineTemplate:{render:function(){with(this){return _c('div',{attrs:{"_i":1}})}},staticRenderFns:[]}})}` + `with(this){return _c("myComponent",{tag:"div",inlineTemplate:{render:function(){with(this){return _c('div')}},staticRenderFns:[]}})}` ) assertCodegen( '
    ', - `with(this){return _c("myComponent",{tag:"div",attrs:{"_i":0}})}` + `with(this){return _c("myComponent",{tag:"div"})}` ) // expect('Inline-template components must have exactly one child element.').toHaveBeenWarned() // expect(console.error.calls.count()).toBe(3) @@ -616,7 +616,7 @@ describe('codegen', () => { it('generate static trees inside v-for', () => { assertCodegen( `

    `, - `with(this){return _c('div',{attrs:{"_i":0}},_l((10),function(i,$10,$20,$30){return _c('div',{attrs:{"_i":("1-"+$30)}},[_m(0,true)])}),0)}` + `with(this){return _c('div',_l((10),function(i,$10,$20,$30){return _c('div',[_m(0,true)])}),0)}` // [`with(this){return _c('p',[_c('span')])}`] ) }) @@ -625,7 +625,7 @@ describe('codegen', () => { // normalize type: 2 assertCodegen( '
    ', - `with(this){return _c('div',{attrs:{"_i":0}},[_c('child',{attrs:{"_i":1}}),_l((_$f(2,{forItems:list})),function(item,$10,$20,$30){return [_c('text',{key:_$f(2,{forIndex:$20,keyIndex:0,key:2+'-0'+$30}),extras:{t0:_s(item)},attrs:{"_i":("2-"+$30)}})]})],2)}` + `with(this){return _c('div',[_c('child',{attrs:{"_i":1}}),_l((_$f(2,{forItems:list})),function(item,$10,$20,$30){return [_c('text',{key:_$f(2,{forIndex:$20,keyIndex:0,key:2+'-0'+$30}),extras:{t0:_s(item)},attrs:{"_i":("2-"+$30)}})]})],2)}` ) }) @@ -634,7 +634,7 @@ describe('codegen', () => { // comments: true // }, baseOptions) // const template = '
    ' - // const generatedCode = `with(this){return _c('div',{attrs:{"_i":0}})}` + // const generatedCode = `with(this){return _c('div')}` // const ast = parse(template, options) // optimize(ast, options) @@ -648,7 +648,7 @@ describe('codegen', () => { // comments: true // }, baseOptions) // const template = '
    ' - // const generatedCode = `with(this){return _c('div',{attrs:{"_i":0}})}` + // const generatedCode = `with(this){return _c('div')}` // const ast = parse(template, options) // optimize(ast, options) @@ -685,7 +685,7 @@ describe('codegen', () => { it('not specified directives option', () => { assertCodegen( '

    hello world

    ', - `with(this){return (_$i(0,show))?_c('p',{attrs:{"_i":0}}):_e()}`, { + `with(this){return (_$i(0,show))?_c('p'):_e()}`, { // isReservedTag } ) @@ -695,7 +695,7 @@ describe('codegen', () => { it('should compile single v-for component inside template', () => { assertCodegen( `
    `, - `with(this){return _c('div',{attrs:{"_i":0}},[(_$i(1,ok))?_l((1),function(i,$10,$20,$30){return _c('foo',{key:i,attrs:{"_i":("2-"+$30)}})}):_e()],2)}` + `with(this){return _c('div',[(_$i(1,ok))?_l((1),function(i,$10,$20,$30){return _c('foo',{key:i,attrs:{"_i":("2-"+$30)}})}):_e()],2)}` ) }) }) diff --git a/packages/uni-template-compiler/__tests__/compiler-app-plus.view.spec.js b/packages/uni-template-compiler/__tests__/compiler-app-plus.view.spec.js index f8afa33b1e6ffecf92d8a17a8a563f63b02804dc..ac2eda9d9e24b14bac4aba58862c9c28e57d551d 100644 --- a/packages/uni-template-compiler/__tests__/compiler-app-plus.view.spec.js +++ b/packages/uni-template-compiler/__tests__/compiler-app-plus.view.spec.js @@ -4,7 +4,7 @@ function assertCodegen (template, generatedCode, ...args) { const compiled = compiler.compile(template, { mp: { platform: 'app-plus' - }, + }, view: true }) expect(compiled.render).toBe(generatedCode) @@ -16,11 +16,11 @@ describe('codegen', () => { assertCodegen( '

    ', `with(this){return _c('v-uni-view',{directives:[{name:"custom1",rawName:"v-custom1:arg1.modifier",value:(_$g(0,'v-custom1')),expression:"_$g(0,'v-custom1')",arg:"arg1",modifiers:{"modifier":true}},{name:"custom2",rawName:"v-custom2"}],attrs:{"_i":0}})}` - ) - // extra - assertCodegen( - '

    ', - `with(this){return _c('v-uni-view',{directives:[{name:"custom1",rawName:"v-custom1:[arg1].modifier",value:(_$g(0,'v-custom1')),expression:"_$g(0,'v-custom1')",arg:_$g(0,'v-custom1-arg'),modifiers:{"modifier":true}},{name:"custom2",rawName:"v-custom2"}],attrs:{"_i":0}})}` + ) + // extra + assertCodegen( + '

    ', + `with(this){return _c('v-uni-view',{directives:[{name:"custom1",rawName:"v-custom1:[arg1].modifier",value:(_$g(0,'v-custom1')),expression:"_$g(0,'v-custom1')",arg:_$g(0,'v-custom1-arg'),modifiers:{"modifier":true}},{name:"custom2",rawName:"v-custom2"}],attrs:{"_i":0}})}` ) }) @@ -699,4 +699,4 @@ describe('codegen', () => { ) }) }) -/* eslint-enable quotes */ +/* eslint-enable quotes */ diff --git a/packages/uni-template-compiler/__tests__/demo.js b/packages/uni-template-compiler/__tests__/demo.js index 2300fdc8c964aec09a4553badeb49b9939732d72..e313d57935e2d385c59e0e5df624c6539a8fd313 100644 --- a/packages/uni-template-compiler/__tests__/demo.js +++ b/packages/uni-template-compiler/__tests__/demo.js @@ -1,7 +1,7 @@ const compiler = require('../lib') const res = compiler.compile( ` -

    hello world

    +

    hello world

    `, { resourcePath: '/User/fxy/Documents/test.wxml', isReservedTag: function (tag) { @@ -13,10 +13,10 @@ const res = compiler.compile( mp: { platform: 'app-plus' }, - // service: true, + service: true, view: true }) console.log(require('util').inspect(res, { colors: true, depth: null -})) +})) diff --git a/packages/uni-template-compiler/lib/app/optimizer.js b/packages/uni-template-compiler/lib/app/optimizer.js new file mode 100644 index 0000000000000000000000000000000000000000..c80c57c7d8bfa84a2adcfb08ebc7fc88efabc0ef --- /dev/null +++ b/packages/uni-template-compiler/lib/app/optimizer.js @@ -0,0 +1,59 @@ +let isPlatformReservedTag + +function no (a, b, c) { + return false +} + +function isBuiltInTag (tag) { + if (tag === 'slot' || tag === 'component') { + return true + } +} + +function isStatic (node) { + if (node.type === 2) { + return false + } + if (node.type === 3) { + return true + } + if (node.dynamicClass || node.dynamicStyle) { + return false + } + return !!(node.pre || ( + !node.hasBindings && // no dynamic bindings + !isBuiltInTag(node.tag) && // not a built-in + isPlatformReservedTag(node.tag) + )) +} + +function markStatic (node) { + if (isStatic(node)) { // 静态节点且仅包含 ID 属性 + if ( + node.attrs.length === 1 && + !node.key && + !node.ref && + !node.slotTarget + ) { + node.plain = true + } + delete node.attrs + } + if (node.type === 1) { + for (let i = 0, l = node.children.length; i < l; i++) { + const child = node.children[i] + markStatic(child) + } + if (node.ifConditions) { + for (let i = 1, l = node.ifConditions.length; i < l; i++) { + const block = node.ifConditions[i].block + markStatic(block) + } + } + } +} + +module.exports = function optimize (root, options) { + isPlatformReservedTag = options.isReservedTag || no + markStatic(root) +} diff --git a/packages/uni-template-compiler/lib/app/service.js b/packages/uni-template-compiler/lib/app/service.js index 1e36d91464db2161a75861b4f5a167413befdc4e..766752c28a5c6e7b48ef854db55ab5317936e13c 100644 --- a/packages/uni-template-compiler/lib/app/service.js +++ b/packages/uni-template-compiler/lib/app/service.js @@ -1,7 +1,7 @@ const { ID, ITERATOR, - isVar, + isVar, getForEl, processForKey, updateForEleId, @@ -18,7 +18,9 @@ const parseBlock = require('./parser/block-parser') const preTransformNode = require('./pre-transform-node') -function genData (el) { +const optimize = require('./optimizer') + +function genData (el) { delete el.$parentIterator3 const { @@ -222,7 +224,7 @@ function processDynamicText (el, state) { }] el.hasBindings = true - if (el.text) { + if (el.text) { // fixed by xxxxxx 注意:保持平台一致性,trim 一下 const ret = parseText(el.text.trim(), false, state) if (ret && ret.dynamicTexts.length) { @@ -296,16 +298,17 @@ function transformNode (el, parent, state) { processDirs(el) } -function postTransformNode (el) { +function postTransformNode (el, options) { if (!el.parent) { // 从根节点开始递归处理 traverseNode(el, false, { forIteratorId: 0, transformNode }) + optimize(el, options) } } module.exports = { preTransformNode, postTransformNode, genData -} +} diff --git a/packages/uni-template-compiler/lib/app/util.js b/packages/uni-template-compiler/lib/app/util.js index 66f823e08617d485fa319c42b0f7af576a8d511c..35aa3850c7dee11d23f63086243e93cb3d6b2650 100644 --- a/packages/uni-template-compiler/lib/app/util.js +++ b/packages/uni-template-compiler/lib/app/util.js @@ -4,7 +4,7 @@ const NUMBER_RE = /^-?\d*(\.\d+)?$/ const ID = '_i' const ITERATOR1 = '$1' const ITERATOR2 = '$2' -const ITERATOR3 = '$3' +const ITERATOR3 = '$3' const DATA_ROOT = '_$g' const V_FOR = 'f' @@ -148,7 +148,7 @@ module.exports = { V_FOR, V_IF, V_ELSE_IF, - ID, + ID, DATA_ROOT, isVar, hasOwn, 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 c789abd3da161defc9dd4ab592e23a1a3042b879..b010cd1a1c593423d4d608e107b3e8ed5247695f 100644 --- a/packages/vue-cli-plugin-uni/lib/app-plus/index.js +++ b/packages/vue-cli-plugin-uni/lib/app-plus/index.js @@ -56,18 +56,18 @@ const v3 = { '../../packages/webpack-uni-app-loader/view/script') }] }) - } - - const entry = {} - if (isAppService) { - entry['app-service'] = path.resolve(process.env.UNI_INPUT_DIR, getMainEntry()) - } else if (isAppView) { - entry['app-view'] = path.resolve(process.env.UNI_INPUT_DIR, getMainEntry()) - } - + } + + const entry = {} + if (isAppService) { + entry['app-service'] = path.resolve(process.env.UNI_INPUT_DIR, getMainEntry()) + } else if (isAppView) { + entry['app-view'] = path.resolve(process.env.UNI_INPUT_DIR, getMainEntry()) + } + return { devtool, - mode: process.env.NODE_ENV, + mode: isAppView ? 'production' : process.env.NODE_ENV, externals: { vue: 'Vue' }, @@ -110,8 +110,8 @@ const v3 = { ] } }, - chainWebpack (webpackConfig, vueOptions) { - webpackConfig.entryPoints.delete('app') + chainWebpack (webpackConfig, vueOptions) { + webpackConfig.entryPoints.delete('app') const isAppService = !!vueOptions.pluginOptions['uni-app-plus']['service'] const isAppView = !!vueOptions.pluginOptions['uni-app-plus']['view'] diff --git a/src/platforms/app-plus/service/framework/page.js b/src/platforms/app-plus/service/framework/page.js index 12ba92571e76a6803f5508e56aba2a9854aeaf06..d20da062dfb2cc192ae8fd26e7ee03f3ee73cf78 100644 --- a/src/platforms/app-plus/service/framework/page.js +++ b/src/platforms/app-plus/service/framework/page.js @@ -117,8 +117,9 @@ export function registerPage ({ timestamp: Date.now() } }, [pageId]) - - createPage(route, pageId, query, pageInstance).$mount() + try { + createPage(route, pageId, query, pageInstance).$mount() + } catch (e) {} } } diff --git a/src/platforms/app-plus/service/publish-handler.js b/src/platforms/app-plus/service/publish-handler.js index 8a0c705ce7dcfaf349132befcbe3f15aeb926868..ed51a512bc81404a8b4f2ca103511fcae961b511 100644 --- a/src/platforms/app-plus/service/publish-handler.js +++ b/src/platforms/app-plus/service/publish-handler.js @@ -6,9 +6,6 @@ import { from './constants' function optimize (k, v) { - if (typeof v === 'undefined') { - return '' - } if ( k === V_IF || k === V_ELSE_IF || diff --git a/src/platforms/app-plus/view/framework/plugins/data.js b/src/platforms/app-plus/view/framework/plugins/data.js index ae72003bee4c9e22ece76117f40f9cdd2d7b5706..755b98cb80ff6e2309cc70359e17ea594a6fd035 100644 --- a/src/platforms/app-plus/view/framework/plugins/data.js +++ b/src/platforms/app-plus/view/framework/plugins/data.js @@ -1,10 +1,5 @@ import Vue from 'vue' -import { - hasOwn -} - from 'uni-shared' - import { PAGE_CREATE, MOUNTED_DATA, @@ -74,16 +69,10 @@ function vdSync ({ } function getData (id, name, isFallbackContent = false) { - const root = this.$r - if (hasOwn(root, id)) { - const vNodeData = root[id] - if (hasOwn(vNodeData, name)) { - return vNodeData[name] - } else { - !isFallbackContent && console.error(this.$options.__file + `:[${this._$id}]$r[${id}][${name}] is undefined`) - } - } else { - !isFallbackContent && console.error(this.$options.__file + `:[${this._$id}]$r[${id}] is undefined`) + try { + return this.$r[id][name] + } catch (e) { + !isFallbackContent && console.error(this.$options.__file + `:[${this._$id}]$r[${id}][${name}] is undefined`) } }