Skip to content

Commit

Permalink
compiler: extra tests
Browse files Browse the repository at this point in the history
  • Loading branch information
josephjclark committed Jul 26, 2024
1 parent 5a7d21f commit c55c9aa
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/compiler/test/compile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ test('compile a single namespaced operation', (t) => {
t.is(result, expected);
});

test('compile a const assignment with single method call', (t) => {
const source = 'const x = dateFns.parse()';
const expected = `const x = dateFns.parse()
export default [];`;
const result = compile(source);
t.is(result, expected);
});

test('compile a single operation without being fussy about semicolons', (t) => {
const source = 'fn()';
const expected = 'export default [fn()];';
Expand Down
26 changes: 26 additions & 0 deletions packages/compiler/test/transforms/top-level-operations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,32 @@ test('moves a method call into the exports array', (t) => {
t.is(call.callee.property.name, 'b');
});

test('does not move a method call inside an asisignment', (t) => {
const ast = createProgramWithExports([
b.variableDeclaration('const', [
b.variableDeclarator(
b.identifier('x'),
b.callExpression(
b.memberExpression(b.identifier('a'), b.identifier('b')),
[]
)
),
]),
]);

const { body } = transform(ast, [visitors]);
console.log(body);

// should add the export
t.is(body.length, 2);

// The first child should be an variable declaration
t.true(n.VariableDeclaration.check(body[0]));

// the exported array should be empty
t.is(body[1].declaration.elements.length, 0);
});

test("does nothing if there's no export statement", (t) => {
const ast = b.program([createOperationStatement('fn')]);

Expand Down

0 comments on commit c55c9aa

Please sign in to comment.