Skip to content

Commit

Permalink
Fix property keys in themes
Browse files Browse the repository at this point in the history
  • Loading branch information
dabbott committed Jan 27, 2024
1 parent ab13e5f commit 17e36d9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
16 changes: 16 additions & 0 deletions packages/noya-compiler/src/__tests__/compile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,22 @@ describe('theme', () => {
imports: [],
};

it('passthrough', () => {
const result = convertTransformer({ theme: 'foo' }, {}, emptyContext);

expect(print(result)).toEqual(`{}`);
});

it('special characters in key', () => {
const result = convertTransformer(
{ theme: 'foo' },
{ '&:foo-bar': 'baz' },
emptyContext,
);

expect(print(result)).toEqual(`{ "&:foo-bar": "baz" }`);
});

it('access key', () => {
const result = convertTransformer(
{ theme: 'foo' },
Expand Down
4 changes: 3 additions & 1 deletion packages/noya-compiler/src/astBuilders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export function createJsxElement(
);
}

function createPropertyKey(key: string): ts.Identifier | ts.StringLiteral {
export function createPropertyKey(
key: string,
): ts.Identifier | ts.StringLiteral {
if (isValidPropertyKey(key)) {
return ts.factory.createIdentifier(key);
} else {
Expand Down
3 changes: 2 additions & 1 deletion packages/noya-compiler/src/compileTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import ts from 'typescript';
import {
createExpressionCode,
createPropertyKey,
generateImportDeclarations,
} from './astBuilders';
import { clean } from './clean';
Expand Down Expand Up @@ -105,7 +106,7 @@ export function convertTransformer(

return [
ts.factory.createPropertyAssignment(
ts.factory.createIdentifier(key),
createPropertyKey(key),
expression,
),
];
Expand Down

0 comments on commit 17e36d9

Please sign in to comment.