tsc-ts 0.0.10 → 0.1.1
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 +29 -18
- package/dist/api/compiler/ast.js +1040 -1007
- 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 +136 -91
- package/dist/api/compiler/checker-contextual.d.ts +20 -0
- package/dist/api/compiler/checker-contextual.js +175 -62
- 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 +258 -212
- 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 +107 -89
- 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 +190 -46
- 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 +97 -31
- package/dist/api/compiler/checker.js +149 -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 +24 -4
- package/dist/api/compiler/compile-program.js +53 -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/expr-record.d.ts +11 -0
- package/dist/api/compiler/expr-record.js +53 -0
- 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/identifier-name.d.ts +9 -0
- package/dist/api/compiler/identifier-name.js +10 -0
- package/dist/api/compiler/instantiation.d.ts +7 -0
- package/dist/api/compiler/instantiation.js +101 -49
- package/dist/api/compiler/jsdoc.js +27 -25
- 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 +42 -20
- package/dist/api/compiler/parser.js +318 -224
- 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 +6 -3
- 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 +306 -283
- 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 +64 -59
- package/dist/api/compiler/scanner.d.ts +27 -2
- package/dist/api/compiler/scanner.js +181 -150
- package/dist/api/compiler/shared-results.d.ts +696 -0
- package/dist/api/compiler/shared-results.js +2905 -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 +307 -239
- 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 +74 -38
- package/src/compiler/binder.ts +39 -4
- package/src/compiler/cgroup.ts +157 -0
- package/src/compiler/character-codes.ts +2 -2
- package/src/compiler/checker-calls.ts +76 -8
- package/src/compiler/checker-classes.ts +80 -25
- package/src/compiler/checker-contextual.ts +110 -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 +95 -47
- 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 +28 -5
- 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 +173 -35
- 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 +175 -41
- package/src/compiler/command-line.ts +28 -28
- package/src/compiler/compile-program.ts +59 -25
- package/src/compiler/decoder.ts +15 -5
- package/src/compiler/diagnostic-messages.ts +1973 -1892
- package/src/compiler/doctor-report.ts +133 -0
- package/src/compiler/emitter.ts +57 -8
- package/src/compiler/encoder.ts +23 -8
- package/src/compiler/expr-record.ts +59 -0
- 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/identifier-name.ts +13 -0
- 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 +7 -3
- 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 +543 -147
- package/src/compiler/parallel-emit.ts +4 -4
- package/src/compiler/parser.ts +166 -47
- 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 +7 -3
- package/src/compiler/printer/helpers.ts +10 -1
- package/src/compiler/printer/name-generator.ts +24 -2
- package/src/compiler/printer/printer.ts +39 -16
- 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 +14 -5
- package/src/compiler/run-config.ts +1383 -0
- package/src/compiler/run-record-read.ts +87 -0
- package/src/compiler/run-records.ts +575 -0
- package/src/compiler/scanner.ts +166 -120
- package/src/compiler/shared-results.ts +3144 -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 +22 -3
- 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 +136 -49
- 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 +67 -6
- package/src/compiler/tsc-cli.ts +35 -4
- package/src/compiler/tsc-compile.ts +220 -10
- package/src/compiler/tsc-watch.ts +97 -47
- 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
|
@@ -7,16 +7,17 @@ import { getThisContainer, isEntityNameExpression, isStatic, skipParentheses, is
|
|
|
7
7
|
import { shouldCheckErasableSyntax } from './checker-declarations.js';
|
|
8
8
|
import { skipTrivia } from './scanner.js';
|
|
9
9
|
import { Diagnostic } from './diagnostics.js';
|
|
10
|
+
import { createDiagnosticForNode } from './checker.js';
|
|
10
11
|
import { checkSuperExpression, checkThisBeforeSuper, checkThisInStaticClassFieldInitializerInDecoratedClass, } from './checker-super.js';
|
|
11
12
|
import { cachedTypeKey, } from './checker-types.js';
|
|
12
13
|
import { createTupleTypeEx, getBigIntLiteralType, getFreshTypeOfLiteralType, getNumberLiteralType, getRegularTypeOfLiteralType, getStringLiteralType, getUnionTypeEx, getWidenedLiteralType, getWidenedUniqueESSymbolType, isErrorType, isTupleType, someType, typesOf, getBaseTypeOfLiteralType, cloneTypeReference, createArrayTypeEx, everyType, getTemplateLiteralType, isMutableArrayOrTuple, } from './checker-type-factory.js';
|
|
13
14
|
import { TupleElementInfo } from './checker-types.js';
|
|
14
15
|
import { getBaseConstraintOfType, getPropertyOfType, getIndexInfoOfType, getIndexInfosOfType, getIndexTypeOfType, getTypeOfPropertyOfType, isArrayLikeType, getBaseConstraintOrType, isApplicableIndexType, getDeclarationModifierFlagsFromSymbol, getApparentType, mapToBaseConstraintOrType, } from './checker-members.js';
|
|
15
|
-
import { getExportSymbolOfValueSymbolIfExported, getMergedSymbol, getSymbolOfDeclaration, resolveEntityName, resolveName, getFirstIdentifier,
|
|
16
|
+
import { getExportSymbolOfValueSymbolIfExported, getMergedSymbol, getSymbolOfDeclaration, resolveEntityName, resolveName, getFirstIdentifier, cannotFindNameAtLocation, getDeclarationOfAliasSymbol, popTypeResolution, pushTypeResolution, reportCircularityError, } from './checker-symbols.js';
|
|
16
17
|
import { getTypeOfSymbol, getWidenedType, isReadonlySymbol, getOptionalType, removeMissingType, addOptionality, } from './checker-symbol-types.js';
|
|
17
18
|
import { getDeclaredTypeOfClassOrInterface } from './checker-declared-types.js';
|
|
18
19
|
import { getTypeFromTypeNode } from './checker-type-nodes.js';
|
|
19
|
-
import { isGenericObjectType, getIndexedAccessTypeOrUndefinedEx, getHomomorphicTypeVariable, isGenericIndexType, isGenericMappedType, isGenericType,
|
|
20
|
+
import { isGenericObjectType, getIndexedAccessTypeOrUndefinedEx, getHomomorphicTypeVariable, isGenericIndexType, isGenericMappedType, isGenericType, getIndexTypeEx, getMappedTypeModifiers, getPropertyNameFromIndex, isNoInferType, } from './checker-type-operators.js';
|
|
20
21
|
import { getTypeFacts, getNonNullableType, getTypeWithFacts, hasTypeFacts } from './checker-flow.js';
|
|
21
22
|
import { checkTypeComparableTo, isTypeAssignableTo, isTypeComparableTo } from './relations.js';
|
|
22
23
|
import { isTypeAssignableToKindEx as isTypeAssignableToKind } from './checker-type-operators.js';
|
|
@@ -33,7 +34,8 @@ import { isInPropertyInitializerOrClassStaticBlock } from './checker-declaration
|
|
|
33
34
|
import { checkObjectLiteral } from './checker-object-literals.js';
|
|
34
35
|
import { evaluate } from './checker-evaluator.js';
|
|
35
36
|
import { checkPrivateIdentifierExpression, checkPropertyAccessExpressionOrQualifiedName, isMethodAccessForCall, } from './checker-property-access.js';
|
|
36
|
-
import { checkBinaryExpression, checkConditionalExpression, checkDeleteExpression, checkPostfixUnaryExpression, checkPrefixUnaryExpression, isTypeAssertion, } from './checker-operators.js';
|
|
37
|
+
import { checkBinaryExpression, checkConditionalExpression, checkDeleteExpression, checkPostfixUnaryExpression, checkPrefixUnaryExpression, grammarErrorOnNode, isTypeAssertion, } from './checker-operators.js';
|
|
38
|
+
import { fileExtensionIsOneOf } from './path.js';
|
|
37
39
|
import { checkJsx } from './checker-jsx.js';
|
|
38
40
|
import { getRegularTypeOfObjectLiteral } from './checker-literals.js';
|
|
39
41
|
import { getReturnTypeOfSignature, getSignatureFromDeclaration, getSingleSignature, getThisTypeOfSignature, } from './checker-signatures.js';
|
|
@@ -41,7 +43,7 @@ import { isFunctionLike, isImportCall, isInJSFile, isRequireCall } from './ast-u
|
|
|
41
43
|
import { isLiteralKind } from './printer/utilities.js';
|
|
42
44
|
import { convertAutoToAny, isEvolvingArrayOperationTarget, getAssignmentTargetKind, getControlFlowContainer, isConstantVariable, isInCompoundLikeAssignment, isMutableLocalVariableDeclaration, isParameterOrMutableLocalVariable, isPastLastAssignment, isSymbolAssignedDefinitely, getFlowTypeOfReference, getNarrowedTypeOfSymbol, } from './checker-narrowing.js';
|
|
43
45
|
import { getFlowTypeOfAutoTypedProperty, getThisTypeOfAssignedFunction } from './checker-javascript.js';
|
|
44
|
-
import { checkExpressionWithContextualType, getThisTypeOfObjectLiteralMember } from './checker-contextual.js';
|
|
46
|
+
import { checkExpressionWithContextualType, getThisTypeOfObjectLiteralMember, isCheckedWithoutContextualType, } from './checker-contextual.js';
|
|
45
47
|
import { getInferenceContext, instantiateContextualType, popContextualType, pushCachedContextualType, } from './checker-contextual.js';
|
|
46
48
|
import { addIntraExpressionInferenceSite, isConstTypeVariable } from './checker-inference.js';
|
|
47
49
|
import { isContextSensitiveFunctionOrObjectLiteralMethod } from './checker-contextual.js';
|
|
@@ -54,6 +56,17 @@ export function checkExpression(c, node) {
|
|
|
54
56
|
return checkExpressionEx(c, node, 0 /* CheckMode.Normal */);
|
|
55
57
|
}
|
|
56
58
|
export function checkExpressionEx(c, node, checkMode) {
|
|
59
|
+
// A completed check of this node under this mode answers this one when the check has no
|
|
60
|
+
// contextual type and no inference context: the checker's state only grew since, so this check
|
|
61
|
+
// would produce the type the completed one produced, report the diagnostics it reported and
|
|
62
|
+
// defer the nodes it deferred. Those diagnostics are equal to ones already reported and a node
|
|
63
|
+
// is deferred at most once, so serving the completed type changes neither.
|
|
64
|
+
const recordable = isCheckedWithoutContextualType(c, node);
|
|
65
|
+
if (recordable) {
|
|
66
|
+
const recorded = c.exprCheckRecord.get(node.id, checkMode);
|
|
67
|
+
if (recorded !== undefined)
|
|
68
|
+
return recorded;
|
|
69
|
+
}
|
|
57
70
|
const saveCurrentNode = c.currentNode;
|
|
58
71
|
c.currentNode = node;
|
|
59
72
|
c.instantiationCount = 0;
|
|
@@ -61,6 +74,8 @@ export function checkExpressionEx(c, node, checkMode) {
|
|
|
61
74
|
if (isConstEnumObjectTypeLocal(t))
|
|
62
75
|
checkConstEnumAccess(c, node, t);
|
|
63
76
|
c.currentNode = saveCurrentNode;
|
|
77
|
+
if (recordable)
|
|
78
|
+
c.exprCheckRecord.set(node.id, checkMode, t);
|
|
64
79
|
return t;
|
|
65
80
|
}
|
|
66
81
|
/**
|
|
@@ -69,14 +84,14 @@ export function checkExpressionEx(c, node, checkMode) {
|
|
|
69
84
|
*/
|
|
70
85
|
function checkConstEnumAccess(c, node, t) {
|
|
71
86
|
const parent = node.parent;
|
|
72
|
-
const ok = ((parent.kind ===
|
|
87
|
+
const ok = ((parent.kind === 213 /* SyntaxKind.PropertyAccessExpression */ || parent.kind === 214 /* SyntaxKind.ElementAccessExpression */) &&
|
|
73
88
|
getExpression(parent) === node) ||
|
|
74
|
-
((node.kind === 79 /* SyntaxKind.Identifier */ || node.kind ===
|
|
89
|
+
((node.kind === 79 /* SyntaxKind.Identifier */ || node.kind === 168 /* SyntaxKind.QualifiedName */) &&
|
|
75
90
|
isInRightSideOfImportOrExportAssignment(node)) ||
|
|
76
|
-
(parent.kind ===
|
|
77
|
-
parent.kind ===
|
|
91
|
+
(parent.kind === 188 /* SyntaxKind.TypeQuery */ && parent.exprName === node) ||
|
|
92
|
+
parent.kind === 283 /* SyntaxKind.ExportSpecifier */;
|
|
78
93
|
if (!ok)
|
|
79
|
-
c.error(node,
|
|
94
|
+
c.error(node, 646 /* Diagnostics.X_const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment_or_type_query */);
|
|
80
95
|
// Under verbatimModuleSyntax, only uses that don't resolve to an import are checked here; imports of
|
|
81
96
|
// ambient const enums are checked with the alias.
|
|
82
97
|
if (c.compilerOptions.isolatedModules === true ||
|
|
@@ -85,17 +100,17 @@ function checkConstEnumAccess(c, node, t) {
|
|
|
85
100
|
resolveName(c, node, getText(getFirstIdentifier(node)), 2097152 /* SymbolFlags.Alias */, undefined, false, true) === undefined)) {
|
|
86
101
|
const constEnumDeclaration = t.symbol.valueDeclaration;
|
|
87
102
|
if ((constEnumDeclaration.flags & 8388608 /* NodeFlags.Ambient */) !== 0 && !isValidTypeOnlyAliasUseSite(node))
|
|
88
|
-
c.error(node,
|
|
103
|
+
c.error(node, 887 /* Diagnostics.Cannot_access_ambient_const_enums_when_0_is_enabled */, getIsolatedModulesLikeFlagName(c));
|
|
89
104
|
}
|
|
90
105
|
}
|
|
91
106
|
function isInRightSideOfImportOrExportAssignment(name) {
|
|
92
107
|
let node = name;
|
|
93
|
-
while (node.parent.kind ===
|
|
108
|
+
while (node.parent.kind === 168 /* SyntaxKind.QualifiedName */)
|
|
94
109
|
node = node.parent;
|
|
95
110
|
const parent = node.parent;
|
|
96
|
-
return ((parent.kind ===
|
|
111
|
+
return ((parent.kind === 273 /* SyntaxKind.ImportEqualsDeclaration */ &&
|
|
97
112
|
parent.moduleReference === node) ||
|
|
98
|
-
(parent.kind ===
|
|
113
|
+
(parent.kind === 279 /* SyntaxKind.ExportAssignment */ && getExpression(parent) === node));
|
|
99
114
|
}
|
|
100
115
|
/** The type of `node`, computed once. */
|
|
101
116
|
export function checkExpressionCached(c, node) {
|
|
@@ -162,11 +177,11 @@ export function checkDeclarationInitializer(c, declaration, checkMode = 0 /* Che
|
|
|
162
177
|
function getQuickTypeOfExpression(c, node) {
|
|
163
178
|
const expr = skipParentheses(node);
|
|
164
179
|
switch (expr.kind) {
|
|
165
|
-
case
|
|
180
|
+
case 225 /* SyntaxKind.AwaitExpression */: {
|
|
166
181
|
const t = getQuickTypeOfExpression(c, getExpression(expr));
|
|
167
182
|
return t !== undefined ? getAwaitedType(c, t) : undefined;
|
|
168
183
|
}
|
|
169
|
-
case
|
|
184
|
+
case 215 /* SyntaxKind.CallExpression */: {
|
|
170
185
|
const call = expr;
|
|
171
186
|
if (call.expression.kind === 107 /* SyntaxKind.SuperKeyword */ ||
|
|
172
187
|
isRequireCall(call, true) ||
|
|
@@ -183,10 +198,10 @@ function getQuickTypeOfExpression(c, node) {
|
|
|
183
198
|
}
|
|
184
199
|
return getReturnTypeOfSingleNonGenericSignature(c, checkNonNullExpression(c, call.expression), 0 /* SignatureKind.Call */);
|
|
185
200
|
}
|
|
186
|
-
case
|
|
201
|
+
case 216 /* SyntaxKind.NewExpression */:
|
|
187
202
|
return getReturnTypeOfSingleNonGenericSignature(c, checkNonNullExpression(c, getExpression(expr)), 1 /* SignatureKind.Construct */);
|
|
188
|
-
case
|
|
189
|
-
case
|
|
203
|
+
case 236 /* SyntaxKind.AsExpression */:
|
|
204
|
+
case 218 /* SyntaxKind.TypeAssertionExpression */: {
|
|
190
205
|
const typeNode = getType(expr);
|
|
191
206
|
return isConstTypeReference(typeNode) ? undefined : getTypeFromTypeNode(c, typeNode);
|
|
192
207
|
}
|
|
@@ -202,18 +217,20 @@ function getReturnTypeOfSingleNonGenericSignature(c, funcType, kind) {
|
|
|
202
217
|
: undefined;
|
|
203
218
|
}
|
|
204
219
|
export function checkComputedPropertyName(c, node) {
|
|
205
|
-
const nodeId = node.
|
|
220
|
+
const nodeId = node.id;
|
|
206
221
|
if (c.resolvedTypes.get(nodeId) === undefined) {
|
|
222
|
+
// A reference to the name while its expression is checked sees a circular type.
|
|
223
|
+
c.resolvedTypes.set(nodeId, c.circularConstraintType);
|
|
207
224
|
const expression = node.expression;
|
|
208
225
|
const container = node.parent.parent;
|
|
209
226
|
// `[x in y]` in a type member is a mapped type written in the wrong place, reported by the parser.
|
|
210
|
-
if ((container.kind ===
|
|
227
|
+
if ((container.kind === 189 /* SyntaxKind.TypeLiteral */ ||
|
|
211
228
|
isClassLike(container) ||
|
|
212
|
-
container.kind ===
|
|
213
|
-
expression.kind ===
|
|
229
|
+
container.kind === 266 /* SyntaxKind.InterfaceDeclaration */) &&
|
|
230
|
+
expression.kind === 228 /* SyntaxKind.BinaryExpression */ &&
|
|
214
231
|
expression.operatorToken.kind === 102 /* SyntaxKind.InKeyword */ &&
|
|
215
|
-
node.parent.kind !==
|
|
216
|
-
node.parent.kind !==
|
|
232
|
+
node.parent.kind !== 179 /* SyntaxKind.GetAccessor */ &&
|
|
233
|
+
node.parent.kind !== 180 /* SyntaxKind.SetAccessor */) {
|
|
217
234
|
c.resolvedTypes.set(nodeId, c.errorType);
|
|
218
235
|
return c.resolvedTypes.get(nodeId);
|
|
219
236
|
}
|
|
@@ -223,14 +240,14 @@ export function checkComputedPropertyName(c, node) {
|
|
|
223
240
|
if ((t.flags & 12 /* TypeFlags.Nullable */) !== 0 ||
|
|
224
241
|
(!isTypeAssignableToKind(c, t, 12583968 /* TypeFlags.StringLike */ | 67648 /* TypeFlags.NumberLike */ | 16896 /* TypeFlags.ESSymbolLike */, false) &&
|
|
225
242
|
!isTypeAssignableTo(c, t, c.stringNumberSymbolType)))
|
|
226
|
-
c.error(node,
|
|
243
|
+
c.error(node, 637 /* Diagnostics.A_computed_property_name_must_be_of_type_string_number_symbol_or_any */);
|
|
227
244
|
}
|
|
228
245
|
return c.resolvedTypes.get(nodeId);
|
|
229
246
|
}
|
|
230
247
|
/** A parameter's declared type without `undefined` when its initializer can't be `undefined`. */
|
|
231
248
|
function removeOptionalityFromDeclaredType(c, declaredType, declaration) {
|
|
232
249
|
const removeUndefined = c.strictNullChecks &&
|
|
233
|
-
declaration.kind ===
|
|
250
|
+
declaration.kind === 171 /* SyntaxKind.Parameter */ &&
|
|
234
251
|
getInitializer(declaration) !== undefined &&
|
|
235
252
|
hasTypeFacts(c, declaredType, 16777216 /* TypeFacts.IsUndefined */) &&
|
|
236
253
|
!parameterInitializerContainsUndefined(c, declaration);
|
|
@@ -257,19 +274,19 @@ function parameterInitializerContainsUndefined(c, declaration) {
|
|
|
257
274
|
/** Whether `node` is the operand of a spread in an object destructuring assignment, as in `({ ...x } = obj)`. */
|
|
258
275
|
function isSpreadDestructuringAssignmentTarget(node) {
|
|
259
276
|
const parent = node.parent;
|
|
260
|
-
if (parent.kind !==
|
|
277
|
+
if (parent.kind !== 306 /* SyntaxKind.SpreadAssignment */ || parent.parent === undefined)
|
|
261
278
|
return false;
|
|
262
279
|
const pattern = parent.parent;
|
|
263
280
|
const grandparent = pattern.parent;
|
|
264
|
-
return ((grandparent.kind ===
|
|
265
|
-
(grandparent.kind ===
|
|
281
|
+
return ((grandparent.kind === 228 /* SyntaxKind.BinaryExpression */ && grandparent.left === pattern) ||
|
|
282
|
+
(grandparent.kind === 252 /* SyntaxKind.ForOfStatement */ && grandparent.initializer === pattern));
|
|
266
283
|
}
|
|
267
284
|
/** Whether `node` is in a binding element of the same declaration as the binding element `declaration`. */
|
|
268
285
|
function isSameScopedBindingElement(node, declaration) {
|
|
269
|
-
if (declaration.kind !==
|
|
286
|
+
if (declaration.kind !== 210 /* SyntaxKind.BindingElement */)
|
|
270
287
|
return false;
|
|
271
288
|
let bindingElement = node.parent;
|
|
272
|
-
while (bindingElement !== undefined && bindingElement.kind !==
|
|
289
|
+
while (bindingElement !== undefined && bindingElement.kind !== 210 /* SyntaxKind.BindingElement */)
|
|
273
290
|
bindingElement = bindingElement.parent;
|
|
274
291
|
return bindingElement !== undefined && getRootDeclaration(bindingElement) === getRootDeclaration(declaration);
|
|
275
292
|
}
|
|
@@ -278,16 +295,16 @@ export function isThisInTypeQuery(node) {
|
|
|
278
295
|
if (node.kind !== 79 /* SyntaxKind.Identifier */ || getText(node) !== 'this')
|
|
279
296
|
return false;
|
|
280
297
|
let current = node;
|
|
281
|
-
while (current.parent.kind ===
|
|
298
|
+
while (current.parent.kind === 168 /* SyntaxKind.QualifiedName */ && current.parent.left === current)
|
|
282
299
|
current = current.parent;
|
|
283
|
-
return current.parent.kind ===
|
|
300
|
+
return current.parent.kind === 188 /* SyntaxKind.TypeQuery */;
|
|
284
301
|
}
|
|
285
302
|
/** The type of the expression in a `typeof` type query. */
|
|
286
303
|
export function checkTypeQueryExpression(c, node) {
|
|
287
304
|
const exprName = node.exprName;
|
|
288
305
|
if (exprName.kind === 79 /* SyntaxKind.Identifier */)
|
|
289
306
|
return checkIdentifier(c, exprName);
|
|
290
|
-
if (exprName.kind ===
|
|
307
|
+
if (exprName.kind === 168 /* SyntaxKind.QualifiedName */)
|
|
291
308
|
return checkQualifiedName(c, exprName);
|
|
292
309
|
if (exprName.kind === 109 /* SyntaxKind.ThisKeyword */)
|
|
293
310
|
return checkThisExpression(c, exprName);
|
|
@@ -299,9 +316,9 @@ export function getResolvedSymbol(c, node) {
|
|
|
299
316
|
if (cached !== undefined)
|
|
300
317
|
return cached;
|
|
301
318
|
let symbol = c.unknownSymbol;
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
const found = resolveName(c, node, text, 111551 /* SymbolFlags.Value */ | 1048576 /* SymbolFlags.ExportValue */,
|
|
319
|
+
const text = getText(node);
|
|
320
|
+
if (text !== '') {
|
|
321
|
+
const found = resolveName(c, node, text, 111551 /* SymbolFlags.Value */ | 1048576 /* SymbolFlags.ExportValue */, cannotFindNameAtLocation, !isWriteOnlyAccess(node), false);
|
|
305
322
|
if (found !== undefined)
|
|
306
323
|
symbol = found;
|
|
307
324
|
}
|
|
@@ -332,40 +349,40 @@ function checkExpressionWorker(c, node, checkMode) {
|
|
|
332
349
|
return getFreshTypeOfLiteralType(c, getNumberLiteralType(c, Number(getText(node))));
|
|
333
350
|
case 9 /* SyntaxKind.BigIntLiteral */:
|
|
334
351
|
return getFreshTypeOfLiteralType(c, getBigIntLiteralType(c, parseBigIntText(getText(node))));
|
|
335
|
-
case
|
|
352
|
+
case 230 /* SyntaxKind.TemplateExpression */:
|
|
336
353
|
return checkTemplateExpression(c, node);
|
|
337
354
|
case 13 /* SyntaxKind.RegularExpressionLiteral */:
|
|
338
355
|
return c.globalRegExpType;
|
|
339
|
-
case
|
|
356
|
+
case 211 /* SyntaxKind.ArrayLiteralExpression */:
|
|
340
357
|
return checkArrayLiteral(c, node, checkMode);
|
|
341
|
-
case
|
|
358
|
+
case 212 /* SyntaxKind.ObjectLiteralExpression */:
|
|
342
359
|
return checkObjectLiteral(c, node, checkMode);
|
|
343
|
-
case
|
|
360
|
+
case 213 /* SyntaxKind.PropertyAccessExpression */:
|
|
344
361
|
return checkPropertyAccessExpression(c, node, false, checkMode);
|
|
345
|
-
case
|
|
362
|
+
case 168 /* SyntaxKind.QualifiedName */:
|
|
346
363
|
return checkQualifiedName(c, node);
|
|
347
|
-
case
|
|
364
|
+
case 214 /* SyntaxKind.ElementAccessExpression */:
|
|
348
365
|
return checkElementAccessExpression(c, node, checkMode);
|
|
349
|
-
case
|
|
366
|
+
case 215 /* SyntaxKind.CallExpression */:
|
|
350
367
|
return checkCallExpression(c, node, checkMode);
|
|
351
|
-
case
|
|
368
|
+
case 216 /* SyntaxKind.NewExpression */:
|
|
352
369
|
return checkNewExpression(c, node, checkMode);
|
|
353
|
-
case
|
|
370
|
+
case 217 /* SyntaxKind.TaggedTemplateExpression */:
|
|
354
371
|
return checkTaggedTemplateExpression(c, node, checkMode);
|
|
355
|
-
case
|
|
372
|
+
case 219 /* SyntaxKind.ParenthesizedExpression */:
|
|
356
373
|
return checkExpressionEx(c, getExpression(node), checkMode);
|
|
357
|
-
case
|
|
374
|
+
case 233 /* SyntaxKind.ClassExpression */:
|
|
358
375
|
return checkClassExpression(c, node);
|
|
359
|
-
case
|
|
360
|
-
case
|
|
376
|
+
case 220 /* SyntaxKind.FunctionExpression */:
|
|
377
|
+
case 221 /* SyntaxKind.ArrowFunction */:
|
|
361
378
|
return checkFunctionExpressionOrObjectLiteralMethod(c, node, checkMode);
|
|
362
|
-
case
|
|
379
|
+
case 223 /* SyntaxKind.TypeOfExpression */:
|
|
363
380
|
checkExpression(c, getExpression(node));
|
|
364
381
|
return c.typeofType;
|
|
365
|
-
case
|
|
366
|
-
case
|
|
382
|
+
case 218 /* SyntaxKind.TypeAssertionExpression */:
|
|
383
|
+
case 236 /* SyntaxKind.AsExpression */:
|
|
367
384
|
return checkAssertion(c, node, checkMode);
|
|
368
|
-
case
|
|
385
|
+
case 237 /* SyntaxKind.NonNullExpression */: {
|
|
369
386
|
const leftType = checkExpressionEx(c, getExpression(node), checkMode);
|
|
370
387
|
if ((node.flags & 32 /* NodeFlags.OptionalChain */) === 0)
|
|
371
388
|
return getNonNullableType(c, leftType);
|
|
@@ -373,41 +390,41 @@ function checkExpressionWorker(c, node, checkMode) {
|
|
|
373
390
|
const nonOptionalType = getOptionalExpressionType(c, leftType, getExpression(node));
|
|
374
391
|
return propagateOptionalTypeMarker(c, getNonNullableType(c, nonOptionalType), node, nonOptionalType !== leftType);
|
|
375
392
|
}
|
|
376
|
-
case
|
|
393
|
+
case 235 /* SyntaxKind.ExpressionWithTypeArguments */:
|
|
377
394
|
return checkExpressionWithTypeArguments(c, node);
|
|
378
|
-
case
|
|
395
|
+
case 240 /* SyntaxKind.SatisfiesExpression */:
|
|
379
396
|
return checkSatisfiesExpression(c, node, checkMode);
|
|
380
|
-
case
|
|
397
|
+
case 238 /* SyntaxKind.MetaProperty */:
|
|
381
398
|
return checkMetaProperty(c, node);
|
|
382
|
-
case
|
|
399
|
+
case 222 /* SyntaxKind.DeleteExpression */:
|
|
383
400
|
return checkDeleteExpression(c, node);
|
|
384
|
-
case
|
|
401
|
+
case 224 /* SyntaxKind.VoidExpression */:
|
|
385
402
|
// The operand is checked deferred.
|
|
386
403
|
checkNodeDeferred(c, node);
|
|
387
404
|
return c.undefinedWideningType;
|
|
388
|
-
case
|
|
405
|
+
case 225 /* SyntaxKind.AwaitExpression */:
|
|
389
406
|
return checkAwaitExpression(c, node);
|
|
390
|
-
case
|
|
407
|
+
case 226 /* SyntaxKind.PrefixUnaryExpression */:
|
|
391
408
|
return checkPrefixUnaryExpression(c, node);
|
|
392
|
-
case
|
|
409
|
+
case 227 /* SyntaxKind.PostfixUnaryExpression */:
|
|
393
410
|
return checkPostfixUnaryExpression(c, node);
|
|
394
|
-
case
|
|
411
|
+
case 228 /* SyntaxKind.BinaryExpression */:
|
|
395
412
|
return checkBinaryExpression(c, node, checkMode);
|
|
396
|
-
case
|
|
413
|
+
case 229 /* SyntaxKind.ConditionalExpression */:
|
|
397
414
|
return checkConditionalExpression(c, node, checkMode);
|
|
398
|
-
case
|
|
415
|
+
case 232 /* SyntaxKind.SpreadElement */:
|
|
399
416
|
return checkSpreadExpression(c, node, checkMode);
|
|
400
|
-
case
|
|
417
|
+
case 234 /* SyntaxKind.OmittedExpression */:
|
|
401
418
|
return c.undefinedWideningType;
|
|
402
|
-
case
|
|
419
|
+
case 231 /* SyntaxKind.YieldExpression */:
|
|
403
420
|
return checkYieldExpression(c, node);
|
|
404
|
-
case
|
|
421
|
+
case 239 /* SyntaxKind.SyntheticExpression */:
|
|
405
422
|
return c.anyType;
|
|
406
|
-
case
|
|
407
|
-
case
|
|
408
|
-
case
|
|
409
|
-
case
|
|
410
|
-
case
|
|
423
|
+
case 296 /* SyntaxKind.JsxExpression */:
|
|
424
|
+
case 286 /* SyntaxKind.JsxElement */:
|
|
425
|
+
case 287 /* SyntaxKind.JsxSelfClosingElement */:
|
|
426
|
+
case 290 /* SyntaxKind.JsxFragment */:
|
|
427
|
+
case 294 /* SyntaxKind.JsxAttributes */:
|
|
411
428
|
return checkJsx(c, node, checkMode);
|
|
412
429
|
}
|
|
413
430
|
return c.errorType;
|
|
@@ -434,7 +451,7 @@ export function checkIdentifier(c, node, checkMode = 0 /* CheckMode.Normal */) {
|
|
|
434
451
|
return c.errorType;
|
|
435
452
|
if (symbol === c.argumentsSymbol) {
|
|
436
453
|
if (isInPropertyInitializerOrClassStaticBlock(node, true)) {
|
|
437
|
-
c.error(node,
|
|
454
|
+
c.error(node, 953 /* Diagnostics.X_arguments_cannot_be_referenced_in_property_initializers_or_class_static_initialization_blocks */);
|
|
438
455
|
return c.errorType;
|
|
439
456
|
}
|
|
440
457
|
return getTypeOfSymbol(c, symbol);
|
|
@@ -446,7 +463,7 @@ export function checkIdentifier(c, node, checkMode = 0 /* CheckMode.Normal */) {
|
|
|
446
463
|
const immediateDeclaration = declaration;
|
|
447
464
|
// In `const [a, b = a + 1] = [2]`, `a` is `any` while computing the contextual type of `[2]`.
|
|
448
465
|
if (declaration !== undefined &&
|
|
449
|
-
declaration.kind ===
|
|
466
|
+
declaration.kind === 210 /* SyntaxKind.BindingElement */ &&
|
|
450
467
|
c.contextualBindingPatterns.includes(declaration.parent) &&
|
|
451
468
|
isDescendantOf(node, declaration.parent))
|
|
452
469
|
return c.nonInferrableAnyType;
|
|
@@ -454,22 +471,22 @@ export function checkIdentifier(c, node, checkMode = 0 /* CheckMode.Normal */) {
|
|
|
454
471
|
const assignmentKind = getAssignmentTargetKind(node);
|
|
455
472
|
if (assignmentKind !== 0 /* AssignmentKind.None */) {
|
|
456
473
|
if ((localOrExportSymbol.flags & 3 /* SymbolFlags.Variable */) === 0) {
|
|
457
|
-
let message =
|
|
474
|
+
let message = 703 /* Diagnostics.Cannot_assign_to_0_because_it_is_not_a_variable */;
|
|
458
475
|
if ((localOrExportSymbol.flags & 384 /* SymbolFlags.Enum */) !== 0)
|
|
459
|
-
message =
|
|
476
|
+
message = 778 /* Diagnostics.Cannot_assign_to_0_because_it_is_an_enum */;
|
|
460
477
|
else if ((localOrExportSymbol.flags & 32 /* SymbolFlags.Class */) !== 0)
|
|
461
|
-
message =
|
|
478
|
+
message = 779 /* Diagnostics.Cannot_assign_to_0_because_it_is_a_class */;
|
|
462
479
|
else if ((localOrExportSymbol.flags & 1536 /* SymbolFlags.Module */) !== 0)
|
|
463
|
-
message =
|
|
480
|
+
message = 781 /* Diagnostics.Cannot_assign_to_0_because_it_is_a_namespace */;
|
|
464
481
|
else if ((localOrExportSymbol.flags & 16 /* SymbolFlags.Function */) !== 0)
|
|
465
|
-
message =
|
|
482
|
+
message = 780 /* Diagnostics.Cannot_assign_to_0_because_it_is_a_function */;
|
|
466
483
|
else if ((localOrExportSymbol.flags & 2097152 /* SymbolFlags.Alias */) !== 0)
|
|
467
|
-
message =
|
|
484
|
+
message = 782 /* Diagnostics.Cannot_assign_to_0_because_it_is_an_import */;
|
|
468
485
|
c.error(node, message, symbolToString(c, symbol));
|
|
469
486
|
return c.errorType;
|
|
470
487
|
}
|
|
471
488
|
if (isReadonlySymbol(c, localOrExportSymbol)) {
|
|
472
|
-
c.error(node,
|
|
489
|
+
c.error(node, 743 /* Diagnostics.Cannot_assign_to_0_because_it_is_a_constant */, symbolToString(c, symbol));
|
|
473
490
|
return c.errorType;
|
|
474
491
|
}
|
|
475
492
|
}
|
|
@@ -485,14 +502,14 @@ export function checkIdentifier(c, node, checkMode = 0 /* CheckMode.Normal */) {
|
|
|
485
502
|
return t;
|
|
486
503
|
if (declaration === undefined)
|
|
487
504
|
return t;
|
|
488
|
-
const isParameter = getRootDeclaration(declaration).kind ===
|
|
505
|
+
const isParameter = getRootDeclaration(declaration).kind === 171 /* SyntaxKind.Parameter */;
|
|
489
506
|
// The CommonJS `module` symbol is declared by its source file.
|
|
490
507
|
const declarationContainer = declaration.parent !== undefined ? getControlFlowContainer(declaration) : undefined;
|
|
491
508
|
let flowContainer = getControlFlowContainer(node);
|
|
492
509
|
const isOuterVariable = flowContainer !== declarationContainer;
|
|
493
510
|
const isModuleExports = (symbol.flags & 134217728 /* SymbolFlags.ModuleExports */) !== 0;
|
|
494
511
|
const typeIsAutomatic = t === c.autoType || t === c.autoArrayType;
|
|
495
|
-
const isAutomaticTypeInNonNull = typeIsAutomatic && node.parent.kind ===
|
|
512
|
+
const isAutomaticTypeInNonNull = typeIsAutomatic && node.parent.kind === 237 /* SyntaxKind.NonNullExpression */;
|
|
496
513
|
// Closures see narrowings of constants, and of variables past their last assignment.
|
|
497
514
|
while (flowContainer !== declarationContainer &&
|
|
498
515
|
(isFunctionExpressionOrArrowFunction(flowContainer) ||
|
|
@@ -501,9 +518,9 @@ export function checkIdentifier(c, node, checkMode = 0 /* CheckMode.Normal */) {
|
|
|
501
518
|
(isParameterOrMutableLocalVariable(c, localOrExportSymbol) && isPastLastAssignment(c, localOrExportSymbol, node))))
|
|
502
519
|
flowContainer = getControlFlowContainer(flowContainer);
|
|
503
520
|
const isNeverInitialized = immediateDeclaration !== undefined &&
|
|
504
|
-
immediateDeclaration.kind ===
|
|
505
|
-
immediateDeclaration.parent.parent.kind !==
|
|
506
|
-
immediateDeclaration.parent.parent.kind !==
|
|
521
|
+
immediateDeclaration.kind === 262 /* SyntaxKind.VariableDeclaration */ &&
|
|
522
|
+
immediateDeclaration.parent.parent.kind !== 251 /* SyntaxKind.ForInStatement */ &&
|
|
523
|
+
immediateDeclaration.parent.parent.kind !== 252 /* SyntaxKind.ForOfStatement */ &&
|
|
507
524
|
getInitializer(immediateDeclaration) === undefined &&
|
|
508
525
|
immediateDeclaration.exclamationToken === undefined &&
|
|
509
526
|
isMutableLocalVariableDeclaration(immediateDeclaration) &&
|
|
@@ -520,9 +537,9 @@ export function checkIdentifier(c, node, checkMode = 0 /* CheckMode.Normal */) {
|
|
|
520
537
|
(t.flags & (3 /* TypeFlags.AnyOrUnknown */ | 16 /* TypeFlags.Void */)) !== 0 ||
|
|
521
538
|
isPartOfTypeQuery(node) ||
|
|
522
539
|
isInAmbientOrTypeNode(node) ||
|
|
523
|
-
node.parent.kind ===
|
|
524
|
-
node.parent.kind ===
|
|
525
|
-
(declaration.kind ===
|
|
540
|
+
node.parent.kind === 283 /* SyntaxKind.ExportSpecifier */)) ||
|
|
541
|
+
node.parent.kind === 237 /* SyntaxKind.NonNullExpression */ ||
|
|
542
|
+
(declaration.kind === 262 /* SyntaxKind.VariableDeclaration */ &&
|
|
526
543
|
declaration.exclamationToken !== undefined) ||
|
|
527
544
|
(declaration.flags & 8388608 /* NodeFlags.Ambient */) !== 0;
|
|
528
545
|
let initialType;
|
|
@@ -542,14 +559,14 @@ export function checkIdentifier(c, node, checkMode = 0 /* CheckMode.Normal */) {
|
|
|
542
559
|
if (!isEvolvingArrayOperationTarget(c, node) && typeIsAutomatic) {
|
|
543
560
|
if (flowType === c.autoType || flowType === c.autoArrayType) {
|
|
544
561
|
if (c.noImplicitAny) {
|
|
545
|
-
c.error(getNameOfDeclaration(declaration),
|
|
546
|
-
c.error(node,
|
|
562
|
+
c.error(getNameOfDeclaration(declaration), 1724 /* Diagnostics.Variable_0_implicitly_has_type_1_in_some_locations_where_its_type_cannot_be_determined */, symbolToString(c, symbol), typeToString(c, flowType));
|
|
563
|
+
c.error(node, 1697 /* Diagnostics.Variable_0_implicitly_has_an_1_type */, symbolToString(c, symbol), typeToString(c, flowType));
|
|
547
564
|
}
|
|
548
565
|
return convertAutoToAny(c, flowType);
|
|
549
566
|
}
|
|
550
567
|
}
|
|
551
568
|
else if (!assumeInitialized && !containsUndefinedType(t) && containsUndefinedType(flowType)) {
|
|
552
|
-
c.error(node,
|
|
569
|
+
c.error(node, 628 /* Diagnostics.Variable_0_is_used_before_being_assigned */, symbolToString(c, symbol));
|
|
553
570
|
return t;
|
|
554
571
|
}
|
|
555
572
|
return assignmentKind !== 0 /* AssignmentKind.None */ ? getBaseTypeOfLiteralType(c, flowType) : flowType;
|
|
@@ -578,11 +595,11 @@ export function someTypeIsGenericWithUnionConstraint(c, t) {
|
|
|
578
595
|
function isConstraintPosition(c, t, node) {
|
|
579
596
|
const parent = node.parent;
|
|
580
597
|
// `obj[x]` keeps `T[K]` when both are generic and obj's constraint isn't nullable.
|
|
581
|
-
return (parent.kind ===
|
|
582
|
-
parent.kind ===
|
|
583
|
-
((parent.kind ===
|
|
598
|
+
return (parent.kind === 213 /* SyntaxKind.PropertyAccessExpression */ ||
|
|
599
|
+
parent.kind === 168 /* SyntaxKind.QualifiedName */ ||
|
|
600
|
+
((parent.kind === 215 /* SyntaxKind.CallExpression */ || parent.kind === 216 /* SyntaxKind.NewExpression */) &&
|
|
584
601
|
getExpression(parent) === node) ||
|
|
585
|
-
(parent.kind ===
|
|
602
|
+
(parent.kind === 214 /* SyntaxKind.ElementAccessExpression */ &&
|
|
586
603
|
getExpression(parent) === node &&
|
|
587
604
|
!(someType(t, (u) => isGenericTypeWithoutNullableConstraint(c, u)) &&
|
|
588
605
|
isGenericIndexType(c, getTypeOfExpression(c, parent.argumentExpression)))));
|
|
@@ -609,11 +626,11 @@ function isGenericTypeWithoutNullableConstraint(c, t) {
|
|
|
609
626
|
function hasContextualTypeWithNoGenericTypes(c, node, checkMode) {
|
|
610
627
|
// JSX tag names are excluded: their contextual type resolves the tag itself.
|
|
611
628
|
if (node.kind !== 79 /* SyntaxKind.Identifier */ &&
|
|
612
|
-
node.kind !==
|
|
613
|
-
node.kind !==
|
|
629
|
+
node.kind !== 213 /* SyntaxKind.PropertyAccessExpression */ &&
|
|
630
|
+
node.kind !== 214 /* SyntaxKind.ElementAccessExpression */)
|
|
614
631
|
return false;
|
|
615
632
|
const parent = node.parent;
|
|
616
|
-
if ((parent.kind ===
|
|
633
|
+
if ((parent.kind === 288 /* SyntaxKind.JsxOpeningElement */ || parent.kind === 287 /* SyntaxKind.JsxSelfClosingElement */) &&
|
|
617
634
|
getTagName(parent) === node)
|
|
618
635
|
return false;
|
|
619
636
|
// Rest elements skip binding pattern contextual types, so their type stays generic when possible.
|
|
@@ -635,9 +652,9 @@ export function isInAmbientOrTypeNode(node) {
|
|
|
635
652
|
if ((node.flags & 8388608 /* NodeFlags.Ambient */) !== 0)
|
|
636
653
|
return true;
|
|
637
654
|
for (let current = node; current !== undefined; current = current.parent) {
|
|
638
|
-
if (current.kind ===
|
|
639
|
-
current.kind ===
|
|
640
|
-
current.kind ===
|
|
655
|
+
if (current.kind === 266 /* SyntaxKind.InterfaceDeclaration */ ||
|
|
656
|
+
current.kind === 267 /* SyntaxKind.TypeAliasDeclaration */ ||
|
|
657
|
+
current.kind === 189 /* SyntaxKind.TypeLiteral */)
|
|
641
658
|
return true;
|
|
642
659
|
}
|
|
643
660
|
return false;
|
|
@@ -647,15 +664,15 @@ export function checkThisExpression(c, node) {
|
|
|
647
664
|
let container = getThisContainer(node, true, true);
|
|
648
665
|
let capturedByArrowFunction = false;
|
|
649
666
|
let thisInComputedPropertyName = false;
|
|
650
|
-
if (container.kind ===
|
|
651
|
-
checkThisBeforeSuper(c, node, container,
|
|
667
|
+
if (container.kind === 178 /* SyntaxKind.Constructor */)
|
|
668
|
+
checkThisBeforeSuper(c, node, container, 1832 /* Diagnostics.X_super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class */);
|
|
652
669
|
for (;;) {
|
|
653
670
|
// Skip arrow functions to the real owner of `this`.
|
|
654
|
-
if (container.kind ===
|
|
671
|
+
if (container.kind === 221 /* SyntaxKind.ArrowFunction */) {
|
|
655
672
|
container = getThisContainer(container, false, !thisInComputedPropertyName);
|
|
656
673
|
capturedByArrowFunction = true;
|
|
657
674
|
}
|
|
658
|
-
if (container.kind ===
|
|
675
|
+
if (container.kind === 169 /* SyntaxKind.ComputedPropertyName */) {
|
|
659
676
|
container = getThisContainer(container, !capturedByArrowFunction, false);
|
|
660
677
|
thisInComputedPropertyName = true;
|
|
661
678
|
continue;
|
|
@@ -664,23 +681,31 @@ export function checkThisExpression(c, node) {
|
|
|
664
681
|
}
|
|
665
682
|
checkThisInStaticClassFieldInitializerInDecoratedClass(c, node, container);
|
|
666
683
|
if (thisInComputedPropertyName)
|
|
667
|
-
c.error(node,
|
|
668
|
-
else if (container.kind ===
|
|
669
|
-
c.error(node,
|
|
670
|
-
else if (container.kind ===
|
|
671
|
-
c.error(node,
|
|
684
|
+
c.error(node, 638 /* Diagnostics.X_this_cannot_be_referenced_in_a_computed_property_name */);
|
|
685
|
+
else if (container.kind === 269 /* SyntaxKind.ModuleDeclaration */)
|
|
686
|
+
c.error(node, 516 /* Diagnostics.X_this_cannot_be_referenced_in_a_module_or_namespace_body */);
|
|
687
|
+
else if (container.kind === 268 /* SyntaxKind.EnumDeclaration */)
|
|
688
|
+
c.error(node, 517 /* Diagnostics.X_this_cannot_be_referenced_in_current_location */);
|
|
672
689
|
const t = tryGetThisTypeAt(c, node, container);
|
|
673
690
|
if (c.noImplicitThis) {
|
|
674
691
|
const globalThisType = getTypeOfSymbol(c, c.globalThisSymbol);
|
|
675
692
|
if (t === globalThisType && capturedByArrowFunction)
|
|
676
|
-
c.error(node,
|
|
677
|
-
else if (t === undefined)
|
|
678
|
-
|
|
693
|
+
c.error(node, 1731 /* Diagnostics.The_containing_arrow_function_captures_the_global_value_of_this */);
|
|
694
|
+
else if (t === undefined) {
|
|
695
|
+
// The related information goes on the reported diagnostic after it is added, as tsgo attaches it,
|
|
696
|
+
// so a later equal report compares unequal to it and is kept.
|
|
697
|
+
const diagnostic = c.error(node, 823 /* Diagnostics.X_this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation */);
|
|
698
|
+
if (container.kind !== 308 /* SyntaxKind.SourceFile */) {
|
|
699
|
+
const outsideThis = tryGetThisTypeAt(c, container, getThisContainer(container, false, false));
|
|
700
|
+
if (outsideThis !== undefined && outsideThis !== globalThisType)
|
|
701
|
+
diagnostic.addRelatedInfo(createDiagnosticForNode(container, 877 /* Diagnostics.An_outer_value_of_this_is_shadowed_by_this_container */, []));
|
|
702
|
+
}
|
|
703
|
+
}
|
|
679
704
|
}
|
|
680
705
|
return t ?? c.anyType;
|
|
681
706
|
}
|
|
682
707
|
function tryGetThisTypeAt(c, node, container) {
|
|
683
|
-
if (isFunctionLike(container) && container.kind !==
|
|
708
|
+
if (isFunctionLike(container) && container.kind !== 178 /* SyntaxKind.Constructor */) {
|
|
684
709
|
const thisType = getThisTypeOfSignature(c, getSignatureOfFullSignatureType(c, container) ?? getSignatureFromDeclaration(c, container)) ?? getContextualThisParameterType(c, container);
|
|
685
710
|
if (thisType !== undefined)
|
|
686
711
|
return getFlowTypeOfReference(c, node, thisType, thisType, undefined);
|
|
@@ -690,12 +715,12 @@ function tryGetThisTypeAt(c, node, container) {
|
|
|
690
715
|
const classSymbol = getSymbolOfDeclaration(c, parent);
|
|
691
716
|
if (classSymbol === undefined)
|
|
692
717
|
return c.anyType;
|
|
693
|
-
const t = isStatic(container) || container.kind ===
|
|
718
|
+
const t = isStatic(container) || container.kind === 177 /* SyntaxKind.ClassStaticBlockDeclaration */
|
|
694
719
|
? getTypeOfSymbol(c, classSymbol)
|
|
695
720
|
: getDeclaredTypeOfClassOrInterface(c, getMergedSymbol(c, classSymbol)).thisType;
|
|
696
721
|
return t !== undefined ? getFlowTypeOfReference(c, node, t, t, undefined) : c.anyType;
|
|
697
722
|
}
|
|
698
|
-
if (container.kind ===
|
|
723
|
+
if (container.kind === 308 /* SyntaxKind.SourceFile */) {
|
|
699
724
|
if (container.externalModuleIndicator !== undefined)
|
|
700
725
|
return c.undefinedType;
|
|
701
726
|
return getTypeOfSymbol(c, c.globalThisSymbol);
|
|
@@ -704,7 +729,7 @@ function tryGetThisTypeAt(c, node, container) {
|
|
|
704
729
|
}
|
|
705
730
|
/** The `this` type of a function expression or method from its context, such as its object literal. */
|
|
706
731
|
export function getContextualThisParameterType(c, func) {
|
|
707
|
-
if (func.kind ===
|
|
732
|
+
if (func.kind === 221 /* SyntaxKind.ArrowFunction */)
|
|
708
733
|
return undefined;
|
|
709
734
|
if (isContextSensitiveFunctionOrObjectLiteralMethod(c, func)) {
|
|
710
735
|
const signature = getContextualSignatureForFunctionLikeDeclaration(c, func);
|
|
@@ -720,12 +745,12 @@ export function getContextualThisParameterType(c, func) {
|
|
|
720
745
|
}
|
|
721
746
|
function getContainingObjectLiteral(func) {
|
|
722
747
|
const parent = func.parent;
|
|
723
|
-
if ((func.kind ===
|
|
724
|
-
func.kind ===
|
|
725
|
-
func.kind ===
|
|
726
|
-
parent.kind ===
|
|
748
|
+
if ((func.kind === 176 /* SyntaxKind.MethodDeclaration */ ||
|
|
749
|
+
func.kind === 179 /* SyntaxKind.GetAccessor */ ||
|
|
750
|
+
func.kind === 180 /* SyntaxKind.SetAccessor */) &&
|
|
751
|
+
parent.kind === 212 /* SyntaxKind.ObjectLiteralExpression */)
|
|
727
752
|
return parent;
|
|
728
|
-
if (func.kind ===
|
|
753
|
+
if (func.kind === 220 /* SyntaxKind.FunctionExpression */ && parent.kind === 304 /* SyntaxKind.PropertyAssignment */)
|
|
729
754
|
return parent.parent;
|
|
730
755
|
return undefined;
|
|
731
756
|
}
|
|
@@ -738,11 +763,11 @@ function checkTemplateExpression(c, node) {
|
|
|
738
763
|
const t = checkExpression(c, expression);
|
|
739
764
|
if (maybeTypeOfKind(t, 16896 /* TypeFlags.ESSymbolLike */) ||
|
|
740
765
|
maybeTypeOfKind(getBaseConstraintOrType(c, t), 16896 /* TypeFlags.ESSymbolLike */))
|
|
741
|
-
c.error(expression,
|
|
766
|
+
c.error(expression, 870 /* Diagnostics.Implicit_conversion_of_a_symbol_to_a_string_will_fail_at_runtime_Consider_wrapping_this_expression_in_String */);
|
|
742
767
|
texts.push(getText(span.literal));
|
|
743
768
|
types.push(isTypeAssignableTo(c, t, c.templateConstraintType) ? t : c.stringType);
|
|
744
769
|
}
|
|
745
|
-
if (node.parent.kind !==
|
|
770
|
+
if (node.parent.kind !== 217 /* SyntaxKind.TaggedTemplateExpression */) {
|
|
746
771
|
const evaluated = evaluate(c, node, node);
|
|
747
772
|
if (evaluated.kind === 2 /* EvaluatedKind.String */)
|
|
748
773
|
return getFreshTypeOfLiteralType(c, getStringLiteralType(c, evaluated.stringValue));
|
|
@@ -755,8 +780,8 @@ function checkTemplateExpression(c, node) {
|
|
|
755
780
|
}
|
|
756
781
|
function isTemplateLiteralContext(node) {
|
|
757
782
|
const parent = node.parent;
|
|
758
|
-
return ((parent.kind ===
|
|
759
|
-
(parent.kind ===
|
|
783
|
+
return ((parent.kind === 219 /* SyntaxKind.ParenthesizedExpression */ && isTemplateLiteralContext(parent)) ||
|
|
784
|
+
(parent.kind === 214 /* SyntaxKind.ElementAccessExpression */ &&
|
|
760
785
|
parent.argumentExpression === node));
|
|
761
786
|
}
|
|
762
787
|
function isTemplateLiteralContextualType(c, t) {
|
|
@@ -781,7 +806,7 @@ function checkArrayLiteral(c, node, checkMode) {
|
|
|
781
806
|
(contextualType !== undefined && someType(contextualType, (t) => isTupleLikeContext(c, t)));
|
|
782
807
|
let hasOmittedExpression = false;
|
|
783
808
|
for (const e of elements) {
|
|
784
|
-
if (e.kind ===
|
|
809
|
+
if (e.kind === 232 /* SyntaxKind.SpreadElement */) {
|
|
785
810
|
const spreadType = checkExpressionEx(c, e.expression, checkMode);
|
|
786
811
|
if (isArrayLikeType(c, spreadType)) {
|
|
787
812
|
elementTypes.push(spreadType);
|
|
@@ -801,13 +826,13 @@ function checkArrayLiteral(c, node, checkMode) {
|
|
|
801
826
|
elementInfos.push(new TupleElementInfo(4 /* ElementFlags.Rest */, undefined));
|
|
802
827
|
}
|
|
803
828
|
}
|
|
804
|
-
else if (c.exactOptionalPropertyTypes && e.kind ===
|
|
829
|
+
else if (c.exactOptionalPropertyTypes && e.kind === 234 /* SyntaxKind.OmittedExpression */) {
|
|
805
830
|
hasOmittedExpression = true;
|
|
806
831
|
elementTypes.push(c.undefinedOrMissingType);
|
|
807
832
|
elementInfos.push(new TupleElementInfo(2 /* ElementFlags.Optional */, undefined));
|
|
808
833
|
}
|
|
809
834
|
else {
|
|
810
|
-
const t = e.kind ===
|
|
835
|
+
const t = e.kind === 234 /* SyntaxKind.OmittedExpression */
|
|
811
836
|
? c.undefinedWideningType
|
|
812
837
|
: checkExpressionForMutableLocationEx(c, e, checkMode);
|
|
813
838
|
if (inTupleContext &&
|
|
@@ -843,10 +868,10 @@ function checkArrayLiteral(c, node, checkMode) {
|
|
|
843
868
|
}
|
|
844
869
|
function isSpreadIntoCallOrNew(node) {
|
|
845
870
|
let parent = node.parent;
|
|
846
|
-
while (parent.kind ===
|
|
871
|
+
while (parent.kind === 219 /* SyntaxKind.ParenthesizedExpression */)
|
|
847
872
|
parent = parent.parent;
|
|
848
|
-
return (parent.kind ===
|
|
849
|
-
(parent.parent.kind ===
|
|
873
|
+
return (parent.kind === 232 /* SyntaxKind.SpreadElement */ &&
|
|
874
|
+
(parent.parent.kind === 215 /* SyntaxKind.CallExpression */ || parent.parent.kind === 216 /* SyntaxKind.NewExpression */));
|
|
850
875
|
}
|
|
851
876
|
function isTupleLikeContext(c, t) {
|
|
852
877
|
if (isTupleLikeType(c, t))
|
|
@@ -870,7 +895,8 @@ export function isTupleLikeType(c, t) {
|
|
|
870
895
|
/** Whether `t` is a mutable array, a mutable tuple, or assignable to `any[]`. */
|
|
871
896
|
export function isMutableArrayLikeType(c, t) {
|
|
872
897
|
return (isMutableArrayOrTuple(c, t) ||
|
|
873
|
-
((t.flags & (1 /* TypeFlags.Any */ | 12 /* TypeFlags.Nullable */)) === 0 &&
|
|
898
|
+
((t.flags & (1 /* TypeFlags.Any */ | 12 /* TypeFlags.Nullable */ | 262144 /* TypeFlags.Never */)) === 0 &&
|
|
899
|
+
isTypeAssignableTo(c, t, c.anyArrayType)));
|
|
874
900
|
}
|
|
875
901
|
function createArrayLiteralType(c, t) {
|
|
876
902
|
if ((t.objectFlags & 4 /* ObjectFlags.Reference */) === 0)
|
|
@@ -899,36 +925,59 @@ export function getPropertyNameOfObjectLiteralElement(c, element) {
|
|
|
899
925
|
return String(Number(getText(name)));
|
|
900
926
|
case 9 /* SyntaxKind.BigIntLiteral */:
|
|
901
927
|
return parseBigIntText(getText(name));
|
|
902
|
-
case
|
|
928
|
+
case 169 /* SyntaxKind.ComputedPropertyName */: {
|
|
903
929
|
const t = checkComputedPropertyName(c, name);
|
|
904
930
|
return isTypeUsableAsPropertyName(t) ? getPropertyNameFromType(t) : undefined;
|
|
905
931
|
}
|
|
906
932
|
}
|
|
907
933
|
return undefined;
|
|
908
934
|
}
|
|
935
|
+
/** Whether `node` is the object literal of the `with` property of an `import()` call's options argument. */
|
|
936
|
+
function isInlineImportAttributes(node) {
|
|
937
|
+
const property = node.parent;
|
|
938
|
+
if (node.kind !== 212 /* SyntaxKind.ObjectLiteralExpression */ ||
|
|
939
|
+
property.kind !== 304 /* SyntaxKind.PropertyAssignment */ ||
|
|
940
|
+
getInitializer(property) !== node)
|
|
941
|
+
return false;
|
|
942
|
+
const name = getName(property);
|
|
943
|
+
if ((name.kind !== 79 /* SyntaxKind.Identifier */ && !isStringLiteralLike(name)) || getText(name) !== 'with')
|
|
944
|
+
return false;
|
|
945
|
+
const options = property.parent;
|
|
946
|
+
if (options.kind !== 212 /* SyntaxKind.ObjectLiteralExpression */)
|
|
947
|
+
return false;
|
|
948
|
+
let importCall = options;
|
|
949
|
+
while (importCall !== undefined && !isImportCall(importCall))
|
|
950
|
+
importCall = importCall.parent;
|
|
951
|
+
if (importCall === undefined)
|
|
952
|
+
return false;
|
|
953
|
+
const args = importCall.arguments.nodes;
|
|
954
|
+
return args.length > 1 && skipParentheses(args[1]) === options;
|
|
955
|
+
}
|
|
909
956
|
/** Whether `node` is in an `as const` context, where literals keep their types. */
|
|
910
957
|
export function isConstContext(c, node) {
|
|
911
958
|
const parent = node.parent;
|
|
912
959
|
if (parent === undefined)
|
|
913
960
|
return false;
|
|
961
|
+
if (isInlineImportAttributes(node))
|
|
962
|
+
return true;
|
|
914
963
|
// Literals contextually typed by a `const` type parameter are in a const context.
|
|
915
964
|
if (isValidConstAssertionArgument(c, node) && isConstTypeVariable(c, getContextualType(c, node), 0))
|
|
916
965
|
return true;
|
|
917
966
|
switch (parent.kind) {
|
|
918
|
-
case
|
|
919
|
-
case
|
|
967
|
+
case 236 /* SyntaxKind.AsExpression */:
|
|
968
|
+
case 218 /* SyntaxKind.TypeAssertionExpression */:
|
|
920
969
|
return isConstTypeReference(getType(parent));
|
|
921
970
|
// As in tsgo, a const context does not reach through `satisfies` or into the branches of a
|
|
922
971
|
// conditional expression: those are in one only when their own contextual type is a `const`
|
|
923
972
|
// type parameter (above).
|
|
924
|
-
case
|
|
925
|
-
case
|
|
926
|
-
case
|
|
973
|
+
case 219 /* SyntaxKind.ParenthesizedExpression */:
|
|
974
|
+
case 211 /* SyntaxKind.ArrayLiteralExpression */:
|
|
975
|
+
case 232 /* SyntaxKind.SpreadElement */:
|
|
927
976
|
return isConstContext(c, parent);
|
|
928
|
-
case
|
|
929
|
-
case
|
|
977
|
+
case 304 /* SyntaxKind.PropertyAssignment */:
|
|
978
|
+
case 305 /* SyntaxKind.ShorthandPropertyAssignment */:
|
|
930
979
|
return isConstContext(c, parent.parent);
|
|
931
|
-
case
|
|
980
|
+
case 241 /* SyntaxKind.TemplateSpan */:
|
|
932
981
|
return isConstContext(c, parent.parent);
|
|
933
982
|
}
|
|
934
983
|
return false;
|
|
@@ -942,21 +991,21 @@ function isValidConstAssertionArgument(c, node) {
|
|
|
942
991
|
case 9 /* SyntaxKind.BigIntLiteral */:
|
|
943
992
|
case 111 /* SyntaxKind.TrueKeyword */:
|
|
944
993
|
case 96 /* SyntaxKind.FalseKeyword */:
|
|
945
|
-
case
|
|
946
|
-
case
|
|
947
|
-
case
|
|
994
|
+
case 211 /* SyntaxKind.ArrayLiteralExpression */:
|
|
995
|
+
case 212 /* SyntaxKind.ObjectLiteralExpression */:
|
|
996
|
+
case 230 /* SyntaxKind.TemplateExpression */:
|
|
948
997
|
return true;
|
|
949
|
-
case
|
|
998
|
+
case 219 /* SyntaxKind.ParenthesizedExpression */:
|
|
950
999
|
return isValidConstAssertionArgument(c, getExpression(node));
|
|
951
|
-
case
|
|
1000
|
+
case 226 /* SyntaxKind.PrefixUnaryExpression */: {
|
|
952
1001
|
const unary = node;
|
|
953
1002
|
const kind = unary.operand.kind;
|
|
954
1003
|
return ((unary.operator === 40 /* SyntaxKind.MinusToken */ &&
|
|
955
1004
|
(kind === 8 /* SyntaxKind.NumericLiteral */ || kind === 9 /* SyntaxKind.BigIntLiteral */)) ||
|
|
956
1005
|
(unary.operator === 39 /* SyntaxKind.PlusToken */ && kind === 8 /* SyntaxKind.NumericLiteral */));
|
|
957
1006
|
}
|
|
958
|
-
case
|
|
959
|
-
case
|
|
1007
|
+
case 213 /* SyntaxKind.PropertyAccessExpression */:
|
|
1008
|
+
case 214 /* SyntaxKind.ElementAccessExpression */: {
|
|
960
1009
|
const expr = skipParentheses(getExpression(node));
|
|
961
1010
|
const symbol = isEntityNameExpression(expr, false)
|
|
962
1011
|
? resolveEntityName(c, expr, 111551 /* SymbolFlags.Value */, true, false, undefined)
|
|
@@ -967,7 +1016,7 @@ function isValidConstAssertionArgument(c, node) {
|
|
|
967
1016
|
return false;
|
|
968
1017
|
}
|
|
969
1018
|
export function isConstTypeReference(node) {
|
|
970
|
-
if (node.kind !==
|
|
1019
|
+
if (node.kind !== 185 /* SyntaxKind.TypeReference */)
|
|
971
1020
|
return false;
|
|
972
1021
|
const ref = node;
|
|
973
1022
|
return (ref.typeName.kind === 79 /* SyntaxKind.Identifier */ && getText(ref.typeName) === 'const' && ref.typeArguments === undefined);
|
|
@@ -1021,11 +1070,11 @@ export function checkNonNullTypeEx(c, t, node, isCallee) {
|
|
|
1021
1070
|
if (isEntityNameExpression(node, false)) {
|
|
1022
1071
|
const nodeText = entityNameToString(node);
|
|
1023
1072
|
if (nodeText.length < 100) {
|
|
1024
|
-
c.error(node,
|
|
1073
|
+
c.error(node, 1882 /* Diagnostics.X_0_is_of_type_unknown */, nodeText);
|
|
1025
1074
|
return c.errorType;
|
|
1026
1075
|
}
|
|
1027
1076
|
}
|
|
1028
|
-
c.error(node,
|
|
1077
|
+
c.error(node, 731 /* Diagnostics.Object_is_of_type_unknown */);
|
|
1029
1078
|
return c.errorType;
|
|
1030
1079
|
}
|
|
1031
1080
|
const facts = getTypeFacts(c, t, 50331648 /* TypeFacts.IsUndefinedOrNull */);
|
|
@@ -1042,33 +1091,33 @@ export function checkNonNullTypeEx(c, t, node, isCallee) {
|
|
|
1042
1091
|
function reportCannotInvokePossiblyNullOrUndefinedError(c, node, facts) {
|
|
1043
1092
|
c.error(node, (facts & 16777216 /* TypeFacts.IsUndefined */) !== 0
|
|
1044
1093
|
? (facts & 33554432 /* TypeFacts.IsNull */) !== 0
|
|
1045
|
-
?
|
|
1046
|
-
:
|
|
1047
|
-
:
|
|
1094
|
+
? 862 /* Diagnostics.Cannot_invoke_an_object_which_is_possibly_null_or_undefined */
|
|
1095
|
+
: 861 /* Diagnostics.Cannot_invoke_an_object_which_is_possibly_undefined */
|
|
1096
|
+
: 860 /* Diagnostics.Cannot_invoke_an_object_which_is_possibly_null */);
|
|
1048
1097
|
}
|
|
1049
1098
|
function reportObjectPossiblyNullOrUndefinedError(c, node, facts) {
|
|
1050
1099
|
if (node.kind === 105 /* SyntaxKind.NullKeyword */) {
|
|
1051
|
-
c.error(node,
|
|
1100
|
+
c.error(node, 1886 /* Diagnostics.The_value_0_cannot_be_used_here */, 'null');
|
|
1052
1101
|
return;
|
|
1053
1102
|
}
|
|
1054
1103
|
const nodeText = isEntityNameExpression(node, false) ? entityNameToString(node) : '';
|
|
1055
1104
|
if (nodeText !== '' && nodeText.length < 100) {
|
|
1056
1105
|
if (node.kind === 79 /* SyntaxKind.Identifier */ && nodeText === 'undefined') {
|
|
1057
|
-
c.error(node,
|
|
1106
|
+
c.error(node, 1886 /* Diagnostics.The_value_0_cannot_be_used_here */, 'undefined');
|
|
1058
1107
|
return;
|
|
1059
1108
|
}
|
|
1060
1109
|
c.error(node, (facts & 16777216 /* TypeFacts.IsUndefined */) !== 0
|
|
1061
1110
|
? (facts & 33554432 /* TypeFacts.IsNull */) !== 0
|
|
1062
|
-
?
|
|
1063
|
-
:
|
|
1064
|
-
:
|
|
1111
|
+
? 1885 /* Diagnostics.X_0_is_possibly_null_or_undefined */
|
|
1112
|
+
: 1884 /* Diagnostics.X_0_is_possibly_undefined */
|
|
1113
|
+
: 1883 /* Diagnostics.X_0_is_possibly_null */, nodeText);
|
|
1065
1114
|
}
|
|
1066
1115
|
else {
|
|
1067
1116
|
c.error(node, (facts & 16777216 /* TypeFacts.IsUndefined */) !== 0
|
|
1068
1117
|
? (facts & 33554432 /* TypeFacts.IsNull */) !== 0
|
|
1069
|
-
?
|
|
1070
|
-
:
|
|
1071
|
-
:
|
|
1118
|
+
? 698 /* Diagnostics.Object_is_possibly_null_or_undefined */
|
|
1119
|
+
: 697 /* Diagnostics.Object_is_possibly_undefined */
|
|
1120
|
+
: 696 /* Diagnostics.Object_is_possibly_null */);
|
|
1072
1121
|
}
|
|
1073
1122
|
}
|
|
1074
1123
|
/** `checkNonNullType`, also reporting a `void` type as possibly undefined. */
|
|
@@ -1079,15 +1128,15 @@ export function checkNonNullNonVoidType(c, t, node) {
|
|
|
1079
1128
|
if (isEntityNameExpression(node, false)) {
|
|
1080
1129
|
const nodeText = entityNameToString(node);
|
|
1081
1130
|
if (node.kind === 79 /* SyntaxKind.Identifier */ && nodeText === 'undefined') {
|
|
1082
|
-
c.error(node,
|
|
1131
|
+
c.error(node, 1886 /* Diagnostics.The_value_0_cannot_be_used_here */, nodeText);
|
|
1083
1132
|
return nonNullType;
|
|
1084
1133
|
}
|
|
1085
1134
|
if (nodeText.length < 100) {
|
|
1086
|
-
c.error(node,
|
|
1135
|
+
c.error(node, 1884 /* Diagnostics.X_0_is_possibly_undefined */, nodeText);
|
|
1087
1136
|
return nonNullType;
|
|
1088
1137
|
}
|
|
1089
1138
|
}
|
|
1090
|
-
c.error(node,
|
|
1139
|
+
c.error(node, 697 /* Diagnostics.Object_is_possibly_undefined */);
|
|
1091
1140
|
return nonNullType;
|
|
1092
1141
|
}
|
|
1093
1142
|
export function entityNameToString(node) {
|
|
@@ -1096,13 +1145,13 @@ export function entityNameToString(node) {
|
|
|
1096
1145
|
return getText(node);
|
|
1097
1146
|
case 109 /* SyntaxKind.ThisKeyword */:
|
|
1098
1147
|
return 'this';
|
|
1099
|
-
case
|
|
1148
|
+
case 213 /* SyntaxKind.PropertyAccessExpression */: {
|
|
1100
1149
|
const access = node;
|
|
1101
1150
|
return entityNameToString(access.expression) + '.' + entityNameToString(access.name);
|
|
1102
1151
|
}
|
|
1103
|
-
case
|
|
1152
|
+
case 168 /* SyntaxKind.QualifiedName */: {
|
|
1104
1153
|
const q = node;
|
|
1105
|
-
return entityNameToString(q.left) + '.' + q.right
|
|
1154
|
+
return entityNameToString(q.left) + '.' + getText(q.right);
|
|
1106
1155
|
}
|
|
1107
1156
|
}
|
|
1108
1157
|
return getText(node);
|
|
@@ -1137,41 +1186,37 @@ export function getFlowTypeOfAccessExpression(c, node, prop, propTypeIn, errorNo
|
|
|
1137
1186
|
if (propType === c.autoType)
|
|
1138
1187
|
return getFlowTypeOfAutoTypedProperty(c, node, prop);
|
|
1139
1188
|
propType = getNarrowableTypeForReference(c, propType, node, checkMode);
|
|
1140
|
-
// `this.x` in the constructor of x's class starts out uninitialized under strictPropertyInitialization
|
|
1189
|
+
// `this.x` in the constructor of x's class starts out uninitialized under strictPropertyInitialization,
|
|
1190
|
+
// and a JavaScript `this.x = …` declaration is unassigned before it in its own function.
|
|
1141
1191
|
let assumeUninitialized = false;
|
|
1142
|
-
|
|
1143
|
-
if (c.strictNullChecks &&
|
|
1144
|
-
c.strictPropertyInitialization &&
|
|
1145
|
-
expression !== undefined &&
|
|
1146
|
-
expression.kind === 109 /* SyntaxKind.ThisKeyword */ &&
|
|
1147
|
-
prop !== undefined) {
|
|
1192
|
+
if (c.strictNullChecks && prop !== undefined) {
|
|
1148
1193
|
const declaration = prop.valueDeclaration;
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
flowContainer
|
|
1153
|
-
|
|
1154
|
-
|
|
1194
|
+
const expression = getExpression(node);
|
|
1195
|
+
if (c.strictPropertyInitialization && expression !== undefined && expression.kind === 109 /* SyntaxKind.ThisKeyword */) {
|
|
1196
|
+
if (declaration !== undefined && isPropertyWithoutInitializer(declaration) && !isStatic(declaration)) {
|
|
1197
|
+
const flowContainer = getControlFlowContainer(node);
|
|
1198
|
+
assumeUninitialized =
|
|
1199
|
+
flowContainer.kind === 178 /* SyntaxKind.Constructor */ &&
|
|
1200
|
+
flowContainer.parent === declaration.parent &&
|
|
1201
|
+
(declaration.flags & 8388608 /* NodeFlags.Ambient */) === 0;
|
|
1202
|
+
}
|
|
1155
1203
|
}
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
declaration instanceof BinaryExpression &&
|
|
1162
|
-
declaration.left.kind === 212 /* SyntaxKind.PropertyAccessExpression */ &&
|
|
1163
|
-
getControlFlowContainer(node) === getControlFlowContainer(declaration);
|
|
1204
|
+
else
|
|
1205
|
+
assumeUninitialized =
|
|
1206
|
+
declaration instanceof BinaryExpression &&
|
|
1207
|
+
declaration.left.kind === 213 /* SyntaxKind.PropertyAccessExpression */ &&
|
|
1208
|
+
getControlFlowContainer(node) === getControlFlowContainer(declaration);
|
|
1164
1209
|
}
|
|
1165
1210
|
const initialType = assumeUninitialized ? getOptionalType(c, propType, false) : propType;
|
|
1166
1211
|
const flowType = getFlowTypeOfReference(c, node, propType, initialType, undefined);
|
|
1167
1212
|
if (assumeUninitialized && !containsUndefinedType(propType) && containsUndefinedType(flowType)) {
|
|
1168
|
-
c.error(errorNode,
|
|
1213
|
+
c.error(errorNode, 726 /* Diagnostics.Property_0_is_used_before_being_assigned */, symbolToString(c, prop));
|
|
1169
1214
|
return propType;
|
|
1170
1215
|
}
|
|
1171
1216
|
return assignmentKind !== 0 /* AssignmentKind.None */ ? getBaseTypeOfLiteralType(c, flowType) : flowType;
|
|
1172
1217
|
}
|
|
1173
1218
|
function isPropertyWithoutInitializer(node) {
|
|
1174
|
-
return (node.kind ===
|
|
1219
|
+
return (node.kind === 174 /* SyntaxKind.PropertyDeclaration */ &&
|
|
1175
1220
|
!hasSyntacticModifier(node, 64 /* ModifierFlags.Abstract */) &&
|
|
1176
1221
|
node.postfixToken === undefined &&
|
|
1177
1222
|
getInitializer(node) === undefined);
|
|
@@ -1194,7 +1239,7 @@ function checkElementAccessExpression(c, node, _checkMode) {
|
|
|
1194
1239
|
const isAssignment = assignmentKind !== 0 /* AssignmentKind.None */;
|
|
1195
1240
|
const objectType = isAssignment || isMethodAccessForCall(node) ? getWidenedType(c, exprType) : exprType;
|
|
1196
1241
|
if (isConstEnumObjectTypeLocal(objectType) && !isStringLiteralLike(indexExpression)) {
|
|
1197
|
-
c.error(indexExpression,
|
|
1242
|
+
c.error(indexExpression, 647 /* Diagnostics.A_const_enum_member_can_only_be_accessed_using_a_string_literal */);
|
|
1198
1243
|
return c.errorType;
|
|
1199
1244
|
}
|
|
1200
1245
|
const effectiveIndexType = isForInVariableForNumericPropertyNames(c, indexExpression) ? c.numberType : indexType;
|
|
@@ -1214,18 +1259,14 @@ export function checkIndexedAccessIndexType(c, t, accessNode) {
|
|
|
1214
1259
|
return t;
|
|
1215
1260
|
const objectType = t.objectType;
|
|
1216
1261
|
const indexType = t.indexType;
|
|
1217
|
-
// Remapping mapped types don't defer their index types.
|
|
1218
|
-
const objectIndexType = isGenericMappedType(c, objectType) &&
|
|
1219
|
-
getMappedTypeNameTypeKind(c, objectType) === 2 /* MappedTypeNameTypeKind.Remapping */
|
|
1220
|
-
? getIndexForMappedType(c, objectType, 0 /* IndexFlags.None */)
|
|
1221
|
-
: getIndexTypeEx(c, objectType, 0 /* IndexFlags.None */);
|
|
1222
1262
|
const hasNumberIndexInfo = getIndexInfoOfType(c, objectType, c.numberType) !== undefined;
|
|
1223
|
-
if (everyType(indexType, (u) => isTypeAssignableTo(c, u,
|
|
1224
|
-
|
|
1263
|
+
if (everyType(indexType, (u) => isTypeAssignableTo(c, u, getIndexTypeEx(c, objectType, 0 /* IndexFlags.None */)) ||
|
|
1264
|
+
(hasNumberIndexInfo && isApplicableIndexType(c, u, c.numberType)))) {
|
|
1265
|
+
if (accessNode.kind === 214 /* SyntaxKind.ElementAccessExpression */ &&
|
|
1225
1266
|
isAssignmentTarget(accessNode) &&
|
|
1226
1267
|
(objectType.objectFlags & 32 /* ObjectFlags.Mapped */) !== 0 &&
|
|
1227
1268
|
(getMappedTypeModifiers(objectType) & 1 /* MappedTypeModifiers.IncludeReadonly */) !== 0)
|
|
1228
|
-
c.error(accessNode,
|
|
1269
|
+
c.error(accessNode, 705 /* Diagnostics.Index_signature_in_type_0_only_permits_reading */, typeToString(c, objectType));
|
|
1229
1270
|
return t;
|
|
1230
1271
|
}
|
|
1231
1272
|
if (isGenericObjectType(c, objectType)) {
|
|
@@ -1236,12 +1277,12 @@ export function checkIndexedAccessIndexType(c, t, accessNode) {
|
|
|
1236
1277
|
(getDeclarationModifierFlagsFromSymbol(c, propertySymbol, false) &
|
|
1237
1278
|
6 /* ModifierFlags.NonPublicAccessibilityModifier */) !==
|
|
1238
1279
|
0) {
|
|
1239
|
-
c.error(accessNode,
|
|
1280
|
+
c.error(accessNode, 1098 /* Diagnostics.Private_or_protected_member_0_cannot_be_accessed_on_a_type_parameter */, propertyName);
|
|
1240
1281
|
return c.errorType;
|
|
1241
1282
|
}
|
|
1242
1283
|
}
|
|
1243
1284
|
}
|
|
1244
|
-
c.error(accessNode,
|
|
1285
|
+
c.error(accessNode, 700 /* Diagnostics.Type_0_cannot_be_used_to_index_type_1 */, typeToString(c, indexType), typeToString(c, objectType));
|
|
1245
1286
|
return c.errorType;
|
|
1246
1287
|
}
|
|
1247
1288
|
function getConstituentProperty(c, objectType, propertyName) {
|
|
@@ -1275,7 +1316,7 @@ function isForInVariableForNumericPropertyNames(c, expr) {
|
|
|
1275
1316
|
let child = expr;
|
|
1276
1317
|
let node = expr.parent;
|
|
1277
1318
|
while (node !== undefined) {
|
|
1278
|
-
if (node.kind ===
|
|
1319
|
+
if (node.kind === 251 /* SyntaxKind.ForInStatement */) {
|
|
1279
1320
|
const statement = node;
|
|
1280
1321
|
if (child === statement.statement &&
|
|
1281
1322
|
getForInVariableSymbol(c, statement) === symbol &&
|
|
@@ -1289,7 +1330,7 @@ function isForInVariableForNumericPropertyNames(c, expr) {
|
|
|
1289
1330
|
}
|
|
1290
1331
|
function getForInVariableSymbol(c, node) {
|
|
1291
1332
|
const initializer = node.initializer;
|
|
1292
|
-
if (initializer.kind ===
|
|
1333
|
+
if (initializer.kind === 263 /* SyntaxKind.VariableDeclarationList */) {
|
|
1293
1334
|
const declarations = initializer.declarations.nodes;
|
|
1294
1335
|
return declarations.length > 0 ? getSymbolOfDeclaration(c, declarations[0]) : undefined;
|
|
1295
1336
|
}
|
|
@@ -1300,21 +1341,26 @@ function hasNumericPropertyNames(c, t) {
|
|
|
1300
1341
|
}
|
|
1301
1342
|
// ---- Assertions
|
|
1302
1343
|
function checkAssertion(c, node, checkMode) {
|
|
1344
|
+
if (node.kind === 218 /* SyntaxKind.TypeAssertionExpression */) {
|
|
1345
|
+
const file = getSourceFileOfNode(node);
|
|
1346
|
+
if (fileExtensionIsOneOf(file.fileName, ['.mts', '.cts']))
|
|
1347
|
+
grammarErrorOnNode(c, node, 1749 /* Diagnostics.This_syntax_is_reserved_in_files_with_the_mts_or_cts_extension_Use_an_as_expression_instead */);
|
|
1348
|
+
}
|
|
1303
1349
|
// `<T>expr`, over `<T>`.
|
|
1304
|
-
if (node.kind ===
|
|
1350
|
+
if (node.kind === 218 /* SyntaxKind.TypeAssertionExpression */ && shouldCheckErasableSyntax(c, node)) {
|
|
1305
1351
|
const file = getSourceFileOfNode(node);
|
|
1306
1352
|
c.addDiagnostic(new Diagnostic(file.diagnosticFile(), skipTrivia(file.text, node.pos), getExpression(node).pos, 243 /* Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled */, []));
|
|
1307
1353
|
}
|
|
1354
|
+
const exprType = checkExpressionEx(c, getExpression(node), checkMode);
|
|
1355
|
+
// The type node is checked in every case, including the `const` of `x as const`.
|
|
1356
|
+
checkTypeNodeIfPresent(c, getType(node));
|
|
1308
1357
|
if (isConstTypeReference(getType(node))) {
|
|
1309
|
-
const exprType = checkExpressionEx(c, getExpression(node), checkMode);
|
|
1310
1358
|
if (!isValidConstAssertionArgument(c, getExpression(node)))
|
|
1311
1359
|
c.error(getExpression(node), 289 /* Diagnostics.A_const_assertion_can_only_be_applied_to_references_to_enum_members_or_string_number_boolean_array_or_object_literals */);
|
|
1312
1360
|
return getRegularTypeOfLiteralType(c, exprType);
|
|
1313
1361
|
}
|
|
1314
|
-
const exprType = checkExpressionEx(c, getExpression(node), checkMode);
|
|
1315
1362
|
// The operand is compared with the asserted type once, after the last check of the operand.
|
|
1316
1363
|
c.nodeLinks(node).assertionExpressionType = exprType;
|
|
1317
|
-
checkTypeNodeIfPresent(c, getType(node));
|
|
1318
1364
|
checkNodeDeferred(c, node);
|
|
1319
1365
|
return getTypeFromTypeNode(c, getType(node));
|
|
1320
1366
|
}
|
|
@@ -1332,7 +1378,7 @@ function checkAssertionCompatibility(c, node, rawExprType, targetType) {
|
|
|
1332
1378
|
if (isErrorType(c, targetType))
|
|
1333
1379
|
return;
|
|
1334
1380
|
if (!isTypeComparableTo(c, targetType, getWidenedType(c, exprType)))
|
|
1335
|
-
checkTypeComparableTo(c, exprType, targetType, node,
|
|
1381
|
+
checkTypeComparableTo(c, exprType, targetType, node, 535 /* Diagnostics.Conversion_of_type_0_to_type_1_may_be_a_mistake_because_neither_type_sufficiently_overlaps_with_the_other_If_this_was_intentional_convert_the_expression_to_unknown_first */);
|
|
1336
1382
|
}
|
|
1337
1383
|
function checkSatisfiesExpression(c, node, checkMode) {
|
|
1338
1384
|
const expr = getExpression(node);
|