Comments in between if, else-if and else blocks produces syntax error
See original GitHub issueIt seems when there are in-line comments between if blocks the else or else-if line is drug up into the comments line resulting in a syntax error. This was produced by running prettier
no additional options.
//
// checks the parent element for time range values or date values
function to_and_from_timestamps(parent) {
var from_ts = '';
var to_ts = '';
var time_values = get_all_form_values(parent);
//
// getting time range data
if (time_values.hasOwnProperty('time_range')) {
from_ts = time_values['time_range'].split('|')[0] + ' 00:00:00';
to_ts = time_values['time_range'].split('|')[1] + ' 23:59:59';
}
// using calendar inputs instead
else {
from_ts = '{st-year}-{st-month}-{st-day} 00:00:00'.format(time_values);
to_ts = '{en-year}-{en-month}-{en-day} 23:59:59'.format(time_values);
}
//
return { from_ts: from_ts, to_ts: to_ts };
}
becomes…
//
// checks the parent element for time range values or date values
function to_and_from_timestamps(parent) {
var from_ts = "";
var to_ts = "";
var time_values = get_all_form_values(parent);
//
// getting time range data
if (time_values.hasOwnProperty("time_range")) {
from_ts = time_values["time_range"].split("|")[0] + " 00:00:00";
to_ts = time_values["time_range"].split("|")[1] + " 23:59:59";
}
// using calendar inputs instead else {
from_ts = "{st-year}-{st-month}-{st-day} 00:00:00".format(time_values);
to_ts = "{en-year}-{en-month}-{en-day} 23:59:59".format(time_values);
}
//
return { from_ts: from_ts, to_ts: to_ts };
}
Issue Analytics
- State:
- Created 7 years ago
- Reactions:6
- Comments:8 (7 by maintainers)
Top Results From Across the Web
if / else errors - learn how to fix these - Codecademy
Typically the following error messages are caused by faulty if/else syntax ------ - *"syntax error"* - *"missing operand; found else"* - *"Unexpected token ......
Read more >else if statement in java returning syntax error - Stack Overflow
Following that, there are two lines of code which execute without problem and then an else is discovered and it causes the error....
Read more >Else-If in Python – Python If Statement Example Syntax
In the if-else statement, we have two branches incase the statement is true or false. The if block is executed in case the...
Read more >Control flow and error handling - JavaScript - MDN Web Docs
In general, it's good practice to always use block statements—especially when nesting if statements: if (condition) { // Statements for when ...
Read more >Python Keywords: An Introduction
Python keywords make up the fundamental building blocks of any Python program. In this tutorial, you'll learn the basic syntax and usage for...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks. Comments are going to be re-hauled this week and should be a lot more stable.
See #487 as a follow-up, it no longer produces invalid code but we need to fix the formatting