Skip to content

Commit

Permalink
fix single token error
Browse files Browse the repository at this point in the history
+ 1.0.11 version bump
  • Loading branch information
michal-kapala committed Mar 28, 2024
1 parent 100dada commit 2e20267
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jitterbit-script",
"version": "1.0.10",
"version": "1.0.11",
"description": "Static typechecker and interpreter for Jitterbit Script",
"main": "build/index.js",
"scripts": {
Expand Down
16 changes: 10 additions & 6 deletions src/frontend/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,17 @@ export default class Parser {
}
}
// Remove <trans> and </trans>, restore EOF
this.tokens.shift();
const last = this.tokens.pop() as Token;
if(last.type === TokenType.CloseTransTag) {
this.endTagStart = last.begin;
this.endTagEnd = last.end;
if(diagnostics && this.tokens.length < 2)
return result;
else {
this.tokens.shift();
const last = this.tokens.pop() as Token;
if(last.type === TokenType.CloseTransTag) {
this.endTagStart = last.begin;
this.endTagEnd = last.end;
}
this.tokens.push(new Token("EndOfFile", TokenType.EOF, last.end, last.end));
}
this.tokens.push(new Token("EndOfFile", TokenType.EOF, last.end, last.end));
return result;
}

Expand Down
4 changes: 1 addition & 3 deletions test.jb
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
<trans>
x +
</trans>
<><
18 changes: 18 additions & 0 deletions tests/typechecker/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,22 @@ msg = Case(
const result = typecheck("");
expect(result.diagnostics.length).toStrictEqual(0);
});

test('"<" script.', function() {
const result = typecheck("<");
expect(result.diagnostics.length).toStrictEqual(2);
// No <trans> tag, the script returns its content as string.
expect(result.diagnostics[0].error).toStrictEqual(true);
// The script is missing '</trans>' scope closing tag.
expect(result.diagnostics[1].error).toStrictEqual(true);
});

test('Fish script ("<><").', function() {
const result = typecheck("<");
expect(result.diagnostics.length).toStrictEqual(2);
// No <trans> tag, the script returns its content as string.
expect(result.diagnostics[0].error).toStrictEqual(true);
// The script is missing '</trans>' scope closing tag.
expect(result.diagnostics[1].error).toStrictEqual(true);
});
});

0 comments on commit 2e20267

Please sign in to comment.