diff --git a/lib/internal/repl/await.js b/lib/internal/repl/await.js index b31008cfa5d37e..f161749c103591 100644 --- a/lib/internal/repl/await.js +++ b/lib/internal/repl/await.js @@ -204,11 +204,11 @@ function processTopLevelAwait(src) { wrappedArray[from] = str; }, prepend(node, str) { - wrappedArray[node.start] = str + wrappedArray[node.start]; + const length = ArrayFrom(node.expression.value).length; + const idx = node.start - wrapped.length - wrappedArray.length - length; + wrappedArray[idx] = str + wrappedArray[idx]; }, append(node, str) { - // We need to calculate the difference between wrapped and wrappedArray - // in order to correctly handle surrogate characters. const offset = wrapped.length - wrappedArray.length; wrappedArray[node.end - 1 - offset] += str; }, diff --git a/test/parallel/test-repl-preprocess-top-level-await.js b/test/parallel/test-repl-preprocess-top-level-await.js index 0786b264c9eb5d..8ff742ed0b77f3 100644 --- a/test/parallel/test-repl-preprocess-top-level-await.js +++ b/test/parallel/test-repl-preprocess-top-level-await.js @@ -26,12 +26,16 @@ const testCases = [ '(async () => { return (await "๐Ÿ‘จโ€๐Ÿ‘จโ€๐Ÿ‘งโ€๐Ÿ‘ง๐Ÿ‘จโ€๐Ÿ‘จโ€๐Ÿ‘งโ€๐Ÿ‘ง๐Ÿ‘จโ€๐Ÿ‘จโ€๐Ÿ‘งโ€๐Ÿ‘ง") })()' ], [ 'async function foo() { await 0; }', null ], + [ 'async function foo() { await "๐Ÿ˜€๐Ÿ˜€๐Ÿ˜€"; }', + null ], [ 'async () => await 0', null ], [ 'class A { async method() { await 0 } }', null ], [ 'await 0; return 0;', null ], + [ 'await "๐Ÿ˜€๐Ÿ˜€๐Ÿ˜€"; await "๐Ÿ˜€๐Ÿ˜€๐Ÿ˜€"; "๐Ÿ˜€๐Ÿ˜€๐Ÿ˜€";', + '(async () => { await "๐Ÿ˜€๐Ÿ˜€๐Ÿ˜€"; await "๐Ÿ˜€๐Ÿ˜€๐Ÿ˜€"; return ("๐Ÿ˜€๐Ÿ˜€๐Ÿ˜€"); })()' ], [ 'var a = await 1', 'var a; (async () => { void (a = await 1) })()' ], [ 'let a = await 1',