Skip to content

Commit c2479ee

Browse files
committed
turn comma separated values into arrays
1 parent 57323a1 commit c2479ee

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

packages/tailwindcss/src/index.ts

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -85,31 +85,35 @@ async function parseCss(
8585
// These are the same primitive values supported by JSON
8686
let value: CssPluginOptions[keyof CssPluginOptions] = decl.value
8787

88-
if (value === 'null') {
89-
value = null
90-
} else if (value === 'true') {
91-
value = true
92-
} else if (value === 'false') {
93-
value = false
94-
} else if (!Number.isNaN(Number(value))) {
95-
value = Number(value)
96-
} else if (
97-
(value[0] === '"' && value[value.length - 1] === '"') ||
98-
(value[0] === "'" && value[value.length - 1] === "'")
99-
) {
100-
value = value.slice(1, -1)
101-
} else if (
102-
(value[0] === '[' && value[value.length - 1] === ']') ||
103-
(value[0] === '{' && value[value.length - 1] === '}')
104-
) {
105-
throw new Error(
106-
`Unexpected \`@plugin\` option: Value of declaration \`${toCss([decl]).trim()}\` is not supported.\n\nIt looks like you want to pass an ${
107-
value[0] === '[' ? 'array' : 'object'
108-
} to plugin options. This is not supported in CSS.`,
109-
)
110-
}
88+
let parts = segment(value, ',').map((part) => {
89+
if (part === 'null') {
90+
return null
91+
} else if (part === 'true') {
92+
return true
93+
} else if (part === 'false') {
94+
return false
95+
} else if (!Number.isNaN(Number(part))) {
96+
return Number(part)
97+
} else if (
98+
(part[0] === '"' && part[part.length - 1] === '"') ||
99+
(part[0] === "'" && part[part.length - 1] === "'")
100+
) {
101+
return part.slice(1, -1)
102+
} else if (
103+
(part[0] === '[' && part[part.length - 1] === ']') ||
104+
(part[0] === '{' && part[part.length - 1] === '}')
105+
) {
106+
throw new Error(
107+
`Unexpected \`@plugin\` option: Value of declaration \`${toCss([decl]).trim()}\` is not supported.\n\nIt looks like you want to pass an ${
108+
part[0] === '[' ? 'array' : 'object'
109+
} to plugin options. This is not supported in CSS.`,
110+
)
111+
}
112+
113+
return value
114+
})
111115

112-
options[decl.property] = value
116+
options[decl.property] = parts.length === 1 ? parts[0] : parts
113117
}
114118

115119
pluginPaths.push([pluginPath, Object.keys(options).length > 0 ? options : null])

packages/tailwindcss/src/plugin-api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ function objectToAst(rules: CssInJs | CssInJs[]): AstNode[] {
346346
return ast
347347
}
348348

349-
export type CssPluginOptions = Record<string, string | number | boolean | null>
349+
type Primitive = string | number | boolean | null
350+
export type CssPluginOptions = Record<string, Primitive | Primitive[]>
350351

351352
interface PluginDetail {
352353
path: string

0 commit comments

Comments
 (0)