|
| 1 | +import { CompilerError } from '@syntaxs/compiler'; |
1 | 2 | import { FULL_MODULE_NAME } from '../index.js';
|
2 | 3 | import { arg } from './arg.js';
|
3 | 4 | import chalk from 'chalk';
|
@@ -37,6 +38,17 @@ export namespace log {
|
37 | 38 | message.forEach(m => console.info(`${chalk.bgBlue(' INFO ')}`, m));
|
38 | 39 | }
|
39 | 40 |
|
| 41 | + /** |
| 42 | + * Logs a {@link CompilerError} as an error. |
| 43 | + * @param e The error. |
| 44 | + * @author efekos |
| 45 | + * @version 1.0.0 |
| 46 | + * @since 0.0.1-alpha |
| 47 | + */ |
| 48 | + export function compilerError(e: CompilerError) { |
| 49 | + log.error(`${chalk.gray(`(${e.file}:${e.range.start.line}:${e.range.start.character})`)} ${e.message}`); |
| 50 | + } |
| 51 | + |
40 | 52 | /**
|
41 | 53 | * Logs every message given as a warning.
|
42 | 54 | * @param {any[]} message Messages to log.
|
@@ -86,6 +98,20 @@ export namespace log {
|
86 | 98 | process.exit(1);
|
87 | 99 | }
|
88 | 100 |
|
| 101 | + |
| 102 | + /** |
| 103 | + * Alias for {@link log.compilerError}, but exits the process after logging. |
| 104 | + * @param e The error. |
| 105 | + * @author efekos |
| 106 | + * @version 1.0.0 |
| 107 | + * @since 0.0.1-alpha |
| 108 | + */ |
| 109 | + export function compilerError(e: CompilerError) { |
| 110 | + log.compilerError(e); |
| 111 | + log.raw('', '', process.cwd(), FULL_MODULE_NAME); |
| 112 | + process.exit(1); |
| 113 | + } |
| 114 | + |
89 | 115 | /**
|
90 | 116 | * Alias for {@link log.raw}, but exits the process after logging.
|
91 | 117 | * @param {any[]} message Messages to log.
|
@@ -116,6 +142,21 @@ export namespace log {
|
116 | 142 | throw new ProgramError();
|
117 | 143 | }
|
118 | 144 |
|
| 145 | + |
| 146 | + |
| 147 | + /** |
| 148 | + * Alias for {@link log.compilerError}, but throws an error after logging. |
| 149 | + * @param e The error. |
| 150 | + * @author efekos |
| 151 | + * @version 1.0.0 |
| 152 | + * @since 0.0.1-alpha |
| 153 | + */ |
| 154 | + export function compilerError(e: CompilerError) { |
| 155 | + log.compilerError(e); |
| 156 | + throw new ProgramError(); |
| 157 | + } |
| 158 | + |
| 159 | + |
119 | 160 | /**
|
120 | 161 | * Alias for {@link log.raw}, but throws an error after logging.
|
121 | 162 | * @param {any[]} message Messages to log.
|
|
0 commit comments