You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Always pass endOfLine 'lf' here to be sure that the next `val.slice(0, -1)` call is always working
1821
+
endOfLine: 'lf',
1822
+
});
1823
+
returnval.slice(0,-1);
1824
+
}
1825
+
1826
+
// Since every line is parsed independently, babel will throw a SyntaxError if the line of code is only valid when there is another statement after it. This is a hack to get babel to properly parse what would otherwise be an invalid standalone JS line (e.g., `if (foo)`)
// If the error is not from the very end of the code, then this fallback approach won't work, so we throw the original error.
1842
+
if(val.length+1!==n)throwerror;
1843
+
1844
+
// At this point, we know the SyntaxError is from the fact that there's no statement after our val's statement, implying we likely need a block after it. Using an empty block to get babel to parse it without affecting the code semantics.
1845
+
// Example: `if (foo)` is not valid JS on its own, but `if (foo) {}` is.
1846
+
try{
1847
+
val=awaitthis.formatRawCode(val+'{}',useSemi);
1848
+
1849
+
// Dynamically find the index of the last `{` in the code, which is the start of the empty block, since it's been reformatted at this point and a newline has likely been added between (shouldn't rely on that behavior though)
1850
+
// Also account for any newly-introduced whitespace right before the empty block
0 commit comments