d2format: path.Clean imports
This commit is contained in:
parent
f561b831d0
commit
dc1536e8fb
3 changed files with 15 additions and 3 deletions
|
|
@ -216,6 +216,12 @@ func (p *printer) _import(i *d2ast.Import) {
|
|||
p.sb.WriteString(pre)
|
||||
p.sb.WriteRune('/')
|
||||
}
|
||||
if len(i.Path) > 0 {
|
||||
i2 := *i
|
||||
i2.Path = append([]*d2ast.StringBox{}, i.Path...)
|
||||
i2.Path[0] = d2ast.RawStringBox(path.Clean(i.Path[0].Unbox().ScalarString()), true)
|
||||
i = &i2
|
||||
}
|
||||
p.path(i.Path)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -649,6 +649,14 @@ x: @./file
|
|||
x: @../file
|
||||
`,
|
||||
exp: `x: @../file
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "import/4",
|
||||
in: `
|
||||
x: @"x/../file"
|
||||
`,
|
||||
exp: `x: @file
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1742,9 +1742,7 @@ func (p *parser) parseImport(spread bool) *d2ast.Import {
|
|||
if k.Path[0].UnquotedString != nil && len(k.Path) > 1 && k.Path[1].UnquotedString != nil && k.Path[1].Unbox().ScalarString() == "d2" {
|
||||
k.Path = append(k.Path[:1], k.Path[2:]...)
|
||||
}
|
||||
if k != nil {
|
||||
imp.Path = k.Path
|
||||
}
|
||||
imp.Path = k.Path
|
||||
return imp
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue