commit
9f12d50e67
2 changed files with 10 additions and 2 deletions
|
|
@ -28,6 +28,7 @@ type compiler struct {
|
||||||
err *d2parser.ParseError
|
err *d2parser.ParseError
|
||||||
|
|
||||||
fs fs.FS
|
fs fs.FS
|
||||||
|
imports []string
|
||||||
// importStack is used to detect cyclic imports.
|
// importStack is used to detect cyclic imports.
|
||||||
importStack []string
|
importStack []string
|
||||||
// importCache enables reuse of files imported multiple times.
|
// 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() {
|
if !c.err.Empty() {
|
||||||
return nil, nil, c.err
|
return nil, nil, c.err
|
||||||
}
|
}
|
||||||
return m, c.importStack, nil
|
return m, c.imports, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *compiler) overlayClasses(m *Map) {
|
func (c *compiler) overlayClasses(m *Map) {
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,13 @@ func (c *compiler) __import(imp *d2ast.Import) (*Map, bool) {
|
||||||
}
|
}
|
||||||
defer c.popImportStack()
|
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]
|
ir, ok := c.importCache[impPath]
|
||||||
if ok {
|
if ok {
|
||||||
return ir, true
|
return ir, true
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue