Skip to content

Commit

Permalink
fix: strict equal checks/tests
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/mode/lua_highlight_rules.js
  • Loading branch information
mkslanc authored and nightwing committed Nov 24, 2024
1 parent bf581ad commit 57dd6b7
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/autocomplete/inline_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
Expand Down Expand Up @@ -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();
},
Expand Down
28 changes: 14 additions & 14 deletions src/ext/beautify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}

Expand All @@ -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();
Expand All @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -232,21 +232,21 @@ 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;

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();

Expand All @@ -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
Expand All @@ -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;
}
Expand Down Expand Up @@ -306,33 +306,33 @@ 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;
}
}

// 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;

Expand Down
4 changes: 4 additions & 0 deletions src/ext/simple_tokenizer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,7 @@ module.exports = {
}

};

if (typeof module !== "undefined" && module === require.main) {
require("asyncjs").test.testcase(module.exports).exec();
}
16 changes: 6 additions & 10 deletions src/mode/lua_highlight_rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -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");
}
Expand Down
8 changes: 4 additions & 4 deletions src/tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -306,7 +306,7 @@ class Tokenizer {
currentState = this.rootScope.fromStack(stack, currentState);
}
else {
currentState = rule.next2(currentState, stack);
currentState = rule.next2(currentState);
}
}
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 57dd6b7

Please sign in to comment.