Skip to content

Commit

Permalink
Reuse the loc of the macroMaybeAttrs hashes for the created attributes
Browse files Browse the repository at this point in the history
The newer template compiler sorts attributes based on their `loc` location when printing. Since previously no `loc` info was added to the newly created attributes, they were being moved to the front of the element. By reusing their original `loc` data we can ensure that the order from the source file is maintained.
  • Loading branch information
Windvis committed Feb 4, 2022
1 parent a3fef30 commit 4951e11
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/macros/src/glimmer/macro-maybe-attrs.ts
Expand Up @@ -20,11 +20,11 @@ export function maybeAttrs(elementNode: any, node: any, builders: any) {

if (result.value) {
for (let bareAttr of bareAttrs) {
elementNode.attributes.push(builders.attr(bareAttr.original, builders.text('')));
elementNode.attributes.push(builders.attr(bareAttr.original, builders.text(''), bareAttr.loc));
}

for (let attr of node.hash.pairs) {
elementNode.attributes.push(builders.attr(attr.key, builders.mustache(attr.value)));
elementNode.attributes.push(builders.attr(attr.key, builders.mustache(attr.value), attr.loc));
}
}
}

0 comments on commit 4951e11

Please sign in to comment.