Skip to content

Commit 8b8ee4f

Browse files
committed
feature: @putout/operate: replaceWithMultiple: trailing comments
1 parent 3960ebe commit 8b8ee4f

File tree

8 files changed

+84
-2
lines changed

8 files changed

+84
-2
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {setTimeout} from 'node:timers/promises';
2+
import blinkenlib from '../dist/blinkenlib_node.js';
3+
/**
4+
* Machine Cross-language struct.
5+
* offsers access to some of the blink Machine struct elements,
6+
* such as registers and virtual memory.
7+
*
8+
* Javascript DataView <-----> Struct of uint32_t pointers to
9+
* important elements of Machine m
10+
*
11+
*
12+
*/
13+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import blinkenlib from '../dist/blinkenlib_node.js';
2+
import {setTimeout} from 'node:timers/promises';
3+
4+
/**
5+
* Machine Cross-language struct.
6+
* offsers access to some of the blink Machine struct elements,
7+
* such as registers and virtual memory.
8+
*
9+
* Javascript DataView <-----> Struct of uint32_t pointers to
10+
* important elements of Machine m
11+
*
12+
*
13+
*/
14+

packages/operate/lib/replace-with/replace-with-multiple.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ const {toExpression} = require('./to-expression');
55
const {isSequenceExpression} = require('@putout/babel').types;
66

77
module.exports.replaceWithMultiple = (path, nodes) => {
8-
const parentComments = path.parentPath.node.comments;
8+
const {node} = path;
99
const {
10+
trailingComments,
1011
comments,
1112
leadingComments,
12-
} = path.node;
13+
} = node;
14+
15+
delete path.node.trailingComments;
16+
17+
const parentComments = path.parentPath.node.comments;
1318

1419
const newNodes = nodes
1520
.filter(Boolean)
@@ -27,6 +32,7 @@ module.exports.replaceWithMultiple = (path, nodes) => {
2732
delete newPath[0].node.leadingComments;
2833

2934
newPath[0].node.comments = comments || parentComments;
35+
newPath.at(-1).node.trailingComments = trailingComments;
3036

3137
return newPath;
3238
};

packages/operate/lib/replace-with/replace-with-multiple.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ const putout = require('putout');
44

55
const {test} = require('supertape');
66
const {types} = require('@putout/babel');
7+
const esm = require('@putout/plugin-esm');
78
const {replaceWithMultiple} = require('./replace-with-multiple');
89
const {readFixtures} = require('../../test/fixture');
910

1011
const {CallExpression} = types;
1112
const fixture = readFixtures(__dirname);
13+
const groupImportsBySource = esm.rules['group-imports-by-source'];
1214

1315
test('putout: operate: replace-with: replaceWithMultiple', (t) => {
1416
const source = fixture.replaceWithMultipleLeadingComment;
@@ -109,3 +111,17 @@ test('putout: operate: replace-with: replaceWithMultiple: comments', (t) => {
109111
t.equal(code, expected);
110112
t.end();
111113
});
114+
115+
test('putout: operate: replace-with: replaceWithMultiple: trailing comments', (t) => {
116+
const source = fixture.replaceWithMultipleTrailingComment;
117+
const {code} = putout(source, {
118+
plugins: [
119+
['group-imports-by-source', groupImportsBySource],
120+
],
121+
});
122+
123+
const expected = fixture.replaceWithMultipleTrailingCommentFix;
124+
125+
t.equal(code, expected);
126+
t.end();
127+
});

packages/operate/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"devDependencies": {
3737
"@putout/engine-runner": "*",
3838
"@putout/eslint-flat": "^3.0.0",
39+
"@putout/plugin-esm": "*",
3940
"@putout/plugin-minify": "*",
4041
"@putout/plugin-remove-unreferenced-variables": "*",
4142
"c8": "^10.0.0",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {setTimeout} from 'node:timers/promises';
2+
import blinkenlib from '../dist/blinkenlib_node.js';
3+
/**
4+
* Machine Cross-language struct.
5+
* offsers access to some of the blink Machine struct elements,
6+
* such as registers and virtual memory.
7+
*
8+
* Javascript DataView <-----> Struct of uint32_t pointers to
9+
* important elements of Machine m
10+
*
11+
*
12+
*/
13+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import blinkenlib from '../dist/blinkenlib_node.js';
2+
import {setTimeout} from 'node:timers/promises';
3+
4+
/**
5+
* Machine Cross-language struct.
6+
* offsers access to some of the blink Machine struct elements,
7+
* such as registers and virtual memory.
8+
*
9+
* Javascript DataView <-----> Struct of uint32_t pointers to
10+
* important elements of Machine m
11+
*
12+
*
13+
*/
14+

packages/plugin-esm/lib/group-imports-by-source/index.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ test('putout: group-imports-by-source: transform', (t) => {
3131
t.end();
3232
});
3333

34+
test('putout: group-imports-by-source: transform: comment', (t) => {
35+
t.transform('comment');
36+
t.end();
37+
});
38+
3439
test('putout: group-imports-by-source: transform: convert-esm-to-commonjs', (t) => {
3540
t.transform('convert-esm-to-commonjs', {
3641
convertEsmToCommonJS,

0 commit comments

Comments
 (0)