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

composeVisitors Rule custom and style not work well #600

Closed
loduis opened this issue Oct 10, 2023 · 0 comments · Fixed by #875
Closed

composeVisitors Rule custom and style not work well #600

loduis opened this issue Oct 10, 2023 · 0 comments · Fixed by #875

Comments

@loduis
Copy link

loduis commented Oct 10, 2023

import { transform, composeVisitors } from 'lightningcss'
import assert from 'node:assert'
const mixins = new Map()

const mixinVisitor = {
  custom: {
    mixin (rule) {
      mixins.set(rule.prelude.value, rule.body.value)
      return []
    },
    apply (rule) {
      return mixins.get(rule.prelude.value)
    }
  }
}

const styleVisitor = {
  style () {

  }
}

const css = Buffer.from(`
  @mixin color {
    color: blue;
  }
  .test { width: 10px; @apply color }
`)

const customAtRules = {
  mixin: {
    prelude: '<custom-ident>',
    body: 'style-block'
  },
  apply: {
    prelude: '<custom-ident>'
  }
}

// Without composeVisitors
const test1 = transform({
  sourceMap: true,
  errorRecovery: true,
  code: css,
  customAtRules,
  visitor: {
    Rule: { ...mixinVisitor, ...styleVisitor }
  }
})

/* This is OK

.test {
  width: 10px;

  & {
    color: #00f;
  }
}
*/

// With composeVisitors
const test2 = transform({
  sourceMap: true,
  errorRecovery: true,
  code: css,
  customAtRules,
  visitor: composeVisitors([
    { Rule: { ...mixinVisitor } },
    { Rule: { ...styleVisitor } }
  ])
})

/* Not work well

@mixin color {
  & {
    color: #00f;
  }
}

.test {
  width: 10px;

  @apply color
}
*/

console.log(test1.code.toString())

console.log('--------------------------')

console.log(test2.code.toString())

assert.strictEqual(test1.code.toString(), test2.code.toString())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant