@griffel/postcss-syntax 1.3.11 → 1.3.13
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/LICENSE.md +21 -0
- package/package.json +6 -4
- package/src/constants.d.ts +5 -0
- package/src/constants.js +9 -0
- package/src/constants.js.map +1 -0
- package/src/createSyntax.d.ts +8 -0
- package/src/createSyntax.js +18 -0
- package/src/createSyntax.js.map +1 -0
- package/src/{index.ts → index.d.ts} +6 -6
- package/src/index.js +17 -0
- package/src/index.js.map +1 -0
- package/src/location-preset.d.ts +28 -0
- package/src/location-preset.js +150 -0
- package/src/location-preset.js.map +1 -0
- package/src/parse.d.ts +17 -0
- package/src/parse.js +113 -0
- package/src/parse.js.map +1 -0
- package/src/stringify.d.ts +2 -0
- package/src/stringify.js +14 -0
- package/src/stringify.js.map +1 -0
- package/src/transform-sync.d.ts +13 -0
- package/src/transform-sync.js +30 -0
- package/src/transform-sync.js.map +1 -0
- package/.babelrc +0 -3
- package/CHANGELOG.json +0 -618
- package/CHANGELOG.md +0 -263
- package/eslint.config.mjs +0 -18
- package/project.json +0 -51
- package/src/constants.ts +0 -5
- package/src/createSyntax.ts +0 -19
- package/src/location-preset.ts +0 -206
- package/src/parse.test.ts +0 -501
- package/src/parse.ts +0 -155
- package/src/stringify.ts +0 -12
- package/src/transform-sync.test.ts +0 -300
- package/src/transform-sync.ts +0 -36
- package/tsconfig.json +0 -16
- package/tsconfig.lib.json +0 -11
- package/tsconfig.spec.json +0 -20
- package/vitest.config.mts +0 -18
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import transformSync, { type TransformOptions } from './transform-sync';
|
|
4
|
-
|
|
5
|
-
describe('transformSync', () => {
|
|
6
|
-
it('should parse TS and return metadata that contains css location', () => {
|
|
7
|
-
const sourceCode = `
|
|
8
|
-
import type { GriffelStyle } from '@griffel/react'
|
|
9
|
-
import { makeStyles } from '@griffel/react';
|
|
10
|
-
|
|
11
|
-
const mixin = (): GriffelStyle => ({
|
|
12
|
-
marginTop: '4px',
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
export const useStyles = makeStyles({
|
|
16
|
-
root: {
|
|
17
|
-
color: 'red',
|
|
18
|
-
backgroundColor: 'green',
|
|
19
|
-
...mixin()
|
|
20
|
-
}
|
|
21
|
-
})
|
|
22
|
-
`;
|
|
23
|
-
const options: TransformOptions = {
|
|
24
|
-
filename: 'test.styles.ts',
|
|
25
|
-
pluginOptions: {
|
|
26
|
-
babelOptions: {
|
|
27
|
-
presets: ['@babel/preset-typescript'],
|
|
28
|
-
},
|
|
29
|
-
generateMetadata: true,
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const result = transformSync(sourceCode, options);
|
|
34
|
-
|
|
35
|
-
expect(result.metadata.cssEntries).toMatchInlineSnapshot(`
|
|
36
|
-
{
|
|
37
|
-
"useStyles": {
|
|
38
|
-
"root": [
|
|
39
|
-
".fe3e8s9{color:red;}",
|
|
40
|
-
".fcnqdeg{background-color:green;}",
|
|
41
|
-
".fvjh0tl{margin-top:4px;}",
|
|
42
|
-
],
|
|
43
|
-
},
|
|
44
|
-
}
|
|
45
|
-
`);
|
|
46
|
-
expect(result.metadata.locations).toMatchInlineSnapshot(`
|
|
47
|
-
{
|
|
48
|
-
"useStyles": {
|
|
49
|
-
"root": {
|
|
50
|
-
"end": Position {
|
|
51
|
-
"column": 7,
|
|
52
|
-
"index": 317,
|
|
53
|
-
"line": 14,
|
|
54
|
-
},
|
|
55
|
-
"filename": undefined,
|
|
56
|
-
"identifierName": undefined,
|
|
57
|
-
"start": Position {
|
|
58
|
-
"column": 6,
|
|
59
|
-
"index": 227,
|
|
60
|
-
"line": 10,
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
}
|
|
65
|
-
`);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('should parse TS and return comment directives prefixed with griffel-', () => {
|
|
69
|
-
const sourceCode = `
|
|
70
|
-
import type { GriffelStyle } from '@griffel/react'
|
|
71
|
-
import { makeStyles, makeResetStyles } from '@griffel/react';
|
|
72
|
-
|
|
73
|
-
export const useStyles = makeStyles({
|
|
74
|
-
// griffel-csslint-disable foo
|
|
75
|
-
// griffel-csslint-disable bar
|
|
76
|
-
root: {
|
|
77
|
-
color: 'red',
|
|
78
|
-
backgroundColor: 'green',
|
|
79
|
-
},
|
|
80
|
-
|
|
81
|
-
// griffel-csslint-disable foo
|
|
82
|
-
foo: {
|
|
83
|
-
color: 'blue'
|
|
84
|
-
}
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
// griffel-csslint-disable foo
|
|
88
|
-
export const useResetStyles = makeResetStyles({
|
|
89
|
-
color: 'red',
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
// griffel-csslint-disable foo
|
|
93
|
-
// griffel-csslint-disable bar
|
|
94
|
-
const useResetStylesExportedLater = makeResetStyles({
|
|
95
|
-
color: 'red',
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
export { useResetStylesExportedLater };
|
|
99
|
-
`;
|
|
100
|
-
|
|
101
|
-
const options: TransformOptions = {
|
|
102
|
-
filename: 'test.styles.ts',
|
|
103
|
-
pluginOptions: {
|
|
104
|
-
babelOptions: {
|
|
105
|
-
presets: ['@babel/preset-typescript'],
|
|
106
|
-
},
|
|
107
|
-
generateMetadata: true,
|
|
108
|
-
},
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
const result = transformSync(sourceCode, options);
|
|
112
|
-
|
|
113
|
-
expect(result.metadata.commentDirectives).toMatchInlineSnapshot(`
|
|
114
|
-
{
|
|
115
|
-
"useStyles": {
|
|
116
|
-
"foo": [
|
|
117
|
-
[
|
|
118
|
-
"griffel-csslint-disable",
|
|
119
|
-
"foo",
|
|
120
|
-
],
|
|
121
|
-
],
|
|
122
|
-
"root": [
|
|
123
|
-
[
|
|
124
|
-
"griffel-csslint-disable",
|
|
125
|
-
"foo",
|
|
126
|
-
],
|
|
127
|
-
[
|
|
128
|
-
"griffel-csslint-disable",
|
|
129
|
-
"bar",
|
|
130
|
-
],
|
|
131
|
-
],
|
|
132
|
-
},
|
|
133
|
-
}
|
|
134
|
-
`);
|
|
135
|
-
|
|
136
|
-
expect(result.metadata.resetCommentDirectives).toMatchInlineSnapshot(`
|
|
137
|
-
{
|
|
138
|
-
"useResetStyles": [
|
|
139
|
-
[
|
|
140
|
-
"griffel-csslint-disable",
|
|
141
|
-
"foo",
|
|
142
|
-
],
|
|
143
|
-
],
|
|
144
|
-
"useResetStylesExportedLater": [
|
|
145
|
-
[
|
|
146
|
-
"griffel-csslint-disable",
|
|
147
|
-
"foo",
|
|
148
|
-
],
|
|
149
|
-
[
|
|
150
|
-
"griffel-csslint-disable",
|
|
151
|
-
"bar",
|
|
152
|
-
],
|
|
153
|
-
],
|
|
154
|
-
}
|
|
155
|
-
`);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it('should return location of makeStyles call expression', () => {
|
|
159
|
-
const sourceCode = `
|
|
160
|
-
import type { GriffelStyle } from "@griffel/react";
|
|
161
|
-
import { makeStyles } from "@griffel/react";
|
|
162
|
-
|
|
163
|
-
const mixin = (): GriffelStyle => ({
|
|
164
|
-
marginTop: "4px",
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
const styles = {
|
|
168
|
-
root: {
|
|
169
|
-
color: "red",
|
|
170
|
-
backgroundColor: "green",
|
|
171
|
-
...mixin(),
|
|
172
|
-
},
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
export const useStyles1 = makeStyles(styles);
|
|
176
|
-
export const useStyles2 = makeStyles(styles);
|
|
177
|
-
`;
|
|
178
|
-
const options: TransformOptions = {
|
|
179
|
-
filename: 'test.styles.ts',
|
|
180
|
-
pluginOptions: {
|
|
181
|
-
babelOptions: {
|
|
182
|
-
presets: ['@babel/preset-typescript'],
|
|
183
|
-
},
|
|
184
|
-
generateMetadata: true,
|
|
185
|
-
},
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
const result = transformSync(sourceCode, options);
|
|
189
|
-
|
|
190
|
-
expect(result.metadata.cssEntries).toMatchInlineSnapshot(`
|
|
191
|
-
{
|
|
192
|
-
"useStyles1": {
|
|
193
|
-
"root": [
|
|
194
|
-
".fe3e8s9{color:red;}",
|
|
195
|
-
".fcnqdeg{background-color:green;}",
|
|
196
|
-
".fvjh0tl{margin-top:4px;}",
|
|
197
|
-
],
|
|
198
|
-
},
|
|
199
|
-
"useStyles2": {
|
|
200
|
-
"root": [
|
|
201
|
-
".fe3e8s9{color:red;}",
|
|
202
|
-
".fcnqdeg{background-color:green;}",
|
|
203
|
-
".fvjh0tl{margin-top:4px;}",
|
|
204
|
-
],
|
|
205
|
-
},
|
|
206
|
-
}
|
|
207
|
-
`);
|
|
208
|
-
expect(result.metadata.callExpressionLocations).toEqual({
|
|
209
|
-
useStyles1: {
|
|
210
|
-
end: {
|
|
211
|
-
column: 50,
|
|
212
|
-
index: 383,
|
|
213
|
-
line: 17,
|
|
214
|
-
},
|
|
215
|
-
start: {
|
|
216
|
-
column: 32,
|
|
217
|
-
index: 365,
|
|
218
|
-
line: 17,
|
|
219
|
-
},
|
|
220
|
-
},
|
|
221
|
-
useStyles2: {
|
|
222
|
-
end: {
|
|
223
|
-
column: 50,
|
|
224
|
-
index: 435,
|
|
225
|
-
line: 18,
|
|
226
|
-
},
|
|
227
|
-
start: {
|
|
228
|
-
column: 32,
|
|
229
|
-
index: 417,
|
|
230
|
-
line: 18,
|
|
231
|
-
},
|
|
232
|
-
},
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
it('should return location of makeResetStyles call expression', () => {
|
|
237
|
-
const sourceCode = `
|
|
238
|
-
import type { GriffelStyle } from "@griffel/react";
|
|
239
|
-
import { makeResetStyles } from "@griffel/react";
|
|
240
|
-
const mixin = (): GriffelStyle => ({
|
|
241
|
-
marginTop: "4px",
|
|
242
|
-
});
|
|
243
|
-
const styles = {
|
|
244
|
-
color: "red",
|
|
245
|
-
backgroundColor: "green",
|
|
246
|
-
...mixin(),
|
|
247
|
-
};
|
|
248
|
-
export const useResetStyles1 = makeResetStyles(styles);
|
|
249
|
-
export const useResetStyles2 = makeResetStyles(styles);
|
|
250
|
-
`;
|
|
251
|
-
const options: TransformOptions = {
|
|
252
|
-
filename: 'test.styles.ts',
|
|
253
|
-
pluginOptions: {
|
|
254
|
-
babelOptions: {
|
|
255
|
-
presets: ['@babel/preset-typescript'],
|
|
256
|
-
},
|
|
257
|
-
generateMetadata: true,
|
|
258
|
-
},
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
const result = transformSync(sourceCode, options);
|
|
262
|
-
|
|
263
|
-
expect(result.metadata.cssResetEntries).toMatchInlineSnapshot(`
|
|
264
|
-
{
|
|
265
|
-
"useResetStyles1": [
|
|
266
|
-
".rv6h41g{color:red;background-color:green;margin-top:4px;}",
|
|
267
|
-
],
|
|
268
|
-
"useResetStyles2": [
|
|
269
|
-
".rv6h41g{color:red;background-color:green;margin-top:4px;}",
|
|
270
|
-
],
|
|
271
|
-
}
|
|
272
|
-
`);
|
|
273
|
-
expect(result.metadata.callExpressionLocations).toEqual({
|
|
274
|
-
useResetStyles1: {
|
|
275
|
-
end: {
|
|
276
|
-
column: 60,
|
|
277
|
-
index: 362,
|
|
278
|
-
line: 12,
|
|
279
|
-
},
|
|
280
|
-
start: {
|
|
281
|
-
column: 37,
|
|
282
|
-
index: 339,
|
|
283
|
-
line: 12,
|
|
284
|
-
},
|
|
285
|
-
},
|
|
286
|
-
useResetStyles2: {
|
|
287
|
-
end: {
|
|
288
|
-
column: 60,
|
|
289
|
-
index: 424,
|
|
290
|
-
line: 13,
|
|
291
|
-
},
|
|
292
|
-
start: {
|
|
293
|
-
column: 37,
|
|
294
|
-
index: 401,
|
|
295
|
-
line: 13,
|
|
296
|
-
},
|
|
297
|
-
},
|
|
298
|
-
});
|
|
299
|
-
});
|
|
300
|
-
});
|
package/src/transform-sync.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import * as Babel from '@babel/core';
|
|
2
|
-
import type { BabelPluginMetadata, BabelPluginOptions } from '@griffel/babel-preset';
|
|
3
|
-
import griffelPreset from '@griffel/babel-preset';
|
|
4
|
-
import type { LocationPluginMetadata } from './location-preset';
|
|
5
|
-
import locationPreset from './location-preset';
|
|
6
|
-
|
|
7
|
-
export type TransformOptions = {
|
|
8
|
-
filename: string;
|
|
9
|
-
pluginOptions: BabelPluginOptions;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Transforms passed source code with Babel, uses user's config for parsing, but ignores it for transforms.
|
|
14
|
-
*/
|
|
15
|
-
export default function transformSync(sourceCode: string, options: TransformOptions) {
|
|
16
|
-
const { plugins, presets } = options.pluginOptions.babelOptions ?? { plugins: [], presets: [] };
|
|
17
|
-
const babelFileResult = Babel.transformSync(sourceCode, {
|
|
18
|
-
// Ignore all user's configs and apply only our plugin
|
|
19
|
-
babelrc: false,
|
|
20
|
-
configFile: false,
|
|
21
|
-
plugins,
|
|
22
|
-
presets: [...(presets ?? []), [griffelPreset, options.pluginOptions], [locationPreset, options.pluginOptions]],
|
|
23
|
-
|
|
24
|
-
filename: options.filename,
|
|
25
|
-
sourceFileName: options.filename,
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
if (babelFileResult === null) {
|
|
29
|
-
throw new Error(`Failed to transform "${options.filename}" due unknown Babel error...`);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return {
|
|
33
|
-
metadata: babelFileResult.metadata as unknown as BabelPluginMetadata & LocationPluginMetadata,
|
|
34
|
-
code: babelFileResult.code,
|
|
35
|
-
};
|
|
36
|
-
}
|
package/tsconfig.json
DELETED
package/tsconfig.lib.json
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"outDir": "../../dist/out-tsc",
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"types": ["node", "environment"]
|
|
8
|
-
},
|
|
9
|
-
"exclude": ["**/*.spec.ts", "**/*.test.ts", "jest.config.ts"],
|
|
10
|
-
"include": ["**/*.ts"]
|
|
11
|
-
}
|
package/tsconfig.spec.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "../../dist/out-tsc",
|
|
5
|
-
"typeRoots": ["../../node_modules", "../../node_modules/@types", "../../typings"],
|
|
6
|
-
"types": ["vitest/importMeta", "vite/client", "node", "vitest", "environment"]
|
|
7
|
-
},
|
|
8
|
-
"include": [
|
|
9
|
-
"vitest.config.mts",
|
|
10
|
-
"**/*.test.ts",
|
|
11
|
-
"**/*.spec.ts",
|
|
12
|
-
"**/*.test.tsx",
|
|
13
|
-
"**/*.spec.tsx",
|
|
14
|
-
"**/*.test.js",
|
|
15
|
-
"**/*.spec.js",
|
|
16
|
-
"**/*.test.jsx",
|
|
17
|
-
"**/*.spec.jsx",
|
|
18
|
-
"**/*.d.ts"
|
|
19
|
-
]
|
|
20
|
-
}
|
package/vitest.config.mts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'vitest/config';
|
|
2
|
-
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
|
|
3
|
-
|
|
4
|
-
export default defineConfig({
|
|
5
|
-
root: __dirname,
|
|
6
|
-
cacheDir: '../../node_modules/.vite/packages/postcss-syntax',
|
|
7
|
-
plugins: [nxViteTsPaths()],
|
|
8
|
-
test: {
|
|
9
|
-
watch: false,
|
|
10
|
-
environment: 'node',
|
|
11
|
-
include: ['{src,tests}/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
|
12
|
-
reporters: ['default'],
|
|
13
|
-
coverage: {
|
|
14
|
-
reportsDirectory: '../../coverage/packages/postcss-syntax',
|
|
15
|
-
provider: 'v8',
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
});
|