Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust based transform #116

Open
wants to merge 93 commits into
base: main
Choose a base branch
from
Open

rust based transform #116

wants to merge 93 commits into from

Conversation

jantimon
Copy link
Owner

@jantimon jantimon commented Jul 10, 2024

an exited yak sitting on a flying rocket. the brand SWC is written on the rocket in yellow letters

fixes #110

Summary by CodeRabbit

  • New Features

    • Introduced a specialized CSS parser for CSS-in-JS scenarios with state management.
    • Added dynamic theming support for components using CSS-in-JS styling.
  • Documentation

    • Added comprehensive README.md and CHANGELOG.md for the CSS-in-JS Parser project.
  • Bug Fixes

    • Improved the accuracy of dynamic style properties in styled components.
  • Enhancements

    • Optimized the performance and reduced the binary size of the yak-swc package.
    • Enhanced CSS parsing and regeneration capabilities.
  • Tests

    • Added extensive unit tests for new parsing and transformation functionalities.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Comment on lines +93 to +94
.replace(/\n [^\|x][\s\S]+/, "")
.replace(/ [\|x] /g, "")
Copy link

Choose a reason for hiding this comment

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

Refactor regular expressions for clarity.

The use of consecutive spaces in regex is hard to read and maintain. Consider using quantifiers to improve clarity.

- .replace(/\n  [^\|x][\s\S]+/, "")
- .replace(/  [\|x] /g, "")
+ .replace(/\n {2}[^\|x][\s\S]+/, "")
+ .replace(/ {2}[\|x] /g, "")
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
.replace(/\n [^\|x][\s\S]+/, "")
.replace(/ [\|x] /g, "")
.replace(/\n {2}[^\|x][\s\S]+/, "")
.replace(/ {2}[\|x] /g, "")
Tools
Biome

[error] 93-93: This regular expression contains unclear uses of consecutive spaces.

It's hard to visually count the amount of spaces.
Safe fix: Use a quantifier instead.

(lint/complexity/noMultipleSpacesInRegularExpressionLiterals)


[error] 94-94: This regular expression contains unclear uses of consecutive spaces.

It's hard to visually count the amount of spaces.
Safe fix: Use a quantifier instead.

(lint/complexity/noMultipleSpacesInRegularExpressionLiterals)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (1)
packages/yak-swc/yak_swc/tests/fixture/cross-file-member/input.tsx (1)

1-11: Confirm TypeScript Errors for colors and fonts Imports

The search results did not reveal any type definitions for the colors and fonts modules. The use of @ts-ignore in the provided snippet indicates that there are TypeScript errors related to these imports. To ensure type safety and avoid potential runtime errors, it is recommended to provide specific types for these modules or fix the underlying issues causing the TypeScript errors.

  • Imports and @ts-ignore: The use of @ts-ignore on lines 2 and 4 could potentially hide type errors that would be better addressed explicitly. Consider providing specific types or fixing the underlying issues causing the TypeScript errors.
  • Styled Component Definition: Ensure that the values from colors and fonts are correctly typed to avoid runtime errors.
Analysis chain

Review of New Styled Button Component

  • Imports and @ts-ignore: The use of @ts-ignore on lines 2 and 4 could potentially hide type errors that would be better addressed explicitly. Consider providing specific types or fixing the underlying issues causing the TypeScript errors.
  • Styled Component Definition: The component definition using styled-components syntax is clear and uses dynamic styling based on imported values. Ensure that the values from colors and fonts are correctly typed to avoid runtime errors.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify types for imported modules `colors` and `fonts`.

# Check if type definitions exist for colors and fonts
rg --type typescript -A 5 $'declare module.*colors' packages/yak-swc/yak_swc/types
rg --type typescript -A 5 $'declare module.*fonts' packages/yak-swc/yak_swc/types

Length of output: 236


Script:

#!/bin/bash
# Description: Verify types for imported modules `colors` and `fonts`.

# Find all TypeScript files and search for type definitions for colors and fonts
fd --extension ts | xargs rg -A 5 'declare module.*colors'
fd --extension ts | xargs rg -A 5 'declare module.*fonts'

Length of output: 120


Script:

#!/bin/bash
# Description: Verify usage of imported modules `colors` and `fonts` in the codebase.

# Search for usage of colors and fonts in the codebase
rg 'colors' -A 5
rg 'fonts' -A 5

Length of output: 20819

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Outside diff range, codebase verification and nitpick comments (2)
packages/yak-swc/yak_swc/tests/fixture/cross-file/input.tsx (1)

1-3: Check TypeScript configuration for @ts-ignore.

The use of @ts-ignore is generally discouraged as it bypasses TypeScript's static type checking. If the import from ./Icon is causing type errors, it would be better to address these directly, possibly by ensuring that the type definitions are correctly set up.

packages/yak-swc/yak_swc/tests/fixture/cross-file-mixin/input.tsx (1)

1-5: Check TypeScript configuration for @ts-ignore.

Similar to the previous file, the use of @ts-ignore is noted. It's important to address any type issues directly rather than bypassing them. This ensures better type safety and code quality.

Comment on lines +343 to +347
} else if (
property.value.type === "TemplateLiteral" &&
property.value.quasis.length === 1
) {
result[key] = property.value.quasis[0].value.raw;
Copy link

Choose a reason for hiding this comment

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

Enhanced Template Literal Support in Object Expressions: Approved.

The support for template literals in object expressions has been enhanced, allowing for more dynamic handling of values. This is a beneficial change for flexibility.

-        property.value.type === "TemplateLiteral" &&
-        property.value.quasis.length === 1
+        property.value.type === "TemplateLiteral" && property.value.quasis.length === 1
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
} else if (
property.value.type === "TemplateLiteral" &&
property.value.quasis.length === 1
) {
result[key] = property.value.quasis[0].value.raw;
} else if (
property.value.type === "TemplateLiteral" && property.value.quasis.length === 1
) {
result[key] = property.value.quasis[0].value.raw;

Comment on lines +286 to +293
} else if (
declaration.init.type === "TemplateLiteral" &&
declaration.init.quasis.length === 1
) {
result[declaration.id.name] = {
type: "constant",
value: declaration.init.quasis[0].value.raw,
};
Copy link

Choose a reason for hiding this comment

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

Handling of Template Literals: Simplified and Effective.

The handling of template literals has been simplified to directly initialize constants when the template has only one quasi. This is a clean and efficient approach.

-                      declaration.init.type === "TemplateLiteral" &&
-                      declaration.init.quasis.length === 1
+                      declaration.init.type === "TemplateLiteral" && declaration.init.quasis.length === 1
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
} else if (
declaration.init.type === "TemplateLiteral" &&
declaration.init.quasis.length === 1
) {
result[declaration.id.name] = {
type: "constant",
value: declaration.init.quasis[0].value.raw,
};
} else if (
declaration.init.type === "TemplateLiteral" && declaration.init.quasis.length === 1
) {
result[declaration.id.name] = {
type: "constant",
value: declaration.init.quasis[0].value.raw,
};

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.

Transitioning from Babel to SWC Rust WASM
4 participants