tsc-ts 0.0.10 → 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 +1 -1
- 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 +20 -15
- package/dist/api/compiler/ast.js +1023 -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 +173 -123
- 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 +469 -438
- 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 -113
- 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 +210 -74
- 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 +137 -34
- 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 +93 -31
- package/dist/api/compiler/checker.js +143 -35
- 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 +19 -4
- package/dist/api/compiler/compile-program.js +45 -26
- package/dist/api/compiler/diagnostic-messages.d.ts +1849 -1774
- package/dist/api/compiler/diagnostic-messages.js +128 -122
- package/dist/api/compiler/diagnostics.js +7 -7
- 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 +10 -0
- package/dist/api/compiler/file-loader.js +138 -41
- 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/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 +3 -1
- package/dist/api/compiler/printer/emit-context.js +16 -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 +1 -0
- package/dist/api/compiler/printer/printer.js +303 -281
- package/dist/api/compiler/printer/utilities.js +149 -147
- package/dist/api/compiler/program-checker.d.ts +8 -2
- package/dist/api/compiler/program-checker.js +84 -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 +2 -0
- package/dist/api/compiler/program.js +69 -57
- 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 +337 -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 +22 -13
- package/dist/api/compiler/symbol.js +15 -1
- 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 +55 -26
- package/src/compiler/binder.ts +39 -4
- package/src/compiler/character-codes.ts +2 -2
- package/src/compiler/checker-calls.ts +76 -8
- 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 +133 -60
- package/src/compiler/checker-heritage.ts +22 -21
- package/src/compiler/checker-inference.ts +514 -87
- 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 +197 -55
- 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 +120 -21
- 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 +168 -41
- package/src/compiler/command-line.ts +28 -28
- package/src/compiler/compile-program.ts +51 -25
- package/src/compiler/decoder.ts +13 -4
- package/src/compiler/diagnostic-messages.ts +1973 -1892
- 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 +139 -32
- package/src/compiler/help.ts +10 -14
- package/src/compiler/incremental.ts +86 -18
- 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 +197 -8
- package/src/compiler/parallel-emit.ts +1 -1
- package/src/compiler/parser.ts +156 -39
- package/src/compiler/path.ts +22 -2
- package/src/compiler/printer/emit-context.ts +16 -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 +35 -14
- package/src/compiler/printer/utilities.ts +8 -2
- package/src/compiler/program-checker.ts +53 -5
- package/src/compiler/program-utilities.ts +23 -10
- package/src/compiler/program.ts +13 -1
- package/src/compiler/pseudo-bigint.ts +17 -0
- package/src/compiler/regexp-checker.ts +63 -30
- package/src/compiler/relations.ts +233 -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 +31 -14
- package/src/compiler/syntax-kind.ts +188 -187
- package/src/compiler/thread-entry.ts +19 -2
- 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 +3 -0
- package/src/compiler/tsc-cli.ts +2 -0
- package/src/compiler/tsc-compile.ts +7 -2
- 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
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ npx tsc-ts --noEmit src/index.ts
|
|
|
33
33
|
|
|
34
34
|
`tsc-ts --api` serves the TypeScript API over stdin and stdout, like `tsc --api`. On Windows, `--api --pipe \\.\pipe\<name>` serves it over a named pipe it creates, as `tsc --api --pipe` does, for clients that connect to the pipe (such as scriptc under Node.js); only the native executable supports `--pipe`. On macOS and Linux, `--api --listen <path>` serves it on a Unix socket it creates, with mode 0600, to one client of the same user at a time, each until the client closes its end. Each client gets the answers a new `tsc-ts --api` process would give, except that symbol ids continue from earlier clients, and the server reads every file through the client again, but it keeps parsed files between clients and reuses those whose text is unchanged, along with the encoding `getSourceFile` sends for each, so a client that opens the same project again loads it faster. The server exits when no client connects for 60 seconds (`--idle-exit <seconds>` sets the time), or after a client when its resident memory is above 2.5 times what it held after its first client (`TSC_TS_LISTEN_MEMORY` sets the limit in megabytes). To stop, it removes the socket file, serves the clients that had connected, and exits. It replaces a socket file that no server answers on, such as one left by a server that was killed. Only the native executable supports `--listen`. With `--default-libraries-from-disk`, the server reads the files in its default library directory (`TSC_TS_LIB_DIR`, or the executable's directory) from the disk itself, even when the client handles file system calls (`--callbacks`), which saves a round trip to the client for each library file.
|
|
35
35
|
|
|
36
|
-
`--checkers N` checks the program on N threads. Unless `--checkers` or `--singleThreaded` is given, the native executable uses one checker per CPU it may run on (up to 16), and at least tsgo's four; it uses fewer than the CPUs, but never fewer than four, when the estimated peak memory of more checkers would not fit 85% of the machine's memory (`TSC_TS_CHECKERS=fixed` keeps tsgo's four), and checkers beyond the fourth stop taking files, one at a time, when the process's memory reaches that share; it shares one program between its threads and also parses and binds the program's files on them. Unless `--singleThreaded` is given, the program's files are parsed and bound on threads also with `--checkers 1`, as tsgo does. Files that share costly declarations, such as a large generated schema and the few files importing it, are checked together on one checker. Under Node.js, where every thread builds its own copy of the program, tsc-ts checks on one thread unless `--checkers` is given. `--incremental`, `--watch` and `--build` always check on one thread. The diagnostics are the same as with one checker.
|
|
36
|
+
`--checkers N` checks the program on N threads. Unless `--checkers` or `--singleThreaded` is given, the native executable uses one checker per CPU it may run on (up to 16), and at least tsgo's four; it uses fewer than the CPUs, but never fewer than four, when the estimated peak memory of more checkers would not fit 85% of the machine's memory (`TSC_TS_CHECKERS=fixed` keeps tsgo's four), and checkers beyond the fourth stop taking files, one at a time, when the process's memory reaches that share; it shares one program between its threads and also parses and binds the program's files on them. Unless `--singleThreaded` is given, the program's files are parsed and bound on threads also with `--checkers 1` and in the first build of `--watch`, with or without build info, as tsgo does. Files that share costly declarations, such as a large generated schema and the few files importing it, are checked together on one checker. Under Node.js, where every thread builds its own copy of the program, tsc-ts checks on one thread unless `--checkers` is given. `--incremental`, `--watch` and `--build` always check on one thread. The diagnostics are the same as with one checker.
|
|
37
37
|
|
|
38
38
|
The native executable never frees syntax trees, types, signatures or symbols: it keeps them until it exits, which saves the cost of tracking them during a build. A one-shot build is unaffected, but a long-running process grows with each rebuild or project update. Native `--watch` (also with `--build`) runs in a child process, and when a change arrives while that process holds more than 2.5 times the memory it held after its first build, a new process replaces it and builds the change, reporting what the old process would have. `TSC_TS_WATCH_MEMORY` sets that limit in megabytes, and `TSC_TS_WATCH_MEMORY=0` turns the replacement off. A `--api` process grows with each project update; restart it to reclaim the memory.
|
|
39
39
|
|
package/bin/tsc-ts.js
CHANGED
|
@@ -2,7 +2,20 @@
|
|
|
2
2
|
// Runs the native tsc-ts executable from this platform's package. The lib
|
|
3
3
|
// files sit next to the executable, where it looks for them.
|
|
4
4
|
import { spawnSync } from 'node:child_process';
|
|
5
|
-
import {
|
|
5
|
+
import { randomBytes } from 'node:crypto';
|
|
6
|
+
import {
|
|
7
|
+
accessSync,
|
|
8
|
+
chmodSync,
|
|
9
|
+
closeSync,
|
|
10
|
+
constants,
|
|
11
|
+
fchmodSync,
|
|
12
|
+
openSync,
|
|
13
|
+
readFileSync,
|
|
14
|
+
renameSync,
|
|
15
|
+
statSync,
|
|
16
|
+
unlinkSync,
|
|
17
|
+
writeSync,
|
|
18
|
+
} from 'node:fs';
|
|
6
19
|
import { createRequire } from 'node:module';
|
|
7
20
|
import { dirname, join } from 'node:path';
|
|
8
21
|
import { executableName, hostDescription, hostPlatform, packageName } from './platforms.js';
|
|
@@ -31,11 +44,67 @@ if (process.platform !== 'win32') {
|
|
|
31
44
|
}
|
|
32
45
|
}
|
|
33
46
|
|
|
47
|
+
if (process.platform === 'linux') writeOnce(executable);
|
|
48
|
+
|
|
34
49
|
const result = spawnSync(executable, process.argv.slice(2), { stdio: 'inherit' });
|
|
35
50
|
if (result.error) fail(`could not run ${executable}: ${result.error.message}`);
|
|
36
51
|
if (result.signal) process.kill(process.pid, result.signal);
|
|
37
52
|
process.exitCode = result.status ?? 1;
|
|
38
53
|
|
|
54
|
+
// The executable's code maps with 2 MiB pages when the page cache holds the
|
|
55
|
+
// file in 2 MiB folios, which a file written with one write gets on file
|
|
56
|
+
// systems with large folios (XFS, ext4 from Linux 6.16). Package managers
|
|
57
|
+
// write it in chunks, which leaves 4 KiB folios until the file is read from
|
|
58
|
+
// disk again. The first run writes it again with one write and renames the
|
|
59
|
+
// copy into place; .tsc-ts-written beside it holds the size of the copy, so
|
|
60
|
+
// later runs only read it. When the directory is not writable, the
|
|
61
|
+
// executable runs as installed.
|
|
62
|
+
function writeOnce(file) {
|
|
63
|
+
const marker = join(dirname(file), '.tsc-ts-written');
|
|
64
|
+
let size;
|
|
65
|
+
try {
|
|
66
|
+
size = statSync(file).size;
|
|
67
|
+
if (readFileSync(marker, 'utf8') === String(size)) return;
|
|
68
|
+
} catch {
|
|
69
|
+
if (size === undefined) return;
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
const bytes = readFileSync(file);
|
|
73
|
+
replaceFile(file, bytes, statSync(file).mode & 0o7777);
|
|
74
|
+
replaceFile(marker, Buffer.from(String(bytes.length)), 0o644);
|
|
75
|
+
} catch {
|
|
76
|
+
// The executable runs as installed.
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Replaces `file` with `bytes` and `mode` through a new file beside it. The copy
|
|
81
|
+
// has an unpredictable name and is created exclusively (an existing path, a
|
|
82
|
+
// symbolic link included, is never opened) with mode 0600, so no other user
|
|
83
|
+
// can open it while it is written; it gets `mode` from its own descriptor
|
|
84
|
+
// before it is renamed into place. Only a copy this run created is removed.
|
|
85
|
+
function replaceFile(file, bytes, mode) {
|
|
86
|
+
const temporary = `${file}.${randomBytes(8).toString('hex')}.tmp`;
|
|
87
|
+
const fd = openSync(
|
|
88
|
+
temporary,
|
|
89
|
+
constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW,
|
|
90
|
+
0o600,
|
|
91
|
+
);
|
|
92
|
+
try {
|
|
93
|
+
for (let offset = 0; offset < bytes.length;) offset += writeSync(fd, bytes, offset, bytes.length - offset);
|
|
94
|
+
fchmodSync(fd, mode);
|
|
95
|
+
closeSync(fd);
|
|
96
|
+
renameSync(temporary, file);
|
|
97
|
+
} catch (error) {
|
|
98
|
+
try {
|
|
99
|
+
closeSync(fd);
|
|
100
|
+
} catch {
|
|
101
|
+
// Closed before the failure.
|
|
102
|
+
}
|
|
103
|
+
unlinkSync(temporary);
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
39
108
|
function fail(message) {
|
|
40
109
|
process.stderr.write(`tsc-ts: ${message}\n`);
|
|
41
110
|
process.exit(1);
|
|
@@ -58,11 +58,23 @@ export declare function canHaveDecorators(node: Node): boolean;
|
|
|
58
58
|
export declare function isStringLiteralLike(node: Node): boolean;
|
|
59
59
|
/** Whether two JSX tag names (identifiers, `this`, namespaced names or property accesses) are the same. */
|
|
60
60
|
export declare function tagNamesAreEquivalent(lhs: Node, rhs: Node): boolean;
|
|
61
|
+
/** Whether `node` is a JSDoc type expression or a type node in one. */
|
|
62
|
+
export declare function isJSDocTypeExpressionOrChild(node: Node): boolean;
|
|
63
|
+
/** The text of a JSDoc type with the leading whitespace and `*` of each line removed, and LF line breaks. */
|
|
64
|
+
export declare function normalizeJSDocTypeSourceText(text: string): string;
|
|
61
65
|
/** The source text of a node, without leading trivia. */
|
|
62
66
|
export declare function getTextOfNodeFromSourceText(sourceText: string, node: Node): string;
|
|
63
67
|
export declare function isImportMeta(node: Node): boolean;
|
|
64
|
-
/** `import(…)` or `import.
|
|
68
|
+
/** `import(…)`, `import.defer(…)` or `import.source(…)`. */
|
|
65
69
|
export declare function isImportCall(node: Node): boolean;
|
|
70
|
+
/** `import.defer` or `import.source`. */
|
|
71
|
+
export declare function isImportPhaseMetaProperty(node: Node): boolean;
|
|
72
|
+
export declare function isImportDeferMetaProperty(node: Node): boolean;
|
|
73
|
+
export declare function isImportSourceMetaProperty(node: Node): boolean;
|
|
74
|
+
/** `import source x from "m"` or `import.source("m")`. */
|
|
75
|
+
export declare function isSourcePhaseImport(node: Node): boolean;
|
|
76
|
+
/** `import.source(…)`. */
|
|
77
|
+
export declare function isSourcePhaseImportCall(node: Node): boolean;
|
|
66
78
|
/** `require(x)` with one argument, a string literal if `requireStringLiteralLikeArgument`. */
|
|
67
79
|
export declare function isRequireCall(node: Node, requireStringLiteralLikeArgument: boolean): boolean;
|
|
68
80
|
/** The string literal of `import("x")` types. */
|
|
@@ -80,3 +92,9 @@ export declare function isAmbientModule(node: Node): boolean;
|
|
|
80
92
|
export declare function isJSDocTypeAssertion(node: Node): boolean;
|
|
81
93
|
/** The expression a check applies to: parentheses and `satisfies` are skipped, but not JavaScript casts. */
|
|
82
94
|
export declare function getEffectiveCheckNode(argument: Node): Node;
|
|
95
|
+
/** The entity name of a heritage clause element: a type reference's type name, or an
|
|
96
|
+
* `ExpressionWithTypeArguments`'s expression. */
|
|
97
|
+
export declare function getHeritageClauseElementName(node: Node): Node;
|
|
98
|
+
/** Whether a name, or the rightmost name of a qualified name, is the type name of a type reference in a
|
|
99
|
+
* heritage clause. */
|
|
100
|
+
export declare function isNameOfHeritageClauseTypeReference(nodeIn: Node): boolean;
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
//
|
|
3
3
|
// Fields of `instanceof`-narrowed nodes are read through `as` casts: scriptc reads them
|
|
4
4
|
// statically, but reads fields of a narrowed value dynamically.
|
|
5
|
-
import { CallExpression, ExternalModuleReference, Identifier, ImportEqualsDeclaration, ImportTypeNode, JsxNamespacedName, LiteralTypeNode, MetaProperty, ModuleDeclaration, PropertyAccessExpression, StringLiteral, getExpression, getIsTypeOnly, getModuleSpecifier, getText, getType, } from './ast.js';
|
|
5
|
+
import { CallExpression, ExternalModuleReference, Identifier, ImportDeclaration, ImportEqualsDeclaration, ImportTypeNode, JsxNamespacedName, LiteralTypeNode, MetaProperty, ModuleDeclaration, PropertyAccessExpression, StringLiteral, getExpression, getIsTypeOnly, getModuleSpecifier, getText, getType, } from './ast.js';
|
|
6
|
+
import { isTypeNodeKind } from './binder-utilities.js';
|
|
7
|
+
import { isLineBreak, isWhiteSpaceLike } from './character-codes.js';
|
|
6
8
|
import { skipTrivia } from './scanner.js';
|
|
7
9
|
export function getBinaryOperatorPrecedence(kind) {
|
|
8
10
|
switch (kind) {
|
|
@@ -51,7 +53,7 @@ export function getBinaryOperatorPrecedence(kind) {
|
|
|
51
53
|
}
|
|
52
54
|
// Tokens
|
|
53
55
|
export function isKeyword(token) {
|
|
54
|
-
return token >= 82 /* SyntaxKind.FirstKeyword */ && token <=
|
|
56
|
+
return token >= 82 /* SyntaxKind.FirstKeyword */ && token <= 167 /* SyntaxKind.LastKeyword */;
|
|
55
57
|
}
|
|
56
58
|
export function isPunctuation(token) {
|
|
57
59
|
return token >= 18 /* SyntaxKind.FirstPunctuation */ && token <= 78 /* SyntaxKind.LastPunctuation */;
|
|
@@ -121,7 +123,7 @@ export function modifierToFlag(kind) {
|
|
|
121
123
|
return 8192 /* ModifierFlags.In */;
|
|
122
124
|
case 147 /* SyntaxKind.OutKeyword */:
|
|
123
125
|
return 16384 /* ModifierFlags.Out */;
|
|
124
|
-
case
|
|
126
|
+
case 172 /* SyntaxKind.Decorator */:
|
|
125
127
|
return 32768 /* ModifierFlags.Decorator */;
|
|
126
128
|
}
|
|
127
129
|
return 0 /* ModifierFlags.None */;
|
|
@@ -180,19 +182,19 @@ export function compareNodePositions(a, b) {
|
|
|
180
182
|
}
|
|
181
183
|
function isLeftHandSideExpressionKind(kind) {
|
|
182
184
|
switch (kind) {
|
|
183
|
-
case
|
|
184
|
-
case
|
|
185
|
-
case
|
|
186
|
-
case
|
|
187
|
-
case
|
|
188
|
-
case
|
|
189
|
-
case
|
|
190
|
-
case
|
|
191
|
-
case
|
|
192
|
-
case
|
|
193
|
-
case
|
|
194
|
-
case
|
|
195
|
-
case
|
|
185
|
+
case 213 /* SyntaxKind.PropertyAccessExpression */:
|
|
186
|
+
case 214 /* SyntaxKind.ElementAccessExpression */:
|
|
187
|
+
case 216 /* SyntaxKind.NewExpression */:
|
|
188
|
+
case 215 /* SyntaxKind.CallExpression */:
|
|
189
|
+
case 286 /* SyntaxKind.JsxElement */:
|
|
190
|
+
case 287 /* SyntaxKind.JsxSelfClosingElement */:
|
|
191
|
+
case 290 /* SyntaxKind.JsxFragment */:
|
|
192
|
+
case 217 /* SyntaxKind.TaggedTemplateExpression */:
|
|
193
|
+
case 211 /* SyntaxKind.ArrayLiteralExpression */:
|
|
194
|
+
case 219 /* SyntaxKind.ParenthesizedExpression */:
|
|
195
|
+
case 212 /* SyntaxKind.ObjectLiteralExpression */:
|
|
196
|
+
case 233 /* SyntaxKind.ClassExpression */:
|
|
197
|
+
case 220 /* SyntaxKind.FunctionExpression */:
|
|
196
198
|
case 79 /* SyntaxKind.Identifier */:
|
|
197
199
|
case 80 /* SyntaxKind.PrivateIdentifier */:
|
|
198
200
|
case 13 /* SyntaxKind.RegularExpressionLiteral */:
|
|
@@ -200,17 +202,17 @@ function isLeftHandSideExpressionKind(kind) {
|
|
|
200
202
|
case 9 /* SyntaxKind.BigIntLiteral */:
|
|
201
203
|
case 10 /* SyntaxKind.StringLiteral */:
|
|
202
204
|
case 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */:
|
|
203
|
-
case
|
|
205
|
+
case 230 /* SyntaxKind.TemplateExpression */:
|
|
204
206
|
case 96 /* SyntaxKind.FalseKeyword */:
|
|
205
207
|
case 105 /* SyntaxKind.NullKeyword */:
|
|
206
208
|
case 109 /* SyntaxKind.ThisKeyword */:
|
|
207
209
|
case 111 /* SyntaxKind.TrueKeyword */:
|
|
208
210
|
case 107 /* SyntaxKind.SuperKeyword */:
|
|
209
|
-
case
|
|
210
|
-
case
|
|
211
|
-
case
|
|
211
|
+
case 237 /* SyntaxKind.NonNullExpression */:
|
|
212
|
+
case 235 /* SyntaxKind.ExpressionWithTypeArguments */:
|
|
213
|
+
case 238 /* SyntaxKind.MetaProperty */:
|
|
212
214
|
case 101 /* SyntaxKind.ImportKeyword */:
|
|
213
|
-
case
|
|
215
|
+
case 284 /* SyntaxKind.MissingDeclaration */:
|
|
214
216
|
return true;
|
|
215
217
|
}
|
|
216
218
|
return false;
|
|
@@ -218,32 +220,32 @@ function isLeftHandSideExpressionKind(kind) {
|
|
|
218
220
|
/** Partially emitted expressions, created by transforms, are skipped. */
|
|
219
221
|
export function isLeftHandSideExpression(node) {
|
|
220
222
|
let expression = node;
|
|
221
|
-
while (expression.kind ===
|
|
223
|
+
while (expression.kind === 349 /* SyntaxKind.PartiallyEmittedExpression */)
|
|
222
224
|
expression = expression.expression;
|
|
223
225
|
return isLeftHandSideExpressionKind(expression.kind);
|
|
224
226
|
}
|
|
225
227
|
export function isFunctionLikeDeclarationKind(kind) {
|
|
226
228
|
switch (kind) {
|
|
227
|
-
case
|
|
228
|
-
case
|
|
229
|
-
case
|
|
230
|
-
case
|
|
231
|
-
case
|
|
232
|
-
case
|
|
233
|
-
case
|
|
229
|
+
case 264 /* SyntaxKind.FunctionDeclaration */:
|
|
230
|
+
case 176 /* SyntaxKind.MethodDeclaration */:
|
|
231
|
+
case 178 /* SyntaxKind.Constructor */:
|
|
232
|
+
case 179 /* SyntaxKind.GetAccessor */:
|
|
233
|
+
case 180 /* SyntaxKind.SetAccessor */:
|
|
234
|
+
case 220 /* SyntaxKind.FunctionExpression */:
|
|
235
|
+
case 221 /* SyntaxKind.ArrowFunction */:
|
|
234
236
|
return true;
|
|
235
237
|
}
|
|
236
238
|
return false;
|
|
237
239
|
}
|
|
238
240
|
export function isFunctionLikeKind(kind) {
|
|
239
241
|
switch (kind) {
|
|
240
|
-
case
|
|
241
|
-
case
|
|
242
|
-
case
|
|
243
|
-
case
|
|
244
|
-
case
|
|
245
|
-
case
|
|
246
|
-
case
|
|
242
|
+
case 175 /* SyntaxKind.MethodSignature */:
|
|
243
|
+
case 181 /* SyntaxKind.CallSignature */:
|
|
244
|
+
case 319 /* SyntaxKind.JSDocSignature */:
|
|
245
|
+
case 182 /* SyntaxKind.ConstructSignature */:
|
|
246
|
+
case 183 /* SyntaxKind.IndexSignature */:
|
|
247
|
+
case 186 /* SyntaxKind.FunctionType */:
|
|
248
|
+
case 187 /* SyntaxKind.ConstructorType */:
|
|
247
249
|
return true;
|
|
248
250
|
}
|
|
249
251
|
return isFunctionLikeDeclarationKind(kind);
|
|
@@ -253,37 +255,37 @@ export function isFunctionLike(node) {
|
|
|
253
255
|
}
|
|
254
256
|
export function canHaveIllegalDecorators(node) {
|
|
255
257
|
switch (node.kind) {
|
|
256
|
-
case
|
|
257
|
-
case
|
|
258
|
-
case
|
|
259
|
-
case
|
|
260
|
-
case
|
|
261
|
-
case
|
|
262
|
-
case
|
|
263
|
-
case
|
|
264
|
-
case
|
|
265
|
-
case
|
|
266
|
-
case
|
|
267
|
-
case
|
|
268
|
-
case
|
|
269
|
-
case
|
|
270
|
-
case
|
|
271
|
-
case
|
|
272
|
-
case
|
|
273
|
-
case
|
|
258
|
+
case 304 /* SyntaxKind.PropertyAssignment */:
|
|
259
|
+
case 305 /* SyntaxKind.ShorthandPropertyAssignment */:
|
|
260
|
+
case 264 /* SyntaxKind.FunctionDeclaration */:
|
|
261
|
+
case 178 /* SyntaxKind.Constructor */:
|
|
262
|
+
case 183 /* SyntaxKind.IndexSignature */:
|
|
263
|
+
case 177 /* SyntaxKind.ClassStaticBlockDeclaration */:
|
|
264
|
+
case 284 /* SyntaxKind.MissingDeclaration */:
|
|
265
|
+
case 245 /* SyntaxKind.VariableStatement */:
|
|
266
|
+
case 266 /* SyntaxKind.InterfaceDeclaration */:
|
|
267
|
+
case 267 /* SyntaxKind.TypeAliasDeclaration */:
|
|
268
|
+
case 268 /* SyntaxKind.EnumDeclaration */:
|
|
269
|
+
case 269 /* SyntaxKind.ModuleDeclaration */:
|
|
270
|
+
case 273 /* SyntaxKind.ImportEqualsDeclaration */:
|
|
271
|
+
case 274 /* SyntaxKind.ImportDeclaration */:
|
|
272
|
+
case 347 /* SyntaxKind.JSImportDeclaration */:
|
|
273
|
+
case 272 /* SyntaxKind.NamespaceExportDeclaration */:
|
|
274
|
+
case 280 /* SyntaxKind.ExportDeclaration */:
|
|
275
|
+
case 279 /* SyntaxKind.ExportAssignment */:
|
|
274
276
|
return true;
|
|
275
277
|
}
|
|
276
278
|
return false;
|
|
277
279
|
}
|
|
278
280
|
export function canHaveDecorators(node) {
|
|
279
281
|
switch (node.kind) {
|
|
280
|
-
case
|
|
281
|
-
case
|
|
282
|
-
case
|
|
283
|
-
case
|
|
284
|
-
case
|
|
285
|
-
case
|
|
286
|
-
case
|
|
282
|
+
case 171 /* SyntaxKind.Parameter */:
|
|
283
|
+
case 174 /* SyntaxKind.PropertyDeclaration */:
|
|
284
|
+
case 176 /* SyntaxKind.MethodDeclaration */:
|
|
285
|
+
case 179 /* SyntaxKind.GetAccessor */:
|
|
286
|
+
case 180 /* SyntaxKind.SetAccessor */:
|
|
287
|
+
case 233 /* SyntaxKind.ClassExpression */:
|
|
288
|
+
case 265 /* SyntaxKind.ClassDeclaration */:
|
|
287
289
|
return true;
|
|
288
290
|
}
|
|
289
291
|
return false;
|
|
@@ -307,11 +309,53 @@ export function tagNamesAreEquivalent(lhs, rhs) {
|
|
|
307
309
|
tagNamesAreEquivalent(lhs.expression, rhs.expression));
|
|
308
310
|
throw new Error('Unhandled case in tagNamesAreEquivalent');
|
|
309
311
|
}
|
|
312
|
+
/** Whether `node` is a JSDoc type expression or a type node in one. */
|
|
313
|
+
export function isJSDocTypeExpressionOrChild(node) {
|
|
314
|
+
if (node.kind === 309 /* SyntaxKind.JSDocTypeExpression */)
|
|
315
|
+
return true;
|
|
316
|
+
if ((node.flags & (4194304 /* NodeFlags.JSDoc */ | 8 /* NodeFlags.Reparsed */)) === 0)
|
|
317
|
+
return false;
|
|
318
|
+
for (let current = node; current !== undefined; current = current.parent)
|
|
319
|
+
if (isTypeNodeKind(current.kind))
|
|
320
|
+
return true;
|
|
321
|
+
return false;
|
|
322
|
+
}
|
|
323
|
+
/** The text of a JSDoc type with the leading whitespace and `*` of each line removed, and LF line breaks. */
|
|
324
|
+
export function normalizeJSDocTypeSourceText(text) {
|
|
325
|
+
let result = '';
|
|
326
|
+
let lineStart = 0;
|
|
327
|
+
let multiline = false;
|
|
328
|
+
for (let i = 0; i < text.length; i++) {
|
|
329
|
+
const ch = text.charCodeAt(i);
|
|
330
|
+
if (!isLineBreak(ch))
|
|
331
|
+
continue;
|
|
332
|
+
result += stripLeadingJSDocComment(text.substring(lineStart, i)) + '\n';
|
|
333
|
+
multiline = true;
|
|
334
|
+
if (ch === 13 /* CharacterCodes.carriageReturn */ && text.charCodeAt(i + 1) === 10 /* CharacterCodes.lineFeed */)
|
|
335
|
+
i++;
|
|
336
|
+
lineStart = i + 1;
|
|
337
|
+
}
|
|
338
|
+
if (!multiline)
|
|
339
|
+
return stripLeadingJSDocComment(text);
|
|
340
|
+
return result + stripLeadingJSDocComment(text.substring(lineStart));
|
|
341
|
+
}
|
|
342
|
+
function stripLeadingJSDocComment(line) {
|
|
343
|
+
let start = 0;
|
|
344
|
+
while (start < line.length && isWhiteSpaceLike(line.charCodeAt(start)))
|
|
345
|
+
start++;
|
|
346
|
+
if (start < line.length && line.charCodeAt(start) === 42 /* CharacterCodes.asterisk */)
|
|
347
|
+
start++;
|
|
348
|
+
while (start < line.length && isWhiteSpaceLike(line.charCodeAt(start)))
|
|
349
|
+
start++;
|
|
350
|
+
return start === 0 ? line : line.substring(start);
|
|
351
|
+
}
|
|
310
352
|
/** The source text of a node, without leading trivia. */
|
|
311
353
|
export function getTextOfNodeFromSourceText(sourceText, node) {
|
|
312
354
|
if (nodeIsMissing(node))
|
|
313
355
|
return '';
|
|
314
|
-
|
|
356
|
+
let text = sourceText.substring(skipTrivia(sourceText, node.pos), node.end);
|
|
357
|
+
if (isJSDocTypeExpressionOrChild(node))
|
|
358
|
+
text = normalizeJSDocTypeSourceText(text);
|
|
315
359
|
if ((node.flags & 268435456 /* NodeFlags.ReparserTransformedLiteral */) !== 0) {
|
|
316
360
|
if (node instanceof StringLiteral)
|
|
317
361
|
return (node.tokenFlags & 65536 /* TokenFlags.SingleQuote */) !== 0 ? "'" + text + "'" : '"' + text + '"';
|
|
@@ -326,17 +370,39 @@ export function isImportMeta(node) {
|
|
|
326
370
|
node.keywordToken === 101 /* SyntaxKind.ImportKeyword */ &&
|
|
327
371
|
node.name.text === 'meta');
|
|
328
372
|
}
|
|
329
|
-
/** `import(…)` or `import.
|
|
373
|
+
/** `import(…)`, `import.defer(…)` or `import.source(…)`. */
|
|
330
374
|
export function isImportCall(node) {
|
|
331
375
|
if (!(node instanceof CallExpression))
|
|
332
376
|
return false;
|
|
333
377
|
const e = node.expression;
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
378
|
+
return e.kind === 101 /* SyntaxKind.ImportKeyword */ || isImportPhaseMetaProperty(e);
|
|
379
|
+
}
|
|
380
|
+
/** `import.defer` or `import.source`. */
|
|
381
|
+
export function isImportPhaseMetaProperty(node) {
|
|
382
|
+
return isImportMetaPropertyNamed(node, 'defer') || isImportMetaPropertyNamed(node, 'source');
|
|
383
|
+
}
|
|
384
|
+
export function isImportDeferMetaProperty(node) {
|
|
385
|
+
return isImportMetaPropertyNamed(node, 'defer');
|
|
386
|
+
}
|
|
387
|
+
export function isImportSourceMetaProperty(node) {
|
|
388
|
+
return isImportMetaPropertyNamed(node, 'source');
|
|
389
|
+
}
|
|
390
|
+
function isImportMetaPropertyNamed(node, name) {
|
|
391
|
+
return (node instanceof MetaProperty &&
|
|
392
|
+
node.keywordToken === 101 /* SyntaxKind.ImportKeyword */ &&
|
|
393
|
+
node.name.text === name);
|
|
394
|
+
}
|
|
395
|
+
/** `import source x from "m"` or `import.source("m")`. */
|
|
396
|
+
export function isSourcePhaseImport(node) {
|
|
397
|
+
if (node instanceof ImportDeclaration) {
|
|
398
|
+
const clause = node.importClause;
|
|
399
|
+
return clause !== undefined && clause.phaseModifier === 167 /* SyntaxKind.SourceKeyword */;
|
|
400
|
+
}
|
|
401
|
+
return isSourcePhaseImportCall(node);
|
|
402
|
+
}
|
|
403
|
+
/** `import.source(…)`. */
|
|
404
|
+
export function isSourcePhaseImportCall(node) {
|
|
405
|
+
return node instanceof CallExpression && isImportSourceMetaProperty(node.expression);
|
|
340
406
|
}
|
|
341
407
|
/** `require(x)` with one argument, a string literal if `requireStringLiteralLikeArgument`. */
|
|
342
408
|
export function isRequireCall(node, requireStringLiteralLikeArgument) {
|
|
@@ -365,36 +431,36 @@ export function isLiteralImportTypeNode(node) {
|
|
|
365
431
|
}
|
|
366
432
|
export function isAnyImportOrReExport(node) {
|
|
367
433
|
switch (node.kind) {
|
|
368
|
-
case
|
|
369
|
-
case
|
|
370
|
-
case
|
|
371
|
-
case
|
|
434
|
+
case 274 /* SyntaxKind.ImportDeclaration */:
|
|
435
|
+
case 273 /* SyntaxKind.ImportEqualsDeclaration */:
|
|
436
|
+
case 347 /* SyntaxKind.JSImportDeclaration */:
|
|
437
|
+
case 280 /* SyntaxKind.ExportDeclaration */:
|
|
372
438
|
return true;
|
|
373
439
|
}
|
|
374
440
|
return false;
|
|
375
441
|
}
|
|
376
442
|
export function getExternalModuleName(node) {
|
|
377
443
|
switch (node.kind) {
|
|
378
|
-
case
|
|
379
|
-
case
|
|
380
|
-
case
|
|
444
|
+
case 274 /* SyntaxKind.ImportDeclaration */:
|
|
445
|
+
case 347 /* SyntaxKind.JSImportDeclaration */:
|
|
446
|
+
case 280 /* SyntaxKind.ExportDeclaration */:
|
|
381
447
|
return getModuleSpecifier(node);
|
|
382
|
-
case
|
|
448
|
+
case 273 /* SyntaxKind.ImportEqualsDeclaration */:
|
|
383
449
|
if (node instanceof ImportEqualsDeclaration) {
|
|
384
450
|
const reference = node.moduleReference;
|
|
385
451
|
if (reference instanceof ExternalModuleReference)
|
|
386
452
|
return reference.expression;
|
|
387
453
|
}
|
|
388
454
|
return undefined;
|
|
389
|
-
case
|
|
455
|
+
case 207 /* SyntaxKind.ImportType */:
|
|
390
456
|
return getImportTypeNodeLiteral(node);
|
|
391
|
-
case
|
|
457
|
+
case 215 /* SyntaxKind.CallExpression */:
|
|
392
458
|
if (node instanceof CallExpression) {
|
|
393
459
|
const args = node.arguments.nodes;
|
|
394
460
|
return args.length > 0 ? args[0] : undefined;
|
|
395
461
|
}
|
|
396
462
|
return undefined;
|
|
397
|
-
case
|
|
463
|
+
case 269 /* SyntaxKind.ModuleDeclaration */:
|
|
398
464
|
if (node instanceof ModuleDeclaration) {
|
|
399
465
|
const name = node.name;
|
|
400
466
|
if (name.kind === 10 /* SyntaxKind.StringLiteral */)
|
|
@@ -409,24 +475,25 @@ export function isGlobalScopeAugmentation(node) {
|
|
|
409
475
|
}
|
|
410
476
|
/** Whether a node is written type-only: an `import type` clause, or a `type` specifier, import or export. */
|
|
411
477
|
export function isTypeOnly(node) {
|
|
412
|
-
if (node.kind ===
|
|
478
|
+
if (node.kind === 275 /* SyntaxKind.ImportClause */)
|
|
413
479
|
return node.phaseModifier === 156 /* SyntaxKind.TypeKeyword */;
|
|
414
480
|
return getIsTypeOnly(node);
|
|
415
481
|
}
|
|
416
482
|
/** Whether a declaration declares only a type. */
|
|
417
483
|
export function isTypeDeclaration(node) {
|
|
418
484
|
switch (node.kind) {
|
|
419
|
-
case
|
|
420
|
-
case
|
|
421
|
-
case
|
|
422
|
-
case
|
|
423
|
-
case
|
|
424
|
-
case
|
|
485
|
+
case 170 /* SyntaxKind.TypeParameter */:
|
|
486
|
+
case 265 /* SyntaxKind.ClassDeclaration */:
|
|
487
|
+
case 266 /* SyntaxKind.InterfaceDeclaration */:
|
|
488
|
+
case 267 /* SyntaxKind.TypeAliasDeclaration */:
|
|
489
|
+
case 346 /* SyntaxKind.JSTypeAliasDeclaration */:
|
|
490
|
+
case 268 /* SyntaxKind.EnumDeclaration */:
|
|
425
491
|
return true;
|
|
426
|
-
case
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
case
|
|
492
|
+
case 275 /* SyntaxKind.ImportClause */:
|
|
493
|
+
// `import type { a } from "m"` declares no type of its own.
|
|
494
|
+
return isTypeOnly(node) && node.name !== undefined;
|
|
495
|
+
case 278 /* SyntaxKind.ImportSpecifier */:
|
|
496
|
+
case 283 /* SyntaxKind.ExportSpecifier */:
|
|
430
497
|
return isTypeOnly(node.parent.parent);
|
|
431
498
|
}
|
|
432
499
|
return false;
|
|
@@ -439,10 +506,10 @@ export function isAmbientModule(node) {
|
|
|
439
506
|
}
|
|
440
507
|
/** Whether `node` is a JavaScript `/** @type {T} *\/ (x)` cast, reparsed as a parenthesized `as` expression. */
|
|
441
508
|
export function isJSDocTypeAssertion(node) {
|
|
442
|
-
if (node.kind !==
|
|
509
|
+
if (node.kind !== 219 /* SyntaxKind.ParenthesizedExpression */ || !isInJSFile(node))
|
|
443
510
|
return false;
|
|
444
511
|
const expression = getExpression(node);
|
|
445
|
-
if (expression === undefined || expression.kind !==
|
|
512
|
+
if (expression === undefined || expression.kind !== 236 /* SyntaxKind.AsExpression */)
|
|
446
513
|
return false;
|
|
447
514
|
const type = getType(expression);
|
|
448
515
|
return type !== undefined && (type.flags & 8 /* NodeFlags.Reparsed */) !== 0;
|
|
@@ -452,11 +519,29 @@ export function getEffectiveCheckNode(argument) {
|
|
|
452
519
|
const inJS = isInJSFile(argument);
|
|
453
520
|
let node = argument;
|
|
454
521
|
for (;;) {
|
|
455
|
-
if (node.kind ===
|
|
522
|
+
if (node.kind === 219 /* SyntaxKind.ParenthesizedExpression */ && !(inJS && isJSDocTypeAssertion(node)))
|
|
456
523
|
node = getExpression(node);
|
|
457
|
-
else if (node.kind ===
|
|
524
|
+
else if (node.kind === 240 /* SyntaxKind.SatisfiesExpression */)
|
|
458
525
|
node = getExpression(node);
|
|
459
526
|
else
|
|
460
527
|
return node;
|
|
461
528
|
}
|
|
462
529
|
}
|
|
530
|
+
/** The entity name of a heritage clause element: a type reference's type name, or an
|
|
531
|
+
* `ExpressionWithTypeArguments`'s expression. */
|
|
532
|
+
export function getHeritageClauseElementName(node) {
|
|
533
|
+
if (node.kind === 185 /* SyntaxKind.TypeReference */)
|
|
534
|
+
return node.typeName;
|
|
535
|
+
return getExpression(node);
|
|
536
|
+
}
|
|
537
|
+
/** Whether a name, or the rightmost name of a qualified name, is the type name of a type reference in a
|
|
538
|
+
* heritage clause. */
|
|
539
|
+
export function isNameOfHeritageClauseTypeReference(nodeIn) {
|
|
540
|
+
let node = nodeIn;
|
|
541
|
+
while (node.parent.kind === 168 /* SyntaxKind.QualifiedName */)
|
|
542
|
+
node = node.parent;
|
|
543
|
+
const parent = node.parent;
|
|
544
|
+
return (parent.kind === 185 /* SyntaxKind.TypeReference */ &&
|
|
545
|
+
parent.typeName === node &&
|
|
546
|
+
parent.parent?.kind === 300 /* SyntaxKind.HeritageClause */);
|
|
547
|
+
}
|