1/* 2 * Copyright (c) 2023-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 16function templateLiterals(): void { 17 const empty = ``; 18 const templateText = `First line \n second line 19third line \n fourth line`; 20 const templateHead = `template-head ${20 + 40}`; 21 const templateTail = `${empty.length > 0 ? 100 : 200} template-tail`; 22 const templateCompound = `apple ${400} orange \n ${500} 23"banana" ${600} 'grapes'`; 24 const nested = `outer ${`inner ${1000} inner-end`} outer-end`; 25} 26 27function tag1(strings: TemplateStringsArray): void { 28 console.log(strings); 29} 30function tag2(strings: TemplateStringsArray, ...values: any[]): void { 31 console.log(strings, values); 32} 33function recursiveTag( 34 strings: TemplateStringsArray, 35 ...values: any[] 36): typeof recursiveTag { 37 console.log(strings, values); 38 return recursiveTag; 39} 40 41function taggedTemplates(arg: string): void { 42 tag1`Birds are singing`; 43 tag2`This product costs ${arg} per month`; 44 recursiveTag`Hello``World`; 45} 46