Skip to content

Commit abe5174

Browse files
committed
fix: fix regression of originalIndexFromIndex
This is regression of 1969f3b fix #4
1 parent 542fb05 commit abe5174

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/StringSource.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ export default class StringSource {
5757
originalIndexFromIndex(generatedIndex) {
5858
let hitTokenMaps = this.tokenMaps.filter((tokenMap, index) => {
5959
const generated = tokenMap.generated;
60-
const nextGenerated = this.tokenMaps[index + 1];
60+
const nextTokenMap = this.tokenMaps[index + 1];
61+
const nextGenerated = nextTokenMap ? nextTokenMap.generated : null;
6162
if (nextGenerated) {
6263
if (generated[0] <= generatedIndex && generatedIndex < nextGenerated[0]) {
6364
return true;

test/StringSource-test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,15 @@ describe("StringSource", function() {
226226
assert.equal(result, "alt text");
227227
assert.equal(source.originalIndexFromIndex(-1), null);
228228
});
229-
it("is test for https://github.com/textlint/textlint-util-to-string/issues/4", function() {
229+
it("test for https://github.com/textlint/textlint-util-to-string/issues/4", function() {
230+
// related https://github.com/textlint/textlint-util-to-string/commit/1969f3b82bc490b435e2b2a631cf89a7158d80ed
230231
const originalText = "This link contains an [errror](index.html).";
231232
const AST = parse(originalText);
232233
const source = new StringSource(AST);
233234
const originalPosition = source.originalPositionFromIndex(22);
234235
assert.deepEqual(originalPosition, {
235236
line: 1,
236-
column: 24
237+
column: 23
237238
});
238239
});
239240
});

0 commit comments

Comments
 (0)