-
Notifications
You must be signed in to change notification settings - Fork 63
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
feat: add last evaluate result at _ variable in relp #135
base: main
Are you sure you want to change the base?
feat: add last evaluate result at _ variable in relp #135
Conversation
runner/repl.js
Outdated
|
||
function setLastEvalExp(prev, ret) { | ||
const lastEvalExp = `let _ = ${ret != null ? ret : "undefined"};\n`; | ||
if (/let _ = .*;\n/.test(prev)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this break after subsequent runs? If we're going with this approach it should be var
not let
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t understand what you are saying.
are you referring to redeclaring the let statement? In this case, we only declare it once for each sequence (just change a assign expression)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you just do _ =
instead of having to deal with let/var and check every time/etc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm, makes sense i’ve made the change...
runner/repl.js
Outdated
|
||
function setLastEvalExp(prev, ret) { | ||
const lastEvalExp = `let _ = ${ret != null ? ret : "undefined"};\n`; | ||
if (/let _ = .*;\n/.test(prev)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you just do _ =
instead of having to deal with let/var and check every time/etc?
I personally don't really like this approach, I feel like this should be done with some AST manipulation in |
ummmmm In this case: const age = 19 the last exp in ast became: _ = const age = 19 |
I think if you want manipulate ast directly you nneed suport vistor pattern... maybe bacoume ast to do that...
I think if you want to manipulate the ast directly, wee need to support the visitor pattern in ast or another algorithm. This ensures proper handling of cases like the last exp is const declarations or other... |
I don’t know, but I think this is not a good approach for that. I see that it is not possible to access this property using this._ or globalThis._. I don’t know how to set it global ctx with changes only in the REPL file.