Skip to content

Commit

Permalink
Remove dedup utility (withastro#235)
Browse files Browse the repository at this point in the history
* Remove dedup util

* add changeset
  • Loading branch information
antonyfaris authored Jul 18, 2022
1 parent 9ae7efa commit edc21c2
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 204 deletions.
5 changes: 5 additions & 0 deletions .changeset/wild-pugs-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'prettier-plugin-astro': patch
---

Remove dedup utility
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"format": "prettier -w . --cache"
},
"dependencies": {
"@astrojs/compiler": "^0.15.2",
"@astrojs/compiler": "^0.19.0",
"prettier": "^2.7.1",
"sass-formatter": "^0.7.2",
"synckit": "^0.7.0"
Expand Down
2 changes: 0 additions & 2 deletions src/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ import {
// trimChildren,
trimTextNodeLeft,
trimTextNodeRight,
removeDuplicates,
getNextNode,
isTagLikeNode,
} from './utils';
Expand Down Expand Up @@ -166,7 +165,6 @@ function print(path: AstPath, opts: ParserOptions, print: printFn): Doc {
// 3. handle printing
switch (node.type) {
case 'root': {
removeDuplicates(node);
return [stripTrailingHardline(path.map(print, 'children')), hardline];
}

Expand Down
24 changes: 0 additions & 24 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,30 +693,6 @@ export function isInsideQuotedAttribute(path: AstPath): boolean {
return stack.some((node) => node.type === 'attribute' && !isLoneMustacheTag(node));
}

/**
* Currently, the compiler has a bug that duplicates text nodes when no
* TagLikeNode elements are present.
*/
export function removeDuplicates(root: RootNode) {
root.children = root.children.filter((node, i, rootChildren) => {
if (node.type !== 'text') return true;
// https://stackoverflow.com/questions/2218999/how-to-remove-all-duplicates-from-an-array-of-objects
return (
i ===
rootChildren.findIndex((t) => {
if (t.position && node.position) {
return (
node.type === 'text' &&
t.position.start.offset === node.position.start.offset &&
t.position.start.line === node.position.start.line &&
t.position.start.column === node.position.start.column
);
}
})
);
});
}

/** True if the node is TagLikeNode:
*
* ElementNode | ComponentNode | CustomElementNode | FragmentNode */
Expand Down
Loading

0 comments on commit edc21c2

Please sign in to comment.