Skip to content

Commit 1a14040

Browse files
committed
fix after rebase
1 parent 5278fb3 commit 1a14040

File tree

4 files changed

+56
-43
lines changed

4 files changed

+56
-43
lines changed

demo/kitchen-sink/demo.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ function loadLanguageProvider(editor) {
130130
}
131131
}, true);
132132
function showOccurrenceMarkers(session, positions) {
133+
if (!session.state) session.state = {}
133134
if (!session.state.occurrenceMarkers) {
134135
session.state.occurrenceMarkers = new MarkerGroup(session);
135136
}
@@ -179,7 +180,7 @@ function loadLanguageProvider(editor) {
179180
let docPos = e.getDocumentPosition();
180181

181182
languageProvider.doHover(session, docPos, function(hover) {
182-
var errorMarker = session.state?.diagnosticMarkers.getMarkerAtPosition(docPos);
183+
var errorMarker = session.state?.diagnosticMarkers?.getMarkerAtPosition(docPos);
183184

184185
if (!errorMarker && !hover?.content) return;
185186

src/layer/text.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ class Text {
416416
if (!isTextToken(token.type.toString())) {
417417
var classes = "ace_" + token.type.toString().replace(/\./g, " ace_");
418418
var span = this.dom.createElement("span");
419-
if (token.type.toString() === "fold")
419+
if (token.type.toString() === "fold") {
420420
span.style.width = (token.value.length * this.config.characterWidth) + "px";
421421
span.setAttribute("title", nls("inline-fold.closed.title", "Unfold code"));
422422
}

src/scope.js

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,68 @@
11
"use strict";
22

3-
var Scope = function (name, parent) {
4-
this.name = name.toString();
5-
this.children = {};
6-
this.parent = parent;
7-
};
8-
(function () {
9-
Scope.prototype.toString = function () {
3+
class Scope {
4+
/**
5+
* @param {string} name
6+
* @param {Scope} [parent]
7+
*/
8+
constructor(name, parent) {
9+
this.name = name.toString();
10+
this.children = {};
11+
this.parent = parent;
12+
}
13+
toString() {
1014
return this.name;
11-
};
12-
Scope.prototype.get = function (name, extraId = '') {
13-
return this.children[name.toString() + extraId] || (this.children[name.toString() + extraId] = new Scope(
14-
name, this));
15-
};
16-
Scope.prototype.find = function (states) {
15+
}
16+
/**
17+
* @param {string} name
18+
* @param {string|undefined} extraId
19+
*/
20+
get(name, extraId) {
21+
var id = name.toString() + (extraId || "");
22+
return this.children[id] || (
23+
this.children[id] = new Scope(name, this)
24+
);
25+
}
26+
find(states) {
1727
var s = this;
1828
while (s && !states[s.name]) {
1929
s = s.parent;
2030
}
2131
return states[s ? s.name : "start"];
22-
};
23-
Scope.prototype.replace = function (a, b) {
32+
}
33+
replace(a, b) {
2434
return this.name.replace(a, b);
25-
};
26-
Scope.prototype.indexOf = function (a, b) {
35+
}
36+
indexOf(a, b) {
2737
return this.name.indexOf(a, b);
28-
};
29-
Scope.prototype.hasParent = function (states) {
38+
}
39+
/**
40+
* @param {string} states
41+
*/
42+
hasParent(states) {
3043
var s = this;
3144
while (s && states !== s.name) {
3245
s = s.parent;
3346
}
3447
return s ? 1 : -1;
35-
};
36-
Scope.prototype.count = function () {
48+
}
49+
count() {
3750
var s = 1;
3851
for (var i in this.children) s += this.children[i].count();
3952
return s;
40-
};
53+
}
4154
/**
4255
*
4356
* @returns {string[]}
4457
*/
45-
Scope.prototype.getAllScopeNames = function () {
58+
getAllScopeNames() {
4659
var scopeNames = [];
4760
var self = this;
4861
do {
4962
scopeNames.push(self.name);
5063
} while (self = self.parent);
5164
return scopeNames;
52-
};
53-
}).call(Scope.prototype);
65+
}
66+
}
5467

5568
exports.Scope = Scope;

src/tokenizer.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -372,21 +372,19 @@ Tokenizer.prototype.reportError = reportError;
372372
*
373373
* @constructor
374374
**/
375-
var CustomTokenizer = function(rules, modeName) {
376-
Tokenizer.call(this, rules);
377-
this.rootScope = new Scope(modeName);
378-
}
379-
oop.inherits(CustomTokenizer, Tokenizer);
380-
381-
(function() {
375+
class CustomTokenizer extends Tokenizer {
376+
constructor(rules, modeName) {
377+
super(rules);
378+
this.rootScope = new Scope(modeName);
379+
}
382380
/**
383381
* Returns an object containing two properties: `tokens`, which contains all the tokens; and `state`, the current state.
384382
* @param {String} line
385383
* @param {String|Scope} startState
386384
* @returns {Object}
387385
* @override
388386
**/
389-
this.getLineTokens = function(line, startState) {
387+
getLineTokens(line, startState) {
390388
var stack = [];
391389

392390
var currentState = (startState !== undefined) ? (startState instanceof Scope) ? startState
@@ -404,7 +402,7 @@ oop.inherits(CustomTokenizer, Tokenizer);
404402
var lastIndex = 0;
405403
var matchAttempts = 0;
406404

407-
var token = {type: null, value: ""};
405+
var token = { type: null, value: "" };
408406

409407
while (match = re.exec(line)) {
410408
var type = currentState.get(mapping.defaultToken);
@@ -420,11 +418,11 @@ oop.inherits(CustomTokenizer, Tokenizer);
420418
} else {
421419
if (token.type)
422420
tokens.push(token);
423-
token = {type: currentState.get(type), value: skipped};
421+
token = { type: currentState.get(type), value: skipped };
424422
}
425423
}
426424

427-
for (var i = 0; i < match.length-2; i++) {
425+
for (var i = 0; i < match.length - 2; i++) {
428426
if (match[i + 1] === undefined)
429427
continue;
430428

@@ -491,14 +489,14 @@ oop.inherits(CustomTokenizer, Tokenizer);
491489
} else {
492490
if (token.type)
493491
tokens.push(token);
494-
token = {type: currentState.get(type), value: value};
492+
token = { type: currentState.get(type), value: value };
495493
}
496494
} else if (type) {
497495
if (token.type)
498496
tokens.push(token);
499-
token = {type: null, value: ""};
497+
token = { type: null, value: "" };
500498
for (var i = 0; i < type.length; i++) {
501-
type[i].type=currentState.get(type[i].type);
499+
type[i].type = currentState.get(type[i].type);
502500
tokens.push(type[i]);
503501
}
504502
}
@@ -544,8 +542,9 @@ oop.inherits(CustomTokenizer, Tokenizer);
544542
return {
545543
tokens: tokens
546544
};
547-
};
548-
}).call(CustomTokenizer.prototype);
545+
}
546+
}
549547

548+
550549
exports.Tokenizer = Tokenizer;
551550
exports.CustomTokenizer = CustomTokenizer;

0 commit comments

Comments
 (0)