UNPKG

@hadss/hmrouter-plugin

Version:

HMRouter Compiler Plugin

33 lines (32 loc) 1.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConstantAnalyzer = void 0; const framework_1 = require("../../../framework"); class ConstantAnalyzer { constructor(constantResolver) { this.constantResolver = constantResolver; } parseConstants(analyzeResults) { analyzeResults.forEach((item) => { this.parseResult(item); }); } parseResult(result) { if (!result.sourceFilePath) { return; } Object.getOwnPropertyNames(result).forEach((key) => { let propertyValue = Reflect.get(result, key); propertyValue = this.parsePropertyValue(result.sourceFilePath, propertyValue); if (propertyValue === '') { throw new Error(`Constants value cannot be an empty string, filePath: ${result.sourceFilePath}`); } Reflect.set(result, key, propertyValue); }); } parsePropertyValue(filePath, propertyValue) { const sourceFile = framework_1.TsAstUtil.getSourceFile(filePath); return this.constantResolver.resolveConstant(propertyValue, sourceFile, filePath); } } exports.ConstantAnalyzer = ConstantAnalyzer;