d2parser: Strip leading ./ from imports

This commit is contained in:
Anmol Sethi 2023-06-06 14:52:54 -07:00
parent bc8f180055
commit 0300b81c31
No known key found for this signature in database
GPG key ID: 8CEF1878FF10ADEB
2 changed files with 15 additions and 0 deletions

View file

@ -633,6 +633,14 @@ x: @file.d2
x: @file."d2"
`,
exp: `x: @file."d2"
`,
},
{
name: "import/3",
in: `
x: @./file
`,
exp: `x: @file
`,
},
}

View file

@ -1720,6 +1720,13 @@ func (p *parser) parseImport(spread bool) *d2ast.Import {
imp.Range.Start = imp.Range.Start.SubtractString("...", p.utf16)
}
s, eof := p.peekn(2)
if eof || s != "./" {
p.rewind()
} else {
p.commit()
}
k := p.parseKey()
if k == nil {
return imp