-
Notifications
You must be signed in to change notification settings - Fork 30k
/
test-repl-preprocess-top-level-await.js
77 lines (72 loc) · 3.13 KB
/
test-repl-preprocess-top-level-await.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
'use strict';
require('../common');
const assert = require('assert');
const { processTopLevelAwait } = require('internal/repl/await');
// Flags: --expose-internals
// This test was created based on
// https://cs.chromium.org/chromium/src/third_party/WebKit/LayoutTests/http/tests/inspector-unit/preprocess-top-level-awaits.js?rcl=358caaba5e763e71c4abb9ada2d9cd8b1188cac9
const testCases = [
[ '0',
null ],
[ 'await 0',
'(async () => { return (await 0) })()' ],
[ 'await 0;',
'(async () => { return (await 0); })()' ],
[ '(await 0)',
'(async () => { return ((await 0)) })()' ],
[ '(await 0);',
'(async () => { return ((await 0)); })()' ],
[ 'async function foo() { await 0; }',
null ],
[ 'async () => await 0',
null ],
[ 'class A { async method() { await 0 } }',
null ],
[ 'await 0; return 0;',
null ],
[ 'var a = await 1',
'let a; (async () => { void (a = await 1) })()' ],
[ 'let a = await 1',
'let a; (async () => { void (a = await 1) })()' ],
[ 'const a = await 1',
'let a; (async () => { void (a = await 1) })()' ],
[ 'for (var i = 0; i < 1; ++i) { await i }',
'let i; (async () => { for (void (i = 0); i < 1; ++i) { await i } })()' ],
[ 'for (let i = 0; i < 1; ++i) { await i }',
'let i; (async () => { for (void (i = 0); i < 1; ++i) { await i } })()' ],
[ 'var {a} = {a:1}, [b] = [1], {c:{d}} = {c:{d: await 1}}',
'let a, b, d; (async () => { void ( ({a} = {a:1}), ([b] = [1]), ' +
'({c:{d}} = {c:{d: await 1}})) })()' ],
[ 'let [a, b, c] = await ([1, 2, 3])',
'let a, b, c; (async () => { void ([a, b, c] = await ([1, 2, 3])) })()'],
[ 'let {a,b,c} = await ({a: 1, b: 2, c: 3})',
'let a, b, c; (async () => { void ({a,b,c} = ' +
'await ({a: 1, b: 2, c: 3})) })()'],
[ 'let {a: [b]} = {a: [await 1]}, [{d}] = [{d: 3}]',
'let b, d; (async () => { void ( ({a: [b]} = {a: [await 1]}),' +
' ([{d}] = [{d: 3}])) })()'],
/* eslint-disable no-template-curly-in-string */
[ 'console.log(`${(await { a: 1 }).a}`)',
'(async () => { return (console.log(`${(await { a: 1 }).a}`)) })()' ],
/* eslint-enable no-template-curly-in-string */
[ 'await 0; function foo() {}',
'let foo; (async () => { await 0; foo=function foo() {} })()' ],
[ 'await 0; class Foo {}',
'let Foo; (async () => { await 0; Foo=class Foo {} })()' ],
[ 'if (await true) { function foo() {} }',
'let foo; (async () => { if (await true) { foo=function foo() {} } })()' ],
[ 'if (await true) { class Foo{} }',
'let Foo; (async () => { if (await true) { Foo=class Foo{} } })()' ],
[ 'if (await true) { var a = 1; }',
'let a; (async () => { if (await true) { void (a = 1); } })()' ],
[ 'if (await true) { let a = 1; }',
'let a; (async () => { if (await true) { void (a = 1); } })()' ],
[ 'var a = await 1; let b = 2; const c = 3;',
'let c; let b; let a; (async () => { void (a = await 1); void (b = 2);' +
' void (c = 3); })()' ],
[ 'let o = await 1, p',
'let o, p; (async () => { void ( (o = await 1), (p=undefined)) })()' ],
];
for (const [input, expected] of testCases) {
assert.strictEqual(processTopLevelAwait(input), expected);
}