🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

json-as

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-as - npm Package Compare versions

Comparing version

to
0.5.12

@@ -13,3 +13,6 @@ {

"options": {
"transform": ["./transform"],
"transform": [
"./transform",
"./transform"
],
"bindings": "esm",

@@ -16,0 +19,0 @@ "exportStart": "_start"

@@ -1,5 +0,2 @@

bench("1+1", () => {
blackbox("1+1".split("+w"))
})
/*import { JSON } from "..";
import { JSON } from "..";

@@ -37,4 +34,3 @@ @json

blackbox([
["a", "b", "c"],
["d", "e", "f"],
["a", "b", "c"]
])

@@ -46,3 +42,3 @@ )

bench("Parse Nested Array", () => {
blackbox(JSON.parse<string[][]>(blackbox('[["a","b","c"],["d","e","f"]]')));
blackbox(JSON.parse<string[][]>(blackbox('[["a","b","c"]]')));
});

@@ -57,3 +53,3 @@

});
/*
bench("Stringify Boolean", () => {

@@ -81,3 +77,2 @@ blackbox(JSON.stringify(blackbox(true)));

blackbox(JSON.parse<f32>(blackbox("3.14")));
});
*/
});*/

@@ -34,3 +34,3 @@ import { JSON } from "..";

});
/*
describe("Ser/de Numbers", () => {

@@ -45,6 +45,6 @@ it("should ser/de integers", () => {

canSerde<u128>(u128.from("0"))
canSerde<u128>(u128.from("100"))
canSerde<u128>(u128.from("101"))
`
// canSerde<u128>(u128.from("0"))
// canSerde<u128>(u128.from("100"))
// canSerde<u128>(u128.from("101"))
canSerde<u128Safe>(u128Safe.from("0"))

@@ -204,2 +204,2 @@ canSerde<u128Safe>(u128Safe.from("100"))

});
});*/
});
import { StringSink } from "as-string-sink/assembly";
import { isSpace } from "assemblyscript/std/assembly/util/string";
import { isSpace } from "util/string";
import { backSlashCode, quoteCode } from "./chars";

@@ -59,4 +59,4 @@ import { u128, u128Safe, u256, u256Safe, i128, i128Safe, i256Safe } from "as-bignum/assembly";

case 0x0B: return "\\u000b";
default: return char;
default: return char;
}
}

@@ -8,30 +8,24 @@ import { u128 } from "as-bignum/assembly";

@json
class Stats {
wins!: u128
loss!: u128
class Vec3 {
x: f32 = 3.4;
y: f32 = 1.2;
z: f32 = 8.3;
}
// @ts-ignore
@json
class Vec3 {
x!: f32;
y!: f32;
z!: f32;
class Stats extends Vec3 {
wins: u128
loss: u128
}
const vec: Vec3 = {
x: 3.4,
y: 1.2,
z: 8.3
}
// @ts-ignore
@json
class Player {
firstName!: string;
lastName!: string;
lastActive!: i32[];
age!: i32;
pos!: Vec3 | null;
isVerified!: boolean;
stats!: Stats
firstName: string;
lastName: string;
lastActive: i32[];
age: i32;
isVerified: boolean;
stats: Stats
}

@@ -42,9 +36,8 @@

lastName: "West",
lastActive: [8, 27, 2022],
lastActive: [
8,
27,
2022
],
age: 23,
pos: {
x: 3.4,
y: 1.2,
z: 8.3
},
isVerified: true,

@@ -60,2 +53,24 @@ stats: {

const deserializedPlayer = JSON.parse<Player>(serializedPlayer);
console.log("Deserialized Player: " + JSON.stringify(deserializedPlayer));
console.log("Deserialized Player: " + JSON.stringify(deserializedPlayer));/*
@json
class Vec2 {
x: f32;
y: f32;
}
const vec: Vec2 = {
x: 0.0,
y: 0.0,
}
let i = 5_000_000;
while (i--) {
JSON.stringify<Vec2>(vec);
}
let start = Date.now();
i = 10_000_000;
while (i--) {
JSON.stringify<Vec2>(vec);
}
console.log(`Took: ${Date.now() - start}ms`)*/
{
"name": "json-as",
"version": "0.5.11",
"version": "0.5.12",
"description": "JSON encoder/decoder for AssemblyScript",

@@ -16,3 +16,3 @@ "types": "assembly/index.ts",

"bench:astral": "astral",
"build:test": "asc assembly/test.ts --target test",
"build:test": "asc assembly/test.ts --target test --runtime stub",
"build:transform": "tsc -p ./transform",

@@ -19,0 +19,0 @@ "test:wasmtime": "wasmtime ./build/test.wasm",

{
"name": "@json-as/transform",
"version": "0.5.11",
"version": "0.5.12",
"description": "JSON encoder/decoder for AssemblyScript",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

@@ -12,2 +12,3 @@ import {

import { SimpleParser } from "visitor-as/dist/index.js";
import { NodeKind } from "types:assemblyscript/src/ast";

@@ -31,2 +32,3 @@ class SchemaData {

visitFieldDeclaration(node: FieldDeclaration): void {
if (toString(node).startsWith("static")) return;
const lineText = toString(node);

@@ -69,2 +71,7 @@ if (lineText.startsWith("private")) return;

// Prevent from being triggered twice
for (const member of node.members) {
if (member.name.text == "__JSON_Serialize") return;
}
this.currentClass = {

@@ -87,3 +94,3 @@ name: toString(node.name),

});
if (parentSchema.length > 0) {
if (parentSchema.length > 0 && parentSchema[0]?.encodeStmts) {
parentSchema[0]?.encodeStmts.push(parentSchema[0]?.encodeStmts.pop() + ",")

@@ -90,0 +97,0 @@ this.currentClass.encodeStmts.push(...parentSchema[0]?.encodeStmts)