diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index 1ac9247e36687b28e4e1064278a3917b74da8685..acfd742a1b515e3c06d08876cefa531d64a8410a 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -171,8 +171,9 @@ export const COMPONENT_CONSTRUCTOR_PARENT: string = 'parent'; export const COMPONENT_CONSTRUCTOR_PARAMS: string = 'params'; export const COMPONENT_PARAMS_FUNCTION: string = 'paramsGenerator_'; export const COMPONENT_PARAMS_LAMBDA_FUNCTION: string = 'paramsLambda'; -export const COMPONENT_THEME_PARENT: string = 'parentTheme'; -export const COMPONENT_PARAMS_THEME: string = 'paramsTheme'; +export const COMPONENT_GET_PARENT_THEME: string = 'getParentTheme'; +export const COMPONENT_PARENT_THEME_LAMBDA_FUNCTION: string = 'parentThemeLambda'; +export const COMPONENT_SET_PARENT_THEME_LAMBDA: string = 'setParentThemeLambda'; export const COMPONENT_CONSTRUCTOR_UNDEFINED: string = 'undefined'; export const COMPONENT_CONSTRUCTOR_LOCALSTORAGE: string = 'localStorage'; export const COMPONENT_ABOUTTOREUSEINTERNAL_FUNCTION: string = 'aboutToReuseInternal'; diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index 035351092a4ea89ab4286db09e9b2a6b2b9896cb..af47413b4a4061a780a9435270eb81927d87824a 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -131,7 +131,7 @@ import { SLIDER, TITLE, COMPONENT_WITH_THEME, - COMPONENT_THEME_PARENT + COMPONENT_GET_PARENT_THEME } from './pre_define'; import { INNER_COMPONENT_NAMES, @@ -864,11 +864,15 @@ export function withThemeArgs(node: ts.Node): ts.Expression[] { } const defaultResult: ts.Expression[] = []; defaultResult.push( - ts.factory.createPropertyAccessExpression( - ts.factory.createThis(), - ts.factory.createIdentifier(COMPONENT_THEME_PARENT) + ts.factory.createCallExpression( + ts.factory.createPropertyAccessExpression( + ts.factory.createThis(), + ts.factory.createIdentifier(COMPONENT_GET_PARENT_THEME) + ), + undefined, + undefined ) - ) + ); return defaultResult; } diff --git a/compiler/src/process_component_class.ts b/compiler/src/process_component_class.ts index 153c6f9c205bdcf9fa57bdab7079c8b4615a212e..1453e78f2282e7dc507ea8800867d3ef1c617e11 100644 --- a/compiler/src/process_component_class.ts +++ b/compiler/src/process_component_class.ts @@ -89,9 +89,7 @@ import { FUNCTION, COMPONENT_PARAMS_LAMBDA_FUNCTION, DECORATOR_COMPONENT_FREEZEWHENINACTIVE, - INIT_ALLOW_COMPONENT_FREEZE, - COMPONENT_THEME_PARENT, - COMPONENT_PARAMS_THEME + INIT_ALLOW_COMPONENT_FREEZE } from './pre_define'; import { BUILDIN_STYLE_NAMES, @@ -330,15 +328,6 @@ function assignParams(parentComponentName: string): ts.Statement[] { ts.factory.createIdentifier(COMPONENT_PARAMS_LAMBDA_FUNCTION) ))], true - ) - ), - ts.factory.createExpressionStatement(ts.factory.createBinaryExpression( - ts.factory.createPropertyAccessExpression( - ts.factory.createThis(), - ts.factory.createIdentifier(COMPONENT_THEME_PARENT) - ), - ts.factory.createToken(ts.SyntaxKind.EqualsToken), - ts.factory.createIdentifier(COMPONENT_PARAMS_THEME) )) ]; } diff --git a/compiler/src/process_component_constructor.ts b/compiler/src/process_component_constructor.ts index 5890820e290c280f3cfa6d050594e0e01ca4eeb5..1c1333f16992b78bd8d320fbbba9e4b8a1cd40be 100644 --- a/compiler/src/process_component_constructor.ts +++ b/compiler/src/process_component_constructor.ts @@ -30,7 +30,6 @@ import { COMPONENT_CONSTRUCTOR_LOCALSTORAGE_TYPE_PU, ELMTID, COMPONENT_PARAMS_LAMBDA_FUNCTION, - COMPONENT_PARAMS_THEME, COMPONENT_IF_UNDEFINED, CUSTOM_COMPONENT_EXTRAINFO } from './pre_define'; @@ -101,7 +100,6 @@ function initConstructorParams(node: ts.ConstructorDeclaration, parentComponentN COMPONENT_CONSTRUCTOR_LOCALSTORAGE_PU, ELMTID, COMPONENT_PARAMS_LAMBDA_FUNCTION, - COMPONENT_PARAMS_THEME, CUSTOM_COMPONENT_EXTRAINFO ]); const newParameters: ts.ParameterDeclaration[] = Array.from(node.parameters); @@ -114,7 +112,7 @@ function initConstructorParams(node: ts.ConstructorDeclaration, parentComponentN ts.factory.createIdentifier(paramName), undefined, undefined, paramName === ELMTID ? ts.factory.createPrefixUnaryExpression(ts.SyntaxKind.MinusToken, ts.factory.createNumericLiteral('1')) - : (paramName === COMPONENT_PARAMS_LAMBDA_FUNCTION || paramName === COMPONENT_PARAMS_THEME + : (paramName === COMPONENT_PARAMS_LAMBDA_FUNCTION ? ts.factory.createIdentifier(COMPONENT_IF_UNDEFINED) : undefined) ) diff --git a/compiler/src/process_component_member.ts b/compiler/src/process_component_member.ts index b7d458e60c47e94e8cecd7c0977bf0dbcffefd05..9116c6fd05d4f3fcd88e599ab037fdb9c93d4753 100644 --- a/compiler/src/process_component_member.ts +++ b/compiler/src/process_component_member.ts @@ -76,7 +76,6 @@ import { RESERT, COMPONENT_IF_UNDEFINED, COMPONENT_PARAMS_LAMBDA_FUNCTION, - COMPONENT_PARAMS_THEME, NULL, OBSERVED, COMPONENT_REQUIRE_DECORATOR, @@ -863,7 +862,6 @@ function addCustomComponentId(node: ts.NewExpression, componentName: string, ts.SyntaxKind.MinusToken, ts.factory.createNumericLiteral('1')) : ts.factory.createIdentifier(ELMTID), ts.factory.createIdentifier(COMPONENT_PARAMS_LAMBDA_FUNCTION), - ts.factory.createIdentifier(COMPONENT_PARAMS_THEME), ts.factory.createObjectLiteralExpression( [ ts.factory.createPropertyAssignment( diff --git a/compiler/src/process_custom_component.ts b/compiler/src/process_custom_component.ts index 9f2f17c448cac7b539c2f0d276a82787c6f7c846..49c2137a11072381d8bf509b34c345645322c20a 100644 --- a/compiler/src/process_custom_component.ts +++ b/compiler/src/process_custom_component.ts @@ -57,7 +57,8 @@ import { FUNCTION, COMPONENT_IF_UNDEFINED, COMPONENT_PARAMS_LAMBDA_FUNCTION, - COMPONENT_PARAMS_THEME, + COMPONENT_PARENT_THEME_LAMBDA_FUNCTION, + COMPONENT_SET_PARENT_THEME_LAMBDA, COMPONENT_PARAMS_FUNCTION, COMPONENT_ABOUTTOREUSEINTERNAL_FUNCTION, NAME @@ -424,10 +425,22 @@ export function assignComponentParams(componentNode: ts.CallExpression, ) ), ts.factory.createVariableDeclaration( - ts.factory.createIdentifier(COMPONENT_PARAMS_THEME), + ts.factory.createIdentifier(COMPONENT_PARENT_THEME_LAMBDA_FUNCTION), undefined, undefined, - withThemeArgs(componentNode)[0] + ts.factory.createArrowFunction( + undefined, + undefined, + [], + undefined, + ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), + ts.factory.createBlock( + [ts.factory.createReturnStatement( + withThemeArgs(componentNode)[0] + )], + true + ) + ) ) ], ts.NodeFlags.Let @@ -491,12 +504,23 @@ function createIfCustomComponent(newNode: ts.NewExpression, componentNode: ts.Ca } function createNewComponent(newNode: ts.NewExpression): ts.Statement { + const node = ts.factory.createCallExpression( + ts.factory.createPropertyAccessExpression( + ts.factory.createIdentifier(BASE_COMPONENT_NAME_PU), + ts.factory.createIdentifier(COMPONENT_SET_PARENT_THEME_LAMBDA) + ), + [], + [newNode, + ts.factory.createIdentifier(COMPONENT_PARENT_THEME_LAMBDA_FUNCTION) + ] + ); + return ts.factory.createExpressionStatement( ts.factory.createCallExpression( ts.factory.createPropertyAccessExpression( ts.factory.createIdentifier(BASE_COMPONENT_NAME_PU), ts.factory.createIdentifier(COMPONENT_CREATE_FUNCTION) - ), undefined, [newNode])); + ), undefined, [node])); } function createNewRecycleComponent(newNode: ts.NewExpression, componentNode: ts.CallExpression,