Skip to content

Commit

Permalink
fix(@putout/plugin-declare-undefined-variables) declare: template.ast…
Browse files Browse the repository at this point in the history
… -> template.ast.fresh
  • Loading branch information
coderaiser committed Oct 1, 2021
1 parent 79c265c commit cccea1f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/plugin-declare-undefined-variables/lib/declare.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const fix = (declarations) => (path) => {
const scope = path.scope.getProgramParent();
const programPath = scope.path;
const bodyPath = programPath.get('body');
const node = template.ast(declarations[name]);
const node = template.ast.fresh(declarations[name]);

for (const currentPath of bodyPath) {
if (isUseStrict(currentPath)) {
Expand Down
35 changes: 35 additions & 0 deletions packages/plugin-declare-undefined-variables/test/declare.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,38 @@ test('putout: plugin: declare-undefined-variables: declare: variable', (t) => {
t.equal(code, expected);
t.end();
});

test('putout: plugin: declare-undefined-variables: cache', (t) => {
const declarations = {
test: `import {test} from 'supertape'`,
stub: `import {stub} from 'supertape'`,
};

const source = montag`
test('', (t) => {
const fn = stub();
fn();
t.end();
});
`;

const {code: secondAttempt} = putout(source, {
plugins: [
['declare-undefined-variables', declare(declarations)],
'merge-duplicate-imports',
],
});

const expected = montag`
import {stub, test} from 'supertape';
test('', (t) => {
const fn = stub();
fn();
t.end();
});
`;

t.equal(secondAttempt, expected);
t.end();
});

0 comments on commit cccea1f

Please sign in to comment.