mirror of
https://github.com/openharmony/developtools_ace-ets2bundle.git
synced 2026-07-21 03:55:23 -04:00
fix buildParam export. Signed-off-by: lihong <lihong67@huawei.com> Change-Id: Ice1252c57d16b88718af008dad1b0293072a85b4
This commit is contained in:
@@ -76,7 +76,10 @@ import {
|
||||
COMMON_ATTRS,
|
||||
CUSTOM_BUILDER_PROPERTIES
|
||||
} from './component_map';
|
||||
import { componentCollection } from './validate_ui_syntax';
|
||||
import {
|
||||
componentCollection,
|
||||
builderParamObjectCollection
|
||||
} from './validate_ui_syntax';
|
||||
import { processCustomComponent } from './process_custom_component';
|
||||
import {
|
||||
LogType,
|
||||
@@ -84,7 +87,6 @@ import {
|
||||
componentInfo,
|
||||
createFunction
|
||||
} from './utils';
|
||||
import { builderParamObjectCollection } from './process_component_member';
|
||||
import { projectConfig } from '../main';
|
||||
import { transformLog, contextGlobal } from './process_ui_syntax';
|
||||
import { props } from './compile_info';
|
||||
|
||||
@@ -115,8 +115,6 @@ export const decoratorParamSet: Set<string> = new Set();
|
||||
|
||||
export const stateObjectCollection: Set<string> = new Set();
|
||||
|
||||
export const builderParamObjectCollection: Map<string, Set<string>> = new Map();
|
||||
|
||||
export class UpdateResult {
|
||||
private itemUpdate: boolean = false;
|
||||
private ctorUpdate: boolean = false;
|
||||
@@ -420,21 +418,12 @@ function createUpdateParams(name: ts.Identifier, decorator: string): ts.Statemen
|
||||
updateParamsNode = createUpdateParamsWithIf(name);
|
||||
break;
|
||||
case COMPONENT_PROP_DECORATOR:
|
||||
case COMPONENT_BUILDERPARAM_DECORATOR:
|
||||
updateParamsNode = createUpdateParamsWithoutIf(name);
|
||||
break;
|
||||
case COMPONENT_OBJECT_LINK_DECORATOR:
|
||||
updateParamsNode = createUpdateParamsWithSet(name);
|
||||
break;
|
||||
case COMPONENT_BUILDERPARAM_DECORATOR:
|
||||
if (decorator === COMPONENT_BUILDERPARAM_DECORATOR) {
|
||||
if (!builderParamObjectCollection.get(componentCollection.currentClassName)) {
|
||||
builderParamObjectCollection.set(componentCollection.currentClassName, new Set([]));
|
||||
}
|
||||
builderParamObjectCollection.get(componentCollection.currentClassName)
|
||||
.add(name.escapedText.toString());
|
||||
}
|
||||
updateParamsNode = createUpdateParamsWithoutIf(name);
|
||||
break;
|
||||
}
|
||||
return updateParamsNode;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,8 @@ import {
|
||||
provideCollection,
|
||||
consumeCollection,
|
||||
objectLinkCollection,
|
||||
isStaticViewCollection
|
||||
isStaticViewCollection,
|
||||
builderParamObjectCollection
|
||||
} from './validate_ui_syntax';
|
||||
import {
|
||||
propAndLinkDecorators,
|
||||
@@ -52,7 +53,6 @@ import {
|
||||
createViewCreate,
|
||||
createCustomComponentNewExpression
|
||||
} from './process_component_member';
|
||||
import { builderParamObjectCollection } from './process_component_member';
|
||||
import {
|
||||
LogType,
|
||||
LogInfo,
|
||||
|
||||
@@ -41,7 +41,8 @@ import {
|
||||
observedClassCollection,
|
||||
enumCollection,
|
||||
getComponentSet,
|
||||
IComponentSet
|
||||
IComponentSet,
|
||||
builderParamObjectCollection
|
||||
} from './validate_ui_syntax';
|
||||
import { LogInfo, LogType } from './utils';
|
||||
import { projectConfig } from '../main';
|
||||
@@ -150,7 +151,8 @@ function visitAllNode(node: ts.Node, defaultNameFromParent: string, asNameFromPa
|
||||
setDependencies(defaultNameFromParent,
|
||||
linkCollection.get(node.expression.escapedText.toString()),
|
||||
propertyCollection.get(node.expression.escapedText.toString()),
|
||||
propCollection.get(node.expression.escapedText.toString()));
|
||||
propCollection.get(node.expression.escapedText.toString()),
|
||||
builderParamObjectCollection.get(node.expression.escapedText.toString()));
|
||||
}
|
||||
addDefaultExport(node);
|
||||
}
|
||||
@@ -177,7 +179,8 @@ function visitAllNode(node: ts.Node, defaultNameFromParent: string, asNameFromPa
|
||||
}
|
||||
setDependencies(asExportName, linkCollection.get(asExportPropertyName),
|
||||
propertyCollection.get(asExportPropertyName),
|
||||
propCollection.get(asExportPropertyName));
|
||||
propCollection.get(asExportPropertyName),
|
||||
builderParamObjectCollection.get(asExportPropertyName));
|
||||
}
|
||||
asExportCollection.set(item.propertyName.escapedText.toString(), item.name.escapedText.toString());
|
||||
}
|
||||
@@ -198,7 +201,7 @@ function visitAllNode(node: ts.Node, defaultNameFromParent: string, asNameFromPa
|
||||
ts.isIdentifier(item.name) && asNameFromParent.has(item.name.escapedText.toString())) {
|
||||
asNameFromParent.set(item.propertyName.escapedText.toString(),
|
||||
asNameFromParent.get(item.name.escapedText.toString()));
|
||||
defaultCollection.add(item.name.escapedText.toString());
|
||||
defaultCollection.add(item.name.escapedText.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -267,12 +270,13 @@ function addDependencies(node: ts.ClassDeclaration, defaultNameFromParent: strin
|
||||
node.modifiers[1] && node.modifiers[0].kind === ts.SyntaxKind.ExportKeyword &&
|
||||
node.modifiers[1].kind === ts.SyntaxKind.DefaultKeyword) {
|
||||
setDependencies(defaultNameFromParent, ComponentSet.links, ComponentSet.properties,
|
||||
ComponentSet.props);
|
||||
ComponentSet.props, ComponentSet.builderParams);
|
||||
} else if (asNameFromParent.has(componentName)) {
|
||||
setDependencies(asNameFromParent.get(componentName), ComponentSet.links, ComponentSet.properties,
|
||||
ComponentSet.props);
|
||||
ComponentSet.props, ComponentSet.builderParams);
|
||||
} else {
|
||||
setDependencies(componentName, ComponentSet.links, ComponentSet.properties, ComponentSet.props);
|
||||
setDependencies(componentName, ComponentSet.links, ComponentSet.properties, ComponentSet.props,
|
||||
ComponentSet.builderParams);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,18 +292,24 @@ function addDefaultExport(node: ts.ClassDeclaration | ts.ExportAssignment): void
|
||||
setDependencies(CUSTOM_COMPONENT_DEFAULT,
|
||||
linkCollection.has(CUSTOM_COMPONENT_DEFAULT) ?
|
||||
new Set([...linkCollection.get(CUSTOM_COMPONENT_DEFAULT), ...linkCollection.get(name)]) :
|
||||
linkCollection.get(name), propertyCollection.has(CUSTOM_COMPONENT_DEFAULT) ?
|
||||
new Set([...propertyCollection.get(CUSTOM_COMPONENT_DEFAULT), ...propertyCollection.get(name)]) :
|
||||
propertyCollection.get(name), propCollection.has(CUSTOM_COMPONENT_DEFAULT) ?
|
||||
linkCollection.get(name),
|
||||
propertyCollection.has(CUSTOM_COMPONENT_DEFAULT) ?
|
||||
new Set([...propertyCollection.get(CUSTOM_COMPONENT_DEFAULT),
|
||||
...propertyCollection.get(name)]) : propertyCollection.get(name),
|
||||
propCollection.has(CUSTOM_COMPONENT_DEFAULT) ?
|
||||
new Set([...propCollection.get(CUSTOM_COMPONENT_DEFAULT), ...propCollection.get(name)]) :
|
||||
propCollection.get(name));
|
||||
propCollection.get(name),
|
||||
builderParamObjectCollection.has(CUSTOM_COMPONENT_DEFAULT) ?
|
||||
new Set([...builderParamObjectCollection.get(CUSTOM_COMPONENT_DEFAULT),
|
||||
...builderParamObjectCollection.get(name)]) : builderParamObjectCollection.get(name));
|
||||
}
|
||||
|
||||
function setDependencies(component: string, linkArray: Set<string>, propertyArray: Set<string>,
|
||||
propArray: Set<string>): void {
|
||||
propArray: Set<string>, builderParamArray: Set<string>): void {
|
||||
linkCollection.set(component, linkArray);
|
||||
propertyCollection.set(component, propertyArray);
|
||||
propCollection.set(component, propArray);
|
||||
builderParamObjectCollection.set(component, builderParamArray);
|
||||
componentCollection.customComponents.add(component);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,8 @@ import {
|
||||
TTOGGLE_CHECKBOX,
|
||||
TOGGLE_SWITCH,
|
||||
COMPONENT_BUTTON,
|
||||
COMPONENT_TOGGLE
|
||||
COMPONENT_TOGGLE,
|
||||
COMPONENT_BUILDERPARAM_DECORATOR
|
||||
} from './pre_define';
|
||||
import {
|
||||
INNER_COMPONENT_NAMES,
|
||||
@@ -94,6 +95,7 @@ export interface IComponentSet {
|
||||
objectLinks: Set<string>;
|
||||
localStorageLink: Map<string, Set<string>>;
|
||||
localStorageProp: Map<string, Set<string>>;
|
||||
builderParams: Set<string>;
|
||||
}
|
||||
|
||||
export const componentCollection: ComponentCollection = {
|
||||
@@ -121,6 +123,7 @@ export const storageLinkCollection: Map<string, Set<string>> = new Map();
|
||||
export const provideCollection: Map<string, Set<string>> = new Map();
|
||||
export const consumeCollection: Map<string, Set<string>> = new Map();
|
||||
export const objectLinkCollection: Map<string, Set<string>> = new Map();
|
||||
export const builderParamObjectCollection: Map<string, Set<string>> = new Map();
|
||||
export const localStorageLinkCollection: Map<string, Map<string, Set<string>>> = new Map();
|
||||
export const localStoragePropCollection: Map<string, Map<string, Set<string>>> = new Map();
|
||||
|
||||
@@ -683,6 +686,7 @@ function collectComponentProps(node: ts.StructDeclaration): void {
|
||||
objectLinkCollection.set(componentName, ComponentSet.objectLinks);
|
||||
localStorageLinkCollection.set(componentName, ComponentSet.localStorageLink);
|
||||
localStoragePropCollection.set(componentName, ComponentSet.localStorageProp);
|
||||
builderParamObjectCollection.set(componentName, ComponentSet.builderParams);
|
||||
}
|
||||
|
||||
export function getComponentSet(node: ts.StructDeclaration): IComponentSet {
|
||||
@@ -696,13 +700,14 @@ export function getComponentSet(node: ts.StructDeclaration): IComponentSet {
|
||||
const provides: Set<string> = new Set();
|
||||
const consumes: Set<string> = new Set();
|
||||
const objectLinks: Set<string> = new Set();
|
||||
const builderParams: Set<string> = new Set();
|
||||
const localStorageLink: Map<string, Set<string>> = new Map();
|
||||
const localStorageProp: Map<string, Set<string>> = new Map();
|
||||
traversalComponentProps(node, properties, regulars, states, links, props, storageProps,
|
||||
storageLinks, provides, consumes, objectLinks, localStorageLink, localStorageProp);
|
||||
storageLinks, provides, consumes, objectLinks, localStorageLink, localStorageProp, builderParams);
|
||||
return {
|
||||
properties, regulars, states, links, props, storageProps, storageLinks, provides,
|
||||
consumes, objectLinks, localStorageLink, localStorageProp
|
||||
consumes, objectLinks, localStorageLink, localStorageProp, builderParams
|
||||
};
|
||||
}
|
||||
|
||||
@@ -710,7 +715,8 @@ function traversalComponentProps(node: ts.StructDeclaration, properties: Set<str
|
||||
regulars: Set<string>, states: Set<string>, links: Set<string>, props: Set<string>,
|
||||
storageProps: Set<string>, storageLinks: Set<string>, provides: Set<string>,
|
||||
consumes: Set<string>, objectLinks: Set<string>,
|
||||
localStorageLink: Map<string, Set<string>>, localStorageProp: Map<string, Set<string>>): void {
|
||||
localStorageLink: Map<string, Set<string>>, localStorageProp: Map<string, Set<string>>,
|
||||
builderParams: Set<string>): void {
|
||||
let isStatic: boolean = true;
|
||||
if (node.members) {
|
||||
const currentMethodCollection: Set<string> = new Set();
|
||||
@@ -727,7 +733,8 @@ function traversalComponentProps(node: ts.StructDeclaration, properties: Set<str
|
||||
if (INNER_COMPONENT_MEMBER_DECORATORS.has(decoratorName)) {
|
||||
dollarCollection.add('$' + propertyName);
|
||||
collectionStates(item.decorators[i], decoratorName, propertyName, states, links, props, storageProps,
|
||||
storageLinks, provides, consumes, objectLinks, localStorageLink, localStorageProp);
|
||||
storageLinks, provides, consumes, objectLinks, localStorageLink, localStorageProp,
|
||||
builderParams);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -744,7 +751,8 @@ function traversalComponentProps(node: ts.StructDeclaration, properties: Set<str
|
||||
function collectionStates(node: ts.Decorator, decorator: string, name: string,
|
||||
states: Set<string>, links: Set<string>, props: Set<string>, storageProps: Set<string>,
|
||||
storageLinks: Set<string>, provides: Set<string>, consumes: Set<string>, objectLinks: Set<string>,
|
||||
localStorageLink: Map<string, Set<string>>, localStorageProp: Map<string, Set<string>>): void {
|
||||
localStorageLink: Map<string, Set<string>>, localStorageProp: Map<string, Set<string>>,
|
||||
builderParams: Set<string>): void {
|
||||
switch (decorator) {
|
||||
case COMPONENT_STATE_DECORATOR:
|
||||
states.add(name);
|
||||
@@ -770,6 +778,9 @@ function collectionStates(node: ts.Decorator, decorator: string, name: string,
|
||||
case COMPONENT_OBJECT_LINK_DECORATOR:
|
||||
objectLinks.add(name);
|
||||
break;
|
||||
case COMPONENT_BUILDERPARAM_DECORATOR:
|
||||
builderParams.add(name);
|
||||
break;
|
||||
case COMPONENT_LOCAL_STORAGE_LINK_DECORATOR :
|
||||
collectionlocalStorageParam(node, name, localStorageLink);
|
||||
break;
|
||||
|
||||
@@ -23,4 +23,17 @@ export struct TestComponent {
|
||||
.fontSize(32)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Component
|
||||
export struct CustomContainerExport {
|
||||
header: string = "";
|
||||
@BuilderParam closer: () => void;
|
||||
build() {
|
||||
Column() {
|
||||
Text(this.header)
|
||||
.fontSize(50)
|
||||
this.closer()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
exports.source = `
|
||||
import { CustomContainerExport } from './test/pages/TestComponent';
|
||||
@Component
|
||||
struct CustomContainer {
|
||||
header: string = "";
|
||||
@@ -60,6 +61,15 @@ struct CustomContainerUser {
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
CustomContainerExport({
|
||||
header: this.text,
|
||||
}){
|
||||
Column(){
|
||||
specificParam("111", "22")
|
||||
}.onClick(()=>{
|
||||
this.text = "changeHeader"
|
||||
})
|
||||
}
|
||||
Row(){
|
||||
CustomContainer({
|
||||
header: this.text,
|
||||
@@ -84,7 +94,10 @@ struct CustomContainerUser {
|
||||
}
|
||||
`
|
||||
exports.expectResult =
|
||||
`class CustomContainer extends View {
|
||||
`"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const TestComponent_1 = require("./test/pages/TestComponent");
|
||||
class CustomContainer extends View {
|
||||
constructor(compilerAssignedUniqueChildId, parent, params) {
|
||||
super(compilerAssignedUniqueChildId, parent);
|
||||
this.header = "";
|
||||
@@ -178,10 +191,38 @@ class CustomContainerUser extends View {
|
||||
}
|
||||
render() {
|
||||
Column.create();
|
||||
Row.create();
|
||||
let earlierCreatedChild_2 = this.findChildById("2");
|
||||
if (earlierCreatedChild_2 == undefined) {
|
||||
View.create(new CustomContainer("2", this, {
|
||||
View.create(new TestComponent_1.CustomContainerExport("2", this, {
|
||||
header: this.text,
|
||||
closer: () => {
|
||||
Column.create();
|
||||
Column.onClick(() => {
|
||||
this.text = "changeHeader";
|
||||
});
|
||||
specificParam("111", "22");
|
||||
Column.pop();
|
||||
}
|
||||
}));
|
||||
}
|
||||
else {
|
||||
earlierCreatedChild_2.updateWithValueParams({
|
||||
header: this.text,
|
||||
closer: () => {
|
||||
Column.create();
|
||||
Column.onClick(() => {
|
||||
this.text = "changeHeader";
|
||||
});
|
||||
specificParam("111", "22");
|
||||
Column.pop();
|
||||
}
|
||||
});
|
||||
View.create(earlierCreatedChild_2);
|
||||
}
|
||||
Row.create();
|
||||
let earlierCreatedChild_3 = this.findChildById("3");
|
||||
if (earlierCreatedChild_3 == undefined) {
|
||||
View.create(new CustomContainer("3", this, {
|
||||
header: this.text,
|
||||
content: this.specificParam,
|
||||
callContent: this.callSpecificParam("callContent1", 'callContent2'),
|
||||
@@ -189,19 +230,19 @@ class CustomContainerUser extends View {
|
||||
}));
|
||||
}
|
||||
else {
|
||||
earlierCreatedChild_2.updateWithValueParams({
|
||||
earlierCreatedChild_3.updateWithValueParams({
|
||||
header: this.text,
|
||||
content: this.specificParam,
|
||||
callContent: this.callSpecificParam("callContent1", 'callContent2'),
|
||||
footer: "Footer"
|
||||
});
|
||||
View.create(earlierCreatedChild_2);
|
||||
View.create(earlierCreatedChild_3);
|
||||
}
|
||||
Row.pop();
|
||||
Row.create();
|
||||
let earlierCreatedChild_3 = this.findChildById("3");
|
||||
if (earlierCreatedChild_3 == undefined) {
|
||||
View.create(new CustomContainer2("3", this, {
|
||||
let earlierCreatedChild_4 = this.findChildById("4");
|
||||
if (earlierCreatedChild_4 == undefined) {
|
||||
View.create(new CustomContainer2("4", this, {
|
||||
header: this.text,
|
||||
content: () => {
|
||||
Column.create();
|
||||
@@ -214,7 +255,7 @@ class CustomContainerUser extends View {
|
||||
}));
|
||||
}
|
||||
else {
|
||||
earlierCreatedChild_3.updateWithValueParams({
|
||||
earlierCreatedChild_4.updateWithValueParams({
|
||||
header: this.text,
|
||||
content: () => {
|
||||
Column.create();
|
||||
@@ -225,7 +266,7 @@ class CustomContainerUser extends View {
|
||||
Column.pop();
|
||||
}
|
||||
});
|
||||
View.create(earlierCreatedChild_3);
|
||||
View.create(earlierCreatedChild_4);
|
||||
}
|
||||
Row.pop();
|
||||
Column.pop();
|
||||
|
||||
Reference in New Issue
Block a user