Skip to content

Where can I change the AST node's value? #1641

Answered by msujew
negahama asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @negahama,

you shouldn't attempt to change the AST. I would instead recommend you to perform the offset (i.e. -1) operation during the transpilation. That way you don't need to keep track of the offset during all other operations (like validation, etc.). You would essentially do something like this:

function transpileExpression(expression: Expression): string {
  const text = transpileExpressionInternal(expression);
  if (isOffsetRequired(expression)) {
    return `${text} - 1`;
  } else {
    return text;
  }
}

function isOffsetRequired(expression: Expression): boolean {
  const container = expression.$container;
  if (isArrayAccess(container)) {
    return true;
  }
  if (isFunctio…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@negahama
Comment options

@cdietrich
Comment options

@negahama
Comment options

@msujew
Comment options

Answer selected by negahama
@negahama
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants