Skip to content

Commit 03f7e78

Browse files
authored
feat: add basic "go to definition" support for Sass (#137)
1 parent 82ba035 commit 03f7e78

16 files changed

+505
-270
lines changed

README.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,17 @@ const b = styles['my_other-class'];
9797

9898
Please note that no options are required. However, depending on your configuration, you may need to customise these options.
9999

100-
| Option | Default value | Description |
101-
| -------------------- | ---------------------------------- | ---------------------------------------------------------------------------- |
102-
| `classnameTransform` | `asIs` | See [`classnameTransform`](#classnameTransform) below. |
103-
| `customMatcher` | `"\\.module\\.(c\|le\|sa\|sc)ss$"` | Changes the file extensions that this plugin processes. |
104-
| `customRenderer` | `false` | See [`customRenderer`](#customRenderer) below. |
105-
| `customTemplate` | `false` | See [`customTemplate`](#customTemplate) below. |
106-
| `namedExports` | `true` | Enables named exports for compatible classnames. |
107-
| `dotenvOptions` | `{}` | Provides options for [`dotenv`](https://github.com/motdotla/dotenv#options). |
108-
| `postcssOptions` | `{}` | See [`postcssOptions`](#postcssOptions) below. |
109-
| `rendererOptions` | `{}` | See [`rendererOptions`](#rendererOptions) below. |
100+
| Option | Default value | Description |
101+
| -------------------- | ---------------------------------- | ---------------------------------------------------------------------------------------------------------- |
102+
| `classnameTransform` | `asIs` | See [`classnameTransform`](#classnameTransform) below. |
103+
| `customMatcher` | `"\\.module\\.(c\|le\|sa\|sc)ss$"` | Changes the file extensions that this plugin processes. |
104+
| `customRenderer` | `false` | See [`customRenderer`](#customRenderer) below. |
105+
| `customTemplate` | `false` | See [`customTemplate`](#customTemplate) below. |
106+
| `jumpToDefinition` | `false` | Enables jump to definition, with limited compatibility. See [`jumpToDefinition`](#jumpToDefinition) below. |
107+
| `namedExports` | `true` | Enables named exports for compatible classnames. |
108+
| `dotenvOptions` | `{}` | Provides options for [`dotenv`](https://github.com/motdotla/dotenv#options). |
109+
| `postcssOptions` | `{}` | See [`postcssOptions`](#postcssOptions) below. |
110+
| `rendererOptions` | `{}` | See [`rendererOptions`](#rendererOptions) below. |
110111

111112
```json
112113
{
@@ -142,7 +143,7 @@ When a custom renderer is provided, not other renderers will be used.
142143

143144
The path to the `customRenderer` must be relative to the project root (i.e. `./myRenderer.js`).
144145

145-
The custom renderer itself should be a JavaScript file. The function will be called with three arguments: a `css` string, an `options` object (see [`options.ts`](https://github.com/mrmckeb/typescript-plugin-css-modules/blob/main/src/options.ts#L33-L41)), and a `compilerOptions` object - which contains options as set in your `tsconfig.json`. It must be synchronous, and must return valid CSS.
146+
The custom renderer itself should be a JavaScript file. The function will be called with three arguments: a `css` string, an `options` object (see [`options.ts`](https://github.com/mrmckeb/typescript-plugin-css-modules/blob/main/src/options.ts#L22-L34)), and a `compilerOptions` object - which contains options as set in your `tsconfig.json`. It must be synchronous, and must return valid CSS.
146147

147148
```js
148149
module.exports = (css, { fileName, logger }) => {
@@ -192,6 +193,12 @@ The [internal `logger`](https://github.com/mrmckeb/typescript-plugin-css-modules
192193

193194
The `classes` object represents all the classnames extracted from the CSS Module. They are available if you want to add a custom representation of the CSS classes.
194195

196+
#### `jumpToDefinition`
197+
198+
This allows an editor like Visual Studio Code to jump to a classname's definition (file and line).
199+
200+
This is experimental, and only works with Sass (for now) and may not always work as expected.
201+
195202
#### `postcssOptions`
196203

197204
| Option | Default value | Description |

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"build": "rm -rf ./lib && tsc",
2929
"lint": "eslint --max-warnings 0 . && yarn prettier -c .",
3030
"prepublishOnly": "yarn build",
31-
"test": "jest ./src"
31+
"test": "jest"
3232
},
3333
"husky": {
3434
"hooks": {
@@ -79,6 +79,7 @@
7979
"postcss-load-config": "^3.0.1",
8080
"reserved-words": "^0.1.2",
8181
"sass": "^1.32.13",
82+
"source-map-js": "^0.6.2",
8283
"stylus": "^0.54.8",
8384
"tsconfig-paths": "^3.9.0"
8485
},
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
declare module 'postcss-icss-selectors' {
22
import { PluginCreator } from 'postcss';
3-
const plugin: PluginCreator<{ mode: 'local' | 'global' }>;
3+
const plugin: PluginCreator<{
4+
generateScopedName?(
5+
localName: string,
6+
filepath: string,
7+
css: string,
8+
): string;
9+
mode?: 'local' | 'global';
10+
}>;
411
export = plugin;
512
}

0 commit comments

Comments
 (0)