Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-react-defaultprops

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-react-defaultprops - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

2

lib/get-function-declaration-props.d.ts
import { types as t, NodePath } from '@babel/core';
export declare const getFunctionDeclarationProps: (path: NodePath<t.FunctionDeclaration>) => {
export declare const getFunctionDeclarationProps: (path: NodePath<t.FunctionDeclaration>, restricted?: boolean) => {
componentName: string;
props: t.ObjectExpression;
};

@@ -5,3 +5,3 @@ "use strict";

const utils_1 = require("./utils");
exports.getFunctionDeclarationProps = (path) => {
exports.getFunctionDeclarationProps = (path, restricted) => {
const { node } = path;

@@ -13,5 +13,5 @@ if (!utils_1.isComponent(node) || !utils_1.isRootPath(path.parentPath))

componentName,
props: utils_1.getProps(path, node, componentName),
props: utils_1.getProps(path, node, componentName, restricted),
};
};
//# sourceMappingURL=get-function-declaration-props.js.map
import { types as t, NodePath } from '@babel/core';
export declare const getPropsFormPath: (path: NodePath<t.FunctionDeclaration> | NodePath<t.VariableDeclaration>) => {
export declare const getPropsFormPath: (path: NodePath<t.FunctionDeclaration> | NodePath<t.VariableDeclaration>, restricted?: boolean) => {
componentName: string;
props: t.ObjectExpression;
};

@@ -7,9 +7,9 @@ "use strict";

const get_function_declaration_props_1 = require("./get-function-declaration-props");
exports.getPropsFormPath = (path) => {
exports.getPropsFormPath = (path, restricted) => {
const { node } = path;
if (core_1.types.isVariableDeclaration(node)) {
return get_variable_declaration_props_1.getVariableDeclarationProps(path);
return get_variable_declaration_props_1.getVariableDeclarationProps(path, restricted);
}
else if (core_1.types.isFunctionDeclaration(node)) {
return get_function_declaration_props_1.getFunctionDeclarationProps(path);
return get_function_declaration_props_1.getFunctionDeclarationProps(path, restricted);
}

@@ -16,0 +16,0 @@ return undefined;

import { types as t, NodePath } from '@babel/core';
export declare const getVariableDeclarationProps: (path: NodePath<t.VariableDeclaration>) => {
export declare const getVariableDeclarationProps: (path: NodePath<t.VariableDeclaration>, restricted?: boolean) => {
componentName: string;
props: t.ObjectExpression;
};

@@ -6,3 +6,3 @@ "use strict";

const utils_1 = require("./utils");
exports.getVariableDeclarationProps = (path) => {
exports.getVariableDeclarationProps = (path, restricted) => {
const { node } = path;

@@ -29,5 +29,5 @@ if (!node.declarations || node.declarations.length === 0) {

componentName,
props: utils_1.getProps(path, funcNode, componentName),
props: utils_1.getProps(path, funcNode, componentName, restricted),
};
};
//# sourceMappingURL=get-variable-declaration-props.js.map

@@ -32,3 +32,3 @@ "use strict";

const componentPath = utils_1.getComponentRecursively(path);
const propInfo = get_props_form_path_1.getPropsFormPath(componentPath);
const propInfo = get_props_form_path_1.getPropsFormPath(componentPath, false);
path.replaceWith(core_1.types.variableDeclaration(path.node.kind, [

@@ -35,0 +35,0 @@ core_1.types.variableDeclarator(declarationNode.id, propInfo ? propInfo.props : core_1.types.nullLiteral()),

import { types as t } from '@babel/core';
export declare const getPropsFormBody: (node: t.FunctionDeclaration | t.ArrowFunctionExpression) => t.AssignmentPattern[];
export declare const getPropsFormBody: (node: t.FunctionDeclaration | t.ArrowFunctionExpression, restricted: boolean) => t.AssignmentPattern[];

@@ -6,3 +6,3 @@ "use strict";

const get_props_from_object_1 = require("./get-props-from-object");
exports.getPropsFormBody = (node) => {
exports.getPropsFormBody = (node, restricted) => {
if (!node.params.length)

@@ -34,5 +34,5 @@ return undefined;

return undefined;
const assignmentPatterns = get_props_from_object_1.getPropsFromObject(variableDeclarators[0].properties, true);
const assignmentPatterns = get_props_from_object_1.getPropsFromObject(variableDeclarators[0].properties, restricted);
return assignmentPatterns;
};
//# sourceMappingURL=get-props-form-body.js.map

@@ -6,3 +6,2 @@ "use strict";

const get_props_from_object_1 = require("./get-props-from-object");
const get_props_form_body_1 = require("./get-props-form-body");
exports.getPropsFromParams = (node) => {

@@ -15,5 +14,4 @@ if (!node.params.length)

}
const assignmentPatterns = get_props_form_body_1.getPropsFormBody(node);
return assignmentPatterns;
return undefined;
};
//# sourceMappingURL=get-props-form-params.js.map

@@ -6,3 +6,3 @@ "use strict";

const is_valid_value_1 = require("./is-valid-value");
exports.getPropsFromObject = (properties, restricted) => {
exports.getPropsFromObject = (properties, restricted = true) => {
const props = properties.reduce((arr, n) => {

@@ -9,0 +9,0 @@ if (!core_1.types.isObjectProperty(n) || !core_1.types.isAssignmentPattern(n.value)) {

import { types as t, NodePath } from '@babel/core';
export declare const getProps: (path: NodePath<t.FunctionDeclaration> | NodePath<t.VariableDeclaration>, func: t.FunctionDeclaration, componentName: string) => t.ObjectExpression;
export declare const getProps: (path: NodePath<t.FunctionDeclaration> | NodePath<t.VariableDeclaration>, func: t.FunctionDeclaration, componentName: string, restricted: boolean) => t.ObjectExpression;

@@ -6,3 +6,3 @@ "use strict";

const core_1 = require("@babel/core");
exports.getProps = (path, func, componentName) => {
exports.getProps = (path, func, componentName, restricted) => {
const firstParam = func.params.length && func.params[0];

@@ -18,3 +18,3 @@ if (firstParam &&

else if (func.body.body) {
const assignmentPatterns = _1.getPropsFormBody(func);
const assignmentPatterns = _1.getPropsFormBody(func, restricted);
return _1.getObjectExpression({

@@ -21,0 +21,0 @@ componentName,

{
"name": "babel-plugin-react-defaultprops",
"version": "1.0.4",
"version": "1.0.5",
"description": "A plugin to extract es6 default parameters",

@@ -5,0 +5,0 @@ "source": "src/plugin.ts",

@@ -6,2 +6,3 @@ import { types as t, NodePath } from '@babel/core';

path: NodePath<t.FunctionDeclaration>,
restricted?: boolean,
) => {

@@ -16,4 +17,4 @@ const { node } = path;

componentName,
props: getProps(path, node, componentName),
props: getProps(path, node, componentName, restricted),
};
};

@@ -7,2 +7,3 @@ import { types as t, NodePath } from '@babel/core';

path: NodePath<t.FunctionDeclaration> | NodePath<t.VariableDeclaration>,
restricted?: boolean,
) => {

@@ -12,7 +13,13 @@ const { node } = path;

if (t.isVariableDeclaration(node)) {
return getVariableDeclarationProps(path as NodePath<t.VariableDeclaration>);
return getVariableDeclarationProps(
path as NodePath<t.VariableDeclaration>,
restricted,
);
} else if (t.isFunctionDeclaration(node)) {
return getFunctionDeclarationProps(path as NodePath<t.FunctionDeclaration>);
return getFunctionDeclarationProps(
path as NodePath<t.FunctionDeclaration>,
restricted,
);
}
return undefined;
};

@@ -6,2 +6,3 @@ import { types as t, NodePath } from '@babel/core';

path: NodePath<t.VariableDeclaration>,
restricted?: boolean,
) => {

@@ -37,4 +38,4 @@ const { node } = path;

componentName,
props: getProps(path, funcNode, componentName),
props: getProps(path, funcNode, componentName, restricted),
};
};

@@ -51,3 +51,3 @@ import { PluginOptions } from './typings';

const componentPath = getComponentRecursively(path);
const propInfo = getPropsFormPath(componentPath);
const propInfo = getPropsFormPath(componentPath, false);

@@ -54,0 +54,0 @@ path.replaceWith(

@@ -6,2 +6,3 @@ import { types as t } from '@babel/core';

node: t.FunctionDeclaration | t.ArrowFunctionExpression,
restricted: boolean,
) => {

@@ -38,3 +39,3 @@ if (!node.params.length) return undefined;

variableDeclarators[0].properties,
true,
restricted,
);

@@ -41,0 +42,0 @@

import { types as t } from '@babel/core';
import { getPropsFromObject } from './get-props-from-object';
import { getPropsFormBody } from './get-props-form-body';

@@ -14,6 +13,3 @@ export const getPropsFromParams = (

}
const assignmentPatterns = getPropsFormBody(node);
return assignmentPatterns;
return undefined;
};

@@ -6,3 +6,3 @@ import { types as t } from '@babel/core';

properties: (t.RestElement | t.ObjectProperty)[],
restricted?: boolean,
restricted = true,
): t.AssignmentPattern[] => {

@@ -9,0 +9,0 @@ const props = properties.reduce((arr, n) => {

@@ -8,2 +8,3 @@ import { getPropsFromParams, getObjectExpression, getPropsFormBody } from '.';

componentName: string,
restricted: boolean,
) => {

@@ -22,3 +23,3 @@ const firstParam = func.params.length && func.params[0];

} else if (func.body.body) {
const assignmentPatterns = getPropsFormBody(func);
const assignmentPatterns = getPropsFormBody(func, restricted);

@@ -25,0 +26,0 @@ return getObjectExpression({

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc