Skip to content

Commit

Permalink
bump: v0.8.6
Browse files Browse the repository at this point in the history
  • Loading branch information
JairusSW committed Jun 13, 2024
1 parent 246d21e commit b14344e
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 174 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
v0.8.2 - Properties starting with `static` or `private` would be ignored
v0.8.3 - Dirty fix to issue #68. Add __JSON_Stringify callable to global scope.
v0.8.4 - Fix #71. Classes with the extending class overriding a property cause the property to be serialized twice.
v0.8.4 - Fix #71. Classes with the extending class overriding a property cause the property to be serialized twice.
v0.8.5 - Fix #73. Support for nullable primatives with Box<T> from as-container
v0.8.6 - Fix. Forgot to stash before publishing. Stash and push what should have been v0.8.5
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
██║ ██║███████║ ╚█████╔╝███████║╚██████╔╝██║ ╚████║
╚═╝ ╚═╝╚══════╝ ╚════╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═══╝

v0.8.5
v0.8.6
</pre>
</h3>

Expand Down
2 changes: 2 additions & 0 deletions assembly/__tests__/as-json.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class Vec3 {
x: f64;
y: f64;
z: f64;

static shouldIgnore: string = "should not be serialized";
}

@json
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "json-as",
"version": "0.8.5",
"version": "0.8.6",
"description": "JSON encoder/decoder for AssemblyScript",
"types": "assembly/index.ts",
"author": "Jairus Tanaka",
Expand Down
124 changes: 52 additions & 72 deletions transform/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class AsJSONTransform extends BaseVisitor {
}
visitMethodDeclaration() { }
visitClassDeclaration(node) {
var _c, _d, _e, _f, _g, _h, _j, _k, _l;
var _c, _d;
const className = node.name.text;
if (!((_c = node.decorators) === null || _c === void 0 ? void 0 : _c.length))
return;
Expand Down Expand Up @@ -80,96 +80,76 @@ class AsJSONTransform extends BaseVisitor {
const member = mem;
const lineText = toString(member);
//console.log("Member: " + lineText)
if (lineText.startsWith("private ") && lineText.startsWith("static "))
continue;
const omitnull = (_d = member.decorators) === null || _d === void 0 ? void 0 : _d.find(v => v.name.text == "omitnull");
console.log((_e = member.decorators) === null || _e === void 0 ? void 0 : _e.find(v => v.name.text === "omitif"));
const omitif = (_k = (_j = (_h = (_g = (_f = member.decorators) === null || _f === void 0 ? void 0 : _f.find(v => v.name.text === "omitif")) === null || _g === void 0 ? void 0 : _g.args) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.value) !== null && _k !== void 0 ? _k : null;
// @ts-ignore
let type = toString(member.type);
const name = member.name.text;
let aliasName = name;
// @ts-ignore
if (member.decorators && ((_l = member.decorators[0]) === null || _l === void 0 ? void 0 : _l.name.text) === "alias") {
if (member.decorators[0] && member.decorators[0].args[0]) {
// @ts-ignore
aliasName = member.decorators[0].args[0].value;
}
}
this.currentClass.keys.push(name);
// @ts-ignore
this.currentClass.types.push(type);
// @ts-ignore
if ([
"u8",
"i8",
"u16",
"i16",
"u32",
"i32",
"u64",
"i64",
].includes(type.toLowerCase())) {
if (omitif) {
this.currentClass.encodeStmts.push(`\${${omitif} ? "" : \`,${encodeKey(aliasName)}:\${this.${name}}\`}`);
}
else {
this.currentClass.encodeStmts.push(`,${encodeKey(aliasName)}:\${this.${name}}`);
if (!lineText.startsWith("private ") && !lineText.startsWith("static ")) {
// @ts-ignore
let type = toString(member.type);
const name = member.name.text;
let aliasName = name;
// @ts-ignore
if (member.decorators && ((_d = member.decorators[0]) === null || _d === void 0 ? void 0 : _d.name.text) === "alias") {
if (member.decorators[0] && member.decorators[0].args[0]) {
// @ts-ignore
aliasName = member.decorators[0].args[0].value;
}
}
this.currentClass.keys.push(name);
// @ts-ignore
this.currentClass.types.push(type);
// @ts-ignore
this.currentClass.setDataStmts.push(`if (key.equals(${JSON.stringify(aliasName)})) {
if ([
"u8",
"i8",
"u16",
"i16",
"u32",
"i32",
"u64",
"i64",
].includes(type.toLowerCase())) {
this.currentClass.encodeStmts.push(`${encodeKey(aliasName)}:\${this.${name}},`);
// @ts-ignore
this.currentClass.setDataStmts.push(`if (key.equals(${JSON.stringify(aliasName)})) {
this.${name} = __atoi_fast<${type}>(data, val_start << 1, val_end << 1);
return;
}`);
if (member.initializer) {
this.currentClass.initializeStmts.push(`this.${name} = ${toString(member.initializer)}`);
if (member.initializer) {
this.currentClass.initializeStmts.push(`this.${name} = ${toString(member.initializer)}`);
}
}
}
else if ([
"f32",
"f64",
].includes(type.toLowerCase())) {
if (omitif) {
this.currentClass.encodeStmts.push(`\${${omitif} ? "" : \`,${encodeKey(aliasName)}:\${this.${name}}\`}`);
}
else {
this.currentClass.encodeStmts.push(`,${encodeKey(aliasName)}:\${this.${name}}`);
}
// @ts-ignore
this.currentClass.setDataStmts.push(`if (key.equals(${JSON.stringify(aliasName)})) {
else // @ts-ignore
if ([
"f32",
"f64",
].includes(type.toLowerCase())) {
this.currentClass.encodeStmts.push(`${encodeKey(aliasName)}:\${this.${name}},`);
// @ts-ignore
this.currentClass.setDataStmts.push(`if (key.equals(${JSON.stringify(aliasName)})) {
this.${name} = __parseObjectValue<${type}>(data.slice(val_start, val_end), initializeDefaultValues);
return;
}`);
if (member.initializer) {
this.currentClass.initializeStmts.push(`this.${name} = ${toString(member.initializer)}`);
}
}
else {
if (omitnull) {
this.currentClass.encodeStmts.push(`c\${changetype<usize>(this.${name}) !== <usize>0 ? "" : \`${encodeKey(aliasName)}:\${__JSON_Stringify<${type}>(this.${name})}\`}`);
console.log(`\${changetype<usize>(this.${name}) != <usize>0 ? \`${encodeKey(aliasName)}:,\${__JSON_Stringify<${type}>(this.${name})}\` : ""}`);
}
else if (omitif) {
this.currentClass.encodeStmts.push(`\${${omitif} ? "" : \`${encodeKey(aliasName)}:,\${__JSON_Stringify<${type}>(this.${name})}\`}`);
if (member.initializer) {
this.currentClass.initializeStmts.push(`this.${name} = ${toString(member.initializer)}`);
}
}
else {
this.currentClass.encodeStmts.push(`,${encodeKey(aliasName)}:\${__JSON_Stringify<${type}>(this.${name})}`);
}
// @ts-ignore
this.currentClass.setDataStmts.push(`if (key.equals(${JSON.stringify(aliasName)})) {
this.currentClass.encodeStmts.push(`${encodeKey(aliasName)}:\${__JSON_Stringify<${type}>(this.${name})},`);
// @ts-ignore
this.currentClass.setDataStmts.push(`if (key.equals(${JSON.stringify(aliasName)})) {
this.${name} = __parseObjectValue<${type}>(val_start ? data.slice(val_start, val_end) : data, initializeDefaultValues);
return;
}`);
if (member.initializer) {
this.currentClass.initializeStmts.push(`this.${name} = ${toString(member.initializer)}`);
if (member.initializer) {
this.currentClass.initializeStmts.push(`this.${name} = ${toString(member.initializer)}`);
}
}
}
}
}
let serializeFunc = "";
if (this.currentClass.encodeStmts.length > 0) {
const stmt = this.currentClass.encodeStmts[0];
this.currentClass.encodeStmts[0] = stmt.slice(1);
const stmt = this.currentClass.encodeStmts[this.currentClass.encodeStmts.length - 1];
this.currentClass.encodeStmts[this.currentClass.encodeStmts.length - 1] =
stmt.slice(0, stmt.length - 1);
serializeFunc = `
__JSON_Serialize(): string {
return \`{${this.currentClass.encodeStmts.join("")}}\`;
Expand Down Expand Up @@ -208,7 +188,7 @@ class AsJSONTransform extends BaseVisitor {
this.schemasList.push(this.currentClass);
this.sources.add(node.name.range.source);
// Uncomment to see the generated code for debugging.
console.log(serializeFunc);
//console.log(serializeFunc);
//console.log(setKeyFunc);
//console.log(initializeFunc);
}
Expand Down
2 changes: 1 addition & 1 deletion transform/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@json-as/transform",
"version": "0.8.5",
"version": "0.8.6",
"description": "JSON encoder/decoder for AssemblyScript",
"main": "./lib/index.js",
"author": "Jairus Tanaka",
Expand Down
Loading

0 comments on commit b14344e

Please sign in to comment.