arktype 2.0.0-dev.1 → 2.0.0-dev.10
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 +270 -151
- package/__tests__/badDefinitionType.test.ts +10 -3
- package/__tests__/basis.test.ts +6 -2
- package/__tests__/bounds.test.ts +282 -352
- package/__tests__/cast.test.ts +7 -2
- package/__tests__/completions.test.ts +8 -3
- package/__tests__/config.test.ts +95 -167
- package/__tests__/dateLiteral.test.ts +8 -4
- package/__tests__/declared.test.ts +7 -6
- package/__tests__/discrimination.test.ts +1 -1
- package/__tests__/divisor.test.ts +46 -22
- package/__tests__/enclosed.test.ts +39 -25
- package/__tests__/examples.test.ts +56 -56
- package/__tests__/expressions.test.ts +184 -112
- package/__tests__/generic.test.ts +307 -288
- package/__tests__/group.test.ts +67 -54
- package/__tests__/imports.test.ts +62 -49
- package/__tests__/instanceof.test.ts +25 -23
- package/__tests__/intersection.test.ts +52 -48
- package/__tests__/keyTraversal.test.ts +77 -73
- package/__tests__/keyof.test.ts +68 -52
- package/__tests__/keywords.test.ts +164 -138
- package/__tests__/literal.test.ts +60 -21
- package/__tests__/match.bench.ts +31 -0
- package/__tests__/match.test.ts +222 -22
- package/__tests__/narrow.test.ts +52 -54
- package/__tests__/objectLiteral.test.ts +347 -205
- package/__tests__/operator.bench.ts +4 -4
- package/__tests__/pipe.test.ts +501 -0
- package/__tests__/realWorld.test.ts +63 -0
- package/__tests__/regex.test.ts +17 -7
- package/__tests__/scope.bench.ts +1 -1
- package/__tests__/scope.test.ts +257 -23
- package/__tests__/serialization.test.ts +19 -0
- package/__tests__/string.test.ts +11 -7
- package/__tests__/submodule.test.ts +26 -39
- package/__tests__/this.test.ts +83 -57
- package/__tests__/thunk.test.ts +13 -7
- package/__tests__/traverse.test.ts +76 -54
- package/__tests__/tsGenerics.test.ts +12 -12
- package/__tests__/type.test.ts +36 -0
- package/__tests__/typeReference.test.ts +7 -7
- package/__tests__/unenclosed.test.ts +116 -100
- package/__tests__/union.test.ts +171 -104
- package/ark.ts +21 -65
- package/generic.ts +69 -0
- package/main.ts +6 -18
- package/match.ts +195 -93
- package/module.ts +15 -0
- package/out/ark.d.ts +15 -39
- package/out/ark.js +9 -18
- package/out/ark.js.map +1 -1
- package/out/generic.d.ts +21 -0
- package/out/generic.js +24 -0
- package/out/generic.js.map +1 -0
- package/out/main.d.ts +6 -7
- package/out/main.js +4 -3
- package/out/main.js.map +1 -1
- package/out/match.d.ts +57 -34
- package/out/match.js +51 -17
- package/out/match.js.map +1 -1
- package/out/module.d.ts +10 -0
- package/out/module.js +3 -0
- package/out/module.js.map +1 -0
- package/out/parser/definition.d.ts +11 -13
- package/out/parser/definition.js +10 -13
- package/out/parser/definition.js.map +1 -1
- package/out/parser/generic.d.ts +5 -7
- package/out/parser/generic.js +7 -11
- package/out/parser/generic.js.map +1 -1
- package/out/parser/objectLiteral.d.ts +45 -14
- package/out/parser/objectLiteral.js +61 -52
- package/out/parser/objectLiteral.js.map +1 -1
- package/out/parser/semantic/bounds.d.ts +10 -8
- package/out/parser/semantic/bounds.js +0 -1
- package/out/parser/semantic/bounds.js.map +1 -1
- package/out/parser/semantic/divisor.d.ts +5 -7
- package/out/parser/semantic/divisor.js +0 -1
- package/out/parser/semantic/infer.d.ts +24 -0
- package/out/parser/semantic/infer.js +1 -0
- package/out/parser/semantic/infer.js.map +1 -0
- package/out/parser/semantic/utils.d.ts +3 -7
- package/out/parser/semantic/utils.js +0 -1
- package/out/parser/semantic/validate.d.ts +15 -14
- package/out/parser/semantic/validate.js +1 -1
- package/out/parser/semantic/validate.js.map +1 -1
- package/out/parser/string/reduce/dynamic.d.ts +13 -13
- package/out/parser/string/reduce/dynamic.js +31 -26
- package/out/parser/string/reduce/dynamic.js.map +1 -1
- package/out/parser/string/reduce/shared.d.ts +6 -20
- package/out/parser/string/reduce/shared.js +0 -1
- package/out/parser/string/reduce/shared.js.map +1 -1
- package/out/parser/string/reduce/static.d.ts +27 -24
- package/out/parser/string/reduce/static.js +0 -1
- package/out/parser/string/shift/operand/date.d.ts +3 -3
- package/out/parser/string/shift/operand/date.js +4 -7
- package/out/parser/string/shift/operand/date.js.map +1 -1
- package/out/parser/string/shift/operand/enclosed.d.ts +4 -19
- package/out/parser/string/shift/operand/enclosed.js +12 -13
- package/out/parser/string/shift/operand/enclosed.js.map +1 -1
- package/out/parser/string/shift/operand/genericArgs.d.ts +9 -10
- package/out/parser/string/shift/operand/genericArgs.js +6 -10
- package/out/parser/string/shift/operand/genericArgs.js.map +1 -1
- package/out/parser/string/shift/operand/operand.d.ts +3 -4
- package/out/parser/string/shift/operand/operand.js +8 -12
- package/out/parser/string/shift/operand/operand.js.map +1 -1
- package/out/parser/string/shift/operand/unenclosed.d.ts +15 -22
- package/out/parser/string/shift/operand/unenclosed.js +24 -36
- package/out/parser/string/shift/operand/unenclosed.js.map +1 -1
- package/out/parser/string/shift/operator/bounds.d.ts +9 -13
- package/out/parser/string/shift/operator/bounds.js +43 -54
- package/out/parser/string/shift/operator/bounds.js.map +1 -1
- package/out/parser/string/shift/operator/divisor.d.ts +2 -4
- package/out/parser/string/shift/operator/divisor.js +1 -3
- package/out/parser/string/shift/operator/divisor.js.map +1 -1
- package/out/parser/string/shift/operator/operator.d.ts +2 -3
- package/out/parser/string/shift/operator/operator.js +12 -19
- package/out/parser/string/shift/operator/operator.js.map +1 -1
- package/out/parser/string/shift/scanner.d.ts +2 -2
- package/out/parser/string/shift/scanner.js +14 -16
- package/out/parser/string/shift/scanner.js.map +1 -1
- package/out/parser/string/string.d.ts +8 -6
- package/out/parser/string/string.js +1 -3
- package/out/parser/string/string.js.map +1 -1
- package/out/parser/tuple.d.ts +102 -43
- package/out/parser/tuple.js +119 -87
- package/out/parser/tuple.js.map +1 -1
- package/out/scope.d.ts +43 -120
- package/out/scope.js +39 -209
- package/out/scope.js.map +1 -1
- package/out/type.d.ts +43 -64
- package/out/type.js +30 -131
- package/out/type.js.map +1 -1
- package/package.json +7 -3
- package/parser/definition.ts +77 -93
- package/parser/generic.ts +38 -40
- package/parser/objectLiteral.ts +172 -136
- package/parser/semantic/bounds.ts +33 -32
- package/parser/semantic/divisor.ts +8 -10
- package/parser/semantic/infer.ts +141 -0
- package/parser/semantic/utils.ts +12 -23
- package/parser/semantic/validate.ts +81 -73
- package/parser/string/reduce/dynamic.ts +67 -55
- package/parser/string/reduce/shared.ts +1 -3
- package/parser/string/reduce/static.ts +67 -69
- package/parser/string/shift/operand/date.ts +15 -14
- package/parser/string/shift/operand/enclosed.ts +30 -25
- package/parser/string/shift/operand/genericArgs.ts +46 -45
- package/parser/string/shift/operand/operand.ts +32 -38
- package/parser/string/shift/operand/unenclosed.ts +107 -158
- package/parser/string/shift/operator/bounds.ts +118 -112
- package/parser/string/shift/operator/divisor.ts +14 -17
- package/parser/string/shift/operator/operator.ts +35 -46
- package/parser/string/shift/scanner.ts +51 -50
- package/parser/string/string.ts +30 -35
- package/parser/tuple.ts +375 -307
- package/scope.ts +170 -453
- package/type.ts +193 -274
- package/__tests__/astUtils.test.ts +0 -17
- package/__tests__/cyclic.test.ts +0 -144
- package/__tests__/jsdoc.test.ts +0 -64
- package/__tests__/morph.test.ts +0 -409
- package/__tests__/nodeDefinitions.test.ts +0 -190
- package/__tests__/typeMethods.test.ts +0 -69
- package/out/ark.d.ts.map +0 -1
- package/out/arkConfig.d.ts +0 -2
- package/out/arkConfig.d.ts.map +0 -1
- package/out/arkConfig.js +0 -10
- package/out/arkConfig.js.map +0 -1
- package/out/main.d.ts.map +0 -1
- package/out/match.d.ts.map +0 -1
- package/out/parser/definition.d.ts.map +0 -1
- package/out/parser/generic.d.ts.map +0 -1
- package/out/parser/objectLiteral.d.ts.map +0 -1
- package/out/parser/semantic/bounds.d.ts.map +0 -1
- package/out/parser/semantic/divisor.d.ts.map +0 -1
- package/out/parser/semantic/intersections.d.ts +0 -14
- package/out/parser/semantic/intersections.d.ts.map +0 -1
- package/out/parser/semantic/intersections.js +0 -2
- package/out/parser/semantic/intersections.js.map +0 -1
- package/out/parser/semantic/semantic.d.ts +0 -33
- package/out/parser/semantic/semantic.d.ts.map +0 -1
- package/out/parser/semantic/semantic.js +0 -2
- package/out/parser/semantic/semantic.js.map +0 -1
- package/out/parser/semantic/utils.d.ts.map +0 -1
- package/out/parser/semantic/validate.d.ts.map +0 -1
- package/out/parser/shared.d.ts +0 -54
- package/out/parser/shared.d.ts.map +0 -1
- package/out/parser/shared.js +0 -47
- package/out/parser/shared.js.map +0 -1
- package/out/parser/string/reduce/dynamic.d.ts.map +0 -1
- package/out/parser/string/reduce/shared.d.ts.map +0 -1
- package/out/parser/string/reduce/static.d.ts.map +0 -1
- package/out/parser/string/shift/operand/date.d.ts.map +0 -1
- package/out/parser/string/shift/operand/enclosed.d.ts.map +0 -1
- package/out/parser/string/shift/operand/genericArgs.d.ts.map +0 -1
- package/out/parser/string/shift/operand/operand.d.ts.map +0 -1
- package/out/parser/string/shift/operand/unenclosed.d.ts.map +0 -1
- package/out/parser/string/shift/operator/bounds.d.ts.map +0 -1
- package/out/parser/string/shift/operator/divisor.d.ts.map +0 -1
- package/out/parser/string/shift/operator/operator.d.ts.map +0 -1
- package/out/parser/string/shift/scanner.d.ts.map +0 -1
- package/out/parser/string/string.d.ts.map +0 -1
- package/out/parser/tuple.d.ts.map +0 -1
- package/out/scope.d.ts.map +0 -1
- package/out/test.d.ts +0 -2
- package/out/test.d.ts.map +0 -1
- package/out/test.js +0 -7
- package/out/test.js.map +0 -1
- package/out/tsconfig.build.tsbuildinfo +0 -1
- package/out/type.d.ts.map +0 -1
- package/out/util.d.ts +0 -19
- package/out/util.d.ts.map +0 -1
- package/out/util.js +0 -7
- package/out/util.js.map +0 -1
- package/parser/semantic/intersections.ts +0 -46
- package/parser/semantic/semantic.ts +0 -144
- package/parser/shared.ts +0 -152
- package/util.ts +0 -36
|
@@ -1,81 +1,82 @@
|
|
|
1
|
-
import { BaseType, schema, type TypeNode } from "@arktype/schema"
|
|
2
1
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
type GenericProps,
|
|
3
|
+
type PrivateDeclaration,
|
|
4
|
+
RawSchema,
|
|
5
|
+
type arkKind,
|
|
6
|
+
hasArkKind,
|
|
7
|
+
type writeNonSubmoduleDotMessage,
|
|
8
|
+
writeUnresolvableMessage
|
|
9
|
+
} from "@arktype/schema"
|
|
10
|
+
import {
|
|
7
11
|
type BigintLiteral,
|
|
8
12
|
type Completion,
|
|
9
13
|
type ErrorMessage,
|
|
14
|
+
type isAnyOrNever,
|
|
10
15
|
type join,
|
|
11
|
-
|
|
16
|
+
printable,
|
|
17
|
+
throwParseError,
|
|
18
|
+
tryParseNumber,
|
|
19
|
+
tryParseWellFormedBigint
|
|
12
20
|
} from "@arktype/util"
|
|
13
|
-
import type {
|
|
14
|
-
import type {
|
|
15
|
-
import {
|
|
16
|
-
import type { GenericInstantiationAst } from "../../../semantic/semantic.js"
|
|
21
|
+
import type { Generic } from "../../../../generic.js"
|
|
22
|
+
import type { GenericInstantiationAst } from "../../../semantic/infer.js"
|
|
23
|
+
import { writePrefixedPrivateReferenceMessage } from "../../../semantic/validate.js"
|
|
17
24
|
import type { DynamicState } from "../../reduce/dynamic.js"
|
|
18
|
-
import type {
|
|
25
|
+
import type { StaticState, state } from "../../reduce/static.js"
|
|
19
26
|
import type { BaseCompletions } from "../../string.js"
|
|
20
27
|
import type { Scanner } from "../scanner.js"
|
|
21
28
|
import {
|
|
29
|
+
type ParsedArgs,
|
|
22
30
|
parseGenericArgs,
|
|
23
|
-
writeInvalidGenericArgsMessage
|
|
24
|
-
type ParsedArgs
|
|
31
|
+
writeInvalidGenericArgsMessage
|
|
25
32
|
} from "./genericArgs.js"
|
|
26
33
|
|
|
27
|
-
export const parseUnenclosed = (s: DynamicState) => {
|
|
34
|
+
export const parseUnenclosed = (s: DynamicState): void => {
|
|
28
35
|
const token = s.scanner.shiftUntilNextTerminator()
|
|
29
|
-
if (token === "keyof")
|
|
30
|
-
|
|
31
|
-
} else {
|
|
32
|
-
s.root = unenclosedToNode(s, token)
|
|
33
|
-
}
|
|
36
|
+
if (token === "keyof") s.addPrefix("keyof")
|
|
37
|
+
else s.root = unenclosedToNode(s, token)
|
|
34
38
|
}
|
|
35
39
|
|
|
36
|
-
export type parseUnenclosed<
|
|
37
|
-
s extends
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
: result extends keyof $
|
|
49
|
-
? $[result] extends GenericProps
|
|
50
|
-
? parseGenericInstantiation<
|
|
40
|
+
export type parseUnenclosed<s extends StaticState, $, args> =
|
|
41
|
+
Scanner.shiftUntilNextTerminator<s["unscanned"]> extends (
|
|
42
|
+
Scanner.shiftResult<infer token, infer unscanned>
|
|
43
|
+
) ?
|
|
44
|
+
token extends "keyof" ? state.addPrefix<s, "keyof", unscanned>
|
|
45
|
+
: tryResolve<s, token, $, args> extends infer result ?
|
|
46
|
+
result extends ErrorMessage<infer message> ? state.error<message>
|
|
47
|
+
: result extends keyof $ ?
|
|
48
|
+
isAnyOrNever<$[result]> extends true ?
|
|
49
|
+
state.setRoot<s, result, unscanned>
|
|
50
|
+
: $[result] extends GenericProps ?
|
|
51
|
+
parseGenericInstantiation<
|
|
51
52
|
token,
|
|
52
53
|
$[result],
|
|
53
54
|
state.scanTo<s, unscanned>,
|
|
54
55
|
$,
|
|
55
56
|
args
|
|
56
|
-
|
|
57
|
-
:
|
|
58
|
-
:
|
|
59
|
-
:
|
|
60
|
-
:
|
|
57
|
+
>
|
|
58
|
+
: state.setRoot<s, result, unscanned>
|
|
59
|
+
: state.setRoot<s, result, unscanned>
|
|
60
|
+
: never
|
|
61
|
+
: never
|
|
61
62
|
|
|
62
63
|
export const parseGenericInstantiation = (
|
|
63
64
|
name: string,
|
|
64
65
|
g: Generic,
|
|
65
66
|
s: DynamicState
|
|
66
|
-
):
|
|
67
|
+
): RawSchema => {
|
|
67
68
|
s.scanner.shiftUntilNonWhitespace()
|
|
68
69
|
const lookahead = s.scanner.shift()
|
|
69
|
-
if (lookahead !== "<")
|
|
70
|
-
return s.error(writeInvalidGenericArgsMessage(name, g.
|
|
71
|
-
|
|
72
|
-
const parsedArgs = parseGenericArgs(name, g.
|
|
70
|
+
if (lookahead !== "<")
|
|
71
|
+
return s.error(writeInvalidGenericArgsMessage(name, g.params, []))
|
|
72
|
+
|
|
73
|
+
const parsedArgs = parseGenericArgs(name, g.params, s)
|
|
73
74
|
const remainingChars = parsedArgs.unscanned.length
|
|
74
75
|
// set the scanner position to where the args scanner left off
|
|
75
76
|
s.scanner.jumpToIndex(
|
|
76
77
|
remainingChars === 0 ? s.scanner.length : -remainingChars
|
|
77
78
|
)
|
|
78
|
-
return g(...parsedArgs.result)
|
|
79
|
+
return g(...parsedArgs.result) as never
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
export type parseGenericInstantiation<
|
|
@@ -85,107 +86,69 @@ export type parseGenericInstantiation<
|
|
|
85
86
|
$,
|
|
86
87
|
args
|
|
87
88
|
// have to skip whitespace here since TS allows instantiations like `Partial <T>`
|
|
88
|
-
> =
|
|
89
|
-
?
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
: state.error<writeInvalidGenericArgsMessage<name, g["parameters"], []>>
|
|
102
|
-
|
|
103
|
-
const unenclosedToNode = (s: DynamicState, token: string): TypeNode =>
|
|
89
|
+
> =
|
|
90
|
+
Scanner.skipWhitespace<s["unscanned"]> extends `<${infer unscanned}` ?
|
|
91
|
+
parseGenericArgs<name, g["params"], unscanned, $, args> extends (
|
|
92
|
+
infer result
|
|
93
|
+
) ?
|
|
94
|
+
result extends ParsedArgs<infer argAsts, infer nextUnscanned> ?
|
|
95
|
+
state.setRoot<s, GenericInstantiationAst<g, argAsts>, nextUnscanned>
|
|
96
|
+
: // propagate error
|
|
97
|
+
result
|
|
98
|
+
: never
|
|
99
|
+
: state.error<writeInvalidGenericArgsMessage<name, g["params"], []>>
|
|
100
|
+
|
|
101
|
+
const unenclosedToNode = (s: DynamicState, token: string): RawSchema =>
|
|
104
102
|
maybeParseReference(s, token) ??
|
|
105
103
|
maybeParseUnenclosedLiteral(s, token) ??
|
|
106
104
|
s.error(
|
|
107
|
-
token === ""
|
|
108
|
-
|
|
109
|
-
|
|
105
|
+
token === "" ? writeMissingOperandMessage(s)
|
|
106
|
+
: token[0] === "#" ?
|
|
107
|
+
writePrefixedPrivateReferenceMessage(token as PrivateDeclaration)
|
|
108
|
+
: writeUnresolvableMessage(token)
|
|
110
109
|
)
|
|
111
110
|
|
|
112
111
|
const maybeParseReference = (
|
|
113
112
|
s: DynamicState,
|
|
114
113
|
token: string
|
|
115
|
-
):
|
|
116
|
-
if (s.ctx.args?.[token])
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (resolution
|
|
121
|
-
return resolution
|
|
122
|
-
}
|
|
123
|
-
if (resolution === undefined) {
|
|
124
|
-
return
|
|
125
|
-
}
|
|
126
|
-
if (hasArkKind(resolution, "generic")) {
|
|
127
|
-
return parseGenericInstantiation(token, resolution, s)
|
|
128
|
-
}
|
|
114
|
+
): RawSchema | undefined => {
|
|
115
|
+
if (s.ctx.args?.[token]) return s.ctx.args[token].raw
|
|
116
|
+
const resolution = s.ctx.$.maybeResolve(token)
|
|
117
|
+
if (resolution instanceof RawSchema) return resolution
|
|
118
|
+
if (resolution === undefined) return
|
|
119
|
+
if (hasArkKind(resolution, "generic"))
|
|
120
|
+
return parseGenericInstantiation(token, resolution as Generic, s)
|
|
129
121
|
return throwParseError(`Unexpected resolution ${printable(resolution)}`)
|
|
130
122
|
}
|
|
131
123
|
|
|
132
124
|
const maybeParseUnenclosedLiteral = (
|
|
133
125
|
s: DynamicState,
|
|
134
126
|
token: string
|
|
135
|
-
):
|
|
127
|
+
): RawSchema | undefined => {
|
|
136
128
|
const maybeNumber = tryParseNumber(token, { strict: true })
|
|
137
|
-
if (maybeNumber !== undefined)
|
|
138
|
-
return
|
|
139
|
-
|
|
129
|
+
if (maybeNumber !== undefined)
|
|
130
|
+
return s.ctx.$.node("unit", { unit: maybeNumber })
|
|
131
|
+
|
|
140
132
|
const maybeBigint = tryParseWellFormedBigint(token)
|
|
141
|
-
if (maybeBigint !== undefined)
|
|
142
|
-
return
|
|
143
|
-
}
|
|
133
|
+
if (maybeBigint !== undefined)
|
|
134
|
+
return s.ctx.$.node("unit", { unit: maybeBigint })
|
|
144
135
|
}
|
|
145
136
|
|
|
146
|
-
type tryResolve<
|
|
147
|
-
|
|
148
|
-
token extends
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
?
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
? $[submodule] extends Module<infer r>
|
|
162
|
-
? reference extends keyof r["exports"]
|
|
163
|
-
? token
|
|
164
|
-
: unknown extends r["exports"]
|
|
165
|
-
? // not sure why I need the additional check here, but for now TS seems to
|
|
166
|
-
// hit this branch for a non-scope dot access rather than failing
|
|
167
|
-
// initially when we try to infer r. if this can be removed without breaking
|
|
168
|
-
// any submodule test cases, do it!
|
|
169
|
-
ErrorMessage<writeNonSubmoduleDotMessage<submodule>>
|
|
170
|
-
: unresolvableError<s, reference, $[submodule], args, [submodule]>
|
|
171
|
-
: ErrorMessage<writeNonSubmoduleDotMessage<submodule>>
|
|
172
|
-
: unresolvableError<s, token, $, args, []>
|
|
173
|
-
|
|
174
|
-
export const writeNonSubmoduleDotMessage = <name extends string>(
|
|
175
|
-
name: name
|
|
176
|
-
): writeNonSubmoduleDotMessage<name> =>
|
|
177
|
-
`'${name}' must reference a module to be accessed using dot syntax`
|
|
178
|
-
|
|
179
|
-
type writeNonSubmoduleDotMessage<name extends string> =
|
|
180
|
-
`'${name}' must reference a module to be accessed using dot syntax`
|
|
181
|
-
|
|
182
|
-
export const writeMissingSubmoduleAccessMessage = <name extends string>(
|
|
183
|
-
name: name
|
|
184
|
-
): writeMissingSubmoduleAccessMessage<name> =>
|
|
185
|
-
`Reference to submodule '${name}' must specify an alias`
|
|
186
|
-
|
|
187
|
-
export type writeMissingSubmoduleAccessMessage<name extends string> =
|
|
188
|
-
`Reference to submodule '${name}' must specify an alias`
|
|
137
|
+
type tryResolve<s extends StaticState, token extends string, $, args> =
|
|
138
|
+
token extends keyof $ ? token
|
|
139
|
+
: `#${token}` extends keyof $ ? token
|
|
140
|
+
: token extends keyof args ? token
|
|
141
|
+
: token extends `${number}` ? token
|
|
142
|
+
: token extends BigintLiteral ? token
|
|
143
|
+
: token extends (
|
|
144
|
+
`${infer submodule extends keyof $ & string}.${infer reference}`
|
|
145
|
+
) ?
|
|
146
|
+
$[submodule] extends { [arkKind]: "module" } ?
|
|
147
|
+
reference extends keyof $[submodule] ?
|
|
148
|
+
token
|
|
149
|
+
: unresolvableError<s, reference, $[submodule], args, [submodule]>
|
|
150
|
+
: ErrorMessage<writeNonSubmoduleDotMessage<submodule>>
|
|
151
|
+
: unresolvableError<s, token, $, args, []>
|
|
189
152
|
|
|
190
153
|
/** Provide valid completions for the current token, or fallback to an
|
|
191
154
|
* unresolvable error if there are none */
|
|
@@ -195,14 +158,15 @@ export type unresolvableError<
|
|
|
195
158
|
$,
|
|
196
159
|
args,
|
|
197
160
|
submodulePath extends string[]
|
|
198
|
-
> =
|
|
199
|
-
?
|
|
161
|
+
> =
|
|
162
|
+
validReferenceFromToken<token, $, args, submodulePath> extends never ?
|
|
163
|
+
ErrorMessage<
|
|
200
164
|
writeUnresolvableMessage<qualifiedReference<token, submodulePath>>
|
|
201
|
-
|
|
202
|
-
:
|
|
165
|
+
>
|
|
166
|
+
: Completion<`${s["scanned"]}${qualifiedReference<
|
|
203
167
|
validReferenceFromToken<token, $, args, submodulePath>,
|
|
204
168
|
submodulePath
|
|
205
|
-
|
|
169
|
+
>}`>
|
|
206
170
|
|
|
207
171
|
type qualifiedReference<
|
|
208
172
|
reference extends string,
|
|
@@ -219,33 +183,18 @@ type validReferenceFromToken<
|
|
|
219
183
|
`${token}${string}`
|
|
220
184
|
>
|
|
221
185
|
|
|
222
|
-
export const
|
|
223
|
-
token: token
|
|
224
|
-
): writeUnresolvableMessage<token> => `'${token}' is unresolvable`
|
|
225
|
-
|
|
226
|
-
type writeUnresolvableMessage<token extends string> =
|
|
227
|
-
`'${token}' is unresolvable`
|
|
228
|
-
|
|
229
|
-
export const writeMissingOperandMessage = <s extends DynamicState>(s: s) => {
|
|
186
|
+
export const writeMissingOperandMessage = (s: DynamicState): string => {
|
|
230
187
|
const operator = s.previousOperator()
|
|
231
|
-
return operator
|
|
232
|
-
|
|
233
|
-
:
|
|
188
|
+
return operator ?
|
|
189
|
+
writeMissingRightOperandMessage(operator, s.scanner.unscanned)
|
|
190
|
+
: writeExpressionExpectedMessage(s.scanner.unscanned)
|
|
234
191
|
}
|
|
235
192
|
|
|
236
|
-
export type writeMissingOperandMessage<
|
|
237
|
-
s extends StaticState,
|
|
238
|
-
operator extends string | undefined = state.previousOperator<s>
|
|
239
|
-
> = operator extends string
|
|
240
|
-
? writeMissingRightOperandMessage<operator, s["unscanned"]>
|
|
241
|
-
: writeExpressionExpectedMessage<s["unscanned"]>
|
|
242
|
-
|
|
243
193
|
export type writeMissingRightOperandMessage<
|
|
244
194
|
token extends string,
|
|
245
195
|
unscanned extends string = ""
|
|
246
|
-
> = `Token '${token}' requires a right operand${unscanned extends ""
|
|
247
|
-
|
|
248
|
-
: ` before '${unscanned}'`}`
|
|
196
|
+
> = `Token '${token}' requires a right operand${unscanned extends "" ? ""
|
|
197
|
+
: ` before '${unscanned}'`}`
|
|
249
198
|
|
|
250
199
|
export const writeMissingRightOperandMessage = <
|
|
251
200
|
token extends string,
|
|
@@ -260,9 +209,9 @@ export const writeMissingRightOperandMessage = <
|
|
|
260
209
|
|
|
261
210
|
export const writeExpressionExpectedMessage = <unscanned extends string>(
|
|
262
211
|
unscanned: unscanned
|
|
263
|
-
)
|
|
212
|
+
): writeExpressionExpectedMessage<unscanned> =>
|
|
213
|
+
`Expected an expression${unscanned ? ` before '${unscanned}'` : ""}` as never
|
|
264
214
|
|
|
265
215
|
export type writeExpressionExpectedMessage<unscanned extends string> =
|
|
266
|
-
`Expected an expression${unscanned extends ""
|
|
267
|
-
|
|
268
|
-
: ` before '${unscanned}'`}`
|
|
216
|
+
`Expected an expression${unscanned extends "" ? ""
|
|
217
|
+
: ` before '${unscanned}'`}`
|