mirror of
https://github.com/jamiebuilds/the-super-tiny-compiler.git
synced 2024-10-27 20:34:08 +00:00
style: prefer const over let
This commit is contained in:
parent
f0321d5b1d
commit
731624c451
@ -384,7 +384,7 @@ function tokenizer(input) {
|
|||||||
let current = 0;
|
let current = 0;
|
||||||
|
|
||||||
// And a `tokens` array for pushing our tokens to.
|
// And a `tokens` array for pushing our tokens to.
|
||||||
let tokens = [];
|
const tokens = [];
|
||||||
|
|
||||||
// We start by creating a `while` loop where we are setting up our `current`
|
// We start by creating a `while` loop where we are setting up our `current`
|
||||||
// variable to be incremented as much as we want `inside` the loop.
|
// variable to be incremented as much as we want `inside` the loop.
|
||||||
@ -436,7 +436,7 @@ function tokenizer(input) {
|
|||||||
//
|
//
|
||||||
// So here we're just going to test for existence and if it does exist we're
|
// So here we're just going to test for existence and if it does exist we're
|
||||||
// going to just `continue` on.
|
// going to just `continue` on.
|
||||||
let WHITESPACE = /\s/;
|
const WHITESPACE = /\s/;
|
||||||
if (WHITESPACE.test(char)) {
|
if (WHITESPACE.test(char)) {
|
||||||
current++;
|
current++;
|
||||||
continue;
|
continue;
|
||||||
@ -451,7 +451,7 @@ function tokenizer(input) {
|
|||||||
// Only two separate tokens
|
// Only two separate tokens
|
||||||
//
|
//
|
||||||
// So we start this off when we encounter the first number in a sequence.
|
// So we start this off when we encounter the first number in a sequence.
|
||||||
let NUMBERS = /[0-9]/;
|
const NUMBERS = /[0-9]/;
|
||||||
if (NUMBERS.test(char)) {
|
if (NUMBERS.test(char)) {
|
||||||
|
|
||||||
// We're going to create a `value` string that we are going to push
|
// We're going to create a `value` string that we are going to push
|
||||||
@ -511,7 +511,7 @@ function tokenizer(input) {
|
|||||||
// ^^^
|
// ^^^
|
||||||
// Name token
|
// Name token
|
||||||
//
|
//
|
||||||
let LETTERS = /[a-z]/i;
|
const LETTERS = /[a-z]/i;
|
||||||
if (LETTERS.test(char)) {
|
if (LETTERS.test(char)) {
|
||||||
let value = '';
|
let value = '';
|
||||||
|
|
||||||
@ -606,7 +606,7 @@ function parser(tokens) {
|
|||||||
// We create a base node with the type `CallExpression`, and we're going
|
// We create a base node with the type `CallExpression`, and we're going
|
||||||
// to set the name as the current token's value since the next token after
|
// to set the name as the current token's value since the next token after
|
||||||
// the open parenthesis is the name of the function.
|
// the open parenthesis is the name of the function.
|
||||||
let node = {
|
const node = {
|
||||||
type: 'CallExpression',
|
type: 'CallExpression',
|
||||||
name: token.value,
|
name: token.value,
|
||||||
params: [],
|
params: [],
|
||||||
@ -674,7 +674,7 @@ function parser(tokens) {
|
|||||||
|
|
||||||
// Now, we're going to create our AST which will have a root which is a
|
// Now, we're going to create our AST which will have a root which is a
|
||||||
// `Program` node.
|
// `Program` node.
|
||||||
let ast = {
|
const ast = {
|
||||||
type: 'Program',
|
type: 'Program',
|
||||||
body: [],
|
body: [],
|
||||||
};
|
};
|
||||||
@ -756,7 +756,7 @@ function traverser(ast, visitor) {
|
|||||||
|
|
||||||
// We start by testing for the existence of a method on the visitor with a
|
// We start by testing for the existence of a method on the visitor with a
|
||||||
// matching `type`.
|
// matching `type`.
|
||||||
let methods = visitor[node.type];
|
const methods = visitor[node.type];
|
||||||
|
|
||||||
// If there is an `enter` method for this node type we'll call it with the
|
// If there is an `enter` method for this node type we'll call it with the
|
||||||
// `node` and its `parent`.
|
// `node` and its `parent`.
|
||||||
@ -859,7 +859,7 @@ function transformer(ast) {
|
|||||||
|
|
||||||
// We'll create a `newAst` which like our previous AST will have a program
|
// We'll create a `newAst` which like our previous AST will have a program
|
||||||
// node.
|
// node.
|
||||||
let newAst = {
|
const newAst = {
|
||||||
type: 'Program',
|
type: 'Program',
|
||||||
body: [],
|
body: [],
|
||||||
};
|
};
|
||||||
@ -1026,10 +1026,10 @@ function codeGenerator(node) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function compiler(input) {
|
function compiler(input) {
|
||||||
let tokens = tokenizer(input);
|
const tokens = tokenizer(input);
|
||||||
let ast = parser(tokens);
|
const ast = parser(tokens);
|
||||||
let newAst = transformer(ast);
|
const newAst = transformer(ast);
|
||||||
let output = codeGenerator(newAst);
|
const output = codeGenerator(newAst);
|
||||||
|
|
||||||
// and simply return the output!
|
// and simply return the output!
|
||||||
return output;
|
return output;
|
||||||
|
Loading…
Reference in New Issue
Block a user