Skip to content

Commit

Permalink
fix: binding param in new operator syntax (#60)
Browse files Browse the repository at this point in the history
* fix: tokenize $ as id than punctuator

tokenizing $ as punctuator is breaking existing workflow engine

* fix: binding param in new operator syntax

this fix is to support new $.CustomError("some error") syntax.
  • Loading branch information
koladilip authored Jun 6, 2024
1 parent 3e09696 commit a5a998c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,11 @@ export class JsonTemplateParser {
private parseIDPath(): string {
const idParts: string[] = [];
while (this.lexer.matchID()) {
idParts.push(this.lexer.value());
let idValue = this.lexer.value();
if (idValue === '$') {
idValue = BINDINGS_PARAM_KEY;
}
idParts.push(idValue);
if (this.lexer.match('.') && this.lexer.matchID(1)) {
this.lexer.ignoreTokens(1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/reverse_translator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export class JsonTemplateReverseTranslator {
code.push(` .${expr.id}`);
}
} else if (expr.id) {
code.push(expr.id);
code.push(expr.id.replace(BINDINGS_PARAM_KEY, '$'));
}
code.push('(');
if (expr.args) {
Expand Down
7 changes: 7 additions & 0 deletions test/scenarios/bindings/data.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Scenario } from '../../types';

class CustomError extends Error {}

export const data: Scenario[] = [
{
templatePath: 'async.jt',
Expand All @@ -10,6 +12,11 @@ export const data: Scenario[] = [
input: [1, 2, 3],
output: [1, 2, 3],
},
{
templatePath: 'new_operator.jt',
bindings: { CustomError },
output: new CustomError('some error'),
},
{
bindings: {
a: 10,
Expand Down
1 change: 1 addition & 0 deletions test/scenarios/bindings/new_operator.jt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
new $.CustomError("some error")

0 comments on commit a5a998c

Please sign in to comment.