Skip to content

Commit

Permalink
feat: use static object properties as identifiers (#749)
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Mar 17, 2023
1 parent 35f2e36 commit 626c54c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/utils/getDisplayName.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { NodePath } from '@babel/core';
import { AssignmentExpression, VariableDeclarator } from '@babel/types';
import {
AssignmentExpression,
ObjectProperty,
VariableDeclarator,
} from '@babel/types';

import { getNameFromFile } from './createFilename';
import getNameFromPath from './getNameFromPath';
Expand All @@ -21,6 +25,8 @@ export default function getDisplayName(
);
if (path.isExportDefaultDeclaration())
return getNameFromFile(file.opts.filename);
if (path.isObjectProperty())
return getNameFromPath((path as NodePath<ObjectProperty>).get('key'));
}
return defaultName || null;
}
25 changes: 25 additions & 0 deletions test/css-tag.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,31 @@ describe('css tag', () => {
},
);

testAllRunners(
'should use object properties as identifiers',
async (runner) => {
const [, styles] = await runner(
`
import { css } from 'astroturf';
const styles = {
blue: css\`
color: blue
\`,
red: css\`
color: red;
\`,
}
`,
{ cssTagName: 'css' },
);

expect(styles[0].identifier).toEqual('blue');
expect(styles[1].identifier).toEqual('red');
},
);

testAllRunners('respects the allowGlobal setting', async (runner) => {
const [, styles] = await runner(
`
Expand Down

0 comments on commit 626c54c

Please sign in to comment.