Skip to content

Commit

Permalink
Merge pull request #1790 from alixander/amend
Browse files Browse the repository at this point in the history
amend expose imports
  • Loading branch information
alixander authored Dec 25, 2023
2 parents 2bb4f98 + 7045eb9 commit 9f12d50
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions d2ir/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions d2ir/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9f12d50

Please sign in to comment.