Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support anonymous and arrow callbacks #1

Merged
merged 4 commits into from
Feb 22, 2022

Conversation

ivov
Copy link
Collaborator

@ivov ivov commented Nov 30, 2021

This PR enables evaluation for anonymous and arrow callbacks, which currently fail with Expression is not valid: missing ) after argument list and Expression is not valid: Malformed arrow function parameter list, respectively.

Support added for:

  • same-line anonymous callback
  • single-line anonymous callback
  • multi-line anonymous callback
  • same-line arrow callback, immediate return
  • same-line arrow callback, standard return
  • single-line arrow callback
const tmpl = require('./dist/tmpl.js').tmpl;

const anon1 = tmpl('{ [1, 2, 3].filter(function (v) { return v > 2 }) }');
const anon2 = tmpl(`{ [1, 2, 3].filter(function (v) {
  return v > 2
})}`);
const anon3 = tmpl(`{ [1, 2, 3].filter(function (v) {
  const a = 1;
  return v > 2
})}`);

const arrow1 = tmpl('{ [1, 2, 3].filter((v) => v > 2) }');
const arrow2 = tmpl('{ [1, 2, 3].filter((v) => { return v > 2 }) }');
const arrow3 = tmpl(`{ [1, 2, 3].filter((v) => {
  return v > 2
}) }`);

console.log(anon1);  // [3]
console.log(anon2);  // [3]
console.log(anon3);  // [3]
console.log(arrow1); // [3]
console.log(arrow2); // [3]
console.log(arrow3); // [3]

Note:

  • This failing test is pre-existent: expressions are just regular JavaScript
  • Multi-line arrow callbacks are unsupported for now, to reduce scope.

@csuermann
Copy link

Hi @ivov,

As expressions are such a critical feature of n8n, it would be good to have decent test coverage for any changes we do. Would you agree?

@ivov
Copy link
Collaborator Author

ivov commented Dec 13, 2021

Done. For reference there were no tests at all for expressions.

@ahsanv ahsanv merged commit 97b32ff into master Feb 22, 2022
valya added a commit that referenced this pull request May 23, 2023
valya added a commit that referenced this pull request May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants