Skip to content

Commit 3fd7b70

Browse files
authored
fix: include string literal object keys as used (#5)
1 parent 1ab56bf commit 3fd7b70

File tree

6 files changed

+34
-3
lines changed

6 files changed

+34
-3
lines changed

Diff for: jest.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const path = require('path');
44
module.exports = {
55
testEnvironment: 'node',
66
transform: defaults.transform,
7-
testRegex: `test/index.test.ts`,
7+
testRegex: `test/index.test.ts$`,
88
globals: {
99
'ts-jest': {
1010
packageJson: path.join(__dirname, 'package.json'),

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"react"
1616
],
1717
"scripts": {
18-
"test": "jest test/index.test.ts",
18+
"test": "jest",
1919
"build": "rm -rf dist && tsc",
2020
"release": "run build && standard-version",
2121
"prepack": "run build"

Diff for: src/injector.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,11 @@ function getUsedProps(
312312
if (node && babelTypes.isObjectPattern(node)) {
313313
node.properties.forEach((x) => {
314314
if (babelTypes.isObjectProperty(x)) {
315-
usedProps.push(x.key.name);
315+
if (babelTypes.isStringLiteral(x.key)) {
316+
usedProps.push(x.key.value);
317+
} else {
318+
usedProps.push(x.key.name);
319+
}
316320
} else if (babelTypes.isIdentifier(x.argument)) {
317321
getUsedPropsInternal(x.argument);
318322
}

Diff for: test/injector/string-props/input.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default function Dialog(props: { 'aria-describedby': string }) {
2+
const { 'aria-describedby': ariaDescribedby } = props;
3+
return <div></div>;
4+
}

Diff for: test/injector/string-props/output.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import PropTypes from 'prop-types';
2+
function Dialog(props) {
3+
const { 'aria-describedby': ariaDescribedby } = props;
4+
return <div></div>;
5+
}
6+
7+
Dialog.propTypes = {
8+
'aria-describedby': PropTypes.string.isRequired,
9+
};
10+
11+
export default Dialog;

Diff for: test/injector/string-props/output.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"type": "ProgramNode",
3+
"body": [
4+
{
5+
"type": "ComponentNode",
6+
"name": "Dialog",
7+
"types": [
8+
{ "type": "PropTypeNode", "name": "aria-describedby", "propType": { "type": "StringNode" } }
9+
]
10+
}
11+
]
12+
}

0 commit comments

Comments
 (0)