MCPcopy Create free account
hub / github.com/MMmaXingXing/mini-vue / parseInterpolation

Function parseInterpolation

code/src/compiler-core/src/parse.ts:123–150  ·  view source on GitHub ↗
(context)

Source from the content-addressed store, hash-verified

121};
122
123const parseInterpolation = (context) => {
124 // {{message}}
125 // 关键字变化点,抽取出来使程序解耦
126 const openDelimiter = "{{";
127 const closeDelimiter = "}}";
128
129 const closeIndex = context.source.indexOf(
130 closeDelimiter,
131 closeDelimiter.length
132 );
133
134 // 前两个数据可以将前两个字符串干掉来进行一字符的推进
135 advanceBy(context, openDelimiter.length);
136
137 const rowContentLength = closeIndex - openDelimiter.length;
138 const rawContent = parseTextData(context, rowContentLength);
139 const content = rawContent.trim();
140
141 // 获取之后删除
142 advanceBy(context, closeDelimiter.length);
143 return {
144 type: NodeTypes.INTERPOLATION,
145 content: {
146 type: NodeTypes.SIMPLE_EXPRESSION,
147 content: content
148 }
149 };
150};
151
152const advanceBy = (context: any, length: number) => {
153 context.source = context.source.slice(length);

Callers 1

parseChildrenFunction · 0.70

Calls 3

indexOfMethod · 0.80
advanceByFunction · 0.70
parseTextDataFunction · 0.70

Tested by

no test coverage detected