• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022-2025 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 = () => { };
17
18const multiply = (x: number, y): number => {
19    return x * y;
20};
21
22function createFunc(): () => number {
23  return () => {
24    return 100;
25};
26}
27
28const foobar = (() => {
29    return 'get result immediately';
30})();
31
32(() => {
33    console.log('foo!');
34})();
35
36void (() => {
37    console.log('bar!');
38})();
39
40const array = [1, 2, 3, 4, 5, 6];
41const double = array.map((e) => {
42    return e * 2;
43});
44const even = array.filter((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 = <T, E>(t: T, e: E) => {
57    return t;
58};
59
60const asyncFun = async () => {
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 = (p: () => number): void => {
72    let a = factorial(3);
73    let b = p();
74    let c = new C();
75    c.m();
76};
77
78let iife = (() => {
79    console.log('called immediately');
80})();
81
82let indexAccess = (() => {
83    console.log('index access');
84})[0];
85
86void (() => {
87    console.log('void');
88});
89
90async function awaitFun() {
91  await (() => {
92    console.log('async');
93});
94}
95
96let typeofFunc = typeof (() => {
97    console.log('typeof');
98})
99
100class BindFuncExpr {
101  foo() {
102    let bar = ((p: boolean) => {
103    console.log('Function.bind(this)');
104}).bind(this);
105  }
106}
107
108let callback = () => { console.log('callback'); }
109callback = callback || (() => { console.log('expr || function(){}'); });
110
111let ternaryExpr = !!callback
112  ? (() => { console.log('ternary 1'); }) || 2
113  : 3 && (() => { console.log('ternary 2'); });