1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
|
=== tests/cases/compiler/truthinessCallExpressionCoercion1.ts ===
function onlyErrorsWhenTestingNonNullableFunctionType(required: () => boolean, optional?: () => boolean) {
>onlyErrorsWhenTestingNonNullableFunctionType : Symbol(onlyErrorsWhenTestingNonNullableFunctionType, Decl(truthinessCallExpressionCoercion1.ts, 0, 0))
>required : Symbol(required, Decl(truthinessCallExpressionCoercion1.ts, 0, 54))
>optional : Symbol(optional, Decl(truthinessCallExpressionCoercion1.ts, 0, 78))
// error
required ? console.log('required') : undefined;
>required : Symbol(required, Decl(truthinessCallExpressionCoercion1.ts, 0, 54))
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>undefined : Symbol(undefined)
// ok
optional ? console.log('optional') : undefined;
>optional : Symbol(optional, Decl(truthinessCallExpressionCoercion1.ts, 0, 78))
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>undefined : Symbol(undefined)
// ok
!!required ? console.log('not required') : undefined;
>required : Symbol(required, Decl(truthinessCallExpressionCoercion1.ts, 0, 54))
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>undefined : Symbol(undefined)
// ok
required() ? console.log('required call') : undefined;
>required : Symbol(required, Decl(truthinessCallExpressionCoercion1.ts, 0, 54))
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>undefined : Symbol(undefined)
}
function onlyErrorsWhenUnusedInBody() {
>onlyErrorsWhenUnusedInBody : Symbol(onlyErrorsWhenUnusedInBody, Decl(truthinessCallExpressionCoercion1.ts, 12, 1))
function test() { return Math.random() > 0.5; }
>test : Symbol(test, Decl(truthinessCallExpressionCoercion1.ts, 14, 39))
>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --))
>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --))
// error
test ? console.log('test') : undefined;
>test : Symbol(test, Decl(truthinessCallExpressionCoercion1.ts, 14, 39))
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>undefined : Symbol(undefined)
// ok
test ? console.log(test) : undefined;
>test : Symbol(test, Decl(truthinessCallExpressionCoercion1.ts, 14, 39))
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>test : Symbol(test, Decl(truthinessCallExpressionCoercion1.ts, 14, 39))
>undefined : Symbol(undefined)
// ok
test ? test() : undefined;
>test : Symbol(test, Decl(truthinessCallExpressionCoercion1.ts, 14, 39))
>test : Symbol(test, Decl(truthinessCallExpressionCoercion1.ts, 14, 39))
>undefined : Symbol(undefined)
// ok
test
>test : Symbol(test, Decl(truthinessCallExpressionCoercion1.ts, 14, 39))
? [() => null].forEach(() => { test(); })
>[() => null].forEach : Symbol(Array.forEach, Decl(lib.es5.d.ts, --, --))
>forEach : Symbol(Array.forEach, Decl(lib.es5.d.ts, --, --))
>test : Symbol(test, Decl(truthinessCallExpressionCoercion1.ts, 14, 39))
: undefined;
>undefined : Symbol(undefined)
// error
test
>test : Symbol(test, Decl(truthinessCallExpressionCoercion1.ts, 14, 39))
? [() => null].forEach(test => { test() })
>[() => null].forEach : Symbol(Array.forEach, Decl(lib.es5.d.ts, --, --))
>forEach : Symbol(Array.forEach, Decl(lib.es5.d.ts, --, --))
>test : Symbol(test, Decl(truthinessCallExpressionCoercion1.ts, 33, 31))
>test : Symbol(test, Decl(truthinessCallExpressionCoercion1.ts, 33, 31))
: undefined;
>undefined : Symbol(undefined)
}
function checksPropertyAccess() {
>checksPropertyAccess : Symbol(checksPropertyAccess, Decl(truthinessCallExpressionCoercion1.ts, 35, 1))
const x = {
>x : Symbol(x, Decl(truthinessCallExpressionCoercion1.ts, 38, 9))
foo: {
>foo : Symbol(foo, Decl(truthinessCallExpressionCoercion1.ts, 38, 15))
bar() { return true; }
>bar : Symbol(bar, Decl(truthinessCallExpressionCoercion1.ts, 39, 14))
}
}
// error
x.foo.bar ? console.log('x.foo.bar') : undefined;
>x.foo.bar : Symbol(bar, Decl(truthinessCallExpressionCoercion1.ts, 39, 14))
>x.foo : Symbol(foo, Decl(truthinessCallExpressionCoercion1.ts, 38, 15))
>x : Symbol(x, Decl(truthinessCallExpressionCoercion1.ts, 38, 9))
>foo : Symbol(foo, Decl(truthinessCallExpressionCoercion1.ts, 38, 15))
>bar : Symbol(bar, Decl(truthinessCallExpressionCoercion1.ts, 39, 14))
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>undefined : Symbol(undefined)
// ok
x.foo.bar ? x.foo.bar : undefined;
>x.foo.bar : Symbol(bar, Decl(truthinessCallExpressionCoercion1.ts, 39, 14))
>x.foo : Symbol(foo, Decl(truthinessCallExpressionCoercion1.ts, 38, 15))
>x : Symbol(x, Decl(truthinessCallExpressionCoercion1.ts, 38, 9))
>foo : Symbol(foo, Decl(truthinessCallExpressionCoercion1.ts, 38, 15))
>bar : Symbol(bar, Decl(truthinessCallExpressionCoercion1.ts, 39, 14))
>x.foo.bar : Symbol(bar, Decl(truthinessCallExpressionCoercion1.ts, 39, 14))
>x.foo : Symbol(foo, Decl(truthinessCallExpressionCoercion1.ts, 38, 15))
>x : Symbol(x, Decl(truthinessCallExpressionCoercion1.ts, 38, 9))
>foo : Symbol(foo, Decl(truthinessCallExpressionCoercion1.ts, 38, 15))
>bar : Symbol(bar, Decl(truthinessCallExpressionCoercion1.ts, 39, 14))
>undefined : Symbol(undefined)
var chrome = {
>chrome : Symbol(chrome, Decl(truthinessCallExpressionCoercion1.ts, 50, 7))
platformKeys: {
>platformKeys : Symbol(platformKeys, Decl(truthinessCallExpressionCoercion1.ts, 50, 18))
subtleCrypto() {
>subtleCrypto : Symbol(subtleCrypto, Decl(truthinessCallExpressionCoercion1.ts, 51, 23))
return {
sign() {},
>sign : Symbol(sign, Decl(truthinessCallExpressionCoercion1.ts, 53, 24))
exportKey() { return true }
>exportKey : Symbol(exportKey, Decl(truthinessCallExpressionCoercion1.ts, 54, 30))
}
}
}
}
// ok
if (chrome.platformKeys.subtleCrypto().exportKey) {
>chrome.platformKeys.subtleCrypto().exportKey : Symbol(exportKey, Decl(truthinessCallExpressionCoercion1.ts, 54, 30))
>chrome.platformKeys.subtleCrypto : Symbol(subtleCrypto, Decl(truthinessCallExpressionCoercion1.ts, 51, 23))
>chrome.platformKeys : Symbol(platformKeys, Decl(truthinessCallExpressionCoercion1.ts, 50, 18))
>chrome : Symbol(chrome, Decl(truthinessCallExpressionCoercion1.ts, 50, 7))
>platformKeys : Symbol(platformKeys, Decl(truthinessCallExpressionCoercion1.ts, 50, 18))
>subtleCrypto : Symbol(subtleCrypto, Decl(truthinessCallExpressionCoercion1.ts, 51, 23))
>exportKey : Symbol(exportKey, Decl(truthinessCallExpressionCoercion1.ts, 54, 30))
chrome.platformKeys.subtleCrypto().exportKey
>chrome.platformKeys.subtleCrypto().exportKey : Symbol(exportKey, Decl(truthinessCallExpressionCoercion1.ts, 54, 30))
>chrome.platformKeys.subtleCrypto : Symbol(subtleCrypto, Decl(truthinessCallExpressionCoercion1.ts, 51, 23))
>chrome.platformKeys : Symbol(platformKeys, Decl(truthinessCallExpressionCoercion1.ts, 50, 18))
>chrome : Symbol(chrome, Decl(truthinessCallExpressionCoercion1.ts, 50, 7))
>platformKeys : Symbol(platformKeys, Decl(truthinessCallExpressionCoercion1.ts, 50, 18))
>subtleCrypto : Symbol(subtleCrypto, Decl(truthinessCallExpressionCoercion1.ts, 51, 23))
>exportKey : Symbol(exportKey, Decl(truthinessCallExpressionCoercion1.ts, 54, 30))
}
}
class Foo {
>Foo : Symbol(Foo, Decl(truthinessCallExpressionCoercion1.ts, 64, 1))
maybeIsUser?: () => boolean;
>maybeIsUser : Symbol(Foo.maybeIsUser, Decl(truthinessCallExpressionCoercion1.ts, 66, 11))
isUser() {
>isUser : Symbol(Foo.isUser, Decl(truthinessCallExpressionCoercion1.ts, 67, 32))
return true;
}
test() {
>test : Symbol(Foo.test, Decl(truthinessCallExpressionCoercion1.ts, 71, 5))
// error
this.isUser ? console.log('this.isUser') : undefined;
>this.isUser : Symbol(Foo.isUser, Decl(truthinessCallExpressionCoercion1.ts, 67, 32))
>this : Symbol(Foo, Decl(truthinessCallExpressionCoercion1.ts, 64, 1))
>isUser : Symbol(Foo.isUser, Decl(truthinessCallExpressionCoercion1.ts, 67, 32))
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>undefined : Symbol(undefined)
// ok
this.maybeIsUser ? console.log('this.maybeIsUser') : undefined;
>this.maybeIsUser : Symbol(Foo.maybeIsUser, Decl(truthinessCallExpressionCoercion1.ts, 66, 11))
>this : Symbol(Foo, Decl(truthinessCallExpressionCoercion1.ts, 64, 1))
>maybeIsUser : Symbol(Foo.maybeIsUser, Decl(truthinessCallExpressionCoercion1.ts, 66, 11))
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>undefined : Symbol(undefined)
// ok
if (this.isUser) {
>this.isUser : Symbol(Foo.isUser, Decl(truthinessCallExpressionCoercion1.ts, 67, 32))
>this : Symbol(Foo, Decl(truthinessCallExpressionCoercion1.ts, 64, 1))
>isUser : Symbol(Foo.isUser, Decl(truthinessCallExpressionCoercion1.ts, 67, 32))
this.isUser();
>this.isUser : Symbol(Foo.isUser, Decl(truthinessCallExpressionCoercion1.ts, 67, 32))
>this : Symbol(Foo, Decl(truthinessCallExpressionCoercion1.ts, 64, 1))
>isUser : Symbol(Foo.isUser, Decl(truthinessCallExpressionCoercion1.ts, 67, 32))
}
}
}
|