Skip to content

Commit

Permalink
catch error when unicode escaping detected; tag 0.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Nov 7, 2021
1 parent 4fdfe47 commit dcb2383
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cirru/parser.ts",
"version": "0.0.4",
"version": "0.0.5",
"description": "Cirru Parser in TypeScript",
"main": "lib/index.js",
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ let lex = (initialCode: string) => {
case "\\":
[acc, state, buffer] = [acc, ELexState.string, `${buffer}\\`];
break;
case "u":
console.warn(`unicode escaping not supported yet, ${code.slice(pointer - 1, pointer + 10)}...`);
[acc, state, buffer] = [acc, ELexState.string, `${buffer}\\u`];
break;
default:
throw new Error(`Unknown ${c} in escape`);
}
Expand Down
10 changes: 10 additions & 0 deletions src/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,13 @@ test("unfolding", () => {
let data = require(path.join(__dirname, "../test/ast/unfolding.json"));
expect(parse(code)).toEqual(data);
});

test("with escaping", () => {
let code = `"\'a"`;
let data = [["'a"]];
expect(parse(code)).toEqual(data);

code = `"\\u{3455}"`;
data = [["\\u{3455}"]];
expect(parse(code)).toEqual(data);
});

0 comments on commit dcb2383

Please sign in to comment.