Skip to content

Commit

Permalink
node is a getter, not a function
Browse files Browse the repository at this point in the history
  • Loading branch information
Janther committed Aug 25, 2023
1 parent b661c6d commit 31ab567
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
3 changes: 1 addition & 2 deletions src/common/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ export function getNextNonSpaceNonCommentCharacter(text, node, locEnd) {
: util.getNextNonSpaceNonCommentCharacter(text, locEnd(node)); // V3 exposes this function directly
}

export const getNode = (path) =>
isPrettier2() ? path.getValue() : path.getNode(); // V3 deprecated `getValue`
export const getNode = (path) => (isPrettier2() ? path.getValue() : path.node); // V3 deprecated `getValue`
/* c8 ignore stop */

export function printString(rawContent, options) {
Expand Down
7 changes: 2 additions & 5 deletions tests/unit/binary-operation.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import genericPrint from '../../src/printer.js';

test('given an unknown operator then the BinaryOperation print function should throw', () => {
const mockPath = {
getNode: () => ({ type: 'BinaryOperation', operator: '?' })
};
const node = mockPath.getNode();
const mockPath = { node: { type: 'BinaryOperation', operator: '?' } };

expect(() => {
genericPrint(mockPath);
}).toThrow(
`Assertion error: no printer found for operator ${JSON.stringify(
node.operator
mockPath.node.operator
)}`
);
});
2 changes: 1 addition & 1 deletion tests/unit/comments/printer.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { printComment } from '../../../src/comments/printer.js';

test('given an unknown comment type then printComment function should throw', () => {
const mockCommentPath = { getNode: () => ({ type: 'UnknownComment' }) };
const mockCommentPath = { node: { type: 'UnknownComment' } };

expect(() => {
printComment(mockCommentPath);
Expand Down
7 changes: 3 additions & 4 deletions tests/unit/printer.test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import genericPrint from '../../src/printer.js';

test('given an unknown module type then genericPrint function should throw', () => {
const mockPath = { getNode: () => ({ type: 'UnknownModule' }) };
const node = mockPath.getNode();
const mockPath = { node: { type: 'UnknownModule' } };

expect(() => {
genericPrint(mockPath);
}).toThrow(`Unknown type: ${JSON.stringify(node.type)}`);
}).toThrow(`Unknown type: ${JSON.stringify(mockPath.node.type)}`);
});

test('if the AST contains a null node, print an empty string', () => {
// Prettier V3 avoids returning null when traversing the AST, but V2 does not.
// By mocking this, we ensure both cases are covered.
const mockPath = { getNode: () => null };
const mockPath = { node: null };

expect(genericPrint(mockPath)).toEqual('');
});

0 comments on commit 31ab567

Please sign in to comment.