From 291f9cd51c05ccc30cb6f6c4ac88ab6cce200b77 Mon Sep 17 00:00:00 2001 From: houhaoyu Date: Tue, 21 Dec 2021 21:20:18 +0800 Subject: [PATCH] houhaoyu fix stateStyles Signed-off-by: houhaoyu Change-Id: I55066b18f7efaa733f91a133bc4a1ab2c6e0b18b --- compiler/src/compile_info.ts | 4 ++-- compiler/src/component_map.ts | 2 +- compiler/src/pre_define.ts | 1 - compiler/src/process_component_build.ts | 12 ++++++------ compiler/src/process_component_class.ts | 2 +- compiler/src/process_ui_syntax.ts | 4 +--- compiler/src/validate_ui_syntax.ts | 2 +- 7 files changed, 12 insertions(+), 15 deletions(-) diff --git a/compiler/src/compile_info.ts b/compiler/src/compile_info.ts index ddeb4fb..97faaa7 100644 --- a/compiler/src/compile_info.ts +++ b/compiler/src/compile_info.ts @@ -256,12 +256,12 @@ export class ResultStates { const componentNameReg: RegExp = /'typeof\s*(\$?[_a-zA-Z0-9]+)' is not callable/; const stateInfoReg: RegExp = /Property\s*'(\$[_a-zA-Z0-9]+)' does not exist on type/; const extendInfoReg: RegExp = - /Property\s*'([_a-zA-Z0-9]+)' does not exist on type\s*'([_a-zA-Z0-9]+)(Attribute|Interface)'\./; + /Property\s*'([_a-zA-Z0-9]+)' does not exist on type\s*'([_a-zA-Z0-9]+)'\./; if (this.matchMessage(message, props, propInfoReg) || this.matchMessage(message, [...componentCollection.customComponents], componentNameReg) || this.matchMessage(message, props, stateInfoReg) || this.matchMessage(message, EXTEND_ATTRIBUTE, extendInfoReg, true) || - this.matchMessage(message, STYLES_ATTRIBUTE, extendInfoReg)) { + this.matchMessage(message, [...STYLES_ATTRIBUTE], extendInfoReg)) { return false; } return true; diff --git a/compiler/src/component_map.ts b/compiler/src/component_map.ts index e646acd..79f1974 100644 --- a/compiler/src/component_map.ts +++ b/compiler/src/component_map.ts @@ -75,7 +75,7 @@ export interface ExtendParamterInterfance { parameterCount: number } export const EXTEND_ATTRIBUTE: Map> = new Map(); -export const STYLES_ATTRIBUTE: string[] = []; +export const STYLES_ATTRIBUTE: Set = new Set(); export const JS_BIND_COMPONENTS: Set = new Set([ ...GESTURE_TYPE_NAMES, 'Gesture', diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index 02acbdd..015eae1 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -184,4 +184,3 @@ export const BUILD_SHARE_PATH: string = '../share'; export const THIS: string = 'this'; export const STYLES: string = 'Styles'; export const VISUAL_STATE: string = 'visualState'; -export const VIEW_STACK_PROCESSOR: string = 'ViewStackProcessor'; diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index e17ceb4..53bf060 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -46,8 +46,7 @@ import { COMPONENT_DEBUGLINE_FUNCTION, ATTRIBUTE_STATESTYLES, THIS, - VISUAL_STATE, - VIEW_STACK_PROCESSOR + VISUAL_STATE } from './pre_define'; import { INNER_COMPONENT_NAMES, @@ -517,9 +516,10 @@ function addComponentAttr(temp: any, node: ts.Identifier, lastStatement: any, validateStateStyleSyntax(temp, log); } } else if (GLOBAL_STYLE_FUNCTION.has(propName) || INNER_STYLE_FUNCTION.has(propName)) { - bindComponentAttr((GLOBAL_STYLE_FUNCTION.get(propName).statements[0] || - INNER_STYLE_FUNCTION.get(propName).statements[0]) as ts.ExpressionStatement, - identifierNode, statements, log, false, true); + const styleBlock: ts.Block = + GLOBAL_STYLE_FUNCTION.get(propName) || INNER_STYLE_FUNCTION.get(propName); + bindComponentAttr(styleBlock.statements[0] as ts.ExpressionStatement, identifierNode, + statements, log, false, true); } else { if (isStylesAttr && !COMMON_ATTRS.has(propName)) { validateStateStyleSyntax(temp, log); @@ -537,7 +537,7 @@ function createViewStackProcessor(item: any, endViewStack: boolean) { } return ts.factory.createExpressionStatement(ts.factory.createCallExpression( ts.factory.createPropertyAccessExpression( - ts.factory.createIdentifier(VIEW_STACK_PROCESSOR), + ts.factory.createIdentifier(GLOBAL_CONTEXT), ts.factory.createIdentifier(VISUAL_STATE) ), undefined, diff --git a/compiler/src/process_component_class.ts b/compiler/src/process_component_class.ts index ab5e98f..e01c872 100644 --- a/compiler/src/process_component_class.ts +++ b/compiler/src/process_component_class.ts @@ -159,7 +159,7 @@ function processComponentMethod(node: ts.MethodDeclaration, parentComponentName: } else if (hasDecorator(node, COMPONENT_STYLES_DECORATOR)) { if (node.parameters && node.parameters.length === 0) { INNER_STYLE_FUNCTION.set(name, node.body); - STYLES_ATTRIBUTE.push(name); + STYLES_ATTRIBUTE.add(name); BUILDIN_STYLE_NAMES.add(name); decoratorParamSet.add(STYLES); } else { diff --git a/compiler/src/process_ui_syntax.ts b/compiler/src/process_ui_syntax.ts index 9ab9d87..a462867 100644 --- a/compiler/src/process_ui_syntax.ts +++ b/compiler/src/process_ui_syntax.ts @@ -56,8 +56,7 @@ import { EXTEND_ATTRIBUTE, JS_BIND_COMPONENTS, INNER_STYLE_FUNCTION, - GLOBAL_STYLE_FUNCTION, - STYLES_ATTRIBUTE + GLOBAL_STYLE_FUNCTION } from './component_map'; import { resources } from '../main'; @@ -82,7 +81,6 @@ export function processUISyntax(program: ts.Program, ut = false): Function { BUILDIN_STYLE_NAMES.delete(styleName); }) GLOBAL_STYLE_FUNCTION.clear(); - STYLES_ATTRIBUTE.length = 0; return node; } else { return node; diff --git a/compiler/src/validate_ui_syntax.ts b/compiler/src/validate_ui_syntax.ts index 12aa57f..db0f79b 100644 --- a/compiler/src/validate_ui_syntax.ts +++ b/compiler/src/validate_ui_syntax.ts @@ -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.push(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()); }