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