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

breaks CSS in JS ${Cls}:not() -> ${Cls}:not () #6259

Closed
brandonkal opened this issue Jun 30, 2019 · 5 comments
Closed

breaks CSS in JS ${Cls}:not() -> ${Cls}:not () #6259

brandonkal opened this issue Jun 30, 2019 · 5 comments
Labels
lang:css/scss/less Issues affecting CSS, Less or SCSS locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. scope:dependency Issues that cannot be solved inside Prettier itself, and must be fixed in a dependency type:bug Issues identifying ugly output, or a defect in the program

Comments

@brandonkal
Copy link

brandonkal commented Jun 30, 2019

Prettier 1.18.2
Playground link

--parser typescript

I am using Typescript but this does not matter here.

Input:

export const Group = styled.div`
  margin: 0;

  .input {
    margin: 0;
  }

  ${StyledInput}:not(:first-child) {
    margin: 0;
  }

  & > :not(.${inputWrap}):not(${Button}) {
    display: flex;
  }
`

Output:

export const Group = styled.div`
  margin: 0;

  .input {
    margin: 0;
  }

  ${StyledInput}:not (:first-child) {
    margin: 0;
  }

  & > :not(.${inputWrap}):not(${Button}) {
    display: flex;
  }
`;

Expected behavior:
No space should be inserted after not as this breaks the CSS.

Updated with minimal reproduction. It appears that having a child selector is required. Oddly, the space is not always inserted as you can see in the last declaration.

@dcecile
Copy link

dcecile commented Jul 15, 2019

Same thing here, but mine is a space inserted before an attribute selector. The added space changes the behaviour of the selector, breaking the CSS.

Input:

const yesFrame = (
    ...args: Interpolation<ThemedStyledProps<{}, Theme>>[]
) => css`
    ${ChatRoot}[data-frame="yes"] & {
        ${css({}, ...args)}
    }
`

Output:

const yesFrame = (
    ...args: Interpolation<ThemedStyledProps<{}, Theme>>[]
) => css`
    ${ChatRoot} [data-frame="yes"] & {
        ${css({}, ...args)}
    }
`

@alexander-akait alexander-akait added lang:css/scss/less Issues affecting CSS, Less or SCSS scope:dependency Issues that cannot be solved inside Prettier itself, and must be fixed in a dependency type:bug Issues identifying ugly output, or a defect in the program labels Jul 15, 2019
@alexander-akait
Copy link
Member

Problem in postcss-selector-parser

@modernserf
Copy link

I am having a similar issue which I imagine has the same root cause:

Playground link

Input:

styled.css`
  font-size: var(--fontSizes-${size});
`;

Output

styled.css`
  font-size: var(--fontSizes- ${size});
`;

fisker added a commit to fisker/prettier that referenced this issue Nov 4, 2019
@fisker
Copy link
Sponsor Member

fisker commented Nov 4, 2019

minimum reproduction

Prettier 1.18.2
Playground link

--parser typescript
--single-quote
--tab-width 5
--use-tabs

Input:

styled.div`
  ${expr}:not(:first-child) {
    // should not add space after :not
  }
  ${expr}[checked] {
    // should not add space before [
  }
  margin: 0;.input {}
`

Output:

styled.div`
	${expr}:not (:first-child) {
		// should not add space after :not
	}
	${expr} [checked] {
		// should not add space before [
	}
	margin: 0;
	.input {
	}
`;

@thorn0
Copy link
Member

thorn0 commented Apr 23, 2020

fixed by #7883
#6259 (comment) is a manifestation of #5465

@thorn0 thorn0 closed this as completed Apr 23, 2020
thorn0 added a commit to thorn0/prettier that referenced this issue Apr 23, 2020
@github-actions github-actions bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jul 23, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lang:css/scss/less Issues affecting CSS, Less or SCSS locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. scope:dependency Issues that cannot be solved inside Prettier itself, and must be fixed in a dependency type:bug Issues identifying ugly output, or a defect in the program
Projects
None yet
Development

No branches or pull requests

6 participants