/*
 * Copyright (c) 2018, 2025, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 */
var path;const TsxUtils=function(preCompUtils,jafUtils,fsUtils,msgCtx,nd){this._utils=preCompUtils;this._jafUtils=jafUtils;this._fsUtils=fsUtils;this._msgCtx=msgCtx;path=nd.path};TsxUtils.prototype.extractComponentInfoFromTSXFile=function(componentFolder,fileName,isLocal,precompileCache){const packRegEx=/@ojmetadata[\s]*pack[\s]*[\"|'](?<pack>[a-zA-Z\-0-9]*)[\"|']/mg;const versionRegEx=/@ojmetadata[\s]*version[\s]*[\"|'](?<version>[\.0-9\-a-zA-Z]*)[\"|']/mg;const jetVersionRegEx=/@ojmetadata[\s]*jetVersion[\s]*[\"|'](?<version>[\.0-9\-a-zA-Z^~><=]*)[\"|']/mg;let componentInfo={};const tsxFile=path.join(componentFolder,fileName);const fileAsStr=this._fsUtils.readFileSync(tsxFile);const componentIdentification=this._getVComponentElementNameAndImpl(fileAsStr);const fullName=componentIdentification.elementName;const className=componentIdentification.class;const componentName=this._getVComponentComponentName(fileAsStr);let fullNameMetadata=false;if(precompileCache){let mdSource=null;if(fullName){this._msgCtx.debug(`Processing tsx and metadata for ${fullName}`);mdSource=`${precompileCache}/${fullName}.json`;if(!this._fsUtils.fileExistsSync(mdSource)){mdSource=`${precompileCache}/${componentName}.json`;if(!componentName||!this._fsUtils.fileExistsSync(mdSource)){mdSource=null}}else{fullNameMetadata=true}}if(mdSource!==null){componentInfo=this._utils.extractComponentInfoFromJSONFile(precompileCache,`${fullNameMetadata?fullName:componentName}.json`,isLocal,true);componentInfo.rootFolder=this._utils.toJAFPath(componentFolder);componentInfo.compiledMetadata=mdSource;componentInfo.vcomponent=true;componentInfo.viewModel={resolved:true,path:this._utils.toJAFPath(tsxFile)};componentInfo.viewModel.className=className;if(!componentName){componentInfo.inferredName=true}if(componentInfo.pack){const matchPack=packRegEx.exec(fileAsStr);if(!matchPack||!matchPack.groups.pack){componentInfo.inferredPack=true}}const matchVer=versionRegEx.exec(fileAsStr);if(!matchVer||!matchVer.groups.version){componentInfo.inferredVersion=true}const matchJetVer=jetVersionRegEx.exec(fileAsStr);if(!matchJetVer||!matchJetVer.groups.version){componentInfo.inferredJetVersion=true}return componentInfo}else{return}}else{if(fullName){this._msgCtx.error(`Unable to audit VComponent ${fullName}, pre-compiled metadata is not available`)}return}};TsxUtils.prototype._getVComponentElementNameAndImpl=function(sourceCode){var resolvedElementName,implementationClass;const elementRegExForFunction=/export const\s*(?<className>\w+)[\w\s\<\>:]*=\s*registerCustomElement[\s<>\w]*\(\s*[\"\'](?<fullName>[\w-]*)\s*[\"\']\s*,/mg;const matchElementFunction=elementRegExForFunction.exec(sourceCode);if(matchElementFunction&&matchElementFunction.groups&&matchElementFunction.groups.fullName&&matchElementFunction.groups.className){resolvedElementName=matchElementFunction.groups.fullName;implementationClass=matchElementFunction.groups.className}else{const elementRegExForClass=/\s*@customElement\s*\(\s*[\"\']\s*(?<fullName>[\w-]*)\s*[\"\']\s*\)/mg;const matchElementClass=elementRegExForClass.exec(sourceCode);if(matchElementClass&&matchElementClass.groups&&matchElementClass.groups.fullName){resolvedElementName=matchElementClass.groups.fullName}const elementRegExForClassImpl=/[\s]*export[\s]*class[\s]*(?<className>[a-zA-Z\-0-9_]*)[\s]*extends[\s]*(?<superClass>[a-zA-Z\-0-9_]*)/mg;while((classDef=elementRegExForClassImpl.exec(sourceCode))!==null){if(classDef.groups.superClass==="Component"){implementationClass=classDef.groups.className}}}if(resolvedElementName&&!implementationClass){this._msgCtx.info(`WARNING: Unable to determine VComponent class-name for ${resolvedElementName}`)}return{elementName:resolvedElementName,class:implementationClass}};TsxUtils.prototype._getVComponentComponentName=function(sourceCode){const nameRegEx=/@ojmetadata[\s]*name [\"|'](?<componentName>[a-zA-Z\-0-9]*)[\"|']/mg;const matchElement=nameRegEx.exec(sourceCode);var ret;if(matchElement&&matchElement.groups&&matchElement.groups.componentName){ret=matchElement.groups.componentName}return ret};TsxUtils.prototype.matchToVComponentImpl=function(testFileName){let componentInfo;let fileNameCanonical=this._utils.toJAFPath(testFileName);if(fileNameCanonical.endsWith(".tsx")){const componentMatch=this._utils.matchComponentPath(fileNameCanonical);if(componentMatch){const testPossibleComponentInfo=this._utils.componentInfo(componentMatch);if(testPossibleComponentInfo.viewModel&&fileNameCanonical===testPossibleComponentInfo.viewModel.path){componentInfo=testPossibleComponentInfo}}}return componentInfo};module.exports=TsxUtils;