1/*
2 * Copyright (c) 2022-2024 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
16const empty = function () {};
17
18const multiply = function (x: number, y): number {
19  return x * y;
20};
21
22function createFunc(): () => number {
23  return function () {
24    return 100;
25  };
26}
27
28const foobar = (function () {
29  return 'get result immediately';
30})();
31
32(function () {
33  console.log('foo!');
34})();
35
36void (function () {
37  console.log('bar!');
38})();
39
40const array = [1, 2, 3, 4, 5, 6];
41const double = array.map(function (e) {
42  return e * 2;
43});
44const even = array.filter(function (x) {
45  return x % 2 === 0;
46});
47
48const retTypeInfer = function (p: any) {
49  return p;
50};
51
52const generator = function * () {
53  yield 1;
54};
55
56const generic = function <T, E>(t: T, e: E) {
57  return t;
58};
59
60const asyncFun = async function() {
61  console.log('baz!');
62};
63
64const factorial = function f(n: number): number {
65  return n == 1 ? 1 : n * f(n - 1);
66};
67
68class C {
69  m() {}
70}
71const noRecursiveCall = function f(p: () => number): void { // Doesn't have recursive call, should be autofixable
72  let a = factorial(3);
73  let b = p();
74  let c = new C()
75  c.m();
76};
77
78let iife = function() {
79  console.log('called immediately');
80}();
81
82let indexAccess = function() {
83  console.log('index access');
84}[0];
85
86void function() {
87  console.log('void');
88};
89
90async function awaitFun() { 
91  await function() {
92    console.log('async');
93  };
94}
95
96let typeofFunc = typeof function() {
97  console.log('typeof');
98}
99
100class BindFuncExpr {
101  foo() {
102    let bar = function(p: boolean) {
103      console.log('Function.bind(this)');
104    }.bind(this);
105  }
106}
107
108let callback = function() { console.log('callback'); }
109callback = callback || function() { console.log('expr || function(){}'); };
110
111let ternaryExpr = !!callback
112  ? function() { console.log('ternary 1'); } || 2
113  : 3 && function() { console.log('ternary 2'); };