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
|
@@ -53,10 +53,10 @@ export function checkPrefixUnaryExpression(c, node) {
|
|
|
53
53
|
case 54 /* SyntaxKind.TildeToken */:
|
|
54
54
|
checkNonNullType(c, operandType, node.operand);
|
|
55
55
|
if (maybeTypeOfKindConsideringBaseConstraint(c, operandType, 16896 /* TypeFlags.ESSymbolLike */))
|
|
56
|
-
c.error(node.operand,
|
|
56
|
+
c.error(node.operand, 642 /* Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol */, tokenToString(node.operator));
|
|
57
57
|
if (node.operator === 39 /* SyntaxKind.PlusToken */) {
|
|
58
58
|
if (maybeTypeOfKindConsideringBaseConstraint(c, operandType, 4224 /* TypeFlags.BigIntLike */))
|
|
59
|
-
c.error(node.operand,
|
|
59
|
+
c.error(node.operand, 875 /* Diagnostics.Operator_0_cannot_be_applied_to_type_1 */, tokenToString(node.operator), typeToString(c, getBaseTypeOfLiteralType(c, operandType)));
|
|
60
60
|
return c.numberType;
|
|
61
61
|
}
|
|
62
62
|
return getUnaryResultType(c, operandType);
|
|
@@ -84,10 +84,10 @@ export function checkPostfixUnaryExpression(c, node) {
|
|
|
84
84
|
return getUnaryResultType(c, operandType);
|
|
85
85
|
}
|
|
86
86
|
function checkIncrementOperand(c, operand, operandType) {
|
|
87
|
-
const ok = checkArithmeticOperandType(c, operand, checkNonNullType(c, operandType, operand),
|
|
87
|
+
const ok = checkArithmeticOperandType(c, operand, checkNonNullType(c, operandType, operand), 539 /* Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_bigint_or_an_enum_type */, false);
|
|
88
88
|
// Only checked when the operand type is fine, to avoid cascading errors.
|
|
89
89
|
if (ok)
|
|
90
|
-
checkReferenceExpression(c, operand,
|
|
90
|
+
checkReferenceExpression(c, operand, 540 /* Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_or_a_property_access */, 916 /* Diagnostics.The_operand_of_an_increment_or_decrement_operator_may_not_be_an_optional_property_access */);
|
|
91
91
|
}
|
|
92
92
|
function getUnaryResultType(c, operandType) {
|
|
93
93
|
if (maybeTypeOfKind(operandType, 4224 /* TypeFlags.BigIntLike */)) {
|
|
@@ -102,17 +102,17 @@ export function checkDeleteExpression(c, node) {
|
|
|
102
102
|
checkExpression(c, getExpression(node));
|
|
103
103
|
const expr = skipParentheses(getExpression(node));
|
|
104
104
|
if (!isAccessExpression(expr)) {
|
|
105
|
-
c.error(expr,
|
|
105
|
+
c.error(expr, 842 /* Diagnostics.The_operand_of_a_delete_operator_must_be_a_property_reference */);
|
|
106
106
|
return c.booleanType;
|
|
107
107
|
}
|
|
108
|
-
if (expr.kind ===
|
|
108
|
+
if (expr.kind === 213 /* SyntaxKind.PropertyAccessExpression */ &&
|
|
109
109
|
expr.name.kind === 80 /* SyntaxKind.PrivateIdentifier */)
|
|
110
|
-
c.error(expr,
|
|
110
|
+
c.error(expr, 1853 /* Diagnostics.The_operand_of_a_delete_operator_cannot_be_a_private_identifier */);
|
|
111
111
|
const resolved = c.resolvedSymbols.get(expr.id);
|
|
112
112
|
if (resolved !== undefined) {
|
|
113
113
|
const symbol = getExportSymbolOfValueSymbolIfExported(c, resolved);
|
|
114
114
|
if (isReadonlySymbol(c, symbol))
|
|
115
|
-
c.error(expr,
|
|
115
|
+
c.error(expr, 843 /* Diagnostics.The_operand_of_a_delete_operator_cannot_be_a_read_only_property */);
|
|
116
116
|
else
|
|
117
117
|
checkDeleteExpressionMustBeOptional(c, expr, symbol);
|
|
118
118
|
}
|
|
@@ -126,7 +126,7 @@ function checkDeleteExpressionMustBeOptional(c, expr, symbol) {
|
|
|
126
126
|
? (symbol.flags & 16777216 /* SymbolFlags.Optional */) !== 0
|
|
127
127
|
: hasTypeFacts(c, t, 16777216 /* TypeFacts.IsUndefined */);
|
|
128
128
|
if (!isOptional)
|
|
129
|
-
c.error(expr,
|
|
129
|
+
c.error(expr, 929 /* Diagnostics.The_operand_of_a_delete_operator_must_be_optional */);
|
|
130
130
|
}
|
|
131
131
|
/** Reports a grammar error unless the file already has syntax errors. */
|
|
132
132
|
export function grammarErrorOnNode(c, node, message, ...args) {
|
|
@@ -155,10 +155,11 @@ function isTypeAny(t) {
|
|
|
155
155
|
return (t.flags & 1 /* TypeFlags.Any */) !== 0;
|
|
156
156
|
}
|
|
157
157
|
export function errorAndMaybeSuggestAwait(c, location, maybeMissingAwait, message, args) {
|
|
158
|
-
|
|
158
|
+
// The related information goes on the reported diagnostic after it is added, as tsgo attaches it,
|
|
159
|
+
// so a later equal report compares unequal to it and is kept.
|
|
160
|
+
const diagnostic = c.error(location, message, ...args);
|
|
159
161
|
if (maybeMissingAwait)
|
|
160
|
-
diagnostic.addRelatedInfo(createDiagnosticForNode(location,
|
|
161
|
-
c.addDiagnostic(diagnostic);
|
|
162
|
+
diagnostic.addRelatedInfo(createDiagnosticForNode(location, 912 /* Diagnostics.Did_you_forget_to_use_await */, []));
|
|
162
163
|
return diagnostic;
|
|
163
164
|
}
|
|
164
165
|
function checkArithmeticOperandType(c, operand, t, message, isAwaitValid) {
|
|
@@ -183,24 +184,24 @@ export function checkReferenceExpression(c, expr, invalidReference, invalidOptio
|
|
|
183
184
|
}
|
|
184
185
|
function skipAssertionsAndParentheses(nodeIn) {
|
|
185
186
|
let node = nodeIn;
|
|
186
|
-
while (node.kind ===
|
|
187
|
-
node.kind ===
|
|
188
|
-
node.kind ===
|
|
189
|
-
node.kind ===
|
|
190
|
-
node.kind ===
|
|
187
|
+
while (node.kind === 219 /* SyntaxKind.ParenthesizedExpression */ ||
|
|
188
|
+
node.kind === 218 /* SyntaxKind.TypeAssertionExpression */ ||
|
|
189
|
+
node.kind === 236 /* SyntaxKind.AsExpression */ ||
|
|
190
|
+
node.kind === 240 /* SyntaxKind.SatisfiesExpression */ ||
|
|
191
|
+
node.kind === 237 /* SyntaxKind.NonNullExpression */)
|
|
191
192
|
node = getExpression(node);
|
|
192
193
|
return node;
|
|
193
194
|
}
|
|
194
195
|
/** `node` without parentheses, type assertions, `satisfies` and non-null assertions. */
|
|
195
196
|
export function skipOuterExpressions(nodeIn) {
|
|
196
197
|
let node = nodeIn;
|
|
197
|
-
while (node.kind ===
|
|
198
|
-
node.kind ===
|
|
199
|
-
node.kind ===
|
|
200
|
-
node.kind ===
|
|
201
|
-
node.kind ===
|
|
202
|
-
node.kind ===
|
|
203
|
-
node.kind ===
|
|
198
|
+
while (node.kind === 219 /* SyntaxKind.ParenthesizedExpression */ ||
|
|
199
|
+
node.kind === 218 /* SyntaxKind.TypeAssertionExpression */ ||
|
|
200
|
+
node.kind === 236 /* SyntaxKind.AsExpression */ ||
|
|
201
|
+
node.kind === 240 /* SyntaxKind.SatisfiesExpression */ ||
|
|
202
|
+
node.kind === 237 /* SyntaxKind.NonNullExpression */ ||
|
|
203
|
+
node.kind === 235 /* SyntaxKind.ExpressionWithTypeArguments */ ||
|
|
204
|
+
node.kind === 349 /* SyntaxKind.PartiallyEmittedExpression */)
|
|
204
205
|
node = getExpression(node);
|
|
205
206
|
return node;
|
|
206
207
|
}
|
|
@@ -210,18 +211,18 @@ export function checkBinaryExpression(c, node, checkMode) {
|
|
|
210
211
|
const right = node.right;
|
|
211
212
|
const operator = node.operatorToken.kind;
|
|
212
213
|
if (operator === 63 /* SyntaxKind.EqualsToken */ &&
|
|
213
|
-
(left.kind ===
|
|
214
|
+
(left.kind === 212 /* SyntaxKind.ObjectLiteralExpression */ || left.kind === 211 /* SyntaxKind.ArrayLiteralExpression */))
|
|
214
215
|
return checkDestructuringAssignment(c, left, checkExpressionEx(c, right, checkMode), checkMode, right.kind === 109 /* SyntaxKind.ThisKeyword */);
|
|
215
216
|
const leftType = checkExpressionEx(c, left, checkMode);
|
|
216
217
|
const rightType = checkExpressionEx(c, right, checkMode);
|
|
217
218
|
if (isLogicalOrCoalescingOperator(operator)) {
|
|
218
219
|
let parent = node.parent;
|
|
219
|
-
while (parent.kind ===
|
|
220
|
-
(parent.kind ===
|
|
220
|
+
while (parent.kind === 219 /* SyntaxKind.ParenthesizedExpression */ ||
|
|
221
|
+
(parent.kind === 228 /* SyntaxKind.BinaryExpression */ &&
|
|
221
222
|
isLogicalOrCoalescingOperator(parent.operatorToken.kind)))
|
|
222
223
|
parent = parent.parent;
|
|
223
|
-
if (operator === 55 /* SyntaxKind.AmpersandAmpersandToken */ || parent.kind ===
|
|
224
|
-
checkTestingKnownTruthyType(c, left, leftType, parent.kind ===
|
|
224
|
+
if (operator === 55 /* SyntaxKind.AmpersandAmpersandToken */ || parent.kind === 247 /* SyntaxKind.IfStatement */)
|
|
225
|
+
checkTestingKnownTruthyType(c, left, leftType, parent.kind === 247 /* SyntaxKind.IfStatement */ ? parent.thenStatement : undefined);
|
|
225
226
|
if (operator !== 60 /* SyntaxKind.QuestionQuestionToken */)
|
|
226
227
|
checkTruthinessOfType(c, leftType, left);
|
|
227
228
|
}
|
|
@@ -266,12 +267,12 @@ function checkBinaryLikeExpressionWorker(c, errorNode, left, operator, right, le
|
|
|
266
267
|
if ((leftType.flags & 8448 /* TypeFlags.BooleanLike */) !== 0 && (rightType.flags & 8448 /* TypeFlags.BooleanLike */) !== 0) {
|
|
267
268
|
const suggested = getSuggestedBooleanOperator(operator);
|
|
268
269
|
if (suggested !== 0 /* SyntaxKind.Unknown */) {
|
|
269
|
-
c.error(errorNode.operatorToken,
|
|
270
|
+
c.error(errorNode.operatorToken, 622 /* Diagnostics.The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead */, tokenToString(operator), tokenToString(suggested));
|
|
270
271
|
return c.numberType;
|
|
271
272
|
}
|
|
272
273
|
}
|
|
273
|
-
const leftOk = checkArithmeticOperandType(c, left, leftType,
|
|
274
|
-
const rightOk = checkArithmeticOperandType(c, right, rightType,
|
|
274
|
+
const leftOk = checkArithmeticOperandType(c, left, leftType, 543 /* Diagnostics.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type */, true);
|
|
275
|
+
const rightOk = checkArithmeticOperandType(c, right, rightType, 544 /* Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type */, true);
|
|
275
276
|
let resultType;
|
|
276
277
|
if ((isTypeAssignableToKind(c, leftType, 3 /* TypeFlags.AnyOrUnknown */) &&
|
|
277
278
|
isTypeAssignableToKind(c, rightType, 3 /* TypeFlags.AnyOrUnknown */)) ||
|
|
@@ -283,7 +284,7 @@ function checkBinaryLikeExpressionWorker(c, errorNode, left, operator, right, le
|
|
|
283
284
|
reportOperatorError(c, leftType, operator, rightType, errorNode, 0 /* RelatedCheck.None */);
|
|
284
285
|
else if ((operator === 42 /* SyntaxKind.AsteriskAsteriskToken */ || operator === 67 /* SyntaxKind.AsteriskAsteriskEqualsToken */) &&
|
|
285
286
|
c.languageVersion < ScriptTarget.ES2016)
|
|
286
|
-
c.error(errorNode,
|
|
287
|
+
c.error(errorNode, 930 /* Diagnostics.Exponentiation_cannot_be_performed_on_bigint_values_unless_the_target_option_is_set_to_es2016_or_later */);
|
|
287
288
|
resultType = c.bigintType;
|
|
288
289
|
}
|
|
289
290
|
else {
|
|
@@ -351,7 +352,7 @@ function checkBinaryLikeExpressionWorker(c, errorNode, left, operator, right, le
|
|
|
351
352
|
operator === 36 /* SyntaxKind.EqualsEqualsEqualsToken */ ||
|
|
352
353
|
operator === 37 /* SyntaxKind.ExclamationEqualsEqualsToken */)) {
|
|
353
354
|
const eqType = operator === 34 /* SyntaxKind.EqualsEqualsToken */ || operator === 36 /* SyntaxKind.EqualsEqualsEqualsToken */;
|
|
354
|
-
c.error(errorNode,
|
|
355
|
+
c.error(errorNode, 968 /* Diagnostics.This_condition_will_always_return_0_since_JavaScript_compares_objects_by_reference_not_value */, eqType ? 'false' : 'true');
|
|
355
356
|
}
|
|
356
357
|
checkNaNEquality(c, errorNode, operator, left, right);
|
|
357
358
|
if (!isRelated(c, 4 /* RelatedCheck.EqualityComparable */, leftType, rightType))
|
|
@@ -402,7 +403,7 @@ function checkBinaryLikeExpressionWorker(c, errorNode, left, operator, right, le
|
|
|
402
403
|
isSideEffectFree(left) &&
|
|
403
404
|
!isIndirectCall(left.parent) &&
|
|
404
405
|
!isInMultipleJsxRootsError(left))
|
|
405
|
-
c.error(left,
|
|
406
|
+
c.error(left, 834 /* Diagnostics.Left_side_of_comma_operator_is_unused_and_has_no_side_effects */);
|
|
406
407
|
return rightType;
|
|
407
408
|
}
|
|
408
409
|
return c.errorType;
|
|
@@ -412,7 +413,7 @@ function isInMultipleJsxRootsError(left) {
|
|
|
412
413
|
const file = getSourceFileOfNode(left);
|
|
413
414
|
const start = skipTrivia(file.text, left.pos);
|
|
414
415
|
for (const d of file.diagnostics)
|
|
415
|
-
if (d.message ===
|
|
416
|
+
if (d.message === 798 /* Diagnostics.JSX_expressions_must_have_one_parent_element */ && d.pos <= start && start < d.end)
|
|
416
417
|
return true;
|
|
417
418
|
return false;
|
|
418
419
|
}
|
|
@@ -442,7 +443,7 @@ function checkForDisallowedESSymbolOperand(c, left, right, leftType, rightType,
|
|
|
442
443
|
offending = right;
|
|
443
444
|
if (offending === undefined)
|
|
444
445
|
return true;
|
|
445
|
-
c.error(offending,
|
|
446
|
+
c.error(offending, 642 /* Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol */, tokenToString(operator));
|
|
446
447
|
return false;
|
|
447
448
|
}
|
|
448
449
|
function isRelated(c, check, left, right) {
|
|
@@ -496,10 +497,10 @@ function reportOperatorError(c, leftType, operator, rightType, errorNode, check)
|
|
|
496
497
|
case 34 /* SyntaxKind.EqualsEqualsToken */:
|
|
497
498
|
case 37 /* SyntaxKind.ExclamationEqualsEqualsToken */:
|
|
498
499
|
case 35 /* SyntaxKind.ExclamationEqualsToken */:
|
|
499
|
-
errorAndMaybeSuggestAwait(c, errorNode, wouldWorkWithAwait,
|
|
500
|
+
errorAndMaybeSuggestAwait(c, errorNode, wouldWorkWithAwait, 548 /* Diagnostics.This_comparison_appears_to_be_unintentional_because_the_types_0_and_1_have_no_overlap */, [leftStr, rightStr]);
|
|
500
501
|
return;
|
|
501
502
|
}
|
|
502
|
-
errorAndMaybeSuggestAwait(c, errorNode, wouldWorkWithAwait,
|
|
503
|
+
errorAndMaybeSuggestAwait(c, errorNode, wouldWorkWithAwait, 546 /* Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2 */, [tokenToString(operator), leftStr, rightStr]);
|
|
503
504
|
}
|
|
504
505
|
function checkAssignmentOperator(c, left, operator, right, leftType, rightType) {
|
|
505
506
|
if (!isAssignmentOperator(operator))
|
|
@@ -510,30 +511,30 @@ function checkAssignmentOperator(c, left, operator, right, leftType, rightType)
|
|
|
510
511
|
let targetType = leftType;
|
|
511
512
|
if (operator >= 64 /* SyntaxKind.FirstCompoundAssignment */ &&
|
|
512
513
|
operator <= 78 /* SyntaxKind.LastCompoundAssignment */ &&
|
|
513
|
-
left.kind ===
|
|
514
|
+
left.kind === 213 /* SyntaxKind.PropertyAccessExpression */)
|
|
514
515
|
targetType = checkPropertyAccessExpression(c, left, true);
|
|
515
516
|
// Assignability is only checked when the target is a reference, to avoid cascading errors.
|
|
516
|
-
if (checkReferenceExpression(c, left,
|
|
517
|
+
if (checkReferenceExpression(c, left, 545 /* Diagnostics.The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access */, 918 /* Diagnostics.The_left_hand_side_of_an_assignment_expression_may_not_be_an_optional_property_access */)) {
|
|
517
518
|
let headMessage = undefined;
|
|
518
519
|
if (c.exactOptionalPropertyTypes &&
|
|
519
|
-
left.kind ===
|
|
520
|
+
left.kind === 213 /* SyntaxKind.PropertyAccessExpression */ &&
|
|
520
521
|
maybeTypeOfKind(rightType, 4 /* TypeFlags.Undefined */)) {
|
|
521
522
|
const access = left;
|
|
522
523
|
const target = getTypeOfPropertyOfType(c, getTypeOfExpression(c, access.expression), getText(access.name));
|
|
523
524
|
if (isExactOptionalPropertyMismatch(c, rightType, target))
|
|
524
525
|
headMessage =
|
|
525
|
-
|
|
526
|
+
590 /* Diagnostics.Type_0_is_not_assignable_to_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_type_of_the_target */;
|
|
526
527
|
}
|
|
527
528
|
checkTypeRelatedToAndOptionallyElaborate(c, rightType, targetType, c.assignableRelation, left, right, headMessage, undefined);
|
|
528
529
|
}
|
|
529
530
|
}
|
|
530
531
|
function isLiteralExpressionOfObject(node) {
|
|
531
532
|
switch (node.kind) {
|
|
532
|
-
case
|
|
533
|
-
case
|
|
533
|
+
case 212 /* SyntaxKind.ObjectLiteralExpression */:
|
|
534
|
+
case 211 /* SyntaxKind.ArrayLiteralExpression */:
|
|
534
535
|
case 13 /* SyntaxKind.RegularExpressionLiteral */:
|
|
535
|
-
case
|
|
536
|
-
case
|
|
536
|
+
case 233 /* SyntaxKind.ClassExpression */:
|
|
537
|
+
case 220 /* SyntaxKind.FunctionExpression */:
|
|
537
538
|
return true;
|
|
538
539
|
}
|
|
539
540
|
return false;
|
|
@@ -543,7 +544,7 @@ function checkNaNEquality(c, errorNode, operator, left, right) {
|
|
|
543
544
|
const isRightNaN = isGlobalNaN(c, skipParentheses(right));
|
|
544
545
|
if (!isLeftNaN && !isRightNaN)
|
|
545
546
|
return;
|
|
546
|
-
const err = c.error(errorNode,
|
|
547
|
+
const err = c.error(errorNode, 973 /* Diagnostics.This_condition_will_always_return_0 */, operator === 36 /* SyntaxKind.EqualsEqualsEqualsToken */ || operator === 34 /* SyntaxKind.EqualsEqualsToken */ ? 'false' : 'true');
|
|
547
548
|
if (isLeftNaN && isRightNaN)
|
|
548
549
|
return;
|
|
549
550
|
const operatorString = operator === 37 /* SyntaxKind.ExclamationEqualsEqualsToken */ || operator === 35 /* SyntaxKind.ExclamationEqualsToken */ ? '!' : '';
|
|
@@ -578,10 +579,10 @@ function checkShiftAmount(c, left, operator, right, errorNode) {
|
|
|
578
579
|
if (result.kind !== 1 /* EvaluatedKind.Number */ || Math.abs(result.numberValue) < 32)
|
|
579
580
|
return;
|
|
580
581
|
let container = right.parent.parent;
|
|
581
|
-
while (container.kind ===
|
|
582
|
+
while (container.kind === 219 /* SyntaxKind.ParenthesizedExpression */)
|
|
582
583
|
container = container.parent;
|
|
583
584
|
const file = getSourceFileOfNode(left);
|
|
584
|
-
c.addErrorOrSuggestion(container.kind ===
|
|
585
|
+
c.addErrorOrSuggestion(container.kind === 307 /* SyntaxKind.EnumMember */, createDiagnosticForNode(errorNode, 1655 /* Diagnostics.This_operation_can_be_simplified_This_shift_is_identical_to_0_1_2 */, [
|
|
585
586
|
getSourceTextOfNode(file, left),
|
|
586
587
|
tokenToString(operator),
|
|
587
588
|
String(result.numberValue % 32),
|
|
@@ -592,12 +593,12 @@ function checkInstanceOfExpression(c, left, right, leftType, rightType, checkMod
|
|
|
592
593
|
return c.silentNeverType;
|
|
593
594
|
// Unknown left operands already reported an error.
|
|
594
595
|
if (!isTypeAny(leftType) && allTypesAssignableToKind(c, leftType, 12713980 /* TypeFlags.Primitive */))
|
|
595
|
-
c.error(left,
|
|
596
|
+
c.error(left, 541 /* Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter */);
|
|
596
597
|
// `x instanceof C` is checked as the call `C[Symbol.hasInstance](x)`.
|
|
597
598
|
const signature = getResolvedSignature(c, left.parent, checkMode);
|
|
598
599
|
if (signature === c.resolvingSignature)
|
|
599
600
|
return c.silentNeverType;
|
|
600
|
-
checkTypeAssignableTo(c, getReturnTypeOfSignature(c, signature), c.booleanType, right,
|
|
601
|
+
checkTypeAssignableTo(c, getReturnTypeOfSignature(c, signature), c.booleanType, right, 988 /* Diagnostics.An_object_s_Symbol_hasInstance_method_must_return_a_boolean_value_for_it_to_be_used_on_the_right_hand_side_of_an_instanceof_expression */);
|
|
601
602
|
return c.booleanType;
|
|
602
603
|
}
|
|
603
604
|
/** The signature of `right[Symbol.hasInstance]` that `left instanceof right` calls, if any. */
|
|
@@ -616,11 +617,11 @@ export function resolveInstanceofExpression(c, node, checkMode) {
|
|
|
616
617
|
return resolveUntypedCall(c, node);
|
|
617
618
|
// Argument errors explain how `left instanceof right` became `right[Symbol.hasInstance](left)`.
|
|
618
619
|
if (callSignatures.length !== 0)
|
|
619
|
-
return resolveCall(c, node, callSignatures, checkMode, 0 /* SignatureFlags.None */,
|
|
620
|
+
return resolveCall(c, node, callSignatures, checkMode, 0 /* SignatureFlags.None */, 987 /* Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_assignable_to_the_first_argument_of_the_right_hand_side_s_Symbol_hasInstance_method */);
|
|
620
621
|
}
|
|
621
622
|
else if (!typeHasCallOrConstructSignatures(c, rightType) &&
|
|
622
623
|
!isTypeSubtypeOf(c, rightType, c.globalFunctionType)) {
|
|
623
|
-
c.error(right,
|
|
624
|
+
c.error(right, 542 /* Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_either_of_type_any_a_class_function_or_other_type_assignable_to_the_Function_interface_type_or_an_object_type_with_a_Symbol_hasInstance_method */);
|
|
624
625
|
return resolveErrorCall(c, node);
|
|
625
626
|
}
|
|
626
627
|
}
|
|
@@ -664,7 +665,7 @@ function checkInExpression(c, left, right, leftType, rightType) {
|
|
|
664
665
|
if (checkTypeAssignableTo(c, checkNonNullType(c, rightType, right), c.nonPrimitiveType, right, undefined)) {
|
|
665
666
|
// `{}` is assignable to `object` but may stand for a primitive, as when narrowed from `unknown`.
|
|
666
667
|
if (hasEmptyObjectIntersection(c, rightType))
|
|
667
|
-
c.error(right,
|
|
668
|
+
c.error(right, 788 /* Diagnostics.Type_0_may_represent_a_primitive_value_which_is_not_permitted_as_the_right_operand_of_the_in_operator */, typeToString(c, rightType));
|
|
668
669
|
}
|
|
669
670
|
return c.booleanType;
|
|
670
671
|
}
|
|
@@ -712,8 +713,8 @@ export function checkTruthinessOfType(c, t, node) {
|
|
|
712
713
|
const semantics = getSyntacticTruthySemantics(c, node);
|
|
713
714
|
if (semantics !== 3 /* PredicateSemantics.Sometimes */)
|
|
714
715
|
c.error(node, semantics === 1 /* PredicateSemantics.Always */
|
|
715
|
-
?
|
|
716
|
-
:
|
|
716
|
+
? 999 /* Diagnostics.This_kind_of_expression_is_always_truthy */
|
|
717
|
+
: 1000 /* Diagnostics.This_kind_of_expression_is_always_falsy */);
|
|
717
718
|
return t;
|
|
718
719
|
}
|
|
719
720
|
function getSyntacticTruthySemantics(c, nodeIn) {
|
|
@@ -724,23 +725,23 @@ function getSyntacticTruthySemantics(c, nodeIn) {
|
|
|
724
725
|
const text = getText(node);
|
|
725
726
|
return text === '0' || text === '1' ? 3 /* PredicateSemantics.Sometimes */ : 1 /* PredicateSemantics.Always */;
|
|
726
727
|
}
|
|
727
|
-
case
|
|
728
|
-
case
|
|
728
|
+
case 211 /* SyntaxKind.ArrayLiteralExpression */:
|
|
729
|
+
case 221 /* SyntaxKind.ArrowFunction */:
|
|
729
730
|
case 9 /* SyntaxKind.BigIntLiteral */:
|
|
730
|
-
case
|
|
731
|
-
case
|
|
732
|
-
case
|
|
733
|
-
case
|
|
734
|
-
case
|
|
731
|
+
case 233 /* SyntaxKind.ClassExpression */:
|
|
732
|
+
case 220 /* SyntaxKind.FunctionExpression */:
|
|
733
|
+
case 286 /* SyntaxKind.JsxElement */:
|
|
734
|
+
case 287 /* SyntaxKind.JsxSelfClosingElement */:
|
|
735
|
+
case 212 /* SyntaxKind.ObjectLiteralExpression */:
|
|
735
736
|
case 13 /* SyntaxKind.RegularExpressionLiteral */:
|
|
736
737
|
return 1 /* PredicateSemantics.Always */;
|
|
737
|
-
case
|
|
738
|
+
case 224 /* SyntaxKind.VoidExpression */:
|
|
738
739
|
case 105 /* SyntaxKind.NullKeyword */:
|
|
739
740
|
return 2 /* PredicateSemantics.Never */;
|
|
740
741
|
case 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */:
|
|
741
742
|
case 10 /* SyntaxKind.StringLiteral */:
|
|
742
743
|
return getText(node) !== '' ? 1 /* PredicateSemantics.Always */ : 2 /* PredicateSemantics.Never */;
|
|
743
|
-
case
|
|
744
|
+
case 229 /* SyntaxKind.ConditionalExpression */: {
|
|
744
745
|
const cond = node;
|
|
745
746
|
return getSyntacticTruthySemantics(c, cond.whenTrue) | getSyntacticTruthySemantics(c, cond.whenFalse);
|
|
746
747
|
}
|
|
@@ -753,42 +754,42 @@ function getSyntacticTruthySemantics(c, nodeIn) {
|
|
|
753
754
|
}
|
|
754
755
|
function checkNullishCoalesceOperands(c, left, right) {
|
|
755
756
|
const grandparent = left.parent.parent;
|
|
756
|
-
if (grandparent.kind ===
|
|
757
|
+
if (grandparent.kind === 228 /* SyntaxKind.BinaryExpression */) {
|
|
757
758
|
const outer = grandparent;
|
|
758
|
-
if (outer.left.kind ===
|
|
759
|
-
grammarErrorOnNode(c, outer.left,
|
|
759
|
+
if (outer.left.kind === 228 /* SyntaxKind.BinaryExpression */ && outer.operatorToken.kind === 56 /* SyntaxKind.BarBarToken */)
|
|
760
|
+
grammarErrorOnNode(c, outer.left, 1158 /* Diagnostics.X_0_and_1_operations_cannot_be_mixed_without_parentheses */, tokenToString(60 /* SyntaxKind.QuestionQuestionToken */), tokenToString(outer.operatorToken.kind));
|
|
760
761
|
}
|
|
761
|
-
else if (left.kind ===
|
|
762
|
+
else if (left.kind === 228 /* SyntaxKind.BinaryExpression */) {
|
|
762
763
|
const operator = left.operatorToken.kind;
|
|
763
764
|
if (operator === 56 /* SyntaxKind.BarBarToken */ || operator === 55 /* SyntaxKind.AmpersandAmpersandToken */)
|
|
764
|
-
grammarErrorOnNode(c, left,
|
|
765
|
+
grammarErrorOnNode(c, left, 1158 /* Diagnostics.X_0_and_1_operations_cannot_be_mixed_without_parentheses */, tokenToString(operator), tokenToString(60 /* SyntaxKind.QuestionQuestionToken */));
|
|
765
766
|
}
|
|
766
|
-
else if (right.kind ===
|
|
767
|
+
else if (right.kind === 228 /* SyntaxKind.BinaryExpression */) {
|
|
767
768
|
const operator = right.operatorToken.kind;
|
|
768
769
|
if (operator === 55 /* SyntaxKind.AmpersandAmpersandToken */)
|
|
769
|
-
grammarErrorOnNode(c, right,
|
|
770
|
+
grammarErrorOnNode(c, right, 1158 /* Diagnostics.X_0_and_1_operations_cannot_be_mixed_without_parentheses */, tokenToString(60 /* SyntaxKind.QuestionQuestionToken */), tokenToString(operator));
|
|
770
771
|
}
|
|
771
772
|
const leftTarget = skipOuterExpressions(left);
|
|
772
773
|
const semantics = getSyntacticNullishnessSemantics(c, leftTarget);
|
|
773
774
|
if (semantics === 1 /* PredicateSemantics.Always */)
|
|
774
|
-
c.error(leftTarget,
|
|
775
|
+
c.error(leftTarget, 998 /* Diagnostics.This_expression_is_always_nullish */);
|
|
775
776
|
else if (semantics !== 3 /* PredicateSemantics.Sometimes */)
|
|
776
|
-
c.error(leftTarget,
|
|
777
|
+
c.error(leftTarget, 996 /* Diagnostics.Right_operand_of_is_unreachable_because_the_left_operand_is_never_nullish */);
|
|
777
778
|
}
|
|
778
779
|
function getSyntacticNullishnessSemantics(c, nodeIn) {
|
|
779
780
|
const node = skipOuterExpressions(nodeIn);
|
|
780
781
|
switch (node.kind) {
|
|
781
|
-
case
|
|
782
|
-
case
|
|
783
|
-
case
|
|
784
|
-
case
|
|
785
|
-
case
|
|
786
|
-
case
|
|
787
|
-
case
|
|
788
|
-
case
|
|
782
|
+
case 225 /* SyntaxKind.AwaitExpression */:
|
|
783
|
+
case 215 /* SyntaxKind.CallExpression */:
|
|
784
|
+
case 217 /* SyntaxKind.TaggedTemplateExpression */:
|
|
785
|
+
case 214 /* SyntaxKind.ElementAccessExpression */:
|
|
786
|
+
case 238 /* SyntaxKind.MetaProperty */:
|
|
787
|
+
case 216 /* SyntaxKind.NewExpression */:
|
|
788
|
+
case 213 /* SyntaxKind.PropertyAccessExpression */:
|
|
789
|
+
case 231 /* SyntaxKind.YieldExpression */:
|
|
789
790
|
case 109 /* SyntaxKind.ThisKeyword */:
|
|
790
791
|
return 3 /* PredicateSemantics.Sometimes */;
|
|
791
|
-
case
|
|
792
|
+
case 228 /* SyntaxKind.BinaryExpression */: {
|
|
792
793
|
const binary = node;
|
|
793
794
|
switch (binary.operatorToken.kind) {
|
|
794
795
|
case 56 /* SyntaxKind.BarBarToken */:
|
|
@@ -799,13 +800,20 @@ function getSyntacticNullishnessSemantics(c, nodeIn) {
|
|
|
799
800
|
// The right operand decides.
|
|
800
801
|
case 27 /* SyntaxKind.CommaToken */:
|
|
801
802
|
case 63 /* SyntaxKind.EqualsToken */:
|
|
802
|
-
case 60 /* SyntaxKind.QuestionQuestionToken */:
|
|
803
|
-
case 77 /* SyntaxKind.QuestionQuestionEqualsToken */:
|
|
804
803
|
return getSyntacticNullishnessSemantics(c, binary.right);
|
|
804
|
+
// The left operand when it isn't nullish, otherwise the right operand.
|
|
805
|
+
case 60 /* SyntaxKind.QuestionQuestionToken */:
|
|
806
|
+
case 77 /* SyntaxKind.QuestionQuestionEqualsToken */: {
|
|
807
|
+
const left = getSyntacticNullishnessSemantics(c, binary.left);
|
|
808
|
+
let result = left & 2 /* PredicateSemantics.Never */;
|
|
809
|
+
if ((left & 1 /* PredicateSemantics.Always */) !== 0)
|
|
810
|
+
result |= getSyntacticNullishnessSemantics(c, binary.right);
|
|
811
|
+
return result;
|
|
812
|
+
}
|
|
805
813
|
}
|
|
806
814
|
return 2 /* PredicateSemantics.Never */;
|
|
807
815
|
}
|
|
808
|
-
case
|
|
816
|
+
case 229 /* SyntaxKind.ConditionalExpression */: {
|
|
809
817
|
const cond = node;
|
|
810
818
|
return getSyntacticNullishnessSemantics(c, cond.whenTrue) | getSyntacticNullishnessSemantics(c, cond.whenFalse);
|
|
811
819
|
}
|
|
@@ -838,7 +846,7 @@ export function checkTestingKnownTruthyType(c, condExpr, condType, body) {
|
|
|
838
846
|
return;
|
|
839
847
|
let expr = skipParentheses(condExpr);
|
|
840
848
|
checkTestingKnownTruthyTypeWorker(c, expr, condType, body);
|
|
841
|
-
while (expr.kind ===
|
|
849
|
+
while (expr.kind === 228 /* SyntaxKind.BinaryExpression */ &&
|
|
842
850
|
(expr.operatorToken.kind === 56 /* SyntaxKind.BarBarToken */ ||
|
|
843
851
|
expr.operatorToken.kind === 60 /* SyntaxKind.QuestionQuestionToken */)) {
|
|
844
852
|
expr = skipParentheses(expr.left);
|
|
@@ -846,7 +854,7 @@ export function checkTestingKnownTruthyType(c, condExpr, condType, body) {
|
|
|
846
854
|
}
|
|
847
855
|
}
|
|
848
856
|
function isLogicalOrCoalescingExpression(node) {
|
|
849
|
-
return (node.kind ===
|
|
857
|
+
return (node.kind === 228 /* SyntaxKind.BinaryExpression */ &&
|
|
850
858
|
isLogicalOrCoalescingOperator(node.operatorToken.kind));
|
|
851
859
|
}
|
|
852
860
|
function checkTestingKnownTruthyTypeWorker(c, condExpr, condType, body) {
|
|
@@ -858,17 +866,17 @@ function checkTestingKnownTruthyTypeWorker(c, condExpr, condType, body) {
|
|
|
858
866
|
return;
|
|
859
867
|
}
|
|
860
868
|
const t = location !== condExpr ? checkExpression(c, location) : condType;
|
|
861
|
-
if ((t.flags & 32768 /* TypeFlags.EnumLiteral */) !== 0 && location.kind ===
|
|
869
|
+
if ((t.flags & 32768 /* TypeFlags.EnumLiteral */) !== 0 && location.kind === 213 /* SyntaxKind.PropertyAccessExpression */) {
|
|
862
870
|
const leftSymbol = c.resolvedSymbols.get(location.expression.id);
|
|
863
871
|
if (leftSymbol !== undefined && (leftSymbol.flags & 384 /* SymbolFlags.Enum */) !== 0) {
|
|
864
872
|
// An enum member with a known value is always truthy or always falsy.
|
|
865
873
|
const value = t;
|
|
866
874
|
const truthy = (t.flags & 1024 /* TypeFlags.StringLiteral */) !== 0 ? value.stringValue !== '' : value.numberValue !== 0;
|
|
867
|
-
c.error(location,
|
|
875
|
+
c.error(location, 973 /* Diagnostics.This_condition_will_always_return_0 */, truthy ? 'true' : 'false');
|
|
868
876
|
return;
|
|
869
877
|
}
|
|
870
878
|
}
|
|
871
|
-
const isPropertyExpressionCast = location.kind ===
|
|
879
|
+
const isPropertyExpressionCast = location.kind === 213 /* SyntaxKind.PropertyAccessExpression */ &&
|
|
872
880
|
isTypeAssertion(location.expression);
|
|
873
881
|
if (!hasTypeFacts(c, t, 4194304 /* TypeFacts.Truthy */) || isPropertyExpressionCast)
|
|
874
882
|
return;
|
|
@@ -880,29 +888,29 @@ function checkTestingKnownTruthyTypeWorker(c, condExpr, condType, body) {
|
|
|
880
888
|
let testedNode = undefined;
|
|
881
889
|
if (location.kind === 79 /* SyntaxKind.Identifier */)
|
|
882
890
|
testedNode = location;
|
|
883
|
-
else if (location.kind ===
|
|
891
|
+
else if (location.kind === 213 /* SyntaxKind.PropertyAccessExpression */)
|
|
884
892
|
testedNode = location.name;
|
|
885
893
|
const testedSymbol = testedNode !== undefined ? getSymbolAtLocationWorker(c, testedNode, false) : undefined;
|
|
886
894
|
if (testedSymbol === undefined && !isPromise)
|
|
887
895
|
return;
|
|
888
896
|
const isUsed = testedSymbol !== undefined &&
|
|
889
|
-
((condExpr.parent.kind ===
|
|
897
|
+
((condExpr.parent.kind === 228 /* SyntaxKind.BinaryExpression */ &&
|
|
890
898
|
isSymbolUsedInBinaryExpressionChain(c, condExpr.parent, testedSymbol)) ||
|
|
891
899
|
(body !== undefined && isSymbolUsedInConditionBody(c, condExpr, body, testedNode, testedSymbol)));
|
|
892
900
|
if (isUsed)
|
|
893
901
|
return;
|
|
894
902
|
if (isPromise)
|
|
895
|
-
errorAndMaybeSuggestAwait(c, location, true,
|
|
903
|
+
errorAndMaybeSuggestAwait(c, location, true, 940 /* Diagnostics.This_condition_will_always_return_true_since_this_0_is_always_defined */, [typeToString(c, t, undefined, 64 /* TypeFormatFlags.UseFullyQualifiedType */)]);
|
|
896
904
|
else
|
|
897
|
-
c.error(location,
|
|
905
|
+
c.error(location, 913 /* Diagnostics.This_condition_will_always_return_true_since_this_function_is_always_defined_Did_you_mean_to_call_it_instead */);
|
|
898
906
|
}
|
|
899
907
|
export function isTypeAssertion(node) {
|
|
900
908
|
const n = skipParentheses(node);
|
|
901
|
-
return n.kind ===
|
|
909
|
+
return n.kind === 218 /* SyntaxKind.TypeAssertionExpression */ || n.kind === 236 /* SyntaxKind.AsExpression */;
|
|
902
910
|
}
|
|
903
911
|
function isSymbolUsedInBinaryExpressionChain(c, nodeIn, testedSymbol) {
|
|
904
912
|
let node = nodeIn;
|
|
905
|
-
while (node.kind ===
|
|
913
|
+
while (node.kind === 228 /* SyntaxKind.BinaryExpression */ &&
|
|
906
914
|
node.operatorToken.kind === 55 /* SyntaxKind.AmpersandAmpersandToken */) {
|
|
907
915
|
if (node.right.forEachChild(new SymbolUseFinder(c, testedSymbol)))
|
|
908
916
|
return true;
|
|
@@ -945,7 +953,7 @@ class ConditionBodyUseFinder extends NodeVisitor {
|
|
|
945
953
|
if (node.kind === 79 /* SyntaxKind.Identifier */ && getSymbolAtLocationWorker(this.c, node, false) === this.testedSymbol) {
|
|
946
954
|
// A simple identifier test needs no target comparison.
|
|
947
955
|
if (this.expr.kind === 79 /* SyntaxKind.Identifier */ ||
|
|
948
|
-
(this.testedNode.kind === 79 /* SyntaxKind.Identifier */ && this.testedNode.parent.kind ===
|
|
956
|
+
(this.testedNode.kind === 79 /* SyntaxKind.Identifier */ && this.testedNode.parent.kind === 228 /* SyntaxKind.BinaryExpression */))
|
|
949
957
|
return true;
|
|
950
958
|
let tested = this.testedNode.parent;
|
|
951
959
|
let child = node.parent;
|
|
@@ -954,14 +962,14 @@ class ConditionBodyUseFinder extends NodeVisitor {
|
|
|
954
962
|
return getSymbolAtLocationWorker(this.c, tested, false) === getSymbolAtLocationWorker(this.c, child, false);
|
|
955
963
|
if (tested.kind === 109 /* SyntaxKind.ThisKeyword */ && child.kind === 109 /* SyntaxKind.ThisKeyword */)
|
|
956
964
|
return true;
|
|
957
|
-
if (tested.kind ===
|
|
965
|
+
if (tested.kind === 213 /* SyntaxKind.PropertyAccessExpression */ && child.kind === 213 /* SyntaxKind.PropertyAccessExpression */) {
|
|
958
966
|
if (getSymbolAtLocationWorker(this.c, tested.name, false) !==
|
|
959
967
|
getSymbolAtLocationWorker(this.c, child.name, false))
|
|
960
968
|
return false;
|
|
961
969
|
child = getExpression(child);
|
|
962
970
|
tested = getExpression(tested);
|
|
963
971
|
}
|
|
964
|
-
else if (tested.kind ===
|
|
972
|
+
else if (tested.kind === 215 /* SyntaxKind.CallExpression */ && child.kind === 215 /* SyntaxKind.CallExpression */) {
|
|
965
973
|
child = getExpression(child);
|
|
966
974
|
tested = getExpression(tested);
|
|
967
975
|
}
|
|
@@ -983,8 +991,8 @@ function isSideEffectFree(expr) {
|
|
|
983
991
|
case 79 /* SyntaxKind.Identifier */:
|
|
984
992
|
case 10 /* SyntaxKind.StringLiteral */:
|
|
985
993
|
case 13 /* SyntaxKind.RegularExpressionLiteral */:
|
|
986
|
-
case
|
|
987
|
-
case
|
|
994
|
+
case 217 /* SyntaxKind.TaggedTemplateExpression */:
|
|
995
|
+
case 230 /* SyntaxKind.TemplateExpression */:
|
|
988
996
|
case 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */:
|
|
989
997
|
case 8 /* SyntaxKind.NumericLiteral */:
|
|
990
998
|
case 9 /* SyntaxKind.BigIntLiteral */:
|
|
@@ -992,27 +1000,27 @@ function isSideEffectFree(expr) {
|
|
|
992
1000
|
case 96 /* SyntaxKind.FalseKeyword */:
|
|
993
1001
|
case 105 /* SyntaxKind.NullKeyword */:
|
|
994
1002
|
case 157 /* SyntaxKind.UndefinedKeyword */:
|
|
995
|
-
case
|
|
996
|
-
case
|
|
997
|
-
case
|
|
998
|
-
case
|
|
999
|
-
case
|
|
1000
|
-
case
|
|
1001
|
-
case
|
|
1002
|
-
case
|
|
1003
|
-
case
|
|
1003
|
+
case 220 /* SyntaxKind.FunctionExpression */:
|
|
1004
|
+
case 233 /* SyntaxKind.ClassExpression */:
|
|
1005
|
+
case 221 /* SyntaxKind.ArrowFunction */:
|
|
1006
|
+
case 211 /* SyntaxKind.ArrayLiteralExpression */:
|
|
1007
|
+
case 212 /* SyntaxKind.ObjectLiteralExpression */:
|
|
1008
|
+
case 223 /* SyntaxKind.TypeOfExpression */:
|
|
1009
|
+
case 237 /* SyntaxKind.NonNullExpression */:
|
|
1010
|
+
case 287 /* SyntaxKind.JsxSelfClosingElement */:
|
|
1011
|
+
case 286 /* SyntaxKind.JsxElement */:
|
|
1004
1012
|
return true;
|
|
1005
|
-
case
|
|
1013
|
+
case 229 /* SyntaxKind.ConditionalExpression */: {
|
|
1006
1014
|
const cond = node;
|
|
1007
1015
|
return isSideEffectFree(cond.whenTrue) && isSideEffectFree(cond.whenFalse);
|
|
1008
1016
|
}
|
|
1009
|
-
case
|
|
1017
|
+
case 228 /* SyntaxKind.BinaryExpression */: {
|
|
1010
1018
|
const binary = node;
|
|
1011
1019
|
if (isAssignmentOperator(binary.operatorToken.kind))
|
|
1012
1020
|
return false;
|
|
1013
1021
|
return isSideEffectFree(binary.left) && isSideEffectFree(binary.right);
|
|
1014
1022
|
}
|
|
1015
|
-
case
|
|
1023
|
+
case 226 /* SyntaxKind.PrefixUnaryExpression */:
|
|
1016
1024
|
switch (node.operator) {
|
|
1017
1025
|
case 53 /* SyntaxKind.ExclamationToken */:
|
|
1018
1026
|
case 39 /* SyntaxKind.PlusToken */:
|
|
@@ -1029,12 +1037,12 @@ function isIndirectCall(node) {
|
|
|
1029
1037
|
const left = node.left;
|
|
1030
1038
|
const right = node.right;
|
|
1031
1039
|
const parent = node.parent;
|
|
1032
|
-
if (parent.kind !==
|
|
1040
|
+
if (parent.kind !== 219 /* SyntaxKind.ParenthesizedExpression */ ||
|
|
1033
1041
|
left.kind !== 8 /* SyntaxKind.NumericLiteral */ ||
|
|
1034
1042
|
getText(left) !== '0')
|
|
1035
1043
|
return false;
|
|
1036
1044
|
const grand = parent.parent;
|
|
1037
|
-
const called = (grand.kind ===
|
|
1038
|
-
grand.kind ===
|
|
1045
|
+
const called = (grand.kind === 215 /* SyntaxKind.CallExpression */ && getExpression(grand) === parent) ||
|
|
1046
|
+
grand.kind === 217 /* SyntaxKind.TaggedTemplateExpression */;
|
|
1039
1047
|
return called && (isAccessExpression(right) || (right.kind === 79 /* SyntaxKind.Identifier */ && getText(right) === 'eval'));
|
|
1040
1048
|
}
|