-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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(repl): Type stripping in the REPL #10934
Conversation
diagnostic.message, | ||
diagnostic.location.line, | ||
diagnostic.location.col | ||
)), |
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.
"'use strict'; void 0;\n{}", | ||
transpiled_src | ||
)) | ||
.await |
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.
A side effect of this is when the transformed AST gets printed the line numbers will no longer match.
For example, before (note line number is 2):
And after (now it's 5):
Is there a way we can fix this easily with the source map since swc can provides that? I'm not super familiar with this, but can look into it if someone believes it's worthwhile.
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.
Is there a way we can fix this easily with the source map since swc can provides that? I'm not super familiar with this, but can look into it if someone believes it's worthwhile.
I don't think it would be that simple - we'd have to store related source map for the last evaluated expression and perform ad-hoc mapping on errors. I think we can skip it for the first pass?
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.
Very impressed how little code is required to provide this functionality!
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.
Class expressions throw parse errors:
class {
foo() {
}
bar() {
}
}
Edit:
Actually, never mind that's consistent with the current behaviour anyway.
@caspervonb it's the case currently in deno 1.11 as well: |
Yeah never mind that note 👍 |
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.
Got a panic
> namespace Foo { bar: String }
undefined
> namespace Foo { bar: String }
undefined
> namespace Foo { bar: String = "32" }
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', cli/tools/repl.rs:529:45
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
@caspervonb interesting! I've opened #10938 to discuss that there (note that |
I'm thinking we should be respecting the media-type as a flag here (e.g, via --ext). |
None => value, | ||
}) | ||
} | ||
Err(err) => { |
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.
Store this as last error?
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'm not sure it's worth the trouble since it's not a thrown error.
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.
Things that would've been SyntaxError's and stored in _
today are caught at this point so.
If we don't store it's somewhat of a regression.
Do you have an example? It might be handled by swc. |
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.
LGTM 🚀
This is part of the implementation for #1158. It allows TypeScript to be inputted in the REPL and it will transpile it to JS for execution.