@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
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Microsoft Corporation.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@griffel/postcss-syntax",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.13",
|
|
4
4
|
"description": "postcss syntax for Griffel",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -10,8 +10,10 @@
|
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@babel/core": "^7.29.0",
|
|
12
12
|
"@babel/helper-plugin-utils": "^7.28.6",
|
|
13
|
-
"@griffel/babel-preset": "^1.
|
|
13
|
+
"@griffel/babel-preset": "^1.9.0",
|
|
14
14
|
"postcss": "^8.5.14"
|
|
15
15
|
},
|
|
16
|
-
"main": "./src/index.js"
|
|
17
|
-
|
|
16
|
+
"main": "./src/index.js",
|
|
17
|
+
"types": "./src/index.d.ts",
|
|
18
|
+
"type": "commonjs"
|
|
19
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const GRIFFEL_SLOT_RAW = "griffel-slot";
|
|
2
|
+
export declare const GRIFFEL_SRC_RAW = "griffel-src";
|
|
3
|
+
export declare const GRIFFEL_DECLARATOR_RAW = "griffel-declarator";
|
|
4
|
+
export declare const GRIFFEL_SLOT_LOCATION_RAW = "griffel-slot-location";
|
|
5
|
+
export declare const GRIFFEL_DECLARATOR_LOCATION_RAW = "griffel-declarator-location";
|
package/src/constants.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GRIFFEL_DECLARATOR_LOCATION_RAW = exports.GRIFFEL_SLOT_LOCATION_RAW = exports.GRIFFEL_DECLARATOR_RAW = exports.GRIFFEL_SRC_RAW = exports.GRIFFEL_SLOT_RAW = void 0;
|
|
4
|
+
exports.GRIFFEL_SLOT_RAW = 'griffel-slot';
|
|
5
|
+
exports.GRIFFEL_SRC_RAW = 'griffel-src';
|
|
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';
|
|
9
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../packages/postcss-syntax/src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,gBAAgB,GAAG,cAAc,CAAC;AAClC,QAAA,eAAe,GAAG,aAAa,CAAC;AAChC,QAAA,sBAAsB,GAAG,oBAAoB,CAAC;AAC9C,QAAA,yBAAyB,GAAG,uBAAuB,CAAC;AACpD,QAAA,+BAA+B,GAAG,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { BabelPluginOptions } from '@griffel/babel-preset';
|
|
2
|
+
import type * as postcss from 'postcss';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a custom syntax with configured options for @griffel/babel-preset
|
|
5
|
+
* @param options - Options to configure @griffel/babel-preset
|
|
6
|
+
* @returns a postcss custom syntax
|
|
7
|
+
*/
|
|
8
|
+
export declare function createSyntax(options: BabelPluginOptions): postcss.Syntax;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSyntax = createSyntax;
|
|
4
|
+
const parse_1 = require("./parse");
|
|
5
|
+
const stringify_1 = require("./stringify");
|
|
6
|
+
/**
|
|
7
|
+
* Creates a custom syntax with configured options for @griffel/babel-preset
|
|
8
|
+
* @param options - Options to configure @griffel/babel-preset
|
|
9
|
+
* @returns a postcss custom syntax
|
|
10
|
+
*/
|
|
11
|
+
function createSyntax(options) {
|
|
12
|
+
const extendedParse = (css, opts) => (0, parse_1.parse)(css, { ...opts, ...options });
|
|
13
|
+
return {
|
|
14
|
+
stringify: stringify_1.stringify,
|
|
15
|
+
parse: extendedParse,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=createSyntax.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSyntax.js","sourceRoot":"","sources":["../../../../packages/postcss-syntax/src/createSyntax.ts"],"names":[],"mappings":";;AAWA,oCAOC;AAfD,mCAAgC;AAChC,2CAAwC;AAExC;;;;GAIG;AACH,SAAgB,YAAY,CAAC,OAA2B;IACtD,MAAM,aAAa,GAAmB,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,IAAA,aAAK,EAAC,GAAG,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IAEzF,OAAO;QACL,SAAS,EAAT,qBAAS;QACT,KAAK,EAAE,aAAa;KACrB,CAAC;AACJ,CAAC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { parse } from './parse';
|
|
2
2
|
import { stringify } from './stringify';
|
|
3
|
-
|
|
4
3
|
export { parse, stringify };
|
|
5
4
|
export { createSyntax } from './createSyntax';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
declare const _default: {
|
|
6
|
+
parse: (css: string | {
|
|
7
|
+
toString(): string;
|
|
8
|
+
}, opts?: import("./parse").ParserOptions) => import("postcss").Root;
|
|
9
|
+
stringify: import("postcss").Stringifier;
|
|
10
10
|
};
|
|
11
|
-
|
|
11
|
+
export default _default;
|
|
12
12
|
export { GRIFFEL_DECLARATOR_LOCATION_RAW, GRIFFEL_SLOT_LOCATION_RAW } from './constants';
|
package/src/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GRIFFEL_SLOT_LOCATION_RAW = exports.GRIFFEL_DECLARATOR_LOCATION_RAW = exports.createSyntax = exports.stringify = exports.parse = void 0;
|
|
4
|
+
const parse_1 = require("./parse");
|
|
5
|
+
Object.defineProperty(exports, "parse", { enumerable: true, get: function () { return parse_1.parse; } });
|
|
6
|
+
const stringify_1 = require("./stringify");
|
|
7
|
+
Object.defineProperty(exports, "stringify", { enumerable: true, get: function () { return stringify_1.stringify; } });
|
|
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,
|
|
13
|
+
};
|
|
14
|
+
var constants_1 = require("./constants");
|
|
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; } });
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/postcss-syntax/src/index.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAGvB,sFAHA,aAAK,OAGA;AAFd,2CAAwC;AAExB,0FAFP,qBAAS,OAEO;AACzB,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AAErB,kBAAe;IACb,KAAK,EAAL,aAAK;IACL,SAAS,EAAT,qBAAS;CACV,CAAC;AAEF,yCAAyF;AAAhF,4HAAA,+BAA+B,OAAA;AAAE,sHAAA,yBAAyB,OAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
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;
|
|
@@ -0,0 +1,150 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,mCAAI,YAAY,CAAC;IAChD,CAAC,CAAC,CAAC;IAEH,MAAM,kBAAkB,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE;;QACnD,OAAO,MAAA,WAAW,CAAC,eAAe,mCAAI,iBAAiB,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,IAAI,EAAE,+BAA+B;QAErC,GAAG;YACD,IAAI,CAAC,uBAAuB,GAAG,EAAE,CAAC;YAClC,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;YACpB,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;YACzB,IAAI,CAAC,iBAAiB,GAAG,EAAE,CAAC;YAC5B,IAAI,CAAC,sBAAsB,GAAG,EAAE,CAAC;QACnC,CAAC;QAED,OAAO,EAAE;YACP,OAAO,EAAE;gBACP,IAA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@
|
|
|
1
|
+
import * as postcss from 'postcss';
|
|
2
|
+
import type { BabelPluginOptions } from '@griffel/babel-preset';
|
|
3
|
+
export type PostCSSParserOptions = Pick<postcss.ProcessOptions<postcss.Document | postcss.Root>, 'from' | 'map'>;
|
|
4
|
+
export interface ParserOptions extends Pick<PostCSSParserOptions, 'from'>, BabelPluginOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Throws error when griffel parsing fails
|
|
7
|
+
* @default false
|
|
8
|
+
*/
|
|
9
|
+
silenceParseErrors?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Generates CSS rules from a JavaScript file. Each slot in `makeStyles` and each `makeResetStyles` will be one line in the output.
|
|
13
|
+
* 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.
|
|
14
|
+
*/
|
|
15
|
+
export declare const parse: (css: string | {
|
|
16
|
+
toString(): string;
|
|
17
|
+
}, opts?: ParserOptions) => postcss.Root;
|
package/src/parse.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parse = void 0;
|
|
4
|
+
const postcss = require("postcss");
|
|
5
|
+
const transform_sync_1 = require("./transform-sync");
|
|
6
|
+
const constants_1 = require("./constants");
|
|
7
|
+
const os = require("os");
|
|
8
|
+
/**
|
|
9
|
+
* Generates CSS rules from a JavaScript file. Each slot in `makeStyles` and each `makeResetStyles` will be one line in the output.
|
|
10
|
+
* 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
|
+
*/
|
|
12
|
+
const parse = (css, opts) => {
|
|
13
|
+
const { from: filename = 'postcss-syntax.styles.ts', silenceParseErrors = false } = opts !== null && opts !== void 0 ? opts : {};
|
|
14
|
+
const griffelPluginOptions = extractGriffelBabelPluginOptions(opts);
|
|
15
|
+
const code = css.toString();
|
|
16
|
+
const cssRuleSlotNames = [];
|
|
17
|
+
const cssRules = [];
|
|
18
|
+
const parseResult = parseGriffelStyles(code, filename, griffelPluginOptions, silenceParseErrors);
|
|
19
|
+
if (!parseResult) {
|
|
20
|
+
const root = postcss.parse(`/* Failed to parse griffel styles: ${filename} */`, { from: filename });
|
|
21
|
+
root.raws[constants_1.GRIFFEL_SRC_RAW] = code;
|
|
22
|
+
return root;
|
|
23
|
+
}
|
|
24
|
+
const { cssEntries, cssResetEntries, callExpressionLocations, resetLocations, locations, commentDirectives, resetCommentDirectives, } = parseResult;
|
|
25
|
+
Object.entries(cssEntries).forEach(([declarator, slots]) => {
|
|
26
|
+
Object.entries(slots).forEach(([slot, rules]) => {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
cssRuleSlotNames.push(`${declarator} ${slot}`);
|
|
29
|
+
let cssRule = rules.join('').replace(new RegExp(os.EOL, 'g'), ' ');
|
|
30
|
+
const ignoredRules = getIgnoredRulesFromDirectives((_b = (_a = commentDirectives[declarator]) === null || _a === void 0 ? void 0 : _a[slot]) !== null && _b !== void 0 ? _b : []);
|
|
31
|
+
if (ignoredRules.length) {
|
|
32
|
+
const stylelintIgnore = `/* stylelint-disable-line ${ignoredRules.join(',')} */`;
|
|
33
|
+
cssRule = `${cssRule} ${stylelintIgnore}`;
|
|
34
|
+
}
|
|
35
|
+
cssRules.push(cssRule);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
Object.entries(cssResetEntries).forEach(([declarator, resetRules]) => {
|
|
39
|
+
var _a;
|
|
40
|
+
cssRuleSlotNames.push(`${declarator}`);
|
|
41
|
+
const ignoredRules = getIgnoredRulesFromDirectives((_a = resetCommentDirectives[declarator]) !== null && _a !== void 0 ? _a : []);
|
|
42
|
+
let cssRule = resetRules.join('').replace(new RegExp(os.EOL, 'g'), ' ');
|
|
43
|
+
if (ignoredRules.length) {
|
|
44
|
+
const stylelintIgnore = `/* stylelint-disable-line ${ignoredRules.join(',')} */`;
|
|
45
|
+
cssRule = `${cssRule} ${stylelintIgnore}`;
|
|
46
|
+
}
|
|
47
|
+
cssRules.push(cssRule);
|
|
48
|
+
});
|
|
49
|
+
const root = postcss.parse(cssRules.join('\n'), { from: filename });
|
|
50
|
+
root.walk(node => {
|
|
51
|
+
var _a, _b, _c;
|
|
52
|
+
if (!node.source || node.source.start === undefined) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const [declarator, slot] = cssRuleSlotNames[node.source.start.line - 1].split(' ');
|
|
56
|
+
node.raws[constants_1.GRIFFEL_DECLARATOR_RAW] = declarator;
|
|
57
|
+
if (slot) {
|
|
58
|
+
node.raws[constants_1.GRIFFEL_SLOT_RAW] = slot;
|
|
59
|
+
node.raws[constants_1.GRIFFEL_SLOT_LOCATION_RAW] = (_b = (_a = locations[declarator]) === null || _a === void 0 ? void 0 : _a[slot]) !== null && _b !== void 0 ? _b : callExpressionLocations[declarator];
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
node.raws[constants_1.GRIFFEL_DECLARATOR_LOCATION_RAW] = (_c = resetLocations[declarator]) !== null && _c !== void 0 ? _c : callExpressionLocations[declarator];
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
root.raws[constants_1.GRIFFEL_SRC_RAW] = css;
|
|
66
|
+
return root;
|
|
67
|
+
};
|
|
68
|
+
exports.parse = parse;
|
|
69
|
+
function parseGriffelStyles(code, filename, pluginOpts, silenceParseErrors) {
|
|
70
|
+
try {
|
|
71
|
+
const { metadata } = (0, transform_sync_1.default)(code, {
|
|
72
|
+
filename,
|
|
73
|
+
pluginOptions: {
|
|
74
|
+
...pluginOpts,
|
|
75
|
+
generateMetadata: true,
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
return metadata;
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
// eslint-disable-next-line no-console
|
|
82
|
+
console.warn('Failed to parse Griffel styles');
|
|
83
|
+
// eslint-disable-next-line no-console
|
|
84
|
+
console.warn(error);
|
|
85
|
+
if (silenceParseErrors) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function getIgnoredRulesFromDirectives(commentDirectives) {
|
|
92
|
+
return commentDirectives
|
|
93
|
+
.filter(([directive]) => directive === 'griffel-csslint-disable')
|
|
94
|
+
.map(([_, rulename]) => rulename);
|
|
95
|
+
}
|
|
96
|
+
const extractGriffelBabelPluginOptions = (opts = {}) => {
|
|
97
|
+
const { babelOptions, evaluationRules, generateMetadata, modules } = opts;
|
|
98
|
+
const babelPluginOptions = {};
|
|
99
|
+
if (babelOptions) {
|
|
100
|
+
babelPluginOptions.babelOptions = babelOptions;
|
|
101
|
+
}
|
|
102
|
+
if (evaluationRules) {
|
|
103
|
+
babelPluginOptions.evaluationRules = evaluationRules;
|
|
104
|
+
}
|
|
105
|
+
if (generateMetadata) {
|
|
106
|
+
babelPluginOptions.generateMetadata = generateMetadata;
|
|
107
|
+
}
|
|
108
|
+
if (modules) {
|
|
109
|
+
babelPluginOptions.modules = modules;
|
|
110
|
+
}
|
|
111
|
+
return babelPluginOptions;
|
|
112
|
+
};
|
|
113
|
+
//# sourceMappingURL=parse.js.map
|
package/src/parse.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../../../packages/postcss-syntax/src/parse.ts"],"names":[],"mappings":";;;AAAA,mCAAmC;AACnC,qDAA6C;AAC7C,2CAMqB;AAGrB,yBAAyB;AAYzB;;;GAGG;AACI,MAAM,KAAK,GAAG,CAAC,GAAoC,EAAE,IAAoB,EAAE,EAAE;IAClF,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,0BAA0B,EAAE,kBAAkB,GAAG,KAAK,EAAE,GAAG,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,EAAE,CAAC;IAC/F,MAAM,oBAAoB,GAAG,gCAAgC,CAAC,IAAI,CAAC,CAAC;IACpE,MAAM,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AC;YACvB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,6BAA6B,CAAC,iBAAqC;IAC1E,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,gCAAgC,GAAG,CAAC,OAAsB,EAAE,EAAE,EAAE;IACpE,MAAM,EAAE,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAC1E,MAAM,kBAAkB,GAAuB,EAAE,CAAC;IAClD,IAAI,YAAY,EAAE,CAAC;QACjB,kBAAkB,CAAC,YAAY,GAAG,YAAY,CAAC;IACjD,CAAC;IAED,IAAI,eAAe,EAAE,CAAC;QACpB,kBAAkB,CAAC,eAAe,GAAG,eAAe,CAAC;IACvD,CAAC;IAED,IAAI,gBAAgB,EAAE,CAAC;QACrB,kBAAkB,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;IACzD,CAAC;IAED,IAAI,OAAO,EAAE,CAAC;QACZ,kBAAkB,CAAC,OAAO,GAAG,OAAO,CAAC;IACvC,CAAC;IAED,OAAO,kBAAkB,CAAC;AAC5B,CAAC,CAAC"}
|
package/src/stringify.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringify = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const stringify = root => {
|
|
6
|
+
const originalSource = root.raw(constants_1.GRIFFEL_SRC_RAW);
|
|
7
|
+
if (originalSource) {
|
|
8
|
+
return originalSource;
|
|
9
|
+
}
|
|
10
|
+
// TODO maybe we could generate some default Griffel file with all styles in one slot
|
|
11
|
+
throw new Error('Griffel syntax stringifier can only stringify AST parsed with the custom syntax');
|
|
12
|
+
};
|
|
13
|
+
exports.stringify = stringify;
|
|
14
|
+
//# sourceMappingURL=stringify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stringify.js","sourceRoot":"","sources":["../../../../packages/postcss-syntax/src/stringify.ts"],"names":[],"mappings":";;;AACA,2CAA8C;AAEvC,MAAM,SAAS,GAAwB,IAAI,CAAC,EAAE;IACnD,MAAM,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,2BAAe,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;AARW,QAAA,SAAS,aAQpB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
package/.babelrc
DELETED