mp-lens
Version:
微信小程序分析工具 (Unused Code, Dependencies, Visualization)
45 lines • 1.64 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.WXSSParser = void 0;
const debug_logger_1 = require("../utils/debug-logger");
class WXSSParser {
constructor() {
// No dependencies needed for pure text analysis
}
async parse(content, filePath) {
try {
const dependencies = new Set();
// Match @import statements
const importRegex = /@import\s+['"]([^'"]+)['"]/g;
// Match url() references
const urlRegex = /url\(['"]?([^'")]+)['"]?\)/g;
let match;
// Process @import statements
while ((match = importRegex.exec(content)) !== null) {
if (match[1]) {
const importPath = match[1];
dependencies.add(importPath);
}
}
// Process url() references
while ((match = urlRegex.exec(content)) !== null) {
if (match[1]) {
const urlPath = match[1].trim();
if (urlPath.startsWith('data:') ||
/^(http|https):\/\//.test(urlPath) ||
/{{.*?}}/.test(urlPath)) {
continue;
}
dependencies.add(urlPath);
}
}
return Array.from(dependencies);
}
catch (e) {
debug_logger_1.logger.warn(`Error parsing WXSS file ${filePath}: ${e.message}`);
throw e; // Re-throw
}
}
}
exports.WXSSParser = WXSSParser;
//# sourceMappingURL=wxss-parser.js.map