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
1 parent
23e0bf1
commit f07223d
Showing
1 changed file
with
21 additions
and
0 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,21 @@ | ||
import { parse } from "../lib"; | ||
|
||
describe("error codes", function () { | ||
it("raises an error with BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED and reasonCode", function () { | ||
const code = `import "foo"`; | ||
const { errors } = parse(code, { | ||
errorRecovery: true, | ||
sourceType: "script", | ||
}); | ||
const error = errors[0]; | ||
expect(error.code).toBe("BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED"); | ||
expect(error.reasonCode).toBe("ImportOutsideModule"); | ||
}); | ||
it("raises an error with BABEL_PARSER_SYNTAX_ERROR and reasonCode", function () { | ||
const code = `a b`; | ||
const { errors } = parse(code, { errorRecovery: true }); | ||
const error = errors[0]; | ||
expect(error.code).toBe("BABEL_PARSER_SYNTAX_ERROR"); | ||
expect(error.reasonCode).toBe("MissingSemicolon"); | ||
}); | ||
}); |