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

CSS not generated in var a = function a() { ... } #83

Open
yume-chan opened this issue May 6, 2024 · 0 comments
Open

CSS not generated in var a = function a() { ... } #83

yume-chan opened this issue May 6, 2024 · 0 comments
Labels
bug report 🦗 Issue is probably a bug, but it needs to be checked bundler: webpack 📦 Issue is related to webpack bundler needs: complete repro 🖥️ Issue need to have complete repro provided

Comments

@yume-chan
Copy link

Environment

  • wyw-in-js version: 0.5.3
  • custom processor: @linaria/atomic
  • Bundler (+ version): vite 5.2.11
  • Node.js version: v20.12.1
  • OS: Windows 11

Description

This is a repost of callstack/linaria#1312

For this code:

import {css} from '@linaria/atomic'

export const a = function a() {
    return css`
        background-color: red;
    `
}

css template string in a() will be replaced with names, but the CSS rules won't be generated.

if (parent) {
if (parent.isVariableDeclarator()) {
const id = parent.get('id');
// FIXME: replace with id.isReferencedIdentifier()
if (id.isIdentifier()) {
const { referencePaths } = path.scope.getBinding(id.node.name) || {
referencePaths: [],
};
isReferenced = referencePaths.length !== 0;
}
}
}

parent is the const a node, but path.scope.getBinding(id.node.name) returns the function a() node. function a() node has no references so CSS extraction was skipped.

This code is simplified from an output of Solid.js babel plugin, so it can't change.

Reproducible Demo

https://github.com/yume-chan/wyw-css-issue

style.js exports two functions a and b, both of them generates CSS styles using wyw-in-js. main.js applies both classes to <h1>, but only b is effective.

@yume-chan yume-chan added bug report 🦗 Issue is probably a bug, but it needs to be checked needs: complete repro 🖥️ Issue need to have complete repro provided needs: triage 🏷 Issue needs to be checked and prioritized labels May 6, 2024
@github-actions github-actions bot added bundler: webpack 📦 Issue is related to webpack bundler and removed needs: triage 🏷 Issue needs to be checked and prioritized labels May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report 🦗 Issue is probably a bug, but it needs to be checked bundler: webpack 📦 Issue is related to webpack bundler needs: complete repro 🖥️ Issue need to have complete repro provided
Projects
None yet
Development

No branches or pull requests

1 participant