@griffel/postcss-syntax 1.0.8 → 1.1.1
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/package.json +2 -2
- package/src/constants.d.ts +2 -0
- package/src/constants.js +3 -1
- package/src/constants.js.map +1 -1
- package/src/index.d.ts +2 -1
- package/src/index.js +4 -1
- package/src/index.js.map +1 -1
- package/src/location-preset.js +0 -3
- package/src/location-preset.js.map +1 -1
- package/src/parse.d.ts +6 -2
- package/src/parse.js +33 -82
- package/src/parse.js.map +1 -1
- package/src/transform-sync.js +5 -18
- package/src/transform-sync.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@griffel/postcss-syntax",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "postcss syntax for Griffel",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@babel/core": "^7.23.2",
|
|
12
|
-
"@griffel/babel-preset": "^1.5.
|
|
12
|
+
"@griffel/babel-preset": "^1.5.9",
|
|
13
13
|
"@babel/helper-plugin-utils": "^7.22.5",
|
|
14
14
|
"postcss": "^8.4.29"
|
|
15
15
|
},
|
package/src/constants.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export declare const GRIFFEL_SLOT_RAW = "griffel-slot";
|
|
2
2
|
export declare const GRIFFEL_SRC_RAW = "griffel-src";
|
|
3
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
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GRIFFEL_DECLARATOR_RAW = exports.GRIFFEL_SRC_RAW = exports.GRIFFEL_SLOT_RAW = void 0;
|
|
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
4
|
exports.GRIFFEL_SLOT_RAW = 'griffel-slot';
|
|
5
5
|
exports.GRIFFEL_SRC_RAW = 'griffel-src';
|
|
6
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';
|
|
7
9
|
//# 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":";;;AAAa,QAAA,gBAAgB,GAAG,cAAc,CAAC;AAClC,QAAA,eAAe,GAAG,aAAa,CAAC;AAChC,QAAA,sBAAsB,GAAG,oBAAoB,CAAC"}
|
|
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"}
|
package/src/index.d.ts
CHANGED
|
@@ -5,7 +5,8 @@ export { createSyntax } from './createSyntax';
|
|
|
5
5
|
declare const _default: {
|
|
6
6
|
parse: (css: string | {
|
|
7
7
|
toString(): string;
|
|
8
|
-
}, opts?: import("./parse").ParserOptions | undefined) => import("postcss/lib/
|
|
8
|
+
}, opts?: import("./parse").ParserOptions | undefined) => import("postcss/lib/root").default;
|
|
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';
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createSyntax = exports.stringify = exports.parse = void 0;
|
|
3
|
+
exports.GRIFFEL_SLOT_LOCATION_RAW = exports.GRIFFEL_DECLARATOR_LOCATION_RAW = exports.createSyntax = exports.stringify = exports.parse = void 0;
|
|
4
4
|
const parse_1 = require("./parse");
|
|
5
5
|
Object.defineProperty(exports, "parse", { enumerable: true, get: function () { return parse_1.parse; } });
|
|
6
6
|
const stringify_1 = require("./stringify");
|
|
@@ -11,4 +11,7 @@ exports.default = {
|
|
|
11
11
|
parse: parse_1.parse,
|
|
12
12
|
stringify: stringify_1.stringify,
|
|
13
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; } });
|
|
14
17
|
//# 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":";;;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"}
|
|
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"}
|
package/src/location-preset.js
CHANGED
|
@@ -72,9 +72,6 @@ const plugin = (0, helper_plugin_utils_1.declare)((api, options) => {
|
|
|
72
72
|
state.locations[declaratorId][key.node.name] = {
|
|
73
73
|
...property.node.loc,
|
|
74
74
|
};
|
|
75
|
-
state.locations[declaratorId][key.node.name] = {
|
|
76
|
-
...property.node.loc,
|
|
77
|
-
};
|
|
78
75
|
});
|
|
79
76
|
}
|
|
80
77
|
if (resetFunctionKinds.includes(callee.node.name)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"location-preset.js","sourceRoot":"","sources":["../../../../packages/postcss-syntax/src/location-preset.ts"],"names":[],"mappings":";;AACA,oEAAqD;AAgBrD;;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,4B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EAAC;wBACrC,KAAK,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;4BAC7C,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG;yBACrB,CAAC;oBACJ,CAAC,CAAC,CAAC;iBACJ;gBAED,IAAI,kBAAkB,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;oBACjD,MAAA,KAAK,CAAC,cAAc,oCAApB,KAAK,CAAC,cAAc,GAAK,EAAE,EAAC;oBAC5B,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;oBAC7C,IAAI,CAAC,WAAW,CAAC,kBAAkB,EAAE,EAAE;wBACrC,OAAO;qBACR;oBAED,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,EAAE;wBACzB,OAAO;qBACR;oBAED,KAAK,CAAC,cAAc,CAAC,YAAY,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC;iBAC3D;YACH,CAAC;SACF;KACF,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,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
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import * as postcss from 'postcss';
|
|
2
2
|
import type { BabelPluginOptions } from '@griffel/babel-preset';
|
|
3
3
|
export type PostCSSParserOptions = Pick<postcss.ProcessOptions<postcss.Document | postcss.Root>, 'from' | 'map'>;
|
|
4
|
-
export interface ParserOptions extends PostCSSParserOptions, BabelPluginOptions {
|
|
4
|
+
export interface ParserOptions extends Pick<PostCSSParserOptions, 'from'>, BabelPluginOptions {
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* Generates CSS rules from a JavaScript file. Each slot in `makeStyles` and each `makeResetStyles` will be one line in the output.
|
|
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.
|
|
9
|
+
*/
|
|
6
10
|
export declare const parse: (css: string | {
|
|
7
11
|
toString(): string;
|
|
8
|
-
}, opts?: ParserOptions) => postcss.
|
|
12
|
+
}, opts?: ParserOptions) => postcss.Root;
|
package/src/parse.js
CHANGED
|
@@ -4,9 +4,13 @@ exports.parse = void 0;
|
|
|
4
4
|
const postcss = require("postcss");
|
|
5
5
|
const transform_sync_1 = require("./transform-sync");
|
|
6
6
|
const constants_1 = require("./constants");
|
|
7
|
+
/**
|
|
8
|
+
* Generates CSS rules from a JavaScript file. Each slot in `makeStyles` and each `makeResetStyles` will be one line in the output.
|
|
9
|
+
* 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.
|
|
10
|
+
*/
|
|
7
11
|
const parse = (css, opts) => {
|
|
8
12
|
const { from: filename = 'postcss-syntax.styles.ts' } = opts !== null && opts !== void 0 ? opts : {};
|
|
9
|
-
const griffelPluginOptions =
|
|
13
|
+
const griffelPluginOptions = extractGriffelBabelPluginOptions(opts);
|
|
10
14
|
const code = css.toString();
|
|
11
15
|
const { metadata } = (0, transform_sync_1.default)(code, {
|
|
12
16
|
filename,
|
|
@@ -16,91 +20,38 @@ const parse = (css, opts) => {
|
|
|
16
20
|
},
|
|
17
21
|
});
|
|
18
22
|
const { cssEntries, cssResetEntries, resetLocations, locations } = metadata;
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const location = locations[declarator][slot];
|
|
26
|
-
const nodes = rules.map(rule => {
|
|
27
|
-
const root = postcss.parse(rule);
|
|
28
|
-
root.walk(node => {
|
|
29
|
-
node.raws[constants_1.GRIFFEL_SLOT_RAW] = slot;
|
|
30
|
-
node.raws[constants_1.GRIFFEL_DECLARATOR_RAW] = declarator;
|
|
31
|
-
if (!node.source) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
// There's currently no way to to map generated CSS to original JS code
|
|
35
|
-
// Mapping each node to the original slot is probably the best we can do for now
|
|
36
|
-
node.source.end = {
|
|
37
|
-
offset: 0,
|
|
38
|
-
column: location.end.column,
|
|
39
|
-
line: location.end.line,
|
|
40
|
-
};
|
|
41
|
-
node.source.start = {
|
|
42
|
-
offset: 0,
|
|
43
|
-
column: location.start.column,
|
|
44
|
-
line: location.start.line,
|
|
45
|
-
};
|
|
46
|
-
});
|
|
47
|
-
return root.nodes[0];
|
|
48
|
-
});
|
|
49
|
-
return [...arr, ...nodes];
|
|
50
|
-
}, []);
|
|
51
|
-
})
|
|
52
|
-
.flat();
|
|
53
|
-
const cssResetRuleNodes = Object.entries(cssResetEntries).map(([declarator, [resetRule]]) => {
|
|
54
|
-
if (!resetLocations[declarator]) {
|
|
55
|
-
throw new Error(`No code location for ${declarator} - please report a bug`);
|
|
56
|
-
}
|
|
57
|
-
const location = resetLocations[declarator];
|
|
58
|
-
const root = postcss.parse(resetRule);
|
|
59
|
-
root.walk(node => {
|
|
60
|
-
node.raws[constants_1.GRIFFEL_DECLARATOR_RAW] = declarator;
|
|
61
|
-
if (!node.source) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
// There's currently no way to to map generated CSS to original JS code through Griffel AOT
|
|
65
|
-
// Mapping each node to the original slot is probably the best we can do for now
|
|
66
|
-
node.source.end = {
|
|
67
|
-
offset: 0,
|
|
68
|
-
column: location.end.column,
|
|
69
|
-
line: location.end.line,
|
|
70
|
-
};
|
|
71
|
-
node.source.start = {
|
|
72
|
-
offset: 0,
|
|
73
|
-
column: location.start.column,
|
|
74
|
-
line: location.start.line,
|
|
75
|
-
};
|
|
23
|
+
const cssRuleSlotNames = [];
|
|
24
|
+
const cssRules = [];
|
|
25
|
+
Object.entries(cssEntries).map(([declarator, slots]) => {
|
|
26
|
+
Object.entries(slots).map(([slot, rules]) => {
|
|
27
|
+
cssRuleSlotNames.push(`${declarator} ${slot}`);
|
|
28
|
+
cssRules.push(rules.join(''));
|
|
76
29
|
});
|
|
77
|
-
return root.nodes[0];
|
|
78
30
|
});
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return doc;
|
|
31
|
+
Object.entries(cssResetEntries).map(([declarator, resetRules]) => {
|
|
32
|
+
cssRuleSlotNames.push(`${declarator}`);
|
|
33
|
+
cssRules.push(resetRules.join(''));
|
|
34
|
+
});
|
|
35
|
+
const root = postcss.parse(cssRules.join('\n'));
|
|
36
|
+
root.walk(node => {
|
|
37
|
+
if (!node.source || node.source.start === undefined) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const [declarator, slot] = cssRuleSlotNames[node.source.start.line - 1].split(' ');
|
|
41
|
+
node.raws[constants_1.GRIFFEL_DECLARATOR_RAW] = declarator;
|
|
42
|
+
if (slot) {
|
|
43
|
+
node.raws[constants_1.GRIFFEL_SLOT_RAW] = slot;
|
|
44
|
+
node.raws[constants_1.GRIFFEL_SLOT_LOCATION_RAW] = locations[declarator][slot];
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
node.raws[constants_1.GRIFFEL_DECLARATOR_LOCATION_RAW] = resetLocations[declarator];
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
root.raws[constants_1.GRIFFEL_SRC_RAW] = css;
|
|
51
|
+
return root;
|
|
101
52
|
};
|
|
102
53
|
exports.parse = parse;
|
|
103
|
-
const
|
|
54
|
+
const extractGriffelBabelPluginOptions = (opts = {}) => {
|
|
104
55
|
const { babelOptions, evaluationRules, generateMetadata, modules } = opts;
|
|
105
56
|
const babelPluginOptions = {};
|
|
106
57
|
if (babelOptions) {
|
package/src/parse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../../../packages/postcss-syntax/src/parse.ts"],"names":[],"mappings":";;;AAAA,mCAAmC;AACnC,qDAA6C;AAC7C,
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../../../packages/postcss-syntax/src/parse.ts"],"names":[],"mappings":";;;AAAA,mCAAmC;AACnC,qDAA6C;AAC7C,2CAMqB;AAOrB;;;GAGG;AACI,MAAM,KAAK,GAAG,CAAC,GAAoC,EAAE,IAAoB,EAAE,EAAE;IAClF,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,0BAA0B,EAAE,GAAG,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,EAAE,CAAC;IACnE,MAAM,oBAAoB,GAAG,gCAAgC,CAAC,IAAI,CAAC,CAAC;IACpE,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;IAC5B,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAA,wBAAa,EAAC,IAAI,EAAE;QACvC,QAAQ;QACR,aAAa,EAAE;YACb,GAAG,oBAAoB;YACvB,gBAAgB,EAAE,IAAI;SACvB;KACF,CAAC,CAAC;IAEH,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,cAAc,EAAE,SAAS,EAAE,GAAG,QAAQ,CAAC;IAE5E,MAAM,gBAAgB,GAAa,EAAE,CAAC;IACtC,MAAM,QAAQ,GAAa,EAAE,CAAC;IAE9B,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,EAAE,KAAK,CAAC,EAAE,EAAE;QACrD,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAA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AC,UAAU,CAAC,CAAC;SACzE;IACH,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,IAAI,CAAC,2BAAe,CAAC,GAAG,GAAG,CAAC;IACjC,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AA9CW,QAAA,KAAK,SA8ChB;AAEF,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;QAChB,kBAAkB,CAAC,YAAY,GAAG,YAAY,CAAC;KAChD;IAED,IAAI,eAAe,EAAE;QACnB,kBAAkB,CAAC,eAAe,GAAG,eAAe,CAAC;KACtD;IAED,IAAI,gBAAgB,EAAE;QACpB,kBAAkB,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;KACxD;IAED,IAAI,OAAO,EAAE;QACX,kBAAkB,CAAC,OAAO,GAAG,OAAO,CAAC;KACtC;IAED,OAAO,kBAAkB,CAAC;AAC5B,CAAC,CAAC"}
|
package/src/transform-sync.js
CHANGED
|
@@ -7,27 +7,14 @@ const location_preset_1 = require("./location-preset");
|
|
|
7
7
|
* Transforms passed source code with Babel, uses user's config for parsing, but ignores it for transforms.
|
|
8
8
|
*/
|
|
9
9
|
function transformSync(sourceCode, options) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
caller: { name: 'griffel' },
|
|
14
|
-
filename: options.filename,
|
|
15
|
-
sourceMaps: true,
|
|
16
|
-
// TODO - we might need to add some babel config in the eslint rule options
|
|
17
|
-
// if the user doesn't want to use their normal babel config for this
|
|
18
|
-
// but let's only add it if it becomes necessary
|
|
19
|
-
});
|
|
20
|
-
if (babelAST === null) {
|
|
21
|
-
throw new Error(`Failed to create AST for "${options.filename}" due unknown Babel error...`);
|
|
22
|
-
}
|
|
23
|
-
const babelFileResult = Babel.transformFromAstSync(babelAST, sourceCode, {
|
|
10
|
+
var _a;
|
|
11
|
+
const { plugins, presets } = (_a = options.pluginOptions.babelOptions) !== null && _a !== void 0 ? _a : { plugins: [], presets: [] };
|
|
12
|
+
const babelFileResult = Babel.transformSync(sourceCode, {
|
|
24
13
|
// Ignore all user's configs and apply only our plugin
|
|
25
14
|
babelrc: false,
|
|
26
15
|
configFile: false,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
[location_preset_1.default, options.pluginOptions],
|
|
30
|
-
],
|
|
16
|
+
plugins,
|
|
17
|
+
presets: [...(presets !== null && presets !== void 0 ? presets : []), [babel_preset_1.default, options.pluginOptions], [location_preset_1.default, options.pluginOptions]],
|
|
31
18
|
filename: options.filename,
|
|
32
19
|
sourceFileName: options.filename,
|
|
33
20
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform-sync.js","sourceRoot":"","sources":["../../../../packages/postcss-syntax/src/transform-sync.ts"],"names":[],"mappings":";;AAAA,qCAAqC;AAErC,wDAAkD;AAElD,uDAA+C;AAO/C;;GAEG;AACH,SAAwB,aAAa,CAAC,UAAkB,EAAE,OAAyB
|
|
1
|
+
{"version":3,"file":"transform-sync.js","sourceRoot":"","sources":["../../../../packages/postcss-syntax/src/transform-sync.ts"],"names":[],"mappings":";;AAAA,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;QAC5B,MAAM,IAAI,KAAK,CAAC,wBAAwB,OAAO,CAAC,QAAQ,8BAA8B,CAAC,CAAC;KACzF;IAED,OAAO;QACL,QAAQ,EAAE,eAAe,CAAC,QAAmE;QAC7F,IAAI,EAAE,eAAe,CAAC,IAAI;KAC3B,CAAC;AACJ,CAAC;AArBD,gCAqBC"}
|