tsc-ts 0.0.10 → 0.1.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/README.md +1 -1
- package/bin/tsc-ts.js +70 -1
- package/dist/api/compiler/ast-utilities.d.ts +19 -1
- package/dist/api/compiler/ast-utilities.js +180 -95
- package/dist/api/compiler/ast.d.ts +20 -15
- package/dist/api/compiler/ast.js +1023 -995
- package/dist/api/compiler/astnav.js +15 -15
- package/dist/api/compiler/binder-utilities.js +186 -186
- package/dist/api/compiler/binder.js +290 -263
- package/dist/api/compiler/character-codes.js +2 -2
- package/dist/api/compiler/checker-calls.js +173 -123
- package/dist/api/compiler/checker-classes.d.ts +14 -3
- package/dist/api/compiler/checker-classes.js +134 -90
- package/dist/api/compiler/checker-contextual.js +64 -61
- package/dist/api/compiler/checker-declaration-order.js +79 -79
- package/dist/api/compiler/checker-declarations.d.ts +1 -0
- package/dist/api/compiler/checker-declarations.js +160 -136
- package/dist/api/compiler/checker-declared-types.js +67 -65
- package/dist/api/compiler/checker-decorators.js +77 -77
- package/dist/api/compiler/checker-deprecation.d.ts +8 -3
- package/dist/api/compiler/checker-deprecation.js +76 -55
- package/dist/api/compiler/checker-destructuring.js +47 -45
- package/dist/api/compiler/checker-elaboration.js +24 -24
- package/dist/api/compiler/checker-emit-helpers.js +4 -4
- package/dist/api/compiler/checker-emit-resolver.d.ts +4 -2
- package/dist/api/compiler/checker-emit-resolver.js +25 -13
- package/dist/api/compiler/checker-evaluator.js +9 -9
- package/dist/api/compiler/checker-expressions.js +244 -211
- package/dist/api/compiler/checker-functions.js +113 -107
- package/dist/api/compiler/checker-generated-code.d.ts +0 -11
- package/dist/api/compiler/checker-generated-code.js +28 -52
- package/dist/api/compiler/checker-grammar.d.ts +1 -0
- package/dist/api/compiler/checker-grammar.js +469 -438
- package/dist/api/compiler/checker-heritage.js +91 -93
- package/dist/api/compiler/checker-inference.d.ts +77 -5
- package/dist/api/compiler/checker-inference.js +487 -113
- package/dist/api/compiler/checker-iteration.d.ts +0 -10
- package/dist/api/compiler/checker-iteration.js +35 -52
- package/dist/api/compiler/checker-javascript.js +14 -14
- package/dist/api/compiler/checker-jsdoc.d.ts +8 -10
- package/dist/api/compiler/checker-jsdoc.js +67 -58
- package/dist/api/compiler/checker-jsx.js +105 -88
- package/dist/api/compiler/checker-members.d.ts +9 -2
- package/dist/api/compiler/checker-members.js +210 -74
- package/dist/api/compiler/checker-modules.d.ts +15 -6
- package/dist/api/compiler/checker-modules.js +469 -309
- package/dist/api/compiler/checker-narrowing.js +273 -189
- package/dist/api/compiler/checker-object-literals.js +25 -22
- package/dist/api/compiler/checker-operators.js +126 -118
- package/dist/api/compiler/checker-overloads.js +27 -27
- package/dist/api/compiler/checker-property-access.js +59 -55
- package/dist/api/compiler/checker-services.d.ts +1 -0
- package/dist/api/compiler/checker-services.js +222 -210
- package/dist/api/compiler/checker-signatures.js +65 -49
- package/dist/api/compiler/checker-source-file.d.ts +5 -0
- package/dist/api/compiler/checker-source-file.js +154 -130
- package/dist/api/compiler/checker-statements.js +33 -32
- package/dist/api/compiler/checker-super.js +50 -50
- package/dist/api/compiler/checker-symbol-types.js +109 -93
- package/dist/api/compiler/checker-symbols.d.ts +13 -1
- package/dist/api/compiler/checker-symbols.js +264 -149
- package/dist/api/compiler/checker-type-factory.d.ts +5 -0
- package/dist/api/compiler/checker-type-factory.js +137 -34
- package/dist/api/compiler/checker-type-nodes.d.ts +1 -0
- package/dist/api/compiler/checker-type-nodes.js +179 -141
- package/dist/api/compiler/checker-type-operators.d.ts +2 -0
- package/dist/api/compiler/checker-type-operators.js +110 -63
- package/dist/api/compiler/checker-types.d.ts +80 -3
- package/dist/api/compiler/checker-types.js +121 -2
- package/dist/api/compiler/checker-unused.js +114 -118
- package/dist/api/compiler/checker-utilities.js +11 -11
- package/dist/api/compiler/checker.d.ts +93 -31
- package/dist/api/compiler/checker.js +143 -35
- package/dist/api/compiler/command-line.d.ts +1 -3
- package/dist/api/compiler/command-line.js +47 -44
- package/dist/api/compiler/compile-program.d.ts +19 -4
- package/dist/api/compiler/compile-program.js +45 -26
- package/dist/api/compiler/diagnostic-messages.d.ts +1849 -1774
- package/dist/api/compiler/diagnostic-messages.js +128 -122
- package/dist/api/compiler/diagnostics.js +7 -7
- package/dist/api/compiler/emitter.d.ts +7 -1
- package/dist/api/compiler/emitter.js +53 -11
- package/dist/api/compiler/file-include.d.ts +2 -1
- package/dist/api/compiler/file-include.js +11 -7
- package/dist/api/compiler/file-loader.d.ts +10 -0
- package/dist/api/compiler/file-loader.js +138 -41
- package/dist/api/compiler/instantiation.d.ts +7 -0
- package/dist/api/compiler/instantiation.js +101 -49
- package/dist/api/compiler/jsdoc.js +23 -23
- package/dist/api/compiler/link-tables.d.ts +48 -18
- package/dist/api/compiler/link-tables.js +80 -37
- package/dist/api/compiler/locales/cs-CZ.d.ts +1 -1
- package/dist/api/compiler/locales/cs-CZ.js +1 -1
- package/dist/api/compiler/locales/de-DE.d.ts +1 -1
- package/dist/api/compiler/locales/de-DE.js +1 -1
- package/dist/api/compiler/locales/es-ES.d.ts +1 -1
- package/dist/api/compiler/locales/es-ES.js +1 -1
- package/dist/api/compiler/locales/fr-FR.d.ts +1 -1
- package/dist/api/compiler/locales/fr-FR.js +1 -1
- package/dist/api/compiler/locales/it-IT.d.ts +1 -1
- package/dist/api/compiler/locales/it-IT.js +1 -1
- package/dist/api/compiler/locales/ja-JP.d.ts +1 -1
- package/dist/api/compiler/locales/ja-JP.js +1 -1
- package/dist/api/compiler/locales/ko-KR.d.ts +1 -1
- package/dist/api/compiler/locales/ko-KR.js +1 -1
- package/dist/api/compiler/locales/pl-PL.d.ts +1 -1
- package/dist/api/compiler/locales/pl-PL.js +1 -1
- package/dist/api/compiler/locales/pt-BR.d.ts +1 -1
- package/dist/api/compiler/locales/pt-BR.js +1 -1
- package/dist/api/compiler/locales/ru-RU.d.ts +1 -1
- package/dist/api/compiler/locales/ru-RU.js +1 -1
- package/dist/api/compiler/locales/tr-TR.d.ts +1 -1
- package/dist/api/compiler/locales/tr-TR.js +1 -1
- package/dist/api/compiler/locales/zh-CN.d.ts +1 -1
- package/dist/api/compiler/locales/zh-CN.js +1 -1
- package/dist/api/compiler/locales/zh-TW.d.ts +1 -1
- package/dist/api/compiler/locales/zh-TW.js +1 -1
- package/dist/api/compiler/module-resolution-types.js +6 -6
- package/dist/api/compiler/module-resolution.d.ts +10 -1
- package/dist/api/compiler/module-resolution.js +115 -84
- package/dist/api/compiler/module-specifiers.d.ts +15 -0
- package/dist/api/compiler/module-specifiers.js +24 -18
- package/dist/api/compiler/name-resolver.js +74 -65
- package/dist/api/compiler/node-builder-names.d.ts +11 -3
- package/dist/api/compiler/node-builder-names.js +210 -90
- package/dist/api/compiler/node-builder-pseudo.js +29 -31
- package/dist/api/compiler/node-builder-reuse.js +23 -22
- package/dist/api/compiler/node-builder.d.ts +18 -1
- package/dist/api/compiler/node-builder.js +191 -102
- package/dist/api/compiler/option-declarations.d.ts +2 -6
- package/dist/api/compiler/option-declarations.js +315 -375
- package/dist/api/compiler/options.d.ts +15 -33
- package/dist/api/compiler/options.js +21 -54
- package/dist/api/compiler/output-paths.d.ts +4 -1
- package/dist/api/compiler/output-paths.js +6 -11
- package/dist/api/compiler/package-json.d.ts +3 -3
- package/dist/api/compiler/package-json.js +11 -10
- package/dist/api/compiler/parser.d.ts +40 -19
- package/dist/api/compiler/parser.js +308 -216
- package/dist/api/compiler/path.d.ts +9 -0
- package/dist/api/compiler/path.js +20 -3
- package/dist/api/compiler/printer/emit-context.d.ts +3 -1
- package/dist/api/compiler/printer/emit-context.js +16 -1
- package/dist/api/compiler/printer/factory-base.d.ts +2 -2
- package/dist/api/compiler/printer/factory-base.js +7 -3
- package/dist/api/compiler/printer/factory.js +3 -1
- package/dist/api/compiler/printer/helpers.js +10 -1
- package/dist/api/compiler/printer/name-generator.d.ts +1 -1
- package/dist/api/compiler/printer/name-generator.js +35 -16
- package/dist/api/compiler/printer/printer.d.ts +1 -0
- package/dist/api/compiler/printer/printer.js +303 -281
- package/dist/api/compiler/printer/utilities.js +149 -147
- package/dist/api/compiler/program-checker.d.ts +8 -2
- package/dist/api/compiler/program-checker.js +84 -34
- package/dist/api/compiler/program-utilities.d.ts +3 -1
- package/dist/api/compiler/program-utilities.js +28 -15
- package/dist/api/compiler/program.d.ts +2 -0
- package/dist/api/compiler/program.js +69 -57
- package/dist/api/compiler/pseudo-bigint.d.ts +2 -0
- package/dist/api/compiler/pseudo-bigint.js +18 -0
- package/dist/api/compiler/regexp-checker.d.ts +1 -1
- package/dist/api/compiler/regexp-checker.js +93 -76
- package/dist/api/compiler/relations.d.ts +27 -4
- package/dist/api/compiler/relations.js +337 -180
- package/dist/api/compiler/reparser.js +60 -56
- package/dist/api/compiler/scanner.d.ts +19 -2
- package/dist/api/compiler/scanner.js +123 -108
- package/dist/api/compiler/shared-results.d.ts +463 -0
- package/dist/api/compiler/shared-results.js +2128 -0
- package/dist/api/compiler/sourcemap.js +2 -2
- package/dist/api/compiler/symbol-accessibility.js +87 -74
- package/dist/api/compiler/symbol.d.ts +22 -13
- package/dist/api/compiler/symbol.js +15 -1
- package/dist/api/compiler/syntax-kind.d.ts +198 -197
- package/dist/api/compiler/transformers/alias-references.js +247 -139
- package/dist/api/compiler/transformers/async-utilities.js +25 -25
- package/dist/api/compiler/transformers/async.d.ts +0 -1
- package/dist/api/compiler/transformers/async.js +64 -77
- package/dist/api/compiler/transformers/class-fields.d.ts +1 -0
- package/dist/api/compiler/transformers/class-fields.js +81 -78
- package/dist/api/compiler/transformers/commonjs-module.js +18 -15
- package/dist/api/compiler/transformers/const-enum-inliner.js +1 -1
- package/dist/api/compiler/transformers/declarations-diagnostics.js +247 -244
- package/dist/api/compiler/transformers/declarations-pseudo.js +100 -100
- package/dist/api/compiler/transformers/declarations-resolver.d.ts +0 -3
- package/dist/api/compiler/transformers/declarations-syntactic.d.ts +1 -2
- package/dist/api/compiler/transformers/declarations-syntactic.js +134 -156
- package/dist/api/compiler/transformers/declarations-tracker.js +18 -18
- package/dist/api/compiler/transformers/declarations.d.ts +4 -1
- package/dist/api/compiler/transformers/declarations.js +305 -238
- package/dist/api/compiler/transformers/decorator-metadata.d.ts +1 -1
- package/dist/api/compiler/transformers/decorator-metadata.js +53 -45
- package/dist/api/compiler/transformers/decorator-utilities.js +24 -24
- package/dist/api/compiler/transformers/destructuring.js +19 -18
- package/dist/api/compiler/transformers/emit-resolver.js +1 -1
- package/dist/api/compiler/transformers/es-decorators.js +55 -55
- package/dist/api/compiler/transformers/external-module-info.js +3 -3
- package/dist/api/compiler/transformers/for-await.js +25 -25
- package/dist/api/compiler/transformers/import-elision.js +14 -14
- package/dist/api/compiler/transformers/jsx.js +12 -12
- package/dist/api/compiler/transformers/legacy-decorators.js +17 -17
- package/dist/api/compiler/transformers/module.js +8 -8
- package/dist/api/compiler/transformers/named-evaluation.js +4 -4
- package/dist/api/compiler/transformers/object-rest-spread.js +20 -20
- package/dist/api/compiler/transformers/optional-chain.js +10 -10
- package/dist/api/compiler/transformers/reference-resolver.d.ts +12 -1
- package/dist/api/compiler/transformers/reference-resolver.js +131 -69
- package/dist/api/compiler/transformers/runtime-syntax.js +35 -31
- package/dist/api/compiler/transformers/subtree-facts.js +47 -47
- package/dist/api/compiler/transformers/syntax-facts.js +56 -58
- package/dist/api/compiler/transformers/type-eraser.js +73 -66
- package/dist/api/compiler/transformers/type-serialization.js +24 -24
- package/dist/api/compiler/transformers/using.js +12 -12
- package/dist/api/compiler/transformers/utilities.js +77 -77
- package/dist/api/compiler/transformers/visitor-base.js +172 -172
- package/dist/api/compiler/transformers/visitor-hooks.js +6 -2
- package/dist/api/compiler/tsconfig.d.ts +10 -2
- package/dist/api/compiler/tsconfig.js +136 -48
- package/dist/api/compiler/type-printer.js +40 -3
- package/dist/api/compiler/types.d.ts +2 -1
- package/dist/api/library/ast.generated.d.ts +42 -39
- package/dist/api/library/ast.generated.js +1 -1
- package/dist/api/library/compiler-options.generated.d.ts +111 -100
- package/dist/api/library/compiler-options.generated.js +1 -1
- package/dist/api/library/disk.js +12 -1
- package/dist/api/library/enums.generated.d.ts +206 -206
- package/dist/api/library/enums.generated.js +206 -206
- package/dist/api/library/nodes.js +26 -26
- package/package.json +9 -9
- package/src/compiler/ast-utilities.ts +99 -7
- package/src/compiler/ast.ts +55 -26
- package/src/compiler/binder.ts +39 -4
- package/src/compiler/character-codes.ts +2 -2
- package/src/compiler/checker-calls.ts +76 -8
- package/src/compiler/checker-classes.ts +78 -24
- package/src/compiler/checker-contextual.ts +6 -1
- package/src/compiler/checker-declarations.ts +31 -4
- package/src/compiler/checker-declared-types.ts +8 -5
- package/src/compiler/checker-decorators.ts +1 -1
- package/src/compiler/checker-deprecation.ts +29 -8
- package/src/compiler/checker-destructuring.ts +10 -3
- package/src/compiler/checker-emit-helpers.ts +1 -0
- package/src/compiler/checker-emit-resolver.ts +16 -6
- package/src/compiler/checker-expressions.ts +79 -46
- package/src/compiler/checker-functions.ts +21 -6
- package/src/compiler/checker-generated-code.ts +2 -22
- package/src/compiler/checker-grammar.ts +133 -60
- package/src/compiler/checker-heritage.ts +22 -21
- package/src/compiler/checker-inference.ts +514 -87
- package/src/compiler/checker-iteration.ts +18 -31
- package/src/compiler/checker-javascript.ts +1 -1
- package/src/compiler/checker-jsdoc.ts +50 -27
- package/src/compiler/checker-jsx.ts +26 -4
- package/src/compiler/checker-members.ts +197 -55
- package/src/compiler/checker-modules.ts +332 -65
- package/src/compiler/checker-narrowing.ts +98 -19
- package/src/compiler/checker-object-literals.ts +3 -0
- package/src/compiler/checker-operators.ts +11 -4
- package/src/compiler/checker-property-access.ts +7 -2
- package/src/compiler/checker-services.ts +39 -12
- package/src/compiler/checker-signatures.ts +15 -1
- package/src/compiler/checker-source-file.ts +39 -13
- package/src/compiler/checker-statements.ts +3 -2
- package/src/compiler/checker-symbol-types.ts +29 -6
- package/src/compiler/checker-symbols.ts +158 -15
- package/src/compiler/checker-type-factory.ts +120 -21
- package/src/compiler/checker-type-nodes.ts +46 -3
- package/src/compiler/checker-type-operators.ts +83 -26
- package/src/compiler/checker-types.ts +147 -4
- package/src/compiler/checker-unused.ts +9 -14
- package/src/compiler/checker.ts +168 -41
- package/src/compiler/command-line.ts +28 -28
- package/src/compiler/compile-program.ts +51 -25
- package/src/compiler/decoder.ts +13 -4
- package/src/compiler/diagnostic-messages.ts +1973 -1892
- package/src/compiler/emitter.ts +57 -8
- package/src/compiler/encoder.ts +23 -8
- package/src/compiler/file-include.ts +9 -3
- package/src/compiler/file-loader.ts +139 -32
- package/src/compiler/help.ts +10 -14
- package/src/compiler/incremental.ts +86 -18
- package/src/compiler/init.ts +2 -7
- package/src/compiler/instantiation.ts +77 -22
- package/src/compiler/jsdoc.ts +3 -1
- package/src/compiler/link-tables.ts +82 -37
- package/src/compiler/locales/cs-CZ.ts +1 -1
- package/src/compiler/locales/de-DE.ts +1 -1
- package/src/compiler/locales/es-ES.ts +1 -1
- package/src/compiler/locales/fr-FR.ts +1 -1
- package/src/compiler/locales/it-IT.ts +1 -1
- package/src/compiler/locales/ja-JP.ts +1 -1
- package/src/compiler/locales/ko-KR.ts +1 -1
- package/src/compiler/locales/pl-PL.ts +1 -1
- package/src/compiler/locales/pt-BR.ts +1 -1
- package/src/compiler/locales/ru-RU.ts +1 -1
- package/src/compiler/locales/tr-TR.ts +1 -1
- package/src/compiler/locales/zh-CN.ts +1 -1
- package/src/compiler/locales/zh-TW.ts +1 -1
- package/src/compiler/module-resolution.ts +44 -8
- package/src/compiler/module-specifiers.ts +62 -20
- package/src/compiler/name-resolver.ts +9 -1
- package/src/compiler/node-builder-names.ts +236 -54
- package/src/compiler/node-builder-pseudo.ts +4 -7
- package/src/compiler/node-builder-reuse.ts +5 -4
- package/src/compiler/node-builder.ts +130 -31
- package/src/compiler/option-declarations.ts +33 -103
- package/src/compiler/options.ts +23 -62
- package/src/compiler/output-paths.ts +5 -18
- package/src/compiler/package-entrypoints.ts +345 -0
- package/src/compiler/package-json.ts +4 -4
- package/src/compiler/parallel-check.ts +197 -8
- package/src/compiler/parallel-emit.ts +1 -1
- package/src/compiler/parser.ts +156 -39
- package/src/compiler/path.ts +22 -2
- package/src/compiler/printer/emit-context.ts +16 -0
- package/src/compiler/printer/factory-base.ts +10 -3
- package/src/compiler/printer/factory.ts +4 -1
- package/src/compiler/printer/helpers.ts +10 -1
- package/src/compiler/printer/name-generator.ts +24 -2
- package/src/compiler/printer/printer.ts +35 -14
- package/src/compiler/printer/utilities.ts +8 -2
- package/src/compiler/program-checker.ts +53 -5
- package/src/compiler/program-utilities.ts +23 -10
- package/src/compiler/program.ts +13 -1
- package/src/compiler/pseudo-bigint.ts +17 -0
- package/src/compiler/regexp-checker.ts +63 -30
- package/src/compiler/relations.ts +233 -77
- package/src/compiler/reparser.ts +7 -2
- package/src/compiler/scanner.ts +109 -79
- package/src/compiler/shared-results.ts +2414 -0
- package/src/compiler/show-config.ts +18 -1
- package/src/compiler/sourcemap.ts +2 -2
- package/src/compiler/symbol-accessibility.ts +26 -3
- package/src/compiler/symbol.ts +31 -14
- package/src/compiler/syntax-kind.ts +188 -187
- package/src/compiler/thread-entry.ts +19 -2
- package/src/compiler/transformers/alias-references.ts +123 -4
- package/src/compiler/transformers/async.ts +2 -17
- package/src/compiler/transformers/class-fields.ts +13 -12
- package/src/compiler/transformers/commonjs-module.ts +11 -7
- package/src/compiler/transformers/declarations-diagnostics.ts +5 -3
- package/src/compiler/transformers/declarations-pseudo.ts +2 -4
- package/src/compiler/transformers/declarations-resolver.ts +0 -3
- package/src/compiler/transformers/declarations-syntactic.ts +1 -21
- package/src/compiler/transformers/declarations.ts +134 -48
- package/src/compiler/transformers/decorator-metadata.ts +9 -1
- package/src/compiler/transformers/destructuring.ts +4 -3
- package/src/compiler/transformers/external-module-info.ts +1 -1
- package/src/compiler/transformers/jsx.ts +2 -1
- package/src/compiler/transformers/reference-resolver.ts +83 -19
- package/src/compiler/transformers/runtime-syntax.ts +6 -1
- package/src/compiler/transformers/syntax-facts.ts +2 -7
- package/src/compiler/transformers/type-eraser.ts +10 -1
- package/src/compiler/transformers/type-serialization.ts +3 -2
- package/src/compiler/transformers/visitor-base.ts +2 -1
- package/src/compiler/transformers/visitor-hooks.ts +9 -4
- package/src/compiler/tsc-build.ts +3 -0
- package/src/compiler/tsc-cli.ts +2 -0
- package/src/compiler/tsc-compile.ts +7 -2
- package/src/compiler/tsc-watch.ts +74 -45
- package/src/compiler/tsconfig.ts +176 -19
- package/src/compiler/type-printer.ts +36 -2
- package/src/compiler/types.ts +2 -1
- package/src/library/ast.generated.ts +57 -41
- package/src/library/compiler-options.generated.ts +117 -103
- package/src/library/disk.ts +10 -1
- package/src/library/enums.generated.ts +196 -196
|
@@ -10,7 +10,7 @@ import { isPartOfTypeNode } from './transformers/alias-references.js';
|
|
|
10
10
|
import { createDiagnosticForNode } from './checker.js';
|
|
11
11
|
import { TypePredicate } from './checker-types.js';
|
|
12
12
|
import { filterType, getIntersectionType, getRegularTypeOfLiteralType, getUnionTypeEx, isErrorType, isUnitType, someType, } from './checker-type-factory.js';
|
|
13
|
-
import { getTypeOfSymbol, getWidenedType, isPrivateWithinAmbient, reportErrorsFromWidening, reportImplicitAny, } from './checker-symbol-types.js';
|
|
13
|
+
import { getTypeOfSymbol, getWidenedType, isPrivateWithinAmbient, reportErrorsFromWidening, reportImplicitAny, getWidenedTypeForVariableLikeDeclaration, } from './checker-symbol-types.js';
|
|
14
14
|
import { getMergedSymbol, getSymbolOfDeclaration } from './checker-symbols.js';
|
|
15
15
|
import { getReturnTypeFromAnnotation, getReturnTypeOfSignature, getSignatureFromDeclaration, } from './checker-signatures.js';
|
|
16
16
|
import { checkExpression, checkExpressionCached, getWidenedLiteralLikeTypeForContextualType, isConstContext, } from './checker-expressions.js';
|
|
@@ -31,7 +31,7 @@ import { isTypeAssignableTo } from './relations.js';
|
|
|
31
31
|
import { inferTypes } from './checker-inference.js';
|
|
32
32
|
import { couldContainTypeVariables, instantiateSignature } from './instantiation.js';
|
|
33
33
|
import { getContextualSignatureForFunctionLikeDeclaration, getInferenceContext, instantiateContextualType, } from './checker-contextual.js';
|
|
34
|
-
import { checkJSDocFullSignature, checkUnmatchedJSDocParameters, getFullSignatureTypeNode } from './checker-jsdoc.js';
|
|
34
|
+
import { checkJSDocFullSignature, checkJSDocFullSignatureType, checkUnmatchedJSDocParameters, getFullSignatureTypeNode, } from './checker-jsdoc.js';
|
|
35
35
|
import { getEffectiveCheckNode, isFunctionLike, nodeIsMissing } from './ast-utilities.js';
|
|
36
36
|
import { getFlowTypeOfReferenceAt, isConstantReference, isReachableFlowNode, isSymbolAssigned, } from './checker-narrowing.js';
|
|
37
37
|
import { FlowNode } from './flow.js';
|
|
@@ -40,9 +40,10 @@ import { typeToString } from './type-printer.js';
|
|
|
40
40
|
import { checkGrammarAwaitExpression, checkGrammarFunctionExpression, checkGrammarYieldOfExpression, } from './checker-grammar.js';
|
|
41
41
|
export function checkFunctionExpressionOrObjectLiteralMethod(c, node, checkMode) {
|
|
42
42
|
checkNodeDeferred(c, node);
|
|
43
|
-
|
|
43
|
+
checkJSDocFullSignatureType(c, node);
|
|
44
|
+
if (node.kind === 220 /* SyntaxKind.FunctionExpression */)
|
|
44
45
|
checkCollisionsForDeclarationName(c, node, getName(node));
|
|
45
|
-
if (node.kind ===
|
|
46
|
+
if (node.kind === 179 /* SyntaxKind.GetAccessor */ || node.kind === 180 /* SyntaxKind.SetAccessor */)
|
|
46
47
|
return c.anyType;
|
|
47
48
|
if ((checkMode & 4 /* CheckMode.SkipContextSensitive */) !== 0 && isContextSensitive(c, node)) {
|
|
48
49
|
// Skip parameters, but keep a return type with the non-contextual parts so that inferences can
|
|
@@ -64,7 +65,7 @@ export function checkFunctionExpressionOrObjectLiteralMethod(c, node, checkMode)
|
|
|
64
65
|
}
|
|
65
66
|
return c.anyFunctionType;
|
|
66
67
|
}
|
|
67
|
-
if (node.kind ===
|
|
68
|
+
if (node.kind === 220 /* SyntaxKind.FunctionExpression */ || node.kind === 221 /* SyntaxKind.ArrowFunction */)
|
|
68
69
|
checkGrammarFunctionExpression(c, node);
|
|
69
70
|
checkJSDocFullSignature(c, node);
|
|
70
71
|
contextuallyCheckFunctionExpressionOrObjectLiteralMethod(c, node, checkMode);
|
|
@@ -118,7 +119,8 @@ function contextuallyCheckFunctionExpressionOrObjectLiteralMethod(c, node, check
|
|
|
118
119
|
if (contextualSignature !== undefined &&
|
|
119
120
|
getType(node) === undefined &&
|
|
120
121
|
resolvedReturnTypeOf(c, signature) === undefined) {
|
|
121
|
-
|
|
122
|
+
// The resolved return type is cached, so it is computed without SkipContextSensitive to keep anyFunctionType out of it.
|
|
123
|
+
const returnType = getReturnTypeFromBodyEx(c, node, checkMode & ~4 /* CheckMode.SkipContextSensitive */);
|
|
122
124
|
if (resolvedReturnTypeOf(c, signature) === undefined)
|
|
123
125
|
signatureSideOf(c, signature).resolvedReturnType = returnType;
|
|
124
126
|
}
|
|
@@ -190,7 +192,9 @@ function assignParameterSymbolType(c, parameter, contextualType) {
|
|
|
190
192
|
return;
|
|
191
193
|
const declaration = parameter.valueDeclaration;
|
|
192
194
|
if (contextualType === undefined) {
|
|
193
|
-
c.symbolTypes.set(id,
|
|
195
|
+
c.symbolTypes.set(id, declaration !== undefined
|
|
196
|
+
? getWidenedTypeForVariableLikeDeclaration(c, declaration, true)
|
|
197
|
+
: getTypeOfSymbol(c, parameter));
|
|
194
198
|
return;
|
|
195
199
|
}
|
|
196
200
|
c.symbolTypes.set(id, addOptionality(c, contextualType, false, declaration !== undefined && getInitializer(declaration) === undefined && isOptionalDeclaration(declaration)));
|
|
@@ -200,10 +204,10 @@ function assignParameterSymbolType(c, parameter, contextualType) {
|
|
|
200
204
|
// Without a better inference than `unknown`, a binding pattern implies the type.
|
|
201
205
|
if (c.symbolTypes.get(id) === c.unknownType &&
|
|
202
206
|
name !== undefined &&
|
|
203
|
-
(name.kind ===
|
|
207
|
+
(name.kind === 208 /* SyntaxKind.ObjectBindingPattern */ || name.kind === 209 /* SyntaxKind.ArrayBindingPattern */))
|
|
204
208
|
c.symbolTypes.set(id, getTypeFromBindingPattern(c, name, false, false));
|
|
205
209
|
if (name !== undefined &&
|
|
206
|
-
(name.kind ===
|
|
210
|
+
(name.kind === 208 /* SyntaxKind.ObjectBindingPattern */ || name.kind === 209 /* SyntaxKind.ArrayBindingPattern */))
|
|
207
211
|
assignBindingElementTypes(c, name, c.symbolTypes.get(id));
|
|
208
212
|
}
|
|
209
213
|
export function getTypeOfObjectLiteralMethod(c, node, checkMode) {
|
|
@@ -245,23 +249,23 @@ export function checkFunctionLikeBody(c, node) {
|
|
|
245
249
|
// Function and class method declarations without a body or return type return `any`.
|
|
246
250
|
if (returnTypeNode === undefined &&
|
|
247
251
|
nodeIsMissing(body) &&
|
|
248
|
-
(node.kind ===
|
|
249
|
-
(node.kind ===
|
|
252
|
+
(node.kind === 264 /* SyntaxKind.FunctionDeclaration */ ||
|
|
253
|
+
(node.kind === 176 /* SyntaxKind.MethodDeclaration */ && node.parent.kind !== 212 /* SyntaxKind.ObjectLiteralExpression */)) &&
|
|
250
254
|
!isPrivateWithinAmbient(node))
|
|
251
255
|
reportImplicitAny(c, node, c.anyType);
|
|
252
256
|
if (body === undefined)
|
|
253
257
|
return;
|
|
254
|
-
const returnType = node.kind !==
|
|
258
|
+
const returnType = node.kind !== 178 /* SyntaxKind.Constructor */ ? getReturnTypeFromAnnotation(c, node) : undefined;
|
|
255
259
|
// Errors only found while inferring the return type (such as of yielded values) need it resolved.
|
|
256
260
|
if (returnTypeNode === undefined &&
|
|
257
261
|
(isFunctionExpressionOrArrowFunction(node) ||
|
|
258
262
|
isObjectLiteralMethod(node) ||
|
|
259
|
-
((functionFlags & 1 /* FunctionFlags.Generator */) !== 0 && node.kind !==
|
|
263
|
+
((functionFlags & 1 /* FunctionFlags.Generator */) !== 0 && node.kind !== 178 /* SyntaxKind.Constructor */)))
|
|
260
264
|
getReturnTypeOfSignature(c, getSignatureFromDeclaration(c, node));
|
|
261
|
-
if (body.kind ===
|
|
265
|
+
if (body.kind === 243 /* SyntaxKind.Block */) {
|
|
262
266
|
for (const s of getStatements(body).nodes)
|
|
263
267
|
checkSourceElement(c, s);
|
|
264
|
-
if (node.kind !==
|
|
268
|
+
if (node.kind !== 178 /* SyntaxKind.Constructor */ && node.kind !== 180 /* SyntaxKind.SetAccessor */)
|
|
265
269
|
checkAllCodePathsInNonVoidFunctionReturnOrThrow(c, node, returnType);
|
|
266
270
|
}
|
|
267
271
|
else {
|
|
@@ -276,7 +280,7 @@ function checkSignatureReturnType(c, node, returnTypeNode, functionFlags) {
|
|
|
276
280
|
if ((functionFlags & (4 /* FunctionFlags.Invalid */ | 1 /* FunctionFlags.Generator */)) === 1 /* FunctionFlags.Generator */) {
|
|
277
281
|
const returnType = getTypeFromTypeNode(c, returnTypeNode);
|
|
278
282
|
if (returnType === c.voidType)
|
|
279
|
-
c.error(returnTypeNode,
|
|
283
|
+
c.error(returnTypeNode, 672 /* Diagnostics.A_generator_cannot_have_a_void_type_annotation */);
|
|
280
284
|
else
|
|
281
285
|
checkGeneratorInstantiationAssignabilityToReturnType(c, returnType, functionFlags, returnTypeNode);
|
|
282
286
|
}
|
|
@@ -304,20 +308,20 @@ function checkAllCodePathsInNonVoidFunctionReturnOrThrow(c, func, returnType) {
|
|
|
304
308
|
return;
|
|
305
309
|
// Signatures, expression bodies and bodies that end in a return or throw have nothing to check.
|
|
306
310
|
const body = getBody(func);
|
|
307
|
-
if (func.kind ===
|
|
311
|
+
if (func.kind === 175 /* SyntaxKind.MethodSignature */ ||
|
|
308
312
|
body === undefined ||
|
|
309
313
|
nodeIsMissing(body) ||
|
|
310
|
-
body.kind !==
|
|
314
|
+
body.kind !== 243 /* SyntaxKind.Block */ ||
|
|
311
315
|
!functionHasImplicitReturn(c, func))
|
|
312
316
|
return;
|
|
313
317
|
const hasExplicitReturn = (func.flags & 512 /* NodeFlags.HasExplicitReturn */) !== 0;
|
|
314
318
|
const errorNode = getType(func) ?? getFullSignatureTypeNode(func) ?? func;
|
|
315
319
|
if (t !== undefined && (t.flags & 262144 /* TypeFlags.Never */) !== 0)
|
|
316
|
-
c.error(errorNode,
|
|
320
|
+
c.error(errorNode, 699 /* Diagnostics.A_function_returning_never_cannot_have_a_reachable_end_point */);
|
|
317
321
|
else if (t !== undefined && !hasExplicitReturn)
|
|
318
|
-
c.error(errorNode,
|
|
322
|
+
c.error(errorNode, 538 /* Diagnostics.A_function_whose_declared_type_is_neither_undefined_void_nor_any_must_return_a_value */);
|
|
319
323
|
else if (t !== undefined && c.strictNullChecks && !isTypeAssignableTo(c, c.undefinedType, t))
|
|
320
|
-
c.error(errorNode,
|
|
324
|
+
c.error(errorNode, 547 /* Diagnostics.Function_lacks_ending_return_statement_and_return_type_does_not_include_undefined */);
|
|
321
325
|
else if (c.compilerOptions.noImplicitReturns === true) {
|
|
322
326
|
if (t === undefined) {
|
|
323
327
|
// Without an annotation, only functions that return values other than void or any are checked.
|
|
@@ -327,7 +331,7 @@ function checkAllCodePathsInNonVoidFunctionReturnOrThrow(c, func, returnType) {
|
|
|
327
331
|
if (isUnwrappedReturnTypeUndefinedVoidOrAny(c, func, inferredReturnType))
|
|
328
332
|
return;
|
|
329
333
|
}
|
|
330
|
-
c.error(errorNode,
|
|
334
|
+
c.error(errorNode, 1720 /* Diagnostics.Not_all_code_paths_return_a_value */);
|
|
331
335
|
}
|
|
332
336
|
}
|
|
333
337
|
export function isUnwrappedReturnTypeUndefinedVoidOrAny(c, func, returnType) {
|
|
@@ -346,7 +350,7 @@ export function checkReturnExpression(c, container, unwrappedReturnType, node, e
|
|
|
346
350
|
const functionFlags = getFunctionFlags(container);
|
|
347
351
|
if (expr !== undefined) {
|
|
348
352
|
const unwrappedExpr = skipParentheses(expr);
|
|
349
|
-
if (unwrappedExpr.kind ===
|
|
353
|
+
if (unwrappedExpr.kind === 229 /* SyntaxKind.ConditionalExpression */) {
|
|
350
354
|
const conditional = unwrappedExpr;
|
|
351
355
|
const whenTrue = conditional.whenTrue;
|
|
352
356
|
const whenFalse = conditional.whenFalse;
|
|
@@ -355,7 +359,7 @@ export function checkReturnExpression(c, container, unwrappedReturnType, node, e
|
|
|
355
359
|
return;
|
|
356
360
|
}
|
|
357
361
|
}
|
|
358
|
-
const inReturnStatement = node.kind ===
|
|
362
|
+
const inReturnStatement = node.kind === 255 /* SyntaxKind.ReturnStatement */;
|
|
359
363
|
const unwrappedExprType = (functionFlags & 2 /* FunctionFlags.Async */) !== 0
|
|
360
364
|
? checkAwaitedType(c, exprType, false, node, 43 /* Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member */)
|
|
361
365
|
: exprType;
|
|
@@ -369,13 +373,16 @@ export function checkAwaitExpression(c, node) {
|
|
|
369
373
|
const operandType = checkExpression(c, getExpression(node));
|
|
370
374
|
const awaitedType = checkAwaitedType(c, operandType, true, node, 256 /* Diagnostics.Type_of_await_operand_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member */);
|
|
371
375
|
if (awaitedType === operandType && !isErrorType(c, awaitedType) && (operandType.flags & 3 /* TypeFlags.AnyOrUnknown */) === 0)
|
|
372
|
-
c.addSuggestion(createDiagnosticForNode(node,
|
|
376
|
+
c.addSuggestion(createDiagnosticForNode(node, 1966 /* Diagnostics.X_await_has_no_effect_on_the_type_of_this_expression */, []));
|
|
373
377
|
return awaitedType;
|
|
374
378
|
}
|
|
375
379
|
// ---- Generators
|
|
376
380
|
export function checkYieldExpression(c, node) {
|
|
377
381
|
checkGrammarYieldOfExpression(c, node);
|
|
378
382
|
const yieldExpr = node;
|
|
383
|
+
// The operand is checked also outside a generator.
|
|
384
|
+
const operand = yieldExpr.expression;
|
|
385
|
+
const yieldExpressionType = operand !== undefined ? checkExpression(c, operand) : c.undefinedWideningType;
|
|
379
386
|
const func = getContainingFunctionLike(node);
|
|
380
387
|
if (func === undefined)
|
|
381
388
|
return c.anyType;
|
|
@@ -394,8 +401,6 @@ export function checkYieldExpression(c, node) {
|
|
|
394
401
|
const iterationTypes = returnType !== undefined ? getIterationTypesOfGeneratorFunctionReturnType(c, returnType, isAsync) : undefined;
|
|
395
402
|
const signatureYieldType = iterationTypes?.yieldType ?? c.anyType;
|
|
396
403
|
const signatureNextType = iterationTypes?.nextType ?? c.anyType;
|
|
397
|
-
const operand = yieldExpr.expression;
|
|
398
|
-
const yieldExpressionType = operand !== undefined ? checkExpression(c, operand) : c.undefinedWideningType;
|
|
399
404
|
const yieldedType = getYieldedTypeOfYieldExpression(c, yieldExpr, yieldExpressionType, signatureNextType, isAsync);
|
|
400
405
|
if (returnType !== undefined && yieldedType !== undefined)
|
|
401
406
|
checkTypeAssignableToAndOptionallyElaborate(c, yieldedType, signatureYieldType, operand ?? node, operand);
|
|
@@ -409,7 +414,7 @@ export function checkYieldExpression(c, node) {
|
|
|
409
414
|
if (c.noImplicitAny && !expressionResultIsUnused(node)) {
|
|
410
415
|
const contextualType = getContextualType(c, node);
|
|
411
416
|
if (contextualType === undefined || (contextualType.flags & 1 /* TypeFlags.Any */) !== 0)
|
|
412
|
-
c.error(node,
|
|
417
|
+
c.error(node, 1747 /* Diagnostics.X_yield_expression_implicitly_results_in_an_any_type_because_its_containing_generator_lacks_a_return_type_annotation */);
|
|
413
418
|
}
|
|
414
419
|
return c.anyType;
|
|
415
420
|
}
|
|
@@ -433,16 +438,16 @@ function expressionResultIsUnused(nodeIn) {
|
|
|
433
438
|
let node = nodeIn;
|
|
434
439
|
for (;;) {
|
|
435
440
|
const parent = node.parent;
|
|
436
|
-
if (parent.kind ===
|
|
441
|
+
if (parent.kind === 219 /* SyntaxKind.ParenthesizedExpression */) {
|
|
437
442
|
node = parent;
|
|
438
443
|
continue;
|
|
439
444
|
}
|
|
440
|
-
if (parent.kind ===
|
|
441
|
-
parent.kind ===
|
|
442
|
-
(parent.kind ===
|
|
445
|
+
if (parent.kind === 246 /* SyntaxKind.ExpressionStatement */ ||
|
|
446
|
+
parent.kind === 224 /* SyntaxKind.VoidExpression */ ||
|
|
447
|
+
(parent.kind === 250 /* SyntaxKind.ForStatement */ &&
|
|
443
448
|
(parent.initializer === node || parent.incrementor === node)))
|
|
444
449
|
return true;
|
|
445
|
-
if (parent.kind ===
|
|
450
|
+
if (parent.kind === 228 /* SyntaxKind.BinaryExpression */ &&
|
|
446
451
|
parent.operatorToken.kind === 27 /* SyntaxKind.CommaToken */) {
|
|
447
452
|
// The left side of a comma is unused; the right side is when the comma is.
|
|
448
453
|
if (node === parent.left)
|
|
@@ -463,43 +468,43 @@ function getContainingFunctionLike(node) {
|
|
|
463
468
|
/** Whether checking `node` depends on its contextual type. */
|
|
464
469
|
export function isContextSensitive(c, node) {
|
|
465
470
|
switch (node.kind) {
|
|
466
|
-
case
|
|
467
|
-
case
|
|
468
|
-
case
|
|
469
|
-
case
|
|
471
|
+
case 220 /* SyntaxKind.FunctionExpression */:
|
|
472
|
+
case 221 /* SyntaxKind.ArrowFunction */:
|
|
473
|
+
case 176 /* SyntaxKind.MethodDeclaration */:
|
|
474
|
+
case 264 /* SyntaxKind.FunctionDeclaration */:
|
|
470
475
|
return isContextSensitiveFunctionLikeDeclaration(c, node);
|
|
471
|
-
case
|
|
476
|
+
case 212 /* SyntaxKind.ObjectLiteralExpression */:
|
|
472
477
|
for (const p of getProperties(node).nodes)
|
|
473
478
|
if (isContextSensitive(c, p))
|
|
474
479
|
return true;
|
|
475
480
|
return false;
|
|
476
|
-
case
|
|
481
|
+
case 211 /* SyntaxKind.ArrayLiteralExpression */:
|
|
477
482
|
for (const e of getElements(node).nodes)
|
|
478
483
|
if (isContextSensitive(c, e))
|
|
479
484
|
return true;
|
|
480
485
|
return false;
|
|
481
|
-
case
|
|
486
|
+
case 229 /* SyntaxKind.ConditionalExpression */: {
|
|
482
487
|
const cond = node;
|
|
483
488
|
return isContextSensitive(c, cond.whenTrue) || isContextSensitive(c, cond.whenFalse);
|
|
484
489
|
}
|
|
485
|
-
case
|
|
490
|
+
case 228 /* SyntaxKind.BinaryExpression */: {
|
|
486
491
|
const binary = node;
|
|
487
492
|
const op = binary.operatorToken.kind;
|
|
488
493
|
return ((op === 56 /* SyntaxKind.BarBarToken */ || op === 60 /* SyntaxKind.QuestionQuestionToken */) &&
|
|
489
494
|
(isContextSensitive(c, binary.left) || isContextSensitive(c, binary.right)));
|
|
490
495
|
}
|
|
491
|
-
case
|
|
496
|
+
case 304 /* SyntaxKind.PropertyAssignment */:
|
|
492
497
|
return isContextSensitive(c, getInitializer(node));
|
|
493
|
-
case
|
|
498
|
+
case 219 /* SyntaxKind.ParenthesizedExpression */:
|
|
494
499
|
return isContextSensitive(c, getExpression(node));
|
|
495
|
-
case
|
|
500
|
+
case 294 /* SyntaxKind.JsxAttributes */:
|
|
496
501
|
return isJsxAttributesContextSensitive(c, node);
|
|
497
|
-
case
|
|
502
|
+
case 293 /* SyntaxKind.JsxAttribute */: {
|
|
498
503
|
// Without an initializer an attribute is `true`.
|
|
499
504
|
const initializer = getInitializer(node);
|
|
500
505
|
return initializer !== undefined && isContextSensitive(c, initializer);
|
|
501
506
|
}
|
|
502
|
-
case
|
|
507
|
+
case 296 /* SyntaxKind.JsxExpression */: {
|
|
503
508
|
const expression = getExpression(node);
|
|
504
509
|
return expression !== undefined && isContextSensitive(c, expression);
|
|
505
510
|
}
|
|
@@ -518,16 +523,16 @@ function isContextSensitiveFunctionLikeDeclaration(c, node) {
|
|
|
518
523
|
*/
|
|
519
524
|
export function getTypePredicateFromBody(c, fn) {
|
|
520
525
|
switch (fn.kind) {
|
|
521
|
-
case
|
|
522
|
-
case
|
|
523
|
-
case
|
|
526
|
+
case 178 /* SyntaxKind.Constructor */:
|
|
527
|
+
case 179 /* SyntaxKind.GetAccessor */:
|
|
528
|
+
case 180 /* SyntaxKind.SetAccessor */:
|
|
524
529
|
return undefined;
|
|
525
530
|
}
|
|
526
531
|
if (getFunctionFlags(fn) !== 0 /* FunctionFlags.Normal */)
|
|
527
532
|
return undefined;
|
|
528
533
|
const body = getBody(fn);
|
|
529
534
|
let singleReturn = undefined;
|
|
530
|
-
if (body !== undefined && body.kind !==
|
|
535
|
+
if (body !== undefined && body.kind !== 243 /* SyntaxKind.Block */)
|
|
531
536
|
singleReturn = body;
|
|
532
537
|
else {
|
|
533
538
|
if (body === undefined)
|
|
@@ -569,7 +574,7 @@ function checkIfExpressionRefinesAnyParameter(c, fn, exprIn) {
|
|
|
569
574
|
}
|
|
570
575
|
function checkIfExpressionRefinesParameter(c, fn, expr, name, initType) {
|
|
571
576
|
let antecedent = getFlowNode(expr);
|
|
572
|
-
if (antecedent === undefined && expr.parent.kind ===
|
|
577
|
+
if (antecedent === undefined && expr.parent.kind === 255 /* SyntaxKind.ReturnStatement */)
|
|
573
578
|
antecedent = getFlowNode(expr.parent);
|
|
574
579
|
if (antecedent === undefined)
|
|
575
580
|
antecedent = new FlowNode(2 /* FlowFlags.Start */, undefined, undefined);
|
|
@@ -588,7 +593,7 @@ function hasContextSensitiveReturnExpression(c, node) {
|
|
|
588
593
|
const body = getBody(node);
|
|
589
594
|
if (body === undefined)
|
|
590
595
|
return false;
|
|
591
|
-
if (body.kind !==
|
|
596
|
+
if (body.kind !== 243 /* SyntaxKind.Block */)
|
|
592
597
|
return isContextSensitive(c, body);
|
|
593
598
|
const collector = new ReturnCollector();
|
|
594
599
|
collector.visitStatements(body);
|
|
@@ -616,7 +621,7 @@ class YieldFinder extends NodeVisitor {
|
|
|
616
621
|
this.c = c;
|
|
617
622
|
}
|
|
618
623
|
visitNode(node) {
|
|
619
|
-
if (node.kind ===
|
|
624
|
+
if (node.kind === 231 /* SyntaxKind.YieldExpression */) {
|
|
620
625
|
const expression = getExpression(node);
|
|
621
626
|
if (expression !== undefined && isContextSensitive(this.c, expression)) {
|
|
622
627
|
this.found = true;
|
|
@@ -630,15 +635,15 @@ class YieldFinder extends NodeVisitor {
|
|
|
630
635
|
}
|
|
631
636
|
function isFunctionLikeOrClass(node) {
|
|
632
637
|
switch (node.kind) {
|
|
633
|
-
case
|
|
634
|
-
case
|
|
635
|
-
case
|
|
636
|
-
case
|
|
637
|
-
case
|
|
638
|
-
case
|
|
639
|
-
case
|
|
640
|
-
case
|
|
641
|
-
case
|
|
638
|
+
case 264 /* SyntaxKind.FunctionDeclaration */:
|
|
639
|
+
case 220 /* SyntaxKind.FunctionExpression */:
|
|
640
|
+
case 221 /* SyntaxKind.ArrowFunction */:
|
|
641
|
+
case 176 /* SyntaxKind.MethodDeclaration */:
|
|
642
|
+
case 179 /* SyntaxKind.GetAccessor */:
|
|
643
|
+
case 180 /* SyntaxKind.SetAccessor */:
|
|
644
|
+
case 178 /* SyntaxKind.Constructor */:
|
|
645
|
+
case 265 /* SyntaxKind.ClassDeclaration */:
|
|
646
|
+
case 233 /* SyntaxKind.ClassExpression */:
|
|
642
647
|
return true;
|
|
643
648
|
}
|
|
644
649
|
return false;
|
|
@@ -663,7 +668,7 @@ export function getReturnTypeFromBodyEx(c, func, checkMode) {
|
|
|
663
668
|
let yieldType;
|
|
664
669
|
let nextType;
|
|
665
670
|
let fallbackReturnType = c.voidType;
|
|
666
|
-
if (body.kind !==
|
|
671
|
+
if (body.kind !== 243 /* SyntaxKind.Block */) {
|
|
667
672
|
returnType = checkExpressionCachedEx(c, body, checkMode);
|
|
668
673
|
if (isConstContext(c, body))
|
|
669
674
|
returnType = getRegularTypeOfLiteralType(c, returnType);
|
|
@@ -793,7 +798,7 @@ function checkAndAggregateReturnExpressionTypes(c, func, checkMode) {
|
|
|
793
798
|
}
|
|
794
799
|
expr = skipParentheses(expr);
|
|
795
800
|
// `return await` unwraps in async functions, and bare calls of the function itself don't contribute.
|
|
796
|
-
if (isAsync && expr.kind ===
|
|
801
|
+
if (isAsync && expr.kind === 225 /* SyntaxKind.AwaitExpression */)
|
|
797
802
|
expr = skipParentheses(getExpression(expr));
|
|
798
803
|
if (isRecursiveCall(c, func, expr)) {
|
|
799
804
|
hasReturnOfTypeNever = true;
|
|
@@ -820,7 +825,7 @@ function checkAndAggregateReturnExpressionTypes(c, func, checkMode) {
|
|
|
820
825
|
return aggregatedTypes;
|
|
821
826
|
}
|
|
822
827
|
function isRecursiveCall(c, func, expr) {
|
|
823
|
-
if (expr.kind !==
|
|
828
|
+
if (expr.kind !== 215 /* SyntaxKind.CallExpression */)
|
|
824
829
|
return false;
|
|
825
830
|
const callee = getExpression(expr);
|
|
826
831
|
if (callee.kind !== 79 /* SyntaxKind.Identifier */)
|
|
@@ -835,11 +840,11 @@ function isRecursiveCall(c, func, expr) {
|
|
|
835
840
|
}
|
|
836
841
|
function mayReturnNever(func) {
|
|
837
842
|
switch (func.kind) {
|
|
838
|
-
case
|
|
839
|
-
case
|
|
843
|
+
case 220 /* SyntaxKind.FunctionExpression */:
|
|
844
|
+
case 221 /* SyntaxKind.ArrowFunction */:
|
|
840
845
|
return true;
|
|
841
|
-
case
|
|
842
|
-
return func.parent.kind ===
|
|
846
|
+
case 176 /* SyntaxKind.MethodDeclaration */:
|
|
847
|
+
return func.parent.kind === 212 /* SyntaxKind.ObjectLiteralExpression */;
|
|
843
848
|
}
|
|
844
849
|
return false;
|
|
845
850
|
}
|
|
@@ -876,23 +881,23 @@ class YieldCollector extends NodeVisitor {
|
|
|
876
881
|
yields = [];
|
|
877
882
|
visit(node) {
|
|
878
883
|
switch (node.kind) {
|
|
879
|
-
case
|
|
884
|
+
case 231 /* SyntaxKind.YieldExpression */: {
|
|
880
885
|
this.yields.push(node);
|
|
881
886
|
const operand = node.expression;
|
|
882
887
|
if (operand !== undefined)
|
|
883
888
|
this.visit(operand);
|
|
884
889
|
return;
|
|
885
890
|
}
|
|
886
|
-
case
|
|
887
|
-
case
|
|
888
|
-
case
|
|
889
|
-
case
|
|
891
|
+
case 268 /* SyntaxKind.EnumDeclaration */:
|
|
892
|
+
case 266 /* SyntaxKind.InterfaceDeclaration */:
|
|
893
|
+
case 269 /* SyntaxKind.ModuleDeclaration */:
|
|
894
|
+
case 267 /* SyntaxKind.TypeAliasDeclaration */:
|
|
890
895
|
return;
|
|
891
896
|
}
|
|
892
897
|
if (isFunctionLike(node)) {
|
|
893
898
|
// Nested functions are skipped, but not their computed names.
|
|
894
899
|
const name = getName(node);
|
|
895
|
-
if (name !== undefined && name.kind ===
|
|
900
|
+
if (name !== undefined && name.kind === 169 /* SyntaxKind.ComputedPropertyName */)
|
|
896
901
|
this.visit(getExpression(name));
|
|
897
902
|
return;
|
|
898
903
|
}
|
|
@@ -913,22 +918,22 @@ export class ReturnCollector {
|
|
|
913
918
|
}
|
|
914
919
|
visit(node) {
|
|
915
920
|
switch (node.kind) {
|
|
916
|
-
case
|
|
921
|
+
case 255 /* SyntaxKind.ReturnStatement */:
|
|
917
922
|
this.returns.push(node);
|
|
918
923
|
return;
|
|
919
|
-
case
|
|
920
|
-
case
|
|
921
|
-
case
|
|
922
|
-
case
|
|
923
|
-
case
|
|
924
|
-
case
|
|
925
|
-
case
|
|
926
|
-
case
|
|
927
|
-
case
|
|
928
|
-
case
|
|
929
|
-
case
|
|
930
|
-
case
|
|
931
|
-
case
|
|
924
|
+
case 264 /* SyntaxKind.FunctionDeclaration */:
|
|
925
|
+
case 220 /* SyntaxKind.FunctionExpression */:
|
|
926
|
+
case 221 /* SyntaxKind.ArrowFunction */:
|
|
927
|
+
case 265 /* SyntaxKind.ClassDeclaration */:
|
|
928
|
+
case 233 /* SyntaxKind.ClassExpression */:
|
|
929
|
+
case 176 /* SyntaxKind.MethodDeclaration */:
|
|
930
|
+
case 179 /* SyntaxKind.GetAccessor */:
|
|
931
|
+
case 180 /* SyntaxKind.SetAccessor */:
|
|
932
|
+
case 178 /* SyntaxKind.Constructor */:
|
|
933
|
+
case 266 /* SyntaxKind.InterfaceDeclaration */:
|
|
934
|
+
case 267 /* SyntaxKind.TypeAliasDeclaration */:
|
|
935
|
+
case 268 /* SyntaxKind.EnumDeclaration */:
|
|
936
|
+
case 269 /* SyntaxKind.ModuleDeclaration */:
|
|
932
937
|
return;
|
|
933
938
|
}
|
|
934
939
|
if (isStatementContainer(node))
|
|
@@ -937,21 +942,21 @@ export class ReturnCollector {
|
|
|
937
942
|
}
|
|
938
943
|
function isStatementContainer(node) {
|
|
939
944
|
switch (node.kind) {
|
|
940
|
-
case
|
|
941
|
-
case
|
|
942
|
-
case
|
|
943
|
-
case
|
|
944
|
-
case
|
|
945
|
-
case
|
|
946
|
-
case
|
|
947
|
-
case
|
|
948
|
-
case
|
|
949
|
-
case
|
|
950
|
-
case
|
|
951
|
-
case
|
|
952
|
-
case
|
|
953
|
-
case
|
|
954
|
-
case
|
|
945
|
+
case 243 /* SyntaxKind.Block */:
|
|
946
|
+
case 247 /* SyntaxKind.IfStatement */:
|
|
947
|
+
case 248 /* SyntaxKind.DoStatement */:
|
|
948
|
+
case 249 /* SyntaxKind.WhileStatement */:
|
|
949
|
+
case 250 /* SyntaxKind.ForStatement */:
|
|
950
|
+
case 251 /* SyntaxKind.ForInStatement */:
|
|
951
|
+
case 252 /* SyntaxKind.ForOfStatement */:
|
|
952
|
+
case 256 /* SyntaxKind.WithStatement */:
|
|
953
|
+
case 257 /* SyntaxKind.SwitchStatement */:
|
|
954
|
+
case 271 /* SyntaxKind.CaseBlock */:
|
|
955
|
+
case 298 /* SyntaxKind.CaseClause */:
|
|
956
|
+
case 299 /* SyntaxKind.DefaultClause */:
|
|
957
|
+
case 258 /* SyntaxKind.LabeledStatement */:
|
|
958
|
+
case 260 /* SyntaxKind.TryStatement */:
|
|
959
|
+
case 301 /* SyntaxKind.CatchClause */:
|
|
955
960
|
return true;
|
|
956
961
|
}
|
|
957
962
|
return false;
|
|
@@ -974,11 +979,12 @@ function assignParameterType(c, declaration) {
|
|
|
974
979
|
const id = getSymbolId(symbol);
|
|
975
980
|
if (c.symbolTypes.get(id) !== undefined)
|
|
976
981
|
return;
|
|
977
|
-
|
|
982
|
+
// Without a context, the parameter's own type, reporting its implicit any errors.
|
|
983
|
+
const t = getWidenedTypeForVariableLikeDeclaration(c, declaration, true);
|
|
978
984
|
c.symbolTypes.set(id, addOptionality(c, t, false, getInitializer(declaration) === undefined && isOptionalDeclaration(declaration)));
|
|
979
985
|
const name = getName(declaration);
|
|
980
986
|
if (name !== undefined &&
|
|
981
|
-
(name.kind ===
|
|
987
|
+
(name.kind === 208 /* SyntaxKind.ObjectBindingPattern */ || name.kind === 209 /* SyntaxKind.ArrayBindingPattern */)) {
|
|
982
988
|
// Without a better inference than `unknown`, a binding pattern implies the type.
|
|
983
989
|
if (c.symbolTypes.get(id) === c.unknownType)
|
|
984
990
|
c.symbolTypes.set(id, getTypeFromBindingPattern(c, name, false, false));
|
|
@@ -988,7 +994,7 @@ function assignParameterType(c, declaration) {
|
|
|
988
994
|
/** Pushes a contextually assigned parameter type into the binding elements of its pattern. */
|
|
989
995
|
function assignBindingElementTypes(c, pattern, parentType) {
|
|
990
996
|
for (const element of getElements(pattern).nodes) {
|
|
991
|
-
if (element.kind !==
|
|
997
|
+
if (element.kind !== 210 /* SyntaxKind.BindingElement */)
|
|
992
998
|
continue;
|
|
993
999
|
const name = getName(element);
|
|
994
1000
|
if (name === undefined)
|
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
import { type Node } from './ast.js';
|
|
2
2
|
import type { Checker } from './checker.js';
|
|
3
3
|
import { type Diagnostic, type DiagnosticMessage } from './diagnostics.js';
|
|
4
|
-
/** A collision check that waits until the file is checked, when the flags it reads are complete. */
|
|
5
|
-
export declare class DeferredCollisionCheck {
|
|
6
|
-
readonly node: Node;
|
|
7
|
-
/** `Reflect` rather than `WeakMap` and `WeakSet`. */
|
|
8
|
-
readonly reflect: boolean;
|
|
9
|
-
constructor(node: Node,
|
|
10
|
-
/** `Reflect` rather than `WeakMap` and `WeakSet`. */
|
|
11
|
-
reflect: boolean);
|
|
12
|
-
}
|
|
13
4
|
/** An error that is not reported under noEmit, since it is about the emitted code. */
|
|
14
5
|
export declare function errorSkippedOnNoEmit(c: Checker, node: Node, message: DiagnosticMessage, ...args: string[]): Diagnostic;
|
|
15
6
|
/** Checks the name of a declaration against the names the emitted code reserves. */
|
|
@@ -21,5 +12,3 @@ export declare function checkCollisionsForDeclarationName(c: Checker, node: Node
|
|
|
21
12
|
export declare function markPrivateIdentifierScope(c: Checker, node: Node): void;
|
|
22
13
|
/** `super.x` in a static initializer before ES2022 is emitted with `Reflect`: marks the block scopes around it. */
|
|
23
14
|
export declare function markSuperPropertyInStaticInitializer(c: Checker, node: Node): void;
|
|
24
|
-
/** Reports the `WeakMap`, `WeakSet` and `Reflect` collisions found while checking the file. */
|
|
25
|
-
export declare function produceDeferredCollisionChecks(c: Checker): void;
|