Skip to content

Commit a48c56d

Browse files
committed
Raise error on invalid @value definitions
1 parent 64c7795 commit a48c56d

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ const replaceValueSymbols = (valueString, replacements) => {
3838
};
3939

4040
const getDefinition = (atRule, existingDefinitions, requiredDefinitions) => {
41-
const [/* match */, name, middle, value, end] = matchValueDefinition.exec(atRule.params);
41+
const matches = matchValueDefinition.exec(atRule.params);
42+
if (!matches) {
43+
throw atRule.error('Invalid @value definition');
44+
}
45+
46+
const [/* match */, name, middle, value, end] = matches;
4247
const valueWithReplacements = replaceValueSymbols(value, existingDefinitions);
4348

4449
if (!requiredDefinitions) {

index.test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,18 @@ test('gives an error when path to imported file is wrong', async (t) => {
6767
await t.expect(processor.process(input, parserOpts)).rejects.toThrow("Can't resolve './non-existent-file.css'");
6868
});
6969

70-
test('gives an error when @value statement is invalid', async (t) => {
70+
test('gives an error when @value import statement is invalid', async (t) => {
7171
const input = '@value , from "./colors.css"';
7272
const processor = postcss([plugin]);
7373
await t.expect(processor.process(input, parserOpts)).rejects.toThrow('@value statement "" is invalid!');
7474
});
7575

76+
test('gives an error when @value declaration is invalid', async (t) => {
77+
const input = '@value oops;';
78+
const processor = postcss([plugin]);
79+
await t.expect(processor.process(input, parserOpts)).rejects.toThrow('Invalid @value definition');
80+
});
81+
7682
test('shouldn\'t break on draft spec syntax', async (t) => {
7783
await run(
7884
t,

0 commit comments

Comments
 (0)