Skip to content

Commit

Permalink
fix: ignore modules without identifier (#627)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Oct 19, 2020
1 parent 028b4f2 commit 71a9ce9
Show file tree
Hide file tree
Showing 7 changed files with 1,428 additions and 1,656 deletions.
3,012 changes: 1,367 additions & 1,645 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,24 @@
"webpack-sources": "^1.1.0"
},
"devDependencies": {
"@babel/cli": "^7.11.6",
"@babel/core": "^7.11.6",
"@babel/preset-env": "^7.11.5",
"@babel/cli": "^7.12.1",
"@babel/core": "^7.12.3",
"@babel/preset-env": "^7.12.1",
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@webpack-contrib/defaults": "^6.3.0",
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
"babel-eslint": "^10.0.2",
"babel-eslint": "^10.1.0",
"babel-jest": "^26.5.2",
"cross-env": "^7.0.2",
"css-loader": "^4.3.0",
"css-loader": "^5.0.0",
"del": "^6.0.0",
"del-cli": "^3.0.1",
"es-check": "^5.1.1",
"eslint": "^7.10.0",
"eslint-config-prettier": "^6.12.0",
"eslint": "^7.11.0",
"eslint-config-prettier": "^6.13.0",
"eslint-plugin-import": "^2.22.1",
"file-loader": "^6.1.0",
"file-loader": "^6.1.1",
"husky": "^4.3.0",
"jest": "^26.5.2",
"jsdom": "^16.4.0",
Expand All @@ -76,7 +76,7 @@
"prettier": "^2.1.2",
"standard-version": "^9.0.0",
"webpack": "^5.1.0",
"webpack-cli": "^3.3.6",
"webpack-cli": "^4.1.0",
"webpack-dev-server": "^3.7.2"
},
"keywords": [
Expand Down
10 changes: 9 additions & 1 deletion src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ export function pitch(request) {
const identifierCountMap = new Map();

for (const dependency of dependencies) {
if (!dependency.identifier) {
// eslint-disable-next-line no-continue
continue;
}

const count = identifierCountMap.get(dependency.identifier) || 0;

this._module.addDependency(
Expand Down Expand Up @@ -197,7 +202,10 @@ export function pitch(request) {
if (namedExport) {
Object.keys(originalExports).forEach((key) => {
if (key !== 'default') {
if (!locals) locals = {};
if (!locals) {
locals = {};
}

locals[key] = originalExports[key];
}
});
Expand Down
2 changes: 1 addition & 1 deletion test/TestCases.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ describe('TestCases', () => {
outputDirectoryForCase,
expectedDirectoryByVersion
);
} else {
} else if (fs.existsSync(expectedDirectory)) {
compareDirectory(outputDirectoryForCase, expectedDirectory);
}

Expand Down
1 change: 1 addition & 0 deletions test/cases/no-identifier/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './style.css';
11 changes: 11 additions & 0 deletions test/cases/no-identifier/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.a {
background: red;
}

:local(.b) {
color: green;
}

:global(.c) {
color: blue;
}
30 changes: 30 additions & 0 deletions test/cases/no-identifier/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Self from '../../../src';

module.exports = {
entry: './index.js',
module: {
rules: [
{
test: /\.css$/,
use: [
Self.loader,
{
loader: 'css-loader',
options: {
modules: {
mode: 'local',
localIdentName: 'foo__[name]__[local]',
exportOnlyLocals: true,
},
},
},
],
},
],
},
plugins: [
new Self({
filename: '[name].css',
}),
],
};

0 comments on commit 71a9ce9

Please sign in to comment.