Skip to content

Instantly share code, notes, and snippets.

@mathjazz
Created January 24, 2018 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mathjazz/4be883ea2562e2cbb59ca26beecf1e93 to your computer and use it in GitHub Desktop.
Save mathjazz/4be883ea2562e2cbb59ca26beecf1e93 to your computer and use it in GitHub Desktop.
serializeExpression
function serializeExpression(expression) {
if (expression.type === 'MessageReference') {
return expression.id.name;
}
if (expression.type === 'ExternalArgument') {
return '$' + expression.id.name;
}
if (expression.type === 'NumberExpression') {
return expression.value || expression.val.value;
}
if (expression.type === 'StringExpression') {
return '"' + (expression.value || expression.val.value) + '"';
}
if (expression.type === 'NamedArgument') {
return expression.name.name + ': ' + serializeExpression(expression.val);
}
if (expression.type === 'CallExpression') {
var args = [];
expression.args.forEach(function (arg) {
args.push(serializeExpression(arg));
});
return expression.callee.name + '(' + args.join(', ') + ')';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment