tsc-ts 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -1
- package/dist/api/compiler/ast-utilities.d.ts +82 -0
- package/dist/api/compiler/ast-utilities.js +462 -0
- package/dist/api/compiler/ast.d.ts +2350 -0
- package/dist/api/compiler/ast.js +11206 -0
- package/dist/api/compiler/astnav.d.ts +37 -0
- package/dist/api/compiler/astnav.js +767 -0
- package/dist/api/compiler/binder-utilities.d.ts +182 -0
- package/dist/api/compiler/binder-utilities.js +1240 -0
- package/dist/api/compiler/binder.d.ts +33 -0
- package/dist/api/compiler/binder.js +2358 -0
- package/dist/api/compiler/character-codes.d.ts +161 -0
- package/dist/api/compiler/character-codes.js +160 -0
- package/dist/api/compiler/checker-calls.d.ts +46 -0
- package/dist/api/compiler/checker-calls.js +1640 -0
- package/dist/api/compiler/checker-classes.d.ts +30 -0
- package/dist/api/compiler/checker-classes.js +582 -0
- package/dist/api/compiler/checker-contextual.d.ts +77 -0
- package/dist/api/compiler/checker-contextual.js +1136 -0
- package/dist/api/compiler/checker-declaration-order.d.ts +12 -0
- package/dist/api/compiler/checker-declaration-order.js +356 -0
- package/dist/api/compiler/checker-declarations.d.ts +33 -0
- package/dist/api/compiler/checker-declarations.js +888 -0
- package/dist/api/compiler/checker-declared-types.d.ts +48 -0
- package/dist/api/compiler/checker-declared-types.js +787 -0
- package/dist/api/compiler/checker-decorators.d.ts +26 -0
- package/dist/api/compiler/checker-decorators.js +562 -0
- package/dist/api/compiler/checker-deprecation.d.ts +33 -0
- package/dist/api/compiler/checker-deprecation.js +315 -0
- package/dist/api/compiler/checker-destructuring.d.ts +34 -0
- package/dist/api/compiler/checker-destructuring.js +584 -0
- package/dist/api/compiler/checker-elaboration.d.ts +15 -0
- package/dist/api/compiler/checker-elaboration.js +290 -0
- package/dist/api/compiler/checker-emit-helpers.d.ts +58 -0
- package/dist/api/compiler/checker-emit-helpers.js +154 -0
- package/dist/api/compiler/checker-emit-resolver.d.ts +75 -0
- package/dist/api/compiler/checker-emit-resolver.js +579 -0
- package/dist/api/compiler/checker-evaluator.d.ts +27 -0
- package/dist/api/compiler/checker-evaluator.js +188 -0
- package/dist/api/compiler/checker-expressions.d.ts +67 -0
- package/dist/api/compiler/checker-expressions.js +1351 -0
- package/dist/api/compiler/checker-features.d.ts +6 -0
- package/dist/api/compiler/checker-features.js +354 -0
- package/dist/api/compiler/checker-flow.d.ts +86 -0
- package/dist/api/compiler/checker-flow.js +169 -0
- package/dist/api/compiler/checker-functions.d.ts +43 -0
- package/dist/api/compiler/checker-functions.js +1002 -0
- package/dist/api/compiler/checker-generated-code.d.ts +25 -0
- package/dist/api/compiler/checker-generated-code.js +168 -0
- package/dist/api/compiler/checker-globals.d.ts +14 -0
- package/dist/api/compiler/checker-globals.js +37 -0
- package/dist/api/compiler/checker-grammar.d.ts +35 -0
- package/dist/api/compiler/checker-grammar.js +2573 -0
- package/dist/api/compiler/checker-heritage.d.ts +28 -0
- package/dist/api/compiler/checker-heritage.js +900 -0
- package/dist/api/compiler/checker-inference.d.ts +179 -0
- package/dist/api/compiler/checker-inference.js +2105 -0
- package/dist/api/compiler/checker-iteration.d.ts +115 -0
- package/dist/api/compiler/checker-iteration.js +857 -0
- package/dist/api/compiler/checker-javascript.d.ts +42 -0
- package/dist/api/compiler/checker-javascript.js +441 -0
- package/dist/api/compiler/checker-jsdoc.d.ts +30 -0
- package/dist/api/compiler/checker-jsdoc.js +320 -0
- package/dist/api/compiler/checker-jsx.d.ts +94 -0
- package/dist/api/compiler/checker-jsx.js +1433 -0
- package/dist/api/compiler/checker-literals.d.ts +6 -0
- package/dist/api/compiler/checker-literals.js +43 -0
- package/dist/api/compiler/checker-members.d.ts +198 -0
- package/dist/api/compiler/checker-members.js +2126 -0
- package/dist/api/compiler/checker-modules.d.ts +85 -0
- package/dist/api/compiler/checker-modules.js +2141 -0
- package/dist/api/compiler/checker-narrowing.d.ts +120 -0
- package/dist/api/compiler/checker-narrowing.js +2797 -0
- package/dist/api/compiler/checker-object-literals.d.ts +14 -0
- package/dist/api/compiler/checker-object-literals.js +479 -0
- package/dist/api/compiler/checker-operators.d.ts +33 -0
- package/dist/api/compiler/checker-operators.js +1040 -0
- package/dist/api/compiler/checker-overloads.d.ts +7 -0
- package/dist/api/compiler/checker-overloads.js +270 -0
- package/dist/api/compiler/checker-property-access.d.ts +34 -0
- package/dist/api/compiler/checker-property-access.js +672 -0
- package/dist/api/compiler/checker-services.d.ts +49 -0
- package/dist/api/compiler/checker-services.js +995 -0
- package/dist/api/compiler/checker-signatures.d.ts +55 -0
- package/dist/api/compiler/checker-signatures.js +788 -0
- package/dist/api/compiler/checker-source-file.d.ts +27 -0
- package/dist/api/compiler/checker-source-file.js +619 -0
- package/dist/api/compiler/checker-statements.d.ts +18 -0
- package/dist/api/compiler/checker-statements.js +226 -0
- package/dist/api/compiler/checker-super.d.ts +13 -0
- package/dist/api/compiler/checker-super.js +241 -0
- package/dist/api/compiler/checker-symbol-types.d.ts +67 -0
- package/dist/api/compiler/checker-symbol-types.js +1885 -0
- package/dist/api/compiler/checker-symbols.d.ts +181 -0
- package/dist/api/compiler/checker-symbols.js +1782 -0
- package/dist/api/compiler/checker-type-factory.d.ts +142 -0
- package/dist/api/compiler/checker-type-factory.js +2501 -0
- package/dist/api/compiler/checker-type-nodes.d.ts +26 -0
- package/dist/api/compiler/checker-type-nodes.js +828 -0
- package/dist/api/compiler/checker-type-operators.d.ts +109 -0
- package/dist/api/compiler/checker-type-operators.js +1842 -0
- package/dist/api/compiler/checker-types.d.ts +1027 -0
- package/dist/api/compiler/checker-types.js +1697 -0
- package/dist/api/compiler/checker-unused.d.ts +19 -0
- package/dist/api/compiler/checker-unused.js +524 -0
- package/dist/api/compiler/checker-utilities.d.ts +33 -0
- package/dist/api/compiler/checker-utilities.js +141 -0
- package/dist/api/compiler/checker.d.ts +491 -0
- package/dist/api/compiler/checker.js +912 -0
- package/dist/api/compiler/command-line.d.ts +32 -0
- package/dist/api/compiler/command-line.js +383 -0
- package/dist/api/compiler/compile-program.d.ts +118 -0
- package/dist/api/compiler/compile-program.js +384 -0
- package/dist/api/compiler/diagnostic-locales.d.ts +22 -0
- package/dist/api/compiler/diagnostic-locales.js +64 -0
- package/dist/api/compiler/diagnostic-messages.d.ts +2166 -0
- package/dist/api/compiler/diagnostic-messages.js +184 -0
- package/dist/api/compiler/diagnostics.d.ts +167 -0
- package/dist/api/compiler/diagnostics.js +820 -0
- package/dist/api/compiler/emitter.d.ts +71 -0
- package/dist/api/compiler/emitter.js +327 -0
- package/dist/api/compiler/file-include.d.ts +117 -0
- package/dist/api/compiler/file-include.js +536 -0
- package/dist/api/compiler/file-loader.d.ts +261 -0
- package/dist/api/compiler/file-loader.js +1257 -0
- package/dist/api/compiler/file-system.d.ts +51 -0
- package/dist/api/compiler/file-system.js +132 -0
- package/dist/api/compiler/flow.d.ts +60 -0
- package/dist/api/compiler/flow.js +45 -0
- package/dist/api/compiler/instantiation.d.ts +74 -0
- package/dist/api/compiler/instantiation.js +799 -0
- package/dist/api/compiler/jsdoc.d.ts +75 -0
- package/dist/api/compiler/jsdoc.js +1229 -0
- package/dist/api/compiler/link-tables.d.ts +36 -0
- package/dist/api/compiler/link-tables.js +83 -0
- package/dist/api/compiler/locale-data.d.ts +24 -0
- package/dist/api/compiler/locale-data.js +183 -0
- package/dist/api/compiler/locale.d.ts +4 -0
- package/dist/api/compiler/locale.js +317 -0
- package/dist/api/compiler/locales/cs-CZ.d.ts +2 -0
- package/dist/api/compiler/locales/cs-CZ.js +3 -0
- package/dist/api/compiler/locales/de-DE.d.ts +2 -0
- package/dist/api/compiler/locales/de-DE.js +3 -0
- package/dist/api/compiler/locales/es-ES.d.ts +2 -0
- package/dist/api/compiler/locales/es-ES.js +3 -0
- package/dist/api/compiler/locales/fr-FR.d.ts +2 -0
- package/dist/api/compiler/locales/fr-FR.js +3 -0
- package/dist/api/compiler/locales/it-IT.d.ts +2 -0
- package/dist/api/compiler/locales/it-IT.js +3 -0
- package/dist/api/compiler/locales/ja-JP.d.ts +2 -0
- package/dist/api/compiler/locales/ja-JP.js +3 -0
- package/dist/api/compiler/locales/ko-KR.d.ts +2 -0
- package/dist/api/compiler/locales/ko-KR.js +3 -0
- package/dist/api/compiler/locales/pl-PL.d.ts +2 -0
- package/dist/api/compiler/locales/pl-PL.js +3 -0
- package/dist/api/compiler/locales/pt-BR.d.ts +2 -0
- package/dist/api/compiler/locales/pt-BR.js +3 -0
- package/dist/api/compiler/locales/ru-RU.d.ts +2 -0
- package/dist/api/compiler/locales/ru-RU.js +3 -0
- package/dist/api/compiler/locales/tr-TR.d.ts +2 -0
- package/dist/api/compiler/locales/tr-TR.js +3 -0
- package/dist/api/compiler/locales/zh-CN.d.ts +2 -0
- package/dist/api/compiler/locales/zh-CN.js +3 -0
- package/dist/api/compiler/locales/zh-TW.d.ts +2 -0
- package/dist/api/compiler/locales/zh-TW.js +3 -0
- package/dist/api/compiler/module-resolution-types.d.ts +83 -0
- package/dist/api/compiler/module-resolution-types.js +176 -0
- package/dist/api/compiler/module-resolution.d.ts +71 -0
- package/dist/api/compiler/module-resolution.js +1598 -0
- package/dist/api/compiler/module-specifiers.d.ts +64 -0
- package/dist/api/compiler/module-specifiers.js +1101 -0
- package/dist/api/compiler/name-resolver.d.ts +43 -0
- package/dist/api/compiler/name-resolver.js +509 -0
- package/dist/api/compiler/node-builder-names.d.ts +32 -0
- package/dist/api/compiler/node-builder-names.js +854 -0
- package/dist/api/compiler/node-builder-pseudo.d.ts +36 -0
- package/dist/api/compiler/node-builder-pseudo.js +744 -0
- package/dist/api/compiler/node-builder-reuse.d.ts +4 -0
- package/dist/api/compiler/node-builder-reuse.js +647 -0
- package/dist/api/compiler/node-builder.d.ts +270 -0
- package/dist/api/compiler/node-builder.js +2645 -0
- package/dist/api/compiler/option-declarations.d.ts +90 -0
- package/dist/api/compiler/option-declarations.js +1460 -0
- package/dist/api/compiler/options.d.ts +289 -0
- package/dist/api/compiler/options.js +1197 -0
- package/dist/api/compiler/output-paths.d.ts +42 -0
- package/dist/api/compiler/output-paths.js +195 -0
- package/dist/api/compiler/package-json.d.ts +175 -0
- package/dist/api/compiler/package-json.js +1015 -0
- package/dist/api/compiler/parallel-parse.d.ts +219 -0
- package/dist/api/compiler/parallel-parse.js +537 -0
- package/dist/api/compiler/parser.d.ts +587 -0
- package/dist/api/compiler/parser.js +6407 -0
- package/dist/api/compiler/path.d.ts +91 -0
- package/dist/api/compiler/path.js +705 -0
- package/dist/api/compiler/printer/async-helpers.d.ts +22 -0
- package/dist/api/compiler/printer/async-helpers.js +91 -0
- package/dist/api/compiler/printer/auto-generate.d.ts +13 -0
- package/dist/api/compiler/printer/auto-generate.js +20 -0
- package/dist/api/compiler/printer/decorator-helpers.d.ts +24 -0
- package/dist/api/compiler/printer/decorator-helpers.js +118 -0
- package/dist/api/compiler/printer/emit-context.d.ts +154 -0
- package/dist/api/compiler/printer/emit-context.js +576 -0
- package/dist/api/compiler/printer/emit-flags.d.ts +60 -0
- package/dist/api/compiler/printer/emit-flags.js +2 -0
- package/dist/api/compiler/printer/factory-base.d.ts +171 -0
- package/dist/api/compiler/printer/factory-base.js +1505 -0
- package/dist/api/compiler/printer/factory.d.ts +147 -0
- package/dist/api/compiler/printer/factory.js +542 -0
- package/dist/api/compiler/printer/helpers.d.ts +27 -0
- package/dist/api/compiler/printer/helpers.js +164 -0
- package/dist/api/compiler/printer/name-generator.d.ts +41 -0
- package/dist/api/compiler/printer/name-generator.js +283 -0
- package/dist/api/compiler/printer/printer.d.ts +411 -0
- package/dist/api/compiler/printer/printer.js +4517 -0
- package/dist/api/compiler/printer/text-writer.d.ts +46 -0
- package/dist/api/compiler/printer/text-writer.js +172 -0
- package/dist/api/compiler/printer/utilities.d.ts +82 -0
- package/dist/api/compiler/printer/utilities.js +817 -0
- package/dist/api/compiler/program-checker.d.ts +156 -0
- package/dist/api/compiler/program-checker.js +526 -0
- package/dist/api/compiler/program-utilities.d.ts +52 -0
- package/dist/api/compiler/program-utilities.js +365 -0
- package/dist/api/compiler/program.d.ts +180 -0
- package/dist/api/compiler/program.js +1011 -0
- package/dist/api/compiler/pseudo-bigint.d.ts +5 -0
- package/dist/api/compiler/pseudo-bigint.js +61 -0
- package/dist/api/compiler/regexp-checker.d.ts +38 -0
- package/dist/api/compiler/regexp-checker.js +942 -0
- package/dist/api/compiler/relations.d.ts +263 -0
- package/dist/api/compiler/relations.js +4002 -0
- package/dist/api/compiler/reparser.d.ts +48 -0
- package/dist/api/compiler/reparser.js +1323 -0
- package/dist/api/compiler/scanner.d.ts +256 -0
- package/dist/api/compiler/scanner.js +2853 -0
- package/dist/api/compiler/side-state.d.ts +16 -0
- package/dist/api/compiler/side-state.js +89 -0
- package/dist/api/compiler/sourcemap.d.ts +55 -0
- package/dist/api/compiler/sourcemap.js +340 -0
- package/dist/api/compiler/spelling.d.ts +14 -0
- package/dist/api/compiler/spelling.js +128 -0
- package/dist/api/compiler/symbol-accessibility.d.ts +57 -0
- package/dist/api/compiler/symbol-accessibility.js +894 -0
- package/dist/api/compiler/symbol.d.ts +240 -0
- package/dist/api/compiler/symbol.js +228 -0
- package/dist/api/compiler/symlinks.d.ts +32 -0
- package/dist/api/compiler/symlinks.js +114 -0
- package/dist/api/compiler/syntax-kind.d.ts +389 -0
- package/dist/api/compiler/syntax-kind.js +2 -0
- package/dist/api/compiler/timeline.d.ts +9 -0
- package/dist/api/compiler/timeline.js +54 -0
- package/dist/api/compiler/transformers/alias-references.d.ts +39 -0
- package/dist/api/compiler/transformers/alias-references.js +676 -0
- package/dist/api/compiler/transformers/async-utilities.d.ts +51 -0
- package/dist/api/compiler/transformers/async-utilities.js +260 -0
- package/dist/api/compiler/transformers/async.d.ts +53 -0
- package/dist/api/compiler/transformers/async.js +645 -0
- package/dist/api/compiler/transformers/class-fields.d.ts +206 -0
- package/dist/api/compiler/transformers/class-fields.js +2418 -0
- package/dist/api/compiler/transformers/class-utilities.d.ts +46 -0
- package/dist/api/compiler/transformers/class-utilities.js +261 -0
- package/dist/api/compiler/transformers/commonjs-module.d.ts +103 -0
- package/dist/api/compiler/transformers/commonjs-module.js +1180 -0
- package/dist/api/compiler/transformers/const-enum-inliner.d.ts +11 -0
- package/dist/api/compiler/transformers/const-enum-inliner.js +36 -0
- package/dist/api/compiler/transformers/declarations-diagnostics.d.ts +52 -0
- package/dist/api/compiler/transformers/declarations-diagnostics.js +538 -0
- package/dist/api/compiler/transformers/declarations-pseudo.d.ts +160 -0
- package/dist/api/compiler/transformers/declarations-pseudo.js +797 -0
- package/dist/api/compiler/transformers/declarations-resolver.d.ts +152 -0
- package/dist/api/compiler/transformers/declarations-resolver.js +35 -0
- package/dist/api/compiler/transformers/declarations-syntactic.d.ts +119 -0
- package/dist/api/compiler/transformers/declarations-syntactic.js +1582 -0
- package/dist/api/compiler/transformers/declarations-tracker.d.ts +46 -0
- package/dist/api/compiler/transformers/declarations-tracker.js +197 -0
- package/dist/api/compiler/transformers/declarations.d.ts +175 -0
- package/dist/api/compiler/transformers/declarations.js +2380 -0
- package/dist/api/compiler/transformers/decorator-metadata.d.ts +54 -0
- package/dist/api/compiler/transformers/decorator-metadata.js +554 -0
- package/dist/api/compiler/transformers/decorator-utilities.d.ts +38 -0
- package/dist/api/compiler/transformers/decorator-utilities.js +238 -0
- package/dist/api/compiler/transformers/destructuring.d.ts +25 -0
- package/dist/api/compiler/transformers/destructuring.js +626 -0
- package/dist/api/compiler/transformers/downlevel.d.ts +6 -0
- package/dist/api/compiler/transformers/downlevel.js +45 -0
- package/dist/api/compiler/transformers/emit-resolver.d.ts +61 -0
- package/dist/api/compiler/transformers/emit-resolver.js +197 -0
- package/dist/api/compiler/transformers/es-decorators.d.ts +118 -0
- package/dist/api/compiler/transformers/es-decorators.js +1901 -0
- package/dist/api/compiler/transformers/exponentiation.d.ts +11 -0
- package/dist/api/compiler/transformers/exponentiation.js +76 -0
- package/dist/api/compiler/transformers/external-module-info.d.ts +35 -0
- package/dist/api/compiler/transformers/external-module-info.js +351 -0
- package/dist/api/compiler/transformers/for-await.d.ts +43 -0
- package/dist/api/compiler/transformers/for-await.js +469 -0
- package/dist/api/compiler/transformers/import-elision.d.ts +16 -0
- package/dist/api/compiler/transformers/import-elision.js +124 -0
- package/dist/api/compiler/transformers/jsx-entities.d.ts +1 -0
- package/dist/api/compiler/transformers/jsx-entities.js +256 -0
- package/dist/api/compiler/transformers/jsx.d.ts +71 -0
- package/dist/api/compiler/transformers/jsx.js +700 -0
- package/dist/api/compiler/transformers/legacy-decorators.d.ts +56 -0
- package/dist/api/compiler/transformers/legacy-decorators.js +564 -0
- package/dist/api/compiler/transformers/logical-assignment.d.ts +14 -0
- package/dist/api/compiler/transformers/logical-assignment.js +62 -0
- package/dist/api/compiler/transformers/module-utilities.d.ts +9 -0
- package/dist/api/compiler/transformers/module-utilities.js +36 -0
- package/dist/api/compiler/transformers/module.d.ts +49 -0
- package/dist/api/compiler/transformers/module.js +296 -0
- package/dist/api/compiler/transformers/named-evaluation.d.ts +26 -0
- package/dist/api/compiler/transformers/named-evaluation.js +266 -0
- package/dist/api/compiler/transformers/nullish-coalescing.d.ts +9 -0
- package/dist/api/compiler/transformers/nullish-coalescing.js +26 -0
- package/dist/api/compiler/transformers/object-rest-spread.d.ts +34 -0
- package/dist/api/compiler/transformers/object-rest-spread.js +411 -0
- package/dist/api/compiler/transformers/optional-catch.d.ts +9 -0
- package/dist/api/compiler/transformers/optional-catch.js +20 -0
- package/dist/api/compiler/transformers/optional-chain.d.ts +14 -0
- package/dist/api/compiler/transformers/optional-chain.js +188 -0
- package/dist/api/compiler/transformers/reference-resolver.d.ts +128 -0
- package/dist/api/compiler/transformers/reference-resolver.js +1155 -0
- package/dist/api/compiler/transformers/runtime-syntax.d.ts +71 -0
- package/dist/api/compiler/transformers/runtime-syntax.js +753 -0
- package/dist/api/compiler/transformers/subtree-facts.d.ts +9 -0
- package/dist/api/compiler/transformers/subtree-facts.js +203 -0
- package/dist/api/compiler/transformers/syntax-facts.d.ts +51 -0
- package/dist/api/compiler/transformers/syntax-facts.js +254 -0
- package/dist/api/compiler/transformers/tagged-template.d.ts +17 -0
- package/dist/api/compiler/transformers/tagged-template.js +148 -0
- package/dist/api/compiler/transformers/transformer.d.ts +17 -0
- package/dist/api/compiler/transformers/transformer.js +54 -0
- package/dist/api/compiler/transformers/type-eraser.d.ts +21 -0
- package/dist/api/compiler/transformers/type-eraser.js +346 -0
- package/dist/api/compiler/transformers/type-serialization.d.ts +20 -0
- package/dist/api/compiler/transformers/type-serialization.js +347 -0
- package/dist/api/compiler/transformers/using.d.ts +56 -0
- package/dist/api/compiler/transformers/using.js +453 -0
- package/dist/api/compiler/transformers/utilities.d.ts +50 -0
- package/dist/api/compiler/transformers/utilities.js +347 -0
- package/dist/api/compiler/transformers/visitor-base.d.ts +6 -0
- package/dist/api/compiler/transformers/visitor-base.js +817 -0
- package/dist/api/compiler/transformers/visitor-hooks.d.ts +29 -0
- package/dist/api/compiler/transformers/visitor-hooks.js +189 -0
- package/dist/api/compiler/tsconfig.d.ts +177 -0
- package/dist/api/compiler/tsconfig.js +1311 -0
- package/dist/api/compiler/type-printer.d.ts +15 -0
- package/dist/api/compiler/type-printer.js +74 -0
- package/dist/api/compiler/types.d.ts +87 -0
- package/dist/api/compiler/types.js +23 -0
- package/dist/api/compiler/unicode-identifiers.d.ts +2 -0
- package/dist/api/compiler/unicode-identifiers.js +209 -0
- package/dist/api/compiler/unicode-properties.d.ts +8 -0
- package/dist/api/compiler/unicode-properties.js +531 -0
- package/dist/api/compiler/vfs-match.d.ts +24 -0
- package/dist/api/compiler/vfs-match.js +587 -0
- package/dist/api/library/ast.d.ts +3 -2
- package/dist/api/library/ast.generated.d.ts +127 -139
- package/dist/api/library/checker.d.ts +51 -0
- package/dist/api/library/checker.js +318 -0
- package/dist/api/library/diagnostics.d.ts +13 -0
- package/dist/api/library/diagnostics.js +50 -0
- package/dist/api/library/disk.d.ts +13 -0
- package/dist/api/library/disk.js +66 -0
- package/dist/api/library/errors.d.ts +13 -0
- package/dist/api/library/errors.js +24 -0
- package/dist/api/library/host.d.ts +24 -0
- package/dist/api/library/host.js +52 -0
- package/dist/api/library/index.d.ts +5 -1
- package/dist/api/library/index.js +4 -0
- package/dist/api/library/nodes.d.ts +51 -0
- package/dist/api/library/nodes.js +196 -0
- package/dist/api/library/options.d.ts +144 -0
- package/dist/api/library/options.js +308 -0
- package/dist/api/library/parse.d.ts +19 -0
- package/dist/api/library/parse.js +41 -0
- package/dist/api/library/program.d.ts +21 -0
- package/dist/api/library/program.js +234 -0
- package/dist/api/library/types.d.ts +14 -1
- package/package.json +12 -8
- package/src/compiler/ast-utilities.ts +548 -0
- package/src/compiler/ast.ts +12862 -0
- package/src/compiler/astnav.ts +799 -0
- package/src/compiler/binder-utilities.ts +1392 -0
- package/src/compiler/binder.ts +2703 -0
- package/src/compiler/build-info.ts +1197 -0
- package/src/compiler/character-codes.ts +323 -0
- package/src/compiler/checker-calls.ts +2155 -0
- package/src/compiler/checker-classes.ts +706 -0
- package/src/compiler/checker-contextual.ts +1457 -0
- package/src/compiler/checker-declaration-order.ts +438 -0
- package/src/compiler/checker-declarations.ts +1194 -0
- package/src/compiler/checker-declared-types.ts +919 -0
- package/src/compiler/checker-decorators.ts +694 -0
- package/src/compiler/checker-deprecation.ts +359 -0
- package/src/compiler/checker-destructuring.ts +805 -0
- package/src/compiler/checker-elaboration.ts +477 -0
- package/src/compiler/checker-emit-helpers.ts +224 -0
- package/src/compiler/checker-emit-resolver.ts +769 -0
- package/src/compiler/checker-evaluator.ts +243 -0
- package/src/compiler/checker-expressions.ts +1831 -0
- package/src/compiler/checker-features.ts +361 -0
- package/src/compiler/checker-flow.ts +394 -0
- package/src/compiler/checker-functions.ts +1296 -0
- package/src/compiler/checker-generated-code.ts +227 -0
- package/src/compiler/checker-globals.ts +52 -0
- package/src/compiler/checker-grammar.ts +3584 -0
- package/src/compiler/checker-heritage.ts +1233 -0
- package/src/compiler/checker-inference.ts +2576 -0
- package/src/compiler/checker-iteration.ts +1206 -0
- package/src/compiler/checker-javascript.ts +502 -0
- package/src/compiler/checker-jsdoc.ts +360 -0
- package/src/compiler/checker-jsx.ts +1924 -0
- package/src/compiler/checker-literals.ts +61 -0
- package/src/compiler/checker-members.ts +2436 -0
- package/src/compiler/checker-modules.ts +2886 -0
- package/src/compiler/checker-narrowing.ts +3230 -0
- package/src/compiler/checker-object-literals.ts +575 -0
- package/src/compiler/checker-operators.ts +1422 -0
- package/src/compiler/checker-overloads.ts +328 -0
- package/src/compiler/checker-property-access.ts +906 -0
- package/src/compiler/checker-services.ts +1149 -0
- package/src/compiler/checker-signatures.ts +1032 -0
- package/src/compiler/checker-source-file.ts +732 -0
- package/src/compiler/checker-statements.ts +292 -0
- package/src/compiler/checker-super.ts +261 -0
- package/src/compiler/checker-symbol-types.ts +2107 -0
- package/src/compiler/checker-symbols.ts +2150 -0
- package/src/compiler/checker-type-factory.ts +2579 -0
- package/src/compiler/checker-type-nodes.ts +1033 -0
- package/src/compiler/checker-type-operators.ts +2502 -0
- package/src/compiler/checker-types.ts +2340 -0
- package/src/compiler/checker-unused.ts +642 -0
- package/src/compiler/checker-utilities.ts +161 -0
- package/src/compiler/checker.ts +1116 -0
- package/src/compiler/command-line.ts +436 -0
- package/src/compiler/compile-program.ts +439 -0
- package/src/compiler/decoder.ts +1209 -0
- package/src/compiler/diagnostic-locales.ts +86 -0
- package/src/compiler/diagnostic-messages.ts +2349 -0
- package/src/compiler/diagnostics.ts +897 -0
- package/src/compiler/emitter.ts +434 -0
- package/src/compiler/encoder.ts +1945 -0
- package/src/compiler/file-include.ts +673 -0
- package/src/compiler/file-loader.ts +1528 -0
- package/src/compiler/file-system.ts +143 -0
- package/src/compiler/flow.ts +89 -0
- package/src/compiler/help.ts +473 -0
- package/src/compiler/incremental.ts +2784 -0
- package/src/compiler/init.ts +141 -0
- package/src/compiler/instantiation.ts +894 -0
- package/src/compiler/jsdoc.ts +1386 -0
- package/src/compiler/link-tables.ts +98 -0
- package/src/compiler/locale-data.ts +203 -0
- package/src/compiler/locale.ts +307 -0
- package/src/compiler/locales/cs-CZ.ts +5 -0
- package/src/compiler/locales/de-DE.ts +5 -0
- package/src/compiler/locales/es-ES.ts +5 -0
- package/src/compiler/locales/fr-FR.ts +5 -0
- package/src/compiler/locales/it-IT.ts +5 -0
- package/src/compiler/locales/ja-JP.ts +5 -0
- package/src/compiler/locales/ko-KR.ts +5 -0
- package/src/compiler/locales/pl-PL.ts +5 -0
- package/src/compiler/locales/pt-BR.ts +5 -0
- package/src/compiler/locales/ru-RU.ts +5 -0
- package/src/compiler/locales/tr-TR.ts +5 -0
- package/src/compiler/locales/zh-CN.ts +5 -0
- package/src/compiler/locales/zh-TW.ts +5 -0
- package/src/compiler/module-resolution-types.ts +243 -0
- package/src/compiler/module-resolution.ts +2072 -0
- package/src/compiler/module-specifiers.ts +1491 -0
- package/src/compiler/name-resolver.ts +646 -0
- package/src/compiler/node-builder-names.ts +1069 -0
- package/src/compiler/node-builder-pseudo.ts +892 -0
- package/src/compiler/node-builder-reuse.ts +764 -0
- package/src/compiler/node-builder.ts +3425 -0
- package/src/compiler/option-declarations.ts +1560 -0
- package/src/compiler/options.ts +1576 -0
- package/src/compiler/output-paths.ts +334 -0
- package/src/compiler/package-json.ts +1083 -0
- package/src/compiler/parallel-check.ts +1951 -0
- package/src/compiler/parallel-parse.ts +590 -0
- package/src/compiler/parse-thread.ts +140 -0
- package/src/compiler/parser.ts +7716 -0
- package/src/compiler/path.ts +717 -0
- package/src/compiler/printer/async-helpers.ts +183 -0
- package/src/compiler/printer/auto-generate.ts +27 -0
- package/src/compiler/printer/decorator-helpers.ts +218 -0
- package/src/compiler/printer/emit-context.ts +679 -0
- package/src/compiler/printer/emit-flags.ts +64 -0
- package/src/compiler/printer/factory-base.ts +2577 -0
- package/src/compiler/printer/factory.ts +764 -0
- package/src/compiler/printer/helpers.ts +291 -0
- package/src/compiler/printer/name-generator.ts +372 -0
- package/src/compiler/printer/printer.ts +5072 -0
- package/src/compiler/printer/text-writer.ts +183 -0
- package/src/compiler/printer/utilities.ts +884 -0
- package/src/compiler/program-checker.ts +592 -0
- package/src/compiler/program-utilities.ts +435 -0
- package/src/compiler/program.ts +1419 -0
- package/src/compiler/pseudo-bigint.ts +62 -0
- package/src/compiler/regexp-checker.ts +1142 -0
- package/src/compiler/relations.ts +5149 -0
- package/src/compiler/reparser.ts +1566 -0
- package/src/compiler/scanner.ts +2951 -0
- package/src/compiler/show-config.ts +239 -0
- package/src/compiler/side-state.ts +125 -0
- package/src/compiler/sourcemap.ts +366 -0
- package/src/compiler/spelling.ts +122 -0
- package/src/compiler/symbol-accessibility.ts +1071 -0
- package/src/compiler/symbol.ts +439 -0
- package/src/compiler/symlinks.ts +137 -0
- package/src/compiler/syntax-kind.ts +391 -0
- package/src/compiler/thread-entry.ts +191 -0
- package/src/compiler/timeline.ts +53 -0
- package/src/compiler/transformers/alias-references.ts +757 -0
- package/src/compiler/transformers/async-utilities.ts +335 -0
- package/src/compiler/transformers/async.ts +838 -0
- package/src/compiler/transformers/class-fields.ts +2967 -0
- package/src/compiler/transformers/class-utilities.ts +324 -0
- package/src/compiler/transformers/commonjs-module.ts +1621 -0
- package/src/compiler/transformers/const-enum-inliner.ts +50 -0
- package/src/compiler/transformers/declarations-diagnostics.ts +832 -0
- package/src/compiler/transformers/declarations-pseudo.ts +966 -0
- package/src/compiler/transformers/declarations-resolver.ts +249 -0
- package/src/compiler/transformers/declarations-syntactic.ts +1859 -0
- package/src/compiler/transformers/declarations-tracker.ts +269 -0
- package/src/compiler/transformers/declarations.ts +3120 -0
- package/src/compiler/transformers/decorator-metadata.ts +697 -0
- package/src/compiler/transformers/decorator-utilities.ts +283 -0
- package/src/compiler/transformers/destructuring.ts +708 -0
- package/src/compiler/transformers/downlevel.ts +50 -0
- package/src/compiler/transformers/emit-resolver.ts +258 -0
- package/src/compiler/transformers/es-decorators.ts +2682 -0
- package/src/compiler/transformers/exponentiation.ts +80 -0
- package/src/compiler/transformers/external-module-info.ts +412 -0
- package/src/compiler/transformers/for-await.ts +687 -0
- package/src/compiler/transformers/import-elision.ts +152 -0
- package/src/compiler/transformers/jsx-entities.ts +256 -0
- package/src/compiler/transformers/jsx.ts +824 -0
- package/src/compiler/transformers/legacy-decorators.ts +726 -0
- package/src/compiler/transformers/logical-assignment.ts +75 -0
- package/src/compiler/transformers/module-utilities.ts +42 -0
- package/src/compiler/transformers/module.ts +474 -0
- package/src/compiler/transformers/named-evaluation.ts +389 -0
- package/src/compiler/transformers/nullish-coalescing.ts +35 -0
- package/src/compiler/transformers/object-rest-spread.ts +577 -0
- package/src/compiler/transformers/optional-catch.ts +29 -0
- package/src/compiler/transformers/optional-chain.ts +246 -0
- package/src/compiler/transformers/reference-resolver.ts +1201 -0
- package/src/compiler/transformers/runtime-syntax.ts +942 -0
- package/src/compiler/transformers/subtree-facts.ts +245 -0
- package/src/compiler/transformers/syntax-facts.ts +353 -0
- package/src/compiler/transformers/tagged-template.ts +167 -0
- package/src/compiler/transformers/transformer.ts +56 -0
- package/src/compiler/transformers/type-eraser.ts +520 -0
- package/src/compiler/transformers/type-serialization.ts +374 -0
- package/src/compiler/transformers/using.ts +613 -0
- package/src/compiler/transformers/utilities.ts +419 -0
- package/src/compiler/transformers/visitor-base.ts +1601 -0
- package/src/compiler/transformers/visitor-hooks.ts +252 -0
- package/src/compiler/tsc-build.ts +1418 -0
- package/src/compiler/tsc-cli.ts +666 -0
- package/src/compiler/tsc-compile.ts +437 -0
- package/src/compiler/tsc-watch.ts +854 -0
- package/src/compiler/tsconfig.ts +1574 -0
- package/src/compiler/type-printer.ts +110 -0
- package/src/compiler/types.ts +115 -0
- package/src/compiler/unicode-identifiers.ts +212 -0
- package/src/compiler/unicode-properties.ts +537 -0
- package/src/compiler/vfs-match.ts +597 -0
- package/src/compiler/xxh3.ts +650 -0
- package/src/library/ast.generated.ts +141 -167
- package/src/library/ast.ts +4 -1
- package/src/library/checker.ts +384 -0
- package/src/library/diagnostics.ts +72 -0
- package/src/library/disk.ts +73 -0
- package/src/library/errors.ts +26 -0
- package/src/library/host.ts +63 -0
- package/src/library/index.ts +21 -0
- package/src/library/nodes.ts +232 -0
- package/src/library/options.ts +449 -0
- package/src/library/parse.ts +63 -0
- package/src/library/program.ts +293 -0
- package/src/library/types.ts +14 -1
|
@@ -0,0 +1,1229 @@
|
|
|
1
|
+
// JSDoc comment parsing, a port of tsgo's parser/jsdoc.go.
|
|
2
|
+
//
|
|
3
|
+
// Comment indentation is measured in UTF-8 bytes, as in tsgo, so comment text matches it exactly.
|
|
4
|
+
import { ArrayTypeNode, ExpressionWithTypeArguments, Identifier, JSDoc, JSDocAugmentsTag, JSDocCallbackTag, JSDocDeprecatedTag, JSDocImplementsTag, JSDocImportTag, JSDocLink, JSDocLinkCode, JSDocLinkPlain, JSDocNameReference, JSDocOverloadTag, JSDocOverrideTag, JSDocParameterOrPropertyTag, JSDocPrivateTag, JSDocProtectedTag, JSDocPublicTag, JSDocReadonlyTag, JSDocReturnTag, JSDocSatisfiesTag, JSDocSeeTag, JSDocSignature, JSDocTemplateTag, JSDocText, JSDocThisTag, JSDocThrowsTag, JSDocTypeExpression, JSDocTypeLiteral, JSDocTypeTag, JSDocTypedefTag, JSDocUnknownTag, ModuleDeclaration, NodeList, PropertyAccessExpression, QualifiedName, TypeParameterDeclaration, TypeReferenceNode, getTagName, getType, } from './ast.js';
|
|
5
|
+
import { isReservedWord, tokenIsIdentifierOrKeyword } from './ast-utilities.js';
|
|
6
|
+
import { isWhiteSpaceLike } from './character-codes.js';
|
|
7
|
+
import { Diagnostic } from './diagnostics.js';
|
|
8
|
+
import { Reparser } from './reparser.js';
|
|
9
|
+
import { getLeadingCommentRanges, getTrailingCommentRanges } from './scanner.js';
|
|
10
|
+
/** Comment text collected while parsing, with the indentation it has reached. */
|
|
11
|
+
class CommentText {
|
|
12
|
+
parts = [];
|
|
13
|
+
indent;
|
|
14
|
+
margin = -1;
|
|
15
|
+
constructor(indent) {
|
|
16
|
+
this.indent = indent;
|
|
17
|
+
}
|
|
18
|
+
push(text) {
|
|
19
|
+
if (this.margin === -1)
|
|
20
|
+
this.margin = this.indent;
|
|
21
|
+
this.parts.push(text);
|
|
22
|
+
this.indent += utf8Length(text);
|
|
23
|
+
return this.indent;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** The JSDoc comments that may document `node`. */
|
|
27
|
+
export function getJSDocCommentRanges(node, text) {
|
|
28
|
+
const ranges = [];
|
|
29
|
+
switch (node.kind) {
|
|
30
|
+
case 170 /* SyntaxKind.Parameter */:
|
|
31
|
+
case 169 /* SyntaxKind.TypeParameter */:
|
|
32
|
+
case 219 /* SyntaxKind.FunctionExpression */:
|
|
33
|
+
case 220 /* SyntaxKind.ArrowFunction */:
|
|
34
|
+
case 218 /* SyntaxKind.ParenthesizedExpression */:
|
|
35
|
+
case 261 /* SyntaxKind.VariableDeclaration */:
|
|
36
|
+
case 282 /* SyntaxKind.ExportSpecifier */:
|
|
37
|
+
addRanges(ranges, getTrailingCommentRanges(text, node.pos));
|
|
38
|
+
addRanges(ranges, getLeadingCommentRanges(text, node.pos));
|
|
39
|
+
break;
|
|
40
|
+
default:
|
|
41
|
+
addRanges(ranges, getLeadingCommentRanges(text, node.pos));
|
|
42
|
+
}
|
|
43
|
+
const result = [];
|
|
44
|
+
for (const comment of ranges) {
|
|
45
|
+
const start = comment.pos;
|
|
46
|
+
if (comment.end > node.end ||
|
|
47
|
+
comment.end - start < 4 ||
|
|
48
|
+
text.charCodeAt(start + 1) !== 42 /* CharacterCodes.asterisk */ ||
|
|
49
|
+
text.charCodeAt(start + 2) !== 42 /* CharacterCodes.asterisk */ ||
|
|
50
|
+
text.charCodeAt(start + 3) === 47 /* CharacterCodes.slash */)
|
|
51
|
+
continue;
|
|
52
|
+
result.push(comment);
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
function addRanges(to, ranges) {
|
|
57
|
+
if (ranges !== undefined)
|
|
58
|
+
for (const range of ranges)
|
|
59
|
+
to.push(range);
|
|
60
|
+
}
|
|
61
|
+
function isJSDocLikeText(text, start) {
|
|
62
|
+
return (text.length - start >= 4 &&
|
|
63
|
+
text.charCodeAt(start + 1) === 42 /* CharacterCodes.asterisk */ &&
|
|
64
|
+
text.charCodeAt(start + 2) === 42 /* CharacterCodes.asterisk */ &&
|
|
65
|
+
text.charCodeAt(start + 3) !== 47 /* CharacterCodes.slash */);
|
|
66
|
+
}
|
|
67
|
+
export class JSDocParser {
|
|
68
|
+
p;
|
|
69
|
+
reparser;
|
|
70
|
+
constructor(p) {
|
|
71
|
+
this.p = p;
|
|
72
|
+
this.reparser = new Reparser(p);
|
|
73
|
+
}
|
|
74
|
+
/** Parses the JSDoc comments before `node` and attaches them; returns whether there were any. */
|
|
75
|
+
attachJSDoc(node) {
|
|
76
|
+
const p = this.p;
|
|
77
|
+
const ranges = getJSDocCommentRanges(node, p.sourceText);
|
|
78
|
+
p.hasDeprecatedTag = false;
|
|
79
|
+
const jsDoc = [];
|
|
80
|
+
let pos = node.pos;
|
|
81
|
+
for (const comment of ranges) {
|
|
82
|
+
const parsed = this.parseJSDocComment(node, comment.pos, comment.end, pos);
|
|
83
|
+
if (parsed !== undefined) {
|
|
84
|
+
parsed.parent = node;
|
|
85
|
+
jsDoc.push(parsed);
|
|
86
|
+
pos = parsed.end;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (jsDoc.length === 0)
|
|
90
|
+
return false;
|
|
91
|
+
node.flags |= 2097152 /* NodeFlags.HasJSDoc */;
|
|
92
|
+
if (p.hasDeprecatedTag) {
|
|
93
|
+
p.hasDeprecatedTag = false;
|
|
94
|
+
node.flags |= 67108864 /* NodeFlags.PossiblyContainsDeprecatedTag */;
|
|
95
|
+
}
|
|
96
|
+
p.setJSDoc(node, jsDoc);
|
|
97
|
+
if (p.isJavaScript())
|
|
98
|
+
this.reparser.reparseTags(node, jsDoc);
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
/** Parses the JSDoc comments before `node` in a file whose JSDoc is parsed on first use. */
|
|
102
|
+
parseJSDocForNode(node) {
|
|
103
|
+
const ranges = getJSDocCommentRanges(node, this.p.sourceText);
|
|
104
|
+
const jsDoc = [];
|
|
105
|
+
let pos = node.pos;
|
|
106
|
+
for (const comment of ranges) {
|
|
107
|
+
const parsed = this.parseJSDocComment(node, comment.pos, comment.end, pos);
|
|
108
|
+
if (parsed !== undefined) {
|
|
109
|
+
parsed.parent = node;
|
|
110
|
+
jsDoc.push(parsed);
|
|
111
|
+
pos = parsed.end;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return jsDoc;
|
|
115
|
+
}
|
|
116
|
+
parseJSDocTypeExpression(mayOmitBraces) {
|
|
117
|
+
const p = this.p;
|
|
118
|
+
const pos = p.nodePos();
|
|
119
|
+
const hasBrace = mayOmitBraces
|
|
120
|
+
? p.parseOptional(18 /* SyntaxKind.OpenBraceToken */)
|
|
121
|
+
: p.parseExpected(18 /* SyntaxKind.OpenBraceToken */);
|
|
122
|
+
const saveContextFlags = p.contextFlags;
|
|
123
|
+
p.setContextFlags(4194304 /* NodeFlags.JSDoc */, true);
|
|
124
|
+
const type = p.parseJSDocType();
|
|
125
|
+
p.contextFlags = saveContextFlags;
|
|
126
|
+
if (hasBrace)
|
|
127
|
+
p.parseExpectedJSDoc(19 /* SyntaxKind.CloseBraceToken */);
|
|
128
|
+
const result = new JSDocTypeExpression(type);
|
|
129
|
+
p.finishNode(result, pos);
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
parseJSDocNameReference() {
|
|
133
|
+
const p = this.p;
|
|
134
|
+
const pos = p.nodePos();
|
|
135
|
+
const hasBrace = p.parseOptional(18 /* SyntaxKind.OpenBraceToken */);
|
|
136
|
+
const entityName = this.parseJSDocLinkName();
|
|
137
|
+
if (hasBrace)
|
|
138
|
+
p.parseExpectedJSDoc(19 /* SyntaxKind.CloseBraceToken */);
|
|
139
|
+
p.scanner.resetPos(p.scanner.getTokenFullStart());
|
|
140
|
+
p.nextTokenJSDoc();
|
|
141
|
+
return p.finishNode(new JSDocNameReference(entityName), pos);
|
|
142
|
+
}
|
|
143
|
+
/** Parses the comment `[start, end)`, saving and restoring the parser state. */
|
|
144
|
+
parseJSDocComment(_parent, start, end, fullStart) {
|
|
145
|
+
const p = this.p;
|
|
146
|
+
const text = p.sourceText;
|
|
147
|
+
if (!isJSDocLikeText(text, start))
|
|
148
|
+
return undefined;
|
|
149
|
+
const saveToken = p.currentToken;
|
|
150
|
+
const saveContextFlags = p.contextFlags;
|
|
151
|
+
const saveScannerState = p.scanner.mark();
|
|
152
|
+
const saveDiagnosticsLength = p.diagnostics.length;
|
|
153
|
+
const saveHasParseError = p.hasParseError;
|
|
154
|
+
const saveHasAwaitIdentifier = p.statementHasAwaitIdentifier;
|
|
155
|
+
// The indent of the first line is that of `/** `, measured from the line start.
|
|
156
|
+
const lineStart = start === 0 ? 0 : text.lastIndexOf('\n', start - 1) + 1;
|
|
157
|
+
const initialIndent = utf8Length(text.substring(lineStart, start)) + 4;
|
|
158
|
+
// Scan the comment without its `*/`, starting after `/**`.
|
|
159
|
+
p.scanner.loadUnits(start, end);
|
|
160
|
+
p.scanner.setTextEnd(end - 2);
|
|
161
|
+
p.scanner.resetPos(start + 3);
|
|
162
|
+
p.setContextFlags(4194304 /* NodeFlags.JSDoc */, true);
|
|
163
|
+
const saveParsingContexts = p.enterJSDocCommentContext();
|
|
164
|
+
const comment = this.parseJSDocCommentWorker(start, end, fullStart, initialIndent);
|
|
165
|
+
// JSDoc diagnostics are reported separately, and only for JavaScript files.
|
|
166
|
+
const diagnostics = p.diagnostics;
|
|
167
|
+
if ((p.contextFlags & 65536 /* NodeFlags.JavaScriptFile */) !== 0)
|
|
168
|
+
for (let i = saveDiagnosticsLength; i < diagnostics.length; i++)
|
|
169
|
+
p.jsDocDiagnostics.push(diagnostics[i]);
|
|
170
|
+
diagnostics.length = saveDiagnosticsLength;
|
|
171
|
+
p.scanner.setTextEnd(text.length);
|
|
172
|
+
p.parsingContexts = saveParsingContexts;
|
|
173
|
+
p.contextFlags = saveContextFlags;
|
|
174
|
+
p.scanner.rewind(saveScannerState);
|
|
175
|
+
p.currentToken = saveToken;
|
|
176
|
+
p.hasParseError = saveHasParseError;
|
|
177
|
+
p.statementHasAwaitIdentifier = saveHasAwaitIdentifier;
|
|
178
|
+
return comment;
|
|
179
|
+
}
|
|
180
|
+
/** `indent` is the margin: the number of columns before the comment text on lines after the first. */
|
|
181
|
+
parseJSDocCommentWorker(start, end, fullStart, indent) {
|
|
182
|
+
const p = this.p;
|
|
183
|
+
// A tag can follow the initial asterisk, so `/** * @type */` doesn't parse a tag.
|
|
184
|
+
const tags = [];
|
|
185
|
+
let tagsPos = -1;
|
|
186
|
+
let tagsEnd = -1;
|
|
187
|
+
let state = 1 /* JSDocState.SawAsterisk */;
|
|
188
|
+
let backtickCount = 0;
|
|
189
|
+
let inFencedCodeBlock = false;
|
|
190
|
+
const commentParts = [];
|
|
191
|
+
let comments = new CommentText(indent);
|
|
192
|
+
let commentsPos = -1;
|
|
193
|
+
let linkEnd = start;
|
|
194
|
+
p.nextTokenJSDoc();
|
|
195
|
+
while (this.parseOptionalJsdoc(5 /* SyntaxKind.WhitespaceTrivia */)) {
|
|
196
|
+
// Skip leading whitespace.
|
|
197
|
+
}
|
|
198
|
+
if (this.parseOptionalJsdoc(4 /* SyntaxKind.NewLineTrivia */)) {
|
|
199
|
+
state = 0 /* JSDocState.BeginningOfLine */;
|
|
200
|
+
comments.indent = 0;
|
|
201
|
+
}
|
|
202
|
+
loop: for (;;) {
|
|
203
|
+
// Three or more consecutive backticks toggle a fenced code block.
|
|
204
|
+
if (p.token() !== 61 /* SyntaxKind.BacktickToken */ && backtickCount > 0) {
|
|
205
|
+
if (backtickCount >= 3)
|
|
206
|
+
inFencedCodeBlock = !inFencedCodeBlock;
|
|
207
|
+
backtickCount = 0;
|
|
208
|
+
}
|
|
209
|
+
switch (p.token()) {
|
|
210
|
+
case 59 /* SyntaxKind.AtToken */: {
|
|
211
|
+
if (inFencedCodeBlock || !p.scanner.canFollowJSDocAt()) {
|
|
212
|
+
state = inFencedCodeBlock ? 3 /* JSDocState.SavingBackticks */ : 2 /* JSDocState.SavingComments */;
|
|
213
|
+
comments.push(p.scanner.getTokenText());
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
removeTrailingWhitespace(comments.parts);
|
|
217
|
+
if (commentsPos === -1)
|
|
218
|
+
commentsPos = p.nodePos();
|
|
219
|
+
const tag = this.parseTag(tags, comments.indent);
|
|
220
|
+
if (tagsPos === -1)
|
|
221
|
+
tagsPos = tag.pos;
|
|
222
|
+
tags.push(tag);
|
|
223
|
+
tagsEnd = tag.end;
|
|
224
|
+
// A tag goes to the end of its line, except the last one; malformed comments like
|
|
225
|
+
// `/** @param {string} x @returns {number} the length */` break this.
|
|
226
|
+
state = 0 /* JSDocState.BeginningOfLine */;
|
|
227
|
+
comments.margin = -1;
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
case 4 /* SyntaxKind.NewLineTrivia */:
|
|
231
|
+
comments.parts.push(p.scanner.getTokenText());
|
|
232
|
+
state = 0 /* JSDocState.BeginningOfLine */;
|
|
233
|
+
comments.indent = 0;
|
|
234
|
+
break;
|
|
235
|
+
case 41 /* SyntaxKind.AsteriskToken */: {
|
|
236
|
+
const asterisk = p.scanner.getTokenText();
|
|
237
|
+
if (state === 1 /* JSDocState.SawAsterisk */) {
|
|
238
|
+
// After a second asterisk, no tag can start on this line.
|
|
239
|
+
state = 2 /* JSDocState.SavingComments */;
|
|
240
|
+
comments.push(asterisk);
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
// Ignore the first asterisk on a line.
|
|
244
|
+
state = 1 /* JSDocState.SawAsterisk */;
|
|
245
|
+
comments.indent += utf8Length(asterisk);
|
|
246
|
+
}
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
case 5 /* SyntaxKind.WhitespaceTrivia */: {
|
|
250
|
+
// Only keep whitespace past the margin.
|
|
251
|
+
const whitespace = p.scanner.getTokenText();
|
|
252
|
+
const length = utf8Length(whitespace);
|
|
253
|
+
if (comments.margin > -1 && comments.indent + length > comments.margin) {
|
|
254
|
+
let existingIndent = comments.margin - comments.indent;
|
|
255
|
+
if (existingIndent < 0)
|
|
256
|
+
existingIndent += length;
|
|
257
|
+
if (existingIndent < 0)
|
|
258
|
+
existingIndent = 0;
|
|
259
|
+
comments.parts.push(sliceFromUtf8Offset(whitespace, existingIndent));
|
|
260
|
+
}
|
|
261
|
+
comments.indent += length;
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
case 1 /* SyntaxKind.EndOfFile */:
|
|
265
|
+
break loop;
|
|
266
|
+
case 81 /* SyntaxKind.JSDocCommentTextToken */:
|
|
267
|
+
if (state !== 3 /* JSDocState.SavingBackticks */)
|
|
268
|
+
state = inFencedCodeBlock ? 3 /* JSDocState.SavingBackticks */ : 2 /* JSDocState.SavingComments */;
|
|
269
|
+
comments.push(p.scanner.getTokenValue());
|
|
270
|
+
break;
|
|
271
|
+
case 61 /* SyntaxKind.BacktickToken */:
|
|
272
|
+
backtickCount++;
|
|
273
|
+
state = state === 3 /* JSDocState.SavingBackticks */ ? 2 /* JSDocState.SavingComments */ : 3 /* JSDocState.SavingBackticks */;
|
|
274
|
+
comments.push(p.scanner.getTokenText());
|
|
275
|
+
break;
|
|
276
|
+
case 18 /* SyntaxKind.OpenBraceToken */: {
|
|
277
|
+
if (inFencedCodeBlock) {
|
|
278
|
+
state = 3 /* JSDocState.SavingBackticks */;
|
|
279
|
+
comments.push(p.scanner.getTokenText());
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
state = 2 /* JSDocState.SavingComments */;
|
|
283
|
+
const commentEnd = p.scanner.getTokenFullStart();
|
|
284
|
+
const linkStart = p.scanner.getTokenEnd() - 1;
|
|
285
|
+
const link = this.parseJSDocLink(linkStart);
|
|
286
|
+
if (link !== undefined) {
|
|
287
|
+
if (linkEnd === start)
|
|
288
|
+
removeLeadingNewlines(comments.parts);
|
|
289
|
+
const jsdocText = new JSDocText(comments.parts.join(''));
|
|
290
|
+
p.finishNodeWithEnd(jsdocText, linkEnd, commentEnd);
|
|
291
|
+
commentParts.push(jsdocText, link);
|
|
292
|
+
const indent = comments.indent;
|
|
293
|
+
const margin = comments.margin;
|
|
294
|
+
comments = new CommentText(indent);
|
|
295
|
+
comments.margin = margin;
|
|
296
|
+
linkEnd = p.scanner.getTokenEnd();
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
// Not a link: doc comment text.
|
|
300
|
+
state = inFencedCodeBlock ? 3 /* JSDocState.SavingBackticks */ : 2 /* JSDocState.SavingComments */;
|
|
301
|
+
comments.push(p.scanner.getTokenText());
|
|
302
|
+
break;
|
|
303
|
+
}
|
|
304
|
+
default:
|
|
305
|
+
// Anything else is comment text; no tag can start on this line until the next line break.
|
|
306
|
+
if (state !== 3 /* JSDocState.SavingBackticks */)
|
|
307
|
+
state = inFencedCodeBlock ? 3 /* JSDocState.SavingBackticks */ : 2 /* JSDocState.SavingComments */;
|
|
308
|
+
comments.push(p.scanner.getTokenText());
|
|
309
|
+
}
|
|
310
|
+
if (state === 2 /* JSDocState.SavingComments */ || state === 3 /* JSDocState.SavingBackticks */)
|
|
311
|
+
p.nextJSDocCommentTextToken(state === 3 /* JSDocState.SavingBackticks */);
|
|
312
|
+
else
|
|
313
|
+
p.nextTokenJSDoc();
|
|
314
|
+
}
|
|
315
|
+
if (commentsPos === -1)
|
|
316
|
+
commentsPos = p.scanner.getTokenFullStart();
|
|
317
|
+
const parts = comments.parts;
|
|
318
|
+
if (parts.length > 0) {
|
|
319
|
+
parts[parts.length - 1] = trimEndUnicodeSpace(parts[parts.length - 1]);
|
|
320
|
+
const jsdocText = new JSDocText(parts.join(''));
|
|
321
|
+
p.finishNodeWithEnd(jsdocText, linkEnd, commentsPos);
|
|
322
|
+
commentParts.push(jsdocText);
|
|
323
|
+
}
|
|
324
|
+
const tagsList = tagsPos !== -1 ? p.newNodeList(tagsPos, tagsEnd, tags) : undefined;
|
|
325
|
+
const jsdocComment = new JSDoc(p.newNodeList(start, commentsPos, commentParts), tagsList);
|
|
326
|
+
return p.finishNodeWithEnd(jsdocComment, fullStart, end);
|
|
327
|
+
}
|
|
328
|
+
isNextNonwhitespaceTokenEndOfFile() {
|
|
329
|
+
// Any number of newlines can follow, so look ahead without limit.
|
|
330
|
+
const p = this.p;
|
|
331
|
+
for (;;) {
|
|
332
|
+
p.nextTokenJSDoc();
|
|
333
|
+
if (p.token() === 1 /* SyntaxKind.EndOfFile */)
|
|
334
|
+
return true;
|
|
335
|
+
if (!(p.token() === 5 /* SyntaxKind.WhitespaceTrivia */ || p.token() === 4 /* SyntaxKind.NewLineTrivia */))
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
/** Skips whitespace, unless only whitespace remains: that shouldn't be in any node's range. */
|
|
340
|
+
skipWhitespace() {
|
|
341
|
+
const p = this.p;
|
|
342
|
+
if (p.token() === 5 /* SyntaxKind.WhitespaceTrivia */ || p.token() === 4 /* SyntaxKind.NewLineTrivia */) {
|
|
343
|
+
if (p.lookAhead(isNextNonwhitespaceTokenEndOfFile))
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
while (p.token() === 5 /* SyntaxKind.WhitespaceTrivia */ || p.token() === 4 /* SyntaxKind.NewLineTrivia */)
|
|
347
|
+
p.nextTokenJSDoc();
|
|
348
|
+
return true;
|
|
349
|
+
}
|
|
350
|
+
/** Skips whitespace and leading asterisks; returns the indentation of the last line if a line break was skipped. */
|
|
351
|
+
skipWhitespaceOrAsterisk() {
|
|
352
|
+
const p = this.p;
|
|
353
|
+
if (p.token() === 5 /* SyntaxKind.WhitespaceTrivia */ || p.token() === 4 /* SyntaxKind.NewLineTrivia */) {
|
|
354
|
+
if (p.lookAhead(isNextNonwhitespaceTokenEndOfFile))
|
|
355
|
+
return '';
|
|
356
|
+
}
|
|
357
|
+
let precedingLineBreak = p.scanner.hasPrecedingLineBreak();
|
|
358
|
+
let seenLineBreak = false;
|
|
359
|
+
let indents = [];
|
|
360
|
+
while ((precedingLineBreak && p.token() === 41 /* SyntaxKind.AsteriskToken */) ||
|
|
361
|
+
p.token() === 5 /* SyntaxKind.WhitespaceTrivia */ ||
|
|
362
|
+
p.token() === 4 /* SyntaxKind.NewLineTrivia */) {
|
|
363
|
+
indents.push(p.scanner.getTokenText());
|
|
364
|
+
if (p.token() === 4 /* SyntaxKind.NewLineTrivia */) {
|
|
365
|
+
precedingLineBreak = true;
|
|
366
|
+
seenLineBreak = true;
|
|
367
|
+
indents = [];
|
|
368
|
+
}
|
|
369
|
+
else if (p.token() === 41 /* SyntaxKind.AsteriskToken */) {
|
|
370
|
+
precedingLineBreak = false;
|
|
371
|
+
}
|
|
372
|
+
p.nextTokenJSDoc();
|
|
373
|
+
}
|
|
374
|
+
return seenLineBreak ? indents.join('') : '';
|
|
375
|
+
}
|
|
376
|
+
parseTag(tags, margin) {
|
|
377
|
+
const p = this.p;
|
|
378
|
+
const start = p.scanner.getTokenStart();
|
|
379
|
+
p.nextTokenJSDoc();
|
|
380
|
+
const tagName = this.parseJSDocIdentifierName(1 /* Diagnostics.Identifier_expected */);
|
|
381
|
+
const indentText = this.skipWhitespaceOrAsterisk();
|
|
382
|
+
switch (tagName.text) {
|
|
383
|
+
case 'implements':
|
|
384
|
+
return this.parseImplementsTag(start, tagName, margin, indentText);
|
|
385
|
+
case 'augments':
|
|
386
|
+
case 'extends':
|
|
387
|
+
return this.parseAugmentsTag(start, tagName, margin, indentText);
|
|
388
|
+
case 'public':
|
|
389
|
+
return p.finishNode(new JSDocPublicTag(tagName, this.parseTrailingTagComments(start, p.nodePos(), margin, indentText)), start);
|
|
390
|
+
case 'private':
|
|
391
|
+
return p.finishNode(new JSDocPrivateTag(tagName, this.parseTrailingTagComments(start, p.nodePos(), margin, indentText)), start);
|
|
392
|
+
case 'protected':
|
|
393
|
+
return p.finishNode(new JSDocProtectedTag(tagName, this.parseTrailingTagComments(start, p.nodePos(), margin, indentText)), start);
|
|
394
|
+
case 'readonly':
|
|
395
|
+
return p.finishNode(new JSDocReadonlyTag(tagName, this.parseTrailingTagComments(start, p.nodePos(), margin, indentText)), start);
|
|
396
|
+
case 'override':
|
|
397
|
+
return p.finishNode(new JSDocOverrideTag(tagName, this.parseTrailingTagComments(start, p.nodePos(), margin, indentText)), start);
|
|
398
|
+
case 'deprecated':
|
|
399
|
+
p.hasDeprecatedTag = true;
|
|
400
|
+
return p.finishNode(new JSDocDeprecatedTag(tagName, this.parseTrailingTagComments(start, p.nodePos(), margin, indentText)), start);
|
|
401
|
+
case 'this':
|
|
402
|
+
return this.parseThisTag(start, tagName, margin, indentText);
|
|
403
|
+
case 'arg':
|
|
404
|
+
case 'argument':
|
|
405
|
+
case 'param':
|
|
406
|
+
return this.parseParameterOrPropertyTag(start, tagName, 2 /* PropertyLikeParse.Parameter */, margin);
|
|
407
|
+
case 'return':
|
|
408
|
+
case 'returns':
|
|
409
|
+
return this.parseReturnTag(tags, start, tagName, margin, indentText);
|
|
410
|
+
case 'template':
|
|
411
|
+
return this.parseTemplateTag(start, tagName, margin, indentText);
|
|
412
|
+
case 'type':
|
|
413
|
+
return this.parseTypeTag(tags, start, tagName, margin, indentText);
|
|
414
|
+
case 'typedef':
|
|
415
|
+
return this.parseTypedefTag(start, tagName, margin, indentText);
|
|
416
|
+
case 'callback':
|
|
417
|
+
return this.parseCallbackTag(start, tagName, margin, indentText);
|
|
418
|
+
case 'overload':
|
|
419
|
+
return this.parseOverloadTag(start, tagName, margin, indentText);
|
|
420
|
+
case 'satisfies':
|
|
421
|
+
return this.parseSatisfiesTag(start, tagName, margin, indentText);
|
|
422
|
+
case 'see':
|
|
423
|
+
return this.parseSeeTag(start, tagName, margin, indentText);
|
|
424
|
+
case 'exception':
|
|
425
|
+
case 'throws':
|
|
426
|
+
return this.parseThrowsTag(start, tagName, margin, indentText);
|
|
427
|
+
case 'import':
|
|
428
|
+
return this.parseImportTag(start, tagName, margin, indentText);
|
|
429
|
+
default:
|
|
430
|
+
return this.parseUnknownTag(start, tagName, margin, indentText);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
parseTrailingTagComments(pos, end, margin, indentText) {
|
|
434
|
+
// Tags like @typedef and @callback have already parsed their comments.
|
|
435
|
+
if (indentText.length === 0)
|
|
436
|
+
margin += utf8Length(this.p.sourceText.substring(pos, end));
|
|
437
|
+
const initialMargin = margin < utf8Length(indentText) ? sliceFromUtf8Offset(indentText, margin) : '';
|
|
438
|
+
return this.parseTagComments(margin, initialMargin);
|
|
439
|
+
}
|
|
440
|
+
/** `initialMargin` is undefined when no indentation precedes the comment. */
|
|
441
|
+
parseTagComments(indent, initialMargin) {
|
|
442
|
+
const p = this.p;
|
|
443
|
+
const commentsPos = p.nodePos();
|
|
444
|
+
let comments = new CommentText(indent);
|
|
445
|
+
const parts = [];
|
|
446
|
+
let linkEnd = -1;
|
|
447
|
+
let state = 0 /* JSDocState.BeginningOfLine */;
|
|
448
|
+
let backtickCount = 0;
|
|
449
|
+
let inFencedCodeBlock = false;
|
|
450
|
+
if (initialMargin !== undefined) {
|
|
451
|
+
// Save comments right away if there's initial indentation.
|
|
452
|
+
if (initialMargin !== '')
|
|
453
|
+
comments.push(initialMargin);
|
|
454
|
+
state = 1 /* JSDocState.SawAsterisk */;
|
|
455
|
+
}
|
|
456
|
+
let tok = p.token();
|
|
457
|
+
loop: for (;;) {
|
|
458
|
+
// Three or more consecutive backticks toggle a fenced code block.
|
|
459
|
+
if (tok !== 61 /* SyntaxKind.BacktickToken */ && backtickCount > 0) {
|
|
460
|
+
if (backtickCount >= 3)
|
|
461
|
+
inFencedCodeBlock = !inFencedCodeBlock;
|
|
462
|
+
backtickCount = 0;
|
|
463
|
+
}
|
|
464
|
+
switch (tok) {
|
|
465
|
+
case 4 /* SyntaxKind.NewLineTrivia */:
|
|
466
|
+
state = 0 /* JSDocState.BeginningOfLine */;
|
|
467
|
+
// Keep the margin unchanged.
|
|
468
|
+
comments.parts.push(p.scanner.getTokenText());
|
|
469
|
+
comments.indent = 0;
|
|
470
|
+
break;
|
|
471
|
+
case 59 /* SyntaxKind.AtToken */:
|
|
472
|
+
if (!inFencedCodeBlock && p.scanner.canFollowJSDocAt()) {
|
|
473
|
+
p.scanner.resetPos(p.scanner.getTokenEnd() - 1);
|
|
474
|
+
break loop;
|
|
475
|
+
}
|
|
476
|
+
state = inFencedCodeBlock ? 3 /* JSDocState.SavingBackticks */ : 2 /* JSDocState.SavingComments */;
|
|
477
|
+
comments.push(p.scanner.getTokenText());
|
|
478
|
+
break;
|
|
479
|
+
case 1 /* SyntaxKind.EndOfFile */:
|
|
480
|
+
break loop;
|
|
481
|
+
case 5 /* SyntaxKind.WhitespaceTrivia */: {
|
|
482
|
+
// Keep only the whitespace past the margin.
|
|
483
|
+
const whitespace = p.scanner.getTokenText();
|
|
484
|
+
const length = utf8Length(whitespace);
|
|
485
|
+
if (comments.margin > -1 && comments.indent + length > comments.margin) {
|
|
486
|
+
comments.parts.push(sliceFromUtf8Offset(whitespace, Math.max(comments.margin - comments.indent, 0)));
|
|
487
|
+
state = inFencedCodeBlock ? 3 /* JSDocState.SavingBackticks */ : 2 /* JSDocState.SavingComments */;
|
|
488
|
+
}
|
|
489
|
+
comments.indent += length;
|
|
490
|
+
break;
|
|
491
|
+
}
|
|
492
|
+
case 18 /* SyntaxKind.OpenBraceToken */: {
|
|
493
|
+
if (inFencedCodeBlock) {
|
|
494
|
+
state = 3 /* JSDocState.SavingBackticks */;
|
|
495
|
+
comments.push(p.scanner.getTokenText());
|
|
496
|
+
break;
|
|
497
|
+
}
|
|
498
|
+
state = 2 /* JSDocState.SavingComments */;
|
|
499
|
+
const commentEnd = p.scanner.getTokenFullStart();
|
|
500
|
+
const linkStart = p.scanner.getTokenEnd() - 1;
|
|
501
|
+
const link = this.parseJSDocLink(linkStart);
|
|
502
|
+
if (link !== undefined) {
|
|
503
|
+
const text = new JSDocText(comments.parts.join(''));
|
|
504
|
+
p.finishNodeWithEnd(text, linkEnd > -1 ? linkEnd : commentsPos, commentEnd);
|
|
505
|
+
parts.push(text, link);
|
|
506
|
+
const indentAfter = comments.indent;
|
|
507
|
+
const margin = comments.margin;
|
|
508
|
+
comments = new CommentText(indentAfter);
|
|
509
|
+
comments.margin = margin;
|
|
510
|
+
linkEnd = p.scanner.getTokenEnd();
|
|
511
|
+
}
|
|
512
|
+
else {
|
|
513
|
+
comments.push(p.scanner.getTokenText());
|
|
514
|
+
}
|
|
515
|
+
break;
|
|
516
|
+
}
|
|
517
|
+
case 61 /* SyntaxKind.BacktickToken */:
|
|
518
|
+
backtickCount++;
|
|
519
|
+
state = state === 3 /* JSDocState.SavingBackticks */ ? 2 /* JSDocState.SavingComments */ : 3 /* JSDocState.SavingBackticks */;
|
|
520
|
+
comments.push(p.scanner.getTokenText());
|
|
521
|
+
break;
|
|
522
|
+
case 81 /* SyntaxKind.JSDocCommentTextToken */:
|
|
523
|
+
// Leading identifiers start recording too.
|
|
524
|
+
if (state !== 3 /* JSDocState.SavingBackticks */)
|
|
525
|
+
state = inFencedCodeBlock ? 3 /* JSDocState.SavingBackticks */ : 2 /* JSDocState.SavingComments */;
|
|
526
|
+
comments.push(p.scanner.getTokenValue());
|
|
527
|
+
break;
|
|
528
|
+
case 41 /* SyntaxKind.AsteriskToken */:
|
|
529
|
+
if (state === 0 /* JSDocState.BeginningOfLine */) {
|
|
530
|
+
// Leading asterisks start recording on the next non-whitespace token.
|
|
531
|
+
state = 1 /* JSDocState.SawAsterisk */;
|
|
532
|
+
comments.indent += 1;
|
|
533
|
+
break;
|
|
534
|
+
}
|
|
535
|
+
// Otherwise the `*` is comment text.
|
|
536
|
+
if (state !== 3 /* JSDocState.SavingBackticks */)
|
|
537
|
+
state = inFencedCodeBlock ? 3 /* JSDocState.SavingBackticks */ : 2 /* JSDocState.SavingComments */;
|
|
538
|
+
comments.push(p.scanner.getTokenText());
|
|
539
|
+
break;
|
|
540
|
+
default:
|
|
541
|
+
if (state !== 3 /* JSDocState.SavingBackticks */)
|
|
542
|
+
state = inFencedCodeBlock ? 3 /* JSDocState.SavingBackticks */ : 2 /* JSDocState.SavingComments */;
|
|
543
|
+
comments.push(p.scanner.getTokenText());
|
|
544
|
+
}
|
|
545
|
+
if (state === 2 /* JSDocState.SavingComments */ || state === 3 /* JSDocState.SavingBackticks */)
|
|
546
|
+
tok = p.nextJSDocCommentTextToken(state === 3 /* JSDocState.SavingBackticks */);
|
|
547
|
+
else
|
|
548
|
+
tok = p.nextTokenJSDoc();
|
|
549
|
+
}
|
|
550
|
+
const texts = comments.parts;
|
|
551
|
+
removeLeadingNewlines(texts);
|
|
552
|
+
removeTrailingWhitespace(texts);
|
|
553
|
+
if (texts.length > 0) {
|
|
554
|
+
const text = new JSDocText(texts.join(''));
|
|
555
|
+
p.finishNode(text, linkEnd > -1 ? linkEnd : commentsPos);
|
|
556
|
+
parts.push(text);
|
|
557
|
+
}
|
|
558
|
+
return parts.length > 0 ? p.newNodeList(commentsPos, p.scanner.getTokenEnd(), parts) : undefined;
|
|
559
|
+
}
|
|
560
|
+
parseJSDocLink(start) {
|
|
561
|
+
const p = this.p;
|
|
562
|
+
const state = p.mark();
|
|
563
|
+
const linkType = this.parseJSDocLinkPrefix();
|
|
564
|
+
if (linkType === undefined) {
|
|
565
|
+
p.rewind(state);
|
|
566
|
+
return undefined;
|
|
567
|
+
}
|
|
568
|
+
p.nextTokenJSDoc();
|
|
569
|
+
// Skip whitespace after the link tag.
|
|
570
|
+
this.skipWhitespace();
|
|
571
|
+
const name = this.parseJSDocLinkName();
|
|
572
|
+
let text = '';
|
|
573
|
+
while (p.token() !== 19 /* SyntaxKind.CloseBraceToken */ &&
|
|
574
|
+
p.token() !== 4 /* SyntaxKind.NewLineTrivia */ &&
|
|
575
|
+
p.token() !== 1 /* SyntaxKind.EndOfFile */) {
|
|
576
|
+
text += p.scanner.getTokenText();
|
|
577
|
+
p.nextTokenJSDoc();
|
|
578
|
+
}
|
|
579
|
+
const link = linkType === 'link'
|
|
580
|
+
? new JSDocLink(name, text)
|
|
581
|
+
: linkType === 'linkcode'
|
|
582
|
+
? new JSDocLinkCode(name, text)
|
|
583
|
+
: new JSDocLinkPlain(name, text);
|
|
584
|
+
return p.finishNodeWithEnd(link, start | 0, p.scanner.getTokenEnd());
|
|
585
|
+
}
|
|
586
|
+
parseJSDocLinkName() {
|
|
587
|
+
const p = this.p;
|
|
588
|
+
if (!tokenIsIdentifierOrKeyword(p.token()))
|
|
589
|
+
return undefined;
|
|
590
|
+
const pos = p.nodePos();
|
|
591
|
+
let name = p.parseIdentifierName();
|
|
592
|
+
while (p.parseOptional(24 /* SyntaxKind.DotToken */)) {
|
|
593
|
+
const right = p.token() === 80 /* SyntaxKind.PrivateIdentifier */ ? p.createMissingIdentifier() : p.parseIdentifierName();
|
|
594
|
+
name = p.finishNode(new QualifiedName(name, right), pos);
|
|
595
|
+
}
|
|
596
|
+
while (p.token() === 80 /* SyntaxKind.PrivateIdentifier */) {
|
|
597
|
+
p.scanner.reScanHashToken();
|
|
598
|
+
p.nextTokenJSDoc();
|
|
599
|
+
name = p.finishNode(new QualifiedName(name, p.parseIdentifier()), pos);
|
|
600
|
+
}
|
|
601
|
+
return name;
|
|
602
|
+
}
|
|
603
|
+
/** The kind of link (`link`, `linkcode` or `linkplain`) after `{@`, or undefined. */
|
|
604
|
+
parseJSDocLinkPrefix() {
|
|
605
|
+
const p = this.p;
|
|
606
|
+
this.skipWhitespaceOrAsterisk();
|
|
607
|
+
if (p.token() === 18 /* SyntaxKind.OpenBraceToken */ &&
|
|
608
|
+
p.nextTokenJSDoc() === 59 /* SyntaxKind.AtToken */ &&
|
|
609
|
+
tokenIsIdentifierOrKeyword(p.nextTokenJSDoc())) {
|
|
610
|
+
const kind = p.scanner.getTokenValue();
|
|
611
|
+
if (kind === 'link' || kind === 'linkcode' || kind === 'linkplain')
|
|
612
|
+
return kind;
|
|
613
|
+
}
|
|
614
|
+
return undefined;
|
|
615
|
+
}
|
|
616
|
+
parseUnknownTag(start, tagName, indent, indentText) {
|
|
617
|
+
const p = this.p;
|
|
618
|
+
return p.finishNode(new JSDocUnknownTag(tagName, this.parseTrailingTagComments(start, p.nodePos(), indent, indentText)), start);
|
|
619
|
+
}
|
|
620
|
+
tryParseTypeExpression() {
|
|
621
|
+
this.skipWhitespaceOrAsterisk();
|
|
622
|
+
return this.p.token() === 18 /* SyntaxKind.OpenBraceToken */ ? this.parseJSDocTypeExpression(false) : undefined;
|
|
623
|
+
}
|
|
624
|
+
/** A name like `foo`, `[foo]`, `foo.bar` or `[foo.bar = 42]`; the caller has parsed an opening `[`. */
|
|
625
|
+
parseBracketNameInPropertyAndParamTag(target, isBracketed) {
|
|
626
|
+
const p = this.p;
|
|
627
|
+
if (isBracketed)
|
|
628
|
+
this.skipWhitespace();
|
|
629
|
+
// A markdown-quoted name, `arg`, isn't legal JSDoc but occurs in the wild.
|
|
630
|
+
const isBackquoted = this.parseOptionalJsdoc(61 /* SyntaxKind.BacktickToken */);
|
|
631
|
+
const name = this.parseJSDocEntityName(target === 2 /* PropertyLikeParse.Parameter */ ? undefined : 1 /* Diagnostics.Identifier_expected */);
|
|
632
|
+
if (isBackquoted)
|
|
633
|
+
p.parseExpectedTokenJSDoc(61 /* SyntaxKind.BacktickToken */);
|
|
634
|
+
if (isBracketed) {
|
|
635
|
+
this.skipWhitespace();
|
|
636
|
+
// An optional default, as in `[foo = 42]`.
|
|
637
|
+
if (p.parseOptionalToken(63 /* SyntaxKind.EqualsToken */) !== undefined)
|
|
638
|
+
p.parseExpression();
|
|
639
|
+
p.parseExpected(23 /* SyntaxKind.CloseBracketToken */);
|
|
640
|
+
}
|
|
641
|
+
return name;
|
|
642
|
+
}
|
|
643
|
+
parseParameterOrPropertyTag(start, tagName, target, indent) {
|
|
644
|
+
const p = this.p;
|
|
645
|
+
let typeExpression = this.tryParseTypeExpression();
|
|
646
|
+
let isNameFirst = typeExpression === undefined;
|
|
647
|
+
this.skipWhitespaceOrAsterisk();
|
|
648
|
+
const isBracketed = this.parseOptionalJsdoc(22 /* SyntaxKind.OpenBracketToken */);
|
|
649
|
+
const name = this.parseBracketNameInPropertyAndParamTag(target, isBracketed);
|
|
650
|
+
const indentText = this.skipWhitespaceOrAsterisk();
|
|
651
|
+
if (isNameFirst && p.lookAhead(isNotJSDocLinkPrefix))
|
|
652
|
+
typeExpression = this.tryParseTypeExpression();
|
|
653
|
+
const comment = this.parseTrailingTagComments(start, p.nodePos(), indent, indentText);
|
|
654
|
+
const nestedTypeLiteral = this.parseNestedTypeLiteral(typeExpression, name, target, indent);
|
|
655
|
+
if (nestedTypeLiteral !== undefined) {
|
|
656
|
+
typeExpression = nestedTypeLiteral;
|
|
657
|
+
isNameFirst = true;
|
|
658
|
+
}
|
|
659
|
+
const kind = target === 1 /* PropertyLikeParse.Property */ ? 340 /* SyntaxKind.JSDocPropertyTag */ : 333 /* SyntaxKind.JSDocParameterTag */;
|
|
660
|
+
return p.finishNode(new JSDocParameterOrPropertyTag(kind, tagName, name, isBracketed, typeExpression, isNameFirst, comment), start);
|
|
661
|
+
}
|
|
662
|
+
parseNestedTypeLiteral(typeExpression, name, target, indent) {
|
|
663
|
+
const p = this.p;
|
|
664
|
+
if (typeExpression === undefined)
|
|
665
|
+
return undefined;
|
|
666
|
+
const type = getType(typeExpression);
|
|
667
|
+
if (type === undefined || !isObjectOrObjectArrayTypeReference(type))
|
|
668
|
+
return undefined;
|
|
669
|
+
const pos = p.nodePos();
|
|
670
|
+
const children = [];
|
|
671
|
+
for (;;) {
|
|
672
|
+
const state = p.mark();
|
|
673
|
+
const child = this.parseChildParameterOrPropertyTag(target, indent, name);
|
|
674
|
+
if (child === undefined) {
|
|
675
|
+
p.rewind(state);
|
|
676
|
+
break;
|
|
677
|
+
}
|
|
678
|
+
if (child.kind === 333 /* SyntaxKind.JSDocParameterTag */ || child.kind === 340 /* SyntaxKind.JSDocPropertyTag */)
|
|
679
|
+
children.push(child);
|
|
680
|
+
else if (child.kind === 337 /* SyntaxKind.JSDocTemplateTag */)
|
|
681
|
+
this.reportTemplateAfterTypedef(child);
|
|
682
|
+
}
|
|
683
|
+
if (children.length === 0)
|
|
684
|
+
return undefined;
|
|
685
|
+
const literal = p.finishNode(new JSDocTypeLiteral(children, type.kind === 189 /* SyntaxKind.ArrayType */), pos);
|
|
686
|
+
return p.finishNode(new JSDocTypeExpression(literal), pos);
|
|
687
|
+
}
|
|
688
|
+
reportTemplateAfterTypedef(tag) {
|
|
689
|
+
const tagName = getTagName(tag);
|
|
690
|
+
this.p.parseErrorAt(tagName.pos, tagName.end, 1768 /* Diagnostics.A_JSDoc_template_tag_may_not_follow_a_typedef_callback_or_overload_tag */);
|
|
691
|
+
return true;
|
|
692
|
+
}
|
|
693
|
+
parseReturnTag(previousTags, start, tagName, indent, indentText) {
|
|
694
|
+
const p = this.p;
|
|
695
|
+
if (hasTagOfKind(previousTags, 334 /* SyntaxKind.JSDocReturnTag */))
|
|
696
|
+
p.parseErrorAt(tagName.pos, p.scanner.getTokenStart(), 173 /* Diagnostics.X_0_tag_already_specified */, [tagName.text]);
|
|
697
|
+
const typeExpression = this.tryParseTypeExpression();
|
|
698
|
+
return p.finishNode(new JSDocReturnTag(tagName, typeExpression, this.parseTrailingTagComments(start, p.nodePos(), indent, indentText)), start);
|
|
699
|
+
}
|
|
700
|
+
/** `indent` -1 skips trailing comments, as for a type tag nested in a typedef. */
|
|
701
|
+
parseTypeTag(previousTags, start, tagName, indent, indentText) {
|
|
702
|
+
const p = this.p;
|
|
703
|
+
if (hasTagOfKind(previousTags, 336 /* SyntaxKind.JSDocTypeTag */))
|
|
704
|
+
p.parseErrorAt(tagName.pos, p.scanner.getTokenStart(), 173 /* Diagnostics.X_0_tag_already_specified */, [tagName.text]);
|
|
705
|
+
const typeExpression = this.parseJSDocTypeExpression(true);
|
|
706
|
+
const comments = indent !== -1 ? this.parseTrailingTagComments(start, p.nodePos(), indent, indentText) : undefined;
|
|
707
|
+
const result = new JSDocTypeTag(tagName, typeExpression, comments);
|
|
708
|
+
p.finishNode(result, start);
|
|
709
|
+
return result;
|
|
710
|
+
}
|
|
711
|
+
parseSeeTag(start, tagName, indent, indentText) {
|
|
712
|
+
const p = this.p;
|
|
713
|
+
const hasNameReference = (p.isIdentifier() && !p.sourceText.startsWith('://', p.scanner.getTokenEnd())) ||
|
|
714
|
+
(p.token() === 18 /* SyntaxKind.OpenBraceToken */ && p.lookAhead(nextTokenIsIdentifierOrKeyword));
|
|
715
|
+
const nameExpression = hasNameReference ? this.parseJSDocNameReference() : undefined;
|
|
716
|
+
const comments = this.parseTrailingTagComments(start, p.nodePos(), indent, indentText);
|
|
717
|
+
return p.finishNode(new JSDocSeeTag(tagName, nameExpression, comments), start);
|
|
718
|
+
}
|
|
719
|
+
parseImplementsTag(start, tagName, margin, indentText) {
|
|
720
|
+
const p = this.p;
|
|
721
|
+
const className = this.parseExpressionWithTypeArgumentsForAugments();
|
|
722
|
+
return p.finishNode(new JSDocImplementsTag(tagName, className, this.parseTrailingTagComments(start, p.nodePos(), margin, indentText)), start);
|
|
723
|
+
}
|
|
724
|
+
parseAugmentsTag(start, tagName, margin, indentText) {
|
|
725
|
+
const p = this.p;
|
|
726
|
+
const className = this.parseExpressionWithTypeArgumentsForAugments();
|
|
727
|
+
return p.finishNode(new JSDocAugmentsTag(tagName, className, this.parseTrailingTagComments(start, p.nodePos(), margin, indentText)), start);
|
|
728
|
+
}
|
|
729
|
+
parseSatisfiesTag(start, tagName, margin, indentText) {
|
|
730
|
+
const p = this.p;
|
|
731
|
+
const typeExpression = this.parseJSDocTypeExpression(false);
|
|
732
|
+
const comments = this.parseTrailingTagComments(start, p.nodePos(), margin, indentText);
|
|
733
|
+
return p.finishNode(new JSDocSatisfiesTag(tagName, typeExpression, comments), start);
|
|
734
|
+
}
|
|
735
|
+
parseThrowsTag(start, tagName, margin, indentText) {
|
|
736
|
+
const p = this.p;
|
|
737
|
+
const typeExpression = this.tryParseTypeExpression();
|
|
738
|
+
const comment = this.parseTrailingTagComments(start, p.nodePos(), margin, indentText);
|
|
739
|
+
return p.finishNode(new JSDocThrowsTag(tagName, typeExpression, comment), start);
|
|
740
|
+
}
|
|
741
|
+
parseImportTag(start, tagName, margin, indentText) {
|
|
742
|
+
const p = this.p;
|
|
743
|
+
const afterImportTagPos = p.scanner.getTokenFullStart();
|
|
744
|
+
const identifier = p.isIdentifier() ? p.parseIdentifier() : undefined;
|
|
745
|
+
const importClause = p.tryParseImportClause(identifier, afterImportTagPos, 156 /* SyntaxKind.TypeKeyword */, true);
|
|
746
|
+
const moduleSpecifier = p.parseModuleSpecifier();
|
|
747
|
+
const attributes = p.tryParseImportAttributes();
|
|
748
|
+
const comments = this.parseTrailingTagComments(start, p.nodePos(), margin, indentText);
|
|
749
|
+
return p.finishNode(new JSDocImportTag(tagName, importClause, moduleSpecifier, attributes, comments), start);
|
|
750
|
+
}
|
|
751
|
+
parseExpressionWithTypeArgumentsForAugments() {
|
|
752
|
+
const p = this.p;
|
|
753
|
+
const usedBrace = p.parseOptional(18 /* SyntaxKind.OpenBraceToken */);
|
|
754
|
+
const pos = p.nodePos();
|
|
755
|
+
const expression = this.parsePropertyAccessEntityNameExpression();
|
|
756
|
+
p.scanner.setSkipJSDocLeadingAsterisks(true);
|
|
757
|
+
const typeArguments = p.parseTypeArguments();
|
|
758
|
+
p.scanner.setSkipJSDocLeadingAsterisks(false);
|
|
759
|
+
const node = new ExpressionWithTypeArguments(expression, typeArguments);
|
|
760
|
+
p.finishNode(node, pos);
|
|
761
|
+
if (usedBrace) {
|
|
762
|
+
this.skipWhitespace();
|
|
763
|
+
p.parseExpected(19 /* SyntaxKind.CloseBraceToken */);
|
|
764
|
+
}
|
|
765
|
+
return node;
|
|
766
|
+
}
|
|
767
|
+
parsePropertyAccessEntityNameExpression() {
|
|
768
|
+
const p = this.p;
|
|
769
|
+
const pos = p.nodePos();
|
|
770
|
+
let node = this.parseJSDocIdentifierName(1 /* Diagnostics.Identifier_expected */);
|
|
771
|
+
while (p.parseOptional(24 /* SyntaxKind.DotToken */)) {
|
|
772
|
+
const name = this.parseJSDocIdentifierName(1 /* Diagnostics.Identifier_expected */);
|
|
773
|
+
node = p.finishNode(new PropertyAccessExpression(node, undefined, name, 0 /* NodeFlags.None */), pos);
|
|
774
|
+
}
|
|
775
|
+
return node;
|
|
776
|
+
}
|
|
777
|
+
parseThisTag(start, tagName, margin, indentText) {
|
|
778
|
+
const p = this.p;
|
|
779
|
+
const typeExpression = this.parseJSDocTypeExpression(true);
|
|
780
|
+
this.skipWhitespace();
|
|
781
|
+
const result = new JSDocThisTag(tagName, typeExpression, this.parseTrailingTagComments(start, p.nodePos(), margin, indentText));
|
|
782
|
+
return p.finishNode(result, start);
|
|
783
|
+
}
|
|
784
|
+
/** A typedef or callback name, possibly dotted (`A.B.C`) into nested namespace declarations. */
|
|
785
|
+
parseJSDocTypeNameWithNamespace(nested) {
|
|
786
|
+
const p = this.p;
|
|
787
|
+
const start = p.scanner.getTokenStart();
|
|
788
|
+
if (!tokenIsIdentifierOrKeyword(p.token()))
|
|
789
|
+
return undefined;
|
|
790
|
+
const typeNameOrNamespaceName = this.parseJSDocIdentifierName(undefined);
|
|
791
|
+
if (this.parseOptionalJsdoc(24 /* SyntaxKind.DotToken */)) {
|
|
792
|
+
const body = this.parseJSDocTypeNameWithNamespace(true);
|
|
793
|
+
const jsDocNamespaceNode = new ModuleDeclaration(undefined, 145 /* SyntaxKind.NamespaceKeyword */, typeNameOrNamespaceName, body);
|
|
794
|
+
if (nested)
|
|
795
|
+
jsDocNamespaceNode.flags |= 32 /* NodeFlags.NestedNamespace */;
|
|
796
|
+
return p.finishNode(jsDocNamespaceNode, start);
|
|
797
|
+
}
|
|
798
|
+
if (nested)
|
|
799
|
+
typeNameOrNamespaceName.flags |= 262144 /* NodeFlags.IdentifierIsInJSDocNamespace */;
|
|
800
|
+
return typeNameOrNamespaceName;
|
|
801
|
+
}
|
|
802
|
+
parseTypedefTag(start, tagName, indent, indentText) {
|
|
803
|
+
const p = this.p;
|
|
804
|
+
let typeExpression = this.tryParseTypeExpression();
|
|
805
|
+
this.skipWhitespaceOrAsterisk();
|
|
806
|
+
let fullName = this.parseJSDocTypeNameWithNamespace(false);
|
|
807
|
+
if (fullName === undefined)
|
|
808
|
+
fullName = this.parseJSDocIdentifierName(1 /* Diagnostics.Identifier_expected */);
|
|
809
|
+
this.skipWhitespace();
|
|
810
|
+
let comment = this.parseTagComments(indent, undefined);
|
|
811
|
+
let end = -1;
|
|
812
|
+
let hasChildren = false;
|
|
813
|
+
const typeExpressionType = typeExpression === undefined ? undefined : getType(typeExpression);
|
|
814
|
+
if (typeExpression === undefined ||
|
|
815
|
+
(typeExpressionType !== undefined && isObjectOrObjectArrayTypeReference(typeExpressionType))) {
|
|
816
|
+
let childTypeTag;
|
|
817
|
+
const jsdocPropertyTags = [];
|
|
818
|
+
for (;;) {
|
|
819
|
+
const state = p.mark();
|
|
820
|
+
const child = this.parseChildParameterOrPropertyTag(1 /* PropertyLikeParse.Property */, indent, undefined);
|
|
821
|
+
if (child === undefined) {
|
|
822
|
+
p.rewind(state);
|
|
823
|
+
break;
|
|
824
|
+
}
|
|
825
|
+
hasChildren = true;
|
|
826
|
+
if (child.kind === 337 /* SyntaxKind.JSDocTemplateTag */) {
|
|
827
|
+
this.reportTemplateAfterTypedef(child);
|
|
828
|
+
}
|
|
829
|
+
else if (child instanceof JSDocTypeTag) {
|
|
830
|
+
if (childTypeTag === undefined) {
|
|
831
|
+
childTypeTag = child;
|
|
832
|
+
}
|
|
833
|
+
else {
|
|
834
|
+
const lastError = p.parseErrorAtCurrentToken(1762 /* Diagnostics.A_JSDoc_typedef_comment_may_not_contain_multiple_type_tags */);
|
|
835
|
+
if (lastError !== undefined)
|
|
836
|
+
lastError.addRelatedInfo(newDiagnosticAtStart(1763 /* Diagnostics.The_tag_was_first_specified_here */));
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
else {
|
|
840
|
+
jsdocPropertyTags.push(child);
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
if (hasChildren) {
|
|
844
|
+
const isArrayType = typeExpressionType !== undefined && typeExpressionType.kind === 189 /* SyntaxKind.ArrayType */;
|
|
845
|
+
const jsdocTypeLiteral = new JSDocTypeLiteral(jsdocPropertyTags, isArrayType);
|
|
846
|
+
const childType = childTypeTag !== undefined && childTypeTag.typeExpression !== undefined
|
|
847
|
+
? getType(childTypeTag.typeExpression)
|
|
848
|
+
: undefined;
|
|
849
|
+
if (childTypeTag !== undefined && childType !== undefined && !isObjectOrObjectArrayTypeReference(childType)) {
|
|
850
|
+
typeExpression = childTypeTag.typeExpression;
|
|
851
|
+
}
|
|
852
|
+
else {
|
|
853
|
+
// This differs from Strada but prevents a crash.
|
|
854
|
+
const pos = jsdocPropertyTags.length > 0 ? jsdocPropertyTags[0].pos : start;
|
|
855
|
+
typeExpression = p.finishNode(jsdocTypeLiteral, pos);
|
|
856
|
+
}
|
|
857
|
+
end = typeExpression.end;
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
// Only include the text between the name and the next token if it's a comment, not just whitespace.
|
|
861
|
+
if (end === -1) {
|
|
862
|
+
if (hasChildren && typeExpression !== undefined)
|
|
863
|
+
end = typeExpression.end;
|
|
864
|
+
else if (comment !== undefined)
|
|
865
|
+
end = p.nodePos();
|
|
866
|
+
else if (fullName !== undefined)
|
|
867
|
+
end = fullName.end;
|
|
868
|
+
else if (typeExpression !== undefined)
|
|
869
|
+
end = typeExpression.end;
|
|
870
|
+
else
|
|
871
|
+
end = tagName.end;
|
|
872
|
+
}
|
|
873
|
+
if (comment === undefined)
|
|
874
|
+
comment = this.parseTrailingTagComments(start, end, indent, indentText);
|
|
875
|
+
const typedefTag = p.finishNodeWithEnd(new JSDocTypedefTag(tagName, typeExpression, fullName, comment), start, end);
|
|
876
|
+
// Overwrite the parent possibly set by the inner type expression parse.
|
|
877
|
+
if (typeExpression !== undefined)
|
|
878
|
+
typeExpression.parent = typedefTag;
|
|
879
|
+
return typedefTag;
|
|
880
|
+
}
|
|
881
|
+
parseCallbackTagParameters(indent) {
|
|
882
|
+
const p = this.p;
|
|
883
|
+
const parameters = [];
|
|
884
|
+
const pos = p.nodePos();
|
|
885
|
+
for (;;) {
|
|
886
|
+
const state = p.mark();
|
|
887
|
+
const child = this.parseChildParameterOrPropertyTag(4 /* PropertyLikeParse.CallbackParameter */, indent, undefined);
|
|
888
|
+
if (child === undefined) {
|
|
889
|
+
p.rewind(state);
|
|
890
|
+
break;
|
|
891
|
+
}
|
|
892
|
+
if (child.kind === 337 /* SyntaxKind.JSDocTemplateTag */)
|
|
893
|
+
this.reportTemplateAfterTypedef(child);
|
|
894
|
+
else
|
|
895
|
+
parameters.push(child);
|
|
896
|
+
}
|
|
897
|
+
return p.newNodeList(pos, p.nodePos(), parameters);
|
|
898
|
+
}
|
|
899
|
+
parseJSDocSignature(start, indent) {
|
|
900
|
+
const p = this.p;
|
|
901
|
+
const parameters = this.parseCallbackTagParameters(indent);
|
|
902
|
+
let returnTag;
|
|
903
|
+
const state = p.mark();
|
|
904
|
+
if (this.parseOptionalJsdoc(59 /* SyntaxKind.AtToken */)) {
|
|
905
|
+
const tag = this.parseTag([], indent);
|
|
906
|
+
if (tag.kind === 334 /* SyntaxKind.JSDocReturnTag */)
|
|
907
|
+
returnTag = tag;
|
|
908
|
+
}
|
|
909
|
+
if (returnTag === undefined)
|
|
910
|
+
p.rewind(state);
|
|
911
|
+
const result = new JSDocSignature(undefined, parameters, returnTag);
|
|
912
|
+
p.finishNode(result, start);
|
|
913
|
+
return result;
|
|
914
|
+
}
|
|
915
|
+
parseCallbackTag(start, tagName, indent, indentText) {
|
|
916
|
+
const p = this.p;
|
|
917
|
+
let fullName = this.parseJSDocTypeNameWithNamespace(false);
|
|
918
|
+
if (fullName === undefined)
|
|
919
|
+
fullName = this.parseJSDocIdentifierName(1 /* Diagnostics.Identifier_expected */);
|
|
920
|
+
this.skipWhitespace();
|
|
921
|
+
let comment = this.parseTagComments(indent, undefined);
|
|
922
|
+
const typeExpression = this.parseJSDocSignature(p.nodePos(), indent);
|
|
923
|
+
if (comment === undefined)
|
|
924
|
+
comment = this.parseTrailingTagComments(start, p.nodePos(), indent, indentText);
|
|
925
|
+
const end = comment !== undefined ? p.nodePos() : typeExpression.end;
|
|
926
|
+
return p.finishNodeWithEnd(new JSDocCallbackTag(tagName, typeExpression, fullName, comment), start, end);
|
|
927
|
+
}
|
|
928
|
+
parseOverloadTag(start, tagName, indent, indentText) {
|
|
929
|
+
const p = this.p;
|
|
930
|
+
this.skipWhitespace();
|
|
931
|
+
let comment = this.parseTagComments(indent, undefined);
|
|
932
|
+
const typeExpression = this.parseJSDocSignature(start, indent);
|
|
933
|
+
if (comment === undefined)
|
|
934
|
+
comment = this.parseTrailingTagComments(start, p.nodePos(), indent, indentText);
|
|
935
|
+
const end = comment !== undefined ? p.nodePos() : typeExpression.end;
|
|
936
|
+
return p.finishNodeWithEnd(new JSDocOverloadTag(tagName, typeExpression, comment), start, end);
|
|
937
|
+
}
|
|
938
|
+
parseChildParameterOrPropertyTag(target, indent, name) {
|
|
939
|
+
const p = this.p;
|
|
940
|
+
let canParseTag = true;
|
|
941
|
+
let seenAsterisk = false;
|
|
942
|
+
for (;;) {
|
|
943
|
+
switch (p.nextTokenJSDoc()) {
|
|
944
|
+
case 59 /* SyntaxKind.AtToken */:
|
|
945
|
+
if (canParseTag && p.scanner.canFollowJSDocAt()) {
|
|
946
|
+
const child = this.tryParseChildTag(target, indent);
|
|
947
|
+
if (child instanceof JSDocParameterOrPropertyTag && name !== undefined) {
|
|
948
|
+
const childName = child.name;
|
|
949
|
+
if (childName instanceof Identifier ||
|
|
950
|
+
!(childName instanceof QualifiedName) ||
|
|
951
|
+
!textsEqual(name, childName.left))
|
|
952
|
+
return undefined;
|
|
953
|
+
}
|
|
954
|
+
return child;
|
|
955
|
+
}
|
|
956
|
+
seenAsterisk = false;
|
|
957
|
+
break;
|
|
958
|
+
case 4 /* SyntaxKind.NewLineTrivia */:
|
|
959
|
+
canParseTag = true;
|
|
960
|
+
seenAsterisk = false;
|
|
961
|
+
break;
|
|
962
|
+
case 41 /* SyntaxKind.AsteriskToken */:
|
|
963
|
+
if (seenAsterisk)
|
|
964
|
+
canParseTag = false;
|
|
965
|
+
seenAsterisk = true;
|
|
966
|
+
break;
|
|
967
|
+
case 79 /* SyntaxKind.Identifier */:
|
|
968
|
+
canParseTag = false;
|
|
969
|
+
break;
|
|
970
|
+
case 1 /* SyntaxKind.EndOfFile */:
|
|
971
|
+
return undefined;
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
tryParseChildTag(target, indent) {
|
|
976
|
+
const p = this.p;
|
|
977
|
+
const start = p.scanner.getTokenFullStart();
|
|
978
|
+
p.nextTokenJSDoc();
|
|
979
|
+
const tagName = this.parseJSDocIdentifierName(1 /* Diagnostics.Identifier_expected */);
|
|
980
|
+
const indentText = this.skipWhitespaceOrAsterisk();
|
|
981
|
+
let t;
|
|
982
|
+
switch (tagName.text) {
|
|
983
|
+
case 'type':
|
|
984
|
+
if (target === 1 /* PropertyLikeParse.Property */)
|
|
985
|
+
return this.parseTypeTag([], start, tagName, -1, '');
|
|
986
|
+
return undefined;
|
|
987
|
+
case 'prop':
|
|
988
|
+
case 'property':
|
|
989
|
+
t = 1 /* PropertyLikeParse.Property */;
|
|
990
|
+
break;
|
|
991
|
+
case 'arg':
|
|
992
|
+
case 'argument':
|
|
993
|
+
case 'param':
|
|
994
|
+
t = 2 /* PropertyLikeParse.Parameter */ | 4 /* PropertyLikeParse.CallbackParameter */;
|
|
995
|
+
break;
|
|
996
|
+
case 'template':
|
|
997
|
+
return this.parseTemplateTag(start, tagName, indent, indentText);
|
|
998
|
+
case 'this':
|
|
999
|
+
return this.parseThisTag(start, tagName, indent, indentText);
|
|
1000
|
+
default:
|
|
1001
|
+
return undefined;
|
|
1002
|
+
}
|
|
1003
|
+
if ((target & t) === 0)
|
|
1004
|
+
return undefined;
|
|
1005
|
+
return this.parseParameterOrPropertyTag(start, tagName, target, indent);
|
|
1006
|
+
}
|
|
1007
|
+
parseTemplateTagTypeParameter() {
|
|
1008
|
+
const p = this.p;
|
|
1009
|
+
const typeParameterPos = p.nodePos();
|
|
1010
|
+
const isBracketed = this.parseOptionalJsdoc(22 /* SyntaxKind.OpenBracketToken */);
|
|
1011
|
+
if (isBracketed)
|
|
1012
|
+
this.skipWhitespace();
|
|
1013
|
+
const modifiers = p.parseModifiersEx(false, true, false);
|
|
1014
|
+
const name = this.parseJSDocIdentifierName(53 /* Diagnostics.Unexpected_token_A_type_parameter_name_was_expected_without_curly_braces */);
|
|
1015
|
+
let defaultType;
|
|
1016
|
+
if (isBracketed) {
|
|
1017
|
+
this.skipWhitespace();
|
|
1018
|
+
p.parseExpected(63 /* SyntaxKind.EqualsToken */);
|
|
1019
|
+
const saveContextFlags = p.contextFlags;
|
|
1020
|
+
p.setContextFlags(4194304 /* NodeFlags.JSDoc */, true);
|
|
1021
|
+
defaultType = p.parseJSDocType();
|
|
1022
|
+
p.contextFlags = saveContextFlags;
|
|
1023
|
+
p.parseExpected(23 /* SyntaxKind.CloseBracketToken */);
|
|
1024
|
+
}
|
|
1025
|
+
if (name.pos === name.end && name.pos >= 0)
|
|
1026
|
+
return undefined;
|
|
1027
|
+
return p.finishNode(new TypeParameterDeclaration(modifiers, name, undefined, undefined, defaultType), typeParameterPos);
|
|
1028
|
+
}
|
|
1029
|
+
parseTemplateTagTypeParameters() {
|
|
1030
|
+
// tsgo builds this list without a text range.
|
|
1031
|
+
const typeParameters = [];
|
|
1032
|
+
do {
|
|
1033
|
+
this.skipWhitespace();
|
|
1034
|
+
const node = this.parseTemplateTagTypeParameter();
|
|
1035
|
+
if (node !== undefined)
|
|
1036
|
+
typeParameters.push(node);
|
|
1037
|
+
this.skipWhitespaceOrAsterisk();
|
|
1038
|
+
} while (this.parseOptionalJsdoc(27 /* SyntaxKind.CommaToken */));
|
|
1039
|
+
return new NodeList(0, 0, typeParameters);
|
|
1040
|
+
}
|
|
1041
|
+
parseTemplateTag(start, tagName, indent, indentText) {
|
|
1042
|
+
// `@template T,U,V` or `@template {Constraint} T`.
|
|
1043
|
+
const p = this.p;
|
|
1044
|
+
const constraint = p.token() === 18 /* SyntaxKind.OpenBraceToken */ ? this.parseJSDocTypeExpression(false) : undefined;
|
|
1045
|
+
const typeParameters = this.parseTemplateTagTypeParameters();
|
|
1046
|
+
const result = new JSDocTemplateTag(tagName, constraint, typeParameters, this.parseTrailingTagComments(start, p.nodePos(), indent, indentText));
|
|
1047
|
+
return p.finishNode(result, start);
|
|
1048
|
+
}
|
|
1049
|
+
parseOptionalJsdoc(t) {
|
|
1050
|
+
if (this.p.token() === t) {
|
|
1051
|
+
this.p.nextTokenJSDoc();
|
|
1052
|
+
return true;
|
|
1053
|
+
}
|
|
1054
|
+
return false;
|
|
1055
|
+
}
|
|
1056
|
+
parseJSDocEntityName(diagnosticMessage) {
|
|
1057
|
+
const p = this.p;
|
|
1058
|
+
let entity = this.parseJSDocIdentifierName(diagnosticMessage);
|
|
1059
|
+
// `y[]` is accepted as an entity name; the brackets aren't kept.
|
|
1060
|
+
if (p.parseOptional(22 /* SyntaxKind.OpenBracketToken */))
|
|
1061
|
+
p.parseExpected(23 /* SyntaxKind.CloseBracketToken */);
|
|
1062
|
+
while (p.parseOptional(24 /* SyntaxKind.DotToken */)) {
|
|
1063
|
+
const name = this.parseJSDocIdentifierName(1 /* Diagnostics.Identifier_expected */);
|
|
1064
|
+
if (p.parseOptional(22 /* SyntaxKind.OpenBracketToken */))
|
|
1065
|
+
p.parseExpected(23 /* SyntaxKind.CloseBracketToken */);
|
|
1066
|
+
entity = p.finishNode(new QualifiedName(entity, name), entity.pos);
|
|
1067
|
+
}
|
|
1068
|
+
return entity;
|
|
1069
|
+
}
|
|
1070
|
+
parseJSDocIdentifierName(diagnosticMessage) {
|
|
1071
|
+
const p = this.p;
|
|
1072
|
+
if (!tokenIsIdentifierOrKeyword(p.token())) {
|
|
1073
|
+
if (diagnosticMessage !== undefined)
|
|
1074
|
+
p.parseErrorAtCurrentToken(diagnosticMessage);
|
|
1075
|
+
else if (isReservedWord(p.token()))
|
|
1076
|
+
p.parseErrorAtCurrentToken(293 /* Diagnostics.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here */, [
|
|
1077
|
+
p.scanner.getTokenText(),
|
|
1078
|
+
]);
|
|
1079
|
+
const missing = p.newIdentifier('');
|
|
1080
|
+
p.finishNode(missing, p.nodePos());
|
|
1081
|
+
return missing;
|
|
1082
|
+
}
|
|
1083
|
+
const pos = p.scanner.getTokenStart();
|
|
1084
|
+
const end = p.scanner.getTokenEnd();
|
|
1085
|
+
const text = p.scanner.getIdentifierValue();
|
|
1086
|
+
p.internIdentifier(text);
|
|
1087
|
+
p.nextTokenJSDoc();
|
|
1088
|
+
const result = p.newIdentifier(text);
|
|
1089
|
+
p.finishNodeWithEnd(result, pos, end);
|
|
1090
|
+
return result;
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
function newDiagnosticAtStart(message) {
|
|
1094
|
+
return new Diagnostic(undefined, 0, 0, message, []);
|
|
1095
|
+
}
|
|
1096
|
+
function hasTagOfKind(tags, kind) {
|
|
1097
|
+
for (const tag of tags)
|
|
1098
|
+
if (tag.kind === kind)
|
|
1099
|
+
return true;
|
|
1100
|
+
return false;
|
|
1101
|
+
}
|
|
1102
|
+
function isObjectOrObjectArrayTypeReference(node) {
|
|
1103
|
+
if (node.kind === 151 /* SyntaxKind.ObjectKeyword */)
|
|
1104
|
+
return true;
|
|
1105
|
+
if (node instanceof ArrayTypeNode)
|
|
1106
|
+
return isObjectOrObjectArrayTypeReference(node.elementType);
|
|
1107
|
+
if (!(node instanceof TypeReferenceNode))
|
|
1108
|
+
return false;
|
|
1109
|
+
const typeName = node.typeName;
|
|
1110
|
+
return (typeName instanceof Identifier &&
|
|
1111
|
+
typeName.text === 'Object' &&
|
|
1112
|
+
node.typeArguments === undefined);
|
|
1113
|
+
}
|
|
1114
|
+
/** Whether two entity names are the same dotted name. */
|
|
1115
|
+
function textsEqual(a, b) {
|
|
1116
|
+
while (!(a instanceof Identifier) || !(b instanceof Identifier)) {
|
|
1117
|
+
if (a instanceof QualifiedName &&
|
|
1118
|
+
b instanceof QualifiedName &&
|
|
1119
|
+
a.right.text === b.right.text) {
|
|
1120
|
+
a = a.left;
|
|
1121
|
+
b = b.left;
|
|
1122
|
+
}
|
|
1123
|
+
else {
|
|
1124
|
+
return false;
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
return a.text === b.text;
|
|
1128
|
+
}
|
|
1129
|
+
function isNextNonwhitespaceTokenEndOfFile(p) {
|
|
1130
|
+
return p.jsdoc.isNextNonwhitespaceTokenEndOfFile();
|
|
1131
|
+
}
|
|
1132
|
+
function isNotJSDocLinkPrefix(p) {
|
|
1133
|
+
return p.jsdoc.parseJSDocLinkPrefix() === undefined;
|
|
1134
|
+
}
|
|
1135
|
+
function nextTokenIsIdentifierOrKeyword(p) {
|
|
1136
|
+
return tokenIsIdentifierOrKeyword(p.nextToken());
|
|
1137
|
+
}
|
|
1138
|
+
/** Removes leading strings made only of line breaks. */
|
|
1139
|
+
function removeLeadingNewlines(comments) {
|
|
1140
|
+
let i = 0;
|
|
1141
|
+
while (i < comments.length && isOnlyLineBreaks(comments[i]))
|
|
1142
|
+
i++;
|
|
1143
|
+
if (i > 0)
|
|
1144
|
+
comments.splice(0, i);
|
|
1145
|
+
}
|
|
1146
|
+
function isOnlyLineBreaks(s) {
|
|
1147
|
+
for (let i = 0; i < s.length; i++) {
|
|
1148
|
+
const ch = s.charCodeAt(i);
|
|
1149
|
+
if (ch !== 13 /* CharacterCodes.carriageReturn */ && ch !== 10 /* CharacterCodes.lineFeed */)
|
|
1150
|
+
return false;
|
|
1151
|
+
}
|
|
1152
|
+
return true;
|
|
1153
|
+
}
|
|
1154
|
+
/** Trims trailing whitespace, dropping strings that become empty. */
|
|
1155
|
+
function removeTrailingWhitespace(comments) {
|
|
1156
|
+
let end = comments.length;
|
|
1157
|
+
for (let i = comments.length - 1; i >= 0; i--) {
|
|
1158
|
+
const trimmed = trimEndWhiteSpaceLike(comments[i]);
|
|
1159
|
+
if (trimmed === '') {
|
|
1160
|
+
end = i;
|
|
1161
|
+
}
|
|
1162
|
+
else {
|
|
1163
|
+
comments[i] = trimmed;
|
|
1164
|
+
break;
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
comments.length = end;
|
|
1168
|
+
}
|
|
1169
|
+
function trimEndWhiteSpaceLike(s) {
|
|
1170
|
+
let end = s.length;
|
|
1171
|
+
while (end > 0 && isWhiteSpaceLike(s.charCodeAt(end - 1)))
|
|
1172
|
+
end--;
|
|
1173
|
+
return s.substring(0, end);
|
|
1174
|
+
}
|
|
1175
|
+
/** Go's unicode.IsSpace. */
|
|
1176
|
+
function isUnicodeSpace(ch) {
|
|
1177
|
+
switch (ch) {
|
|
1178
|
+
case 0x09:
|
|
1179
|
+
case 0x0a:
|
|
1180
|
+
case 0x0b:
|
|
1181
|
+
case 0x0c:
|
|
1182
|
+
case 0x0d:
|
|
1183
|
+
case 0x20:
|
|
1184
|
+
case 0x85:
|
|
1185
|
+
case 0xa0:
|
|
1186
|
+
case 0x1680:
|
|
1187
|
+
case 0x2028:
|
|
1188
|
+
case 0x2029:
|
|
1189
|
+
case 0x202f:
|
|
1190
|
+
case 0x205f:
|
|
1191
|
+
case 0x3000:
|
|
1192
|
+
return true;
|
|
1193
|
+
}
|
|
1194
|
+
return ch >= 0x2000 && ch <= 0x200a;
|
|
1195
|
+
}
|
|
1196
|
+
function trimEndUnicodeSpace(s) {
|
|
1197
|
+
let end = s.length;
|
|
1198
|
+
while (end > 0 && isUnicodeSpace(s.charCodeAt(end - 1)))
|
|
1199
|
+
end--;
|
|
1200
|
+
return s.substring(0, end);
|
|
1201
|
+
}
|
|
1202
|
+
/** The UTF-8 length of `s`, as tsgo measures text (a lone surrogate counts as U+FFFD). */
|
|
1203
|
+
function utf8Length(s) {
|
|
1204
|
+
return Buffer.byteLength(s, 'utf8');
|
|
1205
|
+
}
|
|
1206
|
+
/** `s` from the UTF-8 byte offset `offset` on (rounded up to a character boundary). */
|
|
1207
|
+
function sliceFromUtf8Offset(s, offset) {
|
|
1208
|
+
let bytes = 0;
|
|
1209
|
+
let i = 0;
|
|
1210
|
+
while (i < s.length && bytes < offset) {
|
|
1211
|
+
const ch = s.charCodeAt(i);
|
|
1212
|
+
if (ch < 0x80)
|
|
1213
|
+
bytes += 1;
|
|
1214
|
+
else if (ch < 0x800)
|
|
1215
|
+
bytes += 2;
|
|
1216
|
+
else if (ch >= 0xd800 &&
|
|
1217
|
+
ch <= 0xdbff &&
|
|
1218
|
+
i + 1 < s.length &&
|
|
1219
|
+
s.charCodeAt(i + 1) >= 0xdc00 &&
|
|
1220
|
+
s.charCodeAt(i + 1) <= 0xdfff) {
|
|
1221
|
+
bytes += 4;
|
|
1222
|
+
i++;
|
|
1223
|
+
}
|
|
1224
|
+
else
|
|
1225
|
+
bytes += 3;
|
|
1226
|
+
i++;
|
|
1227
|
+
}
|
|
1228
|
+
return s.substring(i);
|
|
1229
|
+
}
|