Skip to content

Commit

Permalink
xx
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Jun 4, 2020
1 parent d5a43f4 commit e270944
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
4 changes: 4 additions & 0 deletions packages/compare/lib/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const {
isAny,
isAnyLiteral,
isArgs,
isLinkedArgs,
isImports,
isStr,
isPath,
Expand Down Expand Up @@ -204,6 +205,9 @@ function superCompare(nodeValue, value, {add, templateStore}) {
if (isArgs(value))
return true;

if (isLinkedArgs(value))
return true;

if (isObject(value)) {
add(nodeValue, value);
return true;
Expand Down
9 changes: 8 additions & 1 deletion packages/compare/lib/is.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const isStr = (a) => typeof a === 'string';
const ANY_OBJECT = '__object';
const ANY_ARRAY = '__array';
const ARGS = '__args';
const LINKED_ARGS = /__args__[a-z]$/;
const LINKED_NODE = /^__[a-z]$/;
const IMPORTS = '__imports';
const BODY = '__body';
Expand All @@ -25,6 +26,7 @@ const ALL = [
ANY_ARRAY,
ARGS,
LINKED_NODE,
LINKED_ARGS,
IMPORTS,
BODY,
ANY,
Expand All @@ -50,7 +52,8 @@ function check(str, item) {

module.exports.isNameStr = (a) => LINKED_NODE.test(a);
module.exports.isImportsStr = (a) => a === IMPORTS;
module.exports.isArgsStr = (a) => a === ARGS;
module.exports.isArgsStr = (a) => a === ARGS || LINKED_ARGS.test(a);
//module.exports.isLinkedArgsStr = (a) => LINKED_ARGS.test(a);
module.exports.isObjectStr = (a) => a === ANY_OBJECT;
module.exports.isArrayStr = (a) => a === ANY_ARRAY;
module.exports.isAnyStr = (a) => a === ANY;
Expand Down Expand Up @@ -86,6 +89,10 @@ module.exports.isArgs = (a) => {
});
};

module.exports.isLinkedArgs = (a) => {
return isIdentifier(a) && LINKED_ARGS.test(a.name);
};

module.exports.isPath = (path) => Boolean(path.node);
module.exports.isArray = isArray;

Expand Down
7 changes: 3 additions & 4 deletions packages/compare/lib/vars.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,11 @@ test('putout: compare: __args', (t) => {
const varToConst = {
report: () => '',
replace: () => ({
'const t = (__args) => f(__args)': 'const y = (__args) => f(__args)',
'const t = (__args__a) => f(__args__a)': 'const y = (__args__a) => f(__args__a)',
}),
};

const input = 'const t = (a) => f(b)';
const expected = 'const y = (a) => f(b)';
const input = 'const t = (a) => f()';

const {code} = putout(input, {
fixCount: 1,
Expand All @@ -194,7 +193,7 @@ test('putout: compare: __args', (t) => {
}],
});

t.deepEqual(code, expected, 'should equal');
t.deepEqual(code, input, 'should equal');
t.end();
});

0 comments on commit e270944

Please sign in to comment.