Socket
Socket
Sign inDemoInstall

@babel/plugin-transform-react-constant-elements

Package Overview
Dependencies
Maintainers
4
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@babel/plugin-transform-react-constant-elements - npm Package Compare versions

Comparing version 7.16.7 to 7.17.6

82

lib/index.js

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

const analyzer = {
const immutabilityVisitor = {
enter(path, state) {

@@ -63,7 +63,8 @@ const stop = () => {

if (path.isJSXClosingElement()) {
const skip = () => {
path.skip();
return;
}
};
if (path.isJSXClosingElement()) return skip();
if (path.isJSXIdentifier({

@@ -77,3 +78,3 @@ name: "ref"

if (path.isJSXIdentifier() || path.isJSXMemberExpression() || path.isJSXNamespacedName()) {
if (path.isJSXIdentifier() || path.isJSXMemberExpression() || path.isJSXNamespacedName() || path.isImmutable()) {
return;

@@ -87,25 +88,31 @@ }

if (!path.isImmutable()) {
if (path.isPure()) {
const expressionResult = path.evaluate();
const {
mutablePropsAllowed
} = state;
if (expressionResult.confident) {
const {
value
} = expressionResult;
const isMutable = !state.mutablePropsAllowed && value && typeof value === "object" || typeof value === "function";
if (mutablePropsAllowed && path.isFunction()) {
path.traverse(targetScopeVisitor, state);
return skip();
}
if (!isMutable) {
path.skip();
return;
}
} else if (_core.types.isIdentifier(expressionResult.deopt)) {
return;
}
if (!path.isPure()) return stop();
const expressionResult = path.evaluate();
if (expressionResult.confident) {
const {
value
} = expressionResult;
if (mutablePropsAllowed || value === null || typeof value !== "object" && typeof value !== "function") {
return skip();
}
stop();
} else if (_core.types.isIdentifier(expressionResult.deopt)) {
return;
}
},
stop();
}
};
const targetScopeVisitor = {
ReferencedIdentifier(path, state) {

@@ -119,2 +126,7 @@ const {

while (scope !== state.jsxScope) {
if (declares(node, scope)) return;
scope = scope.parent;
}
while (scope) {

@@ -130,2 +142,3 @@ if (scope === state.targetScope) return;

};
const hoistingVisitor = Object.assign({}, immutabilityVisitor, targetScopeVisitor);
return {

@@ -153,13 +166,2 @@ name: "transform-react-constant-elements",

const state = {
isImmutable: true,
mutablePropsAllowed,
targetScope: path.scope.getProgramParent()
};
path.traverse(analyzer, state);
if (!state.isImmutable) return;
const {
targetScope
} = state;
HOISTED.set(path.node, targetScope);
let jsxScope;

@@ -174,2 +176,14 @@ let current = path;

(_jsxScope = jsxScope) != null ? _jsxScope : jsxScope = getHoistingScope(path.scope);
const visitorState = {
isImmutable: true,
mutablePropsAllowed,
jsxScope,
targetScope: path.scope.getProgramParent()
};
path.traverse(hoistingVisitor, visitorState);
if (!visitorState.isImmutable) return;
const {
targetScope
} = visitorState;
HOISTED.set(path.node, targetScope);
if (targetScope === jsxScope) return;

@@ -176,0 +190,0 @@ const id = path.scope.generateUidBasedOnNode(name);

{
"name": "@babel/plugin-transform-react-constant-elements",
"version": "7.16.7",
"version": "7.17.6",
"description": "Treat React JSX elements as value types and hoist them to the highest scope",

@@ -26,3 +26,3 @@ "repository": {

"devDependencies": {
"@babel/core": "^7.16.7",
"@babel/core": "^7.17.5",
"@babel/helper-plugin-test-runner": "^7.16.7"

@@ -29,0 +29,0 @@ },

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