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

Function rewriteId

packages/compiler-sfc/src/script/definePropsDestructure.ts:228–257  ·  view source on GitHub ↗
(id: Identifier, parent: Node, parentStack: Node[])

Source from the content-addressed store, hash-verified

226 }
227
228 function rewriteId(id: Identifier, parent: Node, parentStack: Node[]) {
229 if (
230 (parent.type === 'AssignmentExpression' && id === parent.left) ||
231 parent.type === 'UpdateExpression'
232 ) {
233 ctx.error(`Cannot assign to destructured props as they are readonly.`, id)
234 }
235
236 if (isStaticProperty(parent) && parent.shorthand) {
237 // let binding used in a property shorthand
238 // skip for destructure patterns
239 if (
240 !(parent as any).inPattern ||
241 isInDestructureAssignment(parent, parentStack)
242 ) {
243 // { prop } -> { prop: __props.prop }
244 ctx.s.appendLeft(
245 id.end! + ctx.startOffset!,
246 `: ${genPropsAccessExp(propsLocalToPublicMap[id.name])}`,
247 )
248 }
249 } else {
250 // x --> __props.x
251 ctx.s.overwrite(
252 id.start! + ctx.startOffset!,
253 id.end! + ctx.startOffset!,
254 genPropsAccessExp(propsLocalToPublicMap[id.name]),
255 )
256 }
257 }
258
259 function checkUsage(node: Node, method: string, alias = method) {
260 if (isCallOf(node, alias)) {

Callers 1

enterFunction · 0.85

Calls 4

genPropsAccessExpFunction · 0.90
isStaticPropertyFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected