Skip to content

Commit

Permalink
fix: include string literal object keys as used (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon authored Mar 25, 2020
1 parent 1ab56bf commit 3fd7b70
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const path = require('path');
module.exports = {
testEnvironment: 'node',
transform: defaults.transform,
testRegex: `test/index.test.ts`,
testRegex: `test/index.test.ts$`,
globals: {
'ts-jest': {
packageJson: path.join(__dirname, 'package.json'),
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"react"
],
"scripts": {
"test": "jest test/index.test.ts",
"test": "jest",
"build": "rm -rf dist && tsc",
"release": "run build && standard-version",
"prepack": "run build"
Expand Down
6 changes: 5 additions & 1 deletion src/injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,11 @@ function getUsedProps(
if (node && babelTypes.isObjectPattern(node)) {
node.properties.forEach((x) => {
if (babelTypes.isObjectProperty(x)) {
usedProps.push(x.key.name);
if (babelTypes.isStringLiteral(x.key)) {
usedProps.push(x.key.value);
} else {
usedProps.push(x.key.name);
}
} else if (babelTypes.isIdentifier(x.argument)) {
getUsedPropsInternal(x.argument);
}
Expand Down
4 changes: 4 additions & 0 deletions test/injector/string-props/input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default function Dialog(props: { 'aria-describedby': string }) {
const { 'aria-describedby': ariaDescribedby } = props;
return <div></div>;
}
11 changes: 11 additions & 0 deletions test/injector/string-props/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import PropTypes from 'prop-types';
function Dialog(props) {
const { 'aria-describedby': ariaDescribedby } = props;
return <div></div>;
}

Dialog.propTypes = {
'aria-describedby': PropTypes.string.isRequired,
};

export default Dialog;
12 changes: 12 additions & 0 deletions test/injector/string-props/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "ProgramNode",
"body": [
{
"type": "ComponentNode",
"name": "Dialog",
"types": [
{ "type": "PropTypeNode", "name": "aria-describedby", "propType": { "type": "StringNode" } }
]
}
]
}

0 comments on commit 3fd7b70

Please sign in to comment.