( code = '', options: InternalToHtmlOptions, useString = options.format === 'class' ? 'this.update' : 'update', )
| 540 | }; |
| 541 | |
| 542 | function addUpdateAfterSetInCode( |
| 543 | code = '', |
| 544 | options: InternalToHtmlOptions, |
| 545 | useString = options.format === 'class' ? 'this.update' : 'update', |
| 546 | ) { |
| 547 | let updates = 0; |
| 548 | return babelTransformExpression(code, { |
| 549 | AssignmentExpression(path: babel.NodePath<babel.types.AssignmentExpression>) { |
| 550 | const { node } = path; |
| 551 | if (types.isMemberExpression(node.left)) { |
| 552 | if (types.isIdentifier(node.left.object)) { |
| 553 | // TODO: utillity to properly trace this reference to the beginning |
| 554 | if (node.left.object.name === 'state') { |
| 555 | // TODO: ultimately do updates by property, e.g. updateName() |
| 556 | // that updates any attributes dependent on name, etcç |
| 557 | let parent: NodePath<any> | null = path; |
| 558 | |
| 559 | // `_temp = ` assignments are created sometimes when we insertAfter |
| 560 | // for simple expressions. this causes us to re-process the same expression |
| 561 | // in an infinite loop |
| 562 | while ((parent = parent.parentPath)) { |
| 563 | if ( |
| 564 | types.isAssignmentExpression(parent.node) && |
| 565 | types.isIdentifier(parent.node.left) && |
| 566 | parent.node.left.name.startsWith('_temp') |
| 567 | ) { |
| 568 | return; |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | // Uncomment to debug infinite loops: |
| 573 | // if (updates++ > 1000) { |
| 574 | // console.error('Infinite assignment detected'); |
| 575 | // return; |
| 576 | // } |
| 577 | if (options?.experimental?.addUpdateAfterSetInCode) { |
| 578 | useString = options?.experimental?.addUpdateAfterSetInCode(useString, options, { |
| 579 | node, |
| 580 | code, |
| 581 | types, |
| 582 | }); |
| 583 | } |
| 584 | path.insertAfter(types.callExpression(types.identifier(useString), [])); |
| 585 | } |
| 586 | } |
| 587 | } |
| 588 | }, |
| 589 | }); |
| 590 | } |
| 591 | |
| 592 | const htmlDecode = (html: string) => html.replace(/"/gi, '"'); |
| 593 |
no test coverage detected
searching dependent graphs…