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.0.0 to 1.0.1

5

lib/values/expressions/BinaryExpression.js

@@ -76,7 +76,6 @@ 'use strict';

case 'instanceof':
try {
return leftVal instanceof rightVal;
} catch (err) {
if (typeof rightVal !== 'function') {
return false;
}
return leftVal instanceof rightVal;
default:

@@ -83,0 +82,0 @@ return undefined;

19

lib/values/expressions/Identifier.js

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

'use strict';
"use strict";

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

exports.default = extractValueFromIdentifier;
// TODO: return reserved words in their real form (i.e. String resolves to String not "String").
var JS_RESERVED = {
Array: Array,
Date: Date,
Infinity: Infinity,
Math: Math,
Number: Number,
Object: Object,
String: String,
undefined: undefined
};

@@ -22,3 +31,7 @@ /**

return name === 'undefined' ? undefined : name;
if (JS_RESERVED.hasOwnProperty(name)) {
return JS_RESERVED[name];
}
return name;
}
{
"name": "jsx-ast-utils",
"version": "1.0.0",
"version": "1.0.1",
"description": "AST utility module for statically analyzing JSX",

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

@@ -6,2 +6,6 @@ <p align="center">

</a>
<a href="https://npmjs.org/package/jsx-ast-utils">
<img src="https://img.shields.io/npm/v/jsx-ast-utils.svg"
alt="npm version">
</a>
<a href="https://github.com/evcohen/jsx-ast-utils/blob/master/LICENSE.md">

@@ -14,2 +18,6 @@ <img src="https://img.shields.io/npm/l/jsx-ast-utils.svg"

</a>
<a href='https://npmjs.org/package/jsx-ast-utils'>
<img src='https://img.shields.io/npm/dt/jsx-ast-utils.svg'
alt='Total npm downloads' />
</a>
</p>

@@ -27,3 +35,3 @@

## Usage
This is a utility module to evaluate AST objects for JSX syntax. This can be super useful when writing linting rules for JSX code. It was originally in the code for [eslint-plugin-jsx-a11y](https://github.com/evcohen/eslint-plugin-jsx-a11y), however I thought it could be useful to be extracted and maintained separately so you could write new interesting rules to statically analyze JSX.
This is a utility module to evaluate AST objects for JSX syntax. This can be super useful when writing linting rules for JSX code. It was originally in the code for [jsx-ast-utils](https://github.com/evcohen/jsx-ast-utils), however I thought it could be useful to be extracted and maintained separately so you could write new interesting rules to statically analyze JSX.

@@ -140,3 +148,3 @@ ### ESLint example

### Prop
#### Prop
Object - The JSXAttribute collected by AST parser.

@@ -153,3 +161,3 @@

### Prop
#### Prop
Object - The JSXAttribute collected by AST parser.

@@ -63,7 +63,6 @@ import getValue from './index';

case 'instanceof':
try {
return leftVal instanceof rightVal;
} catch (err) {
if (typeof rightVal !== 'function') {
return false;
}
return leftVal instanceof rightVal;
default:

@@ -70,0 +69,0 @@ return undefined;

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

// TODO: return reserved words in their real form (i.e. String resolves to String not "String").
const JS_RESERVED = {
Array,
Date,
Infinity,
Math,
Number,
Object,
String,
undefined,
};

@@ -14,3 +23,7 @@ /**

return name === 'undefined' ? undefined : name;
if (JS_RESERVED.hasOwnProperty(name)) {
return JS_RESERVED[name];
}
return name;
}

@@ -115,2 +115,65 @@ /* eslint-env mocha */

});
it('should return String object when using a reserved JavaScript object', () => {
const prop = extractProp('<div foo={String} />');
const expected = String;
const actual = getPropValue(prop);
assert.equal(expected, actual);
});
it('should return Array object when using a reserved JavaScript object', () => {
const prop = extractProp('<div foo={Array} />');
const expected = Array;
const actual = getPropValue(prop);
assert.equal(expected, actual);
});
it('should return Date object when using a reserved JavaScript object', () => {
const prop = extractProp('<div foo={Date} />');
const expected = Date;
const actual = getPropValue(prop);
assert.equal(expected, actual);
});
it('should return Infinity object when using a reserved JavaScript object', () => {
const prop = extractProp('<div foo={Infinity} />');
const expected = Infinity;
const actual = getPropValue(prop);
assert.equal(expected, actual);
});
it('should return Math object when using a reserved JavaScript object', () => {
const prop = extractProp('<div foo={Math} />');
const expected = Math;
const actual = getPropValue(prop);
assert.equal(expected, actual);
});
it('should return Number object when using a reserved JavaScript object', () => {
const prop = extractProp('<div foo={Number} />');
const expected = Number;
const actual = getPropValue(prop);
assert.equal(expected, actual);
});
it('should return Object object when using a reserved JavaScript object', () => {
const prop = extractProp('<div foo={Object} />');
const expected = Object;
const actual = getPropValue(prop);
assert.equal(expected, actual);
});
});

@@ -568,2 +631,11 @@

it('should evaluate the `instanceof` operator correctly', () => {
const prop = extractProp('<div foo={{} instanceof Object} />');
const expected = true;
const actual = getPropValue(prop);
assert.equal(expected, actual);
});
it('should evaluate the `instanceof` operator when right side is not a function', () => {
const prop = extractProp('<div foo={"bar" instanceof Baz} />');

@@ -570,0 +642,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