MCPcopy Create free account
hub / github.com/breck7/scroll / macroExpand

Method macroExpand

external/.scrollLibs.js:17007–17030  ·  view source on GitHub ↗
(macroDefinitionAtom, macroUsageAtom)

Source from the content-addressed store, hash-verified

17005 return lastParticle
17006 }
17007 macroExpand(macroDefinitionAtom, macroUsageAtom) {
17008 const clone = this.clone()
17009 const defs = clone.findParticles(macroDefinitionAtom)
17010 const allUses = clone.findParticles(macroUsageAtom)
17011 const atomBreakSymbol = clone.atomBreakSymbol
17012 defs.forEach(def => {
17013 const macroName = def.getAtom(1)
17014 const uses = allUses.filter(particle => particle.hasAtom(1, macroName))
17015 const params = def.getAtomsFrom(2)
17016 const replaceFn = str => {
17017 const paramValues = str.split(atomBreakSymbol).slice(2)
17018 let newParticle = def.subparticlesToString()
17019 params.forEach((param, index) => {
17020 newParticle = newParticle.replace(new RegExp(param, "g"), paramValues[index])
17021 })
17022 return newParticle
17023 }
17024 uses.forEach(particle => {
17025 particle.replaceParticle(replaceFn)
17026 })
17027 def.destroy()
17028 })
17029 return clone
17030 }
17031 setSubparticles(subparticles) {
17032 return this._setSubparticles(subparticles)
17033 }

Callers

nothing calls this directly

Calls 9

cloneMethod · 0.95
findParticlesMethod · 0.80
forEachMethod · 0.80
hasAtomMethod · 0.80
getAtomsFromMethod · 0.80
replaceParticleMethod · 0.80
destroyMethod · 0.80
getAtomMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected