mirror of
https://github.com/openharmony/developtools_ace-ets2bundle.git
synced 2026-08-26 18:46:33 -04:00
Signed-off-by: houhaoyu <houhaoyu@huawei.com> Change-Id: I6458c63b6d5b5b10fee1383862d66a776653cebb
This commit is contained in:
@@ -80,6 +80,8 @@ export const STYLES_ATTRIBUTE: Set<string> = new Set();
|
||||
|
||||
export const INTERFACE_NODE_SET: Set<ts.InterfaceDeclaration> = new Set();
|
||||
|
||||
export const INNER_CUSTOM_BUILDER_METHOD: Set<string> = new Set();
|
||||
|
||||
export const JS_BIND_COMPONENTS: Set<string> = new Set([
|
||||
'ForEach', 'LazyForEach', ...GESTURE_TYPE_NAMES, 'Gesture',
|
||||
'PanGestureOption', 'CustomDialogController', 'Storage', 'Scroller', 'SwiperController',
|
||||
|
||||
@@ -74,7 +74,8 @@ import {
|
||||
INNER_STYLE_FUNCTION,
|
||||
GLOBAL_STYLE_FUNCTION,
|
||||
COMMON_ATTRS,
|
||||
CUSTOM_BUILDER_PROPERTIES
|
||||
CUSTOM_BUILDER_PROPERTIES,
|
||||
INNER_CUSTOM_BUILDER_METHOD
|
||||
} from './component_map';
|
||||
import {
|
||||
componentCollection,
|
||||
@@ -91,7 +92,6 @@ import {
|
||||
import { projectConfig } from '../main';
|
||||
import { transformLog, contextGlobal } from './process_ui_syntax';
|
||||
import { props } from './compile_info';
|
||||
import { INNER_CUSTOM_BUILDER_METHOD } from './process_component_class';
|
||||
|
||||
export function processComponentBuild(node: ts.MethodDeclaration,
|
||||
log: LogInfo[]): ts.MethodDeclaration {
|
||||
@@ -113,7 +113,8 @@ export function processComponentBuild(node: ts.MethodDeclaration,
|
||||
export function processComponentBlock(node: ts.Block, isLazy: boolean, log: LogInfo[],
|
||||
isTransition: boolean = false, isInnerBuilder: boolean = false): ts.Block {
|
||||
const newStatements: ts.Statement[] = [];
|
||||
processComponentChild(node, newStatements, log, {isAcceleratePreview: false, line: 0, column: 0, fileName: ''}, isInnerBuilder);
|
||||
processComponentChild(node, newStatements, log,
|
||||
{isAcceleratePreview: false, line: 0, column: 0, fileName: ''}, isInnerBuilder);
|
||||
if (isLazy) {
|
||||
newStatements.unshift(createRenderingInProgress(true));
|
||||
}
|
||||
@@ -209,8 +210,9 @@ function validateEtsComponentNode(node: ts.CallExpression | ts.EtsComponentExpre
|
||||
|
||||
let sourceNode: ts.SourceFile;
|
||||
|
||||
export function processComponentChild(node: ts.Block | ts.SourceFile, newStatements: ts.Statement[], log: LogInfo[],
|
||||
supplement: supplementType = {isAcceleratePreview: false, line: 0, column: 0, fileName: ''}, isInnerBuilder: boolean = false): void {
|
||||
export function processComponentChild(node: ts.Block | ts.SourceFile, newStatements: ts.Statement[],
|
||||
log: LogInfo[], supplement: supplementType = {isAcceleratePreview: false, line: 0, column: 0, fileName: ''},
|
||||
isInnerBuilder: boolean = false): void {
|
||||
if (supplement.isAcceleratePreview) {
|
||||
newsupplement = supplement;
|
||||
const compilerOptions = ts.readConfigFile(
|
||||
|
||||
@@ -55,14 +55,16 @@ import {
|
||||
COMPONENT_SET_AND_LINK,
|
||||
COMPONENT_SET_AND_PROP,
|
||||
COMPONENT_CONSTRUCTOR_UNDEFINED,
|
||||
CUSTOM_COMPONENT
|
||||
CUSTOM_COMPONENT,
|
||||
COMPONENT_CONSTRUCTOR_PARENT
|
||||
} from './pre_define';
|
||||
import {
|
||||
BUILDIN_STYLE_NAMES,
|
||||
CUSTOM_BUILDER_METHOD,
|
||||
INNER_STYLE_FUNCTION,
|
||||
INTERFACE_NODE_SET,
|
||||
STYLES_ATTRIBUTE
|
||||
STYLES_ATTRIBUTE,
|
||||
INNER_CUSTOM_BUILDER_METHOD
|
||||
} from './component_map';
|
||||
import {
|
||||
componentCollection,
|
||||
@@ -276,7 +278,7 @@ function createLocalStroageCallExpression(node: ts.PropertyDeclaration, name: st
|
||||
]
|
||||
);
|
||||
}
|
||||
export const INNER_CUSTOM_BUILDER_METHOD: Set<string> = new Set();
|
||||
|
||||
function processComponentMethod(node: ts.MethodDeclaration, parentComponentName: ts.Identifier,
|
||||
context: ts.TransformationContext, log: LogInfo[], buildCount: BuildCount): ts.MethodDeclaration {
|
||||
let updateItem: ts.MethodDeclaration = node;
|
||||
@@ -301,18 +303,11 @@ function processComponentMethod(node: ts.MethodDeclaration, parentComponentName:
|
||||
} else if (hasDecorator(node, COMPONENT_BUILDER_DECORATOR)) {
|
||||
CUSTOM_BUILDER_METHOD.add(name);
|
||||
INNER_CUSTOM_BUILDER_METHOD.add(name)
|
||||
node.parameters.push(ts.factory.createParameterDeclaration(
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
ts.factory.createIdentifier("parent"),
|
||||
undefined,
|
||||
undefined,
|
||||
undefined
|
||||
))
|
||||
const builderNode: ts.MethodDeclaration = ts.factory.updateMethodDeclaration(node, undefined, node.modifiers,
|
||||
node.asteriskToken, node.name, node.questionToken, node.typeParameters, node.parameters,
|
||||
node.type, processComponentBlock(node.body, false, log, false, true));
|
||||
node.parameters.push(ts.factory.createParameterDeclaration(undefined, undefined, undefined,
|
||||
ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_PARENT), undefined, undefined, ts.factory.createIdentifier("undefined")));
|
||||
const builderNode: ts.MethodDeclaration = ts.factory.updateMethodDeclaration(node, undefined,
|
||||
node.modifiers, node.asteriskToken, node.name, node.questionToken, node.typeParameters,
|
||||
node.parameters, node.type, processComponentBlock(node.body, false, log, false, true));
|
||||
updateItem = processBuildMember(builderNode, context, log);
|
||||
} else if (hasDecorator(node, COMPONENT_STYLES_DECORATOR)) {
|
||||
if (node.parameters && node.parameters.length === 0) {
|
||||
|
||||
@@ -52,7 +52,8 @@ import {
|
||||
COMPONENT_CREATE_FUNCTION,
|
||||
COMPONENT_BUILDERPARAM_DECORATOR,
|
||||
COMPONENT_LOCAL_STORAGE_LINK_DECORATOR,
|
||||
COMPONENT_LOCAL_STORAGE_PROP_DECORATOR
|
||||
COMPONENT_LOCAL_STORAGE_PROP_DECORATOR,
|
||||
COMPONENT_CONSTRUCTOR_PARENT
|
||||
} from './pre_define';
|
||||
import {
|
||||
forbiddenUseStateType,
|
||||
@@ -593,7 +594,13 @@ function addCustomComponentId(node: ts.NewExpression, componentName: string, isI
|
||||
argumentsArray = [ts.factory.createObjectLiteralExpression([], true)];
|
||||
}
|
||||
argumentsArray.unshift(ts.factory.createStringLiteral((++componentInfo.id).toString()),
|
||||
isInnerBuilder ? ts.factory.createIdentifier('parent') : ts.factory.createThis());
|
||||
isInnerBuilder ? ts.factory.createConditionalExpression(
|
||||
ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_PARENT),
|
||||
ts.factory.createToken(ts.SyntaxKind.QuestionToken),
|
||||
ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_PARENT),
|
||||
ts.factory.createToken(ts.SyntaxKind.ColonToken),
|
||||
ts.factory.createThis()
|
||||
) : ts.factory.createThis());
|
||||
node =
|
||||
ts.factory.updateNewExpression(node, node.expression, node.typeArguments, argumentsArray);
|
||||
} else if (argumentsArray) {
|
||||
|
||||
@@ -32,7 +32,8 @@ import {
|
||||
COMPONENT_CONSTRUCTOR_UNDEFINED,
|
||||
CUSTOM_COMPONENT_NEEDS_UPDATE_FUNCTION,
|
||||
CUSTOM_COMPONENT_MARK_STATIC_FUNCTION,
|
||||
COMPONENT_COMMON
|
||||
COMPONENT_COMMON,
|
||||
COMPONENT_CONSTRUCTOR_PARENT
|
||||
} from './pre_define';
|
||||
import {
|
||||
propertyCollection,
|
||||
@@ -109,7 +110,8 @@ export function processCustomComponent(node: ts.ExpressionStatement, newStatemen
|
||||
ts.factory.createIdentifier(COMPONENT_CREATE_FUNCTION), null)));
|
||||
bindComponentAttr(node, ts.factory.createIdentifier(COMPONENT_COMMON), newStatements, log);
|
||||
}
|
||||
addCustomComponent(node, newStatements, customComponentNewExpression, log, name, componentNode, isInnerBuilder);
|
||||
addCustomComponent(node, newStatements, customComponentNewExpression, log, name, componentNode,
|
||||
isInnerBuilder);
|
||||
if (hasChainCall) {
|
||||
newStatements.push(ts.factory.createExpressionStatement(
|
||||
createFunction(ts.factory.createIdentifier(COMPONENT_COMMON),
|
||||
@@ -140,7 +142,8 @@ function changeNodeFromCallToArrow(node: ts.CallExpression): ts.ArrowFunction {
|
||||
}
|
||||
|
||||
function addCustomComponent(node: ts.ExpressionStatement, newStatements: ts.Statement[],
|
||||
newNode: ts.NewExpression, log: LogInfo[], name: string, componentNode: ts.CallExpression, isInnerBuilder: boolean = false): void {
|
||||
newNode: ts.NewExpression, log: LogInfo[], name: string, componentNode: ts.CallExpression,
|
||||
isInnerBuilder: boolean = false): void {
|
||||
if (ts.isNewExpression(newNode)) {
|
||||
const propertyArray: ts.ObjectLiteralElementLike[] = [];
|
||||
validateCustomComponentPrams(componentNode, name, propertyArray, log);
|
||||
@@ -149,7 +152,8 @@ function addCustomComponent(node: ts.ExpressionStatement, newStatements: ts.Stat
|
||||
}
|
||||
|
||||
function addCustomComponentStatements(node: ts.ExpressionStatement, newStatements: ts.Statement[],
|
||||
newNode: ts.NewExpression, name: string, props: ts.ObjectLiteralElementLike[], isInnerBuilder: boolean = false): void {
|
||||
newNode: ts.NewExpression, name: string, props: ts.ObjectLiteralElementLike[],
|
||||
isInnerBuilder: boolean = false): void {
|
||||
const id: string = componentInfo.id.toString();
|
||||
newStatements.push(createFindChildById(id, name, isInnerBuilder), createCustomComponentIfStatement(id,
|
||||
ts.factory.updateExpressionStatement(node, createViewCreate(newNode)),
|
||||
@@ -360,7 +364,14 @@ function createFindChildById(id: string, name: string, isInnerBuilder: boolean =
|
||||
[ts.factory.createVariableDeclaration(ts.factory.createIdentifier(
|
||||
`${CUSTOM_COMPONENT_EARLIER_CREATE_CHILD}${id}`), undefined, ts.factory.createTypeReferenceNode(
|
||||
ts.factory.createIdentifier(name)), ts.factory.createAsExpression(ts.factory.createCallExpression(
|
||||
ts.factory.createPropertyAccessExpression(isInnerBuilder ? ts.factory.createIdentifier('parent') : ts.factory.createThis(), ts.factory.createIdentifier(
|
||||
ts.factory.createPropertyAccessExpression(isInnerBuilder ?
|
||||
ts.factory.createParenthesizedExpression(ts.factory.createConditionalExpression(
|
||||
ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_PARENT),
|
||||
ts.factory.createToken(ts.SyntaxKind.QuestionToken),
|
||||
ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_PARENT),
|
||||
ts.factory.createToken(ts.SyntaxKind.ColonToken),
|
||||
ts.factory.createThis()
|
||||
)) : ts.factory.createThis(), ts.factory.createIdentifier(
|
||||
`${CUSTOM_COMPONENT_FUNCTION_FIND_CHILD_BY_ID}`)), undefined, [ts.factory.createStringLiteral(id)]),
|
||||
ts.factory.createTypeReferenceNode(ts.factory.createIdentifier(name))))], ts.NodeFlags.Let));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user