GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: throw error when column is negative in `getIndexFromLoc` (#19831) · eslint/eslint@b8a7e7a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/languages/js/source-code
    • source-code.js
  • tests/lib/languages/js/source-code
    • source-code.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/languages/js/source-code/source-code.js‎

Copy file name to clipboardExpand all lines: lib/languages/js/source-code/source-code.js
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,12 @@ class SourceCode extends TokenStore {
816816
);
817817
}
818818

819+
if (loc.column < 0) {
820+
throw new RangeError(
821+
`Invalid column number (column ${loc.column} requested).`,
822+
);
823+
}
824+
819825
const lineStartIndex = this.lineStartIndices[loc.line - 1];
820826
const lineEndIndex =
821827
loc.line === this.lineStartIndices.length
Collapse file

‎tests/lib/languages/js/source-code/source-code.js‎

Copy file name to clipboardExpand all lines: tests/lib/languages/js/source-code/source-code.js
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,6 +2339,21 @@ describe("SourceCode", () => {
23392339
});
23402340

23412341
it("should throw a useful error if `column` is out of range", () => {
2342+
assert.throws(
2343+
() => sourceCode.getIndexFromLoc({ line: 1, column: -1 }),
2344+
"Invalid column number (column -1 requested).",
2345+
);
2346+
2347+
assert.throws(
2348+
() => sourceCode.getIndexFromLoc({ line: 1, column: -5 }),
2349+
"Invalid column number (column -5 requested).",
2350+
);
2351+
2352+
assert.throws(
2353+
() => sourceCode.getIndexFromLoc({ line: 3, column: -1 }),
2354+
"Invalid column number (column -1 requested).",
2355+
);
2356+
23422357
assert.throws(
23432358
() => sourceCode.getIndexFromLoc({ line: 3, column: 4 }),
23442359
/Column number out of range \(column 4 requested, but the length of line 3 is 4\)\./u,

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.