d2 icon indicating copy to clipboard operation
d2 copied to clipboard

compiler: overriding substitutions

Open alixander opened this issue 2 years ago • 2 comments

This should've overridden the label set by the substitution. Since the compiler has to compile the current map to get the variables, we compile substitutions only after.

Screen Shot 2023-11-10 at 3 06 23 PM

One simple solution is to do two passes. The first pass to build up the variable stack and the second to make the subs.

alixander avatar Nov 10 '23 23:11 alixander

nvm, vars has to be reimplemented.

Consider this:

vars: {
  x: {
    label: var-set
  }
}
a: ${x}
a.label: self-set

b.label: self-set
b: ${x}

You just can't know after map compilation whether the substitution came before or after.

We just compile vars in main map compilation. Every time we pop out of a map, we should pop stack of vars.

alixander avatar Dec 08 '23 05:12 alixander

related when working on this: https://github.com/terrastruct/d2/issues/2017

alixander avatar Jul 25 '24 17:07 alixander