@putout/printer
Advanced tools
| import {types} from '@putout/babel'; | ||
| import {createTypeChecker} from '#type-checker'; | ||
| const {isCallExpression} = types; | ||
| export const checkCallsCount = (path, {properties}) => { | ||
| const calls = properties.filter(isCallExpression); | ||
| return checkFilteredCalls(calls); | ||
| }; | ||
| const isTwoCallsWithoutName = createTypeChecker([ | ||
| ['-: length -> !', '=', 2], | ||
| ['+: 0.name -> -'], | ||
| ]); | ||
| const checkFilteredCalls = createTypeChecker([ | ||
| ['-', isTwoCallsWithoutName], | ||
| ['+: length', '>', 1], | ||
| ]); |
| import {types} from '@putout/babel'; | ||
| import {createTypeChecker} from '#type-checker'; | ||
| import {chain} from '../chain.js'; | ||
| import {checkCallsCount} from './check-calls-count.js'; | ||
| const hasPropertyWithComment = (properties) => { | ||
| return properties.find(hasComment); | ||
| }; | ||
| const isPathGet = ([property]) => { | ||
| return isCallExpression(property, { | ||
| name: 'get', | ||
| }); | ||
| }; | ||
| const { | ||
| isIfStatement, | ||
| isCallExpression, | ||
| } = types; | ||
| const isPathFirstArg = ({node, parentPath}) => { | ||
| const [first] = parentPath.node.arguments; | ||
| return node === first; | ||
| }; | ||
| function isPathLastArg({node, parentPath}) { | ||
| const last = parentPath.node.arguments.at(-1); | ||
| return node === last; | ||
| } | ||
| const isFirstArgOfCall = createTypeChecker([ | ||
| ['-: parentPath -> !CallExpression'], | ||
| ['+', isPathFirstArg], | ||
| ]); | ||
| const isLastArgInCall = createTypeChecker([ | ||
| ['-: parentPath -> !CallExpression'], | ||
| ['+', isPathLastArg], | ||
| ]); | ||
| const callWithRoot = (fn) => (a, {root}) => fn(root); | ||
| const isExcludedFromChain = createTypeChecker([ | ||
| '+: -> UnaryExpression', | ||
| '+: -> IfStatement', | ||
| ]); | ||
| const hasComment = ({type}) => type === 'CommentLine'; | ||
| const isInsideMemberCall = createTypeChecker([ | ||
| ['-: node.object -> !Identifier'], | ||
| ['-: node.property -> !Identifier'], | ||
| ['+', isLastArgInCall], | ||
| ['+: parentPath.parentPath -> CallExpression'], | ||
| ]); | ||
| const callWithProperties = (fn) => (a, {properties}) => fn(properties); | ||
| const isFindUpIf = (path) => path.find(isIfUp); | ||
| export const isLooksLikeChain = (path) => { | ||
| const [root, properties] = chain(path); | ||
| return isLikeChain(path, { | ||
| root, | ||
| properties, | ||
| }); | ||
| }; | ||
| const isLikeChain = createTypeChecker([ | ||
| ['-', isInsideMemberCall], | ||
| ['-', callWithRoot(isExcludedFromChain)], | ||
| ['-', callWithProperties(isPathGet)], | ||
| ['+', callWithProperties(hasPropertyWithComment)], | ||
| ['-', isFindUpIf], | ||
| ['-', isFirstArgOfCall], | ||
| ['+', checkCallsCount], | ||
| ]); | ||
| const isIfUp = (path) => { | ||
| const ifPath = path.find(isIfStatement); | ||
| let is = false; | ||
| if (!ifPath) | ||
| return is; | ||
| ifPath.get('test').traverse({ | ||
| MemberExpression(currentPath) { | ||
| if (path === currentPath) { | ||
| is = true; | ||
| path.stop(); | ||
| } | ||
| }, | ||
| }); | ||
| return is; | ||
| }; | ||
@@ -7,3 +7,3 @@ import {types} from '@putout/babel'; | ||
| } from '#is'; | ||
| import {isLooksLikeChain} from '../expressions/member-expression/is-looks-like-chain.js'; | ||
| import {isLooksLikeChain} from '../expressions/member-expression/is-looks-like-chain/index.js'; | ||
| import { | ||
@@ -10,0 +10,0 @@ printTrailingComments, |
| import {maybeParens} from '#maybe-parens'; | ||
| import {createTypeChecker} from '#type-checker'; | ||
| import {maybePrintComputed} from '../object-expression/maybe-print-computed.js'; | ||
| import {isLooksLikeChain} from './is-looks-like-chain.js'; | ||
| import {isLooksLikeChain} from './is-looks-like-chain/index.js'; | ||
@@ -6,0 +6,0 @@ const isObjectInsideArrow = createTypeChecker([ |
@@ -15,3 +15,3 @@ import {types} from '@putout/babel'; | ||
| import {isInsideTuple} from './is-inside-tuple.js'; | ||
| import {isLooksLikeChain} from '../member-expression/is-looks-like-chain.js'; | ||
| import {isLooksLikeChain} from '../member-expression/is-looks-like-chain/index.js'; | ||
| import {isCommaAfterSpread} from './comma.js'; | ||
@@ -18,0 +18,0 @@ import {isMultilineOption} from '../array-expression/is.js'; |
| import {types} from '@putout/babel'; | ||
| import {createTypeChecker} from '#type-checker'; | ||
| import {isLooksLikeChain} from '../../expressions/member-expression/is-looks-like-chain.js'; | ||
| import {isLooksLikeChain} from '../../expressions/member-expression/is-looks-like-chain/index.js'; | ||
@@ -5,0 +5,0 @@ const {isCallExpression} = types; |
+1
-1
| { | ||
| "name": "@putout/printer", | ||
| "version": "18.7.7", | ||
| "version": "18.7.8", | ||
| "type": "module", | ||
@@ -5,0 +5,0 @@ "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)", |
| import {types} from '@putout/babel'; | ||
| import {createTypeChecker} from '#type-checker'; | ||
| import {chain} from './chain.js'; | ||
| const hasPropertyWithComment = (properties) => { | ||
| return properties.find(hasComment); | ||
| }; | ||
| const isPathGet = ([property]) => { | ||
| return isCallExpression(property, { | ||
| name: 'get', | ||
| }); | ||
| }; | ||
| const { | ||
| isIfStatement, | ||
| isCallExpression, | ||
| } = types; | ||
| const isPathFirstArg = ({node, parentPath}) => { | ||
| const [first] = parentPath.node.arguments; | ||
| return node === first; | ||
| }; | ||
| function isPathLastArg({node, parentPath}) { | ||
| const last = parentPath.node.arguments.at(-1); | ||
| return node === last; | ||
| } | ||
| const isFirstArgOfCall = createTypeChecker([ | ||
| ['-: parentPath -> !CallExpression'], | ||
| ['+', isPathFirstArg], | ||
| ]); | ||
| const isLastArgInCall = createTypeChecker([ | ||
| ['-: parentPath -> !CallExpression'], | ||
| ['+', isPathLastArg], | ||
| ]); | ||
| const isCall = (a) => a.type === 'CallExpression'; | ||
| const callWithRoot = (fn) => (a, {root}) => fn(root); | ||
| const isExcludedFromChain = createTypeChecker([ | ||
| '+: -> UnaryExpression', | ||
| '+: -> IfStatement', | ||
| ]); | ||
| const hasComment = ({type}) => type === 'CommentLine'; | ||
| const isInsideMemberCall = createTypeChecker([ | ||
| ['-: node.object -> !Identifier'], | ||
| ['-: node.property -> !Identifier'], | ||
| ['+', isLastArgInCall], | ||
| ['+: parentPath.parentPath -> CallExpression'], | ||
| ]); | ||
| const callWithProperties = (fn) => (a, {properties}) => fn(properties); | ||
| const isFindUpIf = (path) => path.find(isIfUp); | ||
| const checkCallsCount = (path, {properties}) => { | ||
| const calls = properties.filter(isCall); | ||
| const [firstCall] = calls; | ||
| if (calls.length === 2 && !firstCall.name) | ||
| return false; | ||
| return calls.length > 1; | ||
| }; | ||
| export const isLooksLikeChain = (path) => { | ||
| const [root, properties] = chain(path); | ||
| return isLikeChain(path, { | ||
| root, | ||
| properties, | ||
| }); | ||
| }; | ||
| const isLikeChain = createTypeChecker([ | ||
| ['-', isInsideMemberCall], | ||
| ['-', callWithRoot(isExcludedFromChain)], | ||
| ['-', callWithProperties(isPathGet)], | ||
| ['+', callWithProperties(hasPropertyWithComment)], | ||
| ['-', isFindUpIf], | ||
| ['-', isFirstArgOfCall], | ||
| ['+', checkCallsCount], | ||
| ]); | ||
| const isIfUp = (path) => { | ||
| const ifPath = path.find(isIfStatement); | ||
| let is = false; | ||
| if (!ifPath) | ||
| return is; | ||
| ifPath.get('test').traverse({ | ||
| MemberExpression(currentPath) { | ||
| if (path === currentPath) { | ||
| is = true; | ||
| path.stop(); | ||
| } | ||
| }, | ||
| }); | ||
| return is; | ||
| }; |
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
325510
0.12%202
0.5%6802
0.12%