@human-synthesis/norns-core 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/preprocess.js +16 -5
package/package.json
CHANGED
package/src/preprocess.js
CHANGED
|
@@ -267,7 +267,10 @@ function transformIfChains(content) {
|
|
|
267
267
|
const elseIfRe = ELSEIF_RE_TPL(chainIndent);
|
|
268
268
|
const elseRe = ELSE_RE_TPL(chainIndent);
|
|
269
269
|
|
|
270
|
-
|
|
270
|
+
// Collect each branch's header + body, then recurse on the body so
|
|
271
|
+
// nested `+if`/`+else` chains resolve. Mirrors `transformSnippets`.
|
|
272
|
+
/** @type {{ header: string; body: string[] }[]} */
|
|
273
|
+
const branches = [{ header: `${chainIndent}| {#if ${ifExpr}}`, body: [] }];
|
|
271
274
|
i++;
|
|
272
275
|
|
|
273
276
|
while (i < lines.length) {
|
|
@@ -275,19 +278,22 @@ function transformIfChains(content) {
|
|
|
275
278
|
|
|
276
279
|
const eIfM = cur.match(elseIfRe);
|
|
277
280
|
if (eIfM) {
|
|
278
|
-
|
|
281
|
+
branches.push({
|
|
282
|
+
header: `${chainIndent}| {:else if ${stripQuotes(eIfM[1])}}`,
|
|
283
|
+
body: []
|
|
284
|
+
});
|
|
279
285
|
i++;
|
|
280
286
|
continue;
|
|
281
287
|
}
|
|
282
288
|
const eM = cur.match(elseRe);
|
|
283
289
|
if (eM) {
|
|
284
|
-
|
|
290
|
+
branches.push({ header: `${chainIndent}| {:else}`, body: [] });
|
|
285
291
|
i++;
|
|
286
292
|
continue;
|
|
287
293
|
}
|
|
288
294
|
|
|
289
295
|
if (cur.trim() === '') {
|
|
290
|
-
|
|
296
|
+
branches[branches.length - 1].body.push(cur);
|
|
291
297
|
i++;
|
|
292
298
|
continue;
|
|
293
299
|
}
|
|
@@ -295,7 +301,8 @@ function transformIfChains(content) {
|
|
|
295
301
|
const lineIndent = cur.match(/^(\s*)/)[1];
|
|
296
302
|
if (lineIndent.length > chainIndent.length) {
|
|
297
303
|
// Body line — de-indent by one level so it sits at the chain's level.
|
|
298
|
-
|
|
304
|
+
const deindented = cur.startsWith(indentDiff) ? cur.slice(indentDiff.length) : cur;
|
|
305
|
+
branches[branches.length - 1].body.push(deindented);
|
|
299
306
|
i++;
|
|
300
307
|
continue;
|
|
301
308
|
}
|
|
@@ -303,6 +310,10 @@ function transformIfChains(content) {
|
|
|
303
310
|
break;
|
|
304
311
|
}
|
|
305
312
|
|
|
313
|
+
for (const b of branches) {
|
|
314
|
+
out.push(b.header);
|
|
315
|
+
if (b.body.length > 0) out.push(transformIfChains(b.body.join('\n')));
|
|
316
|
+
}
|
|
306
317
|
out.push(`${chainIndent}| {/if}`);
|
|
307
318
|
}
|
|
308
319
|
|