function _compiler(options) {
return function (strings, ...values) {
const genSymPrefix = "gensym_923wedsojasjq_"
const rawSyms = []
const symVals = {}
let ix = 0
for (const value of values) {
const sym = genSymPrefix + ix++
rawSyms.push(`"${sym}"`)
symVals[sym] = value
}
const s = strings.reduce((prev, next, i) => `${prev}${next}${rawSyms[i] || ''}`, '')
const name = (s.match(/^\s*<!--\s*([a-zA-Z0-9_]+)/) || [])[1]
const compiled = compiler.compile(s, {format: "cjs", name, ...options})
const unknownSymTypes = []
compiler.walk(compiled.ast.instance, {
enter(node, parent, prop, index) {
if (node.type !== "Literal" || !(node.value in symVals)) {
return
}
if (parent.type !== "ImportDeclaration") {
unknownSymTypes.push(node)
}
},
})
if (unknownSymTypes.length > 0) {
throw Error("Interpolation is only allowed in import statements (for now)")
}
return Object.assign({requires: symVals}, compiled)
}
}