1. Summary
Refactored src/functional/util/HtmlTemplateProcessor.mjs to use an attributeNameMap instead of a flat array for storing original attribute names. This change ensures correct mapping of dynamic values to their corresponding attributes, especially in complex scenarios involving nested templates and conditional rendering.
2. Rationale
Previously, the HtmlTemplateProcessor relied on a simple array (attributeNames) to track the original, case-sensitive names of attributes associated with dynamic values. This approach was prone to index shifting issues when falsy values were skipped or when nested templates were flattened, leading to incorrect attribute assignments (e.g., handler being mapped to style). By introducing an attributeNameMap that directly associates the dynamic value's index with its attribute name, we eliminate these synchronization problems, making the attribute parsing robust and reliable.
3. Scope & Implementation Plan
- Modify
flattenTemplate: Change its return type to include an attributeNameMap (an object) instead of an attributeNames array.
- Populate
attributeNameMap: Store dynamicValueIndex: attributeName pairs in the map within flattenTemplate, ensuring the attrMatch is recorded at the precise index where its corresponding dynamic value is pushed to flatValues.
- Handle Nested Templates: When flattening nested templates, adjust the keys of the nested
attributeNameMap before merging them into the parent's map to maintain unique and correct indices across the entire flattened structure.
- Update
convertNodeToVdom: Modify this method to retrieve the correct attribute name from the attributeNameMap using the dynamic value's index, rather than relying on a sequential attrNameIndex.
- Update JSDoc: Ensure all relevant JSDoc comments reflect the change from
attributeNames to attributeNameMap.
4. Definition of Done
src/functional/util/HtmlTemplateProcessor.mjs uses attributeNameMap for attribute name tracking.
- The
style vs handler bug (and similar attribute mapping issues) is resolved.
- The attribute mapping logic is robust against nested templates and conditional rendering.
- All related JSDoc comments are updated to reflect the new
attributeNameMap parameter.
1. Summary
Refactored
src/functional/util/HtmlTemplateProcessor.mjsto use anattributeNameMapinstead of a flat array for storing original attribute names. This change ensures correct mapping of dynamic values to their corresponding attributes, especially in complex scenarios involving nested templates and conditional rendering.2. Rationale
Previously, the
HtmlTemplateProcessorrelied on a simple array (attributeNames) to track the original, case-sensitive names of attributes associated with dynamic values. This approach was prone to index shifting issues when falsy values were skipped or when nested templates were flattened, leading to incorrect attribute assignments (e.g.,handlerbeing mapped tostyle). By introducing anattributeNameMapthat directly associates the dynamic value's index with its attribute name, we eliminate these synchronization problems, making the attribute parsing robust and reliable.3. Scope & Implementation Plan
flattenTemplate: Change its return type to include anattributeNameMap(an object) instead of anattributeNamesarray.attributeNameMap: StoredynamicValueIndex: attributeNamepairs in the map withinflattenTemplate, ensuring theattrMatchis recorded at the precise index where its corresponding dynamic value is pushed toflatValues.attributeNameMapbefore merging them into the parent's map to maintain unique and correct indices across the entire flattened structure.convertNodeToVdom: Modify this method to retrieve the correct attribute name from theattributeNameMapusing the dynamic value's index, rather than relying on a sequentialattrNameIndex.attributeNamestoattributeNameMap.4. Definition of Done
src/functional/util/HtmlTemplateProcessor.mjsusesattributeNameMapfor attribute name tracking.stylevshandlerbug (and similar attribute mapping issues) is resolved.attributeNameMapparameter.