-
-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: do not apply plug-in if file does not contain styleName attribu…
…te (#230) * feat: add skipAbsentStyleName * test: add test case for skipAbsentStyleName * feat: refactor skipAbsentStyleName traversal * fix: readd require.resolve for resource path * feat: update options naming * docs: update for skip option * refactor: traverse JSXAttribute instead of element
- Loading branch information
1 parent
d27306c
commit 9fcb91f
Showing
8 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// @flow | ||
|
||
import optionsDefaults from './schemas/optionsDefaults'; | ||
|
||
const attributeNameExists = (programPath: *, stats: *): boolean => { | ||
let exists = false; | ||
|
||
let attributeNames = optionsDefaults.attributeNames; | ||
|
||
if (stats.opts && stats.opts.attributeNames) { | ||
attributeNames = Object.assign({}, attributeNames, stats.opts.attributeNames); | ||
} | ||
|
||
programPath.traverse({ | ||
JSXAttribute (attrPath: *) { | ||
if (exists) { | ||
return; | ||
} | ||
|
||
const attribute = attrPath.node; | ||
|
||
if (typeof attribute.name !== 'undefined' && typeof attributeNames[attribute.name.name] === 'string') { | ||
exists = true; | ||
} | ||
} | ||
}); | ||
|
||
return exists; | ||
}; | ||
|
||
export default attributeNameExists; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,9 @@ | |
} | ||
}, | ||
"type": "object" | ||
}, | ||
"skip": { | ||
"type": "boolean" | ||
} | ||
}, | ||
"type": "object" | ||
|
1 change: 1 addition & 0 deletions
1
test/fixtures/react-css-modules/does not apply plugin if no styleName/bar.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.a {} |
3 changes: 3 additions & 0 deletions
3
test/fixtures/react-css-modules/does not apply plugin if no styleName/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import 'bar.css'; | ||
|
||
<div className="any" />; |
11 changes: 11 additions & 0 deletions
11
test/fixtures/react-css-modules/does not apply plugin if no styleName/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"plugins": [ | ||
[ | ||
"../../../../src", | ||
{ | ||
"generateScopedName": "[name]__[local]", | ||
"skip": true | ||
} | ||
] | ||
] | ||
} |
5 changes: 5 additions & 0 deletions
5
test/fixtures/react-css-modules/does not apply plugin if no styleName/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"use strict"; | ||
|
||
require("bar.css"); | ||
|
||
<div className="any" />; |