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

Strip sourcemap comment from REPL JS before diffing and executing #1580

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Strip sourcemap comment from REPL JS before diffing and executing
  • Loading branch information
cspotcode committed Dec 27, 2021
commit 561b6ddd4a5ca873edf3062068623583a32be128
10 changes: 9 additions & 1 deletion src/repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 480,8 @@ export function createEvalAwarePartialHost(
return { readFile, fileExists };
}

const sourcemapCommentRe = /\/\/# ?sourceMappingURL=\S [\s\r\n]*$/;

type AppendCompileAndEvalInputResult =
| { containsTopLevelAwait: true; valuePromise: Promise<any> }
| { containsTopLevelAwait: false; value: any };
Expand Down Expand Up @@ -525,8 527,14 @@ function appendCompileAndEvalInput(options: {

output = adjustUseStrict(output);

const outputWithoutSourcemapComment = output.replace(sourcemapCommentRe, '');
const oldOutputWithoutSourcemapComment = state.output.replace(
sourcemapCommentRe,
''
);

// Use `diff` to check for new JavaScript to execute.
const changes = diffLines(state.output, output);
const changes = diffLines(oldOutputWithoutSourcemapComment, outputWithoutSourcemapComment);

if (isCompletion) {
undo();
Expand Down