Adding Decorators for comments
This commit is contained in:
@ -4,10 +4,12 @@ import Color from "chalk";
|
||||
import * as Path from "path";
|
||||
import tokenize, { TokenizerError } from "./tokenizer";
|
||||
import parse, { Parsed, ParserError } from "./parser";
|
||||
import get_ir, { IR } from "./ir";
|
||||
import get_ir, { IR, IRError } from "./ir";
|
||||
import compile, { CompileTarget } from "./compile";
|
||||
import { ESMTypescriptTarget, NodeJSTypescriptTarget } from "./targets/typescript";
|
||||
|
||||
class CatchedError extends Error {}
|
||||
|
||||
const log = dbg("app");
|
||||
|
||||
|
||||
@ -75,7 +77,7 @@ type ProcessContext = {
|
||||
processedFiles: Set<string>;
|
||||
};
|
||||
|
||||
function processFile(ctx: ProcessContext, file: string): Parsed | null {
|
||||
function processFile(ctx: ProcessContext, file: string, root = false): Parsed | null {
|
||||
file = Path.resolve(file);
|
||||
if (ctx.processedFiles.has(file)) {
|
||||
log("Skipping file %s since it has already be processed", file);
|
||||
@ -109,13 +111,17 @@ function processFile(ctx: ProcessContext, file: string): Parsed | null {
|
||||
} catch (err) {
|
||||
if (err instanceof TokenizerError) {
|
||||
printError(err, file, err.index);
|
||||
if(!root)
|
||||
throw new CatchedError();
|
||||
} else if (err instanceof ParserError) {
|
||||
printError(err, file, err.token.startIdx);
|
||||
if(!root)
|
||||
throw new CatchedError();
|
||||
} else if(root && err instanceof CatchedError) {
|
||||
return null;
|
||||
} else {
|
||||
throw err;
|
||||
throw err;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,19 +135,27 @@ export default function startCompile(options: CompileOptions) {
|
||||
if(options.input.endsWith(".json")) {
|
||||
ir = JSON.parse(FS.readFileSync(options.input, "utf-8"));
|
||||
} else {
|
||||
const parsed = processFile(ctx, options.input);
|
||||
// console.log(([...parsed].pop() as any).functions)
|
||||
const parsed = processFile(ctx, options.input, true);
|
||||
|
||||
if(!parsed)
|
||||
throw new Error("Error compiling: Parse output is undefined!");
|
||||
|
||||
process.exit(1); // Errors should have already been emitted
|
||||
try {
|
||||
ir = get_ir(parsed);
|
||||
} catch(err) {
|
||||
if(err instanceof IRError) {
|
||||
printError(err, err.statement.location.file, err.statement.location.idx);
|
||||
process.exit(1);
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!ir)
|
||||
throw new Error("Error compiling: Cannot get IR");
|
||||
|
||||
if(options.emitDefinitions) {
|
||||
FS.writeFileSync(options.emitDefinitions, JSON.stringify(ir));
|
||||
FS.writeFileSync(options.emitDefinitions, JSON.stringify(ir, undefined, 3));
|
||||
}
|
||||
|
||||
if(options.targets.length <= 0) {
|
||||
|
Reference in New Issue
Block a user