transpiler: add mechanism to register custom mini language

This commit is contained in:
Felix Roos 2025-03-20 21:18:32 +01:00
parent 05ae31838e
commit 989fdfa20b
No known key found for this signature in database

View file

@ -29,8 +29,15 @@ export function transpiler(input, options = {}) {
let miniLocations = []; let miniLocations = [];
const collectMiniLocations = (value, node) => { const collectMiniLocations = (value, node) => {
const leafLocs = getLeafLocations(`"${value}"`, node.start, input); const minilang = languages.get('minilang');
miniLocations = miniLocations.concat(leafLocs); if (minilang) {
const code = `[${value}]`;
const locs = minilang.getLocations(code, node.start);
miniLocations = miniLocations.concat(locs);
} else {
const leafLocs = getLeafLocations(`"${value}"`, node.start, input);
miniLocations = miniLocations.concat(leafLocs);
}
}; };
let widgets = []; let widgets = [];
@ -142,11 +149,18 @@ function isBackTickString(node, parent) {
function miniWithLocation(value, node) { function miniWithLocation(value, node) {
const { start: fromOffset } = node; const { start: fromOffset } = node;
const minilang = languages.get('minilang');
let name = 'm';
if (minilang && minilang.name) {
name = minilang.name; // name is expected to be exported from the package of the minilang
}
return { return {
type: 'CallExpression', type: 'CallExpression',
callee: { callee: {
type: 'Identifier', type: 'Identifier',
name: 'm', name,
}, },
arguments: [ arguments: [
{ type: 'Literal', value }, { type: 'Literal', value },