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
|
@@ -89,6 +89,7 @@ import {
|
|
|
89
89
|
createArrayType,
|
|
90
90
|
isTupleType,
|
|
91
91
|
newObjectType,
|
|
92
|
+
unionContainsTypeOrPrimitive,
|
|
92
93
|
} from './checker-type-factory.js';
|
|
93
94
|
import {
|
|
94
95
|
areTypesComparable,
|
|
@@ -119,7 +120,7 @@ import {
|
|
|
119
120
|
getInferenceContext,
|
|
120
121
|
isContextSensitiveFunctionOrObjectLiteralMethod,
|
|
121
122
|
} from './checker-contextual.js';
|
|
122
|
-
import { instantiateType } from './instantiation.js';
|
|
123
|
+
import { instantiateType, isNodeDescendantOf } from './instantiation.js';
|
|
123
124
|
import { IterationUse, checkIteratedTypeOrElementType } from './checker-iteration.js';
|
|
124
125
|
import { checkSuperExpression } from './checker-super.js';
|
|
125
126
|
import { getSymbolNameForPrivateIdentifier } from './binder.js';
|
|
@@ -160,7 +161,7 @@ import {
|
|
|
160
161
|
getRangeOfTokenAtPosition,
|
|
161
162
|
getSourceFileOfNode,
|
|
162
163
|
} from './binder-utilities.js';
|
|
163
|
-
import { getDeclaredTypeOfSymbol, isConstructorType } from './checker-declared-types.js';
|
|
164
|
+
import { getDeclaredTypeOfSymbol, getParentOfSymbol, isConstructorType } from './checker-declared-types.js';
|
|
164
165
|
import {
|
|
165
166
|
getErasedSignature,
|
|
166
167
|
getReturnTypeFromAnnotation,
|
|
@@ -946,6 +947,16 @@ function getTypeOfDottedName(c: Checker, node: Node): Type | undefined {
|
|
|
946
947
|
|
|
947
948
|
function getExplicitTypeOfSymbol(c: Checker, original: Symbol): Type | undefined {
|
|
948
949
|
const symbol = resolveSymbol(c, original) ?? original;
|
|
950
|
+
// `for (const x of x.y)` asks for the explicit type of `x` while finding it.
|
|
951
|
+
const resolving = c.resolvingExplicitTypeOfSymbol;
|
|
952
|
+
if (resolving.has(symbol)) return undefined;
|
|
953
|
+
resolving.add(symbol);
|
|
954
|
+
const result = getExplicitTypeOfResolvedSymbol(c, symbol);
|
|
955
|
+
resolving.delete(symbol);
|
|
956
|
+
return result;
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
function getExplicitTypeOfResolvedSymbol(c: Checker, symbol: Symbol): Type | undefined {
|
|
949
960
|
if ((symbol.flags & (SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.Class | SymbolFlags.ValueModule)) !== 0)
|
|
950
961
|
return getTypeOfSymbol(c, symbol);
|
|
951
962
|
if ((symbol.flags & (SymbolFlags.Variable | SymbolFlags.Property)) !== 0) {
|
|
@@ -1194,7 +1205,7 @@ function writeFlowCacheKey(
|
|
|
1194
1205
|
return writeFlowCacheKey(c, getExpression(node)!, declaredType, initialType, flowContainer);
|
|
1195
1206
|
case SyntaxKind.QualifiedName: {
|
|
1196
1207
|
const left = writeFlowCacheKey(c, (node as QualifiedName).left, declaredType, initialType, flowContainer);
|
|
1197
|
-
return left === undefined ? undefined : left + '.' + (node as QualifiedName).right
|
|
1208
|
+
return left === undefined ? undefined : left + '.' + getText((node as QualifiedName).right);
|
|
1198
1209
|
}
|
|
1199
1210
|
case SyntaxKind.PropertyAccessExpression:
|
|
1200
1211
|
case SyntaxKind.ElementAccessExpression: {
|
|
@@ -1556,6 +1567,10 @@ function narrowTypeByEqualityWorker(
|
|
|
1556
1567
|
return valueType;
|
|
1557
1568
|
if ((valueType.flags & TypeFlags.Object) !== 0) return c.nonPrimitiveType;
|
|
1558
1569
|
}
|
|
1570
|
+
if (!doubleEquals && (valueType.flags & TypeFlags.Primitive) !== 0 && isUniformUnionType(c, t)) {
|
|
1571
|
+
const regularType = getRegularTypeOfLiteralType(c, valueType);
|
|
1572
|
+
if (unionContainsTypeOrPrimitive(c, t as UnionType, regularType, false)) return regularType;
|
|
1573
|
+
}
|
|
1559
1574
|
const filtered = filterType(
|
|
1560
1575
|
c,
|
|
1561
1576
|
t,
|
|
@@ -1563,11 +1578,47 @@ function narrowTypeByEqualityWorker(
|
|
|
1563
1578
|
);
|
|
1564
1579
|
return replacePrimitivesWithLiterals(c, filtered, valueType);
|
|
1565
1580
|
}
|
|
1566
|
-
if (isUnitType(valueType))
|
|
1581
|
+
if (isUnitType(valueType)) {
|
|
1582
|
+
if (isUniformUnionType(c, t)) {
|
|
1583
|
+
const filtered = removeType(c, t, getRegularTypeOfLiteralType(c, valueType));
|
|
1584
|
+
if (filtered !== t) return filtered;
|
|
1585
|
+
}
|
|
1567
1586
|
return filterType(c, t, (u) => !(isUnitLikeType(u) && areTypesComparable(c, u, valueType)));
|
|
1587
|
+
}
|
|
1568
1588
|
return t;
|
|
1569
1589
|
}
|
|
1570
1590
|
|
|
1591
|
+
/**
|
|
1592
|
+
* Whether `t` is a primitive union in which no two literal constituents are comparable: it has no
|
|
1593
|
+
* literals of two enums, and not both enum literals and string or number literals. Comparing such a
|
|
1594
|
+
* union with one of its literals matches only that literal.
|
|
1595
|
+
*/
|
|
1596
|
+
function isUniformUnionType(c: Checker, t: Type): boolean {
|
|
1597
|
+
if ((t.objectFlags & ObjectFlags.PrimitiveUnion) === 0) return false;
|
|
1598
|
+
const side = sideOf(c, t);
|
|
1599
|
+
if ((side.objectFlags & ObjectFlags.IsUniformEnumComputed) === 0)
|
|
1600
|
+
side.objectFlags |=
|
|
1601
|
+
ObjectFlags.IsUniformEnumComputed | (computeIsUniformUnionType(c, typesOf(t)) ? ObjectFlags.IsUniformEnum : 0);
|
|
1602
|
+
return (side.objectFlags & ObjectFlags.IsUniformEnum) !== 0;
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
function computeIsUniformUnionType(c: Checker, types: readonly Type[]): boolean {
|
|
1606
|
+
let enumSymbol: Symbol | undefined;
|
|
1607
|
+
let hasStringOrNumberLiteral = false;
|
|
1608
|
+
for (const t of types) {
|
|
1609
|
+
if ((t.flags & TypeFlags.EnumLike) !== 0) {
|
|
1610
|
+
if (hasStringOrNumberLiteral) return false;
|
|
1611
|
+
const parent = getParentOfSymbol(c, t.symbol!);
|
|
1612
|
+
if (enumSymbol === undefined) enumSymbol = parent;
|
|
1613
|
+
else if (enumSymbol !== parent) return false;
|
|
1614
|
+
} else if ((t.flags & TypeFlags.StringOrNumberLiteral) !== 0) {
|
|
1615
|
+
if (enumSymbol !== undefined) return false;
|
|
1616
|
+
hasStringOrNumberLiteral = true;
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
return true;
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1571
1622
|
function isCoercibleUnderDoubleEquals(source: Type, target: Type): boolean {
|
|
1572
1623
|
return (
|
|
1573
1624
|
(source.flags & (TypeFlags.Number | TypeFlags.String | TypeFlags.BooleanLiteral)) !== 0 &&
|
|
@@ -2184,14 +2235,20 @@ function narrowTypeBySwitchOnDiscriminantWorker(c: Checker, t: Type, flow: FlowS
|
|
|
2184
2235
|
return getUnionType(c, ground);
|
|
2185
2236
|
}
|
|
2186
2237
|
const discriminantType = getUnionType(c, clauseTypes);
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2238
|
+
let caseType: Type | undefined;
|
|
2239
|
+
if ((discriminantType.flags & TypeFlags.Never) !== 0) caseType = c.neverType;
|
|
2240
|
+
else {
|
|
2241
|
+
if ((discriminantType.flags & TypeFlags.Primitive) !== 0 && isUniformUnionType(c, t)) {
|
|
2242
|
+
const regularType = getRegularTypeOfLiteralType(c, discriminantType);
|
|
2243
|
+
if (unionContainsTypeOrPrimitive(c, t as UnionType, regularType, false)) caseType = regularType;
|
|
2244
|
+
}
|
|
2245
|
+
if (caseType === undefined)
|
|
2246
|
+
caseType = replacePrimitivesWithLiterals(
|
|
2247
|
+
c,
|
|
2248
|
+
filterType(c, t, (u) => areTypesComparable(c, discriminantType, u)),
|
|
2249
|
+
discriminantType,
|
|
2250
|
+
);
|
|
2251
|
+
}
|
|
2195
2252
|
if (!hasDefaultClause) return caseType;
|
|
2196
2253
|
const defaultType = filterType(c, t, (u) => {
|
|
2197
2254
|
const unit = extractUnitType(u);
|
|
@@ -2400,7 +2457,7 @@ export function isMatchingReference(c: Checker, source: Node, target: Node): boo
|
|
|
2400
2457
|
const targetName = getAccessedPropertyName(c, target);
|
|
2401
2458
|
if (targetName !== undefined)
|
|
2402
2459
|
return (
|
|
2403
|
-
(source as QualifiedName).right
|
|
2460
|
+
getText((source as QualifiedName).right) === targetName &&
|
|
2404
2461
|
isMatchingReference(c, (source as QualifiedName).left, getExpression(target)!)
|
|
2405
2462
|
);
|
|
2406
2463
|
}
|
|
@@ -2416,10 +2473,16 @@ export function isMatchingReference(c: Checker, source: Node, target: Node): boo
|
|
|
2416
2473
|
|
|
2417
2474
|
/** Whether `expr` is `reference.constructor`. */
|
|
2418
2475
|
function isMatchingConstructorReference(c: Checker, f: FlowState, expr: Node): boolean {
|
|
2476
|
+
// Only a literal name is read here; resolving an entity name argument could start a circularity.
|
|
2477
|
+
let name: Node | undefined = undefined;
|
|
2478
|
+
if (expr.kind === SyntaxKind.PropertyAccessExpression) name = (expr as PropertyAccessExpression).name;
|
|
2479
|
+
else if (
|
|
2480
|
+
expr.kind === SyntaxKind.ElementAccessExpression &&
|
|
2481
|
+
isStringLiteralLike((expr as ElementAccessExpression).argumentExpression)
|
|
2482
|
+
)
|
|
2483
|
+
name = (expr as ElementAccessExpression).argumentExpression;
|
|
2419
2484
|
return (
|
|
2420
|
-
|
|
2421
|
-
getAccessedPropertyName(c, expr) === 'constructor' &&
|
|
2422
|
-
isMatchingReference(c, f.reference, getExpression(expr)!)
|
|
2485
|
+
name !== undefined && getText(name) === 'constructor' && isMatchingReference(c, f.reference, getExpression(expr)!)
|
|
2423
2486
|
);
|
|
2424
2487
|
}
|
|
2425
2488
|
|
|
@@ -2646,7 +2709,11 @@ function isCallChain(node: Node): boolean {
|
|
|
2646
2709
|
// ---- Reachability
|
|
2647
2710
|
|
|
2648
2711
|
export function isReachableFlowNode(c: Checker, flow: FlowNode): boolean {
|
|
2712
|
+
// The reduce labels of an enclosing flow analysis don't apply.
|
|
2713
|
+
const outerReduceLabels = c.flowReduceLabels;
|
|
2714
|
+
if (outerReduceLabels.length !== 0) c.flowReduceLabels = [];
|
|
2649
2715
|
const result = isReachableFlowNodeWorker(c, flow, false);
|
|
2716
|
+
c.flowReduceLabels = outerReduceLabels;
|
|
2650
2717
|
c.lastFlowNode = flow;
|
|
2651
2718
|
c.lastFlowNodeReachable = result;
|
|
2652
2719
|
return result;
|
|
@@ -2659,7 +2726,8 @@ function isReachableFlowNodeWorker(c: Checker, start: FlowNode, noCacheCheckIn:
|
|
|
2659
2726
|
if (flow === c.lastFlowNode) return c.lastFlowNodeReachable;
|
|
2660
2727
|
const flags = flow.flags;
|
|
2661
2728
|
if ((flags & FlowFlags.Shared) !== 0) {
|
|
2662
|
-
|
|
2729
|
+
// A result found through a reduce label holds only for that label's antecedents.
|
|
2730
|
+
if (!noCacheCheck && c.flowReduceLabels.length === 0) {
|
|
2663
2731
|
const cached = c.flowNodeReachable.get(flow);
|
|
2664
2732
|
if (cached !== undefined) return cached;
|
|
2665
2733
|
const reachable = isReachableFlowNodeWorker(c, flow, true);
|
|
@@ -2829,7 +2897,6 @@ function findFunctionOrSourceFile(node: Node | undefined): Node | undefined {
|
|
|
2829
2897
|
}
|
|
2830
2898
|
|
|
2831
2899
|
function ensureAssignmentsMarked(c: Checker, symbol: Symbol): void {
|
|
2832
|
-
if (c.symbolLinks(symbol).lastAssignmentPos !== 0) return;
|
|
2833
2900
|
const parent = findFunctionOrSourceFile(symbol.valueDeclaration);
|
|
2834
2901
|
if (parent === undefined) return;
|
|
2835
2902
|
const links = c.nodeLinks(parent);
|
|
@@ -3142,12 +3209,25 @@ export function getNarrowedTypeOfSymbol(c: Checker, symbol: Symbol, location: No
|
|
|
3142
3209
|
)
|
|
3143
3210
|
)
|
|
3144
3211
|
return t;
|
|
3212
|
+
// A reference in the declaration's own initializer would need the declaration's type; defaults of
|
|
3213
|
+
// the binding elements and nested functions are narrowed.
|
|
3214
|
+
const rootInitializer = getInitializer(rootDeclaration);
|
|
3215
|
+
if (
|
|
3216
|
+
rootInitializer !== undefined &&
|
|
3217
|
+
location.pos >= rootInitializer.pos &&
|
|
3218
|
+
location.end <= rootInitializer.end &&
|
|
3219
|
+
isNodeDescendantOf(location, rootInitializer) &&
|
|
3220
|
+
getControlFlowContainer(declaration) === getControlFlowContainer(location)
|
|
3221
|
+
)
|
|
3222
|
+
return t;
|
|
3145
3223
|
const links = c.nodeLinks(parent);
|
|
3146
3224
|
if ((links.flags & NodeCheckFlags.InCheckIdentifier) !== 0) return t;
|
|
3147
3225
|
links.flags |= NodeCheckFlags.InCheckIdentifier;
|
|
3148
3226
|
let result = t;
|
|
3149
3227
|
const parentType = getTypeForBindingElementParent(c, parent, CheckMode.Normal);
|
|
3150
3228
|
const parentTypeConstraint = parentType !== undefined ? mapToBaseConstraintOrType(c, parentType) : undefined;
|
|
3229
|
+
// Only the parent's type is guarded; flow analysis may narrow the binding elements again.
|
|
3230
|
+
links.flags &= ~NodeCheckFlags.InCheckIdentifier;
|
|
3151
3231
|
if (
|
|
3152
3232
|
parentTypeConstraint !== undefined &&
|
|
3153
3233
|
(parentTypeConstraint.flags & TypeFlags.Union) !== 0 &&
|
|
@@ -3167,7 +3247,6 @@ export function getNarrowedTypeOfSymbol(c: Checker, symbol: Symbol, location: No
|
|
|
3167
3247
|
? c.neverType
|
|
3168
3248
|
: getBindingElementTypeFromParentType(c, declaration as BindingElement, narrowedType, true);
|
|
3169
3249
|
}
|
|
3170
|
-
links.flags &= ~NodeCheckFlags.InCheckIdentifier;
|
|
3171
3250
|
return result;
|
|
3172
3251
|
}
|
|
3173
3252
|
|
|
@@ -77,6 +77,7 @@ import {
|
|
|
77
77
|
import { addIntraExpressionInferenceSite } from './checker-inference.js';
|
|
78
78
|
import { isEmptyObjectType } from './checker-type-factory.js';
|
|
79
79
|
import { getTypeOfExpandoObjectLiteral, isJSObjectLiteral } from './checker-javascript.js';
|
|
80
|
+
import { checkNodeDeferred } from './checker-source-file.js';
|
|
80
81
|
import {
|
|
81
82
|
CheckFlags,
|
|
82
83
|
copyDeclarations,
|
|
@@ -153,6 +154,8 @@ class ObjectLiteralBuilder {
|
|
|
153
154
|
export function checkObjectLiteral(c: Checker, node: Node, checkMode: CheckMode): Type {
|
|
154
155
|
const expandoType = getTypeOfExpandoObjectLiteral(c, node);
|
|
155
156
|
if (expandoType !== undefined) return expandoType;
|
|
157
|
+
// Deprecated properties of the contextual type are reported once the file is checked.
|
|
158
|
+
checkNodeDeferred(c, node);
|
|
156
159
|
const inDestructuringPattern = isAssignmentTarget(node);
|
|
157
160
|
checkGrammarObjectLiteralOfExpression(c, node as ObjectLiteralExpression, inDestructuringPattern);
|
|
158
161
|
const allProperties = c.strictNullChecks ? new Map<string, Symbol>() : undefined;
|
|
@@ -260,10 +260,11 @@ export function errorAndMaybeSuggestAwait(
|
|
|
260
260
|
message: DiagnosticMessage,
|
|
261
261
|
args: string[],
|
|
262
262
|
): Diagnostic {
|
|
263
|
-
|
|
263
|
+
// The related information goes on the reported diagnostic after it is added, as tsgo attaches it,
|
|
264
|
+
// so a later equal report compares unequal to it and is kept.
|
|
265
|
+
const diagnostic = c.error(location, message, ...args);
|
|
264
266
|
if (maybeMissingAwait)
|
|
265
267
|
diagnostic.addRelatedInfo(createDiagnosticForNode(location, Diagnostics.Did_you_forget_to_use_await, []));
|
|
266
|
-
c.addDiagnostic(diagnostic);
|
|
267
268
|
return diagnostic;
|
|
268
269
|
}
|
|
269
270
|
|
|
@@ -1145,9 +1146,15 @@ function getSyntacticNullishnessSemantics(c: Checker, nodeIn: Node): PredicateSe
|
|
|
1145
1146
|
// The right operand decides.
|
|
1146
1147
|
case SyntaxKind.CommaToken:
|
|
1147
1148
|
case SyntaxKind.EqualsToken:
|
|
1148
|
-
case SyntaxKind.QuestionQuestionToken:
|
|
1149
|
-
case SyntaxKind.QuestionQuestionEqualsToken:
|
|
1150
1149
|
return getSyntacticNullishnessSemantics(c, binary.right);
|
|
1150
|
+
// The left operand when it isn't nullish, otherwise the right operand.
|
|
1151
|
+
case SyntaxKind.QuestionQuestionToken:
|
|
1152
|
+
case SyntaxKind.QuestionQuestionEqualsToken: {
|
|
1153
|
+
const left = getSyntacticNullishnessSemantics(c, binary.left);
|
|
1154
|
+
let result = left & PredicateSemantics.Never;
|
|
1155
|
+
if ((left & PredicateSemantics.Always) !== 0) result |= getSyntacticNullishnessSemantics(c, binary.right);
|
|
1156
|
+
return result;
|
|
1157
|
+
}
|
|
1151
1158
|
}
|
|
1152
1159
|
return PredicateSemantics.Never;
|
|
1153
1160
|
}
|
|
@@ -195,7 +195,12 @@ export function checkPropertyAccessExpressionOrQualifiedName(
|
|
|
195
195
|
);
|
|
196
196
|
return c.anyType;
|
|
197
197
|
}
|
|
198
|
-
if (name !== '')
|
|
198
|
+
if (name !== '') {
|
|
199
|
+
// Deferred, since printing the containing type can resolve it completely, and report circularities
|
|
200
|
+
// while it is being resolved.
|
|
201
|
+
const containingType = isThisTypeParameter(leftType) ? apparentType : leftType;
|
|
202
|
+
c.deferDiagnostic(right, () => reportNonexistentProperty(c, right, containingType));
|
|
203
|
+
}
|
|
199
204
|
return c.errorType;
|
|
200
205
|
}
|
|
201
206
|
if (indexInfo.isReadonly && (assignmentKind !== AssignmentKind.None || isDeleteTarget(node)))
|
|
@@ -547,7 +552,7 @@ function checkPropertyAccessibilityAtLocation(
|
|
|
547
552
|
errorNode,
|
|
548
553
|
Diagnostics.Property_0_is_private_and_only_accessible_within_class_1,
|
|
549
554
|
symbolToString(c, prop),
|
|
550
|
-
typeToString(c, getDeclaringClass(c, prop)
|
|
555
|
+
typeToString(c, getDeclaringClass(c, prop) ?? containingTypeIn),
|
|
551
556
|
);
|
|
552
557
|
return false;
|
|
553
558
|
}
|
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
type ShorthandPropertyAssignment,
|
|
37
37
|
type SourceFile,
|
|
38
38
|
type TypeParameterDeclaration,
|
|
39
|
+
type ImportAttributes as ImportAttributesNode,
|
|
39
40
|
} from './ast.js';
|
|
40
41
|
import {
|
|
41
42
|
compareNodePositions,
|
|
@@ -44,9 +45,11 @@ import {
|
|
|
44
45
|
isFunctionLike,
|
|
45
46
|
isImportCall,
|
|
46
47
|
isLiteralImportTypeNode,
|
|
48
|
+
isNameOfHeritageClauseTypeReference,
|
|
47
49
|
isStringLiteralLike,
|
|
48
50
|
isTypeDeclaration,
|
|
49
51
|
nodeIsMissing,
|
|
52
|
+
isImportPhaseMetaProperty,
|
|
50
53
|
} from './ast-utilities.js';
|
|
51
54
|
import {
|
|
52
55
|
getNameOfDeclaration,
|
|
@@ -93,6 +96,8 @@ import {
|
|
|
93
96
|
getTargetOfAliasDeclaration,
|
|
94
97
|
resolveExternalModuleName,
|
|
95
98
|
resolveJSDocMemberName,
|
|
99
|
+
checkImportAttributesExpression,
|
|
100
|
+
getImportAttributesTypeForModuleSpecifier,
|
|
96
101
|
} from './checker-modules.js';
|
|
97
102
|
import { getSymbolHasInstanceMethodOfObjectType } from './checker-operators.js';
|
|
98
103
|
import { getSymbolForPrivateIdentifierExpression } from './checker-property-access.js';
|
|
@@ -217,7 +222,13 @@ export function getSymbolAtLocationWorker(c: Checker, node: Node, ignoreErrors:
|
|
|
217
222
|
isLiteralImportTypeNode(grandParent) &&
|
|
218
223
|
(grandParent as ImportTypeNode).argument === parent)
|
|
219
224
|
)
|
|
220
|
-
return resolveExternalModuleName(
|
|
225
|
+
return resolveExternalModuleName(
|
|
226
|
+
c,
|
|
227
|
+
node,
|
|
228
|
+
node,
|
|
229
|
+
ignoreErrors,
|
|
230
|
+
getImportAttributesTypeForModuleSpecifier(c, node),
|
|
231
|
+
);
|
|
221
232
|
if (
|
|
222
233
|
parent.kind === SyntaxKind.CallExpression &&
|
|
223
234
|
isBindableObjectDefinePropertyCall(parent) &&
|
|
@@ -243,7 +254,7 @@ export function getSymbolAtLocationWorker(c: Checker, node: Node, ignoreErrors:
|
|
|
243
254
|
case SyntaxKind.ExportKeyword:
|
|
244
255
|
return parent.kind === SyntaxKind.ExportAssignment ? getSymbol(parent) : undefined;
|
|
245
256
|
case SyntaxKind.ImportKeyword:
|
|
246
|
-
if (
|
|
257
|
+
if (isImportPhaseMetaProperty(parent)) return undefined;
|
|
247
258
|
return parent.kind === SyntaxKind.MetaProperty ? checkMetaPropertyKeyword(c).symbol : undefined;
|
|
248
259
|
case SyntaxKind.NewKeyword:
|
|
249
260
|
return parent.kind === SyntaxKind.MetaProperty ? checkMetaPropertyKeyword(c).symbol : undefined;
|
|
@@ -312,10 +323,13 @@ function getSymbolOfNameOrPropertyAccessExpression(c: Checker, nameIn: Node): Sy
|
|
|
312
323
|
}
|
|
313
324
|
}
|
|
314
325
|
while (isRightSideOfQualifiedNameOrPropertyAccess(name)) name = name.parent!;
|
|
315
|
-
if (
|
|
326
|
+
if (isInNameOfExpressionWithTypeArgumentsOrHeritageTypeReference(name)) {
|
|
316
327
|
let meaning: SymbolFlags;
|
|
317
|
-
if (
|
|
318
|
-
|
|
328
|
+
if (
|
|
329
|
+
name.parent!.kind === SyntaxKind.ExpressionWithTypeArguments ||
|
|
330
|
+
name.parent!.kind === SyntaxKind.TypeReference
|
|
331
|
+
) {
|
|
332
|
+
// A heritage element name is a type, `foo<T>` a value, and a class `extends` both.
|
|
319
333
|
meaning = isPartOfTypeNode(name) ? SymbolFlags.Type : SymbolFlags.Value;
|
|
320
334
|
if (isExpressionWithTypeArgumentsInClassExtendsClause(name.parent!)) meaning |= SymbolFlags.Value;
|
|
321
335
|
} else meaning = SymbolFlags.Namespace;
|
|
@@ -377,6 +391,7 @@ function getSymbolOfNameOrPropertyAccessExpression(c: Checker, nameIn: Node): Sy
|
|
|
377
391
|
const meaning = name.parent!.kind === SyntaxKind.TypeReference ? SymbolFlags.Type : SymbolFlags.Namespace;
|
|
378
392
|
const symbol = resolveEntityName(c, name, meaning, true, true, undefined);
|
|
379
393
|
if (symbol !== undefined && symbol !== c.unknownSymbol) return symbol;
|
|
394
|
+
if (isNameOfHeritageClauseTypeReference(name)) return undefined;
|
|
380
395
|
return getUnresolvedSymbolForEntityName(c, name);
|
|
381
396
|
}
|
|
382
397
|
if (name.parent!.kind === SyntaxKind.TypePredicate)
|
|
@@ -436,11 +451,11 @@ export function getTypeAtLocation(c: Checker, node: Node): Type {
|
|
|
436
451
|
return getTypeOfNode(c, getReparsedNodeForNode(node));
|
|
437
452
|
}
|
|
438
453
|
|
|
439
|
-
function getTypeOfNode(c: Checker, node: Node): Type {
|
|
454
|
+
export function getTypeOfNode(c: Checker, node: Node): Type {
|
|
440
455
|
if (node.kind === SyntaxKind.SourceFile && !isExternalOrCommonJSModule(node as SourceFile)) return c.errorType;
|
|
441
456
|
// Semantic questions inside `with` blocks have no answer.
|
|
442
457
|
if ((node.flags & NodeFlags.InWithStatement) !== 0) return c.errorType;
|
|
443
|
-
const heritage =
|
|
458
|
+
const heritage = getClassOfHeritageElement(node);
|
|
444
459
|
const classType =
|
|
445
460
|
heritage !== undefined ? getDeclaredTypeOfClassOrInterface(c, getSymbolOfDeclaration(c, heritage)!) : undefined;
|
|
446
461
|
if (isPartOfTypeNode(node)) {
|
|
@@ -484,7 +499,8 @@ function getTypeOfNode(c: Checker, node: Node): Type {
|
|
|
484
499
|
(parent as MetaProperty).keywordToken === node.kind
|
|
485
500
|
)
|
|
486
501
|
return checkMetaPropertyKeyword(c);
|
|
487
|
-
if (node.kind === SyntaxKind.ImportAttributes)
|
|
502
|
+
if (node.kind === SyntaxKind.ImportAttributes)
|
|
503
|
+
return checkImportAttributesExpression(c, node as ImportAttributesNode);
|
|
488
504
|
return c.errorType;
|
|
489
505
|
}
|
|
490
506
|
|
|
@@ -803,10 +819,11 @@ function isImportTypeQualifierPart(nodeIn: Node): Node | undefined {
|
|
|
803
819
|
return undefined;
|
|
804
820
|
}
|
|
805
821
|
|
|
806
|
-
function
|
|
822
|
+
function isInNameOfExpressionWithTypeArgumentsOrHeritageTypeReference(nodeIn: Node): boolean {
|
|
807
823
|
let node = nodeIn;
|
|
808
|
-
while (node.parent!.kind === SyntaxKind.PropertyAccessExpression
|
|
809
|
-
|
|
824
|
+
while (node.parent!.kind === SyntaxKind.PropertyAccessExpression || node.parent!.kind === SyntaxKind.QualifiedName)
|
|
825
|
+
node = node.parent!;
|
|
826
|
+
return node.parent!.kind === SyntaxKind.ExpressionWithTypeArguments || isNameOfHeritageClauseTypeReference(node);
|
|
810
827
|
}
|
|
811
828
|
|
|
812
829
|
export function isRightSideOfQualifiedNameOrPropertyAccess(node: Node): boolean {
|
|
@@ -851,7 +868,13 @@ export function isJSDocNameReferenceContext(node: Node): boolean {
|
|
|
851
868
|
|
|
852
869
|
/** The class of an expression with type arguments in its heritage clause. */
|
|
853
870
|
function getClassOfHeritageExpression(node: Node): Node | undefined {
|
|
854
|
-
|
|
871
|
+
return node.kind === SyntaxKind.ExpressionWithTypeArguments ? getClassOfHeritageElement(node) : undefined;
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
/** The class of a heritage clause element: an expression with type arguments, or a type reference in
|
|
875
|
+
* `implements`. */
|
|
876
|
+
function getClassOfHeritageElement(node: Node): Node | undefined {
|
|
877
|
+
if (node.kind !== SyntaxKind.ExpressionWithTypeArguments && node.kind !== SyntaxKind.TypeReference) return undefined;
|
|
855
878
|
const parent = node.parent!;
|
|
856
879
|
return parent.kind === SyntaxKind.HeritageClause && isClassLike(parent.parent!) ? parent.parent : undefined;
|
|
857
880
|
}
|
|
@@ -1088,6 +1111,10 @@ function isInExpressionContext(node: Node): boolean {
|
|
|
1088
1111
|
return getExpression(parent) === node && !isPartOfTypeNode(parent);
|
|
1089
1112
|
case SyntaxKind.ShorthandPropertyAssignment:
|
|
1090
1113
|
return (parent as ShorthandPropertyAssignment).objectAssignmentInitializer === node;
|
|
1114
|
+
case SyntaxKind.FunctionExpression:
|
|
1115
|
+
case SyntaxKind.ClassExpression:
|
|
1116
|
+
// The name of a function or class expression is a declaration name, not an expression.
|
|
1117
|
+
return getName(parent) !== node;
|
|
1091
1118
|
}
|
|
1092
1119
|
return isExpressionNode(parent);
|
|
1093
1120
|
}
|
|
@@ -282,7 +282,20 @@ function getReturnTypesOfSignatures(c: Checker, signatures: readonly Signature[]
|
|
|
282
282
|
export function getReturnTypeOfSignature(c: Checker, sig: Signature): Type {
|
|
283
283
|
if (sig.resolvedReturnType !== undefined) return sig.resolvedReturnType;
|
|
284
284
|
const side = signatureSideOf(c, sig);
|
|
285
|
-
if (side.resolvedReturnType !== undefined)
|
|
285
|
+
if (side.resolvedReturnType !== undefined) {
|
|
286
|
+
if (c.threadSharing !== undefined) noteReturnTypeUse(c, sig);
|
|
287
|
+
return side.resolvedReturnType;
|
|
288
|
+
}
|
|
289
|
+
// TSC_TS_SHARE: checker threads share the return types of declared signatures (shared-results.ts).
|
|
290
|
+
if (c.threadSharing !== undefined && isSharedReturnSignature(c, sig)) {
|
|
291
|
+
const sharing = c.threadSharing;
|
|
292
|
+
if (sharing.computingSignature === sig) sharing.computingSignature = undefined;
|
|
293
|
+
else {
|
|
294
|
+
const t = threadReturnType(c, sig);
|
|
295
|
+
if (side.resolvedReturnType === undefined) side.resolvedReturnType = t;
|
|
296
|
+
return side.resolvedReturnType;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
286
299
|
if (!pushTypeResolution(c, sig, TypeSystemPropertyName.ResolvedReturnType)) return c.errorType;
|
|
287
300
|
let t: Type;
|
|
288
301
|
if (sig.target !== undefined) t = instantiateType(c, getReturnTypeOfSignature(c, sig.target), sig.mapper);
|
|
@@ -335,6 +348,7 @@ export function getReturnTypeOfSignature(c: Checker, sig: Signature): Type {
|
|
|
335
348
|
}
|
|
336
349
|
|
|
337
350
|
import { getOptionalType as getOptionalTypeLocal, addOptionalTypeMarker } from './checker-symbol-types.js';
|
|
351
|
+
import { isSharedReturnSignature, noteReturnTypeUse, threadReturnType } from './shared-results.js';
|
|
338
352
|
|
|
339
353
|
export function isResolvingReturnTypeOfSignature(c: Checker, sig: Signature): boolean {
|
|
340
354
|
if (sig.composite !== undefined)
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
// - grammar: checker-grammar.ts (checks the parser leaves to the checker)
|
|
11
11
|
// - type nodes: `checkTypeNode` below
|
|
12
12
|
import { checkPendingExternalEmitHelpers } from './checker-emit-helpers.js';
|
|
13
|
-
import { produceDeferredCollisionChecks } from './checker-generated-code.js';
|
|
14
13
|
import { resolveUntypedCall } from './checker-calls.js';
|
|
15
14
|
import {
|
|
16
15
|
type ImportTypeNode,
|
|
@@ -58,7 +57,12 @@ import { nodeIsMissing } from './ast-utilities.js';
|
|
|
58
57
|
import { getAttachedJSDoc } from './parser.js';
|
|
59
58
|
import { shouldPreserveConstEnums } from './options.js';
|
|
60
59
|
import { isReachableFlowNode } from './checker-narrowing.js';
|
|
61
|
-
import {
|
|
60
|
+
import {
|
|
61
|
+
getTupleElementFlags,
|
|
62
|
+
getTypeFromIndexedAccessTypeNode,
|
|
63
|
+
getTypeFromTypeNode,
|
|
64
|
+
isAssertionExpression,
|
|
65
|
+
} from './checker-type-nodes.js';
|
|
62
66
|
import { isArrayLikeType } from './checker-members.js';
|
|
63
67
|
import {
|
|
64
68
|
checkBlock,
|
|
@@ -94,6 +98,7 @@ import {
|
|
|
94
98
|
import {
|
|
95
99
|
checkExportAssignment,
|
|
96
100
|
checkExportDeclaration,
|
|
101
|
+
checkImportAttributes,
|
|
97
102
|
checkImportDeclaration,
|
|
98
103
|
checkImportEqualsDeclaration,
|
|
99
104
|
resolveJSDocMemberName,
|
|
@@ -110,9 +115,9 @@ import {
|
|
|
110
115
|
checkComputedPropertyName,
|
|
111
116
|
checkExpression,
|
|
112
117
|
checkIndexedAccessIndexType,
|
|
118
|
+
isConstTypeReference,
|
|
113
119
|
} from './checker-expressions.js';
|
|
114
120
|
import { checkFunctionLikeBody } from './checker-functions.js';
|
|
115
|
-
import { produceDeferredIterationErrors } from './checker-iteration.js';
|
|
116
121
|
import { checkFunctionOrMethodSymbols } from './checker-overloads.js';
|
|
117
122
|
import { checkInferTypeParameterDeclarations, checkTypeLiteralMembers } from './checker-heritage.js';
|
|
118
123
|
import { checkGrammarSourceFile } from './checker-grammar.js';
|
|
@@ -120,7 +125,7 @@ import { Diagnostics } from './diagnostic-messages.js';
|
|
|
120
125
|
import { getTypeOfSymbol, reportImplicitAny } from './checker-symbol-types.js';
|
|
121
126
|
import { getSymbolOfDeclaration } from './checker-symbols.js';
|
|
122
127
|
import { checkUnusedIdentifiers } from './checker-unused.js';
|
|
123
|
-
import { checkDeprecatedTypeReference } from './checker-deprecation.js';
|
|
128
|
+
import { checkContextualDeprecations, checkDeprecatedTypeReference } from './checker-deprecation.js';
|
|
124
129
|
|
|
125
130
|
/**
|
|
126
131
|
* Checks `file` once; diagnostics accumulate in the checker. `checkUnused` also reports unused
|
|
@@ -140,7 +145,6 @@ export function checkSourceFile(c: Checker, file: SourceFile, checkUnused = fals
|
|
|
140
145
|
|
|
141
146
|
function checkSourceFileWorker(c: Checker, file: SourceFile): void {
|
|
142
147
|
c.fileBeingChecked = file;
|
|
143
|
-
c.saveDeferredDiagnostics = true;
|
|
144
148
|
for (const statement of getStatements(file)!.nodes) checkSourceElement(c, statement);
|
|
145
149
|
checkDeferredNodes(c, file);
|
|
146
150
|
if (isExternalOrCommonJSModule(file)) checkExternalModuleExports(c, file);
|
|
@@ -152,9 +156,7 @@ function checkSourceFileWorker(c: Checker, file: SourceFile): void {
|
|
|
152
156
|
checkDeferredNodes(c, file);
|
|
153
157
|
checkPendingExternalEmitHelpers(c, file);
|
|
154
158
|
c.fileBeingChecked = undefined;
|
|
155
|
-
c
|
|
156
|
-
produceDeferredIterationErrors(c);
|
|
157
|
-
produceDeferredCollisionChecks(c);
|
|
159
|
+
produceDeferredDiagnostics(c);
|
|
158
160
|
// The file's deferred nodes are all checked; later ones are not queued (checkNodeDeferred).
|
|
159
161
|
const links = c.nodeLinks(file);
|
|
160
162
|
links.typeChecked = true;
|
|
@@ -175,7 +177,6 @@ function checkSourceFileWorker(c: Checker, file: SourceFile): void {
|
|
|
175
177
|
export function checkSourceFileRange(c: Checker, file: SourceFile, start: number, end: number): boolean {
|
|
176
178
|
const statements = getStatements(file)!.nodes;
|
|
177
179
|
c.fileBeingChecked = file;
|
|
178
|
-
c.saveDeferredDiagnostics = true;
|
|
179
180
|
for (let i = start; i < end; i++) checkSourceElement(c, statements[i]!);
|
|
180
181
|
checkDeferredNodes(c, file);
|
|
181
182
|
const whole = end === statements.length;
|
|
@@ -187,14 +188,24 @@ export function checkSourceFileRange(c: Checker, file: SourceFile, start: number
|
|
|
187
188
|
checkPendingExternalEmitHelpers(c, file);
|
|
188
189
|
}
|
|
189
190
|
c.fileBeingChecked = undefined;
|
|
190
|
-
c
|
|
191
|
-
produceDeferredIterationErrors(c);
|
|
192
|
-
produceDeferredCollisionChecks(c);
|
|
191
|
+
produceDeferredDiagnostics(c);
|
|
193
192
|
// Deferred nodes of a later range are queued again (checkNodeDeferred).
|
|
194
193
|
c.nodeLinks(file).deferredNodes = undefined;
|
|
195
194
|
return c.diagnostics.forFile(file.fileName).length > 0;
|
|
196
195
|
}
|
|
197
196
|
|
|
197
|
+
/**
|
|
198
|
+
* Reports the deferred diagnostics, in the order they were deferred. Diagnostics deferred while they
|
|
199
|
+
* are reported are dropped.
|
|
200
|
+
*/
|
|
201
|
+
export function produceDeferredDiagnostics(c: Checker): void {
|
|
202
|
+
const callbacks = c.deferredDiagnostics;
|
|
203
|
+
if (callbacks.length === 0) return;
|
|
204
|
+
const count = callbacks.length;
|
|
205
|
+
for (let i = 0; i < count; i++) callbacks[i]!();
|
|
206
|
+
c.deferredDiagnostics = [];
|
|
207
|
+
}
|
|
208
|
+
|
|
198
209
|
/** Checks a statement, declaration, class member or type node. */
|
|
199
210
|
export function checkSourceElement(c: Checker, node: Node | undefined): void {
|
|
200
211
|
if (node === undefined) return;
|
|
@@ -445,9 +456,12 @@ function checkTypeNodeWorker(c: Checker, node: Node): void {
|
|
|
445
456
|
break;
|
|
446
457
|
case SyntaxKind.TypeReference:
|
|
447
458
|
case SyntaxKind.ImportType: {
|
|
459
|
+
// `const` in `x as const` is not checked as a type: its type is the type of `x`.
|
|
460
|
+
if (isConstTypeReference(node) && isAssertionExpression(node.parent!)) break;
|
|
448
461
|
const type = getTypeFromTypeNode(c, node);
|
|
449
462
|
checkTypeArgumentConstraintsOfReference(c, node, type);
|
|
450
463
|
checkDeprecatedTypeReference(c, node, type);
|
|
464
|
+
if (node.kind === SyntaxKind.ImportType) checkImportAttributes(c, node);
|
|
451
465
|
break;
|
|
452
466
|
}
|
|
453
467
|
case SyntaxKind.IndexedAccessType:
|
|
@@ -522,6 +536,8 @@ function checkMappedType(c: Checker, node: MappedTypeNode): void {
|
|
|
522
536
|
}
|
|
523
537
|
|
|
524
538
|
function checkTypePredicate(c: Checker, node: TypePredicateNode): void {
|
|
539
|
+
// The predicate's type is checked also in a position a predicate can't have.
|
|
540
|
+
checkTypeNodeIfPresent(c, node.type);
|
|
525
541
|
const parent = getTypePredicateParent(node);
|
|
526
542
|
if (parent === undefined) {
|
|
527
543
|
c.error(node, Diagnostics.A_type_predicate_is_only_allowed_in_return_type_position_for_functions_and_methods);
|
|
@@ -530,7 +546,6 @@ function checkTypePredicate(c: Checker, node: TypePredicateNode): void {
|
|
|
530
546
|
const signature = getSignatureFromDeclaration(c, parent);
|
|
531
547
|
const typePredicate = getTypePredicateOfSignature(c, signature);
|
|
532
548
|
if (typePredicate === undefined) return;
|
|
533
|
-
checkTypeNodeIfPresent(c, node.type);
|
|
534
549
|
if (typePredicate.kind === TypePredicateKind.This || typePredicate.kind === TypePredicateKind.AssertsThis) return;
|
|
535
550
|
const parameterName = node.parameterName;
|
|
536
551
|
if (typePredicate.parameterIndex >= 0) {
|
|
@@ -747,6 +762,17 @@ function checkDeferredNode(c: Checker, node: Node): void {
|
|
|
747
762
|
case SyntaxKind.ClassExpression:
|
|
748
763
|
checkClassLikeDeferred(c, node);
|
|
749
764
|
break;
|
|
765
|
+
case SyntaxKind.ObjectLiteralExpression: {
|
|
766
|
+
// Reported only as suggestions, which are computed when they are asked for (`getSuggestionDiagnostics`).
|
|
767
|
+
const file = getSourceFileOfNode(node);
|
|
768
|
+
const pending = c.objectLiteralsForDeprecations.get(file);
|
|
769
|
+
if (pending === undefined) c.objectLiteralsForDeprecations.set(file, [node]);
|
|
770
|
+
else pending.push(node);
|
|
771
|
+
break;
|
|
772
|
+
}
|
|
773
|
+
case SyntaxKind.JsxAttributes:
|
|
774
|
+
checkContextualDeprecations(c, node);
|
|
775
|
+
break;
|
|
750
776
|
case SyntaxKind.AsExpression:
|
|
751
777
|
case SyntaxKind.TypeAssertionExpression:
|
|
752
778
|
checkAssertionDeferred(c, node);
|
|
@@ -189,15 +189,16 @@ export function checkRightHandSideOfForOf(c: Checker, statement: Node): Type {
|
|
|
189
189
|
|
|
190
190
|
export function checkReturnStatement(c: Checker, node: Node): void {
|
|
191
191
|
const s = node as ReturnStatement;
|
|
192
|
+
// The expression is checked also where a return statement is a grammar error.
|
|
193
|
+
const exprNode = s.expression;
|
|
194
|
+
const exprType = exprNode !== undefined ? checkExpressionCached(c, exprNode) : c.undefinedType;
|
|
192
195
|
const container = getContainingFunction(node);
|
|
193
196
|
// Returns outside functions and in static blocks are grammar errors.
|
|
194
197
|
if (container === undefined) return;
|
|
195
198
|
const signature = getSignatureFromDeclaration(c, container);
|
|
196
199
|
const returnType = getReturnTypeOfSignature(c, signature);
|
|
197
200
|
const functionFlags = getFunctionFlags(container);
|
|
198
|
-
const exprNode = s.expression;
|
|
199
201
|
if (c.strictNullChecks || exprNode !== undefined || (returnType.flags & TypeFlags.Never) !== 0) {
|
|
200
|
-
const exprType = exprNode !== undefined ? checkExpressionCached(c, exprNode) : c.undefinedType;
|
|
201
202
|
if (container.kind === SyntaxKind.SetAccessor) {
|
|
202
203
|
if (exprNode !== undefined) c.error(node, Diagnostics.Setters_cannot_return_a_value);
|
|
203
204
|
} else if (container.kind === SyntaxKind.Constructor) {
|