Cysharp / Cysharp/MemoryPack

Generate tree-shakeable Typescript code

Open
#355 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
4.7k
Forks
313
PR merge metrics
No merged PRs in 30d

Description

Quick refresher on tree-shaking:

export const foo = () => ...
export const bar = () => ...

when referenced with

import { foo } from 'blah';

foo();

will generate

const foo = () => ...
foo();

while

export class Blah {
    function foo() { ... }
    function bar() { ... }
}

when referenced with

import { Blah } from 'blah';

Blah.foo();

will generate

class Blah {
    function foo() { ... }
    function bar() { ... }
}
Blah.foo();

Currently, MemoryPack generates the latter. Meaning, if I only need the serialize() function, the entire class gets bundled anyway. Lots of code that I have no use for.

Additionally, classes get bundled pretty much as-is, while interfaces could be stripped away at bundle time.

For maximum tree-shaking compatibility and minimum bundle sizes, MemoryPack should be generating interfaces and loose functions, for example

export interface Person {
    name: string;
    surname: string;
    shoeSize: number;
    birthday: Date;
}

export function serialize(value: Person | null): Uint8Array {
    // snip...
}

export function deserialize(buffer: ArrayBuffer): Person | null {
    // snip...
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files, tests, or generator entry point; begin by locating the code that emits the current TypeScript classes and comparing its output with the examples. Done means generated output uses interfaces and separately exported serialize/deserialize functions, with unused code removable by tree-shaking; add or run the relevant generator checks once their location is identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, typescript
Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.