Skip to content

Commit 434e4f7

Browse files
committed
fix: @putout/plugin-nodejs: strict-mode: remove-useless: get back
1 parent 897f6d9 commit 434e4f7

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
const {types: types} = require('putout');
4+
const {template: template} = require('putout');
5+
const {NumericLiteral} = types;
6+
7+
template('hello');
8+
NumericLiteral(5);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
template('hello');
2+
NumericLiteral(5);

packages/plugin-nodejs/lib/strict-mode/remove-useless/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ module.exports.traverse = ({push, store}) => ({
3131
},
3232
'Program': {
3333
exit(path) {
34+
const [, ...paths] = path.get('body');
35+
36+
for (const path of paths) {
37+
if (path.isExpressionStatement() && path.node.expression.value === 'use strict')
38+
push(path);
39+
}
40+
3441
const directives = path.get('directives');
3542

3643
if (directives.length)

packages/plugin-nodejs/lib/strict-mode/remove-useless/index.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
const {createTest} = require('@putout/test');
44
const typescript = require('@putout/plugin-typescript');
5+
const putout = require('@putout/plugin-putout');
6+
const nodejs = require('@putout/plugin-nodejs');
57

68
const remove = require('.');
9+
const convertEsmToCommonjs = nodejs.rules['convert-esm-to-commonjs'];
710

811
const test = createTest(__dirname, {
912
plugins: [
@@ -57,3 +60,12 @@ test('plugin-nodejs: strict-mode: remove: transform: typescript', (t) => {
5760
});
5861
t.end();
5962
});
63+
64+
test('plugin-nodejs: strict-mode: remove: transform: expression', (t) => {
65+
t.transform('expression', {
66+
putout,
67+
convertEsmToCommonjs,
68+
nodejs,
69+
});
70+
t.end();
71+
});

0 commit comments

Comments
 (0)