yahoo / yahoo/serialize-javascript

The regExp of IS_PURE_FUNCTION & IS_ARROW_FUNCTION seem to be extra???

Open
#147 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
2.9k
Forks
215
Avg merge
1d 12h
Merged PRs (30d)
2

Description

source code :

var IS_PURE_FUNCTION = /function.?(/;
var IS_ARROW_FUNCTION = /.
?=>.*?/;

// pure functions, example: {key: function() {}}
if(IS_PURE_FUNCTION.test(serializedFn)) {
return serializedFn;
}

// arrow functions, example: arg1 => arg1+5
if(IS_ARROW_FUNCTION.test(serializedFn)) {
return serializedFn;
}

Q:
when I use serialize like:
{
name: "aa",
attrname: "bb",
render(item, row) {
return JSON.parse(item) .map((it) => it.name).join("");
},
}

the regExp will catch this and cause problem, not when it's commented.
then I test the normal way like this:
{
name: "aa",
attrname: "bb",
render: (item, row) => {
return JSON.parse(item) .map((it) => it.name).join("");
},
}

and:

{
name: "aa",
attrname: "bb",
render: function(item, row) {
return JSON.parse(item) .map((it) => it.name).join("");
},
}

without the regExps, these are also correct.

could you please explain me?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing where IS_PURE_FUNCTION and IS_ARROW_FUNCTION are defined and applied to serializedFn, then compare the three render examples in the issue. Determine whether nested arrow functions are being misclassified and document the expected behavior or a reproducible failing test.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.