MCPcopy Index your code
hub / github.com/keepfool/vue-tutorials / parseText

Function parseText

06.Router/basic/js/vue.js:792–837  ·  view source on GitHub ↗

* Parse a template text string into an array of tokens. * * @param {String} text * @return {Array | null} * - {String} type * - {String} value * - {Boolean} [html] * - {Boolean} [oneTime]

(text)

Source from the content-addressed store, hash-verified

790 */
791
792 function parseText(text) {
793 if (!cache) {
794 compileRegex();
795 }
796 var hit = cache.get(text);
797 if (hit) {
798 return hit;
799 }
800 if (!tagRE.test(text)) {
801 return null;
802 }
803 var tokens = [];
804 var lastIndex = tagRE.lastIndex = 0;
805 var match, index, html, value, first, oneTime;
806 /* eslint-disable no-cond-assign */
807 while (match = tagRE.exec(text)) {
808 /* eslint-enable no-cond-assign */
809 index = match.index;
810 // push text token
811 if (index > lastIndex) {
812 tokens.push({
813 value: text.slice(lastIndex, index)
814 });
815 }
816 // tag token
817 html = htmlRE.test(match[0]);
818 value = html ? match[1] : match[2];
819 first = value.charCodeAt(0);
820 oneTime = first === 42; // *
821 value = oneTime ? value.slice(1) : value;
822 tokens.push({
823 tag: true,
824 value: value.trim(),
825 html: html,
826 oneTime: oneTime
827 });
828 lastIndex = index + match[0].length;
829 }
830 if (lastIndex < text.length) {
831 tokens.push({
832 value: text.slice(lastIndex)
833 });
834 }
835 cache.put(text, tokens);
836 return tokens;
837 }
838
839 /**
840 * Format a list of tokens into an expression.

Callers 5

compileElementFunction · 0.70
compileTextNodeFunction · 0.70
compileDirectivesFunction · 0.70
mergeAttrsFunction · 0.70
dataAPIFunction · 0.70

Calls 1

compileRegexFunction · 0.70

Tested by

no test coverage detected