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 #25

Closed

Conversation

ivov
Copy link

@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.

Supported:

  • same-line anonymous callback
  • single-line anonymous callback
  • multi-line anonymous callback
  • same-line arrow callback, no body
  • same-line arrow callback, with body
  • 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]

@GianlucaGuarini
Copy link
Member

GianlucaGuarini commented Feb 15, 2022

Thank you for your PR, riot-tmpl is no longer maintained and it was meant to be used on ie9 (during the pre template literals javascript era).
Your PR uses Regex named groups that are not supported on IE so we can not merge it.

Notice that nor arrow functions are supported on older browsers so adding this feature to this package is unnecessary.

Please use template strings on modern browsers and this package on old legacy ones.

Thank you anyway

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.

2 participants