Socket
Socket
Sign inDemoInstall

jsx-ast-utils

Package Overview
Dependencies
66
Maintainers
3
Versions
35
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.2.2 to 3.3.0

lib/values/JSXFragment.js

29

__tests__/src/getPropValue-babelparser-test.js

@@ -124,4 +124,33 @@ /* eslint-env mocha */

});
it('should return correct representation of JSX element with children as a string', () => {
const prop = extractProp('<div foo={<bar><baz />foo</bar>} />');
const expected = '<bar><baz />foo</bar>';
const actual = getPropValue(prop);
assert.equal(actual, expected);
});
});
(fallbackToBabylon ? describe.skip : describe)('JSXFragment', () => {
it('should return correct representation of JSX fragment as a string', () => {
const prop = extractProp('<div foo={<></>} />');
const expected = '<></>';
const actual = getPropValue(prop);
assert.equal(actual, expected);
});
it('should return correct representation of JSX fragment with children as a string', () => {
const prop = extractProp('<div foo={<><div />abc</>} />');
const expected = '<><div />abc</>';
const actual = getPropValue(prop);
assert.equal(actual, expected);
});
});
describe('Identifier', () => {

@@ -128,0 +157,0 @@ it('should return string representation of variable identifier', () => {

Unreleased
==================
3.3.0 / 2022-04-30
==================
- [New] add `JSXFragment`, `JSXText`; fix `JSXElement` to handle children
- [Dev Deps] update `@babel/core`, `@babel/parser`, `eslint`, `eslint-plugin-import`
3.2.2 / 2022-03-31

@@ -5,0 +10,0 @@ ==================

@@ -20,2 +20,10 @@ 'use strict';

var _JSXFragment = require('../JSXFragment');
var _JSXFragment2 = _interopRequireDefault(_JSXFragment);
var _JSXText = require('../JSXText');
var _JSXText2 = _interopRequireDefault(_JSXText);
var _Identifier = require('./Identifier');

@@ -124,2 +132,4 @@

JSXElement: _JSXElement2.default,
JSXFragment: _JSXFragment2.default,
JSXText: _JSXText2.default,
TaggedTemplateExpression: _TaggedTemplateExpression2.default,

@@ -220,2 +230,4 @@ TemplateLiteral: _TemplateLiteral2.default,

JSXElement: noop,
JSXFragment: noop,
JSXText: noop,
ArrowFunctionExpression: noop,

@@ -222,0 +234,0 @@ FunctionExpression: noop,

7

lib/values/index.js

@@ -20,2 +20,6 @@ 'use strict';

var _JSXText = require('./JSXText');
var _JSXText2 = _interopRequireDefault(_JSXText);
var _expressions = require('./expressions');

@@ -31,3 +35,4 @@

JSXElement: _JSXElement2.default,
JSXExpressionContainer: _expressions2.default
JSXExpressionContainer: _expressions2.default,
JSXText: _JSXText2.default
};

@@ -34,0 +39,0 @@

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

"use strict";
'use strict';

@@ -13,3 +13,12 @@ Object.defineProperty(exports, "__esModule", {

function extractValueFromJSXElement(value) {
return "<" + value.openingElement.name.name + " />";
// eslint-disable-next-line global-require
var getValue = require('.').default;
var Tag = value.openingElement.name.name;
if (value.openingElement.selfClosing) {
return '<' + Tag + ' />';
}
return '<' + Tag + '>' + [].concat(value.children).map(function (x) {
return getValue(x);
}).join('') + '</' + Tag + '>';
}

10

package.json
{
"name": "jsx-ast-utils",
"version": "3.2.2",
"version": "3.3.0",
"description": "AST utility module for statically analyzing JSX",

@@ -20,5 +20,5 @@ "main": "lib/index.js",

"devDependencies": {
"@babel/core": "^7.17.8",
"@babel/core": "^7.17.10",
"@babel/eslint-parser": "^7.17.0",
"@babel/parser": "^7.17.8",
"@babel/parser": "^7.17.10",
"aud": "^2.0.0",

@@ -33,5 +33,5 @@ "babel-cli": "^6.26.0",

"babylon": "^6.18.0",
"eslint": "^8.12.0",
"eslint": "^8.14.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-import": "^2.26.0",
"flow-parser": "^0.126.1",

@@ -38,0 +38,0 @@ "in-publish": "^2.0.1",

import Literal from '../Literal';
import JSXElement from '../JSXElement';
import JSXFragment from '../JSXFragment';
import JSXText from '../JSXText';
import Identifier from './Identifier';

@@ -33,2 +35,4 @@ import TaggedTemplateExpression from './TaggedTemplateExpression';

JSXElement,
JSXFragment,
JSXText,
TaggedTemplateExpression,

@@ -124,2 +128,4 @@ TemplateLiteral,

JSXElement: noop,
JSXFragment: noop,
JSXText: noop,
ArrowFunctionExpression: noop,

@@ -126,0 +132,0 @@ FunctionExpression: noop,

import Literal from './Literal';
import JSXElement from './JSXElement';
import JSXText from './JSXText';
import JSXExpressionContainer, { extractLiteral } from './expressions';

@@ -10,2 +11,3 @@

JSXExpressionContainer,
JSXText,
};

@@ -12,0 +14,0 @@

@@ -7,3 +7,10 @@ /**

export default function extractValueFromJSXElement(value) {
return `<${value.openingElement.name.name} />`;
// eslint-disable-next-line global-require
const getValue = require('.').default;
const Tag = value.openingElement.name.name;
if (value.openingElement.selfClosing) {
return `<${Tag} />`;
}
return `<${Tag}>${[].concat(value.children).map((x) => getValue(x)).join('')}</${Tag}>`;
}
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc