tsc-ts 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -1
- package/dist/api/compiler/ast-utilities.d.ts +82 -0
- package/dist/api/compiler/ast-utilities.js +462 -0
- package/dist/api/compiler/ast.d.ts +2350 -0
- package/dist/api/compiler/ast.js +11206 -0
- package/dist/api/compiler/astnav.d.ts +37 -0
- package/dist/api/compiler/astnav.js +767 -0
- package/dist/api/compiler/binder-utilities.d.ts +182 -0
- package/dist/api/compiler/binder-utilities.js +1240 -0
- package/dist/api/compiler/binder.d.ts +33 -0
- package/dist/api/compiler/binder.js +2358 -0
- package/dist/api/compiler/character-codes.d.ts +161 -0
- package/dist/api/compiler/character-codes.js +160 -0
- package/dist/api/compiler/checker-calls.d.ts +46 -0
- package/dist/api/compiler/checker-calls.js +1640 -0
- package/dist/api/compiler/checker-classes.d.ts +30 -0
- package/dist/api/compiler/checker-classes.js +582 -0
- package/dist/api/compiler/checker-contextual.d.ts +77 -0
- package/dist/api/compiler/checker-contextual.js +1136 -0
- package/dist/api/compiler/checker-declaration-order.d.ts +12 -0
- package/dist/api/compiler/checker-declaration-order.js +356 -0
- package/dist/api/compiler/checker-declarations.d.ts +33 -0
- package/dist/api/compiler/checker-declarations.js +888 -0
- package/dist/api/compiler/checker-declared-types.d.ts +48 -0
- package/dist/api/compiler/checker-declared-types.js +787 -0
- package/dist/api/compiler/checker-decorators.d.ts +26 -0
- package/dist/api/compiler/checker-decorators.js +562 -0
- package/dist/api/compiler/checker-deprecation.d.ts +33 -0
- package/dist/api/compiler/checker-deprecation.js +315 -0
- package/dist/api/compiler/checker-destructuring.d.ts +34 -0
- package/dist/api/compiler/checker-destructuring.js +584 -0
- package/dist/api/compiler/checker-elaboration.d.ts +15 -0
- package/dist/api/compiler/checker-elaboration.js +290 -0
- package/dist/api/compiler/checker-emit-helpers.d.ts +58 -0
- package/dist/api/compiler/checker-emit-helpers.js +154 -0
- package/dist/api/compiler/checker-emit-resolver.d.ts +75 -0
- package/dist/api/compiler/checker-emit-resolver.js +579 -0
- package/dist/api/compiler/checker-evaluator.d.ts +27 -0
- package/dist/api/compiler/checker-evaluator.js +188 -0
- package/dist/api/compiler/checker-expressions.d.ts +67 -0
- package/dist/api/compiler/checker-expressions.js +1351 -0
- package/dist/api/compiler/checker-features.d.ts +6 -0
- package/dist/api/compiler/checker-features.js +354 -0
- package/dist/api/compiler/checker-flow.d.ts +86 -0
- package/dist/api/compiler/checker-flow.js +169 -0
- package/dist/api/compiler/checker-functions.d.ts +43 -0
- package/dist/api/compiler/checker-functions.js +1002 -0
- package/dist/api/compiler/checker-generated-code.d.ts +25 -0
- package/dist/api/compiler/checker-generated-code.js +168 -0
- package/dist/api/compiler/checker-globals.d.ts +14 -0
- package/dist/api/compiler/checker-globals.js +37 -0
- package/dist/api/compiler/checker-grammar.d.ts +35 -0
- package/dist/api/compiler/checker-grammar.js +2573 -0
- package/dist/api/compiler/checker-heritage.d.ts +28 -0
- package/dist/api/compiler/checker-heritage.js +900 -0
- package/dist/api/compiler/checker-inference.d.ts +179 -0
- package/dist/api/compiler/checker-inference.js +2105 -0
- package/dist/api/compiler/checker-iteration.d.ts +115 -0
- package/dist/api/compiler/checker-iteration.js +857 -0
- package/dist/api/compiler/checker-javascript.d.ts +42 -0
- package/dist/api/compiler/checker-javascript.js +441 -0
- package/dist/api/compiler/checker-jsdoc.d.ts +30 -0
- package/dist/api/compiler/checker-jsdoc.js +320 -0
- package/dist/api/compiler/checker-jsx.d.ts +94 -0
- package/dist/api/compiler/checker-jsx.js +1433 -0
- package/dist/api/compiler/checker-literals.d.ts +6 -0
- package/dist/api/compiler/checker-literals.js +43 -0
- package/dist/api/compiler/checker-members.d.ts +198 -0
- package/dist/api/compiler/checker-members.js +2126 -0
- package/dist/api/compiler/checker-modules.d.ts +85 -0
- package/dist/api/compiler/checker-modules.js +2141 -0
- package/dist/api/compiler/checker-narrowing.d.ts +120 -0
- package/dist/api/compiler/checker-narrowing.js +2797 -0
- package/dist/api/compiler/checker-object-literals.d.ts +14 -0
- package/dist/api/compiler/checker-object-literals.js +479 -0
- package/dist/api/compiler/checker-operators.d.ts +33 -0
- package/dist/api/compiler/checker-operators.js +1040 -0
- package/dist/api/compiler/checker-overloads.d.ts +7 -0
- package/dist/api/compiler/checker-overloads.js +270 -0
- package/dist/api/compiler/checker-property-access.d.ts +34 -0
- package/dist/api/compiler/checker-property-access.js +672 -0
- package/dist/api/compiler/checker-services.d.ts +49 -0
- package/dist/api/compiler/checker-services.js +995 -0
- package/dist/api/compiler/checker-signatures.d.ts +55 -0
- package/dist/api/compiler/checker-signatures.js +788 -0
- package/dist/api/compiler/checker-source-file.d.ts +27 -0
- package/dist/api/compiler/checker-source-file.js +619 -0
- package/dist/api/compiler/checker-statements.d.ts +18 -0
- package/dist/api/compiler/checker-statements.js +226 -0
- package/dist/api/compiler/checker-super.d.ts +13 -0
- package/dist/api/compiler/checker-super.js +241 -0
- package/dist/api/compiler/checker-symbol-types.d.ts +67 -0
- package/dist/api/compiler/checker-symbol-types.js +1885 -0
- package/dist/api/compiler/checker-symbols.d.ts +181 -0
- package/dist/api/compiler/checker-symbols.js +1782 -0
- package/dist/api/compiler/checker-type-factory.d.ts +142 -0
- package/dist/api/compiler/checker-type-factory.js +2501 -0
- package/dist/api/compiler/checker-type-nodes.d.ts +26 -0
- package/dist/api/compiler/checker-type-nodes.js +828 -0
- package/dist/api/compiler/checker-type-operators.d.ts +109 -0
- package/dist/api/compiler/checker-type-operators.js +1842 -0
- package/dist/api/compiler/checker-types.d.ts +1027 -0
- package/dist/api/compiler/checker-types.js +1697 -0
- package/dist/api/compiler/checker-unused.d.ts +19 -0
- package/dist/api/compiler/checker-unused.js +524 -0
- package/dist/api/compiler/checker-utilities.d.ts +33 -0
- package/dist/api/compiler/checker-utilities.js +141 -0
- package/dist/api/compiler/checker.d.ts +491 -0
- package/dist/api/compiler/checker.js +912 -0
- package/dist/api/compiler/command-line.d.ts +32 -0
- package/dist/api/compiler/command-line.js +383 -0
- package/dist/api/compiler/compile-program.d.ts +118 -0
- package/dist/api/compiler/compile-program.js +384 -0
- package/dist/api/compiler/diagnostic-locales.d.ts +22 -0
- package/dist/api/compiler/diagnostic-locales.js +64 -0
- package/dist/api/compiler/diagnostic-messages.d.ts +2166 -0
- package/dist/api/compiler/diagnostic-messages.js +184 -0
- package/dist/api/compiler/diagnostics.d.ts +167 -0
- package/dist/api/compiler/diagnostics.js +820 -0
- package/dist/api/compiler/emitter.d.ts +71 -0
- package/dist/api/compiler/emitter.js +327 -0
- package/dist/api/compiler/file-include.d.ts +117 -0
- package/dist/api/compiler/file-include.js +536 -0
- package/dist/api/compiler/file-loader.d.ts +261 -0
- package/dist/api/compiler/file-loader.js +1257 -0
- package/dist/api/compiler/file-system.d.ts +51 -0
- package/dist/api/compiler/file-system.js +132 -0
- package/dist/api/compiler/flow.d.ts +60 -0
- package/dist/api/compiler/flow.js +45 -0
- package/dist/api/compiler/instantiation.d.ts +74 -0
- package/dist/api/compiler/instantiation.js +799 -0
- package/dist/api/compiler/jsdoc.d.ts +75 -0
- package/dist/api/compiler/jsdoc.js +1229 -0
- package/dist/api/compiler/link-tables.d.ts +36 -0
- package/dist/api/compiler/link-tables.js +83 -0
- package/dist/api/compiler/locale-data.d.ts +24 -0
- package/dist/api/compiler/locale-data.js +183 -0
- package/dist/api/compiler/locale.d.ts +4 -0
- package/dist/api/compiler/locale.js +317 -0
- package/dist/api/compiler/locales/cs-CZ.d.ts +2 -0
- package/dist/api/compiler/locales/cs-CZ.js +3 -0
- package/dist/api/compiler/locales/de-DE.d.ts +2 -0
- package/dist/api/compiler/locales/de-DE.js +3 -0
- package/dist/api/compiler/locales/es-ES.d.ts +2 -0
- package/dist/api/compiler/locales/es-ES.js +3 -0
- package/dist/api/compiler/locales/fr-FR.d.ts +2 -0
- package/dist/api/compiler/locales/fr-FR.js +3 -0
- package/dist/api/compiler/locales/it-IT.d.ts +2 -0
- package/dist/api/compiler/locales/it-IT.js +3 -0
- package/dist/api/compiler/locales/ja-JP.d.ts +2 -0
- package/dist/api/compiler/locales/ja-JP.js +3 -0
- package/dist/api/compiler/locales/ko-KR.d.ts +2 -0
- package/dist/api/compiler/locales/ko-KR.js +3 -0
- package/dist/api/compiler/locales/pl-PL.d.ts +2 -0
- package/dist/api/compiler/locales/pl-PL.js +3 -0
- package/dist/api/compiler/locales/pt-BR.d.ts +2 -0
- package/dist/api/compiler/locales/pt-BR.js +3 -0
- package/dist/api/compiler/locales/ru-RU.d.ts +2 -0
- package/dist/api/compiler/locales/ru-RU.js +3 -0
- package/dist/api/compiler/locales/tr-TR.d.ts +2 -0
- package/dist/api/compiler/locales/tr-TR.js +3 -0
- package/dist/api/compiler/locales/zh-CN.d.ts +2 -0
- package/dist/api/compiler/locales/zh-CN.js +3 -0
- package/dist/api/compiler/locales/zh-TW.d.ts +2 -0
- package/dist/api/compiler/locales/zh-TW.js +3 -0
- package/dist/api/compiler/module-resolution-types.d.ts +83 -0
- package/dist/api/compiler/module-resolution-types.js +176 -0
- package/dist/api/compiler/module-resolution.d.ts +71 -0
- package/dist/api/compiler/module-resolution.js +1598 -0
- package/dist/api/compiler/module-specifiers.d.ts +64 -0
- package/dist/api/compiler/module-specifiers.js +1101 -0
- package/dist/api/compiler/name-resolver.d.ts +43 -0
- package/dist/api/compiler/name-resolver.js +509 -0
- package/dist/api/compiler/node-builder-names.d.ts +32 -0
- package/dist/api/compiler/node-builder-names.js +854 -0
- package/dist/api/compiler/node-builder-pseudo.d.ts +36 -0
- package/dist/api/compiler/node-builder-pseudo.js +744 -0
- package/dist/api/compiler/node-builder-reuse.d.ts +4 -0
- package/dist/api/compiler/node-builder-reuse.js +647 -0
- package/dist/api/compiler/node-builder.d.ts +270 -0
- package/dist/api/compiler/node-builder.js +2645 -0
- package/dist/api/compiler/option-declarations.d.ts +90 -0
- package/dist/api/compiler/option-declarations.js +1460 -0
- package/dist/api/compiler/options.d.ts +289 -0
- package/dist/api/compiler/options.js +1197 -0
- package/dist/api/compiler/output-paths.d.ts +42 -0
- package/dist/api/compiler/output-paths.js +195 -0
- package/dist/api/compiler/package-json.d.ts +175 -0
- package/dist/api/compiler/package-json.js +1015 -0
- package/dist/api/compiler/parallel-parse.d.ts +219 -0
- package/dist/api/compiler/parallel-parse.js +537 -0
- package/dist/api/compiler/parser.d.ts +587 -0
- package/dist/api/compiler/parser.js +6407 -0
- package/dist/api/compiler/path.d.ts +91 -0
- package/dist/api/compiler/path.js +705 -0
- package/dist/api/compiler/printer/async-helpers.d.ts +22 -0
- package/dist/api/compiler/printer/async-helpers.js +91 -0
- package/dist/api/compiler/printer/auto-generate.d.ts +13 -0
- package/dist/api/compiler/printer/auto-generate.js +20 -0
- package/dist/api/compiler/printer/decorator-helpers.d.ts +24 -0
- package/dist/api/compiler/printer/decorator-helpers.js +118 -0
- package/dist/api/compiler/printer/emit-context.d.ts +154 -0
- package/dist/api/compiler/printer/emit-context.js +576 -0
- package/dist/api/compiler/printer/emit-flags.d.ts +60 -0
- package/dist/api/compiler/printer/emit-flags.js +2 -0
- package/dist/api/compiler/printer/factory-base.d.ts +171 -0
- package/dist/api/compiler/printer/factory-base.js +1505 -0
- package/dist/api/compiler/printer/factory.d.ts +147 -0
- package/dist/api/compiler/printer/factory.js +542 -0
- package/dist/api/compiler/printer/helpers.d.ts +27 -0
- package/dist/api/compiler/printer/helpers.js +164 -0
- package/dist/api/compiler/printer/name-generator.d.ts +41 -0
- package/dist/api/compiler/printer/name-generator.js +283 -0
- package/dist/api/compiler/printer/printer.d.ts +411 -0
- package/dist/api/compiler/printer/printer.js +4517 -0
- package/dist/api/compiler/printer/text-writer.d.ts +46 -0
- package/dist/api/compiler/printer/text-writer.js +172 -0
- package/dist/api/compiler/printer/utilities.d.ts +82 -0
- package/dist/api/compiler/printer/utilities.js +817 -0
- package/dist/api/compiler/program-checker.d.ts +156 -0
- package/dist/api/compiler/program-checker.js +526 -0
- package/dist/api/compiler/program-utilities.d.ts +52 -0
- package/dist/api/compiler/program-utilities.js +365 -0
- package/dist/api/compiler/program.d.ts +180 -0
- package/dist/api/compiler/program.js +1011 -0
- package/dist/api/compiler/pseudo-bigint.d.ts +5 -0
- package/dist/api/compiler/pseudo-bigint.js +61 -0
- package/dist/api/compiler/regexp-checker.d.ts +38 -0
- package/dist/api/compiler/regexp-checker.js +942 -0
- package/dist/api/compiler/relations.d.ts +263 -0
- package/dist/api/compiler/relations.js +4002 -0
- package/dist/api/compiler/reparser.d.ts +48 -0
- package/dist/api/compiler/reparser.js +1323 -0
- package/dist/api/compiler/scanner.d.ts +256 -0
- package/dist/api/compiler/scanner.js +2853 -0
- package/dist/api/compiler/side-state.d.ts +16 -0
- package/dist/api/compiler/side-state.js +89 -0
- package/dist/api/compiler/sourcemap.d.ts +55 -0
- package/dist/api/compiler/sourcemap.js +340 -0
- package/dist/api/compiler/spelling.d.ts +14 -0
- package/dist/api/compiler/spelling.js +128 -0
- package/dist/api/compiler/symbol-accessibility.d.ts +57 -0
- package/dist/api/compiler/symbol-accessibility.js +894 -0
- package/dist/api/compiler/symbol.d.ts +240 -0
- package/dist/api/compiler/symbol.js +228 -0
- package/dist/api/compiler/symlinks.d.ts +32 -0
- package/dist/api/compiler/symlinks.js +114 -0
- package/dist/api/compiler/syntax-kind.d.ts +389 -0
- package/dist/api/compiler/syntax-kind.js +2 -0
- package/dist/api/compiler/timeline.d.ts +9 -0
- package/dist/api/compiler/timeline.js +54 -0
- package/dist/api/compiler/transformers/alias-references.d.ts +39 -0
- package/dist/api/compiler/transformers/alias-references.js +676 -0
- package/dist/api/compiler/transformers/async-utilities.d.ts +51 -0
- package/dist/api/compiler/transformers/async-utilities.js +260 -0
- package/dist/api/compiler/transformers/async.d.ts +53 -0
- package/dist/api/compiler/transformers/async.js +645 -0
- package/dist/api/compiler/transformers/class-fields.d.ts +206 -0
- package/dist/api/compiler/transformers/class-fields.js +2418 -0
- package/dist/api/compiler/transformers/class-utilities.d.ts +46 -0
- package/dist/api/compiler/transformers/class-utilities.js +261 -0
- package/dist/api/compiler/transformers/commonjs-module.d.ts +103 -0
- package/dist/api/compiler/transformers/commonjs-module.js +1180 -0
- package/dist/api/compiler/transformers/const-enum-inliner.d.ts +11 -0
- package/dist/api/compiler/transformers/const-enum-inliner.js +36 -0
- package/dist/api/compiler/transformers/declarations-diagnostics.d.ts +52 -0
- package/dist/api/compiler/transformers/declarations-diagnostics.js +538 -0
- package/dist/api/compiler/transformers/declarations-pseudo.d.ts +160 -0
- package/dist/api/compiler/transformers/declarations-pseudo.js +797 -0
- package/dist/api/compiler/transformers/declarations-resolver.d.ts +152 -0
- package/dist/api/compiler/transformers/declarations-resolver.js +35 -0
- package/dist/api/compiler/transformers/declarations-syntactic.d.ts +119 -0
- package/dist/api/compiler/transformers/declarations-syntactic.js +1582 -0
- package/dist/api/compiler/transformers/declarations-tracker.d.ts +46 -0
- package/dist/api/compiler/transformers/declarations-tracker.js +197 -0
- package/dist/api/compiler/transformers/declarations.d.ts +175 -0
- package/dist/api/compiler/transformers/declarations.js +2380 -0
- package/dist/api/compiler/transformers/decorator-metadata.d.ts +54 -0
- package/dist/api/compiler/transformers/decorator-metadata.js +554 -0
- package/dist/api/compiler/transformers/decorator-utilities.d.ts +38 -0
- package/dist/api/compiler/transformers/decorator-utilities.js +238 -0
- package/dist/api/compiler/transformers/destructuring.d.ts +25 -0
- package/dist/api/compiler/transformers/destructuring.js +626 -0
- package/dist/api/compiler/transformers/downlevel.d.ts +6 -0
- package/dist/api/compiler/transformers/downlevel.js +45 -0
- package/dist/api/compiler/transformers/emit-resolver.d.ts +61 -0
- package/dist/api/compiler/transformers/emit-resolver.js +197 -0
- package/dist/api/compiler/transformers/es-decorators.d.ts +118 -0
- package/dist/api/compiler/transformers/es-decorators.js +1901 -0
- package/dist/api/compiler/transformers/exponentiation.d.ts +11 -0
- package/dist/api/compiler/transformers/exponentiation.js +76 -0
- package/dist/api/compiler/transformers/external-module-info.d.ts +35 -0
- package/dist/api/compiler/transformers/external-module-info.js +351 -0
- package/dist/api/compiler/transformers/for-await.d.ts +43 -0
- package/dist/api/compiler/transformers/for-await.js +469 -0
- package/dist/api/compiler/transformers/import-elision.d.ts +16 -0
- package/dist/api/compiler/transformers/import-elision.js +124 -0
- package/dist/api/compiler/transformers/jsx-entities.d.ts +1 -0
- package/dist/api/compiler/transformers/jsx-entities.js +256 -0
- package/dist/api/compiler/transformers/jsx.d.ts +71 -0
- package/dist/api/compiler/transformers/jsx.js +700 -0
- package/dist/api/compiler/transformers/legacy-decorators.d.ts +56 -0
- package/dist/api/compiler/transformers/legacy-decorators.js +564 -0
- package/dist/api/compiler/transformers/logical-assignment.d.ts +14 -0
- package/dist/api/compiler/transformers/logical-assignment.js +62 -0
- package/dist/api/compiler/transformers/module-utilities.d.ts +9 -0
- package/dist/api/compiler/transformers/module-utilities.js +36 -0
- package/dist/api/compiler/transformers/module.d.ts +49 -0
- package/dist/api/compiler/transformers/module.js +296 -0
- package/dist/api/compiler/transformers/named-evaluation.d.ts +26 -0
- package/dist/api/compiler/transformers/named-evaluation.js +266 -0
- package/dist/api/compiler/transformers/nullish-coalescing.d.ts +9 -0
- package/dist/api/compiler/transformers/nullish-coalescing.js +26 -0
- package/dist/api/compiler/transformers/object-rest-spread.d.ts +34 -0
- package/dist/api/compiler/transformers/object-rest-spread.js +411 -0
- package/dist/api/compiler/transformers/optional-catch.d.ts +9 -0
- package/dist/api/compiler/transformers/optional-catch.js +20 -0
- package/dist/api/compiler/transformers/optional-chain.d.ts +14 -0
- package/dist/api/compiler/transformers/optional-chain.js +188 -0
- package/dist/api/compiler/transformers/reference-resolver.d.ts +128 -0
- package/dist/api/compiler/transformers/reference-resolver.js +1155 -0
- package/dist/api/compiler/transformers/runtime-syntax.d.ts +71 -0
- package/dist/api/compiler/transformers/runtime-syntax.js +753 -0
- package/dist/api/compiler/transformers/subtree-facts.d.ts +9 -0
- package/dist/api/compiler/transformers/subtree-facts.js +203 -0
- package/dist/api/compiler/transformers/syntax-facts.d.ts +51 -0
- package/dist/api/compiler/transformers/syntax-facts.js +254 -0
- package/dist/api/compiler/transformers/tagged-template.d.ts +17 -0
- package/dist/api/compiler/transformers/tagged-template.js +148 -0
- package/dist/api/compiler/transformers/transformer.d.ts +17 -0
- package/dist/api/compiler/transformers/transformer.js +54 -0
- package/dist/api/compiler/transformers/type-eraser.d.ts +21 -0
- package/dist/api/compiler/transformers/type-eraser.js +346 -0
- package/dist/api/compiler/transformers/type-serialization.d.ts +20 -0
- package/dist/api/compiler/transformers/type-serialization.js +347 -0
- package/dist/api/compiler/transformers/using.d.ts +56 -0
- package/dist/api/compiler/transformers/using.js +453 -0
- package/dist/api/compiler/transformers/utilities.d.ts +50 -0
- package/dist/api/compiler/transformers/utilities.js +347 -0
- package/dist/api/compiler/transformers/visitor-base.d.ts +6 -0
- package/dist/api/compiler/transformers/visitor-base.js +817 -0
- package/dist/api/compiler/transformers/visitor-hooks.d.ts +29 -0
- package/dist/api/compiler/transformers/visitor-hooks.js +189 -0
- package/dist/api/compiler/tsconfig.d.ts +177 -0
- package/dist/api/compiler/tsconfig.js +1311 -0
- package/dist/api/compiler/type-printer.d.ts +15 -0
- package/dist/api/compiler/type-printer.js +74 -0
- package/dist/api/compiler/types.d.ts +87 -0
- package/dist/api/compiler/types.js +23 -0
- package/dist/api/compiler/unicode-identifiers.d.ts +2 -0
- package/dist/api/compiler/unicode-identifiers.js +209 -0
- package/dist/api/compiler/unicode-properties.d.ts +8 -0
- package/dist/api/compiler/unicode-properties.js +531 -0
- package/dist/api/compiler/vfs-match.d.ts +24 -0
- package/dist/api/compiler/vfs-match.js +587 -0
- package/dist/api/library/ast.d.ts +3 -2
- package/dist/api/library/ast.generated.d.ts +127 -139
- package/dist/api/library/checker.d.ts +51 -0
- package/dist/api/library/checker.js +318 -0
- package/dist/api/library/diagnostics.d.ts +13 -0
- package/dist/api/library/diagnostics.js +50 -0
- package/dist/api/library/disk.d.ts +13 -0
- package/dist/api/library/disk.js +66 -0
- package/dist/api/library/errors.d.ts +13 -0
- package/dist/api/library/errors.js +24 -0
- package/dist/api/library/host.d.ts +24 -0
- package/dist/api/library/host.js +52 -0
- package/dist/api/library/index.d.ts +5 -1
- package/dist/api/library/index.js +4 -0
- package/dist/api/library/nodes.d.ts +51 -0
- package/dist/api/library/nodes.js +196 -0
- package/dist/api/library/options.d.ts +144 -0
- package/dist/api/library/options.js +308 -0
- package/dist/api/library/parse.d.ts +19 -0
- package/dist/api/library/parse.js +41 -0
- package/dist/api/library/program.d.ts +21 -0
- package/dist/api/library/program.js +234 -0
- package/dist/api/library/types.d.ts +14 -1
- package/package.json +12 -8
- package/src/compiler/ast-utilities.ts +548 -0
- package/src/compiler/ast.ts +12862 -0
- package/src/compiler/astnav.ts +799 -0
- package/src/compiler/binder-utilities.ts +1392 -0
- package/src/compiler/binder.ts +2703 -0
- package/src/compiler/build-info.ts +1197 -0
- package/src/compiler/character-codes.ts +323 -0
- package/src/compiler/checker-calls.ts +2155 -0
- package/src/compiler/checker-classes.ts +706 -0
- package/src/compiler/checker-contextual.ts +1457 -0
- package/src/compiler/checker-declaration-order.ts +438 -0
- package/src/compiler/checker-declarations.ts +1194 -0
- package/src/compiler/checker-declared-types.ts +919 -0
- package/src/compiler/checker-decorators.ts +694 -0
- package/src/compiler/checker-deprecation.ts +359 -0
- package/src/compiler/checker-destructuring.ts +805 -0
- package/src/compiler/checker-elaboration.ts +477 -0
- package/src/compiler/checker-emit-helpers.ts +224 -0
- package/src/compiler/checker-emit-resolver.ts +769 -0
- package/src/compiler/checker-evaluator.ts +243 -0
- package/src/compiler/checker-expressions.ts +1831 -0
- package/src/compiler/checker-features.ts +361 -0
- package/src/compiler/checker-flow.ts +394 -0
- package/src/compiler/checker-functions.ts +1296 -0
- package/src/compiler/checker-generated-code.ts +227 -0
- package/src/compiler/checker-globals.ts +52 -0
- package/src/compiler/checker-grammar.ts +3584 -0
- package/src/compiler/checker-heritage.ts +1233 -0
- package/src/compiler/checker-inference.ts +2576 -0
- package/src/compiler/checker-iteration.ts +1206 -0
- package/src/compiler/checker-javascript.ts +502 -0
- package/src/compiler/checker-jsdoc.ts +360 -0
- package/src/compiler/checker-jsx.ts +1924 -0
- package/src/compiler/checker-literals.ts +61 -0
- package/src/compiler/checker-members.ts +2436 -0
- package/src/compiler/checker-modules.ts +2886 -0
- package/src/compiler/checker-narrowing.ts +3230 -0
- package/src/compiler/checker-object-literals.ts +575 -0
- package/src/compiler/checker-operators.ts +1422 -0
- package/src/compiler/checker-overloads.ts +328 -0
- package/src/compiler/checker-property-access.ts +906 -0
- package/src/compiler/checker-services.ts +1149 -0
- package/src/compiler/checker-signatures.ts +1032 -0
- package/src/compiler/checker-source-file.ts +732 -0
- package/src/compiler/checker-statements.ts +292 -0
- package/src/compiler/checker-super.ts +261 -0
- package/src/compiler/checker-symbol-types.ts +2107 -0
- package/src/compiler/checker-symbols.ts +2150 -0
- package/src/compiler/checker-type-factory.ts +2579 -0
- package/src/compiler/checker-type-nodes.ts +1033 -0
- package/src/compiler/checker-type-operators.ts +2502 -0
- package/src/compiler/checker-types.ts +2340 -0
- package/src/compiler/checker-unused.ts +642 -0
- package/src/compiler/checker-utilities.ts +161 -0
- package/src/compiler/checker.ts +1116 -0
- package/src/compiler/command-line.ts +436 -0
- package/src/compiler/compile-program.ts +439 -0
- package/src/compiler/decoder.ts +1209 -0
- package/src/compiler/diagnostic-locales.ts +86 -0
- package/src/compiler/diagnostic-messages.ts +2349 -0
- package/src/compiler/diagnostics.ts +897 -0
- package/src/compiler/emitter.ts +434 -0
- package/src/compiler/encoder.ts +1945 -0
- package/src/compiler/file-include.ts +673 -0
- package/src/compiler/file-loader.ts +1528 -0
- package/src/compiler/file-system.ts +143 -0
- package/src/compiler/flow.ts +89 -0
- package/src/compiler/help.ts +473 -0
- package/src/compiler/incremental.ts +2784 -0
- package/src/compiler/init.ts +141 -0
- package/src/compiler/instantiation.ts +894 -0
- package/src/compiler/jsdoc.ts +1386 -0
- package/src/compiler/link-tables.ts +98 -0
- package/src/compiler/locale-data.ts +203 -0
- package/src/compiler/locale.ts +307 -0
- package/src/compiler/locales/cs-CZ.ts +5 -0
- package/src/compiler/locales/de-DE.ts +5 -0
- package/src/compiler/locales/es-ES.ts +5 -0
- package/src/compiler/locales/fr-FR.ts +5 -0
- package/src/compiler/locales/it-IT.ts +5 -0
- package/src/compiler/locales/ja-JP.ts +5 -0
- package/src/compiler/locales/ko-KR.ts +5 -0
- package/src/compiler/locales/pl-PL.ts +5 -0
- package/src/compiler/locales/pt-BR.ts +5 -0
- package/src/compiler/locales/ru-RU.ts +5 -0
- package/src/compiler/locales/tr-TR.ts +5 -0
- package/src/compiler/locales/zh-CN.ts +5 -0
- package/src/compiler/locales/zh-TW.ts +5 -0
- package/src/compiler/module-resolution-types.ts +243 -0
- package/src/compiler/module-resolution.ts +2072 -0
- package/src/compiler/module-specifiers.ts +1491 -0
- package/src/compiler/name-resolver.ts +646 -0
- package/src/compiler/node-builder-names.ts +1069 -0
- package/src/compiler/node-builder-pseudo.ts +892 -0
- package/src/compiler/node-builder-reuse.ts +764 -0
- package/src/compiler/node-builder.ts +3425 -0
- package/src/compiler/option-declarations.ts +1560 -0
- package/src/compiler/options.ts +1576 -0
- package/src/compiler/output-paths.ts +334 -0
- package/src/compiler/package-json.ts +1083 -0
- package/src/compiler/parallel-check.ts +1951 -0
- package/src/compiler/parallel-parse.ts +590 -0
- package/src/compiler/parse-thread.ts +140 -0
- package/src/compiler/parser.ts +7716 -0
- package/src/compiler/path.ts +717 -0
- package/src/compiler/printer/async-helpers.ts +183 -0
- package/src/compiler/printer/auto-generate.ts +27 -0
- package/src/compiler/printer/decorator-helpers.ts +218 -0
- package/src/compiler/printer/emit-context.ts +679 -0
- package/src/compiler/printer/emit-flags.ts +64 -0
- package/src/compiler/printer/factory-base.ts +2577 -0
- package/src/compiler/printer/factory.ts +764 -0
- package/src/compiler/printer/helpers.ts +291 -0
- package/src/compiler/printer/name-generator.ts +372 -0
- package/src/compiler/printer/printer.ts +5072 -0
- package/src/compiler/printer/text-writer.ts +183 -0
- package/src/compiler/printer/utilities.ts +884 -0
- package/src/compiler/program-checker.ts +592 -0
- package/src/compiler/program-utilities.ts +435 -0
- package/src/compiler/program.ts +1419 -0
- package/src/compiler/pseudo-bigint.ts +62 -0
- package/src/compiler/regexp-checker.ts +1142 -0
- package/src/compiler/relations.ts +5149 -0
- package/src/compiler/reparser.ts +1566 -0
- package/src/compiler/scanner.ts +2951 -0
- package/src/compiler/show-config.ts +239 -0
- package/src/compiler/side-state.ts +125 -0
- package/src/compiler/sourcemap.ts +366 -0
- package/src/compiler/spelling.ts +122 -0
- package/src/compiler/symbol-accessibility.ts +1071 -0
- package/src/compiler/symbol.ts +439 -0
- package/src/compiler/symlinks.ts +137 -0
- package/src/compiler/syntax-kind.ts +391 -0
- package/src/compiler/thread-entry.ts +191 -0
- package/src/compiler/timeline.ts +53 -0
- package/src/compiler/transformers/alias-references.ts +757 -0
- package/src/compiler/transformers/async-utilities.ts +335 -0
- package/src/compiler/transformers/async.ts +838 -0
- package/src/compiler/transformers/class-fields.ts +2967 -0
- package/src/compiler/transformers/class-utilities.ts +324 -0
- package/src/compiler/transformers/commonjs-module.ts +1621 -0
- package/src/compiler/transformers/const-enum-inliner.ts +50 -0
- package/src/compiler/transformers/declarations-diagnostics.ts +832 -0
- package/src/compiler/transformers/declarations-pseudo.ts +966 -0
- package/src/compiler/transformers/declarations-resolver.ts +249 -0
- package/src/compiler/transformers/declarations-syntactic.ts +1859 -0
- package/src/compiler/transformers/declarations-tracker.ts +269 -0
- package/src/compiler/transformers/declarations.ts +3120 -0
- package/src/compiler/transformers/decorator-metadata.ts +697 -0
- package/src/compiler/transformers/decorator-utilities.ts +283 -0
- package/src/compiler/transformers/destructuring.ts +708 -0
- package/src/compiler/transformers/downlevel.ts +50 -0
- package/src/compiler/transformers/emit-resolver.ts +258 -0
- package/src/compiler/transformers/es-decorators.ts +2682 -0
- package/src/compiler/transformers/exponentiation.ts +80 -0
- package/src/compiler/transformers/external-module-info.ts +412 -0
- package/src/compiler/transformers/for-await.ts +687 -0
- package/src/compiler/transformers/import-elision.ts +152 -0
- package/src/compiler/transformers/jsx-entities.ts +256 -0
- package/src/compiler/transformers/jsx.ts +824 -0
- package/src/compiler/transformers/legacy-decorators.ts +726 -0
- package/src/compiler/transformers/logical-assignment.ts +75 -0
- package/src/compiler/transformers/module-utilities.ts +42 -0
- package/src/compiler/transformers/module.ts +474 -0
- package/src/compiler/transformers/named-evaluation.ts +389 -0
- package/src/compiler/transformers/nullish-coalescing.ts +35 -0
- package/src/compiler/transformers/object-rest-spread.ts +577 -0
- package/src/compiler/transformers/optional-catch.ts +29 -0
- package/src/compiler/transformers/optional-chain.ts +246 -0
- package/src/compiler/transformers/reference-resolver.ts +1201 -0
- package/src/compiler/transformers/runtime-syntax.ts +942 -0
- package/src/compiler/transformers/subtree-facts.ts +245 -0
- package/src/compiler/transformers/syntax-facts.ts +353 -0
- package/src/compiler/transformers/tagged-template.ts +167 -0
- package/src/compiler/transformers/transformer.ts +56 -0
- package/src/compiler/transformers/type-eraser.ts +520 -0
- package/src/compiler/transformers/type-serialization.ts +374 -0
- package/src/compiler/transformers/using.ts +613 -0
- package/src/compiler/transformers/utilities.ts +419 -0
- package/src/compiler/transformers/visitor-base.ts +1601 -0
- package/src/compiler/transformers/visitor-hooks.ts +252 -0
- package/src/compiler/tsc-build.ts +1418 -0
- package/src/compiler/tsc-cli.ts +666 -0
- package/src/compiler/tsc-compile.ts +437 -0
- package/src/compiler/tsc-watch.ts +854 -0
- package/src/compiler/tsconfig.ts +1574 -0
- package/src/compiler/type-printer.ts +110 -0
- package/src/compiler/types.ts +115 -0
- package/src/compiler/unicode-identifiers.ts +212 -0
- package/src/compiler/unicode-properties.ts +537 -0
- package/src/compiler/vfs-match.ts +597 -0
- package/src/compiler/xxh3.ts +650 -0
- package/src/library/ast.generated.ts +141 -167
- package/src/library/ast.ts +4 -1
- package/src/library/checker.ts +384 -0
- package/src/library/diagnostics.ts +72 -0
- package/src/library/disk.ts +73 -0
- package/src/library/errors.ts +26 -0
- package/src/library/host.ts +63 -0
- package/src/library/index.ts +21 -0
- package/src/library/nodes.ts +232 -0
- package/src/library/options.ts +449 -0
- package/src/library/parse.ts +63 -0
- package/src/library/program.ts +293 -0
- package/src/library/types.ts +14 -1
|
@@ -0,0 +1,897 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diagnostics: message lookup and localization, the `Diagnostic` type, and tsc's plain and
|
|
3
|
+
* pretty diagnostic output.
|
|
4
|
+
*/
|
|
5
|
+
import { CharacterCodes, isDigit, isUnicodeWhiteSpace, utf8Length } from './character-codes.js';
|
|
6
|
+
import { Locale, translations } from './diagnostic-locales.js';
|
|
7
|
+
import { Diagnostics, messageCodes, messageFlags, messageKeys, messageTexts } from './diagnostic-messages.js';
|
|
8
|
+
import { getPathComponentsRelativeTo, getPathFromPathComponents, isRootedDiskPath, pathIsAbsolute } from './path.js';
|
|
9
|
+
import { computeLineOfPosition, computeLineStarts } from './scanner.js';
|
|
10
|
+
|
|
11
|
+
export { Diagnostics, Locale };
|
|
12
|
+
export { parseLocale } from './locale.js';
|
|
13
|
+
|
|
14
|
+
export const enum DiagnosticCategory {
|
|
15
|
+
Warning = 0,
|
|
16
|
+
Error = 1,
|
|
17
|
+
Suggestion = 2,
|
|
18
|
+
Message = 3,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** A diagnostic message template, e.g. `Diagnostics.X_0_expected` for `'{0}' expected.`. */
|
|
22
|
+
export type DiagnosticMessage = Diagnostics;
|
|
23
|
+
|
|
24
|
+
const reportsUnnecessaryFlag = 4;
|
|
25
|
+
const elidedInCompatibilityPyramidFlag = 8;
|
|
26
|
+
const reportsDeprecatedFlag = 16;
|
|
27
|
+
|
|
28
|
+
export function categoryName(category: DiagnosticCategory): string {
|
|
29
|
+
switch (category) {
|
|
30
|
+
case DiagnosticCategory.Warning:
|
|
31
|
+
return 'warning';
|
|
32
|
+
case DiagnosticCategory.Error:
|
|
33
|
+
return 'error';
|
|
34
|
+
case DiagnosticCategory.Suggestion:
|
|
35
|
+
return 'suggestion';
|
|
36
|
+
case DiagnosticCategory.Message:
|
|
37
|
+
return 'message';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function messageCode(message: DiagnosticMessage): number {
|
|
42
|
+
return messageCodes[message]!;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function messageCategory(message: DiagnosticMessage): DiagnosticCategory {
|
|
46
|
+
return (messageFlags[message] & 3) as DiagnosticCategory;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function messageReportsUnnecessary(message: DiagnosticMessage): boolean {
|
|
50
|
+
return (messageFlags[message] & reportsUnnecessaryFlag) !== 0;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function messageElidedInCompatibilityPyramid(message: DiagnosticMessage): boolean {
|
|
54
|
+
return (messageFlags[message] & elidedInCompatibilityPyramidFlag) !== 0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function messageReportsDeprecated(message: DiagnosticMessage): boolean {
|
|
58
|
+
return (messageFlags[message] & reportsDeprecatedFlag) !== 0;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Texts are split out of the generated strings on first use. Index 0 holds English.
|
|
62
|
+
const texts: string[][] = [];
|
|
63
|
+
let keys: string[] = [];
|
|
64
|
+
let messagesByKey: Map<string, DiagnosticMessage> | undefined;
|
|
65
|
+
|
|
66
|
+
function textOf(locale: Locale, message: DiagnosticMessage): string {
|
|
67
|
+
while (texts.length <= locale) texts.push([]);
|
|
68
|
+
let table = texts[locale]!;
|
|
69
|
+
if (table.length === 0) {
|
|
70
|
+
table = (locale === Locale.Default ? messageTexts : translations(locale)).split('\n');
|
|
71
|
+
texts[locale] = table;
|
|
72
|
+
}
|
|
73
|
+
return table[message] ?? '';
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function keyList(): readonly string[] {
|
|
77
|
+
if (keys.length === 0) keys = messageKeys.split('\n');
|
|
78
|
+
return keys;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The message's key, e.g. `_0_expected_1005`, which identifies it in translations and build info. */
|
|
82
|
+
export function messageKey(message: DiagnosticMessage): string {
|
|
83
|
+
return keyList()[message] ?? '';
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The message's English text. */
|
|
87
|
+
export function messageText(message: DiagnosticMessage): string {
|
|
88
|
+
return textOf(Locale.Default, message);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Finds a message by its key. */
|
|
92
|
+
export function messageForKey(key: string): DiagnosticMessage | undefined {
|
|
93
|
+
if (messagesByKey === undefined) {
|
|
94
|
+
messagesByKey = new Map();
|
|
95
|
+
const all = keyList();
|
|
96
|
+
for (let i = 0; i < all.length; i++) messagesByKey.set(all[i]!, i as DiagnosticMessage);
|
|
97
|
+
}
|
|
98
|
+
return messagesByKey.get(key);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** The message's text in `locale`, with `{n}` placeholders replaced by `args[n]`. */
|
|
102
|
+
export function localizeMessage(locale: Locale, message: DiagnosticMessage, args: readonly string[]): string {
|
|
103
|
+
const translated = locale === Locale.Default ? '' : textOf(locale, message);
|
|
104
|
+
return formatMessage(translated !== '' ? translated : textOf(Locale.Default, message), args);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Replaces `{n}` placeholders in `text` with `args[n]`. With no arguments, `text` is returned as is. A
|
|
109
|
+
* placeholder without an argument stays as it is. tsgo panics there instead ("Invalid formatting
|
|
110
|
+
* placeholder"), which ends the run before it reports the rest of its diagnostics.
|
|
111
|
+
*/
|
|
112
|
+
export function formatMessage(text: string, args: readonly string[]): string {
|
|
113
|
+
if (args.length === 0) return text;
|
|
114
|
+
let result = '';
|
|
115
|
+
let start = 0;
|
|
116
|
+
for (let open = text.indexOf('{'); open >= 0; open = text.indexOf('{', open + 1)) {
|
|
117
|
+
let close = open + 1;
|
|
118
|
+
while (close < text.length && isDigit(text.charCodeAt(close))) close++;
|
|
119
|
+
if (close === open + 1 || close >= text.length || text.charCodeAt(close) !== 0x7d) continue;
|
|
120
|
+
const index = Number(text.slice(open + 1, close));
|
|
121
|
+
if (index >= args.length) continue;
|
|
122
|
+
result += text.slice(start, open) + toWellFormed(args[index]!);
|
|
123
|
+
start = close + 1;
|
|
124
|
+
open = close;
|
|
125
|
+
}
|
|
126
|
+
return result + text.slice(start);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Replaces lone surrogates with U+FFFD, as tsgo makes arguments valid UTF-8. */
|
|
130
|
+
function toWellFormed(text: string): string {
|
|
131
|
+
for (let i = 0; i < text.length; i++) {
|
|
132
|
+
const c = text.charCodeAt(i);
|
|
133
|
+
if (c < 0xd800 || c > 0xdfff) continue;
|
|
134
|
+
if (c <= 0xdbff && i + 1 < text.length) {
|
|
135
|
+
const next = text.charCodeAt(i + 1);
|
|
136
|
+
if (next >= 0xdc00 && next <= 0xdfff) {
|
|
137
|
+
i++;
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
text = text.slice(0, i) + '�' + text.slice(i + 1);
|
|
142
|
+
}
|
|
143
|
+
return text;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Where this thread computes the line starts and UTF-8 offsets of files that may be shared with other
|
|
148
|
+
* threads (`useThreadTextCaches`): a copy of each such file, by file, that computes them in place.
|
|
149
|
+
* Files leave the parser with line starts, except declaration files, and without UTF-8 offsets.
|
|
150
|
+
*/
|
|
151
|
+
let threadCopies: Map<DiagnosticFile, DiagnosticFile> | undefined = undefined;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Makes this thread compute the caches of files that do not have them yet in copies of its own: the
|
|
155
|
+
* files may be published (immutable) and shared with other threads. Declaration files leave the
|
|
156
|
+
* parser without them (`Parser.parseSourceFile`): they make up most of the text of a typical program,
|
|
157
|
+
* and are rarely checked or pointed into by a diagnostic.
|
|
158
|
+
*/
|
|
159
|
+
export function useThreadTextCaches(): void {
|
|
160
|
+
if (threadCopies === undefined) threadCopies = new Map<DiagnosticFile, DiagnosticFile>();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** This thread's copy of `file` for its caches, if this thread computes them in copies. */
|
|
164
|
+
function threadCopyOf(file: DiagnosticFile): DiagnosticFile | undefined {
|
|
165
|
+
const copies = threadCopies;
|
|
166
|
+
if (copies === undefined || file.isThreadCopy) return undefined;
|
|
167
|
+
let copy = copies.get(file);
|
|
168
|
+
if (copy === undefined) {
|
|
169
|
+
copy = new DiagnosticFile(file.fileName, file.text);
|
|
170
|
+
// A copy computes its caches in place, each on first use.
|
|
171
|
+
copy.isThreadCopy = true;
|
|
172
|
+
copies.set(file, copy);
|
|
173
|
+
}
|
|
174
|
+
return copy;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** The position of the first code unit at or after `pos` that is a CR or below, or not ASCII; or `end`. */
|
|
178
|
+
function skipPlainASCII(units: Uint16Array, pos: number, end: number): number {
|
|
179
|
+
for (let i = pos | 0; i < end; i = (i + 1) | 0) {
|
|
180
|
+
const c = units[i] | 0;
|
|
181
|
+
if (c <= CharacterCodes.carriageReturn || c >= 0x80) return i;
|
|
182
|
+
}
|
|
183
|
+
return end;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** The text of a file diagnostics point into. */
|
|
187
|
+
export class DiagnosticFile {
|
|
188
|
+
readonly fileName: string;
|
|
189
|
+
readonly text: string;
|
|
190
|
+
// Computed on first use; never empty once computed.
|
|
191
|
+
private lineStarts: number[] = [];
|
|
192
|
+
/** Whether this is a thread's copy of a possibly shared file (`threadCopyOf`). */
|
|
193
|
+
isThreadCopy = false;
|
|
194
|
+
|
|
195
|
+
constructor(fileName: string, text: string) {
|
|
196
|
+
this.fileName = fileName;
|
|
197
|
+
this.text = text;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Computes the line starts, so that later reads never write to the file. The UTF-8 offsets, which
|
|
202
|
+
* only incremental builds read (for the diagnostics they store), are computed on first use, in a
|
|
203
|
+
* thread's copy where the file may be shared (`useThreadTextCaches`).
|
|
204
|
+
*/
|
|
205
|
+
computeCaches(): void {
|
|
206
|
+
if (this.lineStarts.length === 0) this.lineStarts = computeLineStarts(this.text);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Like `computeCaches`, from the text's UTF-16 code units `units[0, text.length)`, so the text
|
|
211
|
+
* itself is neither searched nor copied.
|
|
212
|
+
*/
|
|
213
|
+
computeCachesFromUnits(units: Uint16Array): void {
|
|
214
|
+
const text = this.text;
|
|
215
|
+
// ASCII texts are searched faster than walked.
|
|
216
|
+
if (this.lineStarts.length !== 0 || Buffer.byteLength(text, 'utf8') === text.length) {
|
|
217
|
+
this.computeCaches();
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
const length = text.length | 0;
|
|
221
|
+
const lineStarts: number[] = [0];
|
|
222
|
+
// Visit only the code units that may break a line; `skipPlainASCII` runs over the rest without
|
|
223
|
+
// calls, so native builds keep its loop on registers. A CR followed by an LF leaves the line start
|
|
224
|
+
// to the LF.
|
|
225
|
+
for (let i = skipPlainASCII(units, 0, length); i < length; i = skipPlainASCII(units, (i + 1) | 0, length)) {
|
|
226
|
+
const ch = units[i] | 0;
|
|
227
|
+
if (
|
|
228
|
+
ch === CharacterCodes.lineFeed ||
|
|
229
|
+
(ch === CharacterCodes.carriageReturn &&
|
|
230
|
+
(i + 1 >= length || (units[(i + 1) | 0] | 0) !== CharacterCodes.lineFeed)) ||
|
|
231
|
+
ch === CharacterCodes.lineSeparator ||
|
|
232
|
+
ch === CharacterCodes.paragraphSeparator
|
|
233
|
+
)
|
|
234
|
+
lineStarts.push(i + 1);
|
|
235
|
+
}
|
|
236
|
+
this.lineStarts = lineStarts;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** Start offsets of each line, split at CR, LF, CRLF, LS and PS. */
|
|
240
|
+
getLineStarts(): readonly number[] {
|
|
241
|
+
if (this.lineStarts.length === 0) {
|
|
242
|
+
const copy = threadCopyOf(this);
|
|
243
|
+
if (copy !== undefined) return copy.getLineStarts();
|
|
244
|
+
this.lineStarts = computeLineStarts(this.text);
|
|
245
|
+
}
|
|
246
|
+
return this.lineStarts;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// The non-ASCII characters, in order: their UTF-16 offsets, UTF-8 lengths, and the UTF-8 bytes
|
|
250
|
+
// beyond one per UTF-16 code unit of the text up to and including each. Unset until first used.
|
|
251
|
+
private nonASCIIStarts: number[] | undefined = undefined;
|
|
252
|
+
private nonASCIILengths: number[] = [];
|
|
253
|
+
private extraBytes: number[] = [];
|
|
254
|
+
|
|
255
|
+
private getNonASCIIStarts(): number[] {
|
|
256
|
+
let starts = this.nonASCIIStarts;
|
|
257
|
+
if (starts === undefined) {
|
|
258
|
+
starts = [];
|
|
259
|
+
const text = this.text;
|
|
260
|
+
if (Buffer.byteLength(text, 'utf8') !== text.length) {
|
|
261
|
+
// Scanning the UTF-8 encoding is faster than reading each code unit.
|
|
262
|
+
const bytes = Buffer.from(text, 'utf8');
|
|
263
|
+
const lengths = this.nonASCIILengths;
|
|
264
|
+
const extraBytes = this.extraBytes;
|
|
265
|
+
let extra = 0;
|
|
266
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
267
|
+
const b = bytes[i]!;
|
|
268
|
+
if (b < 0x80) continue;
|
|
269
|
+
// A lone surrogate is encoded as U+FFFD, in 3 bytes.
|
|
270
|
+
const length = b >= 0xf0 ? 4 : b >= 0xe0 ? 3 : 2;
|
|
271
|
+
starts.push(i - extra);
|
|
272
|
+
lengths.push(length);
|
|
273
|
+
extra += length === 4 ? 2 : length - 1;
|
|
274
|
+
extraBytes.push(extra);
|
|
275
|
+
i += length - 1;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
this.nonASCIIStarts = starts;
|
|
279
|
+
}
|
|
280
|
+
return starts;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** The number of non-ASCII characters starting before UTF-16 offset `pos`. */
|
|
284
|
+
private countNonASCIIBefore(starts: readonly number[], pos: number): number {
|
|
285
|
+
let low = 0;
|
|
286
|
+
let high = starts.length;
|
|
287
|
+
while (low < high) {
|
|
288
|
+
const middle = (low + high) >> 1;
|
|
289
|
+
if (starts[middle]! < pos) low = middle + 1;
|
|
290
|
+
else high = middle;
|
|
291
|
+
}
|
|
292
|
+
return low;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/** The UTF-8 offset of UTF-16 offset `pos`, as tsgo counts positions. */
|
|
296
|
+
toUtf8Offset(pos: number): number {
|
|
297
|
+
if (this.nonASCIIStarts === undefined) {
|
|
298
|
+
const copy = threadCopyOf(this);
|
|
299
|
+
if (copy !== undefined) return copy.toUtf8Offset(pos);
|
|
300
|
+
}
|
|
301
|
+
const starts = this.getNonASCIIStarts();
|
|
302
|
+
if (starts.length === 0 || pos <= 0 || pos > this.text.length) return pos;
|
|
303
|
+
const count = this.countNonASCIIBefore(starts, pos);
|
|
304
|
+
if (count === 0) return pos;
|
|
305
|
+
const last = count - 1;
|
|
306
|
+
// The middle of a surrogate pair shares its start's offset.
|
|
307
|
+
if (this.nonASCIILengths[last] === 4 && starts[last]! + 1 === pos)
|
|
308
|
+
return starts[last]! + (last === 0 ? 0 : this.extraBytes[last - 1]!);
|
|
309
|
+
return pos + this.extraBytes[last]!;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** The UTF-16 offset of UTF-8 offset `pos`; inside a character, the offset of its start. */
|
|
313
|
+
fromUtf8Offset(pos: number): number {
|
|
314
|
+
if (this.nonASCIIStarts === undefined) {
|
|
315
|
+
const copy = threadCopyOf(this);
|
|
316
|
+
if (copy !== undefined) return copy.fromUtf8Offset(pos);
|
|
317
|
+
}
|
|
318
|
+
const starts = this.getNonASCIIStarts();
|
|
319
|
+
if (starts.length === 0 || pos <= 0) return pos;
|
|
320
|
+
const extraBytes = this.extraBytes;
|
|
321
|
+
// The last non-ASCII character starting at or before `pos`, in UTF-8.
|
|
322
|
+
let low = 0;
|
|
323
|
+
let high = starts.length;
|
|
324
|
+
while (low < high) {
|
|
325
|
+
const middle = (low + high) >> 1;
|
|
326
|
+
const start8 = starts[middle]! + (middle === 0 ? 0 : extraBytes[middle - 1]!);
|
|
327
|
+
if (start8 <= pos) low = middle + 1;
|
|
328
|
+
else high = middle;
|
|
329
|
+
}
|
|
330
|
+
if (low === 0) return pos;
|
|
331
|
+
const index = low - 1;
|
|
332
|
+
const start = starts[index]!;
|
|
333
|
+
const end8 = start + (index === 0 ? 0 : extraBytes[index - 1]!) + this.nonASCIILengths[index]!;
|
|
334
|
+
if (pos < end8) return start;
|
|
335
|
+
return pos - extraBytes[index]!;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/** What a message chain entry is recomputed from when an incremental build reuses it (`RepopulateInfo`). */
|
|
340
|
+
export const enum RepopulateKind {
|
|
341
|
+
/** How to make a CommonJS file an ES module. */
|
|
342
|
+
ModeMismatch = 1,
|
|
343
|
+
/** Where types for a module might come from. */
|
|
344
|
+
ModuleNotFound = 2,
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* How to recompute a message chain entry that depends on the program (`package.json` scopes, the
|
|
349
|
+
* packages, alternate resolutions) when an incremental build reuses the diagnostic, like tsgo's
|
|
350
|
+
* `RepopulateDiagnosticInfo`.
|
|
351
|
+
*/
|
|
352
|
+
export class RepopulateInfo {
|
|
353
|
+
constructor(
|
|
354
|
+
readonly kind: RepopulateKind,
|
|
355
|
+
readonly moduleReference = '',
|
|
356
|
+
/** The resolution mode of the import (a `ModuleKind`). */
|
|
357
|
+
readonly mode = 0,
|
|
358
|
+
/** The package the types were looked up for, `''` when it is the module reference. */
|
|
359
|
+
readonly packageName = '',
|
|
360
|
+
) {}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* A diagnostic: a message with arguments, optionally at a span of a file. Positions are UTF-16
|
|
365
|
+
* offsets; compiler diagnostics have no file and a position of -1.
|
|
366
|
+
*
|
|
367
|
+
* `messageChain` holds the elaborations printed indented below the message; they are diagnostics
|
|
368
|
+
* whose file and position are not printed, but recorded in build info.
|
|
369
|
+
*/
|
|
370
|
+
export class Diagnostic {
|
|
371
|
+
file: DiagnosticFile | undefined;
|
|
372
|
+
pos: number;
|
|
373
|
+
end: number;
|
|
374
|
+
code: number;
|
|
375
|
+
category: DiagnosticCategory;
|
|
376
|
+
readonly message: DiagnosticMessage;
|
|
377
|
+
readonly args: readonly string[];
|
|
378
|
+
messageChain: Diagnostic[] = [];
|
|
379
|
+
relatedInformation: Diagnostic[] = [];
|
|
380
|
+
readonly reportsUnnecessary: boolean;
|
|
381
|
+
readonly reportsDeprecated: boolean;
|
|
382
|
+
skippedOnNoEmit = false;
|
|
383
|
+
repopulateInfo: RepopulateInfo | undefined = undefined;
|
|
384
|
+
|
|
385
|
+
constructor(
|
|
386
|
+
file: DiagnosticFile | undefined,
|
|
387
|
+
pos: number,
|
|
388
|
+
end: number,
|
|
389
|
+
message: DiagnosticMessage,
|
|
390
|
+
args: readonly string[] = [],
|
|
391
|
+
) {
|
|
392
|
+
this.file = file;
|
|
393
|
+
this.pos = pos;
|
|
394
|
+
this.end = end;
|
|
395
|
+
this.code = messageCode(message);
|
|
396
|
+
this.category = messageCategory(message);
|
|
397
|
+
this.message = message;
|
|
398
|
+
this.args = args;
|
|
399
|
+
this.reportsUnnecessary = messageReportsUnnecessary(message);
|
|
400
|
+
this.reportsDeprecated = messageReportsDeprecated(message);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
localize(locale: Locale): string {
|
|
404
|
+
return localizeMessage(locale, this.message, this.args);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
addMessageChain(chain: Diagnostic | undefined): Diagnostic {
|
|
408
|
+
if (chain !== undefined) this.messageChain.push(chain);
|
|
409
|
+
return this;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
addRelatedInfo(related: Diagnostic | undefined): Diagnostic {
|
|
413
|
+
if (related !== undefined) this.relatedInformation.push(related);
|
|
414
|
+
return this;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
clone(): Diagnostic {
|
|
418
|
+
const result = new Diagnostic(this.file, this.pos, this.end, this.message, this.args);
|
|
419
|
+
result.code = this.code;
|
|
420
|
+
result.category = this.category;
|
|
421
|
+
result.messageChain = this.messageChain;
|
|
422
|
+
result.relatedInformation = this.relatedInformation;
|
|
423
|
+
result.skippedOnNoEmit = this.skippedOnNoEmit;
|
|
424
|
+
result.repopulateInfo = this.repopulateInfo;
|
|
425
|
+
return result;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/** A message with its arguments and no location, such as a module resolution trace. */
|
|
430
|
+
export interface MessageWithArgs {
|
|
431
|
+
readonly message: DiagnosticMessage;
|
|
432
|
+
readonly args: readonly string[];
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
export function messageWithArgs(message: DiagnosticMessage, ...args: string[]): MessageWithArgs {
|
|
436
|
+
return { message, args };
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/** An entry of `Diagnostic.messageChain`. */
|
|
440
|
+
export type DiagnosticMessageChain = Diagnostic;
|
|
441
|
+
|
|
442
|
+
export function createDiagnostic(
|
|
443
|
+
file: DiagnosticFile | undefined,
|
|
444
|
+
pos: number,
|
|
445
|
+
end: number,
|
|
446
|
+
message: DiagnosticMessage,
|
|
447
|
+
...args: string[]
|
|
448
|
+
): Diagnostic {
|
|
449
|
+
return new Diagnostic(file, pos, end, message, args);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/** A diagnostic without a file, such as an options error. */
|
|
453
|
+
export function createCompilerDiagnostic(message: DiagnosticMessage, ...args: string[]): Diagnostic {
|
|
454
|
+
return new Diagnostic(undefined, -1, -1, message, args);
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/** A diagnostic for `message` that elaborates with `chain`, taking its location and related information. */
|
|
458
|
+
export function chainDiagnostic(
|
|
459
|
+
chain: Diagnostic | undefined,
|
|
460
|
+
message: DiagnosticMessage,
|
|
461
|
+
...args: string[]
|
|
462
|
+
): Diagnostic {
|
|
463
|
+
if (chain === undefined) return new Diagnostic(undefined, 0, 0, message, args);
|
|
464
|
+
const result = new Diagnostic(chain.file, chain.pos, chain.end, message, args).addMessageChain(chain);
|
|
465
|
+
// A copy: related information added to the result later is not part of the chained diagnostic, as in tsgo.
|
|
466
|
+
result.relatedInformation = chain.relatedInformation.slice();
|
|
467
|
+
return result;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
//// Ordering
|
|
471
|
+
|
|
472
|
+
/** Orders strings by code point, like Go's byte-wise comparison of UTF-8. */
|
|
473
|
+
export function compareCodePoints(a: string, b: string): number {
|
|
474
|
+
if (a === b) return 0;
|
|
475
|
+
// Integer lengths and bound: with a double bound (Math.min, or lengths not coerced) scriptc
|
|
476
|
+
// rounds the trip count with a libm ceil call on every call.
|
|
477
|
+
const aLength = a.length | 0;
|
|
478
|
+
const bLength = b.length | 0;
|
|
479
|
+
const length = aLength < bLength ? aLength : bLength;
|
|
480
|
+
for (let i = 0; i < length; i++) {
|
|
481
|
+
const x = a.charCodeAt(i);
|
|
482
|
+
const y = b.charCodeAt(i);
|
|
483
|
+
if (x !== y) return x < 0xd800 && y < 0xd800 ? (x < y ? -1 : 1) : compareUnitsAsCodePoints(x, y);
|
|
484
|
+
}
|
|
485
|
+
// Different strings with a common prefix of the shorter one's length differ in length.
|
|
486
|
+
return aLength < bLength ? -1 : 1;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/** Orders two different UTF-16 units as the code points they start. */
|
|
490
|
+
function compareUnitsAsCodePoints(x: number, y: number): number {
|
|
491
|
+
// Surrogates encode code points above every other UTF-16 unit.
|
|
492
|
+
if (x >= 0xd800 && x <= 0xdfff) x += 0x10000;
|
|
493
|
+
if (y >= 0xd800 && y <= 0xdfff) y += 0x10000;
|
|
494
|
+
return x < y ? -1 : 1;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
function compareArgs(a: readonly string[], b: readonly string[]): number {
|
|
498
|
+
const length = Math.min(a.length, b.length);
|
|
499
|
+
for (let i = 0; i < length; i++) {
|
|
500
|
+
const c = compareCodePoints(a[i]!, b[i]!);
|
|
501
|
+
if (c !== 0) return c;
|
|
502
|
+
}
|
|
503
|
+
return a.length - b.length;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
function equalArgs(a: readonly string[], b: readonly string[]): boolean {
|
|
507
|
+
if (a.length !== b.length) return false;
|
|
508
|
+
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
|
|
509
|
+
return true;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
function fileNameOf(d: Diagnostic): string {
|
|
513
|
+
return d.file === undefined ? '' : d.file.fileName;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
function compareChainSize(a: readonly Diagnostic[], b: readonly Diagnostic[]): number {
|
|
517
|
+
if (a.length !== b.length) return b.length - a.length;
|
|
518
|
+
for (let i = 0; i < a.length; i++) {
|
|
519
|
+
const c = compareChainSize(a[i]!.messageChain, b[i]!.messageChain);
|
|
520
|
+
if (c !== 0) return c;
|
|
521
|
+
}
|
|
522
|
+
return 0;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
function compareChainContent(a: readonly Diagnostic[], b: readonly Diagnostic[]): number {
|
|
526
|
+
for (let i = 0; i < a.length; i++) {
|
|
527
|
+
let c = compareArgs(a[i]!.args, b[i]!.args);
|
|
528
|
+
if (c !== 0) return c;
|
|
529
|
+
c = compareChainContent(a[i]!.messageChain, b[i]!.messageChain);
|
|
530
|
+
if (c !== 0) return c;
|
|
531
|
+
}
|
|
532
|
+
return 0;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
function compareRelatedInfo(a: readonly Diagnostic[], b: readonly Diagnostic[]): number {
|
|
536
|
+
if (a.length !== b.length) return b.length - a.length;
|
|
537
|
+
for (let i = 0; i < a.length; i++) {
|
|
538
|
+
const c = compareDiagnostics(a[i]!, b[i]!);
|
|
539
|
+
if (c !== 0) return c;
|
|
540
|
+
}
|
|
541
|
+
return 0;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/** The order tsc reports diagnostics in: by file, position, code, arguments, then elaboration. */
|
|
545
|
+
export function compareDiagnostics(a: Diagnostic, b: Diagnostic): number {
|
|
546
|
+
if (a === b) return 0;
|
|
547
|
+
let c = compareCodePoints(fileNameOf(a), fileNameOf(b));
|
|
548
|
+
if (c !== 0) return c;
|
|
549
|
+
c = a.pos - b.pos;
|
|
550
|
+
if (c !== 0) return c;
|
|
551
|
+
c = a.end - b.end;
|
|
552
|
+
if (c !== 0) return c;
|
|
553
|
+
c = a.code - b.code;
|
|
554
|
+
if (c !== 0) return c;
|
|
555
|
+
c = compareArgs(a.args, b.args);
|
|
556
|
+
if (c !== 0) return c;
|
|
557
|
+
c = compareChainSize(a.messageChain, b.messageChain);
|
|
558
|
+
if (c !== 0) return c;
|
|
559
|
+
c = compareChainContent(a.messageChain, b.messageChain);
|
|
560
|
+
if (c !== 0) return c;
|
|
561
|
+
return compareRelatedInfo(a.relatedInformation, b.relatedInformation);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
function equalChain(a: readonly Diagnostic[], b: readonly Diagnostic[]): boolean {
|
|
565
|
+
if (a.length !== b.length) return false;
|
|
566
|
+
for (let i = 0; i < a.length; i++) {
|
|
567
|
+
if (a[i] === b[i]) continue;
|
|
568
|
+
if (a[i].code !== b[i].code || !equalArgs(a[i].args, b[i].args)) return false;
|
|
569
|
+
if (!equalChain(a[i].messageChain, b[i].messageChain)) return false;
|
|
570
|
+
}
|
|
571
|
+
return true;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/** Whether two diagnostics report the same thing, ignoring related information. */
|
|
575
|
+
export function equalDiagnosticsNoRelatedInfo(a: Diagnostic, b: Diagnostic): boolean {
|
|
576
|
+
if (a === b) return true;
|
|
577
|
+
return (
|
|
578
|
+
fileNameOf(a) === fileNameOf(b) &&
|
|
579
|
+
a.pos === b.pos &&
|
|
580
|
+
a.end === b.end &&
|
|
581
|
+
a.code === b.code &&
|
|
582
|
+
equalArgs(a.args, b.args) &&
|
|
583
|
+
equalChain(a.messageChain, b.messageChain)
|
|
584
|
+
);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
export function equalDiagnostics(a: Diagnostic, b: Diagnostic): boolean {
|
|
588
|
+
if (a === b) return true;
|
|
589
|
+
if (!equalDiagnosticsNoRelatedInfo(a, b)) return false;
|
|
590
|
+
if (a.relatedInformation.length !== b.relatedInformation.length) return false;
|
|
591
|
+
for (let i = 0; i < a.relatedInformation.length; i++) {
|
|
592
|
+
if (!equalDiagnostics(a.relatedInformation[i]!, b.relatedInformation[i]!)) return false;
|
|
593
|
+
}
|
|
594
|
+
return true;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
//// Output
|
|
598
|
+
|
|
599
|
+
export interface DiagnosticFormatOptions {
|
|
600
|
+
readonly locale: Locale;
|
|
601
|
+
readonly currentDirectory: string;
|
|
602
|
+
readonly useCaseSensitiveFileNames: boolean;
|
|
603
|
+
readonly newLine: string;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
const grey = '\u001b[90m';
|
|
607
|
+
const red = '\u001b[91m';
|
|
608
|
+
const yellow = '\u001b[93m';
|
|
609
|
+
const blue = '\u001b[94m';
|
|
610
|
+
const cyan = '\u001b[96m';
|
|
611
|
+
const gutterStyle = '\u001b[7m';
|
|
612
|
+
const gutterSeparator = ' ';
|
|
613
|
+
const reset = '\u001b[0m';
|
|
614
|
+
const ellipsis = '...';
|
|
615
|
+
|
|
616
|
+
function relativeFileName(fileName: string, options: DiagnosticFormatOptions): string {
|
|
617
|
+
if (!isRootedDiskPath(fileName)) return fileName;
|
|
618
|
+
return getPathFromPathComponents(
|
|
619
|
+
getPathComponentsRelativeTo(
|
|
620
|
+
options.currentDirectory,
|
|
621
|
+
fileName,
|
|
622
|
+
options.useCaseSensitiveFileNames,
|
|
623
|
+
options.currentDirectory,
|
|
624
|
+
),
|
|
625
|
+
);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
function flattenChain(chain: readonly Diagnostic[], newLine: string, locale: Locale, level: number): string {
|
|
629
|
+
let result = '';
|
|
630
|
+
for (const entry of chain) {
|
|
631
|
+
result += newLine + ' '.repeat(level) + entry.localize(locale);
|
|
632
|
+
result += flattenChain(entry.messageChain, newLine, locale, level + 1);
|
|
633
|
+
}
|
|
634
|
+
return result;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/** The message followed by its chain, each level indented by two more spaces. */
|
|
638
|
+
export function flattenDiagnosticMessage(diagnostic: Diagnostic, newLine: string, locale: Locale): string {
|
|
639
|
+
return diagnostic.localize(locale) + flattenChain(diagnostic.messageChain, newLine, locale, 1);
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
/** `file(line,col): error TS1005: message`, as tsc prints without `--pretty`. */
|
|
643
|
+
export function formatDiagnostic(diagnostic: Diagnostic, options: DiagnosticFormatOptions): string {
|
|
644
|
+
const file = diagnostic.file;
|
|
645
|
+
return formatDiagnosticIn(diagnostic, file !== undefined ? relativeFileName(file.fileName, options) : '', options);
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
/** `formatDiagnostic` where `fileName` is the relative name of the diagnostic's file, if it has one. */
|
|
649
|
+
function formatDiagnosticIn(diagnostic: Diagnostic, fileName: string, options: DiagnosticFormatOptions): string {
|
|
650
|
+
let result = '';
|
|
651
|
+
const file = diagnostic.file;
|
|
652
|
+
if (file !== undefined) {
|
|
653
|
+
const lineStarts = file.getLineStarts();
|
|
654
|
+
const line = computeLineOfPosition(lineStarts, diagnostic.pos);
|
|
655
|
+
const character = diagnostic.pos - lineStarts[line];
|
|
656
|
+
result += `${fileName}(${line + 1},${character + 1}): `;
|
|
657
|
+
}
|
|
658
|
+
result += `${categoryName(diagnostic.category)} TS${diagnostic.code}: `;
|
|
659
|
+
return result + flattenDiagnosticMessage(diagnostic, options.newLine, options.locale) + options.newLine;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
/** `formatDiagnostic` of each diagnostic. */
|
|
663
|
+
export function formatDiagnostics(diagnostics: readonly Diagnostic[], options: DiagnosticFormatOptions): string {
|
|
664
|
+
let result = '';
|
|
665
|
+
// Sorted diagnostics come a file at a time: the relative name of the last file is kept.
|
|
666
|
+
let lastFile: DiagnosticFile | undefined = undefined;
|
|
667
|
+
let lastName = '';
|
|
668
|
+
for (const diagnostic of diagnostics) {
|
|
669
|
+
const file = diagnostic.file;
|
|
670
|
+
if (file !== undefined && file !== lastFile) {
|
|
671
|
+
lastFile = file;
|
|
672
|
+
lastName = relativeFileName(file.fileName, options);
|
|
673
|
+
}
|
|
674
|
+
result += formatDiagnosticIn(diagnostic, file !== undefined ? lastName : '', options);
|
|
675
|
+
}
|
|
676
|
+
return result;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
function categoryColor(category: DiagnosticCategory): string {
|
|
680
|
+
switch (category) {
|
|
681
|
+
case DiagnosticCategory.Error:
|
|
682
|
+
return red;
|
|
683
|
+
case DiagnosticCategory.Warning:
|
|
684
|
+
return yellow;
|
|
685
|
+
case DiagnosticCategory.Suggestion:
|
|
686
|
+
return grey;
|
|
687
|
+
case DiagnosticCategory.Message:
|
|
688
|
+
return blue;
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
function styled(text: string, style: string): string {
|
|
693
|
+
return style + text + reset;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
function formatLocation(file: DiagnosticFile, pos: number, options: DiagnosticFormatOptions): string {
|
|
697
|
+
const lineStarts = file.getLineStarts();
|
|
698
|
+
const line = computeLineOfPosition(lineStarts, pos);
|
|
699
|
+
const character = pos - lineStarts[line];
|
|
700
|
+
return `${styled(relativeFileName(file.fileName, options), cyan)}:${styled(String(line + 1), yellow)}:${styled(String(character + 1), yellow)}`;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
function trimEndSpace(text: string): string {
|
|
704
|
+
let end = text.length;
|
|
705
|
+
while (end > 0 && isUnicodeWhiteSpace(text.charCodeAt(end - 1))) end--;
|
|
706
|
+
return text.slice(0, end);
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
function codeSnippet(
|
|
710
|
+
file: DiagnosticFile,
|
|
711
|
+
start: number,
|
|
712
|
+
length: number,
|
|
713
|
+
squiggleColor: string,
|
|
714
|
+
indent: string,
|
|
715
|
+
options: DiagnosticFormatOptions,
|
|
716
|
+
): string {
|
|
717
|
+
const newLine = options.newLine;
|
|
718
|
+
const text = file.text;
|
|
719
|
+
const lineStarts = file.getLineStarts();
|
|
720
|
+
const firstLine = computeLineOfPosition(lineStarts, start);
|
|
721
|
+
const firstLineChar = start - lineStarts[firstLine];
|
|
722
|
+
const lastLine = computeLineOfPosition(lineStarts, start + length);
|
|
723
|
+
let lastLineChar = start + length - lineStarts[lastLine];
|
|
724
|
+
// With no length, squiggle the character after the start.
|
|
725
|
+
if (length === 0) lastLineChar++;
|
|
726
|
+
const lastLineOfFile = computeLineOfPosition(lineStarts, text.length);
|
|
727
|
+
|
|
728
|
+
const hasMoreThanFiveLines = lastLine - firstLine >= 4;
|
|
729
|
+
let gutterWidth = String(lastLine + 1).length;
|
|
730
|
+
if (hasMoreThanFiveLines) gutterWidth = Math.max(ellipsis.length, gutterWidth);
|
|
731
|
+
|
|
732
|
+
let result = '';
|
|
733
|
+
for (let i = firstLine; i <= lastLine; i++) {
|
|
734
|
+
result += newLine;
|
|
735
|
+
// For spans over five lines, show the first two and last two.
|
|
736
|
+
if (hasMoreThanFiveLines && firstLine + 1 < i && i < lastLine - 1) {
|
|
737
|
+
result += indent + gutterStyle + ellipsis.padStart(gutterWidth) + reset + gutterSeparator + newLine;
|
|
738
|
+
i = lastLine - 1;
|
|
739
|
+
}
|
|
740
|
+
const lineStart = lineStarts[i]!;
|
|
741
|
+
const lineEnd = i < lastLineOfFile ? lineStarts[i + 1]! : text.length;
|
|
742
|
+
const lineContent = trimEndSpace(text.slice(lineStart, lineEnd)).replaceAll('\t', ' ');
|
|
743
|
+
|
|
744
|
+
result += indent + gutterStyle + String(i + 1).padStart(gutterWidth) + reset + gutterSeparator;
|
|
745
|
+
result += lineContent + newLine;
|
|
746
|
+
result += indent + gutterStyle + ''.padStart(gutterWidth) + reset + gutterSeparator + squiggleColor;
|
|
747
|
+
if (i === firstLine) {
|
|
748
|
+
const lastCharForLine = i === lastLine ? lastLineChar : lineContent.length;
|
|
749
|
+
result += ' '.repeat(firstLineChar) + '~'.repeat(lastCharForLine - firstLineChar);
|
|
750
|
+
} else if (i === lastLine) {
|
|
751
|
+
result += '~'.repeat(lastLineChar);
|
|
752
|
+
} else {
|
|
753
|
+
result += '~'.repeat(lineContent.length);
|
|
754
|
+
}
|
|
755
|
+
result += reset;
|
|
756
|
+
}
|
|
757
|
+
return result;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
/** The colored form with source snippets, as tsc prints with `--pretty`. */
|
|
761
|
+
export function formatDiagnosticWithColorAndContext(diagnostic: Diagnostic, options: DiagnosticFormatOptions): string {
|
|
762
|
+
const newLine = options.newLine;
|
|
763
|
+
let result = '';
|
|
764
|
+
const file = diagnostic.file;
|
|
765
|
+
if (file !== undefined) result += formatLocation(file, diagnostic.pos, options) + ' - ';
|
|
766
|
+
const color = categoryColor(diagnostic.category);
|
|
767
|
+
result += styled(categoryName(diagnostic.category), color);
|
|
768
|
+
result += `${grey} TS${diagnostic.code}: ${reset}`;
|
|
769
|
+
result += flattenDiagnosticMessage(diagnostic, newLine, options.locale);
|
|
770
|
+
if (file !== undefined && diagnostic.code !== messageCode(Diagnostics.File_appears_to_be_binary)) {
|
|
771
|
+
result +=
|
|
772
|
+
newLine + codeSnippet(file, diagnostic.pos, diagnostic.end - diagnostic.pos, color, '', options) + newLine;
|
|
773
|
+
}
|
|
774
|
+
for (const related of diagnostic.relatedInformation) {
|
|
775
|
+
const relatedFile = related.file;
|
|
776
|
+
if (relatedFile !== undefined) {
|
|
777
|
+
result += newLine + ' ' + formatLocation(relatedFile, related.pos, options) + ' - ';
|
|
778
|
+
result += flattenDiagnosticMessage(related, newLine, options.locale);
|
|
779
|
+
result += codeSnippet(relatedFile, related.pos, related.end - related.pos, cyan, ' ', options);
|
|
780
|
+
}
|
|
781
|
+
result += newLine;
|
|
782
|
+
}
|
|
783
|
+
return result;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
export function formatDiagnosticsWithColorAndContext(
|
|
787
|
+
diagnostics: readonly Diagnostic[],
|
|
788
|
+
options: DiagnosticFormatOptions,
|
|
789
|
+
): string {
|
|
790
|
+
let result = '';
|
|
791
|
+
for (let i = 0; i < diagnostics.length; i++) {
|
|
792
|
+
if (i > 0) result += options.newLine;
|
|
793
|
+
result += formatDiagnosticWithColorAndContext(diagnostics[i]!, options);
|
|
794
|
+
}
|
|
795
|
+
return result;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
/** A watch or build status line: `time - message`. */
|
|
799
|
+
export function formatDiagnosticStatus(time: string, diagnostic: Diagnostic, options: DiagnosticFormatOptions): string {
|
|
800
|
+
return `${time} - ${flattenDiagnosticMessage(diagnostic, options.newLine, options.locale)}`;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
/** A watch or build status line with a colored time: `[time] message`. */
|
|
804
|
+
export function formatDiagnosticStatusWithColor(
|
|
805
|
+
time: string,
|
|
806
|
+
diagnostic: Diagnostic,
|
|
807
|
+
options: DiagnosticFormatOptions,
|
|
808
|
+
): string {
|
|
809
|
+
return `[${styled(time, grey)}] ${flattenDiagnosticMessage(diagnostic, options.newLine, options.locale)}`;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
class FileErrors {
|
|
813
|
+
readonly file: DiagnosticFile;
|
|
814
|
+
readonly errors: Diagnostic[] = [];
|
|
815
|
+
|
|
816
|
+
constructor(file: DiagnosticFile) {
|
|
817
|
+
this.file = file;
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
function prettyPathForFileError(entry: FileErrors | undefined, options: DiagnosticFormatOptions): string {
|
|
822
|
+
if (entry === undefined || entry.errors.length === 0) return '';
|
|
823
|
+
const line = computeLineOfPosition(entry.file.getLineStarts(), entry.errors[0].pos);
|
|
824
|
+
let fileName = entry.file.fileName;
|
|
825
|
+
if (pathIsAbsolute(fileName) && pathIsAbsolute(options.currentDirectory)) {
|
|
826
|
+
fileName = relativeFileName(fileName, options);
|
|
827
|
+
}
|
|
828
|
+
return `${fileName}${grey}:${line + 1}${reset}`;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
/**
|
|
832
|
+
* The summary tsc prints after diagnostics with `--pretty`, e.g. "Found 2 errors in 2 files."
|
|
833
|
+
* followed by a table of files; empty when there are no errors.
|
|
834
|
+
*/
|
|
835
|
+
export function formatErrorSummary(diagnostics: readonly Diagnostic[], options: DiagnosticFormatOptions): string {
|
|
836
|
+
const locale = options.locale;
|
|
837
|
+
const newLine = options.newLine;
|
|
838
|
+
let totalErrorCount = 0;
|
|
839
|
+
let globalErrorCount = 0;
|
|
840
|
+
const byFile = new Map<DiagnosticFile, FileErrors>();
|
|
841
|
+
for (const diagnostic of diagnostics) {
|
|
842
|
+
if (diagnostic.category !== DiagnosticCategory.Error) continue;
|
|
843
|
+
totalErrorCount++;
|
|
844
|
+
const file = diagnostic.file;
|
|
845
|
+
if (file === undefined) {
|
|
846
|
+
globalErrorCount++;
|
|
847
|
+
continue;
|
|
848
|
+
}
|
|
849
|
+
let entry = byFile.get(file);
|
|
850
|
+
if (entry === undefined) {
|
|
851
|
+
entry = new FileErrors(file);
|
|
852
|
+
byFile.set(file, entry);
|
|
853
|
+
}
|
|
854
|
+
entry.errors.push(diagnostic);
|
|
855
|
+
}
|
|
856
|
+
if (totalErrorCount === 0) return '';
|
|
857
|
+
|
|
858
|
+
const sorted = [...byFile.values()].sort((a, b) => compareCodePoints(a.file.fileName, b.file.fileName));
|
|
859
|
+
const firstFileName = prettyPathForFileError(sorted.length > 0 ? sorted[0]! : undefined, options);
|
|
860
|
+
const fileCount = sorted.length;
|
|
861
|
+
let message: string;
|
|
862
|
+
if (totalErrorCount === 1) {
|
|
863
|
+
message =
|
|
864
|
+
globalErrorCount > 0 || firstFileName === ''
|
|
865
|
+
? localizeMessage(locale, Diagnostics.Found_1_error, [])
|
|
866
|
+
: localizeMessage(locale, Diagnostics.Found_1_error_in_0, [firstFileName]);
|
|
867
|
+
} else if (fileCount === 0) {
|
|
868
|
+
message = localizeMessage(locale, Diagnostics.Found_0_errors, [String(totalErrorCount)]);
|
|
869
|
+
} else if (fileCount === 1) {
|
|
870
|
+
message = localizeMessage(locale, Diagnostics.Found_0_errors_in_the_same_file_starting_at_Colon_1, [
|
|
871
|
+
String(totalErrorCount),
|
|
872
|
+
firstFileName,
|
|
873
|
+
]);
|
|
874
|
+
} else {
|
|
875
|
+
message = localizeMessage(locale, Diagnostics.Found_0_errors_in_1_files, [
|
|
876
|
+
String(totalErrorCount),
|
|
877
|
+
String(fileCount),
|
|
878
|
+
]);
|
|
879
|
+
}
|
|
880
|
+
let result = newLine + message + newLine + newLine;
|
|
881
|
+
if (fileCount > 1) {
|
|
882
|
+
let maxErrors = 0;
|
|
883
|
+
for (const entry of sorted) maxErrors = Math.max(maxErrors, entry.errors.length);
|
|
884
|
+
const headerRow = localizeMessage(locale, Diagnostics.Errors_Files, []);
|
|
885
|
+
const leftColumnHeadingLength = utf8Length(headerRow.split(' ')[0]!);
|
|
886
|
+
const lengthOfBiggestErrorCount = String(maxErrors).length;
|
|
887
|
+
const leftPaddingGoal = Math.max(leftColumnHeadingLength, lengthOfBiggestErrorCount);
|
|
888
|
+
const headerPadding = Math.max(lengthOfBiggestErrorCount - leftColumnHeadingLength, 0);
|
|
889
|
+
result += ' '.repeat(headerPadding) + headerRow + newLine;
|
|
890
|
+
for (const entry of sorted) {
|
|
891
|
+
result += String(entry.errors.length).padStart(leftPaddingGoal) + ' ';
|
|
892
|
+
result += prettyPathForFileError(entry, options) + newLine;
|
|
893
|
+
}
|
|
894
|
+
result += newLine;
|
|
895
|
+
}
|
|
896
|
+
return result;
|
|
897
|
+
}
|