MCPcopy Create free account
hub / github.com/coder/guts / injectImport

Function injectImport

config/imports.go:54–71  ·  view source on GitHub ↗
(module string, isTypeOnly bool, names ...string)

Source from the content-addressed store, hash-verified

52}
53
54func injectImport(module string, isTypeOnly bool, names ...string) guts.MutationFunc {
55 specs := make([]*bindings.ImportSpecifier, 0, len(names))
56 for _, n := range names {
57 name, alias := splitNameAlias(n)
58 specs = append(specs, &bindings.ImportSpecifier{
59 Name: name,
60 Alias: alias,
61 })
62 }
63 decl := &bindings.ImportDeclaration{
64 Module: module,
65 Named: specs,
66 IsTypeOnly: isTypeOnly,
67 }
68 return func(ts *guts.Typescript) {
69 ts.AppendImport(decl)
70 }
71}
72
73// splitNameAlias parses entries of the form "Name" or "Name=Alias".
74func splitNameAlias(s string) (name, alias string) {

Callers 2

InjectImportFunction · 0.85
InjectTypeImportFunction · 0.85

Calls 2

splitNameAliasFunction · 0.85
AppendImportMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…