From 5e013d9ec1a4fa37ba3995ba1be7c5989a606e34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Harrtell?= Date: Sat, 6 Jun 2020 20:57:36 +0200 Subject: [PATCH] Remove use of plugin-proposal-class-properties --- babel.config.js | 3 - package.json | 1 - src/java/lang/Exception.js | 1 - src/java/lang/Integer.js | 9 ++- src/java/lang/Long.js | 6 +- src/java/lang/StringBuffer.js | 9 ++- src/java/lang/StringBuilder.js | 29 +++++----- src/java/util/ArrayList.js | 55 ++++++++++--------- src/java/util/HashMap.js | 15 +++-- src/java/util/HashSet.js | 42 +++++++------- src/java/util/LinkedList.js | 11 ++-- src/java/util/Stack.js | 27 +++++---- src/java/util/TreeMap.js | 33 ++++++----- src/java/util/TreeSet.js | 33 +++++------ .../jts/geom/TopologyException.js | 5 +- yarn.lock | 2 +- 16 files changed, 138 insertions(+), 143 deletions(-) diff --git a/babel.config.js b/babel.config.js index b99b4ed95..0f1515e6c 100644 --- a/babel.config.js +++ b/babel.config.js @@ -5,8 +5,5 @@ module.exports = { node: ['10'] } }] - ], - plugins: [ - '@babel/plugin-proposal-class-properties' ] } diff --git a/package.json b/package.json index c80875da8..5c21fa434 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,6 @@ "license": "(EDL-1.0 OR EPL-1.0)", "devDependencies": { "@babel/core": "7.10.2", - "@babel/plugin-proposal-class-properties": "7.10.1", "@babel/preset-env": "7.10.2", "babel-eslint": "10.1.0", "chai": "4.2.0", diff --git a/src/java/lang/Exception.js b/src/java/lang/Exception.js index 738469907..6378bd208 100644 --- a/src/java/lang/Exception.js +++ b/src/java/lang/Exception.js @@ -1,5 +1,4 @@ export default class Exception { - message constructor(message) { this.message = message } diff --git a/src/java/lang/Integer.js b/src/java/lang/Integer.js index 60aeb5c5b..03c87b693 100644 --- a/src/java/lang/Integer.js +++ b/src/java/lang/Integer.js @@ -1,17 +1,16 @@ export default class Integer { - #value constructor(value) { - this.#value = value + this.value = value } intValue() { - return this.#value + return this.value } compareTo(o) { - if (this.#value < o) + if (this.value < o) return -1 - if (this.#value > o) + if (this.value > o) return 1 return 0 } diff --git a/src/java/lang/Long.js b/src/java/lang/Long.js index 4c8a71f7e..06ca1bd07 100644 --- a/src/java/lang/Long.js +++ b/src/java/lang/Long.js @@ -1,9 +1,7 @@ export default class Long { - high = 0 - low = 0 constructor(high, low) { - this.low = low - this.high = high + this.low = low || 0 + this.high = high || 0 } static toBinaryString(i) { diff --git a/src/java/lang/StringBuffer.js b/src/java/lang/StringBuffer.js index 1e376ed19..e26fe432c 100644 --- a/src/java/lang/StringBuffer.js +++ b/src/java/lang/StringBuffer.js @@ -1,15 +1,14 @@ export default class StringBuffer { - #str constructor(str) { - this.#str = str + this.str = str } append(e) { - this.#str += e + this.str += e } setCharAt(i, c) { - this.#str = this.#str.substr(0, i) + c + this.#str.substr(i + 1) + this.str = this.str.substr(0, i) + c + this.str.substr(i + 1) } toString() { - return this.#str + return this.str } } \ No newline at end of file diff --git a/src/java/lang/StringBuilder.js b/src/java/lang/StringBuilder.js index 2529b029c..59704dbd2 100644 --- a/src/java/lang/StringBuilder.js +++ b/src/java/lang/StringBuilder.js @@ -1,15 +1,14 @@ -export default function StringBuilder(str) { - this.str = str -} - -StringBuilder.prototype.append = function(e) { - this.str += e -} - -StringBuilder.prototype.setCharAt = function(i, c) { - this.str = this.str.substr(0, i) + c + this.str.substr(i + 1) -} - -StringBuilder.prototype.toString = function() { - return this.str -} +export default class StringBuilder { + constructor(str) { + this.str = str + } + append(e) { + this.str += e + } + setCharAt(i, c) { + this.str = this.str.substr(0, i) + c + this.str.substr(i + 1) + } + toString() { + return this.str + } +} \ No newline at end of file diff --git a/src/java/util/ArrayList.js b/src/java/util/ArrayList.js index 7c5b2efb9..254e17da9 100644 --- a/src/java/util/ArrayList.js +++ b/src/java/util/ArrayList.js @@ -7,36 +7,39 @@ import NoSuchElementException from './NoSuchElementException' * @see http://download.oracle.com/javase/6/docs/api/java/util/ArrayList.html */ export default class ArrayList extends List { - interfaces_ = [List, Collection] - #array = [] constructor(o) { super() + this.array = [] if (o instanceof Collection) this.addAll(o) } + get interfaces_() { + return [List, Collection] + } + ensureCapacity() { } add(e) { if (arguments.length === 1) - this.#array.push(e) + this.array.push(e) else - this.#array.splice(arguments[0], 0, arguments[1]) + this.array.splice(arguments[0], 0, arguments[1]) return true } clear() { - this.#array = [] + this.array = [] } addAll(c) { for (const e of c) - this.#array.push(e) + this.array.push(e) } set(index, element) { - const oldElement = this.#array[index] - this.#array[index] = element + const oldElement = this.array[index] + this.array[index] = element return oldElement } @@ -47,62 +50,60 @@ export default class ArrayList extends List { get(index) { if (index < 0 || index >= this.size()) throw new IndexOutOfBoundsException() - return this.#array[index] + return this.array[index] } isEmpty() { - return this.#array.length === 0 + return this.array.length === 0 } sort(comparator) { if (comparator) - this.#array.sort((a, b) => comparator.compare(a, b)) - else this.#array.sort() + this.array.sort((a, b) => comparator.compare(a, b)) + else this.array.sort() } size() { - return this.#array.length + return this.array.length } toArray() { - return this.#array.slice() + return this.array.slice() } remove(o) { - for (let i = 0, len = this.#array.length; i < len; i++) - if (this.#array[i] === o) - return !!this.#array.splice(i, 1) + for (let i = 0, len = this.array.length; i < len; i++) + if (this.array[i] === o) + return !!this.array.splice(i, 1) return false } [Symbol.iterator]() { - return this.#array.values() + return this.array.values() } } class Iterator { - #arrayList - #position = 0 - constructor(arrayList) { - this.#arrayList = arrayList + this.arrayList = arrayList + this.position = 0 } next() { - if (this.#position === this.#arrayList.size()) + if (this.position === this.arrayList.size()) throw new NoSuchElementException() - return this.#arrayList.get(this.#position++) + return this.arrayList.get(this.position++) } hasNext() { - return this.#position < this.#arrayList.size() + return this.position < this.arrayList.size() } set(element) { - return this.#arrayList.set(this.#position - 1, element) + return this.arrayList.set(this.position - 1, element) } remove() { - this.#arrayList.remove(this.#arrayList.get(this.#position)) + this.arrayList.remove(this.arrayList.get(this.position)) } } diff --git a/src/java/util/HashMap.js b/src/java/util/HashMap.js index 26d17f81c..059770473 100644 --- a/src/java/util/HashMap.js +++ b/src/java/util/HashMap.js @@ -6,20 +6,23 @@ import HashSet from './HashSet' * @see http://download.oracle.com/javase/6/docs/api/java/util/HashMap.html */ export default class HashMap extends MapInterface { - #map = new Map() + constructor() { + super() + this.map = new Map() + } get(key) { - return this.#map.get(key) || null + return this.map.get(key) || null } put(key, value) { - this.#map.set(key, value) + this.map.set(key, value) return value } values() { const arrayList = new ArrayList() - const it = this.#map.values() + const it = this.map.values() let o = it.next() while (!o.done) { arrayList.add(o.value) @@ -30,11 +33,11 @@ export default class HashMap extends MapInterface { entrySet() { const hashSet = new HashSet() - this.#map.entries().forEach(entry => hashSet.add(entry)) + this.map.entries().forEach(entry => hashSet.add(entry)) return hashSet } size() { - return this.#map.size() + return this.map.size() } } diff --git a/src/java/util/HashSet.js b/src/java/util/HashSet.js index 62bfbb562..033168f66 100644 --- a/src/java/util/HashSet.js +++ b/src/java/util/HashSet.js @@ -7,25 +7,25 @@ import Set from './Set' * @see http://docs.oracle.com/javase/6/docs/api/java/util/HashSet.html */ export default class HashSet extends Set { - #map = new Map() constructor(o) { super() + this.map = new Map() if (o instanceof Collection) this.addAll(o) } contains(o) { const hashCode = o.hashCode ? o.hashCode() : o - if (this.#map.has(hashCode)) + if (this.map.has(hashCode)) return true return false } add(o) { const hashCode = o.hashCode ? o.hashCode() : o - if (this.#map.has(hashCode)) + if (this.map.has(hashCode)) return false - return !!this.#map.set(hashCode, o) + return !!this.map.set(hashCode, o) } addAll(c) { @@ -39,50 +39,46 @@ export default class HashSet extends Set { } size() { - return this.#map.size + return this.map.size } isEmpty() { - return this.#map.size === 0 + return this.map.size === 0 } toArray() { - return Array.from(this.#map.values()) + return Array.from(this.map.values()) } iterator() { - return new Iterator(this.#map) + return new Iterator(this.map) } [Symbol.iterator]() { - return this.#map + return this.map } } class Iterator { - #iterator - #done - #value - constructor(map) { - this.#iterator = map.values() - const { done, value } = this.#iterator.next() - this.#done = done - this.#value = value + this.iterator = map.values() + const { done, value } = this.iterator.next() + this.done = done + this.value = value } next() { - if (this.#done) + if (this.done) throw new NoSuchElementException() - const current = this.#value - const { done, value } = this.#iterator.next() - this.#done = done - this.#value = value + const current = this.value + const { done, value } = this.iterator.next() + this.done = done + this.value = value return current } hasNext() { - return !this.#done + return !this.done } remove() { diff --git a/src/java/util/LinkedList.js b/src/java/util/LinkedList.js index e80312d00..fd688b2b7 100644 --- a/src/java/util/LinkedList.js +++ b/src/java/util/LinkedList.js @@ -1,14 +1,17 @@ export default class LinkedList { - #array = [] + constructor() { + this.array = [] + } + addLast(e) { - this.#array.push(e) + this.array.push(e) } removeFirst() { - return this.#array.shift() + return this.array.shift() } isEmpty() { - return this.#array.length === 0 + return this.array.length === 0 } } diff --git a/src/java/util/Stack.js b/src/java/util/Stack.js index 3c1a668d0..ec938dcda 100644 --- a/src/java/util/Stack.js +++ b/src/java/util/Stack.js @@ -6,17 +6,20 @@ import List from './List' * @see http://download.oracle.com/javase/6/docs/api/java/util/Stack.html */ export default class Stack extends List { - #array = [] + constructor() { + super() + this.array = [] + } add(e) { - this.#array.push(e) + this.array.push(e) return true } get(index) { if (index < 0 || index >= this.size()) throw new IndexOutOfBoundsException() - return this.#array[index] + return this.array[index] } /** @@ -25,7 +28,7 @@ export default class Stack extends List { * @return {Object} */ push(e) { - this.#array.push(e) + this.array.push(e) return e } @@ -34,9 +37,9 @@ export default class Stack extends List { * @return {Object} */ pop() { - if (this.#array.length === 0) + if (this.array.length === 0) throw new EmptyStackException() - return this.#array.pop() + return this.array.pop() } /** @@ -45,9 +48,9 @@ export default class Stack extends List { * @return {Object} */ peek() { - if (this.#array.length === 0) + if (this.array.length === 0) throw new EmptyStackException() - return this.#array[this.#array.length - 1] + return this.array[this.array.length - 1] } /** @@ -56,7 +59,7 @@ export default class Stack extends List { * otherwise. */ empty() { - return this.#array.length === 0 + return this.array.length === 0 } /** @@ -81,20 +84,20 @@ export default class Stack extends List { * not on the stack. */ search(o) { - return this.#array.indexOf(o) + return this.array.indexOf(o) } /** * @return {number} */ size() { - return this.#array.length + return this.array.length } /** * @return {Array} */ toArray() { - return this.#array.slice() + return this.array.slice() } } diff --git a/src/java/util/TreeMap.js b/src/java/util/TreeMap.js index 1d9f51cc0..c497efd80 100644 --- a/src/java/util/TreeMap.js +++ b/src/java/util/TreeMap.js @@ -25,11 +25,14 @@ function rightOf(p) { * @see http://download.oracle.com/javase/6/docs/api/java/util/TreeMap.html */ export default class TreeMap extends SortedMap { - #root = null - #size = 0 + constructor() { + super() + this.root_ = null + this.size_ = 0 + } get(key) { - let p = this.#root + let p = this.root_ while (p !== null) { const cmp = key.compareTo(p.key) if (cmp < 0) @@ -42,8 +45,8 @@ export default class TreeMap extends SortedMap { } put(key, value) { - if (this.#root === null) { - this.#root = { + if (this.root_ === null) { + this.root_ = { key: key, value: value, left: null, @@ -57,10 +60,10 @@ export default class TreeMap extends SortedMap { return this.key } } - this.#size = 1 + this.size_ = 1 return null } - let t = this.#root; let parent; let cmp + let t = this.root_; let parent; let cmp do { parent = t cmp = key.compareTo(t.key) @@ -93,7 +96,7 @@ export default class TreeMap extends SortedMap { else parent.right = e this.fixAfterInsertion(e) - this.#size++ + this.size_++ return null } @@ -103,7 +106,7 @@ export default class TreeMap extends SortedMap { fixAfterInsertion(x) { let y x.color = RED - while (x != null && x !== this.#root && x.parent.color === RED) + while (x != null && x !== this.root_ && x.parent.color === RED) if (parentOf(x) === leftOf(parentOf(parentOf(x)))) { y = rightOf(parentOf(parentOf(x))) if (colorOf(y) === RED) { @@ -138,7 +141,7 @@ export default class TreeMap extends SortedMap { } } - this.#root.color = BLACK + this.root_.color = BLACK } values() { @@ -174,7 +177,7 @@ export default class TreeMap extends SortedMap { r.left.parent = p r.parent = p.parent if (p.parent == null) - this.#root = r + this.root_ = r else if (p.parent.left === p) p.parent.left = r else @@ -195,7 +198,7 @@ export default class TreeMap extends SortedMap { l.right.parent = p l.parent = p.parent if (p.parent == null) - this.#root = l + this.root_ = l else if (p.parent.right === p) p.parent.right = l else @@ -209,7 +212,7 @@ export default class TreeMap extends SortedMap { * @return {Object} */ getFirstEntry() { - let p = this.#root + let p = this.root_ if (p != null) while (p.left != null) p = p.left return p @@ -241,11 +244,11 @@ export default class TreeMap extends SortedMap { } size() { - return this.#size + return this.size_ } containsKey(key) { - let p = this.#root + let p = this.root_ while (p !== null) { const cmp = key.compareTo(p.key) if (cmp < 0) diff --git a/src/java/util/TreeSet.js b/src/java/util/TreeSet.js index 42f172db9..2ac28396b 100644 --- a/src/java/util/TreeSet.js +++ b/src/java/util/TreeSet.js @@ -7,16 +7,15 @@ import SortedSet from './SortedSet' * @see http://download.oracle.com/javase/6/docs/api/java/util/TreeSet.html */ export default class TreeSet extends SortedSet { - #array = [] - constructor(o) { super() + this.array = [] if (o instanceof Collection) this.addAll(o) } contains(o) { - for (const e of this.#array) + for (const e of this.array) if (e.compareTo(o) === 0) return true return false @@ -25,12 +24,12 @@ export default class TreeSet extends SortedSet { add(o) { if (this.contains(o)) return false - for (let i = 0, len = this.#array.length; i < len; i++) { - const e = this.#array[i] + for (let i = 0, len = this.array.length; i < len; i++) { + const e = this.array[i] if (e.compareTo(o) === 1) - return !!this.#array.splice(i, 0, o) + return !!this.array.splice(i, 0, o) } - this.#array.push(o) + this.array.push(o) return true } @@ -45,38 +44,36 @@ export default class TreeSet extends SortedSet { } size() { - return this.#array.length + return this.array.length } isEmpty() { - return this.#array.length === 0 + return this.array.length === 0 } toArray() { - return this.#array.slice() + return this.array.slice() } iterator() { - return new Iterator(this.#array) + return new Iterator(this.array) } } class Iterator { - #array - #position = 0 - constructor(array) { - this.#array = array + this.array = array + this.position = 0 } next() { - if (this.#position === this.#array.length) + if (this.position === this.array.length) throw new NoSuchElementException() - return this.#array[this.#position++] + return this.array[this.position++] } hasNext() { - return this.#position < this.#array.length + return this.position < this.array.length } remove() { diff --git a/src/org/locationtech/jts/geom/TopologyException.js b/src/org/locationtech/jts/geom/TopologyException.js index 1b73b0b36..1969bbe72 100644 --- a/src/org/locationtech/jts/geom/TopologyException.js +++ b/src/org/locationtech/jts/geom/TopologyException.js @@ -2,12 +2,11 @@ import Coordinate from './Coordinate' import RuntimeException from '../../../../java/lang/RuntimeException' export default class TopologyException extends RuntimeException { - #pt constructor(msg, pt) { super(pt ? msg + ' [ ' + pt + ' ]' : msg) - this.#pt = pt ? new Coordinate(pt) : undefined + this.pt = pt ? new Coordinate(pt) : undefined } getCoordinate() { - return this.#pt + return this.pt } } diff --git a/yarn.lock b/yarn.lock index 95d889b2e..7ae4eef4a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -303,7 +303,7 @@ "@babel/helper-remap-async-to-generator" "^7.10.1" "@babel/plugin-syntax-async-generators" "^7.8.0" -"@babel/plugin-proposal-class-properties@7.10.1", "@babel/plugin-proposal-class-properties@^7.10.1": +"@babel/plugin-proposal-class-properties@^7.10.1": version "7.10.1" resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-class-properties/-/plugin-proposal-class-properties-7.10.1.tgz#046bc7f6550bb08d9bd1d4f060f5f5a4f1087e01" integrity sha512-sqdGWgoXlnOdgMXU+9MbhzwFRgxVLeiGBqTrnuS7LC2IBU31wSsESbTUreT2O418obpfPdGUR2GbEufZF1bpqw==