Socket
Socket
Sign inDemoInstall

jsx-ast-utils

Package Overview
Dependencies
69
Maintainers
3
Versions
35
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.3.3 to 3.3.4

8

__tests__/helper.js

@@ -21,2 +21,3 @@ /* eslint-env jest */

let plugins = [...defaultPlugins];
let isESM = false;

@@ -37,4 +38,9 @@ export function setParserName(name) {

export function setIsESM() {
isESM = true;
}
beforeEach(() => {
plugins = [...defaultPlugins];
isESM = false;
});

@@ -48,3 +54,3 @@

try {
return babelParser.parse(code, { plugins, sourceFilename: 'test.js' });
return babelParser.parse(code, { plugins, sourceFilename: 'test.js', ...(isESM && { sourceType: 'module' }) });
} catch (_) {

@@ -51,0 +57,0 @@ // eslint-disable-next-line no-console

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

setParserName,
setIsESM,
} from '../helper';

@@ -501,2 +502,17 @@ import { getLiteralPropValue } from '../../src/getPropValue';

describeIfNotBabylon('import.meta', () => {
beforeEach(() => {
setIsESM();
});
it('should return null', () => {
const prop = extractProp('<div foo={import.meta.env.whyIsThisNotOnProcess} />');
const expected = null;
const actual = getLiteralPropValue(prop);
assert.deepEqual(actual, expected);
});
});
describeIfNotBabylon('Typescript', () => {

@@ -503,0 +519,0 @@ beforeEach(() => {

@@ -1151,2 +1151,9 @@ /* eslint-env mocha */

it('should return string representation of a TSNonNullExpression of form `function()!.property`', () => {
const prop = extractProp('<div foo={bar()!.bar} />');
const expected = 'bar()!.bar';
const actual = getPropValue(prop);
assert.equal(actual, expected);
});
it('should return string representation of a TSNonNullExpression of form `object!.property!`', () => {

@@ -1153,0 +1160,0 @@ const prop = extractProp('<div foo={bar!.bar!} />');

@@ -1,4 +0,25 @@

Unreleased
==================
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v3.3.4](https://github.com/jsx-eslint/jsx-ast-utils/compare/v3.3.3...v3.3.4) - 2023-06-28
### Commits
- [Refactor] use `array.prototype.flat` `object.values` over `.reduce` [`bad51d0`](https://github.com/jsx-eslint/jsx-ast-utils/commit/bad51d062000ffdc19d925723a6515458318cf92)
- [meta] add `auto-changelog` [`af1de69`](https://github.com/jsx-eslint/jsx-ast-utils/commit/af1de693d1005144c13a75573631a670fa44547e)
- [Tests] add test for `import.meta` [`1d39f58`](https://github.com/jsx-eslint/jsx-ast-utils/commit/1d39f58c7bc6a89aa936e666b76e355c9436e854)
- [Dev Deps] update `@babel/core`, `@babel/eslint-parser`, `@babel/parser`, `aud`, `eslint`, `eslint-plugin-import` [`3baaf76`](https://github.com/jsx-eslint/jsx-ast-utils/commit/3baaf76c9c48ae85687ed23a3b9894c45927e081)
- [Fix] `TSNonNullExpression`: Handle function calls [`26cc3c4`](https://github.com/jsx-eslint/jsx-ast-utils/commit/26cc3c48165518b9fcdc9c625d918accc3e00107)
- [Dev Deps] update `eslint`, `@babel/core`, `@babel/parser`, `object.entries`, `object.fromentries` [`0e4f80c`](https://github.com/jsx-eslint/jsx-ast-utils/commit/0e4f80c2129c5b5ee50e4df2f25c5fb6728cbe8e)
- [Dev Deps] update `@babel/core`, `@babel/eslint-parser`, `@babel/parser`, `aud` [`b5427a6`](https://github.com/jsx-eslint/jsx-ast-utils/commit/b5427a65fac33e2264461b072b3edb078242dc85)
- [meta] run build in prepack, not prepublish [`a0f4f38`](https://github.com/jsx-eslint/jsx-ast-utils/commit/a0f4f383ddf82cd2914c7e594f356d9a78c80570)
- [Deps] update `array-includes` [`c479841`](https://github.com/jsx-eslint/jsx-ast-utils/commit/c479841d0b65188a3223541e885fa6286756a2c6)
- [Deps] update `object.assign` [`9685dce`](https://github.com/jsx-eslint/jsx-ast-utils/commit/9685dce823d71ac06fccd61d8aa8e13ba3d42f38)
<!-- auto-changelog-above -->
3.3.3 / 2022-08-08

@@ -5,0 +26,0 @@ ==================

18

lib/eventHandlers.js

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

});
exports.eventHandlersByType = undefined;
var _arrayPrototype = require('array.prototype.flat');
var _arrayPrototype2 = _interopRequireDefault(_arrayPrototype);
var _object = require('object.values');
var _object2 = _interopRequireDefault(_object);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**

@@ -28,7 +40,3 @@ * Common event handlers for JSX element event binding.

var eventHandlers = Object.keys(eventHandlersByType).reduce(function (accumulator, type) {
return accumulator.concat(eventHandlersByType[type]);
}, []);
exports.default = eventHandlers;
exports.default = (0, _arrayPrototype2.default)((0, _object2.default)(eventHandlersByType));
exports.eventHandlersByType = eventHandlersByType;

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

});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
exports.default = extractValueFromObjectExpression;

@@ -18,2 +15,4 @@

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
/**

@@ -29,13 +28,12 @@ * Extractor function for an ObjectExpression type value node.

return value.properties.reduce(function (obj, property) {
var object = _extends({}, obj);
// Support types: SpreadProperty and ExperimentalSpreadProperty
if (/^(?:Experimental)?Spread(?:Property|Element)$/.test(property.type)) {
if (property.argument.type === 'ObjectExpression') {
return (0, _object2.default)(object, extractValueFromObjectExpression(property.argument));
return (0, _object2.default)({}, obj, extractValueFromObjectExpression(property.argument));
}
} else {
object[getValue(property.key)] = getValue(property.value);
return (0, _object2.default)({}, obj, _defineProperty({}, getValue(property.key), getValue(property.value)));
}
return object;
return obj;
}, {});
}

@@ -25,19 +25,23 @@ 'use strict';

return partitions.sort(sortStarts).reduce(function (raw, part) {
var type = part.type;
return partitions.sort(sortStarts).map(function (_ref) {
var type = _ref.type,
_ref$value = _ref.value;
_ref$value = _ref$value === undefined ? {} : _ref$value;
var raw = _ref$value.raw,
name = _ref.name;
if (type === 'TemplateElement') {
return raw + part.value.raw;
return raw;
}
if (type === 'Identifier') {
return part.name === 'undefined' ? '' + raw + part.name : raw + '{' + part.name + '}';
return name === 'undefined' ? name : '{' + name + '}';
}
if (type.indexOf('Expression') > -1) {
return raw + '{' + type + '}';
return '{' + type + '}';
}
return raw;
}, '');
return '';
}).join('');
}

@@ -8,2 +8,3 @@ 'use strict';

var extractValueFromThisExpression = require('./ThisExpression').default;
var extractValueFromCallExpression = require('./CallExpression').default;

@@ -46,2 +47,6 @@ function navigate(obj, prop, value) {

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

@@ -48,0 +53,0 @@ return extractValueFromThisExpression();

{
"name": "jsx-ast-utils",
"version": "3.3.3",
"version": "3.3.4",
"description": "AST utility module for statically analyzing JSX",
"main": "lib/index.js",
"scripts": {
"prepack": "npmignore --auto --commentLines=autogenerated",
"prepack": "npmignore --auto --commentLines=autogenerated && npm run build",
"prebuild": "rimraf lib",
"build": "babel src --out-dir lib",
"prepublishOnly": "safe-publish-latest && npm test && npm run build",
"prepublishOnly": "safe-publish-latest && npm test",
"prepublish": "not-in-publish || npm run prepublishOnly",

@@ -18,9 +18,12 @@ "prelint": "npm run build",

"tests-only": "jest --coverage",
"test:watch": "npm run tests-only -- --watch"
"test:watch": "npm run tests-only -- --watch",
"version": "auto-changelog && git add CHANGELOG.md",
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
},
"devDependencies": {
"@babel/core": "^7.18.10",
"@babel/eslint-parser": "^7.18.9",
"@babel/parser": "^7.18.11",
"aud": "^2.0.0",
"@babel/core": "^7.22.5",
"@babel/eslint-parser": "^7.22.5",
"@babel/parser": "^7.22.5",
"aud": "^2.0.3",
"auto-changelog": "^2.4.0",
"babel-cli": "^6.26.0",

@@ -34,5 +37,5 @@ "babel-core": "^6.26.3",

"babylon": "^6.18.0",
"eslint": "^8.21.0",
"eslint": "^8.43.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-import": "^2.27.5",
"flow-parser": "^0.126.1",

@@ -43,4 +46,4 @@ "in-publish": "^2.0.1",

"npmignore": "^0.3.0",
"object.entries": "^1.1.5",
"object.fromentries": "^2.0.5",
"object.entries": "^1.1.6",
"object.fromentries": "^2.0.6",
"rimraf": "^2.7.1",

@@ -65,5 +68,16 @@ "safe-publish-latest": "^2.0.0"

"dependencies": {
"array-includes": "^3.1.5",
"object.assign": "^4.1.3"
"array-includes": "^3.1.6",
"array.prototype.flat": "^1.3.1",
"object.assign": "^4.1.4",
"object.values": "^1.1.6"
},
"auto-changelog": {
"output": "CHANGELOG.md",
"template": "keepachangelog",
"unreleased": false,
"commitLimit": false,
"backfillLimit": false,
"hideCredit": true,
"startingVersion": "3.3.4"
},
"publishConfig": {

@@ -70,0 +84,0 @@ "ignore": [

@@ -0,1 +1,4 @@

import flat from 'array.prototype.flat';
import values from 'object.values';
/**

@@ -105,9 +108,4 @@ * Common event handlers for JSX element event binding.

const eventHandlers = Object.keys(eventHandlersByType).reduce(
(accumulator, type) => accumulator.concat(eventHandlersByType[type]),
[],
);
export default flat(values(eventHandlersByType));
export default eventHandlers;
export { eventHandlersByType };

@@ -13,13 +13,12 @@ import assign from 'object.assign';

return value.properties.reduce((obj, property) => {
const object = { ...obj };
// Support types: SpreadProperty and ExperimentalSpreadProperty
if (/^(?:Experimental)?Spread(?:Property|Element)$/.test(property.type)) {
if (property.argument.type === 'ObjectExpression') {
return assign(object, extractValueFromObjectExpression(property.argument));
return assign({}, obj, extractValueFromObjectExpression(property.argument));
}
} else {
object[getValue(property.key)] = getValue(property.value);
return assign({}, obj, { [getValue(property.key)]: getValue(property.value) });
}
return object;
return obj;
}, {});
}

@@ -20,20 +20,17 @@ function sortStarts(a, b) {

return partitions.sort(sortStarts).reduce((raw, part) => {
const {
type,
} = part;
return partitions.sort(sortStarts).map(({ type, value: { raw } = {}, name }) => {
if (type === 'TemplateElement') {
return raw + part.value.raw;
return raw;
}
if (type === 'Identifier') {
return part.name === 'undefined' ? `${raw}${part.name}` : `${raw}{${part.name}}`;
return name === 'undefined' ? name : `{${name}}`;
}
if (type.indexOf('Expression') > -1) {
return `${raw}{${type}}`;
return `{${type}}`;
}
return raw;
}, '');
return '';
}).join('');
}
const extractValueFromThisExpression = require('./ThisExpression').default;
const extractValueFromCallExpression = require('./CallExpression').default;

@@ -38,2 +39,6 @@ function navigate(obj, prop, value) {

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

@@ -40,0 +45,0 @@ return extractValueFromThisExpression();

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