Socket
Socket
Sign inDemoInstall

metro-babel7-plugin-react-transform

Package Overview
Dependencies
Maintainers
2
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

metro-babel7-plugin-react-transform - npm Package Compare versions

Comparing version 0.49.0 to 0.49.1

2

package.json
{
"version": "0.49.0",
"version": "0.49.1",
"name": "metro-babel7-plugin-react-transform",

@@ -4,0 +4,0 @@ "main": "src/index.js",

@@ -20,10 +20,11 @@ /**

*/
"use strict"; // temporary workaround, don't mind this package
"use strict";
// temporary workaround, don't mind this package
/*eslint-disable eslint-comments/no-unlimited-disable*/
/*eslint-disable*/ var _require = require("@babel/helper-module-imports");
const addDefault = _require.addDefault;
/*eslint-disable*/
const _require = require("@babel/helper-module-imports"),
addDefault = _require.addDefault;
function find(obj, func) {

@@ -41,5 +42,5 @@ let value = undefined;

}
return false;
});
return value;

@@ -51,7 +52,9 @@ }

template = _ref.template;
function matchesPatterns(path, patterns) {
return !!find(patterns, pattern => {
return (
t.isIdentifier(path.node, { name: pattern }) ||
path.matchesPattern(pattern)
t.isIdentifier(path.node, {
name: pattern
}) || path.matchesPattern(pattern)
);

@@ -65,3 +68,5 @@ });

t.isClassMethod(classMember) &&
t.isIdentifier(classMember.key, { name: "render" })
t.isIdentifier(classMember.key, {
name: "render"
})
);

@@ -78,10 +83,13 @@ });

t.isObjectMethod(objectMember)) &&
(t.isIdentifier(objectMember.key, { name: "render" }) ||
t.isStringLiteral(objectMember.key, { value: "render" }))
(t.isIdentifier(objectMember.key, {
name: "render"
}) ||
t.isStringLiteral(objectMember.key, {
value: "render"
}))
);
})
);
}
} // `foo({ displayName: 'NAME' });` => 'NAME'
// `foo({ displayName: 'NAME' });` => 'NAME'
function getDisplayName(node) {

@@ -92,3 +100,2 @@ const property = find(

);
return property && property.value.value;

@@ -99,5 +106,4 @@ }

return !!path.findParent(parentPath => parentPath.isFunction());
}
} // wrapperFunction("componentId")(node)
// wrapperFunction("componentId")(node)
function wrapComponent(node, componentId, wrapperFunctionId) {

@@ -108,5 +114,4 @@ return t.callExpression(

);
}
} // `{ name: foo }` => Node { type: "ObjectExpression", properties: [...] }
// `{ name: foo }` => Node { type: "ObjectExpression", properties: [...] }
function toObjectExpression(object) {

@@ -116,3 +121,2 @@ const properties = Object.keys(object).map(key => {

});
return t.objectExpression(properties);

@@ -128,5 +132,3 @@ }

`);
const VISITED_KEY = "react-transform-" + Date.now();
const componentVisitor = {

@@ -143,7 +145,5 @@ Class(path) {

path.node[VISITED_KEY] = true;
const componentName = (path.node.id && path.node.id.name) || null;
const componentId = componentName || path.scope.generateUid("component");
const isInFunction = hasParentFunction(path);
this.components.push({

@@ -153,5 +153,4 @@ id: componentId,

isInFunction: isInFunction
});
}); // Can't wrap ClassDeclarations
// Can't wrap ClassDeclarations
const isStatement = t.isStatement(path.node);

@@ -163,3 +162,2 @@ const isExport = t.isExportDefaultDeclaration(path.parent);

// need to work around Babel 7 detecting duplicate decls here
path.insertAfter(

@@ -178,9 +176,7 @@ t.expressionStatement(

);
return;
}
const expression = t.toExpression(path.node);
const expression = t.toExpression(path.node); // wrapperFunction("componentId")(node)
// wrapperFunction("componentId")(node)
let wrapped = wrapComponent(

@@ -191,3 +187,2 @@ expression,

);
let constId;

@@ -220,9 +215,7 @@

path.node[VISITED_KEY] = true;
path.node[VISITED_KEY] = true; // `foo({ displayName: 'NAME' });` => 'NAME'
// `foo({ displayName: 'NAME' });` => 'NAME'
const componentName = getDisplayName(path.node);
const componentId = componentName || path.scope.generateUid("component");
const isInFunction = hasParentFunction(path);
this.components.push({

@@ -233,3 +226,2 @@ id: componentId,

});
path.replaceWith(

@@ -245,5 +237,4 @@ wrapComponent(path.node, componentId, this.wrapperFunctionId)

this.program = file.path;
this.options = this.normalizeOptions(options);
this.options = this.normalizeOptions(options); // @todo: clean this shit up
// @todo: clean this shit up
this.configuredTransformsIds = [];

@@ -275,3 +266,2 @@ }

],
transforms: options.transforms.map(opts => {

@@ -291,7 +281,5 @@ return {

);
const wrapperFunctionId = this.file.scope.generateUidIdentifier(
"wrapComponent"
);
const components = this.collectAndWrapComponents(wrapperFunctionId);

@@ -307,3 +295,2 @@

);
const configuredTransforms = this.initTransformers(

@@ -313,7 +300,4 @@ path,

);
const wrapperFunction = this.initWrapperFunction(wrapperFunctionId);
const body = this.program.node.body;
body.unshift(wrapperFunction);

@@ -323,3 +307,2 @@ configuredTransforms.reverse().forEach(node => body.unshift(node));

}
/**

@@ -332,5 +315,5 @@ * const Foo = _wrapComponent('Foo')(class Foo extends React.Component {});

*/
collectAndWrapComponents(wrapperFunctionId) {
const components = [];
this.file.path.traverse(componentVisitor, {

@@ -343,6 +326,4 @@ wrapperFunctionId: wrapperFunctionId,

});
return components;
}
/**

@@ -355,2 +336,3 @@ * const _components = {

*/
initComponentsDeclaration(componentsDeclarationId, components) {

@@ -389,3 +371,2 @@ const props = components.map(component => {

});
return t.variableDeclaration("const", [

@@ -395,3 +376,2 @@ t.variableDeclarator(componentsDeclarationId, t.objectExpression(props))

}
/**

@@ -407,2 +387,3 @@ * import _transformLib from "transform-lib";

*/
initTransformers(path, componentsDeclarationId) {

@@ -414,15 +395,13 @@ return this.options.transforms.map(transform => {

});
const transformLocals = transform.locals.map(local => {
return t.identifier(local);
});
const transformImports = transform.imports.map(importName => {
return addDefault(path, importName, { hint: importName });
return addDefault(path, importName, {
hint: importName
});
});
const configuredTransformId = this.file.scope.generateUidIdentifier(
transformName
);
const configuredTransform = t.variableDeclaration("const", [

@@ -441,9 +420,6 @@ t.variableDeclarator(

]);
this.configuredTransformsIds.push(configuredTransformId);
return configuredTransform;
});
}
/**

@@ -456,6 +432,6 @@ * function _wrapComponent(id) {

*/
initWrapperFunction(wrapperFunctionId) {
const idParam = t.identifier("id");
const componentParam = t.identifier("Component");
const expression = this.configuredTransformsIds

@@ -466,3 +442,2 @@ .reverse()

}, componentParam);
return wrapperFunctionTemplate({

@@ -469,0 +444,0 @@ WRAPPER_FUNCTION_ID: wrapperFunctionId,

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