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

fix(emotion): Port label tests and fix label generation #245

Merged
merged 28 commits into from
Jan 18, 2024

Conversation

Codex-
Copy link
Contributor

@Codex- Codex- commented Jan 12, 2024

Apologies for the large PR. This PR addresses a number of issues with label generation when attempting to find a label for [Local].

All behaviour and code generation has been tested between the original babel implementation and this plugin for consistency.

Added

Changed

  • Moved label related tests under a label folder in fixtures.
    • New structure: fixture/labels/*

Fixed

  • Spaces in names now collapsed to singular hyphens.
  • Labels that are unable to find a context emit an empty string instead of [Local]
  • The following fixes have been made to align with the current @emotion/babel-plugin behaviour:
    • Functions on classes now emit their class name as the label.
    • Calls outside of an assignment (i.e. global scoped called to css() do not emit a label.
    • Keys on objects are now used as labels instead of the parent variable assignment. (Fixes @swc/plugin-emotion seemingly not producing correct labels #180)
    • Functions that return calls to css now use the function name as the label. (Fixes @swc/plugin-emotion seemingly not producing correct labels #180)
    • Named function expressions on variable assignments now use the correct label.
    • String keys on objects now generate the expected label.
    • Class methods use the class name for the label. (Upstream behaviour, weirdly).
    • Class members use the member name for the label.
    • Computed properties should not generate a label.

@Codex- Codex- marked this pull request as ready for review January 12, 2024 22:12
Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

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

Thank you so much!

@kdy1 kdy1 enabled auto-merge (squash) January 18, 2024 09:59
@kdy1 kdy1 disabled auto-merge January 18, 2024 09:59
@kdy1 kdy1 enabled auto-merge (squash) January 18, 2024 09:59
@kdy1 kdy1 merged commit ab782e6 into swc-project:main Jan 18, 2024
6 checks passed
@Codex- Codex- deleted the fix_emotion_label_bugs branch January 18, 2024 11:11
kdy1 pushed a commit that referenced this pull request Jan 22, 2024
Follow up to #245 

Fixes this panic by ensuring that there is something to unwrap:
```
thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', /home/runner/work/plugins/plugins/packages/emotion/transform/src/lib.rs:449:48
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread '<unnamed>' panicked at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/swc-0.270.26/src/plugin.rs:162:14:
failed to invoke plugin: failed to invoke plugin on 'Some("/Users/alexmiller/dev/app/node_modules/jest-runner/build/index.js")'

Caused by:
    0: failed to invoke `@swc/plugin-emotion` as js transform plugin at @swc/plugin-emotion
    1: RuntimeError: unreachable

Stack backtrace:
   0: _napi_register_module_v1
   1: _wasmer_vm_imported_memory32_atomic_notify
   2: _napi_register_module_v1
   3: _napi_register_module_v1
   4: _napi_register_module_v1
   5: _napi_register_module_v1
   6: _napi_register_module_v1
```
@kdy1 kdy1 self-assigned this Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

@swc/plugin-emotion seemingly not producing correct labels
2 participants