tsc-ts 0.0.4 → 0.0.6
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 +34 -2
- 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 +2351 -0
- package/dist/api/compiler/ast.js +11212 -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 +1241 -0
- package/dist/api/compiler/binder.d.ts +33 -0
- package/dist/api/compiler/binder.js +2359 -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 +1641 -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 +357 -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 +788 -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 +314 -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 +291 -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 +580 -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 +2587 -0
- package/dist/api/compiler/checker-heritage.d.ts +28 -0
- package/dist/api/compiler/checker-heritage.js +901 -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 +442 -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 +200 -0
- package/dist/api/compiler/checker-members.js +2148 -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 +483 -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 +271 -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 +789 -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 +51 -0
- package/dist/api/compiler/checker-symbol-types.js +955 -0
- package/dist/api/compiler/checker-symbols.d.ts +181 -0
- package/dist/api/compiler/checker-symbols.js +1784 -0
- package/dist/api/compiler/checker-type-factory.d.ts +142 -0
- package/dist/api/compiler/checker-type-factory.js +2542 -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 +1093 -0
- package/dist/api/compiler/checker-types.js +1874 -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 +512 -0
- package/dist/api/compiler/checker.js +932 -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 +161 -0
- package/dist/api/compiler/diagnostics.js +784 -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 +144 -0
- package/dist/api/compiler/file-include.js +599 -0
- package/dist/api/compiler/file-loader.d.ts +290 -0
- package/dist/api/compiler/file-loader.js +1323 -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 +835 -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 +105 -0
- package/dist/api/compiler/link-tables.js +319 -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 +745 -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 +221 -0
- package/dist/api/compiler/parallel-parse.js +541 -0
- package/dist/api/compiler/parser.d.ts +604 -0
- package/dist/api/compiler/parser.js +6426 -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 +157 -0
- package/dist/api/compiler/printer/emit-context.js +582 -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 +529 -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 +1019 -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 +991 -0
- package/dist/api/compiler/symbol.d.ts +282 -0
- package/dist/api/compiler/symbol.js +339 -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 +677 -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 +539 -0
- package/dist/api/compiler/transformers/declarations-pseudo.d.ts +160 -0
- package/dist/api/compiler/transformers/declarations-pseudo.js +799 -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 +198 -0
- package/dist/api/compiler/transformers/declarations.d.ts +175 -0
- package/dist/api/compiler/transformers/declarations.js +2381 -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 +129 -0
- package/dist/api/compiler/transformers/reference-resolver.js +1157 -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 +10 -0
- package/dist/api/compiler/transformers/subtree-facts.js +205 -0
- package/dist/api/compiler/transformers/syntax-facts.d.ts +52 -0
- package/dist/api/compiler/transformers/syntax-facts.js +258 -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 +12870 -0
- package/src/compiler/astnav.ts +799 -0
- package/src/compiler/binder-utilities.ts +1392 -0
- package/src/compiler/binder.ts +2707 -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 +1201 -0
- package/src/compiler/checker-declared-types.ts +919 -0
- package/src/compiler/checker-decorators.ts +694 -0
- package/src/compiler/checker-deprecation.ts +355 -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 +3596 -0
- package/src/compiler/checker-heritage.ts +1240 -0
- package/src/compiler/checker-inference.ts +2584 -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 +1928 -0
- package/src/compiler/checker-literals.ts +61 -0
- package/src/compiler/checker-members.ts +2480 -0
- package/src/compiler/checker-modules.ts +2896 -0
- package/src/compiler/checker-narrowing.ts +3230 -0
- package/src/compiler/checker-object-literals.ts +591 -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 +1187 -0
- package/src/compiler/checker-symbols.ts +2157 -0
- package/src/compiler/checker-type-factory.ts +2616 -0
- package/src/compiler/checker-type-nodes.ts +1033 -0
- package/src/compiler/checker-type-operators.ts +2510 -0
- package/src/compiler/checker-types.ts +2520 -0
- package/src/compiler/checker-unused.ts +642 -0
- package/src/compiler/checker-utilities.ts +161 -0
- package/src/compiler/checker.ts +1138 -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 +858 -0
- package/src/compiler/emitter.ts +434 -0
- package/src/compiler/encoder.ts +1945 -0
- package/src/compiler/file-include.ts +741 -0
- package/src/compiler/file-loader.ts +1597 -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 +2818 -0
- package/src/compiler/init.ts +141 -0
- package/src/compiler/instantiation.ts +938 -0
- package/src/compiler/jsdoc.ts +1386 -0
- package/src/compiler/link-tables.ts +343 -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 +1071 -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 +3433 -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 +1954 -0
- package/src/compiler/parallel-parse.ts +595 -0
- package/src/compiler/parse-thread.ts +136 -0
- package/src/compiler/parser.ts +7766 -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 +684 -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 +594 -0
- package/src/compiler/program-utilities.ts +435 -0
- package/src/compiler/program.ts +1426 -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 +1166 -0
- package/src/compiler/symbol.ts +557 -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 +833 -0
- package/src/compiler/transformers/declarations-pseudo.ts +969 -0
- package/src/compiler/transformers/declarations-resolver.ts +249 -0
- package/src/compiler/transformers/declarations-syntactic.ts +1867 -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 +1213 -0
- package/src/compiler/transformers/runtime-syntax.ts +942 -0
- package/src/compiler/transformers/subtree-facts.ts +253 -0
- package/src/compiler/transformers/syntax-facts.ts +358 -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 +1422 -0
- package/src/compiler/tsc-cli.ts +669 -0
- package/src/compiler/tsc-compile.ts +446 -0
- package/src/compiler/tsc-watch.ts +922 -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,906 @@
|
|
|
1
|
+
// Property access: member lookup on `a.b` and `A.B`, accessibility and readonly checks, and
|
|
2
|
+
// errors for missing members.
|
|
3
|
+
import { ScriptTarget, getUseDefineForClassFields } from './options.js';
|
|
4
|
+
import { ExternalEmitHelpers, checkExternalEmitHelpers } from './checker-emit-helpers.js';
|
|
5
|
+
import {
|
|
6
|
+
type Node,
|
|
7
|
+
type PropertyAccessExpression,
|
|
8
|
+
type QualifiedName,
|
|
9
|
+
ModifierFlags,
|
|
10
|
+
getBody,
|
|
11
|
+
getExpression,
|
|
12
|
+
getName,
|
|
13
|
+
getParameters,
|
|
14
|
+
getSymbol,
|
|
15
|
+
getText,
|
|
16
|
+
getType,
|
|
17
|
+
type BindingElement,
|
|
18
|
+
BinaryExpression,
|
|
19
|
+
getInitializer,
|
|
20
|
+
} from './ast.js';
|
|
21
|
+
import {
|
|
22
|
+
declarationNameToString,
|
|
23
|
+
getContainingClass,
|
|
24
|
+
getSourceFileOfNode,
|
|
25
|
+
getThisContainer,
|
|
26
|
+
isAccessExpression,
|
|
27
|
+
hasSyntacticModifier,
|
|
28
|
+
isClassLike,
|
|
29
|
+
isOptionalChain,
|
|
30
|
+
isPrivateIdentifierClassElementDeclaration,
|
|
31
|
+
isStatic,
|
|
32
|
+
skipParentheses,
|
|
33
|
+
getElementOrPropertyAccessName,
|
|
34
|
+
isBindableStaticAccessExpression,
|
|
35
|
+
isBindableStaticNameExpression,
|
|
36
|
+
} from './binder-utilities.js';
|
|
37
|
+
import { isFunctionLike, isInJSFile } from './ast-utilities.js';
|
|
38
|
+
import { type Checker, createDiagnosticForNode } from './checker.js';
|
|
39
|
+
import { type Diagnostic, Diagnostics } from './diagnostics.js';
|
|
40
|
+
import { SyntaxKind } from './syntax-kind.js';
|
|
41
|
+
import {
|
|
42
|
+
CheckMode,
|
|
43
|
+
type IntersectionType,
|
|
44
|
+
ObjectFlags,
|
|
45
|
+
type Type,
|
|
46
|
+
TypeFlags,
|
|
47
|
+
TypeFormatFlags,
|
|
48
|
+
type TypeParameter,
|
|
49
|
+
type TypeReference,
|
|
50
|
+
} from './checker-types.js';
|
|
51
|
+
import {
|
|
52
|
+
everyContainedType,
|
|
53
|
+
getTargetType,
|
|
54
|
+
getUnionType,
|
|
55
|
+
isEmptyObjectType,
|
|
56
|
+
isErrorType,
|
|
57
|
+
typesOf,
|
|
58
|
+
} from './checker-type-factory.js';
|
|
59
|
+
import {
|
|
60
|
+
getApparentType,
|
|
61
|
+
getApplicableIndexInfoForName,
|
|
62
|
+
getDeclarationModifierFlagsFromSymbol,
|
|
63
|
+
getPropertiesOfType,
|
|
64
|
+
getPropertiesOfUnionOrIntersectionType,
|
|
65
|
+
getPropertyOfType,
|
|
66
|
+
getPropertyOfTypeEx,
|
|
67
|
+
isConflictingPrivateProperty,
|
|
68
|
+
isDiscriminantWithNeverType,
|
|
69
|
+
} from './checker-members.js';
|
|
70
|
+
import {
|
|
71
|
+
getDeclarationOfAliasSymbol,
|
|
72
|
+
getParentOfSymbol,
|
|
73
|
+
getSpellingSuggestionForName,
|
|
74
|
+
getSymbolOfDeclaration,
|
|
75
|
+
} from './checker-symbols.js';
|
|
76
|
+
import { getFeatureMap } from './checker-features.js';
|
|
77
|
+
import { lazyObjectFlags } from './side-state.js';
|
|
78
|
+
import { isNodeDescendantOf } from './instantiation.js';
|
|
79
|
+
import { getTypeOfSymbol, getWidenedType, getWriteTypeOfSymbol, isReadonlySymbol } from './checker-symbol-types.js';
|
|
80
|
+
import {
|
|
81
|
+
getClassLikeDeclarationOfSymbol,
|
|
82
|
+
getConstraintOfTypeParameter,
|
|
83
|
+
getDeclaredTypeOfSymbol,
|
|
84
|
+
hasBaseType,
|
|
85
|
+
} from './checker-declared-types.js';
|
|
86
|
+
import { getBaseConstraintOfType } from './checker-members.js';
|
|
87
|
+
import { getTypeFromTypeNode } from './checker-type-nodes.js';
|
|
88
|
+
import { isGenericObjectType } from './checker-type-operators.js';
|
|
89
|
+
import { typeToString, symbolToString } from './type-printer.js';
|
|
90
|
+
import { getPromisedTypeOfPromise } from './checker-iteration.js';
|
|
91
|
+
import { AssignmentKind, getAssignmentTargetKind, getControlFlowContainer } from './checker-narrowing.js';
|
|
92
|
+
import { getSymbolNameForPrivateIdentifier } from './binder.js';
|
|
93
|
+
import { checkPropertyNotUsedBeforeDeclaration } from './checker-declaration-order.js';
|
|
94
|
+
import { grammarErrorOnNode } from './checker-operators.js';
|
|
95
|
+
import { markPropertyAliasReferenced } from './checker-modules.js';
|
|
96
|
+
import { checkDeprecatedIndexSignature, checkDeprecatedProperty } from './checker-deprecation.js';
|
|
97
|
+
import { isSelfTypeAccess, markPropertyAsReferenced } from './checker-unused.js';
|
|
98
|
+
import {
|
|
99
|
+
getContextualThisParameterType,
|
|
100
|
+
getFlowTypeOfAccessExpression,
|
|
101
|
+
getResolvedSymbol,
|
|
102
|
+
} from './checker-expressions.js';
|
|
103
|
+
import { isJSLiteralType, isThisPropertyAccessInConstructor } from './checker-javascript.js';
|
|
104
|
+
import { CheckFlags, getDeclarations, getSymbolId, type Symbol, SymbolFlags } from './symbol.js';
|
|
105
|
+
|
|
106
|
+
export function checkPropertyAccessExpressionOrQualifiedName(
|
|
107
|
+
c: Checker,
|
|
108
|
+
node: Node,
|
|
109
|
+
left: Node,
|
|
110
|
+
leftType: Type,
|
|
111
|
+
right: Node,
|
|
112
|
+
writeOnly: boolean,
|
|
113
|
+
checkMode: CheckMode = CheckMode.Normal,
|
|
114
|
+
): Type {
|
|
115
|
+
const parentSymbol = c.resolvedSymbols.get(left.id);
|
|
116
|
+
const assignmentKind = getAssignmentTargetKind(node);
|
|
117
|
+
const widenedType =
|
|
118
|
+
assignmentKind !== AssignmentKind.None || isMethodAccessForCall(node) ? getWidenedType(c, leftType) : leftType;
|
|
119
|
+
const apparentType = getApparentType(c, widenedType);
|
|
120
|
+
const isAnyLike = (apparentType.flags & TypeFlags.Any) !== 0 || apparentType === c.silentNeverType;
|
|
121
|
+
const name = getText(right);
|
|
122
|
+
const isPrivate = right.kind === SyntaxKind.PrivateIdentifier;
|
|
123
|
+
let prop: Symbol | undefined = undefined;
|
|
124
|
+
if (isPrivate) {
|
|
125
|
+
// Downleveled private names use __classPrivateFieldGet and __classPrivateFieldSet.
|
|
126
|
+
if (c.languageVersion < ScriptTarget.ESNext || !getUseDefineForClassFields(c.compilerOptions)) {
|
|
127
|
+
if (assignmentKind !== AssignmentKind.None)
|
|
128
|
+
checkExternalEmitHelpers(c, node, ExternalEmitHelpers.ClassPrivateFieldSet);
|
|
129
|
+
if (assignmentKind !== AssignmentKind.Definite)
|
|
130
|
+
checkExternalEmitHelpers(c, node, ExternalEmitHelpers.ClassPrivateFieldGet);
|
|
131
|
+
}
|
|
132
|
+
const lexicallyScopedSymbol = lookupSymbolForPrivateIdentifierDeclaration(name, right);
|
|
133
|
+
if (
|
|
134
|
+
assignmentKind !== AssignmentKind.None &&
|
|
135
|
+
lexicallyScopedSymbol !== undefined &&
|
|
136
|
+
lexicallyScopedSymbol.valueDeclaration !== undefined &&
|
|
137
|
+
lexicallyScopedSymbol.valueDeclaration.kind === SyntaxKind.MethodDeclaration
|
|
138
|
+
)
|
|
139
|
+
grammarErrorOnNode(
|
|
140
|
+
c,
|
|
141
|
+
right,
|
|
142
|
+
Diagnostics.Cannot_assign_to_private_method_0_Private_methods_are_not_writable,
|
|
143
|
+
name,
|
|
144
|
+
);
|
|
145
|
+
if (isAnyLike) {
|
|
146
|
+
if (lexicallyScopedSymbol !== undefined) return isErrorType(c, apparentType) ? c.errorType : apparentType;
|
|
147
|
+
if (getContainingClassExcludingClassDecorators(right) === undefined) {
|
|
148
|
+
grammarErrorOnNode(c, right, Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies);
|
|
149
|
+
return c.anyType;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (lexicallyScopedSymbol !== undefined) prop = getPropertyOfType(c, leftType, lexicallyScopedSymbol.name);
|
|
153
|
+
if (prop === undefined) {
|
|
154
|
+
// Shadowing and lexical scoping errors specific to private names.
|
|
155
|
+
if (checkPrivateIdentifierPropertyAccess(c, leftType, right, lexicallyScopedSymbol)) return c.errorType;
|
|
156
|
+
} else if (
|
|
157
|
+
(prop.flags & SymbolFlags.SetAccessor) !== 0 &&
|
|
158
|
+
(prop.flags & SymbolFlags.GetAccessor) === 0 &&
|
|
159
|
+
assignmentKind !== AssignmentKind.Definite
|
|
160
|
+
)
|
|
161
|
+
c.error(node, Diagnostics.Private_accessor_was_defined_without_a_getter);
|
|
162
|
+
} else {
|
|
163
|
+
if (isAnyLike) {
|
|
164
|
+
if (left.kind === SyntaxKind.Identifier && c.resolvedSymbols.get(left.id) !== undefined)
|
|
165
|
+
markPropertyAliasReferenced(c, node, undefined, leftType);
|
|
166
|
+
return isErrorType(c, apparentType) ? c.errorType : apparentType;
|
|
167
|
+
}
|
|
168
|
+
prop = getPropertyOfTypeEx(
|
|
169
|
+
c,
|
|
170
|
+
apparentType,
|
|
171
|
+
name,
|
|
172
|
+
isConstEnumObjectType(apparentType),
|
|
173
|
+
node.kind === SyntaxKind.QualifiedName,
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
markPropertyAliasReferenced(c, node, prop, leftType);
|
|
177
|
+
let propType: Type;
|
|
178
|
+
if (prop === undefined) {
|
|
179
|
+
const indexInfo =
|
|
180
|
+
!isPrivate &&
|
|
181
|
+
(assignmentKind === AssignmentKind.None || !isGenericObjectType(c, leftType) || isThisTypeParameter(leftType))
|
|
182
|
+
? getApplicableIndexInfoForName(c, apparentType, name)
|
|
183
|
+
: undefined;
|
|
184
|
+
if (indexInfo === undefined) {
|
|
185
|
+
if (isJSLiteralType(c, leftType)) return c.anyType;
|
|
186
|
+
if (leftType.symbol === c.globalThisSymbol) {
|
|
187
|
+
const globalSymbol = c.globalThisSymbol.exports?.get(name);
|
|
188
|
+
if (globalSymbol !== undefined && (globalSymbol.flags & SymbolFlags.BlockScoped) !== 0)
|
|
189
|
+
c.error(right, Diagnostics.Property_0_does_not_exist_on_type_1, name, typeToString(c, leftType));
|
|
190
|
+
else if (c.noImplicitAny)
|
|
191
|
+
c.error(
|
|
192
|
+
right,
|
|
193
|
+
Diagnostics.Element_implicitly_has_an_any_type_because_type_0_has_no_index_signature,
|
|
194
|
+
typeToString(c, leftType),
|
|
195
|
+
);
|
|
196
|
+
return c.anyType;
|
|
197
|
+
}
|
|
198
|
+
if (name !== '') reportNonexistentProperty(c, right, isThisTypeParameter(leftType) ? apparentType : leftType);
|
|
199
|
+
return c.errorType;
|
|
200
|
+
}
|
|
201
|
+
if (indexInfo.isReadonly && (assignmentKind !== AssignmentKind.None || isDeleteTarget(node)))
|
|
202
|
+
c.error(node, Diagnostics.Index_signature_in_type_0_only_permits_reading, typeToString(c, apparentType));
|
|
203
|
+
propType = indexInfo.valueType;
|
|
204
|
+
if (c.noUncheckedIndexedAccess && assignmentKind !== AssignmentKind.Definite)
|
|
205
|
+
propType = getUnionType(c, [propType, c.missingType]);
|
|
206
|
+
if (
|
|
207
|
+
c.compilerOptions.noPropertyAccessFromIndexSignature === true &&
|
|
208
|
+
node.kind === SyntaxKind.PropertyAccessExpression
|
|
209
|
+
)
|
|
210
|
+
c.error(right, Diagnostics.Property_0_comes_from_an_index_signature_so_it_must_be_accessed_with_0, name);
|
|
211
|
+
checkDeprecatedIndexSignature(c, right, indexInfo.declaration);
|
|
212
|
+
} else {
|
|
213
|
+
checkDeprecatedProperty(c, node, right, prop);
|
|
214
|
+
checkPropertyNotUsedBeforeDeclaration(c, prop, node, right);
|
|
215
|
+
markPropertyAsReferenced(c, prop, node, isSelfTypeAccess(c, left, parentSymbol));
|
|
216
|
+
// An access checked again (under another check mode) usually resolves to the same property.
|
|
217
|
+
if (c.resolvedSymbols.get(node.id) !== prop) c.resolvedSymbols.set(node.id, prop);
|
|
218
|
+
checkPropertyAccessibility(
|
|
219
|
+
c,
|
|
220
|
+
node,
|
|
221
|
+
left.kind === SyntaxKind.SuperKeyword,
|
|
222
|
+
assignmentKind !== AssignmentKind.None,
|
|
223
|
+
apparentType,
|
|
224
|
+
prop,
|
|
225
|
+
);
|
|
226
|
+
if (isAssignmentToReadonlyEntity(c, node, prop, assignmentKind)) {
|
|
227
|
+
c.error(right, Diagnostics.Cannot_assign_to_0_because_it_is_a_read_only_property, name);
|
|
228
|
+
return c.errorType;
|
|
229
|
+
}
|
|
230
|
+
if (isThisPropertyAccessInConstructor(c, node, prop)) propType = c.autoType;
|
|
231
|
+
else
|
|
232
|
+
propType =
|
|
233
|
+
writeOnly || assignmentKind === AssignmentKind.Definite
|
|
234
|
+
? getWriteTypeOfSymbol(c, prop)
|
|
235
|
+
: getTypeOfSymbol(c, prop);
|
|
236
|
+
}
|
|
237
|
+
return getFlowTypeOfAccessExpression(c, node, prop, propType, right, checkMode);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** Whether `node` is a property of an object destructuring assignment from `this`. */
|
|
241
|
+
function isThisInitializedObjectBindingExpression(node: Node): boolean {
|
|
242
|
+
if (node.kind !== SyntaxKind.ShorthandPropertyAssignment && node.kind !== SyntaxKind.PropertyAssignment) return false;
|
|
243
|
+
const binary = node.parent!.parent!;
|
|
244
|
+
return (
|
|
245
|
+
binary.kind === SyntaxKind.BinaryExpression &&
|
|
246
|
+
(binary as BinaryExpression).operatorToken.kind === SyntaxKind.EqualsToken &&
|
|
247
|
+
(binary as BinaryExpression).right.kind === SyntaxKind.ThisKeyword
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function isThisInitializedDeclaration(node: Node): boolean {
|
|
252
|
+
if (node.kind !== SyntaxKind.VariableDeclaration) return false;
|
|
253
|
+
const initializer = getInitializer(node);
|
|
254
|
+
return initializer !== undefined && initializer.kind === SyntaxKind.ThisKeyword;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// ---- Private names
|
|
258
|
+
|
|
259
|
+
/** A private name used as an expression, as in `#x in obj`; records its declaration. */
|
|
260
|
+
export function checkPrivateIdentifierExpression(c: Checker, node: Node): Type {
|
|
261
|
+
const symbol = getSymbolForPrivateIdentifierExpression(c, node);
|
|
262
|
+
if (symbol !== undefined) markPropertyAsReferenced(c, symbol, undefined, false);
|
|
263
|
+
return c.anyType;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export function getSymbolForPrivateIdentifierExpression(c: Checker, node: Node): Symbol | undefined {
|
|
267
|
+
let symbol = c.resolvedSymbols.get(node.id);
|
|
268
|
+
if (symbol === undefined) {
|
|
269
|
+
symbol = lookupSymbolForPrivateIdentifierDeclaration(getText(node), node);
|
|
270
|
+
c.resolvedSymbols.set(node.id, symbol);
|
|
271
|
+
}
|
|
272
|
+
return symbol;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** The declaration of a private name in the enclosing classes, innermost first. */
|
|
276
|
+
function lookupSymbolForPrivateIdentifierDeclaration(name: string, location: Node): Symbol | undefined {
|
|
277
|
+
for (
|
|
278
|
+
let containingClass = getContainingClassExcludingClassDecorators(location);
|
|
279
|
+
containingClass !== undefined;
|
|
280
|
+
containingClass = getContainingClass(containingClass)
|
|
281
|
+
) {
|
|
282
|
+
const symbol = getSymbol(containingClass);
|
|
283
|
+
if (symbol === undefined) continue;
|
|
284
|
+
const memberName = getSymbolNameForPrivateIdentifier(symbol, name);
|
|
285
|
+
const prop = symbol.members?.get(memberName) ?? symbol.exports?.get(memberName);
|
|
286
|
+
if (prop !== undefined) return prop;
|
|
287
|
+
}
|
|
288
|
+
return undefined;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** The containing class of `node`, skipping classes whose decorators contain it. */
|
|
292
|
+
function getContainingClassExcludingClassDecorators(node: Node): Node | undefined {
|
|
293
|
+
for (let current = node.parent; current !== undefined; current = current.parent) {
|
|
294
|
+
if (isClassLike(current)) break;
|
|
295
|
+
if (current.kind === SyntaxKind.Decorator) {
|
|
296
|
+
if (current.parent !== undefined && isClassLike(current.parent)) return getContainingClass(current.parent);
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return getContainingClass(node);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Reports a private name that's on the type but not reachable here: shadowed by another
|
|
305
|
+
* private name of the same spelling, or accessed outside its class.
|
|
306
|
+
*/
|
|
307
|
+
function checkPrivateIdentifierPropertyAccess(
|
|
308
|
+
c: Checker,
|
|
309
|
+
leftType: Type,
|
|
310
|
+
right: Node,
|
|
311
|
+
lexicallyScopedIdentifier: Symbol | undefined,
|
|
312
|
+
): boolean {
|
|
313
|
+
let propertyOnType: Symbol | undefined = undefined;
|
|
314
|
+
for (const symbol of getPropertiesOfType(c, leftType)) {
|
|
315
|
+
const declaration = symbol.valueDeclaration;
|
|
316
|
+
const name = declaration !== undefined ? getName(declaration) : undefined;
|
|
317
|
+
if (name !== undefined && name.kind === SyntaxKind.PrivateIdentifier && getText(name) === getText(right)) {
|
|
318
|
+
propertyOnType = symbol;
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
if (propertyOnType === undefined) return false;
|
|
323
|
+
const diagName = declarationNameToString(getSourceFileOfNode(right), right);
|
|
324
|
+
const typeValueDecl = propertyOnType.valueDeclaration!;
|
|
325
|
+
const typeClass = getContainingClass(typeValueDecl)!;
|
|
326
|
+
const lexicalValueDecl = lexicallyScopedIdentifier?.valueDeclaration;
|
|
327
|
+
if (lexicalValueDecl !== undefined) {
|
|
328
|
+
for (let n = getContainingClass(lexicalValueDecl); n !== undefined; n = n.parent) {
|
|
329
|
+
if (n !== typeClass) continue;
|
|
330
|
+
const diagnostic = c.error(
|
|
331
|
+
right,
|
|
332
|
+
Diagnostics.The_property_0_cannot_be_accessed_on_type_1_within_this_class_because_it_is_shadowed_by_another_private_identifier_with_the_same_spelling,
|
|
333
|
+
diagName,
|
|
334
|
+
typeToString(c, leftType),
|
|
335
|
+
);
|
|
336
|
+
diagnostic.addRelatedInfo(
|
|
337
|
+
createDiagnosticForNode(lexicalValueDecl, Diagnostics.The_shadowing_declaration_of_0_is_defined_here, [
|
|
338
|
+
diagName,
|
|
339
|
+
]),
|
|
340
|
+
);
|
|
341
|
+
diagnostic.addRelatedInfo(
|
|
342
|
+
createDiagnosticForNode(
|
|
343
|
+
typeValueDecl,
|
|
344
|
+
Diagnostics.The_declaration_of_0_that_you_probably_intended_to_use_is_defined_here,
|
|
345
|
+
[diagName],
|
|
346
|
+
),
|
|
347
|
+
);
|
|
348
|
+
return true;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
c.error(
|
|
352
|
+
right,
|
|
353
|
+
Diagnostics.Property_0_is_not_accessible_outside_class_1_because_it_has_a_private_identifier,
|
|
354
|
+
diagName,
|
|
355
|
+
symbolToString(c, getSymbol(typeClass)!),
|
|
356
|
+
);
|
|
357
|
+
return true;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function isThisTypeParameter(t: Type): boolean {
|
|
361
|
+
return (t.flags & TypeFlags.TypeParameter) !== 0 && (t as TypeParameter).isThisType;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function isConstEnumObjectType(t: Type): boolean {
|
|
365
|
+
return (
|
|
366
|
+
(t.objectFlags & ObjectFlags.Anonymous) !== 0 &&
|
|
367
|
+
t.symbol !== undefined &&
|
|
368
|
+
(t.symbol.flags & SymbolFlags.ConstEnum) !== 0
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
export function isMethodAccessForCall(node: Node): boolean {
|
|
373
|
+
let current = node;
|
|
374
|
+
while (current.parent!.kind === SyntaxKind.ParenthesizedExpression) current = current.parent!;
|
|
375
|
+
const parent = current.parent!;
|
|
376
|
+
return (
|
|
377
|
+
(parent.kind === SyntaxKind.CallExpression || parent.kind === SyntaxKind.NewExpression) &&
|
|
378
|
+
getExpression(parent) === current
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/** Whether `node` is the operand of `delete`, through parentheses. */
|
|
383
|
+
export function isDeleteTarget(node: Node): boolean {
|
|
384
|
+
if (!isAccessExpression(node)) return false;
|
|
385
|
+
let current = node.parent!;
|
|
386
|
+
while (current.kind === SyntaxKind.ParenthesizedExpression) current = current.parent!;
|
|
387
|
+
return current.kind === SyntaxKind.DeleteExpression;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/** Whether assigning through `expr` targets a readonly entity, outside of initialization. */
|
|
391
|
+
export function isAssignmentToReadonlyEntity(
|
|
392
|
+
c: Checker,
|
|
393
|
+
expr: Node,
|
|
394
|
+
symbol: Symbol,
|
|
395
|
+
assignmentKind: AssignmentKind,
|
|
396
|
+
): boolean {
|
|
397
|
+
if (assignmentKind === AssignmentKind.None) return false;
|
|
398
|
+
// CommonJS `module.exports` is never readonly.
|
|
399
|
+
if (isAccessExpression(expr)) {
|
|
400
|
+
const target = skipParentheses(getExpression(expr)!);
|
|
401
|
+
if (target.kind === SyntaxKind.Identifier && (getResolvedSymbol(c, target).flags & SymbolFlags.ModuleExports) !== 0)
|
|
402
|
+
return false;
|
|
403
|
+
}
|
|
404
|
+
if (isReadonlySymbol(c, symbol)) {
|
|
405
|
+
// Readonly properties may be assigned through `this` in the constructor of their class.
|
|
406
|
+
if (
|
|
407
|
+
(symbol.flags & SymbolFlags.Property) !== 0 &&
|
|
408
|
+
isAccessExpression(expr) &&
|
|
409
|
+
getExpression(expr)!.kind === SyntaxKind.ThisKeyword
|
|
410
|
+
) {
|
|
411
|
+
const ctor = getControlFlowContainer(expr);
|
|
412
|
+
if (ctor.kind !== SyntaxKind.Constructor) return true;
|
|
413
|
+
const declaration = symbol.valueDeclaration;
|
|
414
|
+
if (declaration !== undefined) {
|
|
415
|
+
const isLocalPropertyDeclaration = ctor.parent === declaration.parent;
|
|
416
|
+
const isLocalParameterProperty = ctor === declaration.parent;
|
|
417
|
+
// A JavaScript `this.x = …` declaration of this class or constructor function.
|
|
418
|
+
const isAssignmentDeclaration = declaration.kind === SyntaxKind.BinaryExpression;
|
|
419
|
+
const parentDeclaration = symbol.parent?.valueDeclaration;
|
|
420
|
+
const isLocalThisPropertyAssignment =
|
|
421
|
+
isAssignmentDeclaration && (parentDeclaration === ctor.parent || parentDeclaration === ctor);
|
|
422
|
+
return !isLocalPropertyDeclaration && !isLocalParameterProperty && !isLocalThisPropertyAssignment;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return true;
|
|
426
|
+
}
|
|
427
|
+
if (isAccessExpression(expr)) {
|
|
428
|
+
// References through namespace imports are readonly.
|
|
429
|
+
const node = skipParentheses(getExpression(expr)!);
|
|
430
|
+
if (node.kind === SyntaxKind.Identifier) {
|
|
431
|
+
const expressionSymbol = getResolvedSymbol(c, node);
|
|
432
|
+
if ((expressionSymbol.flags & SymbolFlags.Alias) !== 0) {
|
|
433
|
+
const declaration = getDeclarationOfAliasSymbol(expressionSymbol);
|
|
434
|
+
return declaration !== undefined && declaration.kind === SyntaxKind.NamespaceImport;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
return false;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// ---- Accessibility
|
|
442
|
+
|
|
443
|
+
/** Checks that `prop` of `containingType` may be accessed at `node`; reports and returns false otherwise. */
|
|
444
|
+
export function checkPropertyAccessibility(
|
|
445
|
+
c: Checker,
|
|
446
|
+
node: Node,
|
|
447
|
+
isSuper: boolean,
|
|
448
|
+
writing: boolean,
|
|
449
|
+
containingType: Type,
|
|
450
|
+
prop: Symbol,
|
|
451
|
+
): boolean {
|
|
452
|
+
let errorNode: Node | undefined;
|
|
453
|
+
if (node.kind === SyntaxKind.PropertyAccessExpression) errorNode = (node as PropertyAccessExpression).name;
|
|
454
|
+
else if (node.kind === SyntaxKind.QualifiedName) errorNode = (node as QualifiedName).right;
|
|
455
|
+
else if (node.kind === SyntaxKind.ImportType) errorNode = node;
|
|
456
|
+
else if (node.kind === SyntaxKind.BindingElement)
|
|
457
|
+
errorNode = (node as BindingElement).propertyName ?? (node as BindingElement).name!;
|
|
458
|
+
else errorNode = getName(node) ?? node;
|
|
459
|
+
return checkPropertyAccessibilityAtLocation(c, node, isSuper, writing, containingType, prop, errorNode);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/** Whether `prop` of `containingType` may be accessed at `node`, without reporting errors. */
|
|
463
|
+
export function isPropertyAccessible(
|
|
464
|
+
c: Checker,
|
|
465
|
+
node: Node,
|
|
466
|
+
isSuper: boolean,
|
|
467
|
+
isWrite: boolean,
|
|
468
|
+
containingType: Type,
|
|
469
|
+
prop: Symbol,
|
|
470
|
+
): boolean {
|
|
471
|
+
if ((containingType.flags & TypeFlags.Any) !== 0) return true;
|
|
472
|
+
// A #private property access in an optional chain is an error the parser reports.
|
|
473
|
+
const declaration = prop.valueDeclaration;
|
|
474
|
+
if (declaration !== undefined && isPrivateIdentifierClassElementDeclaration(declaration)) {
|
|
475
|
+
const declaringClass = getContainingClass(declaration);
|
|
476
|
+
return !isOptionalChain(node) && declaringClass !== undefined && isNodeDescendantOf(node, declaringClass);
|
|
477
|
+
}
|
|
478
|
+
return checkPropertyAccessibilityAtLocation(c, node, isSuper, isWrite, containingType, prop, undefined);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
function checkPropertyAccessibilityAtLocation(
|
|
482
|
+
c: Checker,
|
|
483
|
+
location: Node,
|
|
484
|
+
isSuper: boolean,
|
|
485
|
+
writing: boolean,
|
|
486
|
+
containingTypeIn: Type,
|
|
487
|
+
prop: Symbol,
|
|
488
|
+
errorNode: Node | undefined,
|
|
489
|
+
): boolean {
|
|
490
|
+
const flags = getDeclarationModifierFlagsFromSymbol(c, prop, writing);
|
|
491
|
+
if (isSuper) {
|
|
492
|
+
// Abstract methods can't be reached through `super`.
|
|
493
|
+
if ((flags & ModifierFlags.Abstract) !== 0) {
|
|
494
|
+
if (errorNode !== undefined)
|
|
495
|
+
c.error(
|
|
496
|
+
errorNode,
|
|
497
|
+
Diagnostics.Abstract_method_0_in_class_1_cannot_be_accessed_via_super_expression,
|
|
498
|
+
symbolToString(c, prop),
|
|
499
|
+
typeToString(c, getDeclaringClass(c, prop)!),
|
|
500
|
+
);
|
|
501
|
+
return false;
|
|
502
|
+
}
|
|
503
|
+
// Class fields of the parent aren't on the prototype.
|
|
504
|
+
if ((flags & ModifierFlags.Static) === 0 && hasClassInstancePropertyDeclaration(prop)) {
|
|
505
|
+
if (errorNode !== undefined)
|
|
506
|
+
c.error(
|
|
507
|
+
errorNode,
|
|
508
|
+
Diagnostics.Class_field_0_defined_by_the_parent_class_is_not_accessible_in_the_child_class_via_super,
|
|
509
|
+
symbolToString(c, prop),
|
|
510
|
+
);
|
|
511
|
+
return false;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
// Abstract properties can't be read during initialization of their class.
|
|
515
|
+
if (
|
|
516
|
+
(flags & ModifierFlags.Abstract) !== 0 &&
|
|
517
|
+
symbolHasNonMethodDeclaration(c, prop) &&
|
|
518
|
+
(isThisProperty(location) ||
|
|
519
|
+
isThisInitializedObjectBindingExpression(location) ||
|
|
520
|
+
(location.parent!.kind === SyntaxKind.ObjectBindingPattern &&
|
|
521
|
+
isThisInitializedDeclaration(location.parent!.parent!)))
|
|
522
|
+
) {
|
|
523
|
+
const parentSymbol = getParentOfSymbol(c, prop);
|
|
524
|
+
if (
|
|
525
|
+
parentSymbol !== undefined &&
|
|
526
|
+
(parentSymbol.flags & SymbolFlags.Class) !== 0 &&
|
|
527
|
+
isNodeUsedDuringClassInitialization(location)
|
|
528
|
+
) {
|
|
529
|
+
if (errorNode !== undefined)
|
|
530
|
+
c.error(
|
|
531
|
+
errorNode,
|
|
532
|
+
Diagnostics.Abstract_property_0_in_class_1_cannot_be_accessed_in_the_constructor,
|
|
533
|
+
symbolToString(c, prop),
|
|
534
|
+
symbolToString(c, parentSymbol),
|
|
535
|
+
);
|
|
536
|
+
return false;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
if ((flags & ModifierFlags.NonPublicAccessibilityModifier) === 0) return true;
|
|
540
|
+
// Private members are accessible within their declaring class.
|
|
541
|
+
if ((flags & ModifierFlags.Private) !== 0) {
|
|
542
|
+
const parent = getParentOfSymbol(c, prop);
|
|
543
|
+
const declaringClassDeclaration = parent !== undefined ? getClassLikeDeclarationOfSymbol(parent) : undefined;
|
|
544
|
+
if (!isNodeWithinClass(location, declaringClassDeclaration)) {
|
|
545
|
+
if (errorNode !== undefined)
|
|
546
|
+
c.error(
|
|
547
|
+
errorNode,
|
|
548
|
+
Diagnostics.Property_0_is_private_and_only_accessible_within_class_1,
|
|
549
|
+
symbolToString(c, prop),
|
|
550
|
+
typeToString(c, getDeclaringClass(c, prop)!),
|
|
551
|
+
);
|
|
552
|
+
return false;
|
|
553
|
+
}
|
|
554
|
+
return true;
|
|
555
|
+
}
|
|
556
|
+
// Protected members of a supertype are accessible through `super`.
|
|
557
|
+
if (isSuper) return true;
|
|
558
|
+
// The first enclosing class deriving from the declaring classes of the protected constituents.
|
|
559
|
+
let enclosingClass: Type | undefined = undefined;
|
|
560
|
+
for (
|
|
561
|
+
let container = getContainingClass(location);
|
|
562
|
+
container !== undefined;
|
|
563
|
+
container = getContainingClass(container)
|
|
564
|
+
) {
|
|
565
|
+
const classSymbol = getSymbolOfDeclaration(c, container);
|
|
566
|
+
if (classSymbol === undefined) continue;
|
|
567
|
+
const classType = getDeclaredTypeOfSymbol(c, classSymbol);
|
|
568
|
+
if (isClassDerivedFromDeclaringClasses(c, classType, prop, writing)) {
|
|
569
|
+
enclosingClass = classType;
|
|
570
|
+
break;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
if (enclosingClass === undefined) {
|
|
574
|
+
// Functions with a `this` parameter of a derived class may access instance members.
|
|
575
|
+
const thisClass = getEnclosingClassFromThisParameter(c, location);
|
|
576
|
+
if (thisClass !== undefined && isClassDerivedFromDeclaringClasses(c, thisClass, prop, writing))
|
|
577
|
+
enclosingClass = thisClass;
|
|
578
|
+
if ((flags & ModifierFlags.Static) !== 0 || enclosingClass === undefined) {
|
|
579
|
+
if (errorNode !== undefined)
|
|
580
|
+
c.error(
|
|
581
|
+
errorNode,
|
|
582
|
+
Diagnostics.Property_0_is_protected_and_only_accessible_within_class_1_and_its_subclasses,
|
|
583
|
+
symbolToString(c, prop),
|
|
584
|
+
typeToString(c, getDeclaringClass(c, prop) ?? containingTypeIn),
|
|
585
|
+
);
|
|
586
|
+
return false;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
if ((flags & ModifierFlags.Static) !== 0) return true;
|
|
590
|
+
let containingType: Type | undefined = containingTypeIn;
|
|
591
|
+
if ((containingType.flags & TypeFlags.TypeParameter) !== 0)
|
|
592
|
+
containingType = (containingType as TypeParameter).isThisType
|
|
593
|
+
? getConstraintOfTypeParameter(c, containingType)
|
|
594
|
+
: getBaseConstraintOfType(c, containingType);
|
|
595
|
+
if (containingType === undefined || !hasBaseType(c, containingType, enclosingClass)) {
|
|
596
|
+
if (containingType !== undefined && errorNode !== undefined)
|
|
597
|
+
c.error(
|
|
598
|
+
errorNode,
|
|
599
|
+
Diagnostics.Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1_This_is_an_instance_of_class_2,
|
|
600
|
+
symbolToString(c, prop),
|
|
601
|
+
typeToString(c, enclosingClass),
|
|
602
|
+
typeToString(c, containingType),
|
|
603
|
+
);
|
|
604
|
+
return false;
|
|
605
|
+
}
|
|
606
|
+
return true;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
function hasClassInstancePropertyDeclaration(symbol: Symbol): boolean {
|
|
610
|
+
for (const d of getDeclarations(symbol)) if (isClassInstanceProperty(d)) return true;
|
|
611
|
+
return false;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
function isClassInstanceProperty(node: Node): boolean {
|
|
615
|
+
// `this.x = v` in JavaScript declares a field, but `C.prototype.x = v` and `C.x = v` don't.
|
|
616
|
+
if (isInJSFile(node) && node instanceof BinaryExpression) {
|
|
617
|
+
const left = node.left;
|
|
618
|
+
return (
|
|
619
|
+
(!isBindableStaticAccessExpression(left, false) || !isPrototypeAccess(getExpression(left)!)) &&
|
|
620
|
+
!isBindableStaticNameExpression(left, true)
|
|
621
|
+
);
|
|
622
|
+
}
|
|
623
|
+
return (
|
|
624
|
+
node.parent !== undefined &&
|
|
625
|
+
isClassLike(node.parent) &&
|
|
626
|
+
node.kind === SyntaxKind.PropertyDeclaration &&
|
|
627
|
+
!isStatic(node) &&
|
|
628
|
+
!hasSyntacticModifier(node, ModifierFlags.Accessor)
|
|
629
|
+
);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
function isPrototypeAccess(node: Node): boolean {
|
|
633
|
+
if (!isBindableStaticAccessExpression(node, false)) return false;
|
|
634
|
+
const name = getElementOrPropertyAccessName(node);
|
|
635
|
+
return name !== undefined && getText(name) === 'prototype';
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
function isThisProperty(node: Node): boolean {
|
|
639
|
+
return isAccessExpression(node) && getExpression(node)!.kind === SyntaxKind.ThisKeyword;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
function isNodeUsedDuringClassInitialization(node: Node): boolean {
|
|
643
|
+
for (let element = node.parent; element !== undefined; element = element.parent) {
|
|
644
|
+
if (
|
|
645
|
+
(element.kind === SyntaxKind.Constructor && getBody(element) !== undefined) ||
|
|
646
|
+
element.kind === SyntaxKind.PropertyDeclaration
|
|
647
|
+
)
|
|
648
|
+
return true;
|
|
649
|
+
if (isClassLike(element) || isFunctionLike(element)) return false;
|
|
650
|
+
}
|
|
651
|
+
return false;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
/** The declaring class of a class member. */
|
|
655
|
+
export function getDeclaringClass(c: Checker, prop: Symbol): Type | undefined {
|
|
656
|
+
if (prop.parent === undefined || (prop.parent.flags & SymbolFlags.Class) === 0) return undefined;
|
|
657
|
+
return getDeclaredTypeOfSymbol(c, getParentOfSymbol(c, prop)!);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
function isNodeWithinClass(node: Node, classDeclaration: Node | undefined): boolean {
|
|
661
|
+
for (let container = getContainingClass(node); container !== undefined; container = getContainingClass(container))
|
|
662
|
+
if (container === classDeclaration) return true;
|
|
663
|
+
return false;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
/** The properties a possibly synthetic union or intersection property stands for. */
|
|
667
|
+
function getUnderlyingProperties(c: Checker, prop: Symbol, out: Symbol[]): void {
|
|
668
|
+
if ((prop.checkFlags & CheckFlags.Synthetic) === 0) {
|
|
669
|
+
out.push(prop);
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
672
|
+
const containingType = c.symbolContainingTypes.get(getSymbolId(prop));
|
|
673
|
+
if (containingType === undefined) return;
|
|
674
|
+
for (const t of typesOf(containingType)) {
|
|
675
|
+
const p = getPropertyOfType(c, t, prop.name);
|
|
676
|
+
if (p !== undefined) getUnderlyingProperties(c, p, out);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
function symbolHasNonMethodDeclaration(c: Checker, symbol: Symbol): boolean {
|
|
681
|
+
const props: Symbol[] = [];
|
|
682
|
+
getUnderlyingProperties(c, symbol, props);
|
|
683
|
+
for (const p of props) if ((p.flags & SymbolFlags.Method) === 0) return true;
|
|
684
|
+
return false;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
function isClassDerivedFromDeclaringClasses(c: Checker, checkClass: Type, prop: Symbol, writing: boolean): boolean {
|
|
688
|
+
const props: Symbol[] = [];
|
|
689
|
+
getUnderlyingProperties(c, prop, props);
|
|
690
|
+
for (const p of props) {
|
|
691
|
+
if ((getDeclarationModifierFlagsFromSymbol(c, p, writing) & ModifierFlags.Protected) === 0) continue;
|
|
692
|
+
const declaringClass = getDeclaringClass(c, p);
|
|
693
|
+
if (declaringClass === undefined || !hasBaseType(c, checkClass, declaringClass)) return false;
|
|
694
|
+
}
|
|
695
|
+
return true;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
function getEnclosingClassFromThisParameter(c: Checker, node: Node): Type | undefined {
|
|
699
|
+
const thisContainer = getThisContainer(node, false, false);
|
|
700
|
+
let thisType: Type | undefined = undefined;
|
|
701
|
+
if (isFunctionLike(thisContainer)) {
|
|
702
|
+
const thisParameter = getThisParameterDeclaration(thisContainer);
|
|
703
|
+
const typeNode = thisParameter !== undefined ? getType(thisParameter) : undefined;
|
|
704
|
+
if (typeNode !== undefined) {
|
|
705
|
+
thisType = getTypeFromTypeNode(c, typeNode);
|
|
706
|
+
if ((thisType.flags & TypeFlags.TypeParameter) !== 0) thisType = getConstraintOfTypeParameter(c, thisType);
|
|
707
|
+
} else thisType = getContextualThisParameterType(c, thisContainer);
|
|
708
|
+
}
|
|
709
|
+
if (thisType !== undefined && (thisType.objectFlags & (ObjectFlags.ClassOrInterface | ObjectFlags.Reference)) !== 0)
|
|
710
|
+
return getTargetType(thisType as TypeReference);
|
|
711
|
+
return undefined;
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
/** The explicit `this` parameter of a function, if any. */
|
|
715
|
+
function getThisParameterDeclaration(func: Node): Node | undefined {
|
|
716
|
+
const parameters = getParameters(func);
|
|
717
|
+
if (parameters === undefined || parameters.nodes.length === 0) return undefined;
|
|
718
|
+
const first = parameters.nodes[0]!;
|
|
719
|
+
const name = getName(first);
|
|
720
|
+
return name !== undefined && name.kind === SyntaxKind.Identifier && getText(name) === 'this' ? first : undefined;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
// ---- Missing properties
|
|
724
|
+
|
|
725
|
+
/** Reports a missing property once per name node, with the most helpful message available. */
|
|
726
|
+
export function reportNonexistentProperty(c: Checker, propNode: Node, containingType: Type): void {
|
|
727
|
+
const links = c.nodeLinks(propNode);
|
|
728
|
+
if ((links.flags & 1) !== 0) return;
|
|
729
|
+
links.flags |= 1;
|
|
730
|
+
const name = getText(propNode);
|
|
731
|
+
const missingProperty = declarationNameToString(getSourceFileOfNode(propNode), propNode);
|
|
732
|
+
const container = typeToString(c, containingType);
|
|
733
|
+
let chain: Diagnostic | undefined = undefined;
|
|
734
|
+
if (
|
|
735
|
+
propNode.kind !== SyntaxKind.PrivateIdentifier &&
|
|
736
|
+
(containingType.flags & TypeFlags.Union) !== 0 &&
|
|
737
|
+
(containingType.flags & TypeFlags.Primitive) === 0
|
|
738
|
+
) {
|
|
739
|
+
for (const subtype of typesOf(containingType)) {
|
|
740
|
+
if (
|
|
741
|
+
getPropertyOfType(c, subtype, name) === undefined &&
|
|
742
|
+
getApplicableIndexInfoForName(c, subtype, name) === undefined
|
|
743
|
+
) {
|
|
744
|
+
chain = createDiagnosticForNode(propNode, Diagnostics.Property_0_does_not_exist_on_type_1, [
|
|
745
|
+
missingProperty,
|
|
746
|
+
typeToString(c, subtype),
|
|
747
|
+
]);
|
|
748
|
+
break;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
let diagnostic: Diagnostic;
|
|
753
|
+
if (typeHasStaticProperty(c, name, containingType))
|
|
754
|
+
diagnostic = createDiagnosticForNode(
|
|
755
|
+
propNode,
|
|
756
|
+
Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_to_access_the_static_member_2_instead,
|
|
757
|
+
[missingProperty, container, container + '.' + missingProperty],
|
|
758
|
+
);
|
|
759
|
+
else {
|
|
760
|
+
const promisedType = getPromisedTypeOfPromise(c, containingType);
|
|
761
|
+
if (promisedType !== undefined && getPropertyOfType(c, promisedType, name) !== undefined) {
|
|
762
|
+
diagnostic = createDiagnosticForNode(propNode, Diagnostics.Property_0_does_not_exist_on_type_1, [
|
|
763
|
+
missingProperty,
|
|
764
|
+
container,
|
|
765
|
+
]);
|
|
766
|
+
diagnostic.addRelatedInfo(createDiagnosticForNode(propNode, Diagnostics.Did_you_forget_to_use_await, []));
|
|
767
|
+
} else {
|
|
768
|
+
const libSuggestion = getSuggestedLibForNonExistentProperty(c, missingProperty, containingType);
|
|
769
|
+
const suggestion =
|
|
770
|
+
libSuggestion === '' ? getSuggestedSymbolForNonexistentProperty(c, propNode, containingType) : undefined;
|
|
771
|
+
if (libSuggestion !== '')
|
|
772
|
+
diagnostic = createDiagnosticForNode(
|
|
773
|
+
propNode,
|
|
774
|
+
Diagnostics.Property_0_does_not_exist_on_type_1_Do_you_need_to_change_your_target_library_Try_changing_the_lib_compiler_option_to_2_or_later,
|
|
775
|
+
[missingProperty, container, libSuggestion],
|
|
776
|
+
);
|
|
777
|
+
else if (suggestion !== undefined) {
|
|
778
|
+
diagnostic = createDiagnosticForNode(propNode, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2, [
|
|
779
|
+
missingProperty,
|
|
780
|
+
container,
|
|
781
|
+
suggestion.name,
|
|
782
|
+
]);
|
|
783
|
+
if (suggestion.valueDeclaration !== undefined)
|
|
784
|
+
diagnostic.addRelatedInfo(
|
|
785
|
+
createDiagnosticForNode(suggestion.valueDeclaration, Diagnostics.X_0_is_declared_here, [suggestion.name]),
|
|
786
|
+
);
|
|
787
|
+
} else {
|
|
788
|
+
chain = elaborateNeverIntersection(c, chain, propNode, containingType);
|
|
789
|
+
diagnostic = createDiagnosticForNode(
|
|
790
|
+
propNode,
|
|
791
|
+
containerSeemsToBeEmptyDomElement(c, containingType)
|
|
792
|
+
? Diagnostics.Property_0_does_not_exist_on_type_1_Try_changing_the_lib_compiler_option_to_include_dom
|
|
793
|
+
: Diagnostics.Property_0_does_not_exist_on_type_1,
|
|
794
|
+
[missingProperty, container],
|
|
795
|
+
);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
if (chain !== undefined) diagnostic.addMessageChain(chain);
|
|
800
|
+
c.addDiagnostic(diagnostic);
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* `chain` under the reason an intersection reduced to `never` when `t` is one: a property with conflicting
|
|
805
|
+
* literal types, or one private in some constituents.
|
|
806
|
+
*/
|
|
807
|
+
export function elaborateNeverIntersection(
|
|
808
|
+
c: Checker,
|
|
809
|
+
chain: Diagnostic | undefined,
|
|
810
|
+
node: Node,
|
|
811
|
+
t: Type,
|
|
812
|
+
): Diagnostic | undefined {
|
|
813
|
+
if ((t.flags & TypeFlags.Intersection) === 0 || (lazyObjectFlags(c, t) & ObjectFlags.IsNeverIntersection) === 0)
|
|
814
|
+
return chain;
|
|
815
|
+
const props = getPropertiesOfUnionOrIntersectionType(c, t as IntersectionType);
|
|
816
|
+
let message =
|
|
817
|
+
Diagnostics.The_intersection_0_was_reduced_to_never_because_property_1_has_conflicting_types_in_some_constituents;
|
|
818
|
+
let prop = props.find((p) => isDiscriminantWithNeverType(c, p));
|
|
819
|
+
if (prop === undefined) {
|
|
820
|
+
message =
|
|
821
|
+
Diagnostics.The_intersection_0_was_reduced_to_never_because_property_1_exists_in_multiple_constituents_and_is_private_in_some;
|
|
822
|
+
prop = props.find(isConflictingPrivateProperty);
|
|
823
|
+
}
|
|
824
|
+
if (prop === undefined) return chain;
|
|
825
|
+
const result = createDiagnosticForNode(node, message, [
|
|
826
|
+
typeToString(c, t, undefined, TypeFormatFlags.NoTypeReduction),
|
|
827
|
+
symbolToString(c, prop),
|
|
828
|
+
]);
|
|
829
|
+
return result.addMessageChain(chain);
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
/** The library that adds `missingProperty` to the apparent type's global, or '' if none does. */
|
|
833
|
+
function getSuggestedLibForNonExistentProperty(c: Checker, missingProperty: string, containingType: Type): string {
|
|
834
|
+
const container = getApparentType(c, containingType).symbol;
|
|
835
|
+
if (container === undefined) return '';
|
|
836
|
+
const entries = getFeatureMap().get(container.name);
|
|
837
|
+
if (entries !== undefined) for (const entry of entries) if (entry.props.includes(missingProperty)) return entry.lib;
|
|
838
|
+
return '';
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
/** Whether the type looks like an empty DOM type, as when the DOM lib is missing. */
|
|
842
|
+
function containerSeemsToBeEmptyDomElement(c: Checker, containingType: Type): boolean {
|
|
843
|
+
return (
|
|
844
|
+
!(c.compilerOptions.lib ?? []).includes('lib.dom.d.ts') &&
|
|
845
|
+
everyContainedType(containingType, hasCommonDomTypeName) &&
|
|
846
|
+
isEmptyObjectType(c, containingType)
|
|
847
|
+
);
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
function hasCommonDomTypeName(t: Type): boolean {
|
|
851
|
+
if (t.symbol === undefined) return false;
|
|
852
|
+
const name = t.symbol.name;
|
|
853
|
+
return (
|
|
854
|
+
name === 'EventTarget' ||
|
|
855
|
+
name === 'Node' ||
|
|
856
|
+
name === 'Element' ||
|
|
857
|
+
(name.startsWith('HTML') && name.endsWith('Element'))
|
|
858
|
+
);
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
/** Whether the type's symbol has a static member `name`, as when an instance member was expected. */
|
|
862
|
+
export function typeHasStaticProperty(c: Checker, name: string, containingType: Type): boolean {
|
|
863
|
+
if (containingType.symbol === undefined) return false;
|
|
864
|
+
const prop = getPropertyOfType(c, getTypeOfSymbol(c, containingType.symbol), name);
|
|
865
|
+
return prop !== undefined && prop.valueDeclaration !== undefined && isStatic(prop.valueDeclaration);
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
/** The value member with the closest name, for "Did you mean" suggestions. */
|
|
869
|
+
export function getSuggestedSymbolForNonexistentProperty(
|
|
870
|
+
c: Checker,
|
|
871
|
+
name: Node,
|
|
872
|
+
containingType: Type,
|
|
873
|
+
): Symbol | undefined {
|
|
874
|
+
let props = getPropertiesOfType(c, containingType);
|
|
875
|
+
const parent = name.parent!;
|
|
876
|
+
if (parent.kind === SyntaxKind.PropertyAccessExpression) {
|
|
877
|
+
const valid: Symbol[] = [];
|
|
878
|
+
for (const prop of props)
|
|
879
|
+
if (isValidPropertyAccessForCompletions(c, parent, containingType, prop)) valid.push(prop);
|
|
880
|
+
props = valid;
|
|
881
|
+
}
|
|
882
|
+
return getSpellingSuggestionForName(c, getText(name), props, SymbolFlags.Value);
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
/** The value property of `containingType` with the closest name to `name`. */
|
|
886
|
+
export function getSuggestionForNonexistentProperty(
|
|
887
|
+
c: Checker,
|
|
888
|
+
name: string,
|
|
889
|
+
containingType: Type,
|
|
890
|
+
): Symbol | undefined {
|
|
891
|
+
return getSpellingSuggestionForName(c, name, getPropertiesOfType(c, containingType), SymbolFlags.Value);
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
/** Whether `property` of `t` may be accessed at `node` without an error, as completions decide. */
|
|
895
|
+
function isValidPropertyAccessForCompletions(c: Checker, node: Node, t: Type, property: Symbol): boolean {
|
|
896
|
+
const isSuper =
|
|
897
|
+
node.kind === SyntaxKind.PropertyAccessExpression && getExpression(node)!.kind === SyntaxKind.SuperKeyword;
|
|
898
|
+
if ((t.flags & TypeFlags.Any) !== 0) return true;
|
|
899
|
+
// `#private` access in an optional chain is a parse error.
|
|
900
|
+
const declaration = property.valueDeclaration;
|
|
901
|
+
if (declaration !== undefined && isPrivateIdentifierClassElementDeclaration(declaration)) {
|
|
902
|
+
const declClass = getContainingClass(declaration);
|
|
903
|
+
return !isOptionalChain(node) && declClass !== undefined && isNodeDescendantOf(node, declClass);
|
|
904
|
+
}
|
|
905
|
+
return checkPropertyAccessibilityAtLocation(c, node, isSuper, false, t, property, undefined);
|
|
906
|
+
}
|