Skip to content

Commit

Permalink
add correctness tests for namespace exports
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Jun 22, 2020
1 parent 39e8f7b commit f46f280
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions scripts/end-to-end-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,54 @@
}, { async: true }),
)

// Object rest pattern tests
tests.push(
// Test the correctness of side effect order for the TypeScript namespace exports
test(['in.ts', '--outfile=node.js'], {
'in.ts': `
function fn() {
let trail = []
let t = k => (trail.push(k), k)
let [
{ [t('a')]: a } = { a: t('x') },
{ [t('b')]: b, ...c } = { b: t('y') },
{ [t('d')]: d } = { d: t('z') },
] = [{ a: 1 }, { b: 2, bb: 3 }]
return JSON.stringify({a, b, c, d, trail})
}
namespace ns {
let trail = []
let t = k => (trail.push(k), k)
export let [
{ [t('a')]: a } = { a: t('x') },
{ [t('b')]: b, ...c } = { b: t('y') },
{ [t('d')]: d } = { d: t('z') },
] = [{ a: 1 }, { b: 2, bb: 3 }]
export let result = JSON.stringify({a, b, c, d, trail})
}
if (fn() !== ns.result) throw 'fail'
`,
}),

// Test the array and object rest patterns in TypeScript namespace exports
test(['in.ts', '--outfile=node.js'], {
'in.ts': `
let obj = {};
({a: obj.a, ...obj.b} = {a: 1, b: 2, c: 3});
[obj.c, , ...obj.d] = [1, 2, 3];
({e: obj.e, f: obj.f = 'f'} = {e: 'e'});
[obj.g, , obj.h = 'h'] = ['g', 'gg'];
namespace ns {
export let {a, ...b} = {a: 1, b: 2, c: 3};
export let [c, , ...d] = [1, 2, 3];
export let {e, f = 'f'} = {e: 'e'};
export let [g, , h = 'h'] = ['g', 'gg'];
}
if (JSON.stringify(obj) !== JSON.stringify(ns)) throw 'fail'
`,
}),
)

// Test writing to stdout
tests.push(
// These should succeed
Expand Down

0 comments on commit f46f280

Please sign in to comment.