@csszyx/unplugin 0.11.10 → 0.12.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.
@@ -1,49 +0,0 @@
1
- const LEADING_WHITESPACE_RE = /^\s+/;
2
- const LINE_COMMENT_RE = /^\/\/[^\n]*(?:\n|$)/;
3
- const BLOCK_COMMENT_RE = /^\/\*[\s\S]*?\*\//;
4
- const USE_DIRECTIVE_RE = /^['"]use (?:client|server)['"];?\s*/;
5
- function insertAfterUseDirective(code, insertion) {
6
- let offset = 0;
7
- while (offset < code.length) {
8
- const triviaLength = leadingTriviaLength(code.slice(offset));
9
- if (triviaLength === 0) break;
10
- offset += triviaLength;
11
- }
12
- const directive = USE_DIRECTIVE_RE.exec(code.slice(offset));
13
- if (!directive) return `${insertion}${code}`;
14
- const insertionOffset = offset + directive[0].length;
15
- return `${code.slice(0, insertionOffset)}${insertion}${code.slice(insertionOffset)}`;
16
- }
17
- function leadingTriviaLength(source) {
18
- return LEADING_WHITESPACE_RE.exec(source)?.[0].length ?? LINE_COMMENT_RE.exec(source)?.[0].length ?? BLOCK_COMMENT_RE.exec(source)?.[0].length ?? 0;
19
- }
20
-
21
- const RUNTIME_IMPORT_CLAUSE_RE = /(?:import|export)\s+\{([^{}]*)\}\s*from\s*['"]@csszyx\/runtime['"]/g;
22
- function clauseNames(clauseBody) {
23
- const names = [];
24
- for (const part of clauseBody.split(",")) {
25
- const trimmed = part.trim();
26
- if (!trimmed) {
27
- continue;
28
- }
29
- const spaceAt = trimmed.search(/\s/);
30
- names.push(spaceAt === -1 ? trimmed : trimmed.slice(0, spaceAt));
31
- }
32
- return names;
33
- }
34
- function importsRuntimeHelper(code, helper) {
35
- RUNTIME_IMPORT_CLAUSE_RE.lastIndex = 0;
36
- for (let match = RUNTIME_IMPORT_CLAUSE_RE.exec(code); match; match = RUNTIME_IMPORT_CLAUSE_RE.exec(code)) {
37
- if (clauseNames(match[1]).includes(helper)) {
38
- return true;
39
- }
40
- }
41
- return false;
42
- }
43
- const RUNTIME_IMPORT_APPEND_RE = /(import\s+\{[^{}]*)\}\s*from\s*['"]@csszyx\/runtime['"]/;
44
- function findRuntimeImportClause(code) {
45
- const match = RUNTIME_IMPORT_APPEND_RE.exec(code);
46
- return match ? { statement: match[0], prefixWithBody: match[1] } : null;
47
- }
48
-
49
- export { insertAfterUseDirective as a, findRuntimeImportClause as f, importsRuntimeHelper as i };