Files
bun.sh/src/codegen/class-definitions.ts
Zack Radisic 6ba4e950cc Add Bun.Glob (#6861)
* initial glob impl

* Add `Bun.globMatch`

* Glob boilerplate setup

* Experiment with Rust glob implementation

* Rust impl is slow revert

* Setup glob walking

* Basic glob walker working

* Fix segfault

* Recursive directory traversal

* Fix glob match non-ascii

* Make faster lil bit

* use arena

* ASCII fast path

* Experiment with packed codepoint cursor

Results in ~4% perf boost if the glob pattern needs to create/manipulate cursors (for example when the pattern uses braces)

* Try converting to u32 array

Made it pretty slow

* Lazily create codepoint buffer

* Different walk algorithm

* Fast path optimizations

* Add `dot` option to `Glob`

* .

* Fix some bugs

* Fix bug, clean up lil bit

* Windows fix

* Non absolute paths

* use specific version of fast-glob for benchmarks and tests

* .

* Fix some stuff

* Fix more stuff

* Add `hasPendingActivity()` to glob

* accident

* Symlinks

* fast-glob e2e tests

* remove

* woops

* Fix relative paths

* Fix absolute

* add test for `onlyFiles`

* Fix invalid surrogate pairs problem

* Rename: `match/matchSync` -> `scan/scanSync` and `matchString` -> `match`

* forgot to close cwd fd

* Update types

* Add stress test

* Port `micromatch` / `glob-match` / `globlin` tests

* fix stale reference arena thing

* stupid bug

* Add builtins to classes code generator and add `Glob.scanIter()`

* all iterables

* generate fixtures, remove from git

* fix test

* Fix

* woops on test

* Fix stuff

licenses

license

`has_pending_activity` to usize

cwd threadSafe fix atomic compile errors

`GlobWalker` own `cwd`

Fix windows path and absolute test

stuff

* Fixes

* Fix stuff

* Use Syscall.close

* Use private symbols for underlying scan functions to preevent misuse

* Update types

* Fix build for zig

* Fix tests

* Fix more tests

* Prevent these tests from GC'ing too much

* Make this benchmark work in Node and Bun

* Fix memory leak

* Add leak test

* Fix windows

* comment about arena allocator use for glob walker

* Make leak test run in separate process

* Iterator api for glob

* GlobWalker.Iterator

* fix leak test

* Remove old impl

* filter functions wip start

* stuff

* wip lockfile use glob

* glob working with lockfile

* revert lockfile changes

* Update bun.lockb

* Manually set to cwd to prevent test failing on linux CI

---------

Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2023-11-22 14:26:09 -08:00

97 lines
2.4 KiB
TypeScript

interface PropertyAttribute {
enumerable?: boolean;
configurable?: boolean;
/**
* The name for a private symbol to use as the property name. The value should
* be a private symbol from `BunBuiltinNames.h`. This will omit the property
* from the prototype hash table, instead setting it using `putDirect()`.
*/
privateSymbol?: string;
}
export type Field =
| ({ getter: string; cache?: true | string; this?: boolean } & PropertyAttribute)
| { value: string }
| ({ setter: string; this?: boolean } & PropertyAttribute)
| ({
accessor: { getter: string; setter: string };
cache?: true | string;
this?: boolean;
} & PropertyAttribute)
| ({
fn: string;
length?: number;
DOMJIT?: {
returns: string;
args?: [string, string] | [string, string, string] | [string] | [];
pure?: boolean;
};
} & PropertyAttribute)
| { internal: true }
| {
/**
* The function is a builtin (its implementation is defined in
* src/js/builtins/), this value is the name of the code generator
* function: `camelCase(fileName + functionName + "CodeGenerator"`)
*/
builtin: string;
length?: number;
};
export interface ClassDefinition {
name: string;
construct?: boolean;
call?: boolean;
finalize?: boolean;
klass: Record<string, Field>;
proto: Record<string, Field>;
values?: string[];
JSType?: string;
noConstructor?: boolean;
estimatedSize?: boolean;
hasPendingActivity?: boolean;
isEventEmitter?: boolean;
supportsObjectCreate?: boolean;
getInternalProperties?: boolean;
custom?: Record<string, CustomField>;
configurable?: boolean;
enumerable?: boolean;
structuredClone?: boolean | { transferable: boolean; tag: number };
callbacks?: Record<string, string>;
}
export interface CustomField {
header?: string;
extraHeaderIncludes?: string[];
impl?: string;
type?: string;
}
export function define(
{
klass = {},
proto = {},
values = [],
estimatedSize = false,
call = false,
construct = false,
structuredClone = false,
...rest
} = {} as ClassDefinition,
): ClassDefinition {
return {
...rest,
call,
construct,
estimatedSize,
structuredClone,
values,
klass: Object.fromEntries(Object.entries(klass).sort(([a], [b]) => a.localeCompare(b))),
proto: Object.fromEntries(Object.entries(proto).sort(([a], [b]) => a.localeCompare(b))),
};
}