Skip to content

Commit c55c9aa

Browse files
committed
compiler: extra tests
1 parent 5a7d21f commit c55c9aa

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

packages/compiler/test/compile.test.ts

+8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ test('compile a single namespaced operation', (t) => {
3131
t.is(result, expected);
3232
});
3333

34+
test('compile a const assignment with single method call', (t) => {
35+
const source = 'const x = dateFns.parse()';
36+
const expected = `const x = dateFns.parse()
37+
export default [];`;
38+
const result = compile(source);
39+
t.is(result, expected);
40+
});
41+
3442
test('compile a single operation without being fussy about semicolons', (t) => {
3543
const source = 'fn()';
3644
const expected = 'export default [fn()];';

packages/compiler/test/transforms/top-level-operations.test.ts

+26
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,32 @@ test('moves a method call into the exports array', (t) => {
139139
t.is(call.callee.property.name, 'b');
140140
});
141141

142+
test('does not move a method call inside an asisignment', (t) => {
143+
const ast = createProgramWithExports([
144+
b.variableDeclaration('const', [
145+
b.variableDeclarator(
146+
b.identifier('x'),
147+
b.callExpression(
148+
b.memberExpression(b.identifier('a'), b.identifier('b')),
149+
[]
150+
)
151+
),
152+
]),
153+
]);
154+
155+
const { body } = transform(ast, [visitors]);
156+
console.log(body);
157+
158+
// should add the export
159+
t.is(body.length, 2);
160+
161+
// The first child should be an variable declaration
162+
t.true(n.VariableDeclaration.check(body[0]));
163+
164+
// the exported array should be empty
165+
t.is(body[1].declaration.elements.length, 0);
166+
});
167+
142168
test("does nothing if there's no export statement", (t) => {
143169
const ast = b.program([createOperationStatement('fn')]);
144170

0 commit comments

Comments
 (0)