From cc0036b2e205940240daeb0b1d9db6358d0ba2a6 Mon Sep 17 00:00:00 2001 From: Ben Small Date: Sat, 22 Jan 2022 14:34:57 -0800 Subject: [PATCH 1/3] Fixed scope on variables leaked to global scope Certain loop variables were unscoped, and thereby becoming global; also, a per-level variable (bannedGroup) was not scoped in certain places to the corresponding level object, thus becoming global as well. --- src/js/compiler.js | 4 ++-- src/js/engine.js | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/js/compiler.js b/src/js/compiler.js index 0561c9a05..ddb973b39 100644 --- a/src/js/compiler.js +++ b/src/js/compiler.js @@ -923,7 +923,7 @@ function rulesToArray(state) { } - for (i=0;i Date: Sun, 30 Jan 2022 13:57:58 -0800 Subject: [PATCH 2/3] Modified copyState to make a deep copy of the rules property (The rules property is an array of arrays, but was getting copied as if it was an array of ordinary data.) --- src/js/parser.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/js/parser.js b/src/js/parser.js index d760e64c7..279d3f3cb 100644 --- a/src/js/parser.js +++ b/src/js/parser.js @@ -251,6 +251,7 @@ var codeMirrorFn = function() { var soundsCopy = []; var levelsCopy = []; var winConditionsCopy = []; + var rulesCopy = []; for (var i = 0; i < state.legend_synonyms.length; i++) { legend_synonymsCopy.push(state.legend_synonyms[i].concat([])); @@ -270,6 +271,9 @@ var codeMirrorFn = function() { for (var i = 0; i < state.winconditions.length; i++) { winConditionsCopy.push(state.winconditions[i].concat([])); } + for (var i = 0; i < state.rules.length; i++) { + rulesCopy.push(state.rules[i].concat([])); + } var original_case_namesCopy = Object.assign({},state.original_case_names); @@ -294,7 +298,7 @@ var codeMirrorFn = function() { sounds: soundsCopy, - rules: state.rules.concat([]), + rules: rulesCopy, names: state.names.concat([]), From 15f6b8876958ce4b79593e4331bc61cab4636c55 Mon Sep 17 00:00:00 2001 From: Ben Small Date: Tue, 1 Feb 2022 15:20:57 -0800 Subject: [PATCH 3/3] Changed tokenIndex for level messages to -4 to match messages elsewhere The tokenIndex was being set to 1 for level messages, so the comment handler remained active. This could cause strange behavior if the message began with a '('. --- src/js/parser.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/js/parser.js b/src/js/parser.js index 279d3f3cb..6e987304f 100644 --- a/src/js/parser.js +++ b/src/js/parser.js @@ -1114,7 +1114,7 @@ var codeMirrorFn = function() { if (sol) { if (stream.match(/[\p{Z}\s]*message\b[\p{Z}\s]*/u, true)) { - state.tokenIndex = 1;//1/2 = message/level + state.tokenIndex = -4;//-4/2 = message/level var newdat = ['\n', mixedCase.slice(stream.pos).trim(),state.lineNumber]; if (state.levels[state.levels.length - 1].length == 0) { state.levels.splice(state.levels.length - 1, 0, newdat); @@ -1124,7 +1124,7 @@ var codeMirrorFn = function() { return 'MESSAGE_VERB';//a duplicate of the previous section as a legacy thing for #589 } else if (stream.match(/[\p{Z}\s]*message[\p{Z}\s]*/u, true)) {//duplicating previous section because of #589 logWarning("You probably meant to put a space after 'message' innit. That's ok, I'll still interpret it as a message, but you probably want to put a space there.",state.lineNumber); - state.tokenIndex = 1;//1/2 = message/level + state.tokenIndex = -4;//-4/2 = message/level var newdat = ['\n', mixedCase.slice(stream.pos).trim(),state.lineNumber]; if (state.levels[state.levels.length - 1].length == 0) { state.levels.splice(state.levels.length - 1, 0, newdat); @@ -1162,7 +1162,7 @@ var codeMirrorFn = function() { } } } else { - if (state.tokenIndex == 1) { + if (state.tokenIndex == -4) { stream.skipToEnd(); return 'MESSAGE'; }