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 8, 2022
1 parent 97d10f3 commit 42d8dc4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/macros/src/glimmer/macro-maybe-attrs.ts
Original file line number Diff line number Diff line change
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 42d8dc4

Please sign in to comment.