redscript-mc 1.2.14 → 1.2.15
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/dist/lowering/index.js +12 -25
- package/package.json +1 -1
- package/src/lowering/index.ts +11 -27
package/dist/lowering/index.js
CHANGED
|
@@ -50,10 +50,8 @@ const types_1 = require("../events/types");
|
|
|
50
50
|
// as literal values (coordinates, entity types, block types), so they
|
|
51
51
|
// require MC macro syntax when called with runtime variables.
|
|
52
52
|
// ---------------------------------------------------------------------------
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
'playsound', 'tp', 'tp_to', 'effect', 'effect_clear', 'give',
|
|
56
|
-
]);
|
|
53
|
+
// All builtins support macro parameters - any arg that's a function param
|
|
54
|
+
// will automatically use MC 1.20.2+ macro syntax when needed
|
|
57
55
|
// ---------------------------------------------------------------------------
|
|
58
56
|
// Builtin Functions
|
|
59
57
|
// ---------------------------------------------------------------------------
|
|
@@ -313,7 +311,7 @@ class Lowering {
|
|
|
313
311
|
}
|
|
314
312
|
}
|
|
315
313
|
preScanExpr(expr, paramNames, macroParams) {
|
|
316
|
-
if (expr.kind === 'call' &&
|
|
314
|
+
if (expr.kind === 'call' && BUILTINS[expr.fn] !== undefined) {
|
|
317
315
|
// All ident args to macro-aware builtins that are params → macro params
|
|
318
316
|
for (const arg of expr.args) {
|
|
319
317
|
if (arg.kind === 'ident' && paramNames.has(arg.name)) {
|
|
@@ -2197,28 +2195,17 @@ class Lowering {
|
|
|
2197
2195
|
}
|
|
2198
2196
|
return { kind: 'const', value: 0 };
|
|
2199
2197
|
}
|
|
2200
|
-
//
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
if (
|
|
2205
|
-
|
|
2206
|
-
this.currentFnMacroParams.add(r.macroParam); });
|
|
2207
|
-
}
|
|
2208
|
-
const strArgs = argResults.map(r => r.str);
|
|
2209
|
-
const cmd = BUILTINS[name]?.(strArgs);
|
|
2210
|
-
if (cmd) {
|
|
2211
|
-
this.builder.emitRaw(hasMacroArg ? `$${cmd}` : cmd);
|
|
2212
|
-
}
|
|
2213
|
-
return { kind: 'const', value: 0 };
|
|
2198
|
+
// All builtins support macro params - check if any arg is a param needing macro treatment
|
|
2199
|
+
const argResults = args.map(arg => this.exprToBuiltinArg(arg));
|
|
2200
|
+
const hasMacroArg = argResults.some(r => r.macroParam !== undefined);
|
|
2201
|
+
if (hasMacroArg) {
|
|
2202
|
+
argResults.forEach(r => { if (r.macroParam)
|
|
2203
|
+
this.currentFnMacroParams.add(r.macroParam); });
|
|
2214
2204
|
}
|
|
2215
|
-
|
|
2216
|
-
const
|
|
2217
|
-
? this.exprToSnbt(arg)
|
|
2218
|
-
: this.exprToString(arg));
|
|
2219
|
-
const cmd = BUILTINS[name](strArgs);
|
|
2205
|
+
const strArgs = argResults.map(r => r.str);
|
|
2206
|
+
const cmd = BUILTINS[name]?.(strArgs);
|
|
2220
2207
|
if (cmd) {
|
|
2221
|
-
this.builder.emitRaw(cmd);
|
|
2208
|
+
this.builder.emitRaw(hasMacroArg ? `$${cmd}` : cmd);
|
|
2222
2209
|
}
|
|
2223
2210
|
return { kind: 'const', value: 0 };
|
|
2224
2211
|
}
|
package/package.json
CHANGED
package/src/lowering/index.ts
CHANGED
|
@@ -25,10 +25,8 @@ import { EVENT_TYPES, getEventParamSpecs, isEventTypeName } from '../events/type
|
|
|
25
25
|
// require MC macro syntax when called with runtime variables.
|
|
26
26
|
// ---------------------------------------------------------------------------
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
'playsound', 'tp', 'tp_to', 'effect', 'effect_clear', 'give',
|
|
31
|
-
])
|
|
28
|
+
// All builtins support macro parameters - any arg that's a function param
|
|
29
|
+
// will automatically use MC 1.20.2+ macro syntax when needed
|
|
32
30
|
|
|
33
31
|
// ---------------------------------------------------------------------------
|
|
34
32
|
// Builtin Functions
|
|
@@ -335,7 +333,7 @@ export class Lowering {
|
|
|
335
333
|
}
|
|
336
334
|
|
|
337
335
|
private preScanExpr(expr: Expr, paramNames: Set<string>, macroParams: Set<string>): void {
|
|
338
|
-
if (expr.kind === 'call' &&
|
|
336
|
+
if (expr.kind === 'call' && BUILTINS[expr.fn] !== undefined) {
|
|
339
337
|
// All ident args to macro-aware builtins that are params → macro params
|
|
340
338
|
for (const arg of expr.args) {
|
|
341
339
|
if (arg.kind === 'ident' && paramNames.has(arg.name)) {
|
|
@@ -2528,30 +2526,16 @@ export class Lowering {
|
|
|
2528
2526
|
return { kind: 'const', value: 0 }
|
|
2529
2527
|
}
|
|
2530
2528
|
|
|
2531
|
-
//
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
if (
|
|
2536
|
-
argResults.forEach(r => { if (r.macroParam) this.currentFnMacroParams.add(r.macroParam) })
|
|
2537
|
-
}
|
|
2538
|
-
const strArgs = argResults.map(r => r.str)
|
|
2539
|
-
const cmd = BUILTINS[name]?.(strArgs)
|
|
2540
|
-
if (cmd) {
|
|
2541
|
-
this.builder.emitRaw(hasMacroArg ? `$${cmd}` : cmd)
|
|
2542
|
-
}
|
|
2543
|
-
return { kind: 'const', value: 0 }
|
|
2529
|
+
// All builtins support macro params - check if any arg is a param needing macro treatment
|
|
2530
|
+
const argResults = args.map(arg => this.exprToBuiltinArg(arg))
|
|
2531
|
+
const hasMacroArg = argResults.some(r => r.macroParam !== undefined)
|
|
2532
|
+
if (hasMacroArg) {
|
|
2533
|
+
argResults.forEach(r => { if (r.macroParam) this.currentFnMacroParams.add(r.macroParam) })
|
|
2544
2534
|
}
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
const strArgs = args.map(arg =>
|
|
2548
|
-
arg.kind === 'struct_lit' || arg.kind === 'array_lit'
|
|
2549
|
-
? this.exprToSnbt(arg)
|
|
2550
|
-
: this.exprToString(arg)
|
|
2551
|
-
)
|
|
2552
|
-
const cmd = BUILTINS[name](strArgs)
|
|
2535
|
+
const strArgs = argResults.map(r => r.str)
|
|
2536
|
+
const cmd = BUILTINS[name]?.(strArgs)
|
|
2553
2537
|
if (cmd) {
|
|
2554
|
-
this.builder.emitRaw(cmd)
|
|
2538
|
+
this.builder.emitRaw(hasMacroArg ? `$${cmd}` : cmd)
|
|
2555
2539
|
}
|
|
2556
2540
|
|
|
2557
2541
|
return { kind: 'const', value: 0 }
|