Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
Mesteery committed Aug 29, 2021
1 parent 638fb9b commit 51c3ec4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/internal/repl/await.js
Expand Up @@ -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;
},
Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-repl-preprocess-top-level-await.js
Expand Up @@ -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',
Expand Down

0 comments on commit 51c3ec4

Please sign in to comment.