From 3587127d7c8682e2017004d4a6a0a124154e266d Mon Sep 17 00:00:00 2001 From: Stephan Herzog Date: Tue, 20 Nov 2018 09:27:27 +0100 Subject: [PATCH] feat: respect exclude setting in JSXElement transform --- demo/package.json | 2 +- src/index.js | 12 +++++++++++- .../input.js | 1 + .../options.json | 11 +++++++++++ .../output.js | 3 +++ 5 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/react-css-modules/does not throw error on excluded JSXElement/input.js create mode 100644 test/fixtures/react-css-modules/does not throw error on excluded JSXElement/options.json create mode 100644 test/fixtures/react-css-modules/does not throw error on excluded JSXElement/output.js diff --git a/demo/package.json b/demo/package.json index 334ec16..fed05fd 100644 --- a/demo/package.json +++ b/demo/package.json @@ -4,7 +4,7 @@ "start": "webpack-dev-server" }, "dependencies": { - "babel-plugin-react-css-modules": "^2.1.3", + "babel-plugin-react-css-modules": "^4.0.0", "react": "^15.4.1", "react-dom": "^15.4.1", "webpack": "^2.7.0" diff --git a/src/index.js b/src/index.js index b0367f4..4bd892e 100644 --- a/src/index.js +++ b/src/index.js @@ -121,6 +121,10 @@ export default ({ return require.resolve(path.node.source.value); }; + const isFilenameExcluded = (filename, exclude) => { + return filename.match(new RegExp(exclude)); + }; + const notForPlugin = (path: *, stats: *) => { stats.opts.filetypes = stats.opts.filetypes || {}; @@ -130,7 +134,9 @@ export default ({ return true; } - if (stats.opts.exclude && getTargetResourcePath(path, stats).match(new RegExp(stats.opts.exclude))) { + const filename = getTargetResourcePath(path, stats); + + if (stats.opts.exclude && isFilenameExcluded(filename, stats.opts.exclude)) { return true; } @@ -179,6 +185,10 @@ export default ({ JSXElement (path: *, stats: *): void { const filename = stats.file.opts.filename; + if (stats.opts.exclude && isFilenameExcluded(filename, stats.opts.exclude)) { + return; + } + let attributeNames = optionsDefaults.attributeNames; if (stats.opts && stats.opts.attributeNames) { diff --git a/test/fixtures/react-css-modules/does not throw error on excluded JSXElement/input.js b/test/fixtures/react-css-modules/does not throw error on excluded JSXElement/input.js new file mode 100644 index 0000000..f1d1339 --- /dev/null +++ b/test/fixtures/react-css-modules/does not throw error on excluded JSXElement/input.js @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/test/fixtures/react-css-modules/does not throw error on excluded JSXElement/options.json b/test/fixtures/react-css-modules/does not throw error on excluded JSXElement/options.json new file mode 100644 index 0000000..d31d8d2 --- /dev/null +++ b/test/fixtures/react-css-modules/does not throw error on excluded JSXElement/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "../../../../src", + { + "generateScopedName": "[name]__[local]", + "exclude": "input" + } + ] + ] +} \ No newline at end of file diff --git a/test/fixtures/react-css-modules/does not throw error on excluded JSXElement/output.js b/test/fixtures/react-css-modules/does not throw error on excluded JSXElement/output.js new file mode 100644 index 0000000..0ba6f74 --- /dev/null +++ b/test/fixtures/react-css-modules/does not throw error on excluded JSXElement/output.js @@ -0,0 +1,3 @@ +"use strict"; + +
;