Skip to content

Commit d8efd5f

Browse files
Add error message if stack hasn't been defined
1 parent 261f91a commit d8efd5f

File tree

5 files changed

+38
-14
lines changed

5 files changed

+38
-14
lines changed

.tape.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module.exports = {
2-
'postcss-stack': {
32
'basic': {
4-
message: 'supports basic usage',
3+
message: 'should support basic usage',
54
options: {
65
list: [
76
{ beneath: -1 },
@@ -12,7 +11,7 @@ module.exports = {
1211
}
1312
},
1413
'increment': {
15-
message: 'allows larger increments',
14+
message: 'should allow larger increments',
1615
options: {
1716
list: [
1817
{ beneath: -1 },
@@ -24,7 +23,22 @@ module.exports = {
2423
}
2524
},
2625
'reverse': {
27-
message: 'allows list to be reversed',
26+
message: 'should allow list to be reversed',
27+
options: {
28+
list: [
29+
'modal',
30+
'tool-tip',
31+
'application',
32+
{ beneath: -1 }
33+
],
34+
reverse: true
35+
}
36+
},
37+
'error-message': {
38+
message: 'should throw an error if stack hasn’t been defined',
39+
errors: {
40+
message: /Unknown/
41+
},
2842
options: {
2943
list: [
3044
'modal',
@@ -35,5 +49,4 @@ module.exports = {
3549
reverse: true
3650
}
3751
}
38-
}
39-
};
52+
};

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"build": "rollup --config config/rollup.config.js --silent",
3333
"lint": "eslint --config config/eslint.config.js ./src/",
3434
"pretest": "npm run build && npm run lint",
35-
"test": "postcss-tape",
35+
"test": "postcss-tape --config=./.tape.js --plugin=./dist/index.cjs.js",
3636
"version": "auto-changelog -p && git add CHANGELOG.md"
3737
},
3838
"dependencies": {
@@ -45,7 +45,7 @@
4545
"@philipbordallo/eslint-config": "^2.1.0",
4646
"auto-changelog": "^1.8.0",
4747
"eslint": "^5.6.1",
48-
"postcss-tape": "^2.2.0",
48+
"postcss-tape": "^3.0.0-rc.2",
4949
"rollup": "^0.66.2",
5050
"rollup-plugin-babel": "^4.0.3"
5151
}

src/index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import parser from 'postcss-values-parser';
33

44
import getStack from './lib/getStack';
55

6-
6+
const PLUGIN_NAME = 'postcss-stack';
77
const stackRegExp = /(^|[^\w-])(stack?)\(/i;
88

9-
export default postcss.plugin('postcss-stack', options => (root) => {
9+
export default postcss.plugin(PLUGIN_NAME, options => (root) => {
1010
const stacked = getStack(options);
1111

1212
root.walkDecls((decl) => {
@@ -18,7 +18,15 @@ export default postcss.plugin('postcss-stack', options => (root) => {
1818
ast.walkType('func', (node) => {
1919
const stack = node.nodes.filter(item => item.type === 'string')[0].value;
2020

21-
node.replaceWith(stacked[stack]);
21+
if (typeof stacked[stack] !== 'undefined') {
22+
node.replaceWith(stacked[stack]);
23+
}
24+
else {
25+
throw decl.error('Unknown stack', {
26+
plugin: PLUGIN_NAME,
27+
word: stack,
28+
});
29+
}
2230
});
2331

2432
const modifiedValue = ast.toString();

test/error-message.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.modal {
2+
z-index: stack('does-not-exist')
3+
}

0 commit comments

Comments
 (0)