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

feat(v3): optimize service code

上级 95177e1d
......@@ -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 ||
......
......@@ -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&
......
......@@ -19,11 +19,11 @@ describe('codegen', () => {
)
assertCodegen(
'<div><block v-for="item in items"><div></div><div></div></block></div>',
`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(
'<div><block v-for="item in items" :key="item.id"><div></div><div></div></block></div>',
`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(
'<div><template v-for="item in items"><div></div><div></div></template></div>',
`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(
'<div><template v-for="item in items">text</template></div>',
`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(
'<div><template v-for="item in items">{{text}}</template></div>',
`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(
'<div><template v-for="item in items"><span></span>{{text}}</template></div>',
`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(
'<div><template v-for="item in items">a {{text1}} b {{text2}}</template></div>',
`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(
'<div><template v-for="item in items"><span v-if="item.sub"></span></template></div>',
`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(
'<div>A{{ d | e | f }}B{{text}}C</div>',
`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}})])}`
)
})
})
......
......@@ -17,28 +17,28 @@ describe('codegen', () => {
'<p v-custom1:[arg1].modifier="value1" v-custom2></p>',
`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(
'<div><template v-for="item in items"><div></div><div></div></template></div>',
`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(
'<div><template v-for="item in items"><span v-if="item.sub"></span></template></div>',
`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(
'<div>A{{ d | e | f }}B{{text}}C</div>',
`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(
'<div><slot><div>{{hi}}</div></slot></div>',
`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(
'<div><template v-for="item in items"><div></div><div></div></template></div>',
`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(
'<div><template v-for="item in items"><span v-if="item.sub"></span></template></div>',
`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(
'<div>A{{ d | e | f }}B{{text}}C</div>',
`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(
'<div><slot><div>{{hi}}</div></slot></div>',
`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 */
......@@ -34,86 +34,86 @@ describe('codegen', () => {
it('generate filters with no arguments', () => {
assertCodegen(
'<div>{{ d | e() }}</div>',
`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(
'<div><li v-for="item in items" :key="item.uid"></li></div>',
`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(
'<div><li v-for="(item, i) in items"></li></div>',
`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(
'<div><li v-for="(item, key, index) in items"></li></div>',
`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(
'<div><li v-for="{ a, b } in items"></li></div>',
`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(
'<div><li v-for="({ a, b }, key, index) in items"></li></div>',
`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(
'<div><p></p><li v-for="item in items"></li></div>',
`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(
'<p v-if="show">hello</p>',
`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(
'<div><p v-if="show">hello</p><p v-else>world</p></div>',
`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(
'<div><p v-if="show">hello</p><p v-else-if="hide">world</p></div>',
`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(
'<div><p v-if="show">hello</p><p v-else-if="hide">world</p><p v-else>bye</p></div>',
`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(
'<div><p v-if="show">hello</p><p v-else-if="hide">world</p><p v-else-if="3">elseif</p><p v-else>bye</p></div>',
`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(
'<p ref="component1"></p>',
`with(this){return _c('p',{ref:"component1",attrs:{"_i":0}})}`
`with(this){return _c('p',{ref:"component1"})}`
)
})
it('generate ref on v-for', () => {
assertCodegen(
'<ul><li v-for="item in items" ref="component1"></li></ul>',
`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(
'<div><template><p>{{hello}}</p></template></div>',
`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(
'<div><slot></slot></div>',
`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(
'<div><slot name="one"></slot></div>',
`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(
'<div><slot><div>hi</div></slot></div>',
`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(
'<p slot="one">hello world</p>',
`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(
'<p class="class1">hello world</p>',
`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(
'<input name="field1">',
`with(this){return _c('input',{attrs:{"_i":0}})}`
`with(this){return _c('input')}`
)
})
......@@ -558,7 +558,7 @@ describe('codegen', () => {
it('generate component', () => {
assertCodegen(
'<my-component name="mycomponent1" :msg="msg" @notify="onNotify"><div>hi</div></my-component>',
`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(
'<div is="component1"></div>',
`with(this){return _c("component1",{tag:"div",attrs:{"_i":0}})}`
`with(this){return _c("component1",{tag:"div"})}`
)
assertCodegen(
'<div :is="component1"></div>',
`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(
'<div><div is="component1"></div></div>',
`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(
'<my-component inline-template><p><span>hello world</span></p></my-component>',
`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(
'<my-component inline-template><hr><hr></my-component>',
`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(
'<my-component inline-template></my-component>',
......@@ -603,11 +603,11 @@ describe('codegen', () => {
// have "is" attribute
assertCodegen(
'<div is="myComponent" inline-template><div></div></div>',
`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(
'<div is="myComponent" inline-template></div>',
`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(
`<div><div v-for="i in 10"><p><span></span></p></div></div>`,
`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(
'<div><child></child><template v-for="item in list">{{ item }}</template></div>',
`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 = '<div><!--comment--></div>'
// 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 = '<div><!--\n\'comment\'\n--></div>'
// 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(
'<p v-if="show">hello world</p>',
`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(
`<div><template v-if="ok"><foo v-for="i in 1" :key="i"></foo></template></div>`,
`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)}`
)
})
})
......
......@@ -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(
'<p v-custom1:arg1.modifier="value1" v-custom2></p>',
`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(
'<p v-custom1:[arg1].modifier="value1" v-custom2></p>',
`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(
'<p v-custom1:[arg1].modifier="value1" v-custom2></p>',
`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 */
const compiler = require('../lib')
const res = compiler.compile(
`
<p v-show="shown">hello world</p>
<p slot="one">hello world</p>
`, {
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
}))
}))
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)
}
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
}
}
......@@ -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,
......
......@@ -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']
......
......@@ -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) {}
}
}
......
......@@ -6,9 +6,6 @@ import {
from './constants'
function optimize (k, v) {
if (typeof v === 'undefined') {
return ''
}
if (
k === V_IF ||
k === V_ELSE_IF ||
......
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`)
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册