Socket
Socket
Sign inDemoInstall

@linaria/utils

Package Overview
Dependencies
65
Maintainers
4
Versions
29
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.2.1 to 4.2.2

esm/getScope.js

3

esm/collectExportsAndImports.js

@@ -5,2 +5,3 @@ /* eslint @typescript-eslint/no-use-before-define: ["error", { "functions": false }] */

import { warn } from '@linaria/logger';
import { getScope } from './getScope';
import isExports from './isExports';

@@ -550,3 +551,3 @@ import isNotNull from './isNotNull';

const binding = local.scope.getBinding(local.node.name);
const binding = getScope(local).getBinding(local.node.name);

@@ -553,0 +554,0 @@ if (!binding?.referenced) {

@@ -0,5 +1,22 @@

import { getScope } from './getScope';
function isInVoid(path) {
return path.parentPath?.isUnaryExpression({
operator: 'void'
}) ?? false;
}
function isBindingIdentifier(path) {
return path.isBindingIdentifier() && !isInVoid(path);
}
function isReferencedIdentifier(path) {
return path.isReferencedIdentifier() || isInVoid(path);
} // For some reasons, `isBindingIdentifier` returns true for identifiers inside `void` expressions.
const checkers = {
binding: ex => ex.isBindingIdentifier(),
both: ex => ex.isBindingIdentifier() || ex.isReferencedIdentifier(),
referenced: ex => ex.isReferencedIdentifier()
binding: ex => isBindingIdentifier(ex),
both: ex => isBindingIdentifier(ex) || isReferencedIdentifier(ex),
referenced: ex => isReferencedIdentifier(ex)
};

@@ -23,3 +40,3 @@ export function nonType(path) {

const binding = path.scope.getBinding(path.node.name);
const binding = getScope(path).getBinding(path.node.name);

@@ -26,0 +43,0 @@ if (!binding) {

@@ -0,1 +1,2 @@

import { getScope } from './getScope';
/**

@@ -5,2 +6,3 @@ * Checks that specified Identifier is a global `exports`

*/
export default function isExports(id) {

@@ -11,4 +13,5 @@ if (!id?.isIdentifier() || id.node.name !== 'exports') {

return id.scope.getBinding('exports') === undefined && id.scope.hasGlobal('exports');
const scope = getScope(id);
return scope.getBinding('exports') === undefined && scope.hasGlobal('exports');
}
//# sourceMappingURL=isExports.js.map

@@ -0,1 +1,2 @@

import { getScope } from './getScope';
/**

@@ -5,2 +6,3 @@ * Checks that specified Identifier is a global `require`

*/
export default function isRequire(id) {

@@ -11,4 +13,5 @@ if (!id?.isIdentifier() || id.node.name !== 'require') {

return id.scope.getBinding('require') === undefined && id.scope.hasGlobal('require');
const scope = getScope(id);
return scope.getBinding('require') === undefined && scope.hasGlobal('require');
}
//# sourceMappingURL=isRequire.js.map
import collectExportsAndImports from './collectExportsAndImports';
import { getScope } from './getScope';

@@ -54,3 +55,3 @@ function getCallee(p) {

if (callee.isIdentifier() && isHookOrCreateElement(callee.node.name)) {
const bindingPath = callee.scope.getBinding(callee.node.name)?.path;
const bindingPath = getScope(callee).getBinding(callee.node.name)?.path;
return reactImports.some(i => bindingPath?.isAncestor(i.local));

@@ -75,3 +76,3 @@ }

const bindingPath = object.scope.getBinding(object.node.name)?.path;
const bindingPath = getScope(object).getBinding(object.node.name)?.path;
return bindingPath?.isAncestor(defaultImport.local) ?? false;

@@ -78,0 +79,0 @@ }

@@ -5,2 +5,3 @@ /* eslint-disable no-restricted-syntax */

import findIdentifiers, { nonType } from './findIdentifiers';
import { getScope } from './getScope';
import isNotNull from './isNotNull';

@@ -10,3 +11,3 @@ import isRemoved from './isRemoved';

function getBinding(path) {
const binding = path.scope.getBinding(path.node.name);
const binding = getScope(path).getBinding(path.node.name);

@@ -240,3 +241,3 @@ if (!binding) {

if (!item.node || isRemoved(item)) return;
const binding = item.scope.getBinding(item.node.name);
const binding = getScope(item).getBinding(item.node.name);
if (!binding) return;

@@ -264,3 +265,3 @@ const hasReferences = binding.referencePaths.filter(i => !isRemoved(i)).length > 0;

if (paths.length === 0) return;
const rootPath = paths[0].scope.getProgramParent().path;
const rootPath = getScope(paths[0]).getProgramParent().path;

@@ -281,3 +282,3 @@ if (!fixed.has(rootPath)) {

referencedIdentifiers.push(...findIdentifiers([deletingPath], 'referenced'));
declared.push(...findIdentifiers([deletingPath], 'binding').map(i => i.scope.getBinding(i.node.name)));
declared.push(...findIdentifiers([deletingPath], 'binding').map(i => getScope(i).getBinding(i.node.name)));
mutate(deletingPath, p => {

@@ -284,0 +285,0 @@ if (!isRemoved(p)) p.remove();

import { types as t } from '@babel/core';
import { getScope } from '../getScope';
import { mutate } from '../scopeHelpers';

@@ -17,3 +18,3 @@

const functionScope = path.scope.getFunctionParent();
const functionScope = getScope(path).getFunctionParent();
const scopePath = functionScope?.path;

@@ -20,0 +21,0 @@

@@ -11,2 +11,4 @@ "use strict";

var _getScope = require("./getScope");
var _isExports = _interopRequireDefault(require("./isExports"));

@@ -570,3 +572,3 @@

const binding = local.scope.getBinding(local.node.name);
const binding = (0, _getScope.getScope)(local).getBinding(local.node.name);

@@ -573,0 +575,0 @@ if (!(binding !== null && binding !== void 0 && binding.referenced)) {

@@ -8,6 +8,26 @@ "use strict";

exports.nonType = nonType;
var _getScope = require("./getScope");
function isInVoid(path) {
var _path$parentPath$isUn, _path$parentPath;
return (_path$parentPath$isUn = (_path$parentPath = path.parentPath) === null || _path$parentPath === void 0 ? void 0 : _path$parentPath.isUnaryExpression({
operator: 'void'
})) !== null && _path$parentPath$isUn !== void 0 ? _path$parentPath$isUn : false;
}
function isBindingIdentifier(path) {
return path.isBindingIdentifier() && !isInVoid(path);
}
function isReferencedIdentifier(path) {
return path.isReferencedIdentifier() || isInVoid(path);
} // For some reasons, `isBindingIdentifier` returns true for identifiers inside `void` expressions.
const checkers = {
binding: ex => ex.isBindingIdentifier(),
both: ex => ex.isBindingIdentifier() || ex.isReferencedIdentifier(),
referenced: ex => ex.isReferencedIdentifier()
binding: ex => isBindingIdentifier(ex),
both: ex => isBindingIdentifier(ex) || isReferencedIdentifier(ex),
referenced: ex => isReferencedIdentifier(ex)
};

@@ -33,3 +53,3 @@

const binding = path.scope.getBinding(path.node.name);
const binding = (0, _getScope.getScope)(path).getBinding(path.node.name);

@@ -36,0 +56,0 @@ if (!binding) {

@@ -8,2 +8,4 @@ "use strict";

var _getScope = require("./getScope");
/**

@@ -18,4 +20,5 @@ * Checks that specified Identifier is a global `exports`

return id.scope.getBinding('exports') === undefined && id.scope.hasGlobal('exports');
const scope = (0, _getScope.getScope)(id);
return scope.getBinding('exports') === undefined && scope.hasGlobal('exports');
}
//# sourceMappingURL=isExports.js.map

@@ -8,2 +8,4 @@ "use strict";

var _getScope = require("./getScope");
/**

@@ -18,4 +20,5 @@ * Checks that specified Identifier is a global `require`

return id.scope.getBinding('require') === undefined && id.scope.hasGlobal('require');
const scope = (0, _getScope.getScope)(id);
return scope.getBinding('require') === undefined && scope.hasGlobal('require');
}
//# sourceMappingURL=isRequire.js.map

@@ -10,2 +10,4 @@ "use strict";

var _getScope = require("./getScope");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -66,5 +68,5 @@

if (callee.isIdentifier() && isHookOrCreateElement(callee.node.name)) {
var _callee$scope$getBind;
var _getScope$getBinding;
const bindingPath = (_callee$scope$getBind = callee.scope.getBinding(callee.node.name)) === null || _callee$scope$getBind === void 0 ? void 0 : _callee$scope$getBind.path;
const bindingPath = (_getScope$getBinding = (0, _getScope.getScope)(callee).getBinding(callee.node.name)) === null || _getScope$getBinding === void 0 ? void 0 : _getScope$getBinding.path;
return reactImports.some(i => bindingPath === null || bindingPath === void 0 ? void 0 : bindingPath.isAncestor(i.local));

@@ -74,3 +76,3 @@ }

if (callee.isMemberExpression()) {
var _object$scope$getBind, _bindingPath$isAncest;
var _getScope$getBinding2, _bindingPath$isAncest;

@@ -92,3 +94,3 @@ if (reactImports.some(i => i.local === callee)) {

const bindingPath = (_object$scope$getBind = object.scope.getBinding(object.node.name)) === null || _object$scope$getBind === void 0 ? void 0 : _object$scope$getBind.path;
const bindingPath = (_getScope$getBinding2 = (0, _getScope.getScope)(object).getBinding(object.node.name)) === null || _getScope$getBinding2 === void 0 ? void 0 : _getScope$getBinding2.path;
return (_bindingPath$isAncest = bindingPath === null || bindingPath === void 0 ? void 0 : bindingPath.isAncestor(defaultImport.local)) !== null && _bindingPath$isAncest !== void 0 ? _bindingPath$isAncest : false;

@@ -95,0 +97,0 @@ }

@@ -15,2 +15,4 @@ "use strict";

var _getScope = require("./getScope");
var _isNotNull = _interopRequireDefault(require("./isNotNull"));

@@ -30,3 +32,3 @@

function getBinding(path) {
const binding = path.scope.getBinding(path.node.name);
const binding = (0, _getScope.getScope)(path).getBinding(path.node.name);

@@ -263,3 +265,3 @@ if (!binding) {

if (!item.node || (0, _isRemoved.default)(item)) return;
const binding = item.scope.getBinding(item.node.name);
const binding = (0, _getScope.getScope)(item).getBinding(item.node.name);
if (!binding) return;

@@ -291,3 +293,3 @@ const hasReferences = binding.referencePaths.filter(i => !(0, _isRemoved.default)(i)).length > 0;

if (paths.length === 0) return;
const rootPath = paths[0].scope.getProgramParent().path;
const rootPath = (0, _getScope.getScope)(paths[0]).getProgramParent().path;

@@ -308,3 +310,3 @@ if (!fixed.has(rootPath)) {

referencedIdentifiers.push(...(0, _findIdentifiers.default)([deletingPath], 'referenced'));
declared.push(...(0, _findIdentifiers.default)([deletingPath], 'binding').map(i => i.scope.getBinding(i.node.name)));
declared.push(...(0, _findIdentifiers.default)([deletingPath], 'binding').map(i => (0, _getScope.getScope)(i).getBinding(i.node.name)));
mutate(deletingPath, p => {

@@ -311,0 +313,0 @@ if (!(0, _isRemoved.default)(p)) p.remove();

@@ -10,2 +10,4 @@ "use strict";

var _getScope = require("../getScope");
var _scopeHelpers = require("../scopeHelpers");

@@ -27,3 +29,3 @@

const functionScope = path.scope.getFunctionParent();
const functionScope = (0, _getScope.getScope)(path).getFunctionParent();
const scopePath = functionScope === null || functionScope === void 0 ? void 0 : functionScope.path;

@@ -30,0 +32,0 @@

{
"name": "@linaria/utils",
"description": "Blazing fast zero-runtime CSS in JS library",
"version": "4.2.1",
"version": "4.2.2",
"bugs": "https://github.com/callstack/linaria/issues",

@@ -6,0 +6,0 @@ "dependencies": {

@@ -0,1 +1,2 @@

export type { IVariableContext } from './IVariableContext';
export { default as asyncResolveFallback, syncResolve, } from './asyncResolveFallback';

@@ -2,0 +3,0 @@ export { default as collectExportsAndImports } from './collectExportsAndImports';

import type { TransformOptions } from '@babel/core';
import type { IVariableContext } from '../IVariableContext';
import type { Core } from '../babel';

@@ -12,2 +13,3 @@ export declare type ClassNameSlugVars = {

export declare type ClassNameFn = (hash: string, title: string, args: ClassNameSlugVars) => string;
export declare type VariableNameFn = (context: IVariableContext) => string;
export declare type Evaluator = (filename: string, options: StrictOptions, text: string, only: string[] | null, babel: Core) => [string, Map<string, string[]> | null];

@@ -26,4 +28,5 @@ export declare type EvalRule = {

ignore?: RegExp;
rules: EvalRule[];
tagResolver?: (source: string, tag: string) => string | null;
rules: EvalRule[];
variableNameSlug?: string | VariableNameFn;
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc