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

jsx-ast-utils

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsx-ast-utils - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

5

CHANGELOG.md

@@ -0,1 +1,6 @@

1.1.1 / 2016-06-12
==================
- [fix] Better support for expressions in `TemplateLiteral` extraction.
1.1.0 / 2016-06-10

@@ -2,0 +7,0 @@ ==================

13

lib/hasProp.js

@@ -9,2 +9,9 @@ 'use strict';

exports.hasEveryProp = hasEveryProp;
var _propName = require('./propName');
var _propName2 = _interopRequireDefault(_propName);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var DEFAULT_OPTIONS = {

@@ -24,3 +31,3 @@ spreadStrict: true,

var propName = options.ignoreCase ? prop.toUpperCase() : prop;
var propToCheck = options.ignoreCase ? prop.toUpperCase() : prop;

@@ -33,5 +40,5 @@ return props.some(function (attribute) {

var currentProp = options.ignoreCase ? attribute.name.name.toUpperCase() : attribute.name.name;
var currentProp = options.ignoreCase ? (0, _propName2.default)(attribute).toUpperCase() : (0, _propName2.default)(attribute);
return propName === currentProp;
return propToCheck === currentProp;
});

@@ -38,0 +45,0 @@ }

@@ -30,2 +30,4 @@ 'use strict';

return part.name === 'undefined' ? raw : raw + '{' + part.name + '}';
} else if (type.indexOf('Expression') > -1) {
return raw + '{' + type + '}';
}

@@ -32,0 +34,0 @@

{
"name": "jsx-ast-utils",
"version": "1.1.0",
"version": "1.1.1",
"description": "AST utility module for statically analyzing JSX",

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

@@ -0,1 +1,3 @@

import propName from './propName';
const DEFAULT_OPTIONS = {

@@ -11,3 +13,3 @@ spreadStrict: true,

export default function hasProp(props = [], prop = '', options = DEFAULT_OPTIONS) {
const propName = options.ignoreCase ? prop.toUpperCase() : prop;
const propToCheck = options.ignoreCase ? prop.toUpperCase() : prop;

@@ -21,6 +23,6 @@ return props.some(attribute => {

const currentProp = options.ignoreCase ?
attribute.name.name.toUpperCase() :
attribute.name.name;
propName(attribute).toUpperCase() :
propName(attribute);
return propName === currentProp;
return propToCheck === currentProp;
});

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

@@ -24,2 +24,4 @@ /**

return part.name === 'undefined' ? raw : `${raw}{${part.name}}`;
} else if (type.indexOf('Expression') > -1) {
return `${raw}{${type}}`;
}

@@ -26,0 +28,0 @@

@@ -21,2 +21,15 @@ /* eslint-env mocha */

it('should throw error when trying to get value from unknown node type', () => {
const prop = {
type: 'JSXAttribute',
value: {
type: 'JSXExpressionContainer',
},
};
assert.throws(() => {
getLiteralPropValue(prop);
}, Error);
});
describe('Null', () => {

@@ -23,0 +36,0 @@ it('should return true when no value is given', () => {

@@ -21,2 +21,15 @@ /* eslint-env mocha */

it('should throw error when trying to get value from unknown node type', () => {
const prop = {
type: 'JSXAttribute',
value: {
type: 'JSXExpressionContainer',
},
};
assert.throws(() => {
getPropValue(prop);
}, Error);
});
describe('Null', () => {

@@ -192,2 +205,20 @@ it('should return true when no value is given', () => {

});
it('should return template literal with expression type wrapped in curly braces', () => {
const prop = extractProp('<div foo={`bar ${baz()}`} />');
const expected = 'bar {CallExpression}';
const actual = getPropValue(prop);
assert.equal(expected, actual);
});
it('should ignore non-expressions in the template literal', () => {
const prop = extractProp('<div foo={`bar ${<baz />}`} />');
const expected = 'bar ';
const actual = getPropValue(prop);
assert.equal(expected, actual);
});
});

@@ -194,0 +225,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