transpiler: add mechanism to register custom mini language
This commit is contained in:
parent
05ae31838e
commit
989fdfa20b
1 changed files with 17 additions and 3 deletions
|
|
@ -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 },
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue