summaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-07-03 15:57:17 -0400
committerGitHub <noreply@github.com>2020-07-03 15:57:17 -0400
commite30bab33249a9a99b59a11f8ea582f31651b4710 (patch)
tree64e86136388d408e87f7d5a64fcccafa3aef8a78 /ext/bg/js
parenta07a8dfff667e0bba20d7199c4d7aa610e98bcdb (diff)
Refactor text source map (#649)
* Use a null check instead of array check * Convert statisc to non-private * Use public source * Add public function for getting the mapping
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/text-source-map.js22
1 files changed, 13 insertions, 9 deletions
diff --git a/ext/bg/js/text-source-map.js b/ext/bg/js/text-source-map.js
index 1776ae07..6ed553e6 100644
--- a/ext/bg/js/text-source-map.js
+++ b/ext/bg/js/text-source-map.js
@@ -18,7 +18,7 @@
class TextSourceMap {
constructor(source, mapping=null) {
this._source = source;
- this._mapping = (Array.isArray(mapping) ? TextSourceMap._normalizeMapping(mapping) : null);
+ this._mapping = (mapping !== null ? TextSourceMap.normalizeMapping(mapping) : null);
}
get source() {
@@ -31,19 +31,19 @@ class TextSourceMap {
}
const source = this._source;
- if (!(other instanceof TextSourceMap && source === other._source)) {
+ if (!(other instanceof TextSourceMap && source === other.source)) {
return false;
}
let mapping = this._mapping;
- let otherMapping = other._mapping;
+ let otherMapping = other.getMappingCopy();
if (mapping === null) {
if (otherMapping === null) {
return true;
}
- mapping = TextSourceMap._createMapping(source);
+ mapping = TextSourceMap.createMapping(source);
} else if (otherMapping === null) {
- otherMapping = TextSourceMap._createMapping(source);
+ otherMapping = TextSourceMap.createMapping(source);
}
const mappingLength = mapping.length;
@@ -77,7 +77,7 @@ class TextSourceMap {
if (count <= 0) { return; }
if (this._mapping === null) {
- this._mapping = TextSourceMap._createMapping(this._source);
+ this._mapping = TextSourceMap.createMapping(this._source);
}
let sum = this._mapping[index];
@@ -90,17 +90,21 @@ class TextSourceMap {
insert(index, ...items) {
if (this._mapping === null) {
- this._mapping = TextSourceMap._createMapping(this._source);
+ this._mapping = TextSourceMap.createMapping(this._source);
}
this._mapping.splice(index, 0, ...items);
}
- static _createMapping(text) {
+ getMappingCopy() {
+ return this._mapping !== null ? [...this._mapping] : null;
+ }
+
+ static createMapping(text) {
return new Array(text.length).fill(1);
}
- static _normalizeMapping(mapping) {
+ static normalizeMapping(mapping) {
const result = [];
for (const value of mapping) {
result.push(