boss-css 0.0.1 → 0.0.3
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 +1 -0
- package/dist/_virtual/rolldown_runtime.cjs +43 -0
- package/dist/_virtual/rolldown_runtime.mjs +20 -0
- package/dist/api/browser.cjs +54 -0
- package/dist/api/browser.mjs +48 -0
- package/dist/api/config.cjs +94 -0
- package/dist/api/config.mjs +91 -0
- package/dist/api/css.cjs +304 -0
- package/dist/api/css.mjs +303 -0
- package/dist/api/dictionary.cjs +218 -0
- package/dist/api/dictionary.mjs +215 -0
- package/dist/api/file/dts.cjs +21 -0
- package/dist/api/file/dts.mjs +21 -0
- package/dist/api/file/file.cjs +123 -0
- package/dist/api/file/file.mjs +120 -0
- package/dist/api/file/js.cjs +118 -0
- package/dist/api/file/js.mjs +116 -0
- package/dist/api/names.cjs +52 -0
- package/dist/api/names.mjs +46 -0
- package/dist/api/noopCss.cjs +37 -0
- package/dist/api/noopCss.mjs +36 -0
- package/dist/api/propTree.cjs +54 -0
- package/dist/api/propTree.mjs +48 -0
- package/dist/api/server.cjs +112 -0
- package/dist/api/server.mjs +106 -0
- package/dist/cli/build.cjs +1 -0
- package/dist/cli/build.mjs +3 -0
- package/dist/cli/index.cjs +30 -0
- package/dist/cli/index.mjs +29 -0
- package/dist/cli/tasks/build.cjs +24 -0
- package/dist/cli/tasks/build.mjs +23 -0
- package/dist/cli/tasks/choose.cjs +47 -0
- package/dist/cli/tasks/choose.mjs +46 -0
- package/dist/cli/tasks/compile.cjs +68 -0
- package/dist/cli/tasks/compile.mjs +67 -0
- package/dist/cli/tasks/dev.cjs +51 -0
- package/dist/cli/tasks/dev.mjs +48 -0
- package/dist/cli/tasks/init.cjs +1835 -0
- package/dist/cli/tasks/init.mjs +1831 -0
- package/dist/cli/tasks/watch.cjs +38 -0
- package/dist/cli/tasks/watch.mjs +37 -0
- package/dist/cli/templates/init.cjs +82 -0
- package/dist/cli/templates/init.mjs +78 -0
- package/dist/cli/types.cjs +13 -0
- package/dist/cli/types.mjs +13 -0
- package/dist/cli/utils.cjs +43 -0
- package/dist/cli/utils.mjs +41 -0
- package/dist/compile/classname-strategy.cjs +79 -0
- package/dist/compile/classname-strategy.mjs +77 -0
- package/dist/compile/classname.cjs +366 -0
- package/dist/compile/classname.mjs +360 -0
- package/dist/compile/index.cjs +238 -0
- package/dist/compile/index.mjs +235 -0
- package/dist/compile/jsx.cjs +803 -0
- package/dist/compile/jsx.mjs +800 -0
- package/dist/compile/prepared.cjs +88 -0
- package/dist/compile/prepared.mjs +87 -0
- package/dist/compile/runtime.cjs +33 -0
- package/dist/compile/runtime.mjs +32 -0
- package/dist/compile/transform.cjs +371 -0
- package/dist/compile/transform.mjs +369 -0
- package/dist/cx/index.cjs +93 -0
- package/dist/cx/index.mjs +85 -0
- package/dist/detect-fw/index.cjs +384 -0
- package/dist/detect-fw/index.mjs +379 -0
- package/dist/dev/client.cjs +39 -0
- package/dist/dev/client.mjs +38 -0
- package/dist/dev/plugin/browser.cjs +11 -0
- package/dist/dev/plugin/browser.mjs +9 -0
- package/dist/dev/plugin/server.cjs +86 -0
- package/dist/dev/plugin/server.mjs +78 -0
- package/dist/dev/port.cjs +46 -0
- package/dist/dev/port.mjs +43 -0
- package/dist/dev/runtime.cjs +28 -0
- package/dist/dev/runtime.mjs +29 -0
- package/dist/dev/server.cjs +808 -0
- package/dist/dev/server.mjs +805 -0
- package/dist/dev/shared.cjs +6 -0
- package/dist/dev/shared.mjs +5 -0
- package/dist/eslint-plugin/index.cjs +66 -0
- package/dist/eslint-plugin/index.mjs +66 -0
- package/dist/eslint-plugin/rules/classnames-only.cjs +68 -0
- package/dist/eslint-plugin/rules/classnames-only.mjs +68 -0
- package/dist/eslint-plugin/rules/format-classnames.cjs +137 -0
- package/dist/eslint-plugin/rules/format-classnames.mjs +136 -0
- package/dist/eslint-plugin/rules/no-unknown-classes.cjs +119 -0
- package/dist/eslint-plugin/rules/no-unknown-classes.mjs +119 -0
- package/dist/eslint-plugin/rules/prefer-classnames.cjs +69 -0
- package/dist/eslint-plugin/rules/prefer-classnames.mjs +69 -0
- package/dist/eslint-plugin/rules/prefer-token-values.cjs +197 -0
- package/dist/eslint-plugin/rules/prefer-token-values.mjs +197 -0
- package/dist/eslint-plugin/rules/props-only.cjs +115 -0
- package/dist/eslint-plugin/rules/props-only.mjs +115 -0
- package/dist/eslint-plugin/rules/redundant-cx.cjs +66 -0
- package/dist/eslint-plugin/rules/redundant-cx.mjs +66 -0
- package/dist/eslint-plugin/rules/require-prop-functions.cjs +130 -0
- package/dist/eslint-plugin/rules/require-prop-functions.mjs +130 -0
- package/dist/eslint-plugin/utils/api.cjs +30 -0
- package/dist/eslint-plugin/utils/api.mjs +29 -0
- package/dist/eslint-plugin/utils/ast.cjs +119 -0
- package/dist/eslint-plugin/utils/ast.mjs +112 -0
- package/dist/eslint-plugin/utils/boss-classes.cjs +185 -0
- package/dist/eslint-plugin/utils/boss-classes.mjs +175 -0
- package/dist/eslint-plugin/utils/defaults.cjs +99 -0
- package/dist/eslint-plugin/utils/defaults.mjs +93 -0
- package/dist/eslint-plugin/utils/format.cjs +20 -0
- package/dist/eslint-plugin/utils/format.mjs +19 -0
- package/dist/eslint-plugin/utils/order.cjs +76 -0
- package/dist/eslint-plugin/utils/order.mjs +76 -0
- package/dist/eslint-plugin/utils/property-order.cjs +449 -0
- package/dist/eslint-plugin/utils/property-order.mjs +448 -0
- package/dist/eslint-plugin/utils/static.cjs +36 -0
- package/dist/eslint-plugin/utils/static.mjs +35 -0
- package/dist/fontsource/directory.cjs +39588 -0
- package/dist/fontsource/directory.mjs +39587 -0
- package/dist/fontsource/server.cjs +291 -0
- package/dist/fontsource/server.mjs +282 -0
- package/dist/index.cjs +10 -0
- package/dist/index.mjs +6 -0
- package/dist/log/browser.cjs +28 -0
- package/dist/log/browser.mjs +28 -0
- package/dist/log/server.cjs +32 -0
- package/dist/log/server.mjs +30 -0
- package/dist/merge/index.cjs +590 -0
- package/dist/merge/index.mjs +586 -0
- package/dist/native/browser.cjs +78 -0
- package/dist/native/browser.mjs +77 -0
- package/dist/native/server.cjs +180 -0
- package/dist/native/server.mjs +176 -0
- package/dist/native/styleTypes.cjs +168 -0
- package/dist/native/styleTypes.mjs +164 -0
- package/dist/parser/classname/server.cjs +239 -0
- package/dist/parser/classname/server.mjs +232 -0
- package/dist/parser/jsx/browser.cjs +66 -0
- package/dist/parser/jsx/browser.mjs +63 -0
- package/dist/parser/jsx/extractCode.cjs +99 -0
- package/dist/parser/jsx/extractCode.mjs +98 -0
- package/dist/parser/jsx/extractPrepared.cjs +123 -0
- package/dist/parser/jsx/extractPrepared.mjs +122 -0
- package/dist/parser/jsx/extractProps.cjs +234 -0
- package/dist/parser/jsx/extractProps.mjs +232 -0
- package/dist/parser/jsx/isDOMProp.cjs +17 -0
- package/dist/parser/jsx/isDOMProp.mjs +15 -0
- package/dist/parser/jsx/native.cjs +110 -0
- package/dist/parser/jsx/native.mjs +108 -0
- package/dist/parser/jsx/runtime.cjs +4 -0
- package/dist/parser/jsx/runtime.mjs +3 -0
- package/dist/parser/jsx/server.cjs +278 -0
- package/dist/parser/jsx/server.mjs +268 -0
- package/dist/postcss/index.cjs +16 -0
- package/dist/postcss/index.mjs +16 -0
- package/dist/prop/at/runtime-only.cjs +90 -0
- package/dist/prop/at/runtime-only.mjs +88 -0
- package/dist/prop/at/server.cjs +282 -0
- package/dist/prop/at/server.mjs +268 -0
- package/dist/prop/at/shared.cjs +153 -0
- package/dist/prop/at/shared.mjs +144 -0
- package/dist/prop/bosswind/browser.cjs +18 -0
- package/dist/prop/bosswind/browser.mjs +16 -0
- package/dist/prop/bosswind/runtime-only.cjs +18 -0
- package/dist/prop/bosswind/runtime-only.mjs +16 -0
- package/dist/prop/bosswind/server.cjs +81 -0
- package/dist/prop/bosswind/server.mjs +72 -0
- package/dist/prop/bosswind/shared.cjs +861 -0
- package/dist/prop/bosswind/shared.mjs +855 -0
- package/dist/prop/bosswind/tailwind-theme.cjs +703 -0
- package/dist/prop/bosswind/tailwind-theme.mjs +702 -0
- package/dist/prop/child/runtime-only.cjs +18 -0
- package/dist/prop/child/runtime-only.mjs +15 -0
- package/dist/prop/child/server.cjs +81 -0
- package/dist/prop/child/server.mjs +72 -0
- package/dist/prop/css/getDtsTemplate.cjs +65 -0
- package/dist/prop/css/getDtsTemplate.mjs +63 -0
- package/dist/prop/css/runtime-only.cjs +14 -0
- package/dist/prop/css/runtime-only.mjs +13 -0
- package/dist/prop/css/server.cjs +99 -0
- package/dist/prop/css/server.mjs +90 -0
- package/dist/prop/pseudo/runtime-only.cjs +23 -0
- package/dist/prop/pseudo/runtime-only.mjs +21 -0
- package/dist/prop/pseudo/server.cjs +91 -0
- package/dist/prop/pseudo/server.mjs +82 -0
- package/dist/prop/pseudo/shared.cjs +61 -0
- package/dist/prop/pseudo/shared.mjs +60 -0
- package/dist/reset/server.cjs +34 -0
- package/dist/reset/server.mjs +26 -0
- package/dist/runtime/index.cjs +119 -0
- package/dist/runtime/index.mjs +118 -0
- package/dist/runtime/preact.cjs +4 -0
- package/dist/runtime/preact.mjs +3 -0
- package/dist/runtime/qwik.cjs +21 -0
- package/dist/runtime/qwik.mjs +18 -0
- package/dist/runtime/react.cjs +4 -0
- package/dist/runtime/react.mjs +3 -0
- package/dist/runtime/solid.cjs +15 -0
- package/dist/runtime/solid.mjs +14 -0
- package/dist/runtime/stencil.cjs +25 -0
- package/dist/runtime/stencil.mjs +21 -0
- package/dist/runtime/style.cjs +14 -0
- package/dist/runtime/style.mjs +13 -0
- package/dist/shared/boundaries.cjs +288 -0
- package/dist/shared/boundaries.mjs +285 -0
- package/dist/shared/customCss.cjs +212 -0
- package/dist/shared/customCss.mjs +211 -0
- package/dist/shared/debug.cjs +76 -0
- package/dist/shared/debug.mjs +74 -0
- package/dist/shared/file.cjs +21 -0
- package/dist/shared/file.mjs +19 -0
- package/dist/shared/framework.cjs +10 -0
- package/dist/shared/framework.mjs +9 -0
- package/dist/shared/json.cjs +58 -0
- package/dist/shared/json.mjs +57 -0
- package/dist/shared/types.cjs +11 -0
- package/dist/shared/types.mjs +10 -0
- package/dist/strategy/classic/runtime-only.cjs +190 -0
- package/dist/strategy/classic/runtime-only.mjs +186 -0
- package/dist/strategy/classname-first/runtime-only.cjs +138 -0
- package/dist/strategy/classname-first/runtime-only.mjs +134 -0
- package/dist/strategy/classname-first/server.cjs +139 -0
- package/dist/strategy/classname-first/server.mjs +133 -0
- package/dist/strategy/classname-only/server.cjs +43 -0
- package/dist/strategy/classname-only/server.mjs +35 -0
- package/dist/strategy/inline-first/browser.cjs +61 -0
- package/dist/strategy/inline-first/browser.mjs +58 -0
- package/dist/strategy/inline-first/runtime-only.cjs +159 -0
- package/dist/strategy/inline-first/runtime-only.mjs +155 -0
- package/dist/strategy/inline-first/server.cjs +92 -0
- package/dist/strategy/inline-first/server.mjs +83 -0
- package/dist/strategy/runtime/runtime-only.cjs +24 -0
- package/dist/strategy/runtime/runtime-only.mjs +22 -0
- package/dist/strategy/runtime/server.cjs +72 -0
- package/dist/strategy/runtime/server.mjs +63 -0
- package/dist/strategy/runtime-only/css.cjs +183 -0
- package/dist/strategy/runtime-only/css.mjs +181 -0
- package/dist/tasks/build.cjs +88 -0
- package/dist/tasks/build.mjs +84 -0
- package/dist/tasks/compile.cjs +12 -0
- package/dist/tasks/compile.mjs +12 -0
- package/dist/tasks/postcss.cjs +116 -0
- package/dist/tasks/postcss.mjs +113 -0
- package/dist/tasks/session.cjs +46 -0
- package/dist/tasks/session.mjs +42 -0
- package/dist/tasks/watch.cjs +102 -0
- package/dist/tasks/watch.mjs +99 -0
- package/dist/transform/cache.cjs +24 -0
- package/dist/transform/cache.mjs +21 -0
- package/dist/transform/processFile.cjs +26 -0
- package/dist/transform/processFile.mjs +24 -0
- package/dist/use/token/browser.cjs +65 -0
- package/dist/use/token/browser.mjs +61 -0
- package/dist/use/token/runtime-only.cjs +245 -0
- package/dist/use/token/runtime-only.mjs +239 -0
- package/dist/use/token/server.cjs +325 -0
- package/dist/use/token/server.mjs +313 -0
- package/dist/use/token/vars.cjs +47 -0
- package/dist/use/token/vars.mjs +46 -0
- package/package.json +300 -4
- package/src/api/config.d.ts +1 -0
- package/src/fontsource/types.d.ts +50 -0
- package/src/packages/document-create-element/createElement.browser.js +3 -0
- package/src/packages/document-create-element/createElement.js +7 -0
- package/src/packages/document-create-element/package.json +17 -0
- package/src/packages/is-css-prop/browser.js +13 -0
- package/src/packages/is-css-prop/index.js +13 -0
- package/src/packages/is-css-prop/package-lock.json +52 -0
- package/src/packages/is-css-prop/package.json +17 -0
- package/src/prop/css/csstype.json +4387 -0
- package/src/prop/css/package.json +3 -0
- package/src/reset/reset.css +259 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_jsx = require('./jsx.cjs');
|
|
3
|
+
let _swc_core = require("@swc/core");
|
|
4
|
+
|
|
5
|
+
//#region src/compile/prepared.ts
|
|
6
|
+
function scanPrepared(source, options) {
|
|
7
|
+
const parsed = (0, _swc_core.parseSync)(source, {
|
|
8
|
+
syntax: options.isTs ? "typescript" : "ecmascript",
|
|
9
|
+
tsx: options.isTs && options.isJsx,
|
|
10
|
+
jsx: !options.isTs && options.isJsx
|
|
11
|
+
});
|
|
12
|
+
const definitions = [];
|
|
13
|
+
const usages = [];
|
|
14
|
+
const visit = (node) => {
|
|
15
|
+
if (!node || typeof node !== "object") return;
|
|
16
|
+
if (Array.isArray(node)) {
|
|
17
|
+
node.forEach(visit);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const current = node;
|
|
21
|
+
if (isPreparedAssignment(current)) {
|
|
22
|
+
const prepared = extractPreparedDefinition(current.expression);
|
|
23
|
+
if (prepared) definitions.push(prepared);
|
|
24
|
+
}
|
|
25
|
+
if (current.type === "JSXElement") {
|
|
26
|
+
const preparedUsage = extractPreparedUsage(current);
|
|
27
|
+
if (preparedUsage) usages.push(preparedUsage);
|
|
28
|
+
}
|
|
29
|
+
for (const key of Object.keys(current)) visit(current[key]);
|
|
30
|
+
};
|
|
31
|
+
visit(parsed);
|
|
32
|
+
return {
|
|
33
|
+
definitions,
|
|
34
|
+
usages
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const extractPreparedDefinition = (expression) => {
|
|
38
|
+
const assignment = expression;
|
|
39
|
+
const name = assignment.left?.property?.value;
|
|
40
|
+
const objectExpression = assignment.right ? getPreparedObjectExpression(assignment.right) : null;
|
|
41
|
+
if (!name || !objectExpression) return null;
|
|
42
|
+
const definition = require_jsx.buildPreparedDefinition(objectExpression);
|
|
43
|
+
if (!definition) return null;
|
|
44
|
+
return {
|
|
45
|
+
name,
|
|
46
|
+
definition,
|
|
47
|
+
inlineable: require_jsx.isPreparedDefinitionStatic(definition)
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
const extractPreparedUsage = (element) => {
|
|
51
|
+
const name = element.opening.name;
|
|
52
|
+
if (name.type !== "JSXMemberExpression" || name.object.type !== "Identifier" || name.object.value !== "$$" || name.property.type !== "Identifier" || !/^[A-Z]/.test(name.property.value)) return null;
|
|
53
|
+
const hasSpread = element.opening.attributes.some((attr) => attr.type === "SpreadElement");
|
|
54
|
+
return {
|
|
55
|
+
name: name.property.value,
|
|
56
|
+
hasSpread
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
const isPreparedAssignmentExpression = (node) => {
|
|
60
|
+
if (node.type !== "AssignmentExpression") return false;
|
|
61
|
+
const assignment = node;
|
|
62
|
+
if (assignment.operator && assignment.operator !== "=") return false;
|
|
63
|
+
const left = assignment.left;
|
|
64
|
+
if (!left || left.type !== "MemberExpression") return false;
|
|
65
|
+
if (left.object?.type !== "Identifier" || left.object.value !== "$$") return false;
|
|
66
|
+
const property = left.property;
|
|
67
|
+
if (!property || property.type !== "Identifier") return false;
|
|
68
|
+
if (!property.value || !/^[A-Z]/.test(property.value)) return false;
|
|
69
|
+
return Boolean(assignment.right && getPreparedObjectExpression(assignment.right));
|
|
70
|
+
};
|
|
71
|
+
const isPreparedAssignment = (node) => {
|
|
72
|
+
if (node.type !== "ExpressionStatement") return false;
|
|
73
|
+
const statement = node;
|
|
74
|
+
return Boolean(statement.expression && isPreparedAssignmentExpression(statement.expression));
|
|
75
|
+
};
|
|
76
|
+
const getPreparedObjectExpression = (expression) => {
|
|
77
|
+
if (expression.type === "CallExpression" && expression.arguments.length === 1) {
|
|
78
|
+
const callee = expression.callee;
|
|
79
|
+
if (callee.type === "MemberExpression" && callee.object?.type === "Identifier" && callee.object.value === "$$" && callee.property?.type === "Identifier" && callee.property.value === "$") {
|
|
80
|
+
const arg = expression.arguments[0].expression;
|
|
81
|
+
if (arg.type === "ObjectExpression") return arg;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
//#endregion
|
|
88
|
+
exports.scanPrepared = scanPrepared;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { buildPreparedDefinition, isPreparedDefinitionStatic } from "./jsx.mjs";
|
|
2
|
+
import { parseSync } from "@swc/core";
|
|
3
|
+
|
|
4
|
+
//#region src/compile/prepared.ts
|
|
5
|
+
function scanPrepared(source, options) {
|
|
6
|
+
const parsed = parseSync(source, {
|
|
7
|
+
syntax: options.isTs ? "typescript" : "ecmascript",
|
|
8
|
+
tsx: options.isTs && options.isJsx,
|
|
9
|
+
jsx: !options.isTs && options.isJsx
|
|
10
|
+
});
|
|
11
|
+
const definitions = [];
|
|
12
|
+
const usages = [];
|
|
13
|
+
const visit = (node) => {
|
|
14
|
+
if (!node || typeof node !== "object") return;
|
|
15
|
+
if (Array.isArray(node)) {
|
|
16
|
+
node.forEach(visit);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const current = node;
|
|
20
|
+
if (isPreparedAssignment(current)) {
|
|
21
|
+
const prepared = extractPreparedDefinition(current.expression);
|
|
22
|
+
if (prepared) definitions.push(prepared);
|
|
23
|
+
}
|
|
24
|
+
if (current.type === "JSXElement") {
|
|
25
|
+
const preparedUsage = extractPreparedUsage(current);
|
|
26
|
+
if (preparedUsage) usages.push(preparedUsage);
|
|
27
|
+
}
|
|
28
|
+
for (const key of Object.keys(current)) visit(current[key]);
|
|
29
|
+
};
|
|
30
|
+
visit(parsed);
|
|
31
|
+
return {
|
|
32
|
+
definitions,
|
|
33
|
+
usages
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const extractPreparedDefinition = (expression) => {
|
|
37
|
+
const assignment = expression;
|
|
38
|
+
const name = assignment.left?.property?.value;
|
|
39
|
+
const objectExpression = assignment.right ? getPreparedObjectExpression(assignment.right) : null;
|
|
40
|
+
if (!name || !objectExpression) return null;
|
|
41
|
+
const definition = buildPreparedDefinition(objectExpression);
|
|
42
|
+
if (!definition) return null;
|
|
43
|
+
return {
|
|
44
|
+
name,
|
|
45
|
+
definition,
|
|
46
|
+
inlineable: isPreparedDefinitionStatic(definition)
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
const extractPreparedUsage = (element) => {
|
|
50
|
+
const name = element.opening.name;
|
|
51
|
+
if (name.type !== "JSXMemberExpression" || name.object.type !== "Identifier" || name.object.value !== "$$" || name.property.type !== "Identifier" || !/^[A-Z]/.test(name.property.value)) return null;
|
|
52
|
+
const hasSpread = element.opening.attributes.some((attr) => attr.type === "SpreadElement");
|
|
53
|
+
return {
|
|
54
|
+
name: name.property.value,
|
|
55
|
+
hasSpread
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
const isPreparedAssignmentExpression = (node) => {
|
|
59
|
+
if (node.type !== "AssignmentExpression") return false;
|
|
60
|
+
const assignment = node;
|
|
61
|
+
if (assignment.operator && assignment.operator !== "=") return false;
|
|
62
|
+
const left = assignment.left;
|
|
63
|
+
if (!left || left.type !== "MemberExpression") return false;
|
|
64
|
+
if (left.object?.type !== "Identifier" || left.object.value !== "$$") return false;
|
|
65
|
+
const property = left.property;
|
|
66
|
+
if (!property || property.type !== "Identifier") return false;
|
|
67
|
+
if (!property.value || !/^[A-Z]/.test(property.value)) return false;
|
|
68
|
+
return Boolean(assignment.right && getPreparedObjectExpression(assignment.right));
|
|
69
|
+
};
|
|
70
|
+
const isPreparedAssignment = (node) => {
|
|
71
|
+
if (node.type !== "ExpressionStatement") return false;
|
|
72
|
+
const statement = node;
|
|
73
|
+
return Boolean(statement.expression && isPreparedAssignmentExpression(statement.expression));
|
|
74
|
+
};
|
|
75
|
+
const getPreparedObjectExpression = (expression) => {
|
|
76
|
+
if (expression.type === "CallExpression" && expression.arguments.length === 1) {
|
|
77
|
+
const callee = expression.callee;
|
|
78
|
+
if (callee.type === "MemberExpression" && callee.object?.type === "Identifier" && callee.object.value === "$$" && callee.property?.type === "Identifier" && callee.property.value === "$") {
|
|
79
|
+
const arg = expression.arguments[0].expression;
|
|
80
|
+
if (arg.type === "ObjectExpression") return arg;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
export { scanPrepared };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const require_dictionary = require('../api/dictionary.cjs');
|
|
2
|
+
const require_vars = require('../use/token/vars.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/compile/runtime.ts
|
|
5
|
+
const createBossValue = (unit) => {
|
|
6
|
+
return (value) => {
|
|
7
|
+
if (Array.isArray(value)) return value.map((v) => typeof v === "number" && v !== 0 ? `${v}${unit}` : v).join(" ");
|
|
8
|
+
if (typeof value === "number") return value !== 0 ? `${value}${unit}` : 0;
|
|
9
|
+
return value;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
const createBossTokenVars = (unit, prefix = "") => {
|
|
13
|
+
const toValue = (value, property) => {
|
|
14
|
+
const propertyName = property;
|
|
15
|
+
if (Array.isArray(value)) return value.map((v) => toValue(v, propertyName)).join(" ");
|
|
16
|
+
if (typeof value === "number" || require_dictionary.isNumericValue(value)) {
|
|
17
|
+
const numeric = typeof value === "number" ? value : Number(value);
|
|
18
|
+
if (propertyName && require_dictionary.unitlessProperties.has(propertyName)) return numeric === 0 ? 0 : `${numeric}`;
|
|
19
|
+
return numeric === 0 ? 0 : `${numeric}${unit}`;
|
|
20
|
+
}
|
|
21
|
+
if (value == null) return null;
|
|
22
|
+
return String(value);
|
|
23
|
+
};
|
|
24
|
+
const builder = require_vars.createTokenVars({
|
|
25
|
+
prefix,
|
|
26
|
+
toValue
|
|
27
|
+
});
|
|
28
|
+
return (input) => builder(input);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
exports.createBossTokenVars = createBossTokenVars;
|
|
33
|
+
exports.createBossValue = createBossValue;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { isNumericValue, unitlessProperties } from "../api/dictionary.mjs";
|
|
2
|
+
import { createTokenVars } from "../use/token/vars.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/compile/runtime.ts
|
|
5
|
+
const createBossValue = (unit) => {
|
|
6
|
+
return (value) => {
|
|
7
|
+
if (Array.isArray(value)) return value.map((v) => typeof v === "number" && v !== 0 ? `${v}${unit}` : v).join(" ");
|
|
8
|
+
if (typeof value === "number") return value !== 0 ? `${value}${unit}` : 0;
|
|
9
|
+
return value;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
const createBossTokenVars = (unit, prefix = "") => {
|
|
13
|
+
const toValue = (value, property) => {
|
|
14
|
+
const propertyName = property;
|
|
15
|
+
if (Array.isArray(value)) return value.map((v) => toValue(v, propertyName)).join(" ");
|
|
16
|
+
if (typeof value === "number" || isNumericValue(value)) {
|
|
17
|
+
const numeric = typeof value === "number" ? value : Number(value);
|
|
18
|
+
if (propertyName && unitlessProperties.has(propertyName)) return numeric === 0 ? 0 : `${numeric}`;
|
|
19
|
+
return numeric === 0 ? 0 : `${numeric}${unit}`;
|
|
20
|
+
}
|
|
21
|
+
if (value == null) return null;
|
|
22
|
+
return String(value);
|
|
23
|
+
};
|
|
24
|
+
const builder = createTokenVars({
|
|
25
|
+
prefix,
|
|
26
|
+
toValue
|
|
27
|
+
});
|
|
28
|
+
return (input) => builder(input);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { createBossTokenVars, createBossValue };
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_framework = require('../shared/framework.cjs');
|
|
3
|
+
const require_classname = require('./classname.cjs');
|
|
4
|
+
const require_jsx = require('./jsx.cjs');
|
|
5
|
+
const require_customCss = require('../shared/customCss.cjs');
|
|
6
|
+
let node_path = require("node:path");
|
|
7
|
+
node_path = require_rolldown_runtime.__toESM(node_path);
|
|
8
|
+
let _swc_core = require("@swc/core");
|
|
9
|
+
|
|
10
|
+
//#region src/compile/transform.ts
|
|
11
|
+
const jsxExtensions = new Set([
|
|
12
|
+
".jsx",
|
|
13
|
+
".tsx",
|
|
14
|
+
".js",
|
|
15
|
+
".mjs",
|
|
16
|
+
".cjs"
|
|
17
|
+
]);
|
|
18
|
+
const tsExtensions = new Set([".ts", ".tsx"]);
|
|
19
|
+
const fallbackSpan = {
|
|
20
|
+
start: 0,
|
|
21
|
+
end: 0,
|
|
22
|
+
ctxt: 0
|
|
23
|
+
};
|
|
24
|
+
const ensureSpan = (span) => {
|
|
25
|
+
if (!span) return fallbackSpan;
|
|
26
|
+
if (typeof span.ctxt === "number") return span;
|
|
27
|
+
return {
|
|
28
|
+
...span,
|
|
29
|
+
ctxt: 0
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
const createVoidExpression = (span) => {
|
|
33
|
+
const safeSpan = ensureSpan(span);
|
|
34
|
+
return {
|
|
35
|
+
type: "UnaryExpression",
|
|
36
|
+
span: safeSpan,
|
|
37
|
+
operator: "void",
|
|
38
|
+
argument: {
|
|
39
|
+
type: "NumericLiteral",
|
|
40
|
+
span: safeSpan,
|
|
41
|
+
value: 0
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
async function transformSource(source, options) {
|
|
46
|
+
const ext = node_path.default.extname(options.filename);
|
|
47
|
+
const isTs = tsExtensions.has(ext);
|
|
48
|
+
const isJsx = jsxExtensions.has(ext);
|
|
49
|
+
const parsed = (0, _swc_core.parseSync)(source, {
|
|
50
|
+
syntax: isTs ? "typescript" : "ecmascript",
|
|
51
|
+
tsx: isTs && isJsx,
|
|
52
|
+
jsx: !isTs && isJsx
|
|
53
|
+
});
|
|
54
|
+
const state = {
|
|
55
|
+
api: options.api,
|
|
56
|
+
classNameProp: require_framework.getClassNameProp(options.api.framework),
|
|
57
|
+
compile: options.compile,
|
|
58
|
+
filename: options.filename,
|
|
59
|
+
classNameMapper: options.classNameMapper ?? null,
|
|
60
|
+
needsRuntime: false,
|
|
61
|
+
needsValueHelper: false,
|
|
62
|
+
needsTokenVarsHelper: false,
|
|
63
|
+
replacedElements: 0,
|
|
64
|
+
preparedLocal: new Map(options.preparedLocal ?? []),
|
|
65
|
+
preparedGlobal: options.preparedGlobal ?? /* @__PURE__ */ new Map(),
|
|
66
|
+
preparedRuntime: options.preparedRuntime ?? /* @__PURE__ */ new Set(),
|
|
67
|
+
customCssBlocks: []
|
|
68
|
+
};
|
|
69
|
+
const transformed = await transformProgram(parsed, state);
|
|
70
|
+
normalizeSpans(transformed);
|
|
71
|
+
if (state.customCssBlocks.length) state.api.css?.syncCustomBlocks?.(state.filename, state.customCssBlocks);
|
|
72
|
+
return {
|
|
73
|
+
code: (0, _swc_core.printSync)(transformed).code,
|
|
74
|
+
needsRuntime: state.needsRuntime,
|
|
75
|
+
needsValueHelper: state.needsValueHelper,
|
|
76
|
+
replacedElements: state.replacedElements
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const normalizeSpans = (node) => {
|
|
80
|
+
if (!node || typeof node !== "object") return;
|
|
81
|
+
if (Array.isArray(node)) {
|
|
82
|
+
node.forEach(normalizeSpans);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const record = node;
|
|
86
|
+
if (typeof record.type === "string" && record.span && typeof record.ctxt !== "number") record.ctxt = 0;
|
|
87
|
+
for (const [key, value] of Object.entries(record)) {
|
|
88
|
+
if (key === "span" && value && typeof value === "object") {
|
|
89
|
+
const span = value;
|
|
90
|
+
if (typeof span.start === "number" && typeof span.end === "number" && typeof span.ctxt !== "number") span.ctxt = 0;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
normalizeSpans(value);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
const transformProgram = async (program, state) => {
|
|
97
|
+
const transformed = await transformNode(program, state);
|
|
98
|
+
const needsValueHelper = state.needsValueHelper && !hasValueHelper(transformed);
|
|
99
|
+
const needsTokenVarsHelper = state.needsTokenVarsHelper && !hasTokenVarsHelper(transformed);
|
|
100
|
+
if (needsValueHelper || needsTokenVarsHelper) {
|
|
101
|
+
const helper = createRuntimeHelpersProgram({
|
|
102
|
+
unit: state.api.unit ?? "px",
|
|
103
|
+
prefix: state.api.selectorPrefix ?? "",
|
|
104
|
+
needsValueHelper,
|
|
105
|
+
needsTokenVarsHelper
|
|
106
|
+
});
|
|
107
|
+
if ("body" in transformed) transformed.body = [...helper.body, ...transformed.body];
|
|
108
|
+
}
|
|
109
|
+
if (!state.needsRuntime && "body" in transformed) transformed.body = transformed.body.filter((node) => {
|
|
110
|
+
if (node.type !== "ImportDeclaration") return true;
|
|
111
|
+
const source = node.source.value;
|
|
112
|
+
return !isBossImport(source);
|
|
113
|
+
});
|
|
114
|
+
return transformed;
|
|
115
|
+
};
|
|
116
|
+
const transformNode = async (node, state, context = {}) => {
|
|
117
|
+
if (!node || typeof node !== "object") return node;
|
|
118
|
+
if (Array.isArray(node)) {
|
|
119
|
+
const mapped = [];
|
|
120
|
+
for (const child of node) {
|
|
121
|
+
const next = await transformNode(child, state, context);
|
|
122
|
+
if (next === null) continue;
|
|
123
|
+
mapped.push(next);
|
|
124
|
+
}
|
|
125
|
+
return mapped;
|
|
126
|
+
}
|
|
127
|
+
const current = node;
|
|
128
|
+
const mapToken = state.classNameMapper ? (token) => state.classNameMapper?.get(token) : void 0;
|
|
129
|
+
let keepPreparedMarker = false;
|
|
130
|
+
if (current.type === "ExpressionStatement") {
|
|
131
|
+
const expression = current.expression;
|
|
132
|
+
if (expression) {
|
|
133
|
+
const cssText = require_customCss.extractCustomCssText(expression, state.api);
|
|
134
|
+
if (cssText != null) {
|
|
135
|
+
const span = ensureSpan(expression.span);
|
|
136
|
+
state.customCssBlocks.push({
|
|
137
|
+
start: span.start,
|
|
138
|
+
end: span.end,
|
|
139
|
+
cssText
|
|
140
|
+
});
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (current.type === "CallExpression" || current.type === "TaggedTemplateExpression") {
|
|
146
|
+
const cssText = require_customCss.extractCustomCssText(current, state.api);
|
|
147
|
+
if (cssText != null) {
|
|
148
|
+
const span = ensureSpan(current.span);
|
|
149
|
+
state.customCssBlocks.push({
|
|
150
|
+
start: span.start,
|
|
151
|
+
end: span.end,
|
|
152
|
+
cssText
|
|
153
|
+
});
|
|
154
|
+
return createVoidExpression(span);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (isPreparedAssignment(current)) {
|
|
158
|
+
const prepared = parsePreparedDefinition(current.expression);
|
|
159
|
+
if (prepared) {
|
|
160
|
+
state.preparedLocal.set(prepared.name, prepared.definition);
|
|
161
|
+
if (state.preparedRuntime.has(prepared.name)) {
|
|
162
|
+
state.needsRuntime = true;
|
|
163
|
+
keepPreparedMarker = true;
|
|
164
|
+
} else return null;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (isPreparedAssignmentExpression(current)) {
|
|
168
|
+
const prepared = parsePreparedDefinition(current);
|
|
169
|
+
if (prepared) {
|
|
170
|
+
state.preparedLocal.set(prepared.name, prepared.definition);
|
|
171
|
+
state.needsRuntime = true;
|
|
172
|
+
keepPreparedMarker = true;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (state.classNameMapper && !context.inModuleSpecifier) {
|
|
176
|
+
if (current.type === "StringLiteral") {
|
|
177
|
+
const literal = current;
|
|
178
|
+
const rewritten = require_classname.rewriteClassNameTokensWithMap(literal.value, mapToken);
|
|
179
|
+
if (rewritten !== literal.value) {
|
|
180
|
+
literal.value = rewritten;
|
|
181
|
+
literal.raw = JSON.stringify(rewritten);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (current.type === "TemplateLiteral" && Array.isArray(current.expressions) && current.expressions.length === 0 && Array.isArray(current.quasis) && current.quasis.length) {
|
|
185
|
+
const firstQuasi = current.quasis[0];
|
|
186
|
+
if (firstQuasi) {
|
|
187
|
+
const cooked = firstQuasi.cooked ?? "";
|
|
188
|
+
const rewritten = require_classname.rewriteClassNameTokensWithMap(cooked, mapToken);
|
|
189
|
+
if (rewritten !== cooked) {
|
|
190
|
+
firstQuasi.cooked = rewritten;
|
|
191
|
+
firstQuasi.raw = rewritten;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
const isBossElement = current.type === "JSXElement" && isBossJsxElement(current);
|
|
197
|
+
const isBossMarkerCall = (() => {
|
|
198
|
+
if (current.type !== "CallExpression") return false;
|
|
199
|
+
const call = current;
|
|
200
|
+
if (call.callee.type !== "MemberExpression") return false;
|
|
201
|
+
if (call.callee.object?.type !== "Identifier" || call.callee.object.value !== "$$") return false;
|
|
202
|
+
if (call.callee.property?.type !== "Identifier" || call.callee.property.value !== "$") return false;
|
|
203
|
+
return true;
|
|
204
|
+
})();
|
|
205
|
+
for (const key of Object.keys(current)) {
|
|
206
|
+
let childContext = context.inJsxChild && current.type !== "JSXElement" ? {
|
|
207
|
+
...context,
|
|
208
|
+
inJsxChild: false
|
|
209
|
+
} : context;
|
|
210
|
+
if (isBossElement) childContext = {
|
|
211
|
+
...childContext,
|
|
212
|
+
inBossElement: true
|
|
213
|
+
};
|
|
214
|
+
if (current.type === "JSXElement" && key === "children") childContext = {
|
|
215
|
+
...childContext,
|
|
216
|
+
inJsxChild: true
|
|
217
|
+
};
|
|
218
|
+
if (keepPreparedMarker) {
|
|
219
|
+
if (current.type === "ExpressionStatement" && key === "expression") childContext = {
|
|
220
|
+
...childContext,
|
|
221
|
+
keepBossMarker: true
|
|
222
|
+
};
|
|
223
|
+
if (current.type === "AssignmentExpression" && key === "right") childContext = {
|
|
224
|
+
...childContext,
|
|
225
|
+
keepBossMarker: true
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
if (isBossMarkerCall && key === "callee") childContext = {
|
|
229
|
+
...childContext,
|
|
230
|
+
inBossMarkerCall: true
|
|
231
|
+
};
|
|
232
|
+
if (current.type === "JSXAttribute" && key === "value") {
|
|
233
|
+
const attrName = getJsxAttributeName(current);
|
|
234
|
+
const isBossProp = Boolean(context.inBossElement && attrName && state.api.dictionary.resolve(attrName).descriptor);
|
|
235
|
+
childContext = {
|
|
236
|
+
...childContext,
|
|
237
|
+
inBossPropValue: isBossProp
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
if (current.type === "CallExpression" && key === "arguments") {
|
|
241
|
+
const callee = current.callee;
|
|
242
|
+
const args = current.arguments;
|
|
243
|
+
if (callee.type === "MemberExpression" && callee.object?.type === "Identifier" && callee.object.value === "$$" && callee.property?.type === "Identifier" && callee.property.value === "$" && args.length === 1 && args[0].expression.type === "ObjectExpression") childContext = {
|
|
244
|
+
...childContext,
|
|
245
|
+
inBossPropValue: true
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
if ((current.type === "ImportDeclaration" || current.type === "ExportAllDeclaration" || current.type === "ExportNamedDeclaration") && key === "source") childContext = {
|
|
249
|
+
...childContext,
|
|
250
|
+
inModuleSpecifier: true
|
|
251
|
+
};
|
|
252
|
+
current[key] = await transformNode(current[key], state, childContext);
|
|
253
|
+
}
|
|
254
|
+
if (current.type === "JSXElement") {
|
|
255
|
+
const element = current;
|
|
256
|
+
require_classname.rewriteClassNameTokensInElement(element, state.classNameProp, mapToken);
|
|
257
|
+
return require_jsx.transformJsxElement(element, state, context);
|
|
258
|
+
}
|
|
259
|
+
if (current.type === "CallExpression") {
|
|
260
|
+
const expr = current;
|
|
261
|
+
const callee = expr.callee;
|
|
262
|
+
const isBossMarker = callee.type === "MemberExpression" && callee.object?.type === "Identifier" && callee.object.value === "$$" && callee.property?.type === "Identifier" && callee.property.value === "$";
|
|
263
|
+
if (isBossMarker && context.keepBossMarker) return current;
|
|
264
|
+
if (isBossMarker && expr.arguments.length === 1 && expr.arguments[0].expression.type === "ObjectExpression") return expr.arguments[0].expression;
|
|
265
|
+
if (isBossMarker && expr.arguments.length === 1) {
|
|
266
|
+
const arg = expr.arguments[0].expression;
|
|
267
|
+
if (arg.type === "StringLiteral") {
|
|
268
|
+
const rewritten = require_classname.rewriteClassNameTokensWithMap(arg.value, mapToken);
|
|
269
|
+
arg.value = rewritten;
|
|
270
|
+
arg.raw = JSON.stringify(rewritten);
|
|
271
|
+
} else if (arg.type === "TemplateLiteral" && arg.expressions.length === 0) {
|
|
272
|
+
const rewritten = require_classname.rewriteClassNameTokensWithMap(arg.quasis[0].cooked ?? "", mapToken);
|
|
273
|
+
arg.quasis[0].cooked = rewritten;
|
|
274
|
+
arg.quasis[0].raw = rewritten;
|
|
275
|
+
}
|
|
276
|
+
return arg;
|
|
277
|
+
}
|
|
278
|
+
if (callee.type === "Identifier" && callee.value === "$$") state.needsRuntime = true;
|
|
279
|
+
}
|
|
280
|
+
if (current.type === "MemberExpression") {
|
|
281
|
+
if (context.inBossPropValue) return current;
|
|
282
|
+
if (context.inBossMarkerCall) return current;
|
|
283
|
+
const member = current;
|
|
284
|
+
if (member.object?.type === "Identifier" && member.object.value === "$$") state.needsRuntime = true;
|
|
285
|
+
}
|
|
286
|
+
return current;
|
|
287
|
+
};
|
|
288
|
+
const isBossJsxElement = (node) => {
|
|
289
|
+
const name = node.opening.name;
|
|
290
|
+
if (name.type === "Identifier" && name.value === "$$") return true;
|
|
291
|
+
if (name.type === "JSXMemberExpression" && name.object.type === "Identifier" && name.object.value === "$$") return true;
|
|
292
|
+
return false;
|
|
293
|
+
};
|
|
294
|
+
const getJsxAttributeName = (node) => {
|
|
295
|
+
if (node.name?.type === "Identifier") return node.name.value;
|
|
296
|
+
return null;
|
|
297
|
+
};
|
|
298
|
+
const createRuntimeHelpersProgram = ({ unit, prefix, needsValueHelper, needsTokenVarsHelper }) => {
|
|
299
|
+
const imports = [];
|
|
300
|
+
const lines = [];
|
|
301
|
+
if (needsValueHelper) {
|
|
302
|
+
imports.push("createBossValue");
|
|
303
|
+
lines.push(`const __bossValue = createBossValue(${JSON.stringify(unit)});`);
|
|
304
|
+
}
|
|
305
|
+
if (needsTokenVarsHelper) {
|
|
306
|
+
imports.push("createBossTokenVars");
|
|
307
|
+
lines.push(`const __bossTokenVars = createBossTokenVars(${JSON.stringify(unit)}, ${JSON.stringify(prefix)});`);
|
|
308
|
+
}
|
|
309
|
+
return (0, _swc_core.parseSync)(`import { ${imports.join(", ")} } from "boss-css/compile/runtime";
|
|
310
|
+
${lines.join("\n")}`, { syntax: "ecmascript" });
|
|
311
|
+
};
|
|
312
|
+
const hasValueHelper = (program) => {
|
|
313
|
+
if (!("body" in program)) return false;
|
|
314
|
+
return program.body.some((node) => {
|
|
315
|
+
if (node.type !== "VariableDeclaration") return false;
|
|
316
|
+
return node.declarations.some((decl) => decl.id.type === "Identifier" && decl.id.value === "__bossValue");
|
|
317
|
+
});
|
|
318
|
+
};
|
|
319
|
+
const hasTokenVarsHelper = (program) => {
|
|
320
|
+
if (!("body" in program)) return false;
|
|
321
|
+
return program.body.some((node) => {
|
|
322
|
+
if (node.type !== "VariableDeclaration") return false;
|
|
323
|
+
return node.declarations.some((decl) => decl.id.type === "Identifier" && decl.id.value === "__bossTokenVars");
|
|
324
|
+
});
|
|
325
|
+
};
|
|
326
|
+
const isBossImport = (source) => {
|
|
327
|
+
if (source === "boss-css/compile/runtime") return false;
|
|
328
|
+
return source.includes(".bo$$/server") || source === "boss-css" || source.startsWith("boss-css/") || source === "boss-css/parser/jsx/runtime" || source === "boss-css/runtime" || source.startsWith("boss-css/runtime/") || source.startsWith("@boss-css/");
|
|
329
|
+
};
|
|
330
|
+
const isPreparedAssignmentExpression = (node) => {
|
|
331
|
+
if (node.type !== "AssignmentExpression") return false;
|
|
332
|
+
const assignment = node;
|
|
333
|
+
if (assignment.operator && assignment.operator !== "=") return false;
|
|
334
|
+
const left = assignment.left;
|
|
335
|
+
if (!left || left.type !== "MemberExpression") return false;
|
|
336
|
+
if (left.object?.type !== "Identifier" || left.object.value !== "$$") return false;
|
|
337
|
+
const property = left.property;
|
|
338
|
+
if (!property || property.type !== "Identifier") return false;
|
|
339
|
+
if (!property.value || !/^[A-Z]/.test(property.value)) return false;
|
|
340
|
+
return Boolean(assignment.right && getPreparedObjectExpression(assignment.right));
|
|
341
|
+
};
|
|
342
|
+
const isPreparedAssignment = (node) => {
|
|
343
|
+
if (node.type !== "ExpressionStatement") return false;
|
|
344
|
+
const statement = node;
|
|
345
|
+
return Boolean(statement.expression && isPreparedAssignmentExpression(statement.expression));
|
|
346
|
+
};
|
|
347
|
+
const parsePreparedDefinition = (expression) => {
|
|
348
|
+
const assignment = expression;
|
|
349
|
+
const name = assignment.left?.property?.value;
|
|
350
|
+
const objectExpression = assignment.right ? getPreparedObjectExpression(assignment.right) : null;
|
|
351
|
+
if (!name || !objectExpression) return null;
|
|
352
|
+
const definition = require_jsx.buildPreparedDefinition(objectExpression);
|
|
353
|
+
if (!definition) return null;
|
|
354
|
+
return {
|
|
355
|
+
name,
|
|
356
|
+
definition
|
|
357
|
+
};
|
|
358
|
+
};
|
|
359
|
+
const getPreparedObjectExpression = (expression) => {
|
|
360
|
+
if (expression.type === "CallExpression" && expression.arguments.length === 1) {
|
|
361
|
+
const callee = expression.callee;
|
|
362
|
+
if (callee.type === "MemberExpression" && callee.object?.type === "Identifier" && callee.object.value === "$$" && callee.property?.type === "Identifier" && callee.property.value === "$") {
|
|
363
|
+
const arg = expression.arguments[0].expression;
|
|
364
|
+
if (arg.type === "ObjectExpression") return arg;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return null;
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
//#endregion
|
|
371
|
+
exports.transformSource = transformSource;
|