Run mutating variable macros first

293d6ff60d026f9cde7757cc83d5fda7e244ca13

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +6 -7Showing whitespace changes
public/scripts/variables.js+6 -7
@@ -224,12 +224,11 @@ export function resolveVariable(name, scope = null) {
224}224}
225225
226/**226/**
227 * Returns built-in variable macros.
227 * @returns {import('./macros.js').Macro[]}228 * @returns {import('./macros.js').Macro[]}
228 */229 */
229export function getVariableMacros() {230export function getVariableMacros() {
230 const macros = [231 return [
231 // Replace {{getvar::name}} with the value of the variable name
232 { regex: /{{getvar::([^}]+)}}/gi, replace: (_, name) => getLocalVariable(name.trim()) },
233 // Replace {{setvar::name::value}} with empty string and set the variable name to value232 // Replace {{setvar::name::value}} with empty string and set the variable name to value
234 { regex: /{{setvar::([^:]+)::([^}]+)}}/gi, replace: (_, name, value) => { setLocalVariable(name.trim(), value); return ''; } },233 { regex: /{{setvar::([^:]+)::([^}]+)}}/gi, replace: (_, name, value) => { setLocalVariable(name.trim(), value); return ''; } },
235 // Replace {{addvar::name::value}} with empty string and add value to the variable value234 // Replace {{addvar::name::value}} with empty string and add value to the variable value
@@ -238,8 +237,8 @@ export function getVariableMacros() {
238 { regex: /{{incvar::([^}]+)}}/gi, replace: (_, name) => incrementLocalVariable(name.trim()) },237 { regex: /{{incvar::([^}]+)}}/gi, replace: (_, name) => incrementLocalVariable(name.trim()) },
239 // Replace {{decvar::name}} with empty string and decrement the variable name by 1238 // Replace {{decvar::name}} with empty string and decrement the variable name by 1
240 { regex: /{{decvar::([^}]+)}}/gi, replace: (_, name) => decrementLocalVariable(name.trim()) },239 { regex: /{{decvar::([^}]+)}}/gi, replace: (_, name) => decrementLocalVariable(name.trim()) },
241 // Replace {{getglobalvar::name}} with the value of the global variable name240 // Replace {{getvar::name}} with the value of the variable name
242 { regex: /{{getglobalvar::([^}]+)}}/gi, replace: (_, name) => getGlobalVariable(name.trim()) },241 { regex: /{{getvar::([^}]+)}}/gi, replace: (_, name) => getLocalVariable(name.trim()) },
243 // Replace {{setglobalvar::name::value}} with empty string and set the global variable name to value242 // Replace {{setglobalvar::name::value}} with empty string and set the global variable name to value
244 { regex: /{{setglobalvar::([^:]+)::([^}]+)}}/gi, replace: (_, name, value) => { setGlobalVariable(name.trim(), value); return ''; } },243 { regex: /{{setglobalvar::([^:]+)::([^}]+)}}/gi, replace: (_, name, value) => { setGlobalVariable(name.trim(), value); return ''; } },
245 // Replace {{addglobalvar::name::value}} with empty string and add value to the global variable value244 // Replace {{addglobalvar::name::value}} with empty string and add value to the global variable value
@@ -248,9 +247,9 @@ export function getVariableMacros() {
248 { regex: /{{incglobalvar::([^}]+)}}/gi, replace: (_, name) => incrementGlobalVariable(name.trim()) },247 { regex: /{{incglobalvar::([^}]+)}}/gi, replace: (_, name) => incrementGlobalVariable(name.trim()) },
249 // Replace {{decglobalvar::name}} with empty string and decrement the global variable name by 1248 // Replace {{decglobalvar::name}} with empty string and decrement the global variable name by 1
250 { regex: /{{decglobalvar::([^}]+)}}/gi, replace: (_, name) => decrementGlobalVariable(name.trim()) },249 { regex: /{{decglobalvar::([^}]+)}}/gi, replace: (_, name) => decrementGlobalVariable(name.trim()) },
250 // Replace {{getglobalvar::name}} with the value of the global variable name
251 { regex: /{{getglobalvar::([^}]+)}}/gi, replace: (_, name) => getGlobalVariable(name.trim()) },
251 ];252 ];
252
253 return macros;
254}253}
255254
256async function listVariablesCallback(args) {255async function listVariablesCallback(args) {