tsc-ts 0.0.3 → 0.0.5
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 +46 -0
- package/dist/api/compiler/ast-utilities.d.ts +82 -0
- package/dist/api/compiler/ast-utilities.js +462 -0
- package/dist/api/compiler/ast.d.ts +2350 -0
- package/dist/api/compiler/ast.js +11206 -0
- package/dist/api/compiler/astnav.d.ts +37 -0
- package/dist/api/compiler/astnav.js +767 -0
- package/dist/api/compiler/binder-utilities.d.ts +182 -0
- package/dist/api/compiler/binder-utilities.js +1240 -0
- package/dist/api/compiler/binder.d.ts +33 -0
- package/dist/api/compiler/binder.js +2358 -0
- package/dist/api/compiler/character-codes.d.ts +161 -0
- package/dist/api/compiler/character-codes.js +160 -0
- package/dist/api/compiler/checker-calls.d.ts +46 -0
- package/dist/api/compiler/checker-calls.js +1640 -0
- package/dist/api/compiler/checker-classes.d.ts +30 -0
- package/dist/api/compiler/checker-classes.js +582 -0
- package/dist/api/compiler/checker-contextual.d.ts +77 -0
- package/dist/api/compiler/checker-contextual.js +1136 -0
- package/dist/api/compiler/checker-declaration-order.d.ts +12 -0
- package/dist/api/compiler/checker-declaration-order.js +356 -0
- package/dist/api/compiler/checker-declarations.d.ts +33 -0
- package/dist/api/compiler/checker-declarations.js +888 -0
- package/dist/api/compiler/checker-declared-types.d.ts +48 -0
- package/dist/api/compiler/checker-declared-types.js +787 -0
- package/dist/api/compiler/checker-decorators.d.ts +26 -0
- package/dist/api/compiler/checker-decorators.js +562 -0
- package/dist/api/compiler/checker-deprecation.d.ts +33 -0
- package/dist/api/compiler/checker-deprecation.js +315 -0
- package/dist/api/compiler/checker-destructuring.d.ts +34 -0
- package/dist/api/compiler/checker-destructuring.js +584 -0
- package/dist/api/compiler/checker-elaboration.d.ts +15 -0
- package/dist/api/compiler/checker-elaboration.js +290 -0
- package/dist/api/compiler/checker-emit-helpers.d.ts +58 -0
- package/dist/api/compiler/checker-emit-helpers.js +154 -0
- package/dist/api/compiler/checker-emit-resolver.d.ts +75 -0
- package/dist/api/compiler/checker-emit-resolver.js +579 -0
- package/dist/api/compiler/checker-evaluator.d.ts +27 -0
- package/dist/api/compiler/checker-evaluator.js +188 -0
- package/dist/api/compiler/checker-expressions.d.ts +67 -0
- package/dist/api/compiler/checker-expressions.js +1351 -0
- package/dist/api/compiler/checker-features.d.ts +6 -0
- package/dist/api/compiler/checker-features.js +354 -0
- package/dist/api/compiler/checker-flow.d.ts +86 -0
- package/dist/api/compiler/checker-flow.js +169 -0
- package/dist/api/compiler/checker-functions.d.ts +43 -0
- package/dist/api/compiler/checker-functions.js +1002 -0
- package/dist/api/compiler/checker-generated-code.d.ts +25 -0
- package/dist/api/compiler/checker-generated-code.js +168 -0
- package/dist/api/compiler/checker-globals.d.ts +14 -0
- package/dist/api/compiler/checker-globals.js +37 -0
- package/dist/api/compiler/checker-grammar.d.ts +35 -0
- package/dist/api/compiler/checker-grammar.js +2573 -0
- package/dist/api/compiler/checker-heritage.d.ts +28 -0
- package/dist/api/compiler/checker-heritage.js +900 -0
- package/dist/api/compiler/checker-inference.d.ts +179 -0
- package/dist/api/compiler/checker-inference.js +2105 -0
- package/dist/api/compiler/checker-iteration.d.ts +115 -0
- package/dist/api/compiler/checker-iteration.js +857 -0
- package/dist/api/compiler/checker-javascript.d.ts +42 -0
- package/dist/api/compiler/checker-javascript.js +441 -0
- package/dist/api/compiler/checker-jsdoc.d.ts +30 -0
- package/dist/api/compiler/checker-jsdoc.js +320 -0
- package/dist/api/compiler/checker-jsx.d.ts +94 -0
- package/dist/api/compiler/checker-jsx.js +1433 -0
- package/dist/api/compiler/checker-literals.d.ts +6 -0
- package/dist/api/compiler/checker-literals.js +43 -0
- package/dist/api/compiler/checker-members.d.ts +198 -0
- package/dist/api/compiler/checker-members.js +2126 -0
- package/dist/api/compiler/checker-modules.d.ts +85 -0
- package/dist/api/compiler/checker-modules.js +2141 -0
- package/dist/api/compiler/checker-narrowing.d.ts +120 -0
- package/dist/api/compiler/checker-narrowing.js +2797 -0
- package/dist/api/compiler/checker-object-literals.d.ts +14 -0
- package/dist/api/compiler/checker-object-literals.js +479 -0
- package/dist/api/compiler/checker-operators.d.ts +33 -0
- package/dist/api/compiler/checker-operators.js +1040 -0
- package/dist/api/compiler/checker-overloads.d.ts +7 -0
- package/dist/api/compiler/checker-overloads.js +270 -0
- package/dist/api/compiler/checker-property-access.d.ts +34 -0
- package/dist/api/compiler/checker-property-access.js +672 -0
- package/dist/api/compiler/checker-services.d.ts +49 -0
- package/dist/api/compiler/checker-services.js +995 -0
- package/dist/api/compiler/checker-signatures.d.ts +55 -0
- package/dist/api/compiler/checker-signatures.js +788 -0
- package/dist/api/compiler/checker-source-file.d.ts +27 -0
- package/dist/api/compiler/checker-source-file.js +619 -0
- package/dist/api/compiler/checker-statements.d.ts +18 -0
- package/dist/api/compiler/checker-statements.js +226 -0
- package/dist/api/compiler/checker-super.d.ts +13 -0
- package/dist/api/compiler/checker-super.js +241 -0
- package/dist/api/compiler/checker-symbol-types.d.ts +67 -0
- package/dist/api/compiler/checker-symbol-types.js +1885 -0
- package/dist/api/compiler/checker-symbols.d.ts +181 -0
- package/dist/api/compiler/checker-symbols.js +1782 -0
- package/dist/api/compiler/checker-type-factory.d.ts +142 -0
- package/dist/api/compiler/checker-type-factory.js +2501 -0
- package/dist/api/compiler/checker-type-nodes.d.ts +26 -0
- package/dist/api/compiler/checker-type-nodes.js +828 -0
- package/dist/api/compiler/checker-type-operators.d.ts +109 -0
- package/dist/api/compiler/checker-type-operators.js +1842 -0
- package/dist/api/compiler/checker-types.d.ts +1027 -0
- package/dist/api/compiler/checker-types.js +1697 -0
- package/dist/api/compiler/checker-unused.d.ts +19 -0
- package/dist/api/compiler/checker-unused.js +524 -0
- package/dist/api/compiler/checker-utilities.d.ts +33 -0
- package/dist/api/compiler/checker-utilities.js +141 -0
- package/dist/api/compiler/checker.d.ts +491 -0
- package/dist/api/compiler/checker.js +912 -0
- package/dist/api/compiler/command-line.d.ts +32 -0
- package/dist/api/compiler/command-line.js +383 -0
- package/dist/api/compiler/compile-program.d.ts +118 -0
- package/dist/api/compiler/compile-program.js +384 -0
- package/dist/api/compiler/diagnostic-locales.d.ts +22 -0
- package/dist/api/compiler/diagnostic-locales.js +64 -0
- package/dist/api/compiler/diagnostic-messages.d.ts +2166 -0
- package/dist/api/compiler/diagnostic-messages.js +184 -0
- package/dist/api/compiler/diagnostics.d.ts +167 -0
- package/dist/api/compiler/diagnostics.js +820 -0
- package/dist/api/compiler/emitter.d.ts +71 -0
- package/dist/api/compiler/emitter.js +327 -0
- package/dist/api/compiler/file-include.d.ts +117 -0
- package/dist/api/compiler/file-include.js +536 -0
- package/dist/api/compiler/file-loader.d.ts +261 -0
- package/dist/api/compiler/file-loader.js +1257 -0
- package/dist/api/compiler/file-system.d.ts +51 -0
- package/dist/api/compiler/file-system.js +132 -0
- package/dist/api/compiler/flow.d.ts +60 -0
- package/dist/api/compiler/flow.js +45 -0
- package/dist/api/compiler/instantiation.d.ts +74 -0
- package/dist/api/compiler/instantiation.js +799 -0
- package/dist/api/compiler/jsdoc.d.ts +75 -0
- package/dist/api/compiler/jsdoc.js +1229 -0
- package/dist/api/compiler/link-tables.d.ts +36 -0
- package/dist/api/compiler/link-tables.js +83 -0
- package/dist/api/compiler/locale-data.d.ts +24 -0
- package/dist/api/compiler/locale-data.js +183 -0
- package/dist/api/compiler/locale.d.ts +4 -0
- package/dist/api/compiler/locale.js +317 -0
- package/dist/api/compiler/locales/cs-CZ.d.ts +2 -0
- package/dist/api/compiler/locales/cs-CZ.js +3 -0
- package/dist/api/compiler/locales/de-DE.d.ts +2 -0
- package/dist/api/compiler/locales/de-DE.js +3 -0
- package/dist/api/compiler/locales/es-ES.d.ts +2 -0
- package/dist/api/compiler/locales/es-ES.js +3 -0
- package/dist/api/compiler/locales/fr-FR.d.ts +2 -0
- package/dist/api/compiler/locales/fr-FR.js +3 -0
- package/dist/api/compiler/locales/it-IT.d.ts +2 -0
- package/dist/api/compiler/locales/it-IT.js +3 -0
- package/dist/api/compiler/locales/ja-JP.d.ts +2 -0
- package/dist/api/compiler/locales/ja-JP.js +3 -0
- package/dist/api/compiler/locales/ko-KR.d.ts +2 -0
- package/dist/api/compiler/locales/ko-KR.js +3 -0
- package/dist/api/compiler/locales/pl-PL.d.ts +2 -0
- package/dist/api/compiler/locales/pl-PL.js +3 -0
- package/dist/api/compiler/locales/pt-BR.d.ts +2 -0
- package/dist/api/compiler/locales/pt-BR.js +3 -0
- package/dist/api/compiler/locales/ru-RU.d.ts +2 -0
- package/dist/api/compiler/locales/ru-RU.js +3 -0
- package/dist/api/compiler/locales/tr-TR.d.ts +2 -0
- package/dist/api/compiler/locales/tr-TR.js +3 -0
- package/dist/api/compiler/locales/zh-CN.d.ts +2 -0
- package/dist/api/compiler/locales/zh-CN.js +3 -0
- package/dist/api/compiler/locales/zh-TW.d.ts +2 -0
- package/dist/api/compiler/locales/zh-TW.js +3 -0
- package/dist/api/compiler/module-resolution-types.d.ts +83 -0
- package/dist/api/compiler/module-resolution-types.js +176 -0
- package/dist/api/compiler/module-resolution.d.ts +71 -0
- package/dist/api/compiler/module-resolution.js +1598 -0
- package/dist/api/compiler/module-specifiers.d.ts +64 -0
- package/dist/api/compiler/module-specifiers.js +1101 -0
- package/dist/api/compiler/name-resolver.d.ts +43 -0
- package/dist/api/compiler/name-resolver.js +509 -0
- package/dist/api/compiler/node-builder-names.d.ts +32 -0
- package/dist/api/compiler/node-builder-names.js +854 -0
- package/dist/api/compiler/node-builder-pseudo.d.ts +36 -0
- package/dist/api/compiler/node-builder-pseudo.js +744 -0
- package/dist/api/compiler/node-builder-reuse.d.ts +4 -0
- package/dist/api/compiler/node-builder-reuse.js +647 -0
- package/dist/api/compiler/node-builder.d.ts +270 -0
- package/dist/api/compiler/node-builder.js +2645 -0
- package/dist/api/compiler/option-declarations.d.ts +90 -0
- package/dist/api/compiler/option-declarations.js +1460 -0
- package/dist/api/compiler/options.d.ts +289 -0
- package/dist/api/compiler/options.js +1197 -0
- package/dist/api/compiler/output-paths.d.ts +42 -0
- package/dist/api/compiler/output-paths.js +195 -0
- package/dist/api/compiler/package-json.d.ts +175 -0
- package/dist/api/compiler/package-json.js +1015 -0
- package/dist/api/compiler/parallel-parse.d.ts +219 -0
- package/dist/api/compiler/parallel-parse.js +537 -0
- package/dist/api/compiler/parser.d.ts +587 -0
- package/dist/api/compiler/parser.js +6407 -0
- package/dist/api/compiler/path.d.ts +91 -0
- package/dist/api/compiler/path.js +705 -0
- package/dist/api/compiler/printer/async-helpers.d.ts +22 -0
- package/dist/api/compiler/printer/async-helpers.js +91 -0
- package/dist/api/compiler/printer/auto-generate.d.ts +13 -0
- package/dist/api/compiler/printer/auto-generate.js +20 -0
- package/dist/api/compiler/printer/decorator-helpers.d.ts +24 -0
- package/dist/api/compiler/printer/decorator-helpers.js +118 -0
- package/dist/api/compiler/printer/emit-context.d.ts +154 -0
- package/dist/api/compiler/printer/emit-context.js +576 -0
- package/dist/api/compiler/printer/emit-flags.d.ts +60 -0
- package/dist/api/compiler/printer/emit-flags.js +2 -0
- package/dist/api/compiler/printer/factory-base.d.ts +171 -0
- package/dist/api/compiler/printer/factory-base.js +1505 -0
- package/dist/api/compiler/printer/factory.d.ts +147 -0
- package/dist/api/compiler/printer/factory.js +542 -0
- package/dist/api/compiler/printer/helpers.d.ts +27 -0
- package/dist/api/compiler/printer/helpers.js +164 -0
- package/dist/api/compiler/printer/name-generator.d.ts +41 -0
- package/dist/api/compiler/printer/name-generator.js +283 -0
- package/dist/api/compiler/printer/printer.d.ts +411 -0
- package/dist/api/compiler/printer/printer.js +4517 -0
- package/dist/api/compiler/printer/text-writer.d.ts +46 -0
- package/dist/api/compiler/printer/text-writer.js +172 -0
- package/dist/api/compiler/printer/utilities.d.ts +82 -0
- package/dist/api/compiler/printer/utilities.js +817 -0
- package/dist/api/compiler/program-checker.d.ts +156 -0
- package/dist/api/compiler/program-checker.js +526 -0
- package/dist/api/compiler/program-utilities.d.ts +52 -0
- package/dist/api/compiler/program-utilities.js +365 -0
- package/dist/api/compiler/program.d.ts +180 -0
- package/dist/api/compiler/program.js +1011 -0
- package/dist/api/compiler/pseudo-bigint.d.ts +5 -0
- package/dist/api/compiler/pseudo-bigint.js +61 -0
- package/dist/api/compiler/regexp-checker.d.ts +38 -0
- package/dist/api/compiler/regexp-checker.js +942 -0
- package/dist/api/compiler/relations.d.ts +263 -0
- package/dist/api/compiler/relations.js +4002 -0
- package/dist/api/compiler/reparser.d.ts +48 -0
- package/dist/api/compiler/reparser.js +1323 -0
- package/dist/api/compiler/scanner.d.ts +256 -0
- package/dist/api/compiler/scanner.js +2853 -0
- package/dist/api/compiler/side-state.d.ts +16 -0
- package/dist/api/compiler/side-state.js +89 -0
- package/dist/api/compiler/sourcemap.d.ts +55 -0
- package/dist/api/compiler/sourcemap.js +340 -0
- package/dist/api/compiler/spelling.d.ts +14 -0
- package/dist/api/compiler/spelling.js +128 -0
- package/dist/api/compiler/symbol-accessibility.d.ts +57 -0
- package/dist/api/compiler/symbol-accessibility.js +894 -0
- package/dist/api/compiler/symbol.d.ts +240 -0
- package/dist/api/compiler/symbol.js +228 -0
- package/dist/api/compiler/symlinks.d.ts +32 -0
- package/dist/api/compiler/symlinks.js +114 -0
- package/dist/api/compiler/syntax-kind.d.ts +389 -0
- package/dist/api/compiler/syntax-kind.js +2 -0
- package/dist/api/compiler/timeline.d.ts +9 -0
- package/dist/api/compiler/timeline.js +54 -0
- package/dist/api/compiler/transformers/alias-references.d.ts +39 -0
- package/dist/api/compiler/transformers/alias-references.js +676 -0
- package/dist/api/compiler/transformers/async-utilities.d.ts +51 -0
- package/dist/api/compiler/transformers/async-utilities.js +260 -0
- package/dist/api/compiler/transformers/async.d.ts +53 -0
- package/dist/api/compiler/transformers/async.js +645 -0
- package/dist/api/compiler/transformers/class-fields.d.ts +206 -0
- package/dist/api/compiler/transformers/class-fields.js +2418 -0
- package/dist/api/compiler/transformers/class-utilities.d.ts +46 -0
- package/dist/api/compiler/transformers/class-utilities.js +261 -0
- package/dist/api/compiler/transformers/commonjs-module.d.ts +103 -0
- package/dist/api/compiler/transformers/commonjs-module.js +1180 -0
- package/dist/api/compiler/transformers/const-enum-inliner.d.ts +11 -0
- package/dist/api/compiler/transformers/const-enum-inliner.js +36 -0
- package/dist/api/compiler/transformers/declarations-diagnostics.d.ts +52 -0
- package/dist/api/compiler/transformers/declarations-diagnostics.js +538 -0
- package/dist/api/compiler/transformers/declarations-pseudo.d.ts +160 -0
- package/dist/api/compiler/transformers/declarations-pseudo.js +797 -0
- package/dist/api/compiler/transformers/declarations-resolver.d.ts +152 -0
- package/dist/api/compiler/transformers/declarations-resolver.js +35 -0
- package/dist/api/compiler/transformers/declarations-syntactic.d.ts +119 -0
- package/dist/api/compiler/transformers/declarations-syntactic.js +1582 -0
- package/dist/api/compiler/transformers/declarations-tracker.d.ts +46 -0
- package/dist/api/compiler/transformers/declarations-tracker.js +197 -0
- package/dist/api/compiler/transformers/declarations.d.ts +175 -0
- package/dist/api/compiler/transformers/declarations.js +2380 -0
- package/dist/api/compiler/transformers/decorator-metadata.d.ts +54 -0
- package/dist/api/compiler/transformers/decorator-metadata.js +554 -0
- package/dist/api/compiler/transformers/decorator-utilities.d.ts +38 -0
- package/dist/api/compiler/transformers/decorator-utilities.js +238 -0
- package/dist/api/compiler/transformers/destructuring.d.ts +25 -0
- package/dist/api/compiler/transformers/destructuring.js +626 -0
- package/dist/api/compiler/transformers/downlevel.d.ts +6 -0
- package/dist/api/compiler/transformers/downlevel.js +45 -0
- package/dist/api/compiler/transformers/emit-resolver.d.ts +61 -0
- package/dist/api/compiler/transformers/emit-resolver.js +197 -0
- package/dist/api/compiler/transformers/es-decorators.d.ts +118 -0
- package/dist/api/compiler/transformers/es-decorators.js +1901 -0
- package/dist/api/compiler/transformers/exponentiation.d.ts +11 -0
- package/dist/api/compiler/transformers/exponentiation.js +76 -0
- package/dist/api/compiler/transformers/external-module-info.d.ts +35 -0
- package/dist/api/compiler/transformers/external-module-info.js +351 -0
- package/dist/api/compiler/transformers/for-await.d.ts +43 -0
- package/dist/api/compiler/transformers/for-await.js +469 -0
- package/dist/api/compiler/transformers/import-elision.d.ts +16 -0
- package/dist/api/compiler/transformers/import-elision.js +124 -0
- package/dist/api/compiler/transformers/jsx-entities.d.ts +1 -0
- package/dist/api/compiler/transformers/jsx-entities.js +256 -0
- package/dist/api/compiler/transformers/jsx.d.ts +71 -0
- package/dist/api/compiler/transformers/jsx.js +700 -0
- package/dist/api/compiler/transformers/legacy-decorators.d.ts +56 -0
- package/dist/api/compiler/transformers/legacy-decorators.js +564 -0
- package/dist/api/compiler/transformers/logical-assignment.d.ts +14 -0
- package/dist/api/compiler/transformers/logical-assignment.js +62 -0
- package/dist/api/compiler/transformers/module-utilities.d.ts +9 -0
- package/dist/api/compiler/transformers/module-utilities.js +36 -0
- package/dist/api/compiler/transformers/module.d.ts +49 -0
- package/dist/api/compiler/transformers/module.js +296 -0
- package/dist/api/compiler/transformers/named-evaluation.d.ts +26 -0
- package/dist/api/compiler/transformers/named-evaluation.js +266 -0
- package/dist/api/compiler/transformers/nullish-coalescing.d.ts +9 -0
- package/dist/api/compiler/transformers/nullish-coalescing.js +26 -0
- package/dist/api/compiler/transformers/object-rest-spread.d.ts +34 -0
- package/dist/api/compiler/transformers/object-rest-spread.js +411 -0
- package/dist/api/compiler/transformers/optional-catch.d.ts +9 -0
- package/dist/api/compiler/transformers/optional-catch.js +20 -0
- package/dist/api/compiler/transformers/optional-chain.d.ts +14 -0
- package/dist/api/compiler/transformers/optional-chain.js +188 -0
- package/dist/api/compiler/transformers/reference-resolver.d.ts +128 -0
- package/dist/api/compiler/transformers/reference-resolver.js +1155 -0
- package/dist/api/compiler/transformers/runtime-syntax.d.ts +71 -0
- package/dist/api/compiler/transformers/runtime-syntax.js +753 -0
- package/dist/api/compiler/transformers/subtree-facts.d.ts +9 -0
- package/dist/api/compiler/transformers/subtree-facts.js +203 -0
- package/dist/api/compiler/transformers/syntax-facts.d.ts +51 -0
- package/dist/api/compiler/transformers/syntax-facts.js +254 -0
- package/dist/api/compiler/transformers/tagged-template.d.ts +17 -0
- package/dist/api/compiler/transformers/tagged-template.js +148 -0
- package/dist/api/compiler/transformers/transformer.d.ts +17 -0
- package/dist/api/compiler/transformers/transformer.js +54 -0
- package/dist/api/compiler/transformers/type-eraser.d.ts +21 -0
- package/dist/api/compiler/transformers/type-eraser.js +346 -0
- package/dist/api/compiler/transformers/type-serialization.d.ts +20 -0
- package/dist/api/compiler/transformers/type-serialization.js +347 -0
- package/dist/api/compiler/transformers/using.d.ts +56 -0
- package/dist/api/compiler/transformers/using.js +453 -0
- package/dist/api/compiler/transformers/utilities.d.ts +50 -0
- package/dist/api/compiler/transformers/utilities.js +347 -0
- package/dist/api/compiler/transformers/visitor-base.d.ts +6 -0
- package/dist/api/compiler/transformers/visitor-base.js +817 -0
- package/dist/api/compiler/transformers/visitor-hooks.d.ts +29 -0
- package/dist/api/compiler/transformers/visitor-hooks.js +189 -0
- package/dist/api/compiler/tsconfig.d.ts +177 -0
- package/dist/api/compiler/tsconfig.js +1311 -0
- package/dist/api/compiler/type-printer.d.ts +15 -0
- package/dist/api/compiler/type-printer.js +74 -0
- package/dist/api/compiler/types.d.ts +87 -0
- package/dist/api/compiler/types.js +23 -0
- package/dist/api/compiler/unicode-identifiers.d.ts +2 -0
- package/dist/api/compiler/unicode-identifiers.js +209 -0
- package/dist/api/compiler/unicode-properties.d.ts +8 -0
- package/dist/api/compiler/unicode-properties.js +531 -0
- package/dist/api/compiler/vfs-match.d.ts +24 -0
- package/dist/api/compiler/vfs-match.js +587 -0
- package/dist/api/library/ast.d.ts +74 -0
- package/dist/api/library/ast.generated.d.ts +1145 -0
- package/dist/api/library/ast.generated.js +3 -0
- package/dist/api/library/ast.js +5 -0
- package/dist/api/library/checker.d.ts +51 -0
- package/dist/api/library/checker.js +318 -0
- package/dist/api/library/compiler-options.generated.d.ts +108 -0
- package/dist/api/library/compiler-options.generated.js +3 -0
- package/dist/api/library/diagnostics.d.ts +13 -0
- package/dist/api/library/diagnostics.js +50 -0
- package/dist/api/library/disk.d.ts +13 -0
- package/dist/api/library/disk.js +66 -0
- package/dist/api/library/enums.generated.d.ts +891 -0
- package/dist/api/library/enums.generated.js +916 -0
- package/dist/api/library/errors.d.ts +13 -0
- package/dist/api/library/errors.js +24 -0
- package/dist/api/library/host.d.ts +24 -0
- package/dist/api/library/host.js +52 -0
- package/dist/api/library/index.d.ts +14 -0
- package/dist/api/library/index.js +15 -0
- package/dist/api/library/nodes.d.ts +51 -0
- package/dist/api/library/nodes.js +196 -0
- package/dist/api/library/options.d.ts +144 -0
- package/dist/api/library/options.js +308 -0
- package/dist/api/library/parse.d.ts +19 -0
- package/dist/api/library/parse.js +41 -0
- package/dist/api/library/program.d.ts +21 -0
- package/dist/api/library/program.js +234 -0
- package/dist/api/library/symbols.d.ts +8 -0
- package/dist/api/library/symbols.js +11 -0
- package/dist/api/library/types.d.ts +313 -0
- package/dist/api/library/types.js +6 -0
- package/package.json +22 -8
- package/src/compiler/ast-utilities.ts +548 -0
- package/src/compiler/ast.ts +12862 -0
- package/src/compiler/astnav.ts +799 -0
- package/src/compiler/binder-utilities.ts +1392 -0
- package/src/compiler/binder.ts +2703 -0
- package/src/compiler/build-info.ts +1197 -0
- package/src/compiler/character-codes.ts +323 -0
- package/src/compiler/checker-calls.ts +2155 -0
- package/src/compiler/checker-classes.ts +706 -0
- package/src/compiler/checker-contextual.ts +1457 -0
- package/src/compiler/checker-declaration-order.ts +438 -0
- package/src/compiler/checker-declarations.ts +1194 -0
- package/src/compiler/checker-declared-types.ts +919 -0
- package/src/compiler/checker-decorators.ts +694 -0
- package/src/compiler/checker-deprecation.ts +359 -0
- package/src/compiler/checker-destructuring.ts +805 -0
- package/src/compiler/checker-elaboration.ts +477 -0
- package/src/compiler/checker-emit-helpers.ts +224 -0
- package/src/compiler/checker-emit-resolver.ts +769 -0
- package/src/compiler/checker-evaluator.ts +243 -0
- package/src/compiler/checker-expressions.ts +1831 -0
- package/src/compiler/checker-features.ts +361 -0
- package/src/compiler/checker-flow.ts +394 -0
- package/src/compiler/checker-functions.ts +1296 -0
- package/src/compiler/checker-generated-code.ts +227 -0
- package/src/compiler/checker-globals.ts +52 -0
- package/src/compiler/checker-grammar.ts +3584 -0
- package/src/compiler/checker-heritage.ts +1233 -0
- package/src/compiler/checker-inference.ts +2576 -0
- package/src/compiler/checker-iteration.ts +1206 -0
- package/src/compiler/checker-javascript.ts +502 -0
- package/src/compiler/checker-jsdoc.ts +360 -0
- package/src/compiler/checker-jsx.ts +1924 -0
- package/src/compiler/checker-literals.ts +61 -0
- package/src/compiler/checker-members.ts +2436 -0
- package/src/compiler/checker-modules.ts +2886 -0
- package/src/compiler/checker-narrowing.ts +3230 -0
- package/src/compiler/checker-object-literals.ts +575 -0
- package/src/compiler/checker-operators.ts +1422 -0
- package/src/compiler/checker-overloads.ts +328 -0
- package/src/compiler/checker-property-access.ts +906 -0
- package/src/compiler/checker-services.ts +1149 -0
- package/src/compiler/checker-signatures.ts +1032 -0
- package/src/compiler/checker-source-file.ts +732 -0
- package/src/compiler/checker-statements.ts +292 -0
- package/src/compiler/checker-super.ts +261 -0
- package/src/compiler/checker-symbol-types.ts +2107 -0
- package/src/compiler/checker-symbols.ts +2150 -0
- package/src/compiler/checker-type-factory.ts +2579 -0
- package/src/compiler/checker-type-nodes.ts +1033 -0
- package/src/compiler/checker-type-operators.ts +2502 -0
- package/src/compiler/checker-types.ts +2340 -0
- package/src/compiler/checker-unused.ts +642 -0
- package/src/compiler/checker-utilities.ts +161 -0
- package/src/compiler/checker.ts +1116 -0
- package/src/compiler/command-line.ts +436 -0
- package/src/compiler/compile-program.ts +439 -0
- package/src/compiler/decoder.ts +1209 -0
- package/src/compiler/diagnostic-locales.ts +86 -0
- package/src/compiler/diagnostic-messages.ts +2349 -0
- package/src/compiler/diagnostics.ts +897 -0
- package/src/compiler/emitter.ts +434 -0
- package/src/compiler/encoder.ts +1945 -0
- package/src/compiler/file-include.ts +673 -0
- package/src/compiler/file-loader.ts +1528 -0
- package/src/compiler/file-system.ts +143 -0
- package/src/compiler/flow.ts +89 -0
- package/src/compiler/help.ts +473 -0
- package/src/compiler/incremental.ts +2784 -0
- package/src/compiler/init.ts +141 -0
- package/src/compiler/instantiation.ts +894 -0
- package/src/compiler/jsdoc.ts +1386 -0
- package/src/compiler/link-tables.ts +98 -0
- package/src/compiler/locale-data.ts +203 -0
- package/src/compiler/locale.ts +307 -0
- package/src/compiler/locales/cs-CZ.ts +5 -0
- package/src/compiler/locales/de-DE.ts +5 -0
- package/src/compiler/locales/es-ES.ts +5 -0
- package/src/compiler/locales/fr-FR.ts +5 -0
- package/src/compiler/locales/it-IT.ts +5 -0
- package/src/compiler/locales/ja-JP.ts +5 -0
- package/src/compiler/locales/ko-KR.ts +5 -0
- package/src/compiler/locales/pl-PL.ts +5 -0
- package/src/compiler/locales/pt-BR.ts +5 -0
- package/src/compiler/locales/ru-RU.ts +5 -0
- package/src/compiler/locales/tr-TR.ts +5 -0
- package/src/compiler/locales/zh-CN.ts +5 -0
- package/src/compiler/locales/zh-TW.ts +5 -0
- package/src/compiler/module-resolution-types.ts +243 -0
- package/src/compiler/module-resolution.ts +2072 -0
- package/src/compiler/module-specifiers.ts +1491 -0
- package/src/compiler/name-resolver.ts +646 -0
- package/src/compiler/node-builder-names.ts +1069 -0
- package/src/compiler/node-builder-pseudo.ts +892 -0
- package/src/compiler/node-builder-reuse.ts +764 -0
- package/src/compiler/node-builder.ts +3425 -0
- package/src/compiler/option-declarations.ts +1560 -0
- package/src/compiler/options.ts +1576 -0
- package/src/compiler/output-paths.ts +334 -0
- package/src/compiler/package-json.ts +1083 -0
- package/src/compiler/parallel-check.ts +1951 -0
- package/src/compiler/parallel-parse.ts +590 -0
- package/src/compiler/parse-thread.ts +140 -0
- package/src/compiler/parser.ts +7716 -0
- package/src/compiler/path.ts +717 -0
- package/src/compiler/printer/async-helpers.ts +183 -0
- package/src/compiler/printer/auto-generate.ts +27 -0
- package/src/compiler/printer/decorator-helpers.ts +218 -0
- package/src/compiler/printer/emit-context.ts +679 -0
- package/src/compiler/printer/emit-flags.ts +64 -0
- package/src/compiler/printer/factory-base.ts +2577 -0
- package/src/compiler/printer/factory.ts +764 -0
- package/src/compiler/printer/helpers.ts +291 -0
- package/src/compiler/printer/name-generator.ts +372 -0
- package/src/compiler/printer/printer.ts +5072 -0
- package/src/compiler/printer/text-writer.ts +183 -0
- package/src/compiler/printer/utilities.ts +884 -0
- package/src/compiler/program-checker.ts +592 -0
- package/src/compiler/program-utilities.ts +435 -0
- package/src/compiler/program.ts +1419 -0
- package/src/compiler/pseudo-bigint.ts +62 -0
- package/src/compiler/regexp-checker.ts +1142 -0
- package/src/compiler/relations.ts +5149 -0
- package/src/compiler/reparser.ts +1566 -0
- package/src/compiler/scanner.ts +2951 -0
- package/src/compiler/show-config.ts +239 -0
- package/src/compiler/side-state.ts +125 -0
- package/src/compiler/sourcemap.ts +366 -0
- package/src/compiler/spelling.ts +122 -0
- package/src/compiler/symbol-accessibility.ts +1071 -0
- package/src/compiler/symbol.ts +439 -0
- package/src/compiler/symlinks.ts +137 -0
- package/src/compiler/syntax-kind.ts +391 -0
- package/src/compiler/thread-entry.ts +191 -0
- package/src/compiler/timeline.ts +53 -0
- package/src/compiler/transformers/alias-references.ts +757 -0
- package/src/compiler/transformers/async-utilities.ts +335 -0
- package/src/compiler/transformers/async.ts +838 -0
- package/src/compiler/transformers/class-fields.ts +2967 -0
- package/src/compiler/transformers/class-utilities.ts +324 -0
- package/src/compiler/transformers/commonjs-module.ts +1621 -0
- package/src/compiler/transformers/const-enum-inliner.ts +50 -0
- package/src/compiler/transformers/declarations-diagnostics.ts +832 -0
- package/src/compiler/transformers/declarations-pseudo.ts +966 -0
- package/src/compiler/transformers/declarations-resolver.ts +249 -0
- package/src/compiler/transformers/declarations-syntactic.ts +1859 -0
- package/src/compiler/transformers/declarations-tracker.ts +269 -0
- package/src/compiler/transformers/declarations.ts +3120 -0
- package/src/compiler/transformers/decorator-metadata.ts +697 -0
- package/src/compiler/transformers/decorator-utilities.ts +283 -0
- package/src/compiler/transformers/destructuring.ts +708 -0
- package/src/compiler/transformers/downlevel.ts +50 -0
- package/src/compiler/transformers/emit-resolver.ts +258 -0
- package/src/compiler/transformers/es-decorators.ts +2682 -0
- package/src/compiler/transformers/exponentiation.ts +80 -0
- package/src/compiler/transformers/external-module-info.ts +412 -0
- package/src/compiler/transformers/for-await.ts +687 -0
- package/src/compiler/transformers/import-elision.ts +152 -0
- package/src/compiler/transformers/jsx-entities.ts +256 -0
- package/src/compiler/transformers/jsx.ts +824 -0
- package/src/compiler/transformers/legacy-decorators.ts +726 -0
- package/src/compiler/transformers/logical-assignment.ts +75 -0
- package/src/compiler/transformers/module-utilities.ts +42 -0
- package/src/compiler/transformers/module.ts +474 -0
- package/src/compiler/transformers/named-evaluation.ts +389 -0
- package/src/compiler/transformers/nullish-coalescing.ts +35 -0
- package/src/compiler/transformers/object-rest-spread.ts +577 -0
- package/src/compiler/transformers/optional-catch.ts +29 -0
- package/src/compiler/transformers/optional-chain.ts +246 -0
- package/src/compiler/transformers/reference-resolver.ts +1201 -0
- package/src/compiler/transformers/runtime-syntax.ts +942 -0
- package/src/compiler/transformers/subtree-facts.ts +245 -0
- package/src/compiler/transformers/syntax-facts.ts +353 -0
- package/src/compiler/transformers/tagged-template.ts +167 -0
- package/src/compiler/transformers/transformer.ts +56 -0
- package/src/compiler/transformers/type-eraser.ts +520 -0
- package/src/compiler/transformers/type-serialization.ts +374 -0
- package/src/compiler/transformers/using.ts +613 -0
- package/src/compiler/transformers/utilities.ts +419 -0
- package/src/compiler/transformers/visitor-base.ts +1601 -0
- package/src/compiler/transformers/visitor-hooks.ts +252 -0
- package/src/compiler/tsc-build.ts +1418 -0
- package/src/compiler/tsc-cli.ts +666 -0
- package/src/compiler/tsc-compile.ts +437 -0
- package/src/compiler/tsc-watch.ts +854 -0
- package/src/compiler/tsconfig.ts +1574 -0
- package/src/compiler/type-printer.ts +110 -0
- package/src/compiler/types.ts +115 -0
- package/src/compiler/unicode-identifiers.ts +212 -0
- package/src/compiler/unicode-properties.ts +537 -0
- package/src/compiler/vfs-match.ts +597 -0
- package/src/compiler/xxh3.ts +650 -0
- package/src/library/ast.generated.ts +1685 -0
- package/src/library/ast.ts +104 -0
- package/src/library/checker.ts +384 -0
- package/src/library/compiler-options.generated.ts +114 -0
- package/src/library/diagnostics.ts +72 -0
- package/src/library/disk.ts +73 -0
- package/src/library/enums.generated.ts +1024 -0
- package/src/library/errors.ts +26 -0
- package/src/library/host.ts +63 -0
- package/src/library/index.ts +71 -0
- package/src/library/nodes.ts +232 -0
- package/src/library/options.ts +449 -0
- package/src/library/parse.ts +63 -0
- package/src/library/program.ts +293 -0
- package/src/library/symbols.ts +15 -0
- package/src/library/types.ts +359 -0
|
@@ -0,0 +1,584 @@
|
|
|
1
|
+
// Destructuring: types of binding elements and the types implied by binding patterns.
|
|
2
|
+
import { checkExternalEmitHelpers } from './checker-emit-helpers.js';
|
|
3
|
+
import { checkGrammarRestTrailingComma } from './checker-grammar.js';
|
|
4
|
+
import { markDestructuredPropertyAsReferenced } from './checker-unused.js';
|
|
5
|
+
import { getElements, getInitializer, getName, getProperties, getSymbol, getType, getFlowNode, StringLiteral, ParenthesizedExpression, ElementAccessExpression, } from './ast.js';
|
|
6
|
+
import { isLeftHandSideExpression } from './ast-utilities.js';
|
|
7
|
+
import { getFlowTypeOfReference, getDestructuringPropertyName, getTypeOfInitializer } from './checker-narrowing.js';
|
|
8
|
+
import { getRootDeclaration, isClassLike, isPartOfParameterDeclaration, isPrivateIdentifierClassElementDeclaration, } from './binder-utilities.js';
|
|
9
|
+
import { getSymbolId } from './symbol.js';
|
|
10
|
+
import { TupleElementInfo, } from './checker-types.js';
|
|
11
|
+
import { cloneTypeReference, createAnonymousType, createArrayType, createTupleTypeEx, getElementTypes, getTypeReferenceArity, tupleTargetOf, everyType, filterType, getNumberLiteralType, getUnionType, getUnionTypeEx, isTupleType, mapType, newIndexInfo, someType, typesOf, } from './checker-type-factory.js';
|
|
12
|
+
import { getIndexedAccessTypeEx, getIndexedAccessTypeOrUndefinedEx, getLiteralTypeFromProperty, getLiteralTypeFromPropertyName, isGenericIndexType, isGenericObjectType, } from './checker-type-operators.js';
|
|
13
|
+
import { getBaseConstraintOfType, getBaseConstraintOrType, mapToBaseConstraintOrType, getDeclarationModifierFlagsFromSymbol, getReducedType, getIndexInfosOfType, getPropertiesOfObjectType, getPropertiesOfType, getPropertyOfType, isArrayLikeType, } from './checker-members.js';
|
|
14
|
+
import { getGlobalTypeAliasSymbol, getSymbolOfDeclaration } from './checker-symbols.js';
|
|
15
|
+
import { getTypeForVariableLikeDeclaration, getTypeOfSymbol, addOptionality, getWidenedLiteralTypeForInitializer, widenTypeInferredFromInitializer, isReadonlySymbol, reportImplicitAny, declarationBelongsToPrivateAmbientMember, isOptionalDeclaration, } from './checker-symbol-types.js';
|
|
16
|
+
import { getTypeAliasInstantiation } from './checker-type-nodes.js';
|
|
17
|
+
import { isTypeAssignableTo } from './relations.js';
|
|
18
|
+
import { checkDeclarationInitializer, checkExpression, checkExpressionCached, checkExpressionEx, checkNonNullType, checkTypeAssignableToAndOptionallyElaborate, } from './checker-expressions.js';
|
|
19
|
+
import { checkIteratedTypeOrElementType, createIterableType } from './checker-iteration.js';
|
|
20
|
+
import { ScriptTarget } from './options.js';
|
|
21
|
+
import { checkBinaryExpression, checkReferenceExpression, removeDefinitelyFalsyTypes } from './checker-operators.js';
|
|
22
|
+
import { getNonNullableType, getTypeWithFacts, hasTypeFacts } from './checker-flow.js';
|
|
23
|
+
import { sliceTupleType } from './checker-signatures.js';
|
|
24
|
+
import { getPropertyNameFromType, isTypeUsableAsPropertyName, maybeTypeOfKind } from './checker-utilities.js';
|
|
25
|
+
import { checkPropertyAccessibility } from './checker-property-access.js';
|
|
26
|
+
function isBindingPatternNode(node) {
|
|
27
|
+
return (node !== undefined &&
|
|
28
|
+
(node.kind === 207 /* SyntaxKind.ObjectBindingPattern */ || node.kind === 208 /* SyntaxKind.ArrayBindingPattern */));
|
|
29
|
+
}
|
|
30
|
+
/** The type of a binding element, from the type of the declaration it destructures. */
|
|
31
|
+
export function getTypeForBindingElement(c, declaration) {
|
|
32
|
+
const pattern = declaration.parent;
|
|
33
|
+
const checkMode = declaration.dotDotDotToken !== undefined ? 32 /* CheckMode.RestBindingElement */ : 0 /* CheckMode.Normal */;
|
|
34
|
+
const parentType = getTypeForBindingElementParent(c, pattern.parent, checkMode);
|
|
35
|
+
if (parentType === undefined || parentType === c.errorType)
|
|
36
|
+
return parentType;
|
|
37
|
+
return getBindingElementTypeFromParentType(c, declaration, parentType, false);
|
|
38
|
+
}
|
|
39
|
+
/** The type of a destructured element narrowed like `init["name"]` at the position of its initializer. */
|
|
40
|
+
function getFlowTypeOfDestructuring(c, node, declaredType) {
|
|
41
|
+
const reference = getSyntheticElementAccess(c, node);
|
|
42
|
+
return reference !== undefined
|
|
43
|
+
? getFlowTypeOfReference(c, reference, declaredType, declaredType, undefined)
|
|
44
|
+
: declaredType;
|
|
45
|
+
}
|
|
46
|
+
function getSyntheticElementAccess(c, node) {
|
|
47
|
+
const parentAccess = getParentElementAccess(c, node);
|
|
48
|
+
if (parentAccess === undefined)
|
|
49
|
+
return undefined;
|
|
50
|
+
const flowNode = getFlowNode(parentAccess);
|
|
51
|
+
if (flowNode === undefined)
|
|
52
|
+
return undefined;
|
|
53
|
+
const propName = getDestructuringPropertyName(c, node);
|
|
54
|
+
if (propName === undefined)
|
|
55
|
+
return undefined;
|
|
56
|
+
const literal = new StringLiteral(propName, 0 /* TokenFlags.None */);
|
|
57
|
+
literal.pos = node.pos;
|
|
58
|
+
literal.end = node.end;
|
|
59
|
+
let lhs = parentAccess;
|
|
60
|
+
if (!isLeftHandSideExpression(parentAccess)) {
|
|
61
|
+
lhs = new ParenthesizedExpression(parentAccess);
|
|
62
|
+
lhs.pos = node.pos;
|
|
63
|
+
lhs.end = node.end;
|
|
64
|
+
}
|
|
65
|
+
const result = new ElementAccessExpression(lhs, undefined, literal, 0 /* NodeFlags.None */);
|
|
66
|
+
result.pos = node.pos;
|
|
67
|
+
result.end = node.end;
|
|
68
|
+
literal.parent = result;
|
|
69
|
+
result.parent = node;
|
|
70
|
+
if (lhs !== parentAccess)
|
|
71
|
+
lhs.parent = result;
|
|
72
|
+
result.flowNode = flowNode;
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
function getParentElementAccess(c, node) {
|
|
76
|
+
const ancestor = node.parent.parent;
|
|
77
|
+
switch (ancestor.kind) {
|
|
78
|
+
case 209 /* SyntaxKind.BindingElement */:
|
|
79
|
+
case 303 /* SyntaxKind.PropertyAssignment */:
|
|
80
|
+
return getSyntheticElementAccess(c, ancestor);
|
|
81
|
+
case 210 /* SyntaxKind.ArrayLiteralExpression */:
|
|
82
|
+
return getSyntheticElementAccess(c, node.parent);
|
|
83
|
+
case 261 /* SyntaxKind.VariableDeclaration */:
|
|
84
|
+
return getInitializer(ancestor);
|
|
85
|
+
case 227 /* SyntaxKind.BinaryExpression */:
|
|
86
|
+
return ancestor.right;
|
|
87
|
+
}
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
export function getTypeForBindingElementParent(c, node, checkMode) {
|
|
91
|
+
if (checkMode === 0 /* CheckMode.Normal */) {
|
|
92
|
+
// A resolved type can be used when it includes no optionality.
|
|
93
|
+
const symbol = getSymbolOfDeclaration(c, node);
|
|
94
|
+
if (symbol !== undefined) {
|
|
95
|
+
const cached = c.symbolTypes.get(getSymbolId(symbol));
|
|
96
|
+
if (cached !== undefined && !(c.strictNullChecks && isOptionalDeclaration(node)))
|
|
97
|
+
return cached;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return getTypeForVariableLikeDeclaration(c, node, false, checkMode);
|
|
101
|
+
}
|
|
102
|
+
export function getBindingElementTypeFromParentType(c, declaration, parentTypeIn, noTupleBoundsCheck) {
|
|
103
|
+
if ((parentTypeIn.flags & 1 /* TypeFlags.Any */) !== 0)
|
|
104
|
+
return parentTypeIn;
|
|
105
|
+
let parentType = parentTypeIn;
|
|
106
|
+
const pattern = declaration.parent;
|
|
107
|
+
const parentInitializer = getInitializer(pattern.parent);
|
|
108
|
+
// Ambient destructuring parameters are documentation only, so nullability isn't checked.
|
|
109
|
+
if (c.strictNullChecks && (declaration.flags & 8388608 /* NodeFlags.Ambient */) !== 0 && isPartOfParameterDeclaration(declaration))
|
|
110
|
+
parentType = getNonNullableType(c, parentType);
|
|
111
|
+
else if (c.strictNullChecks &&
|
|
112
|
+
parentInitializer !== undefined &&
|
|
113
|
+
!hasTypeFacts(c, getTypeOfInitializer(c, parentInitializer), 65536 /* TypeFacts.EQUndefined */))
|
|
114
|
+
parentType = getTypeWithFacts(c, parentType, 524288 /* TypeFacts.NEUndefined */);
|
|
115
|
+
const accessFlags = 32 /* AccessFlags.ExpressionPosition */ |
|
|
116
|
+
(noTupleBoundsCheck || declaration.initializer !== undefined ? 16 /* AccessFlags.AllowMissing */ : 0);
|
|
117
|
+
let t;
|
|
118
|
+
if (pattern.kind === 207 /* SyntaxKind.ObjectBindingPattern */) {
|
|
119
|
+
if (declaration.dotDotDotToken !== undefined) {
|
|
120
|
+
parentType = getReducedType(c, parentType);
|
|
121
|
+
if ((parentType.flags & 2 /* TypeFlags.Unknown */) !== 0 || !isValidSpreadType(c, parentType)) {
|
|
122
|
+
c.error(declaration, 832 /* Diagnostics.Rest_types_may_only_be_created_from_object_types */);
|
|
123
|
+
return c.errorType;
|
|
124
|
+
}
|
|
125
|
+
const literalMembers = [];
|
|
126
|
+
for (const e of getElements(pattern).nodes) {
|
|
127
|
+
const element = e;
|
|
128
|
+
if (element.dotDotDotToken === undefined)
|
|
129
|
+
literalMembers.push(element.propertyName ?? element.name);
|
|
130
|
+
}
|
|
131
|
+
t = getRestType(c, parentType, literalMembers, getSymbol(declaration));
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
const name = declaration.propertyName ?? declaration.name;
|
|
135
|
+
const declaredType = getIndexedAccessTypeEx(c, parentType, getLiteralTypeFromPropertyName(c, name) ?? c.errorType, accessFlags, name, undefined);
|
|
136
|
+
t = getFlowTypeOfDestructuring(c, declaration, declaredType);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
// Used when the tuple element for the index is missing; also checks that the parent is iterable.
|
|
141
|
+
const elementType = checkIteratedTypeOrElementType(c, 65 /* IterationUse.Destructuring */ | (declaration.dotDotDotToken !== undefined ? 0 : 128 /* IterationUse.PossiblyOutOfBounds */), parentType, c.undefinedType, pattern);
|
|
142
|
+
const index = getElements(pattern).nodes.indexOf(declaration);
|
|
143
|
+
if (declaration.dotDotDotToken !== undefined) {
|
|
144
|
+
// A rest element of a tuple gets the remaining elements; of an array, the same array type.
|
|
145
|
+
const baseConstraint = mapType(c, parentType, (u) => (u.flags & 117964800 /* TypeFlags.InstantiableNonPrimitive */) !== 0 ? getBaseConstraintOrType(c, u) : u);
|
|
146
|
+
t = everyType(baseConstraint, isTupleType)
|
|
147
|
+
? mapType(c, baseConstraint, (u) => sliceTupleType(c, u, index, 0))
|
|
148
|
+
: createArrayType(c, elementType);
|
|
149
|
+
}
|
|
150
|
+
else if (isArrayLikeType(c, parentType)) {
|
|
151
|
+
const declaredType = getIndexedAccessTypeOrUndefinedEx(c, parentType, getNumberLiteralType(c, index), accessFlags, declaration.name, undefined) ?? c.errorType;
|
|
152
|
+
t = getFlowTypeOfDestructuring(c, declaration, declaredType);
|
|
153
|
+
}
|
|
154
|
+
else
|
|
155
|
+
t = elementType;
|
|
156
|
+
}
|
|
157
|
+
if (declaration.initializer === undefined)
|
|
158
|
+
return t;
|
|
159
|
+
if (getType(walkUpBindingElementsAndPatterns(declaration)) !== undefined) {
|
|
160
|
+
// A default without undefined removes undefined from an annotated type.
|
|
161
|
+
if (c.strictNullChecks && !hasTypeFacts(c, checkDeclarationInitializer(c, declaration), 16777216 /* TypeFacts.IsUndefined */))
|
|
162
|
+
return getNonUndefinedType(c, t);
|
|
163
|
+
return t;
|
|
164
|
+
}
|
|
165
|
+
return widenTypeInferredFromInitializer(c, declaration, getUnionTypeEx(c, [getNonUndefinedType(c, t), checkDeclarationInitializer(c, declaration)], 2 /* UnionReduction.Subtype */, undefined, undefined));
|
|
166
|
+
}
|
|
167
|
+
/** The binding pattern's root declaration: the variable or parameter it destructures. */
|
|
168
|
+
function walkUpBindingElementsAndPatterns(node) {
|
|
169
|
+
let current = node.parent;
|
|
170
|
+
while (current.kind === 209 /* SyntaxKind.BindingElement */ || isBindingPatternNode(current))
|
|
171
|
+
current = current.parent;
|
|
172
|
+
return current;
|
|
173
|
+
}
|
|
174
|
+
/** `t` without undefined, also when it's a generic type whose constraint includes undefined. */
|
|
175
|
+
export function getNonUndefinedType(c, t) {
|
|
176
|
+
const typeOrConstraint = someType(t, (u) => isGenericTypeWithUndefinedConstraint(c, u))
|
|
177
|
+
? mapType(c, t, (u) => ((u.flags & 132644864 /* TypeFlags.Instantiable */) !== 0 ? getBaseConstraintOrType(c, u) : u))
|
|
178
|
+
: t;
|
|
179
|
+
return getTypeWithFacts(c, typeOrConstraint, 524288 /* TypeFacts.NEUndefined */);
|
|
180
|
+
}
|
|
181
|
+
function isGenericTypeWithUndefinedConstraint(c, t) {
|
|
182
|
+
if ((t.flags & 132644864 /* TypeFlags.Instantiable */) === 0)
|
|
183
|
+
return false;
|
|
184
|
+
const constraint = getBaseConstraintOfType(c, t);
|
|
185
|
+
return constraint !== undefined && maybeTypeOfKind(constraint, 4 /* TypeFlags.Undefined */);
|
|
186
|
+
}
|
|
187
|
+
/** The type implied by a binding pattern, for declarations without annotations or initializers. */
|
|
188
|
+
export function getTypeFromBindingPattern(c, pattern, includePatternInType, reportErrors) {
|
|
189
|
+
// References to the pattern's own elements in its initializers are `any` while its type is a contextual type.
|
|
190
|
+
if (includePatternInType)
|
|
191
|
+
c.contextualBindingPatterns.push(pattern);
|
|
192
|
+
const result = pattern.kind === 207 /* SyntaxKind.ObjectBindingPattern */
|
|
193
|
+
? getTypeFromObjectBindingPattern(c, pattern, includePatternInType, reportErrors)
|
|
194
|
+
: getTypeFromArrayBindingPattern(c, pattern, includePatternInType, reportErrors);
|
|
195
|
+
if (includePatternInType)
|
|
196
|
+
c.contextualBindingPatterns.pop();
|
|
197
|
+
return result;
|
|
198
|
+
}
|
|
199
|
+
function getTypeFromObjectBindingPattern(c, pattern, includePatternInType, reportErrors) {
|
|
200
|
+
const members = new Map();
|
|
201
|
+
const indexInfos = [];
|
|
202
|
+
let objectFlags = 128 /* ObjectFlags.ObjectLiteral */ | 131072 /* ObjectFlags.ContainsObjectOrArrayLiteral */;
|
|
203
|
+
for (const node of getElements(pattern).nodes) {
|
|
204
|
+
const e = node;
|
|
205
|
+
if (e.dotDotDotToken !== undefined) {
|
|
206
|
+
indexInfos.push(newIndexInfo(c.stringType, c.anyType, false, undefined));
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
const exprType = getLiteralTypeFromPropertyName(c, e.propertyName ?? e.name) ?? c.errorType;
|
|
210
|
+
if (!isTypeUsableAsPropertyName(exprType)) {
|
|
211
|
+
objectFlags |= 512 /* ObjectFlags.ObjectLiteralPatternWithComputedProperties */;
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
const flags = 4 /* SymbolFlags.Property */ | (e.initializer !== undefined ? 16777216 /* SymbolFlags.Optional */ : 0);
|
|
215
|
+
const symbol = c.newSymbol(flags, getPropertyNameFromType(exprType));
|
|
216
|
+
c.symbolTypes.set(getSymbolId(symbol), getTypeFromBindingElement(c, e, includePatternInType, reportErrors));
|
|
217
|
+
members.set(symbol.name, symbol);
|
|
218
|
+
}
|
|
219
|
+
const result = createAnonymousType(c, undefined, members, [], [], indexInfos);
|
|
220
|
+
result.objectFlags |= objectFlags;
|
|
221
|
+
if (includePatternInType) {
|
|
222
|
+
c.patternForType.set(result, pattern);
|
|
223
|
+
result.objectFlags |= 131072 /* ObjectFlags.ContainsObjectOrArrayLiteral */;
|
|
224
|
+
}
|
|
225
|
+
return result;
|
|
226
|
+
}
|
|
227
|
+
function getTypeFromArrayBindingPattern(c, pattern, includePatternInType, reportErrors) {
|
|
228
|
+
const elements = getElements(pattern).nodes;
|
|
229
|
+
const last = elements.length > 0 ? elements[elements.length - 1] : undefined;
|
|
230
|
+
const restElement = last !== undefined &&
|
|
231
|
+
last.kind === 209 /* SyntaxKind.BindingElement */ &&
|
|
232
|
+
last.dotDotDotToken !== undefined
|
|
233
|
+
? last
|
|
234
|
+
: undefined;
|
|
235
|
+
if (elements.length === 0 || (elements.length === 1 && restElement !== undefined))
|
|
236
|
+
return c.languageVersion >= ScriptTarget.ES2015 ? createIterableType(c, c.anyType) : c.anyArrayType;
|
|
237
|
+
let minLength = 0;
|
|
238
|
+
for (let i = elements.length - 1; i >= 0; i--) {
|
|
239
|
+
const e = elements[i];
|
|
240
|
+
if (!(e === restElement || getName(e) === undefined || getInitializer(e) !== undefined)) {
|
|
241
|
+
minLength = i + 1;
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const types = [];
|
|
246
|
+
const infos = [];
|
|
247
|
+
for (let i = 0; i < elements.length; i++) {
|
|
248
|
+
const e = elements[i];
|
|
249
|
+
types.push(
|
|
250
|
+
// Omitted elements are binding elements without a name.
|
|
251
|
+
getName(e) === undefined
|
|
252
|
+
? c.anyType
|
|
253
|
+
: getTypeFromBindingElement(c, e, includePatternInType, reportErrors));
|
|
254
|
+
const flags = e === restElement ? 4 /* ElementFlags.Rest */ : i >= minLength ? 2 /* ElementFlags.Optional */ : 1 /* ElementFlags.Required */;
|
|
255
|
+
infos.push(new TupleElementInfo(flags, undefined));
|
|
256
|
+
}
|
|
257
|
+
const result = createTupleTypeEx(c, types, infos, false);
|
|
258
|
+
if (!includePatternInType)
|
|
259
|
+
return result;
|
|
260
|
+
const clone = cloneTypeReference(c, result);
|
|
261
|
+
c.patternForType.set(clone, pattern);
|
|
262
|
+
clone.objectFlags |= 131072 /* ObjectFlags.ContainsObjectOrArrayLiteral */;
|
|
263
|
+
return clone;
|
|
264
|
+
}
|
|
265
|
+
function getTypeFromBindingElement(c, element, includePatternInType, reportErrors) {
|
|
266
|
+
if (element.initializer !== undefined) {
|
|
267
|
+
// The implied type doesn't depend on context: the initializer is checked without a contextual
|
|
268
|
+
// type, or with the type implied by the element's own pattern.
|
|
269
|
+
const contextualType = isBindingPatternNode(element.name)
|
|
270
|
+
? getTypeFromBindingPattern(c, element.name, true, false)
|
|
271
|
+
: c.unknownType;
|
|
272
|
+
const t = checkDeclarationInitializer(c, element, 0 /* CheckMode.Normal */, contextualType);
|
|
273
|
+
return addOptionality(c, getWidenedLiteralTypeForInitializer(c, element, t), false, true);
|
|
274
|
+
}
|
|
275
|
+
if (isBindingPatternNode(element.name))
|
|
276
|
+
return getTypeFromBindingPattern(c, element.name, includePatternInType, reportErrors);
|
|
277
|
+
if (reportErrors && c.noImplicitAny && !declarationBelongsToPrivateAmbientMember(element))
|
|
278
|
+
reportImplicitAny(c, element, c.anyType);
|
|
279
|
+
return includePatternInType ? c.nonInferrableAnyType : c.anyType;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* The initializer type of a parameter or its binding element, padded with the members its binding
|
|
283
|
+
* pattern defaults or binds past the end of a tuple.
|
|
284
|
+
*/
|
|
285
|
+
export function padParameterInitializerType(c, declaration, t) {
|
|
286
|
+
if (getRootDeclaration(declaration).kind !== 170 /* SyntaxKind.Parameter */)
|
|
287
|
+
return t;
|
|
288
|
+
const name = getName(declaration);
|
|
289
|
+
if (name === undefined)
|
|
290
|
+
return t;
|
|
291
|
+
if (name.kind === 207 /* SyntaxKind.ObjectBindingPattern */ && (t.objectFlags & 128 /* ObjectFlags.ObjectLiteral */) !== 0)
|
|
292
|
+
return padObjectLiteralType(c, t, name);
|
|
293
|
+
if (name.kind === 208 /* SyntaxKind.ArrayBindingPattern */ && isTupleType(t))
|
|
294
|
+
return padTupleType(c, t, name);
|
|
295
|
+
return t;
|
|
296
|
+
}
|
|
297
|
+
/** An object literal type with optional properties added for the pattern's defaulted elements it lacks. */
|
|
298
|
+
function padObjectLiteralType(c, t, pattern) {
|
|
299
|
+
const missingElements = [];
|
|
300
|
+
for (const node of getElements(pattern).nodes) {
|
|
301
|
+
const e = node;
|
|
302
|
+
if (e.initializer === undefined)
|
|
303
|
+
continue;
|
|
304
|
+
const name = getPropertyNameFromBindingElement(c, e);
|
|
305
|
+
if (name !== undefined && getPropertyOfType(c, t, name) === undefined)
|
|
306
|
+
missingElements.push(e);
|
|
307
|
+
}
|
|
308
|
+
if (missingElements.length === 0)
|
|
309
|
+
return t;
|
|
310
|
+
const members = new Map();
|
|
311
|
+
for (const prop of getPropertiesOfObjectType(c, t))
|
|
312
|
+
members.set(prop.name, prop);
|
|
313
|
+
for (const e of missingElements) {
|
|
314
|
+
const symbol = c.newSymbol(4 /* SymbolFlags.Property */ | 16777216 /* SymbolFlags.Optional */, getPropertyNameFromBindingElement(c, e));
|
|
315
|
+
c.symbolTypes.set(getSymbolId(symbol), getTypeFromBindingElement(c, e, false, false));
|
|
316
|
+
members.set(symbol.name, symbol);
|
|
317
|
+
}
|
|
318
|
+
const result = createAnonymousType(c, t.symbol, members, [], [], getIndexInfosOfType(c, t));
|
|
319
|
+
result.objectFlags = (t.objectFlags & ~-2147483648 /* ObjectFlags.SideState */) | (result.objectFlags & -2147483648 /* ObjectFlags.SideState */);
|
|
320
|
+
return result;
|
|
321
|
+
}
|
|
322
|
+
function getPropertyNameFromBindingElement(c, e) {
|
|
323
|
+
const exprType = getLiteralTypeFromPropertyName(c, e.propertyName ?? e.name);
|
|
324
|
+
return exprType !== undefined && isTypeUsableAsPropertyName(exprType) ? getPropertyNameFromType(exprType) : undefined;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* A parameter's tuple initializer type, padded with optional elements for the pattern's elements
|
|
328
|
+
* past its end, so `([x, y] = [1])` gets `[number, any?]`.
|
|
329
|
+
*/
|
|
330
|
+
export function padTupleType(c, t, pattern) {
|
|
331
|
+
const patternElements = getElements(pattern).nodes;
|
|
332
|
+
const target = tupleTargetOf(t);
|
|
333
|
+
const arity = getTypeReferenceArity(t);
|
|
334
|
+
if ((target.combinedFlags & 12 /* ElementFlags.Variable */) !== 0 || arity >= patternElements.length)
|
|
335
|
+
return t;
|
|
336
|
+
const elementTypes = getElementTypes(c, t).slice();
|
|
337
|
+
const elementInfos = target.elementInfos.slice();
|
|
338
|
+
for (let i = arity; i < patternElements.length; i++) {
|
|
339
|
+
const e = patternElements[i];
|
|
340
|
+
if (i < patternElements.length - 1 ||
|
|
341
|
+
!(e.kind === 209 /* SyntaxKind.BindingElement */ && e.dotDotDotToken !== undefined)) {
|
|
342
|
+
const omitted = e.kind === 233 /* SyntaxKind.OmittedExpression */;
|
|
343
|
+
elementTypes.push(!omitted && hasDefaultValue(e) ? getTypeFromBindingElement(c, e, false, false) : c.anyType);
|
|
344
|
+
elementInfos.push(new TupleElementInfo(2 /* ElementFlags.Optional */, undefined));
|
|
345
|
+
if (!omitted && !hasDefaultValue(e))
|
|
346
|
+
reportImplicitAny(c, e, c.anyType);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return createTupleTypeEx(c, elementTypes, elementInfos, target.readonly);
|
|
350
|
+
}
|
|
351
|
+
// ---- Destructuring assignments
|
|
352
|
+
/** Checks an assignment of `sourceType` to a target, which may be an object or array literal pattern. */
|
|
353
|
+
export function checkDestructuringAssignment(c, node, sourceTypeIn, checkMode, rightIsThis) {
|
|
354
|
+
let sourceType = sourceTypeIn;
|
|
355
|
+
let target = node;
|
|
356
|
+
if (node.kind === 304 /* SyntaxKind.ShorthandPropertyAssignment */) {
|
|
357
|
+
const shorthand = node;
|
|
358
|
+
const initializer = shorthand.objectAssignmentInitializer;
|
|
359
|
+
if (initializer !== undefined) {
|
|
360
|
+
// A default of a type without undefined removes undefined from the assigned type.
|
|
361
|
+
if (c.strictNullChecks && !hasTypeFacts(c, checkExpression(c, initializer), 16777216 /* TypeFacts.IsUndefined */))
|
|
362
|
+
sourceType = getTypeWithFacts(c, sourceType, 524288 /* TypeFacts.NEUndefined */);
|
|
363
|
+
checkShorthandDefault(c, shorthand, initializer, checkMode);
|
|
364
|
+
}
|
|
365
|
+
target = shorthand.name;
|
|
366
|
+
}
|
|
367
|
+
if (target.kind === 227 /* SyntaxKind.BinaryExpression */ &&
|
|
368
|
+
target.operatorToken.kind === 63 /* SyntaxKind.EqualsToken */) {
|
|
369
|
+
checkBinaryExpression(c, target, checkMode);
|
|
370
|
+
target = target.left;
|
|
371
|
+
if (c.strictNullChecks)
|
|
372
|
+
sourceType = getTypeWithFacts(c, sourceType, 524288 /* TypeFacts.NEUndefined */);
|
|
373
|
+
}
|
|
374
|
+
if (target.kind === 211 /* SyntaxKind.ObjectLiteralExpression */)
|
|
375
|
+
return checkObjectLiteralAssignment(c, target, sourceType, rightIsThis);
|
|
376
|
+
if (target.kind === 210 /* SyntaxKind.ArrayLiteralExpression */)
|
|
377
|
+
return checkArrayLiteralAssignment(c, target, sourceType, checkMode);
|
|
378
|
+
return checkReferenceAssignment(c, target, sourceType, checkMode);
|
|
379
|
+
}
|
|
380
|
+
/** Checks `name = initializer` in a shorthand property of an assignment pattern. */
|
|
381
|
+
function checkShorthandDefault(c, node, initializer, checkMode) {
|
|
382
|
+
const leftType = checkExpressionCached(c, node.name);
|
|
383
|
+
const rightType = checkExpressionEx(c, initializer, checkMode);
|
|
384
|
+
if (checkReferenceExpression(c, node.name, 538 /* Diagnostics.The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access */, 911 /* Diagnostics.The_left_hand_side_of_an_assignment_expression_may_not_be_an_optional_property_access */))
|
|
385
|
+
checkTypeAssignableToAndOptionallyElaborate(c, rightType, leftType, node.name, initializer);
|
|
386
|
+
}
|
|
387
|
+
function checkObjectLiteralAssignment(c, node, sourceType, rightIsThis) {
|
|
388
|
+
const properties = getProperties(node).nodes;
|
|
389
|
+
if (c.strictNullChecks && properties.length === 0)
|
|
390
|
+
return checkNonNullType(c, sourceType, node);
|
|
391
|
+
for (let i = 0; i < properties.length; i++)
|
|
392
|
+
checkObjectLiteralDestructuringPropertyAssignment(c, properties, sourceType, i, rightIsThis);
|
|
393
|
+
return sourceType;
|
|
394
|
+
}
|
|
395
|
+
function checkObjectLiteralDestructuringPropertyAssignment(c, properties, objectLiteralType, propertyIndex, rightIsThis) {
|
|
396
|
+
const property = properties[propertyIndex];
|
|
397
|
+
if (property.kind === 303 /* SyntaxKind.PropertyAssignment */ || property.kind === 304 /* SyntaxKind.ShorthandPropertyAssignment */) {
|
|
398
|
+
const name = getName(property);
|
|
399
|
+
markDestructuredPropertyAsReferenced(c, objectLiteralType, name, property, rightIsThis);
|
|
400
|
+
const exprType = getLiteralTypeFromPropertyName(c, name) ?? c.errorType;
|
|
401
|
+
if (isTypeUsableAsPropertyName(exprType)) {
|
|
402
|
+
const prop = getPropertyOfType(c, objectLiteralType, getPropertyNameFromType(exprType));
|
|
403
|
+
if (prop !== undefined)
|
|
404
|
+
checkPropertyAccessibility(c, property, false, true, objectLiteralType, prop);
|
|
405
|
+
}
|
|
406
|
+
const elementType = getIndexedAccessTypeEx(c, objectLiteralType, exprType, 32 /* AccessFlags.ExpressionPosition */ | (hasDefaultValue(property) ? 16 /* AccessFlags.AllowMissing */ : 0), name, undefined);
|
|
407
|
+
const expr = property.kind === 303 /* SyntaxKind.PropertyAssignment */ ? property.initializer : property;
|
|
408
|
+
checkDestructuringAssignment(c, expr, getFlowTypeOfDestructuring(c, property, elementType), 0 /* CheckMode.Normal */, false);
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
if (property.kind === 305 /* SyntaxKind.SpreadAssignment */) {
|
|
412
|
+
if (propertyIndex < properties.length - 1) {
|
|
413
|
+
c.error(property, 628 /* Diagnostics.A_rest_element_must_be_last_in_a_destructuring_pattern */);
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
if (c.languageVersion < ScriptTarget.ES2018)
|
|
417
|
+
checkExternalEmitHelpers(c, property, 1 /* ExternalEmitHelpers.Rest */);
|
|
418
|
+
const nonRestNames = [];
|
|
419
|
+
for (const other of properties)
|
|
420
|
+
if (other.kind !== 305 /* SyntaxKind.SpreadAssignment */)
|
|
421
|
+
nonRestNames.push(getName(other));
|
|
422
|
+
const t = getRestType(c, objectLiteralType, nonRestNames, objectLiteralType.symbol);
|
|
423
|
+
checkGrammarRestTrailingComma(c, property.parent, getProperties(property.parent));
|
|
424
|
+
checkDestructuringAssignment(c, property.expression, t, 0 /* CheckMode.Normal */, false);
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
c.error(property, 102 /* Diagnostics.Property_assignment_expected */);
|
|
428
|
+
}
|
|
429
|
+
function checkArrayLiteralAssignment(c, node, sourceType, checkMode) {
|
|
430
|
+
const elements = getElements(node).nodes;
|
|
431
|
+
// Used when the tuple element for an index is missing; also checks that the source is iterable.
|
|
432
|
+
const possiblyOutOfBoundsType = checkIteratedTypeOrElementType(c, 65 /* IterationUse.Destructuring */ | 128 /* IterationUse.PossiblyOutOfBounds */, sourceType, c.undefinedType, node);
|
|
433
|
+
let inBoundsType = c.noUncheckedIndexedAccess ? undefined : possiblyOutOfBoundsType;
|
|
434
|
+
for (let i = 0; i < elements.length; i++) {
|
|
435
|
+
let t = possiblyOutOfBoundsType;
|
|
436
|
+
if (elements[i].kind === 231 /* SyntaxKind.SpreadElement */) {
|
|
437
|
+
if (inBoundsType === undefined)
|
|
438
|
+
inBoundsType = checkIteratedTypeOrElementType(c, 65 /* IterationUse.Destructuring */, sourceType, c.undefinedType, node);
|
|
439
|
+
t = inBoundsType;
|
|
440
|
+
}
|
|
441
|
+
checkArrayLiteralDestructuringElementAssignment(c, elements, sourceType, i, t, checkMode);
|
|
442
|
+
}
|
|
443
|
+
return sourceType;
|
|
444
|
+
}
|
|
445
|
+
function checkArrayLiteralDestructuringElementAssignment(c, elements, sourceType, elementIndex, elementType, checkMode) {
|
|
446
|
+
const element = elements[elementIndex];
|
|
447
|
+
if (element.kind === 233 /* SyntaxKind.OmittedExpression */)
|
|
448
|
+
return;
|
|
449
|
+
if (element.kind !== 231 /* SyntaxKind.SpreadElement */) {
|
|
450
|
+
if (isArrayLikeType(c, sourceType)) {
|
|
451
|
+
const indexType = getNumberLiteralType(c, elementIndex);
|
|
452
|
+
const accessFlags = 32 /* AccessFlags.ExpressionPosition */ | (hasDefaultValue(element) ? 16 /* AccessFlags.AllowMissing */ : 0);
|
|
453
|
+
// Element access targets would be mistaken for the access itself.
|
|
454
|
+
const accessNode = element.kind === 213 /* SyntaxKind.ElementAccessExpression */ ? undefined : element;
|
|
455
|
+
const t = getIndexedAccessTypeOrUndefinedEx(c, sourceType, indexType, accessFlags, accessNode, undefined) ?? c.errorType;
|
|
456
|
+
const assigned = hasDefaultValue(element) ? getTypeWithFacts(c, t, 524288 /* TypeFacts.NEUndefined */) : t;
|
|
457
|
+
checkDestructuringAssignment(c, element, getFlowTypeOfDestructuring(c, element, assigned), checkMode, false);
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
checkDestructuringAssignment(c, element, elementType, checkMode, false);
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
if (elementIndex < elements.length - 1) {
|
|
464
|
+
c.error(element, 628 /* Diagnostics.A_rest_element_must_be_last_in_a_destructuring_pattern */);
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
const restExpression = element.expression;
|
|
468
|
+
if (restExpression.kind === 227 /* SyntaxKind.BinaryExpression */ &&
|
|
469
|
+
restExpression.operatorToken.kind === 63 /* SyntaxKind.EqualsToken */) {
|
|
470
|
+
c.error(restExpression.operatorToken, 142 /* Diagnostics.A_rest_element_cannot_have_an_initializer */);
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
checkGrammarRestTrailingComma(c, element, getElements(element.parent));
|
|
474
|
+
const t = everyType(sourceType, isTupleType)
|
|
475
|
+
? mapType(c, sourceType, (u) => sliceTupleType(c, u, elementIndex, 0))
|
|
476
|
+
: createArrayType(c, elementType);
|
|
477
|
+
checkDestructuringAssignment(c, restExpression, t, checkMode, false);
|
|
478
|
+
}
|
|
479
|
+
function checkReferenceAssignment(c, target, sourceType, checkMode) {
|
|
480
|
+
const targetType = checkExpressionEx(c, target, checkMode);
|
|
481
|
+
const inRest = target.parent.kind === 305 /* SyntaxKind.SpreadAssignment */;
|
|
482
|
+
if (checkReferenceExpression(c, target, inRest
|
|
483
|
+
? 833 /* Diagnostics.The_target_of_an_object_rest_assignment_must_be_a_variable_or_a_property_access */
|
|
484
|
+
: 538 /* Diagnostics.The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access */, inRest
|
|
485
|
+
? 910 /* Diagnostics.The_target_of_an_object_rest_assignment_may_not_be_an_optional_property_access */
|
|
486
|
+
: 911 /* Diagnostics.The_left_hand_side_of_an_assignment_expression_may_not_be_an_optional_property_access */))
|
|
487
|
+
checkTypeAssignableToAndOptionallyElaborate(c, sourceType, targetType, target, target);
|
|
488
|
+
return sourceType;
|
|
489
|
+
}
|
|
490
|
+
/** Whether a destructuring element has a default value. */
|
|
491
|
+
export function hasDefaultValue(node) {
|
|
492
|
+
switch (node.kind) {
|
|
493
|
+
case 209 /* SyntaxKind.BindingElement */:
|
|
494
|
+
return node.initializer !== undefined;
|
|
495
|
+
case 303 /* SyntaxKind.PropertyAssignment */:
|
|
496
|
+
return hasDefaultValue(node.initializer);
|
|
497
|
+
case 304 /* SyntaxKind.ShorthandPropertyAssignment */:
|
|
498
|
+
return node.objectAssignmentInitializer !== undefined;
|
|
499
|
+
case 227 /* SyntaxKind.BinaryExpression */:
|
|
500
|
+
return node.operatorToken.kind === 63 /* SyntaxKind.EqualsToken */;
|
|
501
|
+
}
|
|
502
|
+
return false;
|
|
503
|
+
}
|
|
504
|
+
// ---- Rest types
|
|
505
|
+
/** The type of an object rest element: `source` without the named properties. */
|
|
506
|
+
export function getRestType(c, sourceIn, properties, symbol) {
|
|
507
|
+
const source = filterType(c, sourceIn, (t) => (t.flags & 12 /* TypeFlags.Nullable */) === 0);
|
|
508
|
+
if ((source.flags & 262144 /* TypeFlags.Never */) !== 0)
|
|
509
|
+
return c.emptyObjectType;
|
|
510
|
+
if ((source.flags & 134217728 /* TypeFlags.Union */) !== 0)
|
|
511
|
+
return mapType(c, source, (t) => getRestType(c, t, properties, symbol));
|
|
512
|
+
const omitKeys = [];
|
|
513
|
+
for (const p of properties)
|
|
514
|
+
omitKeys.push(getLiteralTypeFromPropertyName(c, p) ?? c.errorType);
|
|
515
|
+
let omitKeyType = getUnionType(c, omitKeys);
|
|
516
|
+
const spreadable = [];
|
|
517
|
+
const unspreadableKeys = [];
|
|
518
|
+
for (const prop of getPropertiesOfType(c, source)) {
|
|
519
|
+
const literal = getLiteralTypeFromProperty(c, prop, 19456 /* TypeFlags.StringOrNumberLiteralOrUnique */, false);
|
|
520
|
+
if (!isTypeAssignableTo(c, literal, omitKeyType) &&
|
|
521
|
+
(getDeclarationModifierFlagsFromSymbol(c, prop, false) & (2 /* ModifierFlags.Private */ | 4 /* ModifierFlags.Protected */)) ===
|
|
522
|
+
0 &&
|
|
523
|
+
isSpreadableProperty(prop))
|
|
524
|
+
spreadable.push(prop);
|
|
525
|
+
else
|
|
526
|
+
unspreadableKeys.push(literal);
|
|
527
|
+
}
|
|
528
|
+
if (isGenericObjectType(c, source) || isGenericIndexType(c, omitKeyType)) {
|
|
529
|
+
// Members a rest element never receives, like methods, are omitted explicitly as well.
|
|
530
|
+
if (unspreadableKeys.length !== 0)
|
|
531
|
+
omitKeyType = getUnionType(c, [omitKeyType, ...unspreadableKeys]);
|
|
532
|
+
if ((omitKeyType.flags & 262144 /* TypeFlags.Never */) !== 0)
|
|
533
|
+
return source;
|
|
534
|
+
const omit = getGlobalTypeAliasSymbol(c, 'Omit', 2, true);
|
|
535
|
+
if (omit === undefined)
|
|
536
|
+
return c.errorType;
|
|
537
|
+
return getTypeAliasInstantiation(c, omit, [source, omitKeyType], undefined);
|
|
538
|
+
}
|
|
539
|
+
const members = new Map();
|
|
540
|
+
for (const prop of spreadable)
|
|
541
|
+
members.set(prop.name, getSpreadSymbol(c, prop, false));
|
|
542
|
+
const result = createAnonymousType(c, symbol, members, [], [], getIndexInfosOfType(c, source));
|
|
543
|
+
result.objectFlags |= 8388608 /* ObjectFlags.ObjectRestType */;
|
|
544
|
+
return result;
|
|
545
|
+
}
|
|
546
|
+
/** Approximates own properties: non-methods, plus methods declared outside classes. */
|
|
547
|
+
export function isSpreadableProperty(prop) {
|
|
548
|
+
const notMethodOrAccessor = (prop.flags & (8192 /* SymbolFlags.Method */ | 32768 /* SymbolFlags.GetAccessor */ | 65536 /* SymbolFlags.SetAccessor */)) === 0;
|
|
549
|
+
let hasPrivateName = false;
|
|
550
|
+
let inClass = false;
|
|
551
|
+
for (const d of prop.declarations) {
|
|
552
|
+
if (isPrivateIdentifierClassElementDeclaration(d))
|
|
553
|
+
hasPrivateName = true;
|
|
554
|
+
if (d.parent !== undefined && isClassLike(d.parent))
|
|
555
|
+
inClass = true;
|
|
556
|
+
}
|
|
557
|
+
return (!hasPrivateName && notMethodOrAccessor) || !inClass;
|
|
558
|
+
}
|
|
559
|
+
/** `prop` as a member of a spread or rest type, with the given readonlyness. */
|
|
560
|
+
export function getSpreadSymbol(c, prop, readonly) {
|
|
561
|
+
const isSetonlyAccessor = (prop.flags & 65536 /* SymbolFlags.SetAccessor */) !== 0 && (prop.flags & 32768 /* SymbolFlags.GetAccessor */) === 0;
|
|
562
|
+
if (!isSetonlyAccessor && readonly === isReadonlySymbol(c, prop))
|
|
563
|
+
return prop;
|
|
564
|
+
const result = c.newSymbolWithCheckFlags(4 /* SymbolFlags.Property */ | (prop.flags & 16777216 /* SymbolFlags.Optional */), prop.name, (prop.checkFlags & 4096 /* CheckFlags.Late */) | (readonly ? 8 /* CheckFlags.Readonly */ : 0));
|
|
565
|
+
const id = getSymbolId(result);
|
|
566
|
+
c.symbolTypes.set(id, isSetonlyAccessor ? c.undefinedType : getTypeOfSymbol(c, prop));
|
|
567
|
+
result.declarations = prop.declarations;
|
|
568
|
+
c.symbolNameTypes.set(id, c.symbolNameTypes.get(getSymbolId(prop)));
|
|
569
|
+
c.symbolSyntheticOrigins.set(id, prop);
|
|
570
|
+
return result;
|
|
571
|
+
}
|
|
572
|
+
/** Whether a type may be spread into an object or destructured by an object rest element. */
|
|
573
|
+
export function isValidSpreadType(c, t) {
|
|
574
|
+
const s = removeDefinitelyFalsyTypes(c, mapToBaseConstraintOrType(c, t));
|
|
575
|
+
if ((s.flags & (1 /* TypeFlags.Any */ | 131072 /* TypeFlags.NonPrimitive */ | 1048576 /* TypeFlags.Object */ | 117964800 /* TypeFlags.InstantiableNonPrimitive */)) !==
|
|
576
|
+
0)
|
|
577
|
+
return true;
|
|
578
|
+
if ((s.flags & 402653184 /* TypeFlags.UnionOrIntersection */) === 0)
|
|
579
|
+
return false;
|
|
580
|
+
for (const u of typesOf(s))
|
|
581
|
+
if (!isValidSpreadType(c, u))
|
|
582
|
+
return false;
|
|
583
|
+
return true;
|
|
584
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Node } from './ast.js';
|
|
2
|
+
import { type Diagnostic, type DiagnosticMessage } from './diagnostics.js';
|
|
3
|
+
import { type Checker } from './checker.js';
|
|
4
|
+
import { type Type } from './checker-types.js';
|
|
5
|
+
import { type Relation } from './relations.js';
|
|
6
|
+
/** Checks that `source` relates to `target`, elaborating into `expr` when possible. */
|
|
7
|
+
export declare function checkTypeRelatedToAndOptionallyElaborate(c: Checker, source: Type, target: Type, relation: Relation, errorNode: Node | undefined, expr: Node | undefined, headMessage: DiagnosticMessage | undefined, diagnosticOutput: Diagnostic[] | undefined): boolean;
|
|
8
|
+
export declare function elaborateError(c: Checker, node: Node | undefined, source: Type, target: Type, relation: Relation, headMessage: DiagnosticMessage | undefined, diagnosticOutput: Diagnostic[] | undefined): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Elaborates the element `nameType` of `source` against `target`, reporting at `prop`. With `customMessage`,
|
|
11
|
+
* that message is reported instead of the relation error.
|
|
12
|
+
*/
|
|
13
|
+
export declare function elaborateElement(c: Checker, source: Type, target: Type, relation: Relation, prop: Node, next: Node | undefined, nameType: Type, errorMessage: DiagnosticMessage | undefined, customMessage: DiagnosticMessage | undefined, customArgs: string[], diagnosticOutput: Diagnostic[] | undefined): boolean;
|
|
14
|
+
export declare function getBestMatchIndexedAccessTypeOrUndefined(c: Checker, source: Type, target: Type, nameType: Type): Type | undefined;
|
|
15
|
+
export declare function checkExpressionForMutableLocationWithContextualType(c: Checker, next: Node, sourcePropType: Type): Type;
|