Comparing version
@@ -0,1 +1,2 @@ | ||
import { console, stringify } from '../node_modules/as-console/assembly/wasi' | ||
import { StringSink } from 'as-string-sink' | ||
@@ -55,2 +56,4 @@ import { DynamicObject } from './DynamicObject' | ||
const unknownNull = unknown.wrap(null) | ||
const fwd_slash = "\\" | ||
const empty_stringCode = " ".charCodeAt(0) | ||
@@ -671,2 +674,3 @@ /** | ||
//console.log('Data ' + data) | ||
data = removeJSONWhitespace(data) | ||
const len: u32 = data.length - 1 | ||
@@ -689,3 +693,3 @@ let schema: T | ||
if (depth !== 0 && depth === fdepth) { | ||
//console.log(`Deep: ${prependType(data.slice(lastPos + 1, i + 1))}`) | ||
//console.log(`Deep: ${data.slice(lastPos + 1, i + 1)}`) | ||
result.set(key, data.slice(lastPos + 1, i + 1).trim()) | ||
@@ -700,3 +704,3 @@ // Reset the depth | ||
if (char === colonCode) { | ||
//console.log(`Key: ${prependType(data.slice(lastPos + 1, i - 1))}`) | ||
//console.log(`Key: ${data.slice(lastPos + 1, i - 1)}`) | ||
key = data.slice(lastPos + 1, i - 1).trim() | ||
@@ -706,3 +710,3 @@ lastPos = i | ||
else if (char === commaCode) { | ||
//console.log(`Value: ${prependType(data.slice(lastPos + 1, i))}`) | ||
//console.log(`Value: ${data.slice(lastPos + 1, i)}`) | ||
if ((i - lastPos) > 0) result.set(key, data.slice(lastPos + 1, i).trim()) | ||
@@ -713,5 +717,7 @@ lastPos = i + 1 | ||
} | ||
//console.log(`Trailing: ${prependType(data.slice(lastPos + 1, len))}\n\t\sValid: ${data.slice(lastPos + 1, len).length > 0}`) | ||
//console.log(`Trailing: ${data.slice(lastPos + 1, len)}\n\t\sValid: ${data.slice(lastPos + 1, len).length > 0}`) | ||
if ((len - lastPos) > 0) result.set(key, data.slice(lastPos + 1, len).trim()) | ||
console.log(result.keys()) | ||
console.log(result.values()) | ||
// @ts-ignore | ||
@@ -763,2 +769,20 @@ return schema.__decode(result) | ||
return o | ||
} | ||
export function removeJSONWhitespace(data: string): string { | ||
let result = new StringSink() | ||
let instr = false | ||
let char = 0 | ||
for (let i = 0; i < data.length; i++) { | ||
char = data.charCodeAt(i) | ||
if (char === quoteCode && data.charCodeAt(i - 1) === fwd_slashCode) { | ||
instr = !instr | ||
} | ||
if (instr === true) { | ||
result.writeCodePoint(char) | ||
} else if (instr === false && char !== empty_stringCode) { | ||
result.writeCodePoint(char) | ||
} | ||
} | ||
return result.toString() | ||
} |
@@ -5,3 +5,3 @@ import { unknown, unknownTypes } from './unknown' | ||
import { JSON, parseDynamicObject, parseUnknown, parseUnknownArray } from '.' | ||
import { JSON, parseDynamicObject, parseUnknown, parseUnknownArray, removeJSONWhitespace } from '.' | ||
@@ -191,4 +191,19 @@ import { DynamicObject } from './DynamicObject' | ||
//console.log(JSON.stringify(JSON.parse<unknown[]>('["Welcome to dynamic arrays",3.14,["Very",["Deep",["Array"]]],true,"It also supports nulls",null]'))) | ||
const foo = new Map() | ||
//const foo = new Map() | ||
//console.log(JSON.stringify(parseDynamicObject('{"hello":"world"}'))) | ||
//console.log(JSON.stringify(parseDynamicObject('{"hello":"world"}'))) | ||
// @ts-ignore | ||
@json | ||
class Test { | ||
stuff: string | ||
things: i32 | ||
} | ||
const test: Test = { | ||
stuff: "hi", | ||
things: 42 | ||
} | ||
console.log(stringify(JSON.stringify(test))) | ||
console.log(removeJSONWhitespace('{"stuff":"hi", "things":42}')) | ||
console.log(stringify(JSON.stringify(JSON.parse<Test>('{"stuff":"hi", "things":42}')))) |
{ | ||
"name": "json-as", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "JSON encoder/decoder for AssemblyScript", | ||
@@ -5,0 +5,0 @@ "types": "assembly/index.ts", |
@@ -98,2 +98,3 @@ import { TypeNode, ClassDeclaration, Expression, Token, IndexSignature, ElementAccessExpression, ClassExpression, ExpressionStatement, ArrayLiteralExpression, FieldDeclaration, Statement, BinaryExpression, VariableStatement, TypeParameterNode, TypeName, TypeDeclaration, Transform, ObjectLiteralExpression, FunctionDeclaration, Parser, Source, FunctionExpression, FunctionTypeNode } from "visitor-as/as"; | ||
if (!this.decodeCode.has(className)) this.decodeCode.set(className, []) | ||
// TODO: fix later | ||
// @ts-ignore | ||
@@ -100,0 +101,0 @@ this.encodeStmts.get(className).push( |
74083
1.51%1879
2.01%