From caec113b46b6787ec4c2476c38113ada32eeff72 Mon Sep 17 00:00:00 2001 From: ota-meshi Date: Wed, 17 Nov 2021 11:16:10 +0900 Subject: [PATCH 1/3] Support ranges for errors and warnings --- lib/html/parse-styles.js | 6 ++++++ test/index.js | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/html/parse-styles.js b/lib/html/parse-styles.js index 59c0b9b..35419ec 100644 --- a/lib/html/parse-styles.js +++ b/lib/html/parse-styles.js @@ -61,6 +61,12 @@ class LocalFixer { if (typeof object.offset === "number") { object.offset += this.style.startIndex; } + if (typeof object.endLine === "number") { + if (object.endLine === 1) { + object.endColumn += this.column; + } + object.endLine += this.line; + } } } diff --git a/test/index.js b/test/index.js index 5a094b9..410e433 100644 --- a/test/index.js +++ b/test/index.js @@ -39,7 +39,11 @@ describe("API", () => { syntax.parse("", { from: "SyntaxError.vue", }); - }).to.throw(/SyntaxError.vue:1:8: Unclosed block\b/); + }) + .to.throw(/SyntaxError.vue:1:8: Unclosed block\b/) + .with.include({ line: 1, column: 8 }) + .have.property("input") + .include({ line: 1, column: 8 }); }); it("single line with line ending syntax error", () => { From 068c7441d2fe69d0f2d59066e197875233935985 Mon Sep 17 00:00:00 2001 From: ota-meshi Date: Wed, 17 Nov 2021 11:25:02 +0900 Subject: [PATCH 2/3] fix --- test/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/index.js b/test/index.js index 410e433..6fed97e 100644 --- a/test/index.js +++ b/test/index.js @@ -59,7 +59,11 @@ describe("API", () => { syntax.parse(["", "", ""].join("\n"), { from: "SyntaxError.html", }); - }).to.throw(/SyntaxError.html:2:8: Unclosed block\b/); + }) + .to.throw(/SyntaxError.html:2:8: Unclosed block\b/) + .with.include({ line: 2, column: 8 }) + .have.property("input") + .include({ line: 2, column: 8 }); }); it("custom parse error", () => { From 70a914e1e03aa1a4e497f9955eb6af0c20c1dae6 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Wed, 24 Nov 2021 23:18:00 +0900 Subject: [PATCH 3/3] update --- package-lock.json | 14 +++++++------- package.json | 2 +- test/index.js | 42 +++++++++++++++++++++++++++++++++++++++--- 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index 03a5668..a0fb607 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3708,13 +3708,13 @@ } }, "postcss": { - "version": "8.3.11", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.3.11.tgz", - "integrity": "sha512-hCmlUAIlUiav8Xdqw3Io4LcpA1DOt7h3LSTAC4G6JGHFFaWzI6qvFt9oilvl8BmkbBRX1IhM90ZAmpk68zccQA==", + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.0.tgz", + "integrity": "sha512-BRMNx3Wy7UI89jN8H4ZVS5lQMPM2OSMkOkvDCSjwXa7PWTs24k7Lm55NXLbMbs070LvraXaxN5l1npSOS6wMVw==", "requires": { "nanoid": "^3.1.30", "picocolors": "^1.0.0", - "source-map-js": "^0.6.2" + "source-map-js": "^1.0.1" } }, "postcss-less": { @@ -4191,9 +4191,9 @@ "dev": true }, "source-map-js": { - "version": "0.6.2", - "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-0.6.2.tgz", - "integrity": "sha512-/3GptzWzu0+0MBQFrDKzw/DvvMTUORvgY6k6jd/VS6iCR4RDTKWH6v6WPwQoUO8667uQEf9Oe38DxAYWY5F/Ug==" + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.1.tgz", + "integrity": "sha512-4+TN2b3tqOCd/kaGRJ/sTYA0tR0mdXx26ipdolxcwtJVqEnqNYvlCAt1q3ypy4QMlYus+Zh34RNtYLoq2oQ4IA==" }, "source-map-resolve": { "version": "0.6.0", diff --git a/package.json b/package.json index 605e1c3..852e057 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ }, "dependencies": { "htmlparser2": "^7.1.2", - "postcss": "^8.3.11", + "postcss": "^8.4.0", "postcss-safe-parser": "^6.0.0" }, "devDependencies": { diff --git a/test/index.js b/test/index.js index 6fed97e..b52a1e3 100644 --- a/test/index.js +++ b/test/index.js @@ -44,6 +44,16 @@ describe("API", () => { .with.include({ line: 1, column: 8 }) .have.property("input") .include({ line: 1, column: 8 }); + + expect(() => { + syntax.parse("", { + from: "SyntaxError.vue", + }); + }) + .to.throw(/SyntaxError.vue:1:8: Unknown word\b/) + .with.include({ line: 1, column: 8, endLine: 1, endColumn: 11 }) + .have.property("input") + .include({ line: 1, column: 8, endLine: 1, endColumn: 11 }); }); it("single line with line ending syntax error", () => { @@ -56,14 +66,40 @@ describe("API", () => { it("multi line syntax error", () => { expect(() => { - syntax.parse(["", "", ""].join("\n"), { - from: "SyntaxError.html", - }); + syntax.parse( + [ + // + "", + "", + "", + ].join("\n"), + { + from: "SyntaxError.html", + } + ); }) .to.throw(/SyntaxError.html:2:8: Unclosed block\b/) .with.include({ line: 2, column: 8 }) .have.property("input") .include({ line: 2, column: 8 }); + + expect(() => { + syntax.parse( + [ + // + "", + "", + "", + ].join("\n"), + { + from: "SyntaxError.html", + } + ); + }) + .to.throw(/SyntaxError.html:2:8: Unknown word\b/) + .with.include({ line: 2, column: 8, endLine: 2, endColumn: 11 }) + .have.property("input") + .include({ line: 2, column: 8, endLine: 2, endColumn: 11 }); }); it("custom parse error", () => {