-
-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
77 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { SourceLocation } from './location' | ||
|
||
export interface CompilerError extends SyntaxError { | ||
code: CompilerErrorCodes | ||
loc?: SourceLocation | ||
} | ||
|
||
export const enum CompilerErrorCodes { | ||
MISSING_END_BRACE, | ||
MISSING_END_PAREN, | ||
// Special value for higher-order compilers to pick up the last code | ||
// to avoid collision of error codes. This should always be kept as the last | ||
// item. | ||
__EXTEND_POINT__ | ||
} | ||
|
||
export const errorMessages: { [code: number]: string } = { | ||
// TODO: | ||
[CompilerErrorCodes.MISSING_END_BRACE]: 'foo' | ||
} | ||
|
||
export function createCompilerError( | ||
code: CompilerErrorCodes, | ||
loc?: SourceLocation, | ||
messages?: { [code: number]: string } | ||
): CompilerError { | ||
const msg = __DEV__ ? (messages || errorMessages)[code] : code | ||
const error = new SyntaxError(String(msg)) as CompilerError | ||
error.code = code | ||
error.loc = loc | ||
return error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters