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
|
@@ -39,16 +39,6 @@ export declare class IterationTypes {
|
|
|
39
39
|
hasTypes(): boolean;
|
|
40
40
|
getType(kind: IterationTypeKind): Type | undefined;
|
|
41
41
|
}
|
|
42
|
-
/** A not-iterable error, reported once the file is checked so printing its type can't recurse. */
|
|
43
|
-
export declare class DeferredIterationError {
|
|
44
|
-
readonly errorNode: Node;
|
|
45
|
-
readonly type: Type;
|
|
46
|
-
readonly allowAsyncIterables: boolean;
|
|
47
|
-
readonly related: Diagnostic[];
|
|
48
|
-
constructor(errorNode: Node, type: Type, allowAsyncIterables: boolean, related: Diagnostic[]);
|
|
49
|
-
}
|
|
50
|
-
/** Reports the not-iterable errors deferred while checking a file. */
|
|
51
|
-
export declare function produceDeferredIterationErrors(c: Checker): void;
|
|
52
42
|
export declare function getGlobalIteratorType(c: Checker, isAsync: boolean): Type;
|
|
53
43
|
export declare function getGlobalIterableType(c: Checker, isAsync: boolean): Type;
|
|
54
44
|
export declare function getGlobalIterableIteratorType(c: Checker, isAsync: boolean): Type;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// promised types.
|
|
4
4
|
import { getExpression } from './ast.js';
|
|
5
5
|
import { createDiagnosticForNode } from './checker.js';
|
|
6
|
-
import { cachedTypeKey, } from './checker-types.js';
|
|
6
|
+
import { cachedTypeKey, getMappedType, } from './checker-types.js';
|
|
7
7
|
import { createTypeFromGenericGlobalType, createTypeReference, filterType, getIntersectionType, getTypeArguments, getUnionType, getUnionTypeEx, isEmptyObjectType, mapType, someType, typesOf, } from './checker-type-factory.js';
|
|
8
8
|
import { getBaseConstraintOfType, getBaseConstraintOrType, getIndexTypeOfType, getPropertyOfType, getReducedType, getSignaturesOfType, getTypeOfPropertyOfType, isArrayLikeType, } from './checker-members.js';
|
|
9
9
|
import { getTypeOfSymbol } from './checker-symbol-types.js';
|
|
@@ -45,30 +45,13 @@ function noIterationTypes() {
|
|
|
45
45
|
function anyIterationTypes(c) {
|
|
46
46
|
return new IterationTypes(c.anyType, c.anyType, c.anyType);
|
|
47
47
|
}
|
|
48
|
-
/**
|
|
49
|
-
|
|
50
|
-
errorNode
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
related;
|
|
54
|
-
constructor(errorNode, type, allowAsyncIterables, related) {
|
|
55
|
-
this.errorNode = errorNode;
|
|
56
|
-
this.type = type;
|
|
57
|
-
this.allowAsyncIterables = allowAsyncIterables;
|
|
58
|
-
this.related = related;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
/** Reports the not-iterable errors deferred while checking a file. */
|
|
62
|
-
export function produceDeferredIterationErrors(c) {
|
|
63
|
-
const errors = c.deferredIterationErrors;
|
|
64
|
-
if (errors.length === 0)
|
|
65
|
-
return;
|
|
66
|
-
c.deferredIterationErrors = [];
|
|
67
|
-
for (const e of errors) {
|
|
68
|
-
const diagnostic = reportTypeNotIterableError(c, e.errorNode, e.type, e.allowAsyncIterables);
|
|
69
|
-
for (const d of e.related)
|
|
48
|
+
/** Defers a not-iterable error, so printing its type can't resolve types that are being resolved. */
|
|
49
|
+
function deferTypeNotIterableError(c, errorNode, t, allowAsyncIterables, related) {
|
|
50
|
+
c.deferDiagnostic(errorNode, () => {
|
|
51
|
+
const diagnostic = reportTypeNotIterableError(c, errorNode, t, allowAsyncIterables);
|
|
52
|
+
for (const d of related)
|
|
70
53
|
diagnostic.addRelatedInfo(d);
|
|
71
|
-
}
|
|
54
|
+
});
|
|
72
55
|
}
|
|
73
56
|
// ---- Global types
|
|
74
57
|
export function getGlobalIteratorType(c, isAsync) {
|
|
@@ -160,16 +143,16 @@ export function getIteratedTypeOrElementType(c, use, inputType, sentType, errorN
|
|
|
160
143
|
let diagnostic;
|
|
161
144
|
if ((use & 8 /* IterationUse.ForOfFlag */) !== 0)
|
|
162
145
|
diagnostic =
|
|
163
|
-
|
|
146
|
+
902 /* Diagnostics.Cannot_iterate_value_because_the_next_method_of_its_iterator_expects_type_1_but_for_of_will_always_send_0 */;
|
|
164
147
|
else if ((use & 32 /* IterationUse.SpreadFlag */) !== 0)
|
|
165
148
|
diagnostic =
|
|
166
|
-
|
|
149
|
+
903 /* Diagnostics.Cannot_iterate_value_because_the_next_method_of_its_iterator_expects_type_1_but_array_spread_will_always_send_0 */;
|
|
167
150
|
else if ((use & 64 /* IterationUse.DestructuringFlag */) !== 0)
|
|
168
151
|
diagnostic =
|
|
169
|
-
|
|
152
|
+
904 /* Diagnostics.Cannot_iterate_value_because_the_next_method_of_its_iterator_expects_type_1_but_array_destructuring_will_always_send_0 */;
|
|
170
153
|
else if ((use & 16 /* IterationUse.YieldStarFlag */) !== 0)
|
|
171
154
|
diagnostic =
|
|
172
|
-
|
|
155
|
+
905 /* Diagnostics.Cannot_delegate_iteration_to_value_because_the_next_method_of_its_iterator_expects_type_1_but_the_containing_generator_will_always_send_0 */;
|
|
173
156
|
if (diagnostic !== undefined)
|
|
174
157
|
checkTypeRelatedTo(c, sentType, iterationTypes.nextType, c.assignableRelation, errorNode, diagnostic, undefined);
|
|
175
158
|
}
|
|
@@ -235,12 +218,12 @@ class IterationDiagnosticDetails {
|
|
|
235
218
|
}
|
|
236
219
|
}
|
|
237
220
|
function getIterationDiagnosticDetails(c, use, inputType, allowsStrings) {
|
|
238
|
-
const downlevel =
|
|
221
|
+
const downlevel = 941 /* Diagnostics.Type_0_can_only_be_iterated_through_when_using_the_downlevelIteration_flag_or_with_a_target_of_es2015_or_higher */;
|
|
239
222
|
if (getIterationTypeOfIterable(c, use, 0 /* IterationTypeKind.Yield */, inputType, undefined) !== undefined)
|
|
240
223
|
return new IterationDiagnosticDetails(downlevel, false);
|
|
241
224
|
if (inputType.symbol !== undefined && isES2015OrLaterIterable(inputType.symbol.name))
|
|
242
225
|
return new IterationDiagnosticDetails(downlevel, true);
|
|
243
|
-
return new IterationDiagnosticDetails(allowsStrings ?
|
|
226
|
+
return new IterationDiagnosticDetails(allowsStrings ? 662 /* Diagnostics.Type_0_is_not_an_array_type_or_a_string_type */ : 634 /* Diagnostics.Type_0_is_not_an_array_type */, true);
|
|
244
227
|
}
|
|
245
228
|
function isES2015OrLaterIterable(name) {
|
|
246
229
|
switch (name) {
|
|
@@ -260,13 +243,13 @@ function isES2015OrLaterIterable(name) {
|
|
|
260
243
|
}
|
|
261
244
|
function reportTypeNotIterableError(c, errorNode, t, allowAsyncIterables) {
|
|
262
245
|
const message = allowAsyncIterables
|
|
263
|
-
?
|
|
264
|
-
:
|
|
246
|
+
? 671 /* Diagnostics.Type_0_must_have_a_Symbol_asyncIterator_method_that_returns_an_async_iterator */
|
|
247
|
+
: 655 /* Diagnostics.Type_0_must_have_a_Symbol_iterator_method_that_returns_an_iterator */;
|
|
265
248
|
const parent = errorNode.parent;
|
|
266
249
|
const suggestAwait = getAwaitedTypeOfPromise(c, t) !== undefined ||
|
|
267
250
|
(!allowAsyncIterables &&
|
|
268
251
|
parent !== undefined &&
|
|
269
|
-
parent.kind ===
|
|
252
|
+
parent.kind === 252 /* SyntaxKind.ForOfStatement */ &&
|
|
270
253
|
getExpression(parent) === errorNode &&
|
|
271
254
|
getGlobalIterableType(c, true) !== c.emptyGenericType &&
|
|
272
255
|
isTypeAssignableTo(c, t, createTypeFromGenericGlobalType(c, getGlobalIterableType(c, true), [c.anyType, c.anyType, c.anyType])));
|
|
@@ -312,8 +295,8 @@ function getIterationTypesOfIterableWorker(c, t, use, errorNode) {
|
|
|
312
295
|
for (const constituent of typesOf(t)) {
|
|
313
296
|
const iterationTypes = getIterationTypesOfIterableWorker(c, constituent, use, undefined);
|
|
314
297
|
if (!iterationTypes.hasTypes()) {
|
|
315
|
-
if (errorNode !== undefined
|
|
316
|
-
c
|
|
298
|
+
if (errorNode !== undefined)
|
|
299
|
+
deferTypeNotIterableError(c, errorNode, t, allowAsync, []);
|
|
317
300
|
return noIterationTypes();
|
|
318
301
|
}
|
|
319
302
|
all.push(iterationTypes);
|
|
@@ -345,8 +328,8 @@ function getIterationTypesOfIterableWorker(c, t, use, errorNode) {
|
|
|
345
328
|
return allowAsync ? getAsyncFromSyncIterationTypes(c, iterationTypes, errorNode) : iterationTypes;
|
|
346
329
|
}
|
|
347
330
|
}
|
|
348
|
-
if (errorNode !== undefined
|
|
349
|
-
c
|
|
331
|
+
if (errorNode !== undefined)
|
|
332
|
+
deferTypeNotIterableError(c, errorNode, t, allowAsync, diagnostics);
|
|
350
333
|
return noIterationTypes();
|
|
351
334
|
}
|
|
352
335
|
/** Reads the iteration types of references to the global iterable types from their type arguments. */
|
|
@@ -459,11 +442,11 @@ function getIterationTypesOfMethod(c, t, isAsync, methodName, errorNode, diagnos
|
|
|
459
442
|
if (errorNode !== undefined) {
|
|
460
443
|
const message = methodName === 'next'
|
|
461
444
|
? isAsync
|
|
462
|
-
?
|
|
463
|
-
:
|
|
445
|
+
? 686 /* Diagnostics.An_async_iterator_must_have_a_next_method */
|
|
446
|
+
: 656 /* Diagnostics.An_iterator_must_have_a_next_method */
|
|
464
447
|
: isAsync
|
|
465
|
-
?
|
|
466
|
-
:
|
|
448
|
+
? 907 /* Diagnostics.The_0_property_of_an_async_iterator_must_be_a_method */
|
|
449
|
+
: 906 /* Diagnostics.The_0_property_of_an_iterator_must_be_a_method */;
|
|
467
450
|
reportDiagnostic(c, createDiagnosticForNode(errorNode, message, [methodName]), diagnosticOutput);
|
|
468
451
|
}
|
|
469
452
|
return noIterationTypes();
|
|
@@ -483,7 +466,7 @@ function getIterationTypesOfMethod(c, t, isAsync, methodName, errorNode, diagnos
|
|
|
483
466
|
const typeParameters = (isGeneratorMethod ? globalGeneratorType : globalIteratorType).typeParameters();
|
|
484
467
|
const mapper = methodType.mapper;
|
|
485
468
|
if (mapper !== undefined)
|
|
486
|
-
return new IterationTypes(
|
|
469
|
+
return new IterationTypes(getMappedType(typeParameters[0], mapper), getMappedType(typeParameters[1], mapper), methodName === 'next' ? getMappedType(typeParameters[2], mapper) : undefined);
|
|
487
470
|
}
|
|
488
471
|
}
|
|
489
472
|
// The first parameter and return type of each signature.
|
|
@@ -513,8 +496,8 @@ function getIterationTypesOfMethod(c, t, isAsync, methodName, errorNode, diagnos
|
|
|
513
496
|
if (!iterationTypes.hasTypes()) {
|
|
514
497
|
if (errorNode !== undefined)
|
|
515
498
|
reportDiagnostic(c, createDiagnosticForNode(errorNode, isAsync
|
|
516
|
-
?
|
|
517
|
-
:
|
|
499
|
+
? 709 /* Diagnostics.The_type_returned_by_the_0_method_of_an_async_iterator_must_be_a_promise_for_a_type_with_a_value_property */
|
|
500
|
+
: 657 /* Diagnostics.The_type_returned_by_the_0_method_of_an_iterator_must_have_a_value_property */, [methodName]), diagnosticOutput);
|
|
518
501
|
yieldType = c.anyType;
|
|
519
502
|
returnTypes.push(c.anyType);
|
|
520
503
|
}
|
|
@@ -676,7 +659,7 @@ export function getAwaitedTypeNoAliasEx(c, t, errorNode, message) {
|
|
|
676
659
|
if (errorNode !== undefined && message !== undefined) {
|
|
677
660
|
let chain;
|
|
678
661
|
if (promised.thisTypeForError !== undefined)
|
|
679
|
-
chain = createDiagnosticForNode(errorNode,
|
|
662
|
+
chain = createDiagnosticForNode(errorNode, 824 /* Diagnostics.The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1 */, [typeToString(c, t), typeToString(c, promised.thisTypeForError)]);
|
|
680
663
|
const diagnostic = createDiagnosticForNode(errorNode, message, []);
|
|
681
664
|
if (chain !== undefined) {
|
|
682
665
|
diagnostic.addMessageChain(chain);
|
|
@@ -799,7 +782,7 @@ function getPromisedTypeOfPromiseWorker(c, t, errorNode) {
|
|
|
799
782
|
}
|
|
800
783
|
if (candidates.length === 0) {
|
|
801
784
|
if (errorNode !== undefined)
|
|
802
|
-
c.error(errorNode,
|
|
785
|
+
c.error(errorNode, 824 /* Diagnostics.The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1 */, typeToString(c, t), typeToString(c, thisTypeForError));
|
|
803
786
|
return new PromisedType(undefined, thisTypeForError);
|
|
804
787
|
}
|
|
805
788
|
const onfulfilledParameterType = getTypeWithFacts(c, getUnionType(c, getTypesOfFirstParameterOfSignatures(c, candidates)), 2097152 /* TypeFacts.NEUndefinedOrNull */);
|
|
@@ -844,14 +827,14 @@ export function createPromiseLikeType(c, promisedType) {
|
|
|
844
827
|
export function createPromiseReturnType(c, func, promisedType) {
|
|
845
828
|
const promiseType = createPromiseType(c, promisedType);
|
|
846
829
|
if (promiseType === c.unknownType) {
|
|
847
|
-
c.error(func, func.kind ===
|
|
848
|
-
?
|
|
849
|
-
:
|
|
830
|
+
c.error(func, func.kind === 215 /* SyntaxKind.CallExpression */
|
|
831
|
+
? 850 /* Diagnostics.A_dynamic_import_call_returns_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option */
|
|
832
|
+
: 836 /* Diagnostics.An_async_function_or_method_must_return_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option */);
|
|
850
833
|
return c.errorType;
|
|
851
834
|
}
|
|
852
835
|
if (getGlobalValueSymbol(c, 'Promise', true) === undefined)
|
|
853
|
-
c.error(func, func.kind ===
|
|
854
|
-
?
|
|
855
|
-
:
|
|
836
|
+
c.error(func, func.kind === 215 /* SyntaxKind.CallExpression */
|
|
837
|
+
? 851 /* Diagnostics.A_dynamic_import_call_in_ES5_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option */
|
|
838
|
+
: 844 /* Diagnostics.An_async_function_or_method_in_ES5_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option */);
|
|
856
839
|
return promiseType;
|
|
857
840
|
}
|
|
@@ -100,7 +100,7 @@ function getAssignmentDeclarationInitializerType(c, node) {
|
|
|
100
100
|
}
|
|
101
101
|
return t;
|
|
102
102
|
}
|
|
103
|
-
if (node.kind ===
|
|
103
|
+
if (node.kind === 215 /* SyntaxKind.CallExpression */)
|
|
104
104
|
return getTypeFromPropertyDescriptor(c, getArguments(node).nodes[2]);
|
|
105
105
|
return undefined;
|
|
106
106
|
}
|
|
@@ -116,7 +116,7 @@ function hasParentWithTypeAnnotation(c, symbol) {
|
|
|
116
116
|
if (parent === undefined || parent.valueDeclaration === undefined)
|
|
117
117
|
return false;
|
|
118
118
|
const kind = parent.valueDeclaration.kind;
|
|
119
|
-
if (kind !==
|
|
119
|
+
if (kind !== 220 /* SyntaxKind.FunctionExpression */ && kind !== 221 /* SyntaxKind.ArrowFunction */)
|
|
120
120
|
return false;
|
|
121
121
|
const annotated = getSymbolOfDeclaration(c, parent.valueDeclaration.parent);
|
|
122
122
|
return (annotated !== undefined &&
|
|
@@ -178,7 +178,7 @@ function getThisAssignmentKind(c, symbol) {
|
|
|
178
178
|
}
|
|
179
179
|
const left = declaration.left;
|
|
180
180
|
if (getAssignmentDeclarationKind(declaration) === 3 /* JSDeclarationKind.ThisProperty */ &&
|
|
181
|
-
(left.kind !==
|
|
181
|
+
(left.kind !== 214 /* SyntaxKind.ElementAccessExpression */ || isStringOrNumericLiteralLike(getArgumentExpression(left)))) {
|
|
182
182
|
if (declaration.type !== undefined)
|
|
183
183
|
typeAnnotation = declaration.type;
|
|
184
184
|
}
|
|
@@ -213,7 +213,7 @@ export function isConstructorDeclaredThisProperty(c, symbol) {
|
|
|
213
213
|
function getDeclaringConstructor(symbol) {
|
|
214
214
|
for (const declaration of getDeclarations(symbol)) {
|
|
215
215
|
const container = getThisContainer(declaration, false, false);
|
|
216
|
-
if (container.kind ===
|
|
216
|
+
if (container.kind === 178 /* SyntaxKind.Constructor */)
|
|
217
217
|
return container;
|
|
218
218
|
}
|
|
219
219
|
return undefined;
|
|
@@ -243,7 +243,7 @@ export function getFlowTypeOfAutoTypedProperty(c, reference, prop) {
|
|
|
243
243
|
/** The leftmost expression of a property access, element access or call chain. */
|
|
244
244
|
function getLeftmostAccessExpression(node) {
|
|
245
245
|
let current = node;
|
|
246
|
-
while (isAccessExpression(current) || current.kind ===
|
|
246
|
+
while (isAccessExpression(current) || current.kind === 215 /* SyntaxKind.CallExpression */)
|
|
247
247
|
current = getExpression(current);
|
|
248
248
|
return current;
|
|
249
249
|
}
|
|
@@ -267,7 +267,7 @@ export function getContextualTypeForAssignmentExpression(c, binary) {
|
|
|
267
267
|
break;
|
|
268
268
|
// `F.id = expr` takes a contextual type only from an annotated variable F.
|
|
269
269
|
const declaration = symbol.valueDeclaration;
|
|
270
|
-
if (declaration === undefined || declaration.kind !==
|
|
270
|
+
if (declaration === undefined || declaration.kind !== 262 /* SyntaxKind.VariableDeclaration */)
|
|
271
271
|
return undefined;
|
|
272
272
|
const typeNode = getType(declaration);
|
|
273
273
|
if (typeNode === undefined)
|
|
@@ -279,8 +279,8 @@ export function getContextualTypeForAssignmentExpression(c, binary) {
|
|
|
279
279
|
return getTypeOfPropertyOfContextualType(c, getTypeFromTypeNode(c, typeNode), getPropertyNameFromType(nameType));
|
|
280
280
|
return getTypeOfExpression(c, left);
|
|
281
281
|
}
|
|
282
|
-
case
|
|
283
|
-
case
|
|
282
|
+
case 213 /* SyntaxKind.PropertyAccessExpression */:
|
|
283
|
+
case 214 /* SyntaxKind.ElementAccessExpression */:
|
|
284
284
|
if (binary.symbol !== undefined)
|
|
285
285
|
return undefined;
|
|
286
286
|
break;
|
|
@@ -304,7 +304,7 @@ export function getContextualTypeForAssignmentExpression(c, binary) {
|
|
|
304
304
|
const d = symbol?.valueDeclaration;
|
|
305
305
|
// `this.x = expr` where x is a property with no type annotation or initializer.
|
|
306
306
|
if (d !== undefined &&
|
|
307
|
-
(d.kind ===
|
|
307
|
+
(d.kind === 174 /* SyntaxKind.PropertyDeclaration */ || d.kind === 173 /* SyntaxKind.PropertySignature */) &&
|
|
308
308
|
getType(d) === undefined &&
|
|
309
309
|
getInitializer(d) === undefined)
|
|
310
310
|
return undefined;
|
|
@@ -332,9 +332,9 @@ export function isCommonJSRequire(c, node) {
|
|
|
332
332
|
return false;
|
|
333
333
|
let kind = 0 /* SyntaxKind.Unknown */;
|
|
334
334
|
if ((resolved.flags & 16 /* SymbolFlags.Function */) !== 0)
|
|
335
|
-
kind =
|
|
335
|
+
kind = 264 /* SyntaxKind.FunctionDeclaration */;
|
|
336
336
|
else if ((resolved.flags & 3 /* SymbolFlags.Variable */) !== 0)
|
|
337
|
-
kind =
|
|
337
|
+
kind = 262 /* SyntaxKind.VariableDeclaration */;
|
|
338
338
|
if (kind === 0 /* SyntaxKind.Unknown */)
|
|
339
339
|
return false;
|
|
340
340
|
const declaration = getDeclarationOfKind(resolved, kind);
|
|
@@ -342,7 +342,7 @@ export function isCommonJSRequire(c, node) {
|
|
|
342
342
|
}
|
|
343
343
|
/** The type of the module a `require("m")` call names. */
|
|
344
344
|
export function resolveExternalModuleTypeByLiteral(c, name) {
|
|
345
|
-
const moduleSymbol = resolveExternalModuleName(c, name, name, false);
|
|
345
|
+
const moduleSymbol = resolveExternalModuleName(c, name, name, false, undefined);
|
|
346
346
|
if (moduleSymbol !== undefined) {
|
|
347
347
|
const resolved = resolveExternalModuleSymbol(c, moduleSymbol, false);
|
|
348
348
|
if (resolved !== undefined)
|
|
@@ -352,7 +352,7 @@ export function resolveExternalModuleTypeByLiteral(c, name) {
|
|
|
352
352
|
}
|
|
353
353
|
/** Whether a JavaScript declaration declares an alias: a `require` or an exported entity name. */
|
|
354
354
|
export function isJSAliasDeclaration(node) {
|
|
355
|
-
if (node.kind !==
|
|
355
|
+
if (node.kind !== 228 /* SyntaxKind.BinaryExpression */)
|
|
356
356
|
return isVariableDeclarationInitializedToRequire(node);
|
|
357
357
|
const kind = getAssignmentDeclarationKind(node);
|
|
358
358
|
return ((kind === 1 /* JSDeclarationKind.ModuleExports */ || kind === 2 /* JSDeclarationKind.ExportsProperty */) &&
|
|
@@ -361,7 +361,7 @@ export function isJSAliasDeclaration(node) {
|
|
|
361
361
|
/** `this` in `obj.x = function () {}` is `obj`, except for CommonJS `exports.x = function () {}`. */
|
|
362
362
|
export function getThisTypeOfAssignedFunction(c, func) {
|
|
363
363
|
let parent = func.parent;
|
|
364
|
-
while (parent.kind ===
|
|
364
|
+
while (parent.kind === 219 /* SyntaxKind.ParenthesizedExpression */)
|
|
365
365
|
parent = parent.parent;
|
|
366
366
|
// Compound assignments like `??=` count too.
|
|
367
367
|
if (!(parent instanceof BinaryExpression) ||
|
|
@@ -11,6 +11,8 @@ export declare function getSignatureOfFullSignatureType(c: Checker, node: Node):
|
|
|
11
11
|
export declare function getParameterTypeOfFullSignature(c: Checker, fn: Node, parameter: Node): Type | undefined;
|
|
12
12
|
/** The return type of a function typed by a JSDoc `@type` tag. */
|
|
13
13
|
export declare function getReturnTypeOfFullSignature(c: Checker, fn: Node): Type | undefined;
|
|
14
|
+
/** Checks the type of a JSDoc `@type` on a function as a type node. */
|
|
15
|
+
export declare function checkJSDocFullSignatureType(c: Checker, fn: Node): void;
|
|
14
16
|
/** A JSDoc `@type` on a function needs a call signature taking at least its parameters. */
|
|
15
17
|
export declare function checkJSDocFullSignature(c: Checker, fn: Node): void;
|
|
16
18
|
/**
|
|
@@ -18,13 +20,9 @@ export declare function checkJSDocFullSignature(c: Checker, fn: Node): void;
|
|
|
18
20
|
* without a parent `@param {object}`.
|
|
19
21
|
*/
|
|
20
22
|
export declare function checkUnmatchedJSDocParameters(c: Checker, node: Node): void;
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
constructor(name: Node, tagName: string, className: string, extendsName: string);
|
|
28
|
-
}
|
|
29
|
-
/** The `@augments` or `@extends` tag of a class whose class name differs from its `extends` clause. */
|
|
30
|
-
export declare function findMismatchedAugmentsTag(classLike: Node, extendsType: ExpressionWithTypeArguments): AugmentsMismatch | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Reports an `@augments` or `@extends` tag of a JavaScript class whose class doesn't match the
|
|
25
|
+
* `extends` clause: for an entity name, a different type; for another expression, a type the base
|
|
26
|
+
* type isn't assignable to.
|
|
27
|
+
*/
|
|
28
|
+
export declare function checkJSDocAugmentsTagMatchesExtends(c: Checker, node: Node, baseTypeNode: ExpressionWithTypeArguments, baseType: Type): void;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// JSDoc semantics: the intended types of JSDoc type references like `String`, `function` and
|
|
2
2
|
// `Object<K, V>`, functions typed by a JSDoc `@type` tag, and `@param` tags without parameters.
|
|
3
3
|
import { ArrowFunction, FunctionDeclaration, FunctionExpression, MethodDeclaration, NodeVisitor, getBody, getDotDotDotToken, getExpression, getInitializer, getName, getParameters, getText, getType, } from './ast.js';
|
|
4
|
-
import { getSourceFileOfNode, isTypeNodeKind } from './binder-utilities.js';
|
|
4
|
+
import { getSourceFileOfNode, getSourceTextOfNode, isEntityNameExpression, isTypeNodeKind, } from './binder-utilities.js';
|
|
5
|
+
import { isTypeAssignableTo, isTypeIdenticalTo } from './relations.js';
|
|
5
6
|
import { getAttachedJSDoc, getJSDoc } from './parser.js';
|
|
6
7
|
import { isInJSFile } from './ast-utilities.js';
|
|
7
8
|
import { getGlobalTypeAliasSymbol } from './checker-symbols.js';
|
|
@@ -12,9 +13,10 @@ import { getRestTypeAtPosition, getReturnTypeOfSignature, getSingleCallSignature
|
|
|
12
13
|
import { getContextualCallSignature } from './checker-contextual.js';
|
|
13
14
|
import { entityNameToString, getResolvedSymbol } from './checker-expressions.js';
|
|
14
15
|
import { isArrayType } from './checker-type-factory.js';
|
|
16
|
+
import { checkSourceElement } from './checker-source-file.js';
|
|
15
17
|
/** The type a JSDoc type reference to a JavaScript-style name means, if it is one. */
|
|
16
18
|
export function getIntendedTypeFromJSDocTypeReference(c, node) {
|
|
17
|
-
if ((node.flags & 4194304 /* NodeFlags.JSDoc */) === 0 || node.kind !==
|
|
19
|
+
if ((node.flags & 4194304 /* NodeFlags.JSDoc */) === 0 || node.kind !== 185 /* SyntaxKind.TypeReference */)
|
|
18
20
|
return undefined;
|
|
19
21
|
const reference = node;
|
|
20
22
|
const typeName = reference.typeName;
|
|
@@ -108,13 +110,19 @@ export function getReturnTypeOfFullSignature(c, fn) {
|
|
|
108
110
|
const signature = getSignatureOfFullSignatureType(c, fn);
|
|
109
111
|
return signature !== undefined ? getReturnTypeOfSignature(c, signature) : undefined;
|
|
110
112
|
}
|
|
113
|
+
/** Checks the type of a JSDoc `@type` on a function as a type node. */
|
|
114
|
+
export function checkJSDocFullSignatureType(c, fn) {
|
|
115
|
+
const typeNode = getFullSignatureTypeNode(fn);
|
|
116
|
+
if (typeNode !== undefined)
|
|
117
|
+
checkSourceElement(c, typeNode);
|
|
118
|
+
}
|
|
111
119
|
/** A JSDoc `@type` on a function needs a call signature taking at least its parameters. */
|
|
112
120
|
export function checkJSDocFullSignature(c, fn) {
|
|
113
121
|
const typeNode = getFullSignatureTypeNode(fn);
|
|
114
122
|
if (typeNode === undefined)
|
|
115
123
|
return;
|
|
116
124
|
if (getContextualCallSignature(c, getTypeFromTypeNode(c, typeNode), fn) === undefined)
|
|
117
|
-
c.error(typeNode,
|
|
125
|
+
c.error(typeNode, 1779 /* Diagnostics.A_JSDoc_type_tag_on_a_function_must_have_a_signature_with_the_correct_number_of_arguments */);
|
|
118
126
|
}
|
|
119
127
|
// ---- `@param` tags
|
|
120
128
|
/** The tags of the last JSDoc comment of `node` or of the declaration or statement it heads. */
|
|
@@ -137,16 +145,16 @@ function getNextJSDocCommentLocation(node) {
|
|
|
137
145
|
if (parent === undefined)
|
|
138
146
|
return undefined;
|
|
139
147
|
switch (parent.kind) {
|
|
140
|
-
case
|
|
141
|
-
case
|
|
142
|
-
case
|
|
143
|
-
case
|
|
144
|
-
case
|
|
145
|
-
case
|
|
146
|
-
case
|
|
147
|
-
case
|
|
148
|
+
case 304 /* SyntaxKind.PropertyAssignment */:
|
|
149
|
+
case 279 /* SyntaxKind.ExportAssignment */:
|
|
150
|
+
case 174 /* SyntaxKind.PropertyDeclaration */:
|
|
151
|
+
case 262 /* SyntaxKind.VariableDeclaration */:
|
|
152
|
+
case 240 /* SyntaxKind.SatisfiesExpression */:
|
|
153
|
+
case 255 /* SyntaxKind.ReturnStatement */:
|
|
154
|
+
case 245 /* SyntaxKind.VariableStatement */:
|
|
155
|
+
case 246 /* SyntaxKind.ExpressionStatement */:
|
|
148
156
|
return parent;
|
|
149
|
-
case
|
|
157
|
+
case 263 /* SyntaxKind.VariableDeclarationList */:
|
|
150
158
|
return parent.declarations.nodes[0] === node ? parent : undefined;
|
|
151
159
|
}
|
|
152
160
|
return undefined;
|
|
@@ -164,7 +172,7 @@ export function checkUnmatchedJSDocParameters(c, node) {
|
|
|
164
172
|
return;
|
|
165
173
|
const jsdocParameters = [];
|
|
166
174
|
for (const tag of getAllJSDocTags(node)) {
|
|
167
|
-
if (tag.kind !==
|
|
175
|
+
if (tag.kind !== 334 /* SyntaxKind.JSDocParameterTag */)
|
|
168
176
|
continue;
|
|
169
177
|
const name = tag.name;
|
|
170
178
|
if (name.kind === 79 /* SyntaxKind.Identifier */ && getText(name).length === 0)
|
|
@@ -180,7 +188,7 @@ export function checkUnmatchedJSDocParameters(c, node) {
|
|
|
180
188
|
const name = getName(params[i]);
|
|
181
189
|
if (name.kind === 79 /* SyntaxKind.Identifier */)
|
|
182
190
|
parameters.add(getText(name));
|
|
183
|
-
if (name.kind ===
|
|
191
|
+
if (name.kind === 208 /* SyntaxKind.ObjectBindingPattern */ || name.kind === 209 /* SyntaxKind.ArrayBindingPattern */)
|
|
184
192
|
excludedParameters.add(i);
|
|
185
193
|
}
|
|
186
194
|
if (containsArgumentsReference(c, node)) {
|
|
@@ -196,7 +204,7 @@ export function checkUnmatchedJSDocParameters(c, node) {
|
|
|
196
204
|
const typeNode = typeExpression !== undefined ? getType(typeExpression) : undefined;
|
|
197
205
|
if (typeNode === undefined || isArrayType(c, getTypeFromTypeNode(c, typeNode)))
|
|
198
206
|
return;
|
|
199
|
-
c.error(last.name,
|
|
207
|
+
c.error(last.name, 1778 /* Diagnostics.JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name_It_would_match_arguments_if_it_had_an_array_type */, getText(last.name));
|
|
200
208
|
return;
|
|
201
209
|
}
|
|
202
210
|
if (!isJs)
|
|
@@ -206,10 +214,10 @@ export function checkUnmatchedJSDocParameters(c, node) {
|
|
|
206
214
|
const name = tag.name;
|
|
207
215
|
if (excludedParameters.has(index) || (name.kind === 79 /* SyntaxKind.Identifier */ && parameters.has(getText(name))))
|
|
208
216
|
continue;
|
|
209
|
-
if (name.kind ===
|
|
210
|
-
c.error(name,
|
|
217
|
+
if (name.kind === 168 /* SyntaxKind.QualifiedName */)
|
|
218
|
+
c.error(name, 1781 /* Diagnostics.Qualified_name_0_is_not_allowed_without_a_leading_param_object_1 */, entityNameToString(name), entityNameToString(name.left));
|
|
211
219
|
else if (!tag.isNameFirst)
|
|
212
|
-
c.error(name,
|
|
220
|
+
c.error(name, 1773 /* Diagnostics.JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name */, getText(name));
|
|
213
221
|
}
|
|
214
222
|
}
|
|
215
223
|
/** Finds a reference to `arguments` outside nested functions and types. */
|
|
@@ -223,19 +231,19 @@ class ArgumentsReferenceFinder extends NodeVisitor {
|
|
|
223
231
|
switch (node.kind) {
|
|
224
232
|
case 79 /* SyntaxKind.Identifier */:
|
|
225
233
|
return getText(node) === 'arguments' && getResolvedSymbol(this.c, node) === this.c.argumentsSymbol;
|
|
226
|
-
case
|
|
227
|
-
case
|
|
228
|
-
case
|
|
229
|
-
case
|
|
234
|
+
case 174 /* SyntaxKind.PropertyDeclaration */:
|
|
235
|
+
case 176 /* SyntaxKind.MethodDeclaration */:
|
|
236
|
+
case 179 /* SyntaxKind.GetAccessor */:
|
|
237
|
+
case 180 /* SyntaxKind.SetAccessor */: {
|
|
230
238
|
const name = getName(node);
|
|
231
|
-
if (name !== undefined && name.kind ===
|
|
239
|
+
if (name !== undefined && name.kind === 169 /* SyntaxKind.ComputedPropertyName */)
|
|
232
240
|
return this.visitNode(name);
|
|
233
241
|
break;
|
|
234
242
|
}
|
|
235
|
-
case
|
|
236
|
-
case
|
|
243
|
+
case 213 /* SyntaxKind.PropertyAccessExpression */:
|
|
244
|
+
case 214 /* SyntaxKind.ElementAccessExpression */:
|
|
237
245
|
return this.visitNode(getExpression(node));
|
|
238
|
-
case
|
|
246
|
+
case 304 /* SyntaxKind.PropertyAssignment */:
|
|
239
247
|
return this.visitNode(getInitializer(node));
|
|
240
248
|
}
|
|
241
249
|
if (startsNewLexicalEnvironment(node) || isTypeNodeKind(node.kind))
|
|
@@ -245,15 +253,15 @@ class ArgumentsReferenceFinder extends NodeVisitor {
|
|
|
245
253
|
}
|
|
246
254
|
function startsNewLexicalEnvironment(node) {
|
|
247
255
|
switch (node.kind) {
|
|
248
|
-
case
|
|
249
|
-
case
|
|
250
|
-
case
|
|
251
|
-
case
|
|
252
|
-
case
|
|
253
|
-
case
|
|
254
|
-
case
|
|
255
|
-
case
|
|
256
|
-
case
|
|
256
|
+
case 178 /* SyntaxKind.Constructor */:
|
|
257
|
+
case 220 /* SyntaxKind.FunctionExpression */:
|
|
258
|
+
case 264 /* SyntaxKind.FunctionDeclaration */:
|
|
259
|
+
case 221 /* SyntaxKind.ArrowFunction */:
|
|
260
|
+
case 176 /* SyntaxKind.MethodDeclaration */:
|
|
261
|
+
case 179 /* SyntaxKind.GetAccessor */:
|
|
262
|
+
case 180 /* SyntaxKind.SetAccessor */:
|
|
263
|
+
case 269 /* SyntaxKind.ModuleDeclaration */:
|
|
264
|
+
case 308 /* SyntaxKind.SourceFile */:
|
|
257
265
|
return true;
|
|
258
266
|
}
|
|
259
267
|
return false;
|
|
@@ -280,41 +288,42 @@ function containsArgumentsReference(c, node) {
|
|
|
280
288
|
function getIdentifierFromEntityNameExpression(node) {
|
|
281
289
|
if (node.kind === 79 /* SyntaxKind.Identifier */)
|
|
282
290
|
return node;
|
|
283
|
-
if (node.kind ===
|
|
291
|
+
if (node.kind === 213 /* SyntaxKind.PropertyAccessExpression */)
|
|
284
292
|
return getName(node);
|
|
285
293
|
return undefined;
|
|
286
294
|
}
|
|
287
|
-
/**
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
this.className = className;
|
|
297
|
-
this.extendsName = extendsName;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
/** The `@augments` or `@extends` tag of a class whose class name differs from its `extends` clause. */
|
|
301
|
-
export function findMismatchedAugmentsTag(classLike, extendsType) {
|
|
302
|
-
const jsDoc = getAttachedJSDoc(classLike);
|
|
295
|
+
/**
|
|
296
|
+
* Reports an `@augments` or `@extends` tag of a JavaScript class whose class doesn't match the
|
|
297
|
+
* `extends` clause: for an entity name, a different type; for another expression, a type the base
|
|
298
|
+
* type isn't assignable to.
|
|
299
|
+
*/
|
|
300
|
+
export function checkJSDocAugmentsTagMatchesExtends(c, node, baseTypeNode, baseType) {
|
|
301
|
+
if (!isInJSFile(node))
|
|
302
|
+
return;
|
|
303
|
+
const jsDoc = getAttachedJSDoc(node);
|
|
303
304
|
if (jsDoc === undefined)
|
|
304
|
-
return
|
|
305
|
+
return;
|
|
305
306
|
for (const j of jsDoc) {
|
|
306
307
|
const tags = j.tags;
|
|
307
308
|
if (tags === undefined)
|
|
308
309
|
continue;
|
|
309
310
|
for (const tag of tags.nodes) {
|
|
310
|
-
if (tag.kind !==
|
|
311
|
+
if (tag.kind !== 324 /* SyntaxKind.JSDocAugmentsTag */)
|
|
311
312
|
continue;
|
|
312
313
|
const augments = tag;
|
|
313
|
-
const
|
|
314
|
+
const sourceType = getTypeFromTypeNode(c, augments.className);
|
|
314
315
|
const sourceName = getIdentifierFromEntityNameExpression(augments.className.expression);
|
|
315
|
-
if (
|
|
316
|
-
|
|
316
|
+
if (isEntityNameExpression(baseTypeNode.expression, false)) {
|
|
317
|
+
if (isTypeIdenticalTo(c, sourceType, baseType))
|
|
318
|
+
continue;
|
|
319
|
+
const targetName = getIdentifierFromEntityNameExpression(baseTypeNode.expression);
|
|
320
|
+
if (targetName !== undefined && sourceName !== undefined)
|
|
321
|
+
c.error(sourceName, 1772 /* Diagnostics.JSDoc_0_1_does_not_match_the_extends_2_clause */, getText(augments.tagName), getText(sourceName), getText(targetName));
|
|
322
|
+
}
|
|
323
|
+
else if (sourceName !== undefined && !isTypeAssignableTo(c, baseType, sourceType)) {
|
|
324
|
+
const expression = baseTypeNode.expression;
|
|
325
|
+
c.error(sourceName, 1772 /* Diagnostics.JSDoc_0_1_does_not_match_the_extends_2_clause */, getText(augments.tagName), getText(sourceName), getSourceTextOfNode(getSourceFileOfNode(expression), expression));
|
|
326
|
+
}
|
|
317
327
|
}
|
|
318
328
|
}
|
|
319
|
-
return undefined;
|
|
320
329
|
}
|