* Simple implementation for detecting method shorthand, such as, * ({abc() { return 1; }}).abc is a method shorthand and needs to * be serialized as `{abc() { return 1; }}` rather than `{abc: abc() { return 1; }}`. * Those cases can be detected: * ({abc() {
(fnStr, fnName, objKey)
| 2776 | * ({[some]() { return 1; }})[some] expected: IS_SHORTHAND |
| 2777 | */ |
| 2778 | function isMethodShorthandNotAccurate(fnStr, fnName, objKey) { |
| 2779 | // Assert fnStr, fnName, objKey is a string. |
| 2780 | if (fnName !== objKey) { |
| 2781 | return false; |
| 2782 | } |
| 2783 | var matched = fnStr.match(/^\s*(async\s+)?(function\s*)?(\*\s*)?([a-zA-Z$_][a-zA-Z0-9$_]*)?\s*\(/); |
| 2784 | if (!matched) { |
| 2785 | return false; |
| 2786 | } |
| 2787 | if (matched[2]) { // match 'function' |
| 2788 | return false; |
| 2789 | } |
| 2790 | // May enhanced by /(['"])(?:(?=(\\?))\2.)*?\1/; to match literal string, |
| 2791 | // such as "ab-c", "a\nc". But this simple impl does not cover it. |
| 2792 | if (!matched[4] || matched[4] !== objKey) { // match "maybe function name" |
| 2793 | return false; |
| 2794 | } |
| 2795 | return true; |
| 2796 | } |
| 2797 | |
| 2798 | }; |
| 2799 |
no outgoing calls
no test coverage detected
searching dependent graphs…