8 // Module matching template syntax allows for modules to replace this text with the name of the module declared on import
9 // this allows the reverse router to use correct syntax
10 // Match _LOCAL_.static or _LOCAL_|
11 var namespaceReplacement = regexp.MustCompile(`(_LOCAL_)(\.(.*?))?\\`)
13 // Function to replace the bytes data that may match the _LOCAL_ namespace specifier,
14 // the replacement will be the current module.Name
15 func namespaceReplace(fileBytes []byte, module *Module) []byte {
16 newBytes, lastIndex := &bytes.Buffer{}, 0
17 matches := namespaceReplacement.FindAllSubmatchIndex(fileBytes, -1)
18 for _, match := range matches {
19 // Write up to first bytes
20 newBytes.Write(fileBytes[lastIndex:match[0]])
21 // skip ahead index to match[1]
24 // This match includes the module name as imported by the module
25 // We could transform the module name if it is different..
26 // For now leave it the same
27 // so _LOCAL_.static| becomes static|
30 // Inject the module name
31 newBytes.Write([]byte(module.Name))
34 // Write remainder of document
35 newBytes.Write(fileBytes[lastIndex:])
36 return newBytes.Bytes()