Skip to content

Commit fbb452f

Browse files
committed
feature: @putout/plugin-putout: declare-template-variables: no arguments
1 parent ea64322 commit fbb452f

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const match = () => ({
2+
'const __a = __b': ({__a}) => isIdentifier(__a),
3+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const match = () => ({
2+
'const __a = __b': () => isIdentifier(__a),
3+
});
4+

packages/plugin-putout/lib/declare-template-variables/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,18 @@ export const report = ({node}) => {
1717
};
1818

1919
export const fix = ({path, node}) => {
20-
const [first] = path.node.params;
20+
const {params} = path.node;
2121
const property = objectProperty(node, node, COMPUTED, SHORTHAND);
2222

23+
if (!params.length) {
24+
const properties = [property];
25+
26+
params.push(objectPattern(properties));
27+
return;
28+
}
29+
30+
const [first] = params;
31+
2332
if (isIdentifier(first)) {
2433
path.node.params[0] = objectPattern([property]);
2534
return;
@@ -31,6 +40,7 @@ export const fix = ({path, node}) => {
3140
export const traverse = ({push}) => ({
3241
'(__a, path) => __b': process(push),
3342
'(__a) => __b': process(push),
43+
'() => __a': process(push),
3444
});
3545

3646
const process = (push) => (path) => {

packages/plugin-putout/lib/declare-template-variables/index.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ test('putout: declare-template-variables: transform: arrow-body', (t) => {
3232
t.end();
3333
});
3434

35+
test('putout: declare-template-variables: transform: no-args', (t) => {
36+
t.transform('no-args');
37+
t.end();
38+
});
39+
3540
test('putout: declare-template-variables: no report: declared', (t) => {
3641
t.noReport('declared');
3742
t.end();

0 commit comments

Comments
 (0)