1/* 2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16function gets(): string { 17 return 'ss'; 18} 19 20const b0 = true; 21 22const c0 = b0 && true; 23const c1 = true && '3'; 24const c2 = gets() && false; 25const c3 = 5 && 6; 26 27const d0 = false || b0; 28const d1 = ~'3' || true; 29const d2 = false || gets(); 30const d3 = 4 || 5; 31 32console.log(c1); 33console.log(c2); 34console.log(c3); 35console.log(d1); 36console.log(d2); 37console.log(d3); 38 39const varAny: any = null; 40 41const add0 = 2 + 2; 42const add1 = '2' + '2'; 43const add2 = '2' + varAny; 44const add3 = varAny + '2'; 45const add4 = varAny + 2; 46const add5 = 6 + varAny; 47const add6 = '2' + 2; 48const add7 = 2 + '2'; 49 50enum Const { 51 PI = 3.14, 52 E = 2.7818, 53} 54enum State { 55 OK = 'ok', 56 FAULT = 'fail', 57} 58 59const b1 = 7 ^ varAny; 60const b2 = 7 | varAny; 61const b3 = 7 & varAny; 62 63const b4 = 7 << varAny; 64const b5 = 7 >> varAny; 65const b6 = 7 >>> varAny; 66 67const b7 = varAny << 1; 68const b8 = varAny >> 2; 69const b9 = varAny >>> 3; 70 71const b11 = 7 ^ Const.PI; 72const b12 = 7 | Const.E; 73const b13 = 7 & Const.PI; 74 75const b14 = 7 << Const.PI; 76const b15 = 7 >> Const.E; 77const b16 = 7 >>> Const.PI; 78 79const b17 = Const.PI << 1; 80const b18 = Const.E >> 2; 81const b19 = Const.PI >>> 3; 82 83const b31 = State.OK ^ 7; 84const b32 = 7 | State.FAULT; 85const b33 = 7 & State.OK; 86 87const b34 = 7 << State.OK; 88const b35 = 7 >> State.FAULT; 89const b36 = 7 >>> State.OK; 90 91const b37 = State.FAULT << 1; 92const b38 = State.OK >> 2; 93const b39 = State.FAULT >>> 3; 94 95const a000 = ((k = 10), 2 + 7); 96 97function foo(n: number, m: number): number { 98 return (n/m) + ((n%m) ? 1 : 0); 99} 100 101const b40 = 7 & 5.5; 102const b41 = 5.5 & b40; 103const b42 = 2 | 5.5; 104const b43 = 5.5 | b42; 105const b44 = 4 ^ 5.5; 106const b45 = 5.5 ^ b44; 107 108 109let e1 = Const.PI + Const.E; // OK 110let e2 = State.FAULT + State.OK; // OK 111let e3 = "State: " + State.FAULT; // OK 112let e4 = "Const = " + Const.PI; // OK 113 114let f1 = Const.PI + State.FAULT; // Error 115let f2 = State.OK + Const.E; // Error 116