tsc-ts 0.0.4 → 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 +33 -1
- 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 +3 -2
- package/dist/api/library/ast.generated.d.ts +127 -139
- package/dist/api/library/checker.d.ts +51 -0
- package/dist/api/library/checker.js +318 -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/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 +5 -1
- package/dist/api/library/index.js +4 -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/types.d.ts +14 -1
- package/package.json +12 -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 +141 -167
- package/src/library/ast.ts +4 -1
- package/src/library/checker.ts +384 -0
- package/src/library/diagnostics.ts +72 -0
- package/src/library/disk.ts +73 -0
- package/src/library/errors.ts +26 -0
- package/src/library/host.ts +63 -0
- package/src/library/index.ts +21 -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/types.ts +14 -1
|
@@ -0,0 +1,888 @@
|
|
|
1
|
+
// Declarations: variables, parameters, functions, type aliases, enums, namespaces, imports, exports.
|
|
2
|
+
import { checkCollisionsForDeclarationName } from './checker-generated-code.js';
|
|
3
|
+
import { checkExternalEmitHelpers } from './checker-emit-helpers.js';
|
|
4
|
+
import { convertAutoToAny } from './checker-narrowing.js';
|
|
5
|
+
import { markPropertyAsReferenced } from './checker-unused.js';
|
|
6
|
+
import { NodeVisitor, getExpression, getInitializer, getName, getType, getElements, getSymbol, getLocalSymbol, getBody, getDotDotDotToken, getParameters, getStatements, getText, getTypeArguments, getModifiers, } from './ast.js';
|
|
7
|
+
import { ModuleKind, ScriptTarget } from './options.js';
|
|
8
|
+
import { isExternalModuleNameRelative } from './path.js';
|
|
9
|
+
import { checkTypeNameIsReserved } from './checker-classes.js';
|
|
10
|
+
import { getPropertyNameFromType, isBindingPattern, isTypeUsableAsPropertyName } from './checker-utilities.js';
|
|
11
|
+
import { checkPropertyAccessibility } from './checker-property-access.js';
|
|
12
|
+
import { declarationNameToString, getNameOfDeclaration, getSourceFileOfNode, getAssignmentDeclarationKind, getCombinedModifierFlags, getCombinedNodeFlags, isPartOfParameterDeclaration, getRootDeclaration, getDeclarationOfKind, getModifierFlags, getModuleInstanceState, getRangeOfTokenAtPosition, hasSyntacticModifier, isEntityNameExpression, isEnumConst, isExternalModule, isModuleAugmentationExternal, isVariableDeclarationInitializedToRequire, isClassLike, } from './binder-utilities.js';
|
|
13
|
+
import { Diagnostic } from './diagnostics.js';
|
|
14
|
+
import { getSymbolId } from './symbol.js';
|
|
15
|
+
import { createDiagnosticForNode } from './checker.js';
|
|
16
|
+
import { getLiteralTypeFromPropertyName, intrinsicTypeKind } from './checker-type-operators.js';
|
|
17
|
+
import { SimpleTypeMapper, } from './checker-types.js';
|
|
18
|
+
import { checkTypeArgumentConstraints } from './checker-heritage.js';
|
|
19
|
+
import { getUnionType, isErrorType } from './checker-type-factory.js';
|
|
20
|
+
import { getTypeFromTypeNode } from './checker-type-nodes.js';
|
|
21
|
+
import { computeEnumMemberValues, getConstraintOfTypeParameter, getDeclaredTypeOfSymbol, getDeclaredTypeOfTypeParameter, getDefaultFromTypeParameter, getResolvedTypeParameterDefault, } from './checker-declared-types.js';
|
|
22
|
+
import { getDeclarationOfAliasSymbol, getExportsOfModule, getSymbolFlags, getSymbolOfDeclaration, resolveAlias, resolveName, getCachedGlobalType, } from './checker-symbols.js';
|
|
23
|
+
import { getTypeOfSymbol, getWidenedTypeForVariableLikeDeclaration, widenTypeForVariableLikeDeclaration, isOptionalDeclaration, } from './checker-symbol-types.js';
|
|
24
|
+
import { checkComputedPropertyName, checkExpression, checkExpressionCached, checkNonNullNonVoidType, checkTypeAssignableToAndOptionallyElaborate, isInAmbientOrTypeNode, } from './checker-expressions.js';
|
|
25
|
+
import { checkIteratedTypeOrElementType } from './checker-iteration.js';
|
|
26
|
+
import { isTypeAssignableTo, isTypeIdenticalTo, checkTypeAssignableTo, createMarkerType, getTypeParameterModifiers, } from './relations.js';
|
|
27
|
+
import { getBaseConstraintOfType, getPropertyOfType, getReducedType, getTypeWithThisArgument, } from './checker-members.js';
|
|
28
|
+
import { instantiateType } from './instantiation.js';
|
|
29
|
+
import { symbolToString, typeToString } from './type-printer.js';
|
|
30
|
+
import { checkNodeDeferred, checkSourceElement, checkTypeNodeIfPresent } from './checker-source-file.js';
|
|
31
|
+
import { checkFunctionLikeBody } from './checker-functions.js';
|
|
32
|
+
import { getContainerFlags } from './binder.js';
|
|
33
|
+
import { isAmbientModule, isFunctionLike, isGlobalScopeAugmentation, isInJSFile, nodeIsMissing, nodeIsPresent, } from './ast-utilities.js';
|
|
34
|
+
import { getTypeForBindingElementParent } from './checker-destructuring.js';
|
|
35
|
+
import { checkFunctionOrMethodSymbols } from './checker-overloads.js';
|
|
36
|
+
import { checkJSDocFullSignature } from './checker-jsdoc.js';
|
|
37
|
+
import { checkAliasSymbol } from './checker-modules.js';
|
|
38
|
+
import { checkDecorators } from './checker-decorators.js';
|
|
39
|
+
// ---- Variables and parameters
|
|
40
|
+
export function checkVariableStatement(c, node) {
|
|
41
|
+
checkVariableDeclarationList(c, node.declarationList);
|
|
42
|
+
}
|
|
43
|
+
export function checkVariableDeclarationList(c, node) {
|
|
44
|
+
// `using` and `await using` before ESNext use __addDisposableResource and __disposeResources.
|
|
45
|
+
const blockScopeKind = getCombinedNodeFlags(node) & 7 /* NodeFlags.BlockScoped */;
|
|
46
|
+
if ((blockScopeKind === 4 /* NodeFlags.Using */ || blockScopeKind === 6 /* NodeFlags.AwaitUsing */) &&
|
|
47
|
+
c.languageVersion < ScriptTarget.ESNext)
|
|
48
|
+
checkExternalEmitHelpers(c, node, 262144 /* ExternalEmitHelpers.AddDisposableResourceAndDisposeResources */);
|
|
49
|
+
for (const d of node.declarations.nodes)
|
|
50
|
+
checkVariableLikeDeclaration(c, d);
|
|
51
|
+
}
|
|
52
|
+
/** The initializer of a `using` or `await using` declaration must be disposable, `null` or `undefined`. */
|
|
53
|
+
function checkUsingDeclarationInitializer(c, node, initializer, initType) {
|
|
54
|
+
const blockScopeKind = getCombinedNodeFlags(node) & 7 /* NodeFlags.BlockScoped */;
|
|
55
|
+
if (blockScopeKind === 6 /* NodeFlags.AwaitUsing */) {
|
|
56
|
+
const globalAsyncDisposableType = getCachedGlobalType(c, 'AsyncDisposable', 0, true);
|
|
57
|
+
const globalDisposableType = getCachedGlobalType(c, 'Disposable', 0, true);
|
|
58
|
+
if (globalAsyncDisposableType !== c.emptyObjectType && globalDisposableType !== c.emptyObjectType)
|
|
59
|
+
checkTypeAssignableTo(c, widenTypeForVariableLikeDeclaration(c, initType, node, false), getUnionType(c, [globalAsyncDisposableType, globalDisposableType, c.nullType, c.undefinedType]), initializer, 971 /* Diagnostics.The_initializer_of_an_await_using_declaration_must_be_either_an_object_with_a_Symbol_asyncDispose_or_Symbol_dispose_method_or_be_null_or_undefined */);
|
|
60
|
+
}
|
|
61
|
+
else if (blockScopeKind === 4 /* NodeFlags.Using */) {
|
|
62
|
+
const globalDisposableType = getCachedGlobalType(c, 'Disposable', 0, true);
|
|
63
|
+
if (globalDisposableType !== c.emptyObjectType)
|
|
64
|
+
checkTypeAssignableTo(c, widenTypeForVariableLikeDeclaration(c, initType, node, false), getUnionType(c, [globalDisposableType, c.nullType, c.undefinedType]), initializer, 970 /* Diagnostics.The_initializer_of_a_using_declaration_must_be_either_an_object_with_a_Symbol_dispose_method_or_be_null_or_undefined */);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** Checks a variable, parameter, property or binding element declaration. */
|
|
68
|
+
export function checkVariableLikeDeclaration(c, node) {
|
|
69
|
+
checkDecorators(c, node);
|
|
70
|
+
if (node.kind === 170 /* SyntaxKind.Parameter */)
|
|
71
|
+
checkParameter(c, node);
|
|
72
|
+
const typeNode = getType(node);
|
|
73
|
+
checkTypeNodeIfPresent(c, typeNode);
|
|
74
|
+
const name = getName(node);
|
|
75
|
+
if (node.kind === 172 /* SyntaxKind.PropertySignature */ && name !== undefined && name.kind === 80 /* SyntaxKind.PrivateIdentifier */)
|
|
76
|
+
c.error(node, 1838 /* Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies */);
|
|
77
|
+
if (name !== undefined && name.kind === 168 /* SyntaxKind.ComputedPropertyName */)
|
|
78
|
+
checkComputedPropertyName(c, name);
|
|
79
|
+
const initializer = getInitializer(node);
|
|
80
|
+
// Parameter initializers need an implementation.
|
|
81
|
+
const initializerNotAllowed = initializer !== undefined && node.kind === 170 /* SyntaxKind.Parameter */ && nodeIsMissing(getBody(node.parent));
|
|
82
|
+
if (name !== undefined &&
|
|
83
|
+
(name.kind === 207 /* SyntaxKind.ObjectBindingPattern */ || name.kind === 208 /* SyntaxKind.ArrayBindingPattern */)) {
|
|
84
|
+
if (initializerNotAllowed)
|
|
85
|
+
c.error(node, 545 /* Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation */);
|
|
86
|
+
for (const element of getElements(name).nodes)
|
|
87
|
+
checkBindingElement(c, element);
|
|
88
|
+
if (!initializerNotAllowed)
|
|
89
|
+
checkBindingPatternInitializer(c, node, name, initializer);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (initializerNotAllowed) {
|
|
93
|
+
c.error(node, 545 /* Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation */);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (name !== undefined && name.kind === 9 /* SyntaxKind.BigIntLiteral */)
|
|
97
|
+
c.error(name, 454 /* Diagnostics.A_bigint_literal_cannot_be_used_as_a_property_name */);
|
|
98
|
+
const symbol = getSymbolOfDeclaration(c, node);
|
|
99
|
+
if (symbol === undefined) {
|
|
100
|
+
if (initializer !== undefined)
|
|
101
|
+
checkExpressionCached(c, initializer);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
// `const x = require("m")` declares an alias.
|
|
105
|
+
if ((symbol.flags & 2097152 /* SymbolFlags.Alias */) !== 0 && isVariableDeclarationInitializedToRequire(node)) {
|
|
106
|
+
checkAliasSymbol(c, node);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (name !== undefined &&
|
|
110
|
+
name.kind === 79 /* SyntaxKind.Identifier */ &&
|
|
111
|
+
node.kind !== 173 /* SyntaxKind.PropertyDeclaration */ &&
|
|
112
|
+
node.kind !== 172 /* SyntaxKind.PropertySignature */)
|
|
113
|
+
checkCollisionsForDeclarationName(c, node, name);
|
|
114
|
+
const t = convertAutoToAny(c, getTypeOfSymbol(c, symbol));
|
|
115
|
+
if (node.kind !== 173 /* SyntaxKind.PropertyDeclaration */ &&
|
|
116
|
+
node.kind !== 172 /* SyntaxKind.PropertySignature */ &&
|
|
117
|
+
node.kind !== 170 /* SyntaxKind.Parameter */) {
|
|
118
|
+
checkExportsOnMergedDeclarations(c, node);
|
|
119
|
+
if (node.kind === 261 /* SyntaxKind.VariableDeclaration */)
|
|
120
|
+
checkVarDeclaredNamesNotShadowed(c, node, symbol);
|
|
121
|
+
}
|
|
122
|
+
if (node === symbol.valueDeclaration) {
|
|
123
|
+
// A for-in initializer is already an error.
|
|
124
|
+
if (initializer !== undefined && node.parent.parent.kind !== 250 /* SyntaxKind.ForInStatement */) {
|
|
125
|
+
const initType = checkExpressionCached(c, initializer);
|
|
126
|
+
checkTypeAssignableToAndOptionallyElaborate(c, initType, t, node, initializer);
|
|
127
|
+
checkUsingDeclarationInitializer(c, node, initializer, initType);
|
|
128
|
+
}
|
|
129
|
+
if (name !== undefined && symbol.declarations.length > 1) {
|
|
130
|
+
for (const d of symbol.declarations) {
|
|
131
|
+
if (d !== node && isVariableLike(d) && !areDeclarationFlagsIdentical(d, node)) {
|
|
132
|
+
reportNonIdenticalModifiers(c, name);
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (name !== undefined &&
|
|
140
|
+
symbol.valueDeclaration !== undefined &&
|
|
141
|
+
!areDeclarationFlagsIdentical(node, symbol.valueDeclaration))
|
|
142
|
+
reportNonIdenticalModifiers(c, name);
|
|
143
|
+
// A redeclaration: types must be identical.
|
|
144
|
+
const declarationType = convertAutoToAny(c, getWidenedTypeForVariableLikeDeclaration(c, node, false));
|
|
145
|
+
if (!isErrorType(c, t) &&
|
|
146
|
+
!isErrorType(c, declarationType) &&
|
|
147
|
+
!isTypeIdenticalTo(c, t, declarationType) &&
|
|
148
|
+
(symbol.flags & 67108864 /* SymbolFlags.Assignment */) === 0)
|
|
149
|
+
errorNextVariableOrPropertyDeclarationMustHaveSameType(c, symbol.valueDeclaration, t, node, declarationType);
|
|
150
|
+
if (initializer !== undefined) {
|
|
151
|
+
const initType = checkExpressionCached(c, initializer);
|
|
152
|
+
if (!isErrorType(c, declarationType))
|
|
153
|
+
checkTypeAssignableToAndOptionallyElaborate(c, initType, declarationType, node, initializer);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/** Checks the initializer of a binding pattern, and that a pattern without names destructures a valid type. */
|
|
157
|
+
function checkBindingPatternInitializer(c, node, name, initializer) {
|
|
158
|
+
if (isInAmbientOrTypeNode(node))
|
|
159
|
+
return;
|
|
160
|
+
// A for-in initializer is already an error.
|
|
161
|
+
const needCheckInitializer = initializer !== undefined && node.parent.parent.kind !== 250 /* SyntaxKind.ForInStatement */;
|
|
162
|
+
let needCheckWidenedType = true;
|
|
163
|
+
for (const e of getElements(name).nodes) {
|
|
164
|
+
if (getName(e) !== undefined) {
|
|
165
|
+
needCheckWidenedType = false;
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (!needCheckInitializer && !needCheckWidenedType)
|
|
170
|
+
return;
|
|
171
|
+
const widenedType = getWidenedTypeForVariableLikeDeclaration(c, node, false);
|
|
172
|
+
if (needCheckInitializer) {
|
|
173
|
+
const initializerType = checkExpressionCached(c, initializer);
|
|
174
|
+
if (c.strictNullChecks && needCheckWidenedType)
|
|
175
|
+
checkNonNullNonVoidType(c, initializerType, node);
|
|
176
|
+
else
|
|
177
|
+
checkTypeAssignableToAndOptionallyElaborate(c, initializerType, getWidenedTypeForVariableLikeDeclaration(c, node, false), node, initializer);
|
|
178
|
+
}
|
|
179
|
+
if (needCheckWidenedType) {
|
|
180
|
+
if (name.kind === 208 /* SyntaxKind.ArrayBindingPattern */)
|
|
181
|
+
checkIteratedTypeOrElementType(c, 65 /* IterationUse.Destructuring */, widenedType, c.undefinedType, node);
|
|
182
|
+
else if (c.strictNullChecks)
|
|
183
|
+
checkNonNullNonVoidType(c, widenedType, node);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Reports a `var` that would hoist past a `let` or `const` of the same name declared in an inner
|
|
188
|
+
* scope: the initializer would write to the block-scoped variable.
|
|
189
|
+
*/
|
|
190
|
+
function checkVarDeclaredNamesNotShadowed(c, node, symbol) {
|
|
191
|
+
if ((getCombinedNodeFlags(node) & 7 /* NodeFlags.BlockScoped */) !== 0 || isPartOfParameterDeclaration(node))
|
|
192
|
+
return;
|
|
193
|
+
const name = getName(node);
|
|
194
|
+
if ((symbol.flags & 1 /* SymbolFlags.FunctionScopedVariable */) === 0 || name === undefined)
|
|
195
|
+
return;
|
|
196
|
+
if (name.kind !== 79 /* SyntaxKind.Identifier */)
|
|
197
|
+
return;
|
|
198
|
+
const local = resolveName(c, node, getText(name), 3 /* SymbolFlags.Variable */, undefined, false, false);
|
|
199
|
+
if (local === undefined || local === symbol || (local.flags & 2 /* SymbolFlags.BlockScopedVariable */) === 0)
|
|
200
|
+
return;
|
|
201
|
+
const declaration = local.valueDeclaration;
|
|
202
|
+
if (declaration === undefined || (getCombinedNodeFlags(declaration) & 7 /* NodeFlags.BlockScoped */) === 0)
|
|
203
|
+
return;
|
|
204
|
+
let list = declaration;
|
|
205
|
+
while (list !== undefined && list.kind !== 262 /* SyntaxKind.VariableDeclarationList */)
|
|
206
|
+
list = list.parent;
|
|
207
|
+
const statement = list?.parent;
|
|
208
|
+
const container = statement !== undefined && statement.kind === 244 /* SyntaxKind.VariableStatement */ ? statement.parent : undefined;
|
|
209
|
+
// Block-scoped variables of the function, module or file scope share it with hoisted `var`s.
|
|
210
|
+
const namesShareScope = container !== undefined &&
|
|
211
|
+
((container.kind === 242 /* SyntaxKind.Block */ && isFunctionLike(container.parent)) ||
|
|
212
|
+
container.kind === 269 /* SyntaxKind.ModuleBlock */ ||
|
|
213
|
+
container.kind === 268 /* SyntaxKind.ModuleDeclaration */ ||
|
|
214
|
+
container.kind === 307 /* SyntaxKind.SourceFile */);
|
|
215
|
+
if (namesShareScope)
|
|
216
|
+
return;
|
|
217
|
+
const localName = symbolToString(c, local);
|
|
218
|
+
c.error(node, 644 /* Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1 */, localName, localName);
|
|
219
|
+
}
|
|
220
|
+
/** Parameter properties, `this` parameters and rest parameter types. */
|
|
221
|
+
function checkParameter(c, node) {
|
|
222
|
+
const fn = node.parent;
|
|
223
|
+
const name = getName(node);
|
|
224
|
+
const paramName = name !== undefined && name.kind === 79 /* SyntaxKind.Identifier */ ? getText(name) : '';
|
|
225
|
+
if (hasSyntacticModifier(node, 31 /* ModifierFlags.ParameterPropertyModifier */)) {
|
|
226
|
+
if (shouldCheckErasableSyntax(c, node))
|
|
227
|
+
c.error(node, 243 /* Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled */);
|
|
228
|
+
if (fn.kind !== 177 /* SyntaxKind.Constructor */ || !nodeIsPresent(getBody(fn)))
|
|
229
|
+
c.error(node, 543 /* Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation */);
|
|
230
|
+
if (fn.kind === 177 /* SyntaxKind.Constructor */ && paramName === 'constructor')
|
|
231
|
+
c.error(name, 569 /* Diagnostics.X_constructor_cannot_be_used_as_a_parameter_property_name */);
|
|
232
|
+
}
|
|
233
|
+
if (getInitializer(node) === undefined &&
|
|
234
|
+
isOptionalDeclaration(node) &&
|
|
235
|
+
isBindingPattern(name) &&
|
|
236
|
+
getBody(fn) !== undefined)
|
|
237
|
+
c.error(node, 629 /* Diagnostics.A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature */);
|
|
238
|
+
if (paramName === 'this' || paramName === 'new') {
|
|
239
|
+
if (getParameters(fn).nodes.indexOf(node) !== 0)
|
|
240
|
+
c.error(node, 814 /* Diagnostics.A_0_parameter_must_be_the_first_parameter */, paramName);
|
|
241
|
+
if (fn.kind === 177 /* SyntaxKind.Constructor */ ||
|
|
242
|
+
fn.kind === 181 /* SyntaxKind.ConstructSignature */ ||
|
|
243
|
+
fn.kind === 186 /* SyntaxKind.ConstructorType */)
|
|
244
|
+
c.error(node, 815 /* Diagnostics.A_constructor_cannot_have_a_this_parameter */);
|
|
245
|
+
if (fn.kind === 220 /* SyntaxKind.ArrowFunction */)
|
|
246
|
+
c.error(node, 862 /* Diagnostics.An_arrow_function_cannot_have_a_this_parameter */);
|
|
247
|
+
if (fn.kind === 178 /* SyntaxKind.GetAccessor */ || fn.kind === 179 /* SyntaxKind.SetAccessor */)
|
|
248
|
+
c.error(node, 916 /* Diagnostics.X_get_and_set_accessors_cannot_declare_this_parameters */);
|
|
249
|
+
}
|
|
250
|
+
// Binding patterns in rest parameters are a grammar error. Generic rest types are skipped: the
|
|
251
|
+
// implied `any[]` constraints of `infer` positions aren't computed yet.
|
|
252
|
+
if (getDotDotDotToken(node) !== undefined && !isBindingPattern(name)) {
|
|
253
|
+
const symbol = getSymbolOfDeclaration(c, node);
|
|
254
|
+
const t = symbol !== undefined ? getReducedType(c, getTypeOfSymbol(c, symbol)) : undefined;
|
|
255
|
+
if (t !== undefined && !isTypeAssignableTo(c, t, c.anyReadonlyArrayType))
|
|
256
|
+
c.error(node, 544 /* Diagnostics.A_rest_parameter_must_be_of_an_array_type */);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function isVariableLike(node) {
|
|
260
|
+
switch (node.kind) {
|
|
261
|
+
case 209 /* SyntaxKind.BindingElement */:
|
|
262
|
+
case 306 /* SyntaxKind.EnumMember */:
|
|
263
|
+
case 170 /* SyntaxKind.Parameter */:
|
|
264
|
+
case 303 /* SyntaxKind.PropertyAssignment */:
|
|
265
|
+
case 173 /* SyntaxKind.PropertyDeclaration */:
|
|
266
|
+
case 172 /* SyntaxKind.PropertySignature */:
|
|
267
|
+
case 304 /* SyntaxKind.ShorthandPropertyAssignment */:
|
|
268
|
+
case 261 /* SyntaxKind.VariableDeclaration */:
|
|
269
|
+
return true;
|
|
270
|
+
}
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
273
|
+
function areDeclarationFlagsIdentical(left, right) {
|
|
274
|
+
// Parameters and variables may differ in optionality.
|
|
275
|
+
if ((left.kind === 170 /* SyntaxKind.Parameter */ && right.kind === 261 /* SyntaxKind.VariableDeclaration */) ||
|
|
276
|
+
(left.kind === 261 /* SyntaxKind.VariableDeclaration */ && right.kind === 170 /* SyntaxKind.Parameter */))
|
|
277
|
+
return true;
|
|
278
|
+
if (isOptionalDeclaration(left) !== isOptionalDeclaration(right))
|
|
279
|
+
return false;
|
|
280
|
+
const interestingFlags = 2 /* ModifierFlags.Private */ |
|
|
281
|
+
4 /* ModifierFlags.Protected */ |
|
|
282
|
+
1024 /* ModifierFlags.Async */ |
|
|
283
|
+
64 /* ModifierFlags.Abstract */ |
|
|
284
|
+
8 /* ModifierFlags.Readonly */ |
|
|
285
|
+
256 /* ModifierFlags.Static */;
|
|
286
|
+
return (getModifierFlags(left) & interestingFlags) === (getModifierFlags(right) & interestingFlags);
|
|
287
|
+
}
|
|
288
|
+
function reportNonIdenticalModifiers(c, name) {
|
|
289
|
+
c.error(name, 820 /* Diagnostics.All_declarations_of_0_must_have_identical_modifiers */, declarationNameToString(getSourceFileOfNode(name), name));
|
|
290
|
+
}
|
|
291
|
+
function checkBindingElement(c, element) {
|
|
292
|
+
// Missing array binding elements have no name.
|
|
293
|
+
if (element.name === undefined)
|
|
294
|
+
return;
|
|
295
|
+
if (element.propertyName !== undefined &&
|
|
296
|
+
element.name.kind === 79 /* SyntaxKind.Identifier */ &&
|
|
297
|
+
isPartOfParameterDeclaration(element) &&
|
|
298
|
+
nodeIsMissing(getBody(getRootDeclaration(element).parent))) {
|
|
299
|
+
// Renaming in `type F = ({ a: string }) => void` is confusing, so it's an error once the file is
|
|
300
|
+
// checked if the name is unused, even without noUnusedLocals.
|
|
301
|
+
c.renamedBindingElementsInTypes.push(element);
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
if (element.name.kind === 79 /* SyntaxKind.Identifier */)
|
|
305
|
+
checkCollisionsForDeclarationName(c, element, element.name);
|
|
306
|
+
// An object rest binding before ES2018 uses __rest.
|
|
307
|
+
if (element.parent.kind === 207 /* SyntaxKind.ObjectBindingPattern */ &&
|
|
308
|
+
element.dotDotDotToken !== undefined &&
|
|
309
|
+
c.languageVersion < ScriptTarget.ES2018)
|
|
310
|
+
checkExternalEmitHelpers(c, element, 1 /* ExternalEmitHelpers.Rest */);
|
|
311
|
+
if (element.propertyName !== undefined && element.propertyName.kind === 168 /* SyntaxKind.ComputedPropertyName */)
|
|
312
|
+
checkComputedPropertyName(c, element.propertyName);
|
|
313
|
+
// Private and protected properties can't be destructured outside their classes.
|
|
314
|
+
const parent = element.parent.parent;
|
|
315
|
+
const parentType = getTypeForBindingElementParent(c, parent, element.dotDotDotToken !== undefined ? 32 /* CheckMode.RestBindingElement */ : 0 /* CheckMode.Normal */);
|
|
316
|
+
const propertyName = element.propertyName ?? element.name;
|
|
317
|
+
if (parentType !== undefined && !isBindingPattern(propertyName)) {
|
|
318
|
+
const exprType = getLiteralTypeFromPropertyName(c, propertyName);
|
|
319
|
+
if (exprType !== undefined && isTypeUsableAsPropertyName(exprType)) {
|
|
320
|
+
const property = getPropertyOfType(c, parentType, getPropertyNameFromType(exprType));
|
|
321
|
+
if (property !== undefined) {
|
|
322
|
+
markPropertyAsReferenced(c, property, undefined, false);
|
|
323
|
+
const initializer = getInitializer(parent);
|
|
324
|
+
checkPropertyAccessibility(c, element, initializer !== undefined && initializer.kind === 107 /* SyntaxKind.SuperKeyword */, false, parentType, property);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
const name = element.name;
|
|
329
|
+
if (name !== undefined &&
|
|
330
|
+
(name.kind === 207 /* SyntaxKind.ObjectBindingPattern */ || name.kind === 208 /* SyntaxKind.ArrayBindingPattern */)) {
|
|
331
|
+
for (const e of getElements(name).nodes)
|
|
332
|
+
checkBindingElement(c, e);
|
|
333
|
+
}
|
|
334
|
+
// Initializers in parameters need an implementation.
|
|
335
|
+
if (element.initializer !== undefined &&
|
|
336
|
+
isPartOfParameterDeclaration(element) &&
|
|
337
|
+
nodeIsMissing(getBody(getRootDeclaration(element).parent))) {
|
|
338
|
+
c.error(element, 545 /* Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation */);
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
if (name.kind === 207 /* SyntaxKind.ObjectBindingPattern */ || name.kind === 208 /* SyntaxKind.ArrayBindingPattern */) {
|
|
342
|
+
checkBindingPatternInitializer(c, element, name, element.initializer);
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
{
|
|
346
|
+
const symbol = getSymbolOfDeclaration(c, element);
|
|
347
|
+
if (symbol !== undefined &&
|
|
348
|
+
(symbol.flags & 2097152 /* SymbolFlags.Alias */) !== 0 &&
|
|
349
|
+
isVariableDeclarationInitializedToRequire(element)) {
|
|
350
|
+
checkAliasSymbol(c, element);
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
if (symbol !== undefined) {
|
|
354
|
+
const t = convertAutoToAny(c, getTypeOfSymbol(c, symbol));
|
|
355
|
+
const initializer = element.initializer;
|
|
356
|
+
if (element === symbol.valueDeclaration) {
|
|
357
|
+
// A for-in initializer is already an error.
|
|
358
|
+
if (initializer !== undefined && getRootDeclaration(element).parent.parent.kind !== 250 /* SyntaxKind.ForInStatement */)
|
|
359
|
+
checkTypeAssignableToAndOptionallyElaborate(c, checkExpressionCached(c, initializer), t, element, initializer);
|
|
360
|
+
}
|
|
361
|
+
else if (symbol.valueDeclaration !== undefined) {
|
|
362
|
+
// A redeclaration must have the type of the first declaration.
|
|
363
|
+
const declarationType = convertAutoToAny(c, getWidenedTypeForVariableLikeDeclaration(c, element, false));
|
|
364
|
+
if (!isErrorType(c, t) &&
|
|
365
|
+
!isErrorType(c, declarationType) &&
|
|
366
|
+
!isTypeIdenticalTo(c, t, declarationType) &&
|
|
367
|
+
(symbol.flags & 67108864 /* SymbolFlags.Assignment */) === 0)
|
|
368
|
+
errorNextVariableOrPropertyDeclarationMustHaveSameType(c, symbol.valueDeclaration, t, element, declarationType);
|
|
369
|
+
if (initializer !== undefined)
|
|
370
|
+
checkTypeAssignableToAndOptionallyElaborate(c, checkExpressionCached(c, initializer), declarationType, element, initializer);
|
|
371
|
+
if (!areDeclarationFlagsIdentical(element, symbol.valueDeclaration))
|
|
372
|
+
reportNonIdenticalModifiers(c, name);
|
|
373
|
+
}
|
|
374
|
+
checkExportsOnMergedDeclarations(c, element);
|
|
375
|
+
checkVarDeclaredNamesNotShadowed(c, element, symbol);
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
if (element.initializer !== undefined)
|
|
380
|
+
checkExpressionCached(c, element.initializer);
|
|
381
|
+
}
|
|
382
|
+
function errorNextVariableOrPropertyDeclarationMustHaveSameType(c, firstDeclaration, firstType, nextDeclaration, nextType) {
|
|
383
|
+
const nextDeclarationName = getNameOfDeclaration(nextDeclaration);
|
|
384
|
+
const message = nextDeclaration.kind === 173 /* SyntaxKind.PropertyDeclaration */ || nextDeclaration.kind === 172 /* SyntaxKind.PropertySignature */
|
|
385
|
+
? 849 /* Diagnostics.Subsequent_property_declarations_must_have_the_same_type_Property_0_must_be_of_type_1_but_here_has_type_2 */
|
|
386
|
+
: 574 /* Diagnostics.Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2 */;
|
|
387
|
+
const declName = declarationNameToString(getSourceFileOfNode(nextDeclaration), nextDeclarationName);
|
|
388
|
+
const err = c.error(nextDeclarationName, message, declName, typeToString(c, firstType), typeToString(c, nextType));
|
|
389
|
+
if (firstDeclaration !== undefined)
|
|
390
|
+
err.addRelatedInfo(createDiagnosticForNode(getNameOfDeclaration(firstDeclaration) ?? firstDeclaration, 1356 /* Diagnostics.X_0_was_also_declared_here */, [declName]));
|
|
391
|
+
}
|
|
392
|
+
// ---- Functions
|
|
393
|
+
export function checkFunctionDeclaration(c, node) {
|
|
394
|
+
const symbol = getSymbolOfDeclaration(c, node);
|
|
395
|
+
if (symbol !== undefined)
|
|
396
|
+
getTypeOfSymbol(c, symbol);
|
|
397
|
+
checkFunctionLikeBody(c, node);
|
|
398
|
+
checkJSDocFullSignature(c, node);
|
|
399
|
+
checkFunctionOrMethodSymbols(c, node);
|
|
400
|
+
checkCollisionsForDeclarationName(c, node, getName(node));
|
|
401
|
+
}
|
|
402
|
+
// ---- Types
|
|
403
|
+
export function checkTypeParameter(c, node) {
|
|
404
|
+
const tp = node;
|
|
405
|
+
checkTypeNodeIfPresent(c, tp.constraint);
|
|
406
|
+
checkTypeNodeIfPresent(c, tp.defaultType);
|
|
407
|
+
const symbol = getSymbol(node);
|
|
408
|
+
if (symbol === undefined)
|
|
409
|
+
return;
|
|
410
|
+
const typeParameter = getDeclaredTypeOfTypeParameter(c, symbol);
|
|
411
|
+
// Resolving the base constraint reveals circularities.
|
|
412
|
+
getBaseConstraintOfType(c, typeParameter);
|
|
413
|
+
if (getResolvedTypeParameterDefault(c, typeParameter) === c.circularConstraintType)
|
|
414
|
+
c.error(tp.defaultType, 848 /* Diagnostics.Type_parameter_0_has_a_circular_default */, typeToString(c, typeParameter));
|
|
415
|
+
const constraintType = getConstraintOfTypeParameter(c, typeParameter);
|
|
416
|
+
const defaultType = getDefaultFromTypeParameter(c, typeParameter);
|
|
417
|
+
if (constraintType !== undefined && defaultType !== undefined)
|
|
418
|
+
checkTypeAssignableTo(c, defaultType, getTypeWithThisArgument(c, instantiateType(c, constraintType, new SimpleTypeMapper(typeParameter, defaultType)), defaultType, false), tp.defaultType, 520 /* Diagnostics.Type_0_does_not_satisfy_the_constraint_1 */);
|
|
419
|
+
checkTypeNameIsReserved(c, tp.name, 542 /* Diagnostics.Type_parameter_name_cannot_be_0 */);
|
|
420
|
+
checkNodeDeferred(c, node);
|
|
421
|
+
}
|
|
422
|
+
/** Variance annotations are only allowed on type aliases of object, function, constructor and mapped types. */
|
|
423
|
+
export function checkTypeParameterDeferred(c, node) {
|
|
424
|
+
const parent = node.parent;
|
|
425
|
+
const isTypeAlias = parent.kind === 266 /* SyntaxKind.TypeAliasDeclaration */ || parent.kind === 345 /* SyntaxKind.JSTypeAliasDeclaration */;
|
|
426
|
+
if (!isTypeAlias && parent.kind !== 265 /* SyntaxKind.InterfaceDeclaration */ && !isClassLike(parent))
|
|
427
|
+
return;
|
|
428
|
+
const typeParameterSymbol = getSymbolOfDeclaration(c, node);
|
|
429
|
+
if (typeParameterSymbol === undefined)
|
|
430
|
+
return;
|
|
431
|
+
const typeParameter = getDeclaredTypeOfTypeParameter(c, typeParameterSymbol);
|
|
432
|
+
const modifiers = getTypeParameterModifiers(typeParameter) & (8192 /* ModifierFlags.In */ | 16384 /* ModifierFlags.Out */);
|
|
433
|
+
if (modifiers === 0)
|
|
434
|
+
return;
|
|
435
|
+
const symbol = getSymbolOfDeclaration(c, parent);
|
|
436
|
+
if (symbol === undefined)
|
|
437
|
+
return;
|
|
438
|
+
if (isTypeAlias &&
|
|
439
|
+
(getDeclaredTypeOfSymbol(c, symbol).objectFlags & (16 /* ObjectFlags.Anonymous */ | 32 /* ObjectFlags.Mapped */)) === 0)
|
|
440
|
+
c.error(node, 780 /* Diagnostics.Variance_annotations_are_only_supported_in_type_aliases_for_object_function_constructor_and_mapped_types */);
|
|
441
|
+
else if (modifiers === 8192 /* ModifierFlags.In */ || modifiers === 16384 /* ModifierFlags.Out */) {
|
|
442
|
+
// The declared variance must hold between instantiations with marker sub- and supertypes.
|
|
443
|
+
const isOut = modifiers === 16384 /* ModifierFlags.Out */;
|
|
444
|
+
const source = createMarkerType(c, symbol, typeParameter, isOut ? c.markerSubTypeForCheck : c.markerSuperTypeForCheck);
|
|
445
|
+
const target = createMarkerType(c, symbol, typeParameter, isOut ? c.markerSuperTypeForCheck : c.markerSubTypeForCheck);
|
|
446
|
+
const saveVarianceTypeParameter = c.varianceTypeParameter;
|
|
447
|
+
c.varianceTypeParameter = typeParameter;
|
|
448
|
+
checkTypeAssignableTo(c, source, target, node, 779 /* Diagnostics.Type_0_is_not_assignable_to_type_1_as_implied_by_variance_annotation */);
|
|
449
|
+
c.varianceTypeParameter = saveVarianceTypeParameter;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
/** Checks a type parameter list: each parameter, default ordering and duplicate names. */
|
|
453
|
+
export function checkTypeParameters(c, list) {
|
|
454
|
+
if (list === undefined)
|
|
455
|
+
return;
|
|
456
|
+
const typeParameters = list.nodes;
|
|
457
|
+
let seenDefault = false;
|
|
458
|
+
for (let i = 0; i < typeParameters.length; i++) {
|
|
459
|
+
const node = typeParameters[i];
|
|
460
|
+
checkTypeParameter(c, node);
|
|
461
|
+
if (node.defaultType !== undefined) {
|
|
462
|
+
seenDefault = true;
|
|
463
|
+
const finder = new LaterTypeParameterReferenceFinder(c, typeParameters, i);
|
|
464
|
+
finder.visitNode(node.defaultType);
|
|
465
|
+
}
|
|
466
|
+
else if (seenDefault)
|
|
467
|
+
c.error(node, 838 /* Diagnostics.Required_type_parameters_may_not_follow_optional_type_parameters */);
|
|
468
|
+
for (let j = 0; j < i; j++)
|
|
469
|
+
if (getSymbol(typeParameters[j]) === getSymbol(node))
|
|
470
|
+
c.error(node.name, 478 /* Diagnostics.Duplicate_identifier_0 */, declarationNameToString(getSourceFileOfNode(node), node.name));
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
/** Reports references in a type parameter default to the parameter itself or later ones. */
|
|
474
|
+
class LaterTypeParameterReferenceFinder extends NodeVisitor {
|
|
475
|
+
c;
|
|
476
|
+
typeParameters;
|
|
477
|
+
index;
|
|
478
|
+
constructor(c, typeParameters, index) {
|
|
479
|
+
super();
|
|
480
|
+
this.c = c;
|
|
481
|
+
this.typeParameters = typeParameters;
|
|
482
|
+
this.index = index;
|
|
483
|
+
}
|
|
484
|
+
visitNode(node) {
|
|
485
|
+
if (node.kind === 184 /* SyntaxKind.TypeReference */) {
|
|
486
|
+
const t = getTypeFromTypeNode(this.c, node);
|
|
487
|
+
if ((t.flags & 524288 /* TypeFlags.TypeParameter */) !== 0)
|
|
488
|
+
for (let i = this.index; i < this.typeParameters.length; i++)
|
|
489
|
+
if (t.symbol === getSymbolOfDeclaration(this.c, this.typeParameters[i]))
|
|
490
|
+
this.c.error(node, 876 /* Diagnostics.Type_parameter_defaults_can_only_reference_previously_declared_type_parameters */);
|
|
491
|
+
}
|
|
492
|
+
return node.forEachChild(this);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
export function checkTypeAliasDeclaration(c, node) {
|
|
496
|
+
const alias = node;
|
|
497
|
+
const typeParameters = alias.typeParameters;
|
|
498
|
+
checkTypeNameIsReserved(c, alias.name, 623 /* Diagnostics.Type_alias_name_cannot_be_0 */);
|
|
499
|
+
checkExportsOnMergedDeclarations(c, node);
|
|
500
|
+
checkTypeParameters(c, typeParameters);
|
|
501
|
+
if (alias.type.kind === 141 /* SyntaxKind.IntrinsicKeyword */) {
|
|
502
|
+
const name = getText(alias.name);
|
|
503
|
+
const count = typeParameters !== undefined ? typeParameters.nodes.length : 0;
|
|
504
|
+
if (!(count === 0 && name === 'BuiltinIteratorReturn') &&
|
|
505
|
+
!(count === 1 && intrinsicTypeKind(name) !== 0 /* IntrinsicTypeKind.Unknown */))
|
|
506
|
+
c.error(alias.type, 927 /* Diagnostics.The_intrinsic_keyword_can_only_be_used_to_declare_compiler_provided_intrinsic_types */);
|
|
507
|
+
}
|
|
508
|
+
else
|
|
509
|
+
checkSourceElement(c, alias.type);
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Checks the type arguments of a type reference, an import type or a heritage type reference against the
|
|
513
|
+
* constraints of the type parameters of what it references, as tsgo's checkTypeReferenceOrImport does;
|
|
514
|
+
* not when `type`, the type of the reference, is the error type.
|
|
515
|
+
*/
|
|
516
|
+
export function checkTypeArgumentConstraintsOfReference(c, node, type) {
|
|
517
|
+
if (isErrorType(c, type) || (getTypeArguments(node)?.nodes.length ?? 0) === 0)
|
|
518
|
+
return;
|
|
519
|
+
const symbol = c.resolvedSymbols.get(node.id);
|
|
520
|
+
if (symbol === undefined)
|
|
521
|
+
return;
|
|
522
|
+
let typeParameters = undefined;
|
|
523
|
+
if ((symbol.flags & 524288 /* SymbolFlags.TypeAlias */) !== 0)
|
|
524
|
+
typeParameters = c.symbolLinks(symbol).typeParameters;
|
|
525
|
+
if ((typeParameters === undefined || typeParameters.length === 0) && (type.objectFlags & 4 /* ObjectFlags.Reference */) !== 0)
|
|
526
|
+
typeParameters = type.target.localTypeParameters();
|
|
527
|
+
if (typeParameters !== undefined && typeParameters.length > 0)
|
|
528
|
+
checkTypeArgumentConstraints(c, node, typeParameters);
|
|
529
|
+
}
|
|
530
|
+
export function checkEnumMember(c, node) {
|
|
531
|
+
const name = getName(node);
|
|
532
|
+
if (name !== undefined && name.kind === 80 /* SyntaxKind.PrivateIdentifier */)
|
|
533
|
+
c.error(node, 1842 /* Diagnostics.An_enum_member_cannot_be_named_with_a_private_identifier */);
|
|
534
|
+
const initializer = getInitializer(node);
|
|
535
|
+
if (initializer !== undefined)
|
|
536
|
+
checkExpression(c, initializer);
|
|
537
|
+
}
|
|
538
|
+
export function checkEnumDeclaration(c, node) {
|
|
539
|
+
const name = getName(node);
|
|
540
|
+
checkCollisionsForDeclarationName(c, node, name);
|
|
541
|
+
checkTypeNameIsReserved(c, name, 599 /* Diagnostics.Enum_name_cannot_be_0 */);
|
|
542
|
+
checkExportsOnMergedDeclarations(c, node);
|
|
543
|
+
for (const member of node.members.nodes)
|
|
544
|
+
checkSourceElement(c, member);
|
|
545
|
+
if (shouldCheckErasableSyntax(c, node) && (node.flags & 8388608 /* NodeFlags.Ambient */) === 0)
|
|
546
|
+
c.error(node, 243 /* Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled */);
|
|
547
|
+
computeEnumMemberValues(c, node);
|
|
548
|
+
const symbol = getSymbolOfDeclaration(c, node);
|
|
549
|
+
if (symbol === undefined)
|
|
550
|
+
return;
|
|
551
|
+
const links = c.symbolLinks(symbol);
|
|
552
|
+
if (links.enumChecked)
|
|
553
|
+
return;
|
|
554
|
+
links.enumChecked = true;
|
|
555
|
+
if (symbol.declarations.length > 1) {
|
|
556
|
+
const enumIsConst = isEnumConst(node);
|
|
557
|
+
for (const d of symbol.declarations)
|
|
558
|
+
if (d.kind === 267 /* SyntaxKind.EnumDeclaration */ && isEnumConst(d) !== enumIsConst)
|
|
559
|
+
c.error(getNameOfDeclaration(d), 637 /* Diagnostics.Enum_declarations_must_all_be_const_or_non_const */);
|
|
560
|
+
}
|
|
561
|
+
// Only one declaration of a merged enum may continue automatic numbering from zero.
|
|
562
|
+
let seenEnumMissingInitialInitializer = false;
|
|
563
|
+
for (const d of symbol.declarations) {
|
|
564
|
+
if (d.kind !== 267 /* SyntaxKind.EnumDeclaration */)
|
|
565
|
+
continue;
|
|
566
|
+
const members = d.members.nodes;
|
|
567
|
+
if (members.length === 0 || getInitializer(members[0]) !== undefined)
|
|
568
|
+
continue;
|
|
569
|
+
if (seenEnumMissingInitialInitializer)
|
|
570
|
+
c.error(getName(members[0]), 600 /* Diagnostics.In_an_enum_with_multiple_declarations_only_one_declaration_can_omit_an_initializer_for_its_first_enum_element */);
|
|
571
|
+
else
|
|
572
|
+
seenEnumMissingInitialInitializer = true;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
/** Whether erasableSyntaxOnly applies at `node`: it is set, and `node` is in a TypeScript file. */
|
|
576
|
+
export function shouldCheckErasableSyntax(c, node) {
|
|
577
|
+
return c.compilerOptions.erasableSyntaxOnly === true && !isInJSFile(node);
|
|
578
|
+
}
|
|
579
|
+
export function checkModuleDeclaration(c, node) {
|
|
580
|
+
const module = node;
|
|
581
|
+
const body = module.body;
|
|
582
|
+
if (body !== undefined)
|
|
583
|
+
checkSourceElement(c, body);
|
|
584
|
+
const isGlobalAugmentation = isGlobalScopeAugmentation(node);
|
|
585
|
+
const inAmbientContext = (node.flags & 8388608 /* NodeFlags.Ambient */) !== 0;
|
|
586
|
+
if (isGlobalAugmentation && !inAmbientContext)
|
|
587
|
+
c.error(module.name, 804 /* Diagnostics.Augmentations_for_the_global_scope_should_have_declare_modifier_unless_they_appear_in_already_ambient_context */);
|
|
588
|
+
const contextMessage = isAmbientModule(node)
|
|
589
|
+
? 184 /* Diagnostics.An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file */
|
|
590
|
+
: 185 /* Diagnostics.A_namespace_declaration_is_only_allowed_at_the_top_level_of_a_namespace_or_module */;
|
|
591
|
+
if (checkModuleElementContext(c, node, contextMessage))
|
|
592
|
+
return;
|
|
593
|
+
if (module.name.kind === 79 /* SyntaxKind.Identifier */)
|
|
594
|
+
checkCollisionsForDeclarationName(c, node, module.name);
|
|
595
|
+
if (module.name.kind === 79 /* SyntaxKind.Identifier */ && module.keyword === 144 /* SyntaxKind.ModuleKeyword */)
|
|
596
|
+
c.error(module.name, 455 /* Diagnostics.A_namespace_declaration_should_not_be_declared_using_the_module_keyword_Please_use_the_namespace_keyword_instead */);
|
|
597
|
+
checkExportsOnMergedDeclarations(c, node);
|
|
598
|
+
const symbol = getSymbolOfDeclaration(c, node);
|
|
599
|
+
// Only non-ambient instantiated namespaces.
|
|
600
|
+
if (symbol !== undefined &&
|
|
601
|
+
(symbol.flags & 512 /* SymbolFlags.ValueModule */) !== 0 &&
|
|
602
|
+
!inAmbientContext &&
|
|
603
|
+
isInstantiatedModule(node, c.preserveConstEnums)) {
|
|
604
|
+
if (shouldCheckErasableSyntax(c, node))
|
|
605
|
+
c.error(node, 243 /* Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled */);
|
|
606
|
+
// Namespaces of global scripts can merge across files, which a transpiler of one file cannot see.
|
|
607
|
+
if (c.isolatedModules && getSourceFileOfNode(node).externalModuleIndicator === undefined)
|
|
608
|
+
c.error(module.name, 229 /* Diagnostics.Namespaces_are_not_allowed_in_global_script_files_when_0_is_enabled_If_this_file_is_not_intended_to_be_a_global_script_set_moduleDetection_to_force_or_add_an_empty_export_statement */, c.compilerOptions.verbatimModuleSyntax === true ? 'verbatimModuleSyntax' : 'isolatedModules');
|
|
609
|
+
if (symbol.declarations.length > 1) {
|
|
610
|
+
const classOrFunction = getFirstNonAmbientClassOrFunctionDeclaration(symbol);
|
|
611
|
+
if (classOrFunction !== undefined) {
|
|
612
|
+
if (getSourceFileOfNode(node) !== getSourceFileOfNode(classOrFunction))
|
|
613
|
+
c.error(module.name, 601 /* Diagnostics.A_namespace_declaration_cannot_be_in_a_different_file_from_a_class_or_function_with_which_it_is_merged */);
|
|
614
|
+
else if (node.pos < classOrFunction.pos)
|
|
615
|
+
c.error(module.name, 602 /* Diagnostics.A_namespace_declaration_cannot_be_located_prior_to_a_class_or_function_with_which_it_is_merged */);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
if (c.compilerOptions.verbatimModuleSyntax === true &&
|
|
619
|
+
node.parent.kind === 307 /* SyntaxKind.SourceFile */ &&
|
|
620
|
+
hasSyntacticModifier(node, 32 /* ModifierFlags.Export */) &&
|
|
621
|
+
c.host.getEmitModuleFormatOfFile(node.parent) === ModuleKind.CommonJS) {
|
|
622
|
+
const exportModifier = getModifiers(node).nodes.find((m) => m.kind === 94 /* SyntaxKind.ExportKeyword */);
|
|
623
|
+
c.error(exportModifier, 236 /* Diagnostics.A_top_level_export_modifier_cannot_be_used_on_value_declarations_in_a_CommonJS_module_when_verbatimModuleSyntax_is_enabled */);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
if (!isAmbientModule(node))
|
|
627
|
+
return;
|
|
628
|
+
if (isModuleAugmentationExternal(node)) {
|
|
629
|
+
// Check an augmentation's body only when it merged with its target.
|
|
630
|
+
const checkBody = isGlobalAugmentation || (symbol !== undefined && (symbol.flags & 33554432 /* SymbolFlags.Transient */) !== 0);
|
|
631
|
+
if (checkBody && body !== undefined && body.kind === 269 /* SyntaxKind.ModuleBlock */)
|
|
632
|
+
for (const statement of getStatements(body).nodes)
|
|
633
|
+
checkModuleAugmentationElement(c, statement);
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
const parent = node.parent;
|
|
637
|
+
if (isGlobalAugmentation)
|
|
638
|
+
c.error(module.name, 803 /* Diagnostics.Augmentations_for_the_global_scope_can_only_be_directly_nested_in_external_modules_or_ambient_module_declarations */);
|
|
639
|
+
else if (parent.kind === 307 /* SyntaxKind.SourceFile */ && !isExternalModule(parent)) {
|
|
640
|
+
if (isExternalModuleNameRelative(getText(module.name)))
|
|
641
|
+
c.error(module.name, 604 /* Diagnostics.Ambient_module_declaration_cannot_specify_relative_module_name */);
|
|
642
|
+
}
|
|
643
|
+
else
|
|
644
|
+
c.error(module.name, 603 /* Diagnostics.Ambient_modules_cannot_be_nested_in_other_modules_or_namespaces */);
|
|
645
|
+
}
|
|
646
|
+
export function isInstantiatedModule(node, preserveConstEnums) {
|
|
647
|
+
const state = getModuleInstanceState(node);
|
|
648
|
+
return (state === 2 /* ModuleInstanceState.Instantiated */ || (preserveConstEnums && state === 3 /* ModuleInstanceState.ConstEnumOnly */));
|
|
649
|
+
}
|
|
650
|
+
function getFirstNonAmbientClassOrFunctionDeclaration(symbol) {
|
|
651
|
+
for (const d of symbol.declarations)
|
|
652
|
+
if ((d.kind === 264 /* SyntaxKind.ClassDeclaration */ ||
|
|
653
|
+
(d.kind === 263 /* SyntaxKind.FunctionDeclaration */ && nodeIsPresent(getBody(d)))) &&
|
|
654
|
+
(d.flags & 8388608 /* NodeFlags.Ambient */) === 0)
|
|
655
|
+
return d;
|
|
656
|
+
return undefined;
|
|
657
|
+
}
|
|
658
|
+
function checkModuleAugmentationElement(c, node) {
|
|
659
|
+
switch (node.kind) {
|
|
660
|
+
case 244 /* SyntaxKind.VariableStatement */:
|
|
661
|
+
// Each name, rather than the whole statement.
|
|
662
|
+
for (const d of node.declarationList.declarations.nodes)
|
|
663
|
+
checkModuleAugmentationElement(c, d);
|
|
664
|
+
return;
|
|
665
|
+
case 278 /* SyntaxKind.ExportAssignment */:
|
|
666
|
+
case 279 /* SyntaxKind.ExportDeclaration */:
|
|
667
|
+
grammarErrorOnFirstToken(c, node, 800 /* Diagnostics.Exports_and_export_assignments_are_not_permitted_in_module_augmentations */);
|
|
668
|
+
return;
|
|
669
|
+
case 272 /* SyntaxKind.ImportEqualsDeclaration */:
|
|
670
|
+
// `import a = e.x` is allowed; `import a = require("m")` isn't.
|
|
671
|
+
if (node.moduleReference.kind !== 284 /* SyntaxKind.ExternalModuleReference */)
|
|
672
|
+
return;
|
|
673
|
+
grammarErrorOnFirstToken(c, node, 801 /* Diagnostics.Imports_are_not_permitted_in_module_augmentations_Consider_moving_them_to_the_enclosing_external_module */);
|
|
674
|
+
return;
|
|
675
|
+
case 273 /* SyntaxKind.ImportDeclaration */:
|
|
676
|
+
grammarErrorOnFirstToken(c, node, 801 /* Diagnostics.Imports_are_not_permitted_in_module_augmentations_Consider_moving_them_to_the_enclosing_external_module */);
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
/** Reports at the first token of `node` unless the file has syntax errors. */
|
|
681
|
+
function grammarErrorOnFirstToken(c, node, message) {
|
|
682
|
+
const file = getSourceFileOfNode(node);
|
|
683
|
+
if (file.diagnostics.length > 0)
|
|
684
|
+
return;
|
|
685
|
+
const span = getRangeOfTokenAtPosition(file, node.pos);
|
|
686
|
+
c.addDiagnostic(new Diagnostic(file.diagnosticFile(), span.pos, span.end, message, []));
|
|
687
|
+
}
|
|
688
|
+
// ---- Imports and exports
|
|
689
|
+
/**
|
|
690
|
+
* Reports a module element (import, export, namespace) outside a file, namespace or module body.
|
|
691
|
+
* Callers stop checking the element when this returns true.
|
|
692
|
+
*/
|
|
693
|
+
function checkModuleElementContext(c, node, message) {
|
|
694
|
+
const parent = node.parent.kind;
|
|
695
|
+
if (parent === 307 /* SyntaxKind.SourceFile */ || parent === 269 /* SyntaxKind.ModuleBlock */ || parent === 268 /* SyntaxKind.ModuleDeclaration */)
|
|
696
|
+
return false;
|
|
697
|
+
grammarErrorOnFirstToken(c, node, message);
|
|
698
|
+
return true;
|
|
699
|
+
}
|
|
700
|
+
/** Reports `export =` mixed with other exports, and names exported by more than one declaration. */
|
|
701
|
+
export function checkExternalModuleExports(c, node) {
|
|
702
|
+
const moduleSymbol = getSymbolOfDeclaration(c, node);
|
|
703
|
+
if (moduleSymbol === undefined)
|
|
704
|
+
return;
|
|
705
|
+
const links = c.symbolLinks(moduleSymbol);
|
|
706
|
+
if (links.exportsChecked)
|
|
707
|
+
return;
|
|
708
|
+
links.exportsChecked = true;
|
|
709
|
+
const exportEquals = moduleSymbol.exports?.get("export=" /* InternalSymbolName.ExportEquals */);
|
|
710
|
+
// `export =` conflicts with exported values, and with exported types or namespaces the target also exports.
|
|
711
|
+
if (exportEquals !== undefined &&
|
|
712
|
+
(hasExportedMembersOfKind(c, moduleSymbol, 111551 /* SymbolFlags.Value */) || hasShadowedNamespace(c, exportEquals))) {
|
|
713
|
+
const declaration = getDeclarationOfAliasSymbol(exportEquals) ?? exportEquals.valueDeclaration;
|
|
714
|
+
if (declaration !== undefined && !isTopLevelInExternalModuleAugmentation(declaration))
|
|
715
|
+
c.error(declaration, 487 /* Diagnostics.An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements */);
|
|
716
|
+
}
|
|
717
|
+
for (const [id, symbol] of getExportsOfModule(c, moduleSymbol)) {
|
|
718
|
+
// Namespaces, enums, interfaces and overloads may have several declarations.
|
|
719
|
+
if (id === "\uFFFEexport" /* InternalSymbolName.ExportStar */ || (symbol.flags & (1920 /* SymbolFlags.Namespace */ | 384 /* SymbolFlags.Enum */)) !== 0)
|
|
720
|
+
continue;
|
|
721
|
+
let count = 0;
|
|
722
|
+
for (const d of symbol.declarations)
|
|
723
|
+
if (isNotOverload(d) && !isAccessorDeclaration(d) && d.kind !== 265 /* SyntaxKind.InterfaceDeclaration */)
|
|
724
|
+
count++;
|
|
725
|
+
// A type alias may merge with one value.
|
|
726
|
+
if ((symbol.flags & 524288 /* SymbolFlags.TypeAlias */) !== 0 && count <= 2)
|
|
727
|
+
continue;
|
|
728
|
+
if (count <= 1)
|
|
729
|
+
continue;
|
|
730
|
+
let allExportsProperties = true;
|
|
731
|
+
for (const d of symbol.declarations)
|
|
732
|
+
if (getAssignmentDeclarationKind(d) !== 2 /* JSDeclarationKind.ExportsProperty */)
|
|
733
|
+
allExportsProperties = false;
|
|
734
|
+
if (allExportsProperties)
|
|
735
|
+
continue;
|
|
736
|
+
for (const d of symbol.declarations)
|
|
737
|
+
if (isNotOverload(d))
|
|
738
|
+
c.error(d, 501 /* Diagnostics.Cannot_redeclare_exported_variable_0 */, id);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
function hasExportedMembersOfKind(c, moduleSymbol, kind) {
|
|
742
|
+
if (moduleSymbol.exports === undefined)
|
|
743
|
+
return false;
|
|
744
|
+
for (const [name, symbol] of moduleSymbol.exports)
|
|
745
|
+
if (name !== "export=" /* InternalSymbolName.ExportEquals */ && (getSymbolFlags(c, symbol) & kind) !== 0)
|
|
746
|
+
return true;
|
|
747
|
+
return false;
|
|
748
|
+
}
|
|
749
|
+
function hasShadowedNamespace(c, symbol) {
|
|
750
|
+
if ((symbol.flags & 1024 /* SymbolFlags.NamespaceModule */) === 0 || (symbol.flags & 2097152 /* SymbolFlags.Alias */) === 0)
|
|
751
|
+
return false;
|
|
752
|
+
const target = resolveAlias(c, symbol);
|
|
753
|
+
return ((target.flags & 1920 /* SymbolFlags.Namespace */) !== 0 &&
|
|
754
|
+
hasExportedMembersOfKind(c, target, 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */));
|
|
755
|
+
}
|
|
756
|
+
function isNotOverload(node) {
|
|
757
|
+
return ((node.kind !== 263 /* SyntaxKind.FunctionDeclaration */ && node.kind !== 175 /* SyntaxKind.MethodDeclaration */) ||
|
|
758
|
+
getBody(node) !== undefined);
|
|
759
|
+
}
|
|
760
|
+
function isAccessorDeclaration(node) {
|
|
761
|
+
return node.kind === 178 /* SyntaxKind.GetAccessor */ || node.kind === 179 /* SyntaxKind.SetAccessor */;
|
|
762
|
+
}
|
|
763
|
+
function isTopLevelInExternalModuleAugmentation(node) {
|
|
764
|
+
const parent = node.parent;
|
|
765
|
+
if (parent === undefined || parent.kind !== 269 /* SyntaxKind.ModuleBlock */)
|
|
766
|
+
return false;
|
|
767
|
+
const module = parent.parent;
|
|
768
|
+
return isAmbientModule(module) && isModuleAugmentationExternal(module);
|
|
769
|
+
}
|
|
770
|
+
/** Reports merged declarations that mix exported and local (or default-exported) declarations. */
|
|
771
|
+
export function checkExportsOnMergedDeclarations(c, node) {
|
|
772
|
+
let symbol = getLocalSymbol(node);
|
|
773
|
+
if (symbol === undefined) {
|
|
774
|
+
symbol = getSymbolOfDeclaration(c, node);
|
|
775
|
+
if (symbol === undefined || symbol.exportSymbol === undefined)
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
778
|
+
if (getDeclarationOfKind(symbol, node.kind) !== node)
|
|
779
|
+
return;
|
|
780
|
+
let exported = 0 /* DeclarationSpaces.None */;
|
|
781
|
+
let nonExported = 0 /* DeclarationSpaces.None */;
|
|
782
|
+
let defaultExported = 0 /* DeclarationSpaces.None */;
|
|
783
|
+
for (const d of symbol.declarations) {
|
|
784
|
+
const spaces = getDeclarationSpaces(c, d);
|
|
785
|
+
const flags = getEffectiveDeclarationFlags(d, 32 /* ModifierFlags.Export */ | 2048 /* ModifierFlags.Default */);
|
|
786
|
+
if ((flags & 32 /* ModifierFlags.Export */) !== 0) {
|
|
787
|
+
if ((flags & 2048 /* ModifierFlags.Default */) !== 0)
|
|
788
|
+
defaultExported |= spaces;
|
|
789
|
+
else
|
|
790
|
+
exported |= spaces;
|
|
791
|
+
}
|
|
792
|
+
else
|
|
793
|
+
nonExported |= spaces;
|
|
794
|
+
}
|
|
795
|
+
const nonDefaultExported = exported | nonExported;
|
|
796
|
+
const commonForExportsAndLocals = exported & nonExported;
|
|
797
|
+
const commonForDefaultAndNonDefault = defaultExported & nonDefaultExported;
|
|
798
|
+
if (commonForExportsAndLocals === 0 && commonForDefaultAndNonDefault === 0)
|
|
799
|
+
return;
|
|
800
|
+
for (const d of symbol.declarations) {
|
|
801
|
+
const spaces = getDeclarationSpaces(c, d);
|
|
802
|
+
const name = getNameOfDeclaration(d);
|
|
803
|
+
const text = declarationNameToString(getSourceFileOfNode(d), name);
|
|
804
|
+
if ((spaces & commonForDefaultAndNonDefault) !== 0)
|
|
805
|
+
c.error(name, 786 /* Diagnostics.Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration_instead */, text);
|
|
806
|
+
else if ((spaces & commonForExportsAndLocals) !== 0)
|
|
807
|
+
c.error(name, 566 /* Diagnostics.Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local */, text);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
function getDeclarationSpaces(c, node) {
|
|
811
|
+
switch (node.kind) {
|
|
812
|
+
case 265 /* SyntaxKind.InterfaceDeclaration */:
|
|
813
|
+
case 266 /* SyntaxKind.TypeAliasDeclaration */:
|
|
814
|
+
case 345 /* SyntaxKind.JSTypeAliasDeclaration */:
|
|
815
|
+
return 2 /* DeclarationSpaces.ExportType */;
|
|
816
|
+
case 268 /* SyntaxKind.ModuleDeclaration */:
|
|
817
|
+
return isAmbientModule(node) || getModuleInstanceState(node) !== 1 /* ModuleInstanceState.NonInstantiated */
|
|
818
|
+
? 4 /* DeclarationSpaces.ExportNamespace */ | 1 /* DeclarationSpaces.ExportValue */
|
|
819
|
+
: 4 /* DeclarationSpaces.ExportNamespace */;
|
|
820
|
+
case 264 /* SyntaxKind.ClassDeclaration */:
|
|
821
|
+
case 267 /* SyntaxKind.EnumDeclaration */:
|
|
822
|
+
case 306 /* SyntaxKind.EnumMember */:
|
|
823
|
+
return 2 /* DeclarationSpaces.ExportType */ | 1 /* DeclarationSpaces.ExportValue */;
|
|
824
|
+
case 307 /* SyntaxKind.SourceFile */:
|
|
825
|
+
return 2 /* DeclarationSpaces.ExportType */ | 1 /* DeclarationSpaces.ExportValue */ | 4 /* DeclarationSpaces.ExportNamespace */;
|
|
826
|
+
case 278 /* SyntaxKind.ExportAssignment */: {
|
|
827
|
+
const expression = getExpression(node);
|
|
828
|
+
const symbol = getSymbolOfDeclaration(c, node);
|
|
829
|
+
if (!isEntityNameExpression(expression, false) ||
|
|
830
|
+
symbol === undefined ||
|
|
831
|
+
(symbol.flags & 2097152 /* SymbolFlags.Alias */) === 0)
|
|
832
|
+
return 1 /* DeclarationSpaces.ExportValue */;
|
|
833
|
+
return getAliasDeclarationSpaces(c, node);
|
|
834
|
+
}
|
|
835
|
+
case 272 /* SyntaxKind.ImportEqualsDeclaration */:
|
|
836
|
+
case 275 /* SyntaxKind.NamespaceImport */:
|
|
837
|
+
case 274 /* SyntaxKind.ImportClause */:
|
|
838
|
+
return getAliasDeclarationSpaces(c, node);
|
|
839
|
+
case 174 /* SyntaxKind.MethodSignature */:
|
|
840
|
+
case 172 /* SyntaxKind.PropertySignature */:
|
|
841
|
+
return 2 /* DeclarationSpaces.ExportType */;
|
|
842
|
+
}
|
|
843
|
+
return 1 /* DeclarationSpaces.ExportValue */;
|
|
844
|
+
}
|
|
845
|
+
function getAliasDeclarationSpaces(c, node) {
|
|
846
|
+
const symbol = getSymbolOfDeclaration(c, node);
|
|
847
|
+
if (symbol === undefined)
|
|
848
|
+
return 0 /* DeclarationSpaces.None */;
|
|
849
|
+
let result = 0 /* DeclarationSpaces.None */;
|
|
850
|
+
for (const d of resolveAlias(c, symbol).declarations)
|
|
851
|
+
result |= getDeclarationSpaces(c, d);
|
|
852
|
+
return result;
|
|
853
|
+
}
|
|
854
|
+
export function getEffectiveDeclarationFlags(node, flagsToCheck) {
|
|
855
|
+
let flags = getCombinedModifierFlags(node);
|
|
856
|
+
const parent = node.parent;
|
|
857
|
+
if (parent.kind !== 265 /* SyntaxKind.InterfaceDeclaration */ &&
|
|
858
|
+
parent.kind !== 264 /* SyntaxKind.ClassDeclaration */ &&
|
|
859
|
+
parent.kind !== 232 /* SyntaxKind.ClassExpression */ &&
|
|
860
|
+
(node.flags & 8388608 /* NodeFlags.Ambient */) !== 0) {
|
|
861
|
+
let container = node.parent;
|
|
862
|
+
while (container !== undefined && (getContainerFlags(container) & 1 /* ContainerFlags.IsContainer */) === 0)
|
|
863
|
+
container = container.parent;
|
|
864
|
+
if (container !== undefined &&
|
|
865
|
+
(container.flags & 64 /* NodeFlags.ExportContext */) !== 0 &&
|
|
866
|
+
(flags & 128 /* ModifierFlags.Ambient */) === 0 &&
|
|
867
|
+
!(parent.kind === 269 /* SyntaxKind.ModuleBlock */ && isGlobalScopeAugmentation(parent.parent)))
|
|
868
|
+
flags |= 32 /* ModifierFlags.Export */;
|
|
869
|
+
flags |= 128 /* ModifierFlags.Ambient */;
|
|
870
|
+
}
|
|
871
|
+
return flags & flagsToCheck;
|
|
872
|
+
}
|
|
873
|
+
/** Reports renamings in parameters of bodiless signatures whose new names are unused. */
|
|
874
|
+
export function checkUnusedRenamedBindingElements(c) {
|
|
875
|
+
for (const element of c.renamedBindingElementsInTypes) {
|
|
876
|
+
const symbol = getSymbolOfDeclaration(c, element);
|
|
877
|
+
if (symbol !== undefined && c.symbolReferenceKinds.get(getSymbolId(symbol)) !== 0)
|
|
878
|
+
continue;
|
|
879
|
+
const file = getSourceFileOfNode(element);
|
|
880
|
+
const name = element.name;
|
|
881
|
+
const propertyName = declarationNameToString(file, element.propertyName);
|
|
882
|
+
const diagnostic = c.error(name, 963 /* Diagnostics.X_0_is_an_unused_renaming_of_1_Did_you_intend_to_use_it_as_a_type_annotation */, declarationNameToString(file, name), propertyName);
|
|
883
|
+
const parameter = getRootDeclaration(element);
|
|
884
|
+
if (getType(parameter) === undefined)
|
|
885
|
+
diagnostic.addRelatedInfo(new Diagnostic(file.diagnosticFile(), parameter.end, parameter.end, 964 /* Diagnostics.We_can_only_write_a_type_for_0_by_adding_a_type_for_the_entire_parameter_here */, [propertyName]));
|
|
886
|
+
}
|
|
887
|
+
c.renamedBindingElementsInTypes.length = 0;
|
|
888
|
+
}
|