mirror of
https://github.com/openharmony/developtools_ace-ets2bundle.git
synced 2026-07-24 13:45:41 -04:00
builder transmission parameter rule Signed-off-by: puyajun <puyajun@huawei.com> Change-Id: Ib8e3abcc0b5d8f40644230d4f49b5ee9f66ac97c
This commit is contained in:
@@ -92,7 +92,7 @@ export class ResultStates {
|
||||
}
|
||||
);
|
||||
|
||||
compilation.hooks.buildModule.tap("findModule", (module) => {
|
||||
compilation.hooks.buildModule.tap('findModule', (module) => {
|
||||
if (/node_modules/.test(module.context)) {
|
||||
const modulePath: string =
|
||||
path.resolve(module.resourceResolveData.descriptionFileRoot, MODULE_SHARE_PATH);
|
||||
@@ -113,7 +113,7 @@ export class ResultStates {
|
||||
compilation.hooks.processAssets.tap(
|
||||
{
|
||||
name: 'GLOBAL_COMMON_MODULE_CACHE',
|
||||
stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
|
||||
stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
|
||||
},
|
||||
(assets) => {
|
||||
if (assets['commons.js']) {
|
||||
@@ -133,7 +133,7 @@ export class ResultStates {
|
||||
`globalThis["__common_module_cache__"][moduleId]: null;\n` +
|
||||
`if (commonCachedModule) { return commonCachedModule.exports; }\n` +
|
||||
source.replace('// Execute the module function',
|
||||
`if (globalThis["__common_module_cache__"] && moduleId.indexOf("?name=") < 0 && ` +
|
||||
`if (globalThis["__common_module_cache__"] && moduleId.indexOf("?name=") < 0 && ` +
|
||||
`Object.keys(globalThis["__common_module_cache__"]).indexOf(moduleId) >= 0) {\n` +
|
||||
` globalThis["__common_module_cache__"][moduleId] = module;\n}`);
|
||||
});
|
||||
@@ -157,12 +157,12 @@ export class ResultStates {
|
||||
compiler.hooks.compilation.tap('Collect Components And Modules', compilation => {
|
||||
compilation.hooks.additionalAssets.tapAsync('Collect Components And Modules', callback => {
|
||||
compilation.assets['./component_collection.txt'] =
|
||||
new RawSource(Array.from(appComponentCollection).join(","));
|
||||
new RawSource(Array.from(appComponentCollection).join(','));
|
||||
compilation.assets['./module_collection.txt'] =
|
||||
new RawSource(moduleCollection.size === 0 ? 'NULL' : Array.from(moduleCollection).join(","));
|
||||
new RawSource(moduleCollection.size === 0 ? 'NULL' : Array.from(moduleCollection).join(','));
|
||||
callback();
|
||||
});
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -182,7 +182,6 @@ export const GEOMETRY_VIEW: string = 'GeometryView';
|
||||
export const MODULE_SHARE_PATH: string = 'src' + path.sep + 'ets' + path.sep + 'share';
|
||||
export const BUILD_SHARE_PATH: string = '../share';
|
||||
|
||||
export const CHILD: string = 'child';
|
||||
export const THIS: string = 'this';
|
||||
export const STYLES: string = 'Styles';
|
||||
export const VISUAL_STATE: string = 'visualState';
|
||||
|
||||
@@ -70,7 +70,7 @@ function parseStatement(statement: ts.Statement, content: string, log: LogInfo[]
|
||||
if (visualPath && fs.existsSync(visualPath) && statement.members) {
|
||||
statement.members.forEach(member => {
|
||||
if (member.kind && member.kind === ts.SyntaxKind.MethodDeclaration) {
|
||||
content = parseMember(member, content, log, visualPath)
|
||||
content = parseMember(member, content, log, visualPath);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -108,7 +108,7 @@ function findVisualFile(filePath: string): string {
|
||||
|
||||
function getVisualContent(visualPath: string, log: LogInfo[], pos: number): string {
|
||||
const parseContent: any = genETS(fs.readFileSync(visualPath, 'utf-8'));
|
||||
if (parseContent && parseContent.errorType && parseContent.errorType != '') {
|
||||
if (parseContent && parseContent.errorType && parseContent.errorType !== '') {
|
||||
log.push({
|
||||
type: LogType.ERROR,
|
||||
message: parseContent.message,
|
||||
@@ -118,4 +118,4 @@ function getVisualContent(visualPath: string, log: LogInfo[], pos: number): stri
|
||||
return parseContent ? parseContent.ets : null;
|
||||
}
|
||||
|
||||
module.exports = preProcess;
|
||||
module.exports = preProcess;
|
||||
|
||||
@@ -45,7 +45,6 @@ import {
|
||||
COMPONENT_TRANSITION_NAME,
|
||||
COMPONENT_DEBUGLINE_FUNCTION,
|
||||
ATTRIBUTE_STATESTYLES,
|
||||
CHILD,
|
||||
THIS,
|
||||
VISUAL_STATE,
|
||||
VIEW_STACK_PROCESSOR,
|
||||
@@ -169,10 +168,11 @@ export function processComponentChild(node: ts.Block | ts.SourceFile, newStateme
|
||||
break;
|
||||
case ComponentType.customComponent:
|
||||
if (index + 1 < array.length && ts.isBlock(array[index + 1])) {
|
||||
item = processExpressionStatementChange(item,
|
||||
array[index + 1] as ts.Block, log)
|
||||
if (processExpressionStatementChange(item, array[index + 1] as ts.Block, log)) {
|
||||
item = processExpressionStatementChange(item, array[index + 1] as ts.Block, log);
|
||||
}
|
||||
}
|
||||
processCustomComponent(item, newStatements, log);
|
||||
processCustomComponent(item as ts.ExpressionStatement, newStatements, log);
|
||||
break;
|
||||
case ComponentType.forEachComponent:
|
||||
processForEachComponent(item, newStatements, log);
|
||||
@@ -198,43 +198,48 @@ export function processComponentChild(node: ts.Block | ts.SourceFile, newStateme
|
||||
|
||||
function processExpressionStatementChange(node: ts.ExpressionStatement, nextNode: ts.Block,
|
||||
log: LogInfo[]): ts.ExpressionStatement {
|
||||
// @ts-ignore
|
||||
let name = node.expression.expression.escapedText.toString()
|
||||
let childParam: string;
|
||||
if (builderParamObjectCollection.get(name) && builderParamObjectCollection.get(name).size > 0) {
|
||||
builderParamObjectCollection.get(name).forEach((item) => {
|
||||
childParam = item
|
||||
})
|
||||
// @ts-ignore
|
||||
const newBlock: ts.Block = processComponentBlock(nextNode, false, log);
|
||||
const arrowNode: ts.ArrowFunction = ts.factory.createArrowFunction(undefined, undefined,
|
||||
[], undefined, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), newBlock);
|
||||
const newPropertyAssignment:ts.PropertyAssignment = ts.factory.createPropertyAssignment(
|
||||
ts.factory.createIdentifier(childParam), arrowNode);
|
||||
// @ts-ignore
|
||||
let argumentsArray: ts.ObjectLiteralExpression[] = node.expression.arguments;
|
||||
if (argumentsArray && argumentsArray.length < 1) {
|
||||
argumentsArray = [ts.factory.createObjectLiteralExpression([newPropertyAssignment], true)]
|
||||
} else {
|
||||
// @ts-ignore
|
||||
argumentsArray = [ts.factory.createObjectLiteralExpression(
|
||||
// @ts-ignore
|
||||
node.expression.arguments[0].properties.concat([newPropertyAssignment]), true)]
|
||||
}
|
||||
// @ts-ignore
|
||||
node = ts.factory.updateExpressionStatement(node, ts.factory.updateCallExpression(node.expression,
|
||||
// @ts-ignore
|
||||
node.expression.expression, node.expression.expression.typeArguments, argumentsArray))
|
||||
return node;
|
||||
let name: string;
|
||||
// @ts-ignore
|
||||
if (node.expression.expression && ts.isIdentifier(node.expression.expression)) {
|
||||
name = node.expression.expression.escapedText.toString();
|
||||
}
|
||||
if (builderParamObjectCollection.get(name) &&
|
||||
builderParamObjectCollection.get(name).size === 1) {
|
||||
return processBlockToExpression(node, nextNode, log, name);
|
||||
} else {
|
||||
log.push({
|
||||
type: LogType.ERROR,
|
||||
message: `'${name}' should have a property decorated with @ builderparam .`,
|
||||
message: `In the trailing lambda case, '${name}' must have one and only one property decorated with `
|
||||
+ `@BuilderParam, and its @BuilderParam expects no parameter.`,
|
||||
pos: node.getStart()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function processBlockToExpression(node: ts.ExpressionStatement, nextNode: ts.Block,
|
||||
log: LogInfo[], name: string): ts.ExpressionStatement {
|
||||
const childParam: string = [...builderParamObjectCollection.get(name)].slice(-1)[0];
|
||||
const newBlock: ts.Block = processComponentBlock(nextNode, false, log);
|
||||
const arrowNode: ts.ArrowFunction = ts.factory.createArrowFunction(undefined, undefined,
|
||||
[], undefined, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), newBlock);
|
||||
const newPropertyAssignment:ts.PropertyAssignment = ts.factory.createPropertyAssignment(
|
||||
ts.factory.createIdentifier(childParam), arrowNode);
|
||||
// @ts-ignore
|
||||
let argumentsArray: ts.ObjectLiteralExpression[] = node.expression.arguments;
|
||||
if (argumentsArray && !argumentsArray.length) {
|
||||
argumentsArray = [ts.factory.createObjectLiteralExpression([newPropertyAssignment], true)];
|
||||
} else {
|
||||
argumentsArray = [ts.factory.createObjectLiteralExpression(
|
||||
// @ts-ignore
|
||||
node.expression.arguments[0].properties.concat([newPropertyAssignment]), true)];
|
||||
}
|
||||
node = ts.factory.updateExpressionStatement(node, ts.factory.updateCallExpression(
|
||||
// @ts-ignore
|
||||
node.expression, node.expression.expression, node.expression.expression.typeArguments,
|
||||
argumentsArray));
|
||||
return node;
|
||||
}
|
||||
|
||||
function processInnerComponent(node: ts.ExpressionStatement, index: number, arr: ts.Statement[],
|
||||
newStatements: ts.Statement[], log: LogInfo[], name: string): void {
|
||||
const res: CreateResult = createComponent(node, COMPONENT_CREATE_FUNCTION);
|
||||
@@ -533,7 +538,7 @@ export function bindComponentAttr(node: ts.ExpressionStatement, identifierNode:
|
||||
}
|
||||
}
|
||||
|
||||
function createArrowFunctionFor$$ ($$varExp: ts.Expression): ts.ArrowFunction {
|
||||
function createArrowFunctionFor$$($$varExp: ts.Expression): ts.ArrowFunction {
|
||||
return ts.factory.createArrowFunction(
|
||||
undefined, undefined,
|
||||
[ts.factory.createParameterDeclaration(
|
||||
@@ -557,7 +562,7 @@ function createArrowFunctionFor$$ ($$varExp: ts.Expression): ts.ArrowFunction {
|
||||
function updateArgumentFor$$(argument: any): ts.Expression {
|
||||
if (ts.isElementAccessExpression(argument)) {
|
||||
return ts.factory.updateElementAccessExpression
|
||||
(argument, updateArgumentFor$$(argument.expression), argument.argumentExpression);
|
||||
(argument, updateArgumentFor$$(argument.expression), argument.argumentExpression);
|
||||
} else if (ts.isIdentifier(argument)) {
|
||||
props.push(argument.getText());
|
||||
if (argument.getText() === $$_THIS) {
|
||||
@@ -567,7 +572,7 @@ function updateArgumentFor$$(argument: any): ts.Expression {
|
||||
}
|
||||
} else if (ts.isPropertyAccessExpression(argument)) {
|
||||
return ts.factory.updatePropertyAccessExpression
|
||||
(argument, updateArgumentFor$$(argument.expression), argument.name);
|
||||
(argument, updateArgumentFor$$(argument.expression), argument.name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -633,7 +638,7 @@ function addComponentAttr(temp: any, node: ts.Identifier, lastStatement: any,
|
||||
validateStateStyleSyntax(temp, log);
|
||||
}
|
||||
if (isGlobalStyles) {
|
||||
for (let i=0; i<temp.arguments.length; i++) {
|
||||
for (let i = 0; i < temp.arguments.length; i++) {
|
||||
temp.arguments[i] = traverseStylesAttr(temp.arguments[i]);
|
||||
}
|
||||
}
|
||||
@@ -702,14 +707,14 @@ function traverseStateStylesAttr(temp: any, statements: ts.Statement[],
|
||||
item.initializer.properties.length === 1 &&
|
||||
ts.isPropertyAssignment(item.initializer.properties[0])) {
|
||||
bindComponentAttr(ts.factory.createExpressionStatement
|
||||
(item.initializer.properties[0].initializer), identifierNode, statements, log, false, true);
|
||||
(item.initializer.properties[0].initializer), identifierNode, statements, log, false, true);
|
||||
} else {
|
||||
validateStateStyleSyntax(temp, log);
|
||||
}
|
||||
if (item.name) {
|
||||
statements.push(createViewStackProcessor(item, false));
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function isExtendFunctionNode(identifierNode: ts.Identifier, propName: string): boolean {
|
||||
@@ -830,8 +835,8 @@ export function isAttributeNode(node: ts.ExpressionStatement): boolean {
|
||||
function validateFirstNode(node: ts.Statement): boolean {
|
||||
const isEntryComponent: boolean =
|
||||
componentCollection.entryComponent === componentCollection.currentClassName;
|
||||
if ((isEntryComponent && validateEntryComponent(node)) ||
|
||||
(!isEntryComponent && validateCustomComponent(node))) {
|
||||
if (isEntryComponent && validateEntryComponent(node) ||
|
||||
!isEntryComponent && validateCustomComponent(node)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -846,8 +851,8 @@ function validateEntryComponent(node: ts.Statement): boolean {
|
||||
|
||||
function validateCustomComponent(node: ts.Statement): boolean {
|
||||
if (ts.isIfStatement(node) ||
|
||||
(ts.isExpressionStatement(node) && (INNER_COMPONENT_NAMES.has(getName(node)) ||
|
||||
componentCollection.customComponents.has(getName(node))))) {
|
||||
ts.isExpressionStatement(node) && (INNER_COMPONENT_NAMES.has(getName(node)) ||
|
||||
componentCollection.customComponents.has(getName(node)))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -886,10 +891,10 @@ function getComponentType(node: ts.ExpressionStatement, log: LogInfo[],
|
||||
return ComponentType.forEachComponent;
|
||||
} else if (CUSTOM_BUILDER_METHOD.has(name)) {
|
||||
return ComponentType.customBuilderMethod;
|
||||
} else if (builderParamObjectCollection.get(componentCollection.currentClassName) &&
|
||||
} else if (builderParamObjectCollection.get(componentCollection.currentClassName) &&
|
||||
builderParamObjectCollection.get(componentCollection.currentClassName).has(name)) {
|
||||
return ComponentType.builderParamMethod;
|
||||
}else if (!isAttributeNode(node)) {
|
||||
} else if (!isAttributeNode(node)) {
|
||||
log.push({
|
||||
type: LogType.ERROR,
|
||||
message: `'${node.getText()}' does not meet UI component syntax.`,
|
||||
|
||||
@@ -242,13 +242,13 @@ function processBuildMember(node: ts.MethodDeclaration, context: ts.Transformati
|
||||
}
|
||||
|
||||
function validateBuilderFunctionNode(node: ts.PropertyAccessExpression | ts.Identifier): boolean {
|
||||
if (((ts.isPropertyAccessExpression(node) && node.expression && node.name &&
|
||||
if ((ts.isPropertyAccessExpression(node) && node.expression && node.name &&
|
||||
node.expression.kind === ts.SyntaxKind.ThisKeyword && ts.isIdentifier(node.name) &&
|
||||
CUSTOM_BUILDER_METHOD.has(node.name.escapedText.toString())) ||
|
||||
CUSTOM_BUILDER_METHOD.has(node.name.escapedText.toString()) ||
|
||||
ts.isIdentifier(node) && CUSTOM_BUILDER_METHOD.has(node.escapedText.toString())) &&
|
||||
!((ts.isPropertyAccessExpression(node) && validateBuilderParam(node)) ||
|
||||
(ts.isIdentifier(node) && node.parent && ts.isPropertyAccessExpression(node.parent) &&
|
||||
validateBuilderParam(node.parent)))) {
|
||||
!(ts.isPropertyAccessExpression(node) && validateBuilderParam(node) ||
|
||||
ts.isIdentifier(node) && node.parent && ts.isPropertyAccessExpression(node.parent) &&
|
||||
validateBuilderParam(node.parent))) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@@ -286,21 +286,21 @@ function getParsedBuilderAttrArgument(node: ts.PropertyAccessExpression | ts.Ide
|
||||
ts.factory.createIdentifier(BUILDER_ATTR_NAME),
|
||||
node
|
||||
)
|
||||
])
|
||||
]);
|
||||
}
|
||||
return newObjectNode;
|
||||
}
|
||||
|
||||
function isCustomComponentNode(node:ts.NewExpression | ts.ExpressionStatement): boolean {
|
||||
if ((ts.isNewExpression(node) && ts.isIdentifier(node.expression) && node.expression.escapedText
|
||||
&& componentCollection.customComponents.has(node.expression.escapedText.toString())) ||
|
||||
if (ts.isNewExpression(node) && ts.isIdentifier(node.expression) && node.expression.escapedText
|
||||
&& componentCollection.customComponents.has(node.expression.escapedText.toString()) ||
|
||||
// @ts-ignore
|
||||
(ts.isExpressionStatement(node) && node.expression && node.expression.expression &&
|
||||
ts.isExpressionStatement(node) && node.expression && node.expression.expression &&
|
||||
// @ts-ignore
|
||||
node.expression.expression.expression && node.expression.expression.expression.escapedText &&
|
||||
// @ts-ignore
|
||||
node.expression.expression.expression.escapedText.toString().startsWith(
|
||||
CUSTOM_COMPONENT_EARLIER_CREATE_CHILD))) {
|
||||
CUSTOM_COMPONENT_EARLIER_CREATE_CHILD)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
||||
@@ -77,7 +77,7 @@ export function addConstructor(ctorNode: any, watchMap: Map<string, ts.Node>)
|
||||
ts.factory.createStringLiteral(key),
|
||||
ts.isStringLiteral(value) ?
|
||||
ts.factory.createPropertyAccessExpression(ts.factory.createThis(),
|
||||
ts.factory.createIdentifier(value.text)) : value as ts.PropertyAccessExpression
|
||||
ts.factory.createIdentifier(value.text)) : value as ts.PropertyAccessExpression
|
||||
]
|
||||
));
|
||||
watchStatements.push(watchNode);
|
||||
|
||||
@@ -419,9 +419,9 @@ function createUpdateParams(name: ts.Identifier, decorator: string): ts.Statemen
|
||||
builderParamObjectCollection.set(componentCollection.currentClassName, new Set([]));
|
||||
}
|
||||
builderParamObjectCollection.get(componentCollection.currentClassName)
|
||||
.add(name.escapedText.toString())
|
||||
.add(name.escapedText.toString());
|
||||
}
|
||||
updateParamsNode = createUpdateParamsWithoutIf(name, true);
|
||||
updateParamsNode = createUpdateParamsWithoutIf(name);
|
||||
break;
|
||||
}
|
||||
return updateParamsNode;
|
||||
@@ -437,7 +437,7 @@ function createUpdateParamsWithIf(name: ts.Identifier): ts.IfStatement {
|
||||
createUpdateParamsWithoutIf(name)], true), undefined);
|
||||
}
|
||||
|
||||
function createUpdateParamsWithoutIf(name: ts.Identifier, isAdd: boolean = false): ts.ExpressionStatement {
|
||||
function createUpdateParamsWithoutIf(name: ts.Identifier): ts.ExpressionStatement {
|
||||
return ts.factory.createExpressionStatement(ts.factory.createBinaryExpression(
|
||||
createPropertyAccessExpressionWithThis(name.getText()),
|
||||
ts.factory.createToken(ts.SyntaxKind.EqualsToken),
|
||||
|
||||
@@ -52,6 +52,7 @@ import {
|
||||
createViewCreate,
|
||||
createCustomComponentNewExpression
|
||||
} from './process_component_member';
|
||||
import { builderParamObjectCollection } from './process_component_member';
|
||||
import {
|
||||
LogType,
|
||||
LogInfo,
|
||||
@@ -72,10 +73,44 @@ const decoractorMap: Map<string, Map<string, Set<string>>> = new Map(
|
||||
export function processCustomComponent(node: ts.ExpressionStatement, newStatements: ts.Statement[],
|
||||
log: LogInfo[]): void {
|
||||
if (ts.isCallExpression(node.expression)) {
|
||||
addCustomComponent(node, newStatements, createCustomComponentNewExpression(node.expression), log);
|
||||
let ischangeNode: boolean = false;
|
||||
let customComponentNewExpression: ts.NewExpression = createCustomComponentNewExpression(
|
||||
node.expression);
|
||||
let argumentsArray: ts.PropertyAssignment[];
|
||||
if (isHasChild(node.expression)) {
|
||||
// @ts-ignore
|
||||
argumentsArray = node.expression.arguments[0].properties.slice();
|
||||
argumentsArray.forEach((item: ts.PropertyAssignment, index: number) => {
|
||||
if (ts.isCallExpression(item.initializer)) {
|
||||
ischangeNode = true;
|
||||
const PropertyAssignmentNode: ts.PropertyAssignment = ts.factory.updatePropertyAssignment(
|
||||
item, item.name, changeNodeFromCallToArrow(item.initializer));
|
||||
argumentsArray.splice(index, 1, PropertyAssignmentNode);
|
||||
}
|
||||
});
|
||||
if (ischangeNode) {
|
||||
const newNode: ts.ExpressionStatement = ts.factory.updateExpressionStatement(node,
|
||||
ts.factory.createNewExpression(node.expression.expression, node.expression.typeArguments,
|
||||
[ts.factory.createObjectLiteralExpression(argumentsArray, true)]));
|
||||
customComponentNewExpression = createCustomComponentNewExpression(
|
||||
newNode.expression as ts.CallExpression);
|
||||
}
|
||||
}
|
||||
addCustomComponent(node, newStatements, customComponentNewExpression, log);
|
||||
}
|
||||
}
|
||||
|
||||
function isHasChild(node: ts.CallExpression): boolean {
|
||||
return node.arguments && node.arguments[0] && ts.isObjectLiteralExpression(node.arguments[0]) &&
|
||||
node.arguments[0].properties && node.arguments[0].properties.length;
|
||||
}
|
||||
|
||||
function changeNodeFromCallToArrow(node: ts.CallExpression): ts.ArrowFunction {
|
||||
return ts.factory.createArrowFunction(undefined, undefined, [], undefined,
|
||||
ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
|
||||
ts.factory.createBlock([ts.factory.createExpressionStatement(node)], true));
|
||||
}
|
||||
|
||||
function addCustomComponent(node: ts.ExpressionStatement, newStatements: ts.Statement[],
|
||||
newNode: ts.NewExpression, log: LogInfo[]): void {
|
||||
if (ts.isNewExpression(newNode)) {
|
||||
@@ -105,13 +140,16 @@ function validateCustomComponentPrams(node: ts.ExpressionStatement, name: string
|
||||
ts.isObjectLiteralExpression(nodeArguments[0])) {
|
||||
const nodeArgument: ts.ObjectLiteralExpression = nodeArguments[0] as ts.ObjectLiteralExpression;
|
||||
nodeArgument.properties.forEach(item => {
|
||||
if (item.name && item.name.escapedText) {
|
||||
// @ts-ignore
|
||||
if (item.name && ts.isIdentifier(item.name)) {
|
||||
curChildProps.add(item.name.escapedText.toString());
|
||||
}
|
||||
if (isThisProperty(item, propertySet)) {
|
||||
validateStateManagement(item, name, log);
|
||||
if (isNonThisProperty(item, linkSet)) {
|
||||
if (item.initializer && ts.isCallExpression(item.initializer)) {
|
||||
item = ts.factory.updatePropertyAssignment(item as ts.PropertyAssignment,
|
||||
item.name, changeNodeFromCallToArrow(item.initializer));
|
||||
}
|
||||
props.push(item);
|
||||
}
|
||||
} else {
|
||||
@@ -119,6 +157,7 @@ function validateCustomComponentPrams(node: ts.ExpressionStatement, name: string
|
||||
}
|
||||
});
|
||||
}
|
||||
validateMandatoryToAssignmentViaParam(node, name, curChildProps, log);
|
||||
validateMandatoryToInitViaParam(node, name, curChildProps, log);
|
||||
}
|
||||
|
||||
@@ -346,11 +385,27 @@ function validateNonExistentProperty(node: ts.ObjectLiteralElementLike,
|
||||
customComponentName: string, log: LogInfo[]): void {
|
||||
log.push({
|
||||
type: LogType.ERROR,
|
||||
message: `Property '${node.name.getText()}' does not exist on type '${customComponentName}'.`,
|
||||
message: `Property '${node.name.escapedText.toString()}' does not exist on type '${customComponentName}'.`,
|
||||
pos: node.name.getStart()
|
||||
});
|
||||
}
|
||||
|
||||
function validateMandatoryToAssignmentViaParam(node: ts.ExpressionStatement, customComponentName: string,
|
||||
curChildProps: Set<string>, log: LogInfo[]): void {
|
||||
if (builderParamObjectCollection.get(customComponentName) &&
|
||||
builderParamObjectCollection.get(customComponentName).size) {
|
||||
builderParamObjectCollection.get(customComponentName).forEach((item) => {
|
||||
if (!curChildProps.has(item)) {
|
||||
log.push({
|
||||
type: LogType.ERROR,
|
||||
message: `The property decorated with @BuilderParam '${item}' must be assigned a value .`,
|
||||
pos: node.getStart()
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function validateMandatoryToInitViaParam(node: ts.ExpressionStatement, customComponentName: string,
|
||||
curChildProps: Set<string>, log: LogInfo[]): void {
|
||||
const mandatoryToInitViaParamSet: Set<string> = new Set([
|
||||
|
||||
@@ -81,7 +81,7 @@ export function processUISyntax(program: ts.Program, ut = false): Function {
|
||||
node = ts.visitEachChild(node, processAllNodes, context);
|
||||
GLOBAL_STYLE_FUNCTION.forEach((block, styleName) => {
|
||||
BUILDIN_STYLE_NAMES.delete(styleName);
|
||||
})
|
||||
});
|
||||
GLOBAL_STYLE_FUNCTION.clear();
|
||||
return node;
|
||||
} else {
|
||||
@@ -98,7 +98,7 @@ export function processUISyntax(program: ts.Program, ut = false): Function {
|
||||
componentCollection.currentClassName = null;
|
||||
INNER_STYLE_FUNCTION.forEach((block, styleName) => {
|
||||
BUILDIN_STYLE_NAMES.delete(styleName);
|
||||
})
|
||||
});
|
||||
INNER_STYLE_FUNCTION.clear();
|
||||
} else if (ts.isFunctionDeclaration(node)) {
|
||||
if (hasDecorator(node, COMPONENT_EXTEND_DECORATOR)) {
|
||||
@@ -154,7 +154,7 @@ function collectComponents(node: ts.SourceFile): void {
|
||||
// @ts-ignore
|
||||
if (node.identifiers && node.identifiers.size) {
|
||||
// @ts-ignore
|
||||
for (let key of node.identifiers.keys()) {
|
||||
for (const key of node.identifiers.keys()) {
|
||||
if (JS_BIND_COMPONENTS.has(key)) {
|
||||
appComponentCollection.add(key);
|
||||
}
|
||||
@@ -186,7 +186,7 @@ function processResourceData(node: ts.CallExpression): ts.Node {
|
||||
return node;
|
||||
}
|
||||
|
||||
function createResourceParam(resourceValue: number, resourceType: number,argsArr: ts.Expression[]):
|
||||
function createResourceParam(resourceValue: number, resourceType: number, argsArr: ts.Expression[]):
|
||||
ts.ObjectLiteralExpression {
|
||||
const resourceParams: ts.ObjectLiteralExpression = ts.factory.createObjectLiteralExpression(
|
||||
[
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
*/
|
||||
|
||||
import ts from 'typescript';
|
||||
import path from 'path';
|
||||
|
||||
import { BUILD_OFF } from './pre_define';
|
||||
import {
|
||||
|
||||
@@ -159,10 +159,10 @@ export function createFunction(node: ts.Identifier, attrNode: ts.Identifier,
|
||||
}
|
||||
|
||||
export function circularFile(inputPath: string, outputPath: string): void {
|
||||
if ((!inputPath) || (!outputPath)) {
|
||||
if (!inputPath || !outputPath) {
|
||||
return;
|
||||
}
|
||||
fs.readdir(inputPath, function (err, files) {
|
||||
fs.readdir(inputPath, function(err, files) {
|
||||
if (!files) {
|
||||
return;
|
||||
}
|
||||
@@ -205,4 +205,4 @@ function mkDir(path_: string): void {
|
||||
mkDir(parent);
|
||||
}
|
||||
fs.mkdirSync(path_);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ function checkComponentDecorator(source: string, filePath: string,
|
||||
}
|
||||
if (ts.isFunctionDeclaration(item) && item.decorators && item.decorators.length === 1 &&
|
||||
item.decorators[0].expression && item.decorators[0].expression.getText() === STYLES) {
|
||||
STYLES_ATTRIBUTE.add(item.name.getText())
|
||||
STYLES_ATTRIBUTE.add(item.name.getText());
|
||||
GLOBAL_STYLE_FUNCTION.set(item.name.getText(), item.body);
|
||||
BUILDIN_STYLE_NAMES.add(item.name.getText());
|
||||
}
|
||||
@@ -744,7 +744,7 @@ export function sourceReplace(source: string, sourcePath: string): ReplaceResult
|
||||
return {
|
||||
content: content,
|
||||
log: log
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function preprocessExtend(content: string, sourcePath: string, log: LogInfo[]): string {
|
||||
@@ -772,7 +772,7 @@ export function preprocessExtend(content: string, sourcePath: string, log: LogIn
|
||||
syntaxCheckContent = content;
|
||||
}
|
||||
if (result.error_otherParsers) {
|
||||
for(let i = 0; i < result.error_otherParsers.length; i++) {
|
||||
for (let i = 0; i < result.error_otherParsers.length; i++) {
|
||||
log.push({
|
||||
type: LogType.ERROR,
|
||||
message: result.error_otherParsers[i].errMessage,
|
||||
@@ -810,24 +810,24 @@ export function processSystemApi(content: string, isProcessWhiteList: boolean =
|
||||
const libSoValue: string = item1 || item3;
|
||||
const libSoKey: string = item2 || item4;
|
||||
return `var ${libSoValue} = globalThis.requireNapi("${libSoKey}", true);`;
|
||||
}).replace(REG_SYSTEM, (item, item1, item2, item3, item4, item5, item6, item7) => {
|
||||
let moduleType: string = item2 || item5;
|
||||
let systemKey: string = item3 || item6;
|
||||
let systemValue: string = item1 || item4;
|
||||
moduleCollection.add(`${moduleType}.${systemKey}`);
|
||||
if (NATIVE_MODULE.has(`${moduleType}.${systemKey}`)) {
|
||||
item = `var ${systemValue} = globalThis.requireNativeModule('${moduleType}.${systemKey}')`;
|
||||
} else if (moduleType === SYSTEM_PLUGIN) {
|
||||
item = `var ${systemValue} = isSystemplugin('${systemKey}', '${SYSTEM_PLUGIN}') ? ` +
|
||||
}).replace(REG_SYSTEM, (item, item1, item2, item3, item4, item5, item6, item7) => {
|
||||
const moduleType: string = item2 || item5;
|
||||
const systemKey: string = item3 || item6;
|
||||
const systemValue: string = item1 || item4;
|
||||
moduleCollection.add(`${moduleType}.${systemKey}`);
|
||||
if (NATIVE_MODULE.has(`${moduleType}.${systemKey}`)) {
|
||||
item = `var ${systemValue} = globalThis.requireNativeModule('${moduleType}.${systemKey}')`;
|
||||
} else if (moduleType === SYSTEM_PLUGIN) {
|
||||
item = `var ${systemValue} = isSystemplugin('${systemKey}', '${SYSTEM_PLUGIN}') ? ` +
|
||||
`globalThis.systemplugin.${systemKey} : globalThis.requireNapi('${systemKey}')`;
|
||||
} else if (moduleType === OHOS_PLUGIN) {
|
||||
item = `var ${systemValue} = globalThis.requireNapi('${systemKey}') || ` +
|
||||
} else if (moduleType === OHOS_PLUGIN) {
|
||||
item = `var ${systemValue} = globalThis.requireNapi('${systemKey}') || ` +
|
||||
`(isSystemplugin('${systemKey}', '${OHOS_PLUGIN}') ? ` +
|
||||
`globalThis.ohosplugin.${systemKey} : isSystemplugin('${systemKey}', '${SYSTEM_PLUGIN}') ` +
|
||||
`? globalThis.systemplugin.${systemKey} : undefined)`;
|
||||
}
|
||||
return item;
|
||||
});
|
||||
}
|
||||
return item;
|
||||
});
|
||||
}
|
||||
|
||||
function validateWhiteListModule(moduleType: string, systemKey: string): boolean {
|
||||
|
||||
Reference in New Issue
Block a user