| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e140faf commit dd2984b
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -526,13 +526,32 @@ var es5_visitors = (function() { | |||
| 526 | 526 | /* | |
| 527 | 527 | * HELPER METHODS | |
| 528 | 528 | */ | |
| 529 | + | ||
| 530 | + // Returns the Identifier name of a property's key, or null when the property | ||
| 531 | + // is a SpreadElement, has a computed key, or uses a non-Identifier key | ||
| 532 | + // (e.g. StringLiteral, NumericLiteral). Such properties cannot be mapped to | ||
| 533 | + // a Java method binding, so callers should skip them. | ||
| 534 | + function _getIdentifierKeyName(property) { | ||
| 535 | + if (!property || property.computed) { | ||
| 536 | + return null; | ||
| 537 | + } | ||
| 538 | + if (!property.key || !types.isIdentifier(property.key)) { | ||
| 539 | + return null; | ||
| 540 | + } | ||
| 541 | + return property.key.name; | ||
| 542 | + } | ||
| 543 | + | ||
| 529 | 544 | function _getOverriddenMethods(node, config) { | |
| 530 | 545 | var overriddenMethodNames = []; | |
| 531 | 546 | if (types.isObjectExpression(node)) { | |
| 532 | 547 | var objectProperties = node.properties; | |
| 533 | 548 | ||
| 534 | 549 | for (var index in objectProperties) { | |
| 535 | - overriddenMethodNames.push(objectProperties[index].key.name); | ||
| 550 | + var keyName = _getIdentifierKeyName(objectProperties[index]); | ||
| 551 | + if (keyName === null) { | ||
| 552 | + continue; | ||
| 553 | + } | ||
| 554 | + overriddenMethodNames.push(keyName); | ||
| 536 | 555 | } | |
| 537 | 556 | } | |
| 538 | 557 | ||
@@ -567,9 +586,18 @@ var es5_visitors = (function() { | |||
| 567 | 586 | will get 'method1' and 'method3' | |
| 568 | 587 | */ | |
| 569 | 588 | for (var index in objectProperties) { | |
| 589 | + var keyName = _getIdentifierKeyName(objectProperties[index]); | ||
| 590 | + // Skip spreads, computed keys, and non-Identifier keys — they | ||
| 591 | + // cannot be statically mapped to a Java binding. Without this | ||
| 592 | + // guard, valid (non-NS) `.extend({ ...other, foo })` calls in | ||
| 593 | + // bundled vendor code (e.g. Zod schemas) would crash the parser. | ||
| 594 | + if (keyName === null) { | ||
| 595 | + continue; | ||
| 596 | + } | ||
| 597 | + | ||
| 570 | 598 | // if the user has declared interfaces that he is implementing | |
| 571 | 599 | if (!interfacesFound && | |
| 572 | - objectProperties[index].key.name.toLowerCase() === "interfaces" && | ||
| 600 | + keyName.toLowerCase() === "interfaces" && | ||
| 573 | 601 | types.isArrayExpression(objectProperties[index].value)) { | |
| 574 | 602 | interfacesFound = true; | |
| 575 | 603 | var interfaces = objectProperties[index].value.elements; | |
@@ -579,7 +607,7 @@ var es5_visitors = (function() { | |||
| 579 | 607 | implementedInterfaces.push(interfaceName); | |
| 580 | 608 | } | |
| 581 | 609 | } else { | |
| 582 | - overriddenMethodNames.push(objectProperties[index].key.name) | ||
| 610 | + overriddenMethodNames.push(keyName) | ||
| 583 | 611 | } | |
| 584 | 612 | } | |
| 585 | 613 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments