瀏覽代碼

Don't need to nest ifs like that

master
Dylan Baker 5 年之前
父節點
當前提交
3bfb3f356e
共有 1 個檔案被更改,包括 7 行新增14 行删除
  1. 7
    14
      src/moss.ts

+ 7
- 14
src/moss.ts 查看文件

@@ -15,7 +15,6 @@ import Parser, { ParserError } from './parser';
15 15
 // };
16 16
 
17 17
 const rawArgs = minimist(process.argv.slice(2));
18
-
19 18
 const args = {
20 19
   eval: rawArgs.e || rawArgs.eval,
21 20
   file: rawArgs.f || rawArgs.file,
@@ -37,19 +36,13 @@ const moss = (
37 36
 ): LexerError | ParserError | EnvError | string => {
38 37
   const lexer = new Lexer(source, file);
39 38
   const tokens = lexer.scan();
40
-  if (tokens instanceof LexerError) {
41
-    return tokens;
42
-  } else {
43
-    const parser = new Parser(tokens);
44
-    const tree = parser.parse();
45
-    // print(tree);
46
-    if (tree instanceof ParserError) {
47
-      return tree;
48
-    } else {
49
-      const compiler = new Compiler(tree, { prettyPrint: args.pretty });
50
-      return compiler.compile();
51
-    }
52
-  }
39
+  if (tokens instanceof LexerError) return tokens;
40
+  const parser = new Parser(tokens);
41
+  const tree = parser.parse();
42
+  // print(tree);
43
+  if (tree instanceof ParserError) return tree;
44
+  const compiler = new Compiler(tree, { prettyPrint: args.pretty });
45
+  return compiler.compile();
53 46
 };
54 47
 
55 48
 const run = () => {

Loading…
取消
儲存