Skip to content

Commit 2e413e5

Browse files
committed
feature: @putout/plugin-printer: apply-types: couple
1 parent 9c98c82 commit 2e413e5

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-2
lines changed

packages/plugin-printer/.madrun.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {run} from 'madrun';
22

33
export default {
44
'wisdom': () => run(['lint', 'coverage']),
5-
'test': () => `tape 'lib/**/*.spec.js' test/*.js 'rules/**/*.spec.js'`,
5+
'test': () => `tape 'lib/**/*.spec.js' test/*.js`,
66
'watch:test': async () => `nodemon -w lib -w test -x ${await run('test')}`,
77
'lint': () => `putout .`,
88
'fresh:lint': () => run('lint', '--fresh'),
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
const {types} = require('@putout/babel');
3+
const {isIdentifier} = types;
4+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const {types, isIdentifier} = require('@putout/babel');
2+

packages/plugin-printer/lib/apply-types/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,24 @@ module.exports.match = () => ({
1313
if (!isObjectPattern(__a))
1414
return false;
1515

16-
const [first] = __a.properties;
16+
const {properties} = __a;
17+
18+
if (properties.length > 1) {
19+
const [, second] = properties;
20+
return TYPES.includes(second.value.name);
21+
}
22+
23+
const [first] = properties;
1724

1825
return TYPES.includes(first.value.name);
1926
},
2027
});
2128

2229
module.exports.replace = () => ({
30+
'const {types, __a} = require("@putout/babel")': `{
31+
const {types} = require("@putout/babel");
32+
const {__a} = types;
33+
}`,
2334
'const __a = require("@putout/babel")': 'const __a = require("@putout/babel").types',
2435
'const __a = require("@putout/babel").types': `{
2536
const {types} = require("@putout/babel");

packages/plugin-printer/lib/apply-types/index.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ test('printer: apply-types: transform', (t) => {
2020
t.end();
2121
});
2222

23+
test('printer: apply-types: transform: couple', (t) => {
24+
t.transform('couple');
25+
t.end();
26+
});
27+
2328
test('printer: apply-types: no report: no pattern', (t) => {
2429
t.noReport('no-pattern');
2530
t.end();

0 commit comments

Comments
 (0)