This commit is contained in:
Alexander Wang 2025-04-03 19:52:41 -06:00
parent 9ea0101dbd
commit 1acd6ef34a
No known key found for this signature in database
GPG key ID: BE3937D0D52D8927
3 changed files with 41 additions and 104 deletions

View file

@ -1732,6 +1732,10 @@ environment: {
}
`,
},
assertions: func(t *testing.T, g *d2graph.Graph) {
assert.Equal(t, 1, len(g.Objects))
assert.Equal(t, "k", g.Objects[0].AbsID())
},
},
{
name: "import-connections",

View file

@ -111,6 +111,14 @@ func (c *compiler) __import(imp *d2ast.Import) (*Map, bool) {
c.compileMap(ir, ast, ast)
// We attempt to resolve variables in the imported file scope first
// But ignore errors, in case the variable is meant to be resolved at the
// importer
savedErrors := make([]d2ast.Error, len(c.err.Errors))
copy(savedErrors, c.err.Errors)
c.compileSubstitutions(ir, nil)
c.err.Errors = savedErrors
c.seenImports[impPath] = struct{}{}
return ir, true

View file

@ -3,41 +3,17 @@
"name": "",
"isFolderOnly": false,
"ast": {
"range": "d2/testdata/d2compiler/TestCompile/import-nested-var.d2,0:0:0-3:0:42",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/import-nested-var.d2,0:0:0-2:1:41",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/import-nested-var.d2,0:0:0-0:11:11",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/import-nested-var.d2,0:0:0-0:11:11",
"value": [
{
"string": "development",
"raw_string": "development"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/import-nested-var.d2,0:13:13-2:1:41",
"range": "d2/testdata/d2compiler/TestCompile/import-nested-var.d2,0:0:0-1:0:23",
"nodes": [
{
"import": {
"range": "d2/testdata/d2compiler/TestCompile/import-nested-var.d2,1:2:17-1:24:39",
"range": "d2/testdata/d2compiler/TestCompile/import-nested-var.d2,0:0:0-0:22:22",
"spread": true,
"pre": "",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/import-nested-var.d2,1:6:21-1:12:27",
"range": "d2/testdata/d2compiler/TestCompile/import-nested-var.d2,0:4:4-0:10:10",
"value": [
{
"string": "models",
@ -48,7 +24,7 @@
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/import-nested-var.d2,1:13:28-1:24:39",
"range": "d2/testdata/d2compiler/TestCompile/import-nested-var.d2,0:11:11-0:22:22",
"value": [
{
"string": "environment",
@ -61,11 +37,6 @@
}
}
]
}
}
}
}
]
},
"root": {
"id": "",
@ -93,63 +64,17 @@
},
"edges": null,
"objects": [
{
"id": "development",
"id_val": "development",
"references": [
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile/import-nested-var.d2,0:0:0-0:11:11",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/import-nested-var.d2,0:0:0-0:11:11",
"value": [
{
"string": "development",
"raw_string": "development"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
}
],
"attributes": {
"label": {
"value": "development"
},
"labelDimensions": {
"width": 0,
"height": 0
},
"style": {},
"iconStyle": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": null
},
"zIndex": 0
},
{
"id": "k",
"id_val": "k",
"references": [
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile/models.d2,8:2:56-8:3:57",
"range": "d2/testdata/d2compiler/TestCompile/models.d2,3:4:20-3:5:21",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/models.d2,8:2:56-8:3:57",
"range": "d2/testdata/d2compiler/TestCompile/models.d2,3:4:20-3:5:21",
"value": [
{
"string": "k",