@griffel/postcss-syntax 1.3.10 → 1.3.11
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/.babelrc +3 -0
- package/CHANGELOG.json +618 -0
- package/CHANGELOG.md +263 -0
- package/eslint.config.mjs +18 -0
- package/package.json +5 -7
- package/project.json +51 -0
- package/src/constants.ts +5 -0
- package/src/createSyntax.ts +19 -0
- package/src/{index.d.ts → index.ts} +6 -6
- package/src/location-preset.ts +206 -0
- package/src/parse.test.ts +501 -0
- package/src/parse.ts +155 -0
- package/src/stringify.ts +12 -0
- package/src/transform-sync.test.ts +300 -0
- package/src/transform-sync.ts +36 -0
- package/tsconfig.json +16 -0
- package/tsconfig.lib.json +11 -0
- package/tsconfig.spec.json +20 -0
- package/vitest.config.mts +18 -0
- package/LICENSE.md +0 -21
- package/src/constants.d.ts +0 -5
- package/src/constants.js +0 -9
- package/src/constants.js.map +0 -1
- package/src/createSyntax.d.ts +0 -8
- package/src/createSyntax.js +0 -18
- package/src/createSyntax.js.map +0 -1
- package/src/index.js +0 -17
- package/src/index.js.map +0 -1
- package/src/location-preset.d.ts +0 -28
- package/src/location-preset.js +0 -149
- package/src/location-preset.js.map +0 -1
- package/src/parse.d.ts +0 -17
- package/src/parse.js +0 -112
- package/src/parse.js.map +0 -1
- package/src/stringify.d.ts +0 -2
- package/src/stringify.js +0 -14
- package/src/stringify.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/src/location-preset.js
DELETED
|
@@ -1,149 +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
|
-
CallExpression(path, state) {
|
|
43
|
-
var _a, _b, _c, _d, _e;
|
|
44
|
-
const callee = path.get('callee');
|
|
45
|
-
const declarator = path.findParent(p => p.isVariableDeclarator());
|
|
46
|
-
if (!(declarator === null || declarator === void 0 ? void 0 : declarator.isVariableDeclarator())) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
const id = declarator.get('id');
|
|
50
|
-
const declaratorId = id.isIdentifier() ? id.node.name : 'unknown';
|
|
51
|
-
if (!callee.isIdentifier()) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
// Technically we should check if these function kinds are from Griffel
|
|
55
|
-
// but since we only collect locations, the plugin is idempotent and we
|
|
56
|
-
// it's safe enough to avoid doing that check
|
|
57
|
-
if (functionKinds.includes(callee.node.name)) {
|
|
58
|
-
if (path.node.loc) {
|
|
59
|
-
(_a = state.callExpressionLocations) !== null && _a !== void 0 ? _a : (state.callExpressionLocations = {});
|
|
60
|
-
state.callExpressionLocations[declaratorId] = {
|
|
61
|
-
...path.node.loc,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
const locations = path.get('arguments')[0];
|
|
65
|
-
if (!locations.isObjectExpression()) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
const properties = locations.get('properties');
|
|
69
|
-
properties.forEach(property => {
|
|
70
|
-
var _a, _b, _c, _d;
|
|
71
|
-
var _e, _f;
|
|
72
|
-
if (!property.isObjectProperty()) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
const key = property.get('key');
|
|
76
|
-
if (!key.isIdentifier()) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
if (!property.node.loc) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
(_a = state.locations) !== null && _a !== void 0 ? _a : (state.locations = {});
|
|
83
|
-
(_b = (_e = state.locations)[declaratorId]) !== null && _b !== void 0 ? _b : (_e[declaratorId] = {});
|
|
84
|
-
state.locations[declaratorId][key.node.name] = {
|
|
85
|
-
...property.node.loc,
|
|
86
|
-
};
|
|
87
|
-
const commentDirectives = parseCommentDirectives(property.node.leadingComments);
|
|
88
|
-
if (commentDirectives) {
|
|
89
|
-
(_c = state.commentDirectives) !== null && _c !== void 0 ? _c : (state.commentDirectives = {});
|
|
90
|
-
(_d = (_f = state.commentDirectives)[declaratorId]) !== null && _d !== void 0 ? _d : (_f[declaratorId] = {});
|
|
91
|
-
state.commentDirectives[declaratorId][key.node.name] = commentDirectives;
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
if (resetFunctionKinds.includes(callee.node.name)) {
|
|
96
|
-
if (path.node.loc) {
|
|
97
|
-
(_b = state.callExpressionLocations) !== null && _b !== void 0 ? _b : (state.callExpressionLocations = {});
|
|
98
|
-
state.callExpressionLocations[declaratorId] = {
|
|
99
|
-
...path.node.loc,
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
(_c = state.resetLocations) !== null && _c !== void 0 ? _c : (state.resetLocations = {});
|
|
103
|
-
const resetStyles = path.get('arguments')[0];
|
|
104
|
-
if (!resetStyles.isObjectExpression()) {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
if (!resetStyles.node.loc) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
state.resetLocations[declaratorId] = resetStyles.node.loc;
|
|
111
|
-
// For reset styles we only care about the comment directives on the variable declaration
|
|
112
|
-
// The leading commment can either be attached to a variable declaration of an export declaration (i.e. export const useResetStyles = ...)
|
|
113
|
-
const parentDeclaration = (_d = path.findParent(p => p.isExportNamedDeclaration())) !== null && _d !== void 0 ? _d : path.findParent(p => p.isVariableDeclaration());
|
|
114
|
-
if (parentDeclaration) {
|
|
115
|
-
const commentDirectives = parseCommentDirectives(parentDeclaration.node.leadingComments);
|
|
116
|
-
if (commentDirectives) {
|
|
117
|
-
(_e = state.resetCommentDirectives) !== null && _e !== void 0 ? _e : (state.resetCommentDirectives = {});
|
|
118
|
-
state.resetCommentDirectives[declaratorId] = commentDirectives;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
},
|
|
123
|
-
},
|
|
124
|
-
};
|
|
125
|
-
});
|
|
126
|
-
function parseCommentDirectives(leadingComments) {
|
|
127
|
-
if (!leadingComments) {
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
|
-
const entries = leadingComments
|
|
131
|
-
// We don't support comment blocks
|
|
132
|
-
.filter(comment => comment.type === 'CommentLine')
|
|
133
|
-
.map(comment => {
|
|
134
|
-
const commentValue = comment.value.trim();
|
|
135
|
-
if (!commentValue.startsWith('griffel-')) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
const tokens = commentValue.split(' ');
|
|
139
|
-
return [tokens[0], tokens[1]];
|
|
140
|
-
})
|
|
141
|
-
.filter(Boolean);
|
|
142
|
-
return entries;
|
|
143
|
-
}
|
|
144
|
-
exports.default = (babel, options) => {
|
|
145
|
-
return {
|
|
146
|
-
plugins: [[plugin, options]],
|
|
147
|
-
};
|
|
148
|
-
};
|
|
149
|
-
//# 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,mCAAI,YAAY,CAAC;IAChD,CAAC,CAAC,CAAC;IAEH,MAAM,kBAAkB,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE;;QACnD,OAAO,MAAA,WAAW,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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/parse.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
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
|
-
console.warn('Failed to parse Griffel styles');
|
|
82
|
-
console.warn(error);
|
|
83
|
-
if (silenceParseErrors) {
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
throw error;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
function getIgnoredRulesFromDirectives(commentDirectives) {
|
|
90
|
-
return (commentDirectives
|
|
91
|
-
.filter(([directive]) => directive === 'griffel-csslint-disable')
|
|
92
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
93
|
-
.map(([_, rulename]) => rulename));
|
|
94
|
-
}
|
|
95
|
-
const extractGriffelBabelPluginOptions = (opts = {}) => {
|
|
96
|
-
const { babelOptions, evaluationRules, generateMetadata, modules } = opts;
|
|
97
|
-
const babelPluginOptions = {};
|
|
98
|
-
if (babelOptions) {
|
|
99
|
-
babelPluginOptions.babelOptions = babelOptions;
|
|
100
|
-
}
|
|
101
|
-
if (evaluationRules) {
|
|
102
|
-
babelPluginOptions.evaluationRules = evaluationRules;
|
|
103
|
-
}
|
|
104
|
-
if (generateMetadata) {
|
|
105
|
-
babelPluginOptions.generateMetadata = generateMetadata;
|
|
106
|
-
}
|
|
107
|
-
if (modules) {
|
|
108
|
-
babelPluginOptions.modules = modules;
|
|
109
|
-
}
|
|
110
|
-
return babelPluginOptions;
|
|
111
|
-
};
|
|
112
|
-
//# sourceMappingURL=parse.js.map
|
package/src/parse.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../../../packages/postcss-syntax/src/parse.ts"],"names":[],"mappings":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,CAAC;AAC5B,CAAC,CAAC"}
|
package/src/stringify.d.ts
DELETED
package/src/stringify.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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
|
package/src/stringify.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
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"}
|