Skip to content

Commit

Permalink
fix: don't freeze definitions for compatibility with sass (arktypeio#901
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ssalbdivad authored Jan 12, 2024
1 parent 32ecb70 commit 93d872a
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 73 deletions.
98 changes: 45 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Check out [how it works](#how), [try it in-browser](https://arktype.io/docs/#you
<sub>(or whatever package manager you prefer)</sub>
<br />

Our types are tested in [strict-mode](https://www.typescriptlang.org/tsconfig#strict) with TypeScript versions `4.8`, `4.9`, and `5.0`.
Our types are tested in [strict-mode](https://www.typescriptlang.org/tsconfig#strict) with TypeScript version `4.8` or greater.

_Our APIs have mostly stabilized, but details may still change during the alpha/beta stages of our 1.0 release. If you have suggestions that may require a breaking change, now is the time to let us know!_

Expand Down Expand Up @@ -259,15 +259,12 @@ If the project has been useful to you and you are in a financial position to do
Otherwise, consider sending me an email ([email protected]) or [message me on Discord](https://arktype.io/discord) to let me know you're a fan of ArkType. Either would make my day!
### Current Sponsors 🥰
### ArkSponsors ⛵
<table>
<tr>
<th>fubhy</th>
<th>sam-goodwin</th>
<th>tmm</th>
<th>thomasballinger</th>
<th>jacksteamdev</th>
</tr>
<tr>
<td>
Expand All @@ -284,68 +281,63 @@ Otherwise, consider sending me an email ([email protected]) or [message me on Dis
src="https://avatars.githubusercontent.com/u/38672686"
/></a>
</td>
</tr>
## Sponsors 🥰
<table>
<tr>
<th>tmm</th>
<th>jacksteamdev</th>
<th>neodon</th>
<th>mewhhaha</th>
<th>codeandcats</th>
</tr>
<tr>
<td>
<a href="https://github.com/tmm"
><img
height="64px"
src="https://avatars.githubusercontent.com/u/6759464"
/></a>
</td>
<td>
<a href="https://github.com/thomasballinger"
><img
height="64px"
src="https://avatars.githubusercontent.com/u/458879"
/></a>
</td>
<td>
<a href="https://github.com/jacksteamdev"
><img
height="64px"
src="https://avatars.githubusercontent.com/u/23390212"
/></a>
</td>
<td>
<a href="https://github.com/neodon"
><img height="64px" src="https://avatars.githubusercontent.com/u/82944"
/></a>
</td>
<td>
<a href="https://github.com/mewhhaha"
><img
height="64px"
src="https://avatars.githubusercontent.com/u/3399205"
/></a>
</td>
<td>
<a href="https://github.com/codeandcats"
><img
height="64px"
src="https://avatars.githubusercontent.com/u/6035934"
/></a>
</td>
</tr>
<tr>
<th>neodon</th>
<th>mewhhaha</th>
<th>codeandcats</th>
<th>xrexy</th>
<th>Timeraa</th>
</tr>
<tr>
<td>
<a href="https://github.com/neodon"
><img height="64px" src="https://avatars.githubusercontent.com/u/82944"
/></a>
</td>
<td>
<a href="https://github.com/mewhhaha"
><img
height="64px"
src="https://avatars.githubusercontent.com/u/3399205"
/></a>
</td>
<td>
<a href="https://github.com/codeandcats"
><img
height="64px"
src="https://avatars.githubusercontent.com/u/6035934"
/></a>
</td>
<td>
<a href="https://github.com/xrexy"
><img
height="64px"
src="https://avatars.githubusercontent.com/u/71969236"
/></a>
</td>
<td>
<a href="https://github.com/Timeraa"
><img
height="64px"
src="https://avatars.githubusercontent.com/u/29104008"
/></a>
</td>
</tr>
<th>Timeraa</th>
</tr>
<tr>
<td>
<a href="https://github.com/Timeraa"
><img
height="64px"
src="https://avatars.githubusercontent.com/u/29104008"
/></a>
</td>
</tr>
</table>
5 changes: 5 additions & 0 deletions dev/configs/.changeset/beige-schools-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"arktype": patch
---

fix: don't freeze definitions for compatibility with sass
9 changes: 0 additions & 9 deletions src/scopes/cache.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { deepFreeze } from "../utils/freeze.js"

export class Cache<item = unknown> {
protected cache: { [name in string]?: item } = {}

Expand All @@ -20,10 +18,3 @@ export class Cache<item = unknown> {
return item
}
}

export class FreezingCache<item = unknown> extends Cache<item> {
override set(name: string, item: item) {
this.cache[name] = deepFreeze(item) as item
return item
}
}
19 changes: 8 additions & 11 deletions src/scopes/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import type {
import { compileProblemWriters } from "../traverse/problems.js"
import { chainableNoOpProxy } from "../utils/chainableNoOpProxy.js"
import { throwInternalError, throwParseError } from "../utils/errors.js"
import { deepFreeze } from "../utils/freeze.js"
import type {
Dict,
error,
Expand All @@ -28,7 +27,7 @@ import { hasKeys } from "../utils/generics.js"
import { Path } from "../utils/paths.js"
import type { stringifyUnion } from "../utils/unionToTuple.js"
import type { PrecompiledDefaults } from "./ark.js"
import { Cache, FreezingCache } from "./cache.js"
import { Cache } from "./cache.js"
import type { Expressions } from "./expressions.js"
import type {
AnonymousTypeName,
Expand Down Expand Up @@ -182,7 +181,7 @@ export const isConfigTuple = (def: unknown): def is ConfigTuple =>
export class Scope<context extends ScopeContext = any> {
name: string
config: ScopeConfig
parseCache = new FreezingCache<Node>()
parseCache = new Cache<Node>()
#resolutions = new Cache<Type>()
#exports = new Cache<Type>()

Expand Down Expand Up @@ -307,8 +306,8 @@ export class Scope<context extends ScopeContext = any> {
seen.push(node)
node = this.#resolveRecurse(node, "throw", seen).node
}
t.node = deepFreeze(node)
t.flat = deepFreeze(flattenType(t))
t.node = node
t.flat = flattenType(t)
return t
}

Expand Down Expand Up @@ -360,12 +359,10 @@ export class Scope<context extends ScopeContext = any> {
const t = initializeType("λtype", def, config, this)
const ctx = this.#initializeContext(t)
const root = parseDefinition(def, ctx)
t.node = deepFreeze(
hasKeys(config)
? { config, node: this.resolveTypeNode(root) }
: root
)
t.flat = deepFreeze(flattenType(t))
t.node = hasKeys(config)
? { config, node: this.resolveTypeNode(root) }
: root
t.flat = flattenType(t)
return t
},
{ from: this.expressions.node }
Expand Down

0 comments on commit 93d872a

Please sign in to comment.