Update checked-in dependencies

This commit is contained in:
github-actions[bot] 2025-02-03 17:20:53 +00:00
parent 3e913ef09d
commit 9660df3fcc
990 changed files with 74805 additions and 60149 deletions

View file

@ -1,5 +1,37 @@
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.5](https://github.com/jsx-eslint/jsx-ast-utils/compare/v3.3.4...v3.3.5) - 2023-07-28
### Fixed
- [Fix] `extractProp`: support `JSXFragment` [`#132`](https://github.com/jsx-eslint/jsx-ast-utils/issues/132)
### Commits
- [Dev Deps] update `@babel/core`, `@babel/eslint-parser`, `@babel/parser`, `eslint` [`e5555d1`](https://github.com/jsx-eslint/jsx-ast-utils/commit/e5555d152dbe1e85324139756f637e65fe047976)
- [Tests] fix a test [`bde3ba9`](https://github.com/jsx-eslint/jsx-ast-utils/commit/bde3ba9c9dc294d5472eefa0b3f31ab0e1aed739)
## [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
==================

View file

@ -18,6 +18,7 @@ const defaultPlugins = [
// 'nullishCoalescing', // TODO: update to babel 7
];
let plugins = [...defaultPlugins];
let isESM = false;
export function setParserName(name) {
parserName = name;
@ -33,8 +34,13 @@ export function changePlugins(pluginOrFn) {
}
}
export function setIsESM() {
isESM = true;
}
beforeEach(() => {
plugins = [...defaultPlugins];
isESM = false;
});
function parse(code) {
@ -43,7 +49,7 @@ function parse(code) {
}
if (parserName === 'babel') {
try {
return babelParser.parse(code, { plugins, sourceFilename: 'test.js' });
return babelParser.parse(code, { plugins, sourceFilename: 'test.js', ...(isESM && { sourceType: 'module' }) });
} catch (_) {
// eslint-disable-next-line no-console
console.warn(`Failed to parse with ${fallbackToBabylon ? 'babylon' : 'Babel'} parser.`);

View file

@ -92,5 +92,27 @@ describe('elementType tests', () => {
assert.equal(actual, expected);
});
it('works with nested fragments', () => {
const code = `
<Hello
role="checkbox"
frag={
<>
<div>Hello</div>
<>
<div>There</div>
</>
</>
}
/>
`;
const node = getOpeningElement(code);
const expected = 'Hello';
const actual = elementType(node);
assert.equal(actual, expected);
});
});
});

View file

@ -6,6 +6,7 @@ import {
describeIfNotBabylon,
changePlugins,
setParserName,
setIsESM,
} from '../helper';
import { getLiteralPropValue } from '../../src/getPropValue';
@ -497,6 +498,21 @@ describe('getLiteralPropValue', () => {
});
});
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', () => {
beforeEach(() => {
changePlugins((pls) => [...pls, 'typescript']);
@ -531,7 +547,7 @@ describe('getLiteralPropValue', () => {
});
it('should work with a this.props value', () => {
const prop = extractProp('<a href={this.props.href!}>Download</a>');
const prop = extractProp('<a href={this.props.href!}>Download</a>', 'href');
const expected = null;
const actual = getLiteralPropValue(prop);
assert.equal(actual, expected);

View file

@ -150,6 +150,28 @@ describe('getPropValue', () => {
assert.equal(actual, expected);
});
it('supports a prop value containing nested fragments', () => {
const propCode = `
<>
<div>Hello</div>
<>
<div>There</div>
</>
</>
`;
const code = `
<Hello
role="checkbox"
frag={${propCode}}
/>
`;
const prop = extractProp(code, 'frag');
const actual = getPropValue(prop);
assert.deepEqual(actual, propCode.trim());
});
});
describe('Identifier', () => {
@ -1148,6 +1170,13 @@ describe('getPropValue', () => {
assert.equal(actual, expected);
});
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!`', () => {
const prop = extractProp('<div foo={bar!.bar!} />');
const actual = getPropValue(prop);

View file

@ -3,6 +3,18 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
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 }; }
/**
* Common event handlers for JSX element event binding.
*/
@ -24,9 +36,5 @@ var eventHandlersByType = {
transition: ['onTransitionEnd']
};
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;

View file

@ -3,9 +3,6 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
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;
var _object = require('object.assign');
@ -14,6 +11,8 @@ var _object2 = _interopRequireDefault(_object);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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; }
/**
* Extractor function for an ObjectExpression type value node.
* An object expression is using {}.
@ -24,15 +23,14 @@ function extractValueFromObjectExpression(value) {
// eslint-disable-next-line global-require
var getValue = require('.').default;
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;
}, {});
}

View file

@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
});
exports.default = extractValueFromTSNonNullExpression;
var extractValueFromThisExpression = require('./ThisExpression').default;
var extractValueFromCallExpression = require('./CallExpression').default;
function navigate(obj, prop, value) {
if (value.computed) {
@ -42,6 +43,10 @@ function extractValueFromTSNonNullExpression(value) {
return extractValueFromTSNonNullExpression(value.expression);
}
if (value.type === 'CallExpression') {
return extractValueFromCallExpression(value);
}
if (value.type === 'ThisExpression') {
return extractValueFromThisExpression();
}

View file

@ -22,21 +22,25 @@ function extractValueFromTemplateLiteral(value) {
var partitions = quasis.concat(expressions);
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('');
}

View file

@ -21,6 +21,10 @@ var _JSXText = require('./JSXText');
var _JSXText2 = _interopRequireDefault(_JSXText);
var _JSXFragment = require('./JSXFragment');
var _JSXFragment2 = _interopRequireDefault(_JSXFragment);
var _expressions = require('./expressions');
var _expressions2 = _interopRequireDefault(_expressions);
@ -32,7 +36,8 @@ var TYPES = {
Literal: _Literal2.default,
JSXElement: _JSXElement2.default,
JSXExpressionContainer: _expressions2.default,
JSXText: _JSXText2.default
JSXText: _JSXText2.default,
JSXFragment: _JSXFragment2.default
};
// Composition map of types to their extractor functions to handle literals.
@ -53,6 +58,7 @@ var LITERAL_TYPES = _extends({}, TYPES, {
* @param value - AST Value object on a JSX Attribute.
*/
function getValue(value) {
if (!TYPES[value.type]) console.log(value.type);
return TYPES[value.type](value);
}

View file

@ -1,13 +1,13 @@
{
"name": "jsx-ast-utils",
"version": "3.3.3",
"version": "3.3.5",
"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",
"prelint": "npm run build",
"lint": "eslint .",
@ -15,13 +15,16 @@
"test": "npm run tests-only --",
"posttest": "aud --production",
"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.9",
"@babel/eslint-parser": "^7.22.9",
"@babel/parser": "^7.22.7",
"aud": "^2.0.3",
"auto-changelog": "^2.4.0",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-jest": "^20.0.3",
@ -30,16 +33,16 @@
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babylon": "^6.18.0",
"eslint": "^8.21.0",
"eslint": "^8.45.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",
"in-publish": "^2.0.1",
"jest": "^20.0.4",
"jest-cli": "^20.0.4",
"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",
"safe-publish-latest": "^2.0.0"
},
@ -59,8 +62,19 @@
},
"license": "MIT",
"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": {
"ignore": [

View file

@ -1,3 +1,6 @@
import flat from 'array.prototype.flat';
import values from 'object.values';
/**
* Common event handlers for JSX element event binding.
*/
@ -102,11 +105,6 @@ const eventHandlersByType = {
],
};
const eventHandlers = Object.keys(eventHandlersByType).reduce(
(accumulator, type) => accumulator.concat(eventHandlersByType[type]),
[],
);
export default eventHandlers;
export default flat(values(eventHandlersByType));
export { eventHandlersByType };

View file

@ -10,15 +10,14 @@ export default function extractValueFromObjectExpression(value) {
// eslint-disable-next-line global-require
const getValue = require('.').default;
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;
}, {});
}

View file

@ -1,4 +1,5 @@
const extractValueFromThisExpression = require('./ThisExpression').default;
const extractValueFromCallExpression = require('./CallExpression').default;
function navigate(obj, prop, value) {
if (value.computed) {
@ -35,6 +36,10 @@ export default function extractValueFromTSNonNullExpression(value) {
return extractValueFromTSNonNullExpression(value.expression);
}
if (value.type === 'CallExpression') {
return extractValueFromCallExpression(value);
}
if (value.type === 'ThisExpression') {
return extractValueFromThisExpression();
}

View file

@ -17,22 +17,19 @@ export default function extractValueFromTemplateLiteral(value) {
} = value;
const partitions = quasis.concat(expressions);
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('');
}

View file

@ -1,6 +1,7 @@
import Literal from './Literal';
import JSXElement from './JSXElement';
import JSXText from './JSXText';
import JSXFragment from './JSXFragment';
import JSXExpressionContainer, { extractLiteral } from './expressions';
// Composition map of types to their extractor functions.
@ -9,6 +10,7 @@ const TYPES = {
JSXElement,
JSXExpressionContainer,
JSXText,
JSXFragment,
};
// Composition map of types to their extractor functions to handle literals.
@ -28,6 +30,7 @@ const LITERAL_TYPES = {
* @param value - AST Value object on a JSX Attribute.
*/
export default function getValue(value) {
if (!TYPES[value.type]) console.log(value.type);
return TYPES[value.type](value);
}