@plumeria/compiler 0.14.6 → 0.14.7
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/dist/extract.js +68 -3
- package/dist/index.js +22 -5
- package/package.json +1 -1
package/dist/extract.js
CHANGED
|
@@ -29,12 +29,75 @@ function isInComment(code, position) {
|
|
|
29
29
|
}
|
|
30
30
|
return inMultiLineComment;
|
|
31
31
|
}
|
|
32
|
+
function isInString(code, position) {
|
|
33
|
+
let inSingleQuote = false;
|
|
34
|
+
let inDoubleQuote = false;
|
|
35
|
+
let inBacktick = false;
|
|
36
|
+
let escape = false;
|
|
37
|
+
for (let i = 0; i < position; i++) {
|
|
38
|
+
const char = code[i];
|
|
39
|
+
if (escape) {
|
|
40
|
+
escape = false;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (char === '\\') {
|
|
44
|
+
escape = true;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (!inSingleQuote && !inDoubleQuote && !inBacktick) {
|
|
48
|
+
if (char === "'") {
|
|
49
|
+
inSingleQuote = true;
|
|
50
|
+
}
|
|
51
|
+
else if (char === '"') {
|
|
52
|
+
inDoubleQuote = true;
|
|
53
|
+
}
|
|
54
|
+
else if (char === '`') {
|
|
55
|
+
inBacktick = true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
if (inSingleQuote && char === "'") {
|
|
60
|
+
inSingleQuote = false;
|
|
61
|
+
}
|
|
62
|
+
else if (inDoubleQuote && char === '"') {
|
|
63
|
+
inDoubleQuote = false;
|
|
64
|
+
}
|
|
65
|
+
else if (inBacktick && char === '`') {
|
|
66
|
+
inBacktick = false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return inSingleQuote || inDoubleQuote || inBacktick;
|
|
71
|
+
}
|
|
72
|
+
function isInHtmlText(code, position) {
|
|
73
|
+
let lastOpenTag = -1;
|
|
74
|
+
let lastCloseTag = -1;
|
|
75
|
+
for (let i = position - 1; i >= 0; i--) {
|
|
76
|
+
if (code[i] === '>' && lastCloseTag === -1) {
|
|
77
|
+
lastCloseTag = i;
|
|
78
|
+
}
|
|
79
|
+
if (code[i] === '<') {
|
|
80
|
+
lastOpenTag = i;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
let nextOpenTag = -1;
|
|
85
|
+
for (let i = position; i < code.length; i++) {
|
|
86
|
+
if (code[i] === '<') {
|
|
87
|
+
nextOpenTag = i;
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return lastCloseTag > lastOpenTag && nextOpenTag > position;
|
|
92
|
+
}
|
|
32
93
|
function extractCssProps(code) {
|
|
33
94
|
const propsMatches = [];
|
|
34
95
|
const regex = /css\.props\s*\(/g;
|
|
35
96
|
let match;
|
|
36
97
|
while ((match = regex.exec(code))) {
|
|
37
|
-
if (isInComment(code, match.index)
|
|
98
|
+
if (isInComment(code, match.index) ||
|
|
99
|
+
isInString(code, match.index) ||
|
|
100
|
+
isInHtmlText(code, match.index)) {
|
|
38
101
|
continue;
|
|
39
102
|
}
|
|
40
103
|
const startIndex = match.index + match[0].length;
|
|
@@ -69,7 +132,9 @@ function extractCssCreate(code) {
|
|
|
69
132
|
const regex = /(?:(?:\s*const\s+[a-zA-Z0-9_$]+\s*=\s*css\.create\([\s\S]*?\);\s*))/g;
|
|
70
133
|
let match;
|
|
71
134
|
while ((match = regex.exec(code))) {
|
|
72
|
-
if (isInComment(code, match.index)
|
|
135
|
+
if (isInComment(code, match.index) ||
|
|
136
|
+
isInString(code, match.index) ||
|
|
137
|
+
isInHtmlText(code, match.index)) {
|
|
73
138
|
continue;
|
|
74
139
|
}
|
|
75
140
|
cssCreateMatches.push(match[0]);
|
|
@@ -99,7 +164,7 @@ function parseCssPropsArguments(args) {
|
|
|
99
164
|
}
|
|
100
165
|
return results;
|
|
101
166
|
}
|
|
102
|
-
function extractVueAndSvelte(filePath) {
|
|
167
|
+
async function extractVueAndSvelte(filePath) {
|
|
103
168
|
const ext = path.extname(filePath);
|
|
104
169
|
if (!(ext === '.svelte' || ext === '.vue'))
|
|
105
170
|
return filePath;
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ const combineMediaQuery = require('postcss-combine-media-query');
|
|
|
10
10
|
const { execute } = require('rscute/execute');
|
|
11
11
|
const { transform } = require('lightningcss');
|
|
12
12
|
const { parseSync } = require('@swc/core');
|
|
13
|
-
const { buildGlobal,
|
|
13
|
+
const { buildGlobal, buildProps } = require('@plumeria/core/processors');
|
|
14
14
|
const { extractAndInjectStyleProps, restoreAllOriginals, extractVueAndSvelte, } = require('./extract');
|
|
15
15
|
const projectRoot = process.cwd().split('node_modules')[0];
|
|
16
16
|
const directPath = path.join(projectRoot, 'node_modules/@plumeria/core');
|
|
@@ -105,9 +105,26 @@ async function optimizeCSS() {
|
|
|
105
105
|
cwd: projectRoot,
|
|
106
106
|
});
|
|
107
107
|
const projectName = path.basename(projectRoot);
|
|
108
|
-
const filesSupportExtensions =
|
|
109
|
-
const
|
|
110
|
-
|
|
108
|
+
const filesSupportExtensions = [];
|
|
109
|
+
for (const file of files) {
|
|
110
|
+
const tsFile = await extractVueAndSvelte(file);
|
|
111
|
+
filesSupportExtensions.push(tsFile);
|
|
112
|
+
}
|
|
113
|
+
const styleFiles = filesSupportExtensions
|
|
114
|
+
.filter((file) => isCSS(file, ''))
|
|
115
|
+
.sort();
|
|
116
|
+
const cssPropsFiles = styleFiles.filter((file) => {
|
|
117
|
+
if (file.endsWith('.ts')) {
|
|
118
|
+
const vueFile = file.replace('.ts', '.vue');
|
|
119
|
+
const svelteFile = file.replace('.ts', '.svelte');
|
|
120
|
+
const isGeneratedFromVue = existsSync(vueFile);
|
|
121
|
+
const isGeneratedFromSvelte = existsSync(svelteFile);
|
|
122
|
+
if (isGeneratedFromVue || isGeneratedFromSvelte) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return isCSS(file, 'props');
|
|
127
|
+
});
|
|
111
128
|
for (let i = 0; i < cssPropsFiles.length; i++) {
|
|
112
129
|
await extractAndInjectStyleProps(path.resolve(cssPropsFiles[i]));
|
|
113
130
|
}
|
|
@@ -120,7 +137,7 @@ async function optimizeCSS() {
|
|
|
120
137
|
await buildGlobal(coreFilePath);
|
|
121
138
|
}
|
|
122
139
|
for (let i = 0; i < styleFiles.length; i++) {
|
|
123
|
-
await
|
|
140
|
+
await buildProps(coreFilePath);
|
|
124
141
|
}
|
|
125
142
|
await optimizeCSS();
|
|
126
143
|
await restoreAllOriginals();
|