Skip to content

fix: Babel plugin no longer errors on array values being passed to animationName#276

Merged
layershifter merged 5 commits into
microsoft:mainfrom
khmakoto:keyframeArrayValues
Nov 24, 2022
Merged

fix: Babel plugin no longer errors on array values being passed to animationName#276
layershifter merged 5 commits into
microsoft:mainfrom
khmakoto:keyframeArrayValues

Conversation

@khmakoto

Copy link
Copy Markdown
Member

PR Description

This PR fixes an issue with the babel plugin that errored when an array of animations was being passed to animationName. This happened because the plugin tried to parse each animation as an individual rule instead of as an object with rules inside of it.

Related issue(s)

@khmakoto khmakoto requested a review from a team as a code owner November 22, 2022 22:42
@khmakoto khmakoto self-assigned this Nov 22, 2022
@github-actions

github-actions Bot commented Nov 22, 2022

Copy link
Copy Markdown
Contributor

📊 Bundle size report

🤖 This report was generated against ebd004e9e8935e099c1873bf2d4841c773bb8417

Comment thread change/@griffel-babel-preset-3f5d5c23-15e4-450a-b8d7-eafa30001b48.json Outdated

@layershifter layershifter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also add some coverage.

packages/babel-preset/src/assets/normalizeStyleRules.test.ts

+  it('handles keyframes', () => {
+    expect(
+      normalizeStyleRules(
+        path.posix,
+        '/home/projects/foo',
+        '/home/projects/foo/src/styles/Component.styles.ts',
+
+        {
+          root: {
+            animationName: [{ from: { height: '20px' }, to: { height: '10px' } }],
+          },
+        },
+      ),
+    ).toEqual({
+      root: {
+        animationName: [{ from: { height: '20px' }, to: { height: '10px' } }],
+      },
+    });
+  });

packages/babel-preset/__fixtures__/keyframes/code.ts

import { makeStyles } from '@griffel/react';

export const useStyles = makeStyles({
  single: {
    animationName: {
      from: { transform: 'rotate(0deg)' },
      to: { transform: 'rotate(360deg)' },
    },
  },
  multiple: {
    animationName: [
      {
        from: { transform: 'rotate(0deg)' },
        to: { transform: 'rotate(360deg)' },
      },
      {
        from: { height: '100px' },
        to: { height: '200px' },
      },
    ],
  },
});

packages/babel-preset/__fixtures__/keyframes/output.ts

import { __styles } from '@griffel/react';
export const useStyles = __styles(
  {
    single: {
      Bv12yb3: ['f1g6ul6r', 'f1fp4ujf'],
    },
    multiple: {
      Bv12yb3: ['f1e467oh', 'f1w9bd63'],
    },
  },
  {
    k: [
      '@-webkit-keyframes f1q8eu9e{from{-webkit-transform:rotate(0deg);-moz-transform:rotate(0deg);-ms-transform:rotate(0deg);transform:rotate(0deg);}to{-webkit-transform:rotate(360deg);-moz-transform:rotate(360deg);-ms-transform:rotate(360deg);transform:rotate(360deg);}}',
      '@-webkit-keyframes f55c0se{from{-webkit-transform:rotate(0deg);-moz-transform:rotate(0deg);-ms-transform:rotate(0deg);transform:rotate(0deg);}to{-webkit-transform:rotate(-360deg);-moz-transform:rotate(-360deg);-ms-transform:rotate(-360deg);transform:rotate(-360deg);}}',
      '@keyframes f1q8eu9e{from{-webkit-transform:rotate(0deg);-moz-transform:rotate(0deg);-ms-transform:rotate(0deg);transform:rotate(0deg);}to{-webkit-transform:rotate(360deg);-moz-transform:rotate(360deg);-ms-transform:rotate(360deg);transform:rotate(360deg);}}',
      '@keyframes f55c0se{from{-webkit-transform:rotate(0deg);-moz-transform:rotate(0deg);-ms-transform:rotate(0deg);transform:rotate(0deg);}to{-webkit-transform:rotate(-360deg);-moz-transform:rotate(-360deg);-ms-transform:rotate(-360deg);transform:rotate(-360deg);}}',
      '@-webkit-keyframes f19fnzg9{from{height:100px;}to{height:200px;}}',
      '@keyframes f19fnzg9{from{height:100px;}to{height:200px;}}',
    ],
    d: [
      '.f1g6ul6r{-webkit-animation-name:f1q8eu9e;animation-name:f1q8eu9e;}',
      '.f1fp4ujf{-webkit-animation-name:f55c0se;animation-name:f55c0se;}',
      '.f1e467oh{-webkit-animation-name:f1q8eu9e,f19fnzg9;animation-name:f1q8eu9e,f19fnzg9;}',
      '.f1w9bd63{-webkit-animation-name:f55c0se,f19fnzg9;animation-name:f55c0se,f19fnzg9;}',
    ],
  },
);

packages/babel-preset/src/transformPlugin.test.ts

    {
      title: 'call of non existing module',
      fixture: path.resolve(fixturesDir, 'non-existing-module-call', 'code.ts'),
      outputFixture: path.resolve(fixturesDir, 'non-existing-module-call', 'output.ts'),
    },
+    {
+      title: 'syntax: animationName',
+      fixture: path.resolve(fixturesDir, 'keyframes', 'code.ts'),
+      outputFixture: path.resolve(fixturesDir, 'keyframes', 'output.ts'),
+    },

Humberto Makoto Morimoto Burgos added 3 commits November 23, 2022 15:12
@layershifter layershifter merged commit fc3403a into microsoft:main Nov 24, 2022
@khmakoto khmakoto deleted the keyframeArrayValues branch November 28, 2022 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

animationName with array value not supported by babel-plugin

2 participants