tsc-ts 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -0
- package/dist/api/compiler/ast-utilities.d.ts +82 -0
- package/dist/api/compiler/ast-utilities.js +462 -0
- package/dist/api/compiler/ast.d.ts +2350 -0
- package/dist/api/compiler/ast.js +11206 -0
- package/dist/api/compiler/astnav.d.ts +37 -0
- package/dist/api/compiler/astnav.js +767 -0
- package/dist/api/compiler/binder-utilities.d.ts +182 -0
- package/dist/api/compiler/binder-utilities.js +1240 -0
- package/dist/api/compiler/binder.d.ts +33 -0
- package/dist/api/compiler/binder.js +2358 -0
- package/dist/api/compiler/character-codes.d.ts +161 -0
- package/dist/api/compiler/character-codes.js +160 -0
- package/dist/api/compiler/checker-calls.d.ts +46 -0
- package/dist/api/compiler/checker-calls.js +1640 -0
- package/dist/api/compiler/checker-classes.d.ts +30 -0
- package/dist/api/compiler/checker-classes.js +582 -0
- package/dist/api/compiler/checker-contextual.d.ts +77 -0
- package/dist/api/compiler/checker-contextual.js +1136 -0
- package/dist/api/compiler/checker-declaration-order.d.ts +12 -0
- package/dist/api/compiler/checker-declaration-order.js +356 -0
- package/dist/api/compiler/checker-declarations.d.ts +33 -0
- package/dist/api/compiler/checker-declarations.js +888 -0
- package/dist/api/compiler/checker-declared-types.d.ts +48 -0
- package/dist/api/compiler/checker-declared-types.js +787 -0
- package/dist/api/compiler/checker-decorators.d.ts +26 -0
- package/dist/api/compiler/checker-decorators.js +562 -0
- package/dist/api/compiler/checker-deprecation.d.ts +33 -0
- package/dist/api/compiler/checker-deprecation.js +315 -0
- package/dist/api/compiler/checker-destructuring.d.ts +34 -0
- package/dist/api/compiler/checker-destructuring.js +584 -0
- package/dist/api/compiler/checker-elaboration.d.ts +15 -0
- package/dist/api/compiler/checker-elaboration.js +290 -0
- package/dist/api/compiler/checker-emit-helpers.d.ts +58 -0
- package/dist/api/compiler/checker-emit-helpers.js +154 -0
- package/dist/api/compiler/checker-emit-resolver.d.ts +75 -0
- package/dist/api/compiler/checker-emit-resolver.js +579 -0
- package/dist/api/compiler/checker-evaluator.d.ts +27 -0
- package/dist/api/compiler/checker-evaluator.js +188 -0
- package/dist/api/compiler/checker-expressions.d.ts +67 -0
- package/dist/api/compiler/checker-expressions.js +1351 -0
- package/dist/api/compiler/checker-features.d.ts +6 -0
- package/dist/api/compiler/checker-features.js +354 -0
- package/dist/api/compiler/checker-flow.d.ts +86 -0
- package/dist/api/compiler/checker-flow.js +169 -0
- package/dist/api/compiler/checker-functions.d.ts +43 -0
- package/dist/api/compiler/checker-functions.js +1002 -0
- package/dist/api/compiler/checker-generated-code.d.ts +25 -0
- package/dist/api/compiler/checker-generated-code.js +168 -0
- package/dist/api/compiler/checker-globals.d.ts +14 -0
- package/dist/api/compiler/checker-globals.js +37 -0
- package/dist/api/compiler/checker-grammar.d.ts +35 -0
- package/dist/api/compiler/checker-grammar.js +2573 -0
- package/dist/api/compiler/checker-heritage.d.ts +28 -0
- package/dist/api/compiler/checker-heritage.js +900 -0
- package/dist/api/compiler/checker-inference.d.ts +179 -0
- package/dist/api/compiler/checker-inference.js +2105 -0
- package/dist/api/compiler/checker-iteration.d.ts +115 -0
- package/dist/api/compiler/checker-iteration.js +857 -0
- package/dist/api/compiler/checker-javascript.d.ts +42 -0
- package/dist/api/compiler/checker-javascript.js +441 -0
- package/dist/api/compiler/checker-jsdoc.d.ts +30 -0
- package/dist/api/compiler/checker-jsdoc.js +320 -0
- package/dist/api/compiler/checker-jsx.d.ts +94 -0
- package/dist/api/compiler/checker-jsx.js +1433 -0
- package/dist/api/compiler/checker-literals.d.ts +6 -0
- package/dist/api/compiler/checker-literals.js +43 -0
- package/dist/api/compiler/checker-members.d.ts +198 -0
- package/dist/api/compiler/checker-members.js +2126 -0
- package/dist/api/compiler/checker-modules.d.ts +85 -0
- package/dist/api/compiler/checker-modules.js +2141 -0
- package/dist/api/compiler/checker-narrowing.d.ts +120 -0
- package/dist/api/compiler/checker-narrowing.js +2797 -0
- package/dist/api/compiler/checker-object-literals.d.ts +14 -0
- package/dist/api/compiler/checker-object-literals.js +479 -0
- package/dist/api/compiler/checker-operators.d.ts +33 -0
- package/dist/api/compiler/checker-operators.js +1040 -0
- package/dist/api/compiler/checker-overloads.d.ts +7 -0
- package/dist/api/compiler/checker-overloads.js +270 -0
- package/dist/api/compiler/checker-property-access.d.ts +34 -0
- package/dist/api/compiler/checker-property-access.js +672 -0
- package/dist/api/compiler/checker-services.d.ts +49 -0
- package/dist/api/compiler/checker-services.js +995 -0
- package/dist/api/compiler/checker-signatures.d.ts +55 -0
- package/dist/api/compiler/checker-signatures.js +788 -0
- package/dist/api/compiler/checker-source-file.d.ts +27 -0
- package/dist/api/compiler/checker-source-file.js +619 -0
- package/dist/api/compiler/checker-statements.d.ts +18 -0
- package/dist/api/compiler/checker-statements.js +226 -0
- package/dist/api/compiler/checker-super.d.ts +13 -0
- package/dist/api/compiler/checker-super.js +241 -0
- package/dist/api/compiler/checker-symbol-types.d.ts +67 -0
- package/dist/api/compiler/checker-symbol-types.js +1885 -0
- package/dist/api/compiler/checker-symbols.d.ts +181 -0
- package/dist/api/compiler/checker-symbols.js +1782 -0
- package/dist/api/compiler/checker-type-factory.d.ts +142 -0
- package/dist/api/compiler/checker-type-factory.js +2501 -0
- package/dist/api/compiler/checker-type-nodes.d.ts +26 -0
- package/dist/api/compiler/checker-type-nodes.js +828 -0
- package/dist/api/compiler/checker-type-operators.d.ts +109 -0
- package/dist/api/compiler/checker-type-operators.js +1842 -0
- package/dist/api/compiler/checker-types.d.ts +1027 -0
- package/dist/api/compiler/checker-types.js +1697 -0
- package/dist/api/compiler/checker-unused.d.ts +19 -0
- package/dist/api/compiler/checker-unused.js +524 -0
- package/dist/api/compiler/checker-utilities.d.ts +33 -0
- package/dist/api/compiler/checker-utilities.js +141 -0
- package/dist/api/compiler/checker.d.ts +491 -0
- package/dist/api/compiler/checker.js +912 -0
- package/dist/api/compiler/command-line.d.ts +32 -0
- package/dist/api/compiler/command-line.js +383 -0
- package/dist/api/compiler/compile-program.d.ts +118 -0
- package/dist/api/compiler/compile-program.js +384 -0
- package/dist/api/compiler/diagnostic-locales.d.ts +22 -0
- package/dist/api/compiler/diagnostic-locales.js +64 -0
- package/dist/api/compiler/diagnostic-messages.d.ts +2166 -0
- package/dist/api/compiler/diagnostic-messages.js +184 -0
- package/dist/api/compiler/diagnostics.d.ts +167 -0
- package/dist/api/compiler/diagnostics.js +820 -0
- package/dist/api/compiler/emitter.d.ts +71 -0
- package/dist/api/compiler/emitter.js +327 -0
- package/dist/api/compiler/file-include.d.ts +117 -0
- package/dist/api/compiler/file-include.js +536 -0
- package/dist/api/compiler/file-loader.d.ts +261 -0
- package/dist/api/compiler/file-loader.js +1257 -0
- package/dist/api/compiler/file-system.d.ts +51 -0
- package/dist/api/compiler/file-system.js +132 -0
- package/dist/api/compiler/flow.d.ts +60 -0
- package/dist/api/compiler/flow.js +45 -0
- package/dist/api/compiler/instantiation.d.ts +74 -0
- package/dist/api/compiler/instantiation.js +799 -0
- package/dist/api/compiler/jsdoc.d.ts +75 -0
- package/dist/api/compiler/jsdoc.js +1229 -0
- package/dist/api/compiler/link-tables.d.ts +36 -0
- package/dist/api/compiler/link-tables.js +83 -0
- package/dist/api/compiler/locale-data.d.ts +24 -0
- package/dist/api/compiler/locale-data.js +183 -0
- package/dist/api/compiler/locale.d.ts +4 -0
- package/dist/api/compiler/locale.js +317 -0
- package/dist/api/compiler/locales/cs-CZ.d.ts +2 -0
- package/dist/api/compiler/locales/cs-CZ.js +3 -0
- package/dist/api/compiler/locales/de-DE.d.ts +2 -0
- package/dist/api/compiler/locales/de-DE.js +3 -0
- package/dist/api/compiler/locales/es-ES.d.ts +2 -0
- package/dist/api/compiler/locales/es-ES.js +3 -0
- package/dist/api/compiler/locales/fr-FR.d.ts +2 -0
- package/dist/api/compiler/locales/fr-FR.js +3 -0
- package/dist/api/compiler/locales/it-IT.d.ts +2 -0
- package/dist/api/compiler/locales/it-IT.js +3 -0
- package/dist/api/compiler/locales/ja-JP.d.ts +2 -0
- package/dist/api/compiler/locales/ja-JP.js +3 -0
- package/dist/api/compiler/locales/ko-KR.d.ts +2 -0
- package/dist/api/compiler/locales/ko-KR.js +3 -0
- package/dist/api/compiler/locales/pl-PL.d.ts +2 -0
- package/dist/api/compiler/locales/pl-PL.js +3 -0
- package/dist/api/compiler/locales/pt-BR.d.ts +2 -0
- package/dist/api/compiler/locales/pt-BR.js +3 -0
- package/dist/api/compiler/locales/ru-RU.d.ts +2 -0
- package/dist/api/compiler/locales/ru-RU.js +3 -0
- package/dist/api/compiler/locales/tr-TR.d.ts +2 -0
- package/dist/api/compiler/locales/tr-TR.js +3 -0
- package/dist/api/compiler/locales/zh-CN.d.ts +2 -0
- package/dist/api/compiler/locales/zh-CN.js +3 -0
- package/dist/api/compiler/locales/zh-TW.d.ts +2 -0
- package/dist/api/compiler/locales/zh-TW.js +3 -0
- package/dist/api/compiler/module-resolution-types.d.ts +83 -0
- package/dist/api/compiler/module-resolution-types.js +176 -0
- package/dist/api/compiler/module-resolution.d.ts +71 -0
- package/dist/api/compiler/module-resolution.js +1598 -0
- package/dist/api/compiler/module-specifiers.d.ts +64 -0
- package/dist/api/compiler/module-specifiers.js +1101 -0
- package/dist/api/compiler/name-resolver.d.ts +43 -0
- package/dist/api/compiler/name-resolver.js +509 -0
- package/dist/api/compiler/node-builder-names.d.ts +32 -0
- package/dist/api/compiler/node-builder-names.js +854 -0
- package/dist/api/compiler/node-builder-pseudo.d.ts +36 -0
- package/dist/api/compiler/node-builder-pseudo.js +744 -0
- package/dist/api/compiler/node-builder-reuse.d.ts +4 -0
- package/dist/api/compiler/node-builder-reuse.js +647 -0
- package/dist/api/compiler/node-builder.d.ts +270 -0
- package/dist/api/compiler/node-builder.js +2645 -0
- package/dist/api/compiler/option-declarations.d.ts +90 -0
- package/dist/api/compiler/option-declarations.js +1460 -0
- package/dist/api/compiler/options.d.ts +289 -0
- package/dist/api/compiler/options.js +1197 -0
- package/dist/api/compiler/output-paths.d.ts +42 -0
- package/dist/api/compiler/output-paths.js +195 -0
- package/dist/api/compiler/package-json.d.ts +175 -0
- package/dist/api/compiler/package-json.js +1015 -0
- package/dist/api/compiler/parallel-parse.d.ts +219 -0
- package/dist/api/compiler/parallel-parse.js +537 -0
- package/dist/api/compiler/parser.d.ts +587 -0
- package/dist/api/compiler/parser.js +6407 -0
- package/dist/api/compiler/path.d.ts +91 -0
- package/dist/api/compiler/path.js +705 -0
- package/dist/api/compiler/printer/async-helpers.d.ts +22 -0
- package/dist/api/compiler/printer/async-helpers.js +91 -0
- package/dist/api/compiler/printer/auto-generate.d.ts +13 -0
- package/dist/api/compiler/printer/auto-generate.js +20 -0
- package/dist/api/compiler/printer/decorator-helpers.d.ts +24 -0
- package/dist/api/compiler/printer/decorator-helpers.js +118 -0
- package/dist/api/compiler/printer/emit-context.d.ts +154 -0
- package/dist/api/compiler/printer/emit-context.js +576 -0
- package/dist/api/compiler/printer/emit-flags.d.ts +60 -0
- package/dist/api/compiler/printer/emit-flags.js +2 -0
- package/dist/api/compiler/printer/factory-base.d.ts +171 -0
- package/dist/api/compiler/printer/factory-base.js +1505 -0
- package/dist/api/compiler/printer/factory.d.ts +147 -0
- package/dist/api/compiler/printer/factory.js +542 -0
- package/dist/api/compiler/printer/helpers.d.ts +27 -0
- package/dist/api/compiler/printer/helpers.js +164 -0
- package/dist/api/compiler/printer/name-generator.d.ts +41 -0
- package/dist/api/compiler/printer/name-generator.js +283 -0
- package/dist/api/compiler/printer/printer.d.ts +411 -0
- package/dist/api/compiler/printer/printer.js +4517 -0
- package/dist/api/compiler/printer/text-writer.d.ts +46 -0
- package/dist/api/compiler/printer/text-writer.js +172 -0
- package/dist/api/compiler/printer/utilities.d.ts +82 -0
- package/dist/api/compiler/printer/utilities.js +817 -0
- package/dist/api/compiler/program-checker.d.ts +156 -0
- package/dist/api/compiler/program-checker.js +526 -0
- package/dist/api/compiler/program-utilities.d.ts +52 -0
- package/dist/api/compiler/program-utilities.js +365 -0
- package/dist/api/compiler/program.d.ts +180 -0
- package/dist/api/compiler/program.js +1011 -0
- package/dist/api/compiler/pseudo-bigint.d.ts +5 -0
- package/dist/api/compiler/pseudo-bigint.js +61 -0
- package/dist/api/compiler/regexp-checker.d.ts +38 -0
- package/dist/api/compiler/regexp-checker.js +942 -0
- package/dist/api/compiler/relations.d.ts +263 -0
- package/dist/api/compiler/relations.js +4002 -0
- package/dist/api/compiler/reparser.d.ts +48 -0
- package/dist/api/compiler/reparser.js +1323 -0
- package/dist/api/compiler/scanner.d.ts +256 -0
- package/dist/api/compiler/scanner.js +2853 -0
- package/dist/api/compiler/side-state.d.ts +16 -0
- package/dist/api/compiler/side-state.js +89 -0
- package/dist/api/compiler/sourcemap.d.ts +55 -0
- package/dist/api/compiler/sourcemap.js +340 -0
- package/dist/api/compiler/spelling.d.ts +14 -0
- package/dist/api/compiler/spelling.js +128 -0
- package/dist/api/compiler/symbol-accessibility.d.ts +57 -0
- package/dist/api/compiler/symbol-accessibility.js +894 -0
- package/dist/api/compiler/symbol.d.ts +240 -0
- package/dist/api/compiler/symbol.js +228 -0
- package/dist/api/compiler/symlinks.d.ts +32 -0
- package/dist/api/compiler/symlinks.js +114 -0
- package/dist/api/compiler/syntax-kind.d.ts +389 -0
- package/dist/api/compiler/syntax-kind.js +2 -0
- package/dist/api/compiler/timeline.d.ts +9 -0
- package/dist/api/compiler/timeline.js +54 -0
- package/dist/api/compiler/transformers/alias-references.d.ts +39 -0
- package/dist/api/compiler/transformers/alias-references.js +676 -0
- package/dist/api/compiler/transformers/async-utilities.d.ts +51 -0
- package/dist/api/compiler/transformers/async-utilities.js +260 -0
- package/dist/api/compiler/transformers/async.d.ts +53 -0
- package/dist/api/compiler/transformers/async.js +645 -0
- package/dist/api/compiler/transformers/class-fields.d.ts +206 -0
- package/dist/api/compiler/transformers/class-fields.js +2418 -0
- package/dist/api/compiler/transformers/class-utilities.d.ts +46 -0
- package/dist/api/compiler/transformers/class-utilities.js +261 -0
- package/dist/api/compiler/transformers/commonjs-module.d.ts +103 -0
- package/dist/api/compiler/transformers/commonjs-module.js +1180 -0
- package/dist/api/compiler/transformers/const-enum-inliner.d.ts +11 -0
- package/dist/api/compiler/transformers/const-enum-inliner.js +36 -0
- package/dist/api/compiler/transformers/declarations-diagnostics.d.ts +52 -0
- package/dist/api/compiler/transformers/declarations-diagnostics.js +538 -0
- package/dist/api/compiler/transformers/declarations-pseudo.d.ts +160 -0
- package/dist/api/compiler/transformers/declarations-pseudo.js +797 -0
- package/dist/api/compiler/transformers/declarations-resolver.d.ts +152 -0
- package/dist/api/compiler/transformers/declarations-resolver.js +35 -0
- package/dist/api/compiler/transformers/declarations-syntactic.d.ts +119 -0
- package/dist/api/compiler/transformers/declarations-syntactic.js +1582 -0
- package/dist/api/compiler/transformers/declarations-tracker.d.ts +46 -0
- package/dist/api/compiler/transformers/declarations-tracker.js +197 -0
- package/dist/api/compiler/transformers/declarations.d.ts +175 -0
- package/dist/api/compiler/transformers/declarations.js +2380 -0
- package/dist/api/compiler/transformers/decorator-metadata.d.ts +54 -0
- package/dist/api/compiler/transformers/decorator-metadata.js +554 -0
- package/dist/api/compiler/transformers/decorator-utilities.d.ts +38 -0
- package/dist/api/compiler/transformers/decorator-utilities.js +238 -0
- package/dist/api/compiler/transformers/destructuring.d.ts +25 -0
- package/dist/api/compiler/transformers/destructuring.js +626 -0
- package/dist/api/compiler/transformers/downlevel.d.ts +6 -0
- package/dist/api/compiler/transformers/downlevel.js +45 -0
- package/dist/api/compiler/transformers/emit-resolver.d.ts +61 -0
- package/dist/api/compiler/transformers/emit-resolver.js +197 -0
- package/dist/api/compiler/transformers/es-decorators.d.ts +118 -0
- package/dist/api/compiler/transformers/es-decorators.js +1901 -0
- package/dist/api/compiler/transformers/exponentiation.d.ts +11 -0
- package/dist/api/compiler/transformers/exponentiation.js +76 -0
- package/dist/api/compiler/transformers/external-module-info.d.ts +35 -0
- package/dist/api/compiler/transformers/external-module-info.js +351 -0
- package/dist/api/compiler/transformers/for-await.d.ts +43 -0
- package/dist/api/compiler/transformers/for-await.js +469 -0
- package/dist/api/compiler/transformers/import-elision.d.ts +16 -0
- package/dist/api/compiler/transformers/import-elision.js +124 -0
- package/dist/api/compiler/transformers/jsx-entities.d.ts +1 -0
- package/dist/api/compiler/transformers/jsx-entities.js +256 -0
- package/dist/api/compiler/transformers/jsx.d.ts +71 -0
- package/dist/api/compiler/transformers/jsx.js +700 -0
- package/dist/api/compiler/transformers/legacy-decorators.d.ts +56 -0
- package/dist/api/compiler/transformers/legacy-decorators.js +564 -0
- package/dist/api/compiler/transformers/logical-assignment.d.ts +14 -0
- package/dist/api/compiler/transformers/logical-assignment.js +62 -0
- package/dist/api/compiler/transformers/module-utilities.d.ts +9 -0
- package/dist/api/compiler/transformers/module-utilities.js +36 -0
- package/dist/api/compiler/transformers/module.d.ts +49 -0
- package/dist/api/compiler/transformers/module.js +296 -0
- package/dist/api/compiler/transformers/named-evaluation.d.ts +26 -0
- package/dist/api/compiler/transformers/named-evaluation.js +266 -0
- package/dist/api/compiler/transformers/nullish-coalescing.d.ts +9 -0
- package/dist/api/compiler/transformers/nullish-coalescing.js +26 -0
- package/dist/api/compiler/transformers/object-rest-spread.d.ts +34 -0
- package/dist/api/compiler/transformers/object-rest-spread.js +411 -0
- package/dist/api/compiler/transformers/optional-catch.d.ts +9 -0
- package/dist/api/compiler/transformers/optional-catch.js +20 -0
- package/dist/api/compiler/transformers/optional-chain.d.ts +14 -0
- package/dist/api/compiler/transformers/optional-chain.js +188 -0
- package/dist/api/compiler/transformers/reference-resolver.d.ts +128 -0
- package/dist/api/compiler/transformers/reference-resolver.js +1155 -0
- package/dist/api/compiler/transformers/runtime-syntax.d.ts +71 -0
- package/dist/api/compiler/transformers/runtime-syntax.js +753 -0
- package/dist/api/compiler/transformers/subtree-facts.d.ts +9 -0
- package/dist/api/compiler/transformers/subtree-facts.js +203 -0
- package/dist/api/compiler/transformers/syntax-facts.d.ts +51 -0
- package/dist/api/compiler/transformers/syntax-facts.js +254 -0
- package/dist/api/compiler/transformers/tagged-template.d.ts +17 -0
- package/dist/api/compiler/transformers/tagged-template.js +148 -0
- package/dist/api/compiler/transformers/transformer.d.ts +17 -0
- package/dist/api/compiler/transformers/transformer.js +54 -0
- package/dist/api/compiler/transformers/type-eraser.d.ts +21 -0
- package/dist/api/compiler/transformers/type-eraser.js +346 -0
- package/dist/api/compiler/transformers/type-serialization.d.ts +20 -0
- package/dist/api/compiler/transformers/type-serialization.js +347 -0
- package/dist/api/compiler/transformers/using.d.ts +56 -0
- package/dist/api/compiler/transformers/using.js +453 -0
- package/dist/api/compiler/transformers/utilities.d.ts +50 -0
- package/dist/api/compiler/transformers/utilities.js +347 -0
- package/dist/api/compiler/transformers/visitor-base.d.ts +6 -0
- package/dist/api/compiler/transformers/visitor-base.js +817 -0
- package/dist/api/compiler/transformers/visitor-hooks.d.ts +29 -0
- package/dist/api/compiler/transformers/visitor-hooks.js +189 -0
- package/dist/api/compiler/tsconfig.d.ts +177 -0
- package/dist/api/compiler/tsconfig.js +1311 -0
- package/dist/api/compiler/type-printer.d.ts +15 -0
- package/dist/api/compiler/type-printer.js +74 -0
- package/dist/api/compiler/types.d.ts +87 -0
- package/dist/api/compiler/types.js +23 -0
- package/dist/api/compiler/unicode-identifiers.d.ts +2 -0
- package/dist/api/compiler/unicode-identifiers.js +209 -0
- package/dist/api/compiler/unicode-properties.d.ts +8 -0
- package/dist/api/compiler/unicode-properties.js +531 -0
- package/dist/api/compiler/vfs-match.d.ts +24 -0
- package/dist/api/compiler/vfs-match.js +587 -0
- package/dist/api/library/ast.d.ts +74 -0
- package/dist/api/library/ast.generated.d.ts +1145 -0
- package/dist/api/library/ast.generated.js +3 -0
- package/dist/api/library/ast.js +5 -0
- package/dist/api/library/checker.d.ts +51 -0
- package/dist/api/library/checker.js +318 -0
- package/dist/api/library/compiler-options.generated.d.ts +108 -0
- package/dist/api/library/compiler-options.generated.js +3 -0
- package/dist/api/library/diagnostics.d.ts +13 -0
- package/dist/api/library/diagnostics.js +50 -0
- package/dist/api/library/disk.d.ts +13 -0
- package/dist/api/library/disk.js +66 -0
- package/dist/api/library/enums.generated.d.ts +891 -0
- package/dist/api/library/enums.generated.js +916 -0
- package/dist/api/library/errors.d.ts +13 -0
- package/dist/api/library/errors.js +24 -0
- package/dist/api/library/host.d.ts +24 -0
- package/dist/api/library/host.js +52 -0
- package/dist/api/library/index.d.ts +14 -0
- package/dist/api/library/index.js +15 -0
- package/dist/api/library/nodes.d.ts +51 -0
- package/dist/api/library/nodes.js +196 -0
- package/dist/api/library/options.d.ts +144 -0
- package/dist/api/library/options.js +308 -0
- package/dist/api/library/parse.d.ts +19 -0
- package/dist/api/library/parse.js +41 -0
- package/dist/api/library/program.d.ts +21 -0
- package/dist/api/library/program.js +234 -0
- package/dist/api/library/symbols.d.ts +8 -0
- package/dist/api/library/symbols.js +11 -0
- package/dist/api/library/types.d.ts +313 -0
- package/dist/api/library/types.js +6 -0
- package/package.json +22 -8
- package/src/compiler/ast-utilities.ts +548 -0
- package/src/compiler/ast.ts +12862 -0
- package/src/compiler/astnav.ts +799 -0
- package/src/compiler/binder-utilities.ts +1392 -0
- package/src/compiler/binder.ts +2703 -0
- package/src/compiler/build-info.ts +1197 -0
- package/src/compiler/character-codes.ts +323 -0
- package/src/compiler/checker-calls.ts +2155 -0
- package/src/compiler/checker-classes.ts +706 -0
- package/src/compiler/checker-contextual.ts +1457 -0
- package/src/compiler/checker-declaration-order.ts +438 -0
- package/src/compiler/checker-declarations.ts +1194 -0
- package/src/compiler/checker-declared-types.ts +919 -0
- package/src/compiler/checker-decorators.ts +694 -0
- package/src/compiler/checker-deprecation.ts +359 -0
- package/src/compiler/checker-destructuring.ts +805 -0
- package/src/compiler/checker-elaboration.ts +477 -0
- package/src/compiler/checker-emit-helpers.ts +224 -0
- package/src/compiler/checker-emit-resolver.ts +769 -0
- package/src/compiler/checker-evaluator.ts +243 -0
- package/src/compiler/checker-expressions.ts +1831 -0
- package/src/compiler/checker-features.ts +361 -0
- package/src/compiler/checker-flow.ts +394 -0
- package/src/compiler/checker-functions.ts +1296 -0
- package/src/compiler/checker-generated-code.ts +227 -0
- package/src/compiler/checker-globals.ts +52 -0
- package/src/compiler/checker-grammar.ts +3584 -0
- package/src/compiler/checker-heritage.ts +1233 -0
- package/src/compiler/checker-inference.ts +2576 -0
- package/src/compiler/checker-iteration.ts +1206 -0
- package/src/compiler/checker-javascript.ts +502 -0
- package/src/compiler/checker-jsdoc.ts +360 -0
- package/src/compiler/checker-jsx.ts +1924 -0
- package/src/compiler/checker-literals.ts +61 -0
- package/src/compiler/checker-members.ts +2436 -0
- package/src/compiler/checker-modules.ts +2886 -0
- package/src/compiler/checker-narrowing.ts +3230 -0
- package/src/compiler/checker-object-literals.ts +575 -0
- package/src/compiler/checker-operators.ts +1422 -0
- package/src/compiler/checker-overloads.ts +328 -0
- package/src/compiler/checker-property-access.ts +906 -0
- package/src/compiler/checker-services.ts +1149 -0
- package/src/compiler/checker-signatures.ts +1032 -0
- package/src/compiler/checker-source-file.ts +732 -0
- package/src/compiler/checker-statements.ts +292 -0
- package/src/compiler/checker-super.ts +261 -0
- package/src/compiler/checker-symbol-types.ts +2107 -0
- package/src/compiler/checker-symbols.ts +2150 -0
- package/src/compiler/checker-type-factory.ts +2579 -0
- package/src/compiler/checker-type-nodes.ts +1033 -0
- package/src/compiler/checker-type-operators.ts +2502 -0
- package/src/compiler/checker-types.ts +2340 -0
- package/src/compiler/checker-unused.ts +642 -0
- package/src/compiler/checker-utilities.ts +161 -0
- package/src/compiler/checker.ts +1116 -0
- package/src/compiler/command-line.ts +436 -0
- package/src/compiler/compile-program.ts +439 -0
- package/src/compiler/decoder.ts +1209 -0
- package/src/compiler/diagnostic-locales.ts +86 -0
- package/src/compiler/diagnostic-messages.ts +2349 -0
- package/src/compiler/diagnostics.ts +897 -0
- package/src/compiler/emitter.ts +434 -0
- package/src/compiler/encoder.ts +1945 -0
- package/src/compiler/file-include.ts +673 -0
- package/src/compiler/file-loader.ts +1528 -0
- package/src/compiler/file-system.ts +143 -0
- package/src/compiler/flow.ts +89 -0
- package/src/compiler/help.ts +473 -0
- package/src/compiler/incremental.ts +2784 -0
- package/src/compiler/init.ts +141 -0
- package/src/compiler/instantiation.ts +894 -0
- package/src/compiler/jsdoc.ts +1386 -0
- package/src/compiler/link-tables.ts +98 -0
- package/src/compiler/locale-data.ts +203 -0
- package/src/compiler/locale.ts +307 -0
- package/src/compiler/locales/cs-CZ.ts +5 -0
- package/src/compiler/locales/de-DE.ts +5 -0
- package/src/compiler/locales/es-ES.ts +5 -0
- package/src/compiler/locales/fr-FR.ts +5 -0
- package/src/compiler/locales/it-IT.ts +5 -0
- package/src/compiler/locales/ja-JP.ts +5 -0
- package/src/compiler/locales/ko-KR.ts +5 -0
- package/src/compiler/locales/pl-PL.ts +5 -0
- package/src/compiler/locales/pt-BR.ts +5 -0
- package/src/compiler/locales/ru-RU.ts +5 -0
- package/src/compiler/locales/tr-TR.ts +5 -0
- package/src/compiler/locales/zh-CN.ts +5 -0
- package/src/compiler/locales/zh-TW.ts +5 -0
- package/src/compiler/module-resolution-types.ts +243 -0
- package/src/compiler/module-resolution.ts +2072 -0
- package/src/compiler/module-specifiers.ts +1491 -0
- package/src/compiler/name-resolver.ts +646 -0
- package/src/compiler/node-builder-names.ts +1069 -0
- package/src/compiler/node-builder-pseudo.ts +892 -0
- package/src/compiler/node-builder-reuse.ts +764 -0
- package/src/compiler/node-builder.ts +3425 -0
- package/src/compiler/option-declarations.ts +1560 -0
- package/src/compiler/options.ts +1576 -0
- package/src/compiler/output-paths.ts +334 -0
- package/src/compiler/package-json.ts +1083 -0
- package/src/compiler/parallel-check.ts +1951 -0
- package/src/compiler/parallel-parse.ts +590 -0
- package/src/compiler/parse-thread.ts +140 -0
- package/src/compiler/parser.ts +7716 -0
- package/src/compiler/path.ts +717 -0
- package/src/compiler/printer/async-helpers.ts +183 -0
- package/src/compiler/printer/auto-generate.ts +27 -0
- package/src/compiler/printer/decorator-helpers.ts +218 -0
- package/src/compiler/printer/emit-context.ts +679 -0
- package/src/compiler/printer/emit-flags.ts +64 -0
- package/src/compiler/printer/factory-base.ts +2577 -0
- package/src/compiler/printer/factory.ts +764 -0
- package/src/compiler/printer/helpers.ts +291 -0
- package/src/compiler/printer/name-generator.ts +372 -0
- package/src/compiler/printer/printer.ts +5072 -0
- package/src/compiler/printer/text-writer.ts +183 -0
- package/src/compiler/printer/utilities.ts +884 -0
- package/src/compiler/program-checker.ts +592 -0
- package/src/compiler/program-utilities.ts +435 -0
- package/src/compiler/program.ts +1419 -0
- package/src/compiler/pseudo-bigint.ts +62 -0
- package/src/compiler/regexp-checker.ts +1142 -0
- package/src/compiler/relations.ts +5149 -0
- package/src/compiler/reparser.ts +1566 -0
- package/src/compiler/scanner.ts +2951 -0
- package/src/compiler/show-config.ts +239 -0
- package/src/compiler/side-state.ts +125 -0
- package/src/compiler/sourcemap.ts +366 -0
- package/src/compiler/spelling.ts +122 -0
- package/src/compiler/symbol-accessibility.ts +1071 -0
- package/src/compiler/symbol.ts +439 -0
- package/src/compiler/symlinks.ts +137 -0
- package/src/compiler/syntax-kind.ts +391 -0
- package/src/compiler/thread-entry.ts +191 -0
- package/src/compiler/timeline.ts +53 -0
- package/src/compiler/transformers/alias-references.ts +757 -0
- package/src/compiler/transformers/async-utilities.ts +335 -0
- package/src/compiler/transformers/async.ts +838 -0
- package/src/compiler/transformers/class-fields.ts +2967 -0
- package/src/compiler/transformers/class-utilities.ts +324 -0
- package/src/compiler/transformers/commonjs-module.ts +1621 -0
- package/src/compiler/transformers/const-enum-inliner.ts +50 -0
- package/src/compiler/transformers/declarations-diagnostics.ts +832 -0
- package/src/compiler/transformers/declarations-pseudo.ts +966 -0
- package/src/compiler/transformers/declarations-resolver.ts +249 -0
- package/src/compiler/transformers/declarations-syntactic.ts +1859 -0
- package/src/compiler/transformers/declarations-tracker.ts +269 -0
- package/src/compiler/transformers/declarations.ts +3120 -0
- package/src/compiler/transformers/decorator-metadata.ts +697 -0
- package/src/compiler/transformers/decorator-utilities.ts +283 -0
- package/src/compiler/transformers/destructuring.ts +708 -0
- package/src/compiler/transformers/downlevel.ts +50 -0
- package/src/compiler/transformers/emit-resolver.ts +258 -0
- package/src/compiler/transformers/es-decorators.ts +2682 -0
- package/src/compiler/transformers/exponentiation.ts +80 -0
- package/src/compiler/transformers/external-module-info.ts +412 -0
- package/src/compiler/transformers/for-await.ts +687 -0
- package/src/compiler/transformers/import-elision.ts +152 -0
- package/src/compiler/transformers/jsx-entities.ts +256 -0
- package/src/compiler/transformers/jsx.ts +824 -0
- package/src/compiler/transformers/legacy-decorators.ts +726 -0
- package/src/compiler/transformers/logical-assignment.ts +75 -0
- package/src/compiler/transformers/module-utilities.ts +42 -0
- package/src/compiler/transformers/module.ts +474 -0
- package/src/compiler/transformers/named-evaluation.ts +389 -0
- package/src/compiler/transformers/nullish-coalescing.ts +35 -0
- package/src/compiler/transformers/object-rest-spread.ts +577 -0
- package/src/compiler/transformers/optional-catch.ts +29 -0
- package/src/compiler/transformers/optional-chain.ts +246 -0
- package/src/compiler/transformers/reference-resolver.ts +1201 -0
- package/src/compiler/transformers/runtime-syntax.ts +942 -0
- package/src/compiler/transformers/subtree-facts.ts +245 -0
- package/src/compiler/transformers/syntax-facts.ts +353 -0
- package/src/compiler/transformers/tagged-template.ts +167 -0
- package/src/compiler/transformers/transformer.ts +56 -0
- package/src/compiler/transformers/type-eraser.ts +520 -0
- package/src/compiler/transformers/type-serialization.ts +374 -0
- package/src/compiler/transformers/using.ts +613 -0
- package/src/compiler/transformers/utilities.ts +419 -0
- package/src/compiler/transformers/visitor-base.ts +1601 -0
- package/src/compiler/transformers/visitor-hooks.ts +252 -0
- package/src/compiler/tsc-build.ts +1418 -0
- package/src/compiler/tsc-cli.ts +666 -0
- package/src/compiler/tsc-compile.ts +437 -0
- package/src/compiler/tsc-watch.ts +854 -0
- package/src/compiler/tsconfig.ts +1574 -0
- package/src/compiler/type-printer.ts +110 -0
- package/src/compiler/types.ts +115 -0
- package/src/compiler/unicode-identifiers.ts +212 -0
- package/src/compiler/unicode-properties.ts +537 -0
- package/src/compiler/vfs-match.ts +597 -0
- package/src/compiler/xxh3.ts +650 -0
- package/src/library/ast.generated.ts +1685 -0
- package/src/library/ast.ts +104 -0
- package/src/library/checker.ts +384 -0
- package/src/library/compiler-options.generated.ts +114 -0
- package/src/library/diagnostics.ts +72 -0
- package/src/library/disk.ts +73 -0
- package/src/library/enums.generated.ts +1024 -0
- package/src/library/errors.ts +26 -0
- package/src/library/host.ts +63 -0
- package/src/library/index.ts +71 -0
- package/src/library/nodes.ts +232 -0
- package/src/library/options.ts +449 -0
- package/src/library/parse.ts +63 -0
- package/src/library/program.ts +293 -0
- package/src/library/symbols.ts +15 -0
- package/src/library/types.ts +359 -0
|
@@ -0,0 +1,1240 @@
|
|
|
1
|
+
// Syntax queries the binder, name resolver and checker share, ported from tsgo's ast and
|
|
2
|
+
// scanner utilities.
|
|
3
|
+
//
|
|
4
|
+
// Fields of `instanceof`-narrowed nodes are read through `as` casts: scriptc reads them
|
|
5
|
+
// statically, but reads fields of a narrowed value dynamically.
|
|
6
|
+
import { BinaryExpression, CallExpression, ElementAccessExpression, ExpressionStatement, Identifier, JSDoc, JSDocSatisfiesTag, JsxNamespacedName, MetaProperty, ModuleDeclaration, NodeVisitor, PrefixUnaryExpression, ParenthesizedExpression, PropertyAccessExpression, TaggedTemplateExpression, TypeReferenceNode, VariableDeclaration, VariableStatement, getArguments, getAsteriskToken, getBody, getElements, getExpression, getInitializer, getMembers, getModifiers, getName, getProperties, getPropertyName, getStatements, getTagName, getText, getType, } from './ast.js';
|
|
7
|
+
import { getJSDoc } from './parser.js';
|
|
8
|
+
import { isAssignmentOperator, isLeftHandSideExpression, isStringLiteralLike, nodeIsMissing } from './ast-utilities.js';
|
|
9
|
+
import { Scanner, computeLineOfPosition, skipTrivia } from './scanner.js';
|
|
10
|
+
// Modifiers and flags
|
|
11
|
+
export function getModifierFlags(node) {
|
|
12
|
+
const modifiers = getModifiers(node);
|
|
13
|
+
return modifiers === undefined ? 0 /* ModifierFlags.None */ : modifiers.modifierFlags;
|
|
14
|
+
}
|
|
15
|
+
export function hasSyntacticModifier(node, flags) {
|
|
16
|
+
return (getModifierFlags(node) & flags) !== 0;
|
|
17
|
+
}
|
|
18
|
+
export function hasStaticModifier(node) {
|
|
19
|
+
return hasSyntacticModifier(node, 256 /* ModifierFlags.Static */);
|
|
20
|
+
}
|
|
21
|
+
/** The declaration a binding element belongs to. */
|
|
22
|
+
export function getRootDeclaration(node) {
|
|
23
|
+
let current = node;
|
|
24
|
+
while (current.kind === 209 /* SyntaxKind.BindingElement */)
|
|
25
|
+
current = current.parent.parent;
|
|
26
|
+
return current;
|
|
27
|
+
}
|
|
28
|
+
/** Modifier flags of a variable declaration combined with its list's and statement's. */
|
|
29
|
+
export function getCombinedModifierFlags(node) {
|
|
30
|
+
// Locals stay non-optional: native builds box a `Node | undefined` local at every assignment.
|
|
31
|
+
let current = getRootDeclaration(node);
|
|
32
|
+
let flags = getModifierFlags(current);
|
|
33
|
+
if (current.kind === 261 /* SyntaxKind.VariableDeclaration */) {
|
|
34
|
+
const parent = current.parent;
|
|
35
|
+
if (parent === undefined)
|
|
36
|
+
return flags;
|
|
37
|
+
current = parent;
|
|
38
|
+
}
|
|
39
|
+
if (current.kind === 262 /* SyntaxKind.VariableDeclarationList */) {
|
|
40
|
+
flags |= getModifierFlags(current);
|
|
41
|
+
const parent = current.parent;
|
|
42
|
+
if (parent === undefined)
|
|
43
|
+
return flags;
|
|
44
|
+
current = parent;
|
|
45
|
+
}
|
|
46
|
+
if (current.kind === 244 /* SyntaxKind.VariableStatement */)
|
|
47
|
+
flags |= getModifierFlags(current);
|
|
48
|
+
return flags;
|
|
49
|
+
}
|
|
50
|
+
/** Node flags of a variable declaration combined with its list's and statement's. */
|
|
51
|
+
export function getCombinedNodeFlags(node) {
|
|
52
|
+
// Locals stay non-optional, as in getCombinedModifierFlags.
|
|
53
|
+
let current = getRootDeclaration(node);
|
|
54
|
+
let flags = current.flags;
|
|
55
|
+
if (current.kind === 261 /* SyntaxKind.VariableDeclaration */) {
|
|
56
|
+
const parent = current.parent;
|
|
57
|
+
if (parent === undefined)
|
|
58
|
+
return flags;
|
|
59
|
+
current = parent;
|
|
60
|
+
}
|
|
61
|
+
if (current.kind === 262 /* SyntaxKind.VariableDeclarationList */) {
|
|
62
|
+
flags |= current.flags;
|
|
63
|
+
const parent = current.parent;
|
|
64
|
+
if (parent === undefined)
|
|
65
|
+
return flags;
|
|
66
|
+
current = parent;
|
|
67
|
+
}
|
|
68
|
+
if (current.kind === 244 /* SyntaxKind.VariableStatement */)
|
|
69
|
+
flags |= current.flags;
|
|
70
|
+
return flags;
|
|
71
|
+
}
|
|
72
|
+
export function isEnumConst(node) {
|
|
73
|
+
return (getCombinedModifierFlags(node) & 4096 /* ModifierFlags.Const */) !== 0;
|
|
74
|
+
}
|
|
75
|
+
// Source files
|
|
76
|
+
export function isExternalModule(file) {
|
|
77
|
+
return file.externalModuleIndicator !== undefined;
|
|
78
|
+
}
|
|
79
|
+
export function isExternalOrCommonJSModule(file) {
|
|
80
|
+
return file.externalModuleIndicator !== undefined || file.commonJSModuleIndicator !== undefined;
|
|
81
|
+
}
|
|
82
|
+
export function isJsonSourceFile(file) {
|
|
83
|
+
return file.scriptKind === 6 /* ScriptKind.JSON */;
|
|
84
|
+
}
|
|
85
|
+
/** A source file whose declarations are global. */
|
|
86
|
+
export function isGlobalSourceFile(node) {
|
|
87
|
+
return node.kind === 307 /* SyntaxKind.SourceFile */ && !isExternalOrCommonJSModule(node);
|
|
88
|
+
}
|
|
89
|
+
export function getSourceFileOfNode(node) {
|
|
90
|
+
// Walks parents without rebinding `node`, which native builds would box at every step.
|
|
91
|
+
let parent = node.parent;
|
|
92
|
+
if (parent === undefined)
|
|
93
|
+
return node;
|
|
94
|
+
for (;;) {
|
|
95
|
+
const next = parent.parent;
|
|
96
|
+
if (next === undefined)
|
|
97
|
+
return parent;
|
|
98
|
+
parent = next;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// Kinds
|
|
102
|
+
export function isClassLike(node) {
|
|
103
|
+
return node.kind === 264 /* SyntaxKind.ClassDeclaration */ || node.kind === 232 /* SyntaxKind.ClassExpression */;
|
|
104
|
+
}
|
|
105
|
+
export function isClassElement(node) {
|
|
106
|
+
switch (node.kind) {
|
|
107
|
+
case 177 /* SyntaxKind.Constructor */:
|
|
108
|
+
case 173 /* SyntaxKind.PropertyDeclaration */:
|
|
109
|
+
case 175 /* SyntaxKind.MethodDeclaration */:
|
|
110
|
+
case 178 /* SyntaxKind.GetAccessor */:
|
|
111
|
+
case 179 /* SyntaxKind.SetAccessor */:
|
|
112
|
+
case 182 /* SyntaxKind.IndexSignature */:
|
|
113
|
+
case 176 /* SyntaxKind.ClassStaticBlockDeclaration */:
|
|
114
|
+
case 241 /* SyntaxKind.SemicolonClassElement */:
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
/** As the spec's IsStatic: a static class element or a static block. */
|
|
120
|
+
export function isStatic(node) {
|
|
121
|
+
return (isClassElement(node) && hasStaticModifier(node)) || node.kind === 176 /* SyntaxKind.ClassStaticBlockDeclaration */;
|
|
122
|
+
}
|
|
123
|
+
export function isDeclarationStatementKind(kind) {
|
|
124
|
+
switch (kind) {
|
|
125
|
+
case 263 /* SyntaxKind.FunctionDeclaration */:
|
|
126
|
+
case 283 /* SyntaxKind.MissingDeclaration */:
|
|
127
|
+
case 264 /* SyntaxKind.ClassDeclaration */:
|
|
128
|
+
case 265 /* SyntaxKind.InterfaceDeclaration */:
|
|
129
|
+
case 266 /* SyntaxKind.TypeAliasDeclaration */:
|
|
130
|
+
case 345 /* SyntaxKind.JSTypeAliasDeclaration */:
|
|
131
|
+
case 267 /* SyntaxKind.EnumDeclaration */:
|
|
132
|
+
case 268 /* SyntaxKind.ModuleDeclaration */:
|
|
133
|
+
case 273 /* SyntaxKind.ImportDeclaration */:
|
|
134
|
+
case 346 /* SyntaxKind.JSImportDeclaration */:
|
|
135
|
+
case 272 /* SyntaxKind.ImportEqualsDeclaration */:
|
|
136
|
+
case 279 /* SyntaxKind.ExportDeclaration */:
|
|
137
|
+
case 278 /* SyntaxKind.ExportAssignment */:
|
|
138
|
+
case 271 /* SyntaxKind.NamespaceExportDeclaration */:
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
export function isTypeNodeKind(kind) {
|
|
144
|
+
switch (kind) {
|
|
145
|
+
case 132 /* SyntaxKind.AnyKeyword */:
|
|
146
|
+
case 159 /* SyntaxKind.UnknownKeyword */:
|
|
147
|
+
case 150 /* SyntaxKind.NumberKeyword */:
|
|
148
|
+
case 163 /* SyntaxKind.BigIntKeyword */:
|
|
149
|
+
case 151 /* SyntaxKind.ObjectKeyword */:
|
|
150
|
+
case 135 /* SyntaxKind.BooleanKeyword */:
|
|
151
|
+
case 154 /* SyntaxKind.StringKeyword */:
|
|
152
|
+
case 155 /* SyntaxKind.SymbolKeyword */:
|
|
153
|
+
case 115 /* SyntaxKind.VoidKeyword */:
|
|
154
|
+
case 157 /* SyntaxKind.UndefinedKeyword */:
|
|
155
|
+
case 146 /* SyntaxKind.NeverKeyword */:
|
|
156
|
+
case 141 /* SyntaxKind.IntrinsicKeyword */:
|
|
157
|
+
case 234 /* SyntaxKind.ExpressionWithTypeArguments */:
|
|
158
|
+
case 310 /* SyntaxKind.JSDocAllType */:
|
|
159
|
+
case 311 /* SyntaxKind.JSDocNullableType */:
|
|
160
|
+
case 312 /* SyntaxKind.JSDocNonNullableType */:
|
|
161
|
+
case 313 /* SyntaxKind.JSDocOptionalType */:
|
|
162
|
+
case 314 /* SyntaxKind.JSDocVariadicType */:
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
return kind >= 183 /* SyntaxKind.FirstTypeNode */ && kind <= 206 /* SyntaxKind.LastTypeNode */;
|
|
166
|
+
}
|
|
167
|
+
export function isFunctionExpressionOrArrowFunction(node) {
|
|
168
|
+
return node.kind === 219 /* SyntaxKind.FunctionExpression */ || node.kind === 220 /* SyntaxKind.ArrowFunction */;
|
|
169
|
+
}
|
|
170
|
+
export function isMethodOrAccessor(node) {
|
|
171
|
+
switch (node.kind) {
|
|
172
|
+
case 175 /* SyntaxKind.MethodDeclaration */:
|
|
173
|
+
case 178 /* SyntaxKind.GetAccessor */:
|
|
174
|
+
case 179 /* SyntaxKind.SetAccessor */:
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
export function isObjectLiteralOrClassExpressionMethodOrAccessor(node) {
|
|
180
|
+
if (!isMethodOrAccessor(node))
|
|
181
|
+
return false;
|
|
182
|
+
const parentKind = node.parent.kind;
|
|
183
|
+
return parentKind === 211 /* SyntaxKind.ObjectLiteralExpression */ || parentKind === 232 /* SyntaxKind.ClassExpression */;
|
|
184
|
+
}
|
|
185
|
+
export function isObjectLiteralMethod(node) {
|
|
186
|
+
return (node !== undefined &&
|
|
187
|
+
node.kind === 175 /* SyntaxKind.MethodDeclaration */ &&
|
|
188
|
+
node.parent.kind === 211 /* SyntaxKind.ObjectLiteralExpression */);
|
|
189
|
+
}
|
|
190
|
+
export function isAutoAccessorPropertyDeclaration(node) {
|
|
191
|
+
return node.kind === 173 /* SyntaxKind.PropertyDeclaration */ && hasSyntacticModifier(node, 512 /* ModifierFlags.Accessor */);
|
|
192
|
+
}
|
|
193
|
+
export function isParameterPropertyDeclaration(node, parent) {
|
|
194
|
+
return (node.kind === 170 /* SyntaxKind.Parameter */ &&
|
|
195
|
+
hasSyntacticModifier(node, 31 /* ModifierFlags.ParameterPropertyModifier */) &&
|
|
196
|
+
parent.kind === 177 /* SyntaxKind.Constructor */);
|
|
197
|
+
}
|
|
198
|
+
export function isPrivateIdentifierClassElementDeclaration(node) {
|
|
199
|
+
if (node.kind !== 173 /* SyntaxKind.PropertyDeclaration */ && !isMethodOrAccessor(node))
|
|
200
|
+
return false;
|
|
201
|
+
const name = getName(node);
|
|
202
|
+
return name !== undefined && name.kind === 80 /* SyntaxKind.PrivateIdentifier */;
|
|
203
|
+
}
|
|
204
|
+
export function isAsyncFunction(node) {
|
|
205
|
+
switch (node.kind) {
|
|
206
|
+
case 263 /* SyntaxKind.FunctionDeclaration */:
|
|
207
|
+
case 219 /* SyntaxKind.FunctionExpression */:
|
|
208
|
+
case 220 /* SyntaxKind.ArrowFunction */:
|
|
209
|
+
case 175 /* SyntaxKind.MethodDeclaration */:
|
|
210
|
+
return (getBody(node) !== undefined &&
|
|
211
|
+
getAsteriskToken(node) === undefined &&
|
|
212
|
+
hasSyntacticModifier(node, 1024 /* ModifierFlags.Async */));
|
|
213
|
+
}
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
export function isStringOrNumericLiteralLike(node) {
|
|
217
|
+
return isStringLiteralLike(node) || node.kind === 8 /* SyntaxKind.NumericLiteral */;
|
|
218
|
+
}
|
|
219
|
+
export function isSignedNumericLiteral(node) {
|
|
220
|
+
return (node instanceof PrefixUnaryExpression &&
|
|
221
|
+
(node.operator === 39 /* SyntaxKind.PlusToken */ ||
|
|
222
|
+
node.operator === 40 /* SyntaxKind.MinusToken */) &&
|
|
223
|
+
node.operand.kind === 8 /* SyntaxKind.NumericLiteral */);
|
|
224
|
+
}
|
|
225
|
+
export function isPropertyNameLiteral(node) {
|
|
226
|
+
switch (node.kind) {
|
|
227
|
+
case 79 /* SyntaxKind.Identifier */:
|
|
228
|
+
case 10 /* SyntaxKind.StringLiteral */:
|
|
229
|
+
case 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */:
|
|
230
|
+
case 8 /* SyntaxKind.NumericLiteral */:
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
export function isBooleanLiteral(node) {
|
|
236
|
+
return node.kind === 111 /* SyntaxKind.TrueKeyword */ || node.kind === 96 /* SyntaxKind.FalseKeyword */;
|
|
237
|
+
}
|
|
238
|
+
export function isPrologueDirective(node) {
|
|
239
|
+
return (node instanceof ExpressionStatement && node.expression.kind === 10 /* SyntaxKind.StringLiteral */);
|
|
240
|
+
}
|
|
241
|
+
/** The text of an identifier, literal, meta property or JSX namespaced name. */
|
|
242
|
+
export function nodeText(node) {
|
|
243
|
+
if (node instanceof JsxNamespacedName) {
|
|
244
|
+
const namespaced = node;
|
|
245
|
+
return namespaced.namespace.text + ':' + namespaced.name.text;
|
|
246
|
+
}
|
|
247
|
+
if (node instanceof MetaProperty)
|
|
248
|
+
return node.name.text;
|
|
249
|
+
return getText(node);
|
|
250
|
+
}
|
|
251
|
+
export function isIdentifierNamed(node, name) {
|
|
252
|
+
return node instanceof Identifier && node.text === name;
|
|
253
|
+
}
|
|
254
|
+
// Expressions
|
|
255
|
+
/** `node` without enclosing parentheses. */
|
|
256
|
+
export function skipParentheses(node) {
|
|
257
|
+
let current = node;
|
|
258
|
+
while (current instanceof ParenthesizedExpression)
|
|
259
|
+
current = current.expression;
|
|
260
|
+
return current;
|
|
261
|
+
}
|
|
262
|
+
function getQuestionDotToken(node) {
|
|
263
|
+
if (node instanceof PropertyAccessExpression)
|
|
264
|
+
return node.questionDotToken;
|
|
265
|
+
if (node instanceof ElementAccessExpression)
|
|
266
|
+
return node.questionDotToken;
|
|
267
|
+
if (node instanceof CallExpression)
|
|
268
|
+
return node.questionDotToken;
|
|
269
|
+
if (node instanceof TaggedTemplateExpression)
|
|
270
|
+
return node.questionDotToken;
|
|
271
|
+
return undefined;
|
|
272
|
+
}
|
|
273
|
+
export function isOptionalChain(node) {
|
|
274
|
+
if ((node.flags & 32 /* NodeFlags.OptionalChain */) === 0)
|
|
275
|
+
return false;
|
|
276
|
+
switch (node.kind) {
|
|
277
|
+
case 212 /* SyntaxKind.PropertyAccessExpression */:
|
|
278
|
+
case 213 /* SyntaxKind.ElementAccessExpression */:
|
|
279
|
+
case 214 /* SyntaxKind.CallExpression */:
|
|
280
|
+
case 236 /* SyntaxKind.NonNullExpression */:
|
|
281
|
+
return true;
|
|
282
|
+
}
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
/** The link of an optional chain with the `?.`. */
|
|
286
|
+
export function isOptionalChainRoot(node) {
|
|
287
|
+
return isOptionalChain(node) && node.kind !== 236 /* SyntaxKind.NonNullExpression */ && getQuestionDotToken(node) !== undefined;
|
|
288
|
+
}
|
|
289
|
+
/** Whether `node` is the whole optional chain, not a link in a longer one. */
|
|
290
|
+
export function isOutermostOptionalChain(node) {
|
|
291
|
+
const parent = node.parent;
|
|
292
|
+
return !isOptionalChain(parent) || isOptionalChainRoot(parent) || node !== getExpression(parent);
|
|
293
|
+
}
|
|
294
|
+
export function isExpressionOfOptionalChainRoot(node) {
|
|
295
|
+
const parent = node.parent;
|
|
296
|
+
return isOptionalChainRoot(parent) && getExpression(parent) === node;
|
|
297
|
+
}
|
|
298
|
+
export function isNullishCoalesce(node) {
|
|
299
|
+
return (node instanceof BinaryExpression &&
|
|
300
|
+
node.operatorToken.kind === 60 /* SyntaxKind.QuestionQuestionToken */);
|
|
301
|
+
}
|
|
302
|
+
export function isLogicalOrCoalescingBinaryOperator(kind) {
|
|
303
|
+
return (kind === 56 /* SyntaxKind.BarBarToken */ ||
|
|
304
|
+
kind === 55 /* SyntaxKind.AmpersandAmpersandToken */ ||
|
|
305
|
+
kind === 60 /* SyntaxKind.QuestionQuestionToken */);
|
|
306
|
+
}
|
|
307
|
+
export function isLogicalOrCoalescingAssignmentOperator(kind) {
|
|
308
|
+
return (kind === 76 /* SyntaxKind.AmpersandAmpersandEqualsToken */ ||
|
|
309
|
+
kind === 75 /* SyntaxKind.BarBarEqualsToken */ ||
|
|
310
|
+
kind === 77 /* SyntaxKind.QuestionQuestionEqualsToken */);
|
|
311
|
+
}
|
|
312
|
+
export function isLogicalOrCoalescingAssignmentExpression(node) {
|
|
313
|
+
return (node instanceof BinaryExpression &&
|
|
314
|
+
isLogicalOrCoalescingAssignmentOperator(node.operatorToken.kind));
|
|
315
|
+
}
|
|
316
|
+
/** `&&`, `||` or `??`, possibly parenthesized or negated. */
|
|
317
|
+
export function isLogicalExpression(node) {
|
|
318
|
+
let current = node;
|
|
319
|
+
for (;;) {
|
|
320
|
+
if (current instanceof ParenthesizedExpression) {
|
|
321
|
+
const parenthesized = current;
|
|
322
|
+
current = parenthesized.expression;
|
|
323
|
+
}
|
|
324
|
+
else if (current instanceof PrefixUnaryExpression) {
|
|
325
|
+
const unary = current;
|
|
326
|
+
if (unary.operator !== 53 /* SyntaxKind.ExclamationToken */)
|
|
327
|
+
return false;
|
|
328
|
+
current = unary.operand;
|
|
329
|
+
}
|
|
330
|
+
else if (current instanceof BinaryExpression) {
|
|
331
|
+
const binary = current;
|
|
332
|
+
return isLogicalOrCoalescingBinaryOperator(binary.operatorToken.kind);
|
|
333
|
+
}
|
|
334
|
+
else
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
export function isAssignmentExpression(node, excludeCompoundAssignment) {
|
|
339
|
+
if (!(node instanceof BinaryExpression))
|
|
340
|
+
return false;
|
|
341
|
+
const binary = node;
|
|
342
|
+
const operator = binary.operatorToken.kind;
|
|
343
|
+
return ((operator === 63 /* SyntaxKind.EqualsToken */ || (!excludeCompoundAssignment && isAssignmentOperator(operator))) &&
|
|
344
|
+
isLeftHandSideExpression(binary.left));
|
|
345
|
+
}
|
|
346
|
+
/** `[a, b] = …` or `({ a } = …)`. */
|
|
347
|
+
export function isDestructuringAssignment(node) {
|
|
348
|
+
if (!isAssignmentExpression(node, true))
|
|
349
|
+
return false;
|
|
350
|
+
const kind = node.left.kind;
|
|
351
|
+
return kind === 211 /* SyntaxKind.ObjectLiteralExpression */ || kind === 210 /* SyntaxKind.ArrayLiteralExpression */;
|
|
352
|
+
}
|
|
353
|
+
/** The assignment, update or `for…in`/`for…of` that writes to `node`, if any. */
|
|
354
|
+
export function getAssignmentTarget(node) {
|
|
355
|
+
let current = node;
|
|
356
|
+
for (;;) {
|
|
357
|
+
const parent = current.parent;
|
|
358
|
+
switch (parent.kind) {
|
|
359
|
+
case 227 /* SyntaxKind.BinaryExpression */: {
|
|
360
|
+
const binary = parent;
|
|
361
|
+
return isAssignmentOperator(binary.operatorToken.kind) && binary.left === current ? parent : undefined;
|
|
362
|
+
}
|
|
363
|
+
case 225 /* SyntaxKind.PrefixUnaryExpression */: {
|
|
364
|
+
const operator = parent.operator;
|
|
365
|
+
return operator === 45 /* SyntaxKind.PlusPlusToken */ || operator === 46 /* SyntaxKind.MinusMinusToken */ ? parent : undefined;
|
|
366
|
+
}
|
|
367
|
+
case 226 /* SyntaxKind.PostfixUnaryExpression */: {
|
|
368
|
+
const operator = parent.operator;
|
|
369
|
+
return operator === 45 /* SyntaxKind.PlusPlusToken */ || operator === 46 /* SyntaxKind.MinusMinusToken */ ? parent : undefined;
|
|
370
|
+
}
|
|
371
|
+
case 250 /* SyntaxKind.ForInStatement */:
|
|
372
|
+
case 251 /* SyntaxKind.ForOfStatement */:
|
|
373
|
+
return getInitializer(parent) === current ? parent : undefined;
|
|
374
|
+
case 218 /* SyntaxKind.ParenthesizedExpression */:
|
|
375
|
+
case 210 /* SyntaxKind.ArrayLiteralExpression */:
|
|
376
|
+
case 231 /* SyntaxKind.SpreadElement */:
|
|
377
|
+
case 236 /* SyntaxKind.NonNullExpression */:
|
|
378
|
+
current = parent;
|
|
379
|
+
break;
|
|
380
|
+
case 305 /* SyntaxKind.SpreadAssignment */:
|
|
381
|
+
current = parent.parent;
|
|
382
|
+
break;
|
|
383
|
+
case 304 /* SyntaxKind.ShorthandPropertyAssignment */:
|
|
384
|
+
if (getName(parent) !== current)
|
|
385
|
+
return undefined;
|
|
386
|
+
current = parent.parent;
|
|
387
|
+
break;
|
|
388
|
+
case 303 /* SyntaxKind.PropertyAssignment */:
|
|
389
|
+
if (getName(parent) === current)
|
|
390
|
+
return undefined;
|
|
391
|
+
current = parent.parent;
|
|
392
|
+
break;
|
|
393
|
+
default:
|
|
394
|
+
return undefined;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
export function isAssignmentTarget(node) {
|
|
399
|
+
return getAssignmentTarget(node) !== undefined;
|
|
400
|
+
}
|
|
401
|
+
/** An identifier, `this`, `super` or `import.meta`, possibly with property accesses. */
|
|
402
|
+
export function isDottedName(node) {
|
|
403
|
+
let current = node;
|
|
404
|
+
for (;;) {
|
|
405
|
+
switch (current.kind) {
|
|
406
|
+
case 79 /* SyntaxKind.Identifier */:
|
|
407
|
+
case 109 /* SyntaxKind.ThisKeyword */:
|
|
408
|
+
case 107 /* SyntaxKind.SuperKeyword */:
|
|
409
|
+
case 237 /* SyntaxKind.MetaProperty */:
|
|
410
|
+
return true;
|
|
411
|
+
case 212 /* SyntaxKind.PropertyAccessExpression */:
|
|
412
|
+
current = current.expression;
|
|
413
|
+
break;
|
|
414
|
+
case 218 /* SyntaxKind.ParenthesizedExpression */:
|
|
415
|
+
current = current.expression;
|
|
416
|
+
break;
|
|
417
|
+
default:
|
|
418
|
+
return false;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
/** `a`, `a.b.c`, and in JavaScript `this.a` and `a["b"]`. */
|
|
423
|
+
export function isEntityNameExpression(node, allowJS) {
|
|
424
|
+
if (node.kind === 79 /* SyntaxKind.Identifier */)
|
|
425
|
+
return true;
|
|
426
|
+
if (node instanceof PropertyAccessExpression) {
|
|
427
|
+
const access = node;
|
|
428
|
+
return access.name.kind === 79 /* SyntaxKind.Identifier */ && isEntityNameExpression(access.expression, allowJS);
|
|
429
|
+
}
|
|
430
|
+
if (!allowJS)
|
|
431
|
+
return false;
|
|
432
|
+
if (node.kind === 109 /* SyntaxKind.ThisKeyword */)
|
|
433
|
+
return true;
|
|
434
|
+
if (!(node instanceof ElementAccessExpression))
|
|
435
|
+
return false;
|
|
436
|
+
const access = node;
|
|
437
|
+
return isStringOrNumericLiteralLike(access.argumentExpression) && isEntityNameExpression(access.expression, allowJS);
|
|
438
|
+
}
|
|
439
|
+
/** An `export default` or `module.exports =` expression that aliases a declaration. */
|
|
440
|
+
export function expressionIsAlias(node) {
|
|
441
|
+
return isEntityNameExpression(node, false) || node.kind === 232 /* SyntaxKind.ClassExpression */;
|
|
442
|
+
}
|
|
443
|
+
export function isAccessExpression(node) {
|
|
444
|
+
return node.kind === 212 /* SyntaxKind.PropertyAccessExpression */ || node.kind === 213 /* SyntaxKind.ElementAccessExpression */;
|
|
445
|
+
}
|
|
446
|
+
/** The name of `x.name` or the literal of `x["name"]`. */
|
|
447
|
+
export function getElementOrPropertyAccessName(node) {
|
|
448
|
+
if (node instanceof PropertyAccessExpression)
|
|
449
|
+
return node.name.kind === 79 /* SyntaxKind.Identifier */
|
|
450
|
+
? node.name
|
|
451
|
+
: undefined;
|
|
452
|
+
if (node instanceof ElementAccessExpression) {
|
|
453
|
+
const argument = skipParentheses(node.argumentExpression);
|
|
454
|
+
return isStringOrNumericLiteralLike(argument) ? argument : undefined;
|
|
455
|
+
}
|
|
456
|
+
throw new Error('Unhandled case in getElementOrPropertyAccessName');
|
|
457
|
+
}
|
|
458
|
+
export function isPushOrUnshiftIdentifier(node) {
|
|
459
|
+
const text = getText(node);
|
|
460
|
+
return text === 'push' || text === 'unshift';
|
|
461
|
+
}
|
|
462
|
+
/** The call of an immediately invoked function or arrow function. */
|
|
463
|
+
export function getImmediatelyInvokedFunctionExpression(fn) {
|
|
464
|
+
if (!isFunctionExpressionOrArrowFunction(fn))
|
|
465
|
+
return undefined;
|
|
466
|
+
let prev = fn;
|
|
467
|
+
let parent = fn.parent;
|
|
468
|
+
while (parent.kind === 218 /* SyntaxKind.ParenthesizedExpression */) {
|
|
469
|
+
prev = parent;
|
|
470
|
+
parent = parent.parent;
|
|
471
|
+
}
|
|
472
|
+
if (!(parent instanceof CallExpression))
|
|
473
|
+
return undefined;
|
|
474
|
+
const call = parent;
|
|
475
|
+
return call.expression === prev ? call : undefined;
|
|
476
|
+
}
|
|
477
|
+
/** `x as const` or `<const>x`. */
|
|
478
|
+
export function isConstAssertion(node) {
|
|
479
|
+
if (node.kind !== 235 /* SyntaxKind.AsExpression */ && node.kind !== 217 /* SyntaxKind.TypeAssertionExpression */)
|
|
480
|
+
return false;
|
|
481
|
+
const type = getType(node);
|
|
482
|
+
if (!(type instanceof TypeReferenceNode))
|
|
483
|
+
return false;
|
|
484
|
+
const typeArguments = type.typeArguments;
|
|
485
|
+
return ((typeArguments === undefined || typeArguments.nodes.length === 0) &&
|
|
486
|
+
isIdentifierNamed(type.typeName, 'const'));
|
|
487
|
+
}
|
|
488
|
+
export function isModuleIdentifier(node) {
|
|
489
|
+
return isIdentifierNamed(node, 'module');
|
|
490
|
+
}
|
|
491
|
+
export function isExportsIdentifier(node) {
|
|
492
|
+
return isIdentifierNamed(node, 'exports');
|
|
493
|
+
}
|
|
494
|
+
/** `module.exports` or `module["exports"]`. */
|
|
495
|
+
export function isModuleExportsAccessExpression(node) {
|
|
496
|
+
if (!isAccessExpression(node) || !isModuleIdentifier(getExpression(node)))
|
|
497
|
+
return false;
|
|
498
|
+
const name = getElementOrPropertyAccessName(node);
|
|
499
|
+
return name !== undefined && getText(name) === 'exports';
|
|
500
|
+
}
|
|
501
|
+
function isLiteralLikeElementAccess(node) {
|
|
502
|
+
return (node instanceof ElementAccessExpression &&
|
|
503
|
+
isStringOrNumericLiteralLike(node.argumentExpression));
|
|
504
|
+
}
|
|
505
|
+
export function isBindableStaticAccessExpression(node, excludeThisKeyword) {
|
|
506
|
+
if (node instanceof PropertyAccessExpression) {
|
|
507
|
+
if (!excludeThisKeyword && node.expression.kind === 109 /* SyntaxKind.ThisKeyword */)
|
|
508
|
+
return true;
|
|
509
|
+
if (node.name.kind === 79 /* SyntaxKind.Identifier */ &&
|
|
510
|
+
isBindableStaticNameExpression(node.expression, true))
|
|
511
|
+
return true;
|
|
512
|
+
}
|
|
513
|
+
return isBindableStaticElementAccessExpression(node, excludeThisKeyword);
|
|
514
|
+
}
|
|
515
|
+
export function isBindableStaticElementAccessExpression(node, excludeThisKeyword) {
|
|
516
|
+
if (!isLiteralLikeElementAccess(node))
|
|
517
|
+
return false;
|
|
518
|
+
const expression = node.expression;
|
|
519
|
+
return ((!excludeThisKeyword && expression.kind === 109 /* SyntaxKind.ThisKeyword */) ||
|
|
520
|
+
isEntityNameExpression(expression, false) ||
|
|
521
|
+
isBindableStaticAccessExpression(expression, true));
|
|
522
|
+
}
|
|
523
|
+
export function isBindableStaticNameExpression(node, excludeThisKeyword) {
|
|
524
|
+
return isEntityNameExpression(node, false) || isBindableStaticAccessExpression(node, excludeThisKeyword);
|
|
525
|
+
}
|
|
526
|
+
/** `Object.defineProperty(x, "name", descriptor)` with a bindable `x`. */
|
|
527
|
+
export function isBindableObjectDefinePropertyCall(node) {
|
|
528
|
+
if (!(node instanceof CallExpression))
|
|
529
|
+
return false;
|
|
530
|
+
const args = node.arguments.nodes;
|
|
531
|
+
if (args.length !== 3)
|
|
532
|
+
return false;
|
|
533
|
+
const callee = node.expression;
|
|
534
|
+
return (callee instanceof PropertyAccessExpression &&
|
|
535
|
+
isIdentifierNamed(callee.expression, 'Object') &&
|
|
536
|
+
getText(callee.name) === 'defineProperty' &&
|
|
537
|
+
isStringOrNumericLiteralLike(args[1]) &&
|
|
538
|
+
isBindableStaticNameExpression(args[0], true));
|
|
539
|
+
}
|
|
540
|
+
export function getAssignmentDeclarationKind(node) {
|
|
541
|
+
if (node instanceof BinaryExpression) {
|
|
542
|
+
const binary = node;
|
|
543
|
+
const left = binary.left;
|
|
544
|
+
if (binary.operatorToken.kind !== 63 /* SyntaxKind.EqualsToken */ || !isAccessExpression(left))
|
|
545
|
+
return 0 /* JSDeclarationKind.None */;
|
|
546
|
+
const inJS = (left.flags & 65536 /* NodeFlags.JavaScriptFile */) !== 0;
|
|
547
|
+
const target = getExpression(left);
|
|
548
|
+
if (inJS) {
|
|
549
|
+
if (isModuleExportsAccessExpression(left) && !isExportsIdentifier(binary.right))
|
|
550
|
+
return 1 /* JSDeclarationKind.ModuleExports */;
|
|
551
|
+
if ((isModuleExportsAccessExpression(target) || isExportsIdentifier(target)) &&
|
|
552
|
+
getElementOrPropertyAccessName(left) !== undefined)
|
|
553
|
+
return 2 /* JSDeclarationKind.ExportsProperty */;
|
|
554
|
+
if (target.kind === 109 /* SyntaxKind.ThisKeyword */)
|
|
555
|
+
return 3 /* JSDeclarationKind.ThisProperty */;
|
|
556
|
+
}
|
|
557
|
+
if (left instanceof PropertyAccessExpression) {
|
|
558
|
+
if (isEntityNameExpression(target, inJS) &&
|
|
559
|
+
left.name.kind === 79 /* SyntaxKind.Identifier */)
|
|
560
|
+
return 4 /* JSDeclarationKind.Property */;
|
|
561
|
+
}
|
|
562
|
+
else if (isEntityNameExpression(target, inJS))
|
|
563
|
+
return 4 /* JSDeclarationKind.Property */;
|
|
564
|
+
return 0 /* JSDeclarationKind.None */;
|
|
565
|
+
}
|
|
566
|
+
if (node.kind === 214 /* SyntaxKind.CallExpression */ &&
|
|
567
|
+
(node.flags & 65536 /* NodeFlags.JavaScriptFile */) !== 0 &&
|
|
568
|
+
isBindableObjectDefinePropertyCall(node)) {
|
|
569
|
+
const entityName = getArguments(node).nodes[0];
|
|
570
|
+
return isExportsIdentifier(entityName) || isModuleExportsAccessExpression(entityName)
|
|
571
|
+
? 6 /* JSDeclarationKind.ObjectDefinePropertyExports */
|
|
572
|
+
: 5 /* JSDeclarationKind.ObjectDefinePropertyValue */;
|
|
573
|
+
}
|
|
574
|
+
return 0 /* JSDeclarationKind.None */;
|
|
575
|
+
}
|
|
576
|
+
/** A function, arrow or (in JavaScript) class expression or empty object literal that can get expando properties. */
|
|
577
|
+
export function isExpandoInitializer(declaration, initializer) {
|
|
578
|
+
if (initializer === undefined)
|
|
579
|
+
return false;
|
|
580
|
+
if (isFunctionExpressionOrArrowFunction(initializer))
|
|
581
|
+
return true;
|
|
582
|
+
if ((initializer.flags & 65536 /* NodeFlags.JavaScriptFile */) === 0)
|
|
583
|
+
return false;
|
|
584
|
+
if (initializer.kind === 232 /* SyntaxKind.ClassExpression */)
|
|
585
|
+
return true;
|
|
586
|
+
return (initializer.kind === 211 /* SyntaxKind.ObjectLiteralExpression */ &&
|
|
587
|
+
getProperties(initializer).nodes.length === 0 &&
|
|
588
|
+
getType(declaration) === undefined);
|
|
589
|
+
}
|
|
590
|
+
/** `const x = require("m")` in JavaScript, or a binding element of one. */
|
|
591
|
+
export function isVariableDeclarationInitializedToRequire(node) {
|
|
592
|
+
const candidate = node.kind === 209 /* SyntaxKind.BindingElement */ ? node.parent.parent : node;
|
|
593
|
+
if (!(candidate instanceof VariableDeclaration) ||
|
|
594
|
+
(candidate.flags & 65536 /* NodeFlags.JavaScriptFile */) === 0)
|
|
595
|
+
return false;
|
|
596
|
+
const declaration = candidate;
|
|
597
|
+
const initializer = declaration.initializer;
|
|
598
|
+
if (initializer === undefined)
|
|
599
|
+
return false;
|
|
600
|
+
return ((getModifierFlags(declaration.parent.parent) & 32 /* ModifierFlags.Export */) === 0 &&
|
|
601
|
+
declaration.type === undefined &&
|
|
602
|
+
isRequireCallWithLiteral(initializer));
|
|
603
|
+
}
|
|
604
|
+
function isRequireCallWithLiteral(node) {
|
|
605
|
+
if (!(node instanceof CallExpression) || !isIdentifierNamed(node.expression, 'require'))
|
|
606
|
+
return false;
|
|
607
|
+
const args = node.arguments.nodes;
|
|
608
|
+
return args.length === 1 && isStringLiteralLike(args[0]);
|
|
609
|
+
}
|
|
610
|
+
/** A `@typedef` or `@callback` at the top level of a module. */
|
|
611
|
+
export function isImplicitlyExportedJSDocDeclaration(node) {
|
|
612
|
+
const parent = node.parent;
|
|
613
|
+
if (parent.kind !== 307 /* SyntaxKind.SourceFile */ || !isExternalOrCommonJSModule(parent))
|
|
614
|
+
return false;
|
|
615
|
+
if (node.kind === 345 /* SyntaxKind.JSTypeAliasDeclaration */)
|
|
616
|
+
return true;
|
|
617
|
+
return node.kind === 268 /* SyntaxKind.ModuleDeclaration */ && (node.flags & 8 /* NodeFlags.Reparsed */) !== 0;
|
|
618
|
+
}
|
|
619
|
+
// Declarations
|
|
620
|
+
/** The name of a declaration, not counting names it gets from an enclosing assignment. */
|
|
621
|
+
export function getNonAssignedNameOfDeclaration(declaration) {
|
|
622
|
+
switch (declaration.kind) {
|
|
623
|
+
case 227 /* SyntaxKind.BinaryExpression */:
|
|
624
|
+
case 214 /* SyntaxKind.CallExpression */:
|
|
625
|
+
switch (getAssignmentDeclarationKind(declaration)) {
|
|
626
|
+
case 4 /* JSDeclarationKind.Property */:
|
|
627
|
+
case 3 /* JSDeclarationKind.ThisProperty */:
|
|
628
|
+
case 2 /* JSDeclarationKind.ExportsProperty */: {
|
|
629
|
+
const left = declaration.left;
|
|
630
|
+
const name = getElementOrPropertyAccessName(left);
|
|
631
|
+
return name !== undefined ? name : left;
|
|
632
|
+
}
|
|
633
|
+
case 5 /* JSDeclarationKind.ObjectDefinePropertyValue */:
|
|
634
|
+
case 6 /* JSDeclarationKind.ObjectDefinePropertyExports */:
|
|
635
|
+
return getArguments(declaration).nodes[1];
|
|
636
|
+
}
|
|
637
|
+
return undefined;
|
|
638
|
+
case 278 /* SyntaxKind.ExportAssignment */: {
|
|
639
|
+
const expression = getExpression(declaration);
|
|
640
|
+
return expression.kind === 79 /* SyntaxKind.Identifier */ ? expression : undefined;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
return getName(declaration);
|
|
644
|
+
}
|
|
645
|
+
/** The name a function or class expression gets from the property, variable or assignment it initializes. */
|
|
646
|
+
export function getAssignedName(node) {
|
|
647
|
+
const parent = node.parent;
|
|
648
|
+
if (parent === undefined)
|
|
649
|
+
return undefined;
|
|
650
|
+
switch (parent.kind) {
|
|
651
|
+
case 303 /* SyntaxKind.PropertyAssignment */:
|
|
652
|
+
return getName(parent);
|
|
653
|
+
case 209 /* SyntaxKind.BindingElement */:
|
|
654
|
+
return parent.name;
|
|
655
|
+
case 227 /* SyntaxKind.BinaryExpression */: {
|
|
656
|
+
const binary = parent;
|
|
657
|
+
if (node !== binary.right)
|
|
658
|
+
return undefined;
|
|
659
|
+
const left = binary.left;
|
|
660
|
+
if (left.kind === 79 /* SyntaxKind.Identifier */)
|
|
661
|
+
return left;
|
|
662
|
+
if (left instanceof PropertyAccessExpression)
|
|
663
|
+
return left.name;
|
|
664
|
+
if (left instanceof ElementAccessExpression) {
|
|
665
|
+
const argument = skipParentheses(left.argumentExpression);
|
|
666
|
+
if (isStringOrNumericLiteralLike(argument))
|
|
667
|
+
return argument;
|
|
668
|
+
}
|
|
669
|
+
return undefined;
|
|
670
|
+
}
|
|
671
|
+
case 261 /* SyntaxKind.VariableDeclaration */: {
|
|
672
|
+
const name = parent.name;
|
|
673
|
+
return name.kind === 79 /* SyntaxKind.Identifier */ ? name : undefined;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
return undefined;
|
|
677
|
+
}
|
|
678
|
+
export function getNameOfDeclaration(declaration) {
|
|
679
|
+
if (declaration === undefined)
|
|
680
|
+
return undefined;
|
|
681
|
+
const name = getNonAssignedNameOfDeclaration(declaration);
|
|
682
|
+
if (name !== undefined)
|
|
683
|
+
return name;
|
|
684
|
+
if (isFunctionExpressionOrArrowFunction(declaration) || declaration.kind === 232 /* SyntaxKind.ClassExpression */)
|
|
685
|
+
return getAssignedName(declaration);
|
|
686
|
+
return undefined;
|
|
687
|
+
}
|
|
688
|
+
/** A computed name or element access whose name isn't a literal. */
|
|
689
|
+
export function isDynamicName(name) {
|
|
690
|
+
let expression;
|
|
691
|
+
if (name.kind === 168 /* SyntaxKind.ComputedPropertyName */)
|
|
692
|
+
expression = getExpression(name);
|
|
693
|
+
else if (name instanceof ElementAccessExpression)
|
|
694
|
+
expression = skipParentheses(name.argumentExpression);
|
|
695
|
+
else
|
|
696
|
+
return false;
|
|
697
|
+
return !isStringOrNumericLiteralLike(expression) && !isSignedNumericLiteral(expression);
|
|
698
|
+
}
|
|
699
|
+
export function hasDynamicName(declaration) {
|
|
700
|
+
const name = getNameOfDeclaration(declaration);
|
|
701
|
+
return name !== undefined && isDynamicName(name);
|
|
702
|
+
}
|
|
703
|
+
export function isPartOfParameterDeclaration(node) {
|
|
704
|
+
return getRootDeclaration(node).kind === 170 /* SyntaxKind.Parameter */;
|
|
705
|
+
}
|
|
706
|
+
export function isCatchClauseVariableDeclarationOrBindingElement(declaration) {
|
|
707
|
+
const node = getRootDeclaration(declaration);
|
|
708
|
+
return node.kind === 261 /* SyntaxKind.VariableDeclaration */ && node.parent.kind === 300 /* SyntaxKind.CatchClause */;
|
|
709
|
+
}
|
|
710
|
+
/** A `let`, `const`, `using` or catch variable. */
|
|
711
|
+
export function isBlockOrCatchScoped(declaration) {
|
|
712
|
+
return ((getCombinedNodeFlags(declaration) & 7 /* NodeFlags.BlockScoped */) !== 0 ||
|
|
713
|
+
isCatchClauseVariableDeclarationOrBindingElement(declaration));
|
|
714
|
+
}
|
|
715
|
+
export function getContainingClass(node) {
|
|
716
|
+
let current = node.parent;
|
|
717
|
+
while (current !== undefined && !isClassLike(current))
|
|
718
|
+
current = current.parent;
|
|
719
|
+
return current;
|
|
720
|
+
}
|
|
721
|
+
/** The constructor of a class with a body. */
|
|
722
|
+
export function findConstructorDeclaration(node) {
|
|
723
|
+
const members = getMembers(node);
|
|
724
|
+
if (members === undefined)
|
|
725
|
+
return undefined;
|
|
726
|
+
for (const member of members.nodes)
|
|
727
|
+
if (member.kind === 177 /* SyntaxKind.Constructor */ && !nodeIsMissing(getBody(member)))
|
|
728
|
+
return member;
|
|
729
|
+
return undefined;
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* The nearest function, class member, namespace, enum or source file that determines `this`
|
|
733
|
+
* for `node`; arrow functions count if `includeArrowFunctions`.
|
|
734
|
+
*/
|
|
735
|
+
export function getThisContainer(node, includeArrowFunctions, includeClassComputedPropertyName) {
|
|
736
|
+
let current = node;
|
|
737
|
+
for (;;) {
|
|
738
|
+
const parent = current.parent;
|
|
739
|
+
if (parent === undefined)
|
|
740
|
+
throw new Error('nil parent in getThisContainer');
|
|
741
|
+
current = parent;
|
|
742
|
+
switch (current.kind) {
|
|
743
|
+
case 168 /* SyntaxKind.ComputedPropertyName */:
|
|
744
|
+
if (includeClassComputedPropertyName && isClassLike(current.parent.parent))
|
|
745
|
+
return current;
|
|
746
|
+
current = current.parent.parent;
|
|
747
|
+
break;
|
|
748
|
+
case 171 /* SyntaxKind.Decorator */:
|
|
749
|
+
if (current.parent.kind === 170 /* SyntaxKind.Parameter */ && isClassElement(current.parent.parent))
|
|
750
|
+
current = current.parent.parent;
|
|
751
|
+
else if (isClassElement(current.parent))
|
|
752
|
+
current = current.parent;
|
|
753
|
+
break;
|
|
754
|
+
case 220 /* SyntaxKind.ArrowFunction */:
|
|
755
|
+
if (includeArrowFunctions)
|
|
756
|
+
return current;
|
|
757
|
+
break;
|
|
758
|
+
case 263 /* SyntaxKind.FunctionDeclaration */:
|
|
759
|
+
case 219 /* SyntaxKind.FunctionExpression */:
|
|
760
|
+
case 268 /* SyntaxKind.ModuleDeclaration */:
|
|
761
|
+
case 176 /* SyntaxKind.ClassStaticBlockDeclaration */:
|
|
762
|
+
case 173 /* SyntaxKind.PropertyDeclaration */:
|
|
763
|
+
case 172 /* SyntaxKind.PropertySignature */:
|
|
764
|
+
case 175 /* SyntaxKind.MethodDeclaration */:
|
|
765
|
+
case 174 /* SyntaxKind.MethodSignature */:
|
|
766
|
+
case 177 /* SyntaxKind.Constructor */:
|
|
767
|
+
case 178 /* SyntaxKind.GetAccessor */:
|
|
768
|
+
case 179 /* SyntaxKind.SetAccessor */:
|
|
769
|
+
case 180 /* SyntaxKind.CallSignature */:
|
|
770
|
+
case 181 /* SyntaxKind.ConstructSignature */:
|
|
771
|
+
case 182 /* SyntaxKind.IndexSignature */:
|
|
772
|
+
case 267 /* SyntaxKind.EnumDeclaration */:
|
|
773
|
+
case 307 /* SyntaxKind.SourceFile */:
|
|
774
|
+
return current;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
/** Whether `node` is outside any function, class member or namespace. */
|
|
779
|
+
export function isInTopLevelContext(node) {
|
|
780
|
+
let current = node;
|
|
781
|
+
if (current.kind === 79 /* SyntaxKind.Identifier */) {
|
|
782
|
+
const parent = current.parent;
|
|
783
|
+
if ((parent.kind === 264 /* SyntaxKind.ClassDeclaration */ || parent.kind === 263 /* SyntaxKind.FunctionDeclaration */) &&
|
|
784
|
+
getName(parent) === current)
|
|
785
|
+
current = parent;
|
|
786
|
+
}
|
|
787
|
+
return getThisContainer(current, true, false).kind === 307 /* SyntaxKind.SourceFile */;
|
|
788
|
+
}
|
|
789
|
+
/** An identifier in a property name position, which never resolves to a symbol. */
|
|
790
|
+
export function isIdentifierName(node) {
|
|
791
|
+
const parent = node.parent;
|
|
792
|
+
switch (parent.kind) {
|
|
793
|
+
case 173 /* SyntaxKind.PropertyDeclaration */:
|
|
794
|
+
case 172 /* SyntaxKind.PropertySignature */:
|
|
795
|
+
case 175 /* SyntaxKind.MethodDeclaration */:
|
|
796
|
+
case 174 /* SyntaxKind.MethodSignature */:
|
|
797
|
+
case 178 /* SyntaxKind.GetAccessor */:
|
|
798
|
+
case 179 /* SyntaxKind.SetAccessor */:
|
|
799
|
+
case 306 /* SyntaxKind.EnumMember */:
|
|
800
|
+
case 303 /* SyntaxKind.PropertyAssignment */:
|
|
801
|
+
case 212 /* SyntaxKind.PropertyAccessExpression */:
|
|
802
|
+
return getName(parent) === node;
|
|
803
|
+
case 167 /* SyntaxKind.QualifiedName */:
|
|
804
|
+
return parent.right === node;
|
|
805
|
+
case 209 /* SyntaxKind.BindingElement */:
|
|
806
|
+
case 277 /* SyntaxKind.ImportSpecifier */:
|
|
807
|
+
return getPropertyName(parent) === node;
|
|
808
|
+
case 282 /* SyntaxKind.ExportSpecifier */:
|
|
809
|
+
case 292 /* SyntaxKind.JsxAttribute */:
|
|
810
|
+
case 286 /* SyntaxKind.JsxSelfClosingElement */:
|
|
811
|
+
case 287 /* SyntaxKind.JsxOpeningElement */:
|
|
812
|
+
case 288 /* SyntaxKind.JsxClosingElement */:
|
|
813
|
+
return true;
|
|
814
|
+
}
|
|
815
|
+
return false;
|
|
816
|
+
}
|
|
817
|
+
export function isPartOfTypeQuery(node) {
|
|
818
|
+
let current = node;
|
|
819
|
+
while (current.kind === 167 /* SyntaxKind.QualifiedName */ || current.kind === 79 /* SyntaxKind.Identifier */)
|
|
820
|
+
current = current.parent;
|
|
821
|
+
return current.kind === 187 /* SyntaxKind.TypeQuery */;
|
|
822
|
+
}
|
|
823
|
+
/** A statement that runs code, or a declaration that does (classes, enums, namespaces). */
|
|
824
|
+
export function isPotentiallyExecutableNode(node) {
|
|
825
|
+
if (node.kind >= 244 /* SyntaxKind.FirstStatement */ && node.kind <= 260 /* SyntaxKind.LastStatement */) {
|
|
826
|
+
if (node instanceof VariableStatement) {
|
|
827
|
+
const list = node.declarationList;
|
|
828
|
+
if ((getCombinedNodeFlags(list) & 7 /* NodeFlags.BlockScoped */) !== 0)
|
|
829
|
+
return true;
|
|
830
|
+
for (const declaration of list.declarations.nodes)
|
|
831
|
+
if (getInitializer(declaration) !== undefined)
|
|
832
|
+
return true;
|
|
833
|
+
return false;
|
|
834
|
+
}
|
|
835
|
+
return true;
|
|
836
|
+
}
|
|
837
|
+
return (node.kind === 264 /* SyntaxKind.ClassDeclaration */ ||
|
|
838
|
+
node.kind === 267 /* SyntaxKind.EnumDeclaration */ ||
|
|
839
|
+
node.kind === 268 /* SyntaxKind.ModuleDeclaration */);
|
|
840
|
+
}
|
|
841
|
+
/** A `declare module "m"` that augments an external module rather than declaring one. */
|
|
842
|
+
export function isModuleAugmentationExternal(node) {
|
|
843
|
+
const parent = node.parent;
|
|
844
|
+
switch (parent.kind) {
|
|
845
|
+
case 307 /* SyntaxKind.SourceFile */:
|
|
846
|
+
return isExternalModule(parent);
|
|
847
|
+
case 269 /* SyntaxKind.ModuleBlock */: {
|
|
848
|
+
const grandParent = parent.parent;
|
|
849
|
+
return (grandParent instanceof ModuleDeclaration &&
|
|
850
|
+
isAmbientModuleDeclaration(grandParent) &&
|
|
851
|
+
grandParent.parent.kind === 307 /* SyntaxKind.SourceFile */ &&
|
|
852
|
+
!isExternalModule(grandParent.parent));
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
return false;
|
|
856
|
+
}
|
|
857
|
+
function isAmbientModuleDeclaration(node) {
|
|
858
|
+
return node.name.kind === 10 /* SyntaxKind.StringLiteral */ || node.keyword === 162 /* SyntaxKind.GlobalKeyword */;
|
|
859
|
+
}
|
|
860
|
+
export function moduleExportNameIsDefault(node) {
|
|
861
|
+
return getText(node) === "default" /* InternalSymbolName.Default */;
|
|
862
|
+
}
|
|
863
|
+
export function getDeclarationOfKind(symbol, kind) {
|
|
864
|
+
for (const declaration of symbol.declarations)
|
|
865
|
+
if (declaration.kind === kind)
|
|
866
|
+
return declaration;
|
|
867
|
+
return undefined;
|
|
868
|
+
}
|
|
869
|
+
/** The name of a symbol, with `#name` for private class members. */
|
|
870
|
+
export function symbolName(symbol) {
|
|
871
|
+
const declaration = symbol.valueDeclaration;
|
|
872
|
+
if (declaration !== undefined && isPrivateIdentifierClassElementDeclaration(declaration))
|
|
873
|
+
return getText(getName(declaration));
|
|
874
|
+
return symbol.name;
|
|
875
|
+
}
|
|
876
|
+
/** Whether a namespace declaration has a runtime value. Parents of `node` must be set. */
|
|
877
|
+
/**
|
|
878
|
+
* `names` holds the statements of the blocks searched for the targets of `export { x }` (`forAliasTarget`)
|
|
879
|
+
* by name; a caller that asks for the states of many modules of a file passes the same one.
|
|
880
|
+
*/
|
|
881
|
+
export function getModuleInstanceState(node, names = new StatementsByName()) {
|
|
882
|
+
return new ModuleInstanceStateComputer(names).ofModule(node, []);
|
|
883
|
+
}
|
|
884
|
+
/**
|
|
885
|
+
* The statements of blocks (a block, module block or source file) by the names they declare, in
|
|
886
|
+
* order: a declaration by its name if that is an identifier, a variable statement by the identifier
|
|
887
|
+
* names of its declarations. Built for each block the first time it is searched:
|
|
888
|
+
* scanning the statements for each name made `export { x as default }` in each of the 1,671
|
|
889
|
+
* namespaces of lucide-react's dynamic.d.ts compare against all 8,600 statements of the file.
|
|
890
|
+
*/
|
|
891
|
+
export class StatementsByName {
|
|
892
|
+
blocks = new Map();
|
|
893
|
+
/** The statements of `block` that declare `name`. */
|
|
894
|
+
get(block, name) {
|
|
895
|
+
let byName = this.blocks.get(block);
|
|
896
|
+
if (byName === undefined) {
|
|
897
|
+
byName = new Map();
|
|
898
|
+
for (const statement of getStatements(block).nodes) {
|
|
899
|
+
const declarationName = getName(statement);
|
|
900
|
+
if (declarationName !== undefined) {
|
|
901
|
+
if (declarationName.kind === 79 /* SyntaxKind.Identifier */)
|
|
902
|
+
addStatementByName(byName, getText(declarationName), statement);
|
|
903
|
+
}
|
|
904
|
+
else if (statement instanceof VariableStatement) {
|
|
905
|
+
for (const declaration of statement.declarationList.declarations.nodes) {
|
|
906
|
+
const name = getName(declaration);
|
|
907
|
+
if (name !== undefined && name.kind === 79 /* SyntaxKind.Identifier */)
|
|
908
|
+
addStatementByName(byName, getText(name), statement);
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
this.blocks.set(block, byName);
|
|
913
|
+
}
|
|
914
|
+
return byName.get(name) ?? noStatements;
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
const noStatements = [];
|
|
918
|
+
function addStatementByName(byName, name, statement) {
|
|
919
|
+
const statements = byName.get(name);
|
|
920
|
+
if (statements === undefined)
|
|
921
|
+
byName.set(name, [statement]);
|
|
922
|
+
// A variable statement declaring a name twice is listed once.
|
|
923
|
+
else if (statements[statements.length - 1] !== statement)
|
|
924
|
+
statements.push(statement);
|
|
925
|
+
}
|
|
926
|
+
class ModuleInstanceStateComputer extends NodeVisitor {
|
|
927
|
+
names;
|
|
928
|
+
visited;
|
|
929
|
+
// The module block whose children `visitNode` is folding into `blockState`.
|
|
930
|
+
blockAncestors;
|
|
931
|
+
blockState;
|
|
932
|
+
constructor(names) {
|
|
933
|
+
super();
|
|
934
|
+
this.names = names;
|
|
935
|
+
this.visited = new Map();
|
|
936
|
+
this.blockAncestors = [];
|
|
937
|
+
this.blockState = 1 /* ModuleInstanceState.NonInstantiated */;
|
|
938
|
+
}
|
|
939
|
+
ofModule(node, ancestors) {
|
|
940
|
+
const body = node.body;
|
|
941
|
+
return body === undefined ? 2 /* ModuleInstanceState.Instantiated */ : this.cached(body, withAncestor(ancestors, node));
|
|
942
|
+
}
|
|
943
|
+
cached(node, ancestors) {
|
|
944
|
+
const cached = this.visited.get(node);
|
|
945
|
+
if (cached !== undefined)
|
|
946
|
+
return cached !== 0 /* ModuleInstanceState.Unknown */ ? cached : 1 /* ModuleInstanceState.NonInstantiated */;
|
|
947
|
+
this.visited.set(node, 0 /* ModuleInstanceState.Unknown */);
|
|
948
|
+
const result = this.worker(node, ancestors);
|
|
949
|
+
this.visited.set(node, result);
|
|
950
|
+
return result;
|
|
951
|
+
}
|
|
952
|
+
worker(node, ancestors) {
|
|
953
|
+
switch (node.kind) {
|
|
954
|
+
case 265 /* SyntaxKind.InterfaceDeclaration */:
|
|
955
|
+
case 266 /* SyntaxKind.TypeAliasDeclaration */:
|
|
956
|
+
case 345 /* SyntaxKind.JSTypeAliasDeclaration */:
|
|
957
|
+
return 1 /* ModuleInstanceState.NonInstantiated */;
|
|
958
|
+
case 267 /* SyntaxKind.EnumDeclaration */:
|
|
959
|
+
if (isEnumConst(node))
|
|
960
|
+
return 3 /* ModuleInstanceState.ConstEnumOnly */;
|
|
961
|
+
break;
|
|
962
|
+
case 273 /* SyntaxKind.ImportDeclaration */:
|
|
963
|
+
case 346 /* SyntaxKind.JSImportDeclaration */:
|
|
964
|
+
case 272 /* SyntaxKind.ImportEqualsDeclaration */:
|
|
965
|
+
if (!hasSyntacticModifier(node, 32 /* ModifierFlags.Export */))
|
|
966
|
+
return 1 /* ModuleInstanceState.NonInstantiated */;
|
|
967
|
+
break;
|
|
968
|
+
case 279 /* SyntaxKind.ExportDeclaration */: {
|
|
969
|
+
const exportClause = node.exportClause;
|
|
970
|
+
if (node.moduleSpecifier === undefined &&
|
|
971
|
+
exportClause !== undefined &&
|
|
972
|
+
exportClause.kind === 280 /* SyntaxKind.NamedExports */) {
|
|
973
|
+
let state = 1 /* ModuleInstanceState.NonInstantiated */;
|
|
974
|
+
const specifierAncestors = withAncestor(withAncestor(ancestors, node), exportClause);
|
|
975
|
+
for (const specifier of getElements(exportClause).nodes) {
|
|
976
|
+
const specifierState = this.forAliasTarget(specifier, specifierAncestors);
|
|
977
|
+
if (specifierState > state)
|
|
978
|
+
state = specifierState;
|
|
979
|
+
if (state === 2 /* ModuleInstanceState.Instantiated */)
|
|
980
|
+
return state;
|
|
981
|
+
}
|
|
982
|
+
return state;
|
|
983
|
+
}
|
|
984
|
+
break;
|
|
985
|
+
}
|
|
986
|
+
case 269 /* SyntaxKind.ModuleBlock */: {
|
|
987
|
+
const saveAncestors = this.blockAncestors;
|
|
988
|
+
const saveState = this.blockState;
|
|
989
|
+
this.blockAncestors = withAncestor(ancestors, node);
|
|
990
|
+
this.blockState = 1 /* ModuleInstanceState.NonInstantiated */;
|
|
991
|
+
node.forEachChild(this);
|
|
992
|
+
const state = this.blockState;
|
|
993
|
+
this.blockAncestors = saveAncestors;
|
|
994
|
+
this.blockState = saveState;
|
|
995
|
+
return state;
|
|
996
|
+
}
|
|
997
|
+
case 268 /* SyntaxKind.ModuleDeclaration */:
|
|
998
|
+
return this.ofModule(node, ancestors);
|
|
999
|
+
}
|
|
1000
|
+
return 2 /* ModuleInstanceState.Instantiated */;
|
|
1001
|
+
}
|
|
1002
|
+
visitNode(node) {
|
|
1003
|
+
const childState = this.cached(node, this.blockAncestors);
|
|
1004
|
+
switch (childState) {
|
|
1005
|
+
case 1 /* ModuleInstanceState.NonInstantiated */:
|
|
1006
|
+
return false;
|
|
1007
|
+
case 3 /* ModuleInstanceState.ConstEnumOnly */:
|
|
1008
|
+
this.blockState = 3 /* ModuleInstanceState.ConstEnumOnly */;
|
|
1009
|
+
return false;
|
|
1010
|
+
case 2 /* ModuleInstanceState.Instantiated */:
|
|
1011
|
+
this.blockState = 2 /* ModuleInstanceState.Instantiated */;
|
|
1012
|
+
return true;
|
|
1013
|
+
}
|
|
1014
|
+
throw new Error('Unhandled case in getModuleInstanceStateWorker');
|
|
1015
|
+
}
|
|
1016
|
+
forAliasTarget(specifier, ancestors) {
|
|
1017
|
+
const propertyName = getPropertyName(specifier);
|
|
1018
|
+
const name = propertyName !== undefined ? propertyName : getName(specifier);
|
|
1019
|
+
// `export { "x" }` is invalid; assume a value.
|
|
1020
|
+
if (name.kind !== 79 /* SyntaxKind.Identifier */)
|
|
1021
|
+
return 2 /* ModuleInstanceState.Instantiated */;
|
|
1022
|
+
const text = getText(name);
|
|
1023
|
+
let remaining = ancestors.length;
|
|
1024
|
+
let p = specifier;
|
|
1025
|
+
for (;;) {
|
|
1026
|
+
if (remaining === 0)
|
|
1027
|
+
p = p.parent;
|
|
1028
|
+
else
|
|
1029
|
+
p = ancestors[--remaining];
|
|
1030
|
+
if (p === undefined)
|
|
1031
|
+
break;
|
|
1032
|
+
if (p.kind !== 242 /* SyntaxKind.Block */ && p.kind !== 269 /* SyntaxKind.ModuleBlock */ && p.kind !== 307 /* SyntaxKind.SourceFile */)
|
|
1033
|
+
continue;
|
|
1034
|
+
let found = 0 /* ModuleInstanceState.Unknown */;
|
|
1035
|
+
const statementsAncestors = ancestors.slice(0, remaining);
|
|
1036
|
+
statementsAncestors.push(p);
|
|
1037
|
+
for (const statement of this.names.get(p, text)) {
|
|
1038
|
+
const state = this.cached(statement, statementsAncestors);
|
|
1039
|
+
if (found === 0 /* ModuleInstanceState.Unknown */ || state > found)
|
|
1040
|
+
found = state;
|
|
1041
|
+
if (found === 2 /* ModuleInstanceState.Instantiated */)
|
|
1042
|
+
return found;
|
|
1043
|
+
// A re-exported import alias is ambiguous, like `export import x = mod.x`.
|
|
1044
|
+
if (statement.kind === 272 /* SyntaxKind.ImportEqualsDeclaration */)
|
|
1045
|
+
found = 2 /* ModuleInstanceState.Instantiated */;
|
|
1046
|
+
}
|
|
1047
|
+
if (found !== 0 /* ModuleInstanceState.Unknown */)
|
|
1048
|
+
return found;
|
|
1049
|
+
}
|
|
1050
|
+
// Not found: it could be a value.
|
|
1051
|
+
return 2 /* ModuleInstanceState.Instantiated */;
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
function withAncestor(ancestors, node) {
|
|
1055
|
+
const result = ancestors.slice();
|
|
1056
|
+
result.push(node);
|
|
1057
|
+
return result;
|
|
1058
|
+
}
|
|
1059
|
+
// Text and error ranges
|
|
1060
|
+
/** Source text of `node` without leading trivia. */
|
|
1061
|
+
export function getSourceTextOfNode(file, node) {
|
|
1062
|
+
if (nodeIsMissing(node))
|
|
1063
|
+
return '';
|
|
1064
|
+
return file.text.substring(skipTrivia(file.text, node.pos), node.end);
|
|
1065
|
+
}
|
|
1066
|
+
/** A declaration name for messages: its source text, or `(Missing)`. */
|
|
1067
|
+
export function declarationNameToString(file, name) {
|
|
1068
|
+
if (name === undefined || name.pos === name.end)
|
|
1069
|
+
return '(Missing)';
|
|
1070
|
+
return getTextOfNode(file, name);
|
|
1071
|
+
}
|
|
1072
|
+
function getTextOfNode(file, node) {
|
|
1073
|
+
const text = getSourceTextOfNode(file, node);
|
|
1074
|
+
if ((node.flags & 268435456 /* NodeFlags.ReparserTransformedLiteral */) !== 0 && node.kind === 79 /* SyntaxKind.Identifier */)
|
|
1075
|
+
return getText(node);
|
|
1076
|
+
return text;
|
|
1077
|
+
}
|
|
1078
|
+
/** A text range, as `[pos, end)`. */
|
|
1079
|
+
export class TextRange {
|
|
1080
|
+
pos;
|
|
1081
|
+
end;
|
|
1082
|
+
constructor(pos, end) {
|
|
1083
|
+
this.pos = pos;
|
|
1084
|
+
this.end = end;
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
let rangeScanner;
|
|
1088
|
+
let rangeScannerFile;
|
|
1089
|
+
/** Forgets the file the range scanner last visited. */
|
|
1090
|
+
export function forgetRangeScannerFile() {
|
|
1091
|
+
rangeScanner = undefined;
|
|
1092
|
+
rangeScannerFile = undefined;
|
|
1093
|
+
}
|
|
1094
|
+
function scannerAt(file, pos) {
|
|
1095
|
+
let scanner = rangeScanner;
|
|
1096
|
+
if (scanner === undefined) {
|
|
1097
|
+
scanner = new Scanner();
|
|
1098
|
+
rangeScanner = scanner;
|
|
1099
|
+
}
|
|
1100
|
+
if (rangeScannerFile !== file) {
|
|
1101
|
+
scanner.setText(file.text);
|
|
1102
|
+
scanner.setLanguageVariant(file.languageVariant);
|
|
1103
|
+
rangeScannerFile = file;
|
|
1104
|
+
}
|
|
1105
|
+
scanner.resetTokenState(pos);
|
|
1106
|
+
scanner.scan();
|
|
1107
|
+
return scanner;
|
|
1108
|
+
}
|
|
1109
|
+
/** The token starting at or after `pos`. */
|
|
1110
|
+
export function getRangeOfTokenAtPosition(file, pos) {
|
|
1111
|
+
const scanner = scannerAt(file, pos);
|
|
1112
|
+
return new TextRange(scanner.getTokenStart(), scanner.getTokenEnd());
|
|
1113
|
+
}
|
|
1114
|
+
function isLineBreak(ch) {
|
|
1115
|
+
return ch === 0x0a || ch === 0x0d || ch === 0x2028 || ch === 0x2029;
|
|
1116
|
+
}
|
|
1117
|
+
function getErrorRangeForArrowFunction(file, node) {
|
|
1118
|
+
const text = file.text;
|
|
1119
|
+
const pos = skipTrivia(text, node.pos);
|
|
1120
|
+
const body = getBody(node);
|
|
1121
|
+
if (body !== undefined && body.kind === 242 /* SyntaxKind.Block */) {
|
|
1122
|
+
const lineStarts = file.lineStarts();
|
|
1123
|
+
const startLine = computeLineOfPosition(lineStarts, body.pos);
|
|
1124
|
+
const endLine = computeLineOfPosition(lineStarts, body.end);
|
|
1125
|
+
if (startLine < endLine) {
|
|
1126
|
+
// A multi-line arrow function: the span is its first line, including the line break.
|
|
1127
|
+
let end = lineStarts[startLine];
|
|
1128
|
+
while (end < text.length && !isLineBreak(text.charCodeAt(end)))
|
|
1129
|
+
end += 1;
|
|
1130
|
+
return new TextRange(pos, end);
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
return new TextRange(pos, node.end);
|
|
1134
|
+
}
|
|
1135
|
+
/** The `@satisfies` tag a reparsed `satisfies` expression came from. */
|
|
1136
|
+
function findOriginatingJSDocSatisfiesTag(file, node) {
|
|
1137
|
+
const targetType = node.type;
|
|
1138
|
+
if ((targetType.flags & 8 /* NodeFlags.Reparsed */) === 0)
|
|
1139
|
+
return undefined;
|
|
1140
|
+
for (let current = node.parent; current !== undefined; current = current.parent) {
|
|
1141
|
+
if ((current.flags & 2097152 /* NodeFlags.HasJSDoc */) === 0)
|
|
1142
|
+
continue;
|
|
1143
|
+
let first;
|
|
1144
|
+
for (const jsDoc of getJSDoc(file, current)) {
|
|
1145
|
+
if (!(jsDoc instanceof JSDoc))
|
|
1146
|
+
continue;
|
|
1147
|
+
const tagList = jsDoc.tags;
|
|
1148
|
+
if (tagList === undefined)
|
|
1149
|
+
continue;
|
|
1150
|
+
const tags = tagList.nodes;
|
|
1151
|
+
for (let i = 0; i < tags.length; i++) {
|
|
1152
|
+
const tag = tags[i];
|
|
1153
|
+
if (tag instanceof JSDocSatisfiesTag) {
|
|
1154
|
+
if (first === undefined)
|
|
1155
|
+
first = tag;
|
|
1156
|
+
const type = getType(tag.typeExpression);
|
|
1157
|
+
if (type !== undefined && type.pos === targetType.pos && type.end === targetType.end)
|
|
1158
|
+
return tag;
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
return first;
|
|
1163
|
+
}
|
|
1164
|
+
return undefined;
|
|
1165
|
+
}
|
|
1166
|
+
/** Where to report an error on `node`: usually its name, or its first token. */
|
|
1167
|
+
export function getErrorRangeForNode(file, node) {
|
|
1168
|
+
const text = file.text;
|
|
1169
|
+
let errorNode = node;
|
|
1170
|
+
switch (node.kind) {
|
|
1171
|
+
case 307 /* SyntaxKind.SourceFile */: {
|
|
1172
|
+
const pos = skipTrivia(text, 0);
|
|
1173
|
+
return pos === text.length ? new TextRange(0, 0) : getRangeOfTokenAtPosition(file, pos);
|
|
1174
|
+
}
|
|
1175
|
+
case 263 /* SyntaxKind.FunctionDeclaration */:
|
|
1176
|
+
case 175 /* SyntaxKind.MethodDeclaration */:
|
|
1177
|
+
if ((node.flags & 8 /* NodeFlags.Reparsed */) === 0)
|
|
1178
|
+
errorNode = getNameOfDeclaration(node);
|
|
1179
|
+
break;
|
|
1180
|
+
case 261 /* SyntaxKind.VariableDeclaration */:
|
|
1181
|
+
case 209 /* SyntaxKind.BindingElement */:
|
|
1182
|
+
case 264 /* SyntaxKind.ClassDeclaration */:
|
|
1183
|
+
case 265 /* SyntaxKind.InterfaceDeclaration */:
|
|
1184
|
+
case 268 /* SyntaxKind.ModuleDeclaration */:
|
|
1185
|
+
case 267 /* SyntaxKind.EnumDeclaration */:
|
|
1186
|
+
case 306 /* SyntaxKind.EnumMember */:
|
|
1187
|
+
case 219 /* SyntaxKind.FunctionExpression */:
|
|
1188
|
+
case 178 /* SyntaxKind.GetAccessor */:
|
|
1189
|
+
case 179 /* SyntaxKind.SetAccessor */:
|
|
1190
|
+
case 266 /* SyntaxKind.TypeAliasDeclaration */:
|
|
1191
|
+
case 345 /* SyntaxKind.JSTypeAliasDeclaration */:
|
|
1192
|
+
case 173 /* SyntaxKind.PropertyDeclaration */:
|
|
1193
|
+
case 172 /* SyntaxKind.PropertySignature */:
|
|
1194
|
+
case 275 /* SyntaxKind.NamespaceImport */:
|
|
1195
|
+
errorNode = getNameOfDeclaration(node);
|
|
1196
|
+
break;
|
|
1197
|
+
case 232 /* SyntaxKind.ClassExpression */:
|
|
1198
|
+
errorNode = getName(node);
|
|
1199
|
+
break;
|
|
1200
|
+
case 220 /* SyntaxKind.ArrowFunction */:
|
|
1201
|
+
return getErrorRangeForArrowFunction(file, node);
|
|
1202
|
+
case 297 /* SyntaxKind.CaseClause */:
|
|
1203
|
+
case 298 /* SyntaxKind.DefaultClause */: {
|
|
1204
|
+
const start = skipTrivia(text, node.pos);
|
|
1205
|
+
const statements = getStatements(node).nodes;
|
|
1206
|
+
return new TextRange(start, statements.length !== 0 ? statements[0].pos : node.end);
|
|
1207
|
+
}
|
|
1208
|
+
case 254 /* SyntaxKind.ReturnStatement */:
|
|
1209
|
+
case 230 /* SyntaxKind.YieldExpression */:
|
|
1210
|
+
return getRangeOfTokenAtPosition(file, skipTrivia(text, node.pos));
|
|
1211
|
+
case 239 /* SyntaxKind.SatisfiesExpression */: {
|
|
1212
|
+
const tag = findOriginatingJSDocSatisfiesTag(file, node);
|
|
1213
|
+
if (tag !== undefined)
|
|
1214
|
+
return getRangeOfTokenAtPosition(file, skipTrivia(text, getTagName(tag).pos));
|
|
1215
|
+
return getRangeOfTokenAtPosition(file, skipTrivia(text, getExpression(node).end));
|
|
1216
|
+
}
|
|
1217
|
+
case 177 /* SyntaxKind.Constructor */: {
|
|
1218
|
+
if ((node.flags & 8 /* NodeFlags.Reparsed */) !== 0)
|
|
1219
|
+
break;
|
|
1220
|
+
const scanner = scannerAt(file, node.pos);
|
|
1221
|
+
const start = scanner.getTokenStart();
|
|
1222
|
+
for (;;) {
|
|
1223
|
+
const token = scanner.getToken();
|
|
1224
|
+
if (token === 136 /* SyntaxKind.ConstructorKeyword */ ||
|
|
1225
|
+
token === 10 /* SyntaxKind.StringLiteral */ ||
|
|
1226
|
+
token === 1 /* SyntaxKind.EndOfFile */)
|
|
1227
|
+
break;
|
|
1228
|
+
scanner.scan();
|
|
1229
|
+
}
|
|
1230
|
+
return new TextRange(start, scanner.getTokenEnd());
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
// Without a better node, use the first token of the construct.
|
|
1234
|
+
if (errorNode === undefined)
|
|
1235
|
+
return getRangeOfTokenAtPosition(file, node.pos);
|
|
1236
|
+
let pos = errorNode.pos;
|
|
1237
|
+
if (!nodeIsMissing(errorNode) && errorNode.kind !== 11 /* SyntaxKind.JsxText */)
|
|
1238
|
+
pos = skipTrivia(text, pos);
|
|
1239
|
+
return new TextRange(pos, errorNode.end);
|
|
1240
|
+
}
|