@artel/artc 0.6.25220 → 0.6.25222

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.
Files changed (39) hide show
  1. package/build/Cli.js +3 -3
  2. package/build/api/Api.js +6 -4
  3. package/build/api/ApiNodeJS.js +3 -3
  4. package/build/api/ApiServices.js +394 -284
  5. package/build/{chunk-ASXPPFGP.js → chunk-MBMOAUK7.js} +3 -3
  6. package/build/{chunk-RHY36EE7.js → chunk-ODWG5ZXF.js} +4060 -2261
  7. package/build/{chunk-AUDD2JDS.js → chunk-UZK7JCND.js} +3 -3
  8. package/build/types/analysis/Analyzer.d.ts +53 -6
  9. package/build/types/analysis/ControlFlowGraphBuilder.d.ts +121 -0
  10. package/build/types/analysis/ControlFlowGraphVisualizer.d.ts +12 -0
  11. package/build/types/analysis/DiagnosticCollector.d.ts +3 -0
  12. package/build/types/analysis/NodeTypeUtils.d.ts +4 -1
  13. package/build/types/analysis/SemanticContext.d.ts +7 -0
  14. package/build/types/analysis/SemanticContextBuilder.d.ts +2 -0
  15. package/build/types/analysis/StatementBlockScopeBuilder.d.ts +19 -17
  16. package/build/types/analysis/TypeNarrower.d.ts +62 -0
  17. package/build/types/common/Range.d.ts +1 -0
  18. package/build/types/diagnostic/DiagnosticCode.d.ts +131 -123
  19. package/build/types/diagnostic/DiagnosticData.d.ts +2 -1
  20. package/build/types/emitter/IrBuilder.d.ts +3 -1
  21. package/build/types/emitter/IrToJs.d.ts +1 -0
  22. package/build/types/emitter/Transformer.d.ts +2 -0
  23. package/build/types/emitter/ir/Nodes.d.ts +86 -78
  24. package/build/types/emitter/ir/types.d.ts +2 -2
  25. package/build/types/parser/Scanner.d.ts +1 -0
  26. package/build/types/services/CompletionService.d.ts +2 -1
  27. package/build/types/services/DisplayService.d.ts +4 -2
  28. package/build/types/services/NodeSemanticInfo.d.ts +4 -2
  29. package/build/types/tree/KeywordKind.d.ts +41 -40
  30. package/build/types/tree/NodeKind.d.ts +63 -60
  31. package/build/types/tree/green/Nodes.d.ts +124 -86
  32. package/build/types/tree/green/SyntaxFactory.d.ts +12 -10
  33. package/build/types/tree/green/SyntaxToCode.d.ts +1 -0
  34. package/build/types/tree/green/Token.d.ts +1 -1
  35. package/build/types/tree/green/Utils.d.ts +1 -1
  36. package/build/types/tree/red/Nodes.d.ts +103 -63
  37. package/build/types/tree/red/Utils.d.ts +1 -1
  38. package/build/types/types/TypeFactory.d.ts +2 -1
  39. package/package.json +1 -1
@@ -10,7 +10,7 @@ import {
10
10
  WellKnownDeclarationsLoadError,
11
11
  __async,
12
12
  createTsInteropInputsForCompilation
13
- } from "./chunk-RHY36EE7.js";
13
+ } from "./chunk-ODWG5ZXF.js";
14
14
 
15
15
  // source/executor/Compiler.ts
16
16
  var Compiler = class {
@@ -69,7 +69,7 @@ var Compiler = class {
69
69
  return __async(this, null, function* () {
70
70
  if (analyzer.compilation.mainPackage === void 0) {
71
71
  _diagnostics?.addDiagnostic(new Diagnostic(DiagnosticData.withCode(
72
- 119 /* ProgramWithoutMainPackageCanNotBeCompiled */
72
+ 127 /* ProgramWithoutMainPackageCanNotBeCompiled */
73
73
  ), void 0));
74
74
  return void 0;
75
75
  }
@@ -83,7 +83,7 @@ var Compiler = class {
83
83
  return __async(this, null, function* () {
84
84
  if (analyzer.compilation.mainPackage === void 0) {
85
85
  _diagnostics?.addDiagnostic(new Diagnostic(DiagnosticData.withCode(
86
- 119 /* ProgramWithoutMainPackageCanNotBeCompiled */
86
+ 127 /* ProgramWithoutMainPackageCanNotBeCompiled */
87
87
  ), void 0));
88
88
  return "";
89
89
  }
@@ -21,6 +21,7 @@ import * as autotypeCallExpressionMeaning from './AutotypeCallExpressionMeaning.
21
21
  import * as baseExpressionMeaning from './BaseExpressionMeaning.js';
22
22
  import * as callExpressionMeaning from './CallExpressionMeaning.js';
23
23
  import * as constructorOverloadResolver from './ConstructorOverloadResolver.js';
24
+ import { ControlFlowGraphBuildResult } from './ControlFlowGraphBuilder.js';
24
25
  import { DeclarationsUsageCountResult } from './DeclarationsUsageCounter.js';
25
26
  import * as dereferenceExpressionMeaning from './DereferenceExpressionMeaning.js';
26
27
  import { FoundAnonymousDeclaration } from './FoundDeclaration.js';
@@ -91,8 +92,9 @@ export declare class Analyzer {
91
92
  private readonly _extendedTypes;
92
93
  private readonly _analyzedTranslationPackages;
93
94
  private readonly _linkedMultiPlatformPackagesByPlatform;
94
- private readonly _bodyUsesYieldStatementCheckResults;
95
+ private readonly _functionBlockWithYieldStatementCheckResults;
95
96
  private readonly _namedDeclarationsUsageCountResults;
97
+ private readonly _controlFlowGraphs;
96
98
  get tsInterop(): TsInteropContext;
97
99
  constructor(compilation: project.Compilation, tsInteropInputs: TsInteropInputs);
98
100
  getProjectSourceFile(node: tree.SourceFile): project.SourceFile;
@@ -105,7 +107,8 @@ export declare class Analyzer {
105
107
  referencedType: types.Type;
106
108
  } | undefined;
107
109
  isTypeAssignableTo(source: types.Type, target: types.Type): boolean;
108
- checkStatementBlockInvokesAsyncMethods(node: tree.StatementBlock): boolean;
110
+ getTypeAssignabilityFlags(source: types.Type, target: types.Type): TypeAssignabilityFlags;
111
+ checkBlockInvokesAsyncMethods(node: tree.StatementBlock | tree.FunctionBlock): boolean;
109
112
  getSyntacticAccessKind(node: tree.Expression): SyntacticAccessKind;
110
113
  getTypeMemberEntityContainer(node: tree.TypeMemberDeclaration): e.TypeMemberEntityContainer;
111
114
  getTargetTypeOfExpression(node: tree.Expression, hint?: TargetTypeHint): types.Type | undefined;
@@ -128,8 +131,37 @@ export declare class Analyzer {
128
131
  resolveTag(node: tree.Tag): tagMeaning.ResolutionResult;
129
132
  getObjectExpressionMeaning(node: tree.ObjectExpression): objectExpressionMeaning.Meaning;
130
133
  getBaseExpressionMeaning(node: tree.BaseExpression): baseExpressionMeaning.Meaning;
131
- checkExpressionOptionalChaining(node: tree.Expression): boolean;
132
- makeNoneAssignableToTypeIfExpressionOptionalChaining(type: types.Type, node: tree.Expression): types.Type;
134
+ /**
135
+ * Проверяет, является ли выражение цепочкой доступов через `?`, заканчивающейся выражением, тип которого допускает
136
+ * `пусто`.
137
+ *
138
+ * Пример:
139
+ * ```artel
140
+ * а?.б
141
+ * а?[1]
142
+ * а?^
143
+ * а?()
144
+ * (а)?.б
145
+ * ```
146
+ *
147
+ * где тип переменной `а` допускает `пусто`.
148
+ */
149
+ isExpressionValidOptionalChaining(node: tree.Expression): boolean;
150
+ /**
151
+ * Проверяет, является ли выражение цепочкой доступов через `?`.
152
+ *
153
+ * Пример:
154
+ * ```artel
155
+ * а?.б
156
+ * а?[1]
157
+ * а?^
158
+ * а?()
159
+ * (а)?.б
160
+ * ```
161
+ */
162
+ isExpressionOptionalChainingSyntactically(node: tree.Expression): boolean;
163
+ isExpressionValidOutermostOptionalChaining(node: tree.Expression): boolean;
164
+ makeNoneAssignableToTypeIfExpressionValidOutermostOptionalChaining(type: types.Type, node: tree.Expression): types.Type;
133
165
  checkIdentifierNameIsReserved(name: string, locale: PackageLocale): ReservedIdentifierKind | undefined;
134
166
  getReservedIdentifierName(reservedIdentifierKind: ReservedIdentifierKind, locale: PackageLocale): string;
135
167
  createNameFromIdentifier(node: tree.Identifier): Name;
@@ -152,7 +184,7 @@ export declare class Analyzer {
152
184
  checkExpressionDenotesPackageNameSegment(expression: tree.Expression): {
153
185
  packageTreeNode: PackageNameTreeNode;
154
186
  } | undefined;
155
- checkMethodBodyUsesYieldStatement(node: tree.StatementBlock): boolean;
187
+ checkFunctionBlockWithYieldStatement(node: tree.FunctionBlock): boolean;
156
188
  enumerateAspects(type: types.Type): Iterable<types.StructuredType>;
157
189
  checkTypeIsBasedOnAspect(type: types.Type, aspectEntity: e.StructuredTypeEntity): boolean;
158
190
  resolvePrefixUnaryExpressionUserDefinableOperator(node: tree.PrefixUnaryExpression): WithDiagnostics<FoundAnonymousDeclaration<types.Operator>>;
@@ -200,6 +232,7 @@ export declare class Analyzer {
200
232
  * - Т: Объект? -> нет, поскольку в качестве конкретного типа, заменяющего параметр, может быть использован тип, исключающий `пусто`.
201
233
  */
202
234
  isNoneAssignableToType(type: types.Type): boolean;
235
+ excludeTypeFromUnion(initialType: types.Type, excludedType: types.Type): types.Type;
203
236
  isMethodValueParameterVariadic(entity: e.VariableEntity): boolean;
204
237
  getDefaultTypeParameterConstraint(): types.Type;
205
238
  getOriginalSignatureTypeOfMethodEntity(entity: e.MethodEntity): types.MethodType;
@@ -217,6 +250,7 @@ export declare class Analyzer {
217
250
  createPackageMemberHiding(node: tree.PackageMemberDeclaration, modifierFlags: ModifierFlags): e.EntityHidingLevel | undefined;
218
251
  createTypeMemberHiding(node: tree.TypeMemberDeclaration, modifierFlags: ModifierFlags): e.EntityHidingLevel | undefined;
219
252
  getDeclarationsUsageCount(sourceFile: tree.SourceFile, cancellationToken: CancellationToken | undefined): Promise<DeclarationsUsageCountResult>;
253
+ isFunctionResultNone(node: tree.FunctionBlock): boolean;
220
254
  isExpressionImplicitlyReturnedFromSubprogram(node: tree.ExpressionStatement): boolean;
221
255
  createBackingPackageVariables(declaredMembers: readonly (e.NamedPackageMemberEntity | e.PackageAliasEntity)[], pkg: e.PackageEntity): e.PackageVariableEntity[];
222
256
  createBackingTypeVariables(declaredMembers: readonly NamedTypeMemberEntity[], type: e.TypeEntity): e.TypeVariableEntity[];
@@ -229,6 +263,7 @@ export declare class Analyzer {
229
263
  checkBodyOfRedefinableAliasTypeMethod(node: tree.TypeMethodDeclaration, diagnostics?: DiagnosticAcceptor): {
230
264
  redefinableMethodOfOriginalType: e.TypeMethodEntity;
231
265
  } | undefined;
266
+ getControlFlowGraph(sourceFile: project.SourceFile): ControlFlowGraphBuildResult;
232
267
  private createTsInterop;
233
268
  }
234
269
  export declare class TsInteropInputs {
@@ -299,6 +334,7 @@ declare class Type {
299
334
  private getTargetlessMethodBlockLiteralType;
300
335
  private inferMethodLiteralTypeFromNodeWithFallbackToTargetType;
301
336
  private inferMethodLiteralTypeFromNode;
337
+ private getNarrowedTypeIfNarrowableReference;
302
338
  }
303
339
  declare class ReturnType {
304
340
  private readonly _analyzer;
@@ -426,6 +462,7 @@ declare class Scope {
426
462
  private readonly _nestedMethodDeclarationTypeParametersScopes;
427
463
  private readonly _nestedMethodDeclarationValueParametersScopes;
428
464
  private readonly _methodLiteralScopes;
465
+ private readonly _functionBlockScopes;
429
466
  private readonly _statementBlockScopes;
430
467
  private readonly _forEachStatementScopes;
431
468
  private readonly _catchClauseScopes;
@@ -452,6 +489,7 @@ declare class Scope {
452
489
  ofNestedMethodDeclarationTypeParameters(node: tree.NestedMethodDeclaration): scope.IScope;
453
490
  ofNestedMethodDeclarationValueParameters(node: tree.NestedMethodDeclaration): scope.IScope;
454
491
  ofMethodLiteral(node: tree.MethodLiteral): scope.IScope;
492
+ ofFunctionBlock(node: tree.FunctionBlock): scope.IScope;
455
493
  ofStatementBlock(node: tree.StatementBlock): scope.IScope;
456
494
  ofForStatement(node: tree.ForStatement): scope.IScope;
457
495
  ofCatchClause(node: tree.CatchClause): scope.IScope;
@@ -569,11 +607,20 @@ declare class OwningPlainObjectModificationCheck {
569
607
  private _analyzer;
570
608
  private readonly _owningPlainObjectModificationCheckResult;
571
609
  constructor(_analyzer: Analyzer);
572
- ofDeclarationBody(node: tree.StatementBlock): boolean;
610
+ ofDeclarationBody(node: tree.FunctionBlock): boolean;
573
611
  private checkMethodBodyModifiesPlainObject;
574
612
  private checkReceiverModifiesPlainObjectRecursively;
575
613
  private nodeBelongsToPlainObjectDeclaration;
576
614
  }
615
+ export declare enum TypeAssignabilityFlags {
616
+ NotAssignable = 1,
617
+ Identity = 2,
618
+ DerivedToBase = 4,
619
+ MethodTypes = 8,
620
+ ImplicitConversion = 16,
621
+ First = 1,
622
+ Last = 16
623
+ }
577
624
  declare class PackageImports {
578
625
  private readonly _analyzer;
579
626
  private readonly _packagesAvailableForImport;
@@ -0,0 +1,121 @@
1
+ import { Diagnostic } from '../diagnostic/Diagnostic.js';
2
+ import { SourceFile } from '../project/SourceFile.js';
3
+ import * as tree from '../tree/index.js';
4
+ export declare class ControlFlowGraphBuilder {
5
+ private readonly _sourceFile;
6
+ private readonly _controlFlowNodeByReference;
7
+ private readonly _unreachableCodeDiagnostics;
8
+ private _isInRebuildingFinallyClauseGraphMode;
9
+ private _currentPredecessor;
10
+ private _currentContinueLoopTarget;
11
+ private _currentBreakLoopTarget;
12
+ private _currentErrorTarget;
13
+ private _currentReturnTarget;
14
+ constructor(sourceFile: SourceFile);
15
+ build(): ControlFlowGraphBuildResult;
16
+ private visitNode;
17
+ private visitAssignmentStatement;
18
+ private visitIfStatement;
19
+ private visitWhileStatement;
20
+ private visitLoopStatement;
21
+ private visitForStatement;
22
+ private visitContinueLoopStatement;
23
+ private visitBreakLoopStatement;
24
+ private visitSwitchStatement;
25
+ private visitTryStatement;
26
+ private visitReturnStatement;
27
+ private visitErrorStatement;
28
+ private visitLocalVariableDeclaration;
29
+ private visitWhenTernaryExpression;
30
+ private visitCondition;
31
+ private visitBinaryExpression;
32
+ private visitPrefixUnaryExpressionInCondition;
33
+ private visitIsExpressionInCondition;
34
+ private setAssignmentAsCurrentPredecessor;
35
+ private visitChildren;
36
+ private addUnreachableCodeDiagnostic;
37
+ }
38
+ export declare class ControlFlowGraphBuildResult {
39
+ readonly controlFlowNodeByReference: ReadonlyMap<NarrowableReferenceExpression, ControlFlowNode>;
40
+ readonly unreachableCodeDiagnostics: readonly Diagnostic[];
41
+ constructor(controlFlowNodeByReference: ReadonlyMap<NarrowableReferenceExpression, ControlFlowNode>, unreachableCodeDiagnostics: readonly Diagnostic[]);
42
+ }
43
+ export type NarrowableExpression = tree.IdentifierExpression | tree.PropertyAccessExpression | tree.ObjectExpression;
44
+ export declare function isNarrowableExpression(node: tree.Node): node is tree.Expression;
45
+ export type NarrowableReferenceExpression = tree.IdentifierExpression | tree.PropertyAccessExpression | tree.ObjectExpression;
46
+ export declare function isNarrowableReferenceExpression(node: tree.Node): node is NarrowableReferenceExpression;
47
+ export type ControlFlowNode = ControlFlowNode.Start | ControlFlowNode.Condition | ControlFlowNode.Assignment | ControlFlowNode.Split | ControlFlowNode.Loop | ControlFlowNode.Unreachable;
48
+ export declare namespace ControlFlowNode {
49
+ abstract class ControlFlowNodeBase {
50
+ protected abstract thisAsNode: ControlFlowNode;
51
+ /**
52
+ * Для отладочных целей.
53
+ */
54
+ generateVisualizationCode(): string;
55
+ }
56
+ /**
57
+ * Начальный узел, не имеющий предшественников.
58
+ */
59
+ export class Start extends ControlFlowNodeBase {
60
+ readonly kind = "start";
61
+ get debuggerDisplay(): string;
62
+ protected get thisAsNode(): ControlFlowNode;
63
+ }
64
+ /**
65
+ * Хранит информацию об истинности некоторого условия. Например, если условие `а != пусто` истинно, то из типа
66
+ * переменной `а` необходимо исключить тип `Пусто`.
67
+ */
68
+ export class Condition extends ControlFlowNodeBase {
69
+ readonly predecessor: ControlFlowNode;
70
+ readonly syntaxNode: ConditionControlFlowNodeExpression;
71
+ readonly isTrue: boolean;
72
+ readonly kind = "condition";
73
+ get debuggerDisplay(): string;
74
+ protected get thisAsNode(): ControlFlowNode;
75
+ constructor(predecessor: ControlFlowNode, syntaxNode: ConditionControlFlowNodeExpression, isTrue: boolean);
76
+ }
77
+ /**
78
+ * Создаётся в местах присваивания значений в переменную, а также объявления переменных с начальным значением.
79
+ * После присваивания тип переменной меняется на тип выражения справа от равно.
80
+ */
81
+ export class Assignment extends ControlFlowNodeBase {
82
+ readonly predecessor: ControlFlowNode;
83
+ readonly syntaxNode: tree.AssignmentStatement | tree.LocalVariableDeclaration;
84
+ readonly kind = "assignment";
85
+ get debuggerDisplay(): string;
86
+ protected get thisAsNode(): ControlFlowNode;
87
+ constructor(predecessor: ControlFlowNode, syntaxNode: tree.AssignmentStatement | tree.LocalVariableDeclaration);
88
+ }
89
+ /**
90
+ * Вспомогательный узел, использующийся в местах, где происходит разветвление графа потока управления. Тип переменной
91
+ * для этого узла определяется как союзный тип из типов переменных в предшествующих узлах.
92
+ */
93
+ export class Split extends ControlFlowNodeBase {
94
+ readonly predecessors: readonly ControlFlowNode[];
95
+ readonly kind = "split";
96
+ get debuggerDisplay(): string;
97
+ protected get thisAsNode(): ControlFlowNode;
98
+ constructor(predecessors: readonly ControlFlowNode[]);
99
+ }
100
+ /**
101
+ * Используется для циклов (пока, цикл - повтор пока, для-из). Отличается от узла `Split` тем, что предшествующие
102
+ * узлы, указанные в массиве `loopingPredecessors` образуют циклы в графе потока управления.
103
+ */
104
+ export abstract class Loop extends ControlFlowNodeBase {
105
+ readonly kind = "loop";
106
+ get debuggerDisplay(): string;
107
+ protected get thisAsNode(): ControlFlowNode;
108
+ abstract predecessor: ControlFlowNode;
109
+ abstract loopingPredecessors: readonly ControlFlowNode[];
110
+ }
111
+ /**
112
+ * Обозначает недостижимый код.
113
+ */
114
+ export class Unreachable extends ControlFlowNodeBase {
115
+ readonly kind = "unreachable";
116
+ get debuggerDisplay(): string;
117
+ protected get thisAsNode(): ControlFlowNode;
118
+ }
119
+ export {};
120
+ }
121
+ export type ConditionControlFlowNodeExpression = tree.BinaryExpression | tree.IsExpression;
@@ -0,0 +1,12 @@
1
+ import { ControlFlowNode } from './ControlFlowGraphBuilder.js';
2
+ export declare class ControlFlowGraphVisualizer {
3
+ /**
4
+ * Создаёт описание графа на языке Dot.
5
+ *
6
+ * Визуализацию графа можно посмотреть по этой ссылке:
7
+ * https://dreampuf.github.io/GraphvizOnline/?engine=dot#digraph%20%7B%20%7D
8
+ */
9
+ static generateGraphDescriptionInDotLanguage(startNode: ControlFlowNode): string;
10
+ private static getLabel;
11
+ private static createGetIdFunction;
12
+ }
@@ -18,6 +18,8 @@ export declare class DiagnosticCollector {
18
18
  constructor(analyzer: Analyzer, sourceFile: project.SourceFile, cancellationToken: CancellationToken | undefined);
19
19
  collect(): Promise<Diagnostic[]>;
20
20
  private collectNodeDiagnostics;
21
+ private checkDereferenceExpression;
22
+ private checkIndexedAccessExpression;
21
23
  private checkCallExpression;
22
24
  private addNotTranslatedPackageMembersDiagnostics;
23
25
  private collectNotTranslatedPackageMembers;
@@ -60,6 +62,7 @@ export declare class DiagnosticCollector {
60
62
  private checkAssignmentToObjectExpression;
61
63
  private checkAssignmentToDereferenceExpression;
62
64
  private checkAssignmentToIndexedAccessExpression;
65
+ private checkOptionalChainingIsUsedOnTheLeftSideOfAssignment;
63
66
  private checkGenericSpecializationExpression;
64
67
  private checkMethodSpecialization;
65
68
  private checkTypeSpecialization;
@@ -11,11 +11,13 @@ export declare class NodeTypeUtils {
11
11
  static isTypeSpecifier(node: tree.Node): node is tree.TypeSpecifier;
12
12
  static isMethodDeclaration(node: tree.Node): node is MethodDeclaration;
13
13
  static isVariableDeclaration(node: tree.Node): node is VariableDeclaration;
14
+ static isVariantTypeDeclaration(node: tree.Node): node is VariantTypeDeclaration;
15
+ static isSubprogramDeclaration(node: tree.Node): node is SubprogramDeclaration;
16
+ static isNoneLiteral(node: tree.Node): boolean;
14
17
  }
15
18
  export type PackageTypeDeclaration = tree.PackageAliasTypeDeclaration | tree.PackageMethodTypeDeclaration | tree.PackageStructuredTypeDeclaration | tree.PackageVariantTypeDeclaration;
16
19
  export type StructuredTypeDeclaration = tree.PackageStructuredTypeDeclaration | tree.AnonymousStructuredTypeDeclaration;
17
20
  export type VariantTypeDeclaration = tree.PackageVariantTypeDeclaration | tree.AnonymousVariantTypeDeclaration;
18
- export declare function isVariantTypeDeclaration(node: tree.Node): node is VariantTypeDeclaration;
19
21
  export type MethodTypeDeclaration = tree.PackageMethodTypeDeclaration | tree.AnonymousMethodTypeDeclaration;
20
22
  export type MethodDeclaration = tree.PackageMethodDeclaration | tree.NestedMethodDeclaration | tree.TypeMethodDeclaration;
21
23
  export type TypeDeclaration = StructuredTypeDeclaration | VariantTypeDeclaration | MethodTypeDeclaration | tree.PackageAliasTypeDeclaration | tree.TypeParameterDeclaration;
@@ -27,3 +29,4 @@ export type PackageVariableAccessorDeclaration = tree.PackageVariableGetterDecla
27
29
  export type TypeVariableAccessorDeclaration = tree.TypeVariableGetterDeclaration | tree.TypeVariableSetterDeclaration;
28
30
  export type TypeIndexedAccessorDeclaration = tree.TypeIndexedGetterDeclaration | tree.TypeIndexedSetterDeclaration;
29
31
  export type TypeDereferencedVariableAccessorDeclaration = tree.TypeDereferencedVariableGetterDeclaration | tree.TypeDereferencedVariableSetterDeclaration;
32
+ export type SubprogramDeclaration = tree.FunctionBlockParent | tree.MethodLiteral | tree.MethodBlockLiteral;
@@ -320,6 +320,13 @@ export declare class StatementBlockSemanticContext extends SemanticContextWithPa
320
320
  isInTryStatement(): TryStatementClausesInfo | undefined;
321
321
  isInFinallyClause(): boolean;
322
322
  }
323
+ export declare class FunctionBlockSemanticContext extends SemanticContextWithParent {
324
+ private readonly _analyzer;
325
+ private readonly _node;
326
+ private readonly _scopeChain;
327
+ constructor(analyzer: Analyzer, node: tree.FunctionBlock, parentContext: SemanticContext);
328
+ getScopeChain(): ScopeChain;
329
+ }
323
330
  export type RegularOrBlockMethodLiteral = tree.MethodLiteral | tree.MethodBlockLiteral;
324
331
  export declare class MethodLiteralSemanticContext extends SemanticContextWithParent {
325
332
  private readonly _analyzer;
@@ -34,6 +34,7 @@ export declare class SemanticContextBuilder {
34
34
  ofRegularOrBlockMethodLiteral(node: RegularOrBlockMethodLiteral): SemanticContext;
35
35
  ofForStatement(node: tree.ForStatement): SemanticContext;
36
36
  ofStatementBlock(node: tree.StatementBlock): SemanticContext;
37
+ ofFunctionBlock(node: tree.FunctionBlock): SemanticContext;
37
38
  ofTypeConstructorDeclaration(node: tree.TypeConstructorDeclaration): SemanticContext;
38
39
  ofTypeDestructorDeclaration(node: tree.TypeDestructorDeclaration): SemanticContext;
39
40
  ofTypeIndexedGetterDeclaration(node: tree.TypeIndexedGetterDeclaration, hint: 'body' | 'parameters'): SemanticContext;
@@ -53,4 +54,5 @@ export declare class SemanticContextBuilder {
53
54
  private ofChildOfTypeExtensionDeclaration;
54
55
  private isOffsetBetweenNodes;
55
56
  private isOffsetInsideStatementBlock;
57
+ private isOffsetInsideFunctionBlock;
56
58
  }
@@ -2,22 +2,24 @@ import * as tree from '../tree/index.js';
2
2
  import { Analyzer } from './Analyzer.js';
3
3
  import { IScope } from './Scope.js';
4
4
  export declare class StatementBlockScopeBuilder {
5
- static build(analyzer: Analyzer, node: tree.StatementBlock): IScope;
6
- static buildGenericScope(analyzer: Analyzer, node: tree.StatementBlock): IScope;
7
- static buildScopeForMethodBlockLiteral(analyzer: Analyzer, node: tree.StatementBlock, parent: tree.MethodBlockLiteral): IScope;
8
- static buildScopeForPackageMethodDeclaration(analyzer: Analyzer, node: tree.StatementBlock, parent: tree.PackageMethodDeclaration): IScope;
9
- static buildScopeForTypeVariableGetterDeclaration(analyzer: Analyzer, node: tree.StatementBlock, parent: tree.TypeVariableGetterDeclaration): IScope;
10
- static buildScopeForTypeVariableSetterDeclaration(analyzer: Analyzer, node: tree.StatementBlock, parent: tree.TypeVariableSetterDeclaration): IScope;
11
- static buildScopeForPackageVariableGetterDeclaration(analyzer: Analyzer, node: tree.StatementBlock, parent: tree.PackageVariableGetterDeclaration): IScope;
12
- static buildScopeForPackageVariableSetterDeclaration(analyzer: Analyzer, node: tree.StatementBlock, parent: tree.PackageVariableSetterDeclaration): IScope;
13
- static buildScopeForTypeIndexedGetterDeclaration(analyzer: Analyzer, node: tree.StatementBlock, parent: tree.TypeIndexedGetterDeclaration): IScope;
14
- static buildScopeForTypeIndexedSetterDeclaration(analyzer: Analyzer, node: tree.StatementBlock, parent: tree.TypeIndexedSetterDeclaration): IScope;
15
- static buildScopeForTypeDereferencedVariableGetterDeclaration(analyzer: Analyzer, node: tree.StatementBlock, parent: tree.TypeDereferencedVariableGetterDeclaration): IScope;
16
- static buildScopeForTypeDereferencedVariableSetterDeclaration(analyzer: Analyzer, node: tree.StatementBlock, parent: tree.TypeDereferencedVariableSetterDeclaration): IScope;
17
- static buildScopeForNestedMethodDeclaration(analyzer: Analyzer, node: tree.StatementBlock, parent: tree.NestedMethodDeclaration): IScope;
18
- static buildScopeForMethodLiteral(analyzer: Analyzer, node: tree.StatementBlock, parent: tree.MethodLiteral): IScope;
19
- static buildScopeForTypeConstructorDeclaration(analyzer: Analyzer, node: tree.StatementBlock, parent: tree.TypeConstructorDeclaration): IScope;
20
- static buildScopeForTypeMethodDeclaration(analyzer: Analyzer, node: tree.StatementBlock, parent: tree.TypeMethodDeclaration): IScope;
21
- static buildScopeForOperatorDeclaration(analyzer: Analyzer, node: tree.StatementBlock, parent: tree.OperatorDeclaration): IScope;
5
+ static buildFunctionBlockScope(analyzer: Analyzer, node: tree.FunctionBlock): IScope;
6
+ static buildStatementBlockScope(analyzer: Analyzer, node: tree.StatementBlock): IScope;
7
+ static buildGenericScopeForFunctionBlock(analyzer: Analyzer, node: tree.FunctionBlock): IScope;
8
+ static buildGenericScopeForStatementBlock(analyzer: Analyzer, node: tree.StatementBlock): IScope;
9
+ static buildScopeForMethodBlockLiteral(analyzer: Analyzer, node: tree.FunctionBlock, parent: tree.MethodBlockLiteral): IScope;
10
+ static buildScopeForPackageMethodDeclaration(analyzer: Analyzer, node: tree.FunctionBlock, parent: tree.PackageMethodDeclaration): IScope;
11
+ static buildScopeForTypeVariableGetterDeclaration(analyzer: Analyzer, node: tree.FunctionBlock, parent: tree.TypeVariableGetterDeclaration): IScope;
12
+ static buildScopeForTypeVariableSetterDeclaration(analyzer: Analyzer, node: tree.FunctionBlock, parent: tree.TypeVariableSetterDeclaration): IScope;
13
+ static buildScopeForPackageVariableGetterDeclaration(analyzer: Analyzer, node: tree.FunctionBlock, parent: tree.PackageVariableGetterDeclaration): IScope;
14
+ static buildScopeForPackageVariableSetterDeclaration(analyzer: Analyzer, node: tree.FunctionBlock, parent: tree.PackageVariableSetterDeclaration): IScope;
15
+ static buildScopeForTypeIndexedGetterDeclaration(analyzer: Analyzer, node: tree.FunctionBlock, parent: tree.TypeIndexedGetterDeclaration): IScope;
16
+ static buildScopeForTypeIndexedSetterDeclaration(analyzer: Analyzer, node: tree.FunctionBlock, parent: tree.TypeIndexedSetterDeclaration): IScope;
17
+ static buildScopeForTypeDereferencedVariableGetterDeclaration(analyzer: Analyzer, node: tree.FunctionBlock, parent: tree.TypeDereferencedVariableGetterDeclaration): IScope;
18
+ static buildScopeForTypeDereferencedVariableSetterDeclaration(analyzer: Analyzer, node: tree.FunctionBlock, parent: tree.TypeDereferencedVariableSetterDeclaration): IScope;
19
+ static buildScopeForNestedMethodDeclaration(analyzer: Analyzer, node: tree.FunctionBlock, parent: tree.NestedMethodDeclaration): IScope;
20
+ static buildScopeForMethodLiteral(analyzer: Analyzer, node: tree.FunctionBlock, parent: tree.MethodLiteral): IScope;
21
+ static buildScopeForTypeConstructorDeclaration(analyzer: Analyzer, node: tree.FunctionBlock, parent: tree.TypeConstructorDeclaration): IScope;
22
+ static buildScopeForTypeMethodDeclaration(analyzer: Analyzer, node: tree.FunctionBlock, parent: tree.TypeMethodDeclaration): IScope;
23
+ static buildScopeForOperatorDeclaration(analyzer: Analyzer, node: tree.FunctionBlock, parent: tree.OperatorDeclaration): IScope;
22
24
  private static getLocalNamedDeclarations;
23
25
  }
@@ -0,0 +1,62 @@
1
+ import { LocalVariableEntity, ParameterVariableEntity } from '../entities/VariableEntity.js';
2
+ import * as types from '../types/index.js';
3
+ import { Analyzer } from './Analyzer.js';
4
+ import { ControlFlowNode, NarrowableReferenceExpression } from './ControlFlowGraphBuilder.js';
5
+ export declare class TypeNarrower {
6
+ private readonly _analyzer;
7
+ private readonly _referenceExpression;
8
+ private readonly _initialType;
9
+ private readonly _controlFlowNode;
10
+ private _reference;
11
+ private readonly _typeByNode;
12
+ constructor(analyzer: Analyzer, referenceExpression: NarrowableReferenceExpression, initialType: types.Type, controlFlowNode: ControlFlowNode);
13
+ getType(): types.Type;
14
+ private getTypeAtControlFlowNode;
15
+ private getTypeAtCondition;
16
+ private getTypeAtAssignment;
17
+ private getTypeAtSplit;
18
+ private getTypeAtLoop;
19
+ private getTypeAtComparisonWithNone;
20
+ private getTypeAtIsExpression;
21
+ private addTypeIfUnique;
22
+ private isSameReferenceAsNarrowedExpression;
23
+ private unwrapExpression;
24
+ private getReferenceAtNodeIfNarrowable;
25
+ private getReferenceAtNode;
26
+ private getReferenceAtLocalVariableDeclaration;
27
+ }
28
+ export type NarrowableReference = NarrowableReference.LocalVariable | NarrowableReference.InstanceTypeVariable | NarrowableReference.StaticTypeVariable | NarrowableReference.Object;
29
+ export declare namespace NarrowableReference {
30
+ export class LocalVariable implements INarrowableReference {
31
+ readonly entity: LocalVariableEntity | ParameterVariableEntity;
32
+ readonly kind = "local-variable";
33
+ constructor(entity: LocalVariableEntity | ParameterVariableEntity);
34
+ equals(other: NarrowableReference): boolean;
35
+ contains(_other: NarrowableReference): boolean;
36
+ }
37
+ export class InstanceTypeVariable implements INarrowableReference {
38
+ readonly variable: types.Variable;
39
+ readonly receiver: NarrowableReference;
40
+ readonly kind = "instance-type-variable";
41
+ constructor(variable: types.Variable, receiver: NarrowableReference);
42
+ equals(other: NarrowableReference): boolean;
43
+ contains(other: NarrowableReference): boolean;
44
+ }
45
+ export class StaticTypeVariable implements INarrowableReference {
46
+ readonly variable: types.Variable;
47
+ readonly kind = "static-type-variable";
48
+ constructor(variable: types.Variable);
49
+ equals(other: NarrowableReference): boolean;
50
+ contains(_other: NarrowableReference): boolean;
51
+ }
52
+ export class Object implements INarrowableReference {
53
+ readonly kind = "object";
54
+ equals(other: NarrowableReference): boolean;
55
+ contains(_other: NarrowableReference): boolean;
56
+ }
57
+ interface INarrowableReference {
58
+ equals(other: NarrowableReference): boolean;
59
+ contains(other: NarrowableReference): boolean;
60
+ }
61
+ export {};
62
+ }
@@ -5,6 +5,7 @@ export declare class Range {
5
5
  get isEmpty(): boolean;
6
6
  constructor(start: number, end: number);
7
7
  includes(offset: number): boolean;
8
+ includes(range: Range): boolean;
8
9
  equals(other: Range): boolean;
9
10
  static empty(start: number): Range;
10
11
  }