@tslite/checker 1.0.0 → 1.2.0
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/dist/chunk-BW42VHMU.js +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +116 -14
- package/dist/index.d.ts +116 -14
- package/dist/index.js +1 -1
- package/dist/types/index.cjs +1 -0
- package/dist/types/index.d.cts +948 -0
- package/dist/types/index.d.ts +948 -0
- package/dist/types/index.js +1 -0
- package/package.json +13 -7
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Schema, Schemes, TypeScheme, ObjectSchema, Completion } from '
|
|
2
|
-
export
|
|
3
|
-
import { Scope as Scope$1, BaseNode, Node, types
|
|
1
|
+
import { Schema, Schemes, TypeScheme, ObjectSchema, Completion } from './types/index.cjs';
|
|
2
|
+
export { AnySchema, ApplySchema, ArraySchema, Bindings, DEFAULT_TYPE_LIMITS, Discovery, ElementFlag, FnSchema, GuardSig, INSTANTIATION_COUNT_LIMIT, INSTANTIATION_DEPTH_LIMIT, Incompatibility, IncompatibilityKind, IndexSchema, Instantiation, InstantiationLimitError, KeyofSchema, LiteralSchema, MappedSchema, OverloadSchema, Param, Prop, ScalarSchema, TYPE_EVAL_DEPTH_LIMIT, TupleSchema, TypeEvalLimitError, TypeEvalLimits, TypeForm, TypePosition, UnionSchema, UnionTooComplexError, UnknownSchema, VarCandidates, VarSchema, apparentType, asLiteralOrigin, baseLiteralType, bindTypeParams, comparable, configureTypeLimits, contravariantInference, covariantInference, discover, equals, erasedSignature, expand1, flagAt, format, formatTypeArgs, formatTypeDiff, freeVars, groundVars, inferFromCandidates, inferredTypes, instantiate, instantiateInContextOf, instantiateLoose, isMissingType, isNumericLiteralName, isObjectOrArrayLiteral, isScheme, isSerializable, isVariadicTuple, join, joinAll, missingType, normalizeUnion, ownProp, renameTypeParams, resetInstantiationCount, resetTypeLimits, resolveConditional, resolveOp, resolveTypeOp, restIndex, s, sampleValue, silentNever, substitute, subtype, typeAtPosition, typeDiff, typeFeatures, typeLimits, typeNeedsParens, typeParamArity, unify, widen, widenInferred, widenLiteral, widenOrigin, widenType, withoutUndefined } from './types/index.cjs';
|
|
3
|
+
import { Scope as Scope$1, BaseNode, Node, types, SourceLocation, Expression } from '@tslite/ast';
|
|
4
4
|
import { CapabilityProfile, CompiledProfile } from '@tslite/capability';
|
|
5
5
|
import { Span } from '@tslite/language-service';
|
|
6
6
|
|
|
@@ -17,9 +17,11 @@ declare const childScope: (parent: Scope, vars: Record<string, Schema>) => Scope
|
|
|
17
17
|
declare const lookup: (scope: Scope, name: string) => Schema | undefined;
|
|
18
18
|
/**
|
|
19
19
|
* Todos os nomes visíveis a partir de `scope`, com shadowing — o binding mais
|
|
20
|
-
* interno vence. É o que alimenta o autocomplete de identificadores.
|
|
21
|
-
*
|
|
22
|
-
*
|
|
20
|
+
* interno vence. É o que alimenta o autocomplete de identificadores. Duas
|
|
21
|
+
* chaves moram no mesmo escopo e não são nomes: a que tem `.` é um caminho
|
|
22
|
+
* estreitado por guard (`narrow`, D13), e a que termina em `#` é o tipo
|
|
23
|
+
* DECLARADO de um binding mutável (D63) — nenhum identificador tem esses
|
|
24
|
+
* caracteres.
|
|
23
25
|
*/
|
|
24
26
|
declare const visibleNames: (scope: Scope) => Map<string, Schema>;
|
|
25
27
|
/**
|
|
@@ -112,7 +114,7 @@ declare const resolveNamed: (env: Env, name: string) => Schema | undefined;
|
|
|
112
114
|
declare const resolveScheme: (env: Env, name: string) => TypeScheme | undefined;
|
|
113
115
|
|
|
114
116
|
type Severity = "error" | "warning";
|
|
115
|
-
type DiagnosticCode = "not-assignable" | "unknown-name" | "not-callable" | "no-such-member" | "not-object" | "const-needs-init" | "cannot-redeclare" | "unknown-module" | "not-a-schema" | "type-as-value" | "asserter-needs-name" | "shadows-schema" | "missing-argument" | "excess-argument" | "excess-property" | "spread-argument" | "required-after-optional" | "not-iterable" | "props-mismatch" | "no-matching-overload" | "constraint-violation" | "wrong-type-argument-count" | "unsupported" | "forbidden-member" | "unused-name" | "assign-to-const" | "readonly-write" | "cast-unsound" | "unprovable-value" | "not-arithmetic-operand" | "operator-not-applicable" | "implicit-coercion" | "node-not-allowed" | "name-not-allowed" | "type-feature-not-allowed" | "any-not-allowed" | "narrowing-cast-not-allowed" | "too-deep" | "too-complex-union" | "too-large" | "wrong-result-type";
|
|
117
|
+
type DiagnosticCode = "not-assignable" | "unknown-name" | "not-callable" | "no-such-member" | "not-object" | "possibly-nullish" | "unknown-value" | "const-needs-init" | "cannot-redeclare" | "circular-type-alias" | "circular-type-annotation" | "unknown-module" | "not-a-schema" | "type-as-value" | "asserter-needs-name" | "shadows-schema" | "missing-argument" | "excess-argument" | "excess-property" | "spread-argument" | "required-after-optional" | "not-iterable" | "props-mismatch" | "no-matching-overload" | "constraint-violation" | "wrong-type-argument-count" | "unsupported" | "forbidden-member" | "unused-name" | "assign-to-const" | "readonly-write" | "cast-unsound" | "unprovable-value" | "not-arithmetic-operand" | "operator-not-applicable" | "implicit-coercion" | "node-not-allowed" | "name-not-allowed" | "type-feature-not-allowed" | "any-not-allowed" | "narrowing-cast-not-allowed" | "too-deep" | "too-complex-union" | "too-large" | "wrong-result-type";
|
|
116
118
|
/**
|
|
117
119
|
* A **classe** do diagnóstico — espelha a divisão de passes do `tsc` (que nós
|
|
118
120
|
* fundimos num walk só): `semantic` é o que o **binder** do tsc pega (validade do
|
|
@@ -187,6 +189,29 @@ declare const diag: {
|
|
|
187
189
|
notCallable: (node: BaseNode, type: Schema) => Diagnostic;
|
|
188
190
|
noSuchMember: (node: BaseNode, type: Schema, key: string) => Diagnostic;
|
|
189
191
|
notObject: (node: BaseNode, type: Schema) => Diagnostic;
|
|
192
|
+
/**
|
|
193
|
+
* Ler ou chamar através de um valor que pode ser `null`/`undefined` — o
|
|
194
|
+
* `checkNonNullTypeWithReporter` do tsc (`checker.ts:24098`), que tem uma mensagem por
|
|
195
|
+
* combinação, e a variante "Cannot invoke" quando o valor é chamado.
|
|
196
|
+
*/
|
|
197
|
+
possiblyNullish: (node: BaseNode, nullish: {
|
|
198
|
+
readonly null: boolean;
|
|
199
|
+
readonly undefined: boolean;
|
|
200
|
+
}, invoked?: boolean) => Diagnostic;
|
|
201
|
+
/**
|
|
202
|
+
* Usar um valor `unknown` como objeto — ler dele, chamá-lo, indexá-lo ou operar
|
|
203
|
+
* sobre ele. É o mesmo `checkNonNullTypeWithReporter` (`checker.ts:24102`), no ramo
|
|
204
|
+
* que vem ANTES do nullish e em três linhas:
|
|
205
|
+
*
|
|
206
|
+
* if (strictNullChecks && type.flags & TypeFlags.Unknown) {
|
|
207
|
+
* error(node, Diagnostics.Object_is_of_type_unknown);
|
|
208
|
+
* return errorType;
|
|
209
|
+
* }
|
|
210
|
+
*
|
|
211
|
+
* Um código só e uma mensagem só, para os seis usos (o TS2571 da 3.9.10 — o
|
|
212
|
+
* TS18046 é de versão posterior e não existe na tag).
|
|
213
|
+
*/
|
|
214
|
+
unknownValue: (node: BaseNode) => Diagnostic;
|
|
190
215
|
constNeedsInit: (node: BaseNode) => Diagnostic;
|
|
191
216
|
missingArgument: (node: BaseNode, name: string, expected: Schema) => Diagnostic;
|
|
192
217
|
notASchema: (node: BaseNode, name: string) => Diagnostic;
|
|
@@ -195,7 +220,21 @@ declare const diag: {
|
|
|
195
220
|
shadowsSchema: (node: BaseNode, name: string) => Diagnostic;
|
|
196
221
|
unknownModule: (node: BaseNode, source: string) => Diagnostic;
|
|
197
222
|
cannotRedeclare: (node: BaseNode, name: string) => Diagnostic;
|
|
223
|
+
circularTypeAlias: (node: BaseNode, name: string) => Diagnostic;
|
|
224
|
+
circularTypeAnnotation: (node: BaseNode, name: string) => Diagnostic;
|
|
198
225
|
excessArgument: (node: BaseNode, expected: number, got: number) => Diagnostic;
|
|
226
|
+
/**
|
|
227
|
+
* A ARIDADE de uma chamada, com o texto do `getArgumentArityError` do tsc
|
|
228
|
+
* (`checker.ts:25477`): `Expected {range} arguments, but got {got}.` (TS2554), e
|
|
229
|
+
* `Expected at least {min} arguments, but got {got}.` quando a assinatura tem rest
|
|
230
|
+
* (TS2555). O `range` é `min` ou `min-max`, e o plural é sempre plural, como lá.
|
|
231
|
+
*
|
|
232
|
+
* O CÓDIGO continua dizendo a direção — `missing-argument` quando faltam, e
|
|
233
|
+
* `excess-argument` quando sobram —, que é informação que o texto do tsc perdeu ao
|
|
234
|
+
* usar um único TS2554 para os dois. A régua é a D2: o código é o contrato, a mensagem
|
|
235
|
+
* é prosa.
|
|
236
|
+
*/
|
|
237
|
+
argumentArity: (node: BaseNode, range: string, got: number, kind: "missing" | "excess", atLeast?: boolean) => Diagnostic;
|
|
199
238
|
excessProperty: (node: BaseNode, name: string, target: Schema) => Diagnostic;
|
|
200
239
|
spreadArgument: (node: BaseNode) => Diagnostic;
|
|
201
240
|
requiredAfterOptional: (node: BaseNode) => Diagnostic;
|
|
@@ -207,10 +246,12 @@ declare const diag: {
|
|
|
207
246
|
/**
|
|
208
247
|
* Argumento de tipo explícito com aridade errada. Assinatura **sem** type params
|
|
209
248
|
* declarados conta como `expected: 0` — é o que o tsc faz quando
|
|
210
|
-
* `Signature.typeParameters` é `undefined` (ele nunca infere a lista).
|
|
211
|
-
* texto do TS2558.
|
|
249
|
+
* `Signature.typeParameters` é `undefined` (ele nunca infere a lista). Com default, o
|
|
250
|
+
* esperado é a faixa (`"1-2"`). Mensagem no texto do TS2558, que é sempre plural.
|
|
212
251
|
*/
|
|
213
|
-
wrongTypeArgumentCount: (node: BaseNode, expected: number, got: number) => Diagnostic;
|
|
252
|
+
wrongTypeArgumentCount: (node: BaseNode, expected: number | string, got: number) => Diagnostic;
|
|
253
|
+
/** Nenhuma sobrecarga aceita a aridade, e há uma abaixo e outra acima (≅ TS2743). */
|
|
254
|
+
noOverloadTypeArgumentCount: (node: BaseNode, got: number, below: number, above: number) => Diagnostic;
|
|
214
255
|
/** Referência a um alias com aridade errada — as frases do tsc: TS2315 para um
|
|
215
256
|
* tipo que não é genérico, TS2314 para o resto (com o intervalo quando há default). */
|
|
216
257
|
genericTypeArity: (node: BaseNode, name: string, min: number, max: number) => Diagnostic;
|
|
@@ -491,7 +532,7 @@ type BinaryOpCategory = "additive" | "arithmetic" | "bitwise" | "relational" | "
|
|
|
491
532
|
*/
|
|
492
533
|
type OpResult = "number" | "boolean" | "string" | "additive";
|
|
493
534
|
interface BinaryOpSpec {
|
|
494
|
-
readonly op: types
|
|
535
|
+
readonly op: types.BinaryOperator;
|
|
495
536
|
readonly category: BinaryOpCategory;
|
|
496
537
|
readonly result: OpResult;
|
|
497
538
|
}
|
|
@@ -503,14 +544,14 @@ declare const BINARY_OP: ReadonlyMap<string, BinaryOpSpec>;
|
|
|
503
544
|
* condicional e NÃO tem schema fixo: quem chama trata (ver `binaryType` no checker). */
|
|
504
545
|
declare const opResultSchema: (r: Exclude<OpResult, "additive">) => Schema;
|
|
505
546
|
interface UnaryOpSpec {
|
|
506
|
-
readonly op: types
|
|
547
|
+
readonly op: types.UnaryOperator;
|
|
507
548
|
/** O tipo ao qual o resultado é ASSIGNÁVEL (upper bound). O `unaryType` faz
|
|
508
549
|
* folding de literal (`-1`→`-1`, `!0`→`true`), então o real é um subtipo disto. */
|
|
509
550
|
readonly result: "number" | "boolean" | "string" | "undefined";
|
|
510
551
|
}
|
|
511
552
|
declare const UNARY_OPS: readonly UnaryOpSpec[];
|
|
512
553
|
interface LogicalOpSpec {
|
|
513
|
-
readonly op: types
|
|
554
|
+
readonly op: types.LogicalOperator;
|
|
514
555
|
}
|
|
515
556
|
/** Os lógicos COMPÕEM o tipo dos operandos (`a && b` refina; não é tipo fixo) —
|
|
516
557
|
* por isso sem `result`. No slot, um lógico serve quando os operandos servem. */
|
|
@@ -559,6 +600,67 @@ type BindingMap = WeakMap<BaseNode, BaseNode>;
|
|
|
559
600
|
*/
|
|
560
601
|
declare function collectBindings(root: BaseNode): BindingMap;
|
|
561
602
|
|
|
603
|
+
/** O que um nome denota. */
|
|
604
|
+
type ReferenceSymbol = {
|
|
605
|
+
readonly kind: "local";
|
|
606
|
+
/** O `Identifier` que declara — a identidade, por referência. */
|
|
607
|
+
readonly declaration: BaseNode;
|
|
608
|
+
} | {
|
|
609
|
+
readonly kind: "environment";
|
|
610
|
+
/** O caminho a partir da raiz da DI: `["params"]`, `["params", "id"]`. */
|
|
611
|
+
readonly path: readonly string[];
|
|
612
|
+
};
|
|
613
|
+
/**
|
|
614
|
+
* Onde o nome aparece como SHORTHAND, e portanto nomeia duas coisas ao mesmo tempo
|
|
615
|
+
* — o `prefixText`/`suffixText` do `findRenameLocations` do TypeScript:
|
|
616
|
+
*
|
|
617
|
+
* - `"property"`: o nome é o valor e também a PROPRIEDADE (`{ x }`, ou `const { x
|
|
618
|
+
* } = o` renomeando o `x` local). A propriedade continua com o nome antigo:
|
|
619
|
+
* `{ x: x2 }`;
|
|
620
|
+
* - `"binding"`: o nome é a propriedade e também um BINDING (`const { id } =
|
|
621
|
+
* params`, renomeando o `params.id`). O binding continua com o nome antigo:
|
|
622
|
+
* `{ id2: id }`;
|
|
623
|
+
* - `"import"`: o nome importado é também o local (`import { a } from "m"`,
|
|
624
|
+
* renomeando o local): `import { a as a2 }`.
|
|
625
|
+
*/
|
|
626
|
+
type Shorthand = "property" | "binding" | "import";
|
|
627
|
+
/** Uma referência a tipo nomeado escrita numa anotação (a `typeRefs` do parser). */
|
|
628
|
+
interface TypeRefSite {
|
|
629
|
+
readonly name: string;
|
|
630
|
+
readonly loc: SourceLocation;
|
|
631
|
+
}
|
|
632
|
+
/** Um lugar onde o nome aparece. */
|
|
633
|
+
type Occurrence = {
|
|
634
|
+
/** O nó cujo texto É o nome: `Identifier`, `JSXIdentifier` ou a chave literal. */
|
|
635
|
+
readonly site: "node";
|
|
636
|
+
readonly node: BaseNode;
|
|
637
|
+
readonly symbol: ReferenceSymbol;
|
|
638
|
+
/** A declaração do símbolo, e não um uso. */
|
|
639
|
+
readonly isDeclaration?: true;
|
|
640
|
+
readonly shorthand?: Shorthand;
|
|
641
|
+
} | {
|
|
642
|
+
/** Um segmento do `typeof a.b` numa anotação: o nó não tem posição por segmento. */
|
|
643
|
+
readonly site: "typeQuery";
|
|
644
|
+
readonly node: BaseNode;
|
|
645
|
+
readonly segment: number;
|
|
646
|
+
readonly symbol: ReferenceSymbol;
|
|
647
|
+
} | {
|
|
648
|
+
/** Um nome de tipo numa anotação, que não é nó (E6 do editor). */
|
|
649
|
+
readonly site: "typeRef";
|
|
650
|
+
readonly ref: TypeRefSite;
|
|
651
|
+
readonly symbol: ReferenceSymbol;
|
|
652
|
+
};
|
|
653
|
+
/** Os dois símbolos são o mesmo? */
|
|
654
|
+
declare function sameSymbol(a: ReferenceSymbol, b: ReferenceSymbol): boolean;
|
|
655
|
+
/**
|
|
656
|
+
* Todas as ocorrências de nome do programa, cada uma com o símbolo que denota.
|
|
657
|
+
*
|
|
658
|
+
* Quem renomeia escolhe o símbolo sob o cursor (`occurrenceAt` do editor) e pega as
|
|
659
|
+
* ocorrências com `sameSymbol`; quem renomeia um caminho do ambiente sem cursor (o
|
|
660
|
+
* host que renomeou a declaração no `Env`) filtra pelo caminho direto.
|
|
661
|
+
*/
|
|
662
|
+
declare function collectReferences(root: BaseNode): readonly Occurrence[];
|
|
663
|
+
|
|
562
664
|
/** Anota uma ligação/parâmetro: `x` → `x: T`. */
|
|
563
665
|
declare const annotate: <N extends BaseNode>(node: N, type: Schema) => N & {
|
|
564
666
|
typeAnnotation: Schema;
|
|
@@ -681,4 +783,4 @@ declare function anchorDiagnostics<A>(root: object, diagnostics: readonly Diagno
|
|
|
681
783
|
*/
|
|
682
784
|
declare function spanOf(text: string, loc: SourceLocation | null | undefined): Span | undefined;
|
|
683
785
|
|
|
684
|
-
export { type AnchorDiagnosticsOptions, type AnchoredDiagnostic, type Anchors, BINARY_OP, BINARY_OPS, type BinaryOpCategory, type BinaryOpSpec, type BindingMap, type CheckOptions, type CheckResult, type CheckerErrorCode, type Diagnostic, type DiagnosticCode, type DiagnosticData, type DiagnosticKind, type DiagnosticSink, type Env, type EnvOptions, FUNCTION_KINDS, type Guard, type GuardContext, LOGICAL_OPS, type LogicalOpSpec, type LowerValueOptions, type MissingProperty, type OpResult, type Profile, type Scope, type Severity, type TypeOverlay, UNARY_OPS, type UnaryOpSpec, type UnusedOptions, anchorDiagnostics, annotate, annotateReturn, asExpression, binaryOpsProducing, calleeAllowlist, capabilityNodes, check, childScope, collectBindings, collectMutations, collectUnused, componentProps, componentPropsOf, contextualTypeAt, createAnchors, createEnv, createSink, diag, diagnosticsAt, extractModuleType, fromCapability, guard, guardsFromCompiled, lookup, lowerValue, makeDiagnostic, maxArgs, maxCallNesting, maxDepth, maxFunctionNesting, maxNestingOf, maxNodes, memberCompletions, memberDepth, opResultSchema, resolveNamed, resolveScheme, resultType, rootScope, scopeAt, scopeCompletions, spanOf, typeAt, unaryOpsProducing, visibleNames };
|
|
786
|
+
export { type AnchorDiagnosticsOptions, type AnchoredDiagnostic, type Anchors, BINARY_OP, BINARY_OPS, type BinaryOpCategory, type BinaryOpSpec, type BindingMap, type CheckOptions, type CheckResult, type CheckerErrorCode, Completion, type Diagnostic, type DiagnosticCode, type DiagnosticData, type DiagnosticKind, type DiagnosticSink, type Env, type EnvOptions, FUNCTION_KINDS, type Guard, type GuardContext, LOGICAL_OPS, type LogicalOpSpec, type LowerValueOptions, type MissingProperty, ObjectSchema, type Occurrence, type OpResult, type Profile, type ReferenceSymbol, Schema, Schemes, type Scope, type Severity, type Shorthand, type TypeOverlay, type TypeRefSite, TypeScheme, UNARY_OPS, type UnaryOpSpec, type UnusedOptions, anchorDiagnostics, annotate, annotateReturn, asExpression, binaryOpsProducing, calleeAllowlist, capabilityNodes, check, childScope, collectBindings, collectMutations, collectReferences, collectUnused, componentProps, componentPropsOf, contextualTypeAt, createAnchors, createEnv, createSink, diag, diagnosticsAt, extractModuleType, fromCapability, guard, guardsFromCompiled, lookup, lowerValue, makeDiagnostic, maxArgs, maxCallNesting, maxDepth, maxFunctionNesting, maxNestingOf, maxNodes, memberCompletions, memberDepth, opResultSchema, resolveNamed, resolveScheme, resultType, rootScope, sameSymbol, scopeAt, scopeCompletions, spanOf, typeAt, unaryOpsProducing, visibleNames };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Schema, Schemes, TypeScheme, ObjectSchema, Completion } from '
|
|
2
|
-
export
|
|
3
|
-
import { Scope as Scope$1, BaseNode, Node, types
|
|
1
|
+
import { Schema, Schemes, TypeScheme, ObjectSchema, Completion } from './types/index.js';
|
|
2
|
+
export { AnySchema, ApplySchema, ArraySchema, Bindings, DEFAULT_TYPE_LIMITS, Discovery, ElementFlag, FnSchema, GuardSig, INSTANTIATION_COUNT_LIMIT, INSTANTIATION_DEPTH_LIMIT, Incompatibility, IncompatibilityKind, IndexSchema, Instantiation, InstantiationLimitError, KeyofSchema, LiteralSchema, MappedSchema, OverloadSchema, Param, Prop, ScalarSchema, TYPE_EVAL_DEPTH_LIMIT, TupleSchema, TypeEvalLimitError, TypeEvalLimits, TypeForm, TypePosition, UnionSchema, UnionTooComplexError, UnknownSchema, VarCandidates, VarSchema, apparentType, asLiteralOrigin, baseLiteralType, bindTypeParams, comparable, configureTypeLimits, contravariantInference, covariantInference, discover, equals, erasedSignature, expand1, flagAt, format, formatTypeArgs, formatTypeDiff, freeVars, groundVars, inferFromCandidates, inferredTypes, instantiate, instantiateInContextOf, instantiateLoose, isMissingType, isNumericLiteralName, isObjectOrArrayLiteral, isScheme, isSerializable, isVariadicTuple, join, joinAll, missingType, normalizeUnion, ownProp, renameTypeParams, resetInstantiationCount, resetTypeLimits, resolveConditional, resolveOp, resolveTypeOp, restIndex, s, sampleValue, silentNever, substitute, subtype, typeAtPosition, typeDiff, typeFeatures, typeLimits, typeNeedsParens, typeParamArity, unify, widen, widenInferred, widenLiteral, widenOrigin, widenType, withoutUndefined } from './types/index.js';
|
|
3
|
+
import { Scope as Scope$1, BaseNode, Node, types, SourceLocation, Expression } from '@tslite/ast';
|
|
4
4
|
import { CapabilityProfile, CompiledProfile } from '@tslite/capability';
|
|
5
5
|
import { Span } from '@tslite/language-service';
|
|
6
6
|
|
|
@@ -17,9 +17,11 @@ declare const childScope: (parent: Scope, vars: Record<string, Schema>) => Scope
|
|
|
17
17
|
declare const lookup: (scope: Scope, name: string) => Schema | undefined;
|
|
18
18
|
/**
|
|
19
19
|
* Todos os nomes visíveis a partir de `scope`, com shadowing — o binding mais
|
|
20
|
-
* interno vence. É o que alimenta o autocomplete de identificadores.
|
|
21
|
-
*
|
|
22
|
-
*
|
|
20
|
+
* interno vence. É o que alimenta o autocomplete de identificadores. Duas
|
|
21
|
+
* chaves moram no mesmo escopo e não são nomes: a que tem `.` é um caminho
|
|
22
|
+
* estreitado por guard (`narrow`, D13), e a que termina em `#` é o tipo
|
|
23
|
+
* DECLARADO de um binding mutável (D63) — nenhum identificador tem esses
|
|
24
|
+
* caracteres.
|
|
23
25
|
*/
|
|
24
26
|
declare const visibleNames: (scope: Scope) => Map<string, Schema>;
|
|
25
27
|
/**
|
|
@@ -112,7 +114,7 @@ declare const resolveNamed: (env: Env, name: string) => Schema | undefined;
|
|
|
112
114
|
declare const resolveScheme: (env: Env, name: string) => TypeScheme | undefined;
|
|
113
115
|
|
|
114
116
|
type Severity = "error" | "warning";
|
|
115
|
-
type DiagnosticCode = "not-assignable" | "unknown-name" | "not-callable" | "no-such-member" | "not-object" | "const-needs-init" | "cannot-redeclare" | "unknown-module" | "not-a-schema" | "type-as-value" | "asserter-needs-name" | "shadows-schema" | "missing-argument" | "excess-argument" | "excess-property" | "spread-argument" | "required-after-optional" | "not-iterable" | "props-mismatch" | "no-matching-overload" | "constraint-violation" | "wrong-type-argument-count" | "unsupported" | "forbidden-member" | "unused-name" | "assign-to-const" | "readonly-write" | "cast-unsound" | "unprovable-value" | "not-arithmetic-operand" | "operator-not-applicable" | "implicit-coercion" | "node-not-allowed" | "name-not-allowed" | "type-feature-not-allowed" | "any-not-allowed" | "narrowing-cast-not-allowed" | "too-deep" | "too-complex-union" | "too-large" | "wrong-result-type";
|
|
117
|
+
type DiagnosticCode = "not-assignable" | "unknown-name" | "not-callable" | "no-such-member" | "not-object" | "possibly-nullish" | "unknown-value" | "const-needs-init" | "cannot-redeclare" | "circular-type-alias" | "circular-type-annotation" | "unknown-module" | "not-a-schema" | "type-as-value" | "asserter-needs-name" | "shadows-schema" | "missing-argument" | "excess-argument" | "excess-property" | "spread-argument" | "required-after-optional" | "not-iterable" | "props-mismatch" | "no-matching-overload" | "constraint-violation" | "wrong-type-argument-count" | "unsupported" | "forbidden-member" | "unused-name" | "assign-to-const" | "readonly-write" | "cast-unsound" | "unprovable-value" | "not-arithmetic-operand" | "operator-not-applicable" | "implicit-coercion" | "node-not-allowed" | "name-not-allowed" | "type-feature-not-allowed" | "any-not-allowed" | "narrowing-cast-not-allowed" | "too-deep" | "too-complex-union" | "too-large" | "wrong-result-type";
|
|
116
118
|
/**
|
|
117
119
|
* A **classe** do diagnóstico — espelha a divisão de passes do `tsc` (que nós
|
|
118
120
|
* fundimos num walk só): `semantic` é o que o **binder** do tsc pega (validade do
|
|
@@ -187,6 +189,29 @@ declare const diag: {
|
|
|
187
189
|
notCallable: (node: BaseNode, type: Schema) => Diagnostic;
|
|
188
190
|
noSuchMember: (node: BaseNode, type: Schema, key: string) => Diagnostic;
|
|
189
191
|
notObject: (node: BaseNode, type: Schema) => Diagnostic;
|
|
192
|
+
/**
|
|
193
|
+
* Ler ou chamar através de um valor que pode ser `null`/`undefined` — o
|
|
194
|
+
* `checkNonNullTypeWithReporter` do tsc (`checker.ts:24098`), que tem uma mensagem por
|
|
195
|
+
* combinação, e a variante "Cannot invoke" quando o valor é chamado.
|
|
196
|
+
*/
|
|
197
|
+
possiblyNullish: (node: BaseNode, nullish: {
|
|
198
|
+
readonly null: boolean;
|
|
199
|
+
readonly undefined: boolean;
|
|
200
|
+
}, invoked?: boolean) => Diagnostic;
|
|
201
|
+
/**
|
|
202
|
+
* Usar um valor `unknown` como objeto — ler dele, chamá-lo, indexá-lo ou operar
|
|
203
|
+
* sobre ele. É o mesmo `checkNonNullTypeWithReporter` (`checker.ts:24102`), no ramo
|
|
204
|
+
* que vem ANTES do nullish e em três linhas:
|
|
205
|
+
*
|
|
206
|
+
* if (strictNullChecks && type.flags & TypeFlags.Unknown) {
|
|
207
|
+
* error(node, Diagnostics.Object_is_of_type_unknown);
|
|
208
|
+
* return errorType;
|
|
209
|
+
* }
|
|
210
|
+
*
|
|
211
|
+
* Um código só e uma mensagem só, para os seis usos (o TS2571 da 3.9.10 — o
|
|
212
|
+
* TS18046 é de versão posterior e não existe na tag).
|
|
213
|
+
*/
|
|
214
|
+
unknownValue: (node: BaseNode) => Diagnostic;
|
|
190
215
|
constNeedsInit: (node: BaseNode) => Diagnostic;
|
|
191
216
|
missingArgument: (node: BaseNode, name: string, expected: Schema) => Diagnostic;
|
|
192
217
|
notASchema: (node: BaseNode, name: string) => Diagnostic;
|
|
@@ -195,7 +220,21 @@ declare const diag: {
|
|
|
195
220
|
shadowsSchema: (node: BaseNode, name: string) => Diagnostic;
|
|
196
221
|
unknownModule: (node: BaseNode, source: string) => Diagnostic;
|
|
197
222
|
cannotRedeclare: (node: BaseNode, name: string) => Diagnostic;
|
|
223
|
+
circularTypeAlias: (node: BaseNode, name: string) => Diagnostic;
|
|
224
|
+
circularTypeAnnotation: (node: BaseNode, name: string) => Diagnostic;
|
|
198
225
|
excessArgument: (node: BaseNode, expected: number, got: number) => Diagnostic;
|
|
226
|
+
/**
|
|
227
|
+
* A ARIDADE de uma chamada, com o texto do `getArgumentArityError` do tsc
|
|
228
|
+
* (`checker.ts:25477`): `Expected {range} arguments, but got {got}.` (TS2554), e
|
|
229
|
+
* `Expected at least {min} arguments, but got {got}.` quando a assinatura tem rest
|
|
230
|
+
* (TS2555). O `range` é `min` ou `min-max`, e o plural é sempre plural, como lá.
|
|
231
|
+
*
|
|
232
|
+
* O CÓDIGO continua dizendo a direção — `missing-argument` quando faltam, e
|
|
233
|
+
* `excess-argument` quando sobram —, que é informação que o texto do tsc perdeu ao
|
|
234
|
+
* usar um único TS2554 para os dois. A régua é a D2: o código é o contrato, a mensagem
|
|
235
|
+
* é prosa.
|
|
236
|
+
*/
|
|
237
|
+
argumentArity: (node: BaseNode, range: string, got: number, kind: "missing" | "excess", atLeast?: boolean) => Diagnostic;
|
|
199
238
|
excessProperty: (node: BaseNode, name: string, target: Schema) => Diagnostic;
|
|
200
239
|
spreadArgument: (node: BaseNode) => Diagnostic;
|
|
201
240
|
requiredAfterOptional: (node: BaseNode) => Diagnostic;
|
|
@@ -207,10 +246,12 @@ declare const diag: {
|
|
|
207
246
|
/**
|
|
208
247
|
* Argumento de tipo explícito com aridade errada. Assinatura **sem** type params
|
|
209
248
|
* declarados conta como `expected: 0` — é o que o tsc faz quando
|
|
210
|
-
* `Signature.typeParameters` é `undefined` (ele nunca infere a lista).
|
|
211
|
-
* texto do TS2558.
|
|
249
|
+
* `Signature.typeParameters` é `undefined` (ele nunca infere a lista). Com default, o
|
|
250
|
+
* esperado é a faixa (`"1-2"`). Mensagem no texto do TS2558, que é sempre plural.
|
|
212
251
|
*/
|
|
213
|
-
wrongTypeArgumentCount: (node: BaseNode, expected: number, got: number) => Diagnostic;
|
|
252
|
+
wrongTypeArgumentCount: (node: BaseNode, expected: number | string, got: number) => Diagnostic;
|
|
253
|
+
/** Nenhuma sobrecarga aceita a aridade, e há uma abaixo e outra acima (≅ TS2743). */
|
|
254
|
+
noOverloadTypeArgumentCount: (node: BaseNode, got: number, below: number, above: number) => Diagnostic;
|
|
214
255
|
/** Referência a um alias com aridade errada — as frases do tsc: TS2315 para um
|
|
215
256
|
* tipo que não é genérico, TS2314 para o resto (com o intervalo quando há default). */
|
|
216
257
|
genericTypeArity: (node: BaseNode, name: string, min: number, max: number) => Diagnostic;
|
|
@@ -491,7 +532,7 @@ type BinaryOpCategory = "additive" | "arithmetic" | "bitwise" | "relational" | "
|
|
|
491
532
|
*/
|
|
492
533
|
type OpResult = "number" | "boolean" | "string" | "additive";
|
|
493
534
|
interface BinaryOpSpec {
|
|
494
|
-
readonly op: types
|
|
535
|
+
readonly op: types.BinaryOperator;
|
|
495
536
|
readonly category: BinaryOpCategory;
|
|
496
537
|
readonly result: OpResult;
|
|
497
538
|
}
|
|
@@ -503,14 +544,14 @@ declare const BINARY_OP: ReadonlyMap<string, BinaryOpSpec>;
|
|
|
503
544
|
* condicional e NÃO tem schema fixo: quem chama trata (ver `binaryType` no checker). */
|
|
504
545
|
declare const opResultSchema: (r: Exclude<OpResult, "additive">) => Schema;
|
|
505
546
|
interface UnaryOpSpec {
|
|
506
|
-
readonly op: types
|
|
547
|
+
readonly op: types.UnaryOperator;
|
|
507
548
|
/** O tipo ao qual o resultado é ASSIGNÁVEL (upper bound). O `unaryType` faz
|
|
508
549
|
* folding de literal (`-1`→`-1`, `!0`→`true`), então o real é um subtipo disto. */
|
|
509
550
|
readonly result: "number" | "boolean" | "string" | "undefined";
|
|
510
551
|
}
|
|
511
552
|
declare const UNARY_OPS: readonly UnaryOpSpec[];
|
|
512
553
|
interface LogicalOpSpec {
|
|
513
|
-
readonly op: types
|
|
554
|
+
readonly op: types.LogicalOperator;
|
|
514
555
|
}
|
|
515
556
|
/** Os lógicos COMPÕEM o tipo dos operandos (`a && b` refina; não é tipo fixo) —
|
|
516
557
|
* por isso sem `result`. No slot, um lógico serve quando os operandos servem. */
|
|
@@ -559,6 +600,67 @@ type BindingMap = WeakMap<BaseNode, BaseNode>;
|
|
|
559
600
|
*/
|
|
560
601
|
declare function collectBindings(root: BaseNode): BindingMap;
|
|
561
602
|
|
|
603
|
+
/** O que um nome denota. */
|
|
604
|
+
type ReferenceSymbol = {
|
|
605
|
+
readonly kind: "local";
|
|
606
|
+
/** O `Identifier` que declara — a identidade, por referência. */
|
|
607
|
+
readonly declaration: BaseNode;
|
|
608
|
+
} | {
|
|
609
|
+
readonly kind: "environment";
|
|
610
|
+
/** O caminho a partir da raiz da DI: `["params"]`, `["params", "id"]`. */
|
|
611
|
+
readonly path: readonly string[];
|
|
612
|
+
};
|
|
613
|
+
/**
|
|
614
|
+
* Onde o nome aparece como SHORTHAND, e portanto nomeia duas coisas ao mesmo tempo
|
|
615
|
+
* — o `prefixText`/`suffixText` do `findRenameLocations` do TypeScript:
|
|
616
|
+
*
|
|
617
|
+
* - `"property"`: o nome é o valor e também a PROPRIEDADE (`{ x }`, ou `const { x
|
|
618
|
+
* } = o` renomeando o `x` local). A propriedade continua com o nome antigo:
|
|
619
|
+
* `{ x: x2 }`;
|
|
620
|
+
* - `"binding"`: o nome é a propriedade e também um BINDING (`const { id } =
|
|
621
|
+
* params`, renomeando o `params.id`). O binding continua com o nome antigo:
|
|
622
|
+
* `{ id2: id }`;
|
|
623
|
+
* - `"import"`: o nome importado é também o local (`import { a } from "m"`,
|
|
624
|
+
* renomeando o local): `import { a as a2 }`.
|
|
625
|
+
*/
|
|
626
|
+
type Shorthand = "property" | "binding" | "import";
|
|
627
|
+
/** Uma referência a tipo nomeado escrita numa anotação (a `typeRefs` do parser). */
|
|
628
|
+
interface TypeRefSite {
|
|
629
|
+
readonly name: string;
|
|
630
|
+
readonly loc: SourceLocation;
|
|
631
|
+
}
|
|
632
|
+
/** Um lugar onde o nome aparece. */
|
|
633
|
+
type Occurrence = {
|
|
634
|
+
/** O nó cujo texto É o nome: `Identifier`, `JSXIdentifier` ou a chave literal. */
|
|
635
|
+
readonly site: "node";
|
|
636
|
+
readonly node: BaseNode;
|
|
637
|
+
readonly symbol: ReferenceSymbol;
|
|
638
|
+
/** A declaração do símbolo, e não um uso. */
|
|
639
|
+
readonly isDeclaration?: true;
|
|
640
|
+
readonly shorthand?: Shorthand;
|
|
641
|
+
} | {
|
|
642
|
+
/** Um segmento do `typeof a.b` numa anotação: o nó não tem posição por segmento. */
|
|
643
|
+
readonly site: "typeQuery";
|
|
644
|
+
readonly node: BaseNode;
|
|
645
|
+
readonly segment: number;
|
|
646
|
+
readonly symbol: ReferenceSymbol;
|
|
647
|
+
} | {
|
|
648
|
+
/** Um nome de tipo numa anotação, que não é nó (E6 do editor). */
|
|
649
|
+
readonly site: "typeRef";
|
|
650
|
+
readonly ref: TypeRefSite;
|
|
651
|
+
readonly symbol: ReferenceSymbol;
|
|
652
|
+
};
|
|
653
|
+
/** Os dois símbolos são o mesmo? */
|
|
654
|
+
declare function sameSymbol(a: ReferenceSymbol, b: ReferenceSymbol): boolean;
|
|
655
|
+
/**
|
|
656
|
+
* Todas as ocorrências de nome do programa, cada uma com o símbolo que denota.
|
|
657
|
+
*
|
|
658
|
+
* Quem renomeia escolhe o símbolo sob o cursor (`occurrenceAt` do editor) e pega as
|
|
659
|
+
* ocorrências com `sameSymbol`; quem renomeia um caminho do ambiente sem cursor (o
|
|
660
|
+
* host que renomeou a declaração no `Env`) filtra pelo caminho direto.
|
|
661
|
+
*/
|
|
662
|
+
declare function collectReferences(root: BaseNode): readonly Occurrence[];
|
|
663
|
+
|
|
562
664
|
/** Anota uma ligação/parâmetro: `x` → `x: T`. */
|
|
563
665
|
declare const annotate: <N extends BaseNode>(node: N, type: Schema) => N & {
|
|
564
666
|
typeAnnotation: Schema;
|
|
@@ -681,4 +783,4 @@ declare function anchorDiagnostics<A>(root: object, diagnostics: readonly Diagno
|
|
|
681
783
|
*/
|
|
682
784
|
declare function spanOf(text: string, loc: SourceLocation | null | undefined): Span | undefined;
|
|
683
785
|
|
|
684
|
-
export { type AnchorDiagnosticsOptions, type AnchoredDiagnostic, type Anchors, BINARY_OP, BINARY_OPS, type BinaryOpCategory, type BinaryOpSpec, type BindingMap, type CheckOptions, type CheckResult, type CheckerErrorCode, type Diagnostic, type DiagnosticCode, type DiagnosticData, type DiagnosticKind, type DiagnosticSink, type Env, type EnvOptions, FUNCTION_KINDS, type Guard, type GuardContext, LOGICAL_OPS, type LogicalOpSpec, type LowerValueOptions, type MissingProperty, type OpResult, type Profile, type Scope, type Severity, type TypeOverlay, UNARY_OPS, type UnaryOpSpec, type UnusedOptions, anchorDiagnostics, annotate, annotateReturn, asExpression, binaryOpsProducing, calleeAllowlist, capabilityNodes, check, childScope, collectBindings, collectMutations, collectUnused, componentProps, componentPropsOf, contextualTypeAt, createAnchors, createEnv, createSink, diag, diagnosticsAt, extractModuleType, fromCapability, guard, guardsFromCompiled, lookup, lowerValue, makeDiagnostic, maxArgs, maxCallNesting, maxDepth, maxFunctionNesting, maxNestingOf, maxNodes, memberCompletions, memberDepth, opResultSchema, resolveNamed, resolveScheme, resultType, rootScope, scopeAt, scopeCompletions, spanOf, typeAt, unaryOpsProducing, visibleNames };
|
|
786
|
+
export { type AnchorDiagnosticsOptions, type AnchoredDiagnostic, type Anchors, BINARY_OP, BINARY_OPS, type BinaryOpCategory, type BinaryOpSpec, type BindingMap, type CheckOptions, type CheckResult, type CheckerErrorCode, Completion, type Diagnostic, type DiagnosticCode, type DiagnosticData, type DiagnosticKind, type DiagnosticSink, type Env, type EnvOptions, FUNCTION_KINDS, type Guard, type GuardContext, LOGICAL_OPS, type LogicalOpSpec, type LowerValueOptions, type MissingProperty, ObjectSchema, type Occurrence, type OpResult, type Profile, type ReferenceSymbol, Schema, Schemes, type Scope, type Severity, type Shorthand, type TypeOverlay, type TypeRefSite, TypeScheme, UNARY_OPS, type UnaryOpSpec, type UnusedOptions, anchorDiagnostics, annotate, annotateReturn, asExpression, binaryOpsProducing, calleeAllowlist, capabilityNodes, check, childScope, collectBindings, collectMutations, collectReferences, collectUnused, componentProps, componentPropsOf, contextualTypeAt, createAnchors, createEnv, createSink, diag, diagnosticsAt, extractModuleType, fromCapability, guard, guardsFromCompiled, lookup, lowerValue, makeDiagnostic, maxArgs, maxCallNesting, maxDepth, maxFunctionNesting, maxNestingOf, maxNodes, memberCompletions, memberDepth, opResultSchema, resolveNamed, resolveScheme, resultType, rootScope, sameSymbol, scopeAt, scopeCompletions, spanOf, typeAt, unaryOpsProducing, visibleNames };
|