MCPcopy Index your code
hub / github.com/postcss/postcss / raw

Method raw

lib/stringifier.js:145–197  ·  view source on GitHub ↗
(node, own, detect)

Source from the content-addressed store, hash-verified

143 }
144
145 raw(node, own, detect) {
146 let value
147 if (!detect) detect = own
148
149 // Already had
150 if (own) {
151 value = node.raws[own]
152 if (typeof value !== 'undefined') return value
153 }
154
155 let parent = node.parent
156
157 if (detect === 'before') {
158 // Hack for first rule in CSS
159 if (!parent || (parent.type === 'root' && parent.first === node)) {
160 return ''
161 }
162
163 // `root` nodes in `document` should use only their own raws
164 if (parent && parent.type === 'document') {
165 return ''
166 }
167 }
168
169 // Floating child without parent
170 if (!parent) return DEFAULT_RAW[detect]
171
172 // Detect style by other nodes
173 let root = node.root()
174 let cache = root.rawCache || (root.rawCache = {})
175 if (typeof cache[detect] !== 'undefined') {
176 return cache[detect]
177 }
178
179 if (detect === 'before' || detect === 'after') {
180 return this.beforeAfter(node, detect)
181 } else {
182 let method = 'raw' + capitalize(detect)
183 if (this[method]) {
184 value = this[method](root, node)
185 } else {
186 root.walk(i => {
187 value = i.raws[own]
188 if (typeof value !== 'undefined') return false
189 })
190 }
191 }
192
193 if (typeof value === 'undefined') value = DEFAULT_RAW[detect]
194
195 cache[detect] = value
196 return value
197 }
198
199 rawBeforeClose(root) {
200 let value

Callers 8

beforeAfterMethod · 0.95
blockMethod · 0.95
bodyMethod · 0.95
commentMethod · 0.95
declMethod · 0.95
rawBeforeCommentMethod · 0.95
rawBeforeDeclMethod · 0.95
rawMethod · 0.95

Calls 4

beforeAfterMethod · 0.95
capitalizeFunction · 0.85
walkMethod · 0.80
rootMethod · 0.45

Tested by

no test coverage detected