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,767 @@
|
|
|
1
|
+
// Finding nodes and tokens at positions of a source file, like tsgo's astnav.
|
|
2
|
+
import { getComment, JSDocParameterOrPropertyTag, NodeVisitor, Token, } from './ast.js';
|
|
3
|
+
import { isPropertyNameLiteral } from './binder-utilities.js';
|
|
4
|
+
import { nodeIsMissing } from './ast-utilities.js';
|
|
5
|
+
import { getJSDoc } from './parser.js';
|
|
6
|
+
import { Scanner, skipTrivia } from './scanner.js';
|
|
7
|
+
/** The property name or token touching `position`. */
|
|
8
|
+
export function getTouchingPropertyName(file, position) {
|
|
9
|
+
return findTokenAtPosition(file, position, false, true);
|
|
10
|
+
}
|
|
11
|
+
/** The token touching `position`. */
|
|
12
|
+
export function getTouchingToken(file, position) {
|
|
13
|
+
return findTokenAtPosition(file, position, false, false);
|
|
14
|
+
}
|
|
15
|
+
/** Whether a token ending at a touched position counts as touching it. */
|
|
16
|
+
function isTouchingPropertyName(node) {
|
|
17
|
+
return isPropertyNameLiteral(node) || isKeywordKind(node.kind) || node.kind === 80 /* SyntaxKind.PrivateIdentifier */;
|
|
18
|
+
}
|
|
19
|
+
function isKeywordKind(kind) {
|
|
20
|
+
return kind >= 82 /* SyntaxKind.FirstKeyword */ && kind <= 166 /* SyntaxKind.LastKeyword */;
|
|
21
|
+
}
|
|
22
|
+
function isTokenKind(kind) {
|
|
23
|
+
return kind >= 0 /* SyntaxKind.FirstToken */ && kind <= 166 /* SyntaxKind.LastToken */;
|
|
24
|
+
}
|
|
25
|
+
function isJSDocKind(kind) {
|
|
26
|
+
return kind >= 308 /* SyntaxKind.FirstJSDocNode */ && kind <= 343 /* SyntaxKind.LastJSDocNode */;
|
|
27
|
+
}
|
|
28
|
+
function isReparsed(node) {
|
|
29
|
+
return (node.flags & 8 /* NodeFlags.Reparsed */) !== 0;
|
|
30
|
+
}
|
|
31
|
+
function isWhitespaceOnlyJsxText(node) {
|
|
32
|
+
return node.kind === 11 /* SyntaxKind.JsxText */ && node.containsOnlyTriviaWhiteSpaces;
|
|
33
|
+
}
|
|
34
|
+
function isNonWhitespaceToken(node) {
|
|
35
|
+
return isTokenKind(node.kind) && !isWhitespaceOnlyJsxText(node);
|
|
36
|
+
}
|
|
37
|
+
function isJsxChild(node) {
|
|
38
|
+
switch (node.kind) {
|
|
39
|
+
case 285 /* SyntaxKind.JsxElement */:
|
|
40
|
+
case 295 /* SyntaxKind.JsxExpression */:
|
|
41
|
+
case 286 /* SyntaxKind.JsxSelfClosingElement */:
|
|
42
|
+
case 11 /* SyntaxKind.JsxText */:
|
|
43
|
+
case 289 /* SyntaxKind.JsxFragment */:
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
/** JSDoc nodes whose trivia isn't made of tokens. */
|
|
49
|
+
function shouldSkipChild(node) {
|
|
50
|
+
const kind = node.kind;
|
|
51
|
+
return (kind === 315 /* SyntaxKind.JSDoc */ ||
|
|
52
|
+
kind === 316 /* SyntaxKind.JSDocText */ ||
|
|
53
|
+
kind === 317 /* SyntaxKind.JSDocTypeLiteral */ ||
|
|
54
|
+
kind === 318 /* SyntaxKind.JSDocSignature */ ||
|
|
55
|
+
kind === 319 /* SyntaxKind.JSDocLink */ ||
|
|
56
|
+
kind === 320 /* SyntaxKind.JSDocLinkCode */ ||
|
|
57
|
+
kind === 321 /* SyntaxKind.JSDocLinkPlain */ ||
|
|
58
|
+
(kind >= 322 /* SyntaxKind.FirstJSDocTagNode */ && kind <= 343 /* SyntaxKind.LastJSDocTagNode */));
|
|
59
|
+
}
|
|
60
|
+
/** A lone JSDoc comment node, which navigation treats as part of its parent's text. */
|
|
61
|
+
function isSingleCommentList(list) {
|
|
62
|
+
if (list.nodes.length !== 1)
|
|
63
|
+
return false;
|
|
64
|
+
const parent = list.nodes[0].parent;
|
|
65
|
+
return parent !== undefined && isJSDocKind(parent.kind) && getComment(parent) === list;
|
|
66
|
+
}
|
|
67
|
+
/** The start of a node's first token, optionally including its JSDoc. */
|
|
68
|
+
export function getTokenPosOfNode(node, file, includeJSDoc) {
|
|
69
|
+
// Missing nodes have no width; skipping trivia would move to the next token.
|
|
70
|
+
if (nodeIsMissing(node))
|
|
71
|
+
return node.pos;
|
|
72
|
+
// JSX text can't contain comments, though the scanner would see them.
|
|
73
|
+
if (isJSDocKind(node.kind) || node.kind === 11 /* SyntaxKind.JsxText */)
|
|
74
|
+
return skipTrivia(file.text, node.pos, false, true, false);
|
|
75
|
+
if (includeJSDoc) {
|
|
76
|
+
const jsDoc = getJSDoc(file, node);
|
|
77
|
+
if (jsDoc.length > 0)
|
|
78
|
+
return getTokenPosOfNode(jsDoc[0], file, false);
|
|
79
|
+
}
|
|
80
|
+
return skipTrivia(file.text, node.pos, false, false, (node.flags & 4194304 /* NodeFlags.JSDoc */) !== 0);
|
|
81
|
+
}
|
|
82
|
+
/** Visits the JSDoc and then the children of a node, in the order navigation expects. */
|
|
83
|
+
function visitChildrenAndJSDoc(node, file, visitor) {
|
|
84
|
+
const jsDoc = getJSDoc(file, node);
|
|
85
|
+
for (let i = 0; i < jsDoc.length; i++)
|
|
86
|
+
visitor.visitNode(jsDoc[i]);
|
|
87
|
+
if (node instanceof JSDocParameterOrPropertyTag) {
|
|
88
|
+
// The tag name, the name, then the type, wherever the type is written.
|
|
89
|
+
visitor.visitNode(node.tagName);
|
|
90
|
+
visitor.visitNode(node.name);
|
|
91
|
+
if (node.typeExpression !== undefined)
|
|
92
|
+
visitor.visitNode(node.typeExpression);
|
|
93
|
+
if (node.comment !== undefined)
|
|
94
|
+
visitor.visitList(node.comment);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
node.forEachChild(visitor);
|
|
98
|
+
}
|
|
99
|
+
let navigationScanner;
|
|
100
|
+
let navigationScannerFile;
|
|
101
|
+
/** A scanner positioned on the token at `pos`. */
|
|
102
|
+
function getScannerAt(file, pos) {
|
|
103
|
+
let scanner = navigationScanner;
|
|
104
|
+
if (scanner === undefined) {
|
|
105
|
+
scanner = new Scanner();
|
|
106
|
+
navigationScanner = scanner;
|
|
107
|
+
}
|
|
108
|
+
if (navigationScannerFile !== file) {
|
|
109
|
+
scanner.setText(file.text);
|
|
110
|
+
scanner.setLanguageVariant(file.languageVariant);
|
|
111
|
+
navigationScannerFile = file;
|
|
112
|
+
}
|
|
113
|
+
scanner.resetTokenState(pos);
|
|
114
|
+
scanner.scan();
|
|
115
|
+
return scanner;
|
|
116
|
+
}
|
|
117
|
+
function scanNavigationToken(scanner, containingNode) {
|
|
118
|
+
const token = scanner.getToken();
|
|
119
|
+
if (token === 47 /* SyntaxKind.LessThanLessThanToken */ && isJsxChild(containingNode))
|
|
120
|
+
return scanner.reScanJsxToken(true);
|
|
121
|
+
return token;
|
|
122
|
+
}
|
|
123
|
+
// Tokens made from the scanner, by parent and range, so repeated lookups in a file give the
|
|
124
|
+
// same node. Only the most recently navigated file is cached.
|
|
125
|
+
let tokenCacheFile;
|
|
126
|
+
let tokenCache = new Map();
|
|
127
|
+
/** Forgets the file the navigation scanner and token cache last visited. */
|
|
128
|
+
export function forgetNavigationFile() {
|
|
129
|
+
navigationScanner = undefined;
|
|
130
|
+
navigationScannerFile = undefined;
|
|
131
|
+
tokenCacheFile = undefined;
|
|
132
|
+
tokenCache = new Map();
|
|
133
|
+
}
|
|
134
|
+
/** A token the parser doesn't store, made from the scanner's current token. */
|
|
135
|
+
function createToken(kind, pos, end, parent) {
|
|
136
|
+
const file = navigationScannerFile;
|
|
137
|
+
if (file !== tokenCacheFile) {
|
|
138
|
+
tokenCacheFile = file;
|
|
139
|
+
tokenCache = new Map();
|
|
140
|
+
}
|
|
141
|
+
let byRange = tokenCache.get(parent);
|
|
142
|
+
if (byRange === undefined) {
|
|
143
|
+
byRange = new Map();
|
|
144
|
+
tokenCache.set(parent, byRange);
|
|
145
|
+
}
|
|
146
|
+
const key = pos * 0x4000000 + (end - pos);
|
|
147
|
+
const cached = byRange.get(key);
|
|
148
|
+
if (cached !== undefined && cached.kind === kind)
|
|
149
|
+
return cached;
|
|
150
|
+
const token = new Token(kind);
|
|
151
|
+
token.pos = pos | 0;
|
|
152
|
+
token.end = end | 0;
|
|
153
|
+
token.parent = parent;
|
|
154
|
+
byRange.set(key, token);
|
|
155
|
+
return token;
|
|
156
|
+
}
|
|
157
|
+
// Finds the child of the current node that contains the target position.
|
|
158
|
+
class TokenAtPositionVisitor extends NodeVisitor {
|
|
159
|
+
file;
|
|
160
|
+
position;
|
|
161
|
+
allowPositionInLeadingTrivia;
|
|
162
|
+
includePrecedingToken;
|
|
163
|
+
/** The child to descend into. */
|
|
164
|
+
next = undefined;
|
|
165
|
+
/** A child ending at the position, whose last token may touch it. */
|
|
166
|
+
prevSubtree = undefined;
|
|
167
|
+
/** The lower bound of the token to return; where scanning starts. */
|
|
168
|
+
left = 0;
|
|
169
|
+
/** The first child after the one that moved `left`; scanning stops at its start. */
|
|
170
|
+
nodeAfterLeft = undefined;
|
|
171
|
+
constructor(file, position, allowPositionInLeadingTrivia, includePrecedingToken) {
|
|
172
|
+
super();
|
|
173
|
+
this.file = file;
|
|
174
|
+
this.position = position;
|
|
175
|
+
this.allowPositionInLeadingTrivia = allowPositionInLeadingTrivia;
|
|
176
|
+
this.includePrecedingToken = includePrecedingToken;
|
|
177
|
+
}
|
|
178
|
+
/** -1 if `node` ends before the position, 1 if it starts after it, 0 if it contains it. */
|
|
179
|
+
testNode(node) {
|
|
180
|
+
const position = this.position;
|
|
181
|
+
if (node.kind !== 1 /* SyntaxKind.EndOfFile */ && node.end === position && this.includePrecedingToken && !isReparsed(node))
|
|
182
|
+
this.prevSubtree = node;
|
|
183
|
+
// Nodes at the end of the file contain their end, since there's nowhere else to look.
|
|
184
|
+
if (node.end < position ||
|
|
185
|
+
(node.end === position &&
|
|
186
|
+
node.kind !== 1 /* SyntaxKind.EndOfFile */ &&
|
|
187
|
+
(!isJSDocKind(node.kind) || node.end !== this.file.endOfFileToken.end)))
|
|
188
|
+
return -1;
|
|
189
|
+
const start = this.allowPositionInLeadingTrivia ? node.pos : getTokenPosOfNode(node, this.file, true);
|
|
190
|
+
return start > this.position ? 1 : 0;
|
|
191
|
+
}
|
|
192
|
+
visitNode(node) {
|
|
193
|
+
if (isReparsed(node) || isSingleCommentNode(node))
|
|
194
|
+
return false;
|
|
195
|
+
if (this.nodeAfterLeft === undefined)
|
|
196
|
+
this.nodeAfterLeft = node;
|
|
197
|
+
if (this.next === undefined) {
|
|
198
|
+
const result = this.testNode(node);
|
|
199
|
+
if (result < 0) {
|
|
200
|
+
// `left` can't move into JSDoc: a token after it is scanned with all its leading trivia.
|
|
201
|
+
if (!isJSDocKind(node.kind))
|
|
202
|
+
this.left = node.end;
|
|
203
|
+
this.nodeAfterLeft = undefined;
|
|
204
|
+
}
|
|
205
|
+
else if (result === 0)
|
|
206
|
+
this.next = node;
|
|
207
|
+
}
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
visitList(list) {
|
|
211
|
+
const nodes = list.nodes;
|
|
212
|
+
if (nodes.length === 0 || isSingleCommentList(list))
|
|
213
|
+
return false;
|
|
214
|
+
if (this.nodeAfterLeft === undefined) {
|
|
215
|
+
for (let i = 0; i < nodes.length; i++)
|
|
216
|
+
if (!isReparsed(nodes[i])) {
|
|
217
|
+
this.nodeAfterLeft = nodes[i];
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (this.next !== undefined)
|
|
222
|
+
return false;
|
|
223
|
+
const position = this.position;
|
|
224
|
+
if (list.end === position && this.includePrecedingToken) {
|
|
225
|
+
this.left = list.end;
|
|
226
|
+
this.nodeAfterLeft = undefined;
|
|
227
|
+
for (let i = nodes.length - 1; i >= 0; i--)
|
|
228
|
+
if (!isReparsed(nodes[i])) {
|
|
229
|
+
this.prevSubtree = nodes[i];
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
else if (list.end <= position) {
|
|
234
|
+
this.left = list.end;
|
|
235
|
+
this.nodeAfterLeft = undefined;
|
|
236
|
+
}
|
|
237
|
+
else if (list.pos <= position) {
|
|
238
|
+
let index = this.searchList(nodes, true);
|
|
239
|
+
let candidates = nodes;
|
|
240
|
+
if (index >= 0 && isReparsed(nodes[index])) {
|
|
241
|
+
candidates = nodes.filter((node) => !isReparsed(node));
|
|
242
|
+
index = this.searchList(candidates, false);
|
|
243
|
+
}
|
|
244
|
+
if (index >= 0)
|
|
245
|
+
this.next = candidates[index];
|
|
246
|
+
}
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
visitModifiers(list) {
|
|
250
|
+
return this.visitList(list);
|
|
251
|
+
}
|
|
252
|
+
/** The index of the node containing the position, or -1. */
|
|
253
|
+
searchList(nodes, skipReparsed) {
|
|
254
|
+
let low = 0;
|
|
255
|
+
let high = nodes.length - 1;
|
|
256
|
+
while (low <= high) {
|
|
257
|
+
const middle = low + ((high - low) >> 1);
|
|
258
|
+
const node = nodes[middle];
|
|
259
|
+
if (skipReparsed && isReparsed(node))
|
|
260
|
+
return middle;
|
|
261
|
+
const cmp = this.testNode(node);
|
|
262
|
+
if (cmp < 0) {
|
|
263
|
+
this.left = node.end;
|
|
264
|
+
this.nodeAfterLeft = undefined;
|
|
265
|
+
for (let i = middle + 1; i < nodes.length; i++)
|
|
266
|
+
if (!skipReparsed || !isReparsed(nodes[i])) {
|
|
267
|
+
this.nodeAfterLeft = nodes[i];
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
low = middle + 1;
|
|
271
|
+
}
|
|
272
|
+
else if (cmp > 0)
|
|
273
|
+
high = middle - 1;
|
|
274
|
+
else
|
|
275
|
+
return middle;
|
|
276
|
+
}
|
|
277
|
+
return -1;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
/** Whether `node` is the only comment of a JSDoc node. */
|
|
281
|
+
function isSingleCommentNode(node) {
|
|
282
|
+
const parent = node.parent;
|
|
283
|
+
if (parent === undefined || !isJSDocKind(parent.kind))
|
|
284
|
+
return false;
|
|
285
|
+
const comment = getComment(parent);
|
|
286
|
+
return comment !== undefined && comment.nodes.length === 1 && comment.nodes[0] === node;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* The token at `position`: a node of the tree, or a token made from the scanner. Without
|
|
290
|
+
* `allowPositionInLeadingTrivia`, a position in trivia gives the innermost node containing it.
|
|
291
|
+
* With `includePrecedingToken`, a property name or keyword ending at `position` also counts.
|
|
292
|
+
*/
|
|
293
|
+
function findTokenAtPosition(file, position, allowPositionInLeadingTrivia, includePrecedingToken) {
|
|
294
|
+
let current = file;
|
|
295
|
+
const visitor = new TokenAtPositionVisitor(file, position, allowPositionInLeadingTrivia, includePrecedingToken);
|
|
296
|
+
for (;;) {
|
|
297
|
+
visitChildrenAndJSDoc(current, file, visitor);
|
|
298
|
+
// A subtree ending at the position: its last token may touch it.
|
|
299
|
+
const prevSubtree = visitor.prevSubtree;
|
|
300
|
+
if (prevSubtree !== undefined) {
|
|
301
|
+
const child = findPrecedingTokenIn(file, position, prevSubtree, false);
|
|
302
|
+
if (child !== undefined && child.end === position && isTouchingPropertyName(child))
|
|
303
|
+
return child;
|
|
304
|
+
visitor.prevSubtree = undefined;
|
|
305
|
+
}
|
|
306
|
+
const next = visitor.next;
|
|
307
|
+
if (next === undefined) {
|
|
308
|
+
// As deep as the tree goes: either a token, or one the scanner has to make.
|
|
309
|
+
if (isTokenKind(current.kind) || shouldSkipChild(current))
|
|
310
|
+
return current;
|
|
311
|
+
let left = visitor.left;
|
|
312
|
+
const scanner = getScannerAt(file, left);
|
|
313
|
+
// Scan only up to the next child, so a position between two children finds nothing.
|
|
314
|
+
const end = visitor.nodeAfterLeft !== undefined ? visitor.nodeAfterLeft.pos : current.end;
|
|
315
|
+
while (left < end) {
|
|
316
|
+
const token = scanNavigationToken(scanner, current);
|
|
317
|
+
const tokenFullStart = scanner.getTokenFullStart();
|
|
318
|
+
const tokenStart = allowPositionInLeadingTrivia ? tokenFullStart : scanner.getTokenStart();
|
|
319
|
+
const tokenEnd = scanner.getTokenEnd();
|
|
320
|
+
if (tokenEnd > end)
|
|
321
|
+
break;
|
|
322
|
+
if (tokenStart <= position && position < tokenEnd) {
|
|
323
|
+
if (token === 79 /* SyntaxKind.Identifier */ || !isTokenKind(token)) {
|
|
324
|
+
if (isJSDocKind(current.kind))
|
|
325
|
+
return current;
|
|
326
|
+
throw new Error('did not expect ' + current.kind + ' to have ' + token + ' in its trivia');
|
|
327
|
+
}
|
|
328
|
+
return createToken(token, tokenFullStart, tokenEnd, current);
|
|
329
|
+
}
|
|
330
|
+
if (includePrecedingToken && tokenEnd === position) {
|
|
331
|
+
const prevToken = createToken(token, tokenFullStart, tokenEnd, current);
|
|
332
|
+
if (isTouchingPropertyName(prevToken))
|
|
333
|
+
return prevToken;
|
|
334
|
+
}
|
|
335
|
+
left = tokenEnd;
|
|
336
|
+
scanner.scan();
|
|
337
|
+
}
|
|
338
|
+
return current;
|
|
339
|
+
}
|
|
340
|
+
current = next;
|
|
341
|
+
visitor.left = current.pos;
|
|
342
|
+
visitor.nodeAfterLeft = undefined;
|
|
343
|
+
visitor.next = undefined;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
// Finds the leftmost child ending after the position, and the last child before it.
|
|
347
|
+
class PrecedingChildVisitor extends NodeVisitor {
|
|
348
|
+
position;
|
|
349
|
+
found = undefined;
|
|
350
|
+
prev = undefined;
|
|
351
|
+
constructor(position) {
|
|
352
|
+
super();
|
|
353
|
+
this.position = position;
|
|
354
|
+
}
|
|
355
|
+
visitNode(node) {
|
|
356
|
+
if (isReparsed(node) || isSingleCommentNode(node) || this.found !== undefined)
|
|
357
|
+
return false;
|
|
358
|
+
if (this.position < node.end && (this.prev === undefined || this.prev.end <= this.position))
|
|
359
|
+
this.found = node;
|
|
360
|
+
else
|
|
361
|
+
this.prev = node;
|
|
362
|
+
return false;
|
|
363
|
+
}
|
|
364
|
+
visitList(list) {
|
|
365
|
+
const nodes = list.nodes;
|
|
366
|
+
if (this.found !== undefined || nodes.length === 0 || isSingleCommentList(list))
|
|
367
|
+
return false;
|
|
368
|
+
const position = this.position;
|
|
369
|
+
let low = 0;
|
|
370
|
+
let high = nodes.length - 1;
|
|
371
|
+
let index = -1;
|
|
372
|
+
while (low <= high) {
|
|
373
|
+
const middle = low + ((high - low) >> 1);
|
|
374
|
+
let cmp;
|
|
375
|
+
// Reparsed JSDoc nodes come before the nodes they were made for.
|
|
376
|
+
if (isReparsed(nodes[middle]))
|
|
377
|
+
cmp = -1;
|
|
378
|
+
else if (position < nodes[middle].end) {
|
|
379
|
+
cmp = middle === 0 || position >= nodes[middle - 1].end ? 0 : 1;
|
|
380
|
+
}
|
|
381
|
+
else
|
|
382
|
+
cmp = -1;
|
|
383
|
+
if (cmp < 0)
|
|
384
|
+
low = middle + 1;
|
|
385
|
+
else if (cmp > 0)
|
|
386
|
+
high = middle - 1;
|
|
387
|
+
else {
|
|
388
|
+
index = middle;
|
|
389
|
+
break;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
if (index >= 0)
|
|
393
|
+
this.found = nodes[index];
|
|
394
|
+
const lookup = index >= 0 ? index - 1 : nodes.length - 1;
|
|
395
|
+
for (let i = lookup; i >= 0; i--) {
|
|
396
|
+
if (isReparsed(nodes[i]))
|
|
397
|
+
continue;
|
|
398
|
+
if (this.prev === undefined)
|
|
399
|
+
this.prev = nodes[i];
|
|
400
|
+
}
|
|
401
|
+
return false;
|
|
402
|
+
}
|
|
403
|
+
visitModifiers(list) {
|
|
404
|
+
return this.visitList(list);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* The leftmost token ending after `position`; if that token is invalid or `position` is in
|
|
409
|
+
* its trivia, the rightmost valid token ending at or before `position`.
|
|
410
|
+
*/
|
|
411
|
+
export function findPrecedingToken(file, position) {
|
|
412
|
+
return findPrecedingTokenIn(file, position, file, false);
|
|
413
|
+
}
|
|
414
|
+
function findPrecedingTokenIn(file, position, startNode, excludeJSDoc) {
|
|
415
|
+
let n = startNode;
|
|
416
|
+
for (;;) {
|
|
417
|
+
if (isNonWhitespaceToken(n) && n.kind !== 1 /* SyntaxKind.EndOfFile */)
|
|
418
|
+
return n;
|
|
419
|
+
const visitor = new PrecedingChildVisitor(position);
|
|
420
|
+
visitChildrenAndJSDoc(n, file, visitor);
|
|
421
|
+
const foundChild = visitor.found;
|
|
422
|
+
if (foundChild !== undefined) {
|
|
423
|
+
// A position before the child's tokens, or a child without tokens, looks in earlier children.
|
|
424
|
+
const start = getTokenPosOfNode(foundChild, file, !excludeJSDoc);
|
|
425
|
+
const lookInPreviousChild = start >= position || !isValidPrecedingNode(foundChild, file);
|
|
426
|
+
if (!lookInPreviousChild) {
|
|
427
|
+
n = foundChild;
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
430
|
+
if (position >= foundChild.pos) {
|
|
431
|
+
// JSDoc preceding the child.
|
|
432
|
+
let jsDoc;
|
|
433
|
+
const nodeJSDoc = getJSDoc(file, n);
|
|
434
|
+
for (let i = nodeJSDoc.length - 1; i >= 0; i--)
|
|
435
|
+
if (nodeJSDoc[i].pos >= foundChild.pos) {
|
|
436
|
+
jsDoc = nodeJSDoc[i];
|
|
437
|
+
break;
|
|
438
|
+
}
|
|
439
|
+
if (jsDoc !== undefined) {
|
|
440
|
+
if (!excludeJSDoc && position < jsDoc.end) {
|
|
441
|
+
n = jsDoc;
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
return findRightmostValidToken(jsDoc.end, file, n, position, excludeJSDoc);
|
|
445
|
+
}
|
|
446
|
+
return findRightmostValidToken(foundChild.pos, file, n, -1, excludeJSDoc);
|
|
447
|
+
}
|
|
448
|
+
// Between two visited children.
|
|
449
|
+
return findRightmostValidToken(foundChild.pos, file, n, position, excludeJSDoc);
|
|
450
|
+
}
|
|
451
|
+
// At the end of the file, or in the unvisited trailing tokens of `n`.
|
|
452
|
+
return findRightmostValidToken(n.end, file, n, position >= n.end ? -1 : position, excludeJSDoc);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
function isValidPrecedingNode(node, file) {
|
|
456
|
+
if (node.kind === 1 /* SyntaxKind.EndOfFile */)
|
|
457
|
+
return getJSDoc(file, node).length > 0;
|
|
458
|
+
const start = getTokenPosOfNode(node, file, false);
|
|
459
|
+
return !(isWhitespaceOnlyJsxText(node) || node.end - start === 0);
|
|
460
|
+
}
|
|
461
|
+
// Collects the rightmost valid child and the children visited after it.
|
|
462
|
+
class RightmostChildVisitor extends NodeVisitor {
|
|
463
|
+
file;
|
|
464
|
+
endPos;
|
|
465
|
+
position;
|
|
466
|
+
excludeJSDoc;
|
|
467
|
+
rightmostValid = undefined;
|
|
468
|
+
/** Children after the rightmost valid one. */
|
|
469
|
+
rightmostVisited = [];
|
|
470
|
+
hasChildren = false;
|
|
471
|
+
constructor(file, endPos, position, excludeJSDoc) {
|
|
472
|
+
super();
|
|
473
|
+
this.file = file;
|
|
474
|
+
this.endPos = endPos;
|
|
475
|
+
this.position = position;
|
|
476
|
+
this.excludeJSDoc = excludeJSDoc;
|
|
477
|
+
}
|
|
478
|
+
/** Whether `node` is in the searched range. */
|
|
479
|
+
shouldVisit(node) {
|
|
480
|
+
return !(isReparsed(node) ||
|
|
481
|
+
node.end > this.endPos ||
|
|
482
|
+
getTokenPosOfNode(node, this.file, !this.excludeJSDoc) >= this.position);
|
|
483
|
+
}
|
|
484
|
+
visitNode(node) {
|
|
485
|
+
if (isReparsed(node) || isSingleCommentNode(node))
|
|
486
|
+
return false;
|
|
487
|
+
this.hasChildren = true;
|
|
488
|
+
if (!this.shouldVisit(node))
|
|
489
|
+
return false;
|
|
490
|
+
this.rightmostVisited.push(node);
|
|
491
|
+
if (isValidPrecedingNode(node, this.file)) {
|
|
492
|
+
this.rightmostValid = node;
|
|
493
|
+
this.rightmostVisited = [];
|
|
494
|
+
}
|
|
495
|
+
return false;
|
|
496
|
+
}
|
|
497
|
+
visitList(list) {
|
|
498
|
+
const nodes = list.nodes;
|
|
499
|
+
if (nodes.length === 0 || isSingleCommentList(list))
|
|
500
|
+
return false;
|
|
501
|
+
this.hasChildren = true;
|
|
502
|
+
// The first node ending after `endPos`.
|
|
503
|
+
let low = 0;
|
|
504
|
+
let high = nodes.length - 1;
|
|
505
|
+
while (low <= high) {
|
|
506
|
+
const middle = low + ((high - low) >> 1);
|
|
507
|
+
if (nodes[middle].end > this.endPos)
|
|
508
|
+
high = middle - 1;
|
|
509
|
+
else
|
|
510
|
+
low = middle + 1;
|
|
511
|
+
}
|
|
512
|
+
const index = low;
|
|
513
|
+
let validIndex = -1;
|
|
514
|
+
for (let i = index - 1; i >= 0; i--) {
|
|
515
|
+
if (!this.shouldVisit(nodes[i]))
|
|
516
|
+
continue;
|
|
517
|
+
if (isValidPrecedingNode(nodes[i], this.file)) {
|
|
518
|
+
validIndex = i;
|
|
519
|
+
this.rightmostValid = nodes[i];
|
|
520
|
+
break;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
for (let i = validIndex + 1; i < index; i++)
|
|
524
|
+
if (this.shouldVisit(nodes[i]))
|
|
525
|
+
this.rightmostVisited.push(nodes[i]);
|
|
526
|
+
return false;
|
|
527
|
+
}
|
|
528
|
+
visitModifiers(list) {
|
|
529
|
+
return this.visitList(list);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* The rightmost valid token in `[containingNode.pos, endPos)`; with `position` >= 0, the
|
|
534
|
+
* rightmost one that precedes or touches it.
|
|
535
|
+
*/
|
|
536
|
+
function findRightmostValidToken(endPos, file, containingNode, position, excludeJSDoc) {
|
|
537
|
+
if (position === -1)
|
|
538
|
+
position = containingNode.end;
|
|
539
|
+
let n = containingNode;
|
|
540
|
+
while (n !== undefined) {
|
|
541
|
+
if (isNonWhitespaceToken(n))
|
|
542
|
+
return n;
|
|
543
|
+
const visitor = new RightmostChildVisitor(file, endPos, position, excludeJSDoc);
|
|
544
|
+
visitChildrenAndJSDoc(n, file, visitor);
|
|
545
|
+
const rightmostValid = visitor.rightmostValid;
|
|
546
|
+
// The answer may be an unvisited token after the rightmost valid child. JSDoc nodes
|
|
547
|
+
// don't have trivia tokens.
|
|
548
|
+
if (!shouldSkipChild(n)) {
|
|
549
|
+
let startPos = rightmostValid !== undefined ? rightmostValid.end : n.pos;
|
|
550
|
+
const scanner = getScannerAt(file, startPos);
|
|
551
|
+
const tokens = [];
|
|
552
|
+
const visited = visitor.rightmostVisited;
|
|
553
|
+
for (let i = 0; i < visited.length; i++) {
|
|
554
|
+
const visitedNode = visited[i];
|
|
555
|
+
// Tokens before this child.
|
|
556
|
+
while (startPos < Math.min(visitedNode.pos, position)) {
|
|
557
|
+
const token = scanNavigationToken(scanner, n);
|
|
558
|
+
if (scanner.getTokenStart() >= position)
|
|
559
|
+
break;
|
|
560
|
+
const tokenEnd = scanner.getTokenEnd();
|
|
561
|
+
tokens.push(createToken(token, scanner.getTokenFullStart(), tokenEnd, n));
|
|
562
|
+
startPos = tokenEnd;
|
|
563
|
+
scanner.scan();
|
|
564
|
+
}
|
|
565
|
+
startPos = visitedNode.end;
|
|
566
|
+
scanner.resetPos(startPos);
|
|
567
|
+
scanner.scan();
|
|
568
|
+
}
|
|
569
|
+
// Tokens after the last visited child.
|
|
570
|
+
while (startPos < Math.min(endPos, position)) {
|
|
571
|
+
const token = scanNavigationToken(scanner, n);
|
|
572
|
+
if (scanner.getTokenStart() >= position)
|
|
573
|
+
break;
|
|
574
|
+
const tokenEnd = scanner.getTokenEnd();
|
|
575
|
+
tokens.push(createToken(token, scanner.getTokenFullStart(), tokenEnd, n));
|
|
576
|
+
startPos = tokenEnd;
|
|
577
|
+
scanner.scan();
|
|
578
|
+
}
|
|
579
|
+
for (let i = tokens.length - 1; i >= 0; i--)
|
|
580
|
+
if (!isWhitespaceOnlyJsxText(tokens[i]))
|
|
581
|
+
return tokens[i];
|
|
582
|
+
}
|
|
583
|
+
// A childless node without tokens is the answer itself.
|
|
584
|
+
if (!visitor.hasChildren)
|
|
585
|
+
return n !== containingNode ? n : undefined;
|
|
586
|
+
// Otherwise the answer is in the rightmost valid child.
|
|
587
|
+
if (rightmostValid !== undefined)
|
|
588
|
+
endPos = rightmostValid.end;
|
|
589
|
+
n = rightmostValid;
|
|
590
|
+
}
|
|
591
|
+
return undefined;
|
|
592
|
+
}
|
|
593
|
+
/** The token at `position`, counting leading trivia as part of the token that follows it. */
|
|
594
|
+
export function getTokenAtPosition(file, position) {
|
|
595
|
+
return findTokenAtPosition(file, position, true, false);
|
|
596
|
+
}
|
|
597
|
+
/** Like `findPrecedingToken`, searching from `startNode`. */
|
|
598
|
+
export function findPrecedingTokenEx(file, position, startNode, excludeJSDoc) {
|
|
599
|
+
return findPrecedingTokenIn(file, position, startNode ?? file, excludeJSDoc);
|
|
600
|
+
}
|
|
601
|
+
/** The start of a node's first token. */
|
|
602
|
+
export function getStartOfNode(node, file, includeJSDoc) {
|
|
603
|
+
return getTokenPosOfNode(node, file, includeJSDoc);
|
|
604
|
+
}
|
|
605
|
+
// Collects the children of a node, skipping reparsed nodes and lone JSDoc comments.
|
|
606
|
+
class ChildListVisitor extends NodeVisitor {
|
|
607
|
+
children = [];
|
|
608
|
+
visitNode(node) {
|
|
609
|
+
if (!isReparsed(node) && !isSingleCommentNode(node))
|
|
610
|
+
this.children.push(node);
|
|
611
|
+
return false;
|
|
612
|
+
}
|
|
613
|
+
visitList(list) {
|
|
614
|
+
if (isSingleCommentList(list))
|
|
615
|
+
return false;
|
|
616
|
+
const nodes = list.nodes;
|
|
617
|
+
for (let i = 0; i < nodes.length; i++)
|
|
618
|
+
if (!isReparsed(nodes[i]))
|
|
619
|
+
this.children.push(nodes[i]);
|
|
620
|
+
return false;
|
|
621
|
+
}
|
|
622
|
+
visitModifiers(list) {
|
|
623
|
+
return this.visitList(list);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
/** The JSDoc and children of a node that navigation visits, in order. */
|
|
627
|
+
export function getVisitedChildren(node, file) {
|
|
628
|
+
const visitor = new ChildListVisitor();
|
|
629
|
+
visitChildrenAndJSDoc(node, file, visitor);
|
|
630
|
+
return visitor.children;
|
|
631
|
+
}
|
|
632
|
+
/** The last visited child of a node; tokens the parser doesn't store aren't included. */
|
|
633
|
+
export function getLastVisitedChild(node, file) {
|
|
634
|
+
const children = getVisitedChildren(node, file);
|
|
635
|
+
return children.length > 0 ? children[children.length - 1] : undefined;
|
|
636
|
+
}
|
|
637
|
+
/** The last child of a node, including tokens the parser doesn't store. */
|
|
638
|
+
export function getLastChild(node, file) {
|
|
639
|
+
const lastChildNode = getLastVisitedChild(node, file);
|
|
640
|
+
if (lastChildNode === undefined && isSingleCommentNode(node))
|
|
641
|
+
return undefined;
|
|
642
|
+
const tokenStartPos = lastChildNode !== undefined ? lastChildNode.end : node.pos;
|
|
643
|
+
let lastToken;
|
|
644
|
+
if (tokenStartPos < node.end) {
|
|
645
|
+
const scanner = getScannerAt(file, tokenStartPos);
|
|
646
|
+
for (let startPos = tokenStartPos; startPos < node.end;) {
|
|
647
|
+
const tokenEnd = scanner.getTokenEnd();
|
|
648
|
+
lastToken = createToken(scanner.getToken(), scanner.getTokenFullStart(), tokenEnd, node);
|
|
649
|
+
startPos = tokenEnd;
|
|
650
|
+
scanner.scan();
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
return lastToken ?? lastChildNode;
|
|
654
|
+
}
|
|
655
|
+
/** The last token of a node; undefined for tokens and identifiers. */
|
|
656
|
+
export function getLastToken(node, file) {
|
|
657
|
+
if (node === undefined || isTokenKind(node.kind))
|
|
658
|
+
return undefined;
|
|
659
|
+
const lastChild = getLastChild(node, file);
|
|
660
|
+
if (lastChild === undefined)
|
|
661
|
+
return undefined;
|
|
662
|
+
return isTokenKind(lastChild.kind) ? lastChild : getLastToken(lastChild, file);
|
|
663
|
+
}
|
|
664
|
+
// Finds the first child of a node.
|
|
665
|
+
class FirstChildVisitor extends NodeVisitor {
|
|
666
|
+
first = undefined;
|
|
667
|
+
visitNode(node) {
|
|
668
|
+
this.first = node;
|
|
669
|
+
return true;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
/** The first token of a node; undefined for tokens and identifiers. */
|
|
673
|
+
export function getFirstToken(node, file) {
|
|
674
|
+
if (isTokenKind(node.kind))
|
|
675
|
+
return undefined;
|
|
676
|
+
const visitor = new FirstChildVisitor();
|
|
677
|
+
if ((node.flags & 8 /* NodeFlags.Reparsed */) === 0)
|
|
678
|
+
node.forEachChild(visitor);
|
|
679
|
+
const firstChild = visitor.first;
|
|
680
|
+
const tokenEndPosition = firstChild !== undefined ? firstChild.pos : node.end;
|
|
681
|
+
if (node.pos < tokenEndPosition) {
|
|
682
|
+
const scanner = getScannerAt(file, node.pos);
|
|
683
|
+
return createToken(scanner.getToken(), scanner.getTokenFullStart(), scanner.getTokenEnd(), node);
|
|
684
|
+
}
|
|
685
|
+
if (firstChild === undefined)
|
|
686
|
+
return undefined;
|
|
687
|
+
return isTokenKind(firstChild.kind) ? firstChild : getFirstToken(firstChild, file);
|
|
688
|
+
}
|
|
689
|
+
// Collects a node's children without filtering, for scanning the tokens between them.
|
|
690
|
+
class AllChildrenVisitor extends NodeVisitor {
|
|
691
|
+
children = [];
|
|
692
|
+
visitNode(node) {
|
|
693
|
+
this.children.push(node);
|
|
694
|
+
return false;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
/** The first child or token of `kind` in a node. */
|
|
698
|
+
export function findChildOfKind(containingNode, kind, file) {
|
|
699
|
+
let lastNodePos = containingNode.pos;
|
|
700
|
+
const scanner = getScannerAt(file, lastNodePos);
|
|
701
|
+
const visitor = new AllChildrenVisitor();
|
|
702
|
+
const jsDoc = getJSDoc(file, containingNode);
|
|
703
|
+
for (let i = 0; i < jsDoc.length; i++)
|
|
704
|
+
visitor.children.push(jsDoc[i]);
|
|
705
|
+
containingNode.forEachChild(visitor);
|
|
706
|
+
const children = visitor.children;
|
|
707
|
+
for (let i = 0; i < children.length; i++) {
|
|
708
|
+
const node = children[i];
|
|
709
|
+
if (isReparsed(node))
|
|
710
|
+
continue;
|
|
711
|
+
for (let startPos = lastNodePos; startPos < node.pos;) {
|
|
712
|
+
const tokenEnd = scanner.getTokenEnd();
|
|
713
|
+
if (scanner.getToken() === kind)
|
|
714
|
+
return createToken(kind, scanner.getTokenFullStart(), tokenEnd, containingNode);
|
|
715
|
+
startPos = tokenEnd;
|
|
716
|
+
scanner.scan();
|
|
717
|
+
}
|
|
718
|
+
if (node.kind === kind)
|
|
719
|
+
return node;
|
|
720
|
+
lastNodePos = node.end;
|
|
721
|
+
scanner.resetTokenState(lastNodePos);
|
|
722
|
+
scanner.scan();
|
|
723
|
+
}
|
|
724
|
+
for (let startPos = lastNodePos; startPos < containingNode.end;) {
|
|
725
|
+
const tokenEnd = scanner.getTokenEnd();
|
|
726
|
+
if (scanner.getToken() === kind)
|
|
727
|
+
return createToken(kind, scanner.getTokenFullStart(), tokenEnd, containingNode);
|
|
728
|
+
startPos = tokenEnd;
|
|
729
|
+
scanner.scan();
|
|
730
|
+
}
|
|
731
|
+
return undefined;
|
|
732
|
+
}
|
|
733
|
+
/** The nodes of a list and the tokens between them, such as separating commas. */
|
|
734
|
+
export function getTokensOfNodeList(list, parent, file) {
|
|
735
|
+
const tokens = [];
|
|
736
|
+
const nodes = list.nodes;
|
|
737
|
+
let left = list.pos;
|
|
738
|
+
let index = 0;
|
|
739
|
+
while (left < list.end) {
|
|
740
|
+
if (index < nodes.length && left === nodes[index].pos) {
|
|
741
|
+
tokens.push(nodes[index]);
|
|
742
|
+
left = nodes[index].end;
|
|
743
|
+
index++;
|
|
744
|
+
}
|
|
745
|
+
else {
|
|
746
|
+
const scanner = getScannerAt(file, left);
|
|
747
|
+
const tokenEnd = scanner.getTokenEnd();
|
|
748
|
+
tokens.push(createToken(scanner.getToken(), scanner.getTokenFullStart(), tokenEnd, parent));
|
|
749
|
+
left = tokenEnd;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
return tokens;
|
|
753
|
+
}
|
|
754
|
+
/** The tokens in `[startPos, endPos)` of `parent`'s text, made from the scanner. */
|
|
755
|
+
export function scanTokens(parent, startPos, endPos, file) {
|
|
756
|
+
const tokens = [];
|
|
757
|
+
if (startPos >= endPos)
|
|
758
|
+
return tokens;
|
|
759
|
+
const scanner = getScannerAt(file, startPos);
|
|
760
|
+
for (let pos = startPos; pos < endPos;) {
|
|
761
|
+
const tokenEnd = scanner.getTokenEnd();
|
|
762
|
+
tokens.push(createToken(scanner.getToken(), scanner.getTokenFullStart(), tokenEnd, parent));
|
|
763
|
+
pos = tokenEnd;
|
|
764
|
+
scanner.scan();
|
|
765
|
+
}
|
|
766
|
+
return tokens;
|
|
767
|
+
}
|