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
|
@@ -8,6 +8,7 @@ import { getAliasForTypeNode, getTypeArgumentsOfDeferredReference } from './chec
|
|
|
8
8
|
import { TypeSystemPropertyName, popTypeResolution, pushTypeResolution } from './checker-symbols.js';
|
|
9
9
|
import { isGenericIndexType } from './checker-type-operators.js';
|
|
10
10
|
import { compareCodePoints } from './diagnostics.js';
|
|
11
|
+
import { utf8Length } from './character-codes.js';
|
|
11
12
|
import { Diagnostics } from './diagnostic-messages.js';
|
|
12
13
|
import type { Checker } from './checker.js';
|
|
13
14
|
import {
|
|
@@ -79,6 +80,7 @@ import { addOptionality } from './checker-symbol-types.js';
|
|
|
79
80
|
import { getSourceFileOfNode } from './binder-utilities.js';
|
|
80
81
|
import { isPartOfTypeNode } from './transformers/alias-references.js';
|
|
81
82
|
import { CheckFlags, declarationCount, getSymbolId, type Symbol, SymbolFlags, type SymbolTable } from './symbol.js';
|
|
83
|
+
import { comparePseudoBigInts } from './pseudo-bigint.js';
|
|
82
84
|
|
|
83
85
|
export const enum UnionReduction {
|
|
84
86
|
None = 0,
|
|
@@ -500,6 +502,9 @@ export function compareNodes(c: Checker, n1: Node | undefined, n2: Node | undefi
|
|
|
500
502
|
if (n1 === n2) return 0;
|
|
501
503
|
if (n1 === undefined) return 1;
|
|
502
504
|
if (n2 === undefined) return -1;
|
|
505
|
+
// Siblings are in one file: most compared declarations are members of one declaration.
|
|
506
|
+
const parent = n1.parent;
|
|
507
|
+
if (parent !== undefined && parent === n2.parent) return n1.pos - n2.pos;
|
|
503
508
|
const s1 = sourceFileOf(n1);
|
|
504
509
|
const s2 = sourceFileOf(n2);
|
|
505
510
|
if (s1 !== s2) return (c.fileIndex.get(s1) ?? 0) - (c.fileIndex.get(s2) ?? 0);
|
|
@@ -562,11 +567,12 @@ function getTypeNameSymbol(t: Type): Symbol | undefined {
|
|
|
562
567
|
function compareTypeNames(c: Checker, t1: Type, t2: Type): number {
|
|
563
568
|
const s1 = getTypeNameSymbol(t1);
|
|
564
569
|
const s2 = getTypeNameSymbol(t2);
|
|
565
|
-
if (s1 === s2)
|
|
566
|
-
return t1.alias !== undefined ? compareTypeLists(c, t1.alias.typeArguments, t2.alias!.typeArguments) : 0;
|
|
570
|
+
if (s1 === s2) return compareTypeLists(c, t1.alias?.typeArguments, t2.alias?.typeArguments);
|
|
567
571
|
if (s1 === undefined) return 1;
|
|
568
572
|
if (s2 === undefined) return -1;
|
|
569
|
-
|
|
573
|
+
const r = compareCodePoints(s1.name, s2.name);
|
|
574
|
+
// Distinct declarations with the same name stay together before alias arguments or structure decide.
|
|
575
|
+
return r !== 0 ? r : compareSymbols(c, s1, s2);
|
|
570
576
|
}
|
|
571
577
|
|
|
572
578
|
function compareTypeLists(c: Checker, s1: readonly Type[] | undefined, s2: readonly Type[] | undefined): number {
|
|
@@ -800,8 +806,17 @@ export function compareTypes(c: Checker, t1: Type, t2: Type): number {
|
|
|
800
806
|
if ((flags & TypeFlags.Singleton) !== 0) {
|
|
801
807
|
// Only distinguished by ids.
|
|
802
808
|
} else if ((flags & TypeFlags.Object) !== 0) {
|
|
803
|
-
|
|
804
|
-
|
|
809
|
+
if ((t1.objectFlags & t2.objectFlags & ObjectFlags.InstantiationExpressionType) !== 0) {
|
|
810
|
+
// Instantiation expression types are ordered by their source declaration, since one expression
|
|
811
|
+
// can produce a type for each union constituent, then by the expression, without symbol ids.
|
|
812
|
+
r = compareNodes(c, t1.symbol?.declaration, t2.symbol?.declaration);
|
|
813
|
+
if (r !== 0) return r;
|
|
814
|
+
r = compareNodes(c, (t1 as InstantiationExpressionType).node, (t2 as InstantiationExpressionType).node);
|
|
815
|
+
if (r !== 0) return r;
|
|
816
|
+
} else {
|
|
817
|
+
r = compareSymbols(c, t1.symbol, t2.symbol);
|
|
818
|
+
if (r !== 0) return r;
|
|
819
|
+
}
|
|
805
820
|
if ((t1.objectFlags & ObjectFlags.Reference) !== 0 && (t2.objectFlags & ObjectFlags.Reference) !== 0) {
|
|
806
821
|
const r1 = t1 as TypeReference;
|
|
807
822
|
const r2 = t2 as TypeReference;
|
|
@@ -823,9 +838,28 @@ export function compareTypes(c: Checker, t1: Type, t2: Type): number {
|
|
|
823
838
|
} else if ((t1.objectFlags & ObjectFlags.Reference) !== 0) return -1;
|
|
824
839
|
else if ((t2.objectFlags & ObjectFlags.Reference) !== 0) return 1;
|
|
825
840
|
else {
|
|
841
|
+
// Unnamed non-reference object types are ordered by kind and instantiation data.
|
|
826
842
|
r = (t1.objectFlags & ObjectFlags.ObjectTypeKindMask) - (t2.objectFlags & ObjectFlags.ObjectTypeKindMask);
|
|
827
843
|
if (r !== 0) return r;
|
|
828
|
-
|
|
844
|
+
if ((t1.objectFlags & ObjectFlags.ReverseMapped) !== 0) {
|
|
845
|
+
const r1 = t1 as ReverseMappedType;
|
|
846
|
+
const r2 = t2 as ReverseMappedType;
|
|
847
|
+
r = compareTypes(c, r1.source!, r2.source!);
|
|
848
|
+
if (r !== 0) return r;
|
|
849
|
+
r = compareTypes(c, r1.mappedType!, r2.mappedType!);
|
|
850
|
+
if (r !== 0) return r;
|
|
851
|
+
r = compareTypes(c, r1.constraintType!, r2.constraintType!);
|
|
852
|
+
if (r !== 0) return r;
|
|
853
|
+
}
|
|
854
|
+
let m1 = (t1 as ObjectType).mapper;
|
|
855
|
+
let m2 = (t2 as ObjectType).mapper;
|
|
856
|
+
if ((t1.objectFlags & ObjectFlags.Mapped) !== 0) {
|
|
857
|
+
// instantiateAnonymousType prepends a mapping to a fresh type parameter; compare the
|
|
858
|
+
// instantiation itself rather than the identity of that parameter.
|
|
859
|
+
if (m1 instanceof CompositeTypeMapper) m1 = m1.m2;
|
|
860
|
+
if (m2 instanceof CompositeTypeMapper) m2 = m2.m2;
|
|
861
|
+
}
|
|
862
|
+
r = compareTypeMappers(c, m1, m2);
|
|
829
863
|
if (r !== 0) return r;
|
|
830
864
|
}
|
|
831
865
|
} else if ((flags & TypeFlags.Union) !== 0) {
|
|
@@ -852,6 +886,9 @@ export function compareTypes(c: Checker, t1: Type, t2: Type): number {
|
|
|
852
886
|
} else if ((flags & TypeFlags.NumberLiteral) !== 0) {
|
|
853
887
|
r = compareNumbers((t1 as LiteralType).numberValue, (t2 as LiteralType).numberValue);
|
|
854
888
|
if (r !== 0) return r;
|
|
889
|
+
} else if ((flags & TypeFlags.BigIntLiteral) !== 0) {
|
|
890
|
+
r = comparePseudoBigInts((t1 as LiteralType).stringValue, (t2 as LiteralType).stringValue);
|
|
891
|
+
if (r !== 0) return r;
|
|
855
892
|
} else if ((flags & TypeFlags.BooleanLiteral) !== 0) {
|
|
856
893
|
const b1 = (t1 as LiteralType).stringValue === 'true';
|
|
857
894
|
const b2 = (t2 as LiteralType).stringValue === 'true';
|
|
@@ -1108,7 +1145,30 @@ export function filterType(c: Checker, type: Type, f: (t: Type) => boolean): Typ
|
|
|
1108
1145
|
}
|
|
1109
1146
|
|
|
1110
1147
|
export function removeType(c: Checker, type: Type, target: Type): Type {
|
|
1111
|
-
|
|
1148
|
+
if ((type.flags & TypeFlags.Union) === 0) return type === target ? c.neverType : type;
|
|
1149
|
+
const union = type as UnionType;
|
|
1150
|
+
const origin = union.origin;
|
|
1151
|
+
// An origin that lists the target keeps the rest of its constituents.
|
|
1152
|
+
if (
|
|
1153
|
+
origin !== undefined &&
|
|
1154
|
+
(origin.flags & TypeFlags.Union) !== 0 &&
|
|
1155
|
+
containsType(c, (origin as UnionType).types, target)
|
|
1156
|
+
)
|
|
1157
|
+
return filterType(c, type, (t) => t !== target);
|
|
1158
|
+
const types = union.types;
|
|
1159
|
+
const index =
|
|
1160
|
+
types.length < linearTypeSearchLimit ? indexOfType(types, target, 0) : binarySearchTypes(c, types, target);
|
|
1161
|
+
if (index < 0) return type;
|
|
1162
|
+
if (types.length === 2) return types[1 - index]!;
|
|
1163
|
+
const filtered: Type[] = [];
|
|
1164
|
+
for (let i = 0; i < types.length; i++) if (i !== index) filtered.push(types[i]!);
|
|
1165
|
+
return getUnionTypeFromSortedList(
|
|
1166
|
+
c,
|
|
1167
|
+
filtered,
|
|
1168
|
+
union.objectFlags & (ObjectFlags.PrimitiveUnion | ObjectFlags.ContainsIntersections),
|
|
1169
|
+
undefined,
|
|
1170
|
+
undefined,
|
|
1171
|
+
);
|
|
1112
1172
|
}
|
|
1113
1173
|
|
|
1114
1174
|
export function countTypes(type: Type): number {
|
|
@@ -1136,40 +1196,79 @@ export function getUnionTypeEx(
|
|
|
1136
1196
|
): Type {
|
|
1137
1197
|
if (types.length === 0) return c.neverType;
|
|
1138
1198
|
if (types.length === 1) return types[0]!;
|
|
1139
|
-
//
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1199
|
+
// Unioning two types is the common case, both a union with some other type, like `undefined`, and
|
|
1200
|
+
// two constituents of a list, and the same pairs recur. The union is a function of the two types,
|
|
1201
|
+
// the reduction and the alias, so the result is cached by the pair. A union that exceeded the
|
|
1202
|
+
// complexity limit was reported at the expression that needed it and comes back as the error
|
|
1203
|
+
// type: caching that would silence the report at the next expression with the same input list, so
|
|
1204
|
+
// an error result is not cached.
|
|
1205
|
+
if (types.length === 2 && origin === undefined) {
|
|
1206
|
+
const t0 = types[0]!;
|
|
1207
|
+
const t1 = types[1]!;
|
|
1208
|
+
let id1 = t0.id;
|
|
1209
|
+
let id2 = t1.id;
|
|
1147
1210
|
if (id1 > id2) {
|
|
1148
1211
|
const t = id1;
|
|
1149
1212
|
id1 = id2;
|
|
1150
1213
|
id2 = t;
|
|
1151
1214
|
}
|
|
1152
|
-
// Without an alias, both ids and the reduction pack into one
|
|
1153
|
-
|
|
1215
|
+
// Without an alias or a constrained intersection, both ids and the reduction pack into one
|
|
1216
|
+
// exact number. A constrained intersection's reduction resolves a type variable's constraint
|
|
1217
|
+
// (`addTypeToUnion`), so those pairs take the general path.
|
|
1218
|
+
if (
|
|
1219
|
+
alias === undefined &&
|
|
1220
|
+
id2 < UnionPairIdLimit &&
|
|
1221
|
+
!isConstrainedIntersection(t0) &&
|
|
1222
|
+
!isConstrainedIntersection(t1)
|
|
1223
|
+
) {
|
|
1154
1224
|
const id = (id1 * UnionPairIdLimit + id2) * 4 + unionReduction;
|
|
1155
1225
|
let result = c.unionOfUnionTypesById.get(id);
|
|
1156
1226
|
if (result === undefined) {
|
|
1157
1227
|
result = getUnionTypeWorker(c, types, unionReduction, alias, undefined);
|
|
1158
|
-
c.unionOfUnionTypesById.set(id, result);
|
|
1228
|
+
if (result !== c.errorType) c.unionOfUnionTypesById.set(id, result);
|
|
1229
|
+
}
|
|
1230
|
+
return result;
|
|
1231
|
+
}
|
|
1232
|
+
if ((t0.flags & TypeFlags.Union) !== 0 || (t1.flags & TypeFlags.Union) !== 0) {
|
|
1233
|
+
const key = id1 + ',' + id2 + ',' + unionReduction + aliasKey(alias);
|
|
1234
|
+
let result = c.unionOfUnionTypes.get(key);
|
|
1235
|
+
if (result === undefined) {
|
|
1236
|
+
result = getUnionTypeWorker(c, types, unionReduction, alias, undefined);
|
|
1237
|
+
if (result !== c.errorType) c.unionOfUnionTypes.set(key, result);
|
|
1159
1238
|
}
|
|
1160
1239
|
return result;
|
|
1161
1240
|
}
|
|
1162
|
-
|
|
1163
|
-
|
|
1241
|
+
}
|
|
1242
|
+
// Longer lists recur too, from nested unions and from constituents mapped in the same order.
|
|
1243
|
+
// Normalizing a list costs a sort of its constituents and the reductions, and the union is a
|
|
1244
|
+
// function of the list as given, the reduction and the alias, so the result is cached by the list.
|
|
1245
|
+
if (origin === undefined) {
|
|
1246
|
+
const hash = typeListHash(types, alias, unionReduction);
|
|
1247
|
+
let result = c.unionTypesByInputList.get(hash, types, alias, unionReduction);
|
|
1164
1248
|
if (result === undefined) {
|
|
1165
1249
|
result = getUnionTypeWorker(c, types, unionReduction, alias, undefined);
|
|
1166
|
-
c.
|
|
1250
|
+
if (result !== c.errorType && !hasConstrainedIntersection(types))
|
|
1251
|
+
c.unionTypesByInputList.set(hash, types.slice(), alias, unionReduction, result);
|
|
1167
1252
|
}
|
|
1168
1253
|
return result;
|
|
1169
1254
|
}
|
|
1170
1255
|
return getUnionTypeWorker(c, types, unionReduction, alias, origin);
|
|
1171
1256
|
}
|
|
1172
1257
|
|
|
1258
|
+
/** An intersection that `addTypeToUnion` reduces by resolving a type variable's constraint. */
|
|
1259
|
+
function isConstrainedIntersection(t: Type): boolean {
|
|
1260
|
+
return (t.flags & TypeFlags.Intersection) !== 0 && (t.objectFlags & ObjectFlags.IsConstrainedTypeVariable) !== 0;
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
/** Whether `addTypesToUnion` would set `IncludesConstrainedTypeVariable` for `types`. */
|
|
1264
|
+
function hasConstrainedIntersection(types: readonly Type[]): boolean {
|
|
1265
|
+
for (const t of types) {
|
|
1266
|
+
if (isConstrainedIntersection(t)) return true;
|
|
1267
|
+
if ((t.flags & TypeFlags.Union) !== 0 && hasConstrainedIntersection((t as UnionType).types)) return true;
|
|
1268
|
+
}
|
|
1269
|
+
return false;
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1173
1272
|
class TypeSet {
|
|
1174
1273
|
types: Type[] = [];
|
|
1175
1274
|
includes = 0;
|
|
@@ -1973,21 +2072,26 @@ function intersectUnionsOfPrimitiveTypes(c: Checker, types: Type[]): boolean {
|
|
|
1973
2072
|
}
|
|
1974
2073
|
|
|
1975
2074
|
function eachUnionContains(c: Checker, unionTypes: Type[], t: Type): boolean {
|
|
1976
|
-
for (const type of unionTypes)
|
|
1977
|
-
const u = type as UnionType;
|
|
1978
|
-
if (unionContainsType(c, u, t)) continue;
|
|
1979
|
-
if (t === c.missingType) return unionContainsType(c, u, c.undefinedType);
|
|
1980
|
-
if (t === c.undefinedType) return unionContainsType(c, u, c.missingType);
|
|
1981
|
-
let primitive: Type | undefined;
|
|
1982
|
-
if ((t.flags & TypeFlags.StringLiteral) !== 0) primitive = c.stringType;
|
|
1983
|
-
else if ((t.flags & (TypeFlags.Enum | TypeFlags.NumberLiteral)) !== 0) primitive = c.numberType;
|
|
1984
|
-
else if ((t.flags & TypeFlags.BigIntLiteral) !== 0) primitive = c.bigintType;
|
|
1985
|
-
else if ((t.flags & TypeFlags.UniqueESSymbol) !== 0) primitive = c.esSymbolType;
|
|
1986
|
-
if (primitive === undefined || !unionContainsType(c, u, primitive)) return false;
|
|
1987
|
-
}
|
|
2075
|
+
for (const type of unionTypes) if (!unionContainsTypeOrPrimitive(c, type as UnionType, t, true)) return false;
|
|
1988
2076
|
return true;
|
|
1989
2077
|
}
|
|
1990
2078
|
|
|
2079
|
+
/**
|
|
2080
|
+
* Whether `union` contains `t`, `undefined` where `t` is the missing type and the other way around, or
|
|
2081
|
+
* the primitive type of literal `t` (of a unique symbol only with `matchSymbol`).
|
|
2082
|
+
*/
|
|
2083
|
+
export function unionContainsTypeOrPrimitive(c: Checker, union: UnionType, t: Type, matchSymbol: boolean): boolean {
|
|
2084
|
+
if (unionContainsType(c, union, t)) return true;
|
|
2085
|
+
if (t === c.missingType) return unionContainsType(c, union, c.undefinedType);
|
|
2086
|
+
if (t === c.undefinedType) return unionContainsType(c, union, c.missingType);
|
|
2087
|
+
let primitive: Type | undefined;
|
|
2088
|
+
if ((t.flags & TypeFlags.StringLiteral) !== 0) primitive = c.stringType;
|
|
2089
|
+
else if ((t.flags & (TypeFlags.Enum | TypeFlags.NumberLiteral)) !== 0) primitive = c.numberType;
|
|
2090
|
+
else if ((t.flags & TypeFlags.BigIntLiteral) !== 0) primitive = c.bigintType;
|
|
2091
|
+
else if ((t.flags & TypeFlags.UniqueESSymbol) !== 0 && matchSymbol) primitive = c.esSymbolType;
|
|
2092
|
+
return primitive !== undefined && unionContainsType(c, union, primitive);
|
|
2093
|
+
}
|
|
2094
|
+
|
|
1991
2095
|
export function getCrossProductUnionSize(types: readonly Type[]): number {
|
|
1992
2096
|
let size = 1;
|
|
1993
2097
|
for (const t of types) {
|
|
@@ -2553,7 +2657,13 @@ export function getTemplateLiteralType(c: Checker, texts: string[], types: Type[
|
|
|
2553
2657
|
}
|
|
2554
2658
|
if (types.includes(c.wildcardType)) return c.wildcardType;
|
|
2555
2659
|
const builder = new TemplateBuilder(c, texts[0]!);
|
|
2556
|
-
if (!builder.addSpans(texts, types))
|
|
2660
|
+
if (!builder.addSpans(texts, types)) {
|
|
2661
|
+
if (builder.tooLarge) {
|
|
2662
|
+
c.error(c.currentNode, Diagnostics.Type_instantiation_is_excessively_deep_and_possibly_infinite);
|
|
2663
|
+
return c.errorType;
|
|
2664
|
+
}
|
|
2665
|
+
return c.stringType;
|
|
2666
|
+
}
|
|
2557
2667
|
if (builder.newTypes.length === 0) return getStringLiteralType(c, builder.text);
|
|
2558
2668
|
builder.newTexts.push(builder.text);
|
|
2559
2669
|
const newTexts = builder.newTexts;
|
|
@@ -2572,15 +2682,30 @@ export function getTemplateLiteralType(c: Checker, texts: string[], types: Type[
|
|
|
2572
2682
|
return type;
|
|
2573
2683
|
}
|
|
2574
2684
|
|
|
2685
|
+
/**
|
|
2686
|
+
* Limits on the size of a template literal type that getTemplateLiteralType builds, in UTF-8 bytes of text
|
|
2687
|
+
* and in placeholders. Recursive instantiations such as `Recur<any, `${S}_${S}`>` double the text or the
|
|
2688
|
+
* placeholders on every step and exhaust memory long before the tail recursion limit of conditional types.
|
|
2689
|
+
*/
|
|
2690
|
+
const maxTemplateLiteralTypeLength = 50_000_000;
|
|
2691
|
+
const maxTemplateLiteralTypeSpans = 100_000;
|
|
2692
|
+
|
|
2575
2693
|
class TemplateBuilder {
|
|
2576
2694
|
readonly c: Checker;
|
|
2577
2695
|
text: string;
|
|
2578
2696
|
readonly newTypes: Type[] = [];
|
|
2579
2697
|
readonly newTexts: string[] = [];
|
|
2698
|
+
/** UTF-8 bytes of `text`. */
|
|
2699
|
+
private textBytes: number;
|
|
2700
|
+
/** UTF-8 bytes of the texts already moved into `newTexts`. */
|
|
2701
|
+
private movedBytes = 0;
|
|
2702
|
+
/** Whether `addSpans` stopped because the result passed a size limit. */
|
|
2703
|
+
tooLarge = false;
|
|
2580
2704
|
|
|
2581
2705
|
constructor(c: Checker, text: string) {
|
|
2582
2706
|
this.c = c;
|
|
2583
2707
|
this.text = text;
|
|
2708
|
+
this.textBytes = utf8Length(text);
|
|
2584
2709
|
}
|
|
2585
2710
|
|
|
2586
2711
|
addSpans(texts: string[], types: Type[]): boolean {
|
|
@@ -2588,17 +2713,30 @@ class TemplateBuilder {
|
|
|
2588
2713
|
for (let i = 0; i < types.length; i++) {
|
|
2589
2714
|
const t = types[i]!;
|
|
2590
2715
|
if ((t.flags & (TypeFlags.Literal | TypeFlags.Null | TypeFlags.Undefined)) !== 0) {
|
|
2591
|
-
|
|
2716
|
+
const added = getTemplateStringForType(c, t) + texts[i + 1]!;
|
|
2717
|
+
this.text += added;
|
|
2718
|
+
this.textBytes += utf8Length(added);
|
|
2592
2719
|
} else if ((t.flags & TypeFlags.TemplateLiteral) !== 0) {
|
|
2593
2720
|
const template = t as TemplateLiteralType;
|
|
2594
2721
|
this.text += template.texts[0]!;
|
|
2722
|
+
this.textBytes += utf8Length(template.texts[0]!);
|
|
2595
2723
|
if (!this.addSpans(template.texts, template.types)) return false;
|
|
2596
2724
|
this.text += texts[i + 1]!;
|
|
2725
|
+
this.textBytes += utf8Length(texts[i + 1]!);
|
|
2597
2726
|
} else if (isGenericIndexType(c, t) || isPatternLiteralPlaceholderType(c, t)) {
|
|
2598
2727
|
this.newTypes.push(t);
|
|
2599
2728
|
this.newTexts.push(this.text);
|
|
2729
|
+
this.movedBytes += this.textBytes;
|
|
2600
2730
|
this.text = texts[i + 1]!;
|
|
2731
|
+
this.textBytes = utf8Length(this.text);
|
|
2601
2732
|
} else return false;
|
|
2733
|
+
if (
|
|
2734
|
+
this.movedBytes + this.textBytes > maxTemplateLiteralTypeLength ||
|
|
2735
|
+
this.newTypes.length > maxTemplateLiteralTypeSpans
|
|
2736
|
+
) {
|
|
2737
|
+
this.tooLarge = true;
|
|
2738
|
+
return false;
|
|
2739
|
+
}
|
|
2602
2740
|
}
|
|
2603
2741
|
return true;
|
|
2604
2742
|
}
|
|
@@ -54,6 +54,7 @@ import {
|
|
|
54
54
|
UniqueESSymbolType,
|
|
55
55
|
emptyTypes,
|
|
56
56
|
newTypeMapper,
|
|
57
|
+
TypeParameter,
|
|
57
58
|
} from './checker-types.js';
|
|
58
59
|
import {
|
|
59
60
|
createArrayType,
|
|
@@ -115,6 +116,7 @@ import { checkExpressionWithTypeArguments } from './checker-calls.js';
|
|
|
115
116
|
import { getIntendedTypeFromJSDocTypeReference } from './checker-jsdoc.js';
|
|
116
117
|
import { getCombinedNodeFlags, hasSyntacticModifier } from './binder-utilities.js';
|
|
117
118
|
import { CheckFlags, getDeclarations, getSymbolId, type Symbol, SymbolFlags } from './symbol.js';
|
|
119
|
+
import { isStatement } from './printer/utilities.js';
|
|
118
120
|
|
|
119
121
|
export function getTypeFromTypeNode(c: Checker, node: Node): Type {
|
|
120
122
|
return getConditionalFlowTypeOfType(c, getTypeFromTypeNodeWorker(c, node), node);
|
|
@@ -417,13 +419,19 @@ function isValidESSymbolDeclaration(node: Node): boolean {
|
|
|
417
419
|
return false;
|
|
418
420
|
}
|
|
419
421
|
|
|
422
|
+
/** tsgo's ast.BlockIdOffset, the first id of the symbols a checker numbers. */
|
|
423
|
+
const symbolBlockIdOffset = 2 ** 48;
|
|
424
|
+
|
|
420
425
|
export function getESSymbolLikeTypeForNode(c: Checker, node: Node): Type {
|
|
421
426
|
if (isValidESSymbolDeclaration(node)) {
|
|
422
427
|
const symbol = getSymbolOfDeclaration(c, node);
|
|
423
428
|
if (symbol !== undefined) {
|
|
424
429
|
let uniqueType = c.uniqueESSymbolTypes.get(symbol);
|
|
425
430
|
if (uniqueType === undefined) {
|
|
426
|
-
|
|
431
|
+
// tsgo numbers the symbols its checker keeps links for from 2^48 (ast.BlockIdOffset), and the name's length
|
|
432
|
+
// counts toward the node builder's truncation.
|
|
433
|
+
const name = '@' + symbol.name + '@' + (symbolBlockIdOffset + getSymbolId(symbol));
|
|
434
|
+
uniqueType = new UniqueESSymbolType(c.nextTypeId(), symbol, name);
|
|
427
435
|
c.uniqueESSymbolTypes.set(symbol, uniqueType);
|
|
428
436
|
}
|
|
429
437
|
return uniqueType;
|
|
@@ -442,7 +450,7 @@ function isConstTypeReference(node: Node): boolean {
|
|
|
442
450
|
);
|
|
443
451
|
}
|
|
444
452
|
|
|
445
|
-
function isAssertionExpression(node: Node | undefined): boolean {
|
|
453
|
+
export function isAssertionExpression(node: Node | undefined): boolean {
|
|
446
454
|
return (
|
|
447
455
|
node !== undefined && (node.kind === SyntaxKind.AsExpression || node.kind === SyntaxKind.TypeAssertionExpression)
|
|
448
456
|
);
|
|
@@ -456,12 +464,47 @@ export function getTypeFromTypeReference(c: Checker, node: Node): Type {
|
|
|
456
464
|
else
|
|
457
465
|
type =
|
|
458
466
|
getIntendedTypeFromJSDocTypeReference(c, node) ??
|
|
459
|
-
getTypeReferenceType(c, node, getSymbolFromTypeReference(c, node));
|
|
467
|
+
getDistributedTypeParameter(c, node, getTypeReferenceType(c, node, getSymbolFromTypeReference(c, node)));
|
|
460
468
|
c.resolvedTypes.set(node.id, type);
|
|
461
469
|
}
|
|
462
470
|
return type;
|
|
463
471
|
}
|
|
464
472
|
|
|
473
|
+
/**
|
|
474
|
+
* The distributed form of a type parameter `t` that `node` references inside a distributive conditional type on
|
|
475
|
+
* it (one whose check type is a bare reference to the type parameter), up to the enclosing statement; otherwise `t`.
|
|
476
|
+
*/
|
|
477
|
+
function getDistributedTypeParameter(c: Checker, node: Node, t: Type): Type {
|
|
478
|
+
if ((t.flags & TypeFlags.TypeParameter) === 0 || (t as TypeParameter).isDistributed) return t;
|
|
479
|
+
for (let n = node.parent; n !== undefined && !isStatement(n); n = n.parent) {
|
|
480
|
+
if (n.kind !== SyntaxKind.ConditionalType) continue;
|
|
481
|
+
const checkTypeNode = (n as ConditionalTypeNode).checkType;
|
|
482
|
+
if (isSimpleIdentifierTypeReference(checkTypeNode) && getSymbolFromTypeReference(c, checkTypeNode) === t.symbol)
|
|
483
|
+
return getDistributedTypeFromTypeParameter(c, t as TypeParameter);
|
|
484
|
+
}
|
|
485
|
+
return t;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
function getDistributedTypeFromTypeParameter(c: Checker, t: TypeParameter): TypeParameter {
|
|
489
|
+
let distributed = t.distributedType;
|
|
490
|
+
if (distributed === undefined) {
|
|
491
|
+
distributed = c.newTypeParameter(t.symbol);
|
|
492
|
+
distributed.isDistributed = true;
|
|
493
|
+
distributed.constraint = t;
|
|
494
|
+
t.distributedType = distributed;
|
|
495
|
+
}
|
|
496
|
+
return distributed;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/** A type reference that is a bare identifier without type arguments. */
|
|
500
|
+
function isSimpleIdentifierTypeReference(node: Node): boolean {
|
|
501
|
+
return (
|
|
502
|
+
node.kind === SyntaxKind.TypeReference &&
|
|
503
|
+
(node as TypeReferenceNode).typeName.kind === SyntaxKind.Identifier &&
|
|
504
|
+
(node as TypeReferenceNode).typeArguments === undefined
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
|
|
465
508
|
export function getSymbolFromTypeReference(c: Checker, node: Node): Symbol {
|
|
466
509
|
let symbol = c.resolvedSymbols.get(node.id);
|
|
467
510
|
if (symbol === undefined) {
|
|
@@ -37,6 +37,8 @@ import {
|
|
|
37
37
|
IndexFlags,
|
|
38
38
|
IndexInfo,
|
|
39
39
|
type IndexType,
|
|
40
|
+
ConditionalResultKey,
|
|
41
|
+
DistributedConditional,
|
|
40
42
|
IndexedAccessType,
|
|
41
43
|
type IntersectionType,
|
|
42
44
|
type LiteralType,
|
|
@@ -61,6 +63,8 @@ import {
|
|
|
61
63
|
ReferenceArgs,
|
|
62
64
|
type TypeReference,
|
|
63
65
|
VarianceFlags,
|
|
66
|
+
getMappedType,
|
|
67
|
+
getNonDistributedTypeParameter,
|
|
64
68
|
} from './checker-types.js';
|
|
65
69
|
import {
|
|
66
70
|
UnionReduction,
|
|
@@ -119,7 +123,6 @@ import {
|
|
|
119
123
|
getIndexTypeOfType,
|
|
120
124
|
hasPropertiesOfType,
|
|
121
125
|
keepPropertiesOnly,
|
|
122
|
-
memberResolutionFlags,
|
|
123
126
|
} from './checker-members.js';
|
|
124
127
|
import {
|
|
125
128
|
getLateBoundSymbol,
|
|
@@ -328,13 +331,7 @@ function getIndexTypeForGenericType(c: Checker, t: Type, indexFlags: IndexFlags)
|
|
|
328
331
|
}
|
|
329
332
|
|
|
330
333
|
export function getLiteralTypeFromProperties(c: Checker, t: Type, include: TypeFlags, includeOrigin: boolean): Type {
|
|
331
|
-
const key =
|
|
332
|
-
'props' +
|
|
333
|
-
t.id +
|
|
334
|
-
':' +
|
|
335
|
-
include +
|
|
336
|
-
(includeOrigin ? 'o' : '') +
|
|
337
|
-
((memberResolutionFlags(c, t) & ObjectFlags.UnresolvedMembers) !== 0 ? 'u' : '');
|
|
334
|
+
const key = 'props' + t.id + ':' + include + (includeOrigin ? 'o' : '');
|
|
338
335
|
const cached = c.cachedTypes.get(key);
|
|
339
336
|
if (cached !== undefined) return cached;
|
|
340
337
|
const origin =
|
|
@@ -594,6 +591,7 @@ export function getIndexedAccessTypeOrUndefinedEx(
|
|
|
594
591
|
let t = c.indexedAccessTypes.get(key);
|
|
595
592
|
if (t === undefined) {
|
|
596
593
|
t = newIndexedAccessType(c, objectType, indexType, persistent);
|
|
594
|
+
if (c.indexedAccessKeyFlags !== undefined) c.indexedAccessKeyFlags.set(t, accessFlags);
|
|
597
595
|
t.alias = alias;
|
|
598
596
|
c.indexedAccessTypes.set(key, t);
|
|
599
597
|
}
|
|
@@ -1193,11 +1191,36 @@ export function getSimplifiedType(c: Checker, t: Type, writing: boolean): Type {
|
|
|
1193
1191
|
if ((t.flags & TypeFlags.IndexedAccess) !== 0)
|
|
1194
1192
|
return getSimplifiedIndexedAccessType(c, t as IndexedAccessType, writing);
|
|
1195
1193
|
if ((t.flags & TypeFlags.Conditional) !== 0) return getSimplifiedConditionalType(c, t as ConditionalType, writing);
|
|
1194
|
+
if ((t.flags & TypeFlags.Index) !== 0) return getSimplifiedIndexType(c, t as IndexType);
|
|
1195
|
+
return t;
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
/** Simplifies `keyof` a generic mapped type with an `as` clause to the type of the keys it produces. */
|
|
1199
|
+
function getSimplifiedIndexType(c: Checker, t: IndexType): Type {
|
|
1200
|
+
const target = t.target;
|
|
1201
|
+
if (
|
|
1202
|
+
isGenericMappedType(c, target) &&
|
|
1203
|
+
getNameTypeFromMappedType(c, target as MappedType) !== undefined &&
|
|
1204
|
+
!isMappedTypeWithKeyofConstraintDeclaration(c, target as MappedType)
|
|
1205
|
+
)
|
|
1206
|
+
return getIndexForMappedType(c, target as MappedType, IndexFlags.None);
|
|
1196
1207
|
return t;
|
|
1197
1208
|
}
|
|
1198
1209
|
|
|
1199
1210
|
/** Simplifies `T extends U ? T : never` and `T extends U ? never : T` when the outcome is known. */
|
|
1200
1211
|
function getSimplifiedConditionalType(c: Checker, t: ConditionalType, writing: boolean): Type {
|
|
1212
|
+
const key = cachedTypeKey(
|
|
1213
|
+
writing ? CachedTypeKind.SimplifiedConditionalForWriting : CachedTypeKind.SimplifiedConditionalForReading,
|
|
1214
|
+
t.id,
|
|
1215
|
+
);
|
|
1216
|
+
const cached = c.cachedTypesById.get(key);
|
|
1217
|
+
if (cached !== undefined) return cached;
|
|
1218
|
+
const result = getSimplifiedConditionalTypeWorker(c, t, writing);
|
|
1219
|
+
c.cachedTypesById.set(key, result);
|
|
1220
|
+
return result;
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
function getSimplifiedConditionalTypeWorker(c: Checker, t: ConditionalType, writing: boolean): Type {
|
|
1201
1224
|
const checkType = t.checkType;
|
|
1202
1225
|
const extendsType = t.extendsType;
|
|
1203
1226
|
const trueType = getTrueTypeFromConditionalType(c, t);
|
|
@@ -1561,7 +1584,9 @@ export function getModifiersTypeFromMappedType(c: Checker, t: MappedType): Type
|
|
|
1561
1584
|
const declaredType = getTypeFromMappedTypeNode(c, t.declaration!) as MappedType;
|
|
1562
1585
|
const constraint = getConstraintTypeFromMappedType(c, declaredType);
|
|
1563
1586
|
const extended =
|
|
1564
|
-
(constraint.flags & TypeFlags.TypeParameter) !== 0
|
|
1587
|
+
(constraint.flags & TypeFlags.TypeParameter) !== 0
|
|
1588
|
+
? getConstraintOfTypeParameter(c, getNonDistributedTypeParameter(constraint))
|
|
1589
|
+
: constraint;
|
|
1565
1590
|
side.modifiersType =
|
|
1566
1591
|
extended !== undefined && (extended.flags & TypeFlags.Index) !== 0
|
|
1567
1592
|
? instantiateType(c, (extended as IndexType).target, t.mapper)
|
|
@@ -1584,17 +1609,12 @@ export function getActualTypeVariable(c: Checker, t: Type): Type {
|
|
|
1584
1609
|
if ((t.flags & TypeFlags.Substitution) !== 0) return getActualTypeVariable(c, (t as SubstitutionType).baseType);
|
|
1585
1610
|
if ((t.flags & TypeFlags.IndexedAccess) !== 0) {
|
|
1586
1611
|
const access = t as IndexedAccessType;
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
return getIndexedAccessType(
|
|
1592
|
-
c,
|
|
1593
|
-
getActualTypeVariable(c, access.objectType),
|
|
1594
|
-
getActualTypeVariable(c, access.indexType),
|
|
1595
|
-
);
|
|
1612
|
+
const objectType = getActualTypeVariable(c, access.objectType);
|
|
1613
|
+
const indexType = getActualTypeVariable(c, access.indexType);
|
|
1614
|
+
if (objectType !== access.objectType || indexType !== access.indexType)
|
|
1615
|
+
return getIndexedAccessType(c, objectType, indexType);
|
|
1596
1616
|
}
|
|
1597
|
-
return t;
|
|
1617
|
+
return getNonDistributedTypeParameter(t);
|
|
1598
1618
|
}
|
|
1599
1619
|
|
|
1600
1620
|
export const enum MappedTypeNameTypeKind {
|
|
@@ -1907,7 +1927,7 @@ function instantiateMappedTypeTemplate(
|
|
|
1907
1927
|
)
|
|
1908
1928
|
return getOptionalType(c, propType, true);
|
|
1909
1929
|
if (c.strictNullChecks && (modifiers & MappedTypeModifiers.ExcludeOptional) !== 0 && isOptional)
|
|
1910
|
-
return
|
|
1930
|
+
return removeMissingOrUndefinedType(c, propType);
|
|
1911
1931
|
return propType;
|
|
1912
1932
|
}
|
|
1913
1933
|
|
|
@@ -1975,21 +1995,41 @@ export function getConditionalTypeInstantiation(
|
|
|
1975
1995
|
if (result === undefined) {
|
|
1976
1996
|
const newMapper = newTypeMapper(root.outerTypeParameters, typeArguments);
|
|
1977
1997
|
const checkType = root.checkType;
|
|
1978
|
-
const distributionType = root.isDistributive ? getReducedType(c,
|
|
1998
|
+
const distributionType = root.isDistributive ? getReducedType(c, getMappedType(checkType, newMapper)) : undefined;
|
|
1979
1999
|
// Distributive conditional types distribute over unions.
|
|
1980
2000
|
if (
|
|
1981
2001
|
distributionType !== undefined &&
|
|
1982
2002
|
checkType !== distributionType &&
|
|
1983
2003
|
(distributionType.flags & (TypeFlags.Union | TypeFlags.Never)) !== 0
|
|
1984
|
-
)
|
|
2004
|
+
) {
|
|
2005
|
+
const distributed = c.distributedConditionals;
|
|
1985
2006
|
result = mapTypeWithAlias(
|
|
1986
2007
|
c,
|
|
1987
2008
|
distributionType,
|
|
1988
|
-
(u) =>
|
|
2009
|
+
(u) => {
|
|
2010
|
+
const member = getConditionalType(
|
|
2011
|
+
c,
|
|
2012
|
+
root,
|
|
2013
|
+
prependTypeMapping(checkType, u, newMapper),
|
|
2014
|
+
forConstraint,
|
|
2015
|
+
undefined,
|
|
2016
|
+
);
|
|
2017
|
+
// Sharing results (shared-results.ts) names a distributed member by the instantiation it is part of.
|
|
2018
|
+
if (distributed !== undefined && (member.flags & TypeFlags.Conditional) !== 0) {
|
|
2019
|
+
if (!distributed.has(member))
|
|
2020
|
+
distributed.set(member, new DistributedConditional(typeArguments.slice(), alias, tag, u));
|
|
2021
|
+
c.distributedByKey!.set(distributedKey(root.node.id, typeArguments, alias, tag, u), member);
|
|
2022
|
+
}
|
|
2023
|
+
return member;
|
|
2024
|
+
},
|
|
1989
2025
|
alias,
|
|
1990
2026
|
);
|
|
1991
|
-
else result = getConditionalType(c, root, newMapper, forConstraint, alias);
|
|
2027
|
+
} else result = getConditionalType(c, root, newMapper, forConstraint, alias);
|
|
1992
2028
|
root.instantiations.set(hash, typeArguments, alias, tag, result);
|
|
2029
|
+
// Sharing results names a conditional type made for another root (a tail or nested root) by this instantiation.
|
|
2030
|
+
const results = c.conditionalResults;
|
|
2031
|
+
if (results !== undefined && (result.flags & TypeFlags.Conditional) !== 0 && !results.has(result))
|
|
2032
|
+
results.set(result, new ConditionalResultKey(root, typeArguments.slice(), alias, tag));
|
|
1993
2033
|
}
|
|
1994
2034
|
return result;
|
|
1995
2035
|
}
|
|
@@ -2322,7 +2362,7 @@ function getTailRecursionRoot(c: Checker, newType: Type, newMapper: TypeMapper |
|
|
|
2322
2362
|
const typeArguments: Type[] = [];
|
|
2323
2363
|
for (const t of newRoot.outerTypeParameters) typeArguments.push(typeParamMapper.map(t));
|
|
2324
2364
|
const newRootMapper = newTypeMapper(newRoot.outerTypeParameters, typeArguments);
|
|
2325
|
-
const newCheckType = newRoot.isDistributive ?
|
|
2365
|
+
const newCheckType = newRoot.isDistributive ? getMappedType(newRoot.checkType, newRootMapper) : undefined;
|
|
2326
2366
|
if (
|
|
2327
2367
|
newCheckType === undefined ||
|
|
2328
2368
|
newCheckType === newRoot.checkType ||
|
|
@@ -2435,7 +2475,7 @@ export function isTypeMatchedByTemplateLiteralType(
|
|
|
2435
2475
|
target: TemplateLiteralType,
|
|
2436
2476
|
compareTypes?: TemplateTypeComparer,
|
|
2437
2477
|
): boolean {
|
|
2438
|
-
const inferences = inferTypesFromTemplateLiteralType(c, source, target);
|
|
2478
|
+
const inferences = inferTypesFromTemplateLiteralType(c, source, target, compareTypes);
|
|
2439
2479
|
if (inferences === undefined) return false;
|
|
2440
2480
|
const compare = compareTypes ?? ((s: Type, t: Type) => isTypeAssignableTo(c, s, t));
|
|
2441
2481
|
for (let i = 0; i < inferences.length; i++)
|
|
@@ -2508,3 +2548,20 @@ export function mappedTypeTarget(t: MappedType): MappedType {
|
|
|
2508
2548
|
const target = t.target;
|
|
2509
2549
|
return target !== undefined ? (target as MappedType) : t;
|
|
2510
2550
|
}
|
|
2551
|
+
|
|
2552
|
+
/** The key of the member of a conditional type instantiation's distribution for one constituent (shared-results.ts). */
|
|
2553
|
+
export function distributedKey(
|
|
2554
|
+
root: number,
|
|
2555
|
+
typeArguments: readonly Type[],
|
|
2556
|
+
alias: TypeAlias | undefined,
|
|
2557
|
+
tag: number,
|
|
2558
|
+
constituent: Type,
|
|
2559
|
+
): string {
|
|
2560
|
+
let key = root + ':' + tag + ':' + constituent.id + ':';
|
|
2561
|
+
for (const t of typeArguments) key += t.id + ',';
|
|
2562
|
+
if (alias !== undefined) {
|
|
2563
|
+
key += '@' + getSymbolId(alias.symbol);
|
|
2564
|
+
for (const t of alias.typeArguments) key += ',' + t.id;
|
|
2565
|
+
}
|
|
2566
|
+
return key;
|
|
2567
|
+
}
|