diff --git a/README.md b/README.md index 20a4727951bc20d798c2b42689cf160ad3eb5f6c..039980439eb17eb91727998c95f8bc5e512e6e54 100644 --- a/README.md +++ b/README.md @@ -18,12 +18,13 @@ For more infomation, see: [ARK Runtime Subsystem](https://gitee.com/openharmony/ ``` /ark/ts2abc/ ├── test262 # scripts for configuration and running Test262 +├── testTs # system test cases ├── ts2panda - ├── scripts # Dependency scripts - ├── src # Source code directory - ├── templates # Ruby templates - ├── tests # Unit test cases - ├── tools # Tools provided by ts2abc + ├── scripts # dependency scripts + ├── src # source code directory + ├── templates # ruby templates + ├── tests # unit test cases + ├── tools # tools provided by ts2abc └── ts2abc # ts2abc source code ``` @@ -195,9 +196,65 @@ If no parameter is specified for **\[options\]**, an ARK binary file is generat

-

+

--included-files

+ +

-i

+ +

The list of dependent files

+ +

-

+ +

-

+ + +

--record-type

+ +

-p

+ +

Record type info

+ +

-

+ +

true

+ + +

--dts-type-record

+ +

-q

+ +

Record type info for .d.ts files

+ +

-

+ +

false

+ + +

--debug-type

+ +

-g

+ +

Print type-related log

+ +

-

+ +

false

+ + +

--output-type

+ +

-

+ +

Set output type

+ +

-

+ +

false

+ + + For more infomation, please see: [ARK-Runtime-Usage-Guide](https://gitee.com/openharmony/ark_js_runtime/blob/master/docs/ARK-Runtime-Usage-Guide.md). ## Repositories Involved diff --git a/README_zh.md b/README_zh.md index aa001701a561caba60ff45a72005ead08ffcd509..aa611664131b3d5b5971f85cc2547c4df86b771c 100644 --- a/README_zh.md +++ b/README_zh.md @@ -17,7 +17,8 @@ ts2abc组件是方舟运行时子系统的前端工具,支持将JavaScript文 ``` /ark/ts2abc/ -├── test262 # Test262测试配置和运行脚本 +├── test262 # test262测试配置和运行脚本 +├── testTs # 系统测试目录 ├── ts2panda ├── doc # 文档 ├── scripts # 依赖的脚本 @@ -51,6 +52,7 @@ $ node --expose-gc src/index.js [options] file.js 当不输入任何option参数时,默认生成方舟二进制文件。 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

选项

缩写

@@ -195,9 +197,65 @@ $ node --expose-gc src/index.js [options] file.js

-

--included-files

+

-i

+

编译依赖的文件列表

+

-

+

-

+

--record-type

+

-p

+

是否记录类型信息

+

-

+

true

+

--dts-type-record

+

-q

+

记录.d.ts文件的类型信息

+

-

+

false

+

--debug-type

+

-g

+

打印记录的类型信息

+

-

+

false

+

--output-type

+

-

+

设置输出类型

+

-

+

false

+
+ 更多使用说明请参考:[方舟运行时使用指南](https://gitee.com/openharmony/ark_js_runtime/blob/master/docs/ARK-Runtime-Usage-Guide-zh.md) ## 相关仓 diff --git a/ts2panda/src/cmdOptions.ts b/ts2panda/src/cmdOptions.ts index 72bd24cc4f070ddeb5c49ca7e63a01e8ae088255..860845a68353e98f23bdc48435a67ea43da00cfc 100644 --- a/ts2panda/src/cmdOptions.ts +++ b/ts2panda/src/cmdOptions.ts @@ -41,7 +41,7 @@ const ts2pandaOptions = [ { name: 'included-files', alias: 'i', type: String, lazyMultiple: true, defaultValue: [], description: "The list of dependent files." }, { name: 'record-type', alias: 'p', type: Boolean, defaultValue: false, description: "Record type info. Default: true" }, { name: 'dts-type-record', alias: 'q', type: Boolean, defaultValue: false, description: "Record type info for .d.ts files. Default: false" }, - { name: 'debug-type', alias: 'g', type: Boolean, defaultValue: false, description: "Record type info for .d.ts files. Default: false" }, + { name: 'debug-type', alias: 'g', type: Boolean, defaultValue: false, description: "Print type-related log. Default: false" }, { name: 'output-type', type: Boolean, defaultValue: false, description: "set output type."} ] diff --git a/ts2panda/tests/types/function.test.ts b/ts2panda/tests/types/function.test.ts index 4de684483b27e1b232b1f94aab186dcd34b3ee9b..c0f1ccd58adee9d3cbef84ae82373c0951a56471 100644 --- a/ts2panda/tests/types/function.test.ts +++ b/ts2panda/tests/types/function.test.ts @@ -89,8 +89,8 @@ describe("function tests in function.test.ts", function () { expect(compareLiteralBuffer(buff, result.literalBufferArray), "check literal buffer").to.be.true; }); - it("test function with muti parameter", function () { - let fileNames = 'tests/types/function/function_multi_para.ts'; + it("test function with same type of paras and return", function () { + let fileNames = 'tests/types/function/function_same_para_and_return.ts'; let result = compileTsWithType(fileNames); let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); let locals = functionPg!.getLocals(); @@ -98,7 +98,10 @@ describe("function tests in function.test.ts", function () { let extectedVRegTypePair = [ ["#0#num", 1], ["#1#str", 4], - ["#0#emptyFunc", shift + 2], + ["#0#num", 1], + ["#1#str", 4], + ["#0#foo", shift + 2], + ["#1#bar", shift + 3], ] let vreg2TypeMap = createVRegTypePair(extectedVRegTypePair); expect(compareVReg2Type(vreg2TypeMap, locals), "check vreg typeInfo").to.be.true; @@ -106,15 +109,19 @@ describe("function tests in function.test.ts", function () { // check liberalBuffer let expectedBuffValues = [ [ - [2, 0], [2, 2], [2, 0] + [2, 0], [2, 3], [2, 0] ], [ - [2, 3], [2, 0], [2, 0], [5, 'local'], - [2, 0], [2, 0] + [2, 3],[2, 0],[2, 0],[5, 'twoFunctions'], + [2, 0],[2, 0] ], [ - [2, 3], [2, 0], [2, 0], [5, 'emptyFunc'], - [2, 2], [2, 1], [2, 4], [2, 4] + [2, 3],[2, 0],[2, 0],[5, 'foo'], + [2, 2],[2, 1],[2, 4],[2, 3] + ], + [ + [2, 3],[2, 0],[2, 0],[5, 'bar'], + [2, 2],[2, 1],[2, 4],[2, 3] ] ] let buff = createLiteralBufferArray(expectedBuffValues); diff --git a/ts2panda/tests/types/function/function_same_para_and_return.ts b/ts2panda/tests/types/function/function_same_para_and_return.ts new file mode 100644 index 0000000000000000000000000000000000000000..193eb154669c84e4bda35959fd50ee01dbc6ff22 --- /dev/null +++ b/ts2panda/tests/types/function/function_same_para_and_return.ts @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function twoFunctions() { + function foo(num: number, str: string): void { } + function bar(num: number, str: string): void { } +} \ No newline at end of file diff --git a/ts2panda/tests/types/object/object_class.ts b/ts2panda/tests/types/object/object_class.ts index c3a643151b9965dcce27067644e41de5364d03a9..5810fc907e774bb070c89228a55b3d71977f2de5 100644 --- a/ts2panda/tests/types/object/object_class.ts +++ b/ts2panda/tests/types/object/object_class.ts @@ -14,7 +14,7 @@ */ { - class A{}; + class A { }; let a: { a: A; b: string | number; diff --git a/ts2panda/tests/types/primitives.test.ts b/ts2panda/tests/types/primitives.test.ts index 336db5271fd0339c51559b50ec838c9220145732..28fb39e58cd040a98a84589947b6d041caa612b3 100644 --- a/ts2panda/tests/types/primitives.test.ts +++ b/ts2panda/tests/types/primitives.test.ts @@ -26,8 +26,8 @@ import { PrimitiveType } from '../../src/base/typeSystem'; let shift = PrimitiveType._LENGTH; -describe("primitives tests in primitives.test.ts", function () { - it("test primitives in block", function () { +describe("primitives tests in primitives.test.ts", function() { + it("test primitives in block", function() { let fileNames = 'tests/types/primitives/primitives_in_block.ts'; let result = compileTsWithType(fileNames); let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); @@ -57,7 +57,7 @@ describe("primitives tests in primitives.test.ts", function () { expect(compareLiteralBuffer(buff, result.literalBufferArray), "check literal buffer").to.be.true; }); - it("test number in function", function () { + it("test number in function", function() { let fileNames = 'tests/types/primitives/primitives_in_function.ts'; let result = compileTsWithType(fileNames); let functionPg = result.snippetCompiler.getPandaGenByName("numberFunc"); @@ -97,7 +97,7 @@ describe("primitives tests in primitives.test.ts", function () { expect(compareLiteralBuffer(buff, result.literalBufferArray), "check literal buffer").to.be.true; }); - it("test primitives in for", function () { + it("test primitives in for", function() { let fileNames = 'tests/types/primitives/primitives_in_for.ts'; let result = compileTsWithType(fileNames); let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); @@ -128,7 +128,7 @@ describe("primitives tests in primitives.test.ts", function () { expect(compareLiteralBuffer(buff, result.literalBufferArray), "check literal buffer").to.be.true; }); - it("test primitives in if", function () { + it("test primitives in if", function() { let fileNames = 'tests/types/primitives/primitives_in_if.ts'; let result = compileTsWithType(fileNames); let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); @@ -158,7 +158,7 @@ describe("primitives tests in primitives.test.ts", function () { expect(compareLiteralBuffer(buff, result.literalBufferArray), "check literal buffer").to.be.true; }); - it("test primitives in class", function () { + it("test primitives in class", function() { let fileNames = 'tests/types/primitives/primitives_in_class.ts'; let result = compileTsWithType(fileNames); let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); @@ -194,4 +194,60 @@ describe("primitives tests in primitives.test.ts", function () { let buff = createLiteralBufferArray(expectedBuffValues); expect(compareLiteralBuffer(buff, result.literalBufferArray), "check literal buffer").to.be.true; }); + + it("test primitives with only type annotations", function() { + let fileNames = 'tests/types/primitives/primitives_only_type_annotation.ts'; + let result = compileTsWithType(fileNames); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let locals = functionPg!.getLocals(); + // check vreg + let extectedVRegTypePair = [ + ["#3#num", 1], + ["#4#bool", 2], + ["#5#str", 4], + ["#6#sym", 5], + ["#7#nu", 6], + ["#8#und", 7], + ["#9#vd", 3], + ] + let vreg2TypeMap = createVRegTypePair(extectedVRegTypePair); + expect(compareVReg2Type(vreg2TypeMap, locals), "check vreg typeInfo").to.be.true; + + // check liberalBuffer + let expectedBuffValues = [ + [ + [2, 0], [2, 0], [2, 0] + ] + ] + let buff = createLiteralBufferArray(expectedBuffValues); + expect(compareLiteralBuffer(buff, result.literalBufferArray), "check literal buffer").to.be.true; + }); + + it("test primitives without type annotations", function() { + let fileNames = 'tests/types/primitives/primitives_no_type_annotation.ts'; + let result = compileTsWithType(fileNames); + let functionPg = result.snippetCompiler.getPandaGenByName("func_main_0"); + let locals = functionPg!.getLocals(); + // check vreg + let extectedVRegTypePair = [ + ["#3#num", 0], + ["#4#bool", 0], + ["#5#str", 0], + ["#6#sym", 0], + ["#7#nu", 0], + ["#8#und", 0], + ["#9#vd", 0], + ] + let vreg2TypeMap = createVRegTypePair(extectedVRegTypePair); + expect(compareVReg2Type(vreg2TypeMap, locals), "check vreg typeInfo").to.be.true; + + // check liberalBuffer + let expectedBuffValues = [ + [ + [2, 0], [2, 0], [2, 0] + ] + ] + let buff = createLiteralBufferArray(expectedBuffValues); + expect(compareLiteralBuffer(buff, result.literalBufferArray), "check literal buffer").to.be.true; + }); }); diff --git a/ts2panda/tests/types/primitives/primitives_no_type_annotation.ts b/ts2panda/tests/types/primitives/primitives_no_type_annotation.ts new file mode 100644 index 0000000000000000000000000000000000000000..8cbd78ea65d204084ba98fd583375ef9176cb35d --- /dev/null +++ b/ts2panda/tests/types/primitives/primitives_no_type_annotation.ts @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + let num = 3; + let bool = false; + let str = "myStr"; + let sym = Symbol("mySym"); + let nu = null; + let und = undefined; + let vd = undefined; +} diff --git a/ts2panda/tests/types/primitives/primitives_only_type_annotation.ts b/ts2panda/tests/types/primitives/primitives_only_type_annotation.ts new file mode 100644 index 0000000000000000000000000000000000000000..9041051faf52385651ac065911794da7a0d60352 --- /dev/null +++ b/ts2panda/tests/types/primitives/primitives_only_type_annotation.ts @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + let num: number; + let bool: boolean; + let str: string; + let sym: symbol; + let nu: null; + let und: undefined; + let vd: void; +} \ No newline at end of file