tsc-ts 0.0.9 → 0.1.0
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 +2 -2
- package/bin/tsc-ts.js +70 -1
- package/dist/api/compiler/ast-utilities.d.ts +19 -1
- package/dist/api/compiler/ast-utilities.js +180 -95
- package/dist/api/compiler/ast.d.ts +22 -15
- package/dist/api/compiler/ast.js +1026 -995
- package/dist/api/compiler/astnav.js +15 -15
- package/dist/api/compiler/binder-utilities.js +186 -186
- package/dist/api/compiler/binder.js +290 -263
- package/dist/api/compiler/character-codes.js +2 -2
- package/dist/api/compiler/checker-calls.js +178 -124
- package/dist/api/compiler/checker-classes.d.ts +14 -3
- package/dist/api/compiler/checker-classes.js +134 -90
- package/dist/api/compiler/checker-contextual.js +64 -61
- package/dist/api/compiler/checker-declaration-order.js +79 -79
- package/dist/api/compiler/checker-declarations.d.ts +1 -0
- package/dist/api/compiler/checker-declarations.js +160 -136
- package/dist/api/compiler/checker-declared-types.js +67 -65
- package/dist/api/compiler/checker-decorators.js +77 -77
- package/dist/api/compiler/checker-deprecation.d.ts +8 -3
- package/dist/api/compiler/checker-deprecation.js +76 -55
- package/dist/api/compiler/checker-destructuring.js +47 -45
- package/dist/api/compiler/checker-elaboration.js +24 -24
- package/dist/api/compiler/checker-emit-helpers.js +4 -4
- package/dist/api/compiler/checker-emit-resolver.d.ts +4 -2
- package/dist/api/compiler/checker-emit-resolver.js +25 -13
- package/dist/api/compiler/checker-evaluator.js +9 -9
- package/dist/api/compiler/checker-expressions.js +244 -211
- package/dist/api/compiler/checker-functions.js +113 -107
- package/dist/api/compiler/checker-generated-code.d.ts +0 -11
- package/dist/api/compiler/checker-generated-code.js +28 -52
- package/dist/api/compiler/checker-grammar.d.ts +1 -0
- package/dist/api/compiler/checker-grammar.js +472 -440
- package/dist/api/compiler/checker-heritage.js +91 -93
- package/dist/api/compiler/checker-inference.d.ts +77 -5
- package/dist/api/compiler/checker-inference.js +487 -107
- package/dist/api/compiler/checker-iteration.d.ts +0 -10
- package/dist/api/compiler/checker-iteration.js +35 -52
- package/dist/api/compiler/checker-javascript.js +14 -14
- package/dist/api/compiler/checker-jsdoc.d.ts +8 -10
- package/dist/api/compiler/checker-jsdoc.js +67 -58
- package/dist/api/compiler/checker-jsx.js +105 -88
- package/dist/api/compiler/checker-members.d.ts +9 -2
- package/dist/api/compiler/checker-members.js +212 -75
- package/dist/api/compiler/checker-modules.d.ts +15 -6
- package/dist/api/compiler/checker-modules.js +469 -309
- package/dist/api/compiler/checker-narrowing.js +273 -189
- package/dist/api/compiler/checker-object-literals.js +25 -22
- package/dist/api/compiler/checker-operators.js +126 -118
- package/dist/api/compiler/checker-overloads.js +27 -27
- package/dist/api/compiler/checker-property-access.js +59 -55
- package/dist/api/compiler/checker-services.d.ts +1 -0
- package/dist/api/compiler/checker-services.js +222 -210
- package/dist/api/compiler/checker-signatures.js +65 -49
- package/dist/api/compiler/checker-source-file.d.ts +5 -0
- package/dist/api/compiler/checker-source-file.js +154 -130
- package/dist/api/compiler/checker-statements.js +33 -32
- package/dist/api/compiler/checker-super.js +50 -50
- package/dist/api/compiler/checker-symbol-types.js +109 -93
- package/dist/api/compiler/checker-symbols.d.ts +13 -1
- package/dist/api/compiler/checker-symbols.js +264 -149
- package/dist/api/compiler/checker-type-factory.d.ts +5 -0
- package/dist/api/compiler/checker-type-factory.js +145 -36
- package/dist/api/compiler/checker-type-nodes.d.ts +1 -0
- package/dist/api/compiler/checker-type-nodes.js +179 -141
- package/dist/api/compiler/checker-type-operators.d.ts +2 -0
- package/dist/api/compiler/checker-type-operators.js +110 -63
- package/dist/api/compiler/checker-types.d.ts +80 -3
- package/dist/api/compiler/checker-types.js +121 -2
- package/dist/api/compiler/checker-unused.js +114 -118
- package/dist/api/compiler/checker-utilities.js +11 -11
- package/dist/api/compiler/checker.d.ts +104 -31
- package/dist/api/compiler/checker.js +181 -33
- package/dist/api/compiler/command-line.d.ts +1 -3
- package/dist/api/compiler/command-line.js +47 -44
- package/dist/api/compiler/compile-program.d.ts +42 -3
- package/dist/api/compiler/compile-program.js +139 -27
- package/dist/api/compiler/diagnostic-messages.d.ts +1849 -1774
- package/dist/api/compiler/diagnostic-messages.js +128 -122
- package/dist/api/compiler/diagnostics.d.ts +22 -0
- package/dist/api/compiler/diagnostics.js +93 -11
- package/dist/api/compiler/emitter.d.ts +7 -1
- package/dist/api/compiler/emitter.js +53 -11
- package/dist/api/compiler/file-include.d.ts +2 -1
- package/dist/api/compiler/file-include.js +11 -7
- package/dist/api/compiler/file-loader.d.ts +21 -1
- package/dist/api/compiler/file-loader.js +201 -48
- package/dist/api/compiler/instantiation.d.ts +7 -0
- package/dist/api/compiler/instantiation.js +101 -49
- package/dist/api/compiler/jsdoc.js +23 -23
- package/dist/api/compiler/link-tables.d.ts +48 -18
- package/dist/api/compiler/link-tables.js +80 -37
- package/dist/api/compiler/locales/cs-CZ.d.ts +1 -1
- package/dist/api/compiler/locales/cs-CZ.js +1 -1
- package/dist/api/compiler/locales/de-DE.d.ts +1 -1
- package/dist/api/compiler/locales/de-DE.js +1 -1
- package/dist/api/compiler/locales/es-ES.d.ts +1 -1
- package/dist/api/compiler/locales/es-ES.js +1 -1
- package/dist/api/compiler/locales/fr-FR.d.ts +1 -1
- package/dist/api/compiler/locales/fr-FR.js +1 -1
- package/dist/api/compiler/locales/it-IT.d.ts +1 -1
- package/dist/api/compiler/locales/it-IT.js +1 -1
- package/dist/api/compiler/locales/ja-JP.d.ts +1 -1
- package/dist/api/compiler/locales/ja-JP.js +1 -1
- package/dist/api/compiler/locales/ko-KR.d.ts +1 -1
- package/dist/api/compiler/locales/ko-KR.js +1 -1
- package/dist/api/compiler/locales/pl-PL.d.ts +1 -1
- package/dist/api/compiler/locales/pl-PL.js +1 -1
- package/dist/api/compiler/locales/pt-BR.d.ts +1 -1
- package/dist/api/compiler/locales/pt-BR.js +1 -1
- package/dist/api/compiler/locales/ru-RU.d.ts +1 -1
- package/dist/api/compiler/locales/ru-RU.js +1 -1
- package/dist/api/compiler/locales/tr-TR.d.ts +1 -1
- package/dist/api/compiler/locales/tr-TR.js +1 -1
- package/dist/api/compiler/locales/zh-CN.d.ts +1 -1
- package/dist/api/compiler/locales/zh-CN.js +1 -1
- package/dist/api/compiler/locales/zh-TW.d.ts +1 -1
- package/dist/api/compiler/locales/zh-TW.js +1 -1
- package/dist/api/compiler/module-resolution-types.js +6 -6
- package/dist/api/compiler/module-resolution.d.ts +10 -1
- package/dist/api/compiler/module-resolution.js +115 -84
- package/dist/api/compiler/module-specifiers.d.ts +15 -0
- package/dist/api/compiler/module-specifiers.js +24 -18
- package/dist/api/compiler/name-resolver.js +74 -65
- package/dist/api/compiler/node-builder-names.d.ts +11 -3
- package/dist/api/compiler/node-builder-names.js +210 -90
- package/dist/api/compiler/node-builder-pseudo.js +29 -31
- package/dist/api/compiler/node-builder-reuse.js +23 -22
- package/dist/api/compiler/node-builder.d.ts +18 -1
- package/dist/api/compiler/node-builder.js +191 -102
- package/dist/api/compiler/option-declarations.d.ts +2 -6
- package/dist/api/compiler/option-declarations.js +315 -375
- package/dist/api/compiler/options.d.ts +15 -33
- package/dist/api/compiler/options.js +21 -54
- package/dist/api/compiler/output-paths.d.ts +4 -1
- package/dist/api/compiler/output-paths.js +6 -11
- package/dist/api/compiler/package-json.d.ts +3 -3
- package/dist/api/compiler/package-json.js +11 -10
- package/dist/api/compiler/parallel-parse.d.ts +3 -2
- package/dist/api/compiler/parallel-parse.js +17 -5
- package/dist/api/compiler/parser.d.ts +40 -19
- package/dist/api/compiler/parser.js +308 -216
- package/dist/api/compiler/path.d.ts +9 -0
- package/dist/api/compiler/path.js +20 -3
- package/dist/api/compiler/printer/emit-context.d.ts +5 -1
- package/dist/api/compiler/printer/emit-context.js +20 -1
- package/dist/api/compiler/printer/factory-base.d.ts +2 -2
- package/dist/api/compiler/printer/factory-base.js +7 -3
- package/dist/api/compiler/printer/factory.js +3 -1
- package/dist/api/compiler/printer/helpers.js +10 -1
- package/dist/api/compiler/printer/name-generator.d.ts +1 -1
- package/dist/api/compiler/printer/name-generator.js +35 -16
- package/dist/api/compiler/printer/printer.d.ts +49 -2
- package/dist/api/compiler/printer/printer.js +539 -293
- package/dist/api/compiler/printer/utilities.js +149 -147
- package/dist/api/compiler/program-checker.d.ts +12 -2
- package/dist/api/compiler/program-checker.js +88 -34
- package/dist/api/compiler/program-utilities.d.ts +3 -1
- package/dist/api/compiler/program-utilities.js +28 -15
- package/dist/api/compiler/program.d.ts +4 -6
- package/dist/api/compiler/program.js +74 -87
- package/dist/api/compiler/pseudo-bigint.d.ts +2 -0
- package/dist/api/compiler/pseudo-bigint.js +18 -0
- package/dist/api/compiler/regexp-checker.d.ts +1 -1
- package/dist/api/compiler/regexp-checker.js +93 -76
- package/dist/api/compiler/relations.d.ts +27 -4
- package/dist/api/compiler/relations.js +347 -180
- package/dist/api/compiler/reparser.js +60 -56
- package/dist/api/compiler/scanner.d.ts +19 -2
- package/dist/api/compiler/scanner.js +123 -108
- package/dist/api/compiler/shared-results.d.ts +463 -0
- package/dist/api/compiler/shared-results.js +2128 -0
- package/dist/api/compiler/sourcemap.js +2 -2
- package/dist/api/compiler/symbol-accessibility.js +87 -74
- package/dist/api/compiler/symbol.d.ts +23 -14
- package/dist/api/compiler/symbol.js +23 -11
- package/dist/api/compiler/syntax-kind.d.ts +198 -197
- package/dist/api/compiler/transformers/alias-references.js +247 -139
- package/dist/api/compiler/transformers/async-utilities.js +25 -25
- package/dist/api/compiler/transformers/async.d.ts +0 -1
- package/dist/api/compiler/transformers/async.js +64 -77
- package/dist/api/compiler/transformers/class-fields.d.ts +1 -0
- package/dist/api/compiler/transformers/class-fields.js +81 -78
- package/dist/api/compiler/transformers/commonjs-module.js +18 -15
- package/dist/api/compiler/transformers/const-enum-inliner.js +1 -1
- package/dist/api/compiler/transformers/declarations-diagnostics.js +247 -244
- package/dist/api/compiler/transformers/declarations-pseudo.js +100 -100
- package/dist/api/compiler/transformers/declarations-resolver.d.ts +0 -3
- package/dist/api/compiler/transformers/declarations-syntactic.d.ts +1 -2
- package/dist/api/compiler/transformers/declarations-syntactic.js +134 -156
- package/dist/api/compiler/transformers/declarations-tracker.js +18 -18
- package/dist/api/compiler/transformers/declarations.d.ts +4 -1
- package/dist/api/compiler/transformers/declarations.js +305 -238
- package/dist/api/compiler/transformers/decorator-metadata.d.ts +1 -1
- package/dist/api/compiler/transformers/decorator-metadata.js +53 -45
- package/dist/api/compiler/transformers/decorator-utilities.js +24 -24
- package/dist/api/compiler/transformers/destructuring.js +19 -18
- package/dist/api/compiler/transformers/emit-resolver.js +1 -1
- package/dist/api/compiler/transformers/es-decorators.js +55 -55
- package/dist/api/compiler/transformers/external-module-info.js +3 -3
- package/dist/api/compiler/transformers/for-await.js +25 -25
- package/dist/api/compiler/transformers/import-elision.js +14 -14
- package/dist/api/compiler/transformers/jsx.js +12 -12
- package/dist/api/compiler/transformers/legacy-decorators.js +17 -17
- package/dist/api/compiler/transformers/module.js +8 -8
- package/dist/api/compiler/transformers/named-evaluation.js +4 -4
- package/dist/api/compiler/transformers/object-rest-spread.js +20 -20
- package/dist/api/compiler/transformers/optional-chain.js +10 -10
- package/dist/api/compiler/transformers/reference-resolver.d.ts +12 -1
- package/dist/api/compiler/transformers/reference-resolver.js +131 -69
- package/dist/api/compiler/transformers/runtime-syntax.js +35 -31
- package/dist/api/compiler/transformers/subtree-facts.js +47 -47
- package/dist/api/compiler/transformers/syntax-facts.js +56 -58
- package/dist/api/compiler/transformers/type-eraser.js +73 -66
- package/dist/api/compiler/transformers/type-serialization.js +24 -24
- package/dist/api/compiler/transformers/using.js +12 -12
- package/dist/api/compiler/transformers/utilities.js +77 -77
- package/dist/api/compiler/transformers/visitor-base.js +172 -172
- package/dist/api/compiler/transformers/visitor-hooks.js +6 -2
- package/dist/api/compiler/tsconfig.d.ts +10 -2
- package/dist/api/compiler/tsconfig.js +136 -48
- package/dist/api/compiler/type-printer.js +40 -3
- package/dist/api/compiler/types.d.ts +2 -1
- package/dist/api/library/ast.generated.d.ts +42 -39
- package/dist/api/library/ast.generated.js +1 -1
- package/dist/api/library/compiler-options.generated.d.ts +111 -100
- package/dist/api/library/compiler-options.generated.js +1 -1
- package/dist/api/library/disk.js +12 -1
- package/dist/api/library/enums.generated.d.ts +206 -206
- package/dist/api/library/enums.generated.js +206 -206
- package/dist/api/library/nodes.js +26 -26
- package/package.json +9 -9
- package/src/compiler/ast-utilities.ts +99 -7
- package/src/compiler/ast.ts +58 -26
- package/src/compiler/binder.ts +39 -4
- package/src/compiler/character-codes.ts +2 -2
- package/src/compiler/checker-calls.ts +79 -9
- package/src/compiler/checker-classes.ts +78 -24
- package/src/compiler/checker-contextual.ts +6 -1
- package/src/compiler/checker-declarations.ts +31 -4
- package/src/compiler/checker-declared-types.ts +8 -5
- package/src/compiler/checker-decorators.ts +1 -1
- package/src/compiler/checker-deprecation.ts +29 -8
- package/src/compiler/checker-destructuring.ts +10 -3
- package/src/compiler/checker-emit-helpers.ts +1 -0
- package/src/compiler/checker-emit-resolver.ts +16 -6
- package/src/compiler/checker-expressions.ts +79 -46
- package/src/compiler/checker-functions.ts +21 -6
- package/src/compiler/checker-generated-code.ts +2 -22
- package/src/compiler/checker-grammar.ts +136 -62
- package/src/compiler/checker-heritage.ts +22 -21
- package/src/compiler/checker-inference.ts +514 -82
- package/src/compiler/checker-iteration.ts +18 -31
- package/src/compiler/checker-javascript.ts +1 -1
- package/src/compiler/checker-jsdoc.ts +50 -27
- package/src/compiler/checker-jsx.ts +26 -4
- package/src/compiler/checker-members.ts +200 -56
- package/src/compiler/checker-modules.ts +332 -65
- package/src/compiler/checker-narrowing.ts +98 -19
- package/src/compiler/checker-object-literals.ts +3 -0
- package/src/compiler/checker-operators.ts +11 -4
- package/src/compiler/checker-property-access.ts +7 -2
- package/src/compiler/checker-services.ts +39 -12
- package/src/compiler/checker-signatures.ts +15 -1
- package/src/compiler/checker-source-file.ts +39 -13
- package/src/compiler/checker-statements.ts +3 -2
- package/src/compiler/checker-symbol-types.ts +29 -6
- package/src/compiler/checker-symbols.ts +158 -15
- package/src/compiler/checker-type-factory.ts +124 -23
- package/src/compiler/checker-type-nodes.ts +46 -3
- package/src/compiler/checker-type-operators.ts +83 -26
- package/src/compiler/checker-types.ts +147 -4
- package/src/compiler/checker-unused.ts +9 -14
- package/src/compiler/checker.ts +203 -39
- package/src/compiler/command-line.ts +28 -28
- package/src/compiler/compile-program.ts +167 -27
- package/src/compiler/decoder.ts +13 -4
- package/src/compiler/diagnostic-messages.ts +1973 -1892
- package/src/compiler/diagnostics.ts +84 -3
- package/src/compiler/emitter.ts +57 -8
- package/src/compiler/encoder.ts +23 -8
- package/src/compiler/file-include.ts +9 -3
- package/src/compiler/file-loader.ts +197 -38
- package/src/compiler/help.ts +10 -14
- package/src/compiler/incremental.ts +165 -30
- package/src/compiler/init.ts +2 -7
- package/src/compiler/instantiation.ts +77 -22
- package/src/compiler/jsdoc.ts +3 -1
- package/src/compiler/link-tables.ts +82 -37
- package/src/compiler/locales/cs-CZ.ts +1 -1
- package/src/compiler/locales/de-DE.ts +1 -1
- package/src/compiler/locales/es-ES.ts +1 -1
- package/src/compiler/locales/fr-FR.ts +1 -1
- package/src/compiler/locales/it-IT.ts +1 -1
- package/src/compiler/locales/ja-JP.ts +1 -1
- package/src/compiler/locales/ko-KR.ts +1 -1
- package/src/compiler/locales/pl-PL.ts +1 -1
- package/src/compiler/locales/pt-BR.ts +1 -1
- package/src/compiler/locales/ru-RU.ts +1 -1
- package/src/compiler/locales/tr-TR.ts +1 -1
- package/src/compiler/locales/zh-CN.ts +1 -1
- package/src/compiler/locales/zh-TW.ts +1 -1
- package/src/compiler/module-resolution.ts +44 -8
- package/src/compiler/module-specifiers.ts +62 -20
- package/src/compiler/name-resolver.ts +9 -1
- package/src/compiler/node-builder-names.ts +236 -54
- package/src/compiler/node-builder-pseudo.ts +4 -7
- package/src/compiler/node-builder-reuse.ts +5 -4
- package/src/compiler/node-builder.ts +130 -31
- package/src/compiler/option-declarations.ts +33 -103
- package/src/compiler/options.ts +23 -62
- package/src/compiler/output-paths.ts +5 -18
- package/src/compiler/package-entrypoints.ts +345 -0
- package/src/compiler/package-json.ts +4 -4
- package/src/compiler/parallel-check.ts +326 -52
- package/src/compiler/parallel-emit.ts +320 -0
- package/src/compiler/parallel-parse.ts +16 -5
- package/src/compiler/parse-thread.ts +3 -0
- package/src/compiler/parser.ts +156 -39
- package/src/compiler/path.ts +22 -2
- package/src/compiler/printer/emit-context.ts +21 -0
- package/src/compiler/printer/factory-base.ts +10 -3
- package/src/compiler/printer/factory.ts +4 -1
- package/src/compiler/printer/helpers.ts +10 -1
- package/src/compiler/printer/name-generator.ts +24 -2
- package/src/compiler/printer/printer.ts +266 -30
- package/src/compiler/printer/utilities.ts +8 -2
- package/src/compiler/program-checker.ts +57 -5
- package/src/compiler/program-utilities.ts +23 -10
- package/src/compiler/program.ts +18 -26
- package/src/compiler/pseudo-bigint.ts +17 -0
- package/src/compiler/regexp-checker.ts +63 -30
- package/src/compiler/relations.ts +240 -77
- package/src/compiler/reparser.ts +7 -2
- package/src/compiler/scanner.ts +109 -79
- package/src/compiler/shared-results.ts +2414 -0
- package/src/compiler/show-config.ts +18 -1
- package/src/compiler/sourcemap.ts +2 -2
- package/src/compiler/symbol-accessibility.ts +26 -3
- package/src/compiler/symbol.ts +46 -24
- package/src/compiler/syntax-kind.ts +188 -187
- package/src/compiler/thread-entry.ts +64 -4
- package/src/compiler/transformers/alias-references.ts +123 -4
- package/src/compiler/transformers/async.ts +2 -17
- package/src/compiler/transformers/class-fields.ts +13 -12
- package/src/compiler/transformers/commonjs-module.ts +11 -7
- package/src/compiler/transformers/declarations-diagnostics.ts +5 -3
- package/src/compiler/transformers/declarations-pseudo.ts +2 -4
- package/src/compiler/transformers/declarations-resolver.ts +0 -3
- package/src/compiler/transformers/declarations-syntactic.ts +1 -21
- package/src/compiler/transformers/declarations.ts +134 -48
- package/src/compiler/transformers/decorator-metadata.ts +9 -1
- package/src/compiler/transformers/destructuring.ts +4 -3
- package/src/compiler/transformers/external-module-info.ts +1 -1
- package/src/compiler/transformers/jsx.ts +2 -1
- package/src/compiler/transformers/reference-resolver.ts +83 -19
- package/src/compiler/transformers/runtime-syntax.ts +6 -1
- package/src/compiler/transformers/syntax-facts.ts +2 -7
- package/src/compiler/transformers/type-eraser.ts +10 -1
- package/src/compiler/transformers/type-serialization.ts +3 -2
- package/src/compiler/transformers/visitor-base.ts +2 -1
- package/src/compiler/transformers/visitor-hooks.ts +9 -4
- package/src/compiler/tsc-build.ts +66 -9
- package/src/compiler/tsc-cli.ts +7 -0
- package/src/compiler/tsc-compile.ts +284 -4
- package/src/compiler/tsc-watch.ts +74 -45
- package/src/compiler/tsconfig.ts +176 -19
- package/src/compiler/type-printer.ts +36 -2
- package/src/compiler/types.ts +2 -1
- package/src/library/ast.generated.ts +57 -41
- package/src/library/compiler-options.generated.ts +117 -103
- package/src/library/disk.ts +10 -1
- package/src/library/enums.generated.ts +196 -196
|
@@ -174,7 +174,7 @@ import { SyntaxKind } from '../syntax-kind.js';
|
|
|
174
174
|
import { type CommentRange, TokenFlags } from '../types.js';
|
|
175
175
|
import { ScriptTarget } from '../options.js';
|
|
176
176
|
import { fileExtensionIs } from '../path.js';
|
|
177
|
-
import { isWhiteSpaceLike } from '../character-codes.js';
|
|
177
|
+
import { CharacterCodes, isWhiteSpaceLike } from '../character-codes.js';
|
|
178
178
|
import type { SourceMapGenerator } from '../sourcemap.js';
|
|
179
179
|
import { EmitContext, compareEmitHelpers, type SynthesizedComment } from './emit-context.js';
|
|
180
180
|
import { EmitFlags, GeneratedIdentifierFlags } from './emit-flags.js';
|
|
@@ -375,6 +375,8 @@ const enum ListItem {
|
|
|
375
375
|
ImportSpecifier,
|
|
376
376
|
ExportSpecifier,
|
|
377
377
|
ExpressionWithTypeArguments,
|
|
378
|
+
/** An `ExpressionWithTypeArguments` or a type reference in a heritage clause. */
|
|
379
|
+
HeritageClauseElement,
|
|
378
380
|
JsxChild,
|
|
379
381
|
JsxAttributeLike,
|
|
380
382
|
}
|
|
@@ -399,6 +401,9 @@ const enum State {
|
|
|
399
401
|
SourceMaps = 1 << 1,
|
|
400
402
|
}
|
|
401
403
|
|
|
404
|
+
/** The saved emit flags of a node whose comments were not looked for (`Printer.inCommentFreeRange`). */
|
|
405
|
+
const commentFreeNode = -1;
|
|
406
|
+
|
|
402
407
|
export class Printer extends NameGeneratorHost {
|
|
403
408
|
readonly options: PrinterOptions;
|
|
404
409
|
readonly context: EmitContext;
|
|
@@ -410,6 +415,13 @@ export class Printer extends NameGeneratorHost {
|
|
|
410
415
|
currentSourceFile: SourceFile | undefined;
|
|
411
416
|
private sourceText: string;
|
|
412
417
|
private lineStarts: readonly number[];
|
|
418
|
+
/**
|
|
419
|
+
* The line of the last `lineOf` lookup, `lookupLine`, and the positions it spans, `[lookupLineStart, lookupLineEnd)`,
|
|
420
|
+
* with `lookupLineEnd` -1 after the last line: printing reads positions mostly in order, so most lookups fall on that line.
|
|
421
|
+
*/
|
|
422
|
+
private lookupLine: number;
|
|
423
|
+
private lookupLineStart: number;
|
|
424
|
+
private lookupLineEnd: number;
|
|
413
425
|
private writer: TextWriter;
|
|
414
426
|
private ownWriter: TextWriter | undefined;
|
|
415
427
|
private uniqueHelperNames: Map<string, Identifier> | undefined;
|
|
@@ -423,8 +435,25 @@ export class Printer extends NameGeneratorHost {
|
|
|
423
435
|
private commentsDisabled: boolean;
|
|
424
436
|
/** Emitting the `extends` clause of a conditional or infer type. */
|
|
425
437
|
private inExtends: boolean;
|
|
426
|
-
/**
|
|
427
|
-
|
|
438
|
+
/**
|
|
439
|
+
* Saved comment state, 32-bit values: emit flags, comment pos, comment end, container pos, container end,
|
|
440
|
+
* declaration list end.
|
|
441
|
+
* Flags are `commentFreeNode` for a node that `emitCommentsBeforeNode` handled in a comment-free range.
|
|
442
|
+
*/
|
|
443
|
+
private commentStack: Int32Array;
|
|
444
|
+
/** The used length of `commentStack`: entries are written in place and kept for reuse once popped. */
|
|
445
|
+
private commentDepth: number;
|
|
446
|
+
/** Start positions of `//` and `/*` in `sourceText`, ascending; made on first use for each file. */
|
|
447
|
+
private commentStarts: Int32Array | undefined;
|
|
448
|
+
/**
|
|
449
|
+
* A range of `sourceText`, `[freeStart, freeEnd)`, where no comment starts and the last character is not trivia,
|
|
450
|
+
* so no comment is found from any position in it; -1 when there is none. `freeOwner` is the node it was made for.
|
|
451
|
+
*/
|
|
452
|
+
private freeStart: number;
|
|
453
|
+
private freeEnd: number;
|
|
454
|
+
/** Whether no trailing comment follows `freeEnd`. */
|
|
455
|
+
private freeEndTrailingNone: boolean;
|
|
456
|
+
private freeOwner: Node | undefined;
|
|
428
457
|
/** Saved source map state: emit flags, pos, end, has token range. */
|
|
429
458
|
private readonly sourceMapStack: number[];
|
|
430
459
|
/** The token position after `enterToken` skipped trivia. */
|
|
@@ -457,6 +486,9 @@ export class Printer extends NameGeneratorHost {
|
|
|
457
486
|
this.currentSourceFile = undefined;
|
|
458
487
|
this.sourceText = '';
|
|
459
488
|
this.lineStarts = [];
|
|
489
|
+
this.lookupLine = -1;
|
|
490
|
+
this.lookupLineStart = 0;
|
|
491
|
+
this.lookupLineEnd = 0;
|
|
460
492
|
this.writer = new TextWriter(options.newLine, 4);
|
|
461
493
|
this.ownWriter = undefined;
|
|
462
494
|
this.uniqueHelperNames = undefined;
|
|
@@ -468,7 +500,13 @@ export class Printer extends NameGeneratorHost {
|
|
|
468
500
|
this.detachedComments = [];
|
|
469
501
|
this.commentsDisabled = options.removeComments;
|
|
470
502
|
this.inExtends = false;
|
|
471
|
-
this.commentStack =
|
|
503
|
+
this.commentStack = new Int32Array(96);
|
|
504
|
+
this.commentDepth = 0;
|
|
505
|
+
this.commentStarts = undefined;
|
|
506
|
+
this.freeStart = -1;
|
|
507
|
+
this.freeEnd = -1;
|
|
508
|
+
this.freeEndTrailingNone = false;
|
|
509
|
+
this.freeOwner = undefined;
|
|
472
510
|
this.sourceMapStack = [];
|
|
473
511
|
this.tokenPos = 0;
|
|
474
512
|
this.sourceMapsDisabled = true;
|
|
@@ -518,6 +556,11 @@ export class Printer extends NameGeneratorHost {
|
|
|
518
556
|
this.currentSourceFile = sourceFile;
|
|
519
557
|
this.sourceText = sourceFile === undefined ? '' : sourceFile.text;
|
|
520
558
|
this.lineStarts = sourceFile === undefined ? [] : sourceFile.lineStarts();
|
|
559
|
+
this.lookupLine = -1;
|
|
560
|
+
this.lookupLineStart = 0;
|
|
561
|
+
this.lookupLineEnd = 0;
|
|
562
|
+
this.commentStarts = undefined;
|
|
563
|
+
this.endCommentFreeRange();
|
|
521
564
|
return true;
|
|
522
565
|
}
|
|
523
566
|
|
|
@@ -565,7 +608,8 @@ export class Printer extends NameGeneratorHost {
|
|
|
565
608
|
|
|
566
609
|
isFileLevelUniqueName(name: string): boolean {
|
|
567
610
|
const file = this.currentSourceFile;
|
|
568
|
-
|
|
611
|
+
// The names of the source file as parsed, not as transformed.
|
|
612
|
+
return file === undefined || isFileLevelUniqueName(this.context.mostOriginal(file) as SourceFile, name);
|
|
569
613
|
}
|
|
570
614
|
|
|
571
615
|
private getLiteralTextOfNode(node: Node, sourceFile: SourceFile | undefined, flags: LiteralTextFlags): string {
|
|
@@ -615,6 +659,8 @@ export class Printer extends NameGeneratorHost {
|
|
|
615
659
|
case SyntaxKind.Identifier:
|
|
616
660
|
case SyntaxKind.PrivateIdentifier:
|
|
617
661
|
case SyntaxKind.JsxNamespacedName:
|
|
662
|
+
// Its text either way: the source text, or the text of a node from elsewhere.
|
|
663
|
+
if (this.textIsSourceText(node)) return (node as Identifier | PrivateIdentifier).text;
|
|
618
664
|
if (!canUseSourceFile || !this.isInCurrentSourceFile(node)) {
|
|
619
665
|
if (node instanceof Identifier) return node.text;
|
|
620
666
|
if (node instanceof PrivateIdentifier) return node.text;
|
|
@@ -635,6 +681,38 @@ export class Printer extends NameGeneratorHost {
|
|
|
635
681
|
return getSourceTextOfNode(this.sourceText, node);
|
|
636
682
|
}
|
|
637
683
|
|
|
684
|
+
/**
|
|
685
|
+
* Whether the source text of an identifier or private identifier of the current file, from the end of its leading
|
|
686
|
+
* trivia to its end, is its text: the text ends the node, and the character before it is not part of the token, as
|
|
687
|
+
* it would be in an identifier written with escapes. Nodes from JSDoc may span other text, so they are left to the
|
|
688
|
+
* general path.
|
|
689
|
+
*/
|
|
690
|
+
private textIsSourceText(node: Node): boolean {
|
|
691
|
+
if (!(node instanceof Identifier) && !(node instanceof PrivateIdentifier)) return false;
|
|
692
|
+
if ((node.flags & (NodeFlags.Reparsed | NodeFlags.JSDoc | NodeFlags.ReparserTransformedLiteral)) !== 0)
|
|
693
|
+
return false;
|
|
694
|
+
const text = node.text;
|
|
695
|
+
const source = this.sourceText;
|
|
696
|
+
const end = node.end;
|
|
697
|
+
const start = end - text.length;
|
|
698
|
+
if (text.length === 0 || start < node.pos || end > source.length) return false;
|
|
699
|
+
if (!source.startsWith(text, start)) return false;
|
|
700
|
+
if (start === node.pos) return true;
|
|
701
|
+
const before = source.charCodeAt(start - 1);
|
|
702
|
+
return !(
|
|
703
|
+
(before >= CharacterCodes.a && before <= CharacterCodes.z) ||
|
|
704
|
+
(before >= CharacterCodes.A && before <= CharacterCodes.Z) ||
|
|
705
|
+
(before >= CharacterCodes._0 && before <= CharacterCodes._9) ||
|
|
706
|
+
before === CharacterCodes._ ||
|
|
707
|
+
before === CharacterCodes.$ ||
|
|
708
|
+
before === CharacterCodes.backslash ||
|
|
709
|
+
before === CharacterCodes.openBrace ||
|
|
710
|
+
before === CharacterCodes.closeBrace ||
|
|
711
|
+
before === CharacterCodes.hash ||
|
|
712
|
+
before > CharacterCodes.maxAsciiCharacter
|
|
713
|
+
);
|
|
714
|
+
}
|
|
715
|
+
|
|
638
716
|
private isInCurrentSourceFile(node: Node): boolean {
|
|
639
717
|
const file = this.currentSourceFile;
|
|
640
718
|
if (file === undefined) return false;
|
|
@@ -717,7 +795,28 @@ export class Printer extends NameGeneratorHost {
|
|
|
717
795
|
// Lines between nodes
|
|
718
796
|
|
|
719
797
|
private positionsAreOnSameLine(pos1: number, pos2: number): boolean {
|
|
720
|
-
|
|
798
|
+
if (pos1 === pos2) return true;
|
|
799
|
+
const lower = pos1 < pos2 ? pos1 : pos2;
|
|
800
|
+
const upper = pos1 < pos2 ? pos2 : pos1;
|
|
801
|
+
// What getLinesBetweenPositions finds: no line starts in (lower, upper].
|
|
802
|
+
if (lower < 0) {
|
|
803
|
+
const first = this.lineStarts.length > 0 ? this.lineStarts[0] | 0 : -1;
|
|
804
|
+
return first < 0 || upper < first;
|
|
805
|
+
}
|
|
806
|
+
this.lineOf(lower);
|
|
807
|
+
return this.lookupLineEnd < 0 || upper < this.lookupLineEnd;
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
/** The zero-based line of `pos` (-1 before the first line), which becomes the line of the last lookup. */
|
|
811
|
+
private lineOf(pos: number): number {
|
|
812
|
+
if (pos >= this.lookupLineStart && (pos < this.lookupLineEnd || this.lookupLineEnd < 0) && this.lookupLine >= 0)
|
|
813
|
+
return this.lookupLine;
|
|
814
|
+
const starts = this.lineStarts;
|
|
815
|
+
const line = computeLineOfPosition(starts, pos);
|
|
816
|
+
this.lookupLine = line;
|
|
817
|
+
this.lookupLineStart = line >= 0 ? starts[line] | 0 : 0;
|
|
818
|
+
this.lookupLineEnd = line + 1 < starts.length ? starts[line + 1] | 0 : -1;
|
|
819
|
+
return line;
|
|
721
820
|
}
|
|
722
821
|
|
|
723
822
|
private rangeStart(pos: number): number {
|
|
@@ -1049,8 +1148,13 @@ export class Printer extends NameGeneratorHost {
|
|
|
1049
1148
|
|
|
1050
1149
|
// Names
|
|
1051
1150
|
|
|
1052
|
-
// Source text of names reparsed from JSDoc can span lines.
|
|
1151
|
+
// Source text of names reparsed from JSDoc can span lines; an identifier's own source text has no line breaks.
|
|
1053
1152
|
private emitIdentifierText(node: Identifier): boolean {
|
|
1153
|
+
if (!this.context.autoGenerate.has(node) && this.textIsSourceText(node)) {
|
|
1154
|
+
// writeText's answer for text without line breaks.
|
|
1155
|
+
this.writer.write(node.text);
|
|
1156
|
+
return false;
|
|
1157
|
+
}
|
|
1054
1158
|
return this.writer.writeText(this.getTextOfNode(node));
|
|
1055
1159
|
}
|
|
1056
1160
|
|
|
@@ -1116,7 +1220,8 @@ export class Printer extends NameGeneratorHost {
|
|
|
1116
1220
|
const state = this.enterNode(node);
|
|
1117
1221
|
this.emitEntityName(node.left);
|
|
1118
1222
|
this.write1('.');
|
|
1119
|
-
this.
|
|
1223
|
+
if (node.right instanceof PrivateIdentifier) this.emitPrivateIdentifier(node.right);
|
|
1224
|
+
else this.emitIdentifierName(node.right as Identifier);
|
|
1120
1225
|
this.exitNode(node, state);
|
|
1121
1226
|
return true;
|
|
1122
1227
|
}
|
|
@@ -1813,10 +1918,11 @@ export class Printer extends NameGeneratorHost {
|
|
|
1813
1918
|
this.emitOptionalToken(questionToken);
|
|
1814
1919
|
if (questionToken.kind !== SyntaxKind.QuestionToken) this.write1('?');
|
|
1815
1920
|
}
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1921
|
+
// A mapped type written without a type, `{ [K in keyof T] }`, prints without one.
|
|
1922
|
+
if (node.type !== undefined) {
|
|
1923
|
+
this.write1(': ');
|
|
1924
|
+
this.emitTypeNodeOutsideExtends(node.type);
|
|
1925
|
+
}
|
|
1820
1926
|
this.write1(';');
|
|
1821
1927
|
if (node.members !== undefined && node.members.nodes.length > 0) {
|
|
1822
1928
|
if (singleLine) this.space();
|
|
@@ -2847,8 +2953,8 @@ export class Printer extends NameGeneratorHost {
|
|
|
2847
2953
|
case SyntaxKind.MetaProperty:
|
|
2848
2954
|
if (node instanceof MetaProperty) {
|
|
2849
2955
|
const state = this.enterNode(node);
|
|
2850
|
-
this.emitToken(node.keywordToken, node.pos, node);
|
|
2851
|
-
this.
|
|
2956
|
+
const pos = this.emitToken(node.keywordToken, node.pos, node);
|
|
2957
|
+
this.emitToken(SyntaxKind.DotToken, pos, node);
|
|
2852
2958
|
this.emitIdentifierName(node.name);
|
|
2853
2959
|
this.exitNode(node, state);
|
|
2854
2960
|
return true;
|
|
@@ -3210,6 +3316,10 @@ export class Printer extends NameGeneratorHost {
|
|
|
3210
3316
|
this.emitIdentifierOrString(body.name, false);
|
|
3211
3317
|
body = body.body;
|
|
3212
3318
|
}
|
|
3319
|
+
if (node.attributes !== undefined) {
|
|
3320
|
+
this.write1(' with ');
|
|
3321
|
+
this.emitTypeNode(node.attributes, TypePrecedence.NonArray);
|
|
3322
|
+
}
|
|
3213
3323
|
if (body === undefined) this.write1(';');
|
|
3214
3324
|
else if (body instanceof ModuleBlock) {
|
|
3215
3325
|
this.space();
|
|
@@ -3318,16 +3428,21 @@ export class Printer extends NameGeneratorHost {
|
|
|
3318
3428
|
this.emitBindingIdentifier(bindings.name);
|
|
3319
3429
|
this.exitNode(bindings, bindingsState);
|
|
3320
3430
|
} else if (bindings instanceof NamedImports) {
|
|
3321
|
-
|
|
3322
|
-
this.write1('{');
|
|
3323
|
-
this.emitList(ListItem.ImportSpecifier, bindings, bindings.elements, ListFormat.NamedImportsOrExportsElements);
|
|
3324
|
-
this.write1('}');
|
|
3325
|
-
this.exitNode(bindings, bindingsState);
|
|
3431
|
+
this.emitNamedImports(bindings);
|
|
3326
3432
|
}
|
|
3327
3433
|
this.exitNode(node, state);
|
|
3328
3434
|
return true;
|
|
3329
3435
|
}
|
|
3330
3436
|
|
|
3437
|
+
private emitNamedImports(node: NamedImports): boolean {
|
|
3438
|
+
const state = this.enterNode(node);
|
|
3439
|
+
this.write1('{');
|
|
3440
|
+
this.emitList(ListItem.ImportSpecifier, node, node.elements, ListFormat.NamedImportsOrExportsElements);
|
|
3441
|
+
this.write1('}');
|
|
3442
|
+
this.exitNode(node, state);
|
|
3443
|
+
return true;
|
|
3444
|
+
}
|
|
3445
|
+
|
|
3331
3446
|
/** Import and export specifiers. */
|
|
3332
3447
|
private emitSpecifier(
|
|
3333
3448
|
node: Node,
|
|
@@ -3770,7 +3885,7 @@ export class Printer extends NameGeneratorHost {
|
|
|
3770
3885
|
this.space();
|
|
3771
3886
|
this.emitToken(node.token, node.pos, node);
|
|
3772
3887
|
this.space();
|
|
3773
|
-
this.emitList(ListItem.
|
|
3888
|
+
this.emitList(ListItem.HeritageClauseElement, node, node.types, ListFormat.HeritageClauseTypes);
|
|
3774
3889
|
this.exitNode(node, state);
|
|
3775
3890
|
return true;
|
|
3776
3891
|
}
|
|
@@ -3991,6 +4106,10 @@ export class Printer extends NameGeneratorHost {
|
|
|
3991
4106
|
case ListItem.ExpressionWithTypeArguments:
|
|
3992
4107
|
if (node instanceof ExpressionWithTypeArguments) return this.emitExpressionWithTypeArguments(node);
|
|
3993
4108
|
break;
|
|
4109
|
+
case ListItem.HeritageClauseElement:
|
|
4110
|
+
if (node instanceof ExpressionWithTypeArguments) return this.emitExpressionWithTypeArguments(node);
|
|
4111
|
+
if (node.kind === SyntaxKind.TypeReference) return this.emitTypeNodeWorker(node);
|
|
4112
|
+
break;
|
|
3994
4113
|
case ListItem.JsxChild:
|
|
3995
4114
|
return this.emitJsxChild(node);
|
|
3996
4115
|
case ListItem.JsxAttributeLike:
|
|
@@ -4290,6 +4409,9 @@ export class Printer extends NameGeneratorHost {
|
|
|
4290
4409
|
case SyntaxKind.ImportClause:
|
|
4291
4410
|
if (node instanceof ImportClause) return this.emitImportClause(node);
|
|
4292
4411
|
break;
|
|
4412
|
+
case SyntaxKind.NamedImports:
|
|
4413
|
+
if (node instanceof NamedImports) return this.emitNamedImports(node);
|
|
4414
|
+
break;
|
|
4293
4415
|
case SyntaxKind.ImportSpecifier:
|
|
4294
4416
|
return this.emitListItem(ListItem.ImportSpecifier, node);
|
|
4295
4417
|
case SyntaxKind.ExportSpecifier:
|
|
@@ -4350,10 +4472,18 @@ export class Printer extends NameGeneratorHost {
|
|
|
4350
4472
|
|
|
4351
4473
|
private emitCommentsBeforeNode(node: Node): boolean {
|
|
4352
4474
|
if (!this.shouldEmitComments(node)) return false;
|
|
4475
|
+
if (this.inCommentFreeRange(node)) {
|
|
4476
|
+
// What the general path does for a node without emit data and without comments.
|
|
4477
|
+
this.pushCommentState(commentFreeNode, node.pos, node.end);
|
|
4478
|
+
this.containerPos = node.pos;
|
|
4479
|
+
this.containerEnd = node.end;
|
|
4480
|
+
if (node.kind === SyntaxKind.VariableDeclarationList) this.declarationListContainerEnd = node.end;
|
|
4481
|
+
return true;
|
|
4482
|
+
}
|
|
4353
4483
|
const flags = this.context.getEmitFlags(node);
|
|
4354
4484
|
const pos = this.context.commentPos(node);
|
|
4355
4485
|
const end = this.context.commentEnd(node);
|
|
4356
|
-
this.
|
|
4486
|
+
this.pushCommentState(flags, pos, end);
|
|
4357
4487
|
this.emitLeadingCommentsOfNode(node, flags, pos, end);
|
|
4358
4488
|
if ((flags & EmitFlags.NoLeadingComments) === 0) {
|
|
4359
4489
|
const synthesized = this.context.getSyntheticLeadingComments(node);
|
|
@@ -4363,17 +4493,43 @@ export class Printer extends NameGeneratorHost {
|
|
|
4363
4493
|
return true;
|
|
4364
4494
|
}
|
|
4365
4495
|
|
|
4496
|
+
/** Saves the comment state of a node: its emit flags (or `commentFreeNode`), comment range and the containers. */
|
|
4497
|
+
private pushCommentState(flags: number, pos: number, end: number): boolean {
|
|
4498
|
+
let stack = this.commentStack;
|
|
4499
|
+
const at = this.commentDepth;
|
|
4500
|
+
if (at + 6 > stack.length) {
|
|
4501
|
+
const grown = new Int32Array(stack.length * 2);
|
|
4502
|
+
grown.set(stack);
|
|
4503
|
+
this.commentStack = grown;
|
|
4504
|
+
stack = grown;
|
|
4505
|
+
}
|
|
4506
|
+
stack[at] = flags;
|
|
4507
|
+
stack[at + 1] = pos;
|
|
4508
|
+
stack[at + 2] = end;
|
|
4509
|
+
stack[at + 3] = this.containerPos;
|
|
4510
|
+
stack[at + 4] = this.containerEnd;
|
|
4511
|
+
stack[at + 5] = this.declarationListContainerEnd;
|
|
4512
|
+
this.commentDepth = at + 6;
|
|
4513
|
+
return true;
|
|
4514
|
+
}
|
|
4515
|
+
|
|
4366
4516
|
private emitCommentsAfterNode(node: Node): boolean {
|
|
4367
4517
|
const stack = this.commentStack;
|
|
4368
|
-
const base =
|
|
4369
|
-
|
|
4370
|
-
const
|
|
4371
|
-
const
|
|
4372
|
-
const
|
|
4373
|
-
const
|
|
4374
|
-
const
|
|
4375
|
-
|
|
4376
|
-
|
|
4518
|
+
const base = this.commentDepth - 6;
|
|
4519
|
+
const flags = stack[base]!;
|
|
4520
|
+
const pos = stack[base + 1]!;
|
|
4521
|
+
const end = stack[base + 2]!;
|
|
4522
|
+
const containerPos = stack[base + 3]!;
|
|
4523
|
+
const containerEnd = stack[base + 4]!;
|
|
4524
|
+
const declarationListContainerEnd = stack[base + 5]!;
|
|
4525
|
+
this.commentDepth = base;
|
|
4526
|
+
if (node === this.freeOwner) this.endCommentFreeRange();
|
|
4527
|
+
if (flags === commentFreeNode) {
|
|
4528
|
+
this.containerPos = containerPos;
|
|
4529
|
+
this.containerEnd = containerEnd;
|
|
4530
|
+
this.declarationListContainerEnd = declarationListContainerEnd;
|
|
4531
|
+
return true;
|
|
4532
|
+
}
|
|
4377
4533
|
if ((flags & EmitFlags.NoNestedComments) !== 0) this.commentsDisabled = false;
|
|
4378
4534
|
if ((flags & EmitFlags.NoTrailingComments) === 0) {
|
|
4379
4535
|
const synthesized = this.context.getSyntheticTrailingComments(node);
|
|
@@ -4395,6 +4551,83 @@ export class Printer extends NameGeneratorHost {
|
|
|
4395
4551
|
return true;
|
|
4396
4552
|
}
|
|
4397
4553
|
|
|
4554
|
+
/**
|
|
4555
|
+
* Whether `node` has no emit data and lies in a range of the source text where no comment is found, so that its
|
|
4556
|
+
* comments need not be looked for. Outside such a range, a node whose own range is one starts it (`freeOwner`).
|
|
4557
|
+
*/
|
|
4558
|
+
private inCommentFreeRange(node: Node): boolean {
|
|
4559
|
+
const pos = node.pos;
|
|
4560
|
+
const end = node.end;
|
|
4561
|
+
if (pos < 0 || end <= pos || node.kind === SyntaxKind.JsxText || node.kind === SyntaxKind.NotEmittedStatement)
|
|
4562
|
+
return false;
|
|
4563
|
+
if (this.freeEnd < 0) {
|
|
4564
|
+
if (!this.startCommentFreeRange(pos, end)) return false;
|
|
4565
|
+
this.freeOwner = node;
|
|
4566
|
+
} else if (pos < this.freeStart) return false;
|
|
4567
|
+
if (this.context.hasEmitNode(node)) return false;
|
|
4568
|
+
return end < this.freeEnd || (end === this.freeEnd && this.freeEndTrailingNone);
|
|
4569
|
+
}
|
|
4570
|
+
|
|
4571
|
+
private endCommentFreeRange(): boolean {
|
|
4572
|
+
this.freeStart = -1;
|
|
4573
|
+
this.freeEnd = -1;
|
|
4574
|
+
this.freeEndTrailingNone = false;
|
|
4575
|
+
this.freeOwner = undefined;
|
|
4576
|
+
return true;
|
|
4577
|
+
}
|
|
4578
|
+
|
|
4579
|
+
/** Whether the comment-free range shows that no trailing comment follows `pos`. */
|
|
4580
|
+
private noCommentsAfter(pos: number): boolean {
|
|
4581
|
+
return pos >= this.freeStart && (pos < this.freeEnd || (pos === this.freeEnd && this.freeEndTrailingNone));
|
|
4582
|
+
}
|
|
4583
|
+
|
|
4584
|
+
/** Makes `[pos, end)` the comment-free range if no comment starts in it and its last character is not trivia. */
|
|
4585
|
+
private startCommentFreeRange(pos: number, end: number): boolean {
|
|
4586
|
+
const text = this.sourceText;
|
|
4587
|
+
if (end > text.length) return false;
|
|
4588
|
+
const last = text.charCodeAt(end - 1);
|
|
4589
|
+
if (
|
|
4590
|
+
last === CharacterCodes.space ||
|
|
4591
|
+
last === CharacterCodes.tab ||
|
|
4592
|
+
last === CharacterCodes.lineFeed ||
|
|
4593
|
+
last === CharacterCodes.carriageReturn ||
|
|
4594
|
+
last === CharacterCodes.verticalTab ||
|
|
4595
|
+
last === CharacterCodes.formFeed ||
|
|
4596
|
+
last > CharacterCodes.maxAsciiCharacter
|
|
4597
|
+
)
|
|
4598
|
+
return false;
|
|
4599
|
+
const starts = this.commentStartsOfFile();
|
|
4600
|
+
// The first comment start at or after `pos`.
|
|
4601
|
+
let low = 0;
|
|
4602
|
+
let high = starts.length;
|
|
4603
|
+
while (low < high) {
|
|
4604
|
+
const middle = (low + high) >>> 1;
|
|
4605
|
+
if (starts[middle]! < pos) low = middle + 1;
|
|
4606
|
+
else high = middle;
|
|
4607
|
+
}
|
|
4608
|
+
if (low < starts.length && starts[low]! < end) return false;
|
|
4609
|
+
this.freeStart = pos;
|
|
4610
|
+
this.freeEnd = end;
|
|
4611
|
+
this.freeEndTrailingNone = getTrailingCommentRanges(text, end) === undefined;
|
|
4612
|
+
return true;
|
|
4613
|
+
}
|
|
4614
|
+
|
|
4615
|
+
private commentStartsOfFile(): Int32Array {
|
|
4616
|
+
const cached = this.commentStarts;
|
|
4617
|
+
if (cached !== undefined) return cached;
|
|
4618
|
+
const text = this.sourceText;
|
|
4619
|
+
const length = text.length;
|
|
4620
|
+
const list: number[] = [];
|
|
4621
|
+
for (let i = text.indexOf('/'); i >= 0 && i + 1 < length; i = text.indexOf('/', i + 1)) {
|
|
4622
|
+
const next = text.charCodeAt(i + 1);
|
|
4623
|
+
if (next === CharacterCodes.slash || next === CharacterCodes.asterisk) list.push(i);
|
|
4624
|
+
}
|
|
4625
|
+
const starts = new Int32Array(list.length);
|
|
4626
|
+
for (let i = 0; i < list.length; i++) starts[i] = list[i]!;
|
|
4627
|
+
this.commentStarts = starts;
|
|
4628
|
+
return starts;
|
|
4629
|
+
}
|
|
4630
|
+
|
|
4398
4631
|
/** Emits comments before a token; returns whether `emitCommentsAfterToken` applies, with the token's position in `tokenPos`. */
|
|
4399
4632
|
private emitCommentsBeforeToken(pos: number, contextNode: Node, flags: TokenEmitFlags): boolean {
|
|
4400
4633
|
if ((flags & TokenEmitFlags.NoComments) !== 0 || this.commentsDisabled) {
|
|
@@ -4505,6 +4738,7 @@ export class Printer extends NameGeneratorHost {
|
|
|
4505
4738
|
private emitLeadingComments(pos: number, elided: boolean): boolean {
|
|
4506
4739
|
if (this.commentsDisabled || this.currentSourceFile === undefined || pos < 0 || pos === this.containerPos)
|
|
4507
4740
|
return false;
|
|
4741
|
+
if (pos >= this.freeStart && pos < this.freeEnd) return false;
|
|
4508
4742
|
// 1: only triple-slash comments, 2: all but triple-slash comments, 0: all.
|
|
4509
4743
|
let tripleSlash = 0;
|
|
4510
4744
|
if (!elided) {
|
|
@@ -4552,6 +4786,7 @@ export class Printer extends NameGeneratorHost {
|
|
|
4552
4786
|
(this.containerEnd !== -1 && (pos === this.containerEnd || pos === this.declarationListContainerEnd))
|
|
4553
4787
|
)
|
|
4554
4788
|
return false;
|
|
4789
|
+
if (this.noCommentsAfter(pos)) return false;
|
|
4555
4790
|
const ranges = getTrailingCommentRanges(this.sourceText, pos);
|
|
4556
4791
|
if (ranges === undefined) return false;
|
|
4557
4792
|
let comments: CommentRange[] | undefined = undefined;
|
|
@@ -4567,6 +4802,7 @@ export class Printer extends NameGeneratorHost {
|
|
|
4567
4802
|
if (this.commentsDisabled || this.currentSourceFile === undefined) return false;
|
|
4568
4803
|
if (this.containerEnd !== -1 && (pos === this.containerEnd || pos === this.declarationListContainerEnd))
|
|
4569
4804
|
return false;
|
|
4805
|
+
if (this.noCommentsAfter(pos)) return false;
|
|
4570
4806
|
const comments = getTrailingCommentRanges(this.sourceText, pos);
|
|
4571
4807
|
if (comments === undefined) return false;
|
|
4572
4808
|
for (const comment of comments) {
|
|
@@ -31,7 +31,12 @@ import {
|
|
|
31
31
|
PrivateIdentifier,
|
|
32
32
|
getExpression,
|
|
33
33
|
} from '../ast.js';
|
|
34
|
-
import {
|
|
34
|
+
import {
|
|
35
|
+
OperatorPrecedence,
|
|
36
|
+
getBinaryOperatorPrecedence,
|
|
37
|
+
isJSDocTypeExpressionOrChild,
|
|
38
|
+
normalizeJSDocTypeSourceText,
|
|
39
|
+
} from '../ast-utilities.js';
|
|
35
40
|
import {
|
|
36
41
|
CharacterCodes,
|
|
37
42
|
isDigit,
|
|
@@ -687,7 +692,8 @@ export function getLiteralText(node: Node, sourceText: string | undefined, flags
|
|
|
687
692
|
/** The source text of a node without leading trivia, as tsgo's GetSourceTextOfNodeFromSourceFile. */
|
|
688
693
|
export function getSourceTextOfNode(sourceText: string, node: Node): string {
|
|
689
694
|
if (node.pos === node.end && node.pos >= 0 && node.kind !== SyntaxKind.EndOfFile) return '';
|
|
690
|
-
|
|
695
|
+
let text = sourceText.substring(skipTrivia(sourceText, node.pos), node.end);
|
|
696
|
+
if (isJSDocTypeExpressionOrChild(node)) text = normalizeJSDocTypeSourceText(text);
|
|
691
697
|
if ((node.flags & NodeFlags.ReparserTransformedLiteral) !== 0) {
|
|
692
698
|
if (node instanceof StringLiteral)
|
|
693
699
|
return (node.tokenFlags & TokenFlags.SingleQuote) !== 0 ? "'" + text + "'" : '"' + text + '"';
|
|
@@ -9,7 +9,14 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { type Node, ScriptKind, type SourceFile } from './ast.js';
|
|
11
11
|
import { Checker, CheckerHost, disposeChecker } from './checker.js';
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
compareDiagnostics,
|
|
14
|
+
createDiagnostic,
|
|
15
|
+
Diagnostic,
|
|
16
|
+
type DiagnosticMessage,
|
|
17
|
+
Diagnostics,
|
|
18
|
+
messageCode,
|
|
19
|
+
} from './diagnostics.js';
|
|
13
20
|
import type { EmitResult } from './emitter.js';
|
|
14
21
|
import type { CompilerOptions, ModuleKind } from './options.js';
|
|
15
22
|
import type { ResolvedModule } from './module-resolution-types.js';
|
|
@@ -265,6 +272,12 @@ export class CheckedProgram {
|
|
|
265
272
|
*/
|
|
266
273
|
referenceThreads = 1;
|
|
267
274
|
readonly parallelGlobalDiagnostics: Diagnostic[] = [];
|
|
275
|
+
/**
|
|
276
|
+
* Whether the semantic diagnostics of a file include the global diagnostics its checker found while
|
|
277
|
+
* checking it, as an incremental program caches them (IncrementalProgram). Such a program doesn't report
|
|
278
|
+
* the global diagnostics found by checking otherwise (`reportsGlobalDiagnosticsOfChecking`, compile-program.ts).
|
|
279
|
+
*/
|
|
280
|
+
globalsInFileDiagnostics = false;
|
|
268
281
|
/**
|
|
269
282
|
* The declaration diagnostics checker threads computed under `noEmit` (PlainProgram,
|
|
270
283
|
* IncrementalProgram), by file index; `undefined` for files they did not. Set once every file is
|
|
@@ -276,6 +289,10 @@ export class CheckedProgram {
|
|
|
276
289
|
* emit. Set once every file is checked, when checker threads emit (parallel-check.ts).
|
|
277
290
|
*/
|
|
278
291
|
emittedInParallel: (EmitResult | undefined)[] | undefined = undefined;
|
|
292
|
+
/** Emit threads emitted only the JavaScript of `emittedInParallel`: declarations are emitted here. */
|
|
293
|
+
javaScriptEmittedOnThreads = false;
|
|
294
|
+
/** The declaration emit of each file on the declaration thread (parallel-emit.ts); undefined for one it didn't emit. */
|
|
295
|
+
declarationsEmittedAhead: (EmitResult | undefined)[] | undefined = undefined;
|
|
279
296
|
/**
|
|
280
297
|
* The global diagnostics of this thread's checker before it emitted files while checker threads
|
|
281
298
|
* checked (`emitUncheckedFiles`), reported instead of its current ones.
|
|
@@ -399,11 +416,11 @@ export class CheckedProgram {
|
|
|
399
416
|
return sortAndDeduplicateDiagnostics([...own, ...parallel]);
|
|
400
417
|
}
|
|
401
418
|
|
|
402
|
-
/** Whether `file`'s bind and check diagnostics are
|
|
403
|
-
skipTypeChecking(file: SourceFile): boolean {
|
|
419
|
+
/** Whether `file`'s bind and check diagnostics are skipped; `ignoreNoCheck` leaves `noCheck` out. */
|
|
420
|
+
skipTypeChecking(file: SourceFile, ignoreNoCheck = false): boolean {
|
|
404
421
|
const options = this.program.options;
|
|
405
422
|
return (
|
|
406
|
-
options.noCheck === true ||
|
|
423
|
+
(!ignoreNoCheck && options.noCheck === true) ||
|
|
407
424
|
(options.skipLibCheck === true && file.isDeclarationFile) ||
|
|
408
425
|
(options.skipDefaultLibCheck === true && this.program.isSourceFileDefaultLibrary(file.path)) ||
|
|
409
426
|
this.program.getProjectReferenceFromSource(file.path) !== undefined ||
|
|
@@ -432,7 +449,15 @@ export class CheckedProgram {
|
|
|
432
449
|
private getBindAndCheckDiagnostics(file: SourceFile, checks?: readonly Diagnostic[]): Diagnostic[] {
|
|
433
450
|
const options = this.program.options;
|
|
434
451
|
const diagnostics = file.bindDiagnostics.slice();
|
|
435
|
-
for (const d of checks
|
|
452
|
+
if (checks !== undefined) for (const d of checks) diagnostics.push(d);
|
|
453
|
+
else if (this.globalsInFileDiagnostics) {
|
|
454
|
+
const checker = this.checker;
|
|
455
|
+
const before = checker.getGlobalDiagnostics();
|
|
456
|
+
for (const d of checker.getDiagnostics(file)) diagnostics.push(d);
|
|
457
|
+
const after = checker.getGlobalDiagnostics();
|
|
458
|
+
if (after.length > before.length)
|
|
459
|
+
for (const d of after) if (!containsSortedDiagnostic(before, d)) diagnostics.push(d);
|
|
460
|
+
} else for (const d of this.checker.getDiagnostics(file)) diagnostics.push(d);
|
|
436
461
|
if (isPlainJSFile(file, options)) {
|
|
437
462
|
const result: Diagnostic[] = [];
|
|
438
463
|
for (const d of diagnostics) if (plainJSErrors.has(d.code)) result.push(d);
|
|
@@ -463,6 +488,20 @@ export class CheckedProgram {
|
|
|
463
488
|
}
|
|
464
489
|
}
|
|
465
490
|
|
|
491
|
+
/** Whether `sorted`, in `compareDiagnostics` order, has a diagnostic equal to `diagnostic`. */
|
|
492
|
+
function containsSortedDiagnostic(sorted: readonly Diagnostic[], diagnostic: Diagnostic): boolean {
|
|
493
|
+
let low = 0;
|
|
494
|
+
let high = sorted.length - 1;
|
|
495
|
+
while (low <= high) {
|
|
496
|
+
const middle = (low + high) >>> 1;
|
|
497
|
+
const c = compareDiagnostics(sorted[middle]!, diagnostic);
|
|
498
|
+
if (c === 0) return true;
|
|
499
|
+
if (c < 0) low = middle + 1;
|
|
500
|
+
else high = middle - 1;
|
|
501
|
+
}
|
|
502
|
+
return false;
|
|
503
|
+
}
|
|
504
|
+
|
|
466
505
|
/** The `@ts-ignore` and `@ts-expect-error` comments of a file, by line. */
|
|
467
506
|
class Directives {
|
|
468
507
|
private readonly byLine = new Map<number, { pos: number; end: number; kind: CommentDirectiveKind }>();
|
|
@@ -484,6 +523,11 @@ class Directives {
|
|
|
484
523
|
const lineStarts = this.file.diagnosticFile().getLineStarts();
|
|
485
524
|
const result: Diagnostic[] = [];
|
|
486
525
|
for (const diagnostic of diagnostics) {
|
|
526
|
+
// A global diagnostic, or one of another file, has no line here.
|
|
527
|
+
if (diagnostic.file === undefined || diagnostic.file.fileName !== this.file.fileName) {
|
|
528
|
+
result.push(diagnostic);
|
|
529
|
+
continue;
|
|
530
|
+
}
|
|
487
531
|
let ignored = false;
|
|
488
532
|
for (let line = computeLineOfPosition(lineStarts, diagnostic.pos) - 1; line >= 0; line--) {
|
|
489
533
|
const directive = this.byLine.get(line);
|
|
@@ -560,6 +604,7 @@ const plainJSErrors = codesOf([
|
|
|
560
604
|
Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement,
|
|
561
605
|
Diagnostics.A_default_clause_cannot_appear_more_than_once_in_a_switch_statement,
|
|
562
606
|
Diagnostics.A_default_export_must_be_at_the_top_level_of_a_file_or_module_declaration,
|
|
607
|
+
Diagnostics.A_deferred_import_must_specify_a_namespace_binding,
|
|
563
608
|
Diagnostics.A_definite_assignment_assertion_is_not_permitted_in_this_context,
|
|
564
609
|
Diagnostics.A_destructuring_declaration_must_have_an_initializer,
|
|
565
610
|
Diagnostics.A_get_accessor_cannot_have_parameters,
|
|
@@ -628,6 +673,13 @@ const plainJSErrors = codesOf([
|
|
|
628
673
|
Diagnostics.X_await_using_statements_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules,
|
|
629
674
|
Diagnostics.Private_field_0_must_be_declared_in_an_enclosing_class,
|
|
630
675
|
Diagnostics.This_condition_will_always_return_0_since_JavaScript_compares_objects_by_reference_not_value,
|
|
676
|
+
Diagnostics.A_deferred_import_must_specify_a_namespace_binding,
|
|
677
|
+
Diagnostics.A_source_phase_import_must_specify_a_local_binding,
|
|
678
|
+
Diagnostics.Named_and_namespace_imports_are_not_allowed_in_a_source_phase_import,
|
|
679
|
+
Diagnostics.Optional_chaining_cannot_be_used_with_import_source,
|
|
680
|
+
Diagnostics.Source_phase_imports_are_not_allowed_on_statements_that_compile_to_CommonJS_require_calls,
|
|
681
|
+
Diagnostics.Source_phase_imports_are_only_supported_when_the_module_option_is_set_to_esnext_nodenext_or_preserve,
|
|
682
|
+
Diagnostics.X_0_is_not_a_valid_meta_property_for_keyword_import_Did_you_mean_meta_defer_or_source,
|
|
631
683
|
]);
|
|
632
684
|
|
|
633
685
|
function codesOf(messages: readonly DiagnosticMessage[]): Set<number> {
|