Skip to content

Inclusive slice operation with string end gives wrong result #882

@alangpierce

Description

@alangpierce

decaffeinate is producing the wrong JavaScript based on my CoffeeScript input:

a = [1, 2, 3, 4, 5]
start = '1'
end = '3'
console.log a[start..end]

(repl)

I get this output:

a = [1, 2, 3, 4, 5];
start = '1';
end = '3';
console.log(a.slice(start, end + 1 || undefined));

Here's what I expect it to be instead:

a = [1, 2, 3, 4, 5];
start = '1';
end = '3';
console.log(a.slice(start, +end + 1 || undefined));

Otherwise, it takes the range from '1' to '31'.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions