-
-
Notifications
You must be signed in to change notification settings - Fork 161
Feat/add regexp support for filetype #240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gajus
merged 7 commits into
gajus:master
from
xuxinhang:feat/add_regexp_support_for_filetype
Sep 17, 2020
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8dd11cd
feat: use RegExp as including condition in filetype config
cce93c8
test: add corresponding test cases.
9f41cf7
fix: do not use extension-style filrtype as RegExp pattern
3dd9bfe
feat: modify the priority between RegExp pattern filetype and extensi…
fb7a829
style: no continue
1c94157
style: for comment #2
951f889
Merge branch 'master' into feat/add_regexp_support_for_filetype
xuxinhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,25 @@ | ||
// @flow | ||
|
||
export default (sourceFilePath: string, filetypes: $ReadOnlyArray<string>): ?string => { | ||
// Try to match as the RegExp pattern | ||
for (const pattern of filetypes) { | ||
if (!pattern.match(/^\.[a-z0-9A-Z]+?$/)) { | ||
if (sourceFilePath.match(new RegExp(pattern))) { | ||
return pattern; | ||
} | ||
} | ||
} | ||
|
||
const extensionDotIndex = sourceFilePath.lastIndexOf('.'); | ||
|
||
if (extensionDotIndex > -1) { | ||
const extension = sourceFilePath.substr(extensionDotIndex); | ||
const index = filetypes.indexOf(extension); | ||
|
||
if (index > -1) { | ||
return filetypes[index]; | ||
} | ||
} | ||
|
||
return null; | ||
}; |
This file contains hidden or 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 hidden or 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 hidden or 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
3 changes: 3 additions & 0 deletions
3
test/fixtures/react-css-modules/resolves less stylesheets matching RegExp/bar.less
This file contains hidden or 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 @@ | ||
@color: #f00; | ||
|
||
.a {background-color: @color;} |
3 changes: 3 additions & 0 deletions
3
test/fixtures/react-css-modules/resolves less stylesheets matching RegExp/bar.md.less
This file contains hidden or 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 @@ | ||
@color: #f00; | ||
|
||
.a {background-color: @color;} |
3 changes: 3 additions & 0 deletions
3
test/fixtures/react-css-modules/resolves less stylesheets matching RegExp/input.js
This file contains hidden or 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.md.less'; | ||
|
||
<div styleName="a"></div>; |
15 changes: 15 additions & 0 deletions
15
test/fixtures/react-css-modules/resolves less stylesheets matching RegExp/options.json
This file contains hidden or 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,15 @@ | ||
{ | ||
"plugins": [ | ||
[ | ||
"../../../../src", | ||
{ | ||
"generateScopedName": "[name]__[local]", | ||
"filetypes": { | ||
"\\.md\\.less$": { | ||
"syntax": "postcss-less" | ||
} | ||
} | ||
} | ||
] | ||
] | ||
} |
5 changes: 5 additions & 0 deletions
5
test/fixtures/react-css-modules/resolves less stylesheets matching RegExp/output.js
This file contains hidden or 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.md.less"); | ||
|
||
<div className="bar-md__a"></div>; |
1 change: 1 addition & 0 deletions
1
test/fixtures/react-css-modules/resolves namespaced styleName matching RegExp/bar.md.css
This file contains hidden or 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 {background-color: #f00;} |
1 change: 1 addition & 0 deletions
1
test/fixtures/react-css-modules/resolves namespaced styleName matching RegExp/foo.css
This file contains hidden or 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 {background-color: #f00;} |
4 changes: 4 additions & 0 deletions
4
test/fixtures/react-css-modules/resolves namespaced styleName matching RegExp/input.js
This file contains hidden or 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,4 @@ | ||
import barMd from './bar.md.css'; | ||
import base from './styles/base.css'; | ||
|
||
<div styleName="barMd.a base.b"></div>; |
16 changes: 16 additions & 0 deletions
16
test/fixtures/react-css-modules/resolves namespaced styleName matching RegExp/options.json
This file contains hidden or 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,16 @@ | ||
{ | ||
"plugins": [ | ||
[ | ||
"../../../../src", | ||
{ | ||
"generateScopedName": "[name]__[local]", | ||
"filetypes": { | ||
"\\.md\\.less$": { | ||
"syntax": "postcss-less" | ||
}, | ||
"styles/.*?\\.css$": {} | ||
} | ||
} | ||
] | ||
] | ||
} |
9 changes: 9 additions & 0 deletions
9
test/fixtures/react-css-modules/resolves namespaced styleName matching RegExp/output.js
This file contains hidden or 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,9 @@ | ||
"use strict"; | ||
|
||
var _barMd = _interopRequireDefault(require("./bar.md.css")); | ||
|
||
var _base = _interopRequireDefault(require("./styles/base.css")); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
<div className="bar-md__a base__b"></div>; |
1 change: 1 addition & 0 deletions
1
.../fixtures/react-css-modules/resolves namespaced styleName matching RegExp/styles/base.css
This file contains hidden or 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 @@ | ||
.b {background-color: #0f0;} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.