tsc-ts 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -0
- package/dist/api/compiler/ast-utilities.d.ts +82 -0
- package/dist/api/compiler/ast-utilities.js +462 -0
- package/dist/api/compiler/ast.d.ts +2350 -0
- package/dist/api/compiler/ast.js +11206 -0
- package/dist/api/compiler/astnav.d.ts +37 -0
- package/dist/api/compiler/astnav.js +767 -0
- package/dist/api/compiler/binder-utilities.d.ts +182 -0
- package/dist/api/compiler/binder-utilities.js +1240 -0
- package/dist/api/compiler/binder.d.ts +33 -0
- package/dist/api/compiler/binder.js +2358 -0
- package/dist/api/compiler/character-codes.d.ts +161 -0
- package/dist/api/compiler/character-codes.js +160 -0
- package/dist/api/compiler/checker-calls.d.ts +46 -0
- package/dist/api/compiler/checker-calls.js +1640 -0
- package/dist/api/compiler/checker-classes.d.ts +30 -0
- package/dist/api/compiler/checker-classes.js +582 -0
- package/dist/api/compiler/checker-contextual.d.ts +77 -0
- package/dist/api/compiler/checker-contextual.js +1136 -0
- package/dist/api/compiler/checker-declaration-order.d.ts +12 -0
- package/dist/api/compiler/checker-declaration-order.js +356 -0
- package/dist/api/compiler/checker-declarations.d.ts +33 -0
- package/dist/api/compiler/checker-declarations.js +888 -0
- package/dist/api/compiler/checker-declared-types.d.ts +48 -0
- package/dist/api/compiler/checker-declared-types.js +787 -0
- package/dist/api/compiler/checker-decorators.d.ts +26 -0
- package/dist/api/compiler/checker-decorators.js +562 -0
- package/dist/api/compiler/checker-deprecation.d.ts +33 -0
- package/dist/api/compiler/checker-deprecation.js +315 -0
- package/dist/api/compiler/checker-destructuring.d.ts +34 -0
- package/dist/api/compiler/checker-destructuring.js +584 -0
- package/dist/api/compiler/checker-elaboration.d.ts +15 -0
- package/dist/api/compiler/checker-elaboration.js +290 -0
- package/dist/api/compiler/checker-emit-helpers.d.ts +58 -0
- package/dist/api/compiler/checker-emit-helpers.js +154 -0
- package/dist/api/compiler/checker-emit-resolver.d.ts +75 -0
- package/dist/api/compiler/checker-emit-resolver.js +579 -0
- package/dist/api/compiler/checker-evaluator.d.ts +27 -0
- package/dist/api/compiler/checker-evaluator.js +188 -0
- package/dist/api/compiler/checker-expressions.d.ts +67 -0
- package/dist/api/compiler/checker-expressions.js +1351 -0
- package/dist/api/compiler/checker-features.d.ts +6 -0
- package/dist/api/compiler/checker-features.js +354 -0
- package/dist/api/compiler/checker-flow.d.ts +86 -0
- package/dist/api/compiler/checker-flow.js +169 -0
- package/dist/api/compiler/checker-functions.d.ts +43 -0
- package/dist/api/compiler/checker-functions.js +1002 -0
- package/dist/api/compiler/checker-generated-code.d.ts +25 -0
- package/dist/api/compiler/checker-generated-code.js +168 -0
- package/dist/api/compiler/checker-globals.d.ts +14 -0
- package/dist/api/compiler/checker-globals.js +37 -0
- package/dist/api/compiler/checker-grammar.d.ts +35 -0
- package/dist/api/compiler/checker-grammar.js +2573 -0
- package/dist/api/compiler/checker-heritage.d.ts +28 -0
- package/dist/api/compiler/checker-heritage.js +900 -0
- package/dist/api/compiler/checker-inference.d.ts +179 -0
- package/dist/api/compiler/checker-inference.js +2105 -0
- package/dist/api/compiler/checker-iteration.d.ts +115 -0
- package/dist/api/compiler/checker-iteration.js +857 -0
- package/dist/api/compiler/checker-javascript.d.ts +42 -0
- package/dist/api/compiler/checker-javascript.js +441 -0
- package/dist/api/compiler/checker-jsdoc.d.ts +30 -0
- package/dist/api/compiler/checker-jsdoc.js +320 -0
- package/dist/api/compiler/checker-jsx.d.ts +94 -0
- package/dist/api/compiler/checker-jsx.js +1433 -0
- package/dist/api/compiler/checker-literals.d.ts +6 -0
- package/dist/api/compiler/checker-literals.js +43 -0
- package/dist/api/compiler/checker-members.d.ts +198 -0
- package/dist/api/compiler/checker-members.js +2126 -0
- package/dist/api/compiler/checker-modules.d.ts +85 -0
- package/dist/api/compiler/checker-modules.js +2141 -0
- package/dist/api/compiler/checker-narrowing.d.ts +120 -0
- package/dist/api/compiler/checker-narrowing.js +2797 -0
- package/dist/api/compiler/checker-object-literals.d.ts +14 -0
- package/dist/api/compiler/checker-object-literals.js +479 -0
- package/dist/api/compiler/checker-operators.d.ts +33 -0
- package/dist/api/compiler/checker-operators.js +1040 -0
- package/dist/api/compiler/checker-overloads.d.ts +7 -0
- package/dist/api/compiler/checker-overloads.js +270 -0
- package/dist/api/compiler/checker-property-access.d.ts +34 -0
- package/dist/api/compiler/checker-property-access.js +672 -0
- package/dist/api/compiler/checker-services.d.ts +49 -0
- package/dist/api/compiler/checker-services.js +995 -0
- package/dist/api/compiler/checker-signatures.d.ts +55 -0
- package/dist/api/compiler/checker-signatures.js +788 -0
- package/dist/api/compiler/checker-source-file.d.ts +27 -0
- package/dist/api/compiler/checker-source-file.js +619 -0
- package/dist/api/compiler/checker-statements.d.ts +18 -0
- package/dist/api/compiler/checker-statements.js +226 -0
- package/dist/api/compiler/checker-super.d.ts +13 -0
- package/dist/api/compiler/checker-super.js +241 -0
- package/dist/api/compiler/checker-symbol-types.d.ts +67 -0
- package/dist/api/compiler/checker-symbol-types.js +1885 -0
- package/dist/api/compiler/checker-symbols.d.ts +181 -0
- package/dist/api/compiler/checker-symbols.js +1782 -0
- package/dist/api/compiler/checker-type-factory.d.ts +142 -0
- package/dist/api/compiler/checker-type-factory.js +2501 -0
- package/dist/api/compiler/checker-type-nodes.d.ts +26 -0
- package/dist/api/compiler/checker-type-nodes.js +828 -0
- package/dist/api/compiler/checker-type-operators.d.ts +109 -0
- package/dist/api/compiler/checker-type-operators.js +1842 -0
- package/dist/api/compiler/checker-types.d.ts +1027 -0
- package/dist/api/compiler/checker-types.js +1697 -0
- package/dist/api/compiler/checker-unused.d.ts +19 -0
- package/dist/api/compiler/checker-unused.js +524 -0
- package/dist/api/compiler/checker-utilities.d.ts +33 -0
- package/dist/api/compiler/checker-utilities.js +141 -0
- package/dist/api/compiler/checker.d.ts +491 -0
- package/dist/api/compiler/checker.js +912 -0
- package/dist/api/compiler/command-line.d.ts +32 -0
- package/dist/api/compiler/command-line.js +383 -0
- package/dist/api/compiler/compile-program.d.ts +118 -0
- package/dist/api/compiler/compile-program.js +384 -0
- package/dist/api/compiler/diagnostic-locales.d.ts +22 -0
- package/dist/api/compiler/diagnostic-locales.js +64 -0
- package/dist/api/compiler/diagnostic-messages.d.ts +2166 -0
- package/dist/api/compiler/diagnostic-messages.js +184 -0
- package/dist/api/compiler/diagnostics.d.ts +167 -0
- package/dist/api/compiler/diagnostics.js +820 -0
- package/dist/api/compiler/emitter.d.ts +71 -0
- package/dist/api/compiler/emitter.js +327 -0
- package/dist/api/compiler/file-include.d.ts +117 -0
- package/dist/api/compiler/file-include.js +536 -0
- package/dist/api/compiler/file-loader.d.ts +261 -0
- package/dist/api/compiler/file-loader.js +1257 -0
- package/dist/api/compiler/file-system.d.ts +51 -0
- package/dist/api/compiler/file-system.js +132 -0
- package/dist/api/compiler/flow.d.ts +60 -0
- package/dist/api/compiler/flow.js +45 -0
- package/dist/api/compiler/instantiation.d.ts +74 -0
- package/dist/api/compiler/instantiation.js +799 -0
- package/dist/api/compiler/jsdoc.d.ts +75 -0
- package/dist/api/compiler/jsdoc.js +1229 -0
- package/dist/api/compiler/link-tables.d.ts +36 -0
- package/dist/api/compiler/link-tables.js +83 -0
- package/dist/api/compiler/locale-data.d.ts +24 -0
- package/dist/api/compiler/locale-data.js +183 -0
- package/dist/api/compiler/locale.d.ts +4 -0
- package/dist/api/compiler/locale.js +317 -0
- package/dist/api/compiler/locales/cs-CZ.d.ts +2 -0
- package/dist/api/compiler/locales/cs-CZ.js +3 -0
- package/dist/api/compiler/locales/de-DE.d.ts +2 -0
- package/dist/api/compiler/locales/de-DE.js +3 -0
- package/dist/api/compiler/locales/es-ES.d.ts +2 -0
- package/dist/api/compiler/locales/es-ES.js +3 -0
- package/dist/api/compiler/locales/fr-FR.d.ts +2 -0
- package/dist/api/compiler/locales/fr-FR.js +3 -0
- package/dist/api/compiler/locales/it-IT.d.ts +2 -0
- package/dist/api/compiler/locales/it-IT.js +3 -0
- package/dist/api/compiler/locales/ja-JP.d.ts +2 -0
- package/dist/api/compiler/locales/ja-JP.js +3 -0
- package/dist/api/compiler/locales/ko-KR.d.ts +2 -0
- package/dist/api/compiler/locales/ko-KR.js +3 -0
- package/dist/api/compiler/locales/pl-PL.d.ts +2 -0
- package/dist/api/compiler/locales/pl-PL.js +3 -0
- package/dist/api/compiler/locales/pt-BR.d.ts +2 -0
- package/dist/api/compiler/locales/pt-BR.js +3 -0
- package/dist/api/compiler/locales/ru-RU.d.ts +2 -0
- package/dist/api/compiler/locales/ru-RU.js +3 -0
- package/dist/api/compiler/locales/tr-TR.d.ts +2 -0
- package/dist/api/compiler/locales/tr-TR.js +3 -0
- package/dist/api/compiler/locales/zh-CN.d.ts +2 -0
- package/dist/api/compiler/locales/zh-CN.js +3 -0
- package/dist/api/compiler/locales/zh-TW.d.ts +2 -0
- package/dist/api/compiler/locales/zh-TW.js +3 -0
- package/dist/api/compiler/module-resolution-types.d.ts +83 -0
- package/dist/api/compiler/module-resolution-types.js +176 -0
- package/dist/api/compiler/module-resolution.d.ts +71 -0
- package/dist/api/compiler/module-resolution.js +1598 -0
- package/dist/api/compiler/module-specifiers.d.ts +64 -0
- package/dist/api/compiler/module-specifiers.js +1101 -0
- package/dist/api/compiler/name-resolver.d.ts +43 -0
- package/dist/api/compiler/name-resolver.js +509 -0
- package/dist/api/compiler/node-builder-names.d.ts +32 -0
- package/dist/api/compiler/node-builder-names.js +854 -0
- package/dist/api/compiler/node-builder-pseudo.d.ts +36 -0
- package/dist/api/compiler/node-builder-pseudo.js +744 -0
- package/dist/api/compiler/node-builder-reuse.d.ts +4 -0
- package/dist/api/compiler/node-builder-reuse.js +647 -0
- package/dist/api/compiler/node-builder.d.ts +270 -0
- package/dist/api/compiler/node-builder.js +2645 -0
- package/dist/api/compiler/option-declarations.d.ts +90 -0
- package/dist/api/compiler/option-declarations.js +1460 -0
- package/dist/api/compiler/options.d.ts +289 -0
- package/dist/api/compiler/options.js +1197 -0
- package/dist/api/compiler/output-paths.d.ts +42 -0
- package/dist/api/compiler/output-paths.js +195 -0
- package/dist/api/compiler/package-json.d.ts +175 -0
- package/dist/api/compiler/package-json.js +1015 -0
- package/dist/api/compiler/parallel-parse.d.ts +219 -0
- package/dist/api/compiler/parallel-parse.js +537 -0
- package/dist/api/compiler/parser.d.ts +587 -0
- package/dist/api/compiler/parser.js +6407 -0
- package/dist/api/compiler/path.d.ts +91 -0
- package/dist/api/compiler/path.js +705 -0
- package/dist/api/compiler/printer/async-helpers.d.ts +22 -0
- package/dist/api/compiler/printer/async-helpers.js +91 -0
- package/dist/api/compiler/printer/auto-generate.d.ts +13 -0
- package/dist/api/compiler/printer/auto-generate.js +20 -0
- package/dist/api/compiler/printer/decorator-helpers.d.ts +24 -0
- package/dist/api/compiler/printer/decorator-helpers.js +118 -0
- package/dist/api/compiler/printer/emit-context.d.ts +154 -0
- package/dist/api/compiler/printer/emit-context.js +576 -0
- package/dist/api/compiler/printer/emit-flags.d.ts +60 -0
- package/dist/api/compiler/printer/emit-flags.js +2 -0
- package/dist/api/compiler/printer/factory-base.d.ts +171 -0
- package/dist/api/compiler/printer/factory-base.js +1505 -0
- package/dist/api/compiler/printer/factory.d.ts +147 -0
- package/dist/api/compiler/printer/factory.js +542 -0
- package/dist/api/compiler/printer/helpers.d.ts +27 -0
- package/dist/api/compiler/printer/helpers.js +164 -0
- package/dist/api/compiler/printer/name-generator.d.ts +41 -0
- package/dist/api/compiler/printer/name-generator.js +283 -0
- package/dist/api/compiler/printer/printer.d.ts +411 -0
- package/dist/api/compiler/printer/printer.js +4517 -0
- package/dist/api/compiler/printer/text-writer.d.ts +46 -0
- package/dist/api/compiler/printer/text-writer.js +172 -0
- package/dist/api/compiler/printer/utilities.d.ts +82 -0
- package/dist/api/compiler/printer/utilities.js +817 -0
- package/dist/api/compiler/program-checker.d.ts +156 -0
- package/dist/api/compiler/program-checker.js +526 -0
- package/dist/api/compiler/program-utilities.d.ts +52 -0
- package/dist/api/compiler/program-utilities.js +365 -0
- package/dist/api/compiler/program.d.ts +180 -0
- package/dist/api/compiler/program.js +1011 -0
- package/dist/api/compiler/pseudo-bigint.d.ts +5 -0
- package/dist/api/compiler/pseudo-bigint.js +61 -0
- package/dist/api/compiler/regexp-checker.d.ts +38 -0
- package/dist/api/compiler/regexp-checker.js +942 -0
- package/dist/api/compiler/relations.d.ts +263 -0
- package/dist/api/compiler/relations.js +4002 -0
- package/dist/api/compiler/reparser.d.ts +48 -0
- package/dist/api/compiler/reparser.js +1323 -0
- package/dist/api/compiler/scanner.d.ts +256 -0
- package/dist/api/compiler/scanner.js +2853 -0
- package/dist/api/compiler/side-state.d.ts +16 -0
- package/dist/api/compiler/side-state.js +89 -0
- package/dist/api/compiler/sourcemap.d.ts +55 -0
- package/dist/api/compiler/sourcemap.js +340 -0
- package/dist/api/compiler/spelling.d.ts +14 -0
- package/dist/api/compiler/spelling.js +128 -0
- package/dist/api/compiler/symbol-accessibility.d.ts +57 -0
- package/dist/api/compiler/symbol-accessibility.js +894 -0
- package/dist/api/compiler/symbol.d.ts +240 -0
- package/dist/api/compiler/symbol.js +228 -0
- package/dist/api/compiler/symlinks.d.ts +32 -0
- package/dist/api/compiler/symlinks.js +114 -0
- package/dist/api/compiler/syntax-kind.d.ts +389 -0
- package/dist/api/compiler/syntax-kind.js +2 -0
- package/dist/api/compiler/timeline.d.ts +9 -0
- package/dist/api/compiler/timeline.js +54 -0
- package/dist/api/compiler/transformers/alias-references.d.ts +39 -0
- package/dist/api/compiler/transformers/alias-references.js +676 -0
- package/dist/api/compiler/transformers/async-utilities.d.ts +51 -0
- package/dist/api/compiler/transformers/async-utilities.js +260 -0
- package/dist/api/compiler/transformers/async.d.ts +53 -0
- package/dist/api/compiler/transformers/async.js +645 -0
- package/dist/api/compiler/transformers/class-fields.d.ts +206 -0
- package/dist/api/compiler/transformers/class-fields.js +2418 -0
- package/dist/api/compiler/transformers/class-utilities.d.ts +46 -0
- package/dist/api/compiler/transformers/class-utilities.js +261 -0
- package/dist/api/compiler/transformers/commonjs-module.d.ts +103 -0
- package/dist/api/compiler/transformers/commonjs-module.js +1180 -0
- package/dist/api/compiler/transformers/const-enum-inliner.d.ts +11 -0
- package/dist/api/compiler/transformers/const-enum-inliner.js +36 -0
- package/dist/api/compiler/transformers/declarations-diagnostics.d.ts +52 -0
- package/dist/api/compiler/transformers/declarations-diagnostics.js +538 -0
- package/dist/api/compiler/transformers/declarations-pseudo.d.ts +160 -0
- package/dist/api/compiler/transformers/declarations-pseudo.js +797 -0
- package/dist/api/compiler/transformers/declarations-resolver.d.ts +152 -0
- package/dist/api/compiler/transformers/declarations-resolver.js +35 -0
- package/dist/api/compiler/transformers/declarations-syntactic.d.ts +119 -0
- package/dist/api/compiler/transformers/declarations-syntactic.js +1582 -0
- package/dist/api/compiler/transformers/declarations-tracker.d.ts +46 -0
- package/dist/api/compiler/transformers/declarations-tracker.js +197 -0
- package/dist/api/compiler/transformers/declarations.d.ts +175 -0
- package/dist/api/compiler/transformers/declarations.js +2380 -0
- package/dist/api/compiler/transformers/decorator-metadata.d.ts +54 -0
- package/dist/api/compiler/transformers/decorator-metadata.js +554 -0
- package/dist/api/compiler/transformers/decorator-utilities.d.ts +38 -0
- package/dist/api/compiler/transformers/decorator-utilities.js +238 -0
- package/dist/api/compiler/transformers/destructuring.d.ts +25 -0
- package/dist/api/compiler/transformers/destructuring.js +626 -0
- package/dist/api/compiler/transformers/downlevel.d.ts +6 -0
- package/dist/api/compiler/transformers/downlevel.js +45 -0
- package/dist/api/compiler/transformers/emit-resolver.d.ts +61 -0
- package/dist/api/compiler/transformers/emit-resolver.js +197 -0
- package/dist/api/compiler/transformers/es-decorators.d.ts +118 -0
- package/dist/api/compiler/transformers/es-decorators.js +1901 -0
- package/dist/api/compiler/transformers/exponentiation.d.ts +11 -0
- package/dist/api/compiler/transformers/exponentiation.js +76 -0
- package/dist/api/compiler/transformers/external-module-info.d.ts +35 -0
- package/dist/api/compiler/transformers/external-module-info.js +351 -0
- package/dist/api/compiler/transformers/for-await.d.ts +43 -0
- package/dist/api/compiler/transformers/for-await.js +469 -0
- package/dist/api/compiler/transformers/import-elision.d.ts +16 -0
- package/dist/api/compiler/transformers/import-elision.js +124 -0
- package/dist/api/compiler/transformers/jsx-entities.d.ts +1 -0
- package/dist/api/compiler/transformers/jsx-entities.js +256 -0
- package/dist/api/compiler/transformers/jsx.d.ts +71 -0
- package/dist/api/compiler/transformers/jsx.js +700 -0
- package/dist/api/compiler/transformers/legacy-decorators.d.ts +56 -0
- package/dist/api/compiler/transformers/legacy-decorators.js +564 -0
- package/dist/api/compiler/transformers/logical-assignment.d.ts +14 -0
- package/dist/api/compiler/transformers/logical-assignment.js +62 -0
- package/dist/api/compiler/transformers/module-utilities.d.ts +9 -0
- package/dist/api/compiler/transformers/module-utilities.js +36 -0
- package/dist/api/compiler/transformers/module.d.ts +49 -0
- package/dist/api/compiler/transformers/module.js +296 -0
- package/dist/api/compiler/transformers/named-evaluation.d.ts +26 -0
- package/dist/api/compiler/transformers/named-evaluation.js +266 -0
- package/dist/api/compiler/transformers/nullish-coalescing.d.ts +9 -0
- package/dist/api/compiler/transformers/nullish-coalescing.js +26 -0
- package/dist/api/compiler/transformers/object-rest-spread.d.ts +34 -0
- package/dist/api/compiler/transformers/object-rest-spread.js +411 -0
- package/dist/api/compiler/transformers/optional-catch.d.ts +9 -0
- package/dist/api/compiler/transformers/optional-catch.js +20 -0
- package/dist/api/compiler/transformers/optional-chain.d.ts +14 -0
- package/dist/api/compiler/transformers/optional-chain.js +188 -0
- package/dist/api/compiler/transformers/reference-resolver.d.ts +128 -0
- package/dist/api/compiler/transformers/reference-resolver.js +1155 -0
- package/dist/api/compiler/transformers/runtime-syntax.d.ts +71 -0
- package/dist/api/compiler/transformers/runtime-syntax.js +753 -0
- package/dist/api/compiler/transformers/subtree-facts.d.ts +9 -0
- package/dist/api/compiler/transformers/subtree-facts.js +203 -0
- package/dist/api/compiler/transformers/syntax-facts.d.ts +51 -0
- package/dist/api/compiler/transformers/syntax-facts.js +254 -0
- package/dist/api/compiler/transformers/tagged-template.d.ts +17 -0
- package/dist/api/compiler/transformers/tagged-template.js +148 -0
- package/dist/api/compiler/transformers/transformer.d.ts +17 -0
- package/dist/api/compiler/transformers/transformer.js +54 -0
- package/dist/api/compiler/transformers/type-eraser.d.ts +21 -0
- package/dist/api/compiler/transformers/type-eraser.js +346 -0
- package/dist/api/compiler/transformers/type-serialization.d.ts +20 -0
- package/dist/api/compiler/transformers/type-serialization.js +347 -0
- package/dist/api/compiler/transformers/using.d.ts +56 -0
- package/dist/api/compiler/transformers/using.js +453 -0
- package/dist/api/compiler/transformers/utilities.d.ts +50 -0
- package/dist/api/compiler/transformers/utilities.js +347 -0
- package/dist/api/compiler/transformers/visitor-base.d.ts +6 -0
- package/dist/api/compiler/transformers/visitor-base.js +817 -0
- package/dist/api/compiler/transformers/visitor-hooks.d.ts +29 -0
- package/dist/api/compiler/transformers/visitor-hooks.js +189 -0
- package/dist/api/compiler/tsconfig.d.ts +177 -0
- package/dist/api/compiler/tsconfig.js +1311 -0
- package/dist/api/compiler/type-printer.d.ts +15 -0
- package/dist/api/compiler/type-printer.js +74 -0
- package/dist/api/compiler/types.d.ts +87 -0
- package/dist/api/compiler/types.js +23 -0
- package/dist/api/compiler/unicode-identifiers.d.ts +2 -0
- package/dist/api/compiler/unicode-identifiers.js +209 -0
- package/dist/api/compiler/unicode-properties.d.ts +8 -0
- package/dist/api/compiler/unicode-properties.js +531 -0
- package/dist/api/compiler/vfs-match.d.ts +24 -0
- package/dist/api/compiler/vfs-match.js +587 -0
- package/dist/api/library/ast.d.ts +74 -0
- package/dist/api/library/ast.generated.d.ts +1145 -0
- package/dist/api/library/ast.generated.js +3 -0
- package/dist/api/library/ast.js +5 -0
- package/dist/api/library/checker.d.ts +51 -0
- package/dist/api/library/checker.js +318 -0
- package/dist/api/library/compiler-options.generated.d.ts +108 -0
- package/dist/api/library/compiler-options.generated.js +3 -0
- package/dist/api/library/diagnostics.d.ts +13 -0
- package/dist/api/library/diagnostics.js +50 -0
- package/dist/api/library/disk.d.ts +13 -0
- package/dist/api/library/disk.js +66 -0
- package/dist/api/library/enums.generated.d.ts +891 -0
- package/dist/api/library/enums.generated.js +916 -0
- package/dist/api/library/errors.d.ts +13 -0
- package/dist/api/library/errors.js +24 -0
- package/dist/api/library/host.d.ts +24 -0
- package/dist/api/library/host.js +52 -0
- package/dist/api/library/index.d.ts +14 -0
- package/dist/api/library/index.js +15 -0
- package/dist/api/library/nodes.d.ts +51 -0
- package/dist/api/library/nodes.js +196 -0
- package/dist/api/library/options.d.ts +144 -0
- package/dist/api/library/options.js +308 -0
- package/dist/api/library/parse.d.ts +19 -0
- package/dist/api/library/parse.js +41 -0
- package/dist/api/library/program.d.ts +21 -0
- package/dist/api/library/program.js +234 -0
- package/dist/api/library/symbols.d.ts +8 -0
- package/dist/api/library/symbols.js +11 -0
- package/dist/api/library/types.d.ts +313 -0
- package/dist/api/library/types.js +6 -0
- package/package.json +22 -8
- package/src/compiler/ast-utilities.ts +548 -0
- package/src/compiler/ast.ts +12862 -0
- package/src/compiler/astnav.ts +799 -0
- package/src/compiler/binder-utilities.ts +1392 -0
- package/src/compiler/binder.ts +2703 -0
- package/src/compiler/build-info.ts +1197 -0
- package/src/compiler/character-codes.ts +323 -0
- package/src/compiler/checker-calls.ts +2155 -0
- package/src/compiler/checker-classes.ts +706 -0
- package/src/compiler/checker-contextual.ts +1457 -0
- package/src/compiler/checker-declaration-order.ts +438 -0
- package/src/compiler/checker-declarations.ts +1194 -0
- package/src/compiler/checker-declared-types.ts +919 -0
- package/src/compiler/checker-decorators.ts +694 -0
- package/src/compiler/checker-deprecation.ts +359 -0
- package/src/compiler/checker-destructuring.ts +805 -0
- package/src/compiler/checker-elaboration.ts +477 -0
- package/src/compiler/checker-emit-helpers.ts +224 -0
- package/src/compiler/checker-emit-resolver.ts +769 -0
- package/src/compiler/checker-evaluator.ts +243 -0
- package/src/compiler/checker-expressions.ts +1831 -0
- package/src/compiler/checker-features.ts +361 -0
- package/src/compiler/checker-flow.ts +394 -0
- package/src/compiler/checker-functions.ts +1296 -0
- package/src/compiler/checker-generated-code.ts +227 -0
- package/src/compiler/checker-globals.ts +52 -0
- package/src/compiler/checker-grammar.ts +3584 -0
- package/src/compiler/checker-heritage.ts +1233 -0
- package/src/compiler/checker-inference.ts +2576 -0
- package/src/compiler/checker-iteration.ts +1206 -0
- package/src/compiler/checker-javascript.ts +502 -0
- package/src/compiler/checker-jsdoc.ts +360 -0
- package/src/compiler/checker-jsx.ts +1924 -0
- package/src/compiler/checker-literals.ts +61 -0
- package/src/compiler/checker-members.ts +2436 -0
- package/src/compiler/checker-modules.ts +2886 -0
- package/src/compiler/checker-narrowing.ts +3230 -0
- package/src/compiler/checker-object-literals.ts +575 -0
- package/src/compiler/checker-operators.ts +1422 -0
- package/src/compiler/checker-overloads.ts +328 -0
- package/src/compiler/checker-property-access.ts +906 -0
- package/src/compiler/checker-services.ts +1149 -0
- package/src/compiler/checker-signatures.ts +1032 -0
- package/src/compiler/checker-source-file.ts +732 -0
- package/src/compiler/checker-statements.ts +292 -0
- package/src/compiler/checker-super.ts +261 -0
- package/src/compiler/checker-symbol-types.ts +2107 -0
- package/src/compiler/checker-symbols.ts +2150 -0
- package/src/compiler/checker-type-factory.ts +2579 -0
- package/src/compiler/checker-type-nodes.ts +1033 -0
- package/src/compiler/checker-type-operators.ts +2502 -0
- package/src/compiler/checker-types.ts +2340 -0
- package/src/compiler/checker-unused.ts +642 -0
- package/src/compiler/checker-utilities.ts +161 -0
- package/src/compiler/checker.ts +1116 -0
- package/src/compiler/command-line.ts +436 -0
- package/src/compiler/compile-program.ts +439 -0
- package/src/compiler/decoder.ts +1209 -0
- package/src/compiler/diagnostic-locales.ts +86 -0
- package/src/compiler/diagnostic-messages.ts +2349 -0
- package/src/compiler/diagnostics.ts +897 -0
- package/src/compiler/emitter.ts +434 -0
- package/src/compiler/encoder.ts +1945 -0
- package/src/compiler/file-include.ts +673 -0
- package/src/compiler/file-loader.ts +1528 -0
- package/src/compiler/file-system.ts +143 -0
- package/src/compiler/flow.ts +89 -0
- package/src/compiler/help.ts +473 -0
- package/src/compiler/incremental.ts +2784 -0
- package/src/compiler/init.ts +141 -0
- package/src/compiler/instantiation.ts +894 -0
- package/src/compiler/jsdoc.ts +1386 -0
- package/src/compiler/link-tables.ts +98 -0
- package/src/compiler/locale-data.ts +203 -0
- package/src/compiler/locale.ts +307 -0
- package/src/compiler/locales/cs-CZ.ts +5 -0
- package/src/compiler/locales/de-DE.ts +5 -0
- package/src/compiler/locales/es-ES.ts +5 -0
- package/src/compiler/locales/fr-FR.ts +5 -0
- package/src/compiler/locales/it-IT.ts +5 -0
- package/src/compiler/locales/ja-JP.ts +5 -0
- package/src/compiler/locales/ko-KR.ts +5 -0
- package/src/compiler/locales/pl-PL.ts +5 -0
- package/src/compiler/locales/pt-BR.ts +5 -0
- package/src/compiler/locales/ru-RU.ts +5 -0
- package/src/compiler/locales/tr-TR.ts +5 -0
- package/src/compiler/locales/zh-CN.ts +5 -0
- package/src/compiler/locales/zh-TW.ts +5 -0
- package/src/compiler/module-resolution-types.ts +243 -0
- package/src/compiler/module-resolution.ts +2072 -0
- package/src/compiler/module-specifiers.ts +1491 -0
- package/src/compiler/name-resolver.ts +646 -0
- package/src/compiler/node-builder-names.ts +1069 -0
- package/src/compiler/node-builder-pseudo.ts +892 -0
- package/src/compiler/node-builder-reuse.ts +764 -0
- package/src/compiler/node-builder.ts +3425 -0
- package/src/compiler/option-declarations.ts +1560 -0
- package/src/compiler/options.ts +1576 -0
- package/src/compiler/output-paths.ts +334 -0
- package/src/compiler/package-json.ts +1083 -0
- package/src/compiler/parallel-check.ts +1951 -0
- package/src/compiler/parallel-parse.ts +590 -0
- package/src/compiler/parse-thread.ts +140 -0
- package/src/compiler/parser.ts +7716 -0
- package/src/compiler/path.ts +717 -0
- package/src/compiler/printer/async-helpers.ts +183 -0
- package/src/compiler/printer/auto-generate.ts +27 -0
- package/src/compiler/printer/decorator-helpers.ts +218 -0
- package/src/compiler/printer/emit-context.ts +679 -0
- package/src/compiler/printer/emit-flags.ts +64 -0
- package/src/compiler/printer/factory-base.ts +2577 -0
- package/src/compiler/printer/factory.ts +764 -0
- package/src/compiler/printer/helpers.ts +291 -0
- package/src/compiler/printer/name-generator.ts +372 -0
- package/src/compiler/printer/printer.ts +5072 -0
- package/src/compiler/printer/text-writer.ts +183 -0
- package/src/compiler/printer/utilities.ts +884 -0
- package/src/compiler/program-checker.ts +592 -0
- package/src/compiler/program-utilities.ts +435 -0
- package/src/compiler/program.ts +1419 -0
- package/src/compiler/pseudo-bigint.ts +62 -0
- package/src/compiler/regexp-checker.ts +1142 -0
- package/src/compiler/relations.ts +5149 -0
- package/src/compiler/reparser.ts +1566 -0
- package/src/compiler/scanner.ts +2951 -0
- package/src/compiler/show-config.ts +239 -0
- package/src/compiler/side-state.ts +125 -0
- package/src/compiler/sourcemap.ts +366 -0
- package/src/compiler/spelling.ts +122 -0
- package/src/compiler/symbol-accessibility.ts +1071 -0
- package/src/compiler/symbol.ts +439 -0
- package/src/compiler/symlinks.ts +137 -0
- package/src/compiler/syntax-kind.ts +391 -0
- package/src/compiler/thread-entry.ts +191 -0
- package/src/compiler/timeline.ts +53 -0
- package/src/compiler/transformers/alias-references.ts +757 -0
- package/src/compiler/transformers/async-utilities.ts +335 -0
- package/src/compiler/transformers/async.ts +838 -0
- package/src/compiler/transformers/class-fields.ts +2967 -0
- package/src/compiler/transformers/class-utilities.ts +324 -0
- package/src/compiler/transformers/commonjs-module.ts +1621 -0
- package/src/compiler/transformers/const-enum-inliner.ts +50 -0
- package/src/compiler/transformers/declarations-diagnostics.ts +832 -0
- package/src/compiler/transformers/declarations-pseudo.ts +966 -0
- package/src/compiler/transformers/declarations-resolver.ts +249 -0
- package/src/compiler/transformers/declarations-syntactic.ts +1859 -0
- package/src/compiler/transformers/declarations-tracker.ts +269 -0
- package/src/compiler/transformers/declarations.ts +3120 -0
- package/src/compiler/transformers/decorator-metadata.ts +697 -0
- package/src/compiler/transformers/decorator-utilities.ts +283 -0
- package/src/compiler/transformers/destructuring.ts +708 -0
- package/src/compiler/transformers/downlevel.ts +50 -0
- package/src/compiler/transformers/emit-resolver.ts +258 -0
- package/src/compiler/transformers/es-decorators.ts +2682 -0
- package/src/compiler/transformers/exponentiation.ts +80 -0
- package/src/compiler/transformers/external-module-info.ts +412 -0
- package/src/compiler/transformers/for-await.ts +687 -0
- package/src/compiler/transformers/import-elision.ts +152 -0
- package/src/compiler/transformers/jsx-entities.ts +256 -0
- package/src/compiler/transformers/jsx.ts +824 -0
- package/src/compiler/transformers/legacy-decorators.ts +726 -0
- package/src/compiler/transformers/logical-assignment.ts +75 -0
- package/src/compiler/transformers/module-utilities.ts +42 -0
- package/src/compiler/transformers/module.ts +474 -0
- package/src/compiler/transformers/named-evaluation.ts +389 -0
- package/src/compiler/transformers/nullish-coalescing.ts +35 -0
- package/src/compiler/transformers/object-rest-spread.ts +577 -0
- package/src/compiler/transformers/optional-catch.ts +29 -0
- package/src/compiler/transformers/optional-chain.ts +246 -0
- package/src/compiler/transformers/reference-resolver.ts +1201 -0
- package/src/compiler/transformers/runtime-syntax.ts +942 -0
- package/src/compiler/transformers/subtree-facts.ts +245 -0
- package/src/compiler/transformers/syntax-facts.ts +353 -0
- package/src/compiler/transformers/tagged-template.ts +167 -0
- package/src/compiler/transformers/transformer.ts +56 -0
- package/src/compiler/transformers/type-eraser.ts +520 -0
- package/src/compiler/transformers/type-serialization.ts +374 -0
- package/src/compiler/transformers/using.ts +613 -0
- package/src/compiler/transformers/utilities.ts +419 -0
- package/src/compiler/transformers/visitor-base.ts +1601 -0
- package/src/compiler/transformers/visitor-hooks.ts +252 -0
- package/src/compiler/tsc-build.ts +1418 -0
- package/src/compiler/tsc-cli.ts +666 -0
- package/src/compiler/tsc-compile.ts +437 -0
- package/src/compiler/tsc-watch.ts +854 -0
- package/src/compiler/tsconfig.ts +1574 -0
- package/src/compiler/type-printer.ts +110 -0
- package/src/compiler/types.ts +115 -0
- package/src/compiler/unicode-identifiers.ts +212 -0
- package/src/compiler/unicode-properties.ts +537 -0
- package/src/compiler/vfs-match.ts +597 -0
- package/src/compiler/xxh3.ts +650 -0
- package/src/library/ast.generated.ts +1685 -0
- package/src/library/ast.ts +104 -0
- package/src/library/checker.ts +384 -0
- package/src/library/compiler-options.generated.ts +114 -0
- package/src/library/diagnostics.ts +72 -0
- package/src/library/disk.ts +73 -0
- package/src/library/enums.generated.ts +1024 -0
- package/src/library/errors.ts +26 -0
- package/src/library/host.ts +63 -0
- package/src/library/index.ts +71 -0
- package/src/library/nodes.ts +232 -0
- package/src/library/options.ts +449 -0
- package/src/library/parse.ts +63 -0
- package/src/library/program.ts +293 -0
- package/src/library/symbols.ts +15 -0
- package/src/library/types.ts +359 -0
|
@@ -0,0 +1,1323 @@
|
|
|
1
|
+
// Reparsing of JSDoc in JavaScript files into TypeScript syntax, a port of tsgo's parser/reparser.go.
|
|
2
|
+
//
|
|
3
|
+
// Hosted tags (`@type`, `@param`, `@returns`, …) add children to the node they document; unhosted
|
|
4
|
+
// tags (`@typedef`, `@callback`, `@import`, `@overload`) produce declarations in `Parser.reparseList`.
|
|
5
|
+
// Reparsed nodes are flagged `NodeFlags.Reparsed`.
|
|
6
|
+
//
|
|
7
|
+
// Fields of `instanceof`-narrowed nodes are read through `as` casts: scriptc reads them
|
|
8
|
+
// statically, but reads fields of a narrowed value dynamically.
|
|
9
|
+
import { ArrayTypeNode, ArrowFunction, AsExpression, BinaryExpression, CallSignatureDeclaration, ClassDeclaration, ClassExpression, ConstructSignatureDeclaration, ConstructorDeclaration, ConstructorTypeNode, ElementAccessExpression, ExportAssignment, ExpressionStatement, ExpressionWithTypeArguments, FunctionDeclaration, FunctionExpression, FunctionTypeNode, GetAccessorDeclaration, HeritageClause, Identifier, ImportDeclaration, IndexSignatureDeclaration, JSDoc, JSDocAugmentsTag, JSDocCallbackTag, JSDocImplementsTag, JSDocImportTag, JSDocOverloadTag, JSDocParameterOrPropertyTag, JSDocSatisfiesTag, JSDocSignature, JSDocTemplateTag, JSDocThisTag, JSDocTypeExpression, JSDocTypeLiteral, JSDocTypedefTag, JSDocVariadicType, JSDocOptionalType, KeywordTypeNode, MethodDeclaration, MethodSignatureDeclaration, ModifierList, ModuleBlock, ModuleDeclaration, NodeList, NodeVisitor, NumericLiteral, ParameterDeclaration, ParenthesizedExpression, PropertyAccessExpression, PropertyAssignment, PropertyDeclaration, PropertySignatureDeclaration, QualifiedName, ReturnStatement, SatisfiesExpression, SetAccessorDeclaration, ShorthandPropertyAssignment, StringLiteral, Token, TypeAliasDeclaration, TypeLiteralNode, TypeParameterDeclaration, VariableDeclaration, VariableStatement, getComment, getModifiers, getName, getParameters, getText, getType, getTypeExpression, getTypeParameters, } from './ast.js';
|
|
10
|
+
import { isAssignmentOperator, isFunctionLike, isInJSFile, isLeftHandSideExpression, isStringLiteralLike, } from './ast-utilities.js';
|
|
11
|
+
import { isIdentifierPart, isIdentifierStart } from './character-codes.js';
|
|
12
|
+
/** Sets the parent of every node in a subtree. */
|
|
13
|
+
class ParentInChildrenSetter extends NodeVisitor {
|
|
14
|
+
parent = undefined;
|
|
15
|
+
visitNode(node) {
|
|
16
|
+
node.parent = this.parent;
|
|
17
|
+
const saveParent = this.parent;
|
|
18
|
+
this.parent = node;
|
|
19
|
+
node.forEachChild(this);
|
|
20
|
+
this.parent = saveParent;
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export class Reparser {
|
|
25
|
+
p;
|
|
26
|
+
parentSetter;
|
|
27
|
+
constructor(p) {
|
|
28
|
+
this.p = p;
|
|
29
|
+
this.parentSetter = new ParentInChildrenSetter();
|
|
30
|
+
}
|
|
31
|
+
// Node helpers
|
|
32
|
+
finishReparsedNode(node, locationNode) {
|
|
33
|
+
node.flags = this.p.contextFlags | 8 /* NodeFlags.Reparsed */;
|
|
34
|
+
node.pos = locationNode.pos;
|
|
35
|
+
node.end = locationNode.end;
|
|
36
|
+
this.p.overrideParentInImmediateChildren(node);
|
|
37
|
+
return node;
|
|
38
|
+
}
|
|
39
|
+
finishMutatedNode(node) {
|
|
40
|
+
this.p.overrideParentInImmediateChildren(node);
|
|
41
|
+
return node;
|
|
42
|
+
}
|
|
43
|
+
/** Sets parents in a cloned subtree and flags its root as reparsed. */
|
|
44
|
+
finishClone(clone) {
|
|
45
|
+
const setter = this.parentSetter;
|
|
46
|
+
setter.parent = clone;
|
|
47
|
+
clone.forEachChild(setter);
|
|
48
|
+
setter.parent = undefined;
|
|
49
|
+
clone.flags |= 8 /* NodeFlags.Reparsed */;
|
|
50
|
+
return clone;
|
|
51
|
+
}
|
|
52
|
+
/** A reparsed deep clone, not recorded in `reparsedClones`. */
|
|
53
|
+
deepCloneReparse(node) {
|
|
54
|
+
return this.finishClone(node.deepClone());
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A reparsed deep clone, recorded in `reparsedClones`: the binder attaches symbols to reparsed nodes,
|
|
58
|
+
* and the list maps JSDoc nodes to them.
|
|
59
|
+
*/
|
|
60
|
+
addDeepCloneReparse(node) {
|
|
61
|
+
const clone = this.deepCloneReparse(node);
|
|
62
|
+
this.p.reparsedClones.push(clone);
|
|
63
|
+
return clone;
|
|
64
|
+
}
|
|
65
|
+
addDeepCloneReparseIdentifier(node) {
|
|
66
|
+
const clone = node.copy();
|
|
67
|
+
this.finishClone(clone);
|
|
68
|
+
this.p.reparsedClones.push(clone);
|
|
69
|
+
return clone;
|
|
70
|
+
}
|
|
71
|
+
addTransformedReparse(newNode, old) {
|
|
72
|
+
this.finishReparsedNode(newNode, old);
|
|
73
|
+
newNode.flags |= 268435456 /* NodeFlags.ReparserTransformedLiteral */;
|
|
74
|
+
this.p.reparsedClones.push(newNode);
|
|
75
|
+
return newNode;
|
|
76
|
+
}
|
|
77
|
+
/** A deep clone of modifiers, without reparsed flags or parents. */
|
|
78
|
+
cloneModifiers(modifiers) {
|
|
79
|
+
if (modifiers === undefined)
|
|
80
|
+
return undefined;
|
|
81
|
+
const nodes = [];
|
|
82
|
+
for (const m of modifiers.nodes)
|
|
83
|
+
nodes.push(m.deepClone());
|
|
84
|
+
return new ModifierList(modifiers.pos, modifiers.end, nodes, modifiers.modifierFlags);
|
|
85
|
+
}
|
|
86
|
+
/** Reports an invalid identifier name, at the preceding character if it's missing. */
|
|
87
|
+
checkNonIdentifierName(name) {
|
|
88
|
+
if (name instanceof Identifier && !isValidIdentifier(name.text)) {
|
|
89
|
+
if (name.end - name.pos === 0)
|
|
90
|
+
this.p.parseErrorAt(name.pos - 1, name.pos, 1 /* Diagnostics.Identifier_expected */);
|
|
91
|
+
else
|
|
92
|
+
this.p.parseErrorAt(name.pos, name.end, 1 /* Diagnostics.Identifier_expected */);
|
|
93
|
+
}
|
|
94
|
+
return name;
|
|
95
|
+
}
|
|
96
|
+
// Tags
|
|
97
|
+
reparseTags(parent, jsDoc) {
|
|
98
|
+
let index = 0;
|
|
99
|
+
for (const doc of jsDoc) {
|
|
100
|
+
const isLast = index === jsDoc.length - 1;
|
|
101
|
+
index++;
|
|
102
|
+
const j = asJSDoc(doc);
|
|
103
|
+
if (j === undefined || j.tags === undefined)
|
|
104
|
+
continue;
|
|
105
|
+
for (const tag of j.tags.nodes) {
|
|
106
|
+
this.reparseUnhosted(tag, parent, j);
|
|
107
|
+
if (isLast)
|
|
108
|
+
this.reparseHosted(tag, parent, j);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
reparseUnhosted(tag, parent, jsDoc) {
|
|
114
|
+
const p = this.p;
|
|
115
|
+
if (tag instanceof JSDocTypedefTag) {
|
|
116
|
+
const typeExpression = tag.typeExpression;
|
|
117
|
+
if (typeExpression === undefined)
|
|
118
|
+
return false;
|
|
119
|
+
const fullName = tag.name;
|
|
120
|
+
const modifiers = fullName instanceof ModuleDeclaration ? this.createExportModifier(tag) : undefined;
|
|
121
|
+
const name = this.cloneTypeAliasName(this.checkNonIdentifierName(this.getInnermostNameOfJSDocNamespace(fullName)));
|
|
122
|
+
const typeParameters = this.gatherTypeParameters(jsDoc, true);
|
|
123
|
+
let type;
|
|
124
|
+
if (typeExpression instanceof JSDocTypeExpression)
|
|
125
|
+
type = this.addDeepCloneReparse(typeExpression.type);
|
|
126
|
+
else if (typeExpression instanceof JSDocTypeLiteral)
|
|
127
|
+
type = this.reparseJSDocTypeLiteral(typeExpression);
|
|
128
|
+
else
|
|
129
|
+
throw new Error('typedef tag type expression should be a name reference or a type expression');
|
|
130
|
+
const typeAlias = new TypeAliasDeclaration(345 /* SyntaxKind.JSTypeAliasDeclaration */, modifiers, name, typeParameters, type);
|
|
131
|
+
this.finishReparsedNode(typeAlias, tag);
|
|
132
|
+
this.attachReparsedJSDoc(typeAlias, jsDoc);
|
|
133
|
+
p.reparseList.push(this.wrapInJSDocNamespace(fullName, typeAlias, false));
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
if (tag instanceof JSDocCallbackTag) {
|
|
137
|
+
const fullName = tag.name;
|
|
138
|
+
const modifiers = fullName instanceof ModuleDeclaration ? this.createExportModifier(tag) : undefined;
|
|
139
|
+
const functionType = this.reparseJSDocSignature(tag.typeExpression, tag, jsDoc, tag, undefined);
|
|
140
|
+
const name = this.cloneTypeAliasName(this.getInnermostNameOfJSDocNamespace(fullName));
|
|
141
|
+
const typeParameters = this.gatherTypeParameters(jsDoc, true);
|
|
142
|
+
const typeAlias = new TypeAliasDeclaration(345 /* SyntaxKind.JSTypeAliasDeclaration */, modifiers, name, typeParameters, functionType);
|
|
143
|
+
this.finishReparsedNode(typeAlias, tag);
|
|
144
|
+
this.attachReparsedJSDoc(typeAlias, jsDoc);
|
|
145
|
+
p.reparseList.push(this.wrapInJSDocNamespace(fullName, typeAlias, false));
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
if (tag instanceof JSDocImportTag) {
|
|
149
|
+
const tagImportClause = tag.importClause;
|
|
150
|
+
if (tagImportClause === undefined)
|
|
151
|
+
return false;
|
|
152
|
+
const importClause = tagImportClause.copy();
|
|
153
|
+
this.finishClone(importClause);
|
|
154
|
+
p.reparsedClones.push(importClause);
|
|
155
|
+
importClause.phaseModifier = 156 /* SyntaxKind.TypeKeyword */;
|
|
156
|
+
const moduleSpecifier = this.addDeepCloneReparse(tag.moduleSpecifier);
|
|
157
|
+
const tagAttributes = tag.attributes;
|
|
158
|
+
let attributes;
|
|
159
|
+
if (tagAttributes !== undefined) {
|
|
160
|
+
const copy = tagAttributes.copy();
|
|
161
|
+
this.finishClone(copy);
|
|
162
|
+
p.reparsedClones.push(copy);
|
|
163
|
+
attributes = copy;
|
|
164
|
+
}
|
|
165
|
+
const importDeclaration = new ImportDeclaration(346 /* SyntaxKind.JSImportDeclaration */, undefined, importClause, moduleSpecifier, attributes);
|
|
166
|
+
this.finishReparsedNode(importDeclaration, tag);
|
|
167
|
+
p.reparseList.push(importDeclaration);
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
if (tag instanceof JSDocOverloadTag) {
|
|
171
|
+
// Overload signatures only for functions, methods and constructors outside object literals.
|
|
172
|
+
if ((parent.kind === 263 /* SyntaxKind.FunctionDeclaration */ ||
|
|
173
|
+
parent.kind === 175 /* SyntaxKind.MethodDeclaration */ ||
|
|
174
|
+
parent.kind === 177 /* SyntaxKind.Constructor */) &&
|
|
175
|
+
!p.inObjectLiteralMembers())
|
|
176
|
+
p.reparseList.push(this.reparseJSDocSignature(tag.typeExpression, parent, jsDoc, tag, getModifiers(parent)));
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
attachReparsedJSDoc(node, jsDoc) {
|
|
182
|
+
const docs = [];
|
|
183
|
+
docs.push(jsDoc);
|
|
184
|
+
this.p.setJSDoc(node, docs);
|
|
185
|
+
node.flags |= 2097152 /* NodeFlags.HasJSDoc */;
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
cloneTypeAliasName(name) {
|
|
189
|
+
if (!(name instanceof Identifier))
|
|
190
|
+
throw new Error('Expected an identifier for a JSDoc type alias name');
|
|
191
|
+
return this.addDeepCloneReparseIdentifier(name);
|
|
192
|
+
}
|
|
193
|
+
reparseJSDocSignature(jsSignature, fun, jsDoc, tag, modifiers) {
|
|
194
|
+
const p = this.p;
|
|
195
|
+
const clonedModifiers = this.cloneModifiers(modifiers);
|
|
196
|
+
// The name, then the type parameters, then the parameters, as tsgo creates them.
|
|
197
|
+
let functionName;
|
|
198
|
+
let methodName;
|
|
199
|
+
if (fun instanceof FunctionDeclaration) {
|
|
200
|
+
const name = fun.name;
|
|
201
|
+
if (name !== undefined) {
|
|
202
|
+
this.checkNonIdentifierName(name);
|
|
203
|
+
functionName = name.copy();
|
|
204
|
+
this.finishClone(functionName);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
else if (fun instanceof MethodDeclaration) {
|
|
208
|
+
methodName = this.deepCloneReparse(this.checkNonIdentifierName(fun.name));
|
|
209
|
+
}
|
|
210
|
+
else if (fun.kind !== 177 /* SyntaxKind.Constructor */ && fun.kind !== 331 /* SyntaxKind.JSDocCallbackTag */) {
|
|
211
|
+
throw new Error('Unexpected kind ' + fun.kind);
|
|
212
|
+
}
|
|
213
|
+
const typeParameters = tag.kind !== 331 /* SyntaxKind.JSDocCallbackTag */ ? this.gatherTypeParameters(jsDoc, false) : undefined;
|
|
214
|
+
const parameters = [];
|
|
215
|
+
const signatureParameters = jsSignature instanceof JSDocSignature ? jsSignature.parameters : undefined;
|
|
216
|
+
if (signatureParameters !== undefined) {
|
|
217
|
+
const params = signatureParameters.nodes;
|
|
218
|
+
for (let pi = 0; pi < params.length; pi++) {
|
|
219
|
+
const param = params[pi];
|
|
220
|
+
let parameter;
|
|
221
|
+
if (param instanceof JSDocThisTag) {
|
|
222
|
+
const thisIdent = new Identifier('this');
|
|
223
|
+
thisIdent.pos = param.pos;
|
|
224
|
+
thisIdent.end = param.end;
|
|
225
|
+
thisIdent.flags = p.contextFlags | 8 /* NodeFlags.Reparsed */;
|
|
226
|
+
const type = this.addDeepCloneReparse(getType(param.typeExpression));
|
|
227
|
+
parameter = new ParameterDeclaration(undefined, undefined, thisIdent, undefined, type, undefined);
|
|
228
|
+
}
|
|
229
|
+
else if (param instanceof JSDocParameterOrPropertyTag) {
|
|
230
|
+
// Sub-properties like `@param x.y` describe a parameter's properties, not parameters.
|
|
231
|
+
if (param.name instanceof QualifiedName)
|
|
232
|
+
continue;
|
|
233
|
+
let dotDotDotToken;
|
|
234
|
+
let paramType;
|
|
235
|
+
const typeExpression = param.typeExpression;
|
|
236
|
+
if (typeExpression !== undefined) {
|
|
237
|
+
const type = getType(typeExpression);
|
|
238
|
+
if (type instanceof JSDocVariadicType) {
|
|
239
|
+
dotDotDotToken = new Token(25 /* SyntaxKind.DotDotDotToken */);
|
|
240
|
+
dotDotDotToken.pos = param.pos;
|
|
241
|
+
dotDotDotToken.end = param.end;
|
|
242
|
+
dotDotDotToken.flags = p.contextFlags | 8 /* NodeFlags.Reparsed */;
|
|
243
|
+
paramType = this.reparseJSDocTypeLiteral(type.type);
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
paramType = this.reparseJSDocTypeLiteral(type);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
let name = param.name;
|
|
250
|
+
if (name instanceof Identifier && !isValidIdentifier(name.text)) {
|
|
251
|
+
// Replace invalid characters with `_`, or use `_N` for an empty name, for a valid parameter name.
|
|
252
|
+
name = this.addTransformedReparse(new Identifier(sanitizeIdentifier(name.text, pi)), name);
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
name = this.addDeepCloneReparse(name);
|
|
256
|
+
}
|
|
257
|
+
parameter = new ParameterDeclaration(undefined, dotDotDotToken, name, this.makeQuestionIfOptional(param), paramType, undefined);
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
this.finishReparsedNode(parameter, param);
|
|
263
|
+
parameters.push(parameter);
|
|
264
|
+
this.reparseJSDocComment(parameter, param);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
const parameterList = new NodeList(signatureParameters !== undefined ? signatureParameters.pos : -1, signatureParameters !== undefined ? signatureParameters.end : -1, parameters);
|
|
268
|
+
let returnType;
|
|
269
|
+
const returnTag = getType(jsSignature);
|
|
270
|
+
if (returnTag !== undefined) {
|
|
271
|
+
const returnTypeExpression = getTypeExpression(returnTag);
|
|
272
|
+
if (returnTypeExpression !== undefined)
|
|
273
|
+
returnType = this.addDeepCloneReparse(getType(returnTypeExpression));
|
|
274
|
+
}
|
|
275
|
+
let signature;
|
|
276
|
+
if (fun instanceof FunctionDeclaration)
|
|
277
|
+
signature = new FunctionDeclaration(clonedModifiers, undefined, functionName, typeParameters, parameterList, returnType, undefined, undefined);
|
|
278
|
+
else if (fun instanceof MethodDeclaration)
|
|
279
|
+
signature = new MethodDeclaration(clonedModifiers, undefined, methodName, undefined, typeParameters, parameterList, returnType, undefined, undefined);
|
|
280
|
+
else if (fun instanceof ConstructorDeclaration)
|
|
281
|
+
signature = new ConstructorDeclaration(clonedModifiers, typeParameters, parameterList, returnType, undefined, undefined);
|
|
282
|
+
else
|
|
283
|
+
signature = new FunctionTypeNode(undefined, parameterList, returnType !== undefined ? returnType : new KeywordTypeNode(132 /* SyntaxKind.AnyKeyword */));
|
|
284
|
+
const location = tag instanceof JSDocOverloadTag ? tag.tagName : jsSignature;
|
|
285
|
+
this.finishReparsedNode(signature, location);
|
|
286
|
+
return signature;
|
|
287
|
+
}
|
|
288
|
+
reparseJSDocTypeLiteral(type) {
|
|
289
|
+
if (type instanceof JSDocTypeLiteral) {
|
|
290
|
+
const properties = [];
|
|
291
|
+
const tags = type.jsdocPropertyTags;
|
|
292
|
+
if (tags !== undefined)
|
|
293
|
+
for (const tag of tags) {
|
|
294
|
+
const prop = asParameterOrPropertyTag(tag);
|
|
295
|
+
if (prop !== undefined)
|
|
296
|
+
properties.push(this.reparseJSDocProperty(prop));
|
|
297
|
+
}
|
|
298
|
+
let result = new TypeLiteralNode(this.p.newNodeList(type.pos, type.end, properties));
|
|
299
|
+
if (type.isArrayType) {
|
|
300
|
+
this.finishReparsedNode(result, type);
|
|
301
|
+
result = new ArrayTypeNode(result);
|
|
302
|
+
}
|
|
303
|
+
this.finishReparsedNode(result, type);
|
|
304
|
+
return result;
|
|
305
|
+
}
|
|
306
|
+
return this.addDeepCloneReparse(type);
|
|
307
|
+
}
|
|
308
|
+
reparseJSDocProperty(prop) {
|
|
309
|
+
let name = prop.name;
|
|
310
|
+
if (name instanceof QualifiedName)
|
|
311
|
+
name = name.right;
|
|
312
|
+
if (name instanceof Identifier && !isValidIdentifier(name.text))
|
|
313
|
+
name = this.addTransformedReparse(new StringLiteral(name.text, 0 /* TokenFlags.None */), name);
|
|
314
|
+
else
|
|
315
|
+
name = this.addDeepCloneReparse(name);
|
|
316
|
+
const questionToken = this.makeQuestionIfOptional(prop);
|
|
317
|
+
const propertyType = prop.typeExpression !== undefined ? this.reparseJSDocTypeLiteral(getType(prop.typeExpression)) : undefined;
|
|
318
|
+
const property = new PropertySignatureDeclaration(undefined, name, questionToken, propertyType, undefined);
|
|
319
|
+
this.finishReparsedNode(property, prop);
|
|
320
|
+
this.reparseJSDocComment(property, prop);
|
|
321
|
+
return property;
|
|
322
|
+
}
|
|
323
|
+
/** Copies a tag's comment to a JSDoc node for its reparsed node. */
|
|
324
|
+
reparseJSDocComment(node, tag) {
|
|
325
|
+
const comment = getComment(tag);
|
|
326
|
+
if (comment === undefined)
|
|
327
|
+
return false;
|
|
328
|
+
const nodes = [];
|
|
329
|
+
for (const c of comment.nodes)
|
|
330
|
+
nodes.push(this.deepCloneReparse(c));
|
|
331
|
+
const propJSDoc = new JSDoc(new NodeList(comment.pos, comment.end, nodes), undefined);
|
|
332
|
+
this.finishReparsedNode(propJSDoc, tag);
|
|
333
|
+
propJSDoc.parent = node;
|
|
334
|
+
const docs = [];
|
|
335
|
+
docs.push(propJSDoc);
|
|
336
|
+
this.p.setJSDoc(node, docs);
|
|
337
|
+
node.flags |= 2097152 /* NodeFlags.HasJSDoc */;
|
|
338
|
+
return true;
|
|
339
|
+
}
|
|
340
|
+
/** The type parameters of the `@template` tags; for non-typedefs, none if the comment has a @typedef or @callback. */
|
|
341
|
+
gatherTypeParameters(j, typedefOrCallback) {
|
|
342
|
+
const typeParameters = [];
|
|
343
|
+
let pos = -1;
|
|
344
|
+
let endPos = -1;
|
|
345
|
+
let firstTemplate = true;
|
|
346
|
+
const tags = j.tags;
|
|
347
|
+
if (tags === undefined)
|
|
348
|
+
return undefined;
|
|
349
|
+
for (const tag of tags.nodes) {
|
|
350
|
+
// With a @typedef or @callback, @template declares the defined type's type parameters.
|
|
351
|
+
if (!typedefOrCallback && (tag.kind === 338 /* SyntaxKind.JSDocTypedefTag */ || tag.kind === 331 /* SyntaxKind.JSDocCallbackTag */))
|
|
352
|
+
return undefined;
|
|
353
|
+
if (!(tag instanceof JSDocTemplateTag))
|
|
354
|
+
continue;
|
|
355
|
+
if (firstTemplate) {
|
|
356
|
+
pos = tag.pos;
|
|
357
|
+
firstTemplate = false;
|
|
358
|
+
}
|
|
359
|
+
endPos = tag.end;
|
|
360
|
+
const constraint = tag.constraint;
|
|
361
|
+
let firstTypeParameter = true;
|
|
362
|
+
for (const tp of tag.typeParameters.nodes) {
|
|
363
|
+
let reparse;
|
|
364
|
+
if (constraint !== undefined && firstTypeParameter && tp instanceof TypeParameterDeclaration) {
|
|
365
|
+
const modifiers = this.cloneModifiers(tp.modifiers);
|
|
366
|
+
this.checkNonIdentifierName(tp.name);
|
|
367
|
+
const name = this.addDeepCloneReparseIdentifier(tp.name);
|
|
368
|
+
const constraintType = this.addDeepCloneReparse(getType(constraint));
|
|
369
|
+
const tpDefault = tp.defaultType;
|
|
370
|
+
const defaultType = tpDefault !== undefined ? this.addDeepCloneReparse(tpDefault) : undefined;
|
|
371
|
+
reparse = new TypeParameterDeclaration(modifiers, name, constraintType, undefined, defaultType);
|
|
372
|
+
this.finishReparsedNode(reparse, tp);
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
reparse = this.addDeepCloneReparse(tp);
|
|
376
|
+
}
|
|
377
|
+
typeParameters.push(reparse);
|
|
378
|
+
firstTypeParameter = false;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return typeParameters.length === 0 ? undefined : this.p.newNodeList(pos, endPos, typeParameters);
|
|
382
|
+
}
|
|
383
|
+
reparseHosted(tag, parent, jsDoc) {
|
|
384
|
+
switch (tag.kind) {
|
|
385
|
+
case 336 /* SyntaxKind.JSDocTypeTag */:
|
|
386
|
+
return this.reparseTypeTag(tag, parent);
|
|
387
|
+
case 342 /* SyntaxKind.JSDocSatisfiesTag */:
|
|
388
|
+
if (tag instanceof JSDocSatisfiesTag)
|
|
389
|
+
this.reparseSatisfiesTag(tag, parent);
|
|
390
|
+
return true;
|
|
391
|
+
case 337 /* SyntaxKind.JSDocTemplateTag */: {
|
|
392
|
+
const fun = getFunctionLikeHost(parent);
|
|
393
|
+
if (fun !== undefined) {
|
|
394
|
+
if (getTypeParameters(fun) === undefined && getFullSignature(fun) === undefined) {
|
|
395
|
+
setTypeParameters(fun, this.gatherTypeParameters(jsDoc, false));
|
|
396
|
+
this.finishMutatedNode(fun);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
else if (parent.kind === 264 /* SyntaxKind.ClassDeclaration */ || parent.kind === 232 /* SyntaxKind.ClassExpression */) {
|
|
400
|
+
if (getClassTypeParameters(parent) === undefined) {
|
|
401
|
+
setClassTypeParameters(parent, this.gatherTypeParameters(jsDoc, false));
|
|
402
|
+
this.finishMutatedNode(parent);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
return true;
|
|
406
|
+
}
|
|
407
|
+
case 333 /* SyntaxKind.JSDocParameterTag */: {
|
|
408
|
+
const fun = getFunctionLikeHost(parent);
|
|
409
|
+
if (fun !== undefined && getFullSignature(fun) === undefined && tag instanceof JSDocParameterOrPropertyTag) {
|
|
410
|
+
const param = findMatchingParameter(fun, tag, jsDoc);
|
|
411
|
+
if (param !== undefined) {
|
|
412
|
+
const typeExpression = tag.typeExpression;
|
|
413
|
+
if (param.type === undefined && typeExpression !== undefined)
|
|
414
|
+
param.type = this.reparseJSDocTypeLiteral(getType(typeExpression));
|
|
415
|
+
if (param.questionToken === undefined) {
|
|
416
|
+
const question = this.makeQuestionIfOptional(tag);
|
|
417
|
+
if (question !== undefined)
|
|
418
|
+
param.questionToken = question;
|
|
419
|
+
}
|
|
420
|
+
this.finishMutatedNode(param);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
return true;
|
|
424
|
+
}
|
|
425
|
+
case 335 /* SyntaxKind.JSDocThisTag */: {
|
|
426
|
+
const fun = getFunctionLikeHost(parent);
|
|
427
|
+
if (fun !== undefined && tag instanceof JSDocThisTag) {
|
|
428
|
+
const parameters = getParameters(fun);
|
|
429
|
+
const params = parameters !== undefined ? parameters.nodes : [];
|
|
430
|
+
const firstName = params.length > 0 ? getName(params[0]) : undefined;
|
|
431
|
+
if (params.length === 0 ||
|
|
432
|
+
(firstName !== undefined &&
|
|
433
|
+
firstName.kind !== 109 /* SyntaxKind.ThisKeyword */ &&
|
|
434
|
+
!(firstName instanceof Identifier && firstName.text === 'this'))) {
|
|
435
|
+
// tsgo gives the `this` name no location.
|
|
436
|
+
const thisParam = new ParameterDeclaration(undefined, undefined, new Identifier('this'), undefined, undefined, undefined);
|
|
437
|
+
thisParam.type = this.addDeepCloneReparse(getType(tag.typeExpression));
|
|
438
|
+
this.finishReparsedNode(thisParam, tag.tagName);
|
|
439
|
+
const newParams = [thisParam];
|
|
440
|
+
for (const param of params)
|
|
441
|
+
newParams.push(param);
|
|
442
|
+
setParameters(fun, this.p.newNodeList(parameters !== undefined ? parameters.pos : -1, parameters !== undefined ? parameters.end : -1, newParams));
|
|
443
|
+
this.finishMutatedNode(fun);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
return true;
|
|
447
|
+
}
|
|
448
|
+
case 334 /* SyntaxKind.JSDocReturnTag */: {
|
|
449
|
+
const fun = getFunctionLikeHost(parent);
|
|
450
|
+
if (fun !== undefined && getFullSignature(fun) === undefined) {
|
|
451
|
+
const typeExpression = getTypeExpression(tag);
|
|
452
|
+
if (getType(fun) === undefined && typeExpression !== undefined) {
|
|
453
|
+
setType(fun, this.addDeepCloneReparse(getType(typeExpression)));
|
|
454
|
+
this.finishMutatedNode(fun);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
return true;
|
|
458
|
+
}
|
|
459
|
+
case 329 /* SyntaxKind.JSDocReadonlyTag */:
|
|
460
|
+
case 327 /* SyntaxKind.JSDocPrivateTag */:
|
|
461
|
+
case 326 /* SyntaxKind.JSDocPublicTag */:
|
|
462
|
+
case 328 /* SyntaxKind.JSDocProtectedTag */:
|
|
463
|
+
case 330 /* SyntaxKind.JSDocOverrideTag */:
|
|
464
|
+
return this.reparseModifierTag(tag, parent);
|
|
465
|
+
case 324 /* SyntaxKind.JSDocImplementsTag */:
|
|
466
|
+
if (tag instanceof JSDocImplementsTag)
|
|
467
|
+
this.reparseImplementsTag(tag, parent);
|
|
468
|
+
return true;
|
|
469
|
+
case 323 /* SyntaxKind.JSDocAugmentsTag */:
|
|
470
|
+
if (tag instanceof JSDocAugmentsTag)
|
|
471
|
+
this.reparseAugmentsTag(tag, parent);
|
|
472
|
+
return true;
|
|
473
|
+
}
|
|
474
|
+
return false;
|
|
475
|
+
}
|
|
476
|
+
reparseTypeTag(tag, parent) {
|
|
477
|
+
const typeExpression = getTypeExpression(tag);
|
|
478
|
+
switch (parent.kind) {
|
|
479
|
+
case 244 /* SyntaxKind.VariableStatement */:
|
|
480
|
+
if (parent instanceof VariableStatement)
|
|
481
|
+
for (const declaration of parent.declarationList.declarations.nodes)
|
|
482
|
+
if (declaration instanceof VariableDeclaration &&
|
|
483
|
+
declaration.type === undefined &&
|
|
484
|
+
typeExpression !== undefined) {
|
|
485
|
+
declaration.type = this.addDeepCloneReparse(getType(typeExpression));
|
|
486
|
+
this.finishMutatedNode(declaration);
|
|
487
|
+
return true;
|
|
488
|
+
}
|
|
489
|
+
break;
|
|
490
|
+
case 261 /* SyntaxKind.VariableDeclaration */:
|
|
491
|
+
case 278 /* SyntaxKind.ExportAssignment */:
|
|
492
|
+
case 173 /* SyntaxKind.PropertyDeclaration */:
|
|
493
|
+
case 303 /* SyntaxKind.PropertyAssignment */:
|
|
494
|
+
case 304 /* SyntaxKind.ShorthandPropertyAssignment */:
|
|
495
|
+
case 178 /* SyntaxKind.GetAccessor */:
|
|
496
|
+
if (getType(parent) === undefined && typeExpression !== undefined) {
|
|
497
|
+
setType(parent, this.addDeepCloneReparse(getType(typeExpression)));
|
|
498
|
+
this.finishMutatedNode(parent);
|
|
499
|
+
return true;
|
|
500
|
+
}
|
|
501
|
+
break;
|
|
502
|
+
case 170 /* SyntaxKind.Parameter */:
|
|
503
|
+
if (getType(parent) === undefined && typeExpression !== undefined) {
|
|
504
|
+
setType(parent, this.reparseJSDocTypeLiteral(getType(typeExpression)));
|
|
505
|
+
this.finishMutatedNode(parent);
|
|
506
|
+
return true;
|
|
507
|
+
}
|
|
508
|
+
break;
|
|
509
|
+
case 245 /* SyntaxKind.ExpressionStatement */:
|
|
510
|
+
if (parent instanceof ExpressionStatement) {
|
|
511
|
+
const bin = parent.expression;
|
|
512
|
+
if (bin instanceof BinaryExpression && isAssignmentDeclaration(bin) && typeExpression !== undefined) {
|
|
513
|
+
bin.type = this.addDeepCloneReparse(getType(typeExpression));
|
|
514
|
+
this.finishMutatedNode(bin);
|
|
515
|
+
return true;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
break;
|
|
519
|
+
case 254 /* SyntaxKind.ReturnStatement */:
|
|
520
|
+
case 218 /* SyntaxKind.ParenthesizedExpression */: {
|
|
521
|
+
const expression = getExpressionOfReturnOrParenthesized(parent);
|
|
522
|
+
if (expression !== undefined && typeExpression !== undefined) {
|
|
523
|
+
setExpression(parent, this.makeNewCast(this.addDeepCloneReparse(getType(typeExpression)), expression, true));
|
|
524
|
+
this.finishMutatedNode(parent);
|
|
525
|
+
return true;
|
|
526
|
+
}
|
|
527
|
+
break;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
const fun = getFunctionLikeHost(parent);
|
|
531
|
+
if (fun !== undefined) {
|
|
532
|
+
const parameters = getParameters(fun);
|
|
533
|
+
let noTypedParams = true;
|
|
534
|
+
if (parameters !== undefined)
|
|
535
|
+
for (const param of parameters.nodes)
|
|
536
|
+
if (getType(param) !== undefined) {
|
|
537
|
+
noTypedParams = false;
|
|
538
|
+
break;
|
|
539
|
+
}
|
|
540
|
+
if (getTypeParameters(fun) === undefined &&
|
|
541
|
+
getType(fun) === undefined &&
|
|
542
|
+
noTypedParams &&
|
|
543
|
+
typeExpression !== undefined) {
|
|
544
|
+
setFullSignature(fun, this.addDeepCloneReparse(getType(typeExpression)));
|
|
545
|
+
this.finishMutatedNode(fun);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
return true;
|
|
549
|
+
}
|
|
550
|
+
reparseSatisfiesTag(tag, parent) {
|
|
551
|
+
const typeExpression = tag.typeExpression;
|
|
552
|
+
if (parent instanceof VariableStatement) {
|
|
553
|
+
for (const declaration of parent.declarationList.declarations.nodes)
|
|
554
|
+
if (declaration instanceof VariableDeclaration) {
|
|
555
|
+
const initializer = declaration.initializer;
|
|
556
|
+
if (initializer === undefined)
|
|
557
|
+
continue;
|
|
558
|
+
declaration.initializer = this.makeNewCast(this.addDeepCloneReparse(getType(typeExpression)), initializer, false);
|
|
559
|
+
this.finishMutatedNode(declaration);
|
|
560
|
+
break;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
else if (parent.kind === 261 /* SyntaxKind.VariableDeclaration */ ||
|
|
564
|
+
parent.kind === 173 /* SyntaxKind.PropertyDeclaration */ ||
|
|
565
|
+
parent.kind === 303 /* SyntaxKind.PropertyAssignment */) {
|
|
566
|
+
const initializer = getInitializer(parent);
|
|
567
|
+
if (initializer !== undefined) {
|
|
568
|
+
setInitializer(parent, this.makeNewCast(this.addDeepCloneReparse(getType(typeExpression)), initializer, false));
|
|
569
|
+
this.finishMutatedNode(parent);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
else if (parent instanceof ShorthandPropertyAssignment) {
|
|
573
|
+
const initializer = parent.objectAssignmentInitializer;
|
|
574
|
+
if (initializer !== undefined) {
|
|
575
|
+
parent.objectAssignmentInitializer = this.makeNewCast(this.addDeepCloneReparse(getType(typeExpression)), initializer, false);
|
|
576
|
+
this.finishMutatedNode(parent);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
else if (parent.kind === 254 /* SyntaxKind.ReturnStatement */ ||
|
|
580
|
+
parent.kind === 218 /* SyntaxKind.ParenthesizedExpression */ ||
|
|
581
|
+
parent.kind === 278 /* SyntaxKind.ExportAssignment */) {
|
|
582
|
+
const expression = getExpressionOfReturnOrParenthesized(parent);
|
|
583
|
+
if (expression !== undefined) {
|
|
584
|
+
setExpression(parent, this.makeNewCast(this.addDeepCloneReparse(getType(typeExpression)), expression, false));
|
|
585
|
+
this.finishMutatedNode(parent);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
else if (parent instanceof ExpressionStatement) {
|
|
589
|
+
const bin = parent.expression;
|
|
590
|
+
if (bin instanceof BinaryExpression && isAssignmentDeclaration(bin)) {
|
|
591
|
+
bin.right = this.makeNewCast(this.addDeepCloneReparse(getType(typeExpression)), bin.right, false);
|
|
592
|
+
this.finishMutatedNode(bin);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
return true;
|
|
596
|
+
}
|
|
597
|
+
reparseModifierTag(tag, parent) {
|
|
598
|
+
if (parent instanceof ExpressionStatement)
|
|
599
|
+
parent = parent.expression;
|
|
600
|
+
switch (parent.kind) {
|
|
601
|
+
case 175 /* SyntaxKind.MethodDeclaration */:
|
|
602
|
+
case 178 /* SyntaxKind.GetAccessor */:
|
|
603
|
+
case 179 /* SyntaxKind.SetAccessor */:
|
|
604
|
+
// In object literals these aren't class members: reparsed modifiers would cause spurious grammar errors.
|
|
605
|
+
if (this.p.inObjectLiteralMembers())
|
|
606
|
+
return false;
|
|
607
|
+
break;
|
|
608
|
+
case 173 /* SyntaxKind.PropertyDeclaration */:
|
|
609
|
+
case 177 /* SyntaxKind.Constructor */:
|
|
610
|
+
case 227 /* SyntaxKind.BinaryExpression */:
|
|
611
|
+
break;
|
|
612
|
+
default:
|
|
613
|
+
return false;
|
|
614
|
+
}
|
|
615
|
+
let keyword = 0 /* SyntaxKind.Unknown */;
|
|
616
|
+
switch (tag.kind) {
|
|
617
|
+
case 329 /* SyntaxKind.JSDocReadonlyTag */:
|
|
618
|
+
keyword = 148 /* SyntaxKind.ReadonlyKeyword */;
|
|
619
|
+
break;
|
|
620
|
+
case 327 /* SyntaxKind.JSDocPrivateTag */:
|
|
621
|
+
keyword = 122 /* SyntaxKind.PrivateKeyword */;
|
|
622
|
+
break;
|
|
623
|
+
case 326 /* SyntaxKind.JSDocPublicTag */:
|
|
624
|
+
keyword = 124 /* SyntaxKind.PublicKeyword */;
|
|
625
|
+
break;
|
|
626
|
+
case 328 /* SyntaxKind.JSDocProtectedTag */:
|
|
627
|
+
keyword = 123 /* SyntaxKind.ProtectedKeyword */;
|
|
628
|
+
break;
|
|
629
|
+
default:
|
|
630
|
+
keyword = 164 /* SyntaxKind.OverrideKeyword */;
|
|
631
|
+
}
|
|
632
|
+
const modifier = new Token(keyword);
|
|
633
|
+
modifier.pos = tag.pos;
|
|
634
|
+
modifier.end = tag.end;
|
|
635
|
+
modifier.flags = this.p.contextFlags | 8 /* NodeFlags.Reparsed */;
|
|
636
|
+
const existing = getModifiers(parent);
|
|
637
|
+
let list;
|
|
638
|
+
if (existing === undefined) {
|
|
639
|
+
list = this.p.newModifierList(tag.pos, tag.end, [modifier]);
|
|
640
|
+
}
|
|
641
|
+
else {
|
|
642
|
+
const nodes = existing.nodes.slice();
|
|
643
|
+
nodes.push(modifier);
|
|
644
|
+
list = this.p.newModifierList(existing.pos, existing.end, nodes);
|
|
645
|
+
}
|
|
646
|
+
setModifiers(parent, list);
|
|
647
|
+
this.finishMutatedNode(parent);
|
|
648
|
+
return true;
|
|
649
|
+
}
|
|
650
|
+
reparseImplementsTag(tag, parent) {
|
|
651
|
+
if (parent.kind !== 264 /* SyntaxKind.ClassDeclaration */ && parent.kind !== 232 /* SyntaxKind.ClassExpression */)
|
|
652
|
+
return false;
|
|
653
|
+
const className = tag.className;
|
|
654
|
+
const heritageClauses = getHeritageClauses(parent);
|
|
655
|
+
if (heritageClauses !== undefined) {
|
|
656
|
+
for (const clause of heritageClauses.nodes)
|
|
657
|
+
if (clause instanceof HeritageClause && clause.token === 118 /* SyntaxKind.ImplementsKeyword */) {
|
|
658
|
+
clause.types.nodes.push(this.addDeepCloneReparse(className));
|
|
659
|
+
this.finishMutatedNode(clause);
|
|
660
|
+
return true;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
const typesList = this.p.newNodeList(className.pos, className.end, [this.addDeepCloneReparse(className)]);
|
|
664
|
+
const heritageClause = new HeritageClause(118 /* SyntaxKind.ImplementsKeyword */, typesList);
|
|
665
|
+
this.finishReparsedNode(heritageClause, className);
|
|
666
|
+
if (heritageClauses === undefined)
|
|
667
|
+
setHeritageClauses(parent, this.p.newNodeList(className.pos, className.end, [heritageClause]));
|
|
668
|
+
else
|
|
669
|
+
heritageClauses.nodes.push(heritageClause);
|
|
670
|
+
this.finishMutatedNode(parent);
|
|
671
|
+
return true;
|
|
672
|
+
}
|
|
673
|
+
reparseAugmentsTag(tag, parent) {
|
|
674
|
+
const heritageClauses = getHeritageClauses(parent);
|
|
675
|
+
if (heritageClauses === undefined)
|
|
676
|
+
return false;
|
|
677
|
+
for (const clause of heritageClauses.nodes) {
|
|
678
|
+
if (!(clause instanceof HeritageClause) || clause.token !== 95 /* SyntaxKind.ExtendsKeyword */)
|
|
679
|
+
continue;
|
|
680
|
+
if (clause.types.nodes.length !== 1)
|
|
681
|
+
return false;
|
|
682
|
+
const target = clause.types.nodes[0];
|
|
683
|
+
const source = tag.className;
|
|
684
|
+
if (target instanceof ExpressionWithTypeArguments &&
|
|
685
|
+
hasSamePropertyAccessName(target.expression, source.expression) &&
|
|
686
|
+
target.typeArguments === undefined &&
|
|
687
|
+
source.typeArguments !== undefined) {
|
|
688
|
+
const newArguments = [];
|
|
689
|
+
for (const arg of source.typeArguments.nodes)
|
|
690
|
+
newArguments.push(this.addDeepCloneReparse(arg));
|
|
691
|
+
target.typeArguments = this.p.newNodeList(source.typeArguments.pos, source.typeArguments.end, newArguments);
|
|
692
|
+
this.finishMutatedNode(target);
|
|
693
|
+
}
|
|
694
|
+
return true;
|
|
695
|
+
}
|
|
696
|
+
return false;
|
|
697
|
+
}
|
|
698
|
+
makeQuestionIfOptional(parameter) {
|
|
699
|
+
const typeExpression = parameter.typeExpression;
|
|
700
|
+
if (parameter.isBracketed ||
|
|
701
|
+
(typeExpression !== undefined && getType(typeExpression) instanceof JSDocOptionalType)) {
|
|
702
|
+
const questionToken = new Token(57 /* SyntaxKind.QuestionToken */);
|
|
703
|
+
questionToken.pos = parameter.pos;
|
|
704
|
+
questionToken.end = parameter.end;
|
|
705
|
+
questionToken.flags = this.p.contextFlags | 8 /* NodeFlags.Reparsed */;
|
|
706
|
+
return questionToken;
|
|
707
|
+
}
|
|
708
|
+
return undefined;
|
|
709
|
+
}
|
|
710
|
+
makeNewCast(type, e, isAssertion) {
|
|
711
|
+
const cast = isAssertion ? new AsExpression(e, type) : new SatisfiesExpression(e, type);
|
|
712
|
+
this.p.finishNodeWithEnd(cast, e.pos, e.end);
|
|
713
|
+
return cast;
|
|
714
|
+
}
|
|
715
|
+
createExportModifier(locationNode) {
|
|
716
|
+
const exportModifier = new Token(94 /* SyntaxKind.ExportKeyword */);
|
|
717
|
+
exportModifier.pos = locationNode.pos;
|
|
718
|
+
exportModifier.end = locationNode.end;
|
|
719
|
+
exportModifier.flags = this.p.contextFlags | 8 /* NodeFlags.Reparsed */;
|
|
720
|
+
return this.p.newModifierList(locationNode.pos, locationNode.end, [exportModifier]);
|
|
721
|
+
}
|
|
722
|
+
/** The innermost identifier of a JSDoc namespace chain: `C` for `A.B.C`. */
|
|
723
|
+
getInnermostNameOfJSDocNamespace(fullName) {
|
|
724
|
+
if (fullName === undefined)
|
|
725
|
+
return undefined;
|
|
726
|
+
while (fullName instanceof ModuleDeclaration) {
|
|
727
|
+
const body = fullName.body;
|
|
728
|
+
if (body === undefined)
|
|
729
|
+
return fullName.name;
|
|
730
|
+
fullName = body;
|
|
731
|
+
}
|
|
732
|
+
return fullName;
|
|
733
|
+
}
|
|
734
|
+
/** Wraps `statement` in namespaces for a dotted JSDoc name: `A.B.C` gives `namespace A { namespace B { … } }`. */
|
|
735
|
+
wrapInJSDocNamespace(fullName, statement, nested) {
|
|
736
|
+
if (!(fullName instanceof ModuleDeclaration))
|
|
737
|
+
return statement;
|
|
738
|
+
// Inner namespaces are exported for dotted access; the binder treats the outermost one as
|
|
739
|
+
// exported in module files.
|
|
740
|
+
const wrapped = this.wrapInJSDocNamespace(fullName.body, statement, true);
|
|
741
|
+
const block = new ModuleBlock(this.p.newNodeList(fullName.pos, fullName.end, [wrapped]));
|
|
742
|
+
this.finishReparsedNode(block, fullName);
|
|
743
|
+
const modifiers = nested ? this.createExportModifier(fullName) : undefined;
|
|
744
|
+
const result = new ModuleDeclaration(modifiers, 145 /* SyntaxKind.NamespaceKeyword */, this.addDeepCloneReparse(fullName.name), block);
|
|
745
|
+
this.finishReparsedNode(result, fullName);
|
|
746
|
+
this.p.reparsedClones.push(result);
|
|
747
|
+
return result;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
/** The JSDoc parameter tag's matching parameter, by name or by position. */
|
|
751
|
+
function findMatchingParameter(fun, parameterTag, jsDoc) {
|
|
752
|
+
let tagIndex = -1;
|
|
753
|
+
let paramCount = -1;
|
|
754
|
+
if (jsDoc.tags !== undefined)
|
|
755
|
+
for (const tag of jsDoc.tags.nodes)
|
|
756
|
+
if (tag.kind === 333 /* SyntaxKind.JSDocParameterTag */) {
|
|
757
|
+
paramCount++;
|
|
758
|
+
if (tag === parameterTag) {
|
|
759
|
+
tagIndex = paramCount;
|
|
760
|
+
break;
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
const parameters = getParameters(fun);
|
|
764
|
+
if (parameters === undefined)
|
|
765
|
+
return undefined;
|
|
766
|
+
const params = parameters.nodes;
|
|
767
|
+
const tagName = parameterTag.name;
|
|
768
|
+
let parameterIndex = 0;
|
|
769
|
+
for (const node of params) {
|
|
770
|
+
const parameter = asParameterDeclaration(node);
|
|
771
|
+
if (parameter !== undefined && parameterMatches(parameter, tagName, parameterIndex === tagIndex))
|
|
772
|
+
return parameter;
|
|
773
|
+
parameterIndex++;
|
|
774
|
+
}
|
|
775
|
+
return undefined;
|
|
776
|
+
}
|
|
777
|
+
// Narrowing helpers. scriptc types indexed array elements as possibly undefined and can't narrow
|
|
778
|
+
// those to a class with `instanceof`; these take `for…of` elements.
|
|
779
|
+
function asJSDoc(node) {
|
|
780
|
+
if (node instanceof JSDoc)
|
|
781
|
+
return node;
|
|
782
|
+
return undefined;
|
|
783
|
+
}
|
|
784
|
+
function asParameterOrPropertyTag(node) {
|
|
785
|
+
if (node instanceof JSDocParameterOrPropertyTag)
|
|
786
|
+
return node;
|
|
787
|
+
return undefined;
|
|
788
|
+
}
|
|
789
|
+
function asParameterDeclaration(node) {
|
|
790
|
+
if (node instanceof ParameterDeclaration)
|
|
791
|
+
return node;
|
|
792
|
+
return undefined;
|
|
793
|
+
}
|
|
794
|
+
function parameterMatches(parameter, tagName, isTagIndex) {
|
|
795
|
+
const name = parameter.name;
|
|
796
|
+
if (name instanceof Identifier)
|
|
797
|
+
return (tagName instanceof Identifier &&
|
|
798
|
+
(name.text === tagName.text ||
|
|
799
|
+
(isTagIndex && tagName.text.length === 0)));
|
|
800
|
+
return isTagIndex;
|
|
801
|
+
}
|
|
802
|
+
/** The function documented by a JSDoc host: the host itself, or a function in its initializer or expression. */
|
|
803
|
+
function getFunctionLikeHost(host) {
|
|
804
|
+
let fun = host;
|
|
805
|
+
if (host instanceof VariableStatement) {
|
|
806
|
+
const nodes = host.declarationList.declarations.nodes;
|
|
807
|
+
if (nodes.length !== 0) {
|
|
808
|
+
const first = nodes[0];
|
|
809
|
+
fun = first instanceof VariableDeclaration ? first.initializer : undefined;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
else if (host.kind === 303 /* SyntaxKind.PropertyAssignment */ || host.kind === 173 /* SyntaxKind.PropertyDeclaration */) {
|
|
813
|
+
fun = getInitializer(host);
|
|
814
|
+
}
|
|
815
|
+
else if (host instanceof ExportAssignment) {
|
|
816
|
+
fun = host.expression;
|
|
817
|
+
}
|
|
818
|
+
else if (host instanceof ReturnStatement) {
|
|
819
|
+
fun = host.expression;
|
|
820
|
+
}
|
|
821
|
+
else if (host instanceof ExpressionStatement) {
|
|
822
|
+
fun = getRightMostAssignedExpression(host.expression);
|
|
823
|
+
}
|
|
824
|
+
while (fun instanceof SatisfiesExpression)
|
|
825
|
+
fun = fun.expression;
|
|
826
|
+
return isFunctionLike(fun) ? fun : undefined;
|
|
827
|
+
}
|
|
828
|
+
function getRightMostAssignedExpression(node) {
|
|
829
|
+
while (node instanceof BinaryExpression &&
|
|
830
|
+
(node.operatorToken.kind === 63 /* SyntaxKind.EqualsToken */ ||
|
|
831
|
+
isAssignmentOperator(node.operatorToken.kind)) &&
|
|
832
|
+
isLeftHandSideExpression(node.left))
|
|
833
|
+
node = node.right;
|
|
834
|
+
return node;
|
|
835
|
+
}
|
|
836
|
+
function getExpressionOfReturnOrParenthesized(node) {
|
|
837
|
+
if (node instanceof ReturnStatement)
|
|
838
|
+
return node.expression;
|
|
839
|
+
if (node instanceof ParenthesizedExpression)
|
|
840
|
+
return node.expression;
|
|
841
|
+
if (node instanceof ExportAssignment)
|
|
842
|
+
return node.expression;
|
|
843
|
+
return undefined;
|
|
844
|
+
}
|
|
845
|
+
function hasSamePropertyAccessName(node1, node2) {
|
|
846
|
+
if (node1 instanceof Identifier && node2 instanceof Identifier)
|
|
847
|
+
return node1.text === node2.text;
|
|
848
|
+
if (node1 instanceof PropertyAccessExpression && node2 instanceof PropertyAccessExpression) {
|
|
849
|
+
return (getText(node1.name) === getText(node2.name) &&
|
|
850
|
+
hasSamePropertyAccessName(node1.expression, node2.expression));
|
|
851
|
+
}
|
|
852
|
+
return false;
|
|
853
|
+
}
|
|
854
|
+
// Assignment declarations (tsgo's GetAssignmentDeclarationKind(node) != JSDeclarationKindNone).
|
|
855
|
+
function isIdentifierNamed(node, text) {
|
|
856
|
+
return node instanceof Identifier && node.text === text;
|
|
857
|
+
}
|
|
858
|
+
function skipParentheses(node) {
|
|
859
|
+
while (node instanceof ParenthesizedExpression)
|
|
860
|
+
node = node.expression;
|
|
861
|
+
return node;
|
|
862
|
+
}
|
|
863
|
+
function isStringOrNumericLiteralLike(node) {
|
|
864
|
+
return isStringLiteralLike(node) || node instanceof NumericLiteral;
|
|
865
|
+
}
|
|
866
|
+
function getAccessExpression(node) {
|
|
867
|
+
if (node instanceof PropertyAccessExpression)
|
|
868
|
+
return node.expression;
|
|
869
|
+
if (node instanceof ElementAccessExpression)
|
|
870
|
+
return node.expression;
|
|
871
|
+
return undefined;
|
|
872
|
+
}
|
|
873
|
+
/** The name of a property access with an identifier name, or an element access with a literal argument. */
|
|
874
|
+
function getElementOrPropertyAccessName(node) {
|
|
875
|
+
if (node instanceof PropertyAccessExpression)
|
|
876
|
+
return node.name instanceof Identifier
|
|
877
|
+
? node.name
|
|
878
|
+
: undefined;
|
|
879
|
+
if (node instanceof ElementAccessExpression) {
|
|
880
|
+
const argument = skipParentheses(node.argumentExpression);
|
|
881
|
+
return isStringOrNumericLiteralLike(argument) ? argument : undefined;
|
|
882
|
+
}
|
|
883
|
+
return undefined;
|
|
884
|
+
}
|
|
885
|
+
function isModuleExportsAccessExpression(node) {
|
|
886
|
+
const expression = getAccessExpression(node);
|
|
887
|
+
if (expression !== undefined && isIdentifierNamed(expression, 'module')) {
|
|
888
|
+
const name = getElementOrPropertyAccessName(node);
|
|
889
|
+
return name !== undefined && getText(name) === 'exports';
|
|
890
|
+
}
|
|
891
|
+
return false;
|
|
892
|
+
}
|
|
893
|
+
function isEntityNameExpression(node, allowJS) {
|
|
894
|
+
if (node instanceof Identifier)
|
|
895
|
+
return true;
|
|
896
|
+
if (node instanceof PropertyAccessExpression)
|
|
897
|
+
return (node.name instanceof Identifier &&
|
|
898
|
+
isEntityNameExpression(node.expression, allowJS));
|
|
899
|
+
if (!allowJS)
|
|
900
|
+
return false;
|
|
901
|
+
if (node.kind === 109 /* SyntaxKind.ThisKeyword */)
|
|
902
|
+
return true;
|
|
903
|
+
return (node instanceof ElementAccessExpression &&
|
|
904
|
+
isStringOrNumericLiteralLike(node.argumentExpression) &&
|
|
905
|
+
isEntityNameExpression(node.expression, allowJS));
|
|
906
|
+
}
|
|
907
|
+
function isBindableStaticAccessExpression(node, excludeThisKeyword) {
|
|
908
|
+
if (node instanceof PropertyAccessExpression)
|
|
909
|
+
return ((!excludeThisKeyword && node.expression.kind === 109 /* SyntaxKind.ThisKeyword */) ||
|
|
910
|
+
(node.name instanceof Identifier &&
|
|
911
|
+
isBindableStaticNameExpression(node.expression, true)));
|
|
912
|
+
return isBindableStaticElementAccessExpression(node, excludeThisKeyword);
|
|
913
|
+
}
|
|
914
|
+
function isBindableStaticElementAccessExpression(node, excludeThisKeyword) {
|
|
915
|
+
return (node instanceof ElementAccessExpression &&
|
|
916
|
+
isStringOrNumericLiteralLike(node.argumentExpression) &&
|
|
917
|
+
((!excludeThisKeyword && node.expression.kind === 109 /* SyntaxKind.ThisKeyword */) ||
|
|
918
|
+
isEntityNameExpression(node.expression, false) ||
|
|
919
|
+
isBindableStaticAccessExpression(node.expression, true)));
|
|
920
|
+
}
|
|
921
|
+
function isBindableStaticNameExpression(node, excludeThisKeyword) {
|
|
922
|
+
return isEntityNameExpression(node, false) || isBindableStaticAccessExpression(node, excludeThisKeyword);
|
|
923
|
+
}
|
|
924
|
+
function isAssignmentDeclaration(bin) {
|
|
925
|
+
const left = bin.left;
|
|
926
|
+
if (bin.operatorToken.kind !== 63 /* SyntaxKind.EqualsToken */)
|
|
927
|
+
return false;
|
|
928
|
+
const leftExpression = getAccessExpression(left);
|
|
929
|
+
if (leftExpression === undefined)
|
|
930
|
+
return false;
|
|
931
|
+
const inJS = isInJSFile(left);
|
|
932
|
+
if (inJS) {
|
|
933
|
+
if (isModuleExportsAccessExpression(left) && !isIdentifierNamed(bin.right, 'exports'))
|
|
934
|
+
return true;
|
|
935
|
+
if ((isModuleExportsAccessExpression(leftExpression) || isIdentifierNamed(leftExpression, 'exports')) &&
|
|
936
|
+
getElementOrPropertyAccessName(left) !== undefined)
|
|
937
|
+
return true;
|
|
938
|
+
if (leftExpression.kind === 109 /* SyntaxKind.ThisKeyword */)
|
|
939
|
+
return true;
|
|
940
|
+
}
|
|
941
|
+
if (left instanceof PropertyAccessExpression)
|
|
942
|
+
return (isEntityNameExpression(left.expression, inJS) &&
|
|
943
|
+
left.name instanceof Identifier);
|
|
944
|
+
return (left instanceof ElementAccessExpression &&
|
|
945
|
+
isEntityNameExpression(left.expression, inJS));
|
|
946
|
+
}
|
|
947
|
+
// Fields of function-like and other hosts. (One `instanceof` per statement: scriptc can't access
|
|
948
|
+
// fields through a union of classes.)
|
|
949
|
+
function getFullSignature(node) {
|
|
950
|
+
if (node instanceof FunctionDeclaration)
|
|
951
|
+
return node.fullSignature;
|
|
952
|
+
if (node instanceof MethodDeclaration)
|
|
953
|
+
return node.fullSignature;
|
|
954
|
+
if (node instanceof ConstructorDeclaration)
|
|
955
|
+
return node.fullSignature;
|
|
956
|
+
if (node instanceof GetAccessorDeclaration)
|
|
957
|
+
return node.fullSignature;
|
|
958
|
+
if (node instanceof SetAccessorDeclaration)
|
|
959
|
+
return node.fullSignature;
|
|
960
|
+
if (node instanceof FunctionExpression)
|
|
961
|
+
return node.fullSignature;
|
|
962
|
+
if (node instanceof ArrowFunction)
|
|
963
|
+
return node.fullSignature;
|
|
964
|
+
return undefined;
|
|
965
|
+
}
|
|
966
|
+
/** tsgo stores a full signature on every function-like node, but only these visit it. */
|
|
967
|
+
function setFullSignature(node, value) {
|
|
968
|
+
if (node instanceof FunctionDeclaration) {
|
|
969
|
+
node.fullSignature = value;
|
|
970
|
+
return true;
|
|
971
|
+
}
|
|
972
|
+
if (node instanceof MethodDeclaration) {
|
|
973
|
+
node.fullSignature = value;
|
|
974
|
+
return true;
|
|
975
|
+
}
|
|
976
|
+
if (node instanceof ConstructorDeclaration) {
|
|
977
|
+
node.fullSignature = value;
|
|
978
|
+
return true;
|
|
979
|
+
}
|
|
980
|
+
if (node instanceof GetAccessorDeclaration) {
|
|
981
|
+
node.fullSignature = value;
|
|
982
|
+
return true;
|
|
983
|
+
}
|
|
984
|
+
if (node instanceof SetAccessorDeclaration) {
|
|
985
|
+
node.fullSignature = value;
|
|
986
|
+
return true;
|
|
987
|
+
}
|
|
988
|
+
if (node instanceof FunctionExpression) {
|
|
989
|
+
node.fullSignature = value;
|
|
990
|
+
return true;
|
|
991
|
+
}
|
|
992
|
+
if (node instanceof ArrowFunction) {
|
|
993
|
+
node.fullSignature = value;
|
|
994
|
+
return true;
|
|
995
|
+
}
|
|
996
|
+
return false;
|
|
997
|
+
}
|
|
998
|
+
function setTypeParameters(node, value) {
|
|
999
|
+
if (node instanceof FunctionDeclaration) {
|
|
1000
|
+
node.typeParameters = value;
|
|
1001
|
+
return true;
|
|
1002
|
+
}
|
|
1003
|
+
if (node instanceof MethodDeclaration) {
|
|
1004
|
+
node.typeParameters = value;
|
|
1005
|
+
return true;
|
|
1006
|
+
}
|
|
1007
|
+
if (node instanceof ConstructorDeclaration) {
|
|
1008
|
+
node.typeParameters = value;
|
|
1009
|
+
return true;
|
|
1010
|
+
}
|
|
1011
|
+
if (node instanceof GetAccessorDeclaration) {
|
|
1012
|
+
node.typeParameters = value;
|
|
1013
|
+
return true;
|
|
1014
|
+
}
|
|
1015
|
+
if (node instanceof SetAccessorDeclaration) {
|
|
1016
|
+
node.typeParameters = value;
|
|
1017
|
+
return true;
|
|
1018
|
+
}
|
|
1019
|
+
if (node instanceof FunctionExpression) {
|
|
1020
|
+
node.typeParameters = value;
|
|
1021
|
+
return true;
|
|
1022
|
+
}
|
|
1023
|
+
if (node instanceof ArrowFunction) {
|
|
1024
|
+
node.typeParameters = value;
|
|
1025
|
+
return true;
|
|
1026
|
+
}
|
|
1027
|
+
if (node instanceof MethodSignatureDeclaration) {
|
|
1028
|
+
node.typeParameters = value;
|
|
1029
|
+
return true;
|
|
1030
|
+
}
|
|
1031
|
+
if (node instanceof CallSignatureDeclaration) {
|
|
1032
|
+
node.typeParameters = value;
|
|
1033
|
+
return true;
|
|
1034
|
+
}
|
|
1035
|
+
if (node instanceof ConstructSignatureDeclaration) {
|
|
1036
|
+
node.typeParameters = value;
|
|
1037
|
+
return true;
|
|
1038
|
+
}
|
|
1039
|
+
if (node instanceof FunctionTypeNode) {
|
|
1040
|
+
node.typeParameters = value;
|
|
1041
|
+
return true;
|
|
1042
|
+
}
|
|
1043
|
+
if (node instanceof ConstructorTypeNode) {
|
|
1044
|
+
node.typeParameters = value;
|
|
1045
|
+
return true;
|
|
1046
|
+
}
|
|
1047
|
+
if (node instanceof JSDocSignature) {
|
|
1048
|
+
node.typeParameters = value;
|
|
1049
|
+
return true;
|
|
1050
|
+
}
|
|
1051
|
+
return false;
|
|
1052
|
+
}
|
|
1053
|
+
function setParameters(node, value) {
|
|
1054
|
+
if (node instanceof FunctionDeclaration) {
|
|
1055
|
+
node.parameters = value;
|
|
1056
|
+
return true;
|
|
1057
|
+
}
|
|
1058
|
+
if (node instanceof MethodDeclaration) {
|
|
1059
|
+
node.parameters = value;
|
|
1060
|
+
return true;
|
|
1061
|
+
}
|
|
1062
|
+
if (node instanceof ConstructorDeclaration) {
|
|
1063
|
+
node.parameters = value;
|
|
1064
|
+
return true;
|
|
1065
|
+
}
|
|
1066
|
+
if (node instanceof GetAccessorDeclaration) {
|
|
1067
|
+
node.parameters = value;
|
|
1068
|
+
return true;
|
|
1069
|
+
}
|
|
1070
|
+
if (node instanceof SetAccessorDeclaration) {
|
|
1071
|
+
node.parameters = value;
|
|
1072
|
+
return true;
|
|
1073
|
+
}
|
|
1074
|
+
if (node instanceof FunctionExpression) {
|
|
1075
|
+
node.parameters = value;
|
|
1076
|
+
return true;
|
|
1077
|
+
}
|
|
1078
|
+
if (node instanceof ArrowFunction) {
|
|
1079
|
+
node.parameters = value;
|
|
1080
|
+
return true;
|
|
1081
|
+
}
|
|
1082
|
+
if (node instanceof MethodSignatureDeclaration) {
|
|
1083
|
+
node.parameters = value;
|
|
1084
|
+
return true;
|
|
1085
|
+
}
|
|
1086
|
+
if (node instanceof CallSignatureDeclaration) {
|
|
1087
|
+
node.parameters = value;
|
|
1088
|
+
return true;
|
|
1089
|
+
}
|
|
1090
|
+
if (node instanceof ConstructSignatureDeclaration) {
|
|
1091
|
+
node.parameters = value;
|
|
1092
|
+
return true;
|
|
1093
|
+
}
|
|
1094
|
+
if (node instanceof IndexSignatureDeclaration) {
|
|
1095
|
+
node.parameters = value;
|
|
1096
|
+
return true;
|
|
1097
|
+
}
|
|
1098
|
+
if (node instanceof FunctionTypeNode) {
|
|
1099
|
+
node.parameters = value;
|
|
1100
|
+
return true;
|
|
1101
|
+
}
|
|
1102
|
+
if (node instanceof ConstructorTypeNode) {
|
|
1103
|
+
node.parameters = value;
|
|
1104
|
+
return true;
|
|
1105
|
+
}
|
|
1106
|
+
if (node instanceof JSDocSignature) {
|
|
1107
|
+
node.parameters = value;
|
|
1108
|
+
return true;
|
|
1109
|
+
}
|
|
1110
|
+
return false;
|
|
1111
|
+
}
|
|
1112
|
+
function setType(node, value) {
|
|
1113
|
+
if (node instanceof FunctionDeclaration) {
|
|
1114
|
+
node.type = value;
|
|
1115
|
+
return true;
|
|
1116
|
+
}
|
|
1117
|
+
if (node instanceof MethodDeclaration) {
|
|
1118
|
+
node.type = value;
|
|
1119
|
+
return true;
|
|
1120
|
+
}
|
|
1121
|
+
if (node instanceof ConstructorDeclaration) {
|
|
1122
|
+
node.type = value;
|
|
1123
|
+
return true;
|
|
1124
|
+
}
|
|
1125
|
+
if (node instanceof GetAccessorDeclaration) {
|
|
1126
|
+
node.type = value;
|
|
1127
|
+
return true;
|
|
1128
|
+
}
|
|
1129
|
+
if (node instanceof SetAccessorDeclaration) {
|
|
1130
|
+
node.type = value;
|
|
1131
|
+
return true;
|
|
1132
|
+
}
|
|
1133
|
+
if (node instanceof FunctionExpression) {
|
|
1134
|
+
node.type = value;
|
|
1135
|
+
return true;
|
|
1136
|
+
}
|
|
1137
|
+
if (node instanceof ArrowFunction) {
|
|
1138
|
+
node.type = value;
|
|
1139
|
+
return true;
|
|
1140
|
+
}
|
|
1141
|
+
if (node instanceof MethodSignatureDeclaration) {
|
|
1142
|
+
node.type = value;
|
|
1143
|
+
return true;
|
|
1144
|
+
}
|
|
1145
|
+
if (node instanceof CallSignatureDeclaration) {
|
|
1146
|
+
node.type = value;
|
|
1147
|
+
return true;
|
|
1148
|
+
}
|
|
1149
|
+
if (node instanceof ConstructSignatureDeclaration) {
|
|
1150
|
+
node.type = value;
|
|
1151
|
+
return true;
|
|
1152
|
+
}
|
|
1153
|
+
if (node instanceof IndexSignatureDeclaration) {
|
|
1154
|
+
node.type = value;
|
|
1155
|
+
return true;
|
|
1156
|
+
}
|
|
1157
|
+
if (node instanceof FunctionTypeNode) {
|
|
1158
|
+
node.type = value;
|
|
1159
|
+
return true;
|
|
1160
|
+
}
|
|
1161
|
+
if (node instanceof ConstructorTypeNode) {
|
|
1162
|
+
node.type = value;
|
|
1163
|
+
return true;
|
|
1164
|
+
}
|
|
1165
|
+
if (node instanceof JSDocSignature) {
|
|
1166
|
+
node.type = value;
|
|
1167
|
+
return true;
|
|
1168
|
+
}
|
|
1169
|
+
if (node instanceof VariableDeclaration) {
|
|
1170
|
+
node.type = value;
|
|
1171
|
+
return true;
|
|
1172
|
+
}
|
|
1173
|
+
if (node instanceof ExportAssignment) {
|
|
1174
|
+
node.type = value;
|
|
1175
|
+
return true;
|
|
1176
|
+
}
|
|
1177
|
+
if (node instanceof PropertyDeclaration) {
|
|
1178
|
+
node.type = value;
|
|
1179
|
+
return true;
|
|
1180
|
+
}
|
|
1181
|
+
if (node instanceof PropertyAssignment) {
|
|
1182
|
+
node.type = value;
|
|
1183
|
+
return true;
|
|
1184
|
+
}
|
|
1185
|
+
if (node instanceof ShorthandPropertyAssignment) {
|
|
1186
|
+
node.type = value;
|
|
1187
|
+
return true;
|
|
1188
|
+
}
|
|
1189
|
+
if (node instanceof ParameterDeclaration) {
|
|
1190
|
+
node.type = value;
|
|
1191
|
+
return true;
|
|
1192
|
+
}
|
|
1193
|
+
if (node instanceof BinaryExpression) {
|
|
1194
|
+
node.type = value;
|
|
1195
|
+
return true;
|
|
1196
|
+
}
|
|
1197
|
+
return false;
|
|
1198
|
+
}
|
|
1199
|
+
function setExpression(node, value) {
|
|
1200
|
+
if (node instanceof ReturnStatement) {
|
|
1201
|
+
node.expression = value;
|
|
1202
|
+
return true;
|
|
1203
|
+
}
|
|
1204
|
+
if (node instanceof ParenthesizedExpression) {
|
|
1205
|
+
node.expression = value;
|
|
1206
|
+
return true;
|
|
1207
|
+
}
|
|
1208
|
+
if (node instanceof ExportAssignment) {
|
|
1209
|
+
node.expression = value;
|
|
1210
|
+
return true;
|
|
1211
|
+
}
|
|
1212
|
+
return false;
|
|
1213
|
+
}
|
|
1214
|
+
function setModifiers(node, value) {
|
|
1215
|
+
if (node instanceof MethodDeclaration) {
|
|
1216
|
+
node.modifiers = value;
|
|
1217
|
+
return true;
|
|
1218
|
+
}
|
|
1219
|
+
if (node instanceof GetAccessorDeclaration) {
|
|
1220
|
+
node.modifiers = value;
|
|
1221
|
+
return true;
|
|
1222
|
+
}
|
|
1223
|
+
if (node instanceof SetAccessorDeclaration) {
|
|
1224
|
+
node.modifiers = value;
|
|
1225
|
+
return true;
|
|
1226
|
+
}
|
|
1227
|
+
if (node instanceof PropertyDeclaration) {
|
|
1228
|
+
node.modifiers = value;
|
|
1229
|
+
return true;
|
|
1230
|
+
}
|
|
1231
|
+
if (node instanceof ConstructorDeclaration) {
|
|
1232
|
+
node.modifiers = value;
|
|
1233
|
+
return true;
|
|
1234
|
+
}
|
|
1235
|
+
if (node instanceof BinaryExpression) {
|
|
1236
|
+
node.modifiers = value;
|
|
1237
|
+
return true;
|
|
1238
|
+
}
|
|
1239
|
+
return false;
|
|
1240
|
+
}
|
|
1241
|
+
function getInitializer(node) {
|
|
1242
|
+
if (node instanceof VariableDeclaration)
|
|
1243
|
+
return node.initializer;
|
|
1244
|
+
if (node instanceof PropertyDeclaration)
|
|
1245
|
+
return node.initializer;
|
|
1246
|
+
if (node instanceof PropertyAssignment)
|
|
1247
|
+
return node.initializer;
|
|
1248
|
+
return undefined;
|
|
1249
|
+
}
|
|
1250
|
+
function setInitializer(node, value) {
|
|
1251
|
+
if (node instanceof VariableDeclaration) {
|
|
1252
|
+
node.initializer = value;
|
|
1253
|
+
return true;
|
|
1254
|
+
}
|
|
1255
|
+
if (node instanceof PropertyDeclaration) {
|
|
1256
|
+
node.initializer = value;
|
|
1257
|
+
return true;
|
|
1258
|
+
}
|
|
1259
|
+
if (node instanceof PropertyAssignment) {
|
|
1260
|
+
node.initializer = value;
|
|
1261
|
+
return true;
|
|
1262
|
+
}
|
|
1263
|
+
return false;
|
|
1264
|
+
}
|
|
1265
|
+
function getHeritageClauses(node) {
|
|
1266
|
+
if (node instanceof ClassDeclaration)
|
|
1267
|
+
return node.heritageClauses;
|
|
1268
|
+
if (node instanceof ClassExpression)
|
|
1269
|
+
return node.heritageClauses;
|
|
1270
|
+
return undefined;
|
|
1271
|
+
}
|
|
1272
|
+
function setHeritageClauses(node, value) {
|
|
1273
|
+
if (node instanceof ClassDeclaration) {
|
|
1274
|
+
node.heritageClauses = value;
|
|
1275
|
+
return true;
|
|
1276
|
+
}
|
|
1277
|
+
if (node instanceof ClassExpression) {
|
|
1278
|
+
node.heritageClauses = value;
|
|
1279
|
+
return true;
|
|
1280
|
+
}
|
|
1281
|
+
return false;
|
|
1282
|
+
}
|
|
1283
|
+
function getClassTypeParameters(node) {
|
|
1284
|
+
if (node instanceof ClassDeclaration)
|
|
1285
|
+
return node.typeParameters;
|
|
1286
|
+
if (node instanceof ClassExpression)
|
|
1287
|
+
return node.typeParameters;
|
|
1288
|
+
return undefined;
|
|
1289
|
+
}
|
|
1290
|
+
function setClassTypeParameters(node, value) {
|
|
1291
|
+
if (node instanceof ClassDeclaration) {
|
|
1292
|
+
node.typeParameters = value;
|
|
1293
|
+
return true;
|
|
1294
|
+
}
|
|
1295
|
+
if (node instanceof ClassExpression) {
|
|
1296
|
+
node.typeParameters = value;
|
|
1297
|
+
return true;
|
|
1298
|
+
}
|
|
1299
|
+
return false;
|
|
1300
|
+
}
|
|
1301
|
+
/** Whether `s` is a valid identifier: an identifier start followed by identifier parts. */
|
|
1302
|
+
function isValidIdentifier(s) {
|
|
1303
|
+
if (s.length === 0)
|
|
1304
|
+
return false;
|
|
1305
|
+
for (let i = 0; i < s.length;) {
|
|
1306
|
+
const ch = s.codePointAt(i);
|
|
1307
|
+
if (i === 0 ? !isIdentifierStart(ch) : !isIdentifierPart(ch))
|
|
1308
|
+
return false;
|
|
1309
|
+
i += ch > 0xffff ? 2 : 1;
|
|
1310
|
+
}
|
|
1311
|
+
return true;
|
|
1312
|
+
}
|
|
1313
|
+
/** `s` with invalid identifier characters replaced by `_`, or `_<index>` if empty. */
|
|
1314
|
+
function sanitizeIdentifier(s, index) {
|
|
1315
|
+
let result = '';
|
|
1316
|
+
for (let i = 0; i < s.length;) {
|
|
1317
|
+
const ch = s.codePointAt(i);
|
|
1318
|
+
const valid = i === 0 ? isIdentifierStart(ch) : isIdentifierPart(ch);
|
|
1319
|
+
result += valid ? String.fromCodePoint(ch) : '_';
|
|
1320
|
+
i += ch > 0xffff ? 2 : 1;
|
|
1321
|
+
}
|
|
1322
|
+
return result.length === 0 ? '_' + index : result;
|
|
1323
|
+
}
|