@idlizer/arktscgen 2.1.2 → 2.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/libarkts-copy/README.md +36 -0
- package/build/libarkts-copy/generator/options.json5 +113 -44
- package/build/libarkts-copy/native/src/bridges.cc +70 -2
- package/build/libarkts-copy/native/src/generated/bridges.cc +700 -200
- package/build/libarkts-copy/package.json +27 -15
- package/build/libarkts-copy/src/Es2pandaNativeModule.ts +42 -4
- package/build/libarkts-copy/src/InteropNativeModule.ts +2 -1
- package/build/libarkts-copy/src/arkts-api/AbstractVisitor.ts +50 -0
- package/build/libarkts-copy/src/arkts-api/class-by-peer.ts +8 -6
- package/build/libarkts-copy/src/arkts-api/factory/nodeFactory.ts +95 -117
- package/build/libarkts-copy/src/arkts-api/index.ts +3 -1
- package/build/libarkts-copy/src/arkts-api/node-cache.ts +35 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ArrayExpression.ts +42 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ArrowFunctionExpression.ts +49 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/AssignmentExpression.ts +50 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/{createCallExpression.ts → CallExpression.ts} +27 -4
- package/build/libarkts-copy/src/arkts-api/node-utilities/ClassDefinition.ts +73 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ClassProperty.ts +41 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ETSFunctionType.ts +65 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ETSImportDeclaration.ts +63 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ETSParameterExpression.ts +60 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ETSStructDeclaration.ts +31 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ETSTuple.ts +31 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/MemberExpression.ts +41 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/MethodDefinition.ts +75 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/{createNumberLiteral.ts → NumberLiteral.ts} +15 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ObjectExpression.ts +34 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/ScriptFunction.ts +99 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/TSInterfaceDeclaration.ts +61 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/TSTypeAliasDeclaration.ts +60 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/TSTypeParameter.ts +39 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/TSTypeReferencePart.ts +36 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/TryStatement.ts +44 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/VariableDeclaration.ts +54 -0
- package/build/libarkts-copy/src/arkts-api/node-utilities/VariableDeclarator.ts +37 -0
- package/build/libarkts-copy/src/arkts-api/peers/AstNode.ts +15 -14
- package/build/libarkts-copy/src/arkts-api/peers/ImportPathManager.ts +30 -0
- package/build/libarkts-copy/src/arkts-api/peers/Program.ts +4 -4
- package/build/libarkts-copy/src/arkts-api/peers/SourcePosition.ts +38 -0
- package/build/libarkts-copy/src/arkts-api/static/global.ts +5 -0
- package/build/libarkts-copy/src/arkts-api/static/profiler.ts +25 -0
- package/build/libarkts-copy/src/arkts-api/utilities/private.ts +13 -11
- package/build/libarkts-copy/src/arkts-api/utilities/public.ts +68 -10
- package/build/libarkts-copy/src/arkts-api/visitor.ts +175 -42
- package/build/libarkts-copy/src/generated/Es2pandaEnums.ts +504 -458
- package/build/libarkts-copy/src/generated/Es2pandaNativeModule.ts +225 -75
- package/build/libarkts-copy/src/generated/factory.ts +21 -43
- package/build/libarkts-copy/src/generated/index.ts +24 -3
- package/build/libarkts-copy/src/generated/peers/AnnotatedAstNode.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/AnnotatedExpression.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/AnnotatedStatement.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/AnnotationDeclaration.ts +7 -7
- package/build/libarkts-copy/src/generated/peers/AnnotationUsage.ts +12 -12
- package/build/libarkts-copy/src/generated/peers/ArrayExpression.ts +10 -5
- package/build/libarkts-copy/src/generated/peers/ArrowFunctionExpression.ts +7 -7
- package/build/libarkts-copy/src/generated/peers/AssertStatement.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/AssignmentExpression.ts +13 -7
- package/build/libarkts-copy/src/generated/peers/AstDumper.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/AstVerifier.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/AstVisitor.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/AwaitExpression.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/BigIntLiteral.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/BinaryExpression.ts +14 -7
- package/build/libarkts-copy/src/generated/peers/BindingProps.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/BlockExpression.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/BlockStatement.ts +15 -5
- package/build/libarkts-copy/src/generated/peers/BooleanLiteral.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/BreakStatement.ts +8 -5
- package/build/libarkts-copy/src/generated/peers/CallExpression.ts +8 -8
- package/build/libarkts-copy/src/generated/peers/CatchClause.ts +6 -6
- package/build/libarkts-copy/src/generated/peers/ChainExpression.ts +12 -5
- package/build/libarkts-copy/src/generated/peers/CharLiteral.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/ClassDeclaration.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/ClassDefinition.ts +30 -15
- package/build/libarkts-copy/src/generated/peers/ClassElement.ts +7 -8
- package/build/libarkts-copy/src/generated/peers/ClassExpression.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/ClassProperty.ts +21 -5
- package/build/libarkts-copy/src/generated/peers/ClassStaticBlock.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/CodeGen.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/ConditionalExpression.ts +7 -7
- package/build/libarkts-copy/src/generated/peers/ContinueStatement.ts +8 -5
- package/build/libarkts-copy/src/generated/peers/DebuggerStatement.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/Declaration.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/Decorator.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/DirectEvalExpression.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/DoWhileStatement.ts +6 -6
- package/build/libarkts-copy/src/generated/peers/DynamicImportData.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/ETSClassLiteral.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/ETSDynamicFunctionType.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/ETSFunctionType.ts +15 -15
- package/build/libarkts-copy/src/generated/peers/ETSImportDeclaration.ts +26 -17
- package/build/libarkts-copy/src/generated/peers/ETSKeyofType.ts +53 -0
- package/build/libarkts-copy/src/generated/peers/ETSModule.ts +6 -6
- package/build/libarkts-copy/src/generated/peers/ETSNewArrayInstanceExpression.ts +11 -6
- package/build/libarkts-copy/src/generated/peers/ETSNewClassInstanceExpression.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/ETSNewMultiDimArrayInstanceExpression.ts +11 -6
- package/build/libarkts-copy/src/generated/peers/ETSNullType.ts +6 -6
- package/build/libarkts-copy/src/generated/peers/ETSPackageDeclaration.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/ETSParameterExpression.ts +10 -10
- package/build/libarkts-copy/src/generated/peers/ETSPrimitiveType.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/ETSReExportDeclaration.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/ETSStringLiteralType.ts +50 -0
- package/build/libarkts-copy/src/generated/peers/ETSStructDeclaration.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/ETSTuple.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/ETSTypeReference.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/ETSTypeReferencePart.ts +8 -8
- package/build/libarkts-copy/src/generated/peers/ETSUndefinedType.ts +6 -6
- package/build/libarkts-copy/src/generated/peers/ETSUnionType.ts +7 -7
- package/build/libarkts-copy/src/generated/peers/ETSWildcardType.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/EmptyStatement.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/ErrorLogger.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/ExportAllDeclaration.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/ExportDefaultDeclaration.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/ExportNamedDeclaration.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/ExportSpecifier.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/Expression.ts +4 -5
- package/build/libarkts-copy/src/generated/peers/ExpressionStatement.ts +6 -6
- package/build/libarkts-copy/src/generated/peers/ForInStatement.ts +7 -7
- package/build/libarkts-copy/src/generated/peers/ForOfStatement.ts +7 -7
- package/build/libarkts-copy/src/generated/peers/ForUpdateStatement.ts +7 -7
- package/build/libarkts-copy/src/generated/peers/FunctionDecl.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/FunctionDeclaration.ts +8 -8
- package/build/libarkts-copy/src/generated/peers/FunctionExpression.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/FunctionSignature.ts +6 -7
- package/build/libarkts-copy/src/generated/peers/IRNode.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/Identifier.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/IfStatement.ts +9 -9
- package/build/libarkts-copy/src/generated/peers/ImportDeclaration.ts +10 -10
- package/build/libarkts-copy/src/generated/peers/ImportDefaultSpecifier.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/ImportExpression.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/ImportNamespaceSpecifier.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/ImportSource.ts +1 -15
- package/build/libarkts-copy/src/generated/peers/ImportSpecifier.ts +14 -6
- package/build/libarkts-copy/src/generated/peers/IndexInfo.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/InterfaceDecl.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/LabelPair.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/LabelledStatement.ts +6 -6
- package/build/libarkts-copy/src/generated/peers/Literal.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/LoopStatement.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/MaybeOptionalExpression.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/MemberExpression.ts +24 -8
- package/build/libarkts-copy/src/generated/peers/MetaProperty.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/MethodDefinition.ts +25 -8
- package/build/libarkts-copy/src/generated/peers/NamedType.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/NewExpression.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/NullLiteral.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/NumberLiteral.ts +19 -4
- package/build/libarkts-copy/src/generated/peers/ObjectDescriptor.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/ObjectExpression.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/OmittedExpression.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/OpaqueTypeNode.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/OverloadInfo.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/PrefixAssertionExpression.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/Property.ts +6 -6
- package/build/libarkts-copy/src/generated/peers/RegExpLiteral.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/ReturnStatement.ts +8 -5
- package/build/libarkts-copy/src/generated/peers/ScopeFindResult.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/ScriptFunction.ts +16 -11
- package/build/libarkts-copy/src/generated/peers/ScriptFunctionData.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/SequenceExpression.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/SignatureInfo.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/SourcePosition.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/SourceRange.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/SpreadElement.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/SrcDumper.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/Statement.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/StringLiteral.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/SuperExpression.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/SwitchCaseStatement.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/SwitchStatement.ts +6 -6
- package/build/libarkts-copy/src/generated/peers/TSAnyKeyword.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSArrayType.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSAsExpression.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/TSBigintKeyword.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSBooleanKeyword.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSClassImplements.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/TSConditionalType.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSConstructorType.ts +6 -6
- package/build/libarkts-copy/src/generated/peers/TSEnumDeclaration.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/TSEnumMember.ts +6 -6
- package/build/libarkts-copy/src/generated/peers/TSExternalModuleReference.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSFunctionType.ts +6 -6
- package/build/libarkts-copy/src/generated/peers/TSImportEqualsDeclaration.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSImportType.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSIndexSignature.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSIndexedAccessType.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSInferType.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSInterfaceBody.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/TSInterfaceDeclaration.ts +10 -10
- package/build/libarkts-copy/src/generated/peers/TSInterfaceHeritage.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/TSIntersectionType.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSLiteralType.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSMappedType.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSMethodSignature.ts +7 -7
- package/build/libarkts-copy/src/generated/peers/TSModuleBlock.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSModuleDeclaration.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSNamedTupleMember.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/TSNeverKeyword.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSNonNullExpression.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/TSNullKeyword.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSNumberKeyword.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSObjectKeyword.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSParameterProperty.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSParenthesizedType.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSPropertySignature.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/TSQualifiedName.ts +7 -7
- package/build/libarkts-copy/src/generated/peers/TSSignatureDeclaration.ts +6 -6
- package/build/libarkts-copy/src/generated/peers/TSStringKeyword.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSThisType.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSTupleType.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSTypeAliasDeclaration.ts +8 -8
- package/build/libarkts-copy/src/generated/peers/TSTypeAssertion.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSTypeLiteral.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSTypeOperator.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSTypeParameter.ts +7 -7
- package/build/libarkts-copy/src/generated/peers/TSTypeParameterDeclaration.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSTypeParameterInstantiation.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSTypePredicate.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSTypeQuery.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSTypeReference.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSUndefinedKeyword.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSUnionType.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSUnknownKeyword.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TSVoidKeyword.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TaggedTemplateExpression.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TemplateElement.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TemplateLiteral.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/ThisExpression.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/ThrowStatement.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/TryStatement.ts +10 -6
- package/build/libarkts-copy/src/generated/peers/TypeNode.ts +2 -3
- package/build/libarkts-copy/src/generated/peers/TypedAstNode.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/TypedStatement.ts +1 -2
- package/build/libarkts-copy/src/generated/peers/TypeofExpression.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/UnaryExpression.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/UndefinedLiteral.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/UpdateExpression.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/VReg.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/ValidationInfo.ts +4 -4
- package/build/libarkts-copy/src/generated/peers/VariableDeclaration.ts +5 -5
- package/build/libarkts-copy/src/generated/peers/VariableDeclarator.ts +7 -7
- package/build/libarkts-copy/src/generated/peers/VerificationContext.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/VerifierMessage.ts +35 -0
- package/build/libarkts-copy/src/generated/peers/WhileStatement.ts +6 -6
- package/build/libarkts-copy/src/generated/peers/YieldExpression.ts +4 -4
- package/build/libarkts-copy/src/index.ts +17 -0
- package/build/libarkts-copy/src/reexport-for-generated.ts +1 -1
- package/build/libarkts-copy/src/utils.ts +307 -9
- package/build/libarkts-copy/tsconfig.json +4 -4
- package/lib/index.js +1516 -1120
- package/package.json +6 -6
- package/templates/factory.ts +0 -1
- package/templates/peer.ts +0 -1
- package/build/libarkts-copy/src/Es2pandaEnums.ts +0 -183
- package/build/libarkts-copy/src/arkts-api/node-utilities/createScriptFunction.ts +0 -55
- package/build/libarkts-copy/src/es2panda.ts +0 -277
- package/build/libarkts-copy/src/generated/node-map.ts +0 -182
- package/build/libarkts-copy/src/generated/peers/ETSLaunchExpression.ts +0 -57
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idlizer/arktscgen",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"bin": "lib/index.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"license": "Apache-2.0",
|
|
20
20
|
"keywords": [],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@idlizer/core": "2.1.
|
|
22
|
+
"@idlizer/core": "2.1.5",
|
|
23
23
|
"@types/node": "^18.0.0",
|
|
24
24
|
"commander": "^10.0.0",
|
|
25
25
|
"typescript": "^4.9.5"
|
|
@@ -39,11 +39,11 @@
|
|
|
39
39
|
"scripts": {
|
|
40
40
|
"compile:core": "npm run --prefix ../core compile",
|
|
41
41
|
"compile": "npm run compile:core && rollup -c",
|
|
42
|
-
"external:test": "npm run --prefix ../external/
|
|
43
|
-
"external:clean": "rimraf ../external/
|
|
44
|
-
"external:generate": "npm run compile && node . --panda-sdk-path ../external/incremental/tools/panda/node_modules/@panda/sdk/ --output-dir ../external/
|
|
42
|
+
"external:test": "npm run --prefix ../external/ui2abc/libarkts run",
|
|
43
|
+
"external:clean": "rimraf ../external/ui2abc/libarkts/src/generated/peers",
|
|
44
|
+
"external:generate": "npm run compile && node . --panda-sdk-path ../external/incremental/tools/panda/node_modules/@panda/sdk/ --output-dir ../external/ui2abc/ --options-file ../external/ui2abc/libarkts/generator/options.json5 --debug --no-initialize",
|
|
45
45
|
"all": "npm run compile && npm run external:clean && npm run external:generate && npm run external:test",
|
|
46
|
-
"prepack": "npm run compile && mkdir -p ./build && cp -r ../external/
|
|
46
|
+
"prepack": "npm run compile && mkdir -p ./build && cp -r ../external/ui2abc/libarkts ./build/libarkts-copy",
|
|
47
47
|
"postpack": "rimraf ./build/libarkts-copy",
|
|
48
48
|
"test:pack": "node ./tools/main.mjs test-pack",
|
|
49
49
|
"test:all": "npm run all && npm run test:pack",
|
package/templates/factory.ts
CHANGED
package/templates/peer.ts
CHANGED
|
@@ -1,183 +0,0 @@
|
|
|
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
|
-
|
|
16
|
-
// HANDWRITTEN (for now)
|
|
17
|
-
|
|
18
|
-
export enum Es2pandaAstNodeType {
|
|
19
|
-
AST_NODE_TYPE_ARROW_FUNCTION_EXPRESSION,
|
|
20
|
-
AST_NODE_TYPE_ANNOTATION_DECLARATION,
|
|
21
|
-
AST_NODE_TYPE_ANNOTATION_USAGE,
|
|
22
|
-
AST_NODE_TYPE_ASSERT_STATEMENT,
|
|
23
|
-
AST_NODE_TYPE_AWAIT_EXPRESSION,
|
|
24
|
-
AST_NODE_TYPE_BIGINT_LITERAL,
|
|
25
|
-
AST_NODE_TYPE_BINARY_EXPRESSION,
|
|
26
|
-
AST_NODE_TYPE_BLOCK_STATEMENT,
|
|
27
|
-
AST_NODE_TYPE_BOOLEAN_LITERAL,
|
|
28
|
-
AST_NODE_TYPE_BREAK_STATEMENT,
|
|
29
|
-
AST_NODE_TYPE_CALL_EXPRESSION,
|
|
30
|
-
AST_NODE_TYPE_CATCH_CLAUSE,
|
|
31
|
-
AST_NODE_TYPE_CHAIN_EXPRESSION,
|
|
32
|
-
AST_NODE_TYPE_CHAR_LITERAL,
|
|
33
|
-
AST_NODE_TYPE_CLASS_DEFINITION,
|
|
34
|
-
AST_NODE_TYPE_CLASS_DECLARATION,
|
|
35
|
-
AST_NODE_TYPE_CLASS_EXPRESSION,
|
|
36
|
-
AST_NODE_TYPE_CLASS_PROPERTY,
|
|
37
|
-
AST_NODE_TYPE_CLASS_STATIC_BLOCK,
|
|
38
|
-
AST_NODE_TYPE_CONDITIONAL_EXPRESSION,
|
|
39
|
-
AST_NODE_TYPE_CONTINUE_STATEMENT,
|
|
40
|
-
AST_NODE_TYPE_DEBUGGER_STATEMENT,
|
|
41
|
-
AST_NODE_TYPE_DECORATOR,
|
|
42
|
-
AST_NODE_TYPE_DIRECT_EVAL,
|
|
43
|
-
AST_NODE_TYPE_DO_WHILE_STATEMENT,
|
|
44
|
-
AST_NODE_TYPE_EMPTY_STATEMENT,
|
|
45
|
-
AST_NODE_TYPE_EXPORT_ALL_DECLARATION,
|
|
46
|
-
AST_NODE_TYPE_EXPORT_DEFAULT_DECLARATION,
|
|
47
|
-
AST_NODE_TYPE_EXPORT_NAMED_DECLARATION,
|
|
48
|
-
AST_NODE_TYPE_EXPORT_SPECIFIER,
|
|
49
|
-
AST_NODE_TYPE_EXPRESSION_STATEMENT,
|
|
50
|
-
AST_NODE_TYPE_FOR_IN_STATEMENT,
|
|
51
|
-
AST_NODE_TYPE_FOR_OF_STATEMENT,
|
|
52
|
-
AST_NODE_TYPE_FOR_UPDATE_STATEMENT,
|
|
53
|
-
AST_NODE_TYPE_FUNCTION_DECLARATION,
|
|
54
|
-
AST_NODE_TYPE_FUNCTION_EXPRESSION,
|
|
55
|
-
AST_NODE_TYPE_IDENTIFIER,
|
|
56
|
-
AST_NODE_TYPE_DUMMYNODE,
|
|
57
|
-
AST_NODE_TYPE_IF_STATEMENT,
|
|
58
|
-
AST_NODE_TYPE_IMPORT_DECLARATION,
|
|
59
|
-
AST_NODE_TYPE_IMPORT_EXPRESSION,
|
|
60
|
-
AST_NODE_TYPE_IMPORT_DEFAULT_SPECIFIER,
|
|
61
|
-
AST_NODE_TYPE_IMPORT_NAMESPACE_SPECIFIER,
|
|
62
|
-
AST_NODE_TYPE_IMPORT_SPECIFIER,
|
|
63
|
-
AST_NODE_TYPE_LABELLED_STATEMENT,
|
|
64
|
-
AST_NODE_TYPE_MEMBER_EXPRESSION,
|
|
65
|
-
AST_NODE_TYPE_META_PROPERTY_EXPRESSION,
|
|
66
|
-
AST_NODE_TYPE_METHOD_DEFINITION,
|
|
67
|
-
AST_NODE_TYPE_NAMED_TYPE,
|
|
68
|
-
AST_NODE_TYPE_NEW_EXPRESSION,
|
|
69
|
-
AST_NODE_TYPE_NULL_LITERAL,
|
|
70
|
-
AST_NODE_TYPE_UNDEFINED_LITERAL,
|
|
71
|
-
AST_NODE_TYPE_NUMBER_LITERAL,
|
|
72
|
-
AST_NODE_TYPE_OMITTED_EXPRESSION,
|
|
73
|
-
AST_NODE_TYPE_PREFIX_ASSERTION_EXPRESSION,
|
|
74
|
-
AST_NODE_TYPE_PROPERTY,
|
|
75
|
-
AST_NODE_TYPE_REGEXP_LITERAL,
|
|
76
|
-
AST_NODE_TYPE_REEXPORT_STATEMENT,
|
|
77
|
-
AST_NODE_TYPE_RETURN_STATEMENT,
|
|
78
|
-
AST_NODE_TYPE_SCRIPT_FUNCTION,
|
|
79
|
-
AST_NODE_TYPE_SEQUENCE_EXPRESSION,
|
|
80
|
-
AST_NODE_TYPE_STRING_LITERAL,
|
|
81
|
-
AST_NODE_TYPE_ETS_NULL_TYPE,
|
|
82
|
-
AST_NODE_TYPE_ETS_UNDEFINED_TYPE,
|
|
83
|
-
AST_NODE_TYPE_ETS_NEVER_TYPE,
|
|
84
|
-
AST_NODE_TYPE_ETS_STRING_LITERAL_TYPE,
|
|
85
|
-
AST_NODE_TYPE_ETS_FUNCTION_TYPE,
|
|
86
|
-
AST_NODE_TYPE_ETS_WILDCARD_TYPE,
|
|
87
|
-
AST_NODE_TYPE_ETS_PRIMITIVE_TYPE,
|
|
88
|
-
AST_NODE_TYPE_ETS_PACKAGE_DECLARATION,
|
|
89
|
-
AST_NODE_TYPE_ETS_CLASS_LITERAL,
|
|
90
|
-
AST_NODE_TYPE_ETS_TYPE_REFERENCE,
|
|
91
|
-
AST_NODE_TYPE_ETS_TYPE_REFERENCE_PART,
|
|
92
|
-
AST_NODE_TYPE_ETS_UNION_TYPE,
|
|
93
|
-
AST_NODE_TYPE_ETS_LAUNCH_EXPRESSION,
|
|
94
|
-
AST_NODE_TYPE_ETS_NEW_ARRAY_INSTANCE_EXPRESSION,
|
|
95
|
-
AST_NODE_TYPE_ETS_NEW_MULTI_DIM_ARRAY_INSTANCE_EXPRESSION,
|
|
96
|
-
AST_NODE_TYPE_ETS_NEW_CLASS_INSTANCE_EXPRESSION,
|
|
97
|
-
AST_NODE_TYPE_ETS_IMPORT_DECLARATION,
|
|
98
|
-
AST_NODE_TYPE_ETS_PARAMETER_EXPRESSION,
|
|
99
|
-
AST_NODE_TYPE_ETS_TUPLE,
|
|
100
|
-
AST_NODE_TYPE_ETS_MODULE,
|
|
101
|
-
AST_NODE_TYPE_SUPER_EXPRESSION,
|
|
102
|
-
AST_NODE_TYPE_STRUCT_DECLARATION,
|
|
103
|
-
AST_NODE_TYPE_SWITCH_CASE_STATEMENT,
|
|
104
|
-
AST_NODE_TYPE_SWITCH_STATEMENT,
|
|
105
|
-
AST_NODE_TYPE_TS_ENUM_DECLARATION,
|
|
106
|
-
AST_NODE_TYPE_TS_ENUM_MEMBER,
|
|
107
|
-
AST_NODE_TYPE_TS_EXTERNAL_MODULE_REFERENCE,
|
|
108
|
-
AST_NODE_TYPE_TS_NUMBER_KEYWORD,
|
|
109
|
-
AST_NODE_TYPE_TS_ANY_KEYWORD,
|
|
110
|
-
AST_NODE_TYPE_TS_STRING_KEYWORD,
|
|
111
|
-
AST_NODE_TYPE_TS_BOOLEAN_KEYWORD,
|
|
112
|
-
AST_NODE_TYPE_TS_VOID_KEYWORD,
|
|
113
|
-
AST_NODE_TYPE_TS_UNDEFINED_KEYWORD,
|
|
114
|
-
AST_NODE_TYPE_TS_UNKNOWN_KEYWORD,
|
|
115
|
-
AST_NODE_TYPE_TS_OBJECT_KEYWORD,
|
|
116
|
-
AST_NODE_TYPE_TS_BIGINT_KEYWORD,
|
|
117
|
-
AST_NODE_TYPE_TS_NEVER_KEYWORD,
|
|
118
|
-
AST_NODE_TYPE_TS_NON_NULL_EXPRESSION,
|
|
119
|
-
AST_NODE_TYPE_TS_NULL_KEYWORD,
|
|
120
|
-
AST_NODE_TYPE_TS_ARRAY_TYPE,
|
|
121
|
-
AST_NODE_TYPE_TS_UNION_TYPE,
|
|
122
|
-
AST_NODE_TYPE_TS_TYPE_LITERAL,
|
|
123
|
-
AST_NODE_TYPE_TS_PROPERTY_SIGNATURE,
|
|
124
|
-
AST_NODE_TYPE_TS_METHOD_SIGNATURE,
|
|
125
|
-
AST_NODE_TYPE_TS_SIGNATURE_DECLARATION,
|
|
126
|
-
AST_NODE_TYPE_TS_PARENT_TYPE,
|
|
127
|
-
AST_NODE_TYPE_TS_LITERAL_TYPE,
|
|
128
|
-
AST_NODE_TYPE_TS_INFER_TYPE,
|
|
129
|
-
AST_NODE_TYPE_TS_CONDITIONAL_TYPE,
|
|
130
|
-
AST_NODE_TYPE_TS_IMPORT_TYPE,
|
|
131
|
-
AST_NODE_TYPE_TS_INTERSECTION_TYPE,
|
|
132
|
-
AST_NODE_TYPE_TS_MAPPED_TYPE,
|
|
133
|
-
AST_NODE_TYPE_TS_MODULE_BLOCK,
|
|
134
|
-
AST_NODE_TYPE_TS_THIS_TYPE,
|
|
135
|
-
AST_NODE_TYPE_TS_TYPE_OPERATOR,
|
|
136
|
-
AST_NODE_TYPE_TS_TYPE_PARAMETER,
|
|
137
|
-
AST_NODE_TYPE_TS_TYPE_PARAMETER_DECLARATION,
|
|
138
|
-
AST_NODE_TYPE_TS_TYPE_PARAMETER_INSTANTIATION,
|
|
139
|
-
AST_NODE_TYPE_TS_TYPE_PREDICATE,
|
|
140
|
-
AST_NODE_TYPE_TS_PARAMETER_PROPERTY,
|
|
141
|
-
AST_NODE_TYPE_TS_MODULE_DECLARATION,
|
|
142
|
-
AST_NODE_TYPE_TS_IMPORT_EQUALS_DECLARATION,
|
|
143
|
-
AST_NODE_TYPE_TS_FUNCTION_TYPE,
|
|
144
|
-
AST_NODE_TYPE_TS_CONSTRUCTOR_TYPE,
|
|
145
|
-
AST_NODE_TYPE_TS_TYPE_ALIAS_DECLARATION,
|
|
146
|
-
AST_NODE_TYPE_TS_TYPE_REFERENCE,
|
|
147
|
-
AST_NODE_TYPE_TS_QUALIFIED_NAME,
|
|
148
|
-
AST_NODE_TYPE_TS_INDEXED_ACCESS_TYPE,
|
|
149
|
-
AST_NODE_TYPE_TS_INTERFACE_DECLARATION,
|
|
150
|
-
AST_NODE_TYPE_TS_INTERFACE_BODY,
|
|
151
|
-
AST_NODE_TYPE_TS_INTERFACE_HERITAGE,
|
|
152
|
-
AST_NODE_TYPE_TS_TUPLE_TYPE,
|
|
153
|
-
AST_NODE_TYPE_TS_NAMED_TUPLE_MEMBER,
|
|
154
|
-
AST_NODE_TYPE_TS_INDEX_SIGNATURE,
|
|
155
|
-
AST_NODE_TYPE_TS_TYPE_QUERY,
|
|
156
|
-
AST_NODE_TYPE_TS_AS_EXPRESSION,
|
|
157
|
-
AST_NODE_TYPE_TS_CLASS_IMPLEMENTS,
|
|
158
|
-
AST_NODE_TYPE_TS_TYPE_ASSERTION,
|
|
159
|
-
AST_NODE_TYPE_TAGGED_TEMPLATE_EXPRESSION,
|
|
160
|
-
AST_NODE_TYPE_TEMPLATE_ELEMENT,
|
|
161
|
-
AST_NODE_TYPE_TEMPLATE_LITERAL,
|
|
162
|
-
AST_NODE_TYPE_THIS_EXPRESSION,
|
|
163
|
-
AST_NODE_TYPE_TYPEOF_EXPRESSION,
|
|
164
|
-
AST_NODE_TYPE_THROW_STATEMENT,
|
|
165
|
-
AST_NODE_TYPE_TRY_STATEMENT,
|
|
166
|
-
AST_NODE_TYPE_UNARY_EXPRESSION,
|
|
167
|
-
AST_NODE_TYPE_UPDATE_EXPRESSION,
|
|
168
|
-
AST_NODE_TYPE_VARIABLE_DECLARATION,
|
|
169
|
-
AST_NODE_TYPE_VARIABLE_DECLARATOR,
|
|
170
|
-
AST_NODE_TYPE_WHILE_STATEMENT,
|
|
171
|
-
AST_NODE_TYPE_YIELD_EXPRESSION,
|
|
172
|
-
AST_NODE_TYPE_OPAQUE_TYPE_NODE,
|
|
173
|
-
AST_NODE_TYPE_BLOCK_EXPRESSION,
|
|
174
|
-
AST_NODE_TYPE_ERROR_TYPE_NODE,
|
|
175
|
-
AST_NODE_TYPE_ARRAY_EXPRESSION,
|
|
176
|
-
AST_NODE_TYPE_ARRAY_PATTERN,
|
|
177
|
-
AST_NODE_TYPE_ASSIGNMENT_EXPRESSION,
|
|
178
|
-
AST_NODE_TYPE_ASSIGNMENT_PATTERN,
|
|
179
|
-
AST_NODE_TYPE_OBJECT_EXPRESSION,
|
|
180
|
-
AST_NODE_TYPE_OBJECT_PATTERN,
|
|
181
|
-
AST_NODE_TYPE_SPREAD_ELEMENT,
|
|
182
|
-
AST_NODE_TYPE_REST_ELEMENT,
|
|
183
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 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
|
-
|
|
16
|
-
import { AnnotationUsage } from "../../generated/peers/AnnotationUsage"
|
|
17
|
-
import { AstNode } from "../peers/AstNode"
|
|
18
|
-
import { Expression } from "../../generated/peers/Expression"
|
|
19
|
-
import { FunctionSignature } from "../../generated/peers/FunctionSignature"
|
|
20
|
-
import { Identifier } from "../../generated/peers/Identifier"
|
|
21
|
-
import { ScriptFunction } from "../../generated/peers/ScriptFunction"
|
|
22
|
-
import { TSTypeParameterDeclaration } from "../../generated/peers/TSTypeParameterDeclaration"
|
|
23
|
-
import { TypeNode } from "../../generated/peers/TypeNode"
|
|
24
|
-
import { Es2pandaModifierFlags, Es2pandaScriptFunctionFlags } from "../../generated/Es2pandaEnums"
|
|
25
|
-
|
|
26
|
-
export function createScriptFunction(
|
|
27
|
-
databody: AstNode | undefined,
|
|
28
|
-
typeParams: TSTypeParameterDeclaration | undefined,
|
|
29
|
-
params: readonly Expression[],
|
|
30
|
-
returnTypeAnnotation: TypeNode | undefined,
|
|
31
|
-
hasReceiver: boolean,
|
|
32
|
-
datafuncFlags: Es2pandaScriptFunctionFlags,
|
|
33
|
-
dataflags: Es2pandaModifierFlags,
|
|
34
|
-
ident: Identifier | undefined,
|
|
35
|
-
annotations: readonly AnnotationUsage[] | undefined,
|
|
36
|
-
) {
|
|
37
|
-
const res = ScriptFunction.createScriptFunction(
|
|
38
|
-
databody,
|
|
39
|
-
FunctionSignature.createFunctionSignature(
|
|
40
|
-
typeParams,
|
|
41
|
-
params,
|
|
42
|
-
returnTypeAnnotation,
|
|
43
|
-
hasReceiver,
|
|
44
|
-
),
|
|
45
|
-
datafuncFlags,
|
|
46
|
-
dataflags
|
|
47
|
-
)
|
|
48
|
-
if (ident) {
|
|
49
|
-
res.setIdent(ident)
|
|
50
|
-
}
|
|
51
|
-
if (annotations) {
|
|
52
|
-
res.setAnnotations(annotations)
|
|
53
|
-
}
|
|
54
|
-
return res
|
|
55
|
-
}
|
|
@@ -1,277 +0,0 @@
|
|
|
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
|
-
|
|
16
|
-
import * as fs from "node:fs"
|
|
17
|
-
import * as path from "node:path"
|
|
18
|
-
import { global } from "./arkts-api/static/global"
|
|
19
|
-
import { Command } from "commander"
|
|
20
|
-
import { isNumber, throwError, withWarning, filterSource } from "./utils"
|
|
21
|
-
import { Es2pandaContextState } from "./generated/Es2pandaEnums"
|
|
22
|
-
import { AstNode, Config, Context, createETSModulefromContext, ETSModule, proceedToState } from "./arkts-api"
|
|
23
|
-
|
|
24
|
-
function parseCommandLineArgs() {
|
|
25
|
-
const commander = new Command()
|
|
26
|
-
.option('--file, <char>', 'Path to file to be compiled')
|
|
27
|
-
.option('--arktsconfig, <char>', 'Path to arkts configuration file')
|
|
28
|
-
.option('--ets-module', 'Do nothing, legacy compatibility')
|
|
29
|
-
.option('--output, <char>', 'The name of result file')
|
|
30
|
-
.option('--dump-plugin-ast', 'Dump ast before and after each plugin')
|
|
31
|
-
.option('--restart-stages', 'Restart the compiler to proceed to next stage')
|
|
32
|
-
.option('--generate-decl', 'Generate declaration files')
|
|
33
|
-
.option('--decl-arktsconfig, <char>', 'Path to arkts configutation file for the binary compilation')
|
|
34
|
-
.parse(process.argv)
|
|
35
|
-
.opts()
|
|
36
|
-
|
|
37
|
-
const restOptions = commander.args
|
|
38
|
-
|
|
39
|
-
const filePath = path.resolve(commander.file)
|
|
40
|
-
const configPath = path.resolve(commander.arktsconfig)
|
|
41
|
-
const outputPath = path.resolve(commander.output)
|
|
42
|
-
if (!fs.existsSync(filePath)) {
|
|
43
|
-
throw new Error(`File path doesn't exist: ${filePath}`)
|
|
44
|
-
}
|
|
45
|
-
if (!fs.existsSync(configPath)) {
|
|
46
|
-
throw new Error(`Arktsconfig path doesn't exist: ${configPath}`)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const dumpAst = commander.dumpPluginAst ?? false
|
|
50
|
-
const restartStages = commander.restartStages ?? false
|
|
51
|
-
const generateDecl = commander.generateDecl ?? false
|
|
52
|
-
const dConfigPath = path.resolve(commander.declArktsconfig ?? commander.arktsconfig)
|
|
53
|
-
|
|
54
|
-
return { filePath, configPath, outputPath, dumpAst, restartStages, generateDecl, dConfigPath }
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function insertPlugin(plugin: (ast: AstNode) => void, state: Es2pandaContextState, dumpAst: boolean): AstNode {
|
|
58
|
-
proceedToState(state)
|
|
59
|
-
const script = createETSModulefromContext()
|
|
60
|
-
if (script === undefined) {
|
|
61
|
-
throwError(`Failed to receive ast from es2panda`)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (dumpAst) {
|
|
65
|
-
console.log(`BEFORE ${stateName(state)}:`)
|
|
66
|
-
console.log(filterSource(script.dumpSrc()))
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const transform = plugin
|
|
70
|
-
transform?.(script)
|
|
71
|
-
|
|
72
|
-
if (dumpAst) {
|
|
73
|
-
console.log(`AFTER ${stateName(state)}:`)
|
|
74
|
-
console.log(filterSource(script.dumpSrc()))
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
setAllParents(script)
|
|
78
|
-
return script
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function restartCompiler() {
|
|
82
|
-
console.log("restarting")
|
|
83
|
-
const ast = createETSModulefromContext()
|
|
84
|
-
const srcText = filterSource(ast.dumpSrc())
|
|
85
|
-
global.es2panda._DestroyContext(global.context)
|
|
86
|
-
global.compilerContext = Context.createFromString(srcText)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function restartCompilerWithConfig(configPath: string, filePath: string, stdlib: string, outputPath: string) {
|
|
90
|
-
console.log("restarting with another config")
|
|
91
|
-
const srcText = filterSource(createETSModulefromContext().dumpSrc())
|
|
92
|
-
global.es2panda._DestroyContext(global.context)
|
|
93
|
-
global.es2panda._DestroyConfig(global.config)
|
|
94
|
-
global.config = Config.create([
|
|
95
|
-
'_',
|
|
96
|
-
'--arktsconfig',
|
|
97
|
-
configPath,
|
|
98
|
-
filePath,
|
|
99
|
-
'--extension',
|
|
100
|
-
'ets',
|
|
101
|
-
'--stdlib',
|
|
102
|
-
stdlib,
|
|
103
|
-
'--output',
|
|
104
|
-
outputPath
|
|
105
|
-
]).peer
|
|
106
|
-
global.compilerContext = Context.createFromString(srcText)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const defaultPandaSdk = "../../../incremental/tools/panda/node_modules/@panda/sdk"
|
|
110
|
-
function invokeWithPlugins(
|
|
111
|
-
configPath: string,
|
|
112
|
-
baseUrl: string,
|
|
113
|
-
filePath: string,
|
|
114
|
-
outputPath: string,
|
|
115
|
-
pluginsByState: Map<Es2pandaContextState, ((ast: AstNode) => void)[]>,
|
|
116
|
-
dumpAst: boolean,
|
|
117
|
-
restart: boolean,
|
|
118
|
-
generateDecl: boolean,
|
|
119
|
-
dConfigPath: string,
|
|
120
|
-
): void {
|
|
121
|
-
const source = fs.readFileSync(filePath).toString()
|
|
122
|
-
const sdk = process.env.PANDA_SDK_PATH ?? withWarning(
|
|
123
|
-
defaultPandaSdk,
|
|
124
|
-
`PANDA_SDK_PATH not set, assuming ${defaultPandaSdk}`
|
|
125
|
-
)
|
|
126
|
-
const stdlib = `${sdk}/ets/stdlib`
|
|
127
|
-
|
|
128
|
-
global.filePath = filePath
|
|
129
|
-
global.filePathFromPackageRoot = path.relative(path.join(path.dirname(configPath), baseUrl), filePath)
|
|
130
|
-
global.config = Config.create([
|
|
131
|
-
'_',
|
|
132
|
-
'--arktsconfig',
|
|
133
|
-
configPath,
|
|
134
|
-
filePath,
|
|
135
|
-
'--extension',
|
|
136
|
-
'ets',
|
|
137
|
-
'--stdlib',
|
|
138
|
-
stdlib,
|
|
139
|
-
'--output',
|
|
140
|
-
outputPath
|
|
141
|
-
]).peer
|
|
142
|
-
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
|
|
143
|
-
global.compilerContext = Context.createFromString(source)
|
|
144
|
-
|
|
145
|
-
console.log("PLUGINS: ", pluginsByState.size, pluginsByState)
|
|
146
|
-
|
|
147
|
-
if (pluginsByState.size == 0) {
|
|
148
|
-
proceedToState(Es2pandaContextState.ES2PANDA_STATE_BIN_GENERATED)
|
|
149
|
-
return
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
pluginsByState.get(Es2pandaContextState.ES2PANDA_STATE_PARSED)?.forEach(plugin => {
|
|
153
|
-
insertPlugin(plugin, Es2pandaContextState.ES2PANDA_STATE_PARSED, dumpAst)
|
|
154
|
-
if (restart) {
|
|
155
|
-
restartCompiler()
|
|
156
|
-
}
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
pluginsByState.get(Es2pandaContextState.ES2PANDA_STATE_CHECKED)?.forEach(plugin => {
|
|
160
|
-
insertPlugin(plugin, Es2pandaContextState.ES2PANDA_STATE_CHECKED, dumpAst)
|
|
161
|
-
// TODO: Normally we need just to proceed to a given state,
|
|
162
|
-
// but the compiler crashes now, so we restart
|
|
163
|
-
if (restart) {
|
|
164
|
-
restartCompiler()
|
|
165
|
-
}
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
if (configPath !== dConfigPath) {
|
|
169
|
-
proceedToState(Es2pandaContextState.ES2PANDA_STATE_PARSED)
|
|
170
|
-
restartCompilerWithConfig(dConfigPath, filePath, stdlib, outputPath)
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (generateDecl) {
|
|
174
|
-
proceedToState(Es2pandaContextState.ES2PANDA_STATE_PARSED)
|
|
175
|
-
generateDeclFromCurrentContext(filePath)
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
proceedToState(Es2pandaContextState.ES2PANDA_STATE_BIN_GENERATED)
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function generateDeclFromCurrentContext(filePath: string) {
|
|
182
|
-
const ext = path.extname(filePath)
|
|
183
|
-
const dirs = path.dirname(filePath).split(path.sep)
|
|
184
|
-
const last = dirs.lastIndexOf("ets")
|
|
185
|
-
if (last == -1) {
|
|
186
|
-
throw `Do not apply --generate-decl for files not matching "**/ets/**" file path: ${filePath}`
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
let declFile = ""
|
|
190
|
-
if (last !== -1) { // temporary workaround (ets dir -> dets dir)
|
|
191
|
-
const declDir = path.join('/', ...dirs.map((it, index) => index == last ? "dets" : it))
|
|
192
|
-
fs.mkdirSync(declDir, { recursive: true })
|
|
193
|
-
declFile = path.join(declDir, path.basename(filePath))
|
|
194
|
-
} else { // extension change (.ets -> .d.ets)
|
|
195
|
-
declFile = path.join(path.dirname(filePath), `${path.basename(filePath, ext)}.d${ext}`)
|
|
196
|
-
}
|
|
197
|
-
console.log(`Emiting declaration file to`, declFile)
|
|
198
|
-
|
|
199
|
-
const exports = [...fs.readFileSync(filePath).toString().matchAll(/export .* from .*(\n|$)/g)]
|
|
200
|
-
|
|
201
|
-
let out = [
|
|
202
|
-
filterSource(global.compilerContext.program.astNode.dumpSrc()),
|
|
203
|
-
...exports.map((it) => it[0])
|
|
204
|
-
].join('\n')
|
|
205
|
-
|
|
206
|
-
// TODO: exports are lost on visiting
|
|
207
|
-
const exportAstNodes = ["class", "abstract class", "interface", "@interface", "type", "enum", "final class"]
|
|
208
|
-
exportAstNodes.forEach((astNodeText) => {
|
|
209
|
-
out = out.replaceAll(`\n${astNodeText}`, `\nexport ${astNodeText}`)
|
|
210
|
-
}
|
|
211
|
-
)
|
|
212
|
-
|
|
213
|
-
// TODO: global functions are not exported
|
|
214
|
-
fs.writeFileSync(declFile,
|
|
215
|
-
out
|
|
216
|
-
.replaceAll("\nexport abstract class ETSGLOBAL", "\nabstract class ETSGLOBAL")
|
|
217
|
-
)
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
function setAllParents(ast: AstNode) {
|
|
221
|
-
global.es2panda._AstNodeUpdateAll(global.context, ast.peer)
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
function loadPlugin(configDir: string, jsonPlugin: any) {
|
|
225
|
-
const pluginPath = jsonPlugin.transform ?? throwError(`arktsconfig plugins objects should specify transform`)
|
|
226
|
-
/** TODO: read and pass plugin options */
|
|
227
|
-
const plugin = (pluginPath.startsWith(".") || pluginPath.startsWith("/")) ?
|
|
228
|
-
path.resolve(configDir, pluginPath) : pluginPath
|
|
229
|
-
|
|
230
|
-
const pluginFunction: (config?: any) => any = require(plugin).default(jsonPlugin)
|
|
231
|
-
return pluginFunction
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
function selectPlugins(configDir: string, plugins: any[], stage: string): ((arg: AstNode) => AstNode)[] | undefined {
|
|
235
|
-
const selected = plugins
|
|
236
|
-
.filter(it => (it.stage == stage))
|
|
237
|
-
.map(it => loadPlugin(configDir, it))
|
|
238
|
-
if (selected.length == 0) {
|
|
239
|
-
return undefined
|
|
240
|
-
}
|
|
241
|
-
return selected
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
function stateName(value: Es2pandaContextState): string {
|
|
245
|
-
return Es2pandaContextState[value].substring("ES2PANDA_STATE_".length)
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
function readAndSortPlugins(configDir: string, plugins: any[]) {
|
|
249
|
-
const pluginsByState = new Map<Es2pandaContextState, ((ast: AstNode) => void)[]>()
|
|
250
|
-
|
|
251
|
-
Object.values(Es2pandaContextState)
|
|
252
|
-
.filter(isNumber)
|
|
253
|
-
.forEach(it => {
|
|
254
|
-
const selected = selectPlugins(configDir, plugins, stateName(it).toLowerCase())
|
|
255
|
-
if (selected) pluginsByState.set(
|
|
256
|
-
it,
|
|
257
|
-
selected
|
|
258
|
-
)
|
|
259
|
-
})
|
|
260
|
-
|
|
261
|
-
return pluginsByState
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
export function main() {
|
|
265
|
-
const { filePath, configPath, outputPath, dumpAst, restartStages, generateDecl, dConfigPath } = parseCommandLineArgs()
|
|
266
|
-
const arktsconfig = JSON.parse(fs.readFileSync(configPath).toString())
|
|
267
|
-
const configDir = path.dirname(configPath)
|
|
268
|
-
const compilerOptions = arktsconfig.compilerOptions ?? throwError(`arktsconfig should specify compilerOptions`)
|
|
269
|
-
const baseUrl = compilerOptions.baseUrl
|
|
270
|
-
const plugins = compilerOptions.plugins ?? []
|
|
271
|
-
|
|
272
|
-
const pluginsByState = readAndSortPlugins(configDir, plugins)
|
|
273
|
-
|
|
274
|
-
invokeWithPlugins(configPath, baseUrl, filePath, outputPath, pluginsByState, dumpAst, restartStages, generateDecl, dConfigPath)
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
main()
|