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

jsx-ast-utils

Package Overview
Dependencies
Maintainers
3
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 3.2.1 to 3.2.2

.github/workflows/node-aught.yml

15

__tests__/src/elementType-test.js

@@ -65,12 +65,11 @@ /* eslint-env mocha */

it('should return the correct type of the multiple custom object element given its node object',
() => {
const code = '<UX.Slider.Blue.Light />';
const node = getOpeningElement(code);
it('should return the correct type of the multiple custom object element given its node object', () => {
const code = '<UX.Slider.Blue.Light />';
const node = getOpeningElement(code);
const expected = 'UX.Slider.Blue.Light';
const actual = elementType(node);
const expected = 'UX.Slider.Blue.Light';
const actual = elementType(node);
assert.equal(actual, expected);
});
assert.equal(actual, expected);
});

@@ -77,0 +76,0 @@ it('should return this.Component when given its node object', () => {

@@ -1094,3 +1094,2 @@ /* eslint-env mocha */

it('should return string representation of variable identifier wrapped in a Typescript type coercion', () => {
changePlugins((pls) => [...pls, 'typescript']);
const prop = extractProp('<div foo={bar as any} />');

@@ -1186,2 +1185,20 @@

});
it('should correctly evaluate a bracketed navigation expression that prefixes with !', () => {
const prop = extractProp('<Link foo={data![0].url} />');
const expected = 'data![0].url';
const actual = getPropValue(prop);
assert.equal(actual, expected);
});
it('works with an optional chain with an `as`', () => {
const prop = extractProp('<img src={images?.footer as string} />', 'src');
const expected = 'images?.footer';
const actual = getPropValue(prop, 'src');
assert.equal(actual, expected);
});
});

@@ -1188,0 +1205,0 @@

Unreleased
==================
3.2.2 / 2022-03-31
==================
- [Fix] `TSNonNullExpression`: handle computed MemberExpressions (#109)
- [Fix] avoid a crash in ChainExpressions in a TSAsExpression
3.2.1 / 2021-09-16

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

@@ -18,3 +18,3 @@ 'use strict';

var getValue = require('.').default;
return getValue(value.expression);
return getValue(value.expression || value);
}

@@ -154,3 +154,3 @@ 'use strict';

var errorMessage = function errorMessage(expression) {
return 'The prop value with an expression type of ' + expression + ' could not be resolved. Please file an issue to get this fixed immediately.';
return 'The prop value with an expression type of ' + expression + ' could not be resolved. Please file an issue ( https://github.com/jsx-eslint/jsx-ast-utils/issues/new ) to get this fixed immediately.';
};

@@ -157,0 +157,0 @@

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

function navigate(obj, prop, value) {
if (value.computed) {
return value.optional ? obj + '?.[' + prop + ']' : obj + '[' + prop + ']';
}
return value.optional ? obj + '?.' + prop : obj + '.' + prop;
}
/**

@@ -22,3 +29,3 @@ * Extractor function for a TSNonNullExpression type value node.

// const getValue = require('.').default;
var errorMessage = 'The prop value with an expression type of TSNonNullExpression could not be resolved. Please file issue to get this fixed immediately.';
var errorMessage = 'The prop value with an expression type of TSNonNullExpression could not be resolved. Please file an issue ( https://github.com/jsx-eslint/jsx-ast-utils/issues/new ) to get this fixed immediately.';

@@ -32,2 +39,6 @@ // it's just the name

if (value.type === 'Literal') {
return value.value;
}
if (value.type === 'ThisExpression') {

@@ -51,10 +62,13 @@ return extractValueFromThisExpression();

// contains a property & is not parenthesized
if (value.type === 'MemberExpression' && (!value.extra || value.extra.parenthesized === false)) {
return '' + extractValueFromTSNonNullExpression(value.object) + (value.optional ? '?.' : '.') + extractValueFromTSNonNullExpression(value.property);
}
if (value.type === 'MemberExpression') {
// contains a property & is not parenthesized
if (!value.extra || value.extra.parenthesized === false) {
return navigate(extractValueFromTSNonNullExpression(value.object), extractValueFromTSNonNullExpression(value.property), value);
}
// contains a property & is parenthesized
if (value.type === 'MemberExpression' && value.extra && value.extra.parenthesized === true) {
return '(' + extractValueFromTSNonNullExpression(value.object) + (value.optional ? '?.' : '.') + extractValueFromTSNonNullExpression(value.property) + ')';
// contains a property & is parenthesized
if (value.extra && value.extra.parenthesized === true) {
var result = navigate(extractValueFromTSNonNullExpression(value.object), extractValueFromTSNonNullExpression(value.property), value);
return '(' + result + ')';
}
}

@@ -61,0 +75,0 @@

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

@@ -9,3 +9,4 @@ "main": "lib/index.js",

"build": "babel src --out-dir lib",
"prepublish": "not-in-publish || (safe-publish-latest && npm test && npm run build)",
"prepublishOnly": "safe-publish-latest && npm test && npm run build",
"prepublish": "not-in-publish || npm run prepublishOnly",
"prelint": "npm run build",

@@ -20,8 +21,8 @@ "lint": "eslint .",

"devDependencies": {
"@babel/core": "^7.15.5",
"@babel/parser": "^7.15.6",
"aud": "^1.1.5",
"@babel/core": "^7.17.8",
"@babel/eslint-parser": "^7.17.0",
"@babel/parser": "^7.17.8",
"aud": "^2.0.0",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-eslint": "^10.1.0",
"babel-jest": "^20.0.3",

@@ -33,5 +34,5 @@ "babel-plugin-transform-object-rest-spread": "^6.26.0",

"babylon": "^6.18.0",
"eslint": "^7.32.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.24.2",
"eslint": "^8.12.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.25.4",
"flow-parser": "^0.126.1",

@@ -41,6 +42,6 @@ "in-publish": "^2.0.1",

"jest-cli": "^20.0.4",
"object.entries": "^1.1.4",
"object.fromentries": "^2.0.4",
"object.entries": "^1.1.5",
"object.fromentries": "^2.0.5",
"rimraf": "^2.7.1",
"safe-publish-latest": "^1.1.4"
"safe-publish-latest": "^2.0.0"
},

@@ -75,5 +76,5 @@ "engines": {

"dependencies": {
"array-includes": "^3.1.3",
"array-includes": "^3.1.4",
"object.assign": "^4.1.2"
}
}

@@ -12,3 +12,3 @@ /**

const getValue = require('.').default;
return getValue(value.expression);
return getValue(value.expression || value);
}
const extractValueFromThisExpression = require('./ThisExpression').default;
function navigate(obj, prop, value) {
if (value.computed) {
return value.optional ? `${obj}?.[${prop}]` : `${obj}[${prop}]`;
}
return value.optional ? `${obj}?.${prop}` : `${obj}.${prop}`;
}
/**

@@ -23,2 +30,6 @@ * Extractor function for a TSNonNullExpression type value node.

if (value.type === 'Literal') {
return value.value;
}
if (value.type === 'ThisExpression') {

@@ -40,10 +51,21 @@ return extractValueFromThisExpression();

// contains a property & is not parenthesized
if (value.type === 'MemberExpression' && (!value.extra || value.extra.parenthesized === false)) {
return `${extractValueFromTSNonNullExpression(value.object)}${value.optional ? '?.' : '.'}${extractValueFromTSNonNullExpression(value.property)}`;
}
if (value.type === 'MemberExpression') {
// contains a property & is not parenthesized
if ((!value.extra || value.extra.parenthesized === false)) {
return navigate(
extractValueFromTSNonNullExpression(value.object),
extractValueFromTSNonNullExpression(value.property),
value,
);
}
// contains a property & is parenthesized
if (value.type === 'MemberExpression' && value.extra && value.extra.parenthesized === true) {
return `${'('}${extractValueFromTSNonNullExpression(value.object)}${value.optional ? '?.' : '.'}${extractValueFromTSNonNullExpression(value.property)}${')'}`;
// contains a property & is parenthesized
if (value.extra && value.extra.parenthesized === true) {
const result = navigate(
extractValueFromTSNonNullExpression(value.object),
extractValueFromTSNonNullExpression(value.property),
value,
);
return `(${result})`;
}
}

@@ -50,0 +72,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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