MCPcopy
hub / github.com/hashicorp/hcl / transformContent

Method transformContent

ext/transform/transform.go:54–77  ·  view source on GitHub ↗
(content *hcl.BodyContent)

Source from the content-addressed store, hash-verified

52}
53
54func (w deepWrapper) transformContent(content *hcl.BodyContent) *hcl.BodyContent {
55 if len(content.Blocks) == 0 {
56 // Easy path: if there are no blocks then there are no child bodies to wrap
57 return content
58 }
59
60 // Since we're going to change things here, we'll be polite and clone the
61 // structure so that we don't risk impacting any internal state of the
62 // original body.
63 ret := &hcl.BodyContent{
64 Attributes: content.Attributes,
65 MissingItemRange: content.MissingItemRange,
66 Blocks: make(hcl.Blocks, len(content.Blocks)),
67 }
68
69 for i, givenBlock := range content.Blocks {
70 // Shallow-copy the block so we can mutate it
71 newBlock := *givenBlock
72 newBlock.Body = Deep(newBlock.Body, w.Transformer)
73 ret.Blocks[i] = &newBlock
74 }
75
76 return ret
77}
78
79func (w deepWrapper) JustAttributes() (hcl.Attributes, hcl.Diagnostics) {
80 // Attributes can't have bodies or nested blocks, so this is just a thin wrapper.

Callers 2

ContentMethod · 0.95
PartialContentMethod · 0.95

Calls 1

DeepFunction · 0.85

Tested by

no test coverage detected