Skip to content

Commit

Permalink
Merge branch 'sunjw:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyN9ne committed Jun 19, 2024
2 parents c3ab906 + 54a235f commit c8adf51
Show file tree
Hide file tree
Showing 36 changed files with 354 additions and 79 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
1.2312.0
[Common] Fix regular expression format.
[Common] Change "ROOT" to "$" in JSON viewer.

1.2311.0
[Common] Fix "#" private class members format.

1.2308.0
[NPP] Add ARM64 support.

Expand Down
7 changes: 7 additions & 0 deletions sub-proj/JSToolJS/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
1.2312.0
[Common] Fix regular expression format.
[Common] Change "ROOT" to "$" in JSON viewer.

1.2311.0
[Common] Fix "#" private class members format.

1.2308.0
[NPP] Add ARM64 support.

Expand Down
2 changes: 1 addition & 1 deletion sub-proj/JSToolJS/jsonpptreeview.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class JsonTreeProvider {
* A implementation of TreeDataProvider
*/
constructor(rootJsonValue) {
this.rootNode = new JsonTreeNode("ROOT", rootJsonValue, 0);
this.rootNode = new JsonTreeNode("$", rootJsonValue, 0);
}

isRootNode(element) {
Expand Down
7 changes: 4 additions & 3 deletions sub-proj/JSToolJS/jsparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

'use strict';

const VERSION = "1.2308.0.0";
const VERSION = "1.2312.0.0";

function StringReplaceAll(string, target, replace) {
return string.replace(new RegExp(target, 'g'), replace);
Expand Down Expand Up @@ -146,7 +146,7 @@ class JSParser {
// single operator
return (ch == '.' || ch == '(' || ch == ')' ||
ch == '[' || ch == ']' || ch == '{' || ch == '}' ||
ch == ',' || ch == ';' || ch == '~' ||
ch == ',' || ch == ';' || ch == '~' || ch == '#' ||
ch == '\n');
}

Expand Down Expand Up @@ -558,7 +558,8 @@ class JSParser {
if (tokenBFirst == '/' && this.m_tokenB.type != COMMENT_TYPE_1 &&
this.m_tokenB.type != COMMENT_TYPE_2 &&
((this.m_tokenA.type != STRING_TYPE && this.m_strBeforeReg.indexOf(tokenALast) != -1) ||
(this.m_tokenA.code == "return" || this.m_tokenA.code == "throw"))) {
(this.m_tokenA.code == "return" || this.m_tokenA.code == "throw" ||
this.m_tokenA.code == "in" || this.m_tokenA.code == "of"))) {
this.m_bRegular = true;
this.GetTokenRaw(); // put regular into m_tokenB
}
Expand Down
4 changes: 2 additions & 2 deletions sub-proj/JSToolJS/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sub-proj/JSToolJS/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "jstool",
"displayName": "JSTool",
"description": "JS (JSON) Tool for VSC",
"version": "1.2308.0",
"version": "1.2312.0",
"publisher": "sunjw",
"license": "GPL-2.0",
"engines": {
Expand Down
13 changes: 9 additions & 4 deletions sub-proj/JSToolJS/realjsformatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,12 @@ class RealJSFormatter extends JSParser.JSParser {
//PutToken(m_tokenA);
switch (this.m_tokenA.type) {
case JSParser.REGULAR_TYPE:
this.PutToken(this.m_tokenA); // directly output regular without any format
if (this.m_tokenPreA.type == JSParser.STRING_TYPE &&
!this.m_bracketKeywordSet.includes(this.m_tokenPreA.code)) {
this.PutToken(this.m_tokenA, " ");
} else {
this.PutToken(this.m_tokenA); // directly output regular without any format
}
break;
case JSParser.COMMENT_TYPE_1:
case JSParser.COMMENT_TYPE_2:
Expand Down Expand Up @@ -353,7 +358,8 @@ class RealJSFormatter extends JSParser.JSParser {
if (this.m_tokenA.code == "(" || this.m_tokenA.code == ")" ||
this.m_tokenA.code == "[" || this.m_tokenA.code == "]" ||
this.m_tokenA.code == "!" || this.m_tokenA.code == "!!" ||
this.m_tokenA.code == "~" || this.m_tokenA.code == ".") {
this.m_tokenA.code == "~" || this.m_tokenA.code == "." ||
this.m_tokenA.code == "#") {
// ()[]!. with no format
if ((this.m_tokenA.code == ")" || this.m_tokenA.code == "]") &&
(topStack == JSParser.JS_ASSIGN || topStack == JSParser.JS_HELPER)) {
Expand Down Expand Up @@ -795,7 +801,7 @@ class RealJSFormatter extends JSParser.JSParser {
if (this.m_tokenB.type == JSParser.STRING_TYPE ||
this.m_tokenB.type == JSParser.COMMENT_TYPE_1 ||
this.m_tokenB.type == JSParser.COMMENT_TYPE_2 ||
this.m_tokenB.code == "{" ||
this.m_tokenB.code == "{" || this.m_tokenB.code == "#" ||
(this.m_declareKeywordSet.includes(this.m_tokenA.code) && this.m_tokenB.code == "[")) {
if (this.m_tokenA.type == JSParser.STRING_TYPE &&
this.m_tokenA.code.endsWith("${")) {
Expand Down Expand Up @@ -831,7 +837,6 @@ class RealJSFormatter extends JSParser.JSParser {
// indent after read ()
this.m_brcNeedStack.push(false);
this.m_blockStack.push(this.m_blockMap[this.m_tokenA.code]);

}

if (!bTokenAPropName && this.m_tokenA.code == "switch") {
Expand Down
2 changes: 1 addition & 1 deletion sub-proj/JSToolSite/inc/version.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[JSMinNpp]
name=JSToolNpp.zip
version=1.2308.0
version=1.2312.0
url=download.php
3 changes: 2 additions & 1 deletion sub-proj/JSToolSite/npp/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@
<p>&nbsp;</p>
<p>What's New in <a class="smoothAnchor" href="#download"><?php echo $cur_version; ?></a>:</p>
<ul class="indentList discList">
<li>Add ARM64 support.</li>
<li>Fix regular expression format.</li>
<li>Change "ROOT" to "$" in JSON viewer.</li>
</ul>
<p>&nbsp;</p>
<p><a href='https://ko-fi.com/Y8Y72L3FZ' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://cdn.ko-fi.com/cdn/kofi4.png?v=2' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a></p>
Expand Down
3 changes: 2 additions & 1 deletion sub-proj/JSToolSite/vsc/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
<p>&nbsp;</p>
<p>What's New in <a href="https://marketplace.visualstudio.com/items?itemName=sunjw.jstool" target="_blank"><?php echo $cur_version; ?></a>:</p>
<ul class="indentList discList">
<li>Some tweaks.</li>
<li>Fix regular expression format.</li>
<li>Change "ROOT" to "$" in JSON viewer.</li>
</ul>
<p>&nbsp;</p>
<p><a href='https://ko-fi.com/Y8Y72L3FZ' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://cdn.ko-fi.com/cdn/kofi4.png?v=2' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a></p>
Expand Down
106 changes: 106 additions & 0 deletions sub-proj/Test/jsformat/privateclass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
class ClassWithPrivateField {
#privateField;

constructor() {
this.#privateField = 42;
}
}

class Subclass extends ClassWithPrivateField {
#subPrivateField;

constructor() {
super();
this.#subPrivateField = 23;
}
}

new Subclass(); // In some dev tools, it shows Subclass {#privateField: 42, #subPrivateField: 23}


class ClassWithPrivateField {
#privateField;

constructor() {
delete this.#privateField; // Syntax error
this.#undeclaredField = 42; // Syntax error
}
}

const instance = new ClassWithPrivateField();
instance.#privateField; // Syntax error

class C {
#x;
constructor(x) {
this.#x = x;
}
static getX(obj) {
if (#x in obj) return obj.#x;

return "obj must be an instance of C";
}
}
console.log(C.getX(new C("foo"))); // "foo"
console.log(C.getX(new C(0.196))); // 0.196
console.log(C.getX(new C(new Date()))); // the current date and time
console.log(C.getX({})); // "obj must be an instance of C"

class Stamper extends class {
// A base class whose constructor returns the object it's given
constructor(obj) {
return obj;
}
} {
// This declaration will "stamp" the private field onto the object
// returned by the base class constructor
#stamp = 42;
static getStamp(obj) {
return obj.#stamp;
}
}

const obj = {};
new Stamper(obj);
// `Stamper` calls `Base`, which returns `obj`, so `obj` is
// now the `this` value. `Stamper` then defines `#stamp` on `obj`

console.log(obj); // In some dev tools, it shows {#stamp: 42}
console.log(Stamper.getStamp(obj)); // 42
console.log(obj instanceof Stamper); // false

// You cannot stamp private properties twice
new Stamper(obj); // Error: Initializing an object twice is an error with private fields

class ClassWithPrivateAccessor {
#message;

get #decoratedMessage() {
return `🎬${this.#message}🛑`;
}
set #decoratedMessage(msg) {
this.#message = msg;
}

constructor() {
this.#decoratedMessage = "hello world";
console.log(this.#decoratedMessage);
}
}

new ClassWithPrivateAccessor(); // 🎬hello world🛑

class ClassWithPrivateStaticMethod {
static #isInternalConstructing = false;
static #privateStaticMethod() {
return 42;
}

static publicStaticMethod() {
return this.#privateStaticMethod();
}
}

class Subclass extends ClassWithPrivateStaticMethod {}

console.log(Subclass.publicStaticMethod()); // TypeError: Cannot read private member #privateStaticMethod from an object whose class did not declare it
107 changes: 107 additions & 0 deletions sub-proj/Test/jsformat/privateclass.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
class ClassWithPrivateField {
#privateField;

constructor() {
this.#privateField = 42;
}
}

class Subclass extends ClassWithPrivateField {
#subPrivateField;

constructor() {
super();
this.#subPrivateField = 23;
}
}

new Subclass(); // In some dev tools, it shows Subclass {#privateField: 42, #subPrivateField: 23}


class ClassWithPrivateField {
#privateField;

constructor() {
delete this.#privateField; // Syntax error
this.#undeclaredField = 42; // Syntax error
}
}

const instance = new ClassWithPrivateField();
instance.#privateField; // Syntax error

class C {
#x;
constructor(x) {
this.#x = x;
}
static getX(obj) {
if (#x in obj)
return obj.#x;

return "obj must be an instance of C";
}
}
console.log(C.getX(new C("foo"))); // "foo"
console.log(C.getX(new C(0.196))); // 0.196
console.log(C.getX(new C(new Date()))); // the current date and time
console.log(C.getX({})); // "obj must be an instance of C"

class Stamper extends class {
// A base class whose constructor returns the object it's given
constructor(obj) {
return obj;
}
} {
// This declaration will "stamp" the private field onto the object
// returned by the base class constructor
#stamp = 42;
static getStamp(obj) {
return obj.#stamp;
}
}

const obj = {};
new Stamper(obj);
// `Stamper` calls `Base`, which returns `obj`, so `obj` is
// now the `this` value. `Stamper` then defines `#stamp` on `obj`

console.log(obj); // In some dev tools, it shows {#stamp: 42}
console.log(Stamper.getStamp(obj)); // 42
console.log(obj instanceof Stamper); // false

// You cannot stamp private properties twice
new Stamper(obj); // Error: Initializing an object twice is an error with private fields

class ClassWithPrivateAccessor {
#message;

get #decoratedMessage() {
return `🎬${this.#message}🛑`;
}
set #decoratedMessage(msg) {
this.#message = msg;
}

constructor() {
this.#decoratedMessage = "hello world";
console.log(this.#decoratedMessage);
}
}

new ClassWithPrivateAccessor(); // 🎬hello world🛑

class ClassWithPrivateStaticMethod {
static #isInternalConstructing = false;
static #privateStaticMethod() {
return 42;
}

static publicStaticMethod() {
return this.#privateStaticMethod();
}
}

class Subclass extends ClassWithPrivateStaticMethod {}

console.log(Subclass.publicStaticMethod()); // TypeError: Cannot read private member #privateStaticMethod from an object whose class did not declare it
2 changes: 2 additions & 0 deletions sub-proj/Test/jsformat/reg6.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c8adf51

Please sign in to comment.