Skip to content

Commit b412229

Browse files
committed
feature: @putout/plugin-printer: add-missing-tuples-to-type-checker: identifier
1 parent 39d764a commit b412229

7 files changed

Lines changed: 40 additions & 5 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const beforeIf = createTypeChecker([
2+
['- : -> WrongType'],
3+
['+', isBlockStatement],
4+
['- : ->', isBlockStatement],
5+
]);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const beforeIf = createTypeChecker([
2+
'- : -> WrongType',
3+
isBlockStatement,
4+
['- : ->', isBlockStatement],
5+
]);
6+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const beforeIf = fn([
2+
'- : -> WrongType',
3+
isBlockStatement,
4+
['- : ->', isBlockStatement],
5+
]);
6+

packages/plugin-printer/lib/add-missing-tuples-to-type-checker/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const {
66
isIdentifier,
77
isCallExpression,
88
arrayExpression,
9+
stringLiteral,
910
} = types;
1011

1112
const {replaceWith} = operator;
@@ -15,7 +16,14 @@ export const report = (path) => {
1516
};
1617

1718
export const fix = (path) => {
18-
replaceWith(path, arrayExpression([path.node]));
19+
const {node} = path;
20+
21+
if (isIdentifier(path)) {
22+
replaceWith(path, arrayExpression([stringLiteral('+'), node]));
23+
return;
24+
}
25+
26+
replaceWith(path, arrayExpression([node]));
1927
};
2028

2129
export const traverse = ({push}) => ({

packages/plugin-printer/lib/add-missing-tuples-to-type-checker/index.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,13 @@ test('printer: add-missing-tuples-to-type-checker: transform', (t) => {
1616
t.transform('add-missing-tuples-to-type-checker');
1717
t.end();
1818
});
19+
20+
test('printer: add-missing-tuples-to-type-checker: transform: identifier', (t) => {
21+
t.transform('identifier');
22+
t.end();
23+
});
24+
25+
test('printer: add-missing-tuples-to-type-checker: no report: not-type-checker', (t) => {
26+
t.noReport('not-type-checker');
27+
t.end();
28+
});
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export const beforeIf = createTypeChecker([
22
['-: -> !', isInsideArray],
33
['-: parentPath ->', isCoupleLines],
4-
[isIdentifierAndIdentifier],
5-
[isStringAndIdentifierInsideOneElementArray],
4+
['+', isIdentifierAndIdentifier],
5+
['+', isStringAndIdentifierInsideOneElementArray],
66
]);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export const beforeIf = createTypeChecker([
22
['-: -> !', isInsideArray],
33
['-: parentPath ->', isCoupleLines],
4-
[isIdentifierAndIdentifier],
5-
[isStringAndIdentifierInsideOneElementArray],
4+
['+', isIdentifierAndIdentifier],
5+
['+', isStringAndIdentifierInsideOneElementArray],
66
]);

0 commit comments

Comments
 (0)