Lines Matching refs:ts
16 import ts from 'typescript';
113 export function processCustomComponent(node: ts.ExpressionStatement, newStatements: ts.Statement[],
115 idName: ts.Expression = undefined, builderParamsResult: BuilderParamsResult = null): void {
123 const componentNode: ts.CallExpression = getCustomComponentNode(node);
127 ts.isPropertyAccessExpression(componentNode.parent);
129 let customComponentNewExpression: ts.NewExpression = createCustomComponentNewExpression(
131 let argumentsArray: ts.PropertyAssignment[];
136 argumentsArray.forEach((item: ts.PropertyAssignment, index: number) => {
139 const propertyAssignmentNode: ts.PropertyAssignment = ts.factory.updatePropertyAssignment(
140 item, item.name, changeNodeFromCallToArrow(item.initializer as ts.CallExpression));
145 const newNode: ts.ExpressionStatement = ts.factory.updateExpressionStatement(node,
146 ts.factory.createNewExpression(componentNode.expression, componentNode.typeArguments,
147 [ts.factory.createObjectLiteralExpression(argumentsArray, true)]));
149 newNode.expression as ts.CallExpression, name, isBuilder);
159 const commomComponentNode: ts.Statement[] = [ts.factory.createExpressionStatement(
160 createFunction(ts.factory.createIdentifier(COMPONENT_COMMON),
161 ts.factory.createIdentifier(COMPONENT_CREATE_FUNCTION), null))];
162 const immutableStatements: ts.Statement[] = [];
163 bindComponentAttr(node, ts.factory.createIdentifier(COMPONENT_COMMON), commomComponentNode,
172 newStatements.push(ts.factory.createExpressionStatement(
173 createFunction(ts.factory.createIdentifier(COMPONENT_COMMON),
174 ts.factory.createIdentifier(COMPONENT_CREATE_FUNCTION), null)));
175 bindComponentAttr(node, ts.factory.createIdentifier(COMPONENT_COMMON), newStatements, log);
184 newStatements.push(ts.factory.createExpressionStatement(
185 createFunction(ts.factory.createIdentifier(COMPONENT_COMMON),
186 ts.factory.createIdentifier(COMPONENT_POP_FUNCTION), null)));
202 function createRecycleComponent(isGlobalBuilder: boolean): ts.Statement {
204 [ts.factory.createExpressionStatement(
205 createFunction(ts.factory.createIdentifier(COMPONENT_RECYCLE),
206 ts.factory.createIdentifier(COMPONENT_CREATE_FUNCTION), null))
210 function componentAttributes(componentName: string): ts.Statement {
211 return ts.factory.createExpressionStatement(
212 ts.factory.createCallExpression(
213 ts.factory.createPropertyAccessExpression(
214 ts.factory.createIdentifier(componentName),
215 ts.factory.createIdentifier(COMPONENT_POP_FUNCTION)
220 function isHasChild(node: ts.CallExpression): boolean {
221 return node.arguments && node.arguments[0] && ts.isObjectLiteralExpression(node.arguments[0]) &&
225 function isToChange(item: ts.PropertyAssignment, name: string): boolean {
227 if (item.initializer && ts.isCallExpression(item.initializer) && builderParamName &&
235 function changeNodeFromCallToArrow(node: ts.CallExpression): ts.ConditionalExpression {
236 let builderBindThis: ts.ExpressionStatement = ts.factory.createExpressionStatement(node);
237 if (ts.isCallExpression(node) && node.expression && ts.isIdentifier(node.expression) &&
239 …builderBindThis = transferBuilderCall(ts.factory.createExpressionStatement(node), node.expression.…
244 …ion changeNodeFromCallToArrowDetermine(node: ts.CallExpression, builderBindThis: ts.ExpressionStat…
245 if (ts.isCallExpression(node)) {
246 return ts.factory.createConditionalExpression(
247 ts.factory.createBinaryExpression(
248 ts.factory.createTypeOfExpression(node),
249 ts.factory.createToken(ts.SyntaxKind.EqualsEqualsEqualsToken),
250 ts.factory.createStringLiteral(FUNCTION)
252 ts.factory.createToken(ts.SyntaxKind.QuestionToken),
254 ts.factory.createToken(ts.SyntaxKind.ColonToken),
255 ts.factory.createArrowFunction(
260 ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
261 ts.factory.createBlock(
270 function addCustomComponent(node: ts.ExpressionStatement, newStatements: ts.Statement[],
271 newNode: ts.NewExpression, log: LogInfo[], name: string, componentNode: ts.CallExpression,
274 if (ts.isNewExpression(newNode)) {
275 const propertyArray: ts.ObjectLiteralElementLike[] = [];
282 function addCustomComponentStatements(node: ts.ExpressionStatement, newStatements: ts.Statement[],
283 newNode: ts.NewExpression, name: string, props: ts.ObjectLiteralElementLike[],
284 componentNode: ts.CallExpression, isBuilder: boolean, isGlobalBuilder: boolean,
290 ts.factory.updateExpressionStatement(node, createViewCreate(newNode)),
291 ts.factory.createObjectLiteralExpression(props, true), name));
298 function createChildElmtId(node: ts.CallExpression, name: string): ts.PropertyAssignment[] {
300 const childParam: ts.PropertyAssignment[] = [];
312 …if (ts.isIdentifier(item.name) && propsAndObjectLinks.includes(item.name.escapedText.toString())) {
320 function createCustomComponent(newNode: ts.NewExpression, name: string, componentNode: ts.CallExpre…
322 componentAttrInfo: ComponentAttrInfo, builderParamsResult: BuilderParamsResult): ts.Block {
323 let componentParameter: ts.ObjectLiteralExpression;
325 …componentParameter = ts.factory.createObjectLiteralExpression(createChildElmtId(componentNode, nam…
327 componentParameter = ts.factory.createObjectLiteralExpression([], false);
329 const arrowArgArr: ts.ParameterDeclaration[] = [
330 ts.factory.createParameterDeclaration(undefined, undefined,
331 ts.factory.createIdentifier(ELMTID)
333 ts.factory.createParameterDeclaration(undefined, undefined,
334 ts.factory.createIdentifier(ISINITIALRENDER)
337 const arrowBolck: ts.Statement[] = [
343 arrowArgArr.push(ts.factory.createParameterDeclaration(
344 undefined, undefined, ts.factory.createIdentifier(RECYCLE_NODE),
345 undefined, undefined, ts.factory.createNull()
349 const paramName: ts.Identifier = builderParamsResult.firstParam.name as ts.Identifier;
350 arrowArgArr.push(ts.factory.createParameterDeclaration(undefined, undefined,
351 …paramName, undefined, undefined, ts.factory.createIdentifier(`__${paramName.escapedText.toString()…
358 const observeArgArr: ts.Node[] = [
359 ts.factory.createArrowFunction(undefined, undefined, arrowArgArr, undefined,
360 ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
361 ts.factory.createBlock(arrowBolck, true))
365 observeArgArr.unshift(ts.factory.createStringLiteral(name));
369 return ts.factory.createBlock(
371 ts.factory.createExpressionStatement(ts.factory.createCallExpression(
372 ts.factory.createPropertyAccessExpression(isGlobalBuilder ?
373 … ts.factory.createParenthesizedExpression(parentConditionalExpression()) : ts.factory.createThis(),
375 ts.factory.createIdentifier(OBSERVE_RECYCLE_COMPONENT_CREATION) :
376 ts.factory.createIdentifier(partialUpdateConfig.optimizeComponent ?
379 undefined, observeArgArr as ts.Expression[]))
383 function componentPop(name: string): ts.ObjectLiteralExpression {
384 return ts.factory.createObjectLiteralExpression(
385 [ts.factory.createPropertyAssignment(
386 ts.factory.createIdentifier(NAME),
387 ts.factory.createStringLiteral(name)
393 export function assignComponentParams(componentNode: ts.CallExpression,
394 isBuilder: boolean = false): ts.VariableStatement {
396 …const [keyArray, valueArray]: [ts.Node[], ts.Node[]] = splitComponentParams(componentNode, isBuild… constant
401 return ts.factory.createVariableStatement(
403 ts.factory.createVariableDeclarationList([ts.factory.createVariableDeclaration(
404 ts.factory.createIdentifier(COMPONENT_PARAMS_LAMBDA_FUNCTION),
407 ts.factory.createArrowFunction(
412 ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
413 ts.factory.createBlock(
414 [ts.factory.createReturnStatement(
415 integrateParams ? componentNode.arguments[0] : ts.factory.createObjectLiteralExpression(
424 ts.NodeFlags.Let
428 function reWriteComponentParams(keyArray: ts.Node[], valueArray: ts.Node[]): (ts.PropertyAssignment…
429 ts.ShorthandPropertyAssignment)[] {
430 const returnProperties: (ts.PropertyAssignment | ts.ShorthandPropertyAssignment)[] = [];
431 keyArray.forEach((item: ts.Identifier, index: number) => {
433 returnProperties.push(ts.factory.createShorthandPropertyAssignment(
438 returnProperties.push(ts.factory.createPropertyAssignment(
440 valueArray[index] as ts.Identifier
447 … splitComponentParams(componentNode: ts.CallExpression, isBuilder: boolean, isParamsLambda: boolea…
448 const keyArray: ts.Node[] = [];
449 const valueArray: ts.Node[] = [];
451 …ts.isObjectLiteralExpression(componentNode.arguments[0]) && componentNode.arguments[0].properties)…
452 componentNode.arguments[0].properties.forEach((propertyItem: ts.PropertyAssignment) => {
453 const newPropertyItem: ts.PropertyAssignment =
462 function createIfCustomComponent(newNode: ts.NewExpression, componentNode: ts.CallExpression,
463 …componentParameter: ts.ObjectLiteralExpression, name: string, isGlobalBuilder: boolean, isBuilder:…
464 isRecycleComponent: boolean, componentAttrInfo: ComponentAttrInfo): ts.IfStatement {
465 return ts.factory.createIfStatement(
466 ts.factory.createIdentifier(ISINITIALRENDER),
467 ts.factory.createBlock(
474 ts.factory.createBlock(
475 [ts.factory.createExpressionStatement(ts.factory.createCallExpression(
476 ts.factory.createPropertyAccessExpression(isGlobalBuilder ?
477 … ts.factory.createParenthesizedExpression(parentConditionalExpression()) : ts.factory.createThis(),
478 ts.factory.createIdentifier(UPDATE_STATE_VARS_OF_CHIND_BY_ELMTID)
480 [ts.factory.createIdentifier(ELMTID), componentParameter]))], true)
484 export function assignmentFunction(componeParamName: string): ts.ExpressionStatement {
485 return ts.factory.createExpressionStatement(ts.factory.createBinaryExpression(
486 ts.factory.createPropertyAccessExpression(
487 ts.factory.createIdentifier(componeParamName),
488 ts.factory.createIdentifier(COMPONENT_PARAMS_FUNCTION)
490 ts.factory.createToken(ts.SyntaxKind.EqualsToken),
491 ts.factory.createIdentifier(COMPONENT_PARAMS_LAMBDA_FUNCTION)
495 function componentParamDetachment(newNode: ts.NewExpression, isRecycleComponent: boolean): ts.Varia…
496 return ts.factory.createVariableStatement(
498 ts.factory.createVariableDeclarationList(
499 [ts.factory.createVariableDeclaration(
500 ts.factory.createIdentifier(COMPONENT_CALL),
503 isRecycleComponent ? ts.factory.createConditionalExpression(
504 ts.factory.createIdentifier(RECYCLE_NODE),
505 ts.factory.createToken(ts.SyntaxKind.QuestionToken),
506 ts.factory.createIdentifier(RECYCLE_NODE),
507 ts.factory.createToken(ts.SyntaxKind.ColonToken),
510 ts.NodeFlags.Let
514 function createNewComponent(componeParamName: string): ts.Statement {
515 return ts.factory.createExpressionStatement(
516 ts.factory.createCallExpression(
517 ts.factory.createPropertyAccessExpression(
518 ts.factory.createIdentifier(BASE_COMPONENT_NAME_PU),
519 ts.factory.createIdentifier(COMPONENT_CREATE_FUNCTION)
520 ), undefined, [ts.factory.createIdentifier(componeParamName)]));
523 function createNewRecycleComponent(newNode: ts.NewExpression, componentNode: ts.CallExpression,
524 name: string, componentAttrInfo: ComponentAttrInfo): ts.Statement {
525 let argNode: ts.Expression[] = [];
526 const componentParam: ts.PropertyAssignment[] = [];
528 …ts.isObjectLiteralExpression(componentNode.arguments[0]) && componentNode.arguments[0].properties)…
529 componentNode.arguments[0].properties.forEach((propertyItem: ts.PropertyAssignment) => {
530 …const newPropertyItem: ts.PropertyAssignment = createReference(propertyItem, [], false, false, tru…
533 argNode = [ts.factory.createObjectLiteralExpression(componentParam, false)];
535 argNode = [ts.factory.createObjectLiteralExpression([], false)];
537 const recycleNode: ts.CallExpression = ts.factory.createCallExpression(
539 return ts.factory.createExpressionStatement(
540 ts.factory.createCallExpression(
541 ts.factory.createPropertyAccessExpression(
542 ts.factory.createIdentifier(BASE_COMPONENT_NAME_PU),
543 ts.factory.createIdentifier(COMPONENT_CREATE_RECYCLE)
546 ts.factory.createIdentifier(COMPONENT_CALL),
547 ts.factory.createBinaryExpression(
548 ts.factory.createIdentifier(RECYCLE_NODE),
549 ts.factory.createToken(ts.SyntaxKind.ExclamationEqualsEqualsToken),
550 ts.factory.createNull()
552 componentAttrInfo.reuseId ? componentAttrInfo.reuseId as ts.Expression :
553 ts.factory.createStringLiteral(name),
554 ts.factory.createArrowFunction(undefined, undefined, [], undefined,
555 ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
556 ts.factory.createBlock([
557 ts.factory.createIfStatement(
558 ts.factory.createBinaryExpression(
559 ts.factory.createIdentifier(RECYCLE_NODE),
560 ts.factory.createToken(ts.SyntaxKind.AmpersandAmpersandToken),
561 ts.factory.createBinaryExpression(
562 ts.factory.createTypeOfExpression(
564 ts.factory.createToken(ts.SyntaxKind.EqualsEqualsEqualsToken),
565 ts.factory.createStringLiteral(FUNCTION)
567 ts.factory.createBlock([
568 ts.factory.createExpressionStatement(ts.factory.createCallExpression(
574 ts.factory.createBlock(
576 ts.factory.createIfStatement(ts.factory.createBinaryExpression(
577 …createRecyclePropertyNode(ABOUT_TO_REUSE), ts.factory.createToken(ts.SyntaxKind.AmpersandAmpersand…
578 ts.factory.createBinaryExpression(
579 ts.factory.createTypeOfExpression(createRecyclePropertyNode(ABOUT_TO_REUSE)),
580 ts.factory.createToken(ts.SyntaxKind.EqualsEqualsEqualsToken),
581 ts.factory.createStringLiteral(FUNCTION)
583 … ts.factory.createBlock([ts.factory.createExpressionStatement(recycleNode)], true)),
584 ts.factory.createExpressionStatement(ts.factory.createCallExpression(
594 function createRecyclePropertyNode(recycleFunctionName: string): ts.PropertyAccessExpression {
595 return ts.factory.createPropertyAccessExpression(
596 ts.factory.createIdentifier(RECYCLE_NODE), ts.factory.createIdentifier(recycleFunctionName));
599 function validateCustomComponentPrams(node: ts.CallExpression, name: string,
600 props: ts.ObjectLiteralElementLike[], log: LogInfo[], isBuilder: boolean): void {
602 const nodeArguments: ts.NodeArray<ts.Expression> = node.arguments;
605 ts.isObjectLiteralExpression(nodeArguments[0])) {
606 const nodeArgument: ts.ObjectLiteralExpression = nodeArguments[0] as ts.ObjectLiteralExpression;
608 if (item.name && ts.isIdentifier(item.name)) {
613 if (isToChange(item as ts.PropertyAssignment, name)) {
614 item = ts.factory.updatePropertyAssignment(item as ts.PropertyAssignment,
625 function getCustomComponentNode(node: ts.ExpressionStatement): ts.CallExpression {
630 if (ts.isIdentifier(temp)) {
639 if (ts.isExpressionStatement(parent)) {
642 if (ts.isCallExpression(parent) || ts.isEtsComponentExpression(parent)) {
659 function isThisProperty(node: ts.ObjectLiteralElementLike, propertySet: Set<string>): boolean {
660 if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name) &&
667 function isNonThisProperty(node: ts.ObjectLiteralElementLike, propertySet: Set<string>): boolean {
668 if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name) &&
670 ts.isPropertyAccessExpression(node.initializer) && node.initializer.expression &&
671 node.initializer.expression.kind === ts.SyntaxKind.ThisKeyword &&
672 …ts.isIdentifier(node.initializer.name) && node.initializer.name.escapedText.toString().includes('$…
675 if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name) &&
682 function validateStateManagement(node: ts.ObjectLiteralElementLike, customComponentName: string,
688 function checkFromParentToChild(node: ts.ObjectLiteralElementLike, customComponentName: string,
691 if (ts.isIdentifier(node.name)) {
699 getParentPropertyName(node as ts.PropertyAssignment, curPropertyKind, log);
708 } else if (isInitFromLocal(node) && ts.isPropertyAssignment(node) &&
715 (ts.isPropertyAccessExpression(node.initializer) ||
716 ts.isElementAccessExpression(node.initializer) || ts.isIdentifier(node.initializer))) {
720 getParentPropertyName(node as ts.PropertyAssignment, curPropertyKind, log) || propertyName;
740 function judgeStructAssigned$$(node: ts.ObjectLiteralElementLike): boolean {
742 ts.isPropertyAccessExpression(node.initializer) &&
743 node.initializer.expression && ts.isIdentifier(node.initializer.expression) &&
747 function isInitFromParent(node: ts.ObjectLiteralElementLike): boolean {
748 if (ts.isPropertyAssignment(node) && node.initializer) {
749 if (ts.isPropertyAccessExpression(node.initializer) && node.initializer.expression &&
750 node.initializer.expression.kind === ts.SyntaxKind.ThisKeyword &&
751 ts.isIdentifier(node.initializer.name)) {
753 } else if (ts.isIdentifier(node.initializer) &&
760 function isInitFromLocal(node: ts.ObjectLiteralElementLike): boolean {
761 if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.initializer) &&
767 function getParentPropertyName(node: ts.PropertyAssignment, curPropertyKind: string,
769 const initExpression: ts.Expression = node.initializer;
776 const initName: ts.Identifier = initExpression.name || initExpression;
823 function createFindChildById(id: string, name: string, isBuilder: boolean = false): ts.VariableStat…
824 return ts.factory.createVariableStatement(undefined, ts.factory.createVariableDeclarationList(
825 [ts.factory.createVariableDeclaration(ts.factory.createIdentifier(
826 … `${CUSTOM_COMPONENT_EARLIER_CREATE_CHILD}${id}`), undefined, ts.factory.createTypeReferenceNode(
827 ts.factory.createIdentifier(name)),
828 ts.factory.createConditionalExpression(
829 ts.factory.createParenthesizedExpression(
830 ts.factory.createBinaryExpression(
832 ts.factory.createToken(ts.SyntaxKind.AmpersandAmpersandToken),
833 ts.factory.createPropertyAccessExpression(
835 ts.factory.createIdentifier(CUSTOM_COMPONENT_FUNCTION_FIND_CHILD_BY_ID)
836 ))), ts.factory.createToken(ts.SyntaxKind.QuestionToken),
837 ts.factory.createAsExpression(ts.factory.createCallExpression(
838 ts.factory.createPropertyAccessExpression(createConditionParent(isBuilder),
839 ts.factory.createIdentifier(`${CUSTOM_COMPONENT_FUNCTION_FIND_CHILD_BY_ID}`)), undefined,
840 [isBuilder ? ts.factory.createCallExpression(ts.factory.createIdentifier(GENERATE_ID),
841 undefined, []) : ts.factory.createStringLiteral(id)]),
842 ts.factory.createTypeReferenceNode(ts.factory.createIdentifier(name))),
843 ts.factory.createToken(ts.SyntaxKind.ColonToken),
844 ts.factory.createIdentifier(COMPONENT_IF_UNDEFINED)))], ts.NodeFlags.Let));
847 export function createConditionParent(isBuilder: boolean): ts.ParenthesizedExpression | ts.ThisExpr…
848 …return isBuilder ? ts.factory.createParenthesizedExpression(parentConditionalExpression()) : ts.fa…
851 function createCustomComponentIfStatement(id: string, node: ts.ExpressionStatement,
852 newObjectLiteralExpression: ts.ObjectLiteralExpression, parentName: string): ts.IfStatement {
854 return ts.factory.createIfStatement(ts.factory.createBinaryExpression(
855 ts.factory.createIdentifier(viewName),
856 ts.factory.createToken(ts.SyntaxKind.EqualsEqualsToken),
857 ts.factory.createIdentifier(`${COMPONENT_CONSTRUCTOR_UNDEFINED}`)),
858 ts.factory.createBlock([node], true),
859 ts.factory.createBlock([ts.factory.createExpressionStatement(ts.factory.createCallExpression(
860 ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(
861 viewName), ts.factory.createIdentifier(
864 ts.factory.createExpressionStatement(ts.factory.createCallExpression(
865 ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(`${BASE_COMPONENT_NAME}`),
866 ts.factory.createIdentifier(`${COMPONENT_CREATE_FUNCTION}`)), undefined,
867 [ts.factory.createIdentifier(viewName)]))], true));
870 function createStaticIf(name: string): ts.IfStatement {
871 return ts.factory.createIfStatement(ts.factory.createPrefixUnaryExpression(
872 ts.SyntaxKind.ExclamationToken, ts.factory.createCallExpression(
873 ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(name),
874 ts.factory.createIdentifier(CUSTOM_COMPONENT_NEEDS_UPDATE_FUNCTION)), undefined, [])),
875 ts.factory.createBlock([ts.factory.createExpressionStatement(ts.factory.createCallExpression(
876 ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(name),
877 ts.factory.createIdentifier(CUSTOM_COMPONENT_MARK_STATIC_FUNCTION)),
881 function hasDollar(initExpression: ts.Expression): boolean {
882 if (ts.isPropertyAccessExpression(initExpression) &&
885 } else if (ts.isIdentifier(initExpression) && matchStartWithDollar(initExpression.getText())) {
896 function validateForbiddenToInitViaParam(node: ts.ObjectLiteralElementLike,
915 function validateMandatoryToInitViaParam(node: ts.CallExpression, customComponentName: string,
932 function validateInitDecorator(node: ts.CallExpression, customComponentName: string,
951 function validateIllegalInitFromParent(node: ts.ObjectLiteralElementLike, propertyName: string,
970 function validateNonLinkWithDollar(node: ts.PropertyAssignment, log: LogInfo[]): void {