♻️ Change indentation

pull/65/head
RafaAudibert 6 years ago
parent 2857a32b4c
commit 8fc5f22d6b

@ -594,10 +594,7 @@ function parser(tokens) {
// Next we're going to look for CallExpressions. We start this off when we // Next we're going to look for CallExpressions. We start this off when we
// encounter an open parenthesis. // encounter an open parenthesis.
if ( if (token.type === 'paren' && token.value === '(') {
token.type === 'paren' &&
token.value === '('
) {
// We'll increment `current` to skip the parenthesis since we don't care // We'll increment `current` to skip the parenthesis since we don't care
// about it in our AST. // about it in our AST.
@ -971,23 +968,14 @@ function codeGenerator(node) {
// For `ExpressionStatement` we'll call the code generator on the nested // For `ExpressionStatement` we'll call the code generator on the nested
// expression and we'll add a semicolon... // expression and we'll add a semicolon...
case 'ExpressionStatement': case 'ExpressionStatement':
return ( return `${codeGenerator(node.expression)};`;
codeGenerator(node.expression) +
';' // << (...because we like to code the *correct* way)
);
// For `CallExpression` we will print the `callee`, add an open // For `CallExpression` we will print the `callee`, add an open
// parenthesis, we'll map through each node in the `arguments` array and run // parenthesis, we'll map through each node in the `arguments` array and run
// them through the code generator, joining them with a comma, and then // them through the code generator, joining them with a comma, and then
// we'll add a closing parenthesis. // we'll add a closing parenthesis.
case 'CallExpression': case 'CallExpression':
return ( return codeGenerator(node.callee) + '(' + node.arguments.map(codeGenerator).join(', ') + ')';
codeGenerator(node.callee) +
'(' +
node.arguments.map(codeGenerator)
.join(', ') +
')'
);
// For `Identifier` we'll just return the `node`'s name. // For `Identifier` we'll just return the `node`'s name.
case 'Identifier': case 'Identifier':
@ -999,7 +987,7 @@ function codeGenerator(node) {
// For `StringLiteral` we'll add quotations around the `node`'s value. // For `StringLiteral` we'll add quotations around the `node`'s value.
case 'StringLiteral': case 'StringLiteral':
return '"' + node.value + '"'; return `"${node.value}"`;
// And if we haven't recognized the node, we'll throw an error. // And if we haven't recognized the node, we'll throw an error.
default: default:

Loading…
Cancel
Save