From 57dd6b7d53e3643552adc83405b710796a18bbb2 Mon Sep 17 00:00:00 2001 From: mkslanc Date: Sat, 7 Sep 2024 15:10:43 +0400 Subject: [PATCH] fix: strict equal checks/tests # Conflicts: # src/mode/lua_highlight_rules.js --- src/autocomplete/inline_test.js | 4 ++-- src/ext/beautify.js | 28 ++++++++++++++-------------- src/ext/simple_tokenizer_test.js | 4 ++++ src/mode/lua_highlight_rules.js | 16 ++++++---------- src/tokenizer.js | 8 ++++---- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/autocomplete/inline_test.js b/src/autocomplete/inline_test.js index c1cc1b07020..a717446ea2b 100644 --- a/src/autocomplete/inline_test.js +++ b/src/autocomplete/inline_test.js @@ -344,7 +344,7 @@ module.exports = { // Text to the right of the cursor should be tokenized normally again. var tokens = editor.session.getTokens(2); assert.strictEqual(tokens[0].value, "f hi I should be hidden"); - assert.strictEqual(tokens[0].type, "text"); + assert.equal(tokens[0].type, "text"); done(); }, @@ -375,7 +375,7 @@ module.exports = { // Text to the right of the cursor should be tokenized normally again. var tokens = editor.session.getTokens(2); assert.strictEqual(tokens[0].value, "fhi I should be hidden"); - assert.strictEqual(tokens[0].type, "text"); + assert.equal(tokens[0].type, "text"); done(); }, diff --git a/src/ext/beautify.js b/src/ext/beautify.js index be367fb4e21..c6b83bb3c9e 100644 --- a/src/ext/beautify.js +++ b/src/ext/beautify.js @@ -127,7 +127,7 @@ exports.beautify = function(session) { } // line break before } - if (!inTag && !rowsToAdd && token.type === "paren.rparen" && token.value.substr(0, 1) === "}") { + if (!inTag && !rowsToAdd && token.type == "paren.rparen" && token.value.substr(0, 1) === "}") { rowsToAdd++; } @@ -153,7 +153,7 @@ exports.beautify = function(session) { if (value) { // whitespace - if (token.type === "keyword" && value.match(/^(if|else|elseif|for|foreach|while|switch)$/)) { + if (token.type == "keyword" && value.match(/^(if|else|elseif|for|foreach|while|switch)$/)) { parents[depth] = value; trimNext(); @@ -167,7 +167,7 @@ exports.beautify = function(session) { } } // trim value after opening paren - } else if (token.type === "paren.lparen") { + } else if (token.type == "paren.lparen") { trimNext(); // whitespace after { @@ -194,7 +194,7 @@ exports.beautify = function(session) { } } // remove space before closing paren - } else if (token.type === "paren.rparen") { + } else if (token.type == "paren.rparen") { unindent = 1; // ensure curly brace is preceeded by whitespace @@ -232,13 +232,13 @@ exports.beautify = function(session) { trimLine(); // add spaces around conditional operators - } else if ((token.type === "keyword.operator" || token.type === "keyword") && value.match(/^(=|==|===|!=|!==|&&|\|\||and|or|xor|\+=|.=|>|>=|<|<=|=>)$/)) { + } else if ((token.type == "keyword.operator" || token.type == "keyword") && value.match(/^(=|==|===|!=|!==|&&|\|\||and|or|xor|\+=|.=|>|>=|<|<=|=>)$/)) { trimCode(); trimNext(); spaceBefore = true; spaceAfter = true; // remove space before semicolon - } else if (token.type === "punctuation.operator" && value === ';') { + } else if (token.type == "punctuation.operator" && value === ';') { trimCode(); trimNext(); spaceAfter = true; @@ -246,7 +246,7 @@ exports.beautify = function(session) { if (inCSS) rowsToAdd++; // space after colon or comma - } else if (token.type === "punctuation.operator" && value.match(/^(:|,)$/)) { + } else if (token.type == "punctuation.operator" && value.match(/^(:|,)$/)) { trimCode(); trimNext(); @@ -258,7 +258,7 @@ exports.beautify = function(session) { breakBefore = false; } // ensure space before php closing tag - } else if (token.type === "support.php_tag" && value === "?>" && !breakBefore) { + } else if (token.type == "support.php_tag" && value === "?>" && !breakBefore) { trimCode(); spaceBefore = true; // remove excess space before HTML attribute @@ -273,7 +273,7 @@ exports.beautify = function(session) { trimLine(); if(value === "/>") spaceBefore = true; - } else if (token.type === "keyword" && value.match(/^(case|default)$/)) { + } else if (token.type == "keyword" && value.match(/^(case|default)$/)) { if (caseBody) unindent = 1; } @@ -306,13 +306,13 @@ exports.beautify = function(session) { code += tabString; } - if (token.type === "keyword" && value.match(/^(case|default)$/)) { + if (token.type == "keyword" && value.match(/^(case|default)$/)) { if (caseBody === false) { parents[depth] = value; depth++; caseBody = true; } - } else if (token.type === "keyword" && value.match(/^(break)$/)) { + } else if (token.type == "keyword" && value.match(/^(break)$/)) { if(parents[depth-1] && parents[depth-1].match(/^(case|default)$/)) { depth--; caseBody = false; @@ -320,19 +320,19 @@ exports.beautify = function(session) { } // indent one line after if or else - if (token.type === "paren.lparen") { + if (token.type == "paren.lparen") { roundDepth += (value.match(/\(/g) || []).length; curlyDepth += (value.match(/\{/g) || []).length; depth += value.length; } - if (token.type === "keyword" && value.match(/^(if|else|elseif|for|while)$/)) { + if (token.type == "keyword" && value.match(/^(if|else|elseif|for|while)$/)) { indentNextLine = true; roundDepth = 0; } else if (!roundDepth && value.trim() && token.type !== "comment") indentNextLine = false; - if (token.type === "paren.rparen") { + if (token.type == "paren.rparen") { roundDepth -= (value.match(/\)/g) || []).length; curlyDepth -= (value.match(/\}/g) || []).length; diff --git a/src/ext/simple_tokenizer_test.js b/src/ext/simple_tokenizer_test.js index d60183ce16b..6f5a71446ad 100644 --- a/src/ext/simple_tokenizer_test.js +++ b/src/ext/simple_tokenizer_test.js @@ -69,3 +69,7 @@ module.exports = { } }; + +if (typeof module !== "undefined" && module === require.main) { + require("asyncjs").test.testcase(module.exports).exec(); +} diff --git a/src/mode/lua_highlight_rules.js b/src/mode/lua_highlight_rules.js index 2be37fe1a1f..2e1bacebc10 100644 --- a/src/mode/lua_highlight_rules.js +++ b/src/mode/lua_highlight_rules.js @@ -65,16 +65,14 @@ var LuaHighlightRules = function() { "start" : [{ stateName: "bracketedComment", onMatch2 : function(value, scope){ - var parent = scope.get("bracketedComment" + (value.length - 2)) - parent.meta = (value.length - 2); - return parent.get(this.next).get("comment"); + return scope.get(this.next, value.length - 2).get("comment"); }, regex : /\-\-\[=*\[/, next : [ { onMatch2 : function(value, scope) { - if (scope.parent && value.length == scope.parent.meta) { - return scope.parent.parent.get("comment"); + if (scope == "bracketedComment" && value.length == scope.data) { + return scope.parent.get("comment"); } else { return scope.get("comment"); } @@ -93,16 +91,14 @@ var LuaHighlightRules = function() { { stateName: "bracketedString", onMatch2 : function(value, scope){ - var parent = scope.get("bracketedString" + value.length); - parent.meta = value.length; - return parent.get(this.next).get("string.start"); + return scope.get(this.next, value.length - 2).get("string.start"); }, regex : /\[=*\[/, next : [ { onMatch2 : function(value, scope) { - if (scope.parent && value.length == scope.parent.meta) { - return scope.parent.parent.get("string.end"); + if (scope == "bracketedString" && value.length == scope.data) { + return scope.parent.get("string.end"); } else { return scope.get("string.end"); } diff --git a/src/tokenizer.js b/src/tokenizer.js index 5f2dd7d5956..dac549d52b1 100644 --- a/src/tokenizer.js +++ b/src/tokenizer.js @@ -264,7 +264,7 @@ class Tokenizer { if (index - value.length > lastIndex) { var skipped = line.substring(lastIndex, index - value.length); - if (token.type && token.type === type) { + if (token.type && token.type == type) { token.value += skipped; } else { @@ -297,7 +297,7 @@ class Tokenizer { if (rule.next || rule.next2 || rememberedState) { if (!rememberedState) { - if (typeof rule.next !== 'function') { + if (rule.next && typeof rule.next !== 'function') { currentState = currentState.parent.get(rule.next); } else { @@ -306,7 +306,7 @@ class Tokenizer { currentState = this.rootScope.fromStack(stack, currentState); } else { - currentState = rule.next2(currentState, stack); + currentState = rule.next2(currentState); } } } @@ -335,7 +335,7 @@ class Tokenizer { } if (type && !Array.isArray(type) && type != "") { - if ((!rule || rule.merge !== false) && token.type === type) { + if ((!rule || rule.merge !== false) && token.type == type) { token.value += value; } else {