|
|
|
@ -8,13 +8,18 @@ import (
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
importRe = regexp.MustCompile(`(?ms)import \(([^)]+)\)`)
|
|
|
|
|
otherRe = regexp.MustCompile(`^(?:var|const|func)\s`)
|
|
|
|
|
ErrNoImports = errors.New("no imports found")
|
|
|
|
|
importRe = regexp.MustCompile(`(?ms)^import \(([^)]+)\)`)
|
|
|
|
|
singleImportRe = regexp.MustCompile(`(?ms)^import "[^"]+"`)
|
|
|
|
|
otherRe = regexp.MustCompile(`^(?:var|const|func)\s`)
|
|
|
|
|
ErrNoImports = errors.New("no imports found")
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Source formats a given src's imports
|
|
|
|
|
func Source(src []byte, module string) ([]byte, error) {
|
|
|
|
|
if singleImportRe.Match(src) {
|
|
|
|
|
return src, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
importStart := importRe.FindIndex(src)
|
|
|
|
|
if importStart == nil {
|
|
|
|
|
return nil, fmt.Errorf("could not find imports: %w", ErrNoImports)
|
|
|
|
|