From 694234c334188106861f500deef3fdc5157dfb42 Mon Sep 17 00:00:00 2001 From: anchengjian Date: Mon, 9 Apr 2018 00:46:13 +0800 Subject: [PATCH 1/7] fix: for lint --- src/core/util/env.js | 1 - src/platforms/mp/compiler/codegen/convert/attrs.js | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/core/util/env.js b/src/core/util/env.js index 16cf46d5..2ef6905f 100644 --- a/src/core/util/env.js +++ b/src/core/util/env.js @@ -1,5 +1,4 @@ /* @flow */ -/* globals MutationObserver */ import { noop } from 'shared/util' import { handleError } from './error' diff --git a/src/platforms/mp/compiler/codegen/convert/attrs.js b/src/platforms/mp/compiler/codegen/convert/attrs.js index 8bc8959a..a4ac80d8 100644 --- a/src/platforms/mp/compiler/codegen/convert/attrs.js +++ b/src/platforms/mp/compiler/codegen/convert/attrs.js @@ -9,13 +9,13 @@ function transformDynamicClass (staticClass = '', clsBinding) { const result = babel.transform(`!${clsBinding}`, { plugins: [transformObjectToTernaryOperator] }) // 先实现功能,再优化代码 // https://github.com/babel/babel/issues/7138 - const cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, "") + const cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, '') return `${staticClass} {{${cls}}}` } function transformDynamicStyle (staticStyle = '', styleBinding) { const result = babel.transform(`!${styleBinding}`, { plugins: [transformObjectToString] }) - const cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, "") + const cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, '') return `${staticStyle} {{${cls}}}` } From 323b793be44918db7bd6a1c52a98c8075dc8dbab Mon Sep 17 00:00:00 2001 From: anchengjian Date: Mon, 9 Apr 2018 01:00:36 +0800 Subject: [PATCH 2/7] =?UTF-8?q?fix:=20slot=20=E4=B8=AD=E5=B5=8C=E5=A5=97?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E5=92=8Cevent=E5=A4=B1=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/mpvue-template-compiler/build.js | 8 ++++---- packages/mpvue/index.js | 20 ++++++++++++++------ src/platforms/mp/compiler/codegen/index.js | 3 ++- src/platforms/mp/runtime/events.js | 19 ++++++++++++++----- 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/packages/mpvue-template-compiler/build.js b/packages/mpvue-template-compiler/build.js index 745e1276..2e94845a 100644 --- a/packages/mpvue-template-compiler/build.js +++ b/packages/mpvue-template-compiler/build.js @@ -1676,7 +1676,6 @@ function handleError (err, vm, info) { } /* */ -/* globals MutationObserver */ // can we use __proto__? var hasProto = '__proto__' in {}; @@ -4352,7 +4351,7 @@ function transformDynamicClass (staticClass, clsBinding) { var result = babel.transform(("!" + clsBinding), { plugins: [transformObjectToTernaryOperator] }); // 先实现功能,再优化代码 // https://github.com/babel/babel/issues/7138 - var cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, ""); + var cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, ''); return (staticClass + " {{" + cls + "}}") } @@ -4360,7 +4359,7 @@ function transformDynamicStyle (staticStyle, styleBinding) { if ( staticStyle === void 0 ) staticStyle = ''; var result = babel.transform(("!" + styleBinding), { plugins: [transformObjectToString] }); - var cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, ""); + var cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, ''); return (staticStyle + " {{" + cls + "}}") } @@ -4863,7 +4862,8 @@ function compileToWxml (compiled, options) { slot.code = generate$2(slot.node, options); }); - return { code: code, compiled: compiled, slots: slots } + // TODO: 后期优化掉这种暴力全部 import,虽然对性能没啥大影响 + return { code: code, compiled: compiled, slots: slots, importCode: importCode } } /* */ diff --git a/packages/mpvue/index.js b/packages/mpvue/index.js index 5db75fd2..b31ef044 100644 --- a/packages/mpvue/index.js +++ b/packages/mpvue/index.js @@ -476,7 +476,6 @@ function handleError (err, vm, info) { } /* */ -/* globals MutationObserver */ // can we use __proto__? var hasProto = '__proto__' in {}; @@ -5342,7 +5341,20 @@ function getHandle (vnode, eventid, eventTypes) { var children = ref.children; if ( children === void 0 ) children = []; var componentInstance = ref.componentInstance; if (componentInstance) { - return res + // 增加 slot 情况的处理 + // Object.values 会多增加几行编译后的代码 + Object.keys(componentInstance.$slots).forEach(function (slotKey) { + var slot = componentInstance.$slots[slotKey]; + var slots = Array.isArray(slot) ? slot : [slot]; + slots.forEach(function (node) { + res = res.concat(getHandle(node, eventid, eventTypes)); + }); + }); + } else { + // 避免遍历超出当前组件的 vm + children.forEach(function (node) { + res = res.concat(getHandle(node, eventid, eventTypes)); + }); } var attrs = data.attrs; @@ -5359,10 +5371,6 @@ function getHandle (vnode, eventid, eventTypes) { return res } - children.forEach(function (node) { - res = res.concat(getHandle(node, eventid, eventTypes)); - }); - return res } diff --git a/src/platforms/mp/compiler/codegen/index.js b/src/platforms/mp/compiler/codegen/index.js index 43a0f66f..77ea9e24 100644 --- a/src/platforms/mp/compiler/codegen/index.js +++ b/src/platforms/mp/compiler/codegen/index.js @@ -20,5 +20,6 @@ export function compileToWxml (compiled, options = {}) { slot.code = generate(slot.node, options) }) - return { code, compiled, slots } + // TODO: 后期优化掉这种暴力全部 import,虽然对性能没啥大影响 + return { code, compiled, slots, importCode } } diff --git a/src/platforms/mp/runtime/events.js b/src/platforms/mp/runtime/events.js index 6122b313..e4d365c5 100644 --- a/src/platforms/mp/runtime/events.js +++ b/src/platforms/mp/runtime/events.js @@ -27,7 +27,20 @@ function getHandle (vnode, eventid, eventTypes = []) { const { data = {}, children = [], componentInstance } = vnode || {} if (componentInstance) { - return res + // 增加 slot 情况的处理 + // Object.values 会多增加几行编译后的代码 + Object.keys(componentInstance.$slots).forEach(slotKey => { + const slot = componentInstance.$slots[slotKey] + const slots = Array.isArray(slot) ? slot : [slot] + slots.forEach(node => { + res = res.concat(getHandle(node, eventid, eventTypes)) + }) + }) + } else { + // 避免遍历超出当前组件的 vm + children.forEach(node => { + res = res.concat(getHandle(node, eventid, eventTypes)) + }) } const { attrs, on } = data @@ -43,10 +56,6 @@ function getHandle (vnode, eventid, eventTypes = []) { return res } - children.forEach(node => { - res = res.concat(getHandle(node, eventid, eventTypes)) - }) - return res } From 5db164736566b2bf47ea047b47e31922dee9ace7 Mon Sep 17 00:00:00 2001 From: F-loat <945852046@qq.com> Date: Mon, 9 Apr 2018 22:15:16 +0800 Subject: [PATCH 3/7] =?UTF-8?q?optimize:=20=E4=BA=8B=E4=BB=B6=E5=A4=84?= =?UTF-8?q?=E7=90=86=E5=87=BD=E6=95=B0=E4=B8=8D=E5=AD=98=E5=9C=A8=E6=97=B6?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/platforms/mp/runtime/events.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/platforms/mp/runtime/events.js b/src/platforms/mp/runtime/events.js index e4d365c5..bb038248 100644 --- a/src/platforms/mp/runtime/events.js +++ b/src/platforms/mp/runtime/events.js @@ -99,5 +99,10 @@ export function handleProxyWithVue (e) { if (handles.length) { const event = getWebEventByMP(e) handles.forEach(h => h(event)) + } else { + const currentPage = vm.$mp.page.route + console.group(new Date() + ' 事件警告') + console.warn(`Do not have handler in current page: ${currentPage}. Please make sure that handler has been defined in ${currentPage}, or ${currentPage} has been added into app.json`) + console.groupEnd() } } From 89445c358faeee2640f17300d05a520dc70641cf Mon Sep 17 00:00:00 2001 From: anchengjian Date: Mon, 9 Apr 2018 00:46:13 +0800 Subject: [PATCH 4/7] fix: for lint --- src/core/util/env.js | 1 - src/platforms/mp/compiler/codegen/convert/attrs.js | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/core/util/env.js b/src/core/util/env.js index 16cf46d5..2ef6905f 100644 --- a/src/core/util/env.js +++ b/src/core/util/env.js @@ -1,5 +1,4 @@ /* @flow */ -/* globals MutationObserver */ import { noop } from 'shared/util' import { handleError } from './error' diff --git a/src/platforms/mp/compiler/codegen/convert/attrs.js b/src/platforms/mp/compiler/codegen/convert/attrs.js index 8bc8959a..a4ac80d8 100644 --- a/src/platforms/mp/compiler/codegen/convert/attrs.js +++ b/src/platforms/mp/compiler/codegen/convert/attrs.js @@ -9,13 +9,13 @@ function transformDynamicClass (staticClass = '', clsBinding) { const result = babel.transform(`!${clsBinding}`, { plugins: [transformObjectToTernaryOperator] }) // 先实现功能,再优化代码 // https://github.com/babel/babel/issues/7138 - const cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, "") + const cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, '') return `${staticClass} {{${cls}}}` } function transformDynamicStyle (staticStyle = '', styleBinding) { const result = babel.transform(`!${styleBinding}`, { plugins: [transformObjectToString] }) - const cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, "") + const cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, '') return `${staticStyle} {{${cls}}}` } From 061f4d353123426e8b35b11cf0c6b9cfd4802acd Mon Sep 17 00:00:00 2001 From: anchengjian Date: Mon, 9 Apr 2018 01:00:36 +0800 Subject: [PATCH 5/7] =?UTF-8?q?fix:=20slot=20=E4=B8=AD=E5=B5=8C=E5=A5=97?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E5=92=8Cevent=E5=A4=B1=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/mpvue-template-compiler/build.js | 8 ++++---- packages/mpvue/index.js | 20 ++++++++++++++------ src/platforms/mp/compiler/codegen/index.js | 3 ++- src/platforms/mp/runtime/events.js | 19 ++++++++++++++----- 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/packages/mpvue-template-compiler/build.js b/packages/mpvue-template-compiler/build.js index 745e1276..2e94845a 100644 --- a/packages/mpvue-template-compiler/build.js +++ b/packages/mpvue-template-compiler/build.js @@ -1676,7 +1676,6 @@ function handleError (err, vm, info) { } /* */ -/* globals MutationObserver */ // can we use __proto__? var hasProto = '__proto__' in {}; @@ -4352,7 +4351,7 @@ function transformDynamicClass (staticClass, clsBinding) { var result = babel.transform(("!" + clsBinding), { plugins: [transformObjectToTernaryOperator] }); // 先实现功能,再优化代码 // https://github.com/babel/babel/issues/7138 - var cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, ""); + var cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, ''); return (staticClass + " {{" + cls + "}}") } @@ -4360,7 +4359,7 @@ function transformDynamicStyle (staticStyle, styleBinding) { if ( staticStyle === void 0 ) staticStyle = ''; var result = babel.transform(("!" + styleBinding), { plugins: [transformObjectToString] }); - var cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, ""); + var cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, ''); return (staticStyle + " {{" + cls + "}}") } @@ -4863,7 +4862,8 @@ function compileToWxml (compiled, options) { slot.code = generate$2(slot.node, options); }); - return { code: code, compiled: compiled, slots: slots } + // TODO: 后期优化掉这种暴力全部 import,虽然对性能没啥大影响 + return { code: code, compiled: compiled, slots: slots, importCode: importCode } } /* */ diff --git a/packages/mpvue/index.js b/packages/mpvue/index.js index 5db75fd2..b31ef044 100644 --- a/packages/mpvue/index.js +++ b/packages/mpvue/index.js @@ -476,7 +476,6 @@ function handleError (err, vm, info) { } /* */ -/* globals MutationObserver */ // can we use __proto__? var hasProto = '__proto__' in {}; @@ -5342,7 +5341,20 @@ function getHandle (vnode, eventid, eventTypes) { var children = ref.children; if ( children === void 0 ) children = []; var componentInstance = ref.componentInstance; if (componentInstance) { - return res + // 增加 slot 情况的处理 + // Object.values 会多增加几行编译后的代码 + Object.keys(componentInstance.$slots).forEach(function (slotKey) { + var slot = componentInstance.$slots[slotKey]; + var slots = Array.isArray(slot) ? slot : [slot]; + slots.forEach(function (node) { + res = res.concat(getHandle(node, eventid, eventTypes)); + }); + }); + } else { + // 避免遍历超出当前组件的 vm + children.forEach(function (node) { + res = res.concat(getHandle(node, eventid, eventTypes)); + }); } var attrs = data.attrs; @@ -5359,10 +5371,6 @@ function getHandle (vnode, eventid, eventTypes) { return res } - children.forEach(function (node) { - res = res.concat(getHandle(node, eventid, eventTypes)); - }); - return res } diff --git a/src/platforms/mp/compiler/codegen/index.js b/src/platforms/mp/compiler/codegen/index.js index 43a0f66f..77ea9e24 100644 --- a/src/platforms/mp/compiler/codegen/index.js +++ b/src/platforms/mp/compiler/codegen/index.js @@ -20,5 +20,6 @@ export function compileToWxml (compiled, options = {}) { slot.code = generate(slot.node, options) }) - return { code, compiled, slots } + // TODO: 后期优化掉这种暴力全部 import,虽然对性能没啥大影响 + return { code, compiled, slots, importCode } } diff --git a/src/platforms/mp/runtime/events.js b/src/platforms/mp/runtime/events.js index 6122b313..e4d365c5 100644 --- a/src/platforms/mp/runtime/events.js +++ b/src/platforms/mp/runtime/events.js @@ -27,7 +27,20 @@ function getHandle (vnode, eventid, eventTypes = []) { const { data = {}, children = [], componentInstance } = vnode || {} if (componentInstance) { - return res + // 增加 slot 情况的处理 + // Object.values 会多增加几行编译后的代码 + Object.keys(componentInstance.$slots).forEach(slotKey => { + const slot = componentInstance.$slots[slotKey] + const slots = Array.isArray(slot) ? slot : [slot] + slots.forEach(node => { + res = res.concat(getHandle(node, eventid, eventTypes)) + }) + }) + } else { + // 避免遍历超出当前组件的 vm + children.forEach(node => { + res = res.concat(getHandle(node, eventid, eventTypes)) + }) } const { attrs, on } = data @@ -43,10 +56,6 @@ function getHandle (vnode, eventid, eventTypes = []) { return res } - children.forEach(node => { - res = res.concat(getHandle(node, eventid, eventTypes)) - }) - return res } From c9a844890d48e423afa94cfe01796d9360a41dc4 Mon Sep 17 00:00:00 2001 From: F-loat <945852046@qq.com> Date: Mon, 9 Apr 2018 22:15:16 +0800 Subject: [PATCH 6/7] =?UTF-8?q?optimize:=20=E4=BA=8B=E4=BB=B6=E5=A4=84?= =?UTF-8?q?=E7=90=86=E5=87=BD=E6=95=B0=E4=B8=8D=E5=AD=98=E5=9C=A8=E6=97=B6?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/platforms/mp/runtime/events.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/platforms/mp/runtime/events.js b/src/platforms/mp/runtime/events.js index e4d365c5..bb038248 100644 --- a/src/platforms/mp/runtime/events.js +++ b/src/platforms/mp/runtime/events.js @@ -99,5 +99,10 @@ export function handleProxyWithVue (e) { if (handles.length) { const event = getWebEventByMP(e) handles.forEach(h => h(event)) + } else { + const currentPage = vm.$mp.page.route + console.group(new Date() + ' 事件警告') + console.warn(`Do not have handler in current page: ${currentPage}. Please make sure that handler has been defined in ${currentPage}, or ${currentPage} has been added into app.json`) + console.groupEnd() } } From e179a6dfd96c6784ab60dfd53b64f2c32075d152 Mon Sep 17 00:00:00 2001 From: anchengjian Date: Fri, 13 Apr 2018 14:24:09 +0800 Subject: [PATCH 7/7] new version: 1.0.8 --- packages/mpvue-template-compiler/package.json | 2 +- packages/mpvue/index.js | 7 ++++++- packages/mpvue/package.json | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/mpvue-template-compiler/package.json b/packages/mpvue-template-compiler/package.json index d60dde6f..e0085d58 100644 --- a/packages/mpvue-template-compiler/package.json +++ b/packages/mpvue-template-compiler/package.json @@ -1,6 +1,6 @@ { "name": "mpvue-template-compiler", - "version": "1.0.7", + "version": "1.0.8", "description": "mpvue template compiler for Vue", "main": "index.js", "repository": { diff --git a/packages/mpvue/index.js b/packages/mpvue/index.js index b31ef044..376d1136 100644 --- a/packages/mpvue/index.js +++ b/packages/mpvue/index.js @@ -4144,7 +4144,7 @@ Object.defineProperty(Vue$3.prototype, '$ssrContext', { }); Vue$3.version = '2.4.1'; -Vue$3.mpvueVersion = '1.0.7'; +Vue$3.mpvueVersion = '1.0.8'; /* globals renderer */ @@ -5424,6 +5424,11 @@ function handleProxyWithVue (e) { if (handles.length) { var event = getWebEventByMP(e); handles.forEach(function (h) { return h(event); }); + } else { + var currentPage = vm.$mp.page.route; + console.group(new Date() + ' 事件警告'); + console.warn(("Do not have handler in current page: " + currentPage + ". Please make sure that handler has been defined in " + currentPage + ", or " + currentPage + " has been added into app.json")); + console.groupEnd(); } } diff --git a/packages/mpvue/package.json b/packages/mpvue/package.json index ca8e12fa..3e76d663 100644 --- a/packages/mpvue/package.json +++ b/packages/mpvue/package.json @@ -1,6 +1,6 @@ { "name": "mpvue", - "version": "1.0.7", + "version": "1.0.8", "description": "Vue Runtime for mini program", "main": "index.js", "repository": {