Skip to content

Commit b52aea3

Browse files
committed
fix: strict equal checks/tests
1 parent 1b7d9c3 commit b52aea3

File tree

5 files changed

+30
-30
lines changed

5 files changed

+30
-30
lines changed

src/autocomplete/inline_test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ module.exports = {
344344
// Text to the right of the cursor should be tokenized normally again.
345345
var tokens = editor.session.getTokens(2);
346346
assert.strictEqual(tokens[0].value, "f hi I should be hidden");
347-
assert.strictEqual(tokens[0].type, "text");
347+
assert.equal(tokens[0].type, "text");
348348

349349
done();
350350
},
@@ -375,7 +375,7 @@ module.exports = {
375375
// Text to the right of the cursor should be tokenized normally again.
376376
var tokens = editor.session.getTokens(2);
377377
assert.strictEqual(tokens[0].value, "fhi I should be hidden");
378-
assert.strictEqual(tokens[0].type, "text");
378+
assert.equal(tokens[0].type, "text");
379379

380380
done();
381381
},

src/ext/beautify.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ exports.beautify = function(session) {
127127
}
128128

129129
// line break before }
130-
if (!inTag && !rowsToAdd && token.type === "paren.rparen" && token.value.substr(0, 1) === "}") {
130+
if (!inTag && !rowsToAdd && token.type == "paren.rparen" && token.value.substr(0, 1) === "}") {
131131
rowsToAdd++;
132132
}
133133

@@ -153,7 +153,7 @@ exports.beautify = function(session) {
153153

154154
if (value) {
155155
// whitespace
156-
if (token.type === "keyword" && value.match(/^(if|else|elseif|for|foreach|while|switch)$/)) {
156+
if (token.type == "keyword" && value.match(/^(if|else|elseif|for|foreach|while|switch)$/)) {
157157
parents[depth] = value;
158158

159159
trimNext();
@@ -167,7 +167,7 @@ exports.beautify = function(session) {
167167
}
168168
}
169169
// trim value after opening paren
170-
} else if (token.type === "paren.lparen") {
170+
} else if (token.type == "paren.lparen") {
171171
trimNext();
172172

173173
// whitespace after {
@@ -194,7 +194,7 @@ exports.beautify = function(session) {
194194
}
195195
}
196196
// remove space before closing paren
197-
} else if (token.type === "paren.rparen") {
197+
} else if (token.type == "paren.rparen") {
198198
unindent = 1;
199199

200200
// ensure curly brace is preceeded by whitespace
@@ -232,21 +232,21 @@ exports.beautify = function(session) {
232232

233233
trimLine();
234234
// add spaces around conditional operators
235-
} else if ((token.type === "keyword.operator" || token.type === "keyword") && value.match(/^(=|==|===|!=|!==|&&|\|\||and|or|xor|\+=|.=|>|>=|<|<=|=>)$/)) {
235+
} else if ((token.type == "keyword.operator" || token.type == "keyword") && value.match(/^(=|==|===|!=|!==|&&|\|\||and|or|xor|\+=|.=|>|>=|<|<=|=>)$/)) {
236236
trimCode();
237237
trimNext();
238238
spaceBefore = true;
239239
spaceAfter = true;
240240
// remove space before semicolon
241-
} else if (token.type === "punctuation.operator" && value === ';') {
241+
} else if (token.type == "punctuation.operator" && value === ';') {
242242
trimCode();
243243
trimNext();
244244
spaceAfter = true;
245245

246246
if (inCSS)
247247
rowsToAdd++;
248248
// space after colon or comma
249-
} else if (token.type === "punctuation.operator" && value.match(/^(:|,)$/)) {
249+
} else if (token.type == "punctuation.operator" && value.match(/^(:|,)$/)) {
250250
trimCode();
251251
trimNext();
252252

@@ -258,7 +258,7 @@ exports.beautify = function(session) {
258258
breakBefore = false;
259259
}
260260
// ensure space before php closing tag
261-
} else if (token.type === "support.php_tag" && value === "?>" && !breakBefore) {
261+
} else if (token.type == "support.php_tag" && value === "?>" && !breakBefore) {
262262
trimCode();
263263
spaceBefore = true;
264264
// remove excess space before HTML attribute
@@ -273,7 +273,7 @@ exports.beautify = function(session) {
273273
trimLine();
274274
if(value === "/>")
275275
spaceBefore = true;
276-
} else if (token.type === "keyword" && value.match(/^(case|default)$/)) {
276+
} else if (token.type == "keyword" && value.match(/^(case|default)$/)) {
277277
if (caseBody)
278278
unindent = 1;
279279
}
@@ -306,33 +306,33 @@ exports.beautify = function(session) {
306306
code += tabString;
307307
}
308308

309-
if (token.type === "keyword" && value.match(/^(case|default)$/)) {
309+
if (token.type == "keyword" && value.match(/^(case|default)$/)) {
310310
if (caseBody === false) {
311311
parents[depth] = value;
312312
depth++;
313313
caseBody = true;
314314
}
315-
} else if (token.type === "keyword" && value.match(/^(break)$/)) {
315+
} else if (token.type == "keyword" && value.match(/^(break)$/)) {
316316
if(parents[depth-1] && parents[depth-1].match(/^(case|default)$/)) {
317317
depth--;
318318
caseBody = false;
319319
}
320320
}
321321

322322
// indent one line after if or else
323-
if (token.type === "paren.lparen") {
323+
if (token.type == "paren.lparen") {
324324
roundDepth += (value.match(/\(/g) || []).length;
325325
curlyDepth += (value.match(/\{/g) || []).length;
326326
depth += value.length;
327327
}
328328

329-
if (token.type === "keyword" && value.match(/^(if|else|elseif|for|while)$/)) {
329+
if (token.type == "keyword" && value.match(/^(if|else|elseif|for|while)$/)) {
330330
indentNextLine = true;
331331
roundDepth = 0;
332332
} else if (!roundDepth && value.trim() && token.type !== "comment")
333333
indentNextLine = false;
334334

335-
if (token.type === "paren.rparen") {
335+
if (token.type == "paren.rparen") {
336336
roundDepth -= (value.match(/\)/g) || []).length;
337337
curlyDepth -= (value.match(/\}/g) || []).length;
338338

src/ext/simple_tokenizer_test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,7 @@ module.exports = {
6969
}
7070

7171
};
72+
73+
if (typeof module !== "undefined" && module === require.main) {
74+
require("asyncjs").test.testcase(module.exports).exec();
75+
}

src/mode/lua_highlight_rules.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,14 @@ var LuaHighlightRules = function() {
6565
"start" : [{
6666
stateName: "bracketedComment",
6767
onMatch2 : function(value, scope){
68-
var parent = scope.get("bracketedComment" + (value.length - 2))
69-
parent.meta = (value.length - 2);
70-
return parent.get(this.next).get("comment");
68+
return scope.get(this.next, value.length - 2).get("comment");
7169
},
7270
regex : /\-\-\[=*\[/,
7371
next : [
7472
{
7573
onMatch2 : function(value, scope) {
76-
if (scope.parent && value.length == scope.parent.meta) {
77-
return scope.parent.parent.get("comment");
74+
if (scope == "bracketedComment" && value.length == scope.data) {
75+
return scope.parent.get("comment");
7876
} else {
7977
return scope.get("comment");
8078
}
@@ -93,16 +91,14 @@ var LuaHighlightRules = function() {
9391
{
9492
stateName: "bracketedString",
9593
onMatch2 : function(value, scope){
96-
var parent = scope.get("bracketedString" + value.length);
97-
parent.meta = value.length;
98-
return parent.get(this.next).get("string.start");
94+
return scope.get(this.next, value.length - 2).get("string.start");
9995
},
10096
regex : /\[=*\[/,
10197
next : [
10298
{
10399
onMatch2 : function(value, scope) {
104-
if (scope.parent && value.length == scope.parent.meta) {
105-
return scope.parent.parent.get("string.end");
100+
if (scope == "bracketedString" && value.length == scope.data) {
101+
return scope.parent.get("string.end");
106102
} else {
107103
return scope.get("string.end");
108104
}

src/tokenizer.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class Tokenizer {
264264

265265
if (index - value.length > lastIndex) {
266266
var skipped = line.substring(lastIndex, index - value.length);
267-
if (token.type && token.type === type) {
267+
if (token.type && token.type == type) {
268268
token.value += skipped;
269269
}
270270
else {
@@ -297,7 +297,7 @@ class Tokenizer {
297297

298298
if (rule.next || rule.next2 || rememberedState) {
299299
if (!rememberedState) {
300-
if (typeof rule.next !== 'function') {
300+
if (rule.next && typeof rule.next !== 'function') {
301301
currentState = currentState.parent.get(rule.next);
302302
}
303303
else {
@@ -306,7 +306,7 @@ class Tokenizer {
306306
currentState = this.rootScope.fromStack(stack, currentState);
307307
}
308308
else {
309-
currentState = rule.next2(currentState, stack);
309+
currentState = rule.next2(currentState);
310310
}
311311
}
312312
}
@@ -335,7 +335,7 @@ class Tokenizer {
335335
}
336336

337337
if (type && !Array.isArray(type) && type != "") {
338-
if ((!rule || rule.merge !== false) && token.type === type) {
338+
if ((!rule || rule.merge !== false) && token.type == type) {
339339
token.value += value;
340340
}
341341
else {

0 commit comments

Comments
 (0)