Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mrmckeb/typescript-plugin-css-modules
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v4.2.1
Choose a base ref
...
head repository: mrmckeb/typescript-plugin-css-modules
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v4.2.2
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Feb 20, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    3819676 View commit details
  2. chore: bump version

    mrmckeb committed Feb 20, 2023
    Copy the full SHA
    9809e51 View commit details
Showing with 22 additions and 8 deletions.
  1. +1 −1 package.json
  2. +21 −7 src/helpers/createDtsExports.ts
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript-plugin-css-modules",
"version": "4.2.1",
"version": "4.2.2",
"main": "dist/index.js",
"author": "Brody McKee <mrmckeb@hotmail.com>",
"license": "MIT",
28 changes: 21 additions & 7 deletions src/helpers/createDtsExports.ts
Original file line number Diff line number Diff line change
@@ -76,16 +76,30 @@ export default classes;
.filter(([classname]) => isValidVariable(classname));

filteredClasses.forEach(([classname, originalClassname]) => {
const classRegexp = new RegExp(`${originalClassname}[\\s{]`, 'g');

const matchedLine = cssLines.findIndex((line) => classRegexp.test(line));
const matchedColumn =
matchedLine && cssLines[matchedLine].indexOf(originalClassname);
let matchedLine;
let matchedColumn;

for (let i = 0; i < cssLines.length; i++) {
const match = new RegExp(
// NOTE: This excludes any match not starting with:
// - `.` for classnames,
// - `:` or ` ` for animation names,
// and any matches followed by valid CSS selector characters.
`[:.\\s]${originalClassname}(?![_a-zA-Z0-9-])`,
'g',
).exec(cssLines[i]);

if (match) {
matchedLine = i;
matchedColumn = match.index;
break;
}
}

const { line: lineNumber } = smc.originalPositionFor({
// Lines start at 1, not 0.
line: matchedLine >= 0 ? matchedLine + 1 : 1,
column: matchedColumn >= 0 ? matchedColumn : 0,
line: matchedLine ? matchedLine + 1 : 1,
column: matchedColumn ? matchedColumn : 0,
});

dtsLines[lineNumber ? lineNumber - 1 : 0] +=