From 211707c3193800442184761001ae75e812d8c385 Mon Sep 17 00:00:00 2001 From: Wayne Zhang Date: Tue, 24 Jun 2025 09:26:27 +0800 Subject: [PATCH 1/2] Fix comments order (#265) * Fix comments order * chore: update * Add test * Update index.js --------- Co-authored-by: Yosuke Ota --- src/ast/nodes.ts | 1 - src/script-setup/index.ts | 4 ++++ test/index.js | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/ast/nodes.ts b/src/ast/nodes.ts index 5ebf703..d652e4e 100644 --- a/src/ast/nodes.ts +++ b/src/ast/nodes.ts @@ -7,7 +7,6 @@ import type { ScopeManager } from "eslint-scope" import type { ParseError } from "./errors" import type { HasLocation } from "./locations" import type { Token } from "./tokens" -// eslint-disable-next-line node/no-extraneous-import -- ignore import type { TSESTree } from "@typescript-eslint/utils" //------------------------------------------------------------------------------ diff --git a/src/script-setup/index.ts b/src/script-setup/index.ts index 671a2bc..81bb75b 100644 --- a/src/script-setup/index.ts +++ b/src/script-setup/index.ts @@ -308,6 +308,10 @@ export function parseScriptSetupElements( } result.ast.tokens.sort((a, b) => a.range[0] - b.range[0]) } + + if (result.ast.comments != null) { + result.ast.comments.sort((a, b) => a.range[0] - b.range[0]) + } result.ast.body.sort((a, b) => a.range[0] - b.range[0]) const programStartOffset = result.ast.body.reduce( diff --git a/test/index.js b/test/index.js index e4d898b..bf60f36 100644 --- a/test/index.js +++ b/test/index.js @@ -896,6 +896,44 @@ describe("Basic tests", async () => { assert.strictEqual(messages.length, 1) assert.strictEqual(messages[0].message, "'c' is not defined.") }) + + it("should sort comments by their original source position", () => { + const code = ` + + + +` + + const result = parseForESLint(code, { sourceType: "module" }) + const comments = result.ast.comments + + // Should have 2 comments + assert.strictEqual(comments.length, 2) + + // Comments should be sorted by their original position in source code + assert.strictEqual(comments[0].type, "Line") + assert.strictEqual(comments[0].value, " first") + assert.strictEqual(comments[0].loc.start.line, 3) + + assert.strictEqual(comments[1].type, "Block") + assert.strictEqual(comments[1].value, "*\n * second\n ") + assert.strictEqual(comments[1].loc.start.line, 9) + + // Verify comments are sorted by range + assert.ok(comments[0].range[0] < comments[1].range[0]) + }) }) }) From 73dcb3e4b06b2a9e8aaf035751540da0d36c06e5 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Tue, 24 Jun 2025 10:29:13 +0900 Subject: [PATCH 2/2] 10.1.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 56d21bd..211d5c8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-eslint-parser", - "version": "10.1.3", + "version": "10.1.4", "description": "The ESLint custom parser for `.vue` files.", "main": "index.js", "files": [ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy