Skip to content

Commit

Permalink
Add support for array (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylnuge authored Jul 10, 2024
1 parent 35f549e commit 31bb903
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ export default class Jinter {
} return 'proceed';
});

this.visitor.on('Array', (node, visitor) => {
if (node.type === 'Identifier')
return Array;

if (node.type === 'CallExpression' && node.callee.type === 'MemberExpression') {
const prop: keyof typeof Array = visitor.visitNode(node.callee.property);
const args = node.arguments.map((arg) => visitor.visitNode(arg));
const array_prop = Array[prop] as Function;

if (!array_prop)
return 'proceed';

return array_prop(args);
} return 'proceed';
});

this.visitor.on('Date', (node) => {
if (node.type === 'Identifier')
return Date;
Expand All @@ -88,4 +104,4 @@ export default class Jinter {
public interpret() {
return this.visitor.run();
}
}
}

0 comments on commit 31bb903

Please sign in to comment.