Skip to content

Commit 0deb388

Browse files
committed
warn, don't error
1 parent a48c56d commit 0deb388

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const replaceValueSymbols = (valueString, replacements) => {
4040
const getDefinition = (atRule, existingDefinitions, requiredDefinitions) => {
4141
const matches = matchValueDefinition.exec(atRule.params);
4242
if (!matches) {
43-
throw atRule.error('Invalid @value definition');
43+
return null;
4444
}
4545

4646
const [/* match */, name, middle, value, end] = matches;
@@ -115,6 +115,9 @@ const walk = async (requiredDefinitions, walkFile, root, result) => {
115115
}
116116

117117
const newDefinitions = getDefinition(atRule, existingDefinitions, requiredDefinitions);
118+
if (!newDefinitions) {
119+
result.warn(`Invalid value definition: ${atRule.params}`);
120+
}
118121
return Object.assign(existingDefinitions, newDefinitions);
119122
};
120123

index.test.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ test('should remove exports if noEmitExports is true', async (t) => {
5151
await run(t, '@value red blue;', '', { noEmitExports: true });
5252
});
5353

54-
test('gives an error when there is no semicolon between lines', async (t) => {
54+
test('gives a warning when there is no semicolon between lines', async (t) => {
5555
const input = '@value red blue\n@value green yellow';
5656
const processor = postcss([plugin]);
5757
const result = await processor.process(input, { from: undefined });
@@ -61,6 +61,16 @@ test('gives an error when there is no semicolon between lines', async (t) => {
6161
t.expect(warnings[0].text).toBe('Invalid value definition: red blue\n@value green yellow');
6262
});
6363

64+
test('gives a warning when @value definition is invalid', async (t) => {
65+
const input = '@value oops:;';
66+
const processor = postcss([plugin]);
67+
const result = await processor.process(input, { from: undefined });
68+
const warnings = result.warnings();
69+
70+
t.expect(warnings.length).toBe(1);
71+
t.expect(warnings[0].text).toBe('Invalid value definition: oops:');
72+
});
73+
6474
test('gives an error when path to imported file is wrong', async (t) => {
6575
const input = '@value red from "./non-existent-file.css"';
6676
const processor = postcss([plugin]);
@@ -73,12 +83,6 @@ test('gives an error when @value import statement is invalid', async (t) => {
7383
await t.expect(processor.process(input, parserOpts)).rejects.toThrow('@value statement "" is invalid!');
7484
});
7585

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-
8286
test('shouldn\'t break on draft spec syntax', async (t) => {
8387
await run(
8488
t,

0 commit comments

Comments
 (0)