Skip to content

Commit

Permalink
fix: re-add as-bs dependency so that it will not break in non-local e…
Browse files Browse the repository at this point in the history
…nvironments
  • Loading branch information
JairusSW committed Jan 21, 2025
1 parent e043d95 commit 96484ea
Show file tree
Hide file tree
Showing 18 changed files with 27 additions and 220 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## 2025-01-20 - 1.0.0-alpha.2

- fix: disable SIMD in generated transform code by default
- fix: re-add as-bs dependency so that it will not break in non-local environments

## 2025-01-20 - 1.0.0-alpha.1

Expand Down
2 changes: 1 addition & 1 deletion assembly/__benches__/misc.bench.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { bench } from "as-bench/assembly/bench";
import { bs } from "../../modules/bs";
import { bs } from "as-bs";
import { deserializeString_SIMD } from "../deserialize/simd/string";
import { deserializeString } from "../deserialize/simple/string";
import { bytes } from "../util/bytes";
Expand Down
11 changes: 3 additions & 8 deletions assembly/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// <reference path="./index.d.ts" />
import { bs } from "../modules/bs";
import { bs } from "as-bs";

import { serializeString } from "./serialize/simple/string";
import { serializeArray } from "./serialize/simple/array";
Expand All @@ -23,7 +23,6 @@ import { serializeFloat } from "./serialize/simple/float";
import { serializeObject } from "./serialize/simple/object";
import { ptrToStr } from "./util/ptrToStr";
import { bytes } from "./util";
import { serializeString_SIMD } from "./serialize/simd/string";

export type Raw = string;

Expand Down Expand Up @@ -340,7 +339,7 @@ export namespace JSON {
* Box for primitive types
*/
export class Box<T> {
constructor(public value: T) {}
constructor(public value: T) { }
/**
* Creates a reference to a primitive type
* This means that it can create a nullable primitive
Expand Down Expand Up @@ -375,11 +374,7 @@ export namespace JSON {
store<u64>(bs.offset, 30399761348886638);
bs.offset += 8;
} else if (isString<nonnull<T>>()) {
if (ASC_FEATURE_SIMD) {
serializeString_SIMD(src as string);
} else {
serializeString(src as string);
}
serializeString(src as string);
// @ts-ignore: Supplied by transform
} else if (isDefined(src.__SERIALIZE)) {
// @ts-ignore
Expand Down
2 changes: 1 addition & 1 deletion assembly/serialize/simd/string.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bs } from "../../../modules/bs";
import { bs } from "as-bs";
import { BACK_SLASH } from "../../custom/chars";
import { SERIALIZE_ESCAPE_TABLE } from "../../globals/tables";
import { OBJECT, TOTAL_OVERHEAD } from "rt/common";
Expand Down
2 changes: 1 addition & 1 deletion assembly/serialize/simple/array.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bs } from "../../../modules/bs";
import { bs } from "as-bs";
import { COMMA, BRACKET_RIGHT, BRACKET_LEFT } from "../../custom/chars";
import { JSON } from "../..";

Expand Down
2 changes: 1 addition & 1 deletion assembly/serialize/simple/bool.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bs } from "../../../modules/bs";
import { bs } from "as-bs";

/**
* Serialize a bool to type string
Expand Down
2 changes: 1 addition & 1 deletion assembly/serialize/simple/date.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bs } from "../../../modules/bs";
import { bs } from "as-bs";
import { QUOTE } from "../../custom/chars";
import { bytes } from "../../util/bytes";

Expand Down
2 changes: 1 addition & 1 deletion assembly/serialize/simple/float.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { dtoa_buffered } from "util/number";
import { bs } from "../../../modules/bs";
import { bs } from "as-bs";

export function serializeFloat<T extends number>(data: T): void {
bs.ensureSize(64);
Expand Down
2 changes: 1 addition & 1 deletion assembly/serialize/simple/integer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { itoa_buffered } from "util/number";
import { bs } from "../../../modules/bs";
import { bs } from "as-bs";

export function serializeInteger<T extends number>(data: T): void {
bs.ensureSize(sizeof<T>() << 3);
Expand Down
2 changes: 1 addition & 1 deletion assembly/serialize/simple/map.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { JSON } from "../..";
import { BRACE_LEFT, BRACE_RIGHT, COLON, COMMA } from "../../custom/chars";
import { bs } from "../../../modules/bs";
import { bs } from "as-bs";

export function serializeMap<T extends Map<any, any>>(src: T): void {
const srcSize = src.size;
Expand Down
2 changes: 1 addition & 1 deletion assembly/serialize/simple/string.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { _intTo16 } from "../../custom/util";
import { bytes } from "../../util/bytes";
import { bs } from "../../../modules/bs";
import { bs } from "as-bs";
import { BACK_SLASH, QUOTE } from "../../custom/chars";
import { SERIALIZE_ESCAPE_TABLE } from "../../globals/tables";

Expand Down
4 changes: 2 additions & 2 deletions assembly/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ class Vec3 {

@json
class Player {
// @alias("first name")
@alias("first name")
firstName!: string;
lastName!: string;
lastActive!: i32[];
// Drop in a code block, function, or expression that evaluates to a boolean
@omitif((self: Player): boolean => self.age < 18)
age!: i32;
// @omitnull()
@omitnull()
pos!: Vec3 | null;
isVerified!: boolean;
@inline __INITIALIZE(): this {
Expand Down
167 changes: 0 additions & 167 deletions modules/bs/index.ts

This file was deleted.

8 changes: 0 additions & 8 deletions modules/tsconfig.json

This file was deleted.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"scripts": {
"test": "rm -rf ./build/ && ast test",
"build:bench": "rm -rf ./build/ && asc assembly/__benches__/misc.bench.ts -o ./build/bench.wasm --textFile ./build/bench.wat --transform ./transform --optimizeLevel 3 --shrinkLevel 0 --converge --noAssert --uncheckedBehavior always --runtime incremental --enable simd --enable bulk-memory",
"build:test": "rm -rf ./build/ && JSON_DEBUG=true asc assembly/test.ts --transform ./transform -o ./build/test.wasm --textFile ./build/test.wat --optimizeLevel 3 --shrinkLevel 0 --enable simd --runtime stub",
"build:test": "rm -rf ./build/ && JSON_DEBUG=true asc assembly/test.ts --transform ./transform -o ./build/test.wasm --textFile ./build/test.wat --optimizeLevel 3 --shrinkLevel 0 --runtime stub",
"build:test:simd": "rm -rf ./build/ && JSON_DEBUG=true asc assembly/test.ts --transform ./transform -o ./build/test.wasm --textFile ./build/test.wat --optimizeLevel 3 --shrinkLevel 0 --enable simd --runtime stub",
"test:wasmtime": "wasmtime ./build/test.wasm",
"test:wasmer": "wasmer ./build/test.wasm",
Expand All @@ -67,5 +67,8 @@
"prettier": "prettier -w ."
},
"type": "module",
"types": "assembly/index.ts"
"types": "assembly/index.ts",
"dependencies": {
"as-bs": "^1.0.1"
}
}
12 changes: 3 additions & 9 deletions transform/lib/index.js

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

2 changes: 1 addition & 1 deletion transform/lib/index.js.map

Large diffs are not rendered by default.

17 changes: 3 additions & 14 deletions transform/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,20 +405,9 @@ class JSONTransform extends Visitor {
// }
// }
if (!this.imports.find((i) => i.declarations.find((d) => d.foreignName.text == "bs"))) {
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

let relativePath = path.relative(path.dirname(node.range.source.normalizedPath), path.resolve(__dirname, "../../modules/bs/index.ts"));

if (!relativePath.startsWith(".") && !relativePath.startsWith("/")) relativePath = "./" + relativePath;
// if (!existsSync(relativePath)) {
// throw new Error("Could not find a valid json-as library to import from! Please add import { JSON } from \"path-to-json-as\"; in " + node.range.source.normalizedPath + "!");
// }

const txt = `import { bs } from "${relativePath}";`;
if (!this.jsonImport) {
this.jsonImport = txt;
if (process.env["JSON_DEBUG"]) console.log("Added bs import: " + txt + "\n");
if (!this.bsImport) {
this.bsImport = "import { bs } from \"as-bs\"";
if (process.env["JSON_DEBUG"]) console.log("Added as-bs import: " + this.bsImport + "\n");
}
}

Expand Down

0 comments on commit 96484ea

Please sign in to comment.