Skip to content
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

Fix #1764: evalCode should always persist into the virtual sourcefile #1824

Merged
merged 1 commit into from
Jul 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export function createRepl(options: CreateReplOptions = {}) {
state,
input: code,
context,
overrideIsCompletion: false,
});
assert(result.containsTopLevelAwait === false);
return result.value;
Expand Down Expand Up @@ -512,13 +513,20 @@ function appendCompileAndEvalInput(options: {
/** Enable top-level await but only if the TSNode service allows it. */
enableTopLevelAwait?: boolean;
context: Context | undefined;
/**
* Added so that `evalCode` can be guaranteed *not* to trigger the `isCompletion`
* codepath. However, the `isCompletion` logic is ancient and maybe should be removed entirely.
* Nobody's looked at it in a long time.
*/
overrideIsCompletion?: boolean;
}): AppendCompileAndEvalInputResult {
const {
service,
state,
wrappedErr,
enableTopLevelAwait = false,
context,
overrideIsCompletion,
} = options;
let { input } = options;

Expand All @@ -533,7 +541,7 @@ function appendCompileAndEvalInput(options: {
}

const lines = state.lines;
const isCompletion = !/\n$/.test(input);
const isCompletion = overrideIsCompletion ?? !/\n$/.test(input);
const undo = appendToEvalState(state, input);
let output: string;

Expand Down