Skip to content

Commit 0ac67b1

Browse files
committed
Add a dedicated 'type' token type
Rather than abusing variable-3. Coloring is the same for now.
1 parent 5600b5e commit 0ac67b1

35 files changed

+77
-77
lines changed

lib/codemirror.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
.cm-s-default .cm-property,
120120
.cm-s-default .cm-operator {}
121121
.cm-s-default .cm-variable-2 {color: #05a;}
122-
.cm-s-default .cm-variable-3 {color: #085;}
122+
.cm-s-default .cm-variable-3, .cm-s-default .cm-type {color: #085;}
123123
.cm-s-default .cm-comment {color: #a50;}
124124
.cm-s-default .cm-string {color: #a11;}
125125
.cm-s-default .cm-string-2 {color: #f50;}

mode/clike/clike.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function popContext(state) {
3333
}
3434

3535
function typeBefore(stream, state, pos) {
36-
if (state.prevToken == "variable" || state.prevToken == "variable-3") return true;
36+
if (state.prevToken == "variable" || state.prevToken == "type") return true;
3737
if (/\S(?:[^- ]>|[*\]])\s*$|\*$/.test(stream.string.slice(0, pos))) return true;
3838
if (state.typeAtEndOfLine && stream.column() == stream.indentation()) return true;
3939
}
@@ -112,7 +112,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
112112
if (contains(defKeywords, cur)) isDefKeyword = true;
113113
return "keyword";
114114
}
115-
if (contains(types, cur)) return "variable-3";
115+
if (contains(types, cur)) return "type";
116116
if (contains(builtin, cur)) {
117117
if (contains(blockKeywords, cur)) curPunc = "newstatement";
118118
return "builtin";
@@ -281,7 +281,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
281281
}
282282

283283
function pointerHook(_stream, state) {
284-
if (state.prevToken == "variable-3") return "variable-3";
284+
if (state.prevToken == "type") return "type";
285285
return false;
286286
}
287287

@@ -774,7 +774,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
774774
return "atom";
775775
},
776776
token: function(_stream, state, style) {
777-
if ((style == "variable" || style == "variable-3") &&
777+
if ((style == "variable" || style == "type") &&
778778
state.prevToken == ".") {
779779
return "variable-2";
780780
}

mode/clike/test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }
77

88
MT("indent",
9-
"[variable-3 void] [def foo]([variable-3 void*] [variable a], [variable-3 int] [variable b]) {",
10-
" [variable-3 int] [variable c] [operator =] [variable b] [operator +]",
9+
"[type void] [def foo]([type void*] [variable a], [type int] [variable b]) {",
10+
" [type int] [variable c] [operator =] [variable b] [operator +]",
1111
" [number 1];",
1212
" [keyword return] [operator *][variable a];",
1313
"}");
@@ -21,9 +21,9 @@
2121
"}");
2222

2323
MT("def",
24-
"[variable-3 void] [def foo]() {}",
24+
"[type void] [def foo]() {}",
2525
"[keyword struct] [def bar]{}",
26-
"[variable-3 int] [variable-3 *][def baz]() {}");
26+
"[type int] [type *][def baz]() {}");
2727

2828
MT("def_new_line",
2929
"::[variable std]::[variable SomeTerribleType][operator <][variable T][operator >]",
@@ -37,10 +37,10 @@
3737

3838
MT("preprocessor",
3939
"[meta #define FOO 3]",
40-
"[variable-3 int] [variable foo];",
40+
"[type int] [variable foo];",
4141
"[meta #define BAR\\]",
4242
"[meta 4]",
43-
"[variable-3 unsigned] [variable-3 int] [variable bar] [operator =] [number 8];",
43+
"[type unsigned] [type int] [variable bar] [operator =] [number 8];",
4444
"[meta #include <baz> ][comment // comment]")
4545

4646

mode/elm/elm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
if (smallRE.test(ch)) {
7171
var isDef = source.pos === 1;
7272
source.eatWhile(idRE);
73-
return isDef ? "variable-3" : "variable";
73+
return isDef ? "type" : "variable";
7474
}
7575

7676
if (digitRE.test(ch)) {

mode/javascript/javascript.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
4646

4747
// Extend the 'normal' keywords with the TypeScript language extensions
4848
if (isTS) {
49-
var type = {type: "variable", style: "variable-3"};
49+
var type = {type: "variable", style: "type"};
5050
var tsKeywords = {
5151
// object-like things
5252
"interface": kw("class"),
@@ -543,7 +543,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
543543
}
544544
}
545545
function typeexpr(type) {
546-
if (type == "variable") {cx.marked = "variable-3"; return cont(afterType);}
546+
if (type == "variable") {cx.marked = "type"; return cont(afterType);}
547547
if (type == "string" || type == "number" || type == "atom") return cont(afterType);
548548
if (type == "{") return cont(pushlex("}"), commasep(typeprop, "}", ",;"), poplex, afterType)
549549
if (type == "(") return cont(commasep(typearg, ")"), maybeReturnType)

mode/javascript/test.js

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,15 @@
238238
}
239239

240240
TS("typescript_extend_type",
241-
"[keyword class] [def Foo] [keyword extends] [variable-3 Some][operator <][variable-3 Type][operator >] {}")
241+
"[keyword class] [def Foo] [keyword extends] [type Some][operator <][type Type][operator >] {}")
242242

243243
TS("typescript_arrow_type",
244-
"[keyword let] [def x]: ([variable arg]: [variable-3 Type]) [operator =>] [variable-3 ReturnType]")
244+
"[keyword let] [def x]: ([variable arg]: [type Type]) [operator =>] [type ReturnType]")
245245

246246
TS("typescript_class",
247247
"[keyword class] [def Foo] {",
248248
" [keyword public] [keyword static] [property main]() {}",
249-
" [keyword private] [property _foo]: [variable-3 string];",
249+
" [keyword private] [property _foo]: [type string];",
250250
"}")
251251

252252
TS("typescript_literal_types",
@@ -255,85 +255,85 @@
255255
" [property truthy]: [string 'true'] [operator |] [number 1] [operator |] [atom true];",
256256
" [property falsy]: [string 'false'] [operator |] [number 0] [operator |] [atom false];",
257257
"}",
258-
"[keyword interface] [def MyInstance] [keyword extends] [variable-3 Sequelize].[variable-3 Instance] [operator <] [variable-3 MyAttributes] [operator >] {",
259-
" [property rawAttributes]: [variable-3 MyAttributes];",
258+
"[keyword interface] [def MyInstance] [keyword extends] [type Sequelize].[type Instance] [operator <] [type MyAttributes] [operator >] {",
259+
" [property rawAttributes]: [type MyAttributes];",
260260
" [property truthy]: [string 'true'] [operator |] [number 1] [operator |] [atom true];",
261261
" [property falsy]: [string 'false'] [operator |] [number 0] [operator |] [atom false];",
262262
"}")
263263

264264
TS("typescript_extend_operators",
265265
"[keyword export] [keyword interface] [def UserModel] [keyword extends]",
266-
" [variable-3 Sequelize].[variable-3 Model] [operator <] [variable-3 UserInstance], [variable-3 UserAttributes] [operator >] {",
266+
" [type Sequelize].[type Model] [operator <] [type UserInstance], [type UserAttributes] [operator >] {",
267267
" [property findById]: (",
268-
" [variable userId]: [variable-3 number]",
269-
" ) [operator =>] [variable-3 Promise] [operator <] [variable-3 Array] [operator <] { [property id], [property name] } [operator >>];",
268+
" [variable userId]: [type number]",
269+
" ) [operator =>] [type Promise] [operator <] [type Array] [operator <] { [property id], [property name] } [operator >>];",
270270
" [property updateById]: (",
271-
" [variable userId]: [variable-3 number],",
272-
" [variable isActive]: [variable-3 boolean]",
273-
" ) [operator =>] [variable-3 Promise] [operator <] [variable-3 AccountHolderNotificationPreferenceInstance] [operator >];",
271+
" [variable userId]: [type number],",
272+
" [variable isActive]: [type boolean]",
273+
" ) [operator =>] [type Promise] [operator <] [type AccountHolderNotificationPreferenceInstance] [operator >];",
274274
" }")
275275

276276
TS("typescript_interface_with_const",
277277
"[keyword const] [def hello]: {",
278-
" [property prop1][operator ?]: [variable-3 string];",
279-
" [property prop2][operator ?]: [variable-3 string];",
278+
" [property prop1][operator ?]: [type string];",
279+
" [property prop2][operator ?]: [type string];",
280280
"} [operator =] {};")
281281

282282
TS("typescript_double_extend",
283283
"[keyword export] [keyword interface] [def UserAttributes] {",
284-
" [property id][operator ?]: [variable-3 number];",
285-
" [property createdAt][operator ?]: [variable-3 Date];",
284+
" [property id][operator ?]: [type number];",
285+
" [property createdAt][operator ?]: [type Date];",
286286
"}",
287-
"[keyword export] [keyword interface] [def UserInstance] [keyword extends] [variable-3 Sequelize].[variable-3 Instance][operator <][variable-3 UserAttributes][operator >], [variable-3 UserAttributes] {",
288-
" [property id]: [variable-3 number];",
289-
" [property createdAt]: [variable-3 Date];",
287+
"[keyword export] [keyword interface] [def UserInstance] [keyword extends] [type Sequelize].[type Instance][operator <][type UserAttributes][operator >], [type UserAttributes] {",
288+
" [property id]: [type number];",
289+
" [property createdAt]: [type Date];",
290290
"}");
291291

292292
TS("typescript_index_signature",
293293
"[keyword interface] [def A] {",
294-
" [[ [variable prop]: [variable-3 string] ]]: [variable-3 any];",
295-
" [property prop1]: [variable-3 any];",
294+
" [[ [variable prop]: [type string] ]]: [type any];",
295+
" [property prop1]: [type any];",
296296
"}");
297297

298298
TS("typescript_generic_class",
299-
"[keyword class] [def Foo][operator <][variable-3 T][operator >] {",
299+
"[keyword class] [def Foo][operator <][type T][operator >] {",
300300
" [property bar]() {}",
301-
" [property foo](): [variable-3 Foo] {}",
301+
" [property foo](): [type Foo] {}",
302302
"}")
303303

304304
TS("typescript_type_when_keyword",
305-
"[keyword export] [keyword type] [variable-3 AB] [operator =] [variable-3 A] [operator |] [variable-3 B];",
306-
"[keyword type] [variable-3 Flags] [operator =] {",
307-
" [property p1]: [variable-3 string];",
308-
" [property p2]: [variable-3 boolean];",
305+
"[keyword export] [keyword type] [type AB] [operator =] [type A] [operator |] [type B];",
306+
"[keyword type] [type Flags] [operator =] {",
307+
" [property p1]: [type string];",
308+
" [property p2]: [type boolean];",
309309
"};")
310310

311311
TS("typescript_type_when_not_keyword",
312312
"[keyword class] [def HasType] {",
313-
" [property type]: [variable-3 string];",
314-
" [property constructor]([def type]: [variable-3 string]) {",
313+
" [property type]: [type string];",
314+
" [property constructor]([def type]: [type string]) {",
315315
" [keyword this].[property type] [operator =] [variable-2 type];",
316316
" }",
317-
" [property setType]({ [def type] }: { [property type]: [variable-3 string]; }) {",
317+
" [property setType]({ [def type] }: { [property type]: [type string]; }) {",
318318
" [keyword this].[property type] [operator =] [variable-2 type];",
319319
" }",
320320
"}")
321321

322322
TS("typescript_function_generics",
323323
"[keyword function] [def a]() {}",
324-
"[keyword function] [def b][operator <][variable-3 IA] [keyword extends] [variable-3 object], [variable-3 IB] [keyword extends] [variable-3 object][operator >]() {}",
324+
"[keyword function] [def b][operator <][type IA] [keyword extends] [type object], [type IB] [keyword extends] [type object][operator >]() {}",
325325
"[keyword function] [def c]() {}")
326326

327327
TS("typescript_complex_return_type",
328328
"[keyword function] [def A]() {",
329329
" [keyword return] [keyword this].[property property];",
330330
"}",
331-
"[keyword function] [def B](): [variable-3 Promise][operator <]{ [[ [variable key]: [variable-3 string] ]]: [variable-3 any] } [operator |] [atom null][operator >] {",
331+
"[keyword function] [def B](): [type Promise][operator <]{ [[ [variable key]: [type string] ]]: [type any] } [operator |] [atom null][operator >] {",
332332
" [keyword return] [keyword this].[property property];",
333333
"}")
334334

335335
TS("typescript_complex_type_casting",
336-
"[keyword const] [def giftpay] [operator =] [variable config].[property get]([string 'giftpay']) [keyword as] { [[ [variable platformUuid]: [variable-3 string] ]]: { [property version]: [variable-3 number]; [property apiCode]: [variable-3 string]; } };")
336+
"[keyword const] [def giftpay] [operator =] [variable config].[property get]([string 'giftpay']) [keyword as] { [[ [variable platformUuid]: [type string] ]]: { [property version]: [type number]; [property apiCode]: [type string]; } };")
337337

338338
var jsonld_mode = CodeMirror.getMode(
339339
{indentUnit: 2},

mode/jsx/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@
7272

7373
TS("tsx_react_integration",
7474
"[keyword interface] [def Props] {",
75-
" [property foo]: [variable-3 string];",
75+
" [property foo]: [type string];",
7676
"}",
77-
"[keyword class] [def MyComponent] [keyword extends] [variable-3 React].[variable-3 Component] [operator <] [variable-3 Props], [variable-3 any] [operator >] {",
77+
"[keyword class] [def MyComponent] [keyword extends] [type React].[type Component] [operator <] [type Props], [type any] [operator >] {",
7878
" [property render]() {",
7979
" [keyword return] [bracket&tag <][tag span][bracket&tag >]{[keyword this].[property props].[property foo]}[bracket&tag </][tag span][bracket&tag >]",
8080
" }",

theme/abcdef.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
.cm-s-abcdef span.cm-def { color: #fffabc; }
1515
.cm-s-abcdef span.cm-variable { color: #abcdef; }
1616
.cm-s-abcdef span.cm-variable-2 { color: #cacbcc; }
17-
.cm-s-abcdef span.cm-variable-3 { color: #def; }
17+
.cm-s-abcdef span.cm-variable-3, .cm-s-abcdef span.cm-type { color: #def; }
1818
.cm-s-abcdef span.cm-property { color: #fedcba; }
1919
.cm-s-abcdef span.cm-operator { color: #ff0; }
2020
.cm-s-abcdef span.cm-comment { color: #7a7b7c; font-style: italic;}

theme/ambiance.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

theme/cobalt.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
.cm-s-cobalt span.cm-string { color: #3ad900; }
1616
.cm-s-cobalt span.cm-meta { color: #ff9d00; }
1717
.cm-s-cobalt span.cm-variable-2, .cm-s-cobalt span.cm-tag { color: #9effff; }
18-
.cm-s-cobalt span.cm-variable-3, .cm-s-cobalt span.cm-def { color: white; }
18+
.cm-s-cobalt span.cm-variable-3, .cm-s-cobalt span.cm-def, .cm-s-cobalt .cm-type { color: white; }
1919
.cm-s-cobalt span.cm-bracket { color: #d8d8d8; }
2020
.cm-s-cobalt span.cm-builtin, .cm-s-cobalt span.cm-special { color: #ff9e59; }
2121
.cm-s-cobalt span.cm-link { color: #845dc4; }

0 commit comments

Comments
 (0)