-
-
Notifications
You must be signed in to change notification settings - Fork 747
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
ES5/6/7/8/etc wishlist #1302
Comments
|
|
|
|
|
Right now we store function arguments in their own variables in the function:
Potentially if we stored them as a single string it'd be more memory efficient in all but the single-argument case, and would allow us to have default arguments, eg |
|
|
|
|
|
|
Ok, I was actually able to get |
Webassembly support? |
I did a similar exercise to @vshymanskyy and got various modern JS features working using Webpack/Babel. See: https://github.com/andrewwakeling/espruino-webpack-babel-sample Although supporting modern JS features (spread, destructuring) out-of-the-box would be convenient, these things are somewhat trivial to support if you compile the code. I would love to see fixes/improvement to ensure that more modern JS features work correctly and more reliably (after compilation). It would also be great to see improvements that would reduce the size of the compiled code. e.g. Transpiling async/await increases the bundle size a fair amount. I understand that supporting async/await isn't trivial, so I'm not pushing for this. |
This would allow for shorter syntax which is quite important for Espruino. |
This would be nice way to deal with stuff like case-insensitive Object key lookup in a standard way. |
Hi, sorry to chime in as a complete stranger, but given the whole Babel ecosystem, wouldn't it be more prudent to get complete ES5 feature coverage and then let users compile their ES6+ code down to ES5 before running through Espruino? I'm sorry if this is a naive question that has a straight answer somewhere obvious. |
Hey, no problem. It's actually pretty trivial to set up your own Babel + Espruino CLI toolchain right now if you want to - just not inside the IDE. The problem with Babel on Espruino is really:
It's not a reason not to do it, but I think there's still a place for implementing this stuff natively, especially where doing so reduces the amount of code storage needed. |
That makes sense. Thank you for the clarification.
…On Mon, Jan 7, 2019, 05:55 Gordon Williams ***@***.***> wrote:
Hey, no problem. It's actually pretty trivial to set up your own Babel +
Espruino CLI toolchain right now if you want to - just not inside the IDE.
The problem with Babel on Espruino is really:
*if you write code on the left-hand side of the IDE it goes straight to
Espruino, so you don't get to use babel - in fact babelified code will
probably be harder to interact with.
- Without a lot of work it'd also mess up the debugging functionality
- In fact in quite a few cases babel will significantly increase the
amount of code used on the micro itself
It's not a reason not to do it, but I think there's still a place for
implementing this stuff natively, especially where doing so reduces the
amount of code storage needed.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1302 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADQBPyiV1eySyBmlDdU1z8sHykrOZ72Iks5vAyeRgaJpZM4RXrRR>
.
|
@loganpowell Is there anything in particular from ES5 that you've noticed is missing? Maybe open a separate feature request, if there is something. EDIT: Oh. This is also the ES5 Wishlist. Just add it here, I guess. |
This would allow working with values that do not fit into a standard JS number. In the past, 64 bit numbers were supported, but they were (rightfully) removed to make Espruino more JS-compatible. This is the current status: const testNumber = 18446744073709551615; // 2^64 - 1, max value for a uint64
console.log(testNumber); // Logs -1 instead of 18446744073709551615
const testBigInt = 18446744073709551615n; // Syntax error Note that (for obvious reasons) this feature cannot be transpiled using babel/typescript/esbuild/whatever. |
Thanks - but I think BigInt probably won't make it in, as it would involve quite a lot of extra code to handle the arbitrary precision maths needed (I believe implementing just 64 bit maths isn't good enough?). I guess there is a possibility that Espruino could be extended with some non-standard operator overloading function such that someone could then make a BigInt class in JS though - that could be a possibility. |
Looks like it could be an easy win. I tried opening a draft PR here, but I didn't test it yet. |
New array static methods: Both for standard arrays and typed arrays (
|
I noticed that many modern transpilers/bundlers use it and take its existence for granted, so right now some transpiled code doesn't work unless you add additional quirks and polyfills to make this function available before the transpiled code generated by the transpiler/bundler. Given that Object.getOwnPropertyDescriptors = function getOwnPropertyDescriptors (obj) {
if (obj === null || obj === undefined) {
throw new TypeError('Cannot convert undefined or null to object');
}
const protoPropDescriptor = Object.getOwnPropertyDescriptor(obj, '__proto__');
const descriptors = protoPropDescriptor ? { ['__proto__']: protoPropDescriptor } : {};
for (const name of Object.getOwnPropertyNames(obj)) {
descriptors[name] = Object.getOwnPropertyDescriptor(obj, name);
}
return descriptors;
} |
This should also be something easy to implement in its simplest form, as something similar already exists on Espruino:
Sorry for the noise by the way; I'm trying to run an SDK built for the web on Espruino, so I'm writing down all the things I discover while doing it that might be beneficial to implement in the Espruino core to increase compatibility with the web. |
Thanks! These look like good ideas. It's a shame there isn't TextEncoder/Decoder might be a bit trickier to do in a spec compliant way - I think the closest might be |
Since version 15, Node.js fully supports it too. Considering that every object in Espruino is an I also noticed that Espruino actually already has an This is the shim I'm currently using to use a library that makes use of class Event {
constructor(type, options) {
this.type = type;
this.bubbles = !!(options && options.bubbles);
this.cancelable = !!(options && options.cancelable);
this.composed = !!(options && options.composed);
}
}
class CustomEvent extends Event {
constructor(type, options) {
super(type, options);
this.detail = options && options.detail;
}
}
// Every object is Espruino is a Node.js EventEmitter
// See: https://www.espruino.com/Reference#l_Object_on
class EventTarget {
dispatchEvent(event) {
return this.emit(event.type, event);
}
addEventListener(type, listener) {
this.on(type, listener);
}
removeEventListener(type, listener) {
this.removeListener(type, listener);
}
}
// Then, use it like this
class Test extends EventTarget {
test() {
this.dispatchEvent(new CustomEvent('test', { detail: { a: 'b' }}));
}
}
const t = new Test();
t.addEventListener('test', e => console.log('received test event:', e));
t.test();
// As soon as the event is emitted, this is logged in the console:
// received test event: CustomEvent: {
// "type": "test",
// "bubbles": false, "cancelable": false, "composed": false,
// "detail": {
// "a": "b"
// }
// } |
Thanks - yes, I guess that could be an idea, although it's not actually adding any functionality that's not there already so I feel like this is low priority. Especially on the more constrained devices like micro:bit 1 where we're having to cut features out to fit, it seems a step back to have to remove existing features just so we can duplicate some functions but with longer names.
That one is for use internally (it uses |
These are just different ways of doing a If you want to do it properlyYou should implement some icons and color styling for the different log types. It would also be ideal if warn and error have some sort of trace. If you implement the trace, you might as well also implement `console.trace`.Here is how Firefox does it. (in the order: debug, info, warn, error, trace) Any other methods from the |
Thanks - just done. Aliasing doesn't add a bunch of extra memory use. Stack traces are much harder to accomplish, and while we could send extra formatting chars and the IDE will parse them, I guess if someone is connected to the Bangle via something that's not the IDE, it could cause problems |
Could console.warn and console.error set the background and text color using ansi codes? |
I believe that is what gfwilliams is addressing at the end of their comment. Maybe some programs will not be able to handle ANSI codes, so better to not use them. I don't know enough about espruino to debate that. |
Exactly, yes. Potentially if you really wanted this, it's pretty easy to add a file (maybe to |
It can be polyfilled/implemented in Espruino with the single line |
Just done |
I've tried to use it maybe three times now over the course of a couple of months. The functionality is already achievable e.g. with |
Thanks - that looks like a good one to have. If you're using a regex I believe the But it's nice not to have to rely on regex edit: Just added. Looks like the replace function is only supported right now when using RegExp as the first argument, but changing that to make it work nicely while not using loads of extra flash memory on devices without much available looks like a big task so I'm not doing it at the moment |
I would like to kindly request, if it's not too much trouble, the support for async and await functions. Your assistance would be greatly appreciated. Thank you ever so much |
There's already an item for this above if you look - but as mentioned there it's extremely difficult (if not impossible) to implement in Espruino due to the fact it doesn't work by compiling down to bytecode. I don't think realistically there's a way to make this work except in very basic cases ( |
ES5/ES6 features that aren't in Espruino but that would be useful... I'll do one post per feature, and please use the
add reaction
button to vote on each one.The text was updated successfully, but these errors were encountered: