Skip to content

Commit 2893957

Browse files
committed
Add test
1 parent 54e6e83 commit 2893957

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

test/index.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,44 @@ describe("Basic tests", async () => {
896896
assert.strictEqual(messages.length, 1)
897897
assert.strictEqual(messages[0].message, "'c' is not defined.")
898898
})
899+
900+
it("should sort comments by their original source position", () => {
901+
const code = `<script lang="ts" setup>
902+
const test = () => {
903+
// first
904+
return false
905+
}
906+
</script>
907+
908+
<script lang="ts">
909+
/**
910+
* second
911+
*/
912+
export default {}
913+
</script>
914+
915+
<template>
916+
<div @click="test" />
917+
</template>`
918+
919+
const result = parseForESLint(code, { sourceType: "module" })
920+
const comments = result.ast.comments
921+
922+
// Should have 2 comments
923+
assert.strictEqual(comments.length, 2)
924+
925+
// Comments should be sorted by their original position in source code
926+
assert.strictEqual(comments[0].type, "Line")
927+
assert.strictEqual(comments[0].value, " first")
928+
assert.strictEqual(comments[0].loc.start.line, 3)
929+
930+
assert.strictEqual(comments[1].type, "Block")
931+
assert.strictEqual(comments[1].value, " second")
932+
assert.strictEqual(comments[1].loc.start.line, 9)
933+
934+
// Verify comments are sorted by range
935+
assert.ok(comments[0].range[0] < comments[1].range[0])
936+
})
899937
})
900938
})
901939

0 commit comments

Comments
 (0)