Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inclusive slice operation with string end gives wrong result #882

Closed
alangpierce opened this issue Feb 27, 2017 · 0 comments
Closed

Inclusive slice operation with string end gives wrong result #882

alangpierce opened this issue Feb 27, 2017 · 0 comments
Assignees

Comments

@alangpierce
Copy link
Member

@alangpierce alangpierce commented Feb 27, 2017

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'.

@alangpierce alangpierce self-assigned this Feb 27, 2017
alangpierce added a commit to alangpierce/decaffeinate that referenced this issue Mar 7, 2017
Fixes decaffeinate#882

We need to put a `+` unary op at the front to avoid string concatenation when
adding `1`.
alangpierce added a commit that referenced this issue Mar 7, 2017
Fixes #882

We need to put a `+` unary op at the front to avoid string concatenation when
adding `1`. Also add a space after the `+` when it would otherwise create `++`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.