Merge pull request #1550 from alixander/no-ast-modify
dont modify ast when modifying links in the IR
This commit is contained in:
commit
c670987516
7 changed files with 36 additions and 26 deletions
|
|
@ -580,14 +580,14 @@ func (c *compiler) _compileField(f *Field, refctx *RefContext) {
|
|||
}
|
||||
}
|
||||
} else if refctx.Key.Value.ScalarBox().Unbox() != nil {
|
||||
// If the link is a board, we need to transform it into an absolute path.
|
||||
if f.Name == "link" {
|
||||
c.compileLink(refctx)
|
||||
}
|
||||
f.Primary_ = &Scalar{
|
||||
parent: f,
|
||||
Value: refctx.Key.Value.ScalarBox().Unbox(),
|
||||
}
|
||||
// If the link is a board, we need to transform it into an absolute path.
|
||||
if f.Name == "link" {
|
||||
c.compileLink(f, refctx)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -624,7 +624,7 @@ func (c *compiler) updateLinks(m *Map) {
|
|||
}
|
||||
}
|
||||
|
||||
func (c *compiler) compileLink(refctx *RefContext) {
|
||||
func (c *compiler) compileLink(f *Field, refctx *RefContext) {
|
||||
val := refctx.Key.Value.ScalarBox().Unbox().ScalarString()
|
||||
link, err := d2parser.ParseKey(val)
|
||||
if err != nil {
|
||||
|
|
@ -683,7 +683,7 @@ func (c *compiler) compileLink(refctx *RefContext) {
|
|||
// Create the absolute path by appending scope path with value specified
|
||||
scopeIDA = append(scopeIDA, linkIDA...)
|
||||
kp := d2ast.MakeKeyPath(scopeIDA)
|
||||
refctx.Key.Value = d2ast.MakeValueBox(d2ast.FlatUnquotedString(d2format.Format(kp)))
|
||||
f.Primary_.Value = d2ast.FlatUnquotedString(d2format.Format(kp))
|
||||
}
|
||||
|
||||
func (c *compiler) compileEdges(refctx *RefContext) {
|
||||
|
|
|
|||
5
testdata/d2compiler/TestCompile/link-board-key-nested.exp.json
generated
vendored
5
testdata/d2compiler/TestCompile/link-board-key-nested.exp.json
generated
vendored
|
|
@ -62,10 +62,11 @@
|
|||
"primary": {},
|
||||
"value": {
|
||||
"unquoted_string": {
|
||||
"range": ",0:0:0-0:0:0",
|
||||
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,1:10:15-1:18:23",
|
||||
"value": [
|
||||
{
|
||||
"string": "root.layers.x"
|
||||
"string": "layers.x",
|
||||
"raw_string": "layers.x"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
5
testdata/d2compiler/TestCompile/link-board-mixed.exp.json
generated
vendored
5
testdata/d2compiler/TestCompile/link-board-mixed.exp.json
generated
vendored
|
|
@ -71,10 +71,11 @@
|
|||
"primary": {},
|
||||
"value": {
|
||||
"unquoted_string": {
|
||||
"range": ",0:0:0-0:0:0",
|
||||
"range": "d2/testdata/d2compiler/TestCompile/link-board-mixed.d2,1:15:46-1:25:56",
|
||||
"value": [
|
||||
{
|
||||
"string": "root.layers.cat"
|
||||
"string": "layers.cat",
|
||||
"raw_string": "layers.cat"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
5
testdata/d2compiler/TestCompile/link-board-nested.exp.json
generated
vendored
5
testdata/d2compiler/TestCompile/link-board-nested.exp.json
generated
vendored
|
|
@ -38,10 +38,11 @@
|
|||
"primary": {},
|
||||
"value": {
|
||||
"unquoted_string": {
|
||||
"range": ",0:0:0-0:0:0",
|
||||
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:8:8-0:25:25",
|
||||
"value": [
|
||||
{
|
||||
"string": "root.layers.x.layers.x"
|
||||
"string": "layers.x.layers.x",
|
||||
"raw_string": "layers.x.layers.x"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
5
testdata/d2compiler/TestCompile/link-board-ok.exp.json
generated
vendored
5
testdata/d2compiler/TestCompile/link-board-ok.exp.json
generated
vendored
|
|
@ -38,10 +38,11 @@
|
|||
"primary": {},
|
||||
"value": {
|
||||
"unquoted_string": {
|
||||
"range": ",0:0:0-0:0:0",
|
||||
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,0:8:8-0:16:16",
|
||||
"value": [
|
||||
{
|
||||
"string": "root.layers.x"
|
||||
"string": "layers.x",
|
||||
"raw_string": "layers.x"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
10
testdata/d2compiler/TestCompile/link-board-underscore.exp.json
generated
vendored
10
testdata/d2compiler/TestCompile/link-board-underscore.exp.json
generated
vendored
|
|
@ -180,10 +180,11 @@
|
|||
"primary": {},
|
||||
"value": {
|
||||
"unquoted_string": {
|
||||
"range": ",0:0:0-0:0:0",
|
||||
"range": "d2/testdata/d2compiler/TestCompile/link-board-underscore.d2,6:20:69-6:32:81",
|
||||
"value": [
|
||||
{
|
||||
"string": "root.layers.x"
|
||||
"string": "_._.layers.x",
|
||||
"raw_string": "_._.layers.x"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -223,10 +224,11 @@
|
|||
"primary": {},
|
||||
"value": {
|
||||
"unquoted_string": {
|
||||
"range": ",0:0:0-0:0:0",
|
||||
"range": "d2/testdata/d2compiler/TestCompile/link-board-underscore.d2,7:18:100-7:19:101",
|
||||
"value": [
|
||||
{
|
||||
"string": "root.layers.x"
|
||||
"string": "_",
|
||||
"raw_string": "_"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
20
testdata/d2ir/TestCompile/imports/boards.exp.json
generated
vendored
20
testdata/d2ir/TestCompile/imports/boards.exp.json
generated
vendored
|
|
@ -88,10 +88,11 @@
|
|||
"primary": {},
|
||||
"value": {
|
||||
"unquoted_string": {
|
||||
"range": ",0:0:0-0:0:0",
|
||||
"range": "index.d2,0:8:8-0:16:16",
|
||||
"value": [
|
||||
{
|
||||
"string": "root.layers.x"
|
||||
"string": "layers.x",
|
||||
"raw_string": "layers.x"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -176,10 +177,11 @@
|
|||
"primary": {},
|
||||
"value": {
|
||||
"unquoted_string": {
|
||||
"range": ",0:0:0-0:0:0",
|
||||
"range": "index.d2,0:8:8-0:16:16",
|
||||
"value": [
|
||||
{
|
||||
"string": "root.layers.x"
|
||||
"string": "layers.x",
|
||||
"raw_string": "layers.x"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -285,10 +287,11 @@
|
|||
"primary": {},
|
||||
"value": {
|
||||
"unquoted_string": {
|
||||
"range": ",0:0:0-0:0:0",
|
||||
"range": "x.d2,0:8:8-0:16:16",
|
||||
"value": [
|
||||
{
|
||||
"string": "root.layers.y"
|
||||
"string": "layers.y",
|
||||
"raw_string": "layers.y"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -373,10 +376,11 @@
|
|||
"primary": {},
|
||||
"value": {
|
||||
"unquoted_string": {
|
||||
"range": ",0:0:0-0:0:0",
|
||||
"range": "x.d2,0:8:8-0:16:16",
|
||||
"value": [
|
||||
{
|
||||
"string": "root.layers.y"
|
||||
"string": "layers.y",
|
||||
"raw_string": "layers.y"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue