commit
9f12d50e67
2 changed files with 10 additions and 2 deletions
|
|
@ -27,7 +27,8 @@ type globContext struct {
|
|||
type compiler struct {
|
||||
err *d2parser.ParseError
|
||||
|
||||
fs fs.FS
|
||||
fs fs.FS
|
||||
imports []string
|
||||
// importStack is used to detect cyclic imports.
|
||||
importStack []string
|
||||
// importCache enables reuse of files imported multiple times.
|
||||
|
|
@ -80,7 +81,7 @@ func Compile(ast *d2ast.Map, opts *CompileOptions) (*Map, []string, error) {
|
|||
if !c.err.Empty() {
|
||||
return nil, nil, c.err
|
||||
}
|
||||
return m, c.importStack, nil
|
||||
return m, c.imports, nil
|
||||
}
|
||||
|
||||
func (c *compiler) overlayClasses(m *Map) {
|
||||
|
|
|
|||
|
|
@ -80,6 +80,13 @@ func (c *compiler) __import(imp *d2ast.Import) (*Map, bool) {
|
|||
}
|
||||
defer c.popImportStack()
|
||||
|
||||
// Only get immediate imports.
|
||||
if len(c.importStack) == 2 {
|
||||
if _, ok := c.importCache[impPath]; !ok {
|
||||
c.imports = append(c.imports, imp.PathWithPre())
|
||||
}
|
||||
}
|
||||
|
||||
ir, ok := c.importCache[impPath]
|
||||
if ok {
|
||||
return ir, true
|
||||
|
|
|
|||
Loading…
Reference in a new issue