globs: fix imported case
This commit is contained in:
parent
3edfaa4fe1
commit
12b166b398
4 changed files with 467 additions and 2 deletions
|
|
@ -33,3 +33,4 @@
|
|||
- Fixes incorrect grid cell positioning when the grid has a shape set and fixes content sometimes escaping circle shapes. [#1734](https://github.com/terrastruct/d2/pull/1734)
|
||||
- Fixes content sometimes escaping cloud shapes. [#1736](https://github.com/terrastruct/d2/pull/1736)
|
||||
- Fixes panic using a glob filter (e.g. `&a`) outside globs. [#1748](https://github.com/terrastruct/d2/pull/1748)
|
||||
- Fixes glob keys with import values (e.g. `user*: @lib/user`). [#1755](https://github.com/terrastruct/d2/pull/1755)
|
||||
|
|
|
|||
|
|
@ -419,8 +419,10 @@ func (c *compiler) ampersandFilterMap(dst *Map, ast, scopeAST *d2ast.Map) bool {
|
|||
func (c *compiler) compileMap(dst *Map, ast, scopeAST *d2ast.Map) {
|
||||
var globs []*globContext
|
||||
if len(c.globContextStack) > 0 {
|
||||
previousGlobs := c.globContextStack[len(c.globContextStack)-1]
|
||||
if NodeBoardKind(dst) == BoardLayer {
|
||||
previousGlobs := c.globContexts()
|
||||
// A root layer with existing glob context stack implies it's an import
|
||||
// In which case, the previous globs should be inherited (the else block)
|
||||
if NodeBoardKind(dst) == BoardLayer && !dst.Root() {
|
||||
for _, g := range previousGlobs {
|
||||
if g.refctx.Key.HasTripleGlob() {
|
||||
globs = append(globs, g.prefixed(dst))
|
||||
|
|
|
|||
|
|
@ -184,6 +184,21 @@ label: meow`,
|
|||
assertQuery(t, m, 0, 0, 1, "hi")
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "pattern-value",
|
||||
run: func(t testing.TB) {
|
||||
_, err := compileFS(t, "index.d2", map[string]string{
|
||||
"index.d2": `userWebsite
|
||||
userMobile
|
||||
|
||||
user*: @x
|
||||
`,
|
||||
"x.d2": `shape: person
|
||||
label: meow`,
|
||||
})
|
||||
assert.Success(t, err)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
runa(t, tca)
|
||||
|
|
|
|||
447
testdata/d2ir/TestCompile/imports/pattern-value.exp.json
generated
vendored
Normal file
447
testdata/d2ir/TestCompile/imports/pattern-value.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,447 @@
|
|||
{
|
||||
"fields": [
|
||||
{
|
||||
"name": "userWebsite",
|
||||
"composite": {
|
||||
"fields": [
|
||||
{
|
||||
"name": "shape",
|
||||
"primary": {
|
||||
"value": {
|
||||
"range": "x.d2,0:7:7-0:13:13",
|
||||
"value": [
|
||||
{
|
||||
"string": "person",
|
||||
"raw_string": "person"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"string": {
|
||||
"range": "x.d2,0:0:0-0:5:5",
|
||||
"value": [
|
||||
{
|
||||
"string": "shape",
|
||||
"raw_string": "shape"
|
||||
}
|
||||
]
|
||||
},
|
||||
"key_path": {
|
||||
"range": "x.d2,0:0:0-0:5:5",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "x.d2,0:0:0-0:5:5",
|
||||
"value": [
|
||||
{
|
||||
"string": "shape",
|
||||
"raw_string": "shape"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"context": {
|
||||
"edge": null,
|
||||
"key": {
|
||||
"range": "x.d2,0:0:0-0:13:13",
|
||||
"key": {
|
||||
"range": "x.d2,0:0:0-0:5:5",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "x.d2,0:0:0-0:5:5",
|
||||
"value": [
|
||||
{
|
||||
"string": "shape",
|
||||
"raw_string": "shape"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {
|
||||
"unquoted_string": {
|
||||
"range": "x.d2,0:7:7-0:13:13",
|
||||
"value": [
|
||||
{
|
||||
"string": "person",
|
||||
"raw_string": "person"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"due_to_glob": true,
|
||||
"due_to_lazy_glob": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "label",
|
||||
"primary": {
|
||||
"value": {
|
||||
"range": "x.d2,1:7:21-1:11:25",
|
||||
"value": [
|
||||
{
|
||||
"string": "meow",
|
||||
"raw_string": "meow"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"string": {
|
||||
"range": "x.d2,1:0:14-1:5:19",
|
||||
"value": [
|
||||
{
|
||||
"string": "label",
|
||||
"raw_string": "label"
|
||||
}
|
||||
]
|
||||
},
|
||||
"key_path": {
|
||||
"range": "x.d2,1:0:14-1:5:19",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "x.d2,1:0:14-1:5:19",
|
||||
"value": [
|
||||
{
|
||||
"string": "label",
|
||||
"raw_string": "label"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"context": {
|
||||
"edge": null,
|
||||
"key": {
|
||||
"range": "x.d2,1:0:14-1:11:25",
|
||||
"key": {
|
||||
"range": "x.d2,1:0:14-1:5:19",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "x.d2,1:0:14-1:5:19",
|
||||
"value": [
|
||||
{
|
||||
"string": "label",
|
||||
"raw_string": "label"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {
|
||||
"unquoted_string": {
|
||||
"range": "x.d2,1:7:21-1:11:25",
|
||||
"value": [
|
||||
{
|
||||
"string": "meow",
|
||||
"raw_string": "meow"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"due_to_glob": true,
|
||||
"due_to_lazy_glob": false
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"edges": null
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"string": {
|
||||
"range": "index.d2,0:0:0-0:11:11",
|
||||
"value": [
|
||||
{
|
||||
"string": "userWebsite",
|
||||
"raw_string": "userWebsite"
|
||||
}
|
||||
]
|
||||
},
|
||||
"key_path": {
|
||||
"range": "index.d2,0:0:0-0:11:11",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "index.d2,0:0:0-0:11:11",
|
||||
"value": [
|
||||
{
|
||||
"string": "userWebsite",
|
||||
"raw_string": "userWebsite"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"context": {
|
||||
"edge": null,
|
||||
"key": {
|
||||
"range": "index.d2,0:0:0-0:11:11",
|
||||
"key": {
|
||||
"range": "index.d2,0:0:0-0:11:11",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "index.d2,0:0:0-0:11:11",
|
||||
"value": [
|
||||
{
|
||||
"string": "userWebsite",
|
||||
"raw_string": "userWebsite"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {}
|
||||
}
|
||||
},
|
||||
"due_to_glob": false,
|
||||
"due_to_lazy_glob": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "userMobile",
|
||||
"composite": {
|
||||
"fields": [
|
||||
{
|
||||
"name": "shape",
|
||||
"primary": {
|
||||
"value": {
|
||||
"range": "x.d2,0:7:7-0:13:13",
|
||||
"value": [
|
||||
{
|
||||
"string": "person",
|
||||
"raw_string": "person"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"string": {
|
||||
"range": "x.d2,0:0:0-0:5:5",
|
||||
"value": [
|
||||
{
|
||||
"string": "shape",
|
||||
"raw_string": "shape"
|
||||
}
|
||||
]
|
||||
},
|
||||
"key_path": {
|
||||
"range": "x.d2,0:0:0-0:5:5",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "x.d2,0:0:0-0:5:5",
|
||||
"value": [
|
||||
{
|
||||
"string": "shape",
|
||||
"raw_string": "shape"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"context": {
|
||||
"edge": null,
|
||||
"key": {
|
||||
"range": "x.d2,0:0:0-0:13:13",
|
||||
"key": {
|
||||
"range": "x.d2,0:0:0-0:5:5",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "x.d2,0:0:0-0:5:5",
|
||||
"value": [
|
||||
{
|
||||
"string": "shape",
|
||||
"raw_string": "shape"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {
|
||||
"unquoted_string": {
|
||||
"range": "x.d2,0:7:7-0:13:13",
|
||||
"value": [
|
||||
{
|
||||
"string": "person",
|
||||
"raw_string": "person"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"due_to_glob": true,
|
||||
"due_to_lazy_glob": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "label",
|
||||
"primary": {
|
||||
"value": {
|
||||
"range": "x.d2,1:7:21-1:11:25",
|
||||
"value": [
|
||||
{
|
||||
"string": "meow",
|
||||
"raw_string": "meow"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"string": {
|
||||
"range": "x.d2,1:0:14-1:5:19",
|
||||
"value": [
|
||||
{
|
||||
"string": "label",
|
||||
"raw_string": "label"
|
||||
}
|
||||
]
|
||||
},
|
||||
"key_path": {
|
||||
"range": "x.d2,1:0:14-1:5:19",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "x.d2,1:0:14-1:5:19",
|
||||
"value": [
|
||||
{
|
||||
"string": "label",
|
||||
"raw_string": "label"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"context": {
|
||||
"edge": null,
|
||||
"key": {
|
||||
"range": "x.d2,1:0:14-1:11:25",
|
||||
"key": {
|
||||
"range": "x.d2,1:0:14-1:5:19",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "x.d2,1:0:14-1:5:19",
|
||||
"value": [
|
||||
{
|
||||
"string": "label",
|
||||
"raw_string": "label"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {
|
||||
"unquoted_string": {
|
||||
"range": "x.d2,1:7:21-1:11:25",
|
||||
"value": [
|
||||
{
|
||||
"string": "meow",
|
||||
"raw_string": "meow"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"due_to_glob": true,
|
||||
"due_to_lazy_glob": false
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"edges": null
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"string": {
|
||||
"range": "index.d2,1:0:12-1:10:22",
|
||||
"value": [
|
||||
{
|
||||
"string": "userMobile",
|
||||
"raw_string": "userMobile"
|
||||
}
|
||||
]
|
||||
},
|
||||
"key_path": {
|
||||
"range": "index.d2,1:0:12-1:10:22",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "index.d2,1:0:12-1:10:22",
|
||||
"value": [
|
||||
{
|
||||
"string": "userMobile",
|
||||
"raw_string": "userMobile"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"context": {
|
||||
"edge": null,
|
||||
"key": {
|
||||
"range": "index.d2,1:0:12-1:10:22",
|
||||
"key": {
|
||||
"range": "index.d2,1:0:12-1:10:22",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "index.d2,1:0:12-1:10:22",
|
||||
"value": [
|
||||
{
|
||||
"string": "userMobile",
|
||||
"raw_string": "userMobile"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {}
|
||||
}
|
||||
},
|
||||
"due_to_glob": false,
|
||||
"due_to_lazy_glob": false
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"edges": null
|
||||
}
|
||||
Loading…
Reference in a new issue