Skip to content

Commit a38047a

Browse files
finalfantasiamarijnh
authored andcommitted
[clojure mode] Use === instead of is for equality checks.
1 parent 3ff38f4 commit a38047a

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

mode/clojure/clojure.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -165,21 +165,21 @@ CodeMirror.defineMode("clojure", function (options) {
165165

166166
var ch = stream.next();
167167

168-
if (is(ch, "\\")) {stream.next(); readSymbol(stream); return "string-2";}
169-
if (is(ch, '"')) return (state.tokenize = inString)(stream, state);
168+
if (ch === "\\") {stream.next(); readSymbol(stream); return "string-2";}
169+
if (ch === '"') return (state.tokenize = inString)(stream, state);
170170
if (is(ch, /[(\[{]/)) {tokenType = "open"; return "bracket";}
171171
if (is(ch, /[)\]}]/)) {tokenType = "close"; return "bracket";}
172-
if (is(ch, ";")) {stream.skipToEnd(); tokenType = "space"; return "comment";}
172+
if (ch === ";") {stream.skipToEnd(); tokenType = "space"; return "comment";}
173173
if (is(ch, /[#'@^`~]/)) return "meta";
174174

175175
var name = readSymbol(stream);
176176
tokenType = "symbol";
177177

178-
if (is(name, "comment") && is(state.lastToken, "("))
178+
if (name === "comment" && state.lastToken === "(")
179179
return (state.tokenize = inComment)(stream, state);
180-
if (is(name, atom) || is(name.charAt(0), ":")) return "atom";
180+
if (is(name, atom) || name.charAt(0) === ":") return "atom";
181181
if (is(name, specialForm) || is(name, coreSymbol)) return "keyword";
182-
if (is(state.lastToken, "(")) return "builtin"; // other head symbol
182+
if (state.lastToken === "(") return "builtin"; // other head symbol
183183

184184
return "variable";
185185
}
@@ -188,8 +188,8 @@ CodeMirror.defineMode("clojure", function (options) {
188188
var escaped = false, next;
189189

190190
while (next = stream.next()) {
191-
if (is(next, '"') && !escaped) {state.tokenize = base; break;}
192-
escaped = !escaped && is(next, "\\");
191+
if (next === '"' && !escaped) {state.tokenize = base; break;}
192+
escaped = !escaped && next === "\\";
193193
}
194194

195195
return "string";
@@ -200,9 +200,9 @@ CodeMirror.defineMode("clojure", function (options) {
200200
var next;
201201

202202
while (next = stream.next()) {
203-
if (is(next, ")")) parenthesisCount--;
204-
if (is(next, "(")) parenthesisCount++;
205-
if (is(parenthesisCount, 0)) {
203+
if (next === ")") parenthesisCount--;
204+
if (next === "(") parenthesisCount++;
205+
if (parenthesisCount === 0) {
206206
stream.backUp(1);
207207
state.tokenize = base;
208208
break;
@@ -218,8 +218,8 @@ CodeMirror.defineMode("clojure", function (options) {
218218
var ch;
219219

220220
while (ch = stream.next()) {
221-
if (is(ch, "\\")) stream.next();
222-
else if (!symbol.test(ch)) {stream.backUp(1); break;}
221+
if (ch === "\\") stream.next();
222+
else if (!is(ch, symbol)) {stream.backUp(1); break;}
223223
}
224224

225225
return stream.current();
@@ -233,10 +233,9 @@ CodeMirror.defineMode("clojure", function (options) {
233233
return obj;
234234
}
235235

236-
function is(name, test) {
237-
if (test instanceof RegExp) return test.test(name);
238-
if (test instanceof Object) return test.propertyIsEnumerable(name);
239-
return name === test;
236+
function is(value, test) {
237+
if (test instanceof RegExp) return test.test(value);
238+
if (test instanceof Object) return test.propertyIsEnumerable(value);
240239
}
241240

242241
return {
@@ -254,31 +253,32 @@ CodeMirror.defineMode("clojure", function (options) {
254253

255254
tokenType = null;
256255
var style = state.tokenize(stream, state);
256+
var currentToken = stream.current();
257257

258-
if (!is(tokenType, "space")) {
259-
if (is(state.lastToken, "(") && is(state.ctx.indentTo, null)) {
260-
if (is(tokenType, "symbol") && (is(stream.current(), indentSymbol) ||
261-
is(stream.current(), assumeBody)))
258+
if (tokenType !== "space") {
259+
if (state.lastToken === "(" && state.ctx.indentTo === null) {
260+
if (tokenType === "symbol" && (is(currentToken, indentSymbol) ||
261+
is(currentToken, assumeBody)))
262262
state.ctx.indentTo = state.ctx.start + options.indentUnit;
263263
else state.ctx.indentTo = "next";
264-
} else if (is(state.ctx.indentTo, "next")) {
264+
} else if (state.ctx.indentTo === "next") {
265265
state.ctx.indentTo = stream.column();
266266
}
267267

268-
state.lastToken = stream.current();
268+
state.lastToken = currentToken;
269269
}
270270

271-
if (is(tokenType, "open"))
271+
if (tokenType === "open")
272272
state.ctx = {prev: state.ctx, start: stream.column(), indentTo: null};
273-
else if (is(tokenType, "close")) state.ctx = state.ctx.prev || state.ctx;
273+
else if (tokenType === "close") state.ctx = state.ctx.prev || state.ctx;
274274

275275
return style;
276276
},
277277

278278
indent: function (state) {
279279
var i = state.ctx.indentTo;
280280

281-
return (is(typeof i, "number")) ?
281+
return (typeof i === "number") ?
282282
i :
283283
state.ctx.start + 1;
284284
},

mode/clojure/test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,12 @@
650650
" [bracket (][keyword println] [variable b][bracket )))]"
651651
);
652652

653+
MT("should indent deftest and similar forms that assume body parameter",
654+
"[bracket (][builtin clojure.test/deftest] [variable foo-test]",
655+
" [bracket (][builtin testing] [string \"that foo should work\"]",
656+
" [bracket (][builtin is] [bracket (][keyword =] [atom :baz] [bracket (][builtin foo] [atom :bar][bracket )))))]"
657+
);
658+
653659
function typeTokenPairs(type, tokens) {
654660
return "[" + type + " " + tokens.join("] [" + type + " ") + "]";
655661
}

0 commit comments

Comments
 (0)