|
|
@@ -11,3 +11,48 @@ export function getAndRemoveAttr (el, attr) {
|
|
|
}
|
|
|
return val
|
|
|
}
|
|
|
+
|
|
|
+const modifierRE = /\.[^\.]+/g
|
|
|
+
|
|
|
+export function parseModifiers (name) {
|
|
|
+ var res = Object.create(null)
|
|
|
+ var match = name.match(modifierRE)
|
|
|
+ if (match) {
|
|
|
+ var i = match.length
|
|
|
+ while (i--) {
|
|
|
+ res[match[i].slice(1)] = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return res
|
|
|
+}
|
|
|
+
|
|
|
+export function removeModifiers (name) {
|
|
|
+ return name.replace(modifierRE, '')
|
|
|
+}
|
|
|
+
|
|
|
+const tagRE = /\{\{((?:.|\\n)+?)\}\}/g
|
|
|
+export function parseText (text) {
|
|
|
+ if (!tagRE.test(text)) {
|
|
|
+ return null
|
|
|
+ }
|
|
|
+ var tokens = []
|
|
|
+ var lastIndex = tagRE.lastIndex = 0
|
|
|
+ var match, index, value
|
|
|
+ /* eslint-disable no-cond-assign */
|
|
|
+ while (match = tagRE.exec(text)) {
|
|
|
+ /* eslint-enable no-cond-assign */
|
|
|
+ index = match.index
|
|
|
+ // push text token
|
|
|
+ if (index > lastIndex) {
|
|
|
+ tokens.push(JSON.stringify(text.slice(lastIndex, index)))
|
|
|
+ }
|
|
|
+ // tag token
|
|
|
+ value = match[1]
|
|
|
+ tokens.push('(' + match[1].trim() + ')')
|
|
|
+ lastIndex = index + match[0].length
|
|
|
+ }
|
|
|
+ if (lastIndex < text.length) {
|
|
|
+ tokens.push(JSON.stringify(text.slice(lastIndex)))
|
|
|
+ }
|
|
|
+ return tokens.join('+')
|
|
|
+}
|