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 cannot read properties of undefined (reading 'modifier') #9656

Merged
merged 5 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
make it behave as-if modifiers didn't exist
  • Loading branch information
RobinMalfait committed Nov 3, 2022
commit 5626fe60a780d5565d3d981e2e3526d1e91f6d46
20 changes: 4 additions & 16 deletions src/lib/setupContextUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,15 +582,9 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
api.addVariant(
isSpecial ? `${variant}${key}` : `${variant}-${key}`,
({ args, container }) => {
// For backwards compatibility reasons for older versions of the vscode intellisense
// plugin and the JetBrains plugin.
if (!args) {
return null
}

return variantFn(
value,
modifiersEnabled ? { modifier: args.modifier, container } : { container }
modifiersEnabled ? { modifier: args?.modifier, container } : { container }
)
},

Expand All @@ -609,19 +603,13 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
api.addVariant(
variant,
({ args, container }) => {
// For backwards compatibility reasons for older versions of the vscode intellisense
// plugin and the JetBrains plugin.
if (!args) {
return null
}

if (args.value === sharedState.NONE && !hasDefault) {
if (args?.value === sharedState.NONE && !hasDefault) {
return null
}

return variantFn(
args.value === sharedState.NONE ? options.values.DEFAULT : args.value,
modifiersEnabled ? { modifier: args.modifier, container } : { container }
args?.value === sharedState.NONE ? options.values.DEFAULT : args?.value,
modifiersEnabled ? { modifier: args?.modifier, container } : { container }
)
},
{
Expand Down
36 changes: 13 additions & 23 deletions tests/match-variants.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -827,30 +827,20 @@ it('should be possible to use `undefined` as a DEFAULT value', () => {
})

it('should not break things', () => {
let config = {
plugins: [
({ matchVariant }) => {
matchVariant(
'foo',
(_value, { modifier: _modifier }) => {
expect(true).toBe(true) // Should not be called
return `.foo &`
},
{
modifiers: {
bar: 'bar',
},
}
)
},
],
}
let config = {}

let context = createContext(resolveConfig(config))
let [[, fn]] = context.variantMap.get('foo')
expect(fn()).toBe(null)
expect(fn({})).toBe(null)
expect(fn({ format() {} })).toBe(null)
let [[, fn]] = context.variantMap.get('group')

let format

expect(
fn({
format(input) {
format = input
},
})
).toBe(undefined)

expect.assertions(3)
expect(format).toBe(':merge(.group) &')
})