MCPcopy
hub / github.com/nuxt/nuxt / removeFromSetupReturn

Function removeFromSetupReturn

packages/nuxt/src/components/plugins/tree-shake.ts:113–142  ·  view source on GitHub ↗

* find and remove all property with the name parameter from the setup return statement and the __returned__ object

(codeAst: Program, name: string, magicString: MagicString)

Source from the content-addressed store, hash-verified

111 * find and remove all property with the name parameter from the setup return statement and the __returned__ object
112 */
113function removeFromSetupReturn (codeAst: Program, name: string, magicString: MagicString) {
114 let walkedInSetup = false
115 walk(codeAst, {
116 enter (node) {
117 if (walkedInSetup) {
118 this.skip()
119 } else if (node.type === 'Property' && node.key.type === 'Identifier' && node.key.name === 'setup' && (node.value.type === 'FunctionExpression' || node.value.type === 'ArrowFunctionExpression')) {
120 // walk into the setup function
121 walkedInSetup = true
122 if (node.value.body?.type === 'BlockStatement') {
123 const returnStatement = node.value.body.body.find(statement => statement.type === 'ReturnStatement') as ReturnStatement
124 if (returnStatement && returnStatement.argument?.type === 'ObjectExpression') {
125 // remove from return statement
126 removePropertyFromObject(returnStatement.argument, name, magicString)
127 }
128
129 // remove from __returned__
130 const variableList = node.value.body.body.filter((statement): statement is VariableDeclaration => statement.type === 'VariableDeclaration')
131 const returnedVariableDeclaration = variableList.find(declaration => declaration.declarations[0]?.id.type === 'Identifier' && declaration.declarations[0]?.id.name === '__returned__' && declaration.declarations[0]?.init?.type === 'ObjectExpression')
132 if (returnedVariableDeclaration) {
133 const init = returnedVariableDeclaration.declarations[0]?.init as ObjectExpression | undefined
134 if (init) {
135 removePropertyFromObject(init, name, magicString)
136 }
137 }
138 }
139 }
140 },
141 })
142}
143
144/**
145 * remove a property from an object expression

Callers 1

handlerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…