-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: failure for
toString
called as a static function instead of a …
…method (#745) This required redesigning the compiler context storage implementation, because it used `Record` type which has `toString` inherited from `Object.prototype`. This fix changes `Record` to `Map` to avoid these issues and convey the meaning in a clearer way.
- Loading branch information
1 parent
626953f
commit 7055ce3
Showing
20 changed files
with
1,182 additions
and
1,117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ | |
"ignoreDependencies": [ | ||
"@tact-lang/ton-abi", | ||
"@tact-lang/ton-jest", | ||
"@types/jest", | ||
"dist" | ||
"@types/jest" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,42 @@ | ||
type Key = string | number; | ||
export type Store<T> = Map<Key, T>; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
type Stores = Map<symbol, Store<any> | undefined>; | ||
|
||
export class CompilerContext { | ||
readonly shared: Record<symbol, object | undefined> = {}; | ||
readonly stores: Stores = new Map(); | ||
|
||
constructor( | ||
args: { shared: Record<symbol, object | undefined> } = { | ||
shared: {}, | ||
args: { stores: Stores } = { | ||
stores: new Map(), | ||
}, | ||
) { | ||
this.shared = args.shared; | ||
Object.freeze(this.shared); | ||
this.stores = args.stores; | ||
Object.freeze(this.stores); | ||
Object.freeze(this); | ||
} | ||
|
||
addShared = <T>(store: symbol, key: string | number, value: T) => { | ||
let sh: Record<string, T> = {}; | ||
if (this.shared[store]) { | ||
sh = { ...this.shared[store] }; | ||
} | ||
sh[key] = value; | ||
return new CompilerContext({ shared: { ...this.shared, [store]: sh } }); | ||
updateStore = <T>(storeDispatch: symbol, key: Key, value: T) => { | ||
const store: Store<T> = new Map(this.stores.get(storeDispatch) ?? []); | ||
store.set(key, value); | ||
const updatedStores = new Map(this.stores); | ||
updatedStores.set(storeDispatch, store); | ||
return new CompilerContext({ stores: updatedStores }); | ||
}; | ||
} | ||
|
||
export function createContextStore<T>() { | ||
const symbol = Symbol(); | ||
return { | ||
get(ctx: CompilerContext, key: string | number) { | ||
if (!ctx.shared[symbol]) { | ||
return null; | ||
} | ||
const m = ctx.shared[symbol] as Record<string | number, T>; | ||
if (m[key]) { | ||
return m[key]; | ||
} else { | ||
return null; | ||
} | ||
get(ctx: CompilerContext, key: Key): T | null { | ||
return ctx.stores.get(symbol)?.get(key) ?? null; | ||
}, | ||
all(ctx: CompilerContext): Record<string | number, T> { | ||
if (!ctx.shared[symbol]) { | ||
return {} as Record<string | number, T>; | ||
} | ||
const m = ctx.shared[symbol] as Record<string | number, T>; | ||
return m; | ||
all(ctx: CompilerContext): Store<T> { | ||
return ctx.stores.get(symbol) ?? new Map(); | ||
}, | ||
set(ctx: CompilerContext, key: string | number, v: T) { | ||
return ctx.addShared(symbol, key, v); | ||
set(ctx: CompilerContext, key: Key, v: T): CompilerContext { | ||
return ctx.updateStore(symbol, key, v); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.