13af6ab5fSopenharmony_ci/* 23af6ab5fSopenharmony_ci * Copyright (c) 2022-2024 Huawei Device Co., Ltd. 33af6ab5fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 43af6ab5fSopenharmony_ci * you may not use this file except in compliance with the License. 53af6ab5fSopenharmony_ci * You may obtain a copy of the License at 63af6ab5fSopenharmony_ci * 73af6ab5fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 83af6ab5fSopenharmony_ci * 93af6ab5fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 103af6ab5fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 113af6ab5fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 123af6ab5fSopenharmony_ci * See the License for the specific language governing permissions and 133af6ab5fSopenharmony_ci * limitations under the License. 143af6ab5fSopenharmony_ci */ 153af6ab5fSopenharmony_ci 163af6ab5fSopenharmony_ciimport './short_test.ts'; // import from path 173af6ab5fSopenharmony_ci 183af6ab5fSopenharmony_ciimport { test } from './short_test.ts'; 193af6ab5fSopenharmony_ci 203af6ab5fSopenharmony_cifunction withStmt() { 213af6ab5fSopenharmony_ci const radius = 12; 223af6ab5fSopenharmony_ci with (Math) { 233af6ab5fSopenharmony_ci const area = PI * radius * radius; 243af6ab5fSopenharmony_ci } 253af6ab5fSopenharmony_ci} 263af6ab5fSopenharmony_ci 273af6ab5fSopenharmony_cinamespace X { 283af6ab5fSopenharmony_ci export class C {} 293af6ab5fSopenharmony_ci export interface I { 303af6ab5fSopenharmony_ci f: number; 313af6ab5fSopenharmony_ci } 323af6ab5fSopenharmony_ci export const n = 15; 333af6ab5fSopenharmony_ci export enum E {} 343af6ab5fSopenharmony_ci export function foo(a: number): number { 353af6ab5fSopenharmony_ci return a * a; 363af6ab5fSopenharmony_ci } 373af6ab5fSopenharmony_ci export type N = number; 383af6ab5fSopenharmony_ci 393af6ab5fSopenharmony_ci export namespace XX { 403af6ab5fSopenharmony_ci export class D {} 413af6ab5fSopenharmony_ci } 423af6ab5fSopenharmony_ci 433af6ab5fSopenharmony_ci console.log('Namespace X is initialized'); 443af6ab5fSopenharmony_ci { 453af6ab5fSopenharmony_ci console.log('Block statement'); 463af6ab5fSopenharmony_ci const blockVar = 10; 473af6ab5fSopenharmony_ci } 483af6ab5fSopenharmony_ci} 493af6ab5fSopenharmony_ciconst xc = new X.C(); 503af6ab5fSopenharmony_ciclass IImpl implements X.I { 513af6ab5fSopenharmony_ci f = 10; 523af6ab5fSopenharmony_ci} 533af6ab5fSopenharmony_ciconst xn: X.N = X.foo(100); 543af6ab5fSopenharmony_ciconst d: X.XX.D = new X.XX.D(); 553af6ab5fSopenharmony_ci 563af6ab5fSopenharmony_cinamespace Y.Z { 573af6ab5fSopenharmony_ci export function bar(): void { 583af6ab5fSopenharmony_ci const x = 200; 593af6ab5fSopenharmony_ci } 603af6ab5fSopenharmony_ci} 613af6ab5fSopenharmony_ciY.Z.bar(); 623af6ab5fSopenharmony_ci 633af6ab5fSopenharmony_ci// Namespace used as an object or type. 643af6ab5fSopenharmony_ciconst x = X; 653af6ab5fSopenharmony_ciconsole.log(x.n); 663af6ab5fSopenharmony_ci 673af6ab5fSopenharmony_ciconst xxx = X.XX; 683af6ab5fSopenharmony_ciconst dd = new xxx.D(); 693af6ab5fSopenharmony_ci 703af6ab5fSopenharmony_cifunction xfoo(x: typeof X): void { 713af6ab5fSopenharmony_ci x.foo(25); 723af6ab5fSopenharmony_ci} 733af6ab5fSopenharmony_cixfoo(X); 743af6ab5fSopenharmony_ci 753af6ab5fSopenharmony_cifunction yzbar(yz: typeof Y.Z): void { 763af6ab5fSopenharmony_ci yz.bar(); 773af6ab5fSopenharmony_ci} 783af6ab5fSopenharmony_ciyzbar(Y.Z); 793af6ab5fSopenharmony_ci 803af6ab5fSopenharmony_ciimport { default as def } from 'module'; // default import 813af6ab5fSopenharmony_ci 823af6ab5fSopenharmony_ciinterface I { 833af6ab5fSopenharmony_ci f: number; 843af6ab5fSopenharmony_ci} 853af6ab5fSopenharmony_ciexport default I; // default interface export 863af6ab5fSopenharmony_ciexport default function (n: number) { 873af6ab5fSopenharmony_ci n++; 883af6ab5fSopenharmony_ci} // default function export 893af6ab5fSopenharmony_ciexport default class MyClass {} // default class export 903af6ab5fSopenharmony_ci 913af6ab5fSopenharmony_ci// type-only import 923af6ab5fSopenharmony_ciimport type { APIResponseType } from './api'; 933af6ab5fSopenharmony_ciimport type * as P from 'foo'; 943af6ab5fSopenharmony_ciimport { type T1, type T2 as T3 } from 'foobar'; 953af6ab5fSopenharmony_ci 963af6ab5fSopenharmony_ci// type-only export 973af6ab5fSopenharmony_ciexport type { TypeA as TypeB }; 983af6ab5fSopenharmony_ciexport { type TypeFoo as TypeBar }; 993af6ab5fSopenharmony_ci 1003af6ab5fSopenharmony_ci// Re-exporting 1013af6ab5fSopenharmony_ciexport * from 'module1'; // Ok 1023af6ab5fSopenharmony_ciexport * as Utilities from 'module2'; // Ok 1033af6ab5fSopenharmony_ciexport { SomeFunction, SomeType as OtherType } from 'module3'; // Ok 1043af6ab5fSopenharmony_ci 1053af6ab5fSopenharmony_ciclass Point {} 1063af6ab5fSopenharmony_ciexport = Point; 1073af6ab5fSopenharmony_ci 1083af6ab5fSopenharmony_ciimport Validator = require('module'); 1093af6ab5fSopenharmony_ciimport Button = Components.Button; 1103af6ab5fSopenharmony_ci 1113af6ab5fSopenharmony_cilet m = require('moduleM'); 1123af6ab5fSopenharmony_ciconst k = require('moduleK'); 1133af6ab5fSopenharmony_ci 1143af6ab5fSopenharmony_ciexport { Point }; 1153af6ab5fSopenharmony_ciexport { Point as P }; 1163af6ab5fSopenharmony_ciexport default Point; 1173af6ab5fSopenharmony_ci 1183af6ab5fSopenharmony_ciexport { someFunction1 } from 'module3' 1193af6ab5fSopenharmony_ciexport { default as someFunction2 } from 'module3' 120