oxfmt 0.32.0 → 0.34.0
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/configuration_schema.json +51 -6
- package/dist/{postcss-DKPxyBch.js → angular-DdA9f8ZK.js} +7 -6
- package/dist/{apis-6GJvrGdK.js → apis-Ddb0m55g.js} +4 -4
- package/dist/babel-CmMxKXKi.js +3 -0
- package/dist/{bindings-DuRSBSH9.js → bindings-DTOgpISZ.js} +26 -26
- package/dist/{chunk-DSjvVL_1-DGPqLkX8.js → chunk-DSjvVL_1-K7gBHu1i.js} +1 -1
- package/dist/cli-worker.d.ts +1 -1
- package/dist/cli-worker.js +1 -1
- package/dist/cli.js +5 -4
- package/dist/{babel-CX7YS1y4.js → dist-DQgkZSFc.js} +5160 -1
- package/dist/index.d.ts +9 -4
- package/dist/index.js +2 -2
- package/dist/{v4-C_IPPFom-CzWZrmWL.js → jiti-Bb1dT6Cw-CP1_dUF7.js} +3 -10755
- package/dist/{migrate-prettier-CRIoVxnG.js → migrate-prettier-CPi8N90o.js} +1 -1
- package/dist/postcss-D79LfgjO.js +3 -0
- package/dist/{prettier-iX8V55ba.js → prettier-DIVejRqd.js} +14 -14
- package/dist/{prettier-plugin-oxfmt-CTfSH0ez.js → prettier-plugin-oxfmt-CI1pYfTP.js} +3 -3
- package/dist/{resolve-pWjAK-4f-BDpC233X.js → resolve-pWjAK-4f-YzJRPmwZ.js} +2 -2
- package/dist/{sorter-VB3XW2i_-BpFugw-x.js → sorter-BZkvDMjt-CiG199np.js} +6 -6
- package/dist/sorter-CjGwXe5x.js +5 -0
- package/dist/{utils-D8dQkKEd-Dq0tCGW_.js → utils-D8dQkKEd-bSmL59ud.js} +1 -1
- package/dist/v3-D-mr2VVh-DAVD4LOh.js +16709 -0
- package/dist/v4-C-HWEQJm-DOWhMvfI.js +10759 -0
- package/package.json +20 -20
- package/dist/angular-9UbP57Ow.js +0 -3952
- package/dist/dist-D3CWjTTc.js +0 -1151
- package/dist/sorter-DnKClyKU.js +0 -5
- package/dist/v3-RIpeMkdf-CHWXIFE7.js +0 -79883
- /package/dist/{acorn-DTid_xfu.js → acorn-DSYDYt2u.js} +0 -0
- /package/dist/{estree-vodXR09f.js → estree-DBPlpXot.js} +0 -0
- /package/dist/{flow-D6joRvfg.js → flow-DZRswbuH.js} +0 -0
- /package/dist/{glimmer-CDzFnA-R.js → glimmer-B28TNYIB.js} +0 -0
- /package/dist/{graphql-DQKSu6tT.js → graphql-3p9xuuKy.js} +0 -0
- /package/dist/{html-CRvdkeeP.js → html-D2VbMQAT.js} +0 -0
- /package/dist/{index-DgRWzHwv.d.ts → index-BNhsnuYk.d.ts} +0 -0
- /package/dist/{markdown-CDEe6Nm4.js → markdown-DdJpriJP.js} +0 -0
- /package/dist/{meriyah-DSeGVyBs.js → meriyah-CQnZTN4N.js} +0 -0
- /package/dist/{typescript-BFhFx1UJ.js → typescript-D5lCjM2U.js} +0 -0
- /package/dist/{yaml-DXzn9wd5.js → yaml-jtj0ZWQC.js} +0 -0
package/dist/dist-D3CWjTTc.js
DELETED
|
@@ -1,1151 +0,0 @@
|
|
|
1
|
-
import { t as index_exports } from "./prettier-iX8V55ba.js";
|
|
2
|
-
import { a as __toESM, t as __commonJSMin } from "./chunk-DSjvVL_1-DGPqLkX8.js";
|
|
3
|
-
import { n as loadIfExists, r as maybeResolve, t as expiringMap } from "./resolve-pWjAK-4f-BDpC233X.js";
|
|
4
|
-
import { i as visit, n as cacheForDirs, r as spliceChangesIntoString } from "./utils-D8dQkKEd-Dq0tCGW_.js";
|
|
5
|
-
import { a as sortClasses, i as sortClassList, n as error, o as warn, r as getTailwindConfig$1 } from "./sorter-VB3XW2i_-BpFugw-x.js";
|
|
6
|
-
import { parsers as sn } from "./angular-9UbP57Ow.js";
|
|
7
|
-
import { parsers as ra, t as babel_exports } from "./babel-CX7YS1y4.js";
|
|
8
|
-
import { parsers as en, t as postcss_exports } from "./postcss-DKPxyBch.js";
|
|
9
|
-
import * as path from "node:path";
|
|
10
|
-
import { isAbsolute } from "path";
|
|
11
|
-
|
|
12
|
-
//#region ../../node_modules/.pnpm/prettier-plugin-tailwindcss@0.0.0-insiders.2ac6e70_prettier@3.8.1/node_modules/prettier-plugin-tailwindcss/dist/index.mjs
|
|
13
|
-
var require_isarray = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
14
|
-
var toString = {}.toString;
|
|
15
|
-
module.exports = Array.isArray || function(arr) {
|
|
16
|
-
return toString.call(arr) == "[object Array]";
|
|
17
|
-
};
|
|
18
|
-
}));
|
|
19
|
-
/*!
|
|
20
|
-
* isobject <https://github.com/jonschlinkert/isobject>
|
|
21
|
-
*
|
|
22
|
-
* Copyright (c) 2014-2015, Jon Schlinkert.
|
|
23
|
-
* Licensed under the MIT License.
|
|
24
|
-
*/
|
|
25
|
-
var require_isobject = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
26
|
-
var isArray = require_isarray();
|
|
27
|
-
module.exports = function isObject(val) {
|
|
28
|
-
return val != null && typeof val === "object" && isArray(val) === false;
|
|
29
|
-
};
|
|
30
|
-
}));
|
|
31
|
-
var import_line_column = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
32
|
-
var isArray = require_isarray();
|
|
33
|
-
var isObject = require_isobject();
|
|
34
|
-
Array.prototype.slice;
|
|
35
|
-
module.exports = LineColumnFinder;
|
|
36
|
-
function LineColumnFinder(str, options) {
|
|
37
|
-
if (!(this instanceof LineColumnFinder)) {
|
|
38
|
-
if (typeof options === "number") return new LineColumnFinder(str).fromIndex(options);
|
|
39
|
-
return new LineColumnFinder(str, options);
|
|
40
|
-
}
|
|
41
|
-
this.str = str || "";
|
|
42
|
-
this.lineToIndex = buildLineToIndex(this.str);
|
|
43
|
-
options = options || {};
|
|
44
|
-
this.origin = typeof options.origin === "undefined" ? 1 : options.origin;
|
|
45
|
-
}
|
|
46
|
-
LineColumnFinder.prototype.fromIndex = function(index) {
|
|
47
|
-
if (index < 0 || index >= this.str.length || isNaN(index)) return null;
|
|
48
|
-
var line = findLowerIndexInRangeArray(index, this.lineToIndex);
|
|
49
|
-
return {
|
|
50
|
-
line: line + this.origin,
|
|
51
|
-
col: index - this.lineToIndex[line] + this.origin
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
LineColumnFinder.prototype.toIndex = function(line, column) {
|
|
55
|
-
if (typeof column === "undefined") {
|
|
56
|
-
if (isArray(line) && line.length >= 2) return this.toIndex(line[0], line[1]);
|
|
57
|
-
if (isObject(line) && "line" in line && ("col" in line || "column" in line)) return this.toIndex(line.line, "col" in line ? line.col : line.column);
|
|
58
|
-
return -1;
|
|
59
|
-
}
|
|
60
|
-
if (isNaN(line) || isNaN(column)) return -1;
|
|
61
|
-
line -= this.origin;
|
|
62
|
-
column -= this.origin;
|
|
63
|
-
if (line >= 0 && column >= 0 && line < this.lineToIndex.length) {
|
|
64
|
-
var lineIndex = this.lineToIndex[line];
|
|
65
|
-
var nextIndex = line === this.lineToIndex.length - 1 ? this.str.length : this.lineToIndex[line + 1];
|
|
66
|
-
if (column < nextIndex - lineIndex) return lineIndex + column;
|
|
67
|
-
}
|
|
68
|
-
return -1;
|
|
69
|
-
};
|
|
70
|
-
function buildLineToIndex(str) {
|
|
71
|
-
var lines = str.split("\n"), lineToIndex = new Array(lines.length), index = 0;
|
|
72
|
-
for (var i = 0, l = lines.length; i < l; i++) {
|
|
73
|
-
lineToIndex[i] = index;
|
|
74
|
-
index += lines[i].length + 1;
|
|
75
|
-
}
|
|
76
|
-
return lineToIndex;
|
|
77
|
-
}
|
|
78
|
-
function findLowerIndexInRangeArray(value, arr) {
|
|
79
|
-
if (value >= arr[arr.length - 1]) return arr.length - 1;
|
|
80
|
-
var min = 0, max = arr.length - 2, mid;
|
|
81
|
-
while (min < max) {
|
|
82
|
-
mid = min + (max - min >> 1);
|
|
83
|
-
if (value < arr[mid]) max = mid - 1;
|
|
84
|
-
else if (value >= arr[mid + 1]) min = mid + 1;
|
|
85
|
-
else {
|
|
86
|
-
min = mid;
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return min;
|
|
91
|
-
}
|
|
92
|
-
})))(), 1);
|
|
93
|
-
let prettierConfigCache = expiringMap(1e4);
|
|
94
|
-
async function resolvePrettierConfigDir(filePath, inputDir) {
|
|
95
|
-
let cached = prettierConfigCache.get(inputDir);
|
|
96
|
-
if (cached !== void 0) return cached ?? process.cwd();
|
|
97
|
-
const resolve = async () => {
|
|
98
|
-
try {
|
|
99
|
-
return await index_exports.resolveConfigFile(filePath);
|
|
100
|
-
} catch (err) {
|
|
101
|
-
error("prettier-config-not-found", "Failed to resolve Prettier Config");
|
|
102
|
-
error("prettier-config-not-found-err", err);
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
let prettierConfig = await resolve();
|
|
107
|
-
if (prettierConfig) {
|
|
108
|
-
let configDir = path.dirname(prettierConfig);
|
|
109
|
-
cacheForDirs(prettierConfigCache, inputDir, configDir, configDir);
|
|
110
|
-
return configDir;
|
|
111
|
-
} else {
|
|
112
|
-
prettierConfigCache.set(inputDir, null);
|
|
113
|
-
return process.cwd();
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
async function getTailwindConfig(options) {
|
|
117
|
-
let cwd = process.cwd();
|
|
118
|
-
let inputDir = options.filepath ? path.dirname(options.filepath) : cwd;
|
|
119
|
-
let needsPrettierConfig = options.tailwindConfig && !path.isAbsolute(options.tailwindConfig) || options.tailwindStylesheet && !path.isAbsolute(options.tailwindStylesheet) || options.tailwindEntryPoint && !path.isAbsolute(options.tailwindEntryPoint);
|
|
120
|
-
let configDir;
|
|
121
|
-
if (needsPrettierConfig) configDir = await resolvePrettierConfigDir(options.filepath, inputDir);
|
|
122
|
-
else configDir = cwd;
|
|
123
|
-
let configPath = options.tailwindConfig && !options.tailwindConfig.endsWith(".css") ? options.tailwindConfig : void 0;
|
|
124
|
-
let stylesheetPath = options.tailwindStylesheet;
|
|
125
|
-
if (!stylesheetPath && options.tailwindEntryPoint) {
|
|
126
|
-
warn("entrypoint-is-deprecated", configDir, "Deprecated: Use the `tailwindStylesheet` option for v4 projects instead of `tailwindEntryPoint`.");
|
|
127
|
-
stylesheetPath = options.tailwindEntryPoint;
|
|
128
|
-
}
|
|
129
|
-
if (!stylesheetPath && options.tailwindConfig && options.tailwindConfig.endsWith(".css")) {
|
|
130
|
-
warn("config-as-css-is-deprecated", configDir, "Deprecated: Use the `tailwindStylesheet` option for v4 projects instead of `tailwindConfig`.");
|
|
131
|
-
stylesheetPath = options.tailwindConfig;
|
|
132
|
-
}
|
|
133
|
-
return getTailwindConfig$1({
|
|
134
|
-
base: configDir,
|
|
135
|
-
filepath: options.filepath,
|
|
136
|
-
configPath,
|
|
137
|
-
stylesheetPath,
|
|
138
|
-
packageName: options.tailwindPackageName
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
const options = {
|
|
142
|
-
tailwindConfig: {
|
|
143
|
-
type: "string",
|
|
144
|
-
category: "Tailwind CSS",
|
|
145
|
-
description: "Path to Tailwind configuration file"
|
|
146
|
-
},
|
|
147
|
-
tailwindEntryPoint: {
|
|
148
|
-
type: "string",
|
|
149
|
-
category: "Tailwind CSS",
|
|
150
|
-
description: "Path to the CSS entrypoint in your Tailwind project (v4+)"
|
|
151
|
-
},
|
|
152
|
-
tailwindStylesheet: {
|
|
153
|
-
type: "string",
|
|
154
|
-
category: "Tailwind CSS",
|
|
155
|
-
description: "Path to the CSS stylesheet in your Tailwind project (v4+)"
|
|
156
|
-
},
|
|
157
|
-
tailwindAttributes: {
|
|
158
|
-
type: "string",
|
|
159
|
-
array: true,
|
|
160
|
-
default: [{ value: [] }],
|
|
161
|
-
category: "Tailwind CSS",
|
|
162
|
-
description: "List of attributes/props that contain sortable Tailwind classes"
|
|
163
|
-
},
|
|
164
|
-
tailwindFunctions: {
|
|
165
|
-
type: "string",
|
|
166
|
-
array: true,
|
|
167
|
-
default: [{ value: [] }],
|
|
168
|
-
category: "Tailwind CSS",
|
|
169
|
-
description: "List of functions and tagged templates that contain sortable Tailwind classes"
|
|
170
|
-
},
|
|
171
|
-
tailwindPreserveWhitespace: {
|
|
172
|
-
type: "boolean",
|
|
173
|
-
default: false,
|
|
174
|
-
category: "Tailwind CSS",
|
|
175
|
-
description: "Preserve whitespace around Tailwind classes when sorting"
|
|
176
|
-
},
|
|
177
|
-
tailwindPreserveDuplicates: {
|
|
178
|
-
type: "boolean",
|
|
179
|
-
default: false,
|
|
180
|
-
category: "Tailwind CSS",
|
|
181
|
-
description: "Preserve duplicate classes inside a class list when sorting"
|
|
182
|
-
},
|
|
183
|
-
tailwindPackageName: {
|
|
184
|
-
type: "string",
|
|
185
|
-
default: "tailwindcss",
|
|
186
|
-
category: "Tailwind CSS",
|
|
187
|
-
description: "The package name to use when loading Tailwind CSS"
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
function createMatcher(options, parser, defaults) {
|
|
191
|
-
let staticAttrs = new Set(defaults.staticAttrs);
|
|
192
|
-
let dynamicAttrs = new Set(defaults.dynamicAttrs);
|
|
193
|
-
let functions = new Set(defaults.functions);
|
|
194
|
-
let staticAttrsRegex = [...defaults.staticAttrsRegex];
|
|
195
|
-
let functionsRegex = [...defaults.functionsRegex];
|
|
196
|
-
for (let attr of options.tailwindAttributes ?? []) {
|
|
197
|
-
let regex = parseRegex(attr);
|
|
198
|
-
if (regex) staticAttrsRegex.push(regex);
|
|
199
|
-
else if (parser === "vue" && attr.startsWith(":")) staticAttrs.add(attr.slice(1));
|
|
200
|
-
else if (parser === "vue" && attr.startsWith("v-bind:")) staticAttrs.add(attr.slice(7));
|
|
201
|
-
else if (parser === "vue" && attr.startsWith("v-")) dynamicAttrs.add(attr);
|
|
202
|
-
else if (parser === "angular" && attr.startsWith("[") && attr.endsWith("]")) staticAttrs.add(attr.slice(1, -1));
|
|
203
|
-
else staticAttrs.add(attr);
|
|
204
|
-
}
|
|
205
|
-
for (let attr of staticAttrs) if (parser === "vue") {
|
|
206
|
-
dynamicAttrs.add(`:${attr}`);
|
|
207
|
-
dynamicAttrs.add(`v-bind:${attr}`);
|
|
208
|
-
} else if (parser === "angular") dynamicAttrs.add(`[${attr}]`);
|
|
209
|
-
for (let fn of options.tailwindFunctions ?? []) {
|
|
210
|
-
let regex = parseRegex(fn);
|
|
211
|
-
if (regex) functionsRegex.push(regex);
|
|
212
|
-
else functions.add(fn);
|
|
213
|
-
}
|
|
214
|
-
return {
|
|
215
|
-
hasStaticAttr: (name) => {
|
|
216
|
-
if (nameFromDynamicAttr(name, parser)) return false;
|
|
217
|
-
return hasMatch(name, staticAttrs, staticAttrsRegex);
|
|
218
|
-
},
|
|
219
|
-
hasDynamicAttr: (name) => {
|
|
220
|
-
if (hasMatch(name, dynamicAttrs, [])) return true;
|
|
221
|
-
let newName = nameFromDynamicAttr(name, parser);
|
|
222
|
-
if (!newName) return false;
|
|
223
|
-
return hasMatch(newName, staticAttrs, staticAttrsRegex);
|
|
224
|
-
},
|
|
225
|
-
hasFunction: (name) => hasMatch(name, functions, functionsRegex)
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
function nameFromDynamicAttr(name, parser) {
|
|
229
|
-
if (parser === "vue") {
|
|
230
|
-
if (name.startsWith(":")) return name.slice(1);
|
|
231
|
-
if (name.startsWith("v-bind:")) return name.slice(7);
|
|
232
|
-
if (name.startsWith("v-")) return name;
|
|
233
|
-
return null;
|
|
234
|
-
}
|
|
235
|
-
if (parser === "angular") {
|
|
236
|
-
if (name.startsWith("[") && name.endsWith("]")) return name.slice(1, -1);
|
|
237
|
-
return null;
|
|
238
|
-
}
|
|
239
|
-
return null;
|
|
240
|
-
}
|
|
241
|
-
function hasMatch(name, list, patterns) {
|
|
242
|
-
if (list.has(name)) return true;
|
|
243
|
-
for (let regex of patterns) if (regex.test(name)) return true;
|
|
244
|
-
return false;
|
|
245
|
-
}
|
|
246
|
-
function parseRegex(str) {
|
|
247
|
-
if (!str.startsWith("/")) return null;
|
|
248
|
-
let lastSlash = str.lastIndexOf("/");
|
|
249
|
-
if (lastSlash <= 0) return null;
|
|
250
|
-
try {
|
|
251
|
-
let pattern = str.slice(1, lastSlash);
|
|
252
|
-
let flags = str.slice(lastSlash + 1);
|
|
253
|
-
return new RegExp(pattern, flags);
|
|
254
|
-
} catch {
|
|
255
|
-
return null;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
function createPlugin(transforms) {
|
|
259
|
-
let parsers = Object.create(null);
|
|
260
|
-
let printers = Object.create(null);
|
|
261
|
-
for (let opts of transforms) {
|
|
262
|
-
for (let [name, meta] of Object.entries(opts.parsers)) parsers[name] = async () => {
|
|
263
|
-
var _plugin$parsers;
|
|
264
|
-
let original = (_plugin$parsers = (await loadPlugins(meta.load ?? opts.load ?? [])).parsers) === null || _plugin$parsers === void 0 ? void 0 : _plugin$parsers[name];
|
|
265
|
-
if (!original) return;
|
|
266
|
-
parsers[name] = await createParser({
|
|
267
|
-
name,
|
|
268
|
-
original,
|
|
269
|
-
opts
|
|
270
|
-
});
|
|
271
|
-
return parsers[name];
|
|
272
|
-
};
|
|
273
|
-
for (let [name, _meta] of Object.entries(opts.printers ?? {})) printers[name] = async () => {
|
|
274
|
-
var _plugin$printers;
|
|
275
|
-
let original = (_plugin$printers = (await loadPlugins(opts.load ?? [])).printers) === null || _plugin$printers === void 0 ? void 0 : _plugin$printers[name];
|
|
276
|
-
if (!original) return;
|
|
277
|
-
printers[name] = createPrinter({
|
|
278
|
-
original,
|
|
279
|
-
opts
|
|
280
|
-
});
|
|
281
|
-
return printers[name];
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
return {
|
|
285
|
-
parsers,
|
|
286
|
-
printers
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
async function createParser({ name, original, opts }) {
|
|
290
|
-
let parser = { ...original };
|
|
291
|
-
async function load(options) {
|
|
292
|
-
let parser = { ...original };
|
|
293
|
-
for (const pluginName of opts.compatible || []) {
|
|
294
|
-
var _plugin$parsers2;
|
|
295
|
-
let plugin = await findEnabledPlugin(options, pluginName);
|
|
296
|
-
if (plugin === null || plugin === void 0 || (_plugin$parsers2 = plugin.parsers) === null || _plugin$parsers2 === void 0 ? void 0 : _plugin$parsers2[name]) Object.assign(parser, plugin.parsers[name]);
|
|
297
|
-
}
|
|
298
|
-
return parser;
|
|
299
|
-
}
|
|
300
|
-
parser.preprocess = async (code, options) => {
|
|
301
|
-
let parser = await load(options);
|
|
302
|
-
return parser.preprocess ? parser.preprocess(code, options) : code;
|
|
303
|
-
};
|
|
304
|
-
parser.parse = async (code, options) => {
|
|
305
|
-
let ast = await (await load(options)).parse(code, options, options);
|
|
306
|
-
let env = await loadTailwindCSS({
|
|
307
|
-
opts,
|
|
308
|
-
options
|
|
309
|
-
});
|
|
310
|
-
transformAst({
|
|
311
|
-
ast,
|
|
312
|
-
env,
|
|
313
|
-
opts,
|
|
314
|
-
options
|
|
315
|
-
});
|
|
316
|
-
options.__tailwindcss__ = env;
|
|
317
|
-
return ast;
|
|
318
|
-
};
|
|
319
|
-
return parser;
|
|
320
|
-
}
|
|
321
|
-
function createPrinter({ original, opts }) {
|
|
322
|
-
let printer = { ...original };
|
|
323
|
-
let reprint = opts.reprint;
|
|
324
|
-
if (reprint) {
|
|
325
|
-
printer.print = new Proxy(original.print, { apply(target, thisArg, args) {
|
|
326
|
-
let [path, options] = args;
|
|
327
|
-
let env = options.__tailwindcss__;
|
|
328
|
-
reprint(path, {
|
|
329
|
-
...env,
|
|
330
|
-
options
|
|
331
|
-
});
|
|
332
|
-
return Reflect.apply(target, thisArg, args);
|
|
333
|
-
} });
|
|
334
|
-
if (original.embed) printer.embed = new Proxy(original.embed, { apply(target, thisArg, args) {
|
|
335
|
-
let [path, options] = args;
|
|
336
|
-
let env = options.__tailwindcss__;
|
|
337
|
-
reprint(path, {
|
|
338
|
-
...env,
|
|
339
|
-
options
|
|
340
|
-
});
|
|
341
|
-
return Reflect.apply(target, thisArg, args);
|
|
342
|
-
} });
|
|
343
|
-
}
|
|
344
|
-
return printer;
|
|
345
|
-
}
|
|
346
|
-
async function loadPlugins(fns) {
|
|
347
|
-
let plugin = {
|
|
348
|
-
parsers: Object.create(null),
|
|
349
|
-
printers: Object.create(null),
|
|
350
|
-
options: Object.create(null),
|
|
351
|
-
defaultOptions: Object.create(null),
|
|
352
|
-
languages: []
|
|
353
|
-
};
|
|
354
|
-
for (let moduleName of fns) {
|
|
355
|
-
let loaded = typeof moduleName === "string" ? await loadIfExistsESM(moduleName) : moduleName;
|
|
356
|
-
Object.assign(plugin.parsers, loaded.parsers ?? {});
|
|
357
|
-
Object.assign(plugin.printers, loaded.printers ?? {});
|
|
358
|
-
Object.assign(plugin.options, loaded.options ?? {});
|
|
359
|
-
Object.assign(plugin.defaultOptions, loaded.defaultOptions ?? {});
|
|
360
|
-
plugin.languages = [...plugin.languages ?? [], ...loaded.languages ?? []];
|
|
361
|
-
}
|
|
362
|
-
return plugin;
|
|
363
|
-
}
|
|
364
|
-
async function loadIfExistsESM(name) {
|
|
365
|
-
return await loadIfExists(name) ?? {
|
|
366
|
-
parsers: {},
|
|
367
|
-
printers: {},
|
|
368
|
-
languages: [],
|
|
369
|
-
options: {},
|
|
370
|
-
defaultOptions: {}
|
|
371
|
-
};
|
|
372
|
-
}
|
|
373
|
-
function findEnabledPlugin(options, name) {
|
|
374
|
-
for (let plugin of options.plugins) {
|
|
375
|
-
if (plugin instanceof URL) {
|
|
376
|
-
if (plugin.protocol !== "file:") continue;
|
|
377
|
-
if (plugin.hostname !== "") continue;
|
|
378
|
-
plugin = plugin.pathname;
|
|
379
|
-
}
|
|
380
|
-
if (typeof plugin !== "string") {
|
|
381
|
-
if (!plugin.name) continue;
|
|
382
|
-
plugin = plugin.name;
|
|
383
|
-
}
|
|
384
|
-
if (plugin === name || isAbsolute(plugin) && plugin.includes(name) && maybeResolve(name) === plugin) return loadIfExistsESM(name);
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
async function loadTailwindCSS({ options, opts }) {
|
|
388
|
-
var _parsers$parser, _parsers$parser2;
|
|
389
|
-
let parsers = opts.parsers;
|
|
390
|
-
let parser = options.parser;
|
|
391
|
-
return {
|
|
392
|
-
context: await getTailwindConfig(options),
|
|
393
|
-
matcher: createMatcher(options, parser, {
|
|
394
|
-
staticAttrs: new Set(((_parsers$parser = parsers[parser]) === null || _parsers$parser === void 0 ? void 0 : _parsers$parser.staticAttrs) ?? opts.staticAttrs ?? []),
|
|
395
|
-
dynamicAttrs: new Set(((_parsers$parser2 = parsers[parser]) === null || _parsers$parser2 === void 0 ? void 0 : _parsers$parser2.dynamicAttrs) ?? opts.dynamicAttrs ?? []),
|
|
396
|
-
functions: /* @__PURE__ */ new Set(),
|
|
397
|
-
staticAttrsRegex: [],
|
|
398
|
-
dynamicAttrsRegex: [],
|
|
399
|
-
functionsRegex: []
|
|
400
|
-
}),
|
|
401
|
-
options,
|
|
402
|
-
changes: []
|
|
403
|
-
};
|
|
404
|
-
}
|
|
405
|
-
function transformAst({ ast, env, opts }) {
|
|
406
|
-
let transform = opts.transform;
|
|
407
|
-
if (transform) transform(ast, env);
|
|
408
|
-
}
|
|
409
|
-
function defineTransform(opts) {
|
|
410
|
-
return opts;
|
|
411
|
-
}
|
|
412
|
-
const ESCAPE_SEQUENCE_PATTERN = /\\(['"\\nrtbfv0-7xuU])/g;
|
|
413
|
-
function tryParseAngularAttribute(value, env) {
|
|
414
|
-
try {
|
|
415
|
-
return sn.__ng_directive.parse(value, env.options);
|
|
416
|
-
} catch (err) {
|
|
417
|
-
console.warn("prettier-plugin-tailwindcss: Unable to parse angular directive");
|
|
418
|
-
console.warn(err);
|
|
419
|
-
return null;
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
function transformDynamicAngularAttribute(attr, env) {
|
|
423
|
-
let directiveAst = tryParseAngularAttribute(attr.value, env);
|
|
424
|
-
if (!directiveAst) return;
|
|
425
|
-
let changes = [];
|
|
426
|
-
visit(directiveAst, {
|
|
427
|
-
StringLiteral(node, path) {
|
|
428
|
-
if (!node.value) return;
|
|
429
|
-
let collapseWhitespace = canCollapseWhitespaceIn(path, env);
|
|
430
|
-
changes.push({
|
|
431
|
-
start: node.start + 1,
|
|
432
|
-
end: node.end - 1,
|
|
433
|
-
before: node.value,
|
|
434
|
-
after: sortClasses(node.value, {
|
|
435
|
-
env,
|
|
436
|
-
collapseWhitespace
|
|
437
|
-
})
|
|
438
|
-
});
|
|
439
|
-
},
|
|
440
|
-
TemplateLiteral(node, path) {
|
|
441
|
-
if (!node.quasis.length) return;
|
|
442
|
-
let collapseWhitespace = canCollapseWhitespaceIn(path, env);
|
|
443
|
-
for (let i = 0; i < node.quasis.length; i++) {
|
|
444
|
-
let quasi = node.quasis[i];
|
|
445
|
-
changes.push({
|
|
446
|
-
start: quasi.start,
|
|
447
|
-
end: quasi.end,
|
|
448
|
-
before: quasi.value.raw,
|
|
449
|
-
after: sortClasses(quasi.value.raw, {
|
|
450
|
-
env,
|
|
451
|
-
ignoreFirst: i > 0 && !/^\s/.test(quasi.value.raw),
|
|
452
|
-
ignoreLast: i < node.expressions.length && !/\s$/.test(quasi.value.raw),
|
|
453
|
-
collapseWhitespace: collapseWhitespace ? {
|
|
454
|
-
start: collapseWhitespace.start && i === 0,
|
|
455
|
-
end: collapseWhitespace.end && i >= node.expressions.length
|
|
456
|
-
} : false
|
|
457
|
-
})
|
|
458
|
-
});
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
});
|
|
462
|
-
attr.value = spliceChangesIntoString(attr.value, changes);
|
|
463
|
-
}
|
|
464
|
-
function transformDynamicJsAttribute(attr, env) {
|
|
465
|
-
let { matcher } = env;
|
|
466
|
-
let source = `let __prettier_temp__ = ${attr.value}`;
|
|
467
|
-
let ast = ra["babel-ts"].parse(source, env.options);
|
|
468
|
-
let didChange = false;
|
|
469
|
-
let changes = [];
|
|
470
|
-
function findConcatEntry(path) {
|
|
471
|
-
return path.find((entry) => {
|
|
472
|
-
var _entry$parent;
|
|
473
|
-
return ((_entry$parent = entry.parent) === null || _entry$parent === void 0 ? void 0 : _entry$parent.type) === "BinaryExpression" && entry.parent.operator === "+";
|
|
474
|
-
});
|
|
475
|
-
}
|
|
476
|
-
function addChange(start, end, after) {
|
|
477
|
-
if (start == null || end == null) return;
|
|
478
|
-
let offsetStart = start - 24;
|
|
479
|
-
let offsetEnd = end - 24;
|
|
480
|
-
if (offsetStart < 0 || offsetEnd < 0) return;
|
|
481
|
-
didChange = true;
|
|
482
|
-
changes.push({
|
|
483
|
-
start: offsetStart,
|
|
484
|
-
end: offsetEnd,
|
|
485
|
-
before: attr.value.slice(offsetStart, offsetEnd),
|
|
486
|
-
after
|
|
487
|
-
});
|
|
488
|
-
}
|
|
489
|
-
visit(ast, {
|
|
490
|
-
StringLiteral(node, path) {
|
|
491
|
-
let concat = findConcatEntry(path);
|
|
492
|
-
if (sortStringLiteral(node, {
|
|
493
|
-
env,
|
|
494
|
-
collapseWhitespace: {
|
|
495
|
-
start: (concat === null || concat === void 0 ? void 0 : concat.key) !== "right",
|
|
496
|
-
end: (concat === null || concat === void 0 ? void 0 : concat.key) !== "left"
|
|
497
|
-
}
|
|
498
|
-
})) {
|
|
499
|
-
var _node$extra;
|
|
500
|
-
let raw = ((_node$extra = node.extra) === null || _node$extra === void 0 ? void 0 : _node$extra.raw) ?? node.raw;
|
|
501
|
-
if (typeof raw === "string") addChange(node.start, node.end, raw);
|
|
502
|
-
}
|
|
503
|
-
},
|
|
504
|
-
Literal(node, path) {
|
|
505
|
-
if (!isStringLiteral(node)) return;
|
|
506
|
-
let concat = findConcatEntry(path);
|
|
507
|
-
if (sortStringLiteral(node, {
|
|
508
|
-
env,
|
|
509
|
-
collapseWhitespace: {
|
|
510
|
-
start: (concat === null || concat === void 0 ? void 0 : concat.key) !== "right",
|
|
511
|
-
end: (concat === null || concat === void 0 ? void 0 : concat.key) !== "left"
|
|
512
|
-
}
|
|
513
|
-
})) {
|
|
514
|
-
var _node$extra2;
|
|
515
|
-
let raw = ((_node$extra2 = node.extra) === null || _node$extra2 === void 0 ? void 0 : _node$extra2.raw) ?? node.raw;
|
|
516
|
-
if (typeof raw === "string") addChange(node.start, node.end, raw);
|
|
517
|
-
}
|
|
518
|
-
},
|
|
519
|
-
TemplateLiteral(node, path) {
|
|
520
|
-
let concat = findConcatEntry(path);
|
|
521
|
-
let originalQuasis = node.quasis.map((quasi) => quasi.value.raw);
|
|
522
|
-
if (sortTemplateLiteral(node, {
|
|
523
|
-
env,
|
|
524
|
-
collapseWhitespace: {
|
|
525
|
-
start: (concat === null || concat === void 0 ? void 0 : concat.key) !== "right",
|
|
526
|
-
end: (concat === null || concat === void 0 ? void 0 : concat.key) !== "left"
|
|
527
|
-
}
|
|
528
|
-
})) for (let i = 0; i < node.quasis.length; i++) {
|
|
529
|
-
let quasi = node.quasis[i];
|
|
530
|
-
if (quasi.value.raw !== originalQuasis[i]) addChange(quasi.start, quasi.end, quasi.value.raw);
|
|
531
|
-
}
|
|
532
|
-
},
|
|
533
|
-
TaggedTemplateExpression(node, path) {
|
|
534
|
-
if (!isSortableTemplateExpression(node, matcher)) return;
|
|
535
|
-
let concat = findConcatEntry(path);
|
|
536
|
-
let originalQuasis = node.quasi.quasis.map((quasi) => quasi.value.raw);
|
|
537
|
-
if (sortTemplateLiteral(node.quasi, {
|
|
538
|
-
env,
|
|
539
|
-
collapseWhitespace: {
|
|
540
|
-
start: (concat === null || concat === void 0 ? void 0 : concat.key) !== "right",
|
|
541
|
-
end: (concat === null || concat === void 0 ? void 0 : concat.key) !== "left"
|
|
542
|
-
}
|
|
543
|
-
})) for (let i = 0; i < node.quasi.quasis.length; i++) {
|
|
544
|
-
let quasi = node.quasi.quasis[i];
|
|
545
|
-
if (quasi.value.raw !== originalQuasis[i]) addChange(quasi.start, quasi.end, quasi.value.raw);
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
});
|
|
549
|
-
if (didChange) attr.value = spliceChangesIntoString(attr.value, changes);
|
|
550
|
-
}
|
|
551
|
-
function transformHtml(ast, env) {
|
|
552
|
-
let { matcher } = env;
|
|
553
|
-
let { parser } = env.options;
|
|
554
|
-
for (let attr of ast.attrs ?? []) if (matcher.hasStaticAttr(attr.name)) attr.value = sortClasses(attr.value, { env });
|
|
555
|
-
else if (matcher.hasDynamicAttr(attr.name)) {
|
|
556
|
-
if (!/[`'"]/.test(attr.value)) continue;
|
|
557
|
-
if (parser === "angular") transformDynamicAngularAttribute(attr, env);
|
|
558
|
-
else transformDynamicJsAttribute(attr, env);
|
|
559
|
-
}
|
|
560
|
-
for (let child of ast.children ?? []) transformHtml(child, env);
|
|
561
|
-
}
|
|
562
|
-
function transformGlimmer(ast, env) {
|
|
563
|
-
let { matcher } = env;
|
|
564
|
-
visit(ast, {
|
|
565
|
-
AttrNode(attr, _path, meta) {
|
|
566
|
-
if (matcher.hasStaticAttr(attr.name) && attr.value) meta.sortTextNodes = true;
|
|
567
|
-
},
|
|
568
|
-
TextNode(node, path, meta) {
|
|
569
|
-
if (!meta.sortTextNodes) return;
|
|
570
|
-
let concat = path.find((entry) => {
|
|
571
|
-
return entry.parent && entry.parent.type === "ConcatStatement";
|
|
572
|
-
});
|
|
573
|
-
let siblings = {
|
|
574
|
-
prev: concat === null || concat === void 0 ? void 0 : concat.parent.parts[concat.index - 1],
|
|
575
|
-
next: concat === null || concat === void 0 ? void 0 : concat.parent.parts[concat.index + 1]
|
|
576
|
-
};
|
|
577
|
-
node.chars = sortClasses(node.chars, {
|
|
578
|
-
env,
|
|
579
|
-
ignoreFirst: siblings.prev && !/^\s/.test(node.chars),
|
|
580
|
-
ignoreLast: siblings.next && !/\s$/.test(node.chars),
|
|
581
|
-
collapseWhitespace: {
|
|
582
|
-
start: !siblings.prev,
|
|
583
|
-
end: !siblings.next
|
|
584
|
-
}
|
|
585
|
-
});
|
|
586
|
-
},
|
|
587
|
-
StringLiteral(node, path, meta) {
|
|
588
|
-
if (!meta.sortTextNodes) return;
|
|
589
|
-
let concat = path.find((entry) => {
|
|
590
|
-
return entry.parent && entry.parent.type === "SubExpression" && entry.parent.path.original === "concat";
|
|
591
|
-
});
|
|
592
|
-
node.value = sortClasses(node.value, {
|
|
593
|
-
env,
|
|
594
|
-
ignoreLast: Boolean(concat) && !/[^\S\r\n]$/.test(node.value),
|
|
595
|
-
collapseWhitespace: {
|
|
596
|
-
start: false,
|
|
597
|
-
end: !concat
|
|
598
|
-
}
|
|
599
|
-
});
|
|
600
|
-
}
|
|
601
|
-
});
|
|
602
|
-
}
|
|
603
|
-
function transformLiquid(ast, env) {
|
|
604
|
-
let { matcher } = env;
|
|
605
|
-
function isClassAttr(node) {
|
|
606
|
-
return Array.isArray(node.name) ? node.name.every((n) => n.type === "TextNode" && matcher.hasStaticAttr(n.value)) : matcher.hasStaticAttr(node.name);
|
|
607
|
-
}
|
|
608
|
-
function hasSurroundingQuotes(str) {
|
|
609
|
-
let start = str[0];
|
|
610
|
-
return start === str[str.length - 1] && (start === "\"" || start === "'" || start === "`");
|
|
611
|
-
}
|
|
612
|
-
let sources = [];
|
|
613
|
-
let changes = [];
|
|
614
|
-
function sortAttribute(attr) {
|
|
615
|
-
for (let i = 0; i < attr.value.length; i++) {
|
|
616
|
-
let node = attr.value[i];
|
|
617
|
-
if (node.type === "TextNode") {
|
|
618
|
-
let after = sortClasses(node.value, {
|
|
619
|
-
env,
|
|
620
|
-
ignoreFirst: i > 0 && !/^\s/.test(node.value),
|
|
621
|
-
ignoreLast: i < attr.value.length - 1 && !/\s$/.test(node.value),
|
|
622
|
-
removeDuplicates: false,
|
|
623
|
-
collapseWhitespace: false
|
|
624
|
-
});
|
|
625
|
-
changes.push({
|
|
626
|
-
start: node.position.start,
|
|
627
|
-
end: node.position.end,
|
|
628
|
-
before: node.value,
|
|
629
|
-
after
|
|
630
|
-
});
|
|
631
|
-
} else if ((node.type === "LiquidDrop" || node.type === "LiquidVariableOutput") && typeof node.markup === "object" && node.markup.type === "LiquidVariable") visit(node.markup.expression, { String(node) {
|
|
632
|
-
let pos = { ...node.position };
|
|
633
|
-
if (hasSurroundingQuotes(node.source.slice(pos.start, pos.end))) {
|
|
634
|
-
pos.start += 1;
|
|
635
|
-
pos.end -= 1;
|
|
636
|
-
}
|
|
637
|
-
let after = sortClasses(node.value, { env });
|
|
638
|
-
changes.push({
|
|
639
|
-
start: pos.start,
|
|
640
|
-
end: pos.end,
|
|
641
|
-
before: node.value,
|
|
642
|
-
after
|
|
643
|
-
});
|
|
644
|
-
} });
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
visit(ast, {
|
|
648
|
-
LiquidTag(node) {
|
|
649
|
-
sources.push(node);
|
|
650
|
-
},
|
|
651
|
-
HtmlElement(node) {
|
|
652
|
-
sources.push(node);
|
|
653
|
-
},
|
|
654
|
-
AttrSingleQuoted(node) {
|
|
655
|
-
if (isClassAttr(node)) {
|
|
656
|
-
sources.push(node);
|
|
657
|
-
sortAttribute(node);
|
|
658
|
-
}
|
|
659
|
-
},
|
|
660
|
-
AttrDoubleQuoted(node) {
|
|
661
|
-
if (isClassAttr(node)) {
|
|
662
|
-
sources.push(node);
|
|
663
|
-
sortAttribute(node);
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
});
|
|
667
|
-
for (let node of sources) node.source = spliceChangesIntoString(node.source, changes);
|
|
668
|
-
}
|
|
669
|
-
function sortStringLiteral(node, { env, removeDuplicates, collapseWhitespace = {
|
|
670
|
-
start: true,
|
|
671
|
-
end: true
|
|
672
|
-
} }) {
|
|
673
|
-
var _node$extra3, _node$extra4;
|
|
674
|
-
let result = sortClasses(node.value, {
|
|
675
|
-
env,
|
|
676
|
-
removeDuplicates,
|
|
677
|
-
collapseWhitespace
|
|
678
|
-
});
|
|
679
|
-
if (!(result !== node.value)) return false;
|
|
680
|
-
node.value = result;
|
|
681
|
-
let raw = ((_node$extra3 = node.extra) === null || _node$extra3 === void 0 ? void 0 : _node$extra3.raw) ?? node.raw;
|
|
682
|
-
let quote = raw[0];
|
|
683
|
-
let originalRawContent = raw.slice(1, -1);
|
|
684
|
-
let originalValue = ((_node$extra4 = node.extra) === null || _node$extra4 === void 0 ? void 0 : _node$extra4.rawValue) ?? node.value;
|
|
685
|
-
if (node.extra) {
|
|
686
|
-
if (originalRawContent !== originalValue && originalValue.includes("\\")) result = result.replace(ESCAPE_SEQUENCE_PATTERN, "\\\\$1");
|
|
687
|
-
node.extra = {
|
|
688
|
-
...node.extra,
|
|
689
|
-
rawValue: result,
|
|
690
|
-
raw: quote + result + quote
|
|
691
|
-
};
|
|
692
|
-
} else node.raw = quote + result + quote;
|
|
693
|
-
return true;
|
|
694
|
-
}
|
|
695
|
-
function isStringLiteral(node) {
|
|
696
|
-
return node.type === "StringLiteral" || node.type === "Literal" && typeof node.value === "string";
|
|
697
|
-
}
|
|
698
|
-
function sortTemplateLiteral(node, { env, removeDuplicates, collapseWhitespace = {
|
|
699
|
-
start: true,
|
|
700
|
-
end: true
|
|
701
|
-
} }) {
|
|
702
|
-
let didChange = false;
|
|
703
|
-
for (let i = 0; i < node.quasis.length; i++) {
|
|
704
|
-
let quasi = node.quasis[i];
|
|
705
|
-
let same = quasi.value.raw === quasi.value.cooked;
|
|
706
|
-
let originalRaw = quasi.value.raw;
|
|
707
|
-
let originalCooked = quasi.value.cooked;
|
|
708
|
-
quasi.value.raw = sortClasses(quasi.value.raw, {
|
|
709
|
-
env,
|
|
710
|
-
removeDuplicates,
|
|
711
|
-
ignoreFirst: i > 0 && !/^\s/.test(quasi.value.raw),
|
|
712
|
-
ignoreLast: i < node.expressions.length && !/\s$/.test(quasi.value.raw),
|
|
713
|
-
collapseWhitespace: collapseWhitespace && {
|
|
714
|
-
start: collapseWhitespace && collapseWhitespace.start && i === 0,
|
|
715
|
-
end: collapseWhitespace && collapseWhitespace.end && i >= node.expressions.length
|
|
716
|
-
}
|
|
717
|
-
});
|
|
718
|
-
quasi.value.cooked = same ? quasi.value.raw : sortClasses(quasi.value.cooked, {
|
|
719
|
-
env,
|
|
720
|
-
ignoreFirst: i > 0 && !/^\s/.test(quasi.value.cooked),
|
|
721
|
-
ignoreLast: i < node.expressions.length && !/\s$/.test(quasi.value.cooked),
|
|
722
|
-
removeDuplicates,
|
|
723
|
-
collapseWhitespace: collapseWhitespace && {
|
|
724
|
-
start: collapseWhitespace && collapseWhitespace.start && i === 0,
|
|
725
|
-
end: collapseWhitespace && collapseWhitespace.end && i >= node.expressions.length
|
|
726
|
-
}
|
|
727
|
-
});
|
|
728
|
-
if (quasi.value.raw !== originalRaw || quasi.value.cooked !== originalCooked) didChange = true;
|
|
729
|
-
}
|
|
730
|
-
return didChange;
|
|
731
|
-
}
|
|
732
|
-
function isSortableTemplateExpression(node, matcher) {
|
|
733
|
-
return isSortableExpression(node.tag, matcher);
|
|
734
|
-
}
|
|
735
|
-
function isSortableCallExpression(node, matcher) {
|
|
736
|
-
var _node$arguments;
|
|
737
|
-
if (!((_node$arguments = node.arguments) === null || _node$arguments === void 0 ? void 0 : _node$arguments.length)) return false;
|
|
738
|
-
return isSortableExpression(node.callee, matcher);
|
|
739
|
-
}
|
|
740
|
-
function isSortableExpression(node, matcher) {
|
|
741
|
-
while (node.type === "CallExpression" || node.type === "MemberExpression") if (node.type === "CallExpression") node = node.callee;
|
|
742
|
-
else if (node.type === "MemberExpression") node = node.object;
|
|
743
|
-
if (node.type === "Identifier") return matcher.hasFunction(node.name);
|
|
744
|
-
return false;
|
|
745
|
-
}
|
|
746
|
-
function canCollapseWhitespaceIn(path, env) {
|
|
747
|
-
if (env.options.tailwindPreserveWhitespace) return false;
|
|
748
|
-
let start = true;
|
|
749
|
-
let end = true;
|
|
750
|
-
for (let entry of path) {
|
|
751
|
-
if (!entry.parent) continue;
|
|
752
|
-
if (entry.parent.type === "BinaryExpression" && entry.parent.operator === "+") {
|
|
753
|
-
start && (start = entry.key !== "right");
|
|
754
|
-
end && (end = entry.key !== "left");
|
|
755
|
-
}
|
|
756
|
-
if (entry.parent.type === "TemplateLiteral") {
|
|
757
|
-
let nodeStart = entry.node.start ?? null;
|
|
758
|
-
let nodeEnd = entry.node.end ?? null;
|
|
759
|
-
for (let quasi of entry.parent.quasis) {
|
|
760
|
-
let quasiStart = quasi.start ?? null;
|
|
761
|
-
let quasiEnd = quasi.end ?? null;
|
|
762
|
-
if (nodeStart !== null && quasiEnd !== null && nodeStart - quasiEnd <= 2) start && (start = /^\s/.test(quasi.value.raw));
|
|
763
|
-
if (nodeEnd !== null && quasiStart !== null && nodeEnd - quasiStart <= 2) end && (end = /\s$/.test(quasi.value.raw));
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
return {
|
|
768
|
-
start,
|
|
769
|
-
end
|
|
770
|
-
};
|
|
771
|
-
}
|
|
772
|
-
function transformJavaScript(ast, env) {
|
|
773
|
-
let { matcher } = env;
|
|
774
|
-
function sortInside(ast) {
|
|
775
|
-
visit(ast, (node, path) => {
|
|
776
|
-
let collapseWhitespace = canCollapseWhitespaceIn(path, env);
|
|
777
|
-
if (isStringLiteral(node)) sortStringLiteral(node, {
|
|
778
|
-
env,
|
|
779
|
-
collapseWhitespace
|
|
780
|
-
});
|
|
781
|
-
else if (node.type === "TemplateLiteral") sortTemplateLiteral(node, {
|
|
782
|
-
env,
|
|
783
|
-
collapseWhitespace
|
|
784
|
-
});
|
|
785
|
-
else if (node.type === "TaggedTemplateExpression") {
|
|
786
|
-
if (isSortableTemplateExpression(node, matcher)) sortTemplateLiteral(node.quasi, {
|
|
787
|
-
env,
|
|
788
|
-
collapseWhitespace
|
|
789
|
-
});
|
|
790
|
-
}
|
|
791
|
-
});
|
|
792
|
-
}
|
|
793
|
-
visit(ast, {
|
|
794
|
-
JSXAttribute(node) {
|
|
795
|
-
node = node;
|
|
796
|
-
if (!node.value) return;
|
|
797
|
-
if (typeof node.name.name !== "string") return;
|
|
798
|
-
if (!matcher.hasStaticAttr(node.name.name)) return;
|
|
799
|
-
if (isStringLiteral(node.value)) sortStringLiteral(node.value, { env });
|
|
800
|
-
else if (node.value.type === "JSXExpressionContainer") sortInside(node.value);
|
|
801
|
-
},
|
|
802
|
-
CallExpression(node) {
|
|
803
|
-
node = node;
|
|
804
|
-
if (!isSortableCallExpression(node, matcher)) return;
|
|
805
|
-
node.arguments.forEach((arg) => sortInside(arg));
|
|
806
|
-
},
|
|
807
|
-
TaggedTemplateExpression(node, path) {
|
|
808
|
-
node = node;
|
|
809
|
-
if (!isSortableTemplateExpression(node, matcher)) return;
|
|
810
|
-
let collapseWhitespace = canCollapseWhitespaceIn(path, env);
|
|
811
|
-
sortTemplateLiteral(node.quasi, {
|
|
812
|
-
env,
|
|
813
|
-
collapseWhitespace
|
|
814
|
-
});
|
|
815
|
-
}
|
|
816
|
-
});
|
|
817
|
-
}
|
|
818
|
-
function transformCss(ast, env) {
|
|
819
|
-
function tryParseAtRuleParams(name, params) {
|
|
820
|
-
if (typeof params !== "string") return params;
|
|
821
|
-
try {
|
|
822
|
-
return en.css.parse(`@import ${params};`, { ...env.options }).nodes[0].params;
|
|
823
|
-
} catch (err) {
|
|
824
|
-
console.warn(`[prettier-plugin-tailwindcss] Unable to parse at rule`);
|
|
825
|
-
console.warn({
|
|
826
|
-
name,
|
|
827
|
-
params
|
|
828
|
-
});
|
|
829
|
-
console.warn(err);
|
|
830
|
-
}
|
|
831
|
-
return params;
|
|
832
|
-
}
|
|
833
|
-
ast.walk((node) => {
|
|
834
|
-
if (node.name === "plugin" || node.name === "config" || node.name === "source") node.params = tryParseAtRuleParams(node.name, node.params);
|
|
835
|
-
if (node.type === "css-atrule" && node.name === "apply") {
|
|
836
|
-
let isImportant = /\s+(?:!important|#{(['"]*)!important\1})\s*$/.test(node.params);
|
|
837
|
-
let classList = node.params;
|
|
838
|
-
let prefix = "";
|
|
839
|
-
let suffix = "";
|
|
840
|
-
if (classList.startsWith("~\"") && classList.endsWith("\"")) {
|
|
841
|
-
prefix = "~\"";
|
|
842
|
-
suffix = "\"";
|
|
843
|
-
classList = classList.slice(2, -1);
|
|
844
|
-
isImportant = false;
|
|
845
|
-
} else if (classList.startsWith("~'") && classList.endsWith("'")) {
|
|
846
|
-
prefix = "~'";
|
|
847
|
-
suffix = "'";
|
|
848
|
-
classList = classList.slice(2, -1);
|
|
849
|
-
isImportant = false;
|
|
850
|
-
}
|
|
851
|
-
classList = sortClasses(classList, {
|
|
852
|
-
env,
|
|
853
|
-
ignoreLast: isImportant,
|
|
854
|
-
collapseWhitespace: {
|
|
855
|
-
start: false,
|
|
856
|
-
end: !isImportant
|
|
857
|
-
}
|
|
858
|
-
});
|
|
859
|
-
node.params = `${prefix}${classList}${suffix}`;
|
|
860
|
-
}
|
|
861
|
-
});
|
|
862
|
-
}
|
|
863
|
-
function transformAstro(ast, env) {
|
|
864
|
-
let { matcher } = env;
|
|
865
|
-
if (ast.type === "element" || ast.type === "custom-element" || ast.type === "component") {
|
|
866
|
-
for (let attr of ast.attributes ?? []) if (matcher.hasStaticAttr(attr.name) && attr.type === "attribute" && attr.kind === "quoted") attr.value = sortClasses(attr.value, { env });
|
|
867
|
-
else if (matcher.hasDynamicAttr(attr.name) && attr.type === "attribute" && attr.kind === "expression" && typeof attr.value === "string") transformDynamicJsAttribute(attr, env);
|
|
868
|
-
}
|
|
869
|
-
for (let child of ast.children ?? []) transformAstro(child, env);
|
|
870
|
-
}
|
|
871
|
-
function transformMarko(ast, env) {
|
|
872
|
-
let { matcher } = env;
|
|
873
|
-
const nodesToVisit = [ast];
|
|
874
|
-
while (nodesToVisit.length > 0) {
|
|
875
|
-
const currentNode = nodesToVisit.pop();
|
|
876
|
-
switch (currentNode.type) {
|
|
877
|
-
case "File":
|
|
878
|
-
nodesToVisit.push(currentNode.program);
|
|
879
|
-
break;
|
|
880
|
-
case "Program":
|
|
881
|
-
nodesToVisit.push(...currentNode.body);
|
|
882
|
-
break;
|
|
883
|
-
case "MarkoTag":
|
|
884
|
-
nodesToVisit.push(...currentNode.attributes);
|
|
885
|
-
nodesToVisit.push(currentNode.body);
|
|
886
|
-
break;
|
|
887
|
-
case "MarkoTagBody":
|
|
888
|
-
nodesToVisit.push(...currentNode.body);
|
|
889
|
-
break;
|
|
890
|
-
case "MarkoAttribute":
|
|
891
|
-
if (!matcher.hasStaticAttr(currentNode.name)) break;
|
|
892
|
-
switch (currentNode.value.type) {
|
|
893
|
-
case "ArrayExpression":
|
|
894
|
-
const classList = currentNode.value.elements;
|
|
895
|
-
for (const node of classList) if (node.type === "StringLiteral") node.value = sortClasses(node.value, { env });
|
|
896
|
-
break;
|
|
897
|
-
case "StringLiteral":
|
|
898
|
-
currentNode.value.value = sortClasses(currentNode.value.value, { env });
|
|
899
|
-
break;
|
|
900
|
-
}
|
|
901
|
-
break;
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
function transformTwig(ast, env) {
|
|
906
|
-
let { matcher } = env;
|
|
907
|
-
for (let child of ast.expressions ?? []) transformTwig(child, env);
|
|
908
|
-
visit(ast, {
|
|
909
|
-
Attribute(node, _path, meta) {
|
|
910
|
-
if (!matcher.hasStaticAttr(node.name.name)) return;
|
|
911
|
-
meta.sortTextNodes = true;
|
|
912
|
-
},
|
|
913
|
-
CallExpression(node, _path, meta) {
|
|
914
|
-
while (node.type === "CallExpression" || node.type === "MemberExpression") if (node.type === "CallExpression") node = node.callee;
|
|
915
|
-
else if (node.type === "MemberExpression") node = node.property;
|
|
916
|
-
if (node.type === "Identifier") {
|
|
917
|
-
if (!matcher.hasFunction(node.name)) return;
|
|
918
|
-
}
|
|
919
|
-
meta.sortTextNodes = true;
|
|
920
|
-
},
|
|
921
|
-
StringLiteral(node, path, meta) {
|
|
922
|
-
if (!meta.sortTextNodes) return;
|
|
923
|
-
const concat = path.find((entry) => {
|
|
924
|
-
return entry.parent && (entry.parent.type === "BinaryConcatExpression" || entry.parent.type === "BinaryAddExpression");
|
|
925
|
-
});
|
|
926
|
-
node.value = sortClasses(node.value, {
|
|
927
|
-
env,
|
|
928
|
-
ignoreFirst: (concat === null || concat === void 0 ? void 0 : concat.key) === "right" && !/^[^\S\r\n]/.test(node.value),
|
|
929
|
-
ignoreLast: (concat === null || concat === void 0 ? void 0 : concat.key) === "left" && !/[^\S\r\n]$/.test(node.value),
|
|
930
|
-
collapseWhitespace: {
|
|
931
|
-
start: (concat === null || concat === void 0 ? void 0 : concat.key) !== "right",
|
|
932
|
-
end: (concat === null || concat === void 0 ? void 0 : concat.key) !== "left"
|
|
933
|
-
}
|
|
934
|
-
});
|
|
935
|
-
}
|
|
936
|
-
});
|
|
937
|
-
}
|
|
938
|
-
function transformPug(ast, env) {
|
|
939
|
-
let { matcher } = env;
|
|
940
|
-
for (const token of ast.tokens) if (token.type === "attribute" && matcher.hasStaticAttr(token.name)) token.val = [
|
|
941
|
-
token.val.slice(0, 1),
|
|
942
|
-
sortClasses(token.val.slice(1, -1), { env }),
|
|
943
|
-
token.val.slice(-1)
|
|
944
|
-
].join("");
|
|
945
|
-
let startIdx = -1;
|
|
946
|
-
let endIdx = -1;
|
|
947
|
-
let ranges = [];
|
|
948
|
-
for (let i = 0; i < ast.tokens.length; i++) if (ast.tokens[i].type === "class") {
|
|
949
|
-
startIdx = startIdx === -1 ? i : startIdx;
|
|
950
|
-
endIdx = i;
|
|
951
|
-
} else if (startIdx !== -1) {
|
|
952
|
-
ranges.push([startIdx, endIdx]);
|
|
953
|
-
startIdx = -1;
|
|
954
|
-
endIdx = -1;
|
|
955
|
-
}
|
|
956
|
-
if (startIdx !== -1) {
|
|
957
|
-
ranges.push([startIdx, endIdx]);
|
|
958
|
-
startIdx = -1;
|
|
959
|
-
endIdx = -1;
|
|
960
|
-
}
|
|
961
|
-
for (const [startIdx, endIdx] of ranges) {
|
|
962
|
-
const { classList } = sortClassList({
|
|
963
|
-
classList: ast.tokens.slice(startIdx, endIdx + 1).map((token) => token.val),
|
|
964
|
-
api: env.context,
|
|
965
|
-
removeDuplicates: false
|
|
966
|
-
});
|
|
967
|
-
for (let i = startIdx; i <= endIdx; i++) ast.tokens[i].val = classList[i - startIdx];
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
function transformSvelte(ast, env) {
|
|
971
|
-
let { matcher, changes } = env;
|
|
972
|
-
for (let attr of ast.attributes ?? []) {
|
|
973
|
-
if (!matcher.hasStaticAttr(attr.name) || attr.type !== "Attribute") continue;
|
|
974
|
-
for (let i = 0; i < attr.value.length; i++) {
|
|
975
|
-
let value = attr.value[i];
|
|
976
|
-
if (value.type === "Text") {
|
|
977
|
-
let same = value.raw === value.data;
|
|
978
|
-
value.raw = sortClasses(value.raw, {
|
|
979
|
-
env,
|
|
980
|
-
ignoreFirst: i > 0 && !/^\s/.test(value.raw),
|
|
981
|
-
ignoreLast: i < attr.value.length - 1 && !/\s$/.test(value.raw),
|
|
982
|
-
removeDuplicates: true,
|
|
983
|
-
collapseWhitespace: false
|
|
984
|
-
});
|
|
985
|
-
value.data = same ? value.raw : sortClasses(value.data, {
|
|
986
|
-
env,
|
|
987
|
-
ignoreFirst: i > 0 && !/^\s/.test(value.data),
|
|
988
|
-
ignoreLast: i < attr.value.length - 1 && !/\s$/.test(value.data),
|
|
989
|
-
removeDuplicates: true,
|
|
990
|
-
collapseWhitespace: false
|
|
991
|
-
});
|
|
992
|
-
} else if (value.type === "MustacheTag") visit(value.expression, {
|
|
993
|
-
Literal(node) {
|
|
994
|
-
if (isStringLiteral(node)) {
|
|
995
|
-
let before = node.raw;
|
|
996
|
-
if (sortStringLiteral(node, {
|
|
997
|
-
env,
|
|
998
|
-
removeDuplicates: false,
|
|
999
|
-
collapseWhitespace: false
|
|
1000
|
-
})) changes.push({
|
|
1001
|
-
before,
|
|
1002
|
-
after: node.raw,
|
|
1003
|
-
start: node.loc.start,
|
|
1004
|
-
end: node.loc.end
|
|
1005
|
-
});
|
|
1006
|
-
}
|
|
1007
|
-
},
|
|
1008
|
-
TemplateLiteral(node) {
|
|
1009
|
-
let before = node.quasis.map((quasi) => quasi.value.raw);
|
|
1010
|
-
if (sortTemplateLiteral(node, {
|
|
1011
|
-
env,
|
|
1012
|
-
removeDuplicates: false,
|
|
1013
|
-
collapseWhitespace: false
|
|
1014
|
-
})) for (let [idx, quasi] of node.quasis.entries()) changes.push({
|
|
1015
|
-
before: before[idx],
|
|
1016
|
-
after: quasi.value.raw,
|
|
1017
|
-
start: quasi.loc.start,
|
|
1018
|
-
end: quasi.loc.end
|
|
1019
|
-
});
|
|
1020
|
-
}
|
|
1021
|
-
});
|
|
1022
|
-
}
|
|
1023
|
-
}
|
|
1024
|
-
for (let child of ast.children ?? []) transformSvelte(child, env);
|
|
1025
|
-
if (ast.type === "IfBlock") {
|
|
1026
|
-
var _ast$else;
|
|
1027
|
-
for (let child of ((_ast$else = ast.else) === null || _ast$else === void 0 ? void 0 : _ast$else.children) ?? []) transformSvelte(child, env);
|
|
1028
|
-
}
|
|
1029
|
-
if (ast.type === "AwaitBlock") {
|
|
1030
|
-
let nodes = [
|
|
1031
|
-
ast.pending,
|
|
1032
|
-
ast.then,
|
|
1033
|
-
ast.catch
|
|
1034
|
-
];
|
|
1035
|
-
for (let child of nodes) transformSvelte(child, env);
|
|
1036
|
-
}
|
|
1037
|
-
if (ast.html) transformSvelte(ast.html, env);
|
|
1038
|
-
}
|
|
1039
|
-
const { parsers, printers } = createPlugin([
|
|
1040
|
-
defineTransform({
|
|
1041
|
-
staticAttrs: ["class"],
|
|
1042
|
-
load: ["prettier/plugins/html"],
|
|
1043
|
-
compatible: ["prettier-plugin-organize-attributes"],
|
|
1044
|
-
parsers: {
|
|
1045
|
-
html: {},
|
|
1046
|
-
lwc: {},
|
|
1047
|
-
angular: { dynamicAttrs: ["[ngClass]"] },
|
|
1048
|
-
vue: { dynamicAttrs: [":class", "v-bind:class"] }
|
|
1049
|
-
},
|
|
1050
|
-
transform: transformHtml
|
|
1051
|
-
}),
|
|
1052
|
-
defineTransform({
|
|
1053
|
-
staticAttrs: ["class"],
|
|
1054
|
-
load: ["prettier/plugins/glimmer"],
|
|
1055
|
-
parsers: { glimmer: {} },
|
|
1056
|
-
transform: transformGlimmer
|
|
1057
|
-
}),
|
|
1058
|
-
defineTransform({
|
|
1059
|
-
load: [postcss_exports],
|
|
1060
|
-
compatible: ["prettier-plugin-css-order"],
|
|
1061
|
-
parsers: {
|
|
1062
|
-
css: {},
|
|
1063
|
-
scss: {},
|
|
1064
|
-
less: {}
|
|
1065
|
-
},
|
|
1066
|
-
transform: transformCss
|
|
1067
|
-
}),
|
|
1068
|
-
defineTransform({
|
|
1069
|
-
staticAttrs: ["class", "className"],
|
|
1070
|
-
compatible: [
|
|
1071
|
-
"prettier-plugin-multiline-arrays",
|
|
1072
|
-
"@ianvs/prettier-plugin-sort-imports",
|
|
1073
|
-
"@trivago/prettier-plugin-sort-imports",
|
|
1074
|
-
"prettier-plugin-organize-imports",
|
|
1075
|
-
"prettier-plugin-sort-imports",
|
|
1076
|
-
"prettier-plugin-jsdoc"
|
|
1077
|
-
],
|
|
1078
|
-
parsers: {
|
|
1079
|
-
babel: { load: [babel_exports] },
|
|
1080
|
-
"babel-flow": { load: [babel_exports] },
|
|
1081
|
-
"babel-ts": { load: [babel_exports] },
|
|
1082
|
-
__js_expression: { load: [babel_exports] },
|
|
1083
|
-
typescript: { load: ["prettier/plugins/typescript"] },
|
|
1084
|
-
meriyah: { load: ["prettier/plugins/meriyah"] },
|
|
1085
|
-
acorn: { load: ["prettier/plugins/acorn"] },
|
|
1086
|
-
flow: { load: ["prettier/plugins/flow"] },
|
|
1087
|
-
oxc: { load: ["@prettier/plugin-oxc"] },
|
|
1088
|
-
"oxc-ts": { load: ["@prettier/plugin-oxc"] },
|
|
1089
|
-
hermes: { load: ["@prettier/plugin-hermes"] },
|
|
1090
|
-
astroExpressionParser: {
|
|
1091
|
-
load: ["prettier-plugin-astro"],
|
|
1092
|
-
staticAttrs: ["class"],
|
|
1093
|
-
dynamicAttrs: ["class:list"]
|
|
1094
|
-
}
|
|
1095
|
-
},
|
|
1096
|
-
transform: transformJavaScript
|
|
1097
|
-
}),
|
|
1098
|
-
defineTransform({
|
|
1099
|
-
staticAttrs: ["class"],
|
|
1100
|
-
load: ["prettier-plugin-svelte"],
|
|
1101
|
-
parsers: { svelte: {} },
|
|
1102
|
-
printers: { "svelte-ast": {} },
|
|
1103
|
-
transform: transformSvelte,
|
|
1104
|
-
reprint(path, { options, changes }) {
|
|
1105
|
-
if (options.__mutatedOriginalText) return;
|
|
1106
|
-
options.__mutatedOriginalText = true;
|
|
1107
|
-
if (!(changes === null || changes === void 0 ? void 0 : changes.length)) return;
|
|
1108
|
-
let finder = (0, import_line_column.default)(options.originalText);
|
|
1109
|
-
let stringChanges = changes.map((change) => ({
|
|
1110
|
-
...change,
|
|
1111
|
-
start: finder.toIndex(change.start.line, change.start.column + 1),
|
|
1112
|
-
end: finder.toIndex(change.end.line, change.end.column + 1)
|
|
1113
|
-
}));
|
|
1114
|
-
options.originalText = spliceChangesIntoString(options.originalText, stringChanges);
|
|
1115
|
-
}
|
|
1116
|
-
}),
|
|
1117
|
-
defineTransform({
|
|
1118
|
-
staticAttrs: ["class", "className"],
|
|
1119
|
-
dynamicAttrs: ["class:list", "className"],
|
|
1120
|
-
load: ["prettier-plugin-astro"],
|
|
1121
|
-
parsers: { astro: {} },
|
|
1122
|
-
transform: transformAstro
|
|
1123
|
-
}),
|
|
1124
|
-
defineTransform({
|
|
1125
|
-
staticAttrs: ["class"],
|
|
1126
|
-
load: ["prettier-plugin-marko"],
|
|
1127
|
-
parsers: { marko: {} },
|
|
1128
|
-
transform: transformMarko
|
|
1129
|
-
}),
|
|
1130
|
-
defineTransform({
|
|
1131
|
-
staticAttrs: ["class"],
|
|
1132
|
-
load: ["@zackad/prettier-plugin-twig"],
|
|
1133
|
-
parsers: { twig: {} },
|
|
1134
|
-
transform: transformTwig
|
|
1135
|
-
}),
|
|
1136
|
-
defineTransform({
|
|
1137
|
-
staticAttrs: ["class"],
|
|
1138
|
-
load: ["@prettier/plugin-pug"],
|
|
1139
|
-
parsers: { pug: {} },
|
|
1140
|
-
transform: transformPug
|
|
1141
|
-
}),
|
|
1142
|
-
defineTransform({
|
|
1143
|
-
staticAttrs: ["class"],
|
|
1144
|
-
load: ["@shopify/prettier-plugin-liquid"],
|
|
1145
|
-
parsers: { "liquid-html": {} },
|
|
1146
|
-
transform: transformLiquid
|
|
1147
|
-
})
|
|
1148
|
-
]);
|
|
1149
|
-
|
|
1150
|
-
//#endregion
|
|
1151
|
-
export { options, parsers, printers };
|