idlize
57 строк · 1.7 Кб
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
16import { Context } from "./context.test"
17import { checkDump } from "./util.test"
18import { assert } from "chai"
19
20const someId = "xxx"
21
22suite("Wrapping literals in compute", () => {
23
24test("Object literal is wrapped in compute", () => {
25/** @memo */
26function foo(a: any): any {
27return a
28}
29let result: any
30/** @memo:entry */
31function start(__memo_context: Context, __memo_id: any) {
32result = foo({x: 17, y: 19})
33}
34start(new Context(), someId)
35assert.equal(result.x, 17)
36assert.equal(result.y, 19)
37})
38
39test("Arrow function is wrapped in compute", () => {
40let counter = 0
41/** @memo */
42function arrowFunctionReceiver(a: any) {
43counter++
44}
45/** @memo:entry */
46function start(__memo_context: Context, __memo_id: any) {
47arrowFunctionReceiver(() => {})
48}
49start(new Context(), someId)
50assert.equal(counter, 1)
51})
52
53
54for (let name of ["foo"]) {
55checkDump(name, "wrap_object_literal")
56}
57})
58