Rapydscript: Python-like pre-compiler for JavaScript
rapydscript.com
rapydscript.com
However I think it is a mistake to go 95% of the way towards imitation. Either you go 100% as to provide compatibility, or you distinguish yourself enough to not cause confusion.
I'd much rather have compatibility with real python code, than constructs such as 'do..while' and '[4 til 9]'.
I must admit inline 'def():'s are nice though.
do while(a):
print('This loop will run at least once')
And how about using ES6 generators for Python's generator?`self` is also a poor choice of name for a reference to "the object itself": https://developer.mozilla.org/en-US/docs/Web/API/Window/self
The mapping between the input and output javascript seems quite straightforward for these examples -- and the syntax seems simple(r) at first glance.
[ed: huh, speaking of semicolons and such, I just took a look at https://github.com/atsepkov/RapydScript -- and it mentions: "Note the comma on a new line following a function declaration, it needs to be there to let the compiler know there are more attributes in this object literal, yet it can't go on the same line as the function since it would get parsed as part of the function block. Like Python, however, RapydScript supports new-line shorthand using a ;, which you could use to place the comma on the same line:"
Yeah, well. Semicolon-sometimes is worse than semi-colon always. The fact that it's shorthand for '\n' makes it perhaps even worse. Other than that, I still like what I've seen.]
But to be honest I'm not a pre-compiler advocate.
Javascript is a beautiful language once you stop blaming it for what it wasn't designed for. I feel that pre-compilers just divide the community up and unfortunately I've seen people going for CoffeeScript for example without even trying to grasp the subtleties of Vanilla JS.
Could it be that the official term is "altjs compiler" (?) [1]
Does it handle this? CoffeeScript was a bit too close to JS to get this correct.
CoffeeScript:
var ref;
(ref = [2, 1]) === [1, 2] || ref === [2, 1] || ref === [3, 5] || ref === [3, 5];
RapydScript: function _$rapyd$_in(val, arr) {
if (arr instanceof Array || typeof arr === "string") return arr.indexOf(val) != -1;
else {
if (arr.hasOwnProperty(val)) return true;
return false;
}
}
_$rapyd$_in([2,1], [[1,2], [2,1], [3,5], [3,5]]);
One thing I worried about RapydScript is generated variables. Pre-compiler needs to be scope aware. I am not sure how difficult or feasible it would be.Step 2) Profit