MCPcopy
hub / github.com/vuejs/core / push

Function push

packages/compiler-core/src/codegen.ts:182–236  ·  packages/compiler-core/src/codegen.ts::push
(code, newlineIndex = NewlineType.None, node)

Source from the content-addressed store, hash-verified

180 return `_${helperNameMap[key]}`
181 },
182 push(code, newlineIndex = NewlineType.None, node) {
183 context.code += code
184 if (!__BROWSER__ && context.map) {
185 if (node) {
186 let name
187 if (node.type === NodeTypes.SIMPLE_EXPRESSION && !node.isStatic) {
188 const content = node.content.replace(/^_ctx\./, class="st">'')
189 if (content !== node.content && isSimpleIdentifier(content)) {
190 name = content
191 }
192 }
193 if (node.loc.source) {
194 addMapping(node.loc.start, name)
195 }
196 }
197 if (newlineIndex === NewlineType.Unknown) {
198 class="cm">// multiple newlines, full iteration
199 advancePositionWithMutation(context, code)
200 } else {
201 class="cm">// fast paths
202 context.offset += code.length
203 if (newlineIndex === NewlineType.None) {
204 class="cm">// no newlines; fast path to avoid newline detection
205 if (__TEST__ && code.includes(class="st">'\n')) {
206 throw new Error(
207 `CodegenContext.push() called newlineIndex: none, but contains` +
208 `newlines: ${code.replace(/\n/g, class="st">'\\n')}`,
209 )
210 }
211 context.column += code.length
212 } else {
213 class="cm">// single newline at known index
214 if (newlineIndex === NewlineType.End) {
215 newlineIndex = code.length - 1
216 }
217 if (
218 __TEST__ &&
219 (code.charAt(newlineIndex) !== class="st">'\n' ||
220 code.slice(0, newlineIndex).includes(class="st">'\n') ||
221 code.slice(newlineIndex + 1).includes(class="st">'\n'))
222 ) {
223 throw new Error(
224 `CodegenContext.push() called with newlineIndex: ${newlineIndex} ` +
225 `but does not conform: ${code.replace(/\n/g, class="st">'\\n')}`,
226 )
227 }
228 context.line++
229 context.column = code.length - newlineIndex
230 }
231 }
232 if (node && node.loc !== locStub && node.loc.source) {
233 addMapping(node.loc.end)
234 }
235 }
236 },
237 indent() {
238 newline(++context.indentLevel)
239 },

Callers 15

generateFunction · 0.70
genFunctionPreambleFunction · 0.70
genModulePreambleFunction · 0.70
genAssetsFunction · 0.70
genHoistsFunction · 0.70
genNodeListFunction · 0.70
genInterpolationFunction · 0.70
genCommentFunction · 0.70
genVNodeCallFunction · 0.70
genCallExpressionFunction · 0.70
genObjectExpressionFunction · 0.70

Calls 3

isSimpleIdentifierFunction · 0.90
addMappingFunction · 0.70

Tested by

no test coverage detected