arktype 2.0.0-dev.4 → 2.0.0-dev.6
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 +176 -236
- 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 +16 -8
- package/__tests__/cyclic.test.ts +141 -137
- package/__tests__/dateLiteral.test.ts +8 -4
- package/__tests__/declared.test.ts +2 -2
- package/__tests__/discrimination.test.ts +1 -1
- package/__tests__/divisor.test.ts +45 -25
- 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 +44 -37
- package/__tests__/instanceof.test.ts +17 -15
- package/__tests__/intersection.test.ts +50 -46
- package/__tests__/keyTraversal.test.ts +6 -3
- package/__tests__/keyof.test.ts +68 -52
- package/__tests__/keywords.test.ts +149 -136
- package/__tests__/literal.test.ts +38 -15
- package/__tests__/match.test.ts +234 -224
- package/__tests__/morph.test.ts +300 -269
- package/__tests__/narrow.test.ts +46 -42
- package/__tests__/objectLiteral.test.ts +228 -210
- 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 +65 -18
- 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 +50 -37
- package/__tests__/tsGenerics.test.ts +12 -12
- package/__tests__/type.test.ts +38 -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 +18 -65
- package/generic.ts +67 -0
- package/main.ts +6 -18
- package/match.ts +53 -67
- package/module.ts +15 -0
- package/out/ark.d.ts +12 -36
- package/out/ark.d.ts.map +1 -1
- package/out/ark.js +9 -17
- package/out/ark.js.map +1 -1
- package/out/base.d.ts +205 -0
- package/out/base.d.ts.map +1 -0
- package/out/base.js +320 -0
- package/out/base.js.map +1 -0
- package/out/builtins/builtins.d.ts +23 -0
- package/out/builtins/builtins.d.ts.map +1 -0
- package/out/builtins/builtins.js +15 -0
- package/out/builtins/builtins.js.map +1 -0
- package/out/builtins/jsObjects.d.ts +19 -0
- package/out/builtins/jsObjects.d.ts.map +1 -0
- package/out/builtins/jsObjects.js +18 -0
- package/out/builtins/jsObjects.js.map +1 -0
- package/out/builtins/parsing.d.ts +16 -0
- package/out/builtins/parsing.d.ts.map +1 -0
- package/out/builtins/parsing.js +62 -0
- package/out/builtins/parsing.js.map +1 -0
- package/out/builtins/tsGenerics.d.ts +2 -0
- package/out/builtins/tsGenerics.d.ts.map +1 -0
- package/out/builtins/tsGenerics.js +26 -0
- package/out/builtins/tsGenerics.js.map +1 -0
- package/out/builtins/tsKeywords.d.ts +23 -0
- package/out/builtins/tsKeywords.d.ts.map +1 -0
- package/out/builtins/tsKeywords.js +23 -0
- package/out/builtins/tsKeywords.js.map +1 -0
- package/out/builtins/utils/creditCard.d.ts +3 -0
- package/out/builtins/utils/creditCard.d.ts.map +1 -0
- package/out/builtins/utils/creditCard.js +35 -0
- package/out/builtins/utils/creditCard.js.map +1 -0
- package/out/builtins/utils/date.d.ts +41 -0
- package/out/builtins/utils/date.d.ts.map +1 -0
- package/out/builtins/utils/date.js +56 -0
- package/out/builtins/utils/date.js.map +1 -0
- package/out/builtins/validation.d.ts +19 -0
- package/out/builtins/validation.d.ts.map +1 -0
- package/out/builtins/validation.js +74 -0
- package/out/builtins/validation.js.map +1 -0
- package/out/config.d.ts +9 -0
- package/out/config.d.ts.map +1 -0
- package/out/config.js +18 -0
- package/out/config.js.map +1 -0
- package/out/constraints/ast.d.ts +287 -0
- package/out/constraints/ast.d.ts.map +1 -0
- package/out/constraints/ast.js +2 -0
- package/out/constraints/ast.js.map +1 -0
- package/out/constraints/constraint.d.ts +200 -0
- package/out/constraints/constraint.d.ts.map +1 -0
- package/out/constraints/constraint.js +25 -0
- package/out/constraints/constraint.js.map +1 -0
- package/out/constraints/predicate.d.ts +64 -0
- package/out/constraints/predicate.d.ts.map +1 -0
- package/out/constraints/predicate.js +52 -0
- package/out/constraints/predicate.js.map +1 -0
- package/out/constraints/props/index.d.ts +42 -0
- package/out/constraints/props/index.d.ts.map +1 -0
- package/out/constraints/props/index.js +56 -0
- package/out/constraints/props/index.js.map +1 -0
- package/out/constraints/props/optional.d.ts +37 -0
- package/out/constraints/props/optional.d.ts.map +1 -0
- package/out/constraints/props/optional.js +56 -0
- package/out/constraints/props/optional.js.map +1 -0
- package/out/constraints/props/prop.d.ts +49 -0
- package/out/constraints/props/prop.d.ts.map +1 -0
- package/out/constraints/props/prop.js +106 -0
- package/out/constraints/props/prop.js.map +1 -0
- package/out/constraints/props/props.d.ts +37 -0
- package/out/constraints/props/props.d.ts.map +1 -0
- package/out/constraints/props/props.js +121 -0
- package/out/constraints/props/props.js.map +1 -0
- package/out/constraints/props/required.d.ts +46 -0
- package/out/constraints/props/required.d.ts.map +1 -0
- package/out/constraints/props/required.js +81 -0
- package/out/constraints/props/required.js.map +1 -0
- package/out/constraints/props/sequence.d.ts +82 -0
- package/out/constraints/props/sequence.d.ts.map +1 -0
- package/out/constraints/props/sequence.js +376 -0
- package/out/constraints/props/sequence.js.map +1 -0
- package/out/constraints/props/shared.d.ts +3 -0
- package/out/constraints/props/shared.d.ts.map +1 -0
- package/out/constraints/props/shared.js +4 -0
- package/out/constraints/props/shared.js.map +1 -0
- package/out/constraints/refinements/after.d.ts +33 -0
- package/out/constraints/refinements/after.d.ts.map +1 -0
- package/out/constraints/refinements/after.js +36 -0
- package/out/constraints/refinements/after.js.map +1 -0
- package/out/constraints/refinements/before.d.ts +33 -0
- package/out/constraints/refinements/before.d.ts.map +1 -0
- package/out/constraints/refinements/before.js +43 -0
- package/out/constraints/refinements/before.js.map +1 -0
- package/out/constraints/refinements/divisor.d.ts +52 -0
- package/out/constraints/refinements/divisor.d.ts.map +1 -0
- package/out/constraints/refinements/divisor.js +52 -0
- package/out/constraints/refinements/divisor.js.map +1 -0
- package/out/constraints/refinements/exactLength.d.ts +45 -0
- package/out/constraints/refinements/exactLength.d.ts.map +1 -0
- package/out/constraints/refinements/exactLength.js +52 -0
- package/out/constraints/refinements/exactLength.js.map +1 -0
- package/out/constraints/refinements/kinds.d.ts +29 -0
- package/out/constraints/refinements/kinds.d.ts.map +1 -0
- package/out/constraints/refinements/kinds.js +17 -0
- package/out/constraints/refinements/kinds.js.map +1 -0
- package/out/constraints/refinements/length.d.ts +48 -0
- package/out/constraints/refinements/length.d.ts.map +1 -0
- package/out/constraints/refinements/length.js +53 -0
- package/out/constraints/refinements/length.js.map +1 -0
- package/out/constraints/refinements/max.d.ts +31 -0
- package/out/constraints/refinements/max.d.ts.map +1 -0
- package/out/constraints/refinements/max.js +35 -0
- package/out/constraints/refinements/max.js.map +1 -0
- package/out/constraints/refinements/maxLength.d.ts +32 -0
- package/out/constraints/refinements/maxLength.d.ts.map +1 -0
- package/out/constraints/refinements/maxLength.js +36 -0
- package/out/constraints/refinements/maxLength.js.map +1 -0
- package/out/constraints/refinements/min.d.ts +31 -0
- package/out/constraints/refinements/min.d.ts.map +1 -0
- package/out/constraints/refinements/min.js +28 -0
- package/out/constraints/refinements/min.js.map +1 -0
- package/out/constraints/refinements/minLength.d.ts +32 -0
- package/out/constraints/refinements/minLength.d.ts.map +1 -0
- package/out/constraints/refinements/minLength.js +33 -0
- package/out/constraints/refinements/minLength.js.map +1 -0
- package/out/constraints/refinements/range.d.ts +119 -0
- package/out/constraints/refinements/range.d.ts.map +1 -0
- package/out/constraints/refinements/range.js +89 -0
- package/out/constraints/refinements/range.js.map +1 -0
- package/out/constraints/refinements/regex.d.ts +47 -0
- package/out/constraints/refinements/regex.d.ts.map +1 -0
- package/out/constraints/refinements/regex.js +37 -0
- package/out/constraints/refinements/regex.js.map +1 -0
- package/out/constraints/refinements/shared.d.ts +20 -0
- package/out/constraints/refinements/shared.d.ts.map +1 -0
- package/out/constraints/refinements/shared.js +10 -0
- package/out/constraints/refinements/shared.js.map +1 -0
- package/out/generic.d.ts +22 -0
- package/out/generic.d.ts.map +1 -0
- package/out/generic.js +23 -0
- package/out/generic.js.map +1 -0
- package/out/inference.d.ts +137 -0
- package/out/inference.d.ts.map +1 -0
- package/out/inference.js +73 -0
- package/out/inference.js.map +1 -0
- package/out/keywords/ark.d.ts +70 -0
- package/out/keywords/ark.d.ts.map +1 -0
- package/out/keywords/ark.js +29 -0
- package/out/keywords/ark.js.map +1 -0
- package/out/keywords/internal.d.ts +13 -0
- package/out/keywords/internal.d.ts.map +1 -0
- package/out/keywords/internal.js +13 -0
- package/out/keywords/internal.js.map +1 -0
- package/out/keywords/jsObject.d.ts +20 -0
- package/out/keywords/jsObject.d.ts.map +1 -0
- package/out/keywords/jsObject.js +18 -0
- package/out/keywords/jsObject.js.map +1 -0
- package/out/keywords/parsing.d.ts +17 -0
- package/out/keywords/parsing.d.ts.map +1 -0
- package/out/keywords/parsing.js +64 -0
- package/out/keywords/parsing.js.map +1 -0
- package/out/keywords/root.d.ts +7 -0
- package/out/keywords/root.d.ts.map +1 -0
- package/out/keywords/root.js +4 -0
- package/out/keywords/root.js.map +1 -0
- package/out/keywords/tsGenerics.d.ts +2 -0
- package/out/keywords/tsGenerics.d.ts.map +1 -0
- package/out/keywords/tsGenerics.js +26 -0
- package/out/keywords/tsGenerics.js.map +1 -0
- package/out/keywords/tsPrimitive.d.ts +24 -0
- package/out/keywords/tsPrimitive.d.ts.map +1 -0
- package/out/keywords/tsPrimitive.js +25 -0
- package/out/keywords/tsPrimitive.js.map +1 -0
- package/out/keywords/utils/creditCard.d.ts +11 -0
- package/out/keywords/utils/creditCard.d.ts.map +1 -0
- package/out/keywords/utils/creditCard.js +35 -0
- package/out/keywords/utils/creditCard.js.map +1 -0
- package/out/keywords/utils/date.d.ts +45 -0
- package/out/keywords/utils/date.d.ts.map +1 -0
- package/out/keywords/utils/date.js +56 -0
- package/out/keywords/utils/date.js.map +1 -0
- package/out/keywords/validation.d.ts +20 -0
- package/out/keywords/validation.d.ts.map +1 -0
- package/out/keywords/validation.js +80 -0
- package/out/keywords/validation.js.map +1 -0
- package/out/kinds.d.ts +102 -0
- package/out/kinds.d.ts.map +1 -0
- package/out/kinds.js +29 -0
- package/out/kinds.js.map +1 -0
- package/out/main.d.ts +6 -6
- package/out/main.d.ts.map +1 -1
- package/out/main.js +4 -3
- package/out/main.js.map +1 -1
- package/out/match.d.ts +18 -23
- package/out/match.d.ts.map +1 -1
- package/out/match.js +3 -4
- package/out/match.js.map +1 -1
- package/out/module.d.ts +11 -0
- package/out/module.d.ts.map +1 -0
- package/out/module.js +4 -0
- package/out/module.js.map +1 -0
- package/out/parse.d.ts +29 -0
- package/out/parse.d.ts.map +1 -0
- package/out/parse.js +161 -0
- package/out/parse.js.map +1 -0
- package/out/parser/definition.d.ts +9 -12
- package/out/parser/definition.d.ts.map +1 -1
- package/out/parser/definition.js +10 -12
- package/out/parser/definition.js.map +1 -1
- package/out/parser/generic.d.ts +3 -4
- package/out/parser/generic.d.ts.map +1 -1
- package/out/parser/generic.js +6 -8
- package/out/parser/generic.js.map +1 -1
- package/out/parser/objectLiteral.d.ts +44 -12
- package/out/parser/objectLiteral.d.ts.map +1 -1
- package/out/parser/objectLiteral.js +43 -36
- package/out/parser/objectLiteral.js.map +1 -1
- package/out/parser/semantic/bounds.d.ts +9 -6
- package/out/parser/semantic/bounds.d.ts.map +1 -1
- package/out/parser/semantic/bounds.js.map +1 -1
- package/out/parser/semantic/divisor.d.ts +5 -6
- package/out/parser/semantic/divisor.d.ts.map +1 -1
- package/out/parser/semantic/infer.d.ts +25 -0
- package/out/parser/semantic/infer.d.ts.map +1 -0
- package/out/parser/semantic/infer.js +2 -0
- package/out/parser/semantic/infer.js.map +1 -0
- package/out/parser/semantic/utils.d.ts +3 -6
- package/out/parser/semantic/utils.d.ts.map +1 -1
- package/out/parser/semantic/validate.d.ts +14 -12
- package/out/parser/semantic/validate.d.ts.map +1 -1
- package/out/parser/semantic/validate.js +1 -0
- package/out/parser/semantic/validate.js.map +1 -1
- package/out/parser/string/reduce/dynamic.d.ts +13 -12
- package/out/parser/string/reduce/dynamic.d.ts.map +1 -1
- package/out/parser/string/reduce/dynamic.js +27 -17
- package/out/parser/string/reduce/dynamic.js.map +1 -1
- package/out/parser/string/reduce/shared.d.ts +1 -2
- package/out/parser/string/reduce/shared.d.ts.map +1 -1
- package/out/parser/string/reduce/shared.js.map +1 -1
- package/out/parser/string/reduce/static.d.ts +26 -22
- package/out/parser/string/reduce/static.d.ts.map +1 -1
- package/out/parser/string/shift/operand/date.d.ts +2 -1
- package/out/parser/string/shift/operand/date.d.ts.map +1 -1
- package/out/parser/string/shift/operand/date.js +2 -2
- package/out/parser/string/shift/operand/date.js.map +1 -1
- package/out/parser/string/shift/operand/enclosed.d.ts +2 -2
- package/out/parser/string/shift/operand/enclosed.d.ts.map +1 -1
- package/out/parser/string/shift/operand/enclosed.js +6 -4
- package/out/parser/string/shift/operand/enclosed.js.map +1 -1
- package/out/parser/string/shift/operand/genericArgs.d.ts +9 -9
- package/out/parser/string/shift/operand/genericArgs.d.ts.map +1 -1
- package/out/parser/string/shift/operand/genericArgs.js +6 -8
- package/out/parser/string/shift/operand/genericArgs.js.map +1 -1
- package/out/parser/string/shift/operand/operand.d.ts +3 -3
- package/out/parser/string/shift/operand/operand.d.ts.map +1 -1
- package/out/parser/string/shift/operand/operand.js +8 -11
- package/out/parser/string/shift/operand/operand.js.map +1 -1
- package/out/parser/string/shift/operand/unenclosed.d.ts +13 -20
- package/out/parser/string/shift/operand/unenclosed.d.ts.map +1 -1
- package/out/parser/string/shift/operand/unenclosed.js +21 -26
- package/out/parser/string/shift/operand/unenclosed.js.map +1 -1
- package/out/parser/string/shift/operator/bounds.d.ts +15 -12
- package/out/parser/string/shift/operator/bounds.d.ts.map +1 -1
- package/out/parser/string/shift/operator/bounds.js +42 -48
- package/out/parser/string/shift/operator/bounds.js.map +1 -1
- package/out/parser/string/shift/operator/divisor.d.ts +1 -2
- package/out/parser/string/shift/operator/divisor.d.ts.map +1 -1
- package/out/parser/string/shift/operator/divisor.js.map +1 -1
- package/out/parser/string/shift/operator/operator.d.ts +1 -1
- package/out/parser/string/shift/operator/operator.d.ts.map +1 -1
- package/out/parser/string/shift/operator/operator.js +12 -18
- package/out/parser/string/shift/operator/operator.js.map +1 -1
- package/out/parser/string/shift/scanner.d.ts +2 -1
- package/out/parser/string/shift/scanner.d.ts.map +1 -1
- package/out/parser/string/shift/scanner.js +12 -11
- package/out/parser/string/shift/scanner.js.map +1 -1
- package/out/parser/string/string.d.ts +8 -5
- package/out/parser/string/string.d.ts.map +1 -1
- package/out/parser/string/string.js.map +1 -1
- package/out/parser/tuple.d.ts +96 -37
- package/out/parser/tuple.d.ts.map +1 -1
- package/out/parser/tuple.js +61 -66
- package/out/parser/tuple.js.map +1 -1
- package/out/schema.d.ts +175 -0
- package/out/schema.d.ts.map +1 -0
- package/out/schema.js +73 -0
- package/out/schema.js.map +1 -0
- package/out/schemaScope.d.ts +180 -0
- package/out/schemaScope.d.ts.map +1 -0
- package/out/schemaScope.js +235 -0
- package/out/schemaScope.js.map +1 -0
- package/out/scope.d.ts +42 -114
- package/out/scope.d.ts.map +1 -1
- package/out/scope.js +51 -181
- package/out/scope.js.map +1 -1
- package/out/shared/compile.d.ts +22 -0
- package/out/shared/compile.d.ts.map +1 -0
- package/out/shared/compile.js +79 -0
- package/out/shared/compile.js.map +1 -0
- package/out/shared/context.d.ts +54 -0
- package/out/shared/context.d.ts.map +1 -0
- package/out/shared/context.js +53 -0
- package/out/shared/context.js.map +1 -0
- package/out/shared/declare.d.ts +69 -0
- package/out/shared/declare.d.ts.map +1 -0
- package/out/shared/declare.js +2 -0
- package/out/shared/declare.js.map +1 -0
- package/out/shared/disjoint.d.ts +91 -0
- package/out/shared/disjoint.d.ts.map +1 -0
- package/out/shared/disjoint.js +110 -0
- package/out/shared/disjoint.js.map +1 -0
- package/out/shared/errors.d.ts +99 -0
- package/out/shared/errors.d.ts.map +1 -0
- package/out/shared/errors.js +108 -0
- package/out/shared/errors.js.map +1 -0
- package/out/shared/implement.d.ts +363 -0
- package/out/shared/implement.d.ts.map +1 -0
- package/out/shared/implement.js +68 -0
- package/out/shared/implement.js.map +1 -0
- package/out/shared/inference.d.ts +6 -0
- package/out/shared/inference.d.ts.map +1 -0
- package/out/shared/inference.js +5 -0
- package/out/shared/inference.js.map +1 -0
- package/out/shared/intersections.d.ts +60 -0
- package/out/shared/intersections.d.ts.map +1 -0
- package/out/shared/intersections.js +2 -0
- package/out/shared/intersections.js.map +1 -0
- package/out/shared/traversal.d.ts +62 -0
- package/out/shared/traversal.d.ts.map +1 -0
- package/out/shared/traversal.js +97 -0
- package/out/shared/traversal.js.map +1 -0
- package/out/shared/utils.d.ts +24 -0
- package/out/shared/utils.d.ts.map +1 -0
- package/out/shared/utils.js +15 -0
- package/out/shared/utils.js.map +1 -0
- package/out/type.d.ts +23 -59
- package/out/type.d.ts.map +1 -1
- package/out/type.js +2 -137
- package/out/type.js.map +1 -1
- package/out/types/basis.d.ts +47 -0
- package/out/types/basis.d.ts.map +1 -0
- package/out/types/basis.js +15 -0
- package/out/types/basis.js.map +1 -0
- package/out/types/discriminate.d.ts +34 -0
- package/out/types/discriminate.d.ts.map +1 -0
- package/out/types/discriminate.js +120 -0
- package/out/types/discriminate.js.map +1 -0
- package/out/types/domain.d.ts +57 -0
- package/out/types/domain.d.ts.map +1 -0
- package/out/types/domain.js +41 -0
- package/out/types/domain.js.map +1 -0
- package/out/types/intersection.d.ts +127 -0
- package/out/types/intersection.d.ts.map +1 -0
- package/out/types/intersection.js +379 -0
- package/out/types/intersection.js.map +1 -0
- package/out/types/morph.d.ts +157 -0
- package/out/types/morph.d.ts.map +1 -0
- package/out/types/morph.js +99 -0
- package/out/types/morph.js.map +1 -0
- package/out/types/proto.d.ts +51 -0
- package/out/types/proto.d.ts.map +1 -0
- package/out/types/proto.js +60 -0
- package/out/types/proto.js.map +1 -0
- package/out/types/type.d.ts +143 -0
- package/out/types/type.d.ts.map +1 -0
- package/out/types/type.js +123 -0
- package/out/types/type.js.map +1 -0
- package/out/types/union.d.ts +71 -0
- package/out/types/union.d.ts.map +1 -0
- package/out/types/union.js +379 -0
- package/out/types/union.js.map +1 -0
- package/out/types/unit.d.ts +45 -0
- package/out/types/unit.d.ts.map +1 -0
- package/out/types/unit.js +56 -0
- package/out/types/unit.js.map +1 -0
- package/out/util.d.ts +30 -18
- package/out/util.d.ts.map +1 -1
- package/out/util.js +8 -7
- package/out/util.js.map +1 -1
- package/package.json +7 -3
- package/parser/definition.ts +73 -89
- package/parser/generic.ts +35 -36
- package/parser/objectLiteral.ts +143 -117
- 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 +82 -73
- package/parser/string/reduce/dynamic.ts +61 -46
- package/parser/string/reduce/shared.ts +1 -3
- package/parser/string/reduce/static.ts +65 -67
- package/parser/string/shift/operand/date.ts +12 -8
- package/parser/string/shift/operand/enclosed.ts +22 -17
- 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 +106 -147
- package/parser/string/shift/operator/bounds.ts +114 -106
- package/parser/string/shift/operator/divisor.ts +12 -14
- package/parser/string/shift/operator/operator.ts +35 -46
- package/parser/string/shift/scanner.ts +49 -46
- package/parser/string/string.ts +28 -32
- package/parser/tuple.ts +288 -308
- package/scope.ts +183 -425
- package/type.ts +82 -281
- package/__tests__/astUtils.test.ts +0 -17
- package/__tests__/jsdoc.test.ts +0 -64
- package/__tests__/nodeDefinitions.test.ts +0 -190
- package/__tests__/typeMethods.test.ts +0 -69
- 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/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 -32
- 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/shared.d.ts +0 -62
- package/out/parser/shared.d.ts.map +0 -1
- package/out/parser/shared.js +0 -56
- package/out/parser/shared.js.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/parser/semantic/semantic.ts +0 -143
- package/parser/shared.ts +0 -170
- package/util.ts +0 -36
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RawSchema } from "@arktype/schema"
|
|
2
2
|
import type { ErrorMessage, join } from "@arktype/util"
|
|
3
3
|
import type { DynamicState } from "../../reduce/dynamic.js"
|
|
4
4
|
import { writeUnclosedGroupMessage } from "../../reduce/shared.js"
|
|
@@ -17,7 +17,7 @@ export const parseGenericArgs = (
|
|
|
17
17
|
name: string,
|
|
18
18
|
params: string[],
|
|
19
19
|
s: DynamicState
|
|
20
|
-
) =>
|
|
20
|
+
): ParsedArgs<RawSchema[]> => $parseGenericArgs(name, params, s, [], [])
|
|
21
21
|
|
|
22
22
|
export type parseGenericArgs<
|
|
23
23
|
name extends string,
|
|
@@ -25,15 +25,15 @@ export type parseGenericArgs<
|
|
|
25
25
|
unscanned extends string,
|
|
26
26
|
$,
|
|
27
27
|
args
|
|
28
|
-
> =
|
|
28
|
+
> = $parseGenericArgs<name, params, unscanned, $, args, [], []>
|
|
29
29
|
|
|
30
|
-
const
|
|
30
|
+
const $parseGenericArgs = (
|
|
31
31
|
name: string,
|
|
32
32
|
params: string[],
|
|
33
33
|
s: DynamicState,
|
|
34
34
|
argDefs: string[],
|
|
35
|
-
argNodes:
|
|
36
|
-
): ParsedArgs<
|
|
35
|
+
argNodes: RawSchema[]
|
|
36
|
+
): ParsedArgs<RawSchema[]> => {
|
|
37
37
|
const argState = s.parseUntilFinalizer()
|
|
38
38
|
// remove the finalizing token from the argDef
|
|
39
39
|
argDefs.push(argState.scanner.scanned.slice(0, -1))
|
|
@@ -44,18 +44,16 @@ const parseGenericArgsRecurse = (
|
|
|
44
44
|
result: argNodes,
|
|
45
45
|
unscanned: argState.scanner.unscanned
|
|
46
46
|
}
|
|
47
|
-
} else {
|
|
48
|
-
return argState.error(
|
|
49
|
-
writeInvalidGenericArgsMessage(name, params, argDefs)
|
|
50
|
-
)
|
|
51
47
|
}
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
return argState.error(writeInvalidGenericArgsMessage(name, params, argDefs))
|
|
49
|
+
}
|
|
50
|
+
if (argState.finalizer === ",") {
|
|
51
|
+
return $parseGenericArgs(name, params, s, argDefs, argNodes)
|
|
54
52
|
}
|
|
55
53
|
return argState.error(writeUnclosedGroupMessage(">"))
|
|
56
54
|
}
|
|
57
55
|
|
|
58
|
-
type
|
|
56
|
+
type $parseGenericArgs<
|
|
59
57
|
name extends string,
|
|
60
58
|
params extends string[],
|
|
61
59
|
unscanned extends string,
|
|
@@ -63,31 +61,31 @@ type parseGenericArgsRecurse<
|
|
|
63
61
|
args,
|
|
64
62
|
argDefs extends string[],
|
|
65
63
|
argAsts extends unknown[]
|
|
66
|
-
> =
|
|
67
|
-
state.initialize<unscanned>,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
? {
|
|
64
|
+
> =
|
|
65
|
+
parseUntilFinalizer<state.initialize<unscanned>, $, args> extends (
|
|
66
|
+
infer finalArgState extends StaticState
|
|
67
|
+
) ?
|
|
68
|
+
{
|
|
72
69
|
defs: [
|
|
73
70
|
...argDefs,
|
|
74
|
-
finalArgState["scanned"] extends `${infer def}${"," | ">"}`
|
|
75
|
-
|
|
76
|
-
: finalArgState["scanned"]
|
|
71
|
+
finalArgState["scanned"] extends `${infer def}${"," | ">"}` ? def
|
|
72
|
+
: finalArgState["scanned"]
|
|
77
73
|
]
|
|
78
74
|
asts: [...argAsts, finalArgState["root"]]
|
|
79
75
|
unscanned: finalArgState["unscanned"]
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
76
|
+
} extends (
|
|
77
|
+
{
|
|
78
|
+
defs: infer nextDefs extends string[]
|
|
79
|
+
asts: infer nextAsts extends unknown[]
|
|
80
|
+
unscanned: infer nextUnscanned extends string
|
|
81
|
+
}
|
|
82
|
+
) ?
|
|
83
|
+
finalArgState["finalizer"] extends ">" ?
|
|
84
|
+
nextAsts["length"] extends params["length"] ?
|
|
85
|
+
ParsedArgs<nextAsts, nextUnscanned>
|
|
86
|
+
: state.error<writeInvalidGenericArgsMessage<name, params, nextDefs>>
|
|
87
|
+
: finalArgState["finalizer"] extends "," ?
|
|
88
|
+
$parseGenericArgs<
|
|
91
89
|
name,
|
|
92
90
|
params,
|
|
93
91
|
nextUnscanned,
|
|
@@ -95,12 +93,11 @@ type parseGenericArgsRecurse<
|
|
|
95
93
|
args,
|
|
96
94
|
nextDefs,
|
|
97
95
|
nextAsts
|
|
98
|
-
|
|
99
|
-
: finalArgState["finalizer"] extends ErrorMessage
|
|
100
|
-
? finalArgState
|
|
96
|
+
>
|
|
97
|
+
: finalArgState["finalizer"] extends ErrorMessage ? finalArgState
|
|
101
98
|
: state.error<writeUnclosedGroupMessage<">">>
|
|
102
|
-
:
|
|
103
|
-
:
|
|
99
|
+
: never
|
|
100
|
+
: never
|
|
104
101
|
|
|
105
102
|
export const writeInvalidGenericArgsMessage = <
|
|
106
103
|
name extends string,
|
|
@@ -110,10 +107,12 @@ export const writeInvalidGenericArgsMessage = <
|
|
|
110
107
|
name: name,
|
|
111
108
|
params: params,
|
|
112
109
|
argDefs: argDefs
|
|
113
|
-
) =>
|
|
114
|
-
`${name}<${params.join(", ")}> requires exactly ${
|
|
115
|
-
|
|
116
|
-
}${argDefs.length
|
|
110
|
+
): writeInvalidGenericArgsMessage<name, params, argDefs> =>
|
|
111
|
+
`${name}<${params.join(", ")}> requires exactly ${
|
|
112
|
+
params.length
|
|
113
|
+
} args (got ${argDefs.length}${
|
|
114
|
+
argDefs.length === 0 ? "" : `: ${argDefs.join(", ")}`
|
|
115
|
+
})` as never
|
|
117
116
|
|
|
118
117
|
export type writeInvalidGenericArgsMessage<
|
|
119
118
|
name extends string,
|
|
@@ -122,6 +121,8 @@ export type writeInvalidGenericArgsMessage<
|
|
|
122
121
|
> = `${name}<${join<
|
|
123
122
|
params,
|
|
124
123
|
", "
|
|
125
|
-
>}> requires exactly ${params["length"]} args (got ${argDefs["length"]}${argDefs["length"] extends
|
|
126
|
-
|
|
127
|
-
|
|
124
|
+
>}> requires exactly ${params["length"]} args (got ${argDefs["length"]}${argDefs["length"] extends (
|
|
125
|
+
0
|
|
126
|
+
) ?
|
|
127
|
+
""
|
|
128
|
+
: `: ${join<argDefs, ",">}`})`
|
|
@@ -1,48 +1,42 @@
|
|
|
1
1
|
import type { DynamicState } from "../../reduce/dynamic.js"
|
|
2
|
-
import type {
|
|
2
|
+
import type { StaticState, state } from "../../reduce/static.js"
|
|
3
3
|
import type { BaseCompletions } from "../../string.js"
|
|
4
4
|
import { Scanner } from "../scanner.js"
|
|
5
5
|
import {
|
|
6
|
-
enclosingChar,
|
|
7
|
-
parseEnclosed,
|
|
8
|
-
type EnclosingEndToken,
|
|
9
6
|
type EnclosingQuote,
|
|
10
|
-
type EnclosingStartToken
|
|
7
|
+
type EnclosingStartToken,
|
|
8
|
+
enclosingChar,
|
|
9
|
+
parseEnclosed
|
|
11
10
|
} from "./enclosed.js"
|
|
12
11
|
import { parseUnenclosed, writeMissingOperandMessage } from "./unenclosed.js"
|
|
13
12
|
|
|
14
13
|
export const parseOperand = (s: DynamicState): void =>
|
|
15
|
-
s.scanner.lookahead === ""
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
:
|
|
24
|
-
|
|
25
|
-
? parseEnclosed(s, `d${s.scanner.shift()}` as EnclosingStartToken)
|
|
26
|
-
: parseUnenclosed(s)
|
|
27
|
-
: parseUnenclosed(s)
|
|
14
|
+
s.scanner.lookahead === "" ? s.error(writeMissingOperandMessage(s))
|
|
15
|
+
: s.scanner.lookahead === "(" ? s.shiftedByOne().reduceGroupOpen()
|
|
16
|
+
: s.scanner.lookaheadIsIn(enclosingChar) ? parseEnclosed(s, s.scanner.shift())
|
|
17
|
+
: s.scanner.lookaheadIsIn(Scanner.whiteSpaceTokens) ?
|
|
18
|
+
parseOperand(s.shiftedByOne())
|
|
19
|
+
: s.scanner.lookahead === "d" ?
|
|
20
|
+
s.shiftedByOne().scanner.lookaheadIsIn(enclosingChar) ?
|
|
21
|
+
parseEnclosed(s, `d${s.scanner.shift()}` as EnclosingStartToken)
|
|
22
|
+
: parseUnenclosed(s)
|
|
23
|
+
: parseUnenclosed(s)
|
|
28
24
|
|
|
29
|
-
export type parseOperand<
|
|
30
|
-
s extends
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
: lookahead extends
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
: parseUnenclosed<s, $, args>
|
|
48
|
-
: state.completion<`${s["scanned"]}${BaseCompletions<$, args>}`>
|
|
25
|
+
export type parseOperand<s extends StaticState, $, args> =
|
|
26
|
+
s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ?
|
|
27
|
+
lookahead extends "(" ? state.reduceGroupOpen<s, unscanned>
|
|
28
|
+
: lookahead extends EnclosingStartToken ?
|
|
29
|
+
parseEnclosed<s, lookahead, unscanned>
|
|
30
|
+
: lookahead extends Scanner.WhiteSpaceToken ?
|
|
31
|
+
parseOperand<state.scanTo<s, unscanned>, $, args>
|
|
32
|
+
: lookahead extends "d" ?
|
|
33
|
+
unscanned extends (
|
|
34
|
+
Scanner.shift<
|
|
35
|
+
infer enclosing extends EnclosingQuote,
|
|
36
|
+
infer nextUnscanned
|
|
37
|
+
>
|
|
38
|
+
) ?
|
|
39
|
+
parseEnclosed<s, `d${enclosing}`, nextUnscanned>
|
|
40
|
+
: parseUnenclosed<s, $, args>
|
|
41
|
+
: parseUnenclosed<s, $, args>
|
|
42
|
+
: state.completion<`${s["scanned"]}${BaseCompletions<$, args>}`>
|
|
@@ -1,30 +1,37 @@
|
|
|
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 SchemaModule,
|
|
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,
|
|
10
14
|
type join,
|
|
11
|
-
|
|
15
|
+
printable,
|
|
16
|
+
throwParseError,
|
|
17
|
+
tryParseNumber,
|
|
18
|
+
tryParseWellFormedBigint
|
|
12
19
|
} from "@arktype/util"
|
|
13
|
-
import type {
|
|
14
|
-
import type {
|
|
15
|
-
import {
|
|
16
|
-
import
|
|
20
|
+
import type { Generic } from "../../../../generic.js"
|
|
21
|
+
import type { Module } from "../../../../module.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
36
|
if (token === "keyof") {
|
|
30
37
|
s.addPrefix("keyof")
|
|
@@ -33,49 +40,44 @@ export const parseUnenclosed = (s: DynamicState) => {
|
|
|
33
40
|
}
|
|
34
41
|
}
|
|
35
42
|
|
|
36
|
-
export type parseUnenclosed<
|
|
37
|
-
s extends
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
? result extends ErrorMessage<infer message>
|
|
47
|
-
? state.error<message>
|
|
48
|
-
: result extends keyof $
|
|
49
|
-
? $[result] extends GenericProps
|
|
50
|
-
? parseGenericInstantiation<
|
|
43
|
+
export type parseUnenclosed<s extends StaticState, $, args> =
|
|
44
|
+
Scanner.shiftUntilNextTerminator<s["unscanned"]> extends (
|
|
45
|
+
Scanner.shiftResult<infer token, infer unscanned>
|
|
46
|
+
) ?
|
|
47
|
+
token extends "keyof" ? state.addPrefix<s, "keyof", unscanned>
|
|
48
|
+
: tryResolve<s, token, $, args> extends infer result ?
|
|
49
|
+
result extends ErrorMessage<infer message> ? state.error<message>
|
|
50
|
+
: result extends keyof $ ?
|
|
51
|
+
$[result] extends GenericProps ?
|
|
52
|
+
parseGenericInstantiation<
|
|
51
53
|
token,
|
|
52
54
|
$[result],
|
|
53
55
|
state.scanTo<s, unscanned>,
|
|
54
56
|
$,
|
|
55
57
|
args
|
|
56
|
-
|
|
57
|
-
:
|
|
58
|
-
:
|
|
59
|
-
:
|
|
60
|
-
:
|
|
58
|
+
>
|
|
59
|
+
: state.setRoot<s, result, unscanned>
|
|
60
|
+
: state.setRoot<s, result, unscanned>
|
|
61
|
+
: never
|
|
62
|
+
: never
|
|
61
63
|
|
|
62
64
|
export const parseGenericInstantiation = (
|
|
63
65
|
name: string,
|
|
64
66
|
g: Generic,
|
|
65
67
|
s: DynamicState
|
|
66
|
-
):
|
|
68
|
+
): RawSchema => {
|
|
67
69
|
s.scanner.shiftUntilNonWhitespace()
|
|
68
70
|
const lookahead = s.scanner.shift()
|
|
69
71
|
if (lookahead !== "<") {
|
|
70
|
-
return s.error(writeInvalidGenericArgsMessage(name, g.
|
|
72
|
+
return s.error(writeInvalidGenericArgsMessage(name, g.params, []))
|
|
71
73
|
}
|
|
72
|
-
const parsedArgs = parseGenericArgs(name, g.
|
|
74
|
+
const parsedArgs = parseGenericArgs(name, g.params, s)
|
|
73
75
|
const remainingChars = parsedArgs.unscanned.length
|
|
74
76
|
// set the scanner position to where the args scanner left off
|
|
75
77
|
s.scanner.jumpToIndex(
|
|
76
78
|
remainingChars === 0 ? s.scanner.length : -remainingChars
|
|
77
79
|
)
|
|
78
|
-
return g(...parsedArgs.result)
|
|
80
|
+
return g(...parsedArgs.result) as never
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
export type parseGenericInstantiation<
|
|
@@ -85,107 +87,78 @@ export type parseGenericInstantiation<
|
|
|
85
87
|
$,
|
|
86
88
|
args
|
|
87
89
|
// 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 =>
|
|
90
|
+
> =
|
|
91
|
+
Scanner.skipWhitespace<s["unscanned"]> extends `<${infer unscanned}` ?
|
|
92
|
+
parseGenericArgs<name, g["params"], unscanned, $, args> extends (
|
|
93
|
+
infer result
|
|
94
|
+
) ?
|
|
95
|
+
result extends ParsedArgs<infer argAsts, infer nextUnscanned> ?
|
|
96
|
+
state.setRoot<s, GenericInstantiationAst<g, argAsts>, nextUnscanned>
|
|
97
|
+
: // propagate error
|
|
98
|
+
result
|
|
99
|
+
: never
|
|
100
|
+
: state.error<writeInvalidGenericArgsMessage<name, g["params"], []>>
|
|
101
|
+
|
|
102
|
+
const unenclosedToNode = (s: DynamicState, token: string): RawSchema =>
|
|
104
103
|
maybeParseReference(s, token) ??
|
|
105
104
|
maybeParseUnenclosedLiteral(s, token) ??
|
|
106
105
|
s.error(
|
|
107
|
-
token === ""
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
token === "" ? writeMissingOperandMessage(s)
|
|
107
|
+
: token[0] === "#" ?
|
|
108
|
+
writePrefixedPrivateReferenceMessage(token as PrivateDeclaration)
|
|
109
|
+
: writeUnresolvableMessage(token)
|
|
110
110
|
)
|
|
111
111
|
|
|
112
112
|
const maybeParseReference = (
|
|
113
113
|
s: DynamicState,
|
|
114
114
|
token: string
|
|
115
|
-
):
|
|
116
|
-
if (s.ctx.args?.[token])
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (resolution
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (resolution === undefined) {
|
|
124
|
-
return
|
|
125
|
-
}
|
|
126
|
-
if (hasArkKind(resolution, "generic")) {
|
|
127
|
-
return parseGenericInstantiation(token, resolution, s)
|
|
128
|
-
}
|
|
115
|
+
): RawSchema | undefined => {
|
|
116
|
+
if (s.ctx.args?.[token]) return s.ctx.args[token].raw
|
|
117
|
+
const resolution = s.ctx.$.maybeResolve(token)
|
|
118
|
+
// TODO: centralize member creation
|
|
119
|
+
if (resolution instanceof RawSchema) return resolution.bindScope(s.ctx.$)
|
|
120
|
+
if (resolution === undefined) return
|
|
121
|
+
if (hasArkKind(resolution, "generic"))
|
|
122
|
+
return parseGenericInstantiation(token, resolution as Generic, s)
|
|
129
123
|
return throwParseError(`Unexpected resolution ${printable(resolution)}`)
|
|
130
124
|
}
|
|
131
125
|
|
|
132
126
|
const maybeParseUnenclosedLiteral = (
|
|
133
127
|
s: DynamicState,
|
|
134
128
|
token: string
|
|
135
|
-
):
|
|
129
|
+
): RawSchema | undefined => {
|
|
136
130
|
const maybeNumber = tryParseNumber(token, { strict: true })
|
|
137
131
|
if (maybeNumber !== undefined) {
|
|
138
|
-
return
|
|
132
|
+
return s.ctx.$.node("unit", { unit: maybeNumber })
|
|
139
133
|
}
|
|
140
134
|
const maybeBigint = tryParseWellFormedBigint(token)
|
|
141
135
|
if (maybeBigint !== undefined) {
|
|
142
|
-
return
|
|
136
|
+
return s.ctx.$.node("unit", { unit: maybeBigint })
|
|
143
137
|
}
|
|
144
138
|
}
|
|
145
139
|
|
|
146
|
-
type tryResolve<
|
|
147
|
-
|
|
148
|
-
token extends
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
?
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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`
|
|
140
|
+
type tryResolve<s extends StaticState, token extends string, $, args> =
|
|
141
|
+
token extends keyof $ ? token
|
|
142
|
+
: `#${token}` extends keyof $ ? token
|
|
143
|
+
: token extends keyof args ? token
|
|
144
|
+
: token extends `${number}` ? token
|
|
145
|
+
: token extends BigintLiteral ? token
|
|
146
|
+
: token extends (
|
|
147
|
+
`${infer submodule extends keyof $ & string}.${infer reference}`
|
|
148
|
+
) ?
|
|
149
|
+
$[submodule] extends (
|
|
150
|
+
SchemaModule<infer sub$> | Module<infer sub$> // TODO: shouldn't need both checks?
|
|
151
|
+
) ?
|
|
152
|
+
reference extends keyof sub$ ? token
|
|
153
|
+
: unknown extends sub$ ?
|
|
154
|
+
// not sure why we need the additional check here, but for now TS seems to
|
|
155
|
+
// hit this branch for a non-scope dot access rather than failing
|
|
156
|
+
// initially when we try to infer r. if this can be removed without breaking
|
|
157
|
+
// any submodule test cases, do it!
|
|
158
|
+
ErrorMessage<writeNonSubmoduleDotMessage<submodule>>
|
|
159
|
+
: unresolvableError<s, reference, $[submodule], args, [submodule]>
|
|
160
|
+
: ErrorMessage<writeNonSubmoduleDotMessage<submodule>>
|
|
161
|
+
: unresolvableError<s, token, $, args, []>
|
|
189
162
|
|
|
190
163
|
/** Provide valid completions for the current token, or fallback to an
|
|
191
164
|
* unresolvable error if there are none */
|
|
@@ -195,14 +168,15 @@ export type unresolvableError<
|
|
|
195
168
|
$,
|
|
196
169
|
args,
|
|
197
170
|
submodulePath extends string[]
|
|
198
|
-
> =
|
|
199
|
-
?
|
|
171
|
+
> =
|
|
172
|
+
validReferenceFromToken<token, $, args, submodulePath> extends never ?
|
|
173
|
+
ErrorMessage<
|
|
200
174
|
writeUnresolvableMessage<qualifiedReference<token, submodulePath>>
|
|
201
|
-
|
|
202
|
-
:
|
|
175
|
+
>
|
|
176
|
+
: Completion<`${s["scanned"]}${qualifiedReference<
|
|
203
177
|
validReferenceFromToken<token, $, args, submodulePath>,
|
|
204
178
|
submodulePath
|
|
205
|
-
|
|
179
|
+
>}`>
|
|
206
180
|
|
|
207
181
|
type qualifiedReference<
|
|
208
182
|
reference extends string,
|
|
@@ -219,33 +193,18 @@ type validReferenceFromToken<
|
|
|
219
193
|
`${token}${string}`
|
|
220
194
|
>
|
|
221
195
|
|
|
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) => {
|
|
196
|
+
export const writeMissingOperandMessage = (s: DynamicState): string => {
|
|
230
197
|
const operator = s.previousOperator()
|
|
231
|
-
return operator
|
|
232
|
-
|
|
233
|
-
:
|
|
198
|
+
return operator ?
|
|
199
|
+
writeMissingRightOperandMessage(operator, s.scanner.unscanned)
|
|
200
|
+
: writeExpressionExpectedMessage(s.scanner.unscanned)
|
|
234
201
|
}
|
|
235
202
|
|
|
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
203
|
export type writeMissingRightOperandMessage<
|
|
244
204
|
token extends string,
|
|
245
205
|
unscanned extends string = ""
|
|
246
|
-
> = `Token '${token}' requires a right operand${unscanned extends ""
|
|
247
|
-
|
|
248
|
-
: ` before '${unscanned}'`}`
|
|
206
|
+
> = `Token '${token}' requires a right operand${unscanned extends "" ? ""
|
|
207
|
+
: ` before '${unscanned}'`}`
|
|
249
208
|
|
|
250
209
|
export const writeMissingRightOperandMessage = <
|
|
251
210
|
token extends string,
|
|
@@ -260,9 +219,9 @@ export const writeMissingRightOperandMessage = <
|
|
|
260
219
|
|
|
261
220
|
export const writeExpressionExpectedMessage = <unscanned extends string>(
|
|
262
221
|
unscanned: unscanned
|
|
263
|
-
)
|
|
222
|
+
): writeExpressionExpectedMessage<unscanned> =>
|
|
223
|
+
`Expected an expression${unscanned ? ` before '${unscanned}'` : ""}` as never
|
|
264
224
|
|
|
265
225
|
export type writeExpressionExpectedMessage<unscanned extends string> =
|
|
266
|
-
`Expected an expression${unscanned extends ""
|
|
267
|
-
|
|
268
|
-
: ` before '${unscanned}'`}`
|
|
226
|
+
`Expected an expression${unscanned extends "" ? ""
|
|
227
|
+
: ` before '${unscanned}'`}`
|