From c5c354d593d6f6344e78ca098f1ae1fa3e83d6ed Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 14 Jan 2019 22:56:37 -0500 Subject: [PATCH] feat: new scoped slot syntax implementation update per rfc --- src/compiler/helpers.js | 14 +++++ src/compiler/parser/index.js | 56 +++++++++++++---- .../component/component-scoped-slot.spec.js | 60 +++++++++++++++++++ 3 files changed, 118 insertions(+), 12 deletions(-) diff --git a/src/compiler/helpers.js b/src/compiler/helpers.js index 0411f1a2299..0dd80b03883 100644 --- a/src/compiler/helpers.js +++ b/src/compiler/helpers.js @@ -177,6 +177,20 @@ export function getAndRemoveAttr ( return val } +export function getAndRemoveAttrByRegex ( + el: ASTElement, + name: RegExp +) { + const list = el.attrsList + for (let i = 0, l = list.length; i < l; i++) { + const attr = list[i] + if (name.test(attr.name)) { + list.splice(i, 1) + return attr + } + } +} + function rangeSetItem ( item: any, range?: { start?: number, end?: number } diff --git a/src/compiler/parser/index.js b/src/compiler/parser/index.js index 49a171e10c3..87541ac1aa1 100644 --- a/src/compiler/parser/index.js +++ b/src/compiler/parser/index.js @@ -17,7 +17,8 @@ import { getBindingAttr, getAndRemoveAttr, getRawBindingAttr, - pluckModuleFunction + pluckModuleFunction, + getAndRemoveAttrByRegex } from '../helpers' export const onRE = /^@|^v-on:/ @@ -31,6 +32,8 @@ export const bindRE = /^:|^\.|^v-bind:/ const propBindRE = /^\./ const modifierRE = /\.[^.]+/g +const scopedSlotShorthandRE = /^:?\(.*\)$/ + const lineBreakRE = /[\r\n]/ const whitespaceRE = /\s+/g @@ -568,9 +571,20 @@ function processSlotContent (el) { getAndRemoveAttr(el, 'slot-scope') || // new in 2.6: slot-props and its shorthand works the same as slot-scope // when used on