@jesscss/plugin-less-compat 2.0.0-alpha.7 → 2.0.0-alpha.9
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 +34 -122
- package/lib/index.cjs +13 -821
- package/lib/index.d.ts +0 -3
- package/lib/index.js +15 -786
- package/lib/plugin.d.ts +17 -109
- package/package.json +5 -15
- package/lib/less-adapter.cjs +0 -216
- package/lib/less-adapter.js +0 -181
- package/lib/less-compat-structures.cjs +0 -378
- package/lib/less-compat-structures.d.ts +0 -108
- package/lib/less-compat-structures.js +0 -374
- package/lib/nodes/at-rule.d.ts +0 -2
- package/lib/nodes/attribute-selector.d.ts +0 -2
- package/lib/nodes/call.d.ts +0 -2
- package/lib/nodes/color.d.ts +0 -2
- package/lib/nodes/combinator.d.ts +0 -2
- package/lib/nodes/comment.d.ts +0 -2
- package/lib/nodes/condition.d.ts +0 -2
- package/lib/nodes/declaration.d.ts +0 -2
- package/lib/nodes/dimension.d.ts +0 -2
- package/lib/nodes/expression.d.ts +0 -2
- package/lib/nodes/extend.d.ts +0 -2
- package/lib/nodes/import.d.ts +0 -2
- package/lib/nodes/index.d.ts +0 -45
- package/lib/nodes/keyword.d.ts +0 -2
- package/lib/nodes/list.d.ts +0 -3
- package/lib/nodes/mixin.d.ts +0 -2
- package/lib/nodes/negative.d.ts +0 -2
- package/lib/nodes/operation.d.ts +0 -2
- package/lib/nodes/paren.d.ts +0 -2
- package/lib/nodes/quoted.d.ts +0 -2
- package/lib/nodes/reference.d.ts +0 -2
- package/lib/nodes/ruleset.d.ts +0 -2
- package/lib/nodes/selector.d.ts +0 -3
- package/lib/nodes/sequence.d.ts +0 -2
- package/lib/nodes/url.d.ts +0 -2
- package/lib/nodes/var-declaration.d.ts +0 -2
- package/lib/plugin-utils.d.ts +0 -20
- package/lib/transform/adapter.d.ts +0 -31
- package/lib/transform/from-less.d.ts +0 -30
- package/lib/transform/index.cjs +0 -13
- package/lib/transform/index.d.ts +0 -7
- package/lib/transform/index.js +0 -3
- package/lib/transform/less-adapter.d.ts +0 -29
- package/lib/transform/to-less.d.ts +0 -17
- package/lib/transform/type-map.d.ts +0 -27
- package/lib/transform.cjs +0 -1045
- package/lib/transform.js +0 -1015
- package/lib/types.d.ts +0 -158
package/lib/plugin.d.ts
CHANGED
|
@@ -1,120 +1,28 @@
|
|
|
1
|
-
import { AbstractPlugin, type
|
|
2
|
-
import type {
|
|
3
|
-
|
|
1
|
+
import { AbstractPlugin, type Context } from '@jesscss/core';
|
|
2
|
+
import type { Fn } from '@jesscss/core/value';
|
|
3
|
+
/**
|
|
4
|
+
* Native AST-v2 functions contributed by an application. Function bodies receive
|
|
5
|
+
* typed value objects and the narrow `FnCtx` capability supplied by core; they
|
|
6
|
+
* never receive Less tree nodes or a legacy evaluation context.
|
|
7
|
+
*/
|
|
4
8
|
export interface LessCompatPluginOptions {
|
|
5
|
-
|
|
6
|
-
* Less 4.x custom functions registered through the root
|
|
7
|
-
* `less.functions.functionRegistry.add/addMultiple` API. Keyed by function
|
|
8
|
-
* name; each is bridged onto every compiled tree's root scope so calls resolve
|
|
9
|
-
* during evaluation, exactly like the built-in Less functions.
|
|
10
|
-
*/
|
|
11
|
-
functions?: Record<string, (...args: any[]) => any>;
|
|
12
|
-
/**
|
|
13
|
-
* Less.js plugins - these will have their install() method called to extract visitors.
|
|
14
|
-
* Can be mixed with Jess plugins - Less plugins will be handled by this compat layer,
|
|
15
|
-
* Jess plugins will be passed through.
|
|
16
|
-
*/
|
|
17
|
-
plugins?: any[];
|
|
18
|
-
/**
|
|
19
|
-
* @deprecated Less.js Visitor API - Less.js visitor implementations (advanced - use plugins instead).
|
|
20
|
-
* This is for compatibility with Less.js visitor patterns. Prefer using Jess's native Visitor interface.
|
|
21
|
-
*/
|
|
22
|
-
visitors?: LessVisitor[];
|
|
23
|
-
/** Enable conversion caching (default: true) */
|
|
24
|
-
cache?: boolean;
|
|
25
|
-
/**
|
|
26
|
-
* Plugin registry for deprecated @plugin directive support.
|
|
27
|
-
* Maps plugin names/paths to plugin instances or factory functions.
|
|
28
|
-
* Used when processing @plugin directives in the source.
|
|
29
|
-
*
|
|
30
|
-
* @deprecated Less @plugin is deprecated. Prefer @use / @-use for script integration in .less files.
|
|
31
|
-
*/
|
|
32
|
-
pluginRegistry?: Record<string, any>;
|
|
33
|
-
/**
|
|
34
|
-
* Enable auto-loading of deprecated @plugin plugins by name (Less.js 4.x CLI behavior).
|
|
35
|
-
* When true (default), @plugin directives will attempt to require/import
|
|
36
|
-
* plugins by their npm package name (e.g., "less-plugin-autoprefix").
|
|
37
|
-
* Set to false to disable and only use pluginRegistry.
|
|
38
|
-
*
|
|
39
|
-
* @deprecated Less @plugin is deprecated. Prefer @use / @-use for script integration in .less files.
|
|
40
|
-
*/
|
|
41
|
-
autoLoadPlugins?: boolean;
|
|
42
|
-
/**
|
|
43
|
-
* Reference to the node-modules plugin for npm package resolution.
|
|
44
|
-
* If provided, will be used to resolve npm packages.
|
|
45
|
-
* If not provided, will try to use require() directly.
|
|
46
|
-
*/
|
|
47
|
-
nodeModulesPlugin?: NodeModulesPlugin;
|
|
9
|
+
readonly functions?: readonly Fn[];
|
|
48
10
|
}
|
|
49
11
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
12
|
+
* Transitional package boundary for applications that previously installed the
|
|
13
|
+
* Less compatibility plugin. It contributes only native AST-v2 `Fn` values.
|
|
14
|
+
*
|
|
15
|
+
* Less 4 visitor hooks, `functionRegistry` callbacks, and `@plugin` script
|
|
16
|
+
* execution were legacy tree-runtime APIs. They are intentionally unsupported
|
|
17
|
+
* on the public AST-v2 compiler route: preserving them would require a second
|
|
18
|
+
* evaluator and Node-to-Less/ Less-to-Node conversion bridge.
|
|
52
19
|
*/
|
|
53
20
|
export declare class LessCompatPlugin extends AbstractPlugin {
|
|
54
|
-
opts: LessCompatPluginOptions;
|
|
21
|
+
readonly opts: LessCompatPluginOptions;
|
|
55
22
|
name: string;
|
|
56
|
-
private _cachedVisitor;
|
|
57
|
-
private _lessPluginManager?;
|
|
58
|
-
private _currentFilePath?;
|
|
59
|
-
private _jessFunctionRegistry?;
|
|
60
|
-
private _context?;
|
|
61
|
-
/** Trees whose root scope already received the configured root functions. */
|
|
62
|
-
private _fnRegisteredTrees;
|
|
63
23
|
constructor(opts?: LessCompatPluginOptions);
|
|
64
|
-
|
|
65
|
-
* Return the visitor through the early visitor hook so it runs before
|
|
66
|
-
* evaluation. This keeps Less plugin visitors and preprocessors early without
|
|
67
|
-
* bringing back a public node preparation pass.
|
|
68
|
-
*
|
|
69
|
-
* Less plugins can register visitors via:
|
|
70
|
-
* - addVisitor() - these run early by default
|
|
71
|
-
* - addPreProcessor() - these run early
|
|
72
|
-
* - addPostProcessor() - these run on serialized CSS after render
|
|
73
|
-
*/
|
|
74
|
-
get beforeEvalVisitor(): PluginInterface['beforeEvalVisitor'];
|
|
75
|
-
/**
|
|
76
|
-
* Less post-processors operate on final CSS, not on the preRenderVisitor tree hook.
|
|
77
|
-
*/
|
|
78
|
-
get postEvalVisitor(): PluginInterface['postEvalVisitor'];
|
|
79
|
-
runPostProcessors(css: string, extra?: Record<string, any>): string;
|
|
80
|
-
setCurrentFilePath(filePath: string): void;
|
|
81
|
-
setContext(context: any): void;
|
|
82
|
-
private createJessFunctionBindingRegistry;
|
|
83
|
-
private hasConfiguredBeforeEvalWork;
|
|
84
|
-
private sourceMayContainPluginDirective;
|
|
85
|
-
private treeContainsPluginDirective;
|
|
86
|
-
private warnForPluginDirective;
|
|
87
|
-
private markPluginDirectiveInvisible;
|
|
88
|
-
private registerDenoLessPluginFunctions;
|
|
89
|
-
private loadLessPluginFileWithDeno;
|
|
90
|
-
beforeEvalVisitorForTree(tree: Rules): PluginInterface['beforeEvalVisitor'];
|
|
91
|
-
/**
|
|
92
|
-
* Register the configured Less 4.x root functions onto a parsed tree's root
|
|
93
|
-
* scope, using the same `setFunctionBinding` mechanism the Less plugin uses
|
|
94
|
-
* for built-ins. Idempotent per tree.
|
|
95
|
-
*/
|
|
96
|
-
private registerRootFunctions;
|
|
97
|
-
/**
|
|
98
|
-
* Filter and separate Less plugins from Jess plugins
|
|
99
|
-
* This allows mixed plugin arrays to be handled correctly
|
|
100
|
-
*
|
|
101
|
-
* @deprecated Use filterPlugins from './plugin-utils.js' instead
|
|
102
|
-
*/
|
|
103
|
-
static filterLessPlugins(plugins: any[]): {
|
|
104
|
-
lessPlugins: any[];
|
|
105
|
-
jessPlugins: PluginInterface[];
|
|
106
|
-
};
|
|
107
|
-
/**
|
|
108
|
-
* Return a visitor that wraps Less visitors
|
|
109
|
-
*
|
|
110
|
-
* This visitor intercepts each node, converts it to Less format,
|
|
111
|
-
* runs the Less visitors, and converts back if modified.
|
|
112
|
-
*/
|
|
113
|
-
get visitor(): PluginVisitor | PluginVisitor[] | undefined;
|
|
24
|
+
setContext(context: Context): void;
|
|
114
25
|
}
|
|
115
|
-
/**
|
|
116
|
-
* Create a Less.js compatibility plugin
|
|
117
|
-
*/
|
|
118
26
|
declare const lessCompatPlugin: (opts?: LessCompatPluginOptions) => LessCompatPlugin;
|
|
119
27
|
export default lessCompatPlugin;
|
|
120
28
|
export { lessCompatPlugin };
|
package/package.json
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"description": "
|
|
7
|
-
"version": "2.0.0-alpha.
|
|
6
|
+
"description": "AST-v2 native function contribution plugin for Jess",
|
|
7
|
+
"version": "2.0.0-alpha.9",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"main": "lib/index.cjs",
|
|
10
10
|
"types": "lib/index.d.ts",
|
|
@@ -14,25 +14,15 @@
|
|
|
14
14
|
"import": "./lib/index.js",
|
|
15
15
|
"require": "./lib/index.cjs"
|
|
16
16
|
},
|
|
17
|
-
"./transform": {
|
|
18
|
-
"types": "./lib/transform/index.d.ts",
|
|
19
|
-
"import": "./lib/transform/index.js",
|
|
20
|
-
"require": "./lib/transform/index.cjs"
|
|
21
|
-
},
|
|
22
|
-
"./less-compat-structures": {
|
|
23
|
-
"types": "./lib/less-compat-structures.d.ts",
|
|
24
|
-
"import": "./lib/less-compat-structures.js",
|
|
25
|
-
"require": "./lib/less-compat-structures.cjs"
|
|
26
|
-
},
|
|
27
17
|
"./package.json": "./package.json"
|
|
28
18
|
},
|
|
29
19
|
"files": [
|
|
30
20
|
"lib"
|
|
31
21
|
],
|
|
32
22
|
"dependencies": {
|
|
33
|
-
"@jesscss/core": "2.0.0-alpha.
|
|
34
|
-
"@jesscss/
|
|
35
|
-
"@jesscss/
|
|
23
|
+
"@jesscss/core": "2.0.0-alpha.9",
|
|
24
|
+
"@jesscss/less-parser": "2.0.0-alpha.9",
|
|
25
|
+
"@jesscss/plugin-node-modules": "2.0.0-alpha.9"
|
|
36
26
|
},
|
|
37
27
|
"devDependencies": {
|
|
38
28
|
"less-plugin-autoprefix": "^2.0.0",
|
package/lib/less-adapter.cjs
DELETED
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
//#region src/transform/type-map.ts
|
|
2
|
-
/**
|
|
3
|
-
* Type mapping utilities for converting between Jess and Less node types
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Map Jess node types to Less node types
|
|
7
|
-
*
|
|
8
|
-
* @param jessType - The Jess node type
|
|
9
|
-
* @returns The corresponding Less node type
|
|
10
|
-
*/
|
|
11
|
-
function mapJessTypeToLessType(jessType) {
|
|
12
|
-
return {
|
|
13
|
-
Ruleset: "Ruleset",
|
|
14
|
-
Declaration: "Declaration",
|
|
15
|
-
SelectorList: "Selector",
|
|
16
|
-
ComplexSelector: "Selector",
|
|
17
|
-
CompoundSelector: "Selector",
|
|
18
|
-
BasicSelector: "Element",
|
|
19
|
-
Combinator: "Combinator",
|
|
20
|
-
AttributeSelector: "Attribute",
|
|
21
|
-
Dimension: "Dimension",
|
|
22
|
-
Num: "Dimension",
|
|
23
|
-
Reference: "Variable",
|
|
24
|
-
Mixin: "MixinDefinition",
|
|
25
|
-
Call: "Call",
|
|
26
|
-
Operation: "Operation",
|
|
27
|
-
Expression: "Expression",
|
|
28
|
-
Sequence: "Expression",
|
|
29
|
-
Quoted: "Quoted",
|
|
30
|
-
Url: "URL",
|
|
31
|
-
Color: "Color",
|
|
32
|
-
Comment: "Comment",
|
|
33
|
-
AtRule: "AtRule",
|
|
34
|
-
StyleImport: "Import",
|
|
35
|
-
Extend: "Extend",
|
|
36
|
-
Condition: "Condition",
|
|
37
|
-
Paren: "Paren",
|
|
38
|
-
Negative: "Negative",
|
|
39
|
-
List: "Value",
|
|
40
|
-
VarDeclaration: "Assignment",
|
|
41
|
-
Keyword: "Keyword"
|
|
42
|
-
}[jessType] || jessType;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Map Less node types to Jess node types
|
|
46
|
-
*
|
|
47
|
-
* @param lessType - The Less node type
|
|
48
|
-
* @returns The corresponding Jess node type
|
|
49
|
-
*/
|
|
50
|
-
function mapLessTypeToJessType(lessType) {
|
|
51
|
-
return {
|
|
52
|
-
Ruleset: "Ruleset",
|
|
53
|
-
Declaration: "Declaration",
|
|
54
|
-
Selector: "SelectorList",
|
|
55
|
-
Element: "BasicSelector",
|
|
56
|
-
Combinator: "Combinator",
|
|
57
|
-
Attribute: "AttributeSelector",
|
|
58
|
-
Dimension: "Dimension",
|
|
59
|
-
Variable: "Reference",
|
|
60
|
-
Property: "Reference",
|
|
61
|
-
VariableCall: "Reference",
|
|
62
|
-
MixinDefinition: "Mixin",
|
|
63
|
-
MixinCall: "Call",
|
|
64
|
-
Call: "Call",
|
|
65
|
-
Operation: "Operation",
|
|
66
|
-
Expression: "Expression",
|
|
67
|
-
Quoted: "Quoted",
|
|
68
|
-
URL: "Url",
|
|
69
|
-
Color: "Color",
|
|
70
|
-
Comment: "Comment",
|
|
71
|
-
AtRule: "AtRule",
|
|
72
|
-
Directive: "AtRule",
|
|
73
|
-
Rule: "Declaration",
|
|
74
|
-
Import: "StyleImport",
|
|
75
|
-
Extend: "Extend",
|
|
76
|
-
Condition: "Condition",
|
|
77
|
-
Paren: "Paren",
|
|
78
|
-
Negative: "Negative",
|
|
79
|
-
Value: "List",
|
|
80
|
-
Assignment: "VarDeclaration",
|
|
81
|
-
Keyword: "Keyword"
|
|
82
|
-
}[lessType] || lessType;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Get Less typeIndex for a Jess node type
|
|
86
|
-
*
|
|
87
|
-
* Less.js uses typeIndex for visitor caching. This function
|
|
88
|
-
* maps Jess types to their corresponding Less typeIndex values.
|
|
89
|
-
*
|
|
90
|
-
* @param jessType - The Jess node type
|
|
91
|
-
* @returns The Less typeIndex, or undefined if not found
|
|
92
|
-
*/
|
|
93
|
-
function getLessTypeIndex$1(_jessType) {}
|
|
94
|
-
//#endregion
|
|
95
|
-
//#region src/transform/less-adapter.ts
|
|
96
|
-
const LESS_ADAPTER_SYMBOL = Symbol("less-adapter");
|
|
97
|
-
const JESS_NODE_SYMBOL = Symbol("jess-node");
|
|
98
|
-
const ACTIVE_ADAPTATIONS = /* @__PURE__ */ new WeakSet();
|
|
99
|
-
function getLessTypeIndex(_lessType) {}
|
|
100
|
-
function normalizeField(field) {
|
|
101
|
-
if (typeof field === "function") return { get: field };
|
|
102
|
-
return field;
|
|
103
|
-
}
|
|
104
|
-
var LessAdapterBase = class {
|
|
105
|
-
[LESS_ADAPTER_SYMBOL] = true;
|
|
106
|
-
[JESS_NODE_SYMBOL];
|
|
107
|
-
constructor(node) {
|
|
108
|
-
this[JESS_NODE_SYMBOL] = node;
|
|
109
|
-
Object.defineProperty(this, "__jessNode", {
|
|
110
|
-
enumerable: false,
|
|
111
|
-
configurable: false,
|
|
112
|
-
writable: false,
|
|
113
|
-
value: node
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
get jessNode() {
|
|
117
|
-
return this.__jessNode;
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
var LessNodeAdapter = class extends LessAdapterBase {
|
|
121
|
-
lessType;
|
|
122
|
-
cache;
|
|
123
|
-
acceptImpl;
|
|
124
|
-
constructor(node, definition, cache) {
|
|
125
|
-
super(node);
|
|
126
|
-
this.lessType = definition.lessType;
|
|
127
|
-
this.cache = cache;
|
|
128
|
-
this.acceptImpl = definition.accept;
|
|
129
|
-
Object.defineProperties(this, {
|
|
130
|
-
type: {
|
|
131
|
-
enumerable: true,
|
|
132
|
-
configurable: true,
|
|
133
|
-
get: () => {
|
|
134
|
-
if (typeof this.lessType === "function") return this.lessType(this.jessNode);
|
|
135
|
-
return this.lessType ?? mapJessTypeToLessType(this.jessNode.type);
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
typeIndex: {
|
|
139
|
-
enumerable: true,
|
|
140
|
-
configurable: true,
|
|
141
|
-
get: () => {
|
|
142
|
-
return getLessTypeIndex(typeof this.lessType === "function" ? this.lessType(this.jessNode) : this.lessType ?? mapJessTypeToLessType(this.jessNode.type));
|
|
143
|
-
}
|
|
144
|
-
},
|
|
145
|
-
accept: {
|
|
146
|
-
enumerable: false,
|
|
147
|
-
configurable: true,
|
|
148
|
-
value: (visitor) => {
|
|
149
|
-
if (this.acceptImpl) return this.acceptImpl(this.jessNode, visitor, this.cache);
|
|
150
|
-
return this.jessNode;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
for (const [key, rawField] of Object.entries(definition.fields ?? {})) {
|
|
155
|
-
const field = normalizeField(rawField);
|
|
156
|
-
Object.defineProperty(this, key, {
|
|
157
|
-
enumerable: field.enumerable ?? true,
|
|
158
|
-
configurable: true,
|
|
159
|
-
get: () => field.get(this.jessNode, this.cache),
|
|
160
|
-
set: field.set ? (value) => field.set(this.jessNode, value, this.cache) : void 0
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
function createLessAdapter(jessNode, definition, cache) {
|
|
166
|
-
const cached = cache?.get(jessNode);
|
|
167
|
-
if (cached instanceof LessNodeAdapter) return cached;
|
|
168
|
-
ACTIVE_ADAPTATIONS.add(jessNode);
|
|
169
|
-
try {
|
|
170
|
-
const adapter = new LessNodeAdapter(jessNode, definition, cache);
|
|
171
|
-
cache?.set(jessNode, adapter);
|
|
172
|
-
return adapter;
|
|
173
|
-
} finally {
|
|
174
|
-
ACTIVE_ADAPTATIONS.delete(jessNode);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
function isAdaptingNode(node) {
|
|
178
|
-
return ACTIVE_ADAPTATIONS.has(node);
|
|
179
|
-
}
|
|
180
|
-
//#endregion
|
|
181
|
-
Object.defineProperty(exports, "LessAdapterBase", {
|
|
182
|
-
enumerable: true,
|
|
183
|
-
get: function() {
|
|
184
|
-
return LessAdapterBase;
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
Object.defineProperty(exports, "createLessAdapter", {
|
|
188
|
-
enumerable: true,
|
|
189
|
-
get: function() {
|
|
190
|
-
return createLessAdapter;
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
Object.defineProperty(exports, "getLessTypeIndex", {
|
|
194
|
-
enumerable: true,
|
|
195
|
-
get: function() {
|
|
196
|
-
return getLessTypeIndex$1;
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
Object.defineProperty(exports, "isAdaptingNode", {
|
|
200
|
-
enumerable: true,
|
|
201
|
-
get: function() {
|
|
202
|
-
return isAdaptingNode;
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
Object.defineProperty(exports, "mapJessTypeToLessType", {
|
|
206
|
-
enumerable: true,
|
|
207
|
-
get: function() {
|
|
208
|
-
return mapJessTypeToLessType;
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
Object.defineProperty(exports, "mapLessTypeToJessType", {
|
|
212
|
-
enumerable: true,
|
|
213
|
-
get: function() {
|
|
214
|
-
return mapLessTypeToJessType;
|
|
215
|
-
}
|
|
216
|
-
});
|
package/lib/less-adapter.js
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
//#region src/transform/type-map.ts
|
|
2
|
-
/**
|
|
3
|
-
* Type mapping utilities for converting between Jess and Less node types
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Map Jess node types to Less node types
|
|
7
|
-
*
|
|
8
|
-
* @param jessType - The Jess node type
|
|
9
|
-
* @returns The corresponding Less node type
|
|
10
|
-
*/
|
|
11
|
-
function mapJessTypeToLessType(jessType) {
|
|
12
|
-
return {
|
|
13
|
-
Ruleset: "Ruleset",
|
|
14
|
-
Declaration: "Declaration",
|
|
15
|
-
SelectorList: "Selector",
|
|
16
|
-
ComplexSelector: "Selector",
|
|
17
|
-
CompoundSelector: "Selector",
|
|
18
|
-
BasicSelector: "Element",
|
|
19
|
-
Combinator: "Combinator",
|
|
20
|
-
AttributeSelector: "Attribute",
|
|
21
|
-
Dimension: "Dimension",
|
|
22
|
-
Num: "Dimension",
|
|
23
|
-
Reference: "Variable",
|
|
24
|
-
Mixin: "MixinDefinition",
|
|
25
|
-
Call: "Call",
|
|
26
|
-
Operation: "Operation",
|
|
27
|
-
Expression: "Expression",
|
|
28
|
-
Sequence: "Expression",
|
|
29
|
-
Quoted: "Quoted",
|
|
30
|
-
Url: "URL",
|
|
31
|
-
Color: "Color",
|
|
32
|
-
Comment: "Comment",
|
|
33
|
-
AtRule: "AtRule",
|
|
34
|
-
StyleImport: "Import",
|
|
35
|
-
Extend: "Extend",
|
|
36
|
-
Condition: "Condition",
|
|
37
|
-
Paren: "Paren",
|
|
38
|
-
Negative: "Negative",
|
|
39
|
-
List: "Value",
|
|
40
|
-
VarDeclaration: "Assignment",
|
|
41
|
-
Keyword: "Keyword"
|
|
42
|
-
}[jessType] || jessType;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Map Less node types to Jess node types
|
|
46
|
-
*
|
|
47
|
-
* @param lessType - The Less node type
|
|
48
|
-
* @returns The corresponding Jess node type
|
|
49
|
-
*/
|
|
50
|
-
function mapLessTypeToJessType(lessType) {
|
|
51
|
-
return {
|
|
52
|
-
Ruleset: "Ruleset",
|
|
53
|
-
Declaration: "Declaration",
|
|
54
|
-
Selector: "SelectorList",
|
|
55
|
-
Element: "BasicSelector",
|
|
56
|
-
Combinator: "Combinator",
|
|
57
|
-
Attribute: "AttributeSelector",
|
|
58
|
-
Dimension: "Dimension",
|
|
59
|
-
Variable: "Reference",
|
|
60
|
-
Property: "Reference",
|
|
61
|
-
VariableCall: "Reference",
|
|
62
|
-
MixinDefinition: "Mixin",
|
|
63
|
-
MixinCall: "Call",
|
|
64
|
-
Call: "Call",
|
|
65
|
-
Operation: "Operation",
|
|
66
|
-
Expression: "Expression",
|
|
67
|
-
Quoted: "Quoted",
|
|
68
|
-
URL: "Url",
|
|
69
|
-
Color: "Color",
|
|
70
|
-
Comment: "Comment",
|
|
71
|
-
AtRule: "AtRule",
|
|
72
|
-
Directive: "AtRule",
|
|
73
|
-
Rule: "Declaration",
|
|
74
|
-
Import: "StyleImport",
|
|
75
|
-
Extend: "Extend",
|
|
76
|
-
Condition: "Condition",
|
|
77
|
-
Paren: "Paren",
|
|
78
|
-
Negative: "Negative",
|
|
79
|
-
Value: "List",
|
|
80
|
-
Assignment: "VarDeclaration",
|
|
81
|
-
Keyword: "Keyword"
|
|
82
|
-
}[lessType] || lessType;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Get Less typeIndex for a Jess node type
|
|
86
|
-
*
|
|
87
|
-
* Less.js uses typeIndex for visitor caching. This function
|
|
88
|
-
* maps Jess types to their corresponding Less typeIndex values.
|
|
89
|
-
*
|
|
90
|
-
* @param jessType - The Jess node type
|
|
91
|
-
* @returns The Less typeIndex, or undefined if not found
|
|
92
|
-
*/
|
|
93
|
-
function getLessTypeIndex$1(_jessType) {}
|
|
94
|
-
//#endregion
|
|
95
|
-
//#region src/transform/less-adapter.ts
|
|
96
|
-
const LESS_ADAPTER_SYMBOL = Symbol("less-adapter");
|
|
97
|
-
const JESS_NODE_SYMBOL = Symbol("jess-node");
|
|
98
|
-
const ACTIVE_ADAPTATIONS = /* @__PURE__ */ new WeakSet();
|
|
99
|
-
function getLessTypeIndex(_lessType) {}
|
|
100
|
-
function normalizeField(field) {
|
|
101
|
-
if (typeof field === "function") return { get: field };
|
|
102
|
-
return field;
|
|
103
|
-
}
|
|
104
|
-
var LessAdapterBase = class {
|
|
105
|
-
[LESS_ADAPTER_SYMBOL] = true;
|
|
106
|
-
[JESS_NODE_SYMBOL];
|
|
107
|
-
constructor(node) {
|
|
108
|
-
this[JESS_NODE_SYMBOL] = node;
|
|
109
|
-
Object.defineProperty(this, "__jessNode", {
|
|
110
|
-
enumerable: false,
|
|
111
|
-
configurable: false,
|
|
112
|
-
writable: false,
|
|
113
|
-
value: node
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
get jessNode() {
|
|
117
|
-
return this.__jessNode;
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
var LessNodeAdapter = class extends LessAdapterBase {
|
|
121
|
-
lessType;
|
|
122
|
-
cache;
|
|
123
|
-
acceptImpl;
|
|
124
|
-
constructor(node, definition, cache) {
|
|
125
|
-
super(node);
|
|
126
|
-
this.lessType = definition.lessType;
|
|
127
|
-
this.cache = cache;
|
|
128
|
-
this.acceptImpl = definition.accept;
|
|
129
|
-
Object.defineProperties(this, {
|
|
130
|
-
type: {
|
|
131
|
-
enumerable: true,
|
|
132
|
-
configurable: true,
|
|
133
|
-
get: () => {
|
|
134
|
-
if (typeof this.lessType === "function") return this.lessType(this.jessNode);
|
|
135
|
-
return this.lessType ?? mapJessTypeToLessType(this.jessNode.type);
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
typeIndex: {
|
|
139
|
-
enumerable: true,
|
|
140
|
-
configurable: true,
|
|
141
|
-
get: () => {
|
|
142
|
-
return getLessTypeIndex(typeof this.lessType === "function" ? this.lessType(this.jessNode) : this.lessType ?? mapJessTypeToLessType(this.jessNode.type));
|
|
143
|
-
}
|
|
144
|
-
},
|
|
145
|
-
accept: {
|
|
146
|
-
enumerable: false,
|
|
147
|
-
configurable: true,
|
|
148
|
-
value: (visitor) => {
|
|
149
|
-
if (this.acceptImpl) return this.acceptImpl(this.jessNode, visitor, this.cache);
|
|
150
|
-
return this.jessNode;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
for (const [key, rawField] of Object.entries(definition.fields ?? {})) {
|
|
155
|
-
const field = normalizeField(rawField);
|
|
156
|
-
Object.defineProperty(this, key, {
|
|
157
|
-
enumerable: field.enumerable ?? true,
|
|
158
|
-
configurable: true,
|
|
159
|
-
get: () => field.get(this.jessNode, this.cache),
|
|
160
|
-
set: field.set ? (value) => field.set(this.jessNode, value, this.cache) : void 0
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
function createLessAdapter(jessNode, definition, cache) {
|
|
166
|
-
const cached = cache?.get(jessNode);
|
|
167
|
-
if (cached instanceof LessNodeAdapter) return cached;
|
|
168
|
-
ACTIVE_ADAPTATIONS.add(jessNode);
|
|
169
|
-
try {
|
|
170
|
-
const adapter = new LessNodeAdapter(jessNode, definition, cache);
|
|
171
|
-
cache?.set(jessNode, adapter);
|
|
172
|
-
return adapter;
|
|
173
|
-
} finally {
|
|
174
|
-
ACTIVE_ADAPTATIONS.delete(jessNode);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
function isAdaptingNode(node) {
|
|
178
|
-
return ACTIVE_ADAPTATIONS.has(node);
|
|
179
|
-
}
|
|
180
|
-
//#endregion
|
|
181
|
-
export { mapJessTypeToLessType as a, getLessTypeIndex$1 as i, createLessAdapter as n, mapLessTypeToJessType as o, isAdaptingNode as r, LessAdapterBase as t };
|