(id: Identifier, parent: Node, parentStack: Node[])
| 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)) { |
no test coverage detected