tsc-ts 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -2
- package/dist/api/compiler/ast-utilities.d.ts +82 -0
- package/dist/api/compiler/ast-utilities.js +462 -0
- package/dist/api/compiler/ast.d.ts +2351 -0
- package/dist/api/compiler/ast.js +11212 -0
- package/dist/api/compiler/astnav.d.ts +37 -0
- package/dist/api/compiler/astnav.js +767 -0
- package/dist/api/compiler/binder-utilities.d.ts +182 -0
- package/dist/api/compiler/binder-utilities.js +1241 -0
- package/dist/api/compiler/binder.d.ts +33 -0
- package/dist/api/compiler/binder.js +2359 -0
- package/dist/api/compiler/character-codes.d.ts +161 -0
- package/dist/api/compiler/character-codes.js +160 -0
- package/dist/api/compiler/checker-calls.d.ts +46 -0
- package/dist/api/compiler/checker-calls.js +1641 -0
- package/dist/api/compiler/checker-classes.d.ts +30 -0
- package/dist/api/compiler/checker-classes.js +582 -0
- package/dist/api/compiler/checker-contextual.d.ts +77 -0
- package/dist/api/compiler/checker-contextual.js +1136 -0
- package/dist/api/compiler/checker-declaration-order.d.ts +12 -0
- package/dist/api/compiler/checker-declaration-order.js +357 -0
- package/dist/api/compiler/checker-declarations.d.ts +33 -0
- package/dist/api/compiler/checker-declarations.js +888 -0
- package/dist/api/compiler/checker-declared-types.d.ts +48 -0
- package/dist/api/compiler/checker-declared-types.js +788 -0
- package/dist/api/compiler/checker-decorators.d.ts +26 -0
- package/dist/api/compiler/checker-decorators.js +562 -0
- package/dist/api/compiler/checker-deprecation.d.ts +33 -0
- package/dist/api/compiler/checker-deprecation.js +314 -0
- package/dist/api/compiler/checker-destructuring.d.ts +34 -0
- package/dist/api/compiler/checker-destructuring.js +584 -0
- package/dist/api/compiler/checker-elaboration.d.ts +15 -0
- package/dist/api/compiler/checker-elaboration.js +291 -0
- package/dist/api/compiler/checker-emit-helpers.d.ts +58 -0
- package/dist/api/compiler/checker-emit-helpers.js +154 -0
- package/dist/api/compiler/checker-emit-resolver.d.ts +75 -0
- package/dist/api/compiler/checker-emit-resolver.js +580 -0
- package/dist/api/compiler/checker-evaluator.d.ts +27 -0
- package/dist/api/compiler/checker-evaluator.js +188 -0
- package/dist/api/compiler/checker-expressions.d.ts +67 -0
- package/dist/api/compiler/checker-expressions.js +1351 -0
- package/dist/api/compiler/checker-features.d.ts +6 -0
- package/dist/api/compiler/checker-features.js +354 -0
- package/dist/api/compiler/checker-flow.d.ts +86 -0
- package/dist/api/compiler/checker-flow.js +169 -0
- package/dist/api/compiler/checker-functions.d.ts +43 -0
- package/dist/api/compiler/checker-functions.js +1002 -0
- package/dist/api/compiler/checker-generated-code.d.ts +25 -0
- package/dist/api/compiler/checker-generated-code.js +168 -0
- package/dist/api/compiler/checker-globals.d.ts +14 -0
- package/dist/api/compiler/checker-globals.js +37 -0
- package/dist/api/compiler/checker-grammar.d.ts +35 -0
- package/dist/api/compiler/checker-grammar.js +2587 -0
- package/dist/api/compiler/checker-heritage.d.ts +28 -0
- package/dist/api/compiler/checker-heritage.js +901 -0
- package/dist/api/compiler/checker-inference.d.ts +179 -0
- package/dist/api/compiler/checker-inference.js +2105 -0
- package/dist/api/compiler/checker-iteration.d.ts +115 -0
- package/dist/api/compiler/checker-iteration.js +857 -0
- package/dist/api/compiler/checker-javascript.d.ts +42 -0
- package/dist/api/compiler/checker-javascript.js +442 -0
- package/dist/api/compiler/checker-jsdoc.d.ts +30 -0
- package/dist/api/compiler/checker-jsdoc.js +320 -0
- package/dist/api/compiler/checker-jsx.d.ts +94 -0
- package/dist/api/compiler/checker-jsx.js +1433 -0
- package/dist/api/compiler/checker-literals.d.ts +6 -0
- package/dist/api/compiler/checker-literals.js +43 -0
- package/dist/api/compiler/checker-members.d.ts +200 -0
- package/dist/api/compiler/checker-members.js +2148 -0
- package/dist/api/compiler/checker-modules.d.ts +85 -0
- package/dist/api/compiler/checker-modules.js +2141 -0
- package/dist/api/compiler/checker-narrowing.d.ts +120 -0
- package/dist/api/compiler/checker-narrowing.js +2797 -0
- package/dist/api/compiler/checker-object-literals.d.ts +14 -0
- package/dist/api/compiler/checker-object-literals.js +483 -0
- package/dist/api/compiler/checker-operators.d.ts +33 -0
- package/dist/api/compiler/checker-operators.js +1040 -0
- package/dist/api/compiler/checker-overloads.d.ts +7 -0
- package/dist/api/compiler/checker-overloads.js +271 -0
- package/dist/api/compiler/checker-property-access.d.ts +34 -0
- package/dist/api/compiler/checker-property-access.js +672 -0
- package/dist/api/compiler/checker-services.d.ts +49 -0
- package/dist/api/compiler/checker-services.js +995 -0
- package/dist/api/compiler/checker-signatures.d.ts +55 -0
- package/dist/api/compiler/checker-signatures.js +789 -0
- package/dist/api/compiler/checker-source-file.d.ts +27 -0
- package/dist/api/compiler/checker-source-file.js +619 -0
- package/dist/api/compiler/checker-statements.d.ts +18 -0
- package/dist/api/compiler/checker-statements.js +226 -0
- package/dist/api/compiler/checker-super.d.ts +13 -0
- package/dist/api/compiler/checker-super.js +241 -0
- package/dist/api/compiler/checker-symbol-types.d.ts +51 -0
- package/dist/api/compiler/checker-symbol-types.js +955 -0
- package/dist/api/compiler/checker-symbols.d.ts +181 -0
- package/dist/api/compiler/checker-symbols.js +1784 -0
- package/dist/api/compiler/checker-type-factory.d.ts +142 -0
- package/dist/api/compiler/checker-type-factory.js +2542 -0
- package/dist/api/compiler/checker-type-nodes.d.ts +26 -0
- package/dist/api/compiler/checker-type-nodes.js +828 -0
- package/dist/api/compiler/checker-type-operators.d.ts +109 -0
- package/dist/api/compiler/checker-type-operators.js +1842 -0
- package/dist/api/compiler/checker-types.d.ts +1093 -0
- package/dist/api/compiler/checker-types.js +1874 -0
- package/dist/api/compiler/checker-unused.d.ts +19 -0
- package/dist/api/compiler/checker-unused.js +524 -0
- package/dist/api/compiler/checker-utilities.d.ts +33 -0
- package/dist/api/compiler/checker-utilities.js +141 -0
- package/dist/api/compiler/checker.d.ts +512 -0
- package/dist/api/compiler/checker.js +932 -0
- package/dist/api/compiler/command-line.d.ts +32 -0
- package/dist/api/compiler/command-line.js +383 -0
- package/dist/api/compiler/compile-program.d.ts +118 -0
- package/dist/api/compiler/compile-program.js +384 -0
- package/dist/api/compiler/diagnostic-locales.d.ts +22 -0
- package/dist/api/compiler/diagnostic-locales.js +64 -0
- package/dist/api/compiler/diagnostic-messages.d.ts +2166 -0
- package/dist/api/compiler/diagnostic-messages.js +184 -0
- package/dist/api/compiler/diagnostics.d.ts +161 -0
- package/dist/api/compiler/diagnostics.js +784 -0
- package/dist/api/compiler/emitter.d.ts +71 -0
- package/dist/api/compiler/emitter.js +327 -0
- package/dist/api/compiler/file-include.d.ts +144 -0
- package/dist/api/compiler/file-include.js +599 -0
- package/dist/api/compiler/file-loader.d.ts +290 -0
- package/dist/api/compiler/file-loader.js +1323 -0
- package/dist/api/compiler/file-system.d.ts +51 -0
- package/dist/api/compiler/file-system.js +132 -0
- package/dist/api/compiler/flow.d.ts +60 -0
- package/dist/api/compiler/flow.js +45 -0
- package/dist/api/compiler/instantiation.d.ts +74 -0
- package/dist/api/compiler/instantiation.js +835 -0
- package/dist/api/compiler/jsdoc.d.ts +75 -0
- package/dist/api/compiler/jsdoc.js +1229 -0
- package/dist/api/compiler/link-tables.d.ts +105 -0
- package/dist/api/compiler/link-tables.js +319 -0
- package/dist/api/compiler/locale-data.d.ts +24 -0
- package/dist/api/compiler/locale-data.js +183 -0
- package/dist/api/compiler/locale.d.ts +4 -0
- package/dist/api/compiler/locale.js +317 -0
- package/dist/api/compiler/locales/cs-CZ.d.ts +2 -0
- package/dist/api/compiler/locales/cs-CZ.js +3 -0
- package/dist/api/compiler/locales/de-DE.d.ts +2 -0
- package/dist/api/compiler/locales/de-DE.js +3 -0
- package/dist/api/compiler/locales/es-ES.d.ts +2 -0
- package/dist/api/compiler/locales/es-ES.js +3 -0
- package/dist/api/compiler/locales/fr-FR.d.ts +2 -0
- package/dist/api/compiler/locales/fr-FR.js +3 -0
- package/dist/api/compiler/locales/it-IT.d.ts +2 -0
- package/dist/api/compiler/locales/it-IT.js +3 -0
- package/dist/api/compiler/locales/ja-JP.d.ts +2 -0
- package/dist/api/compiler/locales/ja-JP.js +3 -0
- package/dist/api/compiler/locales/ko-KR.d.ts +2 -0
- package/dist/api/compiler/locales/ko-KR.js +3 -0
- package/dist/api/compiler/locales/pl-PL.d.ts +2 -0
- package/dist/api/compiler/locales/pl-PL.js +3 -0
- package/dist/api/compiler/locales/pt-BR.d.ts +2 -0
- package/dist/api/compiler/locales/pt-BR.js +3 -0
- package/dist/api/compiler/locales/ru-RU.d.ts +2 -0
- package/dist/api/compiler/locales/ru-RU.js +3 -0
- package/dist/api/compiler/locales/tr-TR.d.ts +2 -0
- package/dist/api/compiler/locales/tr-TR.js +3 -0
- package/dist/api/compiler/locales/zh-CN.d.ts +2 -0
- package/dist/api/compiler/locales/zh-CN.js +3 -0
- package/dist/api/compiler/locales/zh-TW.d.ts +2 -0
- package/dist/api/compiler/locales/zh-TW.js +3 -0
- package/dist/api/compiler/module-resolution-types.d.ts +83 -0
- package/dist/api/compiler/module-resolution-types.js +176 -0
- package/dist/api/compiler/module-resolution.d.ts +71 -0
- package/dist/api/compiler/module-resolution.js +1598 -0
- package/dist/api/compiler/module-specifiers.d.ts +64 -0
- package/dist/api/compiler/module-specifiers.js +1101 -0
- package/dist/api/compiler/name-resolver.d.ts +43 -0
- package/dist/api/compiler/name-resolver.js +509 -0
- package/dist/api/compiler/node-builder-names.d.ts +32 -0
- package/dist/api/compiler/node-builder-names.js +854 -0
- package/dist/api/compiler/node-builder-pseudo.d.ts +36 -0
- package/dist/api/compiler/node-builder-pseudo.js +745 -0
- package/dist/api/compiler/node-builder-reuse.d.ts +4 -0
- package/dist/api/compiler/node-builder-reuse.js +647 -0
- package/dist/api/compiler/node-builder.d.ts +270 -0
- package/dist/api/compiler/node-builder.js +2645 -0
- package/dist/api/compiler/option-declarations.d.ts +90 -0
- package/dist/api/compiler/option-declarations.js +1460 -0
- package/dist/api/compiler/options.d.ts +289 -0
- package/dist/api/compiler/options.js +1197 -0
- package/dist/api/compiler/output-paths.d.ts +42 -0
- package/dist/api/compiler/output-paths.js +195 -0
- package/dist/api/compiler/package-json.d.ts +175 -0
- package/dist/api/compiler/package-json.js +1015 -0
- package/dist/api/compiler/parallel-parse.d.ts +221 -0
- package/dist/api/compiler/parallel-parse.js +541 -0
- package/dist/api/compiler/parser.d.ts +604 -0
- package/dist/api/compiler/parser.js +6426 -0
- package/dist/api/compiler/path.d.ts +91 -0
- package/dist/api/compiler/path.js +705 -0
- package/dist/api/compiler/printer/async-helpers.d.ts +22 -0
- package/dist/api/compiler/printer/async-helpers.js +91 -0
- package/dist/api/compiler/printer/auto-generate.d.ts +13 -0
- package/dist/api/compiler/printer/auto-generate.js +20 -0
- package/dist/api/compiler/printer/decorator-helpers.d.ts +24 -0
- package/dist/api/compiler/printer/decorator-helpers.js +118 -0
- package/dist/api/compiler/printer/emit-context.d.ts +157 -0
- package/dist/api/compiler/printer/emit-context.js +582 -0
- package/dist/api/compiler/printer/emit-flags.d.ts +60 -0
- package/dist/api/compiler/printer/emit-flags.js +2 -0
- package/dist/api/compiler/printer/factory-base.d.ts +171 -0
- package/dist/api/compiler/printer/factory-base.js +1505 -0
- package/dist/api/compiler/printer/factory.d.ts +147 -0
- package/dist/api/compiler/printer/factory.js +542 -0
- package/dist/api/compiler/printer/helpers.d.ts +27 -0
- package/dist/api/compiler/printer/helpers.js +164 -0
- package/dist/api/compiler/printer/name-generator.d.ts +41 -0
- package/dist/api/compiler/printer/name-generator.js +283 -0
- package/dist/api/compiler/printer/printer.d.ts +411 -0
- package/dist/api/compiler/printer/printer.js +4517 -0
- package/dist/api/compiler/printer/text-writer.d.ts +46 -0
- package/dist/api/compiler/printer/text-writer.js +172 -0
- package/dist/api/compiler/printer/utilities.d.ts +82 -0
- package/dist/api/compiler/printer/utilities.js +817 -0
- package/dist/api/compiler/program-checker.d.ts +156 -0
- package/dist/api/compiler/program-checker.js +529 -0
- package/dist/api/compiler/program-utilities.d.ts +52 -0
- package/dist/api/compiler/program-utilities.js +365 -0
- package/dist/api/compiler/program.d.ts +180 -0
- package/dist/api/compiler/program.js +1019 -0
- package/dist/api/compiler/pseudo-bigint.d.ts +5 -0
- package/dist/api/compiler/pseudo-bigint.js +61 -0
- package/dist/api/compiler/regexp-checker.d.ts +38 -0
- package/dist/api/compiler/regexp-checker.js +942 -0
- package/dist/api/compiler/relations.d.ts +263 -0
- package/dist/api/compiler/relations.js +4002 -0
- package/dist/api/compiler/reparser.d.ts +48 -0
- package/dist/api/compiler/reparser.js +1323 -0
- package/dist/api/compiler/scanner.d.ts +256 -0
- package/dist/api/compiler/scanner.js +2853 -0
- package/dist/api/compiler/side-state.d.ts +16 -0
- package/dist/api/compiler/side-state.js +89 -0
- package/dist/api/compiler/sourcemap.d.ts +55 -0
- package/dist/api/compiler/sourcemap.js +340 -0
- package/dist/api/compiler/spelling.d.ts +14 -0
- package/dist/api/compiler/spelling.js +128 -0
- package/dist/api/compiler/symbol-accessibility.d.ts +57 -0
- package/dist/api/compiler/symbol-accessibility.js +991 -0
- package/dist/api/compiler/symbol.d.ts +282 -0
- package/dist/api/compiler/symbol.js +339 -0
- package/dist/api/compiler/symlinks.d.ts +32 -0
- package/dist/api/compiler/symlinks.js +114 -0
- package/dist/api/compiler/syntax-kind.d.ts +389 -0
- package/dist/api/compiler/syntax-kind.js +2 -0
- package/dist/api/compiler/timeline.d.ts +9 -0
- package/dist/api/compiler/timeline.js +54 -0
- package/dist/api/compiler/transformers/alias-references.d.ts +39 -0
- package/dist/api/compiler/transformers/alias-references.js +677 -0
- package/dist/api/compiler/transformers/async-utilities.d.ts +51 -0
- package/dist/api/compiler/transformers/async-utilities.js +260 -0
- package/dist/api/compiler/transformers/async.d.ts +53 -0
- package/dist/api/compiler/transformers/async.js +645 -0
- package/dist/api/compiler/transformers/class-fields.d.ts +206 -0
- package/dist/api/compiler/transformers/class-fields.js +2418 -0
- package/dist/api/compiler/transformers/class-utilities.d.ts +46 -0
- package/dist/api/compiler/transformers/class-utilities.js +261 -0
- package/dist/api/compiler/transformers/commonjs-module.d.ts +103 -0
- package/dist/api/compiler/transformers/commonjs-module.js +1180 -0
- package/dist/api/compiler/transformers/const-enum-inliner.d.ts +11 -0
- package/dist/api/compiler/transformers/const-enum-inliner.js +36 -0
- package/dist/api/compiler/transformers/declarations-diagnostics.d.ts +52 -0
- package/dist/api/compiler/transformers/declarations-diagnostics.js +539 -0
- package/dist/api/compiler/transformers/declarations-pseudo.d.ts +160 -0
- package/dist/api/compiler/transformers/declarations-pseudo.js +799 -0
- package/dist/api/compiler/transformers/declarations-resolver.d.ts +152 -0
- package/dist/api/compiler/transformers/declarations-resolver.js +35 -0
- package/dist/api/compiler/transformers/declarations-syntactic.d.ts +119 -0
- package/dist/api/compiler/transformers/declarations-syntactic.js +1582 -0
- package/dist/api/compiler/transformers/declarations-tracker.d.ts +46 -0
- package/dist/api/compiler/transformers/declarations-tracker.js +198 -0
- package/dist/api/compiler/transformers/declarations.d.ts +175 -0
- package/dist/api/compiler/transformers/declarations.js +2381 -0
- package/dist/api/compiler/transformers/decorator-metadata.d.ts +54 -0
- package/dist/api/compiler/transformers/decorator-metadata.js +554 -0
- package/dist/api/compiler/transformers/decorator-utilities.d.ts +38 -0
- package/dist/api/compiler/transformers/decorator-utilities.js +238 -0
- package/dist/api/compiler/transformers/destructuring.d.ts +25 -0
- package/dist/api/compiler/transformers/destructuring.js +626 -0
- package/dist/api/compiler/transformers/downlevel.d.ts +6 -0
- package/dist/api/compiler/transformers/downlevel.js +45 -0
- package/dist/api/compiler/transformers/emit-resolver.d.ts +61 -0
- package/dist/api/compiler/transformers/emit-resolver.js +197 -0
- package/dist/api/compiler/transformers/es-decorators.d.ts +118 -0
- package/dist/api/compiler/transformers/es-decorators.js +1901 -0
- package/dist/api/compiler/transformers/exponentiation.d.ts +11 -0
- package/dist/api/compiler/transformers/exponentiation.js +76 -0
- package/dist/api/compiler/transformers/external-module-info.d.ts +35 -0
- package/dist/api/compiler/transformers/external-module-info.js +351 -0
- package/dist/api/compiler/transformers/for-await.d.ts +43 -0
- package/dist/api/compiler/transformers/for-await.js +469 -0
- package/dist/api/compiler/transformers/import-elision.d.ts +16 -0
- package/dist/api/compiler/transformers/import-elision.js +124 -0
- package/dist/api/compiler/transformers/jsx-entities.d.ts +1 -0
- package/dist/api/compiler/transformers/jsx-entities.js +256 -0
- package/dist/api/compiler/transformers/jsx.d.ts +71 -0
- package/dist/api/compiler/transformers/jsx.js +700 -0
- package/dist/api/compiler/transformers/legacy-decorators.d.ts +56 -0
- package/dist/api/compiler/transformers/legacy-decorators.js +564 -0
- package/dist/api/compiler/transformers/logical-assignment.d.ts +14 -0
- package/dist/api/compiler/transformers/logical-assignment.js +62 -0
- package/dist/api/compiler/transformers/module-utilities.d.ts +9 -0
- package/dist/api/compiler/transformers/module-utilities.js +36 -0
- package/dist/api/compiler/transformers/module.d.ts +49 -0
- package/dist/api/compiler/transformers/module.js +296 -0
- package/dist/api/compiler/transformers/named-evaluation.d.ts +26 -0
- package/dist/api/compiler/transformers/named-evaluation.js +266 -0
- package/dist/api/compiler/transformers/nullish-coalescing.d.ts +9 -0
- package/dist/api/compiler/transformers/nullish-coalescing.js +26 -0
- package/dist/api/compiler/transformers/object-rest-spread.d.ts +34 -0
- package/dist/api/compiler/transformers/object-rest-spread.js +411 -0
- package/dist/api/compiler/transformers/optional-catch.d.ts +9 -0
- package/dist/api/compiler/transformers/optional-catch.js +20 -0
- package/dist/api/compiler/transformers/optional-chain.d.ts +14 -0
- package/dist/api/compiler/transformers/optional-chain.js +188 -0
- package/dist/api/compiler/transformers/reference-resolver.d.ts +129 -0
- package/dist/api/compiler/transformers/reference-resolver.js +1157 -0
- package/dist/api/compiler/transformers/runtime-syntax.d.ts +71 -0
- package/dist/api/compiler/transformers/runtime-syntax.js +753 -0
- package/dist/api/compiler/transformers/subtree-facts.d.ts +10 -0
- package/dist/api/compiler/transformers/subtree-facts.js +205 -0
- package/dist/api/compiler/transformers/syntax-facts.d.ts +52 -0
- package/dist/api/compiler/transformers/syntax-facts.js +258 -0
- package/dist/api/compiler/transformers/tagged-template.d.ts +17 -0
- package/dist/api/compiler/transformers/tagged-template.js +148 -0
- package/dist/api/compiler/transformers/transformer.d.ts +17 -0
- package/dist/api/compiler/transformers/transformer.js +54 -0
- package/dist/api/compiler/transformers/type-eraser.d.ts +21 -0
- package/dist/api/compiler/transformers/type-eraser.js +346 -0
- package/dist/api/compiler/transformers/type-serialization.d.ts +20 -0
- package/dist/api/compiler/transformers/type-serialization.js +347 -0
- package/dist/api/compiler/transformers/using.d.ts +56 -0
- package/dist/api/compiler/transformers/using.js +453 -0
- package/dist/api/compiler/transformers/utilities.d.ts +50 -0
- package/dist/api/compiler/transformers/utilities.js +347 -0
- package/dist/api/compiler/transformers/visitor-base.d.ts +6 -0
- package/dist/api/compiler/transformers/visitor-base.js +817 -0
- package/dist/api/compiler/transformers/visitor-hooks.d.ts +29 -0
- package/dist/api/compiler/transformers/visitor-hooks.js +189 -0
- package/dist/api/compiler/tsconfig.d.ts +177 -0
- package/dist/api/compiler/tsconfig.js +1311 -0
- package/dist/api/compiler/type-printer.d.ts +15 -0
- package/dist/api/compiler/type-printer.js +74 -0
- package/dist/api/compiler/types.d.ts +87 -0
- package/dist/api/compiler/types.js +23 -0
- package/dist/api/compiler/unicode-identifiers.d.ts +2 -0
- package/dist/api/compiler/unicode-identifiers.js +209 -0
- package/dist/api/compiler/unicode-properties.d.ts +8 -0
- package/dist/api/compiler/unicode-properties.js +531 -0
- package/dist/api/compiler/vfs-match.d.ts +24 -0
- package/dist/api/compiler/vfs-match.js +587 -0
- package/dist/api/library/ast.d.ts +3 -2
- package/dist/api/library/ast.generated.d.ts +127 -139
- package/dist/api/library/checker.d.ts +51 -0
- package/dist/api/library/checker.js +318 -0
- package/dist/api/library/diagnostics.d.ts +13 -0
- package/dist/api/library/diagnostics.js +50 -0
- package/dist/api/library/disk.d.ts +13 -0
- package/dist/api/library/disk.js +66 -0
- package/dist/api/library/errors.d.ts +13 -0
- package/dist/api/library/errors.js +24 -0
- package/dist/api/library/host.d.ts +24 -0
- package/dist/api/library/host.js +52 -0
- package/dist/api/library/index.d.ts +5 -1
- package/dist/api/library/index.js +4 -0
- package/dist/api/library/nodes.d.ts +51 -0
- package/dist/api/library/nodes.js +196 -0
- package/dist/api/library/options.d.ts +144 -0
- package/dist/api/library/options.js +308 -0
- package/dist/api/library/parse.d.ts +19 -0
- package/dist/api/library/parse.js +41 -0
- package/dist/api/library/program.d.ts +21 -0
- package/dist/api/library/program.js +234 -0
- package/dist/api/library/types.d.ts +14 -1
- package/package.json +12 -8
- package/src/compiler/ast-utilities.ts +548 -0
- package/src/compiler/ast.ts +12870 -0
- package/src/compiler/astnav.ts +799 -0
- package/src/compiler/binder-utilities.ts +1392 -0
- package/src/compiler/binder.ts +2707 -0
- package/src/compiler/build-info.ts +1197 -0
- package/src/compiler/character-codes.ts +323 -0
- package/src/compiler/checker-calls.ts +2155 -0
- package/src/compiler/checker-classes.ts +706 -0
- package/src/compiler/checker-contextual.ts +1457 -0
- package/src/compiler/checker-declaration-order.ts +438 -0
- package/src/compiler/checker-declarations.ts +1201 -0
- package/src/compiler/checker-declared-types.ts +919 -0
- package/src/compiler/checker-decorators.ts +694 -0
- package/src/compiler/checker-deprecation.ts +355 -0
- package/src/compiler/checker-destructuring.ts +805 -0
- package/src/compiler/checker-elaboration.ts +477 -0
- package/src/compiler/checker-emit-helpers.ts +224 -0
- package/src/compiler/checker-emit-resolver.ts +769 -0
- package/src/compiler/checker-evaluator.ts +243 -0
- package/src/compiler/checker-expressions.ts +1831 -0
- package/src/compiler/checker-features.ts +361 -0
- package/src/compiler/checker-flow.ts +394 -0
- package/src/compiler/checker-functions.ts +1296 -0
- package/src/compiler/checker-generated-code.ts +227 -0
- package/src/compiler/checker-globals.ts +52 -0
- package/src/compiler/checker-grammar.ts +3596 -0
- package/src/compiler/checker-heritage.ts +1240 -0
- package/src/compiler/checker-inference.ts +2584 -0
- package/src/compiler/checker-iteration.ts +1206 -0
- package/src/compiler/checker-javascript.ts +502 -0
- package/src/compiler/checker-jsdoc.ts +360 -0
- package/src/compiler/checker-jsx.ts +1928 -0
- package/src/compiler/checker-literals.ts +61 -0
- package/src/compiler/checker-members.ts +2480 -0
- package/src/compiler/checker-modules.ts +2896 -0
- package/src/compiler/checker-narrowing.ts +3230 -0
- package/src/compiler/checker-object-literals.ts +591 -0
- package/src/compiler/checker-operators.ts +1422 -0
- package/src/compiler/checker-overloads.ts +328 -0
- package/src/compiler/checker-property-access.ts +906 -0
- package/src/compiler/checker-services.ts +1149 -0
- package/src/compiler/checker-signatures.ts +1032 -0
- package/src/compiler/checker-source-file.ts +732 -0
- package/src/compiler/checker-statements.ts +292 -0
- package/src/compiler/checker-super.ts +261 -0
- package/src/compiler/checker-symbol-types.ts +1187 -0
- package/src/compiler/checker-symbols.ts +2157 -0
- package/src/compiler/checker-type-factory.ts +2616 -0
- package/src/compiler/checker-type-nodes.ts +1033 -0
- package/src/compiler/checker-type-operators.ts +2510 -0
- package/src/compiler/checker-types.ts +2520 -0
- package/src/compiler/checker-unused.ts +642 -0
- package/src/compiler/checker-utilities.ts +161 -0
- package/src/compiler/checker.ts +1138 -0
- package/src/compiler/command-line.ts +436 -0
- package/src/compiler/compile-program.ts +439 -0
- package/src/compiler/decoder.ts +1209 -0
- package/src/compiler/diagnostic-locales.ts +86 -0
- package/src/compiler/diagnostic-messages.ts +2349 -0
- package/src/compiler/diagnostics.ts +858 -0
- package/src/compiler/emitter.ts +434 -0
- package/src/compiler/encoder.ts +1945 -0
- package/src/compiler/file-include.ts +741 -0
- package/src/compiler/file-loader.ts +1597 -0
- package/src/compiler/file-system.ts +143 -0
- package/src/compiler/flow.ts +89 -0
- package/src/compiler/help.ts +473 -0
- package/src/compiler/incremental.ts +2818 -0
- package/src/compiler/init.ts +141 -0
- package/src/compiler/instantiation.ts +938 -0
- package/src/compiler/jsdoc.ts +1386 -0
- package/src/compiler/link-tables.ts +343 -0
- package/src/compiler/locale-data.ts +203 -0
- package/src/compiler/locale.ts +307 -0
- package/src/compiler/locales/cs-CZ.ts +5 -0
- package/src/compiler/locales/de-DE.ts +5 -0
- package/src/compiler/locales/es-ES.ts +5 -0
- package/src/compiler/locales/fr-FR.ts +5 -0
- package/src/compiler/locales/it-IT.ts +5 -0
- package/src/compiler/locales/ja-JP.ts +5 -0
- package/src/compiler/locales/ko-KR.ts +5 -0
- package/src/compiler/locales/pl-PL.ts +5 -0
- package/src/compiler/locales/pt-BR.ts +5 -0
- package/src/compiler/locales/ru-RU.ts +5 -0
- package/src/compiler/locales/tr-TR.ts +5 -0
- package/src/compiler/locales/zh-CN.ts +5 -0
- package/src/compiler/locales/zh-TW.ts +5 -0
- package/src/compiler/module-resolution-types.ts +243 -0
- package/src/compiler/module-resolution.ts +2072 -0
- package/src/compiler/module-specifiers.ts +1491 -0
- package/src/compiler/name-resolver.ts +646 -0
- package/src/compiler/node-builder-names.ts +1071 -0
- package/src/compiler/node-builder-pseudo.ts +892 -0
- package/src/compiler/node-builder-reuse.ts +764 -0
- package/src/compiler/node-builder.ts +3433 -0
- package/src/compiler/option-declarations.ts +1560 -0
- package/src/compiler/options.ts +1576 -0
- package/src/compiler/output-paths.ts +334 -0
- package/src/compiler/package-json.ts +1083 -0
- package/src/compiler/parallel-check.ts +1954 -0
- package/src/compiler/parallel-parse.ts +595 -0
- package/src/compiler/parse-thread.ts +136 -0
- package/src/compiler/parser.ts +7766 -0
- package/src/compiler/path.ts +717 -0
- package/src/compiler/printer/async-helpers.ts +183 -0
- package/src/compiler/printer/auto-generate.ts +27 -0
- package/src/compiler/printer/decorator-helpers.ts +218 -0
- package/src/compiler/printer/emit-context.ts +684 -0
- package/src/compiler/printer/emit-flags.ts +64 -0
- package/src/compiler/printer/factory-base.ts +2577 -0
- package/src/compiler/printer/factory.ts +764 -0
- package/src/compiler/printer/helpers.ts +291 -0
- package/src/compiler/printer/name-generator.ts +372 -0
- package/src/compiler/printer/printer.ts +5072 -0
- package/src/compiler/printer/text-writer.ts +183 -0
- package/src/compiler/printer/utilities.ts +884 -0
- package/src/compiler/program-checker.ts +594 -0
- package/src/compiler/program-utilities.ts +435 -0
- package/src/compiler/program.ts +1426 -0
- package/src/compiler/pseudo-bigint.ts +62 -0
- package/src/compiler/regexp-checker.ts +1142 -0
- package/src/compiler/relations.ts +5149 -0
- package/src/compiler/reparser.ts +1566 -0
- package/src/compiler/scanner.ts +2951 -0
- package/src/compiler/show-config.ts +239 -0
- package/src/compiler/side-state.ts +125 -0
- package/src/compiler/sourcemap.ts +366 -0
- package/src/compiler/spelling.ts +122 -0
- package/src/compiler/symbol-accessibility.ts +1166 -0
- package/src/compiler/symbol.ts +557 -0
- package/src/compiler/symlinks.ts +137 -0
- package/src/compiler/syntax-kind.ts +391 -0
- package/src/compiler/thread-entry.ts +191 -0
- package/src/compiler/timeline.ts +53 -0
- package/src/compiler/transformers/alias-references.ts +757 -0
- package/src/compiler/transformers/async-utilities.ts +335 -0
- package/src/compiler/transformers/async.ts +838 -0
- package/src/compiler/transformers/class-fields.ts +2967 -0
- package/src/compiler/transformers/class-utilities.ts +324 -0
- package/src/compiler/transformers/commonjs-module.ts +1621 -0
- package/src/compiler/transformers/const-enum-inliner.ts +50 -0
- package/src/compiler/transformers/declarations-diagnostics.ts +833 -0
- package/src/compiler/transformers/declarations-pseudo.ts +969 -0
- package/src/compiler/transformers/declarations-resolver.ts +249 -0
- package/src/compiler/transformers/declarations-syntactic.ts +1867 -0
- package/src/compiler/transformers/declarations-tracker.ts +269 -0
- package/src/compiler/transformers/declarations.ts +3120 -0
- package/src/compiler/transformers/decorator-metadata.ts +697 -0
- package/src/compiler/transformers/decorator-utilities.ts +283 -0
- package/src/compiler/transformers/destructuring.ts +708 -0
- package/src/compiler/transformers/downlevel.ts +50 -0
- package/src/compiler/transformers/emit-resolver.ts +258 -0
- package/src/compiler/transformers/es-decorators.ts +2682 -0
- package/src/compiler/transformers/exponentiation.ts +80 -0
- package/src/compiler/transformers/external-module-info.ts +412 -0
- package/src/compiler/transformers/for-await.ts +687 -0
- package/src/compiler/transformers/import-elision.ts +152 -0
- package/src/compiler/transformers/jsx-entities.ts +256 -0
- package/src/compiler/transformers/jsx.ts +824 -0
- package/src/compiler/transformers/legacy-decorators.ts +726 -0
- package/src/compiler/transformers/logical-assignment.ts +75 -0
- package/src/compiler/transformers/module-utilities.ts +42 -0
- package/src/compiler/transformers/module.ts +474 -0
- package/src/compiler/transformers/named-evaluation.ts +389 -0
- package/src/compiler/transformers/nullish-coalescing.ts +35 -0
- package/src/compiler/transformers/object-rest-spread.ts +577 -0
- package/src/compiler/transformers/optional-catch.ts +29 -0
- package/src/compiler/transformers/optional-chain.ts +246 -0
- package/src/compiler/transformers/reference-resolver.ts +1213 -0
- package/src/compiler/transformers/runtime-syntax.ts +942 -0
- package/src/compiler/transformers/subtree-facts.ts +253 -0
- package/src/compiler/transformers/syntax-facts.ts +358 -0
- package/src/compiler/transformers/tagged-template.ts +167 -0
- package/src/compiler/transformers/transformer.ts +56 -0
- package/src/compiler/transformers/type-eraser.ts +520 -0
- package/src/compiler/transformers/type-serialization.ts +374 -0
- package/src/compiler/transformers/using.ts +613 -0
- package/src/compiler/transformers/utilities.ts +419 -0
- package/src/compiler/transformers/visitor-base.ts +1601 -0
- package/src/compiler/transformers/visitor-hooks.ts +252 -0
- package/src/compiler/tsc-build.ts +1422 -0
- package/src/compiler/tsc-cli.ts +669 -0
- package/src/compiler/tsc-compile.ts +446 -0
- package/src/compiler/tsc-watch.ts +922 -0
- package/src/compiler/tsconfig.ts +1574 -0
- package/src/compiler/type-printer.ts +110 -0
- package/src/compiler/types.ts +115 -0
- package/src/compiler/unicode-identifiers.ts +212 -0
- package/src/compiler/unicode-properties.ts +537 -0
- package/src/compiler/vfs-match.ts +597 -0
- package/src/compiler/xxh3.ts +650 -0
- package/src/library/ast.generated.ts +141 -167
- package/src/library/ast.ts +4 -1
- package/src/library/checker.ts +384 -0
- package/src/library/diagnostics.ts +72 -0
- package/src/library/disk.ts +73 -0
- package/src/library/errors.ts +26 -0
- package/src/library/host.ts +63 -0
- package/src/library/index.ts +21 -0
- package/src/library/nodes.ts +232 -0
- package/src/library/options.ts +449 -0
- package/src/library/parse.ts +63 -0
- package/src/library/program.ts +293 -0
- package/src/library/types.ts +14 -1
|
@@ -0,0 +1,1323 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds every file of a program: root files, libraries, references, imports and type directives, in tsgo's order.
|
|
3
|
+
*/
|
|
4
|
+
import { ImportDeclaration, ParseOptions, StringLiteral, getText, } from './ast.js';
|
|
5
|
+
import { FileIncludeReason, IncludeProcessor, ProcessingDiagnostic } from './file-include.js';
|
|
6
|
+
import { ModuleResolutionHost, Resolver, getAutomaticTypeDirectiveNames } from './module-resolution.js';
|
|
7
|
+
import { getResolutionDiagnostic, inferredTypesContainingFile, } from './module-resolution-types.js';
|
|
8
|
+
import { getAllowJS, getIsolatedModules, getModuleResolutionKind, ModuleKind, ModuleResolutionKind, } from './options.js';
|
|
9
|
+
import { isPrepared, preparedLoad, preparedPackageJsonLookups, takePreparedFile, } from './parallel-parse.js';
|
|
10
|
+
import { parseSourceFile } from './parser.js';
|
|
11
|
+
import { mark } from './timeline.js';
|
|
12
|
+
import { combinePaths, fileExtensionIsOneOf, getCanonicalFileName, getDirectoryPath, getNormalizedAbsolutePath, getRootLength, hasJSFileExtension, isRootedDiskPath, normalizePath, normalizeSlashes, removeTrailingDirectorySeparator, supportedTSExtensionsWithJsonFlat, toFileNameLowerCase, toPath, } from './path.js';
|
|
13
|
+
import { getDefaultLibFileName, getDefaultResolutionModeForFile, getExternalModuleIndicatorOptions, getImpliedNodeFormatForFile, getJSXImplicitImportBase, getJSXRuntimeImport, getLibFileName, getModeForUsageLocation, isExternalModule, isSourceFileJS, libFileMetadata, libNames, SourceFileMetadata, } from './program-utilities.js';
|
|
14
|
+
import { hasExtension } from './vfs-match.js';
|
|
15
|
+
import { ConfigParser, flattenExtensions, getSupportedExtensions, getSupportedExtensionsWithJsonIfResolveJsonModule, } from './tsconfig.js';
|
|
16
|
+
/** Files and services the compiler reads through. */
|
|
17
|
+
export class CompilerHost extends ModuleResolutionHost {
|
|
18
|
+
fs;
|
|
19
|
+
currentDirectory;
|
|
20
|
+
defaultLibraryPath;
|
|
21
|
+
configParser;
|
|
22
|
+
constructor(fs, currentDirectory,
|
|
23
|
+
/** Where bundled `lib.*.d.ts` files are. */
|
|
24
|
+
defaultLibraryPath) {
|
|
25
|
+
super();
|
|
26
|
+
this.fs = fs;
|
|
27
|
+
this.currentDirectory = currentDirectory;
|
|
28
|
+
this.defaultLibraryPath = defaultLibraryPath;
|
|
29
|
+
this.configParser = new ConfigParser(fs, currentDirectory);
|
|
30
|
+
}
|
|
31
|
+
useCaseSensitiveFileNames() {
|
|
32
|
+
return this.fs.useCaseSensitiveFileNames;
|
|
33
|
+
}
|
|
34
|
+
getCurrentDirectory() {
|
|
35
|
+
return this.currentDirectory;
|
|
36
|
+
}
|
|
37
|
+
fileExists(path) {
|
|
38
|
+
return this.fs.fileExists(path);
|
|
39
|
+
}
|
|
40
|
+
directoryExists(path) {
|
|
41
|
+
return this.fs.directoryExists(path);
|
|
42
|
+
}
|
|
43
|
+
readFile(path) {
|
|
44
|
+
return this.fs.readFile(path);
|
|
45
|
+
}
|
|
46
|
+
realpath(path) {
|
|
47
|
+
return this.fs.realpath(path);
|
|
48
|
+
}
|
|
49
|
+
getDirectories(path) {
|
|
50
|
+
return this.fs.getAccessibleEntries(path).directories;
|
|
51
|
+
}
|
|
52
|
+
/** Parses a file, or returns `undefined` if it can't be read. */
|
|
53
|
+
getSourceFile(fileName, path, externalModuleIndicatorOptions) {
|
|
54
|
+
// A file that parse threads prepared (parallel-parse.ts).
|
|
55
|
+
const prepared = takePreparedFile(fileName, path, externalModuleIndicatorOptions);
|
|
56
|
+
if (prepared !== undefined)
|
|
57
|
+
return prepared;
|
|
58
|
+
const text = this.fs.readFile(fileName);
|
|
59
|
+
if (text === undefined)
|
|
60
|
+
return undefined;
|
|
61
|
+
return parseSourceFile(fileName, text, new ParseOptions(path, 0 /* ScriptKind.Unknown */, externalModuleIndicatorOptions));
|
|
62
|
+
}
|
|
63
|
+
/** The config of a referenced project, or `undefined` if it can't be read. */
|
|
64
|
+
getResolvedProjectReference(fileName) {
|
|
65
|
+
return this.configParser.parseConfigFile(fileName, undefined, undefined, []);
|
|
66
|
+
}
|
|
67
|
+
/** Called with module resolution traces under `--traceResolution`. */
|
|
68
|
+
trace(_message) { }
|
|
69
|
+
}
|
|
70
|
+
/** A bundled library file. */
|
|
71
|
+
export class LibFile {
|
|
72
|
+
name;
|
|
73
|
+
path;
|
|
74
|
+
replaced;
|
|
75
|
+
constructor(name, path,
|
|
76
|
+
/** Found through `libReplacement` in `node_modules/@typescript/lib-*`. */
|
|
77
|
+
replaced) {
|
|
78
|
+
this.name = name;
|
|
79
|
+
this.path = path;
|
|
80
|
+
this.replaced = replaced;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** The JSX runtime import of a file, synthesized for resolution. */
|
|
84
|
+
export class JsxRuntimeImport {
|
|
85
|
+
moduleReference;
|
|
86
|
+
specifier;
|
|
87
|
+
constructor(moduleReference, specifier) {
|
|
88
|
+
this.moduleReference = moduleReference;
|
|
89
|
+
this.specifier = specifier;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** A file found through a package installed at several places, kept only once. */
|
|
93
|
+
export class RedirectFile {
|
|
94
|
+
index;
|
|
95
|
+
fileName;
|
|
96
|
+
path;
|
|
97
|
+
target;
|
|
98
|
+
constructor(
|
|
99
|
+
/** Where in `getSourceFiles()` order it is explained. */
|
|
100
|
+
index, fileName, path,
|
|
101
|
+
/** The path of the file it redirects to. */
|
|
102
|
+
target) {
|
|
103
|
+
this.index = index;
|
|
104
|
+
this.fileName = fileName;
|
|
105
|
+
this.path = path;
|
|
106
|
+
this.target = target;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export function modeAwareKey(name, mode) {
|
|
110
|
+
return mode + '|' + name;
|
|
111
|
+
}
|
|
112
|
+
/** A file a loaded file adds (`ParseTask.addSubTask`), as a parse thread recorded it (`LoadedFile`). */
|
|
113
|
+
export class LoadedReference {
|
|
114
|
+
normalizedFilePath;
|
|
115
|
+
libName;
|
|
116
|
+
reason;
|
|
117
|
+
increaseDepth;
|
|
118
|
+
elideOnDepth;
|
|
119
|
+
packageId;
|
|
120
|
+
constructor(normalizedFilePath,
|
|
121
|
+
/** The library file's name, or `''`. */
|
|
122
|
+
libName, reason, increaseDepth, elideOnDepth, packageId) {
|
|
123
|
+
this.normalizedFilePath = normalizedFilePath;
|
|
124
|
+
this.libName = libName;
|
|
125
|
+
this.reason = reason;
|
|
126
|
+
this.increaseDepth = increaseDepth;
|
|
127
|
+
this.elideOnDepth = elideOnDepth;
|
|
128
|
+
this.packageId = packageId;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* What a parse thread's FileLoader found loading a file it prepared (parallel-parse.ts): the same
|
|
133
|
+
* as the program's FileLoader finds, since both load with the same options and file system. The
|
|
134
|
+
* program's FileLoader takes it instead of resolving the file's references, imports and type
|
|
135
|
+
* directives again, and takes its reasons as they are (they are immutable).
|
|
136
|
+
*/
|
|
137
|
+
export class LoadedFile {
|
|
138
|
+
file;
|
|
139
|
+
isLibFile;
|
|
140
|
+
metadata;
|
|
141
|
+
references;
|
|
142
|
+
resolutionsInFile;
|
|
143
|
+
typeResolutionsInFile;
|
|
144
|
+
processingDiagnostics;
|
|
145
|
+
importHelpersImportSpecifier;
|
|
146
|
+
jsxRuntimeImport;
|
|
147
|
+
constructor(file, isLibFile, metadata, references, resolutionsInFile, typeResolutionsInFile, processingDiagnostics, importHelpersImportSpecifier, jsxRuntimeImport) {
|
|
148
|
+
this.file = file;
|
|
149
|
+
this.isLibFile = isLibFile;
|
|
150
|
+
this.metadata = metadata;
|
|
151
|
+
this.references = references;
|
|
152
|
+
this.resolutionsInFile = resolutionsInFile;
|
|
153
|
+
this.typeResolutionsInFile = typeResolutionsInFile;
|
|
154
|
+
this.processingDiagnostics = processingDiagnostics;
|
|
155
|
+
this.importHelpersImportSpecifier = importHelpersImportSpecifier;
|
|
156
|
+
this.jsxRuntimeImport = jsxRuntimeImport;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/** Sub-tasks of a prepared file built ahead (`FileLoader.takeAhead`), and what they were built from. */
|
|
160
|
+
class SubTasksAhead {
|
|
161
|
+
loaded;
|
|
162
|
+
subTasks;
|
|
163
|
+
constructor(loaded, subTasks) {
|
|
164
|
+
this.loaded = loaded;
|
|
165
|
+
this.subTasks = subTasks;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
class ParseTask {
|
|
169
|
+
normalizedFilePath;
|
|
170
|
+
libFile;
|
|
171
|
+
includeReason;
|
|
172
|
+
isForAutomaticTypeDirective;
|
|
173
|
+
increaseDepth;
|
|
174
|
+
elideOnDepth;
|
|
175
|
+
packageId;
|
|
176
|
+
path = '';
|
|
177
|
+
file = undefined;
|
|
178
|
+
redirectedParseTask = undefined;
|
|
179
|
+
subTasks = [];
|
|
180
|
+
loaded = false;
|
|
181
|
+
startedSubTasks = false;
|
|
182
|
+
metadata = libFileMetadata;
|
|
183
|
+
resolutionsInFile = undefined;
|
|
184
|
+
resolutionsTrace = [];
|
|
185
|
+
typeResolutionsInFile = undefined;
|
|
186
|
+
typeResolutionsTrace = [];
|
|
187
|
+
processingDiagnostics = [];
|
|
188
|
+
importHelpersImportSpecifier = undefined;
|
|
189
|
+
jsxRuntimeImport = undefined;
|
|
190
|
+
/** The task of the same file name that was loaded instead of this one. */
|
|
191
|
+
loadedTask = undefined;
|
|
192
|
+
constructor(normalizedFilePath, libFile, includeReason, isForAutomaticTypeDirective, increaseDepth,
|
|
193
|
+
/** A JavaScript file found in `node_modules`, loaded only within `maxNodeModuleJsDepth`. */
|
|
194
|
+
elideOnDepth, packageId) {
|
|
195
|
+
this.normalizedFilePath = normalizedFilePath;
|
|
196
|
+
this.libFile = libFile;
|
|
197
|
+
this.includeReason = includeReason;
|
|
198
|
+
this.isForAutomaticTypeDirective = isForAutomaticTypeDirective;
|
|
199
|
+
this.increaseDepth = increaseDepth;
|
|
200
|
+
this.elideOnDepth = elideOnDepth;
|
|
201
|
+
this.packageId = packageId;
|
|
202
|
+
}
|
|
203
|
+
addSubTask(fileName, libFile, reason, increaseDepth, elideOnDepth, packageId) {
|
|
204
|
+
this.subTasks.push(new ParseTask(normalizePath(fileName), libFile, reason, false, increaseDepth, elideOnDepth, packageId));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/** The tasks of one path, by file name casing. */
|
|
208
|
+
class ParseTaskData {
|
|
209
|
+
tasks = new Map();
|
|
210
|
+
lowestDepth = Number.MAX_SAFE_INTEGER;
|
|
211
|
+
startedSubTasks = false;
|
|
212
|
+
packageId = undefined;
|
|
213
|
+
constructor(task) {
|
|
214
|
+
this.tasks.set(task.normalizedFilePath, task);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/** Pending processing of `tasks[index]`. */
|
|
218
|
+
class ParseWork {
|
|
219
|
+
tasks;
|
|
220
|
+
index;
|
|
221
|
+
data;
|
|
222
|
+
loaded;
|
|
223
|
+
depth;
|
|
224
|
+
constructor(tasks, index, data, loaded, depth) {
|
|
225
|
+
this.tasks = tasks;
|
|
226
|
+
this.index = index;
|
|
227
|
+
this.data = data;
|
|
228
|
+
this.loaded = loaded;
|
|
229
|
+
this.depth = depth;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/** Referenced projects, and how their sources map to declaration outputs. */
|
|
233
|
+
export class ProjectReferenceMapper {
|
|
234
|
+
config;
|
|
235
|
+
configToProjectReference = new Map();
|
|
236
|
+
referencesInConfigFile = new Map();
|
|
237
|
+
sourceToProjectReference = new Map();
|
|
238
|
+
outputDtsToProjectReference = new Map();
|
|
239
|
+
realpathDtsToSource = new Map();
|
|
240
|
+
/** Set while loading files, for symlink lookups. */
|
|
241
|
+
loader = undefined;
|
|
242
|
+
constructor(config) {
|
|
243
|
+
this.config = config;
|
|
244
|
+
}
|
|
245
|
+
/** The declaration output to load instead of a source of a referenced project, or `''`. */
|
|
246
|
+
getParseFileRedirect(path) {
|
|
247
|
+
const output = this.sourceToProjectReference.get(path);
|
|
248
|
+
return output !== undefined ? output.outputDts : '';
|
|
249
|
+
}
|
|
250
|
+
/** The referenced project whose options apply to a file. */
|
|
251
|
+
getRedirectForResolution(path, fileName) {
|
|
252
|
+
return (this.sourceToProjectReference.get(path) ??
|
|
253
|
+
this.outputDtsToProjectReference.get(path) ??
|
|
254
|
+
this.getSourceToDtsIfSymlink(path, fileName));
|
|
255
|
+
}
|
|
256
|
+
getCompilerOptionsForFile(path, fileName) {
|
|
257
|
+
return this.getRedirectForResolution(path, fileName)?.resolved.options ?? this.config.options;
|
|
258
|
+
}
|
|
259
|
+
/** Under `preserveSymlinks`, a symlinked declaration in `node_modules` may be the output of a reference. */
|
|
260
|
+
getSourceToDtsIfSymlink(path, fileName) {
|
|
261
|
+
const known = this.realpathDtsToSource.get(path);
|
|
262
|
+
if (known !== undefined)
|
|
263
|
+
return known ?? undefined;
|
|
264
|
+
const loader = this.loader;
|
|
265
|
+
if (loader === undefined || this.config.options.preserveSymlinks !== true)
|
|
266
|
+
return undefined;
|
|
267
|
+
let result;
|
|
268
|
+
if (fileName.includes('/node_modules/')) {
|
|
269
|
+
const realPath = loader.toPath(loader.host.realpath(fileName));
|
|
270
|
+
if (realPath !== path)
|
|
271
|
+
result = this.outputDtsToProjectReference.get(realPath);
|
|
272
|
+
}
|
|
273
|
+
this.realpathDtsToSource.set(path, result ?? null);
|
|
274
|
+
return result;
|
|
275
|
+
}
|
|
276
|
+
/** The configs of the root config's references, `undefined` for those that couldn't be read. */
|
|
277
|
+
resolvedProjectReferences() {
|
|
278
|
+
const result = [];
|
|
279
|
+
const configFile = this.config.configFile;
|
|
280
|
+
if (configFile === undefined)
|
|
281
|
+
return result;
|
|
282
|
+
for (const path of this.referencesInConfigFile.get(configFile.sourceFile.path) ?? []) {
|
|
283
|
+
result.push(this.configToProjectReference.get(path));
|
|
284
|
+
}
|
|
285
|
+
return result;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
/** A referenced project to read. */
|
|
289
|
+
class ProjectReferenceTask {
|
|
290
|
+
configName;
|
|
291
|
+
resolved = undefined;
|
|
292
|
+
subTasks = [];
|
|
293
|
+
constructor(configName) {
|
|
294
|
+
this.configName = configName;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
class ReferenceDiagnostic {
|
|
298
|
+
message;
|
|
299
|
+
args;
|
|
300
|
+
constructor(message, args) {
|
|
301
|
+
this.message = message;
|
|
302
|
+
this.args = args;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
/** What loading produced. */
|
|
306
|
+
export class ProcessedFiles {
|
|
307
|
+
resolver;
|
|
308
|
+
files;
|
|
309
|
+
filesByPath;
|
|
310
|
+
missingFiles;
|
|
311
|
+
resolvedModules;
|
|
312
|
+
typeResolutionsInFile;
|
|
313
|
+
sourceFileMetadata;
|
|
314
|
+
jsxRuntimeImports;
|
|
315
|
+
importHelpersImportSpecifiers;
|
|
316
|
+
libFiles;
|
|
317
|
+
sourceFilesFoundSearchingNodeModules;
|
|
318
|
+
includeProcessor;
|
|
319
|
+
outputFileToProjectReferenceSource;
|
|
320
|
+
redirectTargets;
|
|
321
|
+
redirectFilesByPath;
|
|
322
|
+
projectReferenceMapper;
|
|
323
|
+
preparedPackageJsons;
|
|
324
|
+
constructor(resolver,
|
|
325
|
+
/** Libraries first, sorted, then other files in load order. */
|
|
326
|
+
files, filesByPath, missingFiles, resolvedModules, typeResolutionsInFile, sourceFileMetadata, jsxRuntimeImports, importHelpersImportSpecifiers, libFiles,
|
|
327
|
+
/** Files found while searching `node_modules`. */
|
|
328
|
+
sourceFilesFoundSearchingNodeModules, includeProcessor,
|
|
329
|
+
/** Declaration outputs of referenced projects loaded for their sources, mapped back to the sources. */
|
|
330
|
+
outputFileToProjectReferenceSource, redirectTargets, redirectFilesByPath, projectReferenceMapper,
|
|
331
|
+
/**
|
|
332
|
+
* The `package.json` lookups made resolving the files whose resolutions were taken from parse
|
|
333
|
+
* threads (`preparedPackageJsonLookups`); `undefined` where they may miss some.
|
|
334
|
+
*/
|
|
335
|
+
preparedPackageJsons) {
|
|
336
|
+
this.resolver = resolver;
|
|
337
|
+
this.files = files;
|
|
338
|
+
this.filesByPath = filesByPath;
|
|
339
|
+
this.missingFiles = missingFiles;
|
|
340
|
+
this.resolvedModules = resolvedModules;
|
|
341
|
+
this.typeResolutionsInFile = typeResolutionsInFile;
|
|
342
|
+
this.sourceFileMetadata = sourceFileMetadata;
|
|
343
|
+
this.jsxRuntimeImports = jsxRuntimeImports;
|
|
344
|
+
this.importHelpersImportSpecifiers = importHelpersImportSpecifiers;
|
|
345
|
+
this.libFiles = libFiles;
|
|
346
|
+
this.sourceFilesFoundSearchingNodeModules = sourceFilesFoundSearchingNodeModules;
|
|
347
|
+
this.includeProcessor = includeProcessor;
|
|
348
|
+
this.outputFileToProjectReferenceSource = outputFileToProjectReferenceSource;
|
|
349
|
+
this.redirectTargets = redirectTargets;
|
|
350
|
+
this.redirectFilesByPath = redirectFilesByPath;
|
|
351
|
+
this.projectReferenceMapper = projectReferenceMapper;
|
|
352
|
+
this.preparedPackageJsons = preparedPackageJsons;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
/** The files of `processed` with `file` in place of the file at its path, for `Program.updateFile`. */
|
|
356
|
+
export function withReplacedFile(processed, file) {
|
|
357
|
+
const files = processed.files.slice();
|
|
358
|
+
files[files.findIndex((f) => f.path === file.path)] = file;
|
|
359
|
+
const filesByPath = new Map(processed.filesByPath);
|
|
360
|
+
filesByPath.set(file.path, file);
|
|
361
|
+
return new ProcessedFiles(processed.resolver, files, filesByPath, processed.missingFiles, processed.resolvedModules, processed.typeResolutionsInFile, processed.sourceFileMetadata, processed.jsxRuntimeImports, processed.importHelpersImportSpecifiers, processed.libFiles, processed.sourceFilesFoundSearchingNodeModules, processed.includeProcessor.copy(file.path), processed.outputFileToProjectReferenceSource, processed.redirectTargets, processed.redirectFilesByPath, processed.projectReferenceMapper, processed.preparedPackageJsons);
|
|
362
|
+
}
|
|
363
|
+
/** Whether `file` imports the `importHelpers` module (tslib) under `options`. */
|
|
364
|
+
export function needsImportHelpersImportSpecifier(file, options) {
|
|
365
|
+
if (options.importHelpers !== true)
|
|
366
|
+
return false;
|
|
367
|
+
return isSourceFileJS(file) || (!file.isDeclarationFile && (getIsolatedModules(options) || isExternalModule(file)));
|
|
368
|
+
}
|
|
369
|
+
/** The module `file` imports the JSX runtime from under `options`, or '' if it imports none. */
|
|
370
|
+
export function jsxRuntimeImportOf(file, options) {
|
|
371
|
+
if (file.scriptKind !== 2 /* ScriptKind.JSX */ && file.scriptKind !== 4 /* ScriptKind.TSX */)
|
|
372
|
+
return '';
|
|
373
|
+
return getJSXRuntimeImport(getJSXImplicitImportBase(options, file), options);
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Whether `next`, a new version of `file`, can take its place in a program without loading the program again,
|
|
377
|
+
* as tsgo's canReplaceFileInProgram checks: it has the same script kind, is a module if `file` is one, and has
|
|
378
|
+
* the same module specifiers with the same resolution modes (`modeOf`), module augmentation names, ambient
|
|
379
|
+
* modules, file, type and library references, `// @ts-check` directive and node core module style. A CommonJS
|
|
380
|
+
* module indicator is set when a file is bound, so `next` has none yet; the new program's binder sets it.
|
|
381
|
+
*/
|
|
382
|
+
export function canReplaceFile(file, next, modeOf) {
|
|
383
|
+
return (file.scriptKind === next.scriptKind &&
|
|
384
|
+
isExternalModule(file) === isExternalModule(next) &&
|
|
385
|
+
file.usesUriStyleNodeCoreModules === next.usesUriStyleNodeCoreModules &&
|
|
386
|
+
sameNodes(file.imports, next.imports, (a, b) => (a.kind !== 10 /* SyntaxKind.StringLiteral */ || getText(a) === getText(b)) && modeOf(file, a) === modeOf(next, b)) &&
|
|
387
|
+
sameNodes(file.moduleAugmentations, next.moduleAugmentations, (a, b) => getText(a) === getText(b)) &&
|
|
388
|
+
sameStrings(file.ambientModuleNames, next.ambientModuleNames) &&
|
|
389
|
+
sameFileReferences(file.referencedFiles, next.referencedFiles) &&
|
|
390
|
+
sameFileReferences(file.typeReferenceDirectives, next.typeReferenceDirectives) &&
|
|
391
|
+
sameFileReferences(file.libReferenceDirectives, next.libReferenceDirectives) &&
|
|
392
|
+
(file.checkJsDirective === undefined
|
|
393
|
+
? next.checkJsDirective === undefined
|
|
394
|
+
: next.checkJsDirective !== undefined && file.checkJsDirective.enabled === next.checkJsDirective.enabled));
|
|
395
|
+
}
|
|
396
|
+
function sameNodes(a, b, same) {
|
|
397
|
+
if (a.length !== b.length)
|
|
398
|
+
return false;
|
|
399
|
+
for (let i = 0; i < a.length; i++)
|
|
400
|
+
if (a[i].kind !== b[i].kind || !same(a[i], b[i]))
|
|
401
|
+
return false;
|
|
402
|
+
return true;
|
|
403
|
+
}
|
|
404
|
+
function sameStrings(a, b) {
|
|
405
|
+
if (a.length !== b.length)
|
|
406
|
+
return false;
|
|
407
|
+
for (let i = 0; i < a.length; i++)
|
|
408
|
+
if (a[i] !== b[i])
|
|
409
|
+
return false;
|
|
410
|
+
return true;
|
|
411
|
+
}
|
|
412
|
+
function sameFileReferences(a, b) {
|
|
413
|
+
if (a.length !== b.length)
|
|
414
|
+
return false;
|
|
415
|
+
for (let i = 0; i < a.length; i++) {
|
|
416
|
+
if (a[i].fileName !== b[i].fileName ||
|
|
417
|
+
a[i].resolutionMode !== b[i].resolutionMode ||
|
|
418
|
+
a[i].preserve !== b[i].preserve)
|
|
419
|
+
return false;
|
|
420
|
+
}
|
|
421
|
+
return true;
|
|
422
|
+
}
|
|
423
|
+
class LibResolution {
|
|
424
|
+
libraryName;
|
|
425
|
+
resolution;
|
|
426
|
+
trace;
|
|
427
|
+
constructor(libraryName, resolution, trace) {
|
|
428
|
+
this.libraryName = libraryName;
|
|
429
|
+
this.resolution = resolution;
|
|
430
|
+
this.trace = trace;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
/** Loads files depth-first in tsgo's single-threaded order; the result does not depend on that order. */
|
|
434
|
+
export class FileLoader {
|
|
435
|
+
host;
|
|
436
|
+
config;
|
|
437
|
+
resolver;
|
|
438
|
+
mapper;
|
|
439
|
+
options;
|
|
440
|
+
defaultLibraryPath;
|
|
441
|
+
supportedExtensions;
|
|
442
|
+
supportedExtensionsWithJson;
|
|
443
|
+
maxNodeModuleJsDepth;
|
|
444
|
+
rootTasks = [];
|
|
445
|
+
taskDataByPath = new Map();
|
|
446
|
+
/** Work queued by `start`, run last-in first-out like tsgo's single-threaded work group. */
|
|
447
|
+
work = [];
|
|
448
|
+
libFileCache = new Map();
|
|
449
|
+
libResolutions = new Map();
|
|
450
|
+
referenceTasks = new Map();
|
|
451
|
+
/** `toPath` of each file name seen: every reference to a file asks again. */
|
|
452
|
+
paths = new Map();
|
|
453
|
+
/** The normalized config file name root files are found from, once computed. */
|
|
454
|
+
rootContainingFile = undefined;
|
|
455
|
+
/** Root files whose tasks `addRootFiles` added. */
|
|
456
|
+
rootFilesAdded = 0;
|
|
457
|
+
/** The sub-tasks of prepared files, by file name, built ahead by `takeAhead`. */
|
|
458
|
+
subTasksAhead = new Map();
|
|
459
|
+
/** Whether the work of the root tasks is queued (`startRootTasks`). */
|
|
460
|
+
rootTasksStarted = false;
|
|
461
|
+
/** Set while `walkAhead` runs: the walk stops at work that would parse a file not prepared yet. */
|
|
462
|
+
walkingAhead = false;
|
|
463
|
+
/**
|
|
464
|
+
* Whether a file that parse threads prepared is loaded from what its thread found (its metadata
|
|
465
|
+
* and resolutions). If not, only the parsed and bound file is taken, and this loader looks up the
|
|
466
|
+
* file's metadata and resolves its references and imports itself, as without parse threads.
|
|
467
|
+
*/
|
|
468
|
+
takesPreparedResolutions = true;
|
|
469
|
+
// Whether a file's resolutions were taken from a parse thread.
|
|
470
|
+
tookPreparedResolutions = false;
|
|
471
|
+
constructor(host, config) {
|
|
472
|
+
this.host = host;
|
|
473
|
+
this.config = config;
|
|
474
|
+
const options = config.options;
|
|
475
|
+
this.options = options;
|
|
476
|
+
this.defaultLibraryPath = getNormalizedAbsolutePath(host.defaultLibraryPath, host.currentDirectory);
|
|
477
|
+
this.supportedExtensions = getSupportedExtensions(options);
|
|
478
|
+
this.supportedExtensionsWithJson = getSupportedExtensionsWithJsonIfResolveJsonModule(options);
|
|
479
|
+
this.maxNodeModuleJsDepth = options.maxNodeModuleJsDepth ?? 0;
|
|
480
|
+
this.mapper = new ProjectReferenceMapper(config);
|
|
481
|
+
this.loadProjectReferences();
|
|
482
|
+
this.resolver = new Resolver(host, options);
|
|
483
|
+
}
|
|
484
|
+
toPath(fileName) {
|
|
485
|
+
let path = this.paths.get(fileName);
|
|
486
|
+
if (path === undefined) {
|
|
487
|
+
path = toPath(fileName, this.host.currentDirectory, this.host.fs.useCaseSensitiveFileNames);
|
|
488
|
+
this.paths.set(fileName, path);
|
|
489
|
+
}
|
|
490
|
+
return path;
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Adds the tasks of up to `count` more root files, the first step of `load`: the main thread does
|
|
494
|
+
* this while parse threads load the files (parallel-parse.ts). Returns whether every root file's
|
|
495
|
+
* task is added.
|
|
496
|
+
*/
|
|
497
|
+
addRootFiles(count) {
|
|
498
|
+
const rootFiles = this.config.fileNames;
|
|
499
|
+
const end = Math.min(rootFiles.length, this.rootFilesAdded + count);
|
|
500
|
+
for (let i = this.rootFilesAdded; i < end; i++)
|
|
501
|
+
this.addRootFileTask(rootFiles[i], FileIncludeReason.rootFile(i));
|
|
502
|
+
this.rootFilesAdded = end;
|
|
503
|
+
return end === rootFiles.length;
|
|
504
|
+
}
|
|
505
|
+
/** Builds ahead what loading takes from each of `files` (`takeLoadedFile`). */
|
|
506
|
+
takeAhead(files) {
|
|
507
|
+
for (const prepared of files) {
|
|
508
|
+
const loaded = prepared.loaded;
|
|
509
|
+
if (loaded === undefined)
|
|
510
|
+
continue;
|
|
511
|
+
const subTasks = this.subTasksOf(loaded);
|
|
512
|
+
for (const task of subTasks)
|
|
513
|
+
task.path = this.toPath(task.normalizedFilePath);
|
|
514
|
+
this.subTasksAhead.set(prepared.fileName, new SubTasksAhead(loaded, subTasks));
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Loads what it can while parse threads load more files (parallel-parse.ts), the main thread's work
|
|
519
|
+
* for each batch they return: builds ahead what loading takes from its `files` (`takeAhead`), and once
|
|
520
|
+
* every root file's task is added, runs the walk `load` would run, in the same order, up to work that
|
|
521
|
+
* would parse a file the threads have not prepared yet. A later batch, or `load`, goes on from there.
|
|
522
|
+
* The order decides the program where a file is reached at several depths (the depth it is first
|
|
523
|
+
* loaded at decides the depths of the files it adds), so the walk keeps it.
|
|
524
|
+
*/
|
|
525
|
+
walkAhead(files) {
|
|
526
|
+
this.takeAhead(files);
|
|
527
|
+
if (!this.rootTasksStarted && this.rootFilesAdded < this.config.fileNames.length)
|
|
528
|
+
return;
|
|
529
|
+
this.startRootTasks();
|
|
530
|
+
this.walkingAhead = true;
|
|
531
|
+
this.walk();
|
|
532
|
+
this.walkingAhead = false;
|
|
533
|
+
}
|
|
534
|
+
load() {
|
|
535
|
+
this.addRootFiles(this.config.fileNames.length);
|
|
536
|
+
this.startRootTasks();
|
|
537
|
+
mark('loader roots added');
|
|
538
|
+
this.walk();
|
|
539
|
+
mark('loader walked');
|
|
540
|
+
const result = this.collect();
|
|
541
|
+
mark('loader collected');
|
|
542
|
+
this.mapper.loader = undefined;
|
|
543
|
+
return result;
|
|
544
|
+
}
|
|
545
|
+
/** Adds the tasks of the libraries and of the automatic type directives, after those of the root files. */
|
|
546
|
+
addLastRootTasks() {
|
|
547
|
+
if (this.config.fileNames.length === 0)
|
|
548
|
+
return;
|
|
549
|
+
if (this.options.noLib !== true) {
|
|
550
|
+
const lib = this.options.lib;
|
|
551
|
+
if (lib === undefined) {
|
|
552
|
+
const libFile = this.pathForLibFile(getDefaultLibFileName(this.options));
|
|
553
|
+
this.addRootTask(libFile.path, libFile, FileIncludeReason.libFile(-1));
|
|
554
|
+
}
|
|
555
|
+
else {
|
|
556
|
+
for (let i = 0; i < lib.length; i++) {
|
|
557
|
+
const name = getLibFileName(lib[i]);
|
|
558
|
+
if (name === '')
|
|
559
|
+
continue;
|
|
560
|
+
const libFile = this.pathForLibFile(name);
|
|
561
|
+
this.addRootTask(libFile.path, libFile, FileIncludeReason.libFile(i));
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
const containingDirectory = this.options.configFilePath !== undefined
|
|
566
|
+
? getDirectoryPath(this.options.configFilePath)
|
|
567
|
+
: this.host.currentDirectory;
|
|
568
|
+
this.rootTasks.push(new ParseTask(combinePaths(containingDirectory, inferredTypesContainingFile), undefined, undefined, true, false, false, undefined));
|
|
569
|
+
}
|
|
570
|
+
/** Adds the last root tasks and queues the work of every root task, once every root file's task is added. */
|
|
571
|
+
startRootTasks() {
|
|
572
|
+
if (this.rootTasksStarted)
|
|
573
|
+
return;
|
|
574
|
+
this.rootTasksStarted = true;
|
|
575
|
+
this.addLastRootTasks();
|
|
576
|
+
this.start(this.rootTasks, 0);
|
|
577
|
+
}
|
|
578
|
+
walk() {
|
|
579
|
+
for (let work = this.work.pop(); work !== undefined; work = this.work.pop()) {
|
|
580
|
+
if (this.walkingAhead && this.parsesUnprepared(work.tasks[work.index], work.data)) {
|
|
581
|
+
this.work.push(work);
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
this.run(work);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Drops the tasks once the program has its files, so that whatever holds the loader after loading
|
|
589
|
+
* (a parse session's callbacks) no longer keeps every file's task, sub-task list and resolution
|
|
590
|
+
* traces. Freeing them takes a while on large programs, so the drivers call this once checking
|
|
591
|
+
* has started (`releaseLater`).
|
|
592
|
+
*/
|
|
593
|
+
release() {
|
|
594
|
+
this.rootTasks.length = 0;
|
|
595
|
+
this.taskDataByPath.clear();
|
|
596
|
+
this.work.length = 0;
|
|
597
|
+
this.subTasksAhead.clear();
|
|
598
|
+
this.referenceTasks.clear();
|
|
599
|
+
this.paths.clear();
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Parse threads (parallel-parse.ts): loads one file as `load` would, parsing it through
|
|
603
|
+
* `host.getSourceFile`, and adds the files it references, imports and type directives add to `out`
|
|
604
|
+
* (libraries by name). `depth` is the file's `maxNodeModuleJsDepth` depth.
|
|
605
|
+
*/
|
|
606
|
+
loadAhead(kind, name, depth, out) {
|
|
607
|
+
let task;
|
|
608
|
+
if (kind === 2 /* LoadKind.Library */) {
|
|
609
|
+
const libFile = this.pathForLibFile(name);
|
|
610
|
+
task = new ParseTask(getNormalizedAbsolutePath(libFile.path, this.host.currentDirectory), libFile, undefined, false, false, false, undefined);
|
|
611
|
+
}
|
|
612
|
+
else if (kind === 3 /* LoadKind.AutomaticTypes */) {
|
|
613
|
+
const containingDirectory = this.options.configFilePath !== undefined
|
|
614
|
+
? getDirectoryPath(this.options.configFilePath)
|
|
615
|
+
: this.host.currentDirectory;
|
|
616
|
+
task = new ParseTask(combinePaths(containingDirectory, inferredTypesContainingFile), undefined, undefined, true, false, false, undefined);
|
|
617
|
+
}
|
|
618
|
+
else {
|
|
619
|
+
let fileName = name;
|
|
620
|
+
if (kind === 0 /* LoadKind.Root */) {
|
|
621
|
+
const configFile = this.config.configFile;
|
|
622
|
+
const containingFile = configFile !== undefined
|
|
623
|
+
? getNormalizedAbsolutePath(configFile.sourceFile.fileName, this.host.currentDirectory)
|
|
624
|
+
: this.host.currentDirectory;
|
|
625
|
+
const resolved = this.getSourceFileFromReference(name, name, containingFile, FileIncludeReason.rootFile(0));
|
|
626
|
+
if (typeof resolved !== 'string')
|
|
627
|
+
return undefined;
|
|
628
|
+
fileName = resolved;
|
|
629
|
+
}
|
|
630
|
+
task = new ParseTask(fileName, undefined, undefined, false, false, false, undefined);
|
|
631
|
+
}
|
|
632
|
+
task.path = this.toPath(task.normalizedFilePath);
|
|
633
|
+
this.loadTask(task);
|
|
634
|
+
const redirected = task.redirectedParseTask;
|
|
635
|
+
if (redirected !== undefined) {
|
|
636
|
+
// A source file of a referenced project: queue its output declaration file, which the program
|
|
637
|
+
// loads in its place. The redirected task has this task's include reason, which is undefined
|
|
638
|
+
// for a task loaded ahead, so no reference is recorded for it.
|
|
639
|
+
out.push(1 /* LoadKind.File */, redirected.normalizedFilePath, depth);
|
|
640
|
+
return undefined;
|
|
641
|
+
}
|
|
642
|
+
const references = [];
|
|
643
|
+
for (const sub of task.subTasks) {
|
|
644
|
+
references.push(new LoadedReference(sub.normalizedFilePath, sub.libFile !== undefined ? sub.libFile.name : '', sub.includeReason, sub.increaseDepth, sub.elideOnDepth, sub.packageId));
|
|
645
|
+
const subDepth = sub.increaseDepth ? depth + 1 : depth;
|
|
646
|
+
// `run` skips these.
|
|
647
|
+
if (sub.elideOnDepth && subDepth > this.maxNodeModuleJsDepth)
|
|
648
|
+
continue;
|
|
649
|
+
if (sub.libFile !== undefined)
|
|
650
|
+
out.push(2 /* LoadKind.Library */, sub.libFile.name, subDepth);
|
|
651
|
+
else
|
|
652
|
+
out.push(1 /* LoadKind.File */, sub.normalizedFilePath, subDepth);
|
|
653
|
+
}
|
|
654
|
+
const file = task.file;
|
|
655
|
+
// Traces are reported in the program's order: such programs resolve on their own.
|
|
656
|
+
if (file === undefined || this.options.traceResolution === true)
|
|
657
|
+
return undefined;
|
|
658
|
+
return new LoadedFile(file, task.libFile !== undefined, task.metadata, references, task.resolutionsInFile, task.typeResolutionsInFile, task.processingDiagnostics, task.importHelpersImportSpecifier, task.jsxRuntimeImport);
|
|
659
|
+
}
|
|
660
|
+
// ---- Project references
|
|
661
|
+
loadProjectReferences() {
|
|
662
|
+
const references = this.config.resolvedProjectReferencePaths();
|
|
663
|
+
if (references.length === 0)
|
|
664
|
+
return;
|
|
665
|
+
const configFile = this.config.configFile;
|
|
666
|
+
if (configFile === undefined)
|
|
667
|
+
return;
|
|
668
|
+
this.mapper.loader = this;
|
|
669
|
+
const tasks = createProjectReferenceTasks(references);
|
|
670
|
+
this.parseProjectReferences(tasks);
|
|
671
|
+
this.mapper.referencesInConfigFile.set(configFile.sourceFile.path, this.mapProjectReferences(tasks, new Set()));
|
|
672
|
+
}
|
|
673
|
+
parseProjectReferences(tasks) {
|
|
674
|
+
for (let i = 0; i < tasks.length; i++) {
|
|
675
|
+
const task = tasks[i];
|
|
676
|
+
const path = this.toPath(task.configName);
|
|
677
|
+
const existing = this.referenceTasks.get(path);
|
|
678
|
+
if (existing !== undefined) {
|
|
679
|
+
tasks[i] = existing;
|
|
680
|
+
continue;
|
|
681
|
+
}
|
|
682
|
+
this.referenceTasks.set(path, task);
|
|
683
|
+
task.resolved = this.host.getResolvedProjectReference(task.configName);
|
|
684
|
+
if (task.resolved !== undefined) {
|
|
685
|
+
const subReferences = task.resolved.resolvedProjectReferencePaths();
|
|
686
|
+
if (subReferences.length > 0)
|
|
687
|
+
task.subTasks = createProjectReferenceTasks(subReferences);
|
|
688
|
+
}
|
|
689
|
+
this.parseProjectReferences(task.subTasks);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
mapProjectReferences(tasks, seen) {
|
|
693
|
+
const results = [];
|
|
694
|
+
for (const task of tasks) {
|
|
695
|
+
const path = this.toPath(task.configName);
|
|
696
|
+
results.push(path);
|
|
697
|
+
if (seen.has(task))
|
|
698
|
+
continue;
|
|
699
|
+
seen.add(task);
|
|
700
|
+
this.mapper.configToProjectReference.set(path, task.resolved);
|
|
701
|
+
const resolved = task.resolved;
|
|
702
|
+
if (resolved !== undefined && resolved.configFile !== this.config.configFile) {
|
|
703
|
+
// A project's files are mapped before its references', which win for files in both.
|
|
704
|
+
for (const [source, reference] of resolved.sourceToProjectReference()) {
|
|
705
|
+
this.mapper.sourceToProjectReference.set(source, reference);
|
|
706
|
+
}
|
|
707
|
+
for (const [output, reference] of resolved.outputDtsToProjectReference()) {
|
|
708
|
+
this.mapper.outputDtsToProjectReference.set(output, reference);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
this.mapper.referencesInConfigFile.set(path, this.mapProjectReferences(task.subTasks, seen));
|
|
712
|
+
}
|
|
713
|
+
return results;
|
|
714
|
+
}
|
|
715
|
+
// ---- Root tasks
|
|
716
|
+
addRootTask(fileName, libFile, reason) {
|
|
717
|
+
const absolute = getNormalizedAbsolutePath(fileName, this.host.currentDirectory);
|
|
718
|
+
if (this.options.allowNonTsExtensions === true || hasExtension(absolute)) {
|
|
719
|
+
this.rootTasks.push(new ParseTask(absolute, libFile, reason, false, false, false, undefined));
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
addRootFileTask(fileName, reason) {
|
|
723
|
+
const currentDirectory = this.host.currentDirectory;
|
|
724
|
+
const absolute = getNormalizedAbsolutePath(fileName, currentDirectory);
|
|
725
|
+
let containingFile = this.rootContainingFile;
|
|
726
|
+
if (containingFile === undefined) {
|
|
727
|
+
const configFile = this.config.configFile;
|
|
728
|
+
containingFile =
|
|
729
|
+
configFile !== undefined
|
|
730
|
+
? getNormalizedAbsolutePath(configFile.sourceFile.fileName, currentDirectory)
|
|
731
|
+
: currentDirectory;
|
|
732
|
+
this.rootContainingFile = containingFile;
|
|
733
|
+
}
|
|
734
|
+
const resolved = this.getSourceFileFromReference(absolute, fileName, containingFile, reason);
|
|
735
|
+
if (typeof resolved === 'string') {
|
|
736
|
+
this.rootTasks.push(new ParseTask(resolved, undefined, reason, false, false, false, undefined));
|
|
737
|
+
return;
|
|
738
|
+
}
|
|
739
|
+
const task = new ParseTask(absolute, undefined, reason, false, false, false, undefined);
|
|
740
|
+
task.processingDiagnostics.push(ProcessingDiagnostic.explainingFileInclude('', reason, resolved.message, resolved.args));
|
|
741
|
+
this.rootTasks.push(task);
|
|
742
|
+
}
|
|
743
|
+
isSupportedExtension(canonicalFileName) {
|
|
744
|
+
for (const group of this.supportedExtensionsWithJson) {
|
|
745
|
+
if (fileExtensionIsOneOf(canonicalFileName, group))
|
|
746
|
+
return true;
|
|
747
|
+
}
|
|
748
|
+
return false;
|
|
749
|
+
}
|
|
750
|
+
supportedExtensionsList() {
|
|
751
|
+
return "'" + flattenExtensions(this.supportedExtensions).join("', '") + "'";
|
|
752
|
+
}
|
|
753
|
+
/** The file a root file or `/// <reference path>` names, trying extensions, or why there is none. */
|
|
754
|
+
getSourceFileFromReference(fileName, referenceText, containingFile, reason) {
|
|
755
|
+
const allowNonTsExtensions = this.options.allowNonTsExtensions === true;
|
|
756
|
+
const diagnosticFileName = normalizeSlashes(referenceText);
|
|
757
|
+
const fs = this.host.fs;
|
|
758
|
+
if (hasExtension(fileName)) {
|
|
759
|
+
const canonicalFileName = getCanonicalFileName(fileName, fs.useCaseSensitiveFileNames);
|
|
760
|
+
if (!allowNonTsExtensions && !this.isSupportedExtension(canonicalFileName)) {
|
|
761
|
+
if (hasJSFileExtension(canonicalFileName)) {
|
|
762
|
+
return new ReferenceDiagnostic(1519 /* Diagnostics.File_0_is_a_JavaScript_file_Did_you_mean_to_enable_the_allowJs_option */, [diagnosticFileName]);
|
|
763
|
+
}
|
|
764
|
+
return new ReferenceDiagnostic(1230 /* Diagnostics.File_0_has_an_unsupported_extension_The_only_supported_extensions_are_1 */, [diagnosticFileName, this.supportedExtensionsList()]);
|
|
765
|
+
}
|
|
766
|
+
if (!fs.fileExists(fileName))
|
|
767
|
+
return new ReferenceDiagnostic(1229 /* Diagnostics.File_0_not_found */, [diagnosticFileName]);
|
|
768
|
+
if (reason.isReferencedFile() &&
|
|
769
|
+
getCanonicalFileName(containingFile, fs.useCaseSensitiveFileNames) === canonicalFileName) {
|
|
770
|
+
return new ReferenceDiagnostic(3 /* Diagnostics.A_file_cannot_have_a_reference_to_itself */, []);
|
|
771
|
+
}
|
|
772
|
+
return fileName;
|
|
773
|
+
}
|
|
774
|
+
if (allowNonTsExtensions) {
|
|
775
|
+
return fs.fileExists(fileName)
|
|
776
|
+
? fileName
|
|
777
|
+
: new ReferenceDiagnostic(1229 /* Diagnostics.File_0_not_found */, [diagnosticFileName]);
|
|
778
|
+
}
|
|
779
|
+
for (const extension of this.supportedExtensions[0]) {
|
|
780
|
+
const candidate = fileName + extension;
|
|
781
|
+
if (fs.fileExists(candidate))
|
|
782
|
+
return candidate;
|
|
783
|
+
}
|
|
784
|
+
return new ReferenceDiagnostic(1383 /* Diagnostics.Could_not_resolve_the_path_0_with_the_extensions_Colon_1 */, [
|
|
785
|
+
diagnosticFileName,
|
|
786
|
+
this.supportedExtensionsList(),
|
|
787
|
+
]);
|
|
788
|
+
}
|
|
789
|
+
// ---- Libraries
|
|
790
|
+
/** The normalized file name of the library file `name` (`lib.dom.d.ts`), as `loadAhead` loads it. */
|
|
791
|
+
libraryFileName(name) {
|
|
792
|
+
return getNormalizedAbsolutePath(this.pathForLibFile(name).path, this.host.currentDirectory);
|
|
793
|
+
}
|
|
794
|
+
pathForLibFile(name) {
|
|
795
|
+
const cached = this.libFileCache.get(name);
|
|
796
|
+
if (cached !== undefined)
|
|
797
|
+
return cached;
|
|
798
|
+
let path = combinePaths(this.defaultLibraryPath, name);
|
|
799
|
+
let replaced = false;
|
|
800
|
+
if (this.options.libReplacement === true && name !== 'lib.d.ts') {
|
|
801
|
+
const libraryName = getLibraryNameFromLibFileName(name);
|
|
802
|
+
const containingDirectory = this.options.configFilePath !== undefined
|
|
803
|
+
? getDirectoryPath(this.options.configFilePath)
|
|
804
|
+
: this.host.currentDirectory;
|
|
805
|
+
const resolveFrom = combinePaths(containingDirectory, '__lib_node_modules_lookup_' + name + '__.ts');
|
|
806
|
+
const trace = [];
|
|
807
|
+
const resolution = this.resolver.resolveModuleName(libraryName, resolveFrom, ModuleKind.CommonJS, undefined, trace);
|
|
808
|
+
if (resolution.resolvedFileName !== '') {
|
|
809
|
+
path = resolution.resolvedFileName;
|
|
810
|
+
replaced = true;
|
|
811
|
+
}
|
|
812
|
+
const key = this.toPath(resolveFrom);
|
|
813
|
+
if (!this.libResolutions.has(key))
|
|
814
|
+
this.libResolutions.set(key, new LibResolution(libraryName, resolution, trace));
|
|
815
|
+
}
|
|
816
|
+
const libFile = new LibFile(name, path, replaced);
|
|
817
|
+
this.libFileCache.set(name, libFile);
|
|
818
|
+
return libFile;
|
|
819
|
+
}
|
|
820
|
+
libFilePriority(file) {
|
|
821
|
+
const directory = removeTrailingDirectorySeparator(this.defaultLibraryPath);
|
|
822
|
+
const fileName = file.fileName;
|
|
823
|
+
if (fileName.startsWith(directory) &&
|
|
824
|
+
fileName.length > directory.length &&
|
|
825
|
+
fileName.charCodeAt(directory.length) === 0x2f) {
|
|
826
|
+
const baseName = fileName.slice(fileName.lastIndexOf('/') + 1);
|
|
827
|
+
if (baseName === 'lib.d.ts' || baseName === 'lib.es6.d.ts')
|
|
828
|
+
return 0;
|
|
829
|
+
let name = baseName.startsWith('lib.') ? baseName.slice(4) : baseName;
|
|
830
|
+
if (name.endsWith('.d.ts'))
|
|
831
|
+
name = name.slice(0, -5);
|
|
832
|
+
const index = libNames.indexOf(name);
|
|
833
|
+
if (index !== -1)
|
|
834
|
+
return index + 1;
|
|
835
|
+
}
|
|
836
|
+
return libNames.length + 2;
|
|
837
|
+
}
|
|
838
|
+
// ---- Loading
|
|
839
|
+
start(tasks, depth) {
|
|
840
|
+
for (let i = 0; i < tasks.length; i++) {
|
|
841
|
+
const task = tasks[i];
|
|
842
|
+
// Sub-tasks built ahead have their paths.
|
|
843
|
+
if (task.path === '')
|
|
844
|
+
task.path = this.toPath(task.normalizedFilePath);
|
|
845
|
+
let data = this.taskDataByPath.get(task.path);
|
|
846
|
+
const loaded = data !== undefined;
|
|
847
|
+
if (data === undefined) {
|
|
848
|
+
data = new ParseTaskData(task);
|
|
849
|
+
this.taskDataByPath.set(task.path, data);
|
|
850
|
+
}
|
|
851
|
+
this.work.push(new ParseWork(tasks, i, data, loaded, depth));
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
run(work) {
|
|
855
|
+
const task = work.tasks[work.index];
|
|
856
|
+
const data = work.data;
|
|
857
|
+
let startSubTasks = false;
|
|
858
|
+
if (work.loaded) {
|
|
859
|
+
const existing = data.tasks.get(task.normalizedFilePath);
|
|
860
|
+
if (existing !== undefined) {
|
|
861
|
+
task.loadedTask = existing;
|
|
862
|
+
}
|
|
863
|
+
else {
|
|
864
|
+
data.tasks.set(task.normalizedFilePath, task);
|
|
865
|
+
// A new casing of a file: load its references if another casing's were.
|
|
866
|
+
startSubTasks = data.startedSubTasks;
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
if (data.packageId === undefined && task.packageId !== undefined)
|
|
870
|
+
data.packageId = task.packageId;
|
|
871
|
+
const depth = task.increaseDepth ? work.depth + 1 : work.depth;
|
|
872
|
+
if (depth < data.lowestDepth) {
|
|
873
|
+
// Reached at a lower depth than before: load references again.
|
|
874
|
+
data.lowestDepth = depth;
|
|
875
|
+
startSubTasks = true;
|
|
876
|
+
data.startedSubTasks = true;
|
|
877
|
+
}
|
|
878
|
+
if (task.elideOnDepth && depth > this.maxNodeModuleJsDepth)
|
|
879
|
+
return;
|
|
880
|
+
for (const taskByFileName of data.tasks.values()) {
|
|
881
|
+
let loadSubTasks = startSubTasks;
|
|
882
|
+
if (!taskByFileName.loaded) {
|
|
883
|
+
this.loadTask(taskByFileName);
|
|
884
|
+
if (taskByFileName.redirectedParseTask !== undefined) {
|
|
885
|
+
loadSubTasks = true;
|
|
886
|
+
data.startedSubTasks = true;
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
if (!taskByFileName.startedSubTasks && loadSubTasks) {
|
|
890
|
+
taskByFileName.startedSubTasks = true;
|
|
891
|
+
this.start(taskByFileName.subTasks, data.lowestDepth);
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
/**
|
|
896
|
+
* Whether running the work of `task` (of `data`'s path) may parse a file that parse threads have not
|
|
897
|
+
* prepared yet: a task of the path not loaded yet, or `task`, a new casing.
|
|
898
|
+
*/
|
|
899
|
+
parsesUnprepared(task, data) {
|
|
900
|
+
if (!data.tasks.has(task.normalizedFilePath) && !isPrepared(task.normalizedFilePath))
|
|
901
|
+
return true;
|
|
902
|
+
for (const other of data.tasks.values())
|
|
903
|
+
if (!other.loaded && !other.isForAutomaticTypeDirective && !isPrepared(other.normalizedFilePath))
|
|
904
|
+
return true;
|
|
905
|
+
return false;
|
|
906
|
+
}
|
|
907
|
+
loadTask(task) {
|
|
908
|
+
task.loaded = true;
|
|
909
|
+
if (task.isForAutomaticTypeDirective) {
|
|
910
|
+
this.loadAutomaticTypeDirectives(task);
|
|
911
|
+
return;
|
|
912
|
+
}
|
|
913
|
+
const redirect = this.mapper.getParseFileRedirect(task.path);
|
|
914
|
+
if (redirect !== '') {
|
|
915
|
+
const redirected = new ParseTask(normalizePath(redirect), task.libFile, task.includeReason, false, false, false, undefined);
|
|
916
|
+
task.redirectedParseTask = redirected;
|
|
917
|
+
task.subTasks = [redirected];
|
|
918
|
+
return;
|
|
919
|
+
}
|
|
920
|
+
const fs = this.host.fs;
|
|
921
|
+
if (hasExtension(task.normalizedFilePath) && this.options.allowNonTsExtensions !== true) {
|
|
922
|
+
const canonicalFileName = getCanonicalFileName(task.normalizedFilePath, fs.useCaseSensitiveFileNames);
|
|
923
|
+
if (!this.isSupportedExtension(canonicalFileName)) {
|
|
924
|
+
task.processingDiagnostics.push(hasJSFileExtension(canonicalFileName)
|
|
925
|
+
? ProcessingDiagnostic.explainingFileInclude('', task.includeReason, 1519 /* Diagnostics.File_0_is_a_JavaScript_file_Did_you_mean_to_enable_the_allowJs_option */, [task.normalizedFilePath])
|
|
926
|
+
: ProcessingDiagnostic.explainingFileInclude('', task.includeReason, 1230 /* Diagnostics.File_0_has_an_unsupported_extension_The_only_supported_extensions_are_1 */, [task.normalizedFilePath, this.supportedExtensionsList()]));
|
|
927
|
+
return;
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
// What a parse thread found loading this file, if it prepared it as the same kind of file.
|
|
931
|
+
let loaded = this.takesPreparedResolutions ? preparedLoad(task.normalizedFilePath) : undefined;
|
|
932
|
+
if (loaded !== undefined && loaded.isLibFile !== (task.libFile !== undefined))
|
|
933
|
+
loaded = undefined;
|
|
934
|
+
// Default libraries are scripts: skip looking up their package.json.
|
|
935
|
+
task.metadata =
|
|
936
|
+
task.libFile !== undefined
|
|
937
|
+
? libFileMetadata
|
|
938
|
+
: (loaded?.metadata ?? this.loadSourceFileMetadata(task.normalizedFilePath));
|
|
939
|
+
const options = this.mapper.getCompilerOptionsForFile(task.path, task.normalizedFilePath);
|
|
940
|
+
const file = this.host.getSourceFile(task.normalizedFilePath, task.path, getExternalModuleIndicatorOptions(task.normalizedFilePath, options, task.metadata));
|
|
941
|
+
if (file === undefined)
|
|
942
|
+
return;
|
|
943
|
+
task.file = file;
|
|
944
|
+
if (loaded !== undefined && loaded.file === file) {
|
|
945
|
+
this.takeLoadedFile(task, loaded);
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
if (this.options.noResolve !== true) {
|
|
949
|
+
for (let i = 0; i < file.referencedFiles.length; i++)
|
|
950
|
+
this.resolveTripleSlashPathReference(task, file, i);
|
|
951
|
+
this.resolveTypeReferenceDirectives(task, file);
|
|
952
|
+
}
|
|
953
|
+
if (this.options.noLib !== true) {
|
|
954
|
+
for (let i = 0; i < file.libReferenceDirectives.length; i++) {
|
|
955
|
+
const reason = FileIncludeReason.reference(3 /* FileIncludeKind.LibReferenceDirective */, task.path, i, undefined);
|
|
956
|
+
const name = getLibFileName(file.libReferenceDirectives[i].fileName);
|
|
957
|
+
if (name === '') {
|
|
958
|
+
task.processingDiagnostics.push(ProcessingDiagnostic.unknownReference(reason));
|
|
959
|
+
continue;
|
|
960
|
+
}
|
|
961
|
+
const libFile = this.pathForLibFile(name);
|
|
962
|
+
task.addSubTask(libFile.path, libFile, reason, false, false, undefined);
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
this.resolveImportsAndModuleAugmentations(task, file);
|
|
966
|
+
}
|
|
967
|
+
/** Loads `task` from what a parse thread found loading the same file (`LoadedFile`). */
|
|
968
|
+
takeLoadedFile(task, loaded) {
|
|
969
|
+
this.tookPreparedResolutions = true;
|
|
970
|
+
const ahead = this.subTasksAhead.get(task.normalizedFilePath);
|
|
971
|
+
if (ahead !== undefined && ahead.loaded === loaded) {
|
|
972
|
+
this.subTasksAhead.delete(task.normalizedFilePath);
|
|
973
|
+
task.subTasks = ahead.subTasks;
|
|
974
|
+
}
|
|
975
|
+
else
|
|
976
|
+
task.subTasks = this.subTasksOf(loaded);
|
|
977
|
+
for (const diagnostic of loaded.processingDiagnostics)
|
|
978
|
+
task.processingDiagnostics.push(diagnostic.copy());
|
|
979
|
+
task.resolutionsInFile = loaded.resolutionsInFile;
|
|
980
|
+
task.typeResolutionsInFile = loaded.typeResolutionsInFile;
|
|
981
|
+
task.importHelpersImportSpecifier = loaded.importHelpersImportSpecifier;
|
|
982
|
+
task.jsxRuntimeImport = loaded.jsxRuntimeImport;
|
|
983
|
+
}
|
|
984
|
+
/** New tasks of the references a parse thread found loading a file. */
|
|
985
|
+
subTasksOf(loaded) {
|
|
986
|
+
const subTasks = [];
|
|
987
|
+
for (const reference of loaded.references) {
|
|
988
|
+
const libFile = reference.libName !== '' ? this.pathForLibFile(reference.libName) : undefined;
|
|
989
|
+
subTasks.push(new ParseTask(reference.normalizedFilePath, libFile, reference.reason, false, reference.increaseDepth, reference.elideOnDepth, reference.packageId));
|
|
990
|
+
}
|
|
991
|
+
return subTasks;
|
|
992
|
+
}
|
|
993
|
+
loadSourceFileMetadata(fileName) {
|
|
994
|
+
return sourceFileMetadataOf(this.resolver, this.options, fileName);
|
|
995
|
+
}
|
|
996
|
+
resolveTripleSlashPathReference(task, file, index) {
|
|
997
|
+
const moduleName = file.referencedFiles[index].fileName;
|
|
998
|
+
const containingFile = file.fileName;
|
|
999
|
+
const referencedFileName = isRootedDiskPath(moduleName)
|
|
1000
|
+
? moduleName
|
|
1001
|
+
: combinePaths(getDirectoryPath(containingFile), moduleName);
|
|
1002
|
+
const reason = FileIncludeReason.reference(1 /* FileIncludeKind.ReferenceFile */, this.toPath(containingFile), index, undefined);
|
|
1003
|
+
const resolved = this.getSourceFileFromReference(normalizePath(referencedFileName), moduleName, containingFile, reason);
|
|
1004
|
+
if (typeof resolved !== 'string') {
|
|
1005
|
+
task.processingDiagnostics.push(ProcessingDiagnostic.explainingFileInclude('', reason, resolved.message, resolved.args));
|
|
1006
|
+
return;
|
|
1007
|
+
}
|
|
1008
|
+
task.addSubTask(resolved, undefined, reason, false, false, undefined);
|
|
1009
|
+
}
|
|
1010
|
+
resolveTypeReferenceDirectives(task, file) {
|
|
1011
|
+
const references = file.typeReferenceDirectives;
|
|
1012
|
+
if (references.length === 0)
|
|
1013
|
+
return;
|
|
1014
|
+
const resolutions = new Map();
|
|
1015
|
+
for (let i = 0; i < references.length; i++) {
|
|
1016
|
+
const reference = references[i];
|
|
1017
|
+
const redirect = this.mapper.getRedirectForResolution(file.path, file.fileName);
|
|
1018
|
+
const containingFile = redirect !== undefined ? redirect.source : file.fileName;
|
|
1019
|
+
const options = redirect !== undefined ? redirect.resolved.options : this.options;
|
|
1020
|
+
const mode = reference.resolutionMode !== ModuleKind.None
|
|
1021
|
+
? reference.resolutionMode
|
|
1022
|
+
: getDefaultResolutionModeForFile(file.fileName, task.metadata, options);
|
|
1023
|
+
const resolved = this.resolver.resolveTypeReferenceDirective(reference.fileName, containingFile, mode, redirect?.resolved, task.typeResolutionsTrace);
|
|
1024
|
+
resolutions.set(modeAwareKey(reference.fileName, mode), resolved);
|
|
1025
|
+
const reason = FileIncludeReason.reference(2 /* FileIncludeKind.TypeReferenceDirective */, task.path, i, undefined);
|
|
1026
|
+
if (resolved.resolvedFileName !== '') {
|
|
1027
|
+
task.addSubTask(resolved.resolvedFileName, undefined, reason, resolved.isExternalLibraryImport, false, resolved.packageId);
|
|
1028
|
+
}
|
|
1029
|
+
else {
|
|
1030
|
+
task.processingDiagnostics.push(ProcessingDiagnostic.unknownReference(reason));
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
task.typeResolutionsInFile = resolutions;
|
|
1034
|
+
}
|
|
1035
|
+
loadAutomaticTypeDirectives(task) {
|
|
1036
|
+
const names = getAutomaticTypeDirectiveNames(this.options, this.host);
|
|
1037
|
+
if (names.length === 0)
|
|
1038
|
+
return;
|
|
1039
|
+
const resolutions = new Map();
|
|
1040
|
+
for (const name of names) {
|
|
1041
|
+
// Resolved without a mode: CommonJS under node16/nodenext, `import` conditions under bundler.
|
|
1042
|
+
const resolved = this.resolver.resolveTypeReferenceDirective(name, task.normalizedFilePath, ModuleKind.None, undefined, task.typeResolutionsTrace);
|
|
1043
|
+
resolutions.set(modeAwareKey(name, ModuleKind.None), resolved);
|
|
1044
|
+
if (resolved.resolvedFileName !== '') {
|
|
1045
|
+
task.addSubTask(resolved.resolvedFileName, undefined, FileIncludeReason.automaticTypeDirective(name, resolved.packageId), resolved.isExternalLibraryImport, false, resolved.packageId);
|
|
1046
|
+
}
|
|
1047
|
+
else {
|
|
1048
|
+
task.processingDiagnostics.push(ProcessingDiagnostic.explainingFileInclude('', FileIncludeReason.automaticTypeDirective(name, undefined), 821 /* Diagnostics.Cannot_find_type_definition_file_for_0 */, [name]));
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
task.typeResolutionsInFile = resolutions;
|
|
1052
|
+
}
|
|
1053
|
+
resolveImportsAndModuleAugmentations(task, file) {
|
|
1054
|
+
const moduleNames = [];
|
|
1055
|
+
const redirect = this.mapper.getRedirectForResolution(file.path, file.fileName);
|
|
1056
|
+
const containingFile = redirect !== undefined ? redirect.source : file.fileName;
|
|
1057
|
+
const options = redirect !== undefined ? redirect.resolved.options : this.options;
|
|
1058
|
+
if (needsImportHelpersImportSpecifier(file, options)) {
|
|
1059
|
+
const specifier = createSyntheticImport('tslib', file);
|
|
1060
|
+
moduleNames.push(specifier);
|
|
1061
|
+
task.importHelpersImportSpecifier = specifier;
|
|
1062
|
+
}
|
|
1063
|
+
const jsxImport = jsxRuntimeImportOf(file, options);
|
|
1064
|
+
if (jsxImport !== '') {
|
|
1065
|
+
const specifier = createSyntheticImport(jsxImport, file);
|
|
1066
|
+
moduleNames.push(specifier);
|
|
1067
|
+
task.jsxRuntimeImport = new JsxRuntimeImport(jsxImport, specifier);
|
|
1068
|
+
}
|
|
1069
|
+
const importsStart = moduleNames.length;
|
|
1070
|
+
for (const specifier of file.imports)
|
|
1071
|
+
moduleNames.push(specifier);
|
|
1072
|
+
for (const augmentation of file.moduleAugmentations) {
|
|
1073
|
+
// `declare global` needs no resolution.
|
|
1074
|
+
if (augmentation.kind === 10 /* SyntaxKind.StringLiteral */)
|
|
1075
|
+
moduleNames.push(augmentation);
|
|
1076
|
+
}
|
|
1077
|
+
if (moduleNames.length === 0)
|
|
1078
|
+
return;
|
|
1079
|
+
const resolutions = new Map();
|
|
1080
|
+
for (let index = 0; index < moduleNames.length; index++) {
|
|
1081
|
+
const entry = moduleNames[index];
|
|
1082
|
+
const moduleName = getText(entry);
|
|
1083
|
+
if (moduleName === '')
|
|
1084
|
+
continue;
|
|
1085
|
+
const mode = getModeForUsageLocation(file.fileName, task.metadata, entry, options);
|
|
1086
|
+
const resolved = this.resolver.resolveModuleName(moduleName, containingFile, mode, redirect?.resolved, task.resolutionsTrace);
|
|
1087
|
+
resolutions.set(modeAwareKey(moduleName, mode), resolved);
|
|
1088
|
+
const resolvedFileName = resolved.resolvedFileName;
|
|
1089
|
+
if (resolvedFileName === '')
|
|
1090
|
+
continue;
|
|
1091
|
+
// Redirected files are not JavaScript files.
|
|
1092
|
+
const isJsFile = !fileExtensionIsOneOf(resolvedFileName, supportedTSExtensionsWithJsonFlat) &&
|
|
1093
|
+
this.mapper.getRedirectForResolution(this.toPath(resolvedFileName), resolvedFileName) === undefined;
|
|
1094
|
+
const isJsFileFromNodeModules = resolved.isExternalLibraryImport && isJsFile && resolvedFileName.includes('/node_modules/');
|
|
1095
|
+
const importIndex = index - importsStart;
|
|
1096
|
+
const imports = file.imports;
|
|
1097
|
+
// Imports from JSDoc of TypeScript files only resolve; module augmentations aren't added either.
|
|
1098
|
+
const shouldAddFile = getResolutionDiagnostic(options, resolved, file.isDeclarationFile) === undefined &&
|
|
1099
|
+
options.noResolve !== true &&
|
|
1100
|
+
!(isJsFile && !getAllowJS(options)) &&
|
|
1101
|
+
(importIndex < 0 ||
|
|
1102
|
+
(importIndex < imports.length &&
|
|
1103
|
+
((imports[importIndex].flags & 65536 /* NodeFlags.JavaScriptFile */) !== 0 ||
|
|
1104
|
+
(imports[importIndex].flags & 4194304 /* NodeFlags.JSDoc */) === 0)));
|
|
1105
|
+
if (!shouldAddFile)
|
|
1106
|
+
continue;
|
|
1107
|
+
// `as`: scriptc loses instanceof narrowing here.
|
|
1108
|
+
const specifier = importIndex < 0 && entry instanceof StringLiteral ? entry : undefined;
|
|
1109
|
+
task.addSubTask(resolvedFileName, undefined, FileIncludeReason.reference(0 /* FileIncludeKind.Import */, task.path, importIndex, specifier), resolved.isExternalLibraryImport, isJsFileFromNodeModules, resolved.packageId);
|
|
1110
|
+
}
|
|
1111
|
+
task.resolutionsInFile = resolutions;
|
|
1112
|
+
}
|
|
1113
|
+
// ---- Collecting
|
|
1114
|
+
collect() {
|
|
1115
|
+
const host = this.host;
|
|
1116
|
+
const cs = host.fs.useCaseSensitiveFileNames;
|
|
1117
|
+
const missingFiles = [];
|
|
1118
|
+
const files = [];
|
|
1119
|
+
const libFiles = [];
|
|
1120
|
+
const filesByPath = new Map();
|
|
1121
|
+
const tasksSeenByNameIgnoreCase = cs ? new Map() : undefined;
|
|
1122
|
+
const includeProcessor = new IncludeProcessor();
|
|
1123
|
+
const outputFileToProjectReferenceSource = new Map();
|
|
1124
|
+
const resolvedModules = new Map();
|
|
1125
|
+
const typeResolutionsInFile = new Map();
|
|
1126
|
+
const sourceFileMetadata = new Map();
|
|
1127
|
+
const jsxRuntimeImports = new Map();
|
|
1128
|
+
const importHelpersImportSpecifiers = new Map();
|
|
1129
|
+
const sourceFilesFoundSearchingNodeModules = new Set();
|
|
1130
|
+
const libFilesByPath = new Map();
|
|
1131
|
+
const deduplicatePackages = this.options.deduplicatePackages !== false;
|
|
1132
|
+
const redirectTargets = new Map();
|
|
1133
|
+
const redirectFilesByPath = new Map();
|
|
1134
|
+
const packageIdToSourceFile = new Map();
|
|
1135
|
+
const checkCasing = this.options.forceConsistentCasingInFileNames !== false;
|
|
1136
|
+
const seen = new Map();
|
|
1137
|
+
const collectFiles = (tasks) => {
|
|
1138
|
+
for (let task of tasks) {
|
|
1139
|
+
const includeReason = task.includeReason;
|
|
1140
|
+
// Automatic type directive tasks are an implementation detail, not a reason.
|
|
1141
|
+
if (task.redirectedParseTask === undefined && !task.isForAutomaticTypeDirective) {
|
|
1142
|
+
if (task.loadedTask !== undefined)
|
|
1143
|
+
task = task.loadedTask;
|
|
1144
|
+
if (includeReason !== undefined)
|
|
1145
|
+
addIncludeReason(includeProcessor, task, includeReason);
|
|
1146
|
+
}
|
|
1147
|
+
const data = this.taskDataByPath.get(task.path);
|
|
1148
|
+
if (!task.loaded || data === undefined)
|
|
1149
|
+
continue;
|
|
1150
|
+
const checkedName = seen.get(data);
|
|
1151
|
+
if (checkedName !== undefined) {
|
|
1152
|
+
// The same name normalizes the same: only another spelling needs comparing.
|
|
1153
|
+
if (checkCasing &&
|
|
1154
|
+
checkedName !== task.normalizedFilePath &&
|
|
1155
|
+
withoutRoot(getNormalizedAbsolutePath(checkedName, host.currentDirectory)) !==
|
|
1156
|
+
withoutRoot(getNormalizedAbsolutePath(task.normalizedFilePath, host.currentDirectory))) {
|
|
1157
|
+
includeProcessor.addCasingDiagnostic(task.path, checkedName, task.normalizedFilePath, includeReason);
|
|
1158
|
+
}
|
|
1159
|
+
continue;
|
|
1160
|
+
}
|
|
1161
|
+
seen.set(data, task.normalizedFilePath);
|
|
1162
|
+
if (tasksSeenByNameIgnoreCase !== undefined) {
|
|
1163
|
+
const lowerCasePath = toFileNameLowerCase(task.path);
|
|
1164
|
+
const existing = tasksSeenByNameIgnoreCase.get(lowerCasePath);
|
|
1165
|
+
if (existing !== undefined) {
|
|
1166
|
+
includeProcessor.addCasingDiagnostic(existing.path, existing.normalizedFilePath, task.normalizedFilePath, includeReason);
|
|
1167
|
+
}
|
|
1168
|
+
else {
|
|
1169
|
+
tasksSeenByNameIgnoreCase.set(lowerCasePath, task);
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
for (const trace of task.typeResolutionsTrace)
|
|
1173
|
+
host.trace(trace);
|
|
1174
|
+
for (const trace of task.resolutionsTrace)
|
|
1175
|
+
host.trace(trace);
|
|
1176
|
+
const file = task.file;
|
|
1177
|
+
const packageId = data.packageId;
|
|
1178
|
+
if (deduplicatePackages && packageId !== undefined && packageId.name !== '') {
|
|
1179
|
+
const key = packageIdKey(packageId);
|
|
1180
|
+
const packageIdFile = packageIdToSourceFile.get(key);
|
|
1181
|
+
if (packageIdFile !== undefined) {
|
|
1182
|
+
const targets = redirectTargets.get(packageIdFile.path);
|
|
1183
|
+
if (targets === undefined)
|
|
1184
|
+
redirectTargets.set(packageIdFile.path, [task.normalizedFilePath]);
|
|
1185
|
+
else
|
|
1186
|
+
targets.push(task.normalizedFilePath);
|
|
1187
|
+
redirectFilesByPath.set(task.path, new RedirectFile(files.length + redirectFilesByPath.size, task.normalizedFilePath, task.path, packageIdFile.path));
|
|
1188
|
+
filesByPath.set(task.path, packageIdFile);
|
|
1189
|
+
if (data.lowestDepth > 0)
|
|
1190
|
+
sourceFilesFoundSearchingNodeModules.add(task.path);
|
|
1191
|
+
continue;
|
|
1192
|
+
}
|
|
1193
|
+
if (file !== undefined)
|
|
1194
|
+
packageIdToSourceFile.set(key, file);
|
|
1195
|
+
}
|
|
1196
|
+
if (task.subTasks.length > 0)
|
|
1197
|
+
collectFiles(task.subTasks);
|
|
1198
|
+
const redirected = task.redirectedParseTask;
|
|
1199
|
+
if (redirected !== undefined) {
|
|
1200
|
+
outputFileToProjectReferenceSource.set(redirected.path, task.normalizedFilePath);
|
|
1201
|
+
continue;
|
|
1202
|
+
}
|
|
1203
|
+
if (task.isForAutomaticTypeDirective) {
|
|
1204
|
+
typeResolutionsInFile.set(task.path, task.typeResolutionsInFile);
|
|
1205
|
+
for (const diagnostic of task.processingDiagnostics)
|
|
1206
|
+
includeProcessor.addProcessingDiagnostic(diagnostic);
|
|
1207
|
+
continue;
|
|
1208
|
+
}
|
|
1209
|
+
const path = task.path;
|
|
1210
|
+
for (const diagnostic of task.processingDiagnostics)
|
|
1211
|
+
includeProcessor.addProcessingDiagnostic(diagnostic);
|
|
1212
|
+
if (file === undefined) {
|
|
1213
|
+
missingFiles.push(task.normalizedFilePath);
|
|
1214
|
+
continue;
|
|
1215
|
+
}
|
|
1216
|
+
if (task.libFile !== undefined) {
|
|
1217
|
+
libFiles.push(file);
|
|
1218
|
+
libFilesByPath.set(path, task.libFile);
|
|
1219
|
+
}
|
|
1220
|
+
else {
|
|
1221
|
+
files.push(file);
|
|
1222
|
+
}
|
|
1223
|
+
filesByPath.set(path, file);
|
|
1224
|
+
resolvedModules.set(path, task.resolutionsInFile);
|
|
1225
|
+
typeResolutionsInFile.set(path, task.typeResolutionsInFile);
|
|
1226
|
+
sourceFileMetadata.set(path, task.metadata);
|
|
1227
|
+
if (task.jsxRuntimeImport !== undefined)
|
|
1228
|
+
jsxRuntimeImports.set(path, task.jsxRuntimeImport);
|
|
1229
|
+
if (task.importHelpersImportSpecifier !== undefined) {
|
|
1230
|
+
importHelpersImportSpecifiers.set(path, task.importHelpersImportSpecifier);
|
|
1231
|
+
}
|
|
1232
|
+
if (data.lowestDepth > 0)
|
|
1233
|
+
sourceFilesFoundSearchingNodeModules.add(path);
|
|
1234
|
+
}
|
|
1235
|
+
};
|
|
1236
|
+
collectFiles(this.rootTasks);
|
|
1237
|
+
const priorities = new Map();
|
|
1238
|
+
for (const file of libFiles)
|
|
1239
|
+
priorities.set(file, this.libFilePriority(file));
|
|
1240
|
+
libFiles.sort((a, b) => (priorities.get(a) ?? 0) - (priorities.get(b) ?? 0));
|
|
1241
|
+
const allFiles = [...libFiles, ...files];
|
|
1242
|
+
for (const redirect of redirectFilesByPath.values())
|
|
1243
|
+
redirect.index += libFiles.length;
|
|
1244
|
+
const keys = [...this.libResolutions.keys()].sort();
|
|
1245
|
+
for (const key of keys) {
|
|
1246
|
+
const resolution = this.libResolutions.get(key);
|
|
1247
|
+
if (resolution === undefined)
|
|
1248
|
+
continue;
|
|
1249
|
+
const cache = new Map();
|
|
1250
|
+
cache.set(modeAwareKey(resolution.libraryName, ModuleKind.CommonJS), resolution.resolution);
|
|
1251
|
+
resolvedModules.set(key, cache);
|
|
1252
|
+
for (const trace of resolution.trace)
|
|
1253
|
+
host.trace(trace);
|
|
1254
|
+
}
|
|
1255
|
+
return new ProcessedFiles(this.resolver, allFiles, filesByPath, missingFiles, resolvedModules, typeResolutionsInFile, sourceFileMetadata, jsxRuntimeImports, importHelpersImportSpecifiers, libFilesByPath, sourceFilesFoundSearchingNodeModules, includeProcessor, outputFileToProjectReferenceSource, redirectTargets, redirectFilesByPath, this.mapper, this.tookPreparedResolutions ? preparedPackageJsonLookups() : noPackageJsonLookups);
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
const noPackageJsonLookups = [];
|
|
1259
|
+
/** Releases `loader` (`FileLoader.release`) on a later turn of the event loop, while checking runs. */
|
|
1260
|
+
export function releaseLater(loader) {
|
|
1261
|
+
setImmediate(() => loader.release());
|
|
1262
|
+
}
|
|
1263
|
+
function addIncludeReason(processor, task, reason) {
|
|
1264
|
+
const redirected = task.redirectedParseTask;
|
|
1265
|
+
if (redirected !== undefined)
|
|
1266
|
+
addIncludeReason(processor, redirected, reason);
|
|
1267
|
+
else if (task.loaded)
|
|
1268
|
+
processor.addReason(task.path, reason);
|
|
1269
|
+
}
|
|
1270
|
+
function createProjectReferenceTasks(paths) {
|
|
1271
|
+
const tasks = [];
|
|
1272
|
+
for (const path of paths)
|
|
1273
|
+
tasks.push(new ProjectReferenceTask(path));
|
|
1274
|
+
return tasks;
|
|
1275
|
+
}
|
|
1276
|
+
function packageIdKey(id) {
|
|
1277
|
+
return id.name + '\0' + id.subModuleName + '\0' + id.version + '\0' + id.peerDependencies;
|
|
1278
|
+
}
|
|
1279
|
+
function withoutRoot(path) {
|
|
1280
|
+
return path.slice(getRootLength(path));
|
|
1281
|
+
}
|
|
1282
|
+
/** A specifier of an import the compiler adds, such as `tslib` for `importHelpers`. */
|
|
1283
|
+
function createSyntheticImport(text, file) {
|
|
1284
|
+
const specifier = new StringLiteral(text, 0 /* TokenFlags.None */);
|
|
1285
|
+
const declaration = new ImportDeclaration(273 /* SyntaxKind.ImportDeclaration */, undefined, undefined, specifier, undefined);
|
|
1286
|
+
specifier.parent = declaration;
|
|
1287
|
+
declaration.parent = file;
|
|
1288
|
+
return specifier;
|
|
1289
|
+
}
|
|
1290
|
+
/** `lib.dom.iterable.d.ts` to `@typescript/lib-dom/iterable`, `lib.es2015.symbol.wellknown.d.ts` to `@typescript/lib-es2015/symbol-wellknown`. */
|
|
1291
|
+
function getLibraryNameFromLibFileName(libFileName) {
|
|
1292
|
+
const components = libFileName.split('.');
|
|
1293
|
+
let path = '@typescript/lib-';
|
|
1294
|
+
if (components.length > 1)
|
|
1295
|
+
path += components[1];
|
|
1296
|
+
for (let i = 2; i < components.length && components[i] !== '' && components[i] !== 'd'; i++) {
|
|
1297
|
+
path += (i === 2 ? '/' : '-') + components[i];
|
|
1298
|
+
}
|
|
1299
|
+
return path;
|
|
1300
|
+
}
|
|
1301
|
+
/**
|
|
1302
|
+
* The metadata of `fileName` in a program with `options`: the `type` and directory of its nearest
|
|
1303
|
+
* package.json (`resolver`), where they apply, and its implied module format.
|
|
1304
|
+
*/
|
|
1305
|
+
export function sourceFileMetadataOf(resolver, options, fileName) {
|
|
1306
|
+
const scope = resolver.getPackageScopeForPath(getDirectoryPath(fileName));
|
|
1307
|
+
const kind = getModuleResolutionKind(options);
|
|
1308
|
+
let packageJsonType = '';
|
|
1309
|
+
let packageJsonDirectory = '';
|
|
1310
|
+
const contents = scope?.contents;
|
|
1311
|
+
if (scope !== undefined && contents !== undefined) {
|
|
1312
|
+
packageJsonDirectory = scope.packageDirectory;
|
|
1313
|
+
const type = contents.type.value;
|
|
1314
|
+
if (type !== undefined &&
|
|
1315
|
+
((!fileExtensionIsOneOf(fileName, ['.mts', '.cts', '.mjs', '.cjs']) &&
|
|
1316
|
+
ModuleResolutionKind.Node16 <= kind &&
|
|
1317
|
+
kind <= ModuleResolutionKind.NodeNext) ||
|
|
1318
|
+
fileName.includes('/node_modules/'))) {
|
|
1319
|
+
packageJsonType = type;
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
return new SourceFileMetadata(packageJsonType, packageJsonDirectory, getImpliedNodeFormatForFile(fileName, packageJsonType));
|
|
1323
|
+
}
|