@griffel/postcss-syntax 1.3.13 → 1.3.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +136 -19
- package/package.json +14 -8
- package/src/constants.js +5 -8
- package/src/constants.js.map +1 -1
- package/src/createSyntax.d.ts +4 -4
- package/src/createSyntax.js +7 -10
- package/src/createSyntax.js.map +1 -1
- package/src/index.d.ts +5 -5
- package/src/index.js +8 -15
- package/src/index.js.map +1 -1
- package/src/parse.d.ts +4 -2
- package/src/parse.js +30 -43
- package/src/parse.js.map +1 -1
- package/src/resolveModule.d.ts +10 -0
- package/src/resolveModule.js +37 -0
- package/src/resolveModule.js.map +1 -0
- package/src/stringify.js +3 -7
- package/src/stringify.js.map +1 -1
- package/src/location-preset.d.ts +0 -28
- package/src/location-preset.js +0 -150
- package/src/location-preset.js.map +0 -1
- package/src/transform-sync.d.ts +0 -13
- package/src/transform-sync.js +0 -30
- package/src/transform-sync.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,33 +1,150 @@
|
|
|
1
|
-
#
|
|
1
|
+
# PostCSS syntax for Griffel
|
|
2
2
|
|
|
3
|
-
A
|
|
4
|
-
Griffel CSS
|
|
3
|
+
A PostCSS [custom syntax](https://postcss.org/docs/how-to-write-custom-syntax) that exposes the CSS
|
|
4
|
+
generated by Griffel to CSS tooling, most notably [stylelint](https://stylelint.io/).
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
Griffel compiles `makeStyles()` and `makeResetStyles()` calls to atomic CSS ahead of time, so that CSS
|
|
7
|
+
never exists as a `.css` file and a CSS linter has nothing to read. This package closes that gap: it
|
|
8
|
+
runs the Griffel transform over a JavaScript/TypeScript file and returns a PostCSS AST of the
|
|
9
|
+
generated CSS, with source locations that point back to the original JavaScript.
|
|
7
10
|
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
|
12
|
+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
|
10
13
|
|
|
11
|
-
|
|
14
|
+
- [Install](#install)
|
|
15
|
+
- [Usage with stylelint](#usage-with-stylelint)
|
|
16
|
+
- [Disabling rules](#disabling-rules)
|
|
17
|
+
- [Linting custom wrappers](#linting-custom-wrappers)
|
|
18
|
+
- [API](#api)
|
|
19
|
+
- [Limitations](#limitations)
|
|
12
20
|
|
|
13
|
-
|
|
14
|
-
compilation lacks the capability to map generated CSS back to the original javascript properties very accurately.
|
|
21
|
+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
|
15
22
|
|
|
16
|
-
##
|
|
23
|
+
## Install
|
|
17
24
|
|
|
18
|
-
|
|
19
|
-
|
|
25
|
+
```bash
|
|
26
|
+
yarn add --dev @griffel/postcss-syntax
|
|
27
|
+
# or
|
|
28
|
+
npm install --save-dev @griffel/postcss-syntax
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
> ⚠️ This package is **ESM only**. If your project is CommonJS, use `stylelint.config.mjs` rather than
|
|
32
|
+
> `.stylelintrc.js`, as the latter is loaded with `require()`.
|
|
33
|
+
|
|
34
|
+
## Usage with stylelint
|
|
35
|
+
|
|
36
|
+
Stylelint calls a PostCSS syntax a [custom syntax](https://stylelint.io/developer-guide/syntaxes).
|
|
37
|
+
Point `customSyntax` at this package:
|
|
38
|
+
|
|
39
|
+
```json title=".stylelintrc.json"
|
|
40
|
+
{
|
|
41
|
+
"customSyntax": "@griffel/postcss-syntax",
|
|
42
|
+
"rules": {
|
|
43
|
+
"selector-anb-no-unmatchable": true
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Then lint your style files:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npx stylelint "src/**/*.styles.ts"
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
For example, this file:
|
|
55
|
+
|
|
56
|
+
```ts title="example.styles.ts"
|
|
57
|
+
import { makeStyles } from '@griffel/react';
|
|
58
|
+
|
|
59
|
+
export const useStyles = makeStyles({
|
|
60
|
+
root: {
|
|
61
|
+
':nth-child(0)': { color: 'red' },
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
...generates `.fwey13v:nth-child(0){color:red;}`, which makes stylelint report
|
|
67
|
+
`selector-anb-no-unmatchable`. The reported location points at the `root` slot in `example.styles.ts`,
|
|
68
|
+
not at the generated CSS.
|
|
69
|
+
|
|
70
|
+
## Disabling rules
|
|
71
|
+
|
|
72
|
+
`stylelint-disable` comments cannot be placed in generated CSS, so use a `griffel-csslint-disable`
|
|
73
|
+
comment directive instead. For `makeStyles()` place it above a slot:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
export const useStyles = makeStyles({
|
|
77
|
+
// griffel-csslint-disable selector-anb-no-unmatchable
|
|
78
|
+
root: {
|
|
79
|
+
':nth-child(0)': { color: 'red' },
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
For `makeResetStyles()` place it above the declaration:
|
|
20
85
|
|
|
21
86
|
```ts
|
|
87
|
+
// griffel-csslint-disable selector-anb-no-unmatchable
|
|
88
|
+
export const useResetStyles = makeResetStyles({
|
|
89
|
+
':nth-child(0)': { color: 'red' },
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
A directive must be a line comment (`//`) and disables exactly one rule. To disable several rules, use
|
|
94
|
+
several comments:
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
export const useStyles = makeStyles({
|
|
98
|
+
// griffel-csslint-disable selector-anb-no-unmatchable
|
|
99
|
+
// griffel-csslint-disable declaration-property-value-no-unknown
|
|
100
|
+
root: {/* ... */},
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Linting custom wrappers
|
|
105
|
+
|
|
106
|
+
By default only `makeStyles()`/`makeResetStyles()` imported from `@griffel/core`, `@griffel/react` or
|
|
107
|
+
`@fluentui/react-components` are processed. If your project re-exports them from its own package, use
|
|
108
|
+
`createSyntax()` to build a configured syntax:
|
|
109
|
+
|
|
110
|
+
```js title="stylelint.config.mjs"
|
|
22
111
|
import { createSyntax } from '@griffel/postcss-syntax';
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
})
|
|
112
|
+
|
|
113
|
+
export default {
|
|
114
|
+
customSyntax: createSyntax({
|
|
115
|
+
importsToTransform: ['@griffel/react', '@myScope/griffel'],
|
|
116
|
+
}),
|
|
117
|
+
rules: {
|
|
118
|
+
'selector-anb-no-unmatchable': true,
|
|
119
|
+
},
|
|
120
|
+
};
|
|
28
121
|
```
|
|
29
122
|
|
|
30
|
-
|
|
31
|
-
|
|
123
|
+
`createSyntax()` accepts:
|
|
124
|
+
|
|
125
|
+
| Option | Type | Default | Description |
|
|
126
|
+
| ---------------------- | ---------- | ------------------------------------------------------------------- | ------------------------------------------------------------- |
|
|
127
|
+
| `importsToTransform` | `string[]` | `['@griffel/core', '@griffel/react', '@fluentui/react-components']` | Modules whose Griffel imports should be processed. |
|
|
128
|
+
| `functionsToTransform` | `string[]` | `['makeStyles', 'makeResetStyles', 'makeStaticStyles']` | Function names that should be treated as Griffel style calls. |
|
|
129
|
+
|
|
130
|
+
> ⚠️ Both options **replace** their defaults rather than extend them. Keep `@griffel/react` in the
|
|
131
|
+
> list if you also import from it directly.
|
|
132
|
+
|
|
133
|
+
## API
|
|
134
|
+
|
|
135
|
+
- `parse(css, options?)` — parses a JavaScript/TypeScript source and returns a PostCSS AST of the
|
|
136
|
+
generated CSS. Supports `from`, `silenceParseErrors`, `importsToTransform` and
|
|
137
|
+
`functionsToTransform`.
|
|
138
|
+
- `stringify(node, builder)` — the matching stringifier.
|
|
139
|
+
- `createSyntax(options)` — returns a `{ parse, stringify }` syntax configured with the options above.
|
|
140
|
+
|
|
141
|
+
When a file cannot be parsed, `parse()` emits a `/* Failed to parse griffel styles: <file> */` comment
|
|
142
|
+
and logs the error. Pass `silenceParseErrors: true` to suppress the log.
|
|
32
143
|
|
|
144
|
+
## Limitations
|
|
33
145
|
|
|
146
|
+
- Only `makeStyles()` and `makeResetStyles()` produce CSS, and both must be statically evaluable, see
|
|
147
|
+
[limitations of the build time transform](https://griffel.js.org/react/guides/limitations).
|
|
148
|
+
- The stringifier only works on an AST produced by this syntax, as Griffel's ahead of time compilation
|
|
149
|
+
cannot map generated CSS back to the original JavaScript accurately enough for arbitrary input. For
|
|
150
|
+
the same reason stylelint's `--fix` is not supported.
|
package/package.json
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@griffel/postcss-syntax",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.15",
|
|
4
4
|
"description": "postcss syntax for Griffel",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/microsoft/griffel"
|
|
9
9
|
},
|
|
10
|
-
"
|
|
11
|
-
"@babel/core": "^7.29.0",
|
|
12
|
-
"@babel/helper-plugin-utils": "^7.28.6",
|
|
13
|
-
"@griffel/babel-preset": "^1.9.0",
|
|
14
|
-
"postcss": "^8.5.14"
|
|
15
|
-
},
|
|
10
|
+
"type": "module",
|
|
16
11
|
"main": "./src/index.js",
|
|
17
12
|
"types": "./src/index.d.ts",
|
|
18
|
-
"
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./src/index.d.ts",
|
|
16
|
+
"default": "./src/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@griffel/transform": "^3.0.8",
|
|
22
|
+
"postcss": "^8.5.18"
|
|
23
|
+
},
|
|
24
|
+
"module": "./src/index.js"
|
|
19
25
|
}
|
package/src/constants.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.GRIFFEL_DECLARATOR_RAW = 'griffel-declarator';
|
|
7
|
-
exports.GRIFFEL_SLOT_LOCATION_RAW = 'griffel-slot-location';
|
|
8
|
-
exports.GRIFFEL_DECLARATOR_LOCATION_RAW = 'griffel-declarator-location';
|
|
1
|
+
export const GRIFFEL_SLOT_RAW = 'griffel-slot';
|
|
2
|
+
export const GRIFFEL_SRC_RAW = 'griffel-src';
|
|
3
|
+
export const GRIFFEL_DECLARATOR_RAW = 'griffel-declarator';
|
|
4
|
+
export const GRIFFEL_SLOT_LOCATION_RAW = 'griffel-slot-location';
|
|
5
|
+
export const GRIFFEL_DECLARATOR_LOCATION_RAW = 'griffel-declarator-location';
|
|
9
6
|
//# sourceMappingURL=constants.js.map
|
package/src/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../packages/postcss-syntax/src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../packages/postcss-syntax/src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,cAAc,CAAC;AAC/C,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAAC;AAC7C,MAAM,CAAC,MAAM,sBAAsB,GAAG,oBAAoB,CAAC;AAC3D,MAAM,CAAC,MAAM,yBAAyB,GAAG,uBAAuB,CAAC;AACjE,MAAM,CAAC,MAAM,+BAA+B,GAAG,6BAA6B,CAAC"}
|
package/src/createSyntax.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ParserOptions } from './parse.js';
|
|
2
2
|
import type * as postcss from 'postcss';
|
|
3
3
|
/**
|
|
4
|
-
* Creates a custom syntax with configured options
|
|
5
|
-
* @param options - Options to configure
|
|
4
|
+
* Creates a custom syntax with configured options
|
|
5
|
+
* @param options - Options to configure the transform
|
|
6
6
|
* @returns a postcss custom syntax
|
|
7
7
|
*/
|
|
8
|
-
export declare function createSyntax(options:
|
|
8
|
+
export declare function createSyntax(options: Pick<ParserOptions, 'importsToTransform' | 'functionsToTransform'>): postcss.Syntax;
|
package/src/createSyntax.js
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.createSyntax = createSyntax;
|
|
4
|
-
const parse_1 = require("./parse");
|
|
5
|
-
const stringify_1 = require("./stringify");
|
|
1
|
+
import { parse } from './parse.js';
|
|
2
|
+
import { stringify } from './stringify.js';
|
|
6
3
|
/**
|
|
7
|
-
* Creates a custom syntax with configured options
|
|
8
|
-
* @param options - Options to configure
|
|
4
|
+
* Creates a custom syntax with configured options
|
|
5
|
+
* @param options - Options to configure the transform
|
|
9
6
|
* @returns a postcss custom syntax
|
|
10
7
|
*/
|
|
11
|
-
function createSyntax(options) {
|
|
12
|
-
const extendedParse = (css, opts) =>
|
|
8
|
+
export function createSyntax(options) {
|
|
9
|
+
const extendedParse = (css, opts) => parse(css, { ...opts, ...options });
|
|
13
10
|
return {
|
|
14
|
-
stringify
|
|
11
|
+
stringify,
|
|
15
12
|
parse: extendedParse,
|
|
16
13
|
};
|
|
17
14
|
}
|
package/src/createSyntax.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSyntax.js","sourceRoot":"","sources":["../../../../packages/postcss-syntax/src/createSyntax.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createSyntax.js","sourceRoot":"","sources":["../../../../packages/postcss-syntax/src/createSyntax.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAC1B,OAA2E;IAE3E,MAAM,aAAa,GAAmB,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IAEzF,OAAO;QACL,SAAS;QACT,KAAK,EAAE,aAAa;KACrB,CAAC;AACJ,CAAC"}
|
package/src/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { parse } from './parse';
|
|
2
|
-
import { stringify } from './stringify';
|
|
1
|
+
import { parse } from './parse.js';
|
|
2
|
+
import { stringify } from './stringify.js';
|
|
3
3
|
export { parse, stringify };
|
|
4
|
-
export { createSyntax } from './createSyntax';
|
|
4
|
+
export { createSyntax } from './createSyntax.js';
|
|
5
5
|
declare const _default: {
|
|
6
6
|
parse: (css: string | {
|
|
7
7
|
toString(): string;
|
|
8
|
-
}, opts?: import("./parse").ParserOptions) => import("postcss").Root;
|
|
8
|
+
}, opts?: import("./parse.js").ParserOptions) => import("postcss").Root;
|
|
9
9
|
stringify: import("postcss").Stringifier;
|
|
10
10
|
};
|
|
11
11
|
export default _default;
|
|
12
|
-
export { GRIFFEL_DECLARATOR_LOCATION_RAW, GRIFFEL_SLOT_LOCATION_RAW } from './constants';
|
|
12
|
+
export { GRIFFEL_DECLARATOR_LOCATION_RAW, GRIFFEL_SLOT_LOCATION_RAW } from './constants.js';
|
package/src/index.js
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var createSyntax_1 = require("./createSyntax");
|
|
9
|
-
Object.defineProperty(exports, "createSyntax", { enumerable: true, get: function () { return createSyntax_1.createSyntax; } });
|
|
10
|
-
exports.default = {
|
|
11
|
-
parse: parse_1.parse,
|
|
12
|
-
stringify: stringify_1.stringify,
|
|
1
|
+
import { parse } from './parse.js';
|
|
2
|
+
import { stringify } from './stringify.js';
|
|
3
|
+
export { parse, stringify };
|
|
4
|
+
export { createSyntax } from './createSyntax.js';
|
|
5
|
+
export default {
|
|
6
|
+
parse,
|
|
7
|
+
stringify,
|
|
13
8
|
};
|
|
14
|
-
|
|
15
|
-
Object.defineProperty(exports, "GRIFFEL_DECLARATOR_LOCATION_RAW", { enumerable: true, get: function () { return constants_1.GRIFFEL_DECLARATOR_LOCATION_RAW; } });
|
|
16
|
-
Object.defineProperty(exports, "GRIFFEL_SLOT_LOCATION_RAW", { enumerable: true, get: function () { return constants_1.GRIFFEL_SLOT_LOCATION_RAW; } });
|
|
9
|
+
export { GRIFFEL_DECLARATOR_LOCATION_RAW, GRIFFEL_SLOT_LOCATION_RAW } from './constants.js';
|
|
17
10
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/postcss-syntax/src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/postcss-syntax/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,eAAe;IACb,KAAK;IACL,SAAS;CACV,CAAC;AAEF,OAAO,EAAE,+BAA+B,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC"}
|
package/src/parse.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as postcss from 'postcss';
|
|
2
|
-
import type {
|
|
2
|
+
import type { TransformOptions as GriffelTransformOptions } from '@griffel/transform';
|
|
3
3
|
export type PostCSSParserOptions = Pick<postcss.ProcessOptions<postcss.Document | postcss.Root>, 'from' | 'map'>;
|
|
4
|
-
|
|
4
|
+
type ModuleMatchingOptions = Pick<GriffelTransformOptions, 'importsToTransform' | 'functionsToTransform'>;
|
|
5
|
+
export interface ParserOptions extends Pick<PostCSSParserOptions, 'from'>, ModuleMatchingOptions {
|
|
5
6
|
/**
|
|
6
7
|
* Throws error when griffel parsing fails
|
|
7
8
|
* @default false
|
|
@@ -15,3 +16,4 @@ export interface ParserOptions extends Pick<PostCSSParserOptions, 'from'>, Babel
|
|
|
15
16
|
export declare const parse: (css: string | {
|
|
16
17
|
toString(): string;
|
|
17
18
|
}, opts?: ParserOptions) => postcss.Root;
|
|
19
|
+
export {};
|
package/src/parse.js
CHANGED
|
@@ -1,33 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const constants_1 = require("./constants");
|
|
7
|
-
const os = require("os");
|
|
1
|
+
import * as postcss from 'postcss';
|
|
2
|
+
import { transformSync as griffelTransformSync } from '@griffel/transform';
|
|
3
|
+
import { GRIFFEL_DECLARATOR_LOCATION_RAW, GRIFFEL_DECLARATOR_RAW, GRIFFEL_SLOT_LOCATION_RAW, GRIFFEL_SLOT_RAW, GRIFFEL_SRC_RAW, } from './constants.js';
|
|
4
|
+
import { nodeResolve } from './resolveModule.js';
|
|
5
|
+
import * as os from 'os';
|
|
8
6
|
/**
|
|
9
7
|
* Generates CSS rules from a JavaScript file. Each slot in `makeStyles` and each `makeResetStyles` will be one line in the output.
|
|
10
8
|
* It returns a PostCSS AST that parses the generated CSS rules. For each node in AST, attaches information about its related slot location from the original js file.
|
|
11
9
|
*/
|
|
12
|
-
const parse = (css, opts) => {
|
|
13
|
-
const { from: filename = 'postcss-syntax.styles.ts', silenceParseErrors = false } = opts
|
|
14
|
-
const
|
|
10
|
+
export const parse = (css, opts) => {
|
|
11
|
+
const { from: filename = 'postcss-syntax.styles.ts', silenceParseErrors = false } = opts ?? {};
|
|
12
|
+
const pluginOptions = extractPluginOptions(opts);
|
|
15
13
|
const code = css.toString();
|
|
16
14
|
const cssRuleSlotNames = [];
|
|
17
15
|
const cssRules = [];
|
|
18
|
-
const parseResult = parseGriffelStyles(code, filename,
|
|
16
|
+
const parseResult = parseGriffelStyles(code, filename, pluginOptions, silenceParseErrors);
|
|
19
17
|
if (!parseResult) {
|
|
20
18
|
const root = postcss.parse(`/* Failed to parse griffel styles: ${filename} */`, { from: filename });
|
|
21
|
-
root.raws[
|
|
19
|
+
root.raws[GRIFFEL_SRC_RAW] = code;
|
|
22
20
|
return root;
|
|
23
21
|
}
|
|
24
22
|
const { cssEntries, cssResetEntries, callExpressionLocations, resetLocations, locations, commentDirectives, resetCommentDirectives, } = parseResult;
|
|
25
23
|
Object.entries(cssEntries).forEach(([declarator, slots]) => {
|
|
26
24
|
Object.entries(slots).forEach(([slot, rules]) => {
|
|
27
|
-
var _a, _b;
|
|
28
25
|
cssRuleSlotNames.push(`${declarator} ${slot}`);
|
|
29
26
|
let cssRule = rules.join('').replace(new RegExp(os.EOL, 'g'), ' ');
|
|
30
|
-
const ignoredRules = getIgnoredRulesFromDirectives(
|
|
27
|
+
const ignoredRules = getIgnoredRulesFromDirectives(commentDirectives[declarator]?.[slot] ?? []);
|
|
31
28
|
if (ignoredRules.length) {
|
|
32
29
|
const stylelintIgnore = `/* stylelint-disable-line ${ignoredRules.join(',')} */`;
|
|
33
30
|
cssRule = `${cssRule} ${stylelintIgnore}`;
|
|
@@ -36,9 +33,8 @@ const parse = (css, opts) => {
|
|
|
36
33
|
});
|
|
37
34
|
});
|
|
38
35
|
Object.entries(cssResetEntries).forEach(([declarator, resetRules]) => {
|
|
39
|
-
var _a;
|
|
40
36
|
cssRuleSlotNames.push(`${declarator}`);
|
|
41
|
-
const ignoredRules = getIgnoredRulesFromDirectives(
|
|
37
|
+
const ignoredRules = getIgnoredRulesFromDirectives(resetCommentDirectives[declarator] ?? []);
|
|
42
38
|
let cssRule = resetRules.join('').replace(new RegExp(os.EOL, 'g'), ' ');
|
|
43
39
|
if (ignoredRules.length) {
|
|
44
40
|
const stylelintIgnore = `/* stylelint-disable-line ${ignoredRules.join(',')} */`;
|
|
@@ -48,34 +44,31 @@ const parse = (css, opts) => {
|
|
|
48
44
|
});
|
|
49
45
|
const root = postcss.parse(cssRules.join('\n'), { from: filename });
|
|
50
46
|
root.walk(node => {
|
|
51
|
-
var _a, _b, _c;
|
|
52
47
|
if (!node.source || node.source.start === undefined) {
|
|
53
48
|
return;
|
|
54
49
|
}
|
|
55
50
|
const [declarator, slot] = cssRuleSlotNames[node.source.start.line - 1].split(' ');
|
|
56
|
-
node.raws[
|
|
51
|
+
node.raws[GRIFFEL_DECLARATOR_RAW] = declarator;
|
|
57
52
|
if (slot) {
|
|
58
|
-
node.raws[
|
|
59
|
-
node.raws[
|
|
53
|
+
node.raws[GRIFFEL_SLOT_RAW] = slot;
|
|
54
|
+
node.raws[GRIFFEL_SLOT_LOCATION_RAW] = locations[declarator]?.[slot] ?? callExpressionLocations[declarator];
|
|
60
55
|
}
|
|
61
56
|
else {
|
|
62
|
-
node.raws[
|
|
57
|
+
node.raws[GRIFFEL_DECLARATOR_LOCATION_RAW] = resetLocations[declarator] ?? callExpressionLocations[declarator];
|
|
63
58
|
}
|
|
64
59
|
});
|
|
65
|
-
root.raws[
|
|
60
|
+
root.raws[GRIFFEL_SRC_RAW] = css;
|
|
66
61
|
return root;
|
|
67
62
|
};
|
|
68
|
-
exports.parse = parse;
|
|
69
63
|
function parseGriffelStyles(code, filename, pluginOpts, silenceParseErrors) {
|
|
70
64
|
try {
|
|
71
|
-
const { metadata } = (
|
|
65
|
+
const { metadata } = griffelTransformSync(code, {
|
|
72
66
|
filename,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
},
|
|
67
|
+
resolveModule: nodeResolve,
|
|
68
|
+
generateMetadata: true,
|
|
69
|
+
...pluginOpts,
|
|
77
70
|
});
|
|
78
|
-
return metadata;
|
|
71
|
+
return metadata ?? null;
|
|
79
72
|
}
|
|
80
73
|
catch (error) {
|
|
81
74
|
// eslint-disable-next-line no-console
|
|
@@ -93,21 +86,15 @@ function getIgnoredRulesFromDirectives(commentDirectives) {
|
|
|
93
86
|
.filter(([directive]) => directive === 'griffel-csslint-disable')
|
|
94
87
|
.map(([_, rulename]) => rulename);
|
|
95
88
|
}
|
|
96
|
-
const
|
|
97
|
-
const {
|
|
98
|
-
const
|
|
99
|
-
if (
|
|
100
|
-
|
|
89
|
+
const extractPluginOptions = (opts = {}) => {
|
|
90
|
+
const { importsToTransform, functionsToTransform } = opts;
|
|
91
|
+
const pluginOptions = {};
|
|
92
|
+
if (importsToTransform) {
|
|
93
|
+
pluginOptions.importsToTransform = importsToTransform;
|
|
101
94
|
}
|
|
102
|
-
if (
|
|
103
|
-
|
|
95
|
+
if (functionsToTransform) {
|
|
96
|
+
pluginOptions.functionsToTransform = functionsToTransform;
|
|
104
97
|
}
|
|
105
|
-
|
|
106
|
-
babelPluginOptions.generateMetadata = generateMetadata;
|
|
107
|
-
}
|
|
108
|
-
if (modules) {
|
|
109
|
-
babelPluginOptions.modules = modules;
|
|
110
|
-
}
|
|
111
|
-
return babelPluginOptions;
|
|
98
|
+
return pluginOptions;
|
|
112
99
|
};
|
|
113
100
|
//# sourceMappingURL=parse.js.map
|
package/src/parse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../../../packages/postcss-syntax/src/parse.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../../../packages/postcss-syntax/src/parse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,aAAa,IAAI,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EACL,+BAA+B,EAC/B,sBAAsB,EACtB,yBAAyB,EACzB,gBAAgB,EAChB,eAAe,GAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE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E,IAAI;YACtB,GAAG,UAAU;SACd,CAAC,CAAC;QAEH,OAAO,QAAQ,IAAI,IAAI,CAAC;IAC1B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,sCAAsC;QACtC,OAAO,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;QAC/C,sCAAsC;QACtC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACpB,IAAI,kBAAkB,EAAE,CAAC;YACvB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,6BAA6B,CAAC,iBAAsD;IAC3F,OAAO,iBAAiB;SACrB,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC,SAAS,KAAK,yBAAyB,CAAC;SAChE,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,oBAAoB,GAAG,CAAC,OAAsB,EAAE,EAAE,EAAE;IACxD,MAAM,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,GAAG,IAAI,CAAC;IAC1D,MAAM,aAAa,GAA0B,EAAE,CAAC;IAEhD,IAAI,kBAAkB,EAAE,CAAC;QACvB,aAAa,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;IACxD,CAAC;IAED,IAAI,oBAAoB,EAAE,CAAC;QACzB,aAAa,CAAC,oBAAoB,GAAG,oBAAoB,CAAC;IAC5D,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TransformOptions as GriffelTransformOptions } from '@griffel/transform';
|
|
2
|
+
/**
|
|
3
|
+
* A Node based module resolver for `@griffel/transform`. In addition to the extensions that Node
|
|
4
|
+
* resolves by default it also accepts TypeScript/JSX extensions by temporarily registering them
|
|
5
|
+
* with Node's resolver, so imports inside `.ts`/`.tsx` style files can be resolved.
|
|
6
|
+
*
|
|
7
|
+
* Node builtins are reported via `builtin: true` so that `@griffel/transform` can reject them with
|
|
8
|
+
* a descriptive error instead of trying to evaluate them in its sandbox.
|
|
9
|
+
*/
|
|
10
|
+
export declare const nodeResolve: GriffelTransformOptions['resolveModule'];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import NativeModule from 'node:module';
|
|
2
|
+
const EXTRA_EXTENSIONS = ['.ts', '.tsx', '.jsx', '.cjs'];
|
|
3
|
+
/**
|
|
4
|
+
* A Node based module resolver for `@griffel/transform`. In addition to the extensions that Node
|
|
5
|
+
* resolves by default it also accepts TypeScript/JSX extensions by temporarily registering them
|
|
6
|
+
* with Node's resolver, so imports inside `.ts`/`.tsx` style files can be resolved.
|
|
7
|
+
*
|
|
8
|
+
* Node builtins are reported via `builtin: true` so that `@griffel/transform` can reject them with
|
|
9
|
+
* a descriptive error instead of trying to evaluate them in its sandbox.
|
|
10
|
+
*/
|
|
11
|
+
export const nodeResolve = (id, opts) => {
|
|
12
|
+
if (NativeModule.isBuiltin(id)) {
|
|
13
|
+
return { path: id, builtin: true };
|
|
14
|
+
}
|
|
15
|
+
const extensions = NativeModule._extensions;
|
|
16
|
+
const added = [];
|
|
17
|
+
try {
|
|
18
|
+
for (const ext of EXTRA_EXTENSIONS) {
|
|
19
|
+
if (!(ext in extensions)) {
|
|
20
|
+
extensions[ext] = () => {
|
|
21
|
+
/* no-op: registers the extension so Node's resolver accepts it */
|
|
22
|
+
};
|
|
23
|
+
added.push(ext);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
path: NativeModule._resolveFilename(id, opts),
|
|
28
|
+
builtin: false,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
for (const ext of added) {
|
|
33
|
+
delete extensions[ext];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=resolveModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveModule.js","sourceRoot":"","sources":["../../../../packages/postcss-syntax/src/resolveModule.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,aAAa,CAAC;AAGvC,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAEzD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,WAAW,GAA6C,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE;IAChF,IAAI,YAAY,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC;QAC/B,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IACrC,CAAC;IAED,MAAM,UAAU,GAAI,YAAuE,CAAC,WAAW,CAAC;IACxG,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,IAAI,CAAC;QACH,KAAK,MAAM,GAAG,IAAI,gBAAgB,EAAE,CAAC;YACnC,IAAI,CAAC,CAAC,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC;gBACzB,UAAU,CAAC,GAAG,CAAC,GAAG,GAAG,EAAE;oBACrB,kEAAkE;gBACpE,CAAC,CAAC;gBACF,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAClB,CAAC;QACH,CAAC;QAED,OAAO;YACL,IAAI,EACF,YACD,CAAC,gBAAgB,CAAC,EAAE,EAAE,IAAI,CAAC;YAC5B,OAAO,EAAE,KAAK;SACf,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;YACxB,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;AACH,CAAC,CAAC"}
|
package/src/stringify.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const constants_1 = require("./constants");
|
|
5
|
-
const stringify = root => {
|
|
6
|
-
const originalSource = root.raw(constants_1.GRIFFEL_SRC_RAW);
|
|
1
|
+
import { GRIFFEL_SRC_RAW } from './constants.js';
|
|
2
|
+
export const stringify = root => {
|
|
3
|
+
const originalSource = root.raw(GRIFFEL_SRC_RAW);
|
|
7
4
|
if (originalSource) {
|
|
8
5
|
return originalSource;
|
|
9
6
|
}
|
|
10
7
|
// TODO maybe we could generate some default Griffel file with all styles in one slot
|
|
11
8
|
throw new Error('Griffel syntax stringifier can only stringify AST parsed with the custom syntax');
|
|
12
9
|
};
|
|
13
|
-
exports.stringify = stringify;
|
|
14
10
|
//# sourceMappingURL=stringify.js.map
|
package/src/stringify.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stringify.js","sourceRoot":"","sources":["../../../../packages/postcss-syntax/src/stringify.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"stringify.js","sourceRoot":"","sources":["../../../../packages/postcss-syntax/src/stringify.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,MAAM,CAAC,MAAM,SAAS,GAAwB,IAAI,CAAC,EAAE;IACnD,MAAM,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IACjD,IAAI,cAAc,EAAE,CAAC;QACnB,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,qFAAqF;IACrF,MAAM,IAAI,KAAK,CAAC,iFAAiF,CAAC,CAAC;AACrG,CAAC,CAAC"}
|
package/src/location-preset.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { PluginObj, PluginPass, types as t, ConfigAPI } from '@babel/core';
|
|
2
|
-
import type { BabelPluginOptions } from '@griffel/babel-preset';
|
|
3
|
-
export type CommentDirective = [ /** directive *//** directive */ string, /** value */ string];
|
|
4
|
-
export type CommentDirectivesBySlot = Record</** slot */ string, CommentDirective[]>;
|
|
5
|
-
export type CommentDirectivesByHookDeclarator = Record</** hook declarator */ string, CommentDirectivesBySlot>;
|
|
6
|
-
export type LocationsBySlot = Record</** slot */ string, t.SourceLocation>;
|
|
7
|
-
export type LocationsByHookDeclarator = Record</** hook declarator */ string, LocationsBySlot>;
|
|
8
|
-
export type ResetCommentDirectivesByHookDeclarator = Record</** hook declarator */ string, CommentDirective[]>;
|
|
9
|
-
export type ResetLocationsByHookDeclarator = Record</** hook declarator */ string, t.SourceLocation>;
|
|
10
|
-
export interface LocationPluginState extends PluginPass {
|
|
11
|
-
callExpressionLocations?: Record</** hook declarator */ string, t.SourceLocation>;
|
|
12
|
-
locations?: LocationsByHookDeclarator;
|
|
13
|
-
commentDirectives?: CommentDirectivesByHookDeclarator;
|
|
14
|
-
resetCommentDirectives?: ResetCommentDirectivesByHookDeclarator;
|
|
15
|
-
resetLocations?: ResetLocationsByHookDeclarator;
|
|
16
|
-
}
|
|
17
|
-
export interface LocationPluginMetadata {
|
|
18
|
-
callExpressionLocations: Record</** hook declarator */ string, t.SourceLocation>;
|
|
19
|
-
locations: LocationsByHookDeclarator;
|
|
20
|
-
commentDirectives: CommentDirectivesByHookDeclarator;
|
|
21
|
-
resetCommentDirectives: ResetCommentDirectivesByHookDeclarator;
|
|
22
|
-
resetLocations: ResetLocationsByHookDeclarator;
|
|
23
|
-
}
|
|
24
|
-
export type LocationPluginOptions = Pick<BabelPluginOptions, 'modules'>;
|
|
25
|
-
declare const _default: (babel: ConfigAPI, options: LocationPluginOptions) => {
|
|
26
|
-
plugins: (LocationPluginOptions | ((api: object, options: LocationPluginOptions | null | undefined, dirname: string) => PluginObj<LocationPluginState>))[][];
|
|
27
|
-
};
|
|
28
|
-
export default _default;
|
package/src/location-preset.js
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const helper_plugin_utils_1 = require("@babel/helper-plugin-utils");
|
|
4
|
-
/**
|
|
5
|
-
* A plugin that parses Griffel code and returns code locations mapped to respective styles and slots
|
|
6
|
-
*/
|
|
7
|
-
const plugin = (0, helper_plugin_utils_1.declare)((api, options) => {
|
|
8
|
-
api.assertVersion(7);
|
|
9
|
-
const { modules = [
|
|
10
|
-
{ moduleSource: '@griffel/react', importName: 'makeStyles', resetImportName: 'makeResetStyles' },
|
|
11
|
-
{ moduleSource: '@fluentui/react-components', importName: 'makeStyles', resetImportName: 'makeResetStyles' },
|
|
12
|
-
], } = options;
|
|
13
|
-
const functionKinds = modules.map(moduleEntry => {
|
|
14
|
-
var _a;
|
|
15
|
-
return (_a = moduleEntry.importName) !== null && _a !== void 0 ? _a : 'makeStyles';
|
|
16
|
-
});
|
|
17
|
-
const resetFunctionKinds = modules.map(moduleEntry => {
|
|
18
|
-
var _a;
|
|
19
|
-
return (_a = moduleEntry.resetImportName) !== null && _a !== void 0 ? _a : 'makeResetStyles';
|
|
20
|
-
});
|
|
21
|
-
return {
|
|
22
|
-
name: '@griffel/slot-location-plugin',
|
|
23
|
-
pre() {
|
|
24
|
-
this.callExpressionLocations = {};
|
|
25
|
-
this.locations = {};
|
|
26
|
-
this.resetLocations = {};
|
|
27
|
-
this.commentDirectives = {};
|
|
28
|
-
this.resetCommentDirectives = {};
|
|
29
|
-
},
|
|
30
|
-
visitor: {
|
|
31
|
-
Program: {
|
|
32
|
-
exit() {
|
|
33
|
-
Object.assign(this.file.metadata, {
|
|
34
|
-
callExpressionLocations: this.callExpressionLocations,
|
|
35
|
-
locations: this.locations,
|
|
36
|
-
resetLocations: this.resetLocations,
|
|
37
|
-
commentDirectives: this.commentDirectives,
|
|
38
|
-
resetCommentDirectives: this.resetCommentDirectives,
|
|
39
|
-
});
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
43
|
-
CallExpression(path, state) {
|
|
44
|
-
var _a, _b, _c, _d, _e;
|
|
45
|
-
const callee = path.get('callee');
|
|
46
|
-
const declarator = path.findParent(p => p.isVariableDeclarator());
|
|
47
|
-
if (!(declarator === null || declarator === void 0 ? void 0 : declarator.isVariableDeclarator())) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
const id = declarator.get('id');
|
|
51
|
-
const declaratorId = id.isIdentifier() ? id.node.name : 'unknown';
|
|
52
|
-
if (!callee.isIdentifier()) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
// Technically we should check if these function kinds are from Griffel
|
|
56
|
-
// but since we only collect locations, the plugin is idempotent and we
|
|
57
|
-
// it's safe enough to avoid doing that check
|
|
58
|
-
if (functionKinds.includes(callee.node.name)) {
|
|
59
|
-
if (path.node.loc) {
|
|
60
|
-
(_a = state.callExpressionLocations) !== null && _a !== void 0 ? _a : (state.callExpressionLocations = {});
|
|
61
|
-
state.callExpressionLocations[declaratorId] = {
|
|
62
|
-
...path.node.loc,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
const locations = path.get('arguments')[0];
|
|
66
|
-
if (!locations.isObjectExpression()) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
const properties = locations.get('properties');
|
|
70
|
-
properties.forEach(property => {
|
|
71
|
-
var _a, _b, _c, _d;
|
|
72
|
-
var _e, _f;
|
|
73
|
-
if (!property.isObjectProperty()) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
const key = property.get('key');
|
|
77
|
-
if (!key.isIdentifier()) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
if (!property.node.loc) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
(_a = state.locations) !== null && _a !== void 0 ? _a : (state.locations = {});
|
|
84
|
-
(_b = (_e = state.locations)[declaratorId]) !== null && _b !== void 0 ? _b : (_e[declaratorId] = {});
|
|
85
|
-
state.locations[declaratorId][key.node.name] = {
|
|
86
|
-
...property.node.loc,
|
|
87
|
-
};
|
|
88
|
-
const commentDirectives = parseCommentDirectives(property.node.leadingComments);
|
|
89
|
-
if (commentDirectives) {
|
|
90
|
-
(_c = state.commentDirectives) !== null && _c !== void 0 ? _c : (state.commentDirectives = {});
|
|
91
|
-
(_d = (_f = state.commentDirectives)[declaratorId]) !== null && _d !== void 0 ? _d : (_f[declaratorId] = {});
|
|
92
|
-
state.commentDirectives[declaratorId][key.node.name] = commentDirectives;
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
if (resetFunctionKinds.includes(callee.node.name)) {
|
|
97
|
-
if (path.node.loc) {
|
|
98
|
-
(_b = state.callExpressionLocations) !== null && _b !== void 0 ? _b : (state.callExpressionLocations = {});
|
|
99
|
-
state.callExpressionLocations[declaratorId] = {
|
|
100
|
-
...path.node.loc,
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
(_c = state.resetLocations) !== null && _c !== void 0 ? _c : (state.resetLocations = {});
|
|
104
|
-
const resetStyles = path.get('arguments')[0];
|
|
105
|
-
if (!resetStyles.isObjectExpression()) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
if (!resetStyles.node.loc) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
state.resetLocations[declaratorId] = resetStyles.node.loc;
|
|
112
|
-
// For reset styles we only care about the comment directives on the variable declaration
|
|
113
|
-
// The leading commment can either be attached to a variable declaration of an export declaration (i.e. export const useResetStyles = ...)
|
|
114
|
-
const parentDeclaration = (_d = path.findParent(p => p.isExportNamedDeclaration())) !== null && _d !== void 0 ? _d : path.findParent(p => p.isVariableDeclaration());
|
|
115
|
-
if (parentDeclaration) {
|
|
116
|
-
const commentDirectives = parseCommentDirectives(parentDeclaration.node.leadingComments);
|
|
117
|
-
if (commentDirectives) {
|
|
118
|
-
(_e = state.resetCommentDirectives) !== null && _e !== void 0 ? _e : (state.resetCommentDirectives = {});
|
|
119
|
-
state.resetCommentDirectives[declaratorId] = commentDirectives;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
};
|
|
126
|
-
});
|
|
127
|
-
function parseCommentDirectives(leadingComments) {
|
|
128
|
-
if (!leadingComments) {
|
|
129
|
-
return null;
|
|
130
|
-
}
|
|
131
|
-
const entries = leadingComments
|
|
132
|
-
// We don't support comment blocks
|
|
133
|
-
.filter(comment => comment.type === 'CommentLine')
|
|
134
|
-
.map(comment => {
|
|
135
|
-
const commentValue = comment.value.trim();
|
|
136
|
-
if (!commentValue.startsWith('griffel-')) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
const tokens = commentValue.split(' ');
|
|
140
|
-
return [tokens[0], tokens[1]];
|
|
141
|
-
})
|
|
142
|
-
.filter(Boolean);
|
|
143
|
-
return entries;
|
|
144
|
-
}
|
|
145
|
-
exports.default = (babel, options) => {
|
|
146
|
-
return {
|
|
147
|
-
plugins: [[plugin, options]],
|
|
148
|
-
};
|
|
149
|
-
};
|
|
150
|
-
//# sourceMappingURL=location-preset.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"location-preset.js","sourceRoot":"","sources":["../../../../packages/postcss-syntax/src/location-preset.ts"],"names":[],"mappings":";;AACA,oEAAqD;AAkCrD;;GAEG;AACH,MAAM,MAAM,GAAG,IAAA,6BAAO,EAAwD,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE;IAC7F,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAErB,MAAM,EACJ,OAAO,GAAG;QACR,EAAE,YAAY,EAAE,gBAAgB,EAAE,UAAU,EAAE,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE;QAChG,EAAE,YAAY,EAAE,4BAA4B,EAAE,UAAU,EAAE,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE;KAC7G,GACF,GAAG,OAAO,CAAC;IAEZ,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE;;QAC9C,OAAO,MAAA,WAAW,CAAC,UAAU,mC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,CAAC,YAAY,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YACzC,OAAO;QACT,CAAC;QAED,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACvC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAChC,CAAC,CAAC;SACD,MAAM,CAAC,OAAO,CAAuB,CAAC;IAEzC,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,kBAAe,CAAC,KAAgB,EAAE,OAA8B,EAAE,EAAE;IAClE,OAAO;QACL,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC7B,CAAC;AACJ,CAAC,CAAC"}
|
package/src/transform-sync.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { BabelPluginMetadata, BabelPluginOptions } from '@griffel/babel-preset';
|
|
2
|
-
import type { LocationPluginMetadata } from './location-preset';
|
|
3
|
-
export type TransformOptions = {
|
|
4
|
-
filename: string;
|
|
5
|
-
pluginOptions: BabelPluginOptions;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Transforms passed source code with Babel, uses user's config for parsing, but ignores it for transforms.
|
|
9
|
-
*/
|
|
10
|
-
export default function transformSync(sourceCode: string, options: TransformOptions): {
|
|
11
|
-
metadata: BabelPluginMetadata & LocationPluginMetadata;
|
|
12
|
-
code: string | null | undefined;
|
|
13
|
-
};
|
package/src/transform-sync.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = transformSync;
|
|
4
|
-
const Babel = require("@babel/core");
|
|
5
|
-
const babel_preset_1 = require("@griffel/babel-preset");
|
|
6
|
-
const location_preset_1 = require("./location-preset");
|
|
7
|
-
/**
|
|
8
|
-
* Transforms passed source code with Babel, uses user's config for parsing, but ignores it for transforms.
|
|
9
|
-
*/
|
|
10
|
-
function transformSync(sourceCode, options) {
|
|
11
|
-
var _a;
|
|
12
|
-
const { plugins, presets } = (_a = options.pluginOptions.babelOptions) !== null && _a !== void 0 ? _a : { plugins: [], presets: [] };
|
|
13
|
-
const babelFileResult = Babel.transformSync(sourceCode, {
|
|
14
|
-
// Ignore all user's configs and apply only our plugin
|
|
15
|
-
babelrc: false,
|
|
16
|
-
configFile: false,
|
|
17
|
-
plugins,
|
|
18
|
-
presets: [...(presets !== null && presets !== void 0 ? presets : []), [babel_preset_1.default, options.pluginOptions], [location_preset_1.default, options.pluginOptions]],
|
|
19
|
-
filename: options.filename,
|
|
20
|
-
sourceFileName: options.filename,
|
|
21
|
-
});
|
|
22
|
-
if (babelFileResult === null) {
|
|
23
|
-
throw new Error(`Failed to transform "${options.filename}" due unknown Babel error...`);
|
|
24
|
-
}
|
|
25
|
-
return {
|
|
26
|
-
metadata: babelFileResult.metadata,
|
|
27
|
-
code: babelFileResult.code,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=transform-sync.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transform-sync.js","sourceRoot":"","sources":["../../../../packages/postcss-syntax/src/transform-sync.ts"],"names":[],"mappings":";;AAcA,gCAqBC;AAnCD,qCAAqC;AAErC,wDAAkD;AAElD,uDAA+C;AAO/C;;GAEG;AACH,SAAwB,aAAa,CAAC,UAAkB,EAAE,OAAyB;;IACjF,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,MAAA,OAAO,CAAC,aAAa,CAAC,YAAY,mCAAI,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IAChG,MAAM,eAAe,GAAG,KAAK,CAAC,aAAa,CAAC,UAAU,EAAE;QACtD,sDAAsD;QACtD,OAAO,EAAE,KAAK;QACd,UAAU,EAAE,KAAK;QACjB,OAAO;QACP,OAAO,EAAE,CAAC,GAAG,CAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC,EAAE,CAAC,sBAAa,EAAE,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC,yBAAc,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;QAE9G,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,cAAc,EAAE,OAAO,CAAC,QAAQ;KACjC,CAAC,CAAC;IAEH,IAAI,eAAe,KAAK,IAAI,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,wBAAwB,OAAO,CAAC,QAAQ,8BAA8B,CAAC,CAAC;IAC1F,CAAC;IAED,OAAO;QACL,QAAQ,EAAE,eAAe,CAAC,QAAmE;QAC7F,IAAI,EAAE,eAAe,CAAC,IAAI;KAC3B,CAAC;AACJ,CAAC"}
|