arktype 1.1.0-dev-2 → 2.0.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/array.test.ts +272 -0
- package/__tests__/astUtils.test.ts +17 -0
- package/__tests__/badDefinitionType.test.ts +51 -0
- package/__tests__/basis.test.ts +46 -0
- package/__tests__/bounds.test.ts +388 -0
- package/__tests__/cast.test.ts +32 -0
- package/__tests__/completions.test.ts +46 -0
- package/__tests__/config.test.ts +168 -0
- package/__tests__/cyclic.test.ts +144 -0
- package/__tests__/dateLiteral.test.ts +32 -0
- package/__tests__/declared.test.ts +123 -0
- package/__tests__/discrimination.test.ts +74 -0
- package/__tests__/divisor.test.ts +90 -0
- package/__tests__/enclosed.test.ts +93 -0
- package/__tests__/examples.test.ts +56 -0
- package/__tests__/expressions.test.ts +138 -0
- package/__tests__/generateBenchData.ts +89 -0
- package/__tests__/generated/cyclic.ts +3058 -0
- package/__tests__/generic.test.ts +294 -0
- package/__tests__/group.test.ts +72 -0
- package/__tests__/hkt.test.ts +22 -0
- package/__tests__/imports.test.ts +113 -0
- package/__tests__/instanceof.test.ts +102 -0
- package/__tests__/intersection.test.ts +104 -0
- package/__tests__/jsdoc.test.ts +64 -0
- package/__tests__/keyTraversal.test.ts +73 -0
- package/__tests__/keyof.test.ts +134 -0
- package/__tests__/keywords.test.ts +188 -0
- package/__tests__/literal.test.ts +51 -0
- package/__tests__/match.test.ts +34 -0
- package/__tests__/methods.bench.ts +22 -0
- package/__tests__/morph.test.ts +409 -0
- package/__tests__/narrow.test.ts +102 -0
- package/__tests__/nodeDefinitions.test.ts +190 -0
- package/__tests__/object.bench.ts +28 -0
- package/__tests__/objectLiteral.test.ts +300 -0
- package/__tests__/operand.bench.ts +45 -0
- package/__tests__/operator.bench.ts +130 -0
- package/__tests__/regex.test.ts +58 -0
- package/__tests__/scope.bench.ts +39 -0
- package/__tests__/scope.test.ts +140 -0
- package/__tests__/string.test.ts +48 -0
- package/__tests__/submodule.test.ts +99 -0
- package/__tests__/this.test.ts +57 -0
- package/__tests__/thunk.test.ts +80 -0
- package/__tests__/traverse.test.ts +119 -0
- package/__tests__/tsGenerics.test.ts +12 -0
- package/__tests__/typeMethods.test.ts +69 -0
- package/__tests__/typeReference.test.ts +39 -0
- package/__tests__/unenclosed.test.ts +120 -0
- package/__tests__/union.test.ts +147 -0
- package/ark.ts +91 -0
- package/main.ts +7 -9
- package/match.ts +47 -68
- package/out/ark.d.ts +52 -0
- package/out/ark.d.ts.map +1 -0
- package/out/ark.js +19 -0
- package/out/ark.js.map +1 -0
- package/out/arkConfig.d.ts +2 -0
- package/out/arkConfig.d.ts.map +1 -0
- package/out/arkConfig.js +10 -0
- package/out/arkConfig.js.map +1 -0
- package/out/main.d.ts +7 -0
- package/out/main.d.ts.map +1 -0
- package/out/main.js +4 -0
- package/out/main.js.map +1 -0
- package/out/match.d.ts +48 -0
- package/out/match.d.ts.map +1 -0
- package/{dist → out}/match.js +0 -5
- package/out/match.js.map +1 -0
- package/{dist → out}/parser/definition.d.ts +3 -3
- package/out/parser/definition.d.ts.map +1 -0
- package/{dist → out}/parser/definition.js +8 -5
- package/out/parser/definition.js.map +1 -0
- package/out/parser/generic.d.ts +18 -0
- package/out/parser/generic.d.ts.map +1 -0
- package/out/parser/generic.js +19 -0
- package/out/parser/generic.js.map +1 -0
- package/{dist → out}/parser/objectLiteral.d.ts +14 -5
- package/out/parser/objectLiteral.d.ts.map +1 -0
- package/out/parser/objectLiteral.js +66 -0
- package/out/parser/objectLiteral.js.map +1 -0
- package/out/parser/semantic/bounds.d.ts +13 -0
- package/out/parser/semantic/bounds.d.ts.map +1 -0
- package/{dist → out}/parser/semantic/bounds.js.map +1 -1
- package/{dist → out}/parser/semantic/divisor.d.ts +2 -2
- package/{dist → out}/parser/semantic/divisor.d.ts.map +1 -1
- package/{dist → out}/parser/semantic/intersections.d.ts +1 -2
- package/out/parser/semantic/intersections.d.ts.map +1 -0
- package/out/parser/semantic/semantic.d.ts +33 -0
- package/out/parser/semantic/semantic.d.ts.map +1 -0
- package/{dist → out}/parser/semantic/utils.d.ts +1 -1
- package/{dist → out}/parser/semantic/utils.d.ts.map +1 -1
- package/{dist → out}/parser/semantic/validate.d.ts +3 -3
- package/out/parser/semantic/validate.d.ts.map +1 -0
- package/{dist → out}/parser/semantic/validate.js.map +1 -1
- package/{dist → out}/parser/shared.d.ts +7 -1
- package/out/parser/shared.d.ts.map +1 -0
- package/{dist → out}/parser/shared.js +7 -1
- package/out/parser/shared.js.map +1 -0
- package/{dist → out}/parser/string/reduce/dynamic.d.ts +11 -9
- package/out/parser/string/reduce/dynamic.d.ts.map +1 -0
- package/{dist → out}/parser/string/reduce/dynamic.js +13 -2
- package/out/parser/string/reduce/dynamic.js.map +1 -0
- package/{dist → out}/parser/string/reduce/shared.d.ts +29 -2
- package/{dist → out}/parser/string/reduce/shared.d.ts.map +1 -1
- package/{dist → out}/parser/string/reduce/shared.js +20 -1
- package/out/parser/string/reduce/shared.js.map +1 -0
- package/{dist → out}/parser/string/reduce/static.d.ts +1 -2
- package/out/parser/string/reduce/static.d.ts.map +1 -0
- package/{dist → out}/parser/string/shift/operand/date.d.ts +3 -3
- package/out/parser/string/shift/operand/date.d.ts.map +1 -0
- package/{dist → out}/parser/string/shift/operand/date.js.map +1 -1
- package/{dist → out}/parser/string/shift/operand/enclosed.d.ts +2 -2
- package/{dist → out}/parser/string/shift/operand/enclosed.d.ts.map +1 -1
- package/{dist → out}/parser/string/shift/operand/enclosed.js +4 -4
- package/out/parser/string/shift/operand/enclosed.js.map +1 -0
- package/out/parser/string/shift/operand/genericArgs.d.ts +29 -0
- package/out/parser/string/shift/operand/genericArgs.d.ts.map +1 -0
- package/out/parser/string/shift/operand/genericArgs.js +25 -0
- package/out/parser/string/shift/operand/genericArgs.js.map +1 -0
- package/{dist → out}/parser/string/shift/operand/operand.d.ts.map +1 -1
- package/{dist → out}/parser/string/shift/operand/operand.js.map +1 -1
- package/{dist → out}/parser/string/shift/operand/unenclosed.d.ts +7 -9
- package/out/parser/string/shift/operand/unenclosed.d.ts.map +1 -0
- package/{dist → out}/parser/string/shift/operand/unenclosed.js +10 -10
- package/out/parser/string/shift/operand/unenclosed.js.map +1 -0
- package/{dist → out}/parser/string/shift/operator/bounds.d.ts +11 -33
- package/out/parser/string/shift/operator/bounds.d.ts.map +1 -0
- package/out/parser/string/shift/operator/bounds.js +106 -0
- package/out/parser/string/shift/operator/bounds.js.map +1 -0
- package/{dist → out}/parser/string/shift/operator/divisor.js.map +1 -1
- package/out/parser/string/shift/operator/operator.d.ts.map +1 -0
- package/{dist → out}/parser/string/shift/operator/operator.js.map +1 -1
- package/{dist → out}/parser/string/shift/scanner.d.ts +1 -1
- package/{dist → out}/parser/string/shift/scanner.d.ts.map +1 -1
- package/out/parser/string/shift/scanner.js.map +1 -0
- package/{dist → out}/parser/string/string.d.ts +9 -11
- package/out/parser/string/string.d.ts.map +1 -0
- package/out/parser/string/string.js +23 -0
- package/out/parser/string/string.js.map +1 -0
- package/{dist → out}/parser/tuple.d.ts +9 -11
- package/out/parser/tuple.d.ts.map +1 -0
- package/{dist → out}/parser/tuple.js +17 -14
- package/out/parser/tuple.js.map +1 -0
- package/{dist → out}/scope.d.ts +16 -16
- package/out/scope.d.ts.map +1 -0
- package/{dist → out}/scope.js +27 -22
- package/out/scope.js.map +1 -0
- package/out/test.d.ts +2 -0
- package/out/test.d.ts.map +1 -0
- package/out/test.js +7 -0
- package/out/test.js.map +1 -0
- package/out/tsconfig.build.tsbuildinfo +1 -0
- package/{dist → out}/type.d.ts +23 -47
- package/out/type.d.ts.map +1 -0
- package/{dist → out}/type.js +27 -31
- package/out/type.js.map +1 -0
- package/out/util.d.ts +19 -0
- package/out/util.d.ts.map +1 -0
- package/out/util.js +7 -0
- package/out/util.js.map +1 -0
- package/package.json +13 -15
- package/parser/definition.ts +58 -55
- package/parser/generic.ts +17 -157
- package/parser/objectLiteral.ts +107 -30
- package/parser/semantic/bounds.ts +22 -24
- package/parser/semantic/divisor.ts +2 -2
- package/parser/semantic/intersections.ts +17 -18
- package/parser/semantic/semantic.ts +80 -43
- package/parser/semantic/utils.ts +7 -7
- package/parser/semantic/validate.ts +40 -36
- package/parser/shared.ts +28 -17
- package/parser/string/reduce/dynamic.ts +26 -11
- package/parser/string/reduce/shared.ts +35 -7
- package/parser/string/reduce/static.ts +20 -22
- package/parser/string/shift/operand/date.ts +1 -4
- package/parser/string/shift/operand/enclosed.ts +5 -6
- package/parser/string/shift/operand/genericArgs.ts +127 -0
- package/parser/string/shift/operand/operand.ts +21 -21
- package/parser/string/shift/operand/unenclosed.ts +54 -68
- package/parser/string/shift/operator/bounds.ts +99 -64
- package/parser/string/shift/operator/operator.ts +31 -31
- package/parser/string/shift/scanner.ts +7 -7
- package/parser/string/string.ts +29 -32
- package/parser/tuple.ts +87 -88
- package/scope.ts +81 -80
- package/type.ts +76 -132
- package/util.ts +36 -0
- package/dist/main.d.ts +0 -11
- package/dist/main.d.ts.map +0 -1
- package/dist/main.js +0 -8
- package/dist/main.js.map +0 -1
- package/dist/match.d.ts +0 -46
- package/dist/match.d.ts.map +0 -1
- package/dist/match.js.map +0 -1
- package/dist/parser/definition.d.ts.map +0 -1
- package/dist/parser/definition.js.map +0 -1
- package/dist/parser/generic.d.ts +0 -44
- package/dist/parser/generic.d.ts.map +0 -1
- package/dist/parser/generic.js +0 -46
- package/dist/parser/generic.js.map +0 -1
- package/dist/parser/objectLiteral.d.ts.map +0 -1
- package/dist/parser/objectLiteral.js +0 -38
- package/dist/parser/objectLiteral.js.map +0 -1
- package/dist/parser/semantic/bounds.d.ts +0 -13
- package/dist/parser/semantic/bounds.d.ts.map +0 -1
- package/dist/parser/semantic/intersections.d.ts.map +0 -1
- package/dist/parser/semantic/semantic.d.ts +0 -22
- package/dist/parser/semantic/semantic.d.ts.map +0 -1
- package/dist/parser/semantic/validate.d.ts.map +0 -1
- package/dist/parser/shared.d.ts.map +0 -1
- package/dist/parser/shared.js.map +0 -1
- package/dist/parser/string/reduce/dynamic.d.ts.map +0 -1
- package/dist/parser/string/reduce/dynamic.js.map +0 -1
- package/dist/parser/string/reduce/shared.js.map +0 -1
- package/dist/parser/string/reduce/static.d.ts.map +0 -1
- package/dist/parser/string/shift/operand/date.d.ts.map +0 -1
- package/dist/parser/string/shift/operand/enclosed.js.map +0 -1
- package/dist/parser/string/shift/operand/unenclosed.d.ts.map +0 -1
- package/dist/parser/string/shift/operand/unenclosed.js.map +0 -1
- package/dist/parser/string/shift/operator/bounds.d.ts.map +0 -1
- package/dist/parser/string/shift/operator/bounds.js +0 -95
- package/dist/parser/string/shift/operator/bounds.js.map +0 -1
- package/dist/parser/string/shift/operator/operator.d.ts.map +0 -1
- package/dist/parser/string/shift/scanner.js.map +0 -1
- package/dist/parser/string/string.d.ts.map +0 -1
- package/dist/parser/string/string.js +0 -31
- package/dist/parser/string/string.js.map +0 -1
- package/dist/parser/tuple.d.ts.map +0 -1
- package/dist/parser/tuple.js.map +0 -1
- package/dist/scope.d.ts.map +0 -1
- package/dist/scope.js.map +0 -1
- package/dist/scopes/ark.d.ts +0 -38
- package/dist/scopes/ark.d.ts.map +0 -1
- package/dist/scopes/ark.js +0 -24
- package/dist/scopes/ark.js.map +0 -1
- package/dist/scopes/jsObjects.d.ts +0 -19
- package/dist/scopes/jsObjects.d.ts.map +0 -1
- package/dist/scopes/jsObjects.js +0 -15
- package/dist/scopes/jsObjects.js.map +0 -1
- package/dist/scopes/parsing.d.ts +0 -18
- package/dist/scopes/parsing.d.ts.map +0 -1
- package/dist/scopes/parsing.js +0 -61
- package/dist/scopes/parsing.js.map +0 -1
- package/dist/scopes/tsGenerics.d.ts +0 -17
- package/dist/scopes/tsGenerics.d.ts.map +0 -1
- package/dist/scopes/tsGenerics.js +0 -13
- package/dist/scopes/tsGenerics.js.map +0 -1
- package/dist/scopes/tsKeywords.d.ts +0 -24
- package/dist/scopes/tsKeywords.d.ts.map +0 -1
- package/dist/scopes/tsKeywords.js +0 -20
- package/dist/scopes/tsKeywords.js.map +0 -1
- package/dist/scopes/utils/creditCard.d.ts +0 -3
- package/dist/scopes/utils/creditCard.d.ts.map +0 -1
- package/dist/scopes/utils/creditCard.js +0 -36
- package/dist/scopes/utils/creditCard.js.map +0 -1
- package/dist/scopes/utils/date.d.ts +0 -24
- package/dist/scopes/utils/date.d.ts.map +0 -1
- package/dist/scopes/utils/date.js +0 -53
- package/dist/scopes/utils/date.js.map +0 -1
- package/dist/scopes/validation.d.ts +0 -20
- package/dist/scopes/validation.d.ts.map +0 -1
- package/dist/scopes/validation.js +0 -57
- package/dist/scopes/validation.js.map +0 -1
- package/dist/type.d.ts.map +0 -1
- package/dist/type.js.map +0 -1
- package/scopes/ark.ts +0 -64
- package/scopes/jsObjects.ts +0 -29
- package/scopes/parsing.ts +0 -81
- package/scopes/tsGenerics.ts +0 -28
- package/scopes/tsKeywords.ts +0 -39
- package/scopes/utils/creditCard.ts +0 -37
- package/scopes/utils/date.ts +0 -108
- package/scopes/validation.ts +0 -81
- /package/{dist → out}/parser/semantic/bounds.js +0 -0
- /package/{dist → out}/parser/semantic/divisor.js +0 -0
- /package/{dist → out}/parser/semantic/divisor.js.map +0 -0
- /package/{dist → out}/parser/semantic/intersections.js +0 -0
- /package/{dist → out}/parser/semantic/intersections.js.map +0 -0
- /package/{dist → out}/parser/semantic/semantic.js +0 -0
- /package/{dist → out}/parser/semantic/semantic.js.map +0 -0
- /package/{dist → out}/parser/semantic/utils.js +0 -0
- /package/{dist → out}/parser/semantic/utils.js.map +0 -0
- /package/{dist → out}/parser/semantic/validate.js +0 -0
- /package/{dist → out}/parser/string/reduce/static.js +0 -0
- /package/{dist → out}/parser/string/reduce/static.js.map +0 -0
- /package/{dist → out}/parser/string/shift/operand/date.js +0 -0
- /package/{dist → out}/parser/string/shift/operand/operand.d.ts +0 -0
- /package/{dist → out}/parser/string/shift/operand/operand.js +0 -0
- /package/{dist → out}/parser/string/shift/operator/divisor.d.ts +0 -0
- /package/{dist → out}/parser/string/shift/operator/divisor.d.ts.map +0 -0
- /package/{dist → out}/parser/string/shift/operator/divisor.js +0 -0
- /package/{dist → out}/parser/string/shift/operator/operator.d.ts +0 -0
- /package/{dist → out}/parser/string/shift/operator/operator.js +0 -0
- /package/{dist → out}/parser/string/shift/scanner.js +0 -0
package/parser/tuple.ts
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
type
|
|
2
|
+
keywords,
|
|
3
|
+
schema,
|
|
4
|
+
type BaseMeta,
|
|
5
5
|
type Morph,
|
|
6
6
|
type Out,
|
|
7
7
|
type Predicate,
|
|
8
|
-
type
|
|
8
|
+
type Schema,
|
|
9
|
+
type TypeNode,
|
|
10
|
+
type ValidatorKind,
|
|
11
|
+
type extractIn,
|
|
12
|
+
type extractOut,
|
|
9
13
|
type inferMorphOut,
|
|
10
14
|
type inferNarrow
|
|
11
15
|
} from "@arktype/schema"
|
|
12
16
|
import {
|
|
13
17
|
isArray,
|
|
14
18
|
objectKindOrDomainOf,
|
|
15
|
-
|
|
19
|
+
printable,
|
|
16
20
|
throwParseError,
|
|
17
21
|
type BuiltinObjectKind,
|
|
18
22
|
type Constructor,
|
|
@@ -23,7 +27,6 @@ import {
|
|
|
23
27
|
type isAny
|
|
24
28
|
} from "@arktype/util"
|
|
25
29
|
import type { ParseContext } from "../scope.js"
|
|
26
|
-
import type { extractIn, extractOut } from "../type.js"
|
|
27
30
|
import type { inferDefinition, validateDefinition } from "./definition.js"
|
|
28
31
|
import type { inferIntersection } from "./semantic/intersections.js"
|
|
29
32
|
import type { InfixOperator, PostfixExpression } from "./semantic/semantic.js"
|
|
@@ -39,7 +42,7 @@ import type { BaseCompletions } from "./string/string.js"
|
|
|
39
42
|
export const parseTuple = (def: List, ctx: ParseContext) =>
|
|
40
43
|
maybeParseTupleExpression(def, ctx) ?? parseTupleLiteral(def, ctx)
|
|
41
44
|
|
|
42
|
-
export const parseTupleLiteral = (def: List, ctx: ParseContext):
|
|
45
|
+
export const parseTupleLiteral = (def: List, ctx: ParseContext): TypeNode => {
|
|
43
46
|
const props: unknown[] = []
|
|
44
47
|
let isVariadic = false
|
|
45
48
|
for (let i = 0; i < def.length; i++) {
|
|
@@ -59,7 +62,7 @@ export const parseTupleLiteral = (def: List, ctx: ParseContext): Root => {
|
|
|
59
62
|
const parsedEntry = parseEntry([`${i}`, elementDef])
|
|
60
63
|
const value = ctx.scope.parse(parsedEntry.innerValue, ctx)
|
|
61
64
|
if (isVariadic) {
|
|
62
|
-
if (!value.extends(
|
|
65
|
+
if (!value.extends(keywords.Array)) {
|
|
63
66
|
return throwParseError(writeNonArrayRestMessage(elementDef))
|
|
64
67
|
}
|
|
65
68
|
if (i !== def.length - 1) {
|
|
@@ -68,7 +71,7 @@ export const parseTupleLiteral = (def: List, ctx: ParseContext): Root => {
|
|
|
68
71
|
// TODO: Fix builtins.arrayIndexTypeNode()
|
|
69
72
|
const elementType = value.getPath()
|
|
70
73
|
// TODO: first variadic i
|
|
71
|
-
props.push({ key:
|
|
74
|
+
props.push({ key: keywords.number, value: elementType })
|
|
72
75
|
} else {
|
|
73
76
|
props.push({
|
|
74
77
|
key: {
|
|
@@ -89,28 +92,28 @@ export const parseTupleLiteral = (def: List, ctx: ParseContext): Root => {
|
|
|
89
92
|
optional: false
|
|
90
93
|
},
|
|
91
94
|
// , ctx
|
|
92
|
-
value:
|
|
95
|
+
value: schema({ unit: def.length })
|
|
93
96
|
})
|
|
94
97
|
}
|
|
95
98
|
// props , ctx
|
|
96
|
-
return
|
|
99
|
+
return schema(Array)
|
|
97
100
|
}
|
|
98
101
|
|
|
99
102
|
export const maybeParseTupleExpression = (
|
|
100
103
|
def: List,
|
|
101
104
|
ctx: ParseContext
|
|
102
|
-
):
|
|
105
|
+
): TypeNode | undefined => {
|
|
103
106
|
const tupleExpressionResult = isIndexOneExpression(def)
|
|
104
107
|
? indexOneParsers[def[1]](def as never, ctx)
|
|
105
108
|
: isIndexZeroExpression(def)
|
|
106
|
-
|
|
107
|
-
|
|
109
|
+
? prefixParsers[def[0]](def as never, ctx)
|
|
110
|
+
: undefined
|
|
108
111
|
if (tupleExpressionResult) {
|
|
109
112
|
return tupleExpressionResult.isNever()
|
|
110
113
|
? throwParseError(
|
|
111
114
|
writeUnsatisfiableExpressionError(
|
|
112
115
|
def
|
|
113
|
-
.map((def) => (typeof def === "string" ? def :
|
|
116
|
+
.map((def) => (typeof def === "string" ? def : printable(def)))
|
|
114
117
|
.join(" ")
|
|
115
118
|
)
|
|
116
119
|
)
|
|
@@ -130,21 +133,17 @@ export type validateTuple<
|
|
|
130
133
|
> = def extends IndexZeroExpression
|
|
131
134
|
? validatePrefixExpression<def, $, args>
|
|
132
135
|
: def extends PostfixExpression
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
? BaseCompletions<$, args, IndexOneOperator>
|
|
145
|
-
: def[1]
|
|
146
|
-
]
|
|
147
|
-
: validateTupleLiteral<def, $, args>
|
|
136
|
+
? validatePostfixExpression<def, $, args>
|
|
137
|
+
: def extends InfixExpression
|
|
138
|
+
? validateInfixExpression<def, $, args>
|
|
139
|
+
: def extends
|
|
140
|
+
| readonly ["", ...unknown[]]
|
|
141
|
+
| readonly [unknown, "", ...unknown[]]
|
|
142
|
+
? readonly [
|
|
143
|
+
def[0] extends "" ? BaseCompletions<$, args, IndexZeroOperator> : def[0],
|
|
144
|
+
def[1] extends "" ? BaseCompletions<$, args, IndexOneOperator> : def[1]
|
|
145
|
+
]
|
|
146
|
+
: validateTupleLiteral<def, $, args>
|
|
148
147
|
|
|
149
148
|
export type validateTupleLiteral<
|
|
150
149
|
def extends List,
|
|
@@ -187,10 +186,10 @@ type semanticallyValidateRestElement<operand, $, args> = inferDefinition<
|
|
|
187
186
|
? result extends never
|
|
188
187
|
? writeNonArrayRestMessage<operand>
|
|
189
188
|
: isAny<result> extends true
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
189
|
+
? writeNonArrayRestMessage<operand>
|
|
190
|
+
: result extends readonly unknown[]
|
|
191
|
+
? operand
|
|
192
|
+
: writeNonArrayRestMessage<operand>
|
|
194
193
|
: never
|
|
195
194
|
|
|
196
195
|
export const writeNonArrayRestMessage = <operand>(operand: operand) =>
|
|
@@ -260,28 +259,28 @@ export type inferTupleExpression<
|
|
|
260
259
|
> = def[1] extends "[]"
|
|
261
260
|
? inferDefinition<def[0], $, args>[]
|
|
262
261
|
: def[1] extends "&"
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
262
|
+
? inferIntersection<
|
|
263
|
+
inferDefinition<def[0], $, args>,
|
|
264
|
+
inferDefinition<def[2], $, args>
|
|
265
|
+
>
|
|
266
|
+
: def[1] extends "|"
|
|
267
|
+
? inferDefinition<def[0], $, args> | inferDefinition<def[2], $, args>
|
|
268
|
+
: def[1] extends ":"
|
|
269
|
+
? inferNarrow<inferDefinition<def[0], $, args>, def[2]>
|
|
270
|
+
: def[1] extends "=>"
|
|
271
|
+
? parseMorph<def[0], def[2], $, args>
|
|
272
|
+
: def[1] extends "@"
|
|
273
|
+
? inferDefinition<def[0], $, args>
|
|
274
|
+
: def extends readonly ["===", ...infer values]
|
|
275
|
+
? values[number]
|
|
276
|
+
: def extends readonly [
|
|
277
|
+
"instanceof",
|
|
278
|
+
...infer constructors extends Constructor[]
|
|
279
|
+
]
|
|
280
|
+
? InstanceType<constructors[number]>
|
|
281
|
+
: def[0] extends "keyof"
|
|
282
|
+
? inferKeyOfExpression<def[1], $, args>
|
|
283
|
+
: never
|
|
285
284
|
|
|
286
285
|
export type validatePrefixExpression<
|
|
287
286
|
def extends IndexZeroExpression,
|
|
@@ -290,12 +289,12 @@ export type validatePrefixExpression<
|
|
|
290
289
|
> = def["length"] extends 1
|
|
291
290
|
? readonly [writeMissingRightOperandMessage<def[0]>]
|
|
292
291
|
: def[0] extends "keyof"
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
292
|
+
? readonly [def[0], validateDefinition<def[1], $, args>]
|
|
293
|
+
: def[0] extends "==="
|
|
294
|
+
? readonly [def[0], ...unknown[]]
|
|
295
|
+
: def[0] extends "instanceof"
|
|
296
|
+
? readonly [def[0], ...Constructor[]]
|
|
297
|
+
: never
|
|
299
298
|
|
|
300
299
|
export type validatePostfixExpression<
|
|
301
300
|
def extends PostfixExpression,
|
|
@@ -317,14 +316,14 @@ export type validateInfixExpression<
|
|
|
317
316
|
def[1] extends "|"
|
|
318
317
|
? validateDefinition<def[2], $, args>
|
|
319
318
|
: def[1] extends "&"
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
319
|
+
? validateDefinition<def[2], $, args>
|
|
320
|
+
: def[1] extends ":"
|
|
321
|
+
? Predicate<extractIn<inferDefinition<def[0], $, args>>>
|
|
322
|
+
: def[1] extends "=>"
|
|
323
|
+
? Morph<extractOut<inferDefinition<def[0], $, args>>, unknown>
|
|
324
|
+
: def[1] extends "@"
|
|
325
|
+
? BaseMeta | string
|
|
326
|
+
: validateDefinition<def[2], $, args>
|
|
328
327
|
]
|
|
329
328
|
|
|
330
329
|
export type UnparsedTupleExpressionInput = {
|
|
@@ -356,12 +355,12 @@ const parseArrayTuple: PostfixParser<"[]"> = (def, ctx) =>
|
|
|
356
355
|
export type PostfixParser<token extends IndexOneOperator> = (
|
|
357
356
|
def: IndexOneExpression<token>,
|
|
358
357
|
ctx: ParseContext
|
|
359
|
-
) =>
|
|
358
|
+
) => TypeNode
|
|
360
359
|
|
|
361
360
|
export type PrefixParser<token extends IndexZeroOperator> = (
|
|
362
361
|
def: IndexZeroExpression<token>,
|
|
363
362
|
ctx: ParseContext
|
|
364
|
-
) =>
|
|
363
|
+
) => TypeNode
|
|
365
364
|
|
|
366
365
|
export type TupleExpression = IndexZeroExpression | IndexOneExpression
|
|
367
366
|
|
|
@@ -386,19 +385,13 @@ export const parseMorphTuple: PostfixParser<"=>"> = (def, ctx) => {
|
|
|
386
385
|
writeMalformedFunctionalExpressionMessage("=>", def[2])
|
|
387
386
|
)
|
|
388
387
|
}
|
|
389
|
-
// TODO:
|
|
390
|
-
return
|
|
388
|
+
// TODO: nested morphs?
|
|
389
|
+
return schema({
|
|
390
|
+
in: ctx.scope.parse(def[0], ctx) as Schema<ValidatorKind>,
|
|
391
|
+
morph: def[2] as Morph
|
|
392
|
+
})
|
|
391
393
|
}
|
|
392
394
|
|
|
393
|
-
export type parseMorph<inDef, morph, $, args> = morph extends Morph
|
|
394
|
-
? (
|
|
395
|
-
// TODO: should this be extractOut
|
|
396
|
-
In: extractIn<inferDefinition<inDef, $, args>>
|
|
397
|
-
) => Out<inferMorphOut<ReturnType<morph>>>
|
|
398
|
-
: never
|
|
399
|
-
|
|
400
|
-
export type MorphAst<i = any, o = any> = (In: i) => Out<o>
|
|
401
|
-
|
|
402
395
|
export const writeMalformedFunctionalExpressionMessage = (
|
|
403
396
|
operator: FunctionalTupleOperator,
|
|
404
397
|
value: unknown
|
|
@@ -407,6 +400,12 @@ export const writeMalformedFunctionalExpressionMessage = (
|
|
|
407
400
|
operator === ":" ? "Narrow" : "Morph"
|
|
408
401
|
} expression requires a function following '${operator}' (was ${typeof value})`
|
|
409
402
|
|
|
403
|
+
export type parseMorph<inDef, morph, $, args> = morph extends Morph
|
|
404
|
+
? (
|
|
405
|
+
In: extractIn<inferDefinition<inDef, $, args>>
|
|
406
|
+
) => Out<inferMorphOut<ReturnType<morph>>>
|
|
407
|
+
: never
|
|
408
|
+
|
|
410
409
|
export const parseNarrowTuple: PostfixParser<":"> = (def, ctx) => {
|
|
411
410
|
if (typeof def[2] !== "function") {
|
|
412
411
|
return throwParseError(
|
|
@@ -445,7 +444,7 @@ const prefixParsers: {
|
|
|
445
444
|
[token in IndexZeroOperator]: PrefixParser<token>
|
|
446
445
|
} = {
|
|
447
446
|
keyof: parseKeyOfTuple,
|
|
448
|
-
instanceof: (def
|
|
447
|
+
instanceof: (def) => {
|
|
449
448
|
if (typeof def[1] !== "function") {
|
|
450
449
|
return throwParseError(
|
|
451
450
|
writeInvalidConstructorMessage(objectKindOrDomainOf(def[1]))
|
|
@@ -455,14 +454,14 @@ const prefixParsers: {
|
|
|
455
454
|
.slice(1)
|
|
456
455
|
.map((ctor) =>
|
|
457
456
|
typeof ctor === "function"
|
|
458
|
-
? {
|
|
457
|
+
? { proto: ctor as Constructor }
|
|
459
458
|
: throwParseError(
|
|
460
459
|
writeInvalidConstructorMessage(objectKindOrDomainOf(ctor))
|
|
461
460
|
)
|
|
462
461
|
)
|
|
463
|
-
return
|
|
462
|
+
return schema(...branches)
|
|
464
463
|
},
|
|
465
|
-
"===": (def) =>
|
|
464
|
+
"===": (def) => schema.units(...def.slice(1))
|
|
466
465
|
}
|
|
467
466
|
|
|
468
467
|
const isIndexZeroExpression = (def: List): def is IndexZeroExpression =>
|
|
@@ -472,4 +471,4 @@ export const writeInvalidConstructorMessage = <
|
|
|
472
471
|
actual extends Domain | BuiltinObjectKind
|
|
473
472
|
>(
|
|
474
473
|
actual: actual
|
|
475
|
-
) => `Expected a constructor following 'instanceof' operator (was ${actual})
|
|
474
|
+
) => `Expected a constructor following 'instanceof' operator (was ${actual})`
|
package/scope.ts
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
BaseType,
|
|
3
|
+
keywords,
|
|
4
|
+
type ArkErrorCode,
|
|
5
|
+
type KeyCheckKind,
|
|
6
|
+
type TypeNode,
|
|
7
|
+
type extractIn,
|
|
8
|
+
type extractOut
|
|
9
|
+
} from "@arktype/schema"
|
|
2
10
|
import {
|
|
3
11
|
domainOf,
|
|
4
12
|
hasDomain,
|
|
5
13
|
isThunk,
|
|
14
|
+
map,
|
|
6
15
|
throwParseError,
|
|
7
|
-
transform,
|
|
8
16
|
type Dict,
|
|
9
17
|
type evaluate,
|
|
10
18
|
type isAny,
|
|
11
19
|
type nominal
|
|
12
20
|
} from "@arktype/util"
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
createWhenParser,
|
|
16
|
-
type MatchParser,
|
|
17
|
-
type WhenParser
|
|
18
|
-
} from "./match.js"
|
|
21
|
+
import type { type } from "./ark.js"
|
|
22
|
+
import { createMatchParser, type MatchParser } from "./match.js"
|
|
19
23
|
import {
|
|
20
24
|
parseObject,
|
|
21
25
|
writeBadDefinitionTypeMessage,
|
|
@@ -27,31 +31,26 @@ import {
|
|
|
27
31
|
type GenericDeclaration,
|
|
28
32
|
type GenericParamsParseError
|
|
29
33
|
} from "./parser/generic.js"
|
|
34
|
+
import { DynamicState } from "./parser/string/reduce/dynamic.js"
|
|
30
35
|
import {
|
|
31
36
|
writeMissingSubmoduleAccessMessage,
|
|
32
37
|
writeNonSubmoduleDotMessage,
|
|
33
38
|
writeUnresolvableMessage
|
|
34
39
|
} from "./parser/string/shift/operand/unenclosed.js"
|
|
35
|
-
import {
|
|
36
|
-
import type { type } from "./scopes/ark.js"
|
|
40
|
+
import { fullStringParse } from "./parser/string/string.js"
|
|
37
41
|
import {
|
|
38
|
-
|
|
42
|
+
Type,
|
|
39
43
|
createTypeParser,
|
|
40
44
|
generic,
|
|
41
|
-
hasArkKind,
|
|
42
|
-
Type,
|
|
43
45
|
validateUninstantiatedGeneric,
|
|
44
|
-
type arkKind,
|
|
45
46
|
type DeclarationParser,
|
|
46
47
|
type DefinitionParser,
|
|
47
|
-
type extractIn,
|
|
48
|
-
type extractOut,
|
|
49
48
|
type Generic,
|
|
50
49
|
type GenericProps,
|
|
51
|
-
type KeyCheckKind,
|
|
52
50
|
type TypeConfig,
|
|
53
51
|
type TypeParser
|
|
54
52
|
} from "./type.js"
|
|
53
|
+
import { addArkKind, hasArkKind, type arkKind } from "./util.js"
|
|
55
54
|
|
|
56
55
|
export type ScopeParser<parent, ambient> = {
|
|
57
56
|
<const def>(def: validateScope<def, parent & ambient>): Scope<{
|
|
@@ -71,7 +70,7 @@ export type ScopeParser<parent, ambient> = {
|
|
|
71
70
|
|
|
72
71
|
export type ScopeConfig = {
|
|
73
72
|
ambient?: Scope | null
|
|
74
|
-
codes?: Record<
|
|
73
|
+
codes?: Record<ArkErrorCode, { mustBe?: string }>
|
|
75
74
|
keys?: KeyCheckKind
|
|
76
75
|
}
|
|
77
76
|
|
|
@@ -82,27 +81,22 @@ type validateScope<def, $> = {
|
|
|
82
81
|
? def[k]
|
|
83
82
|
: validateDefinition<def[k], $ & bootstrap<def>, {}>
|
|
84
83
|
: parseScopeKey<k>["params"] extends GenericParamsParseError
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
84
|
+
? // use the full nominal type here to avoid an overlap between the
|
|
85
|
+
// error message and a possible value for the property
|
|
86
|
+
parseScopeKey<k>["params"][0]
|
|
87
|
+
: validateDefinition<
|
|
88
|
+
def[k],
|
|
89
|
+
$ & bootstrap<def>,
|
|
90
|
+
{
|
|
91
|
+
// once we support constraints on generic parameters, we'd use
|
|
92
|
+
// the base type here: https://github.com/arktypeio/arktype/issues/796
|
|
93
|
+
[param in parseScopeKey<k>["params"][number]]: unknown
|
|
94
|
+
}
|
|
95
|
+
>
|
|
97
96
|
}
|
|
98
97
|
|
|
99
98
|
export type bindThis<def> = { this: Def<def> }
|
|
100
99
|
|
|
101
|
-
export const bindThis = () => ({
|
|
102
|
-
// TODO: fix
|
|
103
|
-
this: builtins.unknown
|
|
104
|
-
})
|
|
105
|
-
|
|
106
100
|
/** nominal type for an unparsed definition used during scope bootstrapping */
|
|
107
101
|
type Def<def = {}> = nominal<def, "unparsed">
|
|
108
102
|
|
|
@@ -132,8 +126,8 @@ type bootstrapAliases<def> = {
|
|
|
132
126
|
>]: def[k] extends PreparsedResolution
|
|
133
127
|
? def[k]
|
|
134
128
|
: def[k] extends (() => infer thunkReturn extends PreparsedResolution)
|
|
135
|
-
|
|
136
|
-
|
|
129
|
+
? thunkReturn
|
|
130
|
+
: Def<def[k]>
|
|
137
131
|
} & {
|
|
138
132
|
[k in keyof def & GenericDeclaration as extractGenericName<k>]: Generic<
|
|
139
133
|
parseGenericParams<extractGenericParameters<k>>,
|
|
@@ -146,10 +140,10 @@ type inferBootstrapped<r extends Resolutions> = evaluate<{
|
|
|
146
140
|
[name in keyof r["exports"]]: r["exports"][name] extends Def<infer def>
|
|
147
141
|
? inferDefinition<def, $<r>, {}>
|
|
148
142
|
: r["exports"][name] extends GenericProps<infer params, infer def>
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
143
|
+
? // add the scope in which the generic was defined here
|
|
144
|
+
Generic<params, def, $<r>>
|
|
145
|
+
: // otherwise should be a submodule
|
|
146
|
+
r["exports"][name]
|
|
153
147
|
}>
|
|
154
148
|
|
|
155
149
|
type extractGenericName<k> = k extends GenericDeclaration<infer name>
|
|
@@ -175,10 +169,10 @@ export type resolve<reference extends keyof $ | keyof args, $, args> = (
|
|
|
175
169
|
? [resolution] extends [never]
|
|
176
170
|
? never
|
|
177
171
|
: isAny<resolution> extends true
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
172
|
+
? any
|
|
173
|
+
: resolution extends Def<infer def>
|
|
174
|
+
? inferDefinition<def, $, args>
|
|
175
|
+
: resolution
|
|
182
176
|
: never
|
|
183
177
|
|
|
184
178
|
export type moduleKeyOf<$> = {
|
|
@@ -204,10 +198,10 @@ export type Module<r extends Resolutions = any> = {
|
|
|
204
198
|
? [r["exports"][k]] extends [never]
|
|
205
199
|
? Type<never, $<r>>
|
|
206
200
|
: isAny<r["exports"][k]> extends true
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
201
|
+
? Type<any, $<r>>
|
|
202
|
+
: r["exports"][k] extends PreparsedResolution
|
|
203
|
+
? r["exports"][k]
|
|
204
|
+
: Type<r["exports"][k], $<r>>
|
|
211
205
|
: // set the nominal symbol's value to something validation won't care about
|
|
212
206
|
// since the inferred type will be omitted anyways
|
|
213
207
|
type.cast<"module">
|
|
@@ -223,10 +217,10 @@ export type ParseContext = {
|
|
|
223
217
|
baseName: string
|
|
224
218
|
path: string[]
|
|
225
219
|
scope: Scope
|
|
226
|
-
args: Record<string,
|
|
220
|
+
args: Record<string, TypeNode> | undefined
|
|
227
221
|
}
|
|
228
222
|
|
|
229
|
-
type MergedResolutions = Record<string,
|
|
223
|
+
type MergedResolutions = Record<string, TypeNode | Generic>
|
|
230
224
|
|
|
231
225
|
type ParseContextInput = Pick<ParseContext, "baseName" | "args">
|
|
232
226
|
|
|
@@ -236,7 +230,7 @@ export class Scope<r extends Resolutions = any> {
|
|
|
236
230
|
|
|
237
231
|
config: TypeConfig
|
|
238
232
|
|
|
239
|
-
private parseCache: Record<string,
|
|
233
|
+
private parseCache: Record<string, TypeNode> = {}
|
|
240
234
|
private resolutions: MergedResolutions
|
|
241
235
|
|
|
242
236
|
/** The set of names defined at the root-level of the scope mapped to their
|
|
@@ -244,7 +238,6 @@ export class Scope<r extends Resolutions = any> {
|
|
|
244
238
|
aliases: Record<string, unknown> = {}
|
|
245
239
|
private exportedNames: exportedName<r>[] = []
|
|
246
240
|
private ambient: Scope | null
|
|
247
|
-
private references: Root[] = []
|
|
248
241
|
|
|
249
242
|
constructor(def: Dict, config: ScopeConfig) {
|
|
250
243
|
for (const k in def) {
|
|
@@ -275,8 +268,6 @@ export class Scope<r extends Resolutions = any> {
|
|
|
275
268
|
|
|
276
269
|
match: MatchParser<$<r>> = createMatchParser(this as never) as never
|
|
277
270
|
|
|
278
|
-
when: WhenParser<$<r>> = createWhenParser(this as never) as never
|
|
279
|
-
|
|
280
271
|
// TODO: decide if this API will be used for non-validated types
|
|
281
272
|
declare: DeclarationParser<$<r>> = () => ({ type: this.type }) as never
|
|
282
273
|
|
|
@@ -324,15 +315,15 @@ export class Scope<r extends Resolutions = any> {
|
|
|
324
315
|
return this.parse(def, this.createRootContext(input))
|
|
325
316
|
}
|
|
326
317
|
|
|
327
|
-
parse(def: unknown, ctx: ParseContext):
|
|
318
|
+
parse(def: unknown, ctx: ParseContext): TypeNode {
|
|
328
319
|
if (typeof def === "string") {
|
|
329
320
|
if (ctx.args !== undefined) {
|
|
330
321
|
// we can only rely on the cache if there are no contextual
|
|
331
322
|
// resolutions like "this" or generic args
|
|
332
|
-
return parseString(def, ctx)
|
|
323
|
+
return this.parseString(def, ctx)
|
|
333
324
|
}
|
|
334
325
|
if (!this.parseCache[def]) {
|
|
335
|
-
this.parseCache[def] = parseString(def, ctx)
|
|
326
|
+
this.parseCache[def] = this.parseString(def, ctx)
|
|
336
327
|
}
|
|
337
328
|
return this.parseCache[def]
|
|
338
329
|
}
|
|
@@ -341,7 +332,16 @@ export class Scope<r extends Resolutions = any> {
|
|
|
341
332
|
: throwParseError(writeBadDefinitionTypeMessage(domainOf(def)))
|
|
342
333
|
}
|
|
343
334
|
|
|
344
|
-
|
|
335
|
+
parseString(def: string, ctx: ParseContext): TypeNode {
|
|
336
|
+
return (
|
|
337
|
+
this.maybeResolveNode(def) ??
|
|
338
|
+
((def.endsWith("[]") &&
|
|
339
|
+
this.maybeResolveNode(def.slice(0, -2))?.array()) ||
|
|
340
|
+
fullStringParse(new DynamicState(def, ctx)))
|
|
341
|
+
)
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
maybeResolve(name: string): TypeNode | Generic | undefined {
|
|
345
345
|
const cached = this.resolutions[name]
|
|
346
346
|
if (cached) {
|
|
347
347
|
return cached
|
|
@@ -357,11 +357,11 @@ export class Scope<r extends Resolutions = any> {
|
|
|
357
357
|
const resolution = hasArkKind(def, "generic")
|
|
358
358
|
? validateUninstantiatedGeneric(def)
|
|
359
359
|
: hasArkKind(def, "module")
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
360
|
+
? throwParseError(writeMissingSubmoduleAccessMessage(name))
|
|
361
|
+
: this.parseDefinition(
|
|
362
|
+
def,
|
|
363
|
+
this.createRootContext({ baseName: name, args: {} })
|
|
364
|
+
)
|
|
365
365
|
this.resolutions[name] = resolution
|
|
366
366
|
return resolution
|
|
367
367
|
}
|
|
@@ -391,20 +391,20 @@ export class Scope<r extends Resolutions = any> {
|
|
|
391
391
|
// might be something like a decimal literal, so just fall through to return
|
|
392
392
|
}
|
|
393
393
|
|
|
394
|
-
maybeResolveNode(name: string):
|
|
394
|
+
maybeResolveNode(name: string): TypeNode | undefined {
|
|
395
395
|
const result = this.maybeResolve(name)
|
|
396
|
-
return
|
|
396
|
+
return result instanceof BaseType ? (result as never) : undefined
|
|
397
397
|
}
|
|
398
398
|
|
|
399
399
|
import<names extends exportedName<r>[]>(
|
|
400
400
|
...names: names
|
|
401
401
|
): destructuredImportContext<
|
|
402
402
|
r,
|
|
403
|
-
names extends [] ? keyof r["exports"] : names[number]
|
|
403
|
+
names extends [] ? keyof r["exports"] & string : names[number]
|
|
404
404
|
> {
|
|
405
405
|
return addArkKind(
|
|
406
|
-
|
|
407
|
-
`#${alias
|
|
406
|
+
map(this.export(...names) as Dict, (alias, value) => [
|
|
407
|
+
`#${alias}`,
|
|
408
408
|
value
|
|
409
409
|
]) as never,
|
|
410
410
|
"module"
|
|
@@ -414,7 +414,7 @@ export class Scope<r extends Resolutions = any> {
|
|
|
414
414
|
compile() {
|
|
415
415
|
return ""
|
|
416
416
|
// this.export()
|
|
417
|
-
// const references: Set<
|
|
417
|
+
// const references: Set<Root> = new Set()
|
|
418
418
|
// for (const k in this.exportedResolutions!) {
|
|
419
419
|
// const resolution = this.exportedResolutions[k]
|
|
420
420
|
// if (hasArkKind(resolution, "node") && !references.has(resolution)) {
|
|
@@ -433,6 +433,11 @@ export class Scope<r extends Resolutions = any> {
|
|
|
433
433
|
// .join("\n")
|
|
434
434
|
}
|
|
435
435
|
|
|
436
|
+
bindThis() {
|
|
437
|
+
// TODO: fix
|
|
438
|
+
return { this: keywords.unknown }
|
|
439
|
+
}
|
|
440
|
+
|
|
436
441
|
private exportedResolutions: MergedResolutions | undefined
|
|
437
442
|
private exportCache: ExportCache | undefined
|
|
438
443
|
export<names extends exportedName<r>[]>(
|
|
@@ -465,10 +470,7 @@ export class Scope<r extends Resolutions = any> {
|
|
|
465
470
|
}
|
|
466
471
|
const namesToExport = names.length ? names : this.exportedNames
|
|
467
472
|
return addArkKind(
|
|
468
|
-
|
|
469
|
-
name,
|
|
470
|
-
this.exportCache![name]
|
|
471
|
-
]) as never,
|
|
473
|
+
map(namesToExport, (_, name) => [name, this.exportCache![name]]) as never,
|
|
472
474
|
"module"
|
|
473
475
|
) as never
|
|
474
476
|
}
|
|
@@ -482,16 +484,15 @@ const resolutionsOfModule = (typeSet: ExportCache) => {
|
|
|
482
484
|
const v = typeSet[k]
|
|
483
485
|
if (hasArkKind(v, "module")) {
|
|
484
486
|
const innerResolutions = resolutionsOfModule(v as never)
|
|
485
|
-
const prefixedResolutions =
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
)
|
|
487
|
+
const prefixedResolutions = map(innerResolutions, (innerK, innerV) => [
|
|
488
|
+
`${k}.${innerK}`,
|
|
489
|
+
innerV
|
|
490
|
+
])
|
|
489
491
|
Object.assign(result, prefixedResolutions)
|
|
490
492
|
} else if (hasArkKind(v, "generic")) {
|
|
491
493
|
result[k] = v
|
|
492
494
|
} else {
|
|
493
|
-
|
|
494
|
-
result[k] = v.root as never
|
|
495
|
+
result[k] = (v as Type).root
|
|
495
496
|
}
|
|
496
497
|
}
|
|
497
498
|
return result
|