swc-playground icon indicating copy to clipboard operation
swc-playground copied to clipboard

feat: add "Log view"

Open mongolyy opened this issue 3 years ago • 7 comments

Description

Add "Log view" at side bar.(like typescript playground)

mongolyy avatar Mar 27 '22 09:03 mongolyy

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Mar 27 '22 09:03 CLAassistant

This PR isn't just to add a feature about "Log View", however it's about allowing to execute code, which is misleading.

g-plane avatar Mar 27 '22 09:03 g-plane

Thank you for your comment!

This PR isn't just to add a feature about "Log View", however it's about allowing to execute code, which is misleading.

Should I stop executing code in the playground (in terms of security risks, etc.)? If so, what is the best way to do this? I'm terribly sorry, but I don't know a good way...

mongolyy avatar Mar 27 '22 09:03 mongolyy

I noticed your comment. If execution itself is not a problem, I will use Function instead of eval()! https://developer.mozilla.org/en-US/docs/web/javascript/reference/global_objects/eval#never_use_eval!

mongolyy avatar Mar 27 '22 09:03 mongolyy

You're right. Using eval (and Function, etc.) would be dangerous, though it will be run on clients. There's an alternative: Create a JavaScript module dynamically, then use import() to execute it, but it has a disadvantage: The code will and must be run under a module context, while users may want to run as a normal script, not a module.

There's a safer way to achieve this, but it's out of scope, because it's still under ECMAScript proposal (Stage 3).

I'm not sure whether we really need this feature or not, however it's nice to have. We don't need to close this PR. Let's leave it and see how others says. If it's highly requested, we can consider it.

g-plane avatar Mar 27 '22 09:03 g-plane

Thank you very much for your detailed explanation. Due to my lack of knowledge, I did not understand everything, but I did understand the outline.

Let's leave it and see how others says. If it's highly requested, we can consider it.

Ok! I agree with this approach. ECMAScript proposal (perhaps shadowrealm ?) may also be in stage 4 when we get a response from others that they want it.

mongolyy avatar Mar 27 '22 10:03 mongolyy

Yes, it's ShadowRealm.

g-plane avatar Mar 27 '22 11:03 g-plane