@oracle/oraclejet-audit 15.1.9 → 16.0.1

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.
Files changed (151) hide show
  1. package/corePackMigrator/corePackMigrator.js +2 -2
  2. package/corePackMigrator/metadata/actionCardMetadata.json +8 -0
  3. package/corePackMigrator/metadata/avatarMetadata.json +0 -12
  4. package/corePackMigrator/metadata/drawerPopupMetadata.json +16 -0
  5. package/corePackMigrator/metadata/formLayoutMetadata.json +34 -0
  6. package/corePackMigrator/metadata/highlightTextMetadata.json +8 -0
  7. package/corePackMigrator/metadata/inputNumberMetadata.json +26 -2
  8. package/corePackMigrator/metadata/inputPasswordMetadata.json +32 -2
  9. package/corePackMigrator/metadata/inputTextMetadata.json +26 -2
  10. package/corePackMigrator/metadata/legendItemMetadata.json +1 -5
  11. package/corePackMigrator/metadata/legendMetadata.json +42 -0
  12. package/corePackMigrator/metadata/legendSectionMetadata.json +6 -4
  13. package/corePackMigrator/metadata/listviewMetadata.json +61 -2
  14. package/corePackMigrator/metadata/messageBannerMetadata.json +8 -0
  15. package/corePackMigrator/metadata/messagesMetadata.json +17 -5
  16. package/corePackMigrator/metadata/radiosetMetadata.json +86 -0
  17. package/corePackMigrator/metadata/ratingGaugeMetadata.json +29 -17
  18. package/corePackMigrator/metadata/selectManyMetadata.json +9 -3
  19. package/corePackMigrator/metadata/selectSingleMetadata.json +16 -5
  20. package/corePackMigrator/metadata/selectorMetadata.json +37 -0
  21. package/corePackMigrator/metadata/statusMeterGaugeMetadata.json +21 -9
  22. package/corePackMigrator/metadata/tagCloudMetadata.json +8 -0
  23. package/corePackMigrator/metadata/textAreaMetadata.json +8 -2
  24. package/corePackMigrator/resource/astUtils.js +1 -1
  25. package/corePackMigrator/resource/componentMigrator.js +1 -1
  26. package/corePackMigrator/resource/fileScanner.js +1 -1
  27. package/corePackMigrator/resource/htmlUtils.js +1 -1
  28. package/corePackMigrator/resource/manifest.json +25 -10
  29. package/corePackMigrator/resource/migrationConfig.json +3 -0
  30. package/corePackMigrator/templates/componentMetaData.json +18 -4
  31. package/corePackMigrator/templates/migrationConfig.json +15 -3
  32. package/corePackMigrator/utilities/logging.js +1 -1
  33. package/jaf-amd.js +1 -1
  34. package/jaf.js +1 -1
  35. package/jafapi.js +1 -1
  36. package/lib/AST_Ts.js +1 -1
  37. package/lib/AstJson.js +1 -1
  38. package/lib/AstNodeTypes.js +1 -1
  39. package/lib/Components.js +1 -1
  40. package/lib/DomUtils.js +1 -1
  41. package/lib/FsUtils.js +1 -1
  42. package/lib/HtmlUtils.js +1 -1
  43. package/lib/JafLib.js +1 -1
  44. package/lib/MetaLib.js +1 -1
  45. package/lib/OjCPack.js +1 -1
  46. package/lib/Registry.js +1 -1
  47. package/lib/RulePack.js +1 -1
  48. package/lib/RuleSet.js +1 -1
  49. package/lib/Rules.js +1 -1
  50. package/lib/Stats.js +1 -1
  51. package/lib/Ts.js +1 -1
  52. package/lib/TsUtils.js +6 -0
  53. package/lib/TsxUtils.js +1 -1
  54. package/lib/TsxUtils2.js +1 -1
  55. package/lib/Utils.js +1 -1
  56. package/lib/checkage.js +1 -1
  57. package/lib/defaults.js +1 -1
  58. package/lib/jsx.js +1 -1
  59. package/lib/migrator.js +1 -1
  60. package/lib/scaffold.js +1 -1
  61. package/lib/sublib/precomp/ComponentFinder.js +6 -0
  62. package/lib/sublib/precomp/Precompiler.js +6 -0
  63. package/lib/sublib/precomp/TsxUtils.js +6 -0
  64. package/lib/sublib/precomp/Utils.js +6 -0
  65. package/meta/15.0.0/jetauditmeta.js +1 -1
  66. package/meta/15.1.0/jetauditmeta.js +1 -1
  67. package/meta/16.0.0/jetauditmeta.js +9 -0
  68. package/meta/metaverlist.json +1 -1
  69. package/package.json +10 -7
  70. package/profiles/best-practice.json +1 -0
  71. package/rulepacks/csp/csp-json-unsafe-expr.js +1 -1
  72. package/rulepacks/jetwc/jetwc-bootstrap.js +1 -1
  73. package/rulepacks/jetwc/jetwc-require-paths.js +1 -1
  74. package/rulepacks/jetwc/jetwc-schema.js +1 -1
  75. package/rulepacks/jetwc/jetwc-well-formed-description.js +6 -0
  76. package/rulepacks/jetwc/msgid.json +1 -1
  77. package/rulepacks/jetwc/rules.json +1 -1
  78. package/rulepacks/jetwc-lib/jetwcutils-componentAuditUtils.js +1 -1
  79. package/rulepacks/jetwc-lib/jetwcutils-componentFinder.js +1 -1
  80. package/rulepacks/jetwc-lib/jetwcutils-tsxUtils.js +1 -1
  81. package/rulepacks/jetwco/jetwco-bootstrap.js +1 -1
  82. package/rulepacks/jetwco/jetwco-cacc-methodParamTypes.js +1 -1
  83. package/rulepacks/jetwco/jetwco-cacc-methodReturnType.js +1 -1
  84. package/rulepacks/jetwco/jetwco-description-standards.js +1 -1
  85. package/rulepacks/jetwco/jetwco-license-info.js +1 -1
  86. package/rulepacks/jetwco/jetwco-validate-applied-audits.js +6 -0
  87. package/rulepacks/jetwco/msgid.json +1 -1
  88. package/rulepacks/jetwco/rules.json +1 -1
  89. package/rulepacks/ojc/msgid.json +1 -1
  90. package/rulepacks/ojc/ojc-html-button-defslot.js +6 -0
  91. package/rulepacks/ojc/ojc-tsx-button-defslot.js +6 -0
  92. package/rulepacks/ojc/rules.json +1 -1
  93. package/rules/jaf/jaf-css-diagnose.js +1 -1
  94. package/rules/jaf/jaf-js-diagnose.js +1 -1
  95. package/rules/jaf/jaf-sys-dup-component.js +6 -0
  96. package/rules/jaf/jaf-sys-rule-opt.js +6 -0
  97. package/rules/jaf/jaf-ts-precompile.js +6 -0
  98. package/rules/jaf/msgid.json +1 -1
  99. package/rules/jaf/rules.json +1 -1
  100. package/rules/jet/helpers/has-slot-name.js +1 -1
  101. package/rules/jet/msgid.json +1 -1
  102. package/rules/jet/oj-cca-compjson-bp-jetver.js +1 -1
  103. package/rules/jet/oj-html-alta-deprecated.js +1 -1
  104. package/rules/jet/oj-html-attr-expr-writeback.js +6 -0
  105. package/rules/jet/oj-html-binding-as-slot-child.js +6 -0
  106. package/rules/jet/oj-html-event-focus-blur.js +6 -0
  107. package/rules/jet/oj-html-form-bindif.js +1 -1
  108. package/rules/jet/oj-html-ojattr-deprecated.js +1 -1
  109. package/rules/jet/oj-html-ojattr-enum-deprecated.js +1 -1
  110. package/rules/jet/oj-html-ojattr.js +1 -1
  111. package/rules/jet/oj-html-ojtag-deprecated.js +1 -1
  112. package/rules/jet/oj-html-ojtag-nonglobattr-prefix.js +1 -1
  113. package/rules/jet/oj-html-prop-anti-pattern.js +6 -0
  114. package/rules/jet/oj-html-slot-default.js +6 -0
  115. package/rules/jet/oj-html-slot-deprecated.js +1 -1
  116. package/rules/jet/oj-html-slot-name.js +1 -1
  117. package/rules/jet/oj-html-slot-pref-content.js +1 -1
  118. package/rules/jet/oj-html-style-deprecated.js +1 -1
  119. package/rules/jet/oj-html-treeview-actionable-content.js +6 -0
  120. package/rules/jet/oj-html-wctag-anti-pattern.js +6 -0
  121. package/rules/jet/oj-html-wctag-maintenance.js +1 -1
  122. package/rules/jet/oj-html-wctag-supersedes.js +1 -1
  123. package/rules/jet/oj-js-ojcomp-exist.js +1 -1
  124. package/rules/jet/oj-ts-ojcomp-exist.js +1 -1
  125. package/rules/jet/oj-tsx-aria-ojselector-labelledby.js +1 -1
  126. package/rules/jet/oj-tsx-aria-prop.js +1 -1
  127. package/rules/jet/oj-tsx-event.js +6 -0
  128. package/rules/jet/oj-tsx-ojattr-deprecated.js +1 -1
  129. package/rules/jet/oj-tsx-ojattr-enum-deprecated.js +1 -1
  130. package/rules/jet/oj-tsx-ojattr-value.js +1 -1
  131. package/rules/jet/oj-tsx-ojattr.js +1 -1
  132. package/rules/jet/oj-tsx-ojtag-deprecated.js +1 -1
  133. package/rules/jet/oj-tsx-pageopts-type.js +1 -1
  134. package/rules/jet/oj-tsx-picker-attrs.js +1 -1
  135. package/rules/jet/oj-tsx-popup-sibling.js +6 -0
  136. package/rules/jet/oj-tsx-prop-anti-pattern.js +6 -0
  137. package/rules/jet/oj-tsx-rating-gauge-size.js +1 -1
  138. package/rules/jet/oj-tsx-rating-gauge-track-resize.js +1 -1
  139. package/rules/jet/oj-tsx-slot-deprecated.js +1 -1
  140. package/rules/jet/oj-tsx-slot-pref-content.js +1 -1
  141. package/rules/jet/oj-tsx-treeview-actionable-content.js +6 -0
  142. package/rules/jet/oj-tsx-unsup-theme.js +1 -1
  143. package/rules/jet/oj-tsx-wctag-anti-pattern.js +6 -0
  144. package/rules/jet/oj-tsx-wctag-maintenance.js +1 -1
  145. package/rules/jet/rules.json +1 -1
  146. package/schema/component-schema.json +1 -1
  147. package/src/JafCore.js +1 -1
  148. package/types/index.d.ts +1 -0
  149. package/rulepacks/jetwc-lib/jetwcutils-preCompiler.js +0 -6
  150. package/rules/jet/oj-html-combo-converter.js +0 -6
  151. package/rules/jet/oj-tsx-combo-converter.js +0 -6
package/jaf.js CHANGED
@@ -4,4 +4,4 @@
4
4
  * Licensed under The Universal Permissive License (UPL), Version 1.0
5
5
  * as shown at https://oss.oracle.com/licenses/upl/
6
6
  */
7
- (function(){const ac=require("./src/JafCore");var nd={fs:require("fs"),path:require("path"),glob:require("glob"),process:process,os:require("os"),decomment:require("strip-json-comments"),decache:require("decache"),Config:require("./lib/Config"),metaLoader:require("./lib/metaLoader"),ruleLoader:require("./lib/ruleLoader"),msgidLoader:require("./lib/msgidLoader"),jsonLoader:require("./lib/JsonLoader"),Components:require("./lib/Components"),ComponentSvcs:require("./lib/ComponentSvcs"),schema:require("./lib/schema"),builtinpacks:require("./lib/builtinpacks"),extends:require("./lib/extends"),tsparse:require("@typescript-eslint/typescript-estree"),scaffold:require("./lib/scaffold.js"),scaffoldRule:require("./lib/scaffoldRule.js"),fsUtils:require("./lib/FsUtils"),zipUtils:require("./lib/ZipUtils"),ojetUtils:require("./lib/OjetLib"),Watch:require("./lib/Watch"),colors:require("./lib/Color"),Cli:require("./lib/Cli"),jetver:require("./lib/jetver"),exportRules:require("./lib/exportRules"),spinner:require("./lib/spinnernoop")};let rc=new ac(nd).start();if(rc!==99){process.exit(rc)}})();
7
+ (function(){const ac=require("./src/JafCore");var nd={fs:require("fs"),path:require("path"),glob:require("glob"),process:process,os:require("os"),decomment:require("strip-json-comments"),decache:require("decache"),Config:require("./lib/Config"),metaLoader:require("./lib/metaLoader"),ruleLoader:require("./lib/ruleLoader"),msgidLoader:require("./lib/msgidLoader"),jsonLoader:require("./lib/JsonLoader"),Components:require("./lib/Components"),ComponentSvcs:require("./lib/ComponentSvcs"),schema:require("./lib/schema"),builtinpacks:require("./lib/builtinpacks"),extends:require("./lib/extends"),tsparse:require("@typescript-eslint/typescript-estree"),scaffold:require("./lib/scaffold.js"),scaffoldRule:require("./lib/scaffoldRule.js"),fsUtils:require("./lib/FsUtils"),zipUtils:require("./lib/ZipUtils"),ojetUtils:require("./lib/OjetLib"),tsUtils:require("./lib/TsUtils"),Watch:require("./lib/Watch"),colors:require("./lib/Color"),Cli:require("./lib/Cli"),jetver:require("./lib/jetver"),exportRules:require("./lib/exportRules"),spinner:require("./lib/spinnernoop")};let rc=new ac(nd).start();if(rc!==99){process.exit(rc)}})();
package/jafapi.js CHANGED
@@ -3,4 +3,4 @@
3
3
  * Licensed under The Universal Permissive License (UPL), Version 1.0
4
4
  * as shown at https://oss.oracle.com/licenses/upl/
5
5
  */
6
- var Jaf=function(){this._audit=require("./src/JafCore");this._api=require("./lib/api");this._nd={fs:require("fs"),path:require("path"),glob:require("glob"),process:process,os:require("os"),decomment:require("strip-json-comments"),decache:require("decache"),Config:require("./lib/Config"),metaLoader:require("./lib/metaLoader"),ruleLoader:require("./lib/ruleLoader"),msgidLoader:require("./lib/msgidLoader"),jsonLoader:require("./lib/JsonLoader"),Components:require("./lib/Components"),ComponentSvcs:require("./lib/ComponentSvcs"),schema:require("./lib/schema"),builtinpacks:null,extends:require("./lib/extends"),tsparse:require("@typescript-eslint/typescript-estree"),fsUtils:require("./lib/FsUtils"),zipUtils:require("./lib/ZipUtils"),jetver:require("./lib/jetver"),exportRules:require("./lib/exportRules"),spinner:require("./lib/spinnernoop")};this._audit=new this._audit(this._nd,"api");this._api=new this._api(this._nd,this._audit);this._error=1};Jaf.prototype.initSync=function(config,cbIssue,cbMsg,cbSummary){this._error=this._api.startSync({config:config,cbIssue:cbIssue,cbMsg:cbMsg,cbSummary:cbSummary});return this._error};Jaf.prototype.init=function(config){this._error=0;return this._api.start({config:config})};Jaf.prototype.auditSync=function(filespec){var i,rc=this._error;if(!this._error){if(this._audit._regListenerTypesSet){return rc}if(Array.isArray(filespec)&&filespec.length){for(i=0;i<filespec.length;i++){rc=this._api.auditSync(filespec[i])}}else{rc=this._api.auditSync(filespec)}}return rc};Jaf.prototype.audit=function(filespec){var _self=this;return new Promise((resolve,reject)=>{if(!_self._error){_self._api.audit(filespec).then(rc=>{if(_self.getMarker()){console.log(`jafapi audit.then(${_self.getMarker()}) rc = ${rc}`)}rc?resolve(rc):reject(1)}).catch(e=>{if(_self.getMarker()){console.log(`jafapi catch(${_self.getMarker()}) ${e}`)}reject(e)})}else{reject(_self._error)}})};Jaf.prototype.on=function(evName,fn,extra){this._api.on(evName,fn,extra);return this};Jaf.prototype.removeAllListeners=function(evName){this._api.removeAllListeners(evName);return this};Jaf.prototype.removeListener=function(evName,fn){this._api.removeListener(evName,fn);return this};Jaf.prototype.plugins=function(ar){this._api.plugins(ar);return this};Jaf.prototype.getDescription=function(issue,short){return this._api.getDescription(issue,short)};Jaf.prototype.getActiveRulesetInfo=function(fmt){fmt=fmt!=="json"&&fmt!=="prose"&&fmt!=="sonar"?"json":fmt;return this._api.getRulesetInfo(fmt,true)};Jaf.prototype.setCallbacks=function(fnIssue,fnMsg,fnSummary){this._audit.setApiCallbacks(fnIssue,fnMsg,fnSummary)};Jaf.prototype.enableMsgId=function(msgid,state){return this._api.enableMsgId(msgid,state)};Jaf.prototype.getConfig=function(){return this._api.getConfig()};Jaf.prototype.getSevLib=function(){return this._api.getSevLib()};Jaf.prototype.enableRule=function(ruleName,state){return this._api.enableRule(ruleName,state)};Jaf.prototype.getInfo=function(){return this._api.getInfo()};Jaf.prototype.getMarker=function(){return this._api.getMarker()};Jaf.prototype.setMarker=function(mark){return this._api.setMarker(mark)};Jaf.prototype.setVsCodeExtHint=function(isVsCodeExt){isVsCodeExt=isVsCodeExt!==undefined?!!isVsCodeExt:true;return this._api.setVsCodeExtHint(isVsCodeExt)};module.exports=Jaf;
6
+ var Jaf=function(){this._audit=require("./src/JafCore");this._api=require("./lib/api");this._nd={fs:require("fs"),path:require("path"),glob:require("glob"),process:process,os:require("os"),decomment:require("strip-json-comments"),decache:require("decache"),Config:require("./lib/Config"),metaLoader:require("./lib/metaLoader"),ruleLoader:require("./lib/ruleLoader"),msgidLoader:require("./lib/msgidLoader"),jsonLoader:require("./lib/JsonLoader"),Components:require("./lib/Components"),ComponentSvcs:require("./lib/ComponentSvcs"),schema:require("./lib/schema"),builtinpacks:null,extends:require("./lib/extends"),tsparse:require("@typescript-eslint/typescript-estree"),fsUtils:require("./lib/FsUtils"),zipUtils:require("./lib/ZipUtils"),tsUtils:require("./lib/TsUtils"),jetver:require("./lib/jetver"),exportRules:require("./lib/exportRules"),spinner:require("./lib/spinnernoop")};this._audit=new this._audit(this._nd,"api");this._api=new this._api(this._nd,this._audit);this._error=1};Jaf.prototype.initSync=function(config,cbIssue,cbMsg,cbSummary){this._error=this._api.startSync({config:config,cbIssue:cbIssue,cbMsg:cbMsg,cbSummary:cbSummary});return this._error};Jaf.prototype.init=function(config){this._error=0;return this._api.start({config:config})};Jaf.prototype.auditSync=function(filespec){var i,rc=this._error;if(!this._error){if(this._audit._regListenerTypesSet){return rc}if(Array.isArray(filespec)&&filespec.length){for(i=0;i<filespec.length;i++){rc=this._api.auditSync(filespec[i])}}else{rc=this._api.auditSync(filespec)}}return rc};Jaf.prototype.audit=function(filespec){var _self=this;return new Promise((resolve,reject)=>{if(!_self._error){_self._api.audit(filespec).then(rc=>{if(_self.getMarker()){console.log(`jafapi audit.then(${_self.getMarker()}) rc = ${rc}`)}rc?resolve(rc):reject(1)}).catch(e=>{if(_self.getMarker()){console.log(`jafapi catch(${_self.getMarker()}) ${e}`)}reject(e)})}else{reject(_self._error)}})};Jaf.prototype.on=function(evName,fn,extra){this._api.on(evName,fn,extra);return this};Jaf.prototype.removeAllListeners=function(evName){this._api.removeAllListeners(evName);return this};Jaf.prototype.removeListener=function(evName,fn){this._api.removeListener(evName,fn);return this};Jaf.prototype.plugins=function(ar){this._api.plugins(ar);return this};Jaf.prototype.getDescription=function(issue,short){return this._api.getDescription(issue,short)};Jaf.prototype.getActiveRulesetInfo=function(fmt){fmt=fmt!=="json"&&fmt!=="prose"&&fmt!=="sonar"?"json":fmt;return this._api.getRulesetInfo(fmt,true)};Jaf.prototype.setCallbacks=function(fnIssue,fnMsg,fnSummary){this._audit.setApiCallbacks(fnIssue,fnMsg,fnSummary)};Jaf.prototype.enableMsgId=function(msgid,state){return this._api.enableMsgId(msgid,state)};Jaf.prototype.getConfig=function(){return this._api.getConfig()};Jaf.prototype.getSevLib=function(){return this._api.getSevLib()};Jaf.prototype.enableRule=function(ruleName,state){return this._api.enableRule(ruleName,state)};Jaf.prototype.getInfo=function(){return this._api.getInfo()};Jaf.prototype.getMarker=function(){return this._api.getMarker()};Jaf.prototype.setMarker=function(mark){return this._api.setMarker(mark)};Jaf.prototype.setVsCodeExtHint=function(isVsCodeExt){isVsCodeExt=isVsCodeExt!==undefined?!!isVsCodeExt:true;return this._api.setVsCodeExtHint(isVsCodeExt)};module.exports=Jaf;
package/lib/AST_Ts.js CHANGED
@@ -3,4 +3,4 @@
3
3
  * Licensed under The Universal Permissive License (UPL), Version 1.0
4
4
  * as shown at https://oss.oracle.com/licenses/upl/
5
5
  */
6
- const NT=require("./AstNodeTypes");const Scope=require("./Scope");const COMMON_DOC_METHODS={"getElementsByClassName":true,"getElementsByTagName":true,"getElementsByTagNameNS":true,"getElementById":true,"getElementsByName":true,"querySelector":true,"querySelectorAll":true,"createElement":true,"createElementNS":true};const LOC="loc";const RANGE="range";const PARENT="parent";var AST=function(data,file,fileType,nd,ecmaVer,comments,msgCtx,config){var opts={ecmaVersion:ecmaVer,comment:comments};if(fileType==="tsx"){opts.jsx=true;opts.comment=true}opts.loc=true;opts.range=true;opts.errorOnUnknownASTType=true;opts.project="D:/vsprojects/JetAuditDev/tsconfig/tsconfig.json";this._ast=nd.tsparse.parse(data,opts);this._data=data;this._file=file;this._fileType=fileType;this._tlib=null;this._scope=null;this._utils=null;this._program=null;this._isComments=comments;this._msgCtx=msgCtx;this._config=config;this._nd=nd};AST.prototype.walk=function(callback){try{this._walkAddParent(callback)}catch(e){console.log(`JAF internal TS/TSX WALK ERROR: ${e}`)}};AST.prototype.getAst=function(){return this._ast};AST.prototype.getFilePath=function(){return this._file};AST.prototype.getFileType=function(){return this._fileTpe};AST.prototype.getRawComments=function(){return this._ast.comments};AST.prototype.getNodeFromIndex=function(index){return _getNodeFromIndex2(this._ast,index)};function _getNodeFromIndex2(node,index){var body,n,i,ret=null;if(!node){return null}if(index===node.range[0]){return node}if(index<node.range[0]||index>node.range[1]){return null}if(node.body){body=node.body;if(Array.isArray(body)){for(i=0;i<body.length;i++){n=body[i];if(index<n.range[0]){ret=n}else{ret=_getNodeFromIndex2(n,index)}if(ret){if(ret===-1){ret=null}break}}}else{ret=_getNodeFromIndex2(body,index);if(ret){if(ret===-1){ret=null}}}}else{if(node.type==="IfStatement"){ret=_getNodeFromIndex2(node.consequent,index)}else{ret=node}}return ret};AST.prototype.getUtils=function(){if(!this._utils){this._utils={getBlock:this.getBlock.bind(this),getBody:this.getBody.bind(this),getProgram:this.getProgram.bind(this),getContainingFunctionName:this.getContainingFunctionName.bind(this),isFuncArg:this.isFuncArg.bind(this),getScopes:this._createVarScopes.bind(this),getNodeTypes:_getNodeTypes,isCommonDocApi:this.isCommonDocApi,parseDefine:this.parseDefine.bind(this),parseImport:this.parseImport.bind(this)}}return this._utils};function _getNodeTypes(){return NT};AST.prototype.getBlock=function(node){var block;if(!node){if(!this._program){node=this._ast;if(node.type!==NT.PROGRAM){node=null}this._program=node}else{node=this._program}block=node}else{while(node){if(node.type){if(node.type===NT.BLOCK_STMT||node.type===NT.PROGRAM){block=node;break}}node=node.parent}}return block};AST.prototype.getBody=function(node){var block=this.getBlock(node);return block?block.body:block};AST.prototype.getFunctionBody=function(node){var block;if(!node){if(!this._program){node=this._ast;if(node.type!==NT.PROGRAM){node=null}this._program=node}else{node=this._program}block=node}else{while(node){if(node.type){if(node.type===NT.FUNC_DECLARATION||node.type===NT.PROGRAM){block=node;break}}node=node.parent}}return block};AST.prototype.getProgram=function(){return this._ast.type===NT.PROGRAM?this._ast:null};AST.prototype.getContainingFunctionName=function(node){var body=this.getFunctionBody(node);return body&&body.id?body.id.name:undefined};AST.prototype._createVarScopes=function(){if(!this._scope){this._scope=new Scope(this._msgCtx,this._config,this._file,this._nd);this._scopeStacks=this._scope.build(this._ast);this._accessor=this._scope.getAccessor()}return this._accessor};AST.prototype.getData=function(){return this._data};AST.prototype.isFuncArg=function(node,varName){var args,arg,n,j,ret=false;var n=node;while(n.type&&n.type!==NT.FUNC_DECLARATION){n=n.parent;if(!n||!n.type){n=null;break}}if(n){args=n.params;for(j=0;j<args.length;j++){arg=args[j];if(arg.type===NT.IDENTIFIER){if(arg.name===varName){ret=true;break}}}}return ret};AST.prototype.isCommonDocApi=function(method){return COMMON_DOC_METHODS[method]};AST.prototype.parseDefine=function(node,obj){var modules,names,len,i;if(!node.arguments||node.arguments.length<2){return null}modules=node.arguments[0].elements;names=node.arguments[1].params;obj=obj||null;if(modules&&names&&modules.length){len=Math.min(modules.length,names.length);obj=obj?obj:{};for(i=0;i<len;i++){obj[names[i].name]=modules[i].value}}return obj};AST.prototype.parseImport=function(node,obj){var source,specifiers,spec,name,i;obj=obj||{};source=node.source&&node.source.value;if(node.specifiers){specifiers=node.specifiers;for(var i=0;i<specifiers.length;i++){spec=specifiers[i];if((spec.type===NT.IMPORT_DEF_SPECIFIER||spec.type===NT.IMPORT_SPECIFIER)&&spec.local){name=spec.local.name;obj[name]=source}}}return obj};AST.prototype._walkAddParent=function(fn){var stack=[this._ast],i,j,key,len,node,child,subchild;for(i=0;i<stack.length;i+=1){node=stack[i];if(node.type==="Line"||node.type==="EmptyStatement"){continue}fn(node);for(key in node){if(key!==PARENT){if(key===RANGE||key===LOC){continue}child=node[key];if(child instanceof Array){for(j=0,len=child.length;j<len;j+=1){subchild=child[j];if(subchild){subchild.parent=node;stack.push(subchild)}}}else if(child!=void 0&&typeof child.type==="string"){child.parent=node;stack.push(child)}}}}};module.exports=AST;
6
+ const NT=require("./AstNodeTypes");const Scope=require("./Scope");const COMMON_DOC_METHODS={"getElementsByClassName":true,"getElementsByTagName":true,"getElementsByTagNameNS":true,"getElementById":true,"getElementsByName":true,"querySelector":true,"querySelectorAll":true,"createElement":true,"createElementNS":true};const LOC="loc";const RANGE="range";const PARENT="parent";const TSXFUNCTION="TsxFunction";var AST=function(data,file,fileType,nd,ecmaVer,comments,msgCtx,config){var opts={ecmaVersion:ecmaVer,comment:comments};if(fileType==="tsx"){opts.jsx=true;opts.comment=true}opts.loc=true;opts.range=true;opts.errorOnUnknownASTType=true;opts.project="D:/vsprojects/JetAuditDev/tsconfig/tsconfig.json";this._ast=nd.tsparse.parse(data,opts);this._data=data;this._file=file;this._fileType=fileType;this._tlib=null;this._scope=null;this._utils=null;this._program=null;this._isComments=comments;this._msgCtx=msgCtx;this._config=config;this._nd=nd};AST.prototype.walk=function(callback){try{this._walkAddParent(callback)}catch(e){console.log(`JAF internal TS/TSX WALK ERROR: ${e}`)}};AST.prototype.getAst=function(){return this._ast};AST.prototype.getFilePath=function(){return this._file};AST.prototype.getFileType=function(){return this._fileTpe};AST.prototype.getRawComments=function(){return this._ast.comments};AST.prototype.getNodeFromIndex=function(index){return _getNodeFromIndex2(this._ast,index)};function _getNodeFromIndex2(node,index){var body,n,i,ret=null;if(!node){return null}if(index===node.range[0]){return node}if(index<node.range[0]||index>node.range[1]){return null}if(node.body){body=node.body;if(Array.isArray(body)){for(i=0;i<body.length;i++){n=body[i];if(index<n.range[0]){ret=n}else{ret=_getNodeFromIndex2(n,index)}if(ret){if(ret===-1){ret=null}break}}}else{ret=_getNodeFromIndex2(body,index);if(ret){if(ret===-1){ret=null}}}}else{if(node.type===NT.IF_STMT){ret=_getNodeFromIndex2(node.consequent,index)}else{ret=node}}return ret};AST.prototype.extractNamedFuncs=function(){let body,node,decls,fname,func;if(!(body=this._ast.body)){return}body.forEach((node,b)=>{if(node.type===NT.VAR_DECLARATION&&(decls=node.declarations)){decls.forEach(decl=>{if(fname=decl.id?.name){if(decl.init?.type===NT.ARROW_FUNC_EXPR){if(!this._namedFuncs){this._namedFuncs=[]}let func={type:TSXFUNCTION,name:fname,node:decl.init,body:decl.init.body,range:decl.init.range};this._namedFuncs.push(func);if(func.body?.type===NT.BLOCK_STMT&&func.body.body){func.returns=[];func.body.body.forEach(stmt=>{if(stmt.type===NT.RETURN_STMT){func.returns.push({node:stmt})}})}};}})}else if(node.type===NT.FUNC_DECLARATION&&(body=node.body)){if(node?.id.type===NT.IDENTIFIER&&node.body.body){if(!this._namedFuncs){this._namedFuncs=[]}func={type:TSXFUNCTION,name:node.id.name,node:node,body:node.body,range:node.range};this._namedFuncs.push(func);node.body.body.forEach(stmt=>{if(stmt.type===NT.RETURN_STMT){if(!func.returns){func.returns=[]}func.returns.push({node:stmt})}})}}});return this._namedFuncs};AST.prototype.getUtils=function(){if(!this._utils){this._utils={getBlock:this.getBlock.bind(this),getBody:this.getBody.bind(this),getProgram:this.getProgram.bind(this),getContainingFunctionName:this.getContainingFunctionName.bind(this),isFuncArg:this.isFuncArg.bind(this),getScopes:this._createVarScopes.bind(this),getNodeTypes:_getNodeTypes,isCommonDocApi:this.isCommonDocApi,parseDefine:this.parseDefine.bind(this),parseImport:this.parseImport.bind(this)}}return this._utils};function _getNodeTypes(){return NT};AST.prototype.getBlock=function(node){var block;if(!node){if(!this._program){node=this._ast;if(node.type!==NT.PROGRAM){node=null}this._program=node}else{node=this._program}block=node}else{while(node){if(node.type){if(node.type===NT.BLOCK_STMT||node.type===NT.PROGRAM){block=node;break}}node=node.parent}}return block};AST.prototype.getBody=function(node){var block=this.getBlock(node);return block?block.body:block};AST.prototype.getFunctionBody=function(node){var block;if(!node){if(!this._program){node=this._ast;if(node.type!==NT.PROGRAM){node=null}this._program=node}else{node=this._program}block=node}else{while(node){if(node.type){if(node.type===NT.FUNC_DECLARATION||node.type===NT.PROGRAM){block=node;break}}node=node.parent}}return block};AST.prototype.getProgram=function(){return this._ast.type===NT.PROGRAM?this._ast:null};AST.prototype.getContainingFunctionName=function(node){var body=this.getFunctionBody(node);return body&&body.id?body.id.name:undefined};AST.prototype._createVarScopes=function(){if(!this._scope){this._scope=new Scope(this._msgCtx,this._config,this._file,this._nd);this._scopeStacks=this._scope.build(this._ast);this._accessor=this._scope.getAccessor()}return this._accessor};AST.prototype.getData=function(){return this._data};AST.prototype.isFuncArg=function(node,varName){var args,arg,n,j,ret=false;var n=node;while(n.type&&n.type!==NT.FUNC_DECLARATION){n=n.parent;if(!n||!n.type){n=null;break}}if(n){args=n.params;for(j=0;j<args.length;j++){arg=args[j];if(arg.type===NT.IDENTIFIER){if(arg.name===varName){ret=true;break}}}}return ret};AST.prototype.isCommonDocApi=function(method){return COMMON_DOC_METHODS[method]};AST.prototype.parseDefine=function(node,obj){var modules,names,len,i;if(!node.arguments||node.arguments.length<2){return null}modules=node.arguments[0].elements;names=node.arguments[1].params;obj=obj||null;if(modules&&names&&modules.length){len=Math.min(modules.length,names.length);obj=obj?obj:{};for(i=0;i<len;i++){obj[names[i].name]=modules[i].value}}return obj};AST.prototype.parseImport=function(node,obj){var source,specifiers,spec,name,i;obj=obj||{};source=node.source&&node.source.value;if(node.specifiers){specifiers=node.specifiers;for(var i=0;i<specifiers.length;i++){spec=specifiers[i];if((spec.type===NT.IMPORT_DEF_SPECIFIER||spec.type===NT.IMPORT_SPECIFIER)&&spec.local){name=spec.local.name;obj[name]=source}}}return obj};AST.prototype._walkAddParent=function(fn){var stack=[this._ast],i,j,key,len,node,child,subchild;for(i=0;i<stack.length;i+=1){node=stack[i];if(node.type==="Line"||node.type===NT.EMPTY_STMT){continue}fn(node);for(key in node){if(key!==PARENT){if(key===RANGE||key===LOC){continue}child=node[key];if(child instanceof Array){for(j=0,len=child.length;j<len;j+=1){subchild=child[j];if(subchild){subchild.parent=node;stack.push(subchild)}}}else if(child!=void 0&&typeof child.type==="string"){child.parent=node;stack.push(child)}}}}};module.exports=AST;
package/lib/AstJson.js CHANGED
@@ -3,4 +3,4 @@
3
3
  * Licensed under The Universal Permissive License (UPL), Version 1.0
4
4
  * as shown at https://oss.oracle.com/licenses/upl/
5
5
  */
6
- const PROP="P";const RBRACE="}";const LBRACE="{";const LSQUARE="[";const RSQUARE="]";const NUMBER="N";const STRING="S";const BOOL="B";const NULL="NL";const COLON=":";const DQUOTE="\"";const ESCAPE="\\";const COMMA=",";const UNARY_MINUS="-";const $DIGIT="$digit";const EOF="";function AstJson(msgContext){this._msgContext=msgContext};AstJson.prototype.parse=function(data){var ret;this._data=data;this._index=-1;this._row=1;this._col=0;this._curChar=null;this._objStack=[];this._listStack=[];this._curProp=null;this._curObj=null;this._tokValue=null;ret=this._parse();return ret};AstJson.prototype._parse=function(){var tok;do{switch(tok){case STRING:case NUMBER:case BOOL:case NULL:{if(this._curProp){this._curProp.value=this._tokValue}else{this._curProp=this._tokValue}this._curList.push(this._curProp);this._curProp=null;break}case PROP:{this._curProp={name:this._tokValue.rawValue,pos:{row:this._startRow,col:this._startCol,start:this._startIndex,end:this._getTokEndIndex(this._tokValue.rawValue,this._startIndex,"string"),index:this._startIndex}};this._next(COLON);break}case LBRACE:{if(this._curProp){this._curProp.value=this._tokValue}if(this._curObj){this._objStack.push(this._curObj)}this._curObj=this._tokValue;this._curObj.members=[];if(this._curList){if(this._curProp)this._curList.push(this._curProp);else this._curList.push(this._curObj)}this._listStack.push(this._curList);this._curList=this._curObj.members;break}case RBRACE:{if(this._objStack.length){this._curObj=this._objStack.pop()}if(this._listStack.length){this._curList=this._listStack.pop()}break}case LSQUARE:{if(this._curList){this._listStack.push(this._curList)}if(this._curProp){this._curProp.value=this._tokValue;this._curList.push(this._curProp)}else if(this._curList){this._curList.push(this._tokValue)}this._curList=this._tokValue.members;this._curProp=null;break}case RSQUARE:{this._curList=this._listStack.pop();break}}}while((tok=this._getToken())!==EOF);return this._startToken===LBRACE?this._curObj:this._curList};AstJson.prototype._getToken=function(){var s;while(true){s=this._getNextChar();if(s===DQUOTE){this._tokValue=this._getString();this._getTokValue("string",this._tokValue,true);return this._peekNext(COLON)?PROP:STRING}else if(this._isNumber(s)){this._tokValue=this._getNumber(s);this._getTokValue("number",this._tokValue,true);return NUMBER}else if(s==="t"||s==="f"){this._tokValue=this._getBoolean(s);this._getTokValue("boolean",this._tokValue,true);return BOOL}else if(s==="n"){this._tokValue=this._getNull();this._getTokValue("null",this._tokValue,true);return NULL}else if(s===LBRACE){this._tokValue={type:"Object",value:"{",pos:{row:this._row,col:this._col,start:this._index,end:this._index,index:this._index}};if(!this._startToken){this._startToken=LBRACE}return LBRACE}else if(s===RBRACE){return RBRACE}else if(s===LSQUARE){this._tokValue={type:"array",pos:{row:this._row,col:this._col,start:this._index,end:this._index,index:this._index},members:[]};if(!this._startToken){this._startToken=LSQUARE}return LSQUARE}else if(s===RSQUARE){return RSQUARE}else if(s===EOF){return EOF}else if(s===COMMA){continue}else{if(this._msgContext){this._msgContext.assert("JSON -> AST - unexpected char '"+s+"'")}return s}}};AstJson.prototype._getString=function(){var str="",s,inEscape;this._startRow=this._row;this._startCol=this._col;this._startIndex=this._index;while(true){s=this._getChar();if(s===ESCAPE){inEscape=true;continue}if(!inEscape){if(s===DQUOTE){return{value:str,rawValue:str}}}inEscape=false;str+=s}};AstJson.prototype._getNumber=function(s){var str=s;this._startRow=this._row;this._startCol=this._col;this._startIndex=this._index;while(true){s=this._getChar();if(this._isNumber(s)){if(s!==UNARY_MINUS){str+=s;continue}}this._unget();break}return{value:parseInt(str),rawValue:str}};AstJson.prototype._getBoolean=function(s){var ret={};this._startRow=this._row;this._startCol=this._col;this._startIndex=this._index;if(s==="t"){this._next("r");this._next("u");this._next("e");ret.value=true;ret.rawValue="true"}else{this._next("a");this._next("l");this._next("s");this._next("e");ret.value=false;ret.rawValue="false"}return ret};AstJson.prototype._getNull=function(){this._startRow=this._row;this._startCol=this._col;this._startIndex=this._index;this._next("u");this._next("l");this._next("l");return{value:null,rawValue:"null"}};AstJson.prototype._getTokValue=function(type,tokValue,startRc){this._tokValue={type:type,value:this._tokValue.value,rawValue:this._tokValue.rawValue,pos:{row:startRc?this._startRow:this._row,col:startRc?this._startCol:this._col,start:this._startIndex,end:this._getTokEndIndex(this._tokValue.rawValue,this._startIndex,type),index:this._startIndex}}};AstJson.prototype._next=function(s){while(true){if(this._getNextChar()===s){break}}};AstJson.prototype._peekNext=function(s){var n,r,c,val,ret=false;n=this._index;r=this._row;c=this._col;if(s===$DIGIT){val=this._getNextChar();ret=!isNaN(parseInt(val,10))}else{ret=this._getNextChar()===s}this._index=n;this._row=r;this._col=c;return ret};AstJson.prototype._getNextChar=function(){var s;while(true){s=this._getChar();if(s===EOF){return EOF}if(!_isWhite(s)){return s}}};AstJson.prototype._getChar=function(){if(!this._doNotadvance){this._index=this._index>=0?++this._index:0}else{this._unget=false}if(this._index<this._data.length){this._curChar=this._data.substr(this._index,1);if(this._curChar==="\n"){this._row++;this._col=0}else if(this._curChar!=="\r"){this._col++}return this._curChar}return EOF};AstJson.prototype._unget=function(){this._doNotAdvance=true};AstJson.prototype._getTokEndIndex=function(s,start,type){var end=start;if(type==="string"){end+=2}return end+s.length-1};AstJson.prototype._isNumber=function(s){var num;if(s===UNARY_MINUS){num=this._peekNext($DIGIT);return num>="0"&&num<="9"}return!isNaN(parseInt(s,10))};function _isWhite(s){return s==" "||s==="\n"||s==="\r"||s==="\t"};module.exports=AstJson;
6
+ const PROP="P";const RBRACE="}";const LBRACE="{";const LSQUARE="[";const RSQUARE="]";const NUMBER="N";const STRING="S";const BOOL="B";const NULL="NL";const COLON=":";const DQUOTE="\"";const ESCAPE="\\";const COMMA=",";const UNARY_MINUS="-";const $DIGIT="$digit";const EOF="";function AstJson(msgContext){this._msgContext=msgContext};AstJson.prototype.parse=function(data){var ret;this._data=data;this._index=-1;this._row=1;this._col=0;this._curChar=null;this._objStack=[];this._listStack=[];this._curProp=null;this._curObj=null;this._tokValue=null;ret=this._parse();return ret};AstJson.prototype._parse=function(){var tok;do{switch(tok){case STRING:case NUMBER:case BOOL:case NULL:{if(this._curProp){this._curProp.value=this._tokValue}else{this._curProp=this._tokValue}this._curList.push(this._curProp);this._curProp=null;break}case PROP:{this._curProp={name:this._tokValue.rawValue,pos:{row:this._startRow,col:this._startCol,start:this._startIndex,end:this._getTokEndIndex(this._tokValue.rawValue,this._startIndex,"string"),index:this._startIndex}};this._next(COLON);break}case LBRACE:{if(this._curProp){this._curProp.value=this._tokValue}if(this._curObj){this._objStack.push(this._curObj)}this._curObj=this._tokValue;this._curObj.members=[];if(this._curList){if(this._curProp)this._curList.push(this._curProp);else this._curList.push(this._curObj)}this._listStack.push(this._curList);this._curList=this._curObj.members;break}case RBRACE:{if(this._objStack.length){this._curObj=this._objStack.pop()}if(this._listStack.length){this._curList=this._listStack.pop()}break}case LSQUARE:{if(this._curList){this._listStack.push(this._curList)}if(this._curProp){this._curProp.value=this._tokValue;this._curList.push(this._curProp)}else if(this._curList){this._curList.push(this._tokValue)}this._curList=this._tokValue.members;this._curProp=null;break}case RSQUARE:{this._curList=this._listStack.pop();break}}}while((tok=this._getToken())!==EOF);return this._startToken===LBRACE?this._curObj:this._curList};AstJson.prototype._getToken=function(){var s;while(true){s=this._getNextChar();if(s===DQUOTE){this._tokValue=this._getString();this._getTokValue("string",this._tokValue,true);return this._peekNext(COLON)?PROP:STRING}else if(this._isNumber(s)){this._tokValue=this._getNumber(s);this._getTokValue("number",this._tokValue,true);return NUMBER}else if(s==="t"||s==="f"){this._tokValue=this._getBoolean(s);this._getTokValue("boolean",this._tokValue,true);return BOOL}else if(s==="n"){this._tokValue=this._getNull();this._getTokValue("null",this._tokValue,true);return NULL}else if(s===LBRACE){this._tokValue={type:"Object",value:"{",pos:{row:this._row,col:this._col,start:this._index,end:this._index,index:this._index}};if(!this._startToken){this._startToken=LBRACE}return LBRACE}else if(s===RBRACE){return RBRACE}else if(s===LSQUARE){this._tokValue={type:"array",pos:{row:this._row,col:this._col,start:this._index,end:this._index,index:this._index},members:[]};if(!this._startToken){this._startToken=LSQUARE}return LSQUARE}else if(s===RSQUARE){return RSQUARE}else if(s===EOF){return EOF}else if(s===COMMA){continue}else{if(this._msgContext){this._msgContext.assert("JSON -> AST - unexpected char '"+s+"'")}return s}}};AstJson.prototype._getString=function(){var str="",s,inEscape;this._startRow=this._row;this._startCol=this._col;this._startIndex=this._index;while((s=this._getChar())!==EOF){if(s===ESCAPE&&!inEscape){inEscape=true;continue}if(inEscape){inEscape=false;if(s==="n"){str+"\n"}else if(s==="\""){str+="\""}else if(s==="t"){str+="\t"}else{str+=" "+s}continue}if(s===DQUOTE){break}str+=s}return{value:str,rawValue:str}};AstJson.prototype._getNumber=function(s){var str=s;this._startRow=this._row;this._startCol=this._col;this._startIndex=this._index;while(true){s=this._getChar();if(this._isNumber(s)){if(s!==UNARY_MINUS){str+=s;continue}}this._unget();break}return{value:parseInt(str),rawValue:str}};AstJson.prototype._getBoolean=function(s){var ret={};this._startRow=this._row;this._startCol=this._col;this._startIndex=this._index;if(s==="t"){this._next("r");this._next("u");this._next("e");ret.value=true;ret.rawValue="true"}else{this._next("a");this._next("l");this._next("s");this._next("e");ret.value=false;ret.rawValue="false"}return ret};AstJson.prototype._getNull=function(){this._startRow=this._row;this._startCol=this._col;this._startIndex=this._index;this._next("u");this._next("l");this._next("l");return{value:null,rawValue:"null"}};AstJson.prototype._getTokValue=function(type,tokValue,startRc){this._tokValue={type:type,value:this._tokValue.value,rawValue:this._tokValue.rawValue,pos:{row:startRc?this._startRow:this._row,col:startRc?this._startCol:this._col,start:this._startIndex,end:this._getTokEndIndex(this._tokValue.rawValue,this._startIndex,type),index:this._startIndex}}};AstJson.prototype._next=function(s){while(true){if(this._getNextChar()===s){break}}};AstJson.prototype._peekNext=function(s){var n,r,c,val,ret=false;n=this._index;r=this._row;c=this._col;if(s===$DIGIT){val=this._getNextChar();ret=!isNaN(parseInt(val,10))}else{ret=this._getNextChar()===s}this._index=n;this._row=r;this._col=c;return ret};AstJson.prototype._getNextChar=function(){var s;while(true){s=this._getChar();if(s===EOF){return EOF}if(!_isWhite(s)){return s}}};AstJson.prototype._getChar=function(){if(!this._doNotadvance){this._index=this._index>=0?++this._index:0}else{this._unget=false}if(this._index<this._data.length){this._curChar=this._data.substr(this._index,1);if(this._curChar==="\n"){this._row++;this._col=0}else if(this._curChar!=="\r"){this._col++}return this._curChar}return EOF};AstJson.prototype._unget=function(){this._doNotAdvance=true};AstJson.prototype._getTokEndIndex=function(s,start,type){var end=start;if(type==="string"){end+=2}return end+s.length-1};AstJson.prototype._isNumber=function(s){var num;if(s===UNARY_MINUS){num=this._peekNext($DIGIT);return num>="0"&&num<="9"}return!isNaN(parseInt(s,10))};function _isWhite(s){return s==" "||s==="\n"||s==="\r"||s==="\t"};module.exports=AstJson;
@@ -3,4 +3,4 @@
3
3
  * Licensed under The Universal Permissive License (UPL), Version 1.0
4
4
  * as shown at https://oss.oracle.com/licenses/upl/
5
5
  */
6
- module.exports.ARRAY_EXPR="ArrayExpression";module.exports.ARROW_FUNC_EXPR="ArrowFunctionExpression";module.exports.ASSIGN_PATTERN="AssignmentPattern";module.exports.ASSIGN_EXPR="AssignmentExpression";module.exports.ASSIGNMENT_EXPR="AssignmentExpression";module.exports.AWAIT_EXPR="AwaitExpression";module.exports.BINARY_EXPR="BinaryExpression";module.exports.BLOCK_STMT="BlockStatement";module.exports.BREAK_STMT="BreakStatement";module.exports.CALL_EXPR="CallExpression";module.exports.CATCH_CLAUSE="CatchClause";module.exports.CLASS_BODY="ClassBody";module.exports.CLASS_DECLARATION="ClassDeclaration";module.exports.CLASS_EXPR="ClassExpression";module.exports.CLASS_PROP="ClassProperty";module.exports.CONDITIONAL_EXPR="ConditionalExpression";module.exports.CONTINUE_STMT="ContinueStatement";module.exports.DO_WHILE_STMT="DoWhileStatement";module.exports.DEBUG_STMT="DebuggerStatement";module.exports.EMPTY_STMT="EmptyStatement";module.exports.EX_REST_PROP="ExperimentalRestProperty";module.exports.EX_SPREAD_STMT="ExperimentalSpreadProperty";module.exports.EXPR_STMT="ExpressionStatement";module.exports.FOR_STMT="ForStatement";module.exports.FOR_IN_STMT="ForInStatement";module.exports.FOR_OF_STMT="ForOfStatement";module.exports.FUNC_DECLARATION="FunctionDeclaration";module.exports.FUNC_EXPR="FunctionExpression";module.exports.IDENTIFIER="Identifier";module.exports.IF_STMT="IfStatement";module.exports.LOGIC_EXPR="LogicalExpression";module.exports.LABELED_STMT="LabeledStatement";module.exports.LITERAL="Literal";module.exports.MEMBER_EXPR="MemberExpression";module.exports.META_PROP="MetaProperty";module.exports.METH_DEF="MethodDefinition";module.exports.NEW_EXPR="NewExpression";module.exports.OBJ_EXPR="ObjectExpression";module.exports.OBJ_PATTERN="ObjectPattern";module.exports.PROGRAM="Program";module.exports.PROPERTY="Property";module.exports.PROPERTY_DEF="PropertyDefinition";module.exports.REST_ELEM="RestElement";module.exports.RETURN_STMT="ReturnStatement";module.exports.SEQUENCE_EXPR="SequenceExpression";module.exports.SPREAD_ELEM="SpreadElement";module.exports.SUPER="Super";module.exports.SWITCH_CASE="SwitchCase";module.exports.SWITCH_STMT="SwitchStatement";module.exports.TAGGED_TEMPLATE_EXPR="TaggedTemplateExpression";module.exports.TEMPLATE_ELEM="TemplateElement";module.exports.TEMPLATE_LIT="TemplateLiteral";module.exports.THIS_EXPR="ThisExpression";module.exports.THROW_EXPR="ThrowExpression";module.exports.TRY_STMT="TryStatement";module.exports.UNARY_EXPR="UnaryExpression";module.exports.UPDATE_EXPR="UpdateExpression";module.exports.VAR_DECLARATION="VariableDeclaration";module.exports.VAR_DECLARATOR="VariableDeclarator";module.exports.WHILE_STMT="WhileStatement";module.exports.WITH_STMT="WithStatement";module.exports.YIELD_EXPR="YieldExpression";module.exports.JSX_ID="JSXIdentifier";module.exports.JSX_NS_NAME="JSXNamespacedName";module.exports.JSX_EMPTY_EXPR="JSXEmptyExpression";module.exports.JSX_EXPR_CONTAINER="JSXExpressionContainer";module.exports.JSX_ELEM="JSXElement";module.exports.JSX_CLOSING_ELEM="JSXClosingElement";module.exports.JSX_OPENING_ELEM="JSXOpeningElement";module.exports.JSX_ATTRIB="JSXAttribute";module.exports.JSX_SPREAD_ATTRIB="JSXSpreadAttribute";module.exports.JSX_TEXT="JSXText";module.exports.EXPORT_DEFAULT_DECL="ExportDefaultDeclaration";module.exports.EXPORT_NAMED_DECL="ExportNamedDeclaration";module.exports.EXPORT_ALL_DECL="ExportAllDeclaration";module.exports.EXPORT_ASSIGNMENT="TSExportAssignment";module.exports.EXPORT_SPECIFIER="ExportSpecifier";module.exports.IMPORT_DECL="ImportDeclaration";module.exports.IMPORT_EQUALS_DECL="TSImportEqualsDeclaration";module.exports.IMPORT_SPECIFIER="ImportSpecifier";module.exports.IMPORT_DEF_SPECIFIER="ImportDefaultSpecifier";module.exports.IMPORT_NS_SPECIFIER="ImportNamespaceSpecifier";module.exports.ANY_KEYWORD="TSAnyKeyword";module.exports.ARRAY_TYPE="TSArrayType";module.exports.AS_EXPR="TSAsExpression";module.exports.BOOLEAN_KEYWORD="TSBooleanKeyword";module.exports.EXTERN_MOD_REF="TSExternalModuleReference";module.exports.ENUM_TS_DECL="TSEnumDeclaration";module.exports.FUNCTION_TYPE="TSFunctionType";module.exports.INTERFACE_BODY="TSInterfaceBody";module.exports.INTERFACE_DECL="TSInterfaceDeclaration";module.exports.INTERSECTION_TYPE="TSIntersectionType";module.exports.LITERAL_TYPE="TSLiteralType";module.exports.NUMBER_KEYWORD="TSNumberKeyword";module.exports.OBJECT_KEYWORD="TSObjectKeyword";module.exports.OPTIONAL_TYPE="TSOptionalType";module.exports.PROPERTY_SIGNATURE="TSPropertySignature";module.exports.STRING_KEYWORD="TSStringKeyword";module.exports.TUPLE_TYPE="TSTupleType";module.exports.TYPE_ALIAS_DECL="TSTypeAliasDeclaration";module.exports.TYPE_LITERAL="TSTypeLiteral";module.exports.TYPE_REF="TSTypeReference";module.exports.UNION_TYPE="TSUnionType";
6
+ module.exports.ARRAY_EXPR="ArrayExpression";module.exports.ARROW_FUNC_EXPR="ArrowFunctionExpression";module.exports.ASSIGN_PATTERN="AssignmentPattern";module.exports.ASSIGN_EXPR="AssignmentExpression";module.exports.ASSIGNMENT_EXPR="AssignmentExpression";module.exports.AWAIT_EXPR="AwaitExpression";module.exports.BINARY_EXPR="BinaryExpression";module.exports.BLOCK_STMT="BlockStatement";module.exports.BREAK_STMT="BreakStatement";module.exports.CALL_EXPR="CallExpression";module.exports.CATCH_CLAUSE="CatchClause";module.exports.CLASS_BODY="ClassBody";module.exports.CLASS_DECLARATION="ClassDeclaration";module.exports.CLASS_EXPR="ClassExpression";module.exports.CLASS_PROP="ClassProperty";module.exports.CONDITIONAL_EXPR="ConditionalExpression";module.exports.CONTINUE_STMT="ContinueStatement";module.exports.DO_WHILE_STMT="DoWhileStatement";module.exports.DEBUG_STMT="DebuggerStatement";module.exports.EMPTY_STMT="EmptyStatement";module.exports.EX_REST_PROP="ExperimentalRestProperty";module.exports.EX_SPREAD_STMT="ExperimentalSpreadProperty";module.exports.EXPR_STMT="ExpressionStatement";module.exports.FOR_STMT="ForStatement";module.exports.FOR_IN_STMT="ForInStatement";module.exports.FOR_OF_STMT="ForOfStatement";module.exports.FUNC_DECLARATION="FunctionDeclaration";module.exports.FUNC_EXPR="FunctionExpression";module.exports.IDENTIFIER="Identifier";module.exports.IF_STMT="IfStatement";module.exports.LOGIC_EXPR="LogicalExpression";module.exports.LABELED_STMT="LabeledStatement";module.exports.LINE="Line";module.exports.LITERAL="Literal";module.exports.MEMBER_EXPR="MemberExpression";module.exports.META_PROP="MetaProperty";module.exports.METH_DEF="MethodDefinition";module.exports.NEW_EXPR="NewExpression";module.exports.OBJ_EXPR="ObjectExpression";module.exports.OBJ_PATTERN="ObjectPattern";module.exports.PROGRAM="Program";module.exports.PROPERTY="Property";module.exports.PROPERTY_DEF="PropertyDefinition";module.exports.REST_ELEM="RestElement";module.exports.RETURN_STMT="ReturnStatement";module.exports.SEQUENCE_EXPR="SequenceExpression";module.exports.SPREAD_ELEM="SpreadElement";module.exports.SUPER="Super";module.exports.SWITCH_CASE="SwitchCase";module.exports.SWITCH_STMT="SwitchStatement";module.exports.TAGGED_TEMPLATE_EXPR="TaggedTemplateExpression";module.exports.TEMPLATE_ELEM="TemplateElement";module.exports.TEMPLATE_LIT="TemplateLiteral";module.exports.THIS_EXPR="ThisExpression";module.exports.THROW_EXPR="ThrowExpression";module.exports.TRY_STMT="TryStatement";module.exports.UNARY_EXPR="UnaryExpression";module.exports.UPDATE_EXPR="UpdateExpression";module.exports.VAR_DECLARATION="VariableDeclaration";module.exports.VAR_DECLARATOR="VariableDeclarator";module.exports.WHILE_STMT="WhileStatement";module.exports.WITH_STMT="WithStatement";module.exports.YIELD_EXPR="YieldExpression";module.exports.JSX_ID="JSXIdentifier";module.exports.JSX_NS_NAME="JSXNamespacedName";module.exports.JSX_EMPTY_EXPR="JSXEmptyExpression";module.exports.JSX_EXPR_CONTAINER="JSXExpressionContainer";module.exports.JSX_ELEM="JSXElement";module.exports.JSX_CLOSING_ELEM="JSXClosingElement";module.exports.JSX_OPENING_ELEM="JSXOpeningElement";module.exports.JSX_ATTRIB="JSXAttribute";module.exports.JSX_SPREAD_ATTRIB="JSXSpreadAttribute";module.exports.JSX_TEXT="JSXText";module.exports.EXPORT_DEFAULT_DECL="ExportDefaultDeclaration";module.exports.EXPORT_NAMED_DECL="ExportNamedDeclaration";module.exports.EXPORT_ALL_DECL="ExportAllDeclaration";module.exports.EXPORT_ASSIGNMENT="TSExportAssignment";module.exports.EXPORT_SPECIFIER="ExportSpecifier";module.exports.IMPORT_DECL="ImportDeclaration";module.exports.IMPORT_EQUALS_DECL="TSImportEqualsDeclaration";module.exports.IMPORT_SPECIFIER="ImportSpecifier";module.exports.IMPORT_DEF_SPECIFIER="ImportDefaultSpecifier";module.exports.IMPORT_NS_SPECIFIER="ImportNamespaceSpecifier";module.exports.ANY_KEYWORD="TSAnyKeyword";module.exports.ARRAY_TYPE="TSArrayType";module.exports.AS_EXPR="TSAsExpression";module.exports.BOOLEAN_KEYWORD="TSBooleanKeyword";module.exports.EXTERN_MOD_REF="TSExternalModuleReference";module.exports.ENUM_TS_DECL="TSEnumDeclaration";module.exports.FUNCTION_TYPE="TSFunctionType";module.exports.INTERFACE_BODY="TSInterfaceBody";module.exports.INTERFACE_DECL="TSInterfaceDeclaration";module.exports.INTERSECTION_TYPE="TSIntersectionType";module.exports.LITERAL_TYPE="TSLiteralType";module.exports.NUMBER_KEYWORD="TSNumberKeyword";module.exports.OBJECT_KEYWORD="TSObjectKeyword";module.exports.OPTIONAL_TYPE="TSOptionalType";module.exports.PROPERTY_SIGNATURE="TSPropertySignature";module.exports.STRING_KEYWORD="TSStringKeyword";module.exports.TUPLE_TYPE="TSTupleType";module.exports.TYPE_ALIAS_DECL="TSTypeAliasDeclaration";module.exports.TYPE_LITERAL="TSTypeLiteral";module.exports.TYPE_REF="TSTypeReference";module.exports.UNION_TYPE="TSUnionType";
package/lib/Components.js CHANGED
@@ -3,4 +3,4 @@
3
3
  * Licensed under The Universal Permissive License (UPL), Version 1.0
4
4
  * as shown at https://oss.oracle.com/licenses/upl/
5
5
  */
6
- "use strict";const COMPONENT_JSON="component.json";const PROPERTIES="properties";const PROP_SLOTS="slots";const PROP_DYNAMIC_SLOTS="dynamicSlots";const PROP_PROPS="props";const PROP_EVENTS="events";const PROP_STYLECLASSES="styleClasses";const PROP_IMPLEMENTS="implements";const PROP_REQUIRED="required";const PROP_FOLDER="folder";const PROP_VERSION="version";const PROP_UNSUP_THEME="unsupTheme";const PROP_STATUS="status";const PROP_SUBCOMPONENT_TYPE="subcomponentType";const PROP_TYPE="type";const PROP_PACK="pack";const PROPERTY_VALUE="propertyValue";const PROPERTY_TYPE="propertyType";const PACK_PRIVATE="packPrivate";const DEPRECATED="deprecated";const MAINTENANCE="maintenance";const SUPERSEDES="supersedes";const ANTIPATTERN="antiPattern";const DYNAMIC_FORM_ELEM="DynamicFormElement";const DYNAMIC_TABLE_ELEM="DynamicTableElement";const VB_FRAGMENT_ELEM="VbFragmentElement";const OJ_C="oj-c";const DOT=".";const DASH_CHANGED="-changed";const FT_HTML="html";const FT_TSX="tsx";const REGXPR=/string|number|object|array|boolean|[\|.<>]/gi;function Components(nd,runMode,cwd,compSvcs,urlBase,urls,filePaths,metaLib,ojcPack,jetCore,runOpts,msgCtx,appCtx){this._nd=nd;this._tagLookup={};this._jetTagLookup={};this._styleLookup={};this._ignored={};this._maintenance=null;this._supersedes=null;this._antiPattern=null;this._meta={};this._path=null;this._reqAttrs=null;this._metaLib=metaLib;this._ojcPack=ojcPack;this._utils=appCtx.utils;this._fsUtils=appCtx.fsUtils;this._curFileType=null;this._compSvcs=compSvcs;this._isAMD=runMode==="amd";this._cwd=cwd;this._error=msgCtx.error;this._warn=msgCtx.warn;this._debug=msgCtx.debug;this._info=msgCtx.info;this._msg=msgCtx.msg;this._console=msgCtx.console;this._isDebug=msgCtx.isDebug;this._isVerbose=msgCtx.isVerbose;this._count=0;this._isOk=true;this._runOpts=runOpts;this._init(urlBase,urls,filePaths,jetCore)};Components.prototype.isTag=function(tagName){return!!this._tagLookup[_removeChevrons(tagName)]};Components.prototype.isJetTag=function(tagName){return!!this._jetTagLookup[_removeChevrons(tagName)]};Components.prototype.isKnownTag=function(tagName){tagName=_removeChevrons(tagName);return this._jetTagLookup[tagName]||this._tagLookup[tagName]};Components.prototype.isTagAttr=function(tagName,attrName){return this.isTagProp(tagName,attrName)||this.isJetTagProp(tagName,attrName)};Components.prototype.isJetTagAttr=function(tagName,attrName){return this.isJetTagProp(tagName,attrName)};Components.prototype.isTagDeprecated=function(tag){var comp,stats,status,ret=null;tag=_removeChevrons(tag);if(comp=this._tagLookup[tag]||this._jetTagLookup[tag]){if(stats=comp.status){for(status of stats){if((!status.type||status.type===DEPRECATED)&&!status.hasOwnProperty("target")){ret=status;if(ret.description){ret.description=this._utils.removeLink(ret.description)}break}}}}return ret};Components.prototype.isTagAttrDeprecated=function(tagName,attrName){var prop,status,stats,o,ret=null;if((prop=this.getAnyTagProp(tagName,attrName))&&(stats=prop.status)){ret=[];for(status of stats){if(!status.type||status.type===DEPRECATED){o={type:DEPRECATED};if(status.hasOwnProperty("target")){o.target=status.target}if(status.hasOwnProperty("description")){o.description=status.description}if(status.hasOwnProperty("since")){o.since=status.since}if(status.hasOwnProperty("value")){o.value=status.value}ret.push(o)}}ret=ret.length?ret:null}return ret};Components.prototype.isTagEventDeprecated=function(tagName,event){var prop,status,stat,dep,ret;if(prop=this.getAnyTagEvent(tagName,event)){if(status=prop.status){for(let i=0;i<status.length;i++){dep=status[i];if(!dep.type||dep.type===DEPRECATED){ret=stat;break}}}}return ret?ret:null};Components.prototype.isTagAttrTranslatable=function(tag,attr){var prop=this.getAnyTagProp(tag,attr);return prop&&prop.translatable};Components.prototype.isTagAttrReadOnly=function(tag,attr){var prop=this.getAnyTagProp(tag,attr);return prop&&prop.readonly};Components.prototype.isTagProp=function(tagName,propName){return!!this.getTagProp(tagName,propName)};Components.prototype.isJetTagProp=function(tagName,propName){return!!this.getJetTagProp(tagName,propName)};Components.prototype.getTagProp=function(tagName,propName){var ret;if(this.isTag(tagName)){ret=this._getTagProp(tagName,propName,false)}return ret?ret:null};Components.prototype.getJetTagProp=function(tagName,propName){var ret;if(this.isJetTag(tagName)){ret=this._getTagProp(tagName,propName,true)}return ret?ret:null};Components.prototype.getAnyTagProp=function(tagName,propName){return this._getTagProp(tagName,propName,true)||this._getTagProp(tagName,propName,false)};Components.prototype._getTagProp=function(tagName,propName,isOJC){var tag,props,list;list=isOJC?this._jetTagLookup:this._tagLookup;tag=list[_removeChevrons(tagName)];props=tag?tag[PROP_PROPS]:null;if(props){propName=propName.charAt(0)===":"?propName.substring(1):propName;if(this._curFileType!=="tsx"){propName=_propToCamelCase(propName)}}return props?props[propName]:null};Components.prototype.getTagPropType=function(tagName,propName){var prop,ret;if(prop=this.getTagProp(tagName,propName)){ret=prop?prop.type:undefined}return ret};Components.prototype.getAnyTagEvent=function(tag,event){return this._getTagEvent(tag,event,true)||this._getTagEvent(tag,event,false)};Components.prototype._getTagEvent=function(tagName,eventName,isOJC){var tag,events,event,list;list=isOJC?this._jetTagLookup:this._tagLookup;tag=list[_removeChevrons(tagName)];if(events=tag?tag[PROP_EVENTS]:null){if(!(event=events[eventName])){if(eventName.endsWith(DASH_CHANGED)){eventName=eventName.substring(0,eventName.length-DASH_CHANGED.length);if(this._curFileType!=="tsx"){eventName=_propToCamelCase(eventName)}}event=events[eventName]}}return event?event.status:null};Components.prototype.getComponentMetadata=function(tag){return this._meta[tag]||null};Components.prototype.getComponentPropMetadata=function(tagName,propName){var comp,sofar,props;tagName=_removeChevrons(tagName);if(!(comp=this._meta[tagName])||!(props=comp.properties)){return null}let subprops=propName.split(DOT);if(this._curFileType===FT_HTML){subprops.forEach((subprop,i,ar)=>{ar[i]=_propToCamelCase(subprop)})}if(subprops.length===1){return props[propName]||null}sofar=comp;let nextprop,i;for(i=0;i<subprops.length;i++){nextprop=subprops[i];if(sofar.hasOwnProperty(PROPERTIES)){sofar=sofar.properties[nextprop]||null;if(!sofar){break}}else{sofar=null;break}}return sofar};Components.prototype.getTagMetadata=function(tag){tag=_removeChevrons(tag);return this._tagLookup[tag]||this._jetTagLookup[tag]};Components.prototype.getJetTag=function(tag){var meta;return(meta=this._jetTagLookup[tag])?meta:null};Components.prototype.getMaintenanceTags=function(){return this._maintenance};Components.prototype.isTagEvent=function(tagName,eventName){var propName,o,b;o=this._tagLookup[tagName]||this._jetTagLookup[tagName];if(o){if(eventName.startsWith("on-")){b=o.events&&o.events[eventName];if(b)return b;if(o.implements&&(o.implements.includes(DYNAMIC_FORM_ELEM)||o.implements.includes(DYNAMIC_TABLE_ELEM)||o.implements.includes(VB_FRAGMENT_ELEM))){return true}if(eventName.endsWith(DASH_CHANGED)){if(o.props){propName=eventName.replace(DASH_CHANGED,"").substring(3);propName=_propToCamelCase(propName);return!!o.props[propName]}}}}return false};Components.prototype.isTagStyle=function(tag,style){var meta,ret=false;if(meta=this._tagLookup[tag]||this._jetTagLookup[tag]){let styles;if(styles=meta.styleClasses){ret=!!styles[style]}}return ret};Components.prototype.isJetStyle=function(style){var tag,ret=false;if(tag=this._styleLookup[style]){ret=!!this._jetTagLookup[tag]}return ret};Components.prototype.isStyle=function(style){return!!this._styleLookup[style]};Components.prototype.getStyleMetadata=function(style){var tag,styles,sc,ret=null;if(tag=this._styleLookup[style]){if(styles=this._tagLookup[tag].styleClasses){if(sc=styles[style]){ret={tag:tag,meta:sc}}}}return ret};Components.prototype.getStyleSelector=function(style){var sm=this.getStyleMetadata(style);return sm&&sm.meta?sm.meta.styleSelector:null};Components.prototype.hasTagSlotName=function(tagName,slotName){var o=this._tagLookup[tagName]||this._jetTagLookup[tagName];return!!(o&&o.slots&&o.slots[slotName])};Components.prototype.getPreferredSlotContent=function(tag,slotName,impls){var o,slot,prefContent=null,comps=null,content;if(this._utils.hasAnyProps(impls)){if(o=this._tagLookup[tag]||this._jetTagLookup[tag]){if(o.slots){slotName=slotName?slotName:"";if(slot=o.slots[slotName]){if(prefContent=slot.preferredContent){prefContent.forEach(impl=>{if(content=impls[impl]){if(!comps){comps=[]}comps.push(...content)}})}}}}}return prefContent||comps?{interfaces:prefContent,components:comps}:null};Components.prototype.getTagSlotMetadata=function(tag,slot){var o,ret;if(o=this._tagLookup[tag]||this._jetTagLookup[tag]){if(o.slots){slot=slot?slot:"";if(slot=o.slots[slot]){ret=slot}}}return ret};Components.prototype.hasTagDynamicSlot=function(tag){var o,ret=false;if(o=this._tagLookup[tag]||this._jetTagLookup[tag]){ret=o.hasOwnProperty(PROP_DYNAMIC_SLOTS)}return ret};Components.prototype.hasTagAttrValues=function(tagName,attrName){var prop,ret=false;if((prop=this.getTagProp(tagName,attrName))||(prop=this.getJetTagProp(tagName,attrName))){ret=!!prop.enumValues}return ret};Components.prototype.isTagAttrValue=function(tagName,attrName,value){var prop,ret;if((prop=this.getTagProp(tagName,attrName))||(prop=this.getJetTagProp(tagName,attrName))){if(prop&&prop.enumValues){ret=prop.enumValues.indexOf(value)>=0}}return!!ret};Components.prototype.isTagAttrEnumDeprecated=function(tag,attr,val){var prop,stats,status,ret=null;if(prop=this.getAnyTagProp(tag,attr)){if(stats=prop.status){for(status of stats){if((!status.type||status.type===DEPRECATED)&&status.target===PROPERTY_VALUE){if(status.value&&status.value.includes(val)){ret={type:DEPRECATED};if(status.hasOwnProperty("target")){ret.target=status.target}if(status.hasOwnProperty("description")){ret.description=status.description}if(status.hasOwnProperty("since")){ret.since=status.since}if(status.hasOwnProperty("value")){ret.value=status.value}break}}}}}return ret};Components.prototype.isTagSupportedInTheme=function(tag,theme){var o,unsup,ret=true;if(o=this.getTagMetadata(tag)){unsup=o[PROP_UNSUP_THEME];if(unsup){ret=!unsup.includes(theme)}}return ret};Components.prototype.isAttrSupportedInTheme=function(tag,attr,theme){var prop,unsup,ret=true;if(prop=this.getAnyTagProp(tag,attr)){if(unsup=prop[PROP_UNSUP_THEME]){ret=!unsup.includes(theme)}}return ret};Components.prototype.isTagPackPrivate=function(tag){var o,ret;tag=_removeChevrons(tag);if(o=this._tagLookup[tag]||this._jetTagLookup[tag]){ret=o[PROP_SUBCOMPONENT_TYPE]===PACK_PRIVATE}return ret};Components.prototype.getSubcomponentType=function(tag){var o,ret;if(o=this._tagLookup[tag]||this._jetTagLookup[tag]){ret=o[PROP_SUBCOMPONENT_TYPE]}return ret||null};Components.prototype.getRequiredProps=function(tagName){var tag,props,prop,propName,obj,ret=null;tagName=_removeChevrons(tagName);if(this._reqAttrs){let r=this._reqAttrs[tagName];if(r){return typeof r==="boolean"?null:r}}tag=this._tagLookup[tagName]||this._jetTagLookup[tagName];if(tag&&tag.props){if(!this._reqAttrs){this._reqAttrs={}}if(!this._reqAttrs[tagName]){this._reqAttrs[tagName]=true}props=tag.props;for(propName in props){prop=props[propName];if(prop.required){if(!obj){obj=[]}obj.push(propName)}}}if(obj&&obj.length){let i,j,p;for(i=0;i<obj.length;i++){if(p=obj[i]){p+=".";for(j=i+1;j<obj.length;j++){if(obj[j].startsWith(p)){obj.splice(i,1);i--;break}}}}this._reqAttrs[tagName]=obj;ret=obj}return ret};Components.prototype.getRequiredAttrs=function(tagName){return this.getRequiredProps(tagName)};Components.prototype.getInterfaces=function(tag){var o,ret;if(o=this._tagLookup[tag]||this._jetTagLookup[tag]){ret=o.implements}return ret||null};Components.prototype.getUserNames=function(){var name,a=[];for(name in this._tagLookup){a.push({name:name,version:this._tagLookup[name].version})}return a};Components.prototype.getJetNames=function(){var name,a=[];for(name in this._jetTagLookup){a.push({name:name,version:this._jetTagLookup[name].version})}return a};Components.prototype.getCount=function(){return this._count};Components.prototype.isTagMaintenance=function(tag){return this._maintenance&&this._maintenance.has(tag)};Components.prototype.isTagSupersedes=function(tag){return this._supersedes&&this._supersedes.has(tag)};Components.prototype.isTagAntiPattern=function(tag){return this._antiPattern&&this._antiPattern.has(tag)};Components.prototype.getTagMaintenanceStatus=function(tag){return this.getTagStatus(tag,MAINTENANCE)};Components.prototype.getTagSupersedesStatus=function(tag){return this.getTagStatus(tag,SUPERSEDES)};Components.prototype.getTagAntiPatternStatus=function(tag){return this.getTagStatus(tag,ANTIPATTERN)};Components.prototype.getTagStatus=function(tag,type){var ret=null;if(type===SUPERSEDES&&this.isTagSupersedes(tag)||type===MAINTENANCE&&this.isTagMaintenance(tag)||type===DEPRECATED&&this.isTagDeprecated(tag)||type===ANTIPATTERN&&this.isTagAntiPattern(tag)){let comp,arStat,stat,i;if(comp=this._tagLookup[tag]||this._jetTagLookup[tag]){arStat=comp.status;for(i=0;i<arStat.length;i++){stat=arStat[i];if(stat.type===type||type===DEPRECATED&&!stat.type){ret=stat;break}}}}return ret};Components.prototype.isRuleIgnored=function(compName,ruleName){var ret,ar;if(ar=this._ignored[compName]){ret=ar.includes(ruleName)}return!!ret};Components.prototype.isOk=function(){return this._isOk};Components.prototype.setCurFileType=function(ft){this._curFileType=ft};Components.prototype._init=function(base,urls,filePaths,jetCore){if(this._isAMD){this._processJetCorePack();return}if(base){base=base.trim();if(base.charAt(base.length-1)!=="/"){base=base+"/"}}else{base=""}this._processFilePaths(filePaths);this._processUrls(base,urls);this._processJetCorePack();this._createStyleLookup();this._processJetCore(jetCore)};Components.prototype._processFilePaths=function(filePaths){var obj,compEntry,fpath,i,j;if(!filePaths){return}this._console("\nPre-processing user-declared web component metadata...");for(i=0;i<filePaths.length;i++){compEntry=filePaths[i];var dirStack=this._nd.glob.sync(compEntry);for(j=0;j<dirStack.length;j++){fpath=dirStack[j];if(this._runOpts.isDryRun||this._runOpts.isDebug){let msg="-".repeat(70)+"\n"+(this._runOpts.isDryRun?"* ":"")+"processing component path '"+fpath+"' ...";if(this._runOpts.isDryRun){console.log(msg)}else{this._debug(msg)}}if(fpath.toLowerCase().endsWith(".zip")){obj=this._compSvcs._extractComponentJsonFromZip(fpath);if(obj.obj){this.processComponentJson(obj.obj,fpath,true)}else if(obj.msg){this._error("Failed to parse component.json : "+obj.msg+" - "+fpath)}else if(obj.error){this._error("Failed to unzip '"+fpath+"'")}continue}if(this._isComponentJsonPath(fpath)){if(obj=this._readComponentJson(fpath)){if(obj.type&&obj.type==="pack"){continue}this.processComponentJson(obj,this._nd.path.dirname(fpath),true)}continue}this._recurse(fpath)}}if(this._isDebug){this._debug("-".repeat(70))}};Components.prototype._recurse=function(fpath){var dirs,inFile,obj,i;try{dirs=this._nd.fs.readdirSync(fpath);if(this._isDebug){this._debug(` processing ${fpath} ${dirs.length} component dirs ...`)}for(i=0;i<dirs.length;i++){inFile=dirs[i];if(inFile===COMPONENT_JSON){inFile=this._nd.path.join(fpath,COMPONENT_JSON);if(this._isDebug){this._debug(" processing "+inFile+"...")}obj=this._readComponentJson(inFile);if(obj){if(!obj.type||obj.type==="composite"){this.processComponentJson(obj,fpath,true)}}else{return}}var curPath=this._nd.path.join(fpath,inFile);if(this._fsUtils.getFileType(curPath)==="d"){this._recurse(curPath)}}}catch(e){this._error("Component check failed - "+e);this._isOk=false}};Components.prototype._processUrls=function(base,urls){var url,i;if(!urls){return}for(i=0;i<urls.length;i++){url=urls[i];if(this._runOpts.isDryRun||this._runOpts.isDebug){let msg;msg="-".repeat(70)+"\nprocessing URL '"+url+"'";if(this._runOpts.isDryRun){console.log(msg);continue}else{this._debug(msg)}}if(_isRelativeUrl(url)){url=base+url;if(_isRelativeUrl(url)){this._error("component URL incomplete - '"+url+"'");continue}}this._processUrl(url)}};Components.prototype._processUrl=function(url){var resp,obj,rc,tempFile,tmp;try{resp=this._compSvcs.loadUrl(url);if(resp.eCode==="ETIMEDOUT"){this._error("config.componentUrls - request timed-out for '"+url+"'");this._isOk=false;return}try{if(resp.type==="json"){if(resp.body){obj=JSON.parse(resp.body);if(!this.processComponentJson(obj,url,false)){this._isOk=false}}else{this._error("Server responded with "+resp.statusCode+" URL: '"+url+"'")}}else if(resp.type=="zip"){rc=this._compSvcs.writeZipBufferToFile(resp.body);if(typeof rc==="boolean"&&rc){tempFile=this._compSvcs.getLastZipFilePath();obj=this._compSvcs.extractComponentJsonFromZip(tempFile);if(obj.obj){this.processComponentJson(obj.obj,url,true)}else if(obj.msg){this._error("Failed to parse component.json : "+obj.msg+" - "+url)}else if(obj.error){this._error("Failed to unzip '"+url+"'")}this._compSvcs.deleteZipFile(tempFile)}else{this._error("Failed to create local temp zip file from URL '"+url+"' : rc.message");this._isOk=false}}else{tmp=typeof resp.type==="string"?resp.type:"?";this._error("Server responded with unexpected data ('"+tmp+"') : '"+url+"'");this._isOk=false}}catch(e){this._error("Invalid JSON - URL '"+url+"' : "+e);this._isOk=false}}catch(e1){this._error("URL access failed "+(e1.message.includes("ENOTFOUND")?"(NOT FOUND)":"")+" - URL '"+url+"'");this._isOk=false}};Components.prototype._processJetCorePack=function(){var comps,comp;if(comps=this._ojcPack.getComponents()){for(comp in comps){this.processComponentJson(comps[comp],"oj-c")}}};Components.prototype.processComponentJson=function(obj,fromLocation){var comp,props,events,event,eventName,compName,metaObj;var isOJC;compName=obj.pack?obj.pack+"-"+obj.name:obj.name;isOJC=obj.pack===OJ_C;if(!this._isAMD){if(this._runOpts.isDryRun){console.log(" Would have processed '"+fromLocation+"'");return}if(obj.type&&obj.type==="pack"){return this._processJetPack(obj,fromLocation)}if(!isOJC){if(!this._compSvcs.validateComponentJson(obj,fromLocation)){this._isOk=false;return false}}}if(this._tagLookup[compName]||this._jetTagLookup[compName]){this._warn(`Ignoring duplicate component '${compName}' at '${fromLocation}'`);return true}this._meta[compName]=obj;if(isOJC){this._jetTagLookup[compName]=comp={}}else{this._tagLookup[compName]=comp={}}comp[PROP_FOLDER]=fromLocation;comp[PROP_VERSION]=obj.version;if(obj.extension&&obj.extension.audit&&obj.extension.audit.ignore){let ar;if((ar=obj.extension.audit.ignore)&&ar.length){this._ignored[compName]=[...ar]}}if(obj.hasOwnProperty(PROP_SLOTS)){comp[PROP_SLOTS]=obj[PROP_SLOTS]}if(obj.hasOwnProperty(PROP_DYNAMIC_SLOTS)){comp[PROP_DYNAMIC_SLOTS]=obj[PROP_DYNAMIC_SLOTS]}if(obj.properties){comp[PROP_PROPS]=props={};this._extractProps(props,null,obj.properties,obj.name)}if(obj.events){comp[PROP_EVENTS]=events={};for(event in obj.events){eventName=_propEventToKebabCase(event);events[eventName]=obj.events[event];metaObj=obj.events}}if(obj.implements){comp[PROP_IMPLEMENTS]=obj.implements;this._metaLib.processImplements(compName,obj.implements)}if(obj.status){let status,i;metaObj=obj.status;for(i=0;i<metaObj.length;i++){status=metaObj[i];if(status.type===MAINTENANCE){if(!this._maintenance){this._maintenance=new Set}this._maintenance.add(compName)}else if(status.type===SUPERSEDES){if(!this._supercedes){this._supersedes=new Set}this._supersedes.add(compName)}else if(status.type===ANTIPATTERN){if(!this._antiPattern){this._antiPattern=new Set}this._antiPattern.add(compName)}}}if(obj.extension&&obj.extension.theme&&obj.extension.theme.unsupportedThemes){comp[PROP_UNSUP_THEME]=obj.extension.theme.unsupportedThemes}if(obj.hasOwnProperty(PROP_SUBCOMPONENT_TYPE)){comp[PROP_SUBCOMPONENT_TYPE]=obj[PROP_SUBCOMPONENT_TYPE]}if(obj.type){comp[PROP_TYPE]=obj.type}if(obj.pack){comp[PROP_PACK]=obj.pack}if(obj.hasOwnProperty("required")){comp[PROP_REQUIRED]=obj.required}if(obj.status){comp[PROP_STATUS]=obj.status}if(obj.styleClasses){comp[PROP_STYLECLASSES]=this._extractStyles(obj.styleClasses)}this._count++;return true};Components.prototype._extractProps=function(propObj,propSoFar,properties,name,rdonly){var prop,thisProp,soFar,obj;for(prop in properties){soFar=(propSoFar?propSoFar+DOT:"")+prop;propObj[soFar]=obj={};thisProp=properties[prop];if(thisProp.hasOwnProperty("enumValues")){if(Array.isArray(thisProp.enumValues)){obj.enumValues=thisProp.enumValues}else{this._error(`Web component '${name}' property '${soFar}' has invalid 'enumValues' in component.json`)}}if(thisProp.hasOwnProperty("status")){obj.status=thisProp.status}if(thisProp.hasOwnProperty("type")){obj.type=thisProp.type}if(thisProp.required){obj.required=true}if(thisProp.extension&&thisProp.extension.theme&&thisProp.extension.theme.unsupportedThemes){obj[PROP_UNSUP_THEME]=thisProp.extension.theme.unsupportedThemes}if(thisProp.hasOwnProperty("translatable")){obj.translatable=true}if(typeof thisProp.readonly==="boolean"){obj.readonly=thisProp.readOnly}else{if(rdonly){obj.readonly=true}}if(thisProp.hasOwnProperty("properties")){obj.properties=true;this._extractProps(propObj,soFar,thisProp.properties,name,obj.readonly)}}};Components.prototype._extractStyles=function(styleClasses){var so,si,obj,ret={},i,j;if(!Array.isArray(styleClasses)){return ret}for(i=0;i<styleClasses.length;i++){so=styleClasses[i];if(so.kind==="class"){ret[so.name]=this._extractStyleClass(so)}else if(so.kind==="set"&&so.styleItems&&Array.isArray(so.styleItems)){ret[so.name]=obj={kind:"set"};if(so.status){obj.status=so.status}obj.styleClasses={};for(j=0;j<so.styleItems.length;j++){si=so.styleItems[j];obj.styleClasses[si.name]=this._extractStyleClass(si)}}else if(so.kind==="template"){}}return ret};Components.prototype._extractStyleClass=function(so){var obj={};if(so.styleSelector){obj.styleSelector=so.styleSelector}if(so.status){obj.status=so.status}return obj};Components.prototype._processJetPack=function(obj,fromLocation){var deps,dep,urlKey,depUrl,msg,i;if(this._runOpts.isDryRun||this._runOpts.isDebug){msg="processing JET Pack "+obj.name+" (version: "+obj.version+") : '"+fromLocation+"'";if(this._runOpts.isDryRun){console.log("* "+msg);return}else{this._debug(msg)}}if(!fromLocation.includes("http")){this._error("JET packs loaded via config 'components' property (file based) are currently not supported");return false}i=fromLocation.indexOf(obj.name);if(i>=0){urlKey=fromLocation.substring(0,i)}else{this._error("Cannot handle Jet Pack URL format to load dependencies : "+fromLocation)}deps=obj.dependencies;if(deps){for(dep in deps){depUrl=urlKey+dep+"/versions/"+obj.dependencies[dep]+"/content/component.json";if(this._isDebug){this._debug(` processing dependency ${dep} ${obj.dependencies[dep]}`)}this._processUrls("",[depUrl])}}return false};Components.prototype._processJetCore=function(jetCorePath){var files,file,obj,i;if(!jetCorePath){return}this._console("-".repeat(70)+"\nPerforming schema analysis on JET Core components (dt) using '"+this._compSvcs.getSchemaName()+"'...");try{files=this._nd.fs.readdirSync(jetCorePath);this._console(` processing ${files.length} $jetCore components...`);for(i=0;i<files.length;i++){file=files[i];if(file.endsWith(".json")){file=this._nd.path.join(jetCorePath,file);try{obj=this._readComponentJson(file);if(obj){this._compSvcs.validateComponentJson(obj,file)}}catch(e){}}}}catch(e1){this._error("!!! $JetCore Component check failed - "+e1)}this._console(" processing "+(files?files.length+" ":"")+"$jetCore components completed");this._console("-".repeat(70))};Components.prototype._createStyleLookup=function(){var tag,o,scl,st;for(tag in this._tagLookup){o=this._tagLookup[tag];if(scl=o.styleClasses){for(st in scl){this._styleLookup[st]=tag}}}};Components.prototype._readComponentJson=function(inFile){var obj=null;if(this._isDebug){this._debug(` loading '${inFile}'`)}obj=this._nd.jsonLoader.load(inFile,this._nd,this._error,false,this._utils);if(!obj){this._isOk=false}return obj};Components.prototype._isComponentJsonPath=function(filePath){return filePath.toLowerCase().endsWith(COMPONENT_JSON)};Components.prototype.dumpComponentNames=function(){var names;names=this.getUserNames();if(!names.length){this._console("[info]: No valid user web components declared!","I")}else{this._console("[info] :--------- Declared Web Components ---------","I");this._dumpComponentNames(names);this._console("[info]: -------- End Declared Web Components ---------\n","I")}names=this.getJetNames();if(!names.length){this._console("[info]: No valid user JET Core Pack components declared!","I")}else{this._console("[info] :--------- Declared JET OJ-C Pack Web Components ---------","I");this._dumpComponentNames(names);this._console("[info]: -------- End Declared OJ-C Pack Web Components ---------\n","I")}};Components.prototype._dumpComponentNames=function(names){var meta,obj,i;for(i=0;i<names.length;i++){obj=names[i];this._console(` ${obj.name} (${obj.version})`,"I");meta=this.getTagMetadata(obj.name);if(meta.implements){this._console(` Impls: ${meta.implements.join(",")}`)}}};function _propToKebabCase(str){return str.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/([A-Z])([A-Z])(?=[a-z])/g,"$1-$2").toLowerCase()};function _propEventToKebabCase(str){return"on-"+_propToKebabCase(str)};function _propToCamelCase(str){var parts,i;function _camelCase(str){return str.replace(/(?:^\w|[A-Z]|\b\w)/g,function(word,index){return index==0?word.toLowerCase():word.toUpperCase()}).replace(/-|\s+/g,"")};parts=str.split(DOT);for(i=0;i<parts.length;i++){parts[i]=_camelCase(parts[i])}return parts.join(DOT)};function _isRelativeUrl(url){url=url.toLowerCase();return!(url.indexOf("http://")===0||url.indexOf("https://")===0)};function _removeChevrons(tagName){if(tagName){let len=tagName.length-1;let start=tagName.charAt(0)==="<"?1:0;let end=tagName.charAt(len)===">"?len:++len;tagName=tagName.substring(start,end)}return tagName};module.exports=Components;
6
+ "use strict";const COMPONENT_JSON="component.json";const PROPERTIES="properties";const PROP_SLOTS="slots";const PROP_DYNAMIC_SLOTS="dynamicSlots";const PROP_PROPS="props";const PROP_EVENTS="events";const PROP_STYLECLASSES="styleClasses";const PROP_IMPLEMENTS="implements";const PROP_REQUIRED="required";const PROP_FOLDER="folder";const PROP_VERSION="version";const PROP_UNSUP_THEME="unsupTheme";const PROP_STATUS="status";const PROP_SUBCOMPONENT_TYPE="subcomponentType";const PROP_DEPENDENCIES="dependencies";const PROP_TYPE="type";const PROP_PACK="pack";const PROPERTY_VALUE="propertyValue";const PROPERTY_TYPE="propertyType";const PACK_PRIVATE="packPrivate";const DEPRECATED="deprecated";const MAINTENANCE="maintenance";const SUPERSEDES="supersedes";const ANTIPATTERN="antiPattern";const DYNAMIC_FORM_ELEM="DynamicFormElement";const DYNAMIC_TABLE_ELEM="DynamicTableElement";const VB_FRAGMENT_ELEM="VbFragmentElement";const CUSTOM_ELEMENT="@customElement";const REGISTER_CUSTOM_ELEMENT="registerCustomElement";const OJ_C="oj-c";const DOT=".";const CHANGED="Changed";const FT_HTML="html";const FT_TSX="tsx";const REGXPR=/string|number|object|array|boolean|[\|.<>]/gi;function Components(nd,runMode,cwd,compSvcs,urlBase,urls,filePaths,metaLib,ojcPack,jetCore,runOpts,msgCtx,appCtx){this._nd=nd;this._tagLookup={};this._jetTagLookup={};this._VCompLookup={};this._styleLookup={};this._ignored={};this._maintenance=null;this._supersedes=null;this._antiPattern=null;this._meta={};this._path=null;this._reqAttrs=null;this._metaLib=metaLib;this._ojcPack=ojcPack;this._utils=appCtx.utils;this._fsUtils=appCtx.fsUtils;this._tsUtils=appCtx.tsUtils;this._curFileType=null;this._oConfig=appCtx.config;this._VFilesInspected=null;this._VTypes=null;this._compSvcs=compSvcs;this._isAMD=runMode==="amd";this._cwd=cwd;this._error=msgCtx.error;this._warn=msgCtx.warn;this._debug=msgCtx.debug;this._info=msgCtx.info;this._msg=msgCtx.msg;this._console=msgCtx.console;this._jafMsg=msgCtx.jafMsg;this._isDebug=msgCtx.isDebug;this._isVerbose=msgCtx.isVerbose;this._count=0;this._isOk=true;this._runOpts=runOpts;this._init(urlBase,urls,filePaths,jetCore);if(this._tsUtils){this._initVComponents()}};Components.prototype.isUserTag=function(tagName){var tag=_removeChevrons(tagName);return!!(this._tagLookup[tag]||this._VCompLookup[tag])};Components.prototype.isJetCoreTag=function(tagName){return!!this._jetTagLookup[_removeChevrons(tagName)]};Components.prototype.isVComponentTag=function(tagName){return!!this._VCompLookup[_removeChevrons(tagName)]};Components.prototype.isKnownTag=function(tagName){return!!this._lookupTag(tagName)};Components.prototype._lookupTag=function(tagName){tagName=_removeChevrons(tagName);return this._jetTagLookup[tagName]||this._tagLookup[tagName]||this._VCompLookup[tagName]};Components.prototype.isTagAttr=function(tagName,attrName){return this.isTagProp(tagName,attrName)||this.isJetTagProp(tagName,attrName)};Components.prototype.isJetTagAttr=function(tagName,attrName){return this.isJetTagProp(tagName,attrName)};Components.prototype.isTagDeprecated=function(tag){var comp,stats,status,ret=null;if(comp=this._lookupTag(_removeChevrons(tag))){if(stats=comp.status){for(status of stats){if((!status.type||status.type===DEPRECATED)&&!status.hasOwnProperty("target")){ret=status;if(ret.description){ret.description=this._utils.removeLink(ret.description)}break}}}}return ret};Components.prototype.isTagAttrDeprecated=function(tagName,attrName){var prop,status,stats,o,ret=null;if((prop=this.getAnyTagProp(tagName,attrName))&&(stats=prop.status)){ret=[];for(status of stats){if(!status.type||status.type===DEPRECATED){o={type:DEPRECATED};if(status.hasOwnProperty("target")){o.target=status.target}if(status.hasOwnProperty("description")){o.description=status.description}if(status.hasOwnProperty("since")){o.since=status.since}if(status.hasOwnProperty("value")){o.value=status.value}ret.push(o)}}ret=ret.length?ret:null}return ret};Components.prototype.isTagEventDeprecated=function(tagName,eventName){var event,stats,ret=null;if(event=this.getAnyTagEvent(tagName,eventName)){if(stats=event.status){stats.forEach(stat=>{if(!stat.type||stat.type===DEPRECATED){if(!ret){ret=[]}ret.push(stat)}})}}return ret};Components.prototype.getTagPropertyFromEvent=function(tagName,eventName){var o,ret;if(o=this.getTagEventName(tagName,eventName)){ret=o.name}return ret?ret:null};Components.prototype.isTagAttrTranslatable=function(tag,attr){var prop=this.getAnyTagProp(tag,attr);return prop&&prop.translatable};Components.prototype.isTagAttrReadOnly=function(tag,attr){var prop=this.getAnyTagProp(tag,attr);return prop&&prop.readonly};Components.prototype.isTagAttrWriteback=function(tag,attr){var prop=this.getAnyTagProp(tag,attr);return prop&&prop.writeback};Components.prototype.isTagProp=function(tagName,propName){return!!this.getTagProp(tagName,propName)};Components.prototype.isJetTagProp=function(tagName,propName){return!!this.getJetTagProp(tagName,propName)};Components.prototype.getTagProp=function(tagName,propName){var ret;if(this.isUserTag(tagName)){ret=this._getTagProp(tagName,propName,false)}return ret?ret:null};Components.prototype.getJetTagProp=function(tagName,propName){var ret;if(this.isJetCoreTag(tagName)){ret=this._getTagProp(tagName,propName,true)}return ret?ret:null};Components.prototype.getAnyTagProp=function(tagName,propName){return this._getTagProp(tagName,propName,true)||this._getTagProp(tagName,propName,false)};Components.prototype._getTagProp=function(tagName,propName,isOJC){var tag,props,list;tagName=_removeChevrons(tagName);if(isOJC){tag=this._jetTagLookup[tagName]}else{tag=this._tagLookup[tagName]||this._VCompLookup[tagName]};props=tag?tag[PROP_PROPS]:null;if(props){propName=propName.charAt(0)===":"?propName.substring(1):propName;if(this._curFileType!=="tsx"){propName=_propToCamelCase(propName)}}return props?props[propName]:null};Components.prototype.getTagPropType=function(tagName,propName){var prop,ret;if(prop=this.getTagProp(tagName,propName)){ret=prop?prop.type:undefined}return ret};Components.prototype.getAnyTagEvent=function(tag,event){return this._getTagEvent(tag,event,true)||this._getTagEvent(tag,event,false)};Components.prototype._getTagEvent=function(tagName,eventName,isOJC){var tagObj,events,event;if(!eventName.startsWith("on")){return null}tagName=_removeChevrons(tagName);if(isOJC){tagObj=this._jetTagLookup[tagName]}else{tagObj=this._tagLookup[tagName]||this._VCompLookup[tagName]}if(!tagObj){return null}if(!(events=tagObj[PROP_EVENTS])){return null}if(eventName.includes("-")){eventName=eventName.substring(3);eventName=_propToCamelCase(eventName)}else{eventName=eventName.substring(2)}event=events[eventName];return event?event:null};Components.prototype.getComponentPropMetadata=function(tagName,propName){var comp,sofar,props;tagName=_removeChevrons(tagName);if(!(comp=this._meta[tagName])||!(props=comp.properties)){return null}let subprops=propName.split(DOT);if(this._curFileType===FT_HTML){subprops.forEach((subprop,i,ar)=>{ar[i]=_propToCamelCase(subprop)})}if(subprops.length===1){return props[propName]||null}sofar=comp;let nextprop,i;for(i=0;i<subprops.length;i++){nextprop=subprops[i];if(sofar.hasOwnProperty(PROPERTIES)){sofar=sofar.properties[nextprop]||null;if(!sofar){break}}else{sofar=null;break}}return sofar};Components.prototype.getComponentMetadata=function(tag){return this._meta[tag]||null};Components.prototype.getAllCustomMetadata=function(){var name,comp,obj;var ret={};var i=2;var lookup=this._tagLookup;while(i){for(name in lookup){ret[name]=obj={};comp=lookup[name];obj.folder=comp.folder;obj.json=this.getComponentMetadata(name);if(i===1){obj.VCType=this._VTypes[name]}}i--;lookup=this._VCompLookup}return ret};Components.prototype.getJetTag=function(tag){var o;return(o=this._jetTagLookup[tag])?o:null};Components.prototype.getMaintenanceTags=function(){return this._maintenance};Components.prototype.isTagEvent=function(tagName,eventName){return!!this.getTagEventName(tagName,eventName)};Components.prototype.getTagEventName=function(tagName,eventName){var propName,tagObj,events,impls;tagObj=this._lookupTag(_removeChevrons(tagName));if(!tagObj||!eventName.startsWith("on")){return null}if(eventName.includes("-")){eventName=eventName.substring(3);eventName=_propToCamelCase(eventName)}else{eventName=eventName.substring(2)}if(tagObj.events&&tagObj.events[eventName]){return{type:"event",name:eventName}}if((impls=tagObj.implements)&&(impls.includes(DYNAMIC_FORM_ELEM)||impls.includes(DYNAMIC_TABLE_ELEM)||impls.includes(VB_FRAGMENT_ELEM))){return{type:"dynamic",name:eventName}}if(eventName.endsWith(CHANGED)&&tagObj.props){propName=eventName.replace(CHANGED,"");if(tagObj.props[propName]){return{type:"property",name:propName}};}return null};Components.prototype.isTagStyle=function(tag,style){var tagObj,ret=false;if(tagObj=this._lookupTag(_removeChevrons(tag))){let styles;if(styles=tagObj.styleClasses){ret=!!styles[style]}}return ret};Components.prototype.isJetStyle=function(style){var tag,ret=false;if(tag=this._styleLookup[style]){ret=!!this._jetTagLookup[tag]}return ret};Components.prototype.isStyle=function(style){return!!this._styleLookup[style]};Components.prototype.getStyleMetadata=function(style){var tag,styles,sc,ret=null;if(tag=this._styleLookup[style]){if(styles=this._tagLookup[tag].styleClasses){if(sc=styles[style]){ret={tag:tag,meta:sc}}}}return ret};Components.prototype.getStyleSelector=function(style){var sm=this.getStyleMetadata(style);return sm&&sm.meta?sm.meta.styleSelector:null};Components.prototype.hasTagSlotName=function(tagName,slotName){var o=this._lookupTag(_removeChevrons(tagName));return!!(o&&o.slots&&o.slots[slotName])};Components.prototype.getPreferredSlotContent=function(tag,slotName,impls){var o,slot,prefContent=null,comps=null,content;if(this._utils.hasAnyProps(impls)){if(o=this._lookupTag(_removeChevrons(tag))){if(o.slots){slotName=slotName?slotName:"";if(slot=o.slots[slotName]){if((prefContent=slot.preferredContent)&&prefContent.length){prefContent.forEach(impl=>{if(content=impls[impl]){if(!comps){comps=[]}comps.push(...content)}})}else{prefContent=null}}}}}return prefContent||comps?{interfaces:prefContent,components:comps}:null};Components.prototype.getTagSlotMetadata=function(tag,slot){var o,ret;if(o=this._lookupTag(_removeChevrons(tag))){if(o.slots){slot=slot?slot:"";if(slot=o.slots[slot]){ret=slot}}}return ret};Components.prototype.hasTagDynamicSlot=function(tag){var o,ret=false;if(o=this._lookupTag(_removeChevrons(tag))){ret=o.hasOwnProperty(PROP_DYNAMIC_SLOTS)}return ret};Components.prototype.hasTagAttrValues=function(tagName,attrName){var prop,ret=false;if((prop=this.getTagProp(tagName,attrName))||(prop=this.getJetTagProp(tagName,attrName))){ret=!!prop.enumValues}return ret};Components.prototype.isTagAttrValue=function(tagName,attrName,value){var prop,ret;if((prop=this.getTagProp(tagName,attrName))||(prop=this.getJetTagProp(tagName,attrName))){if(prop&&prop.enumValues){ret=prop.enumValues.indexOf(value)>=0}}return!!ret};Components.prototype.isTagAttrEnumDeprecated=function(tag,attr,val){var prop,stats,status,ret=null;if(prop=this.getAnyTagProp(tag,attr)){if(stats=prop.status){for(status of stats){if((!status.type||status.type===DEPRECATED)&&status.target===PROPERTY_VALUE){if(status.value&&status.value.includes(val)){ret={type:DEPRECATED};if(status.hasOwnProperty("target")){ret.target=status.target}if(status.hasOwnProperty("description")){ret.description=status.description}if(status.hasOwnProperty("since")){ret.since=status.since}if(status.hasOwnProperty("value")){ret.value=status.value}break}}}}}return ret};Components.prototype.isTagSupportedInTheme=function(tag,theme){var o,unsup,ret=true;if(o=this._lookupTag(tag)){if(unsup=o[PROP_UNSUP_THEME]){ret=!unsup.includes(theme)}}return ret};Components.prototype.isAttrSupportedInTheme=function(tag,attr,theme){var prop,unsup,ret=true;if(prop=this.getAnyTagProp(tag,attr)){if(unsup=prop[PROP_UNSUP_THEME]){ret=!unsup.includes(theme)}}return ret};Components.prototype.isTagPackPrivate=function(tag){var o,ret;if(o=this._lookupTag(_removeChevrons(tag))){ret=o[PROP_SUBCOMPONENT_TYPE]===PACK_PRIVATE}return ret};Components.prototype.getSubcomponentType=function(tag){var o,ret;if(o=this._lookupTag(_removeChevrons(tag))){ret=o[PROP_SUBCOMPONENT_TYPE]}return ret||null};Components.prototype.getRequiredProps=function(tagName){var tag,props,prop,propName,obj,ret=null;tagName=_removeChevrons(tagName);if(this._reqAttrs){let r=this._reqAttrs[tagName];if(r){return typeof r==="boolean"?null:r}}tag=this._lookupTag(tagName);if(tag&&tag.props){if(!this._reqAttrs){this._reqAttrs={}}if(!this._reqAttrs[tagName]){this._reqAttrs[tagName]=true}props=tag.props;for(propName in props){prop=props[propName];if(prop.required){if(!obj){obj=[]}obj.push(propName)}}}if(obj&&obj.length){let i,j,p;for(i=0;i<obj.length;i++){if(p=obj[i]){p+=".";for(j=i+1;j<obj.length;j++){if(obj[j].startsWith(p)){obj.splice(i,1);i--;break}}}}this._reqAttrs[tagName]=obj;ret=obj}return ret};Components.prototype.getRequiredAttrs=function(tagName){return this.getRequiredProps(tagName)};Components.prototype.getInterfaces=function(tag){var o,ret;if(o=this._lookupTag(_removeChevrons(tag))){ret=o.implements}return ret?ret:null};Components.prototype.getCount=function(){return this._count};Components.prototype.isTagStatus=function(tag,statType){return!!this._getTagStatus(tag,statType)};Components.prototype.getTagStatus=function(tag,statType){var ret=null,omitted=statType===undefined;var comp,arStat,stat,stType,i;if(comp=this._lookupTag(_removeChevrons(tag))){if(arStat=comp.status){for(i=0;i<arStat.length;i++){stat=arStat[i];stType=stat.type||DEPRECATED;if(omitted||stType===statType){if(!ret){ret=[]}ret.push(stat)}}}}return ret};Components.prototype.getPropStatus=function(tagName,propName,statType){let comp,arStat,ret;if(comp=this._lookupTag(_removeChevrons(tagName))){if(arStat=comp?.props[propName]?.status){let stat,stType,i,omitted=statType===undefined;for(i=0;i<arStat.length;i++){stat=arStat[i];stType=stat.type||DEPRECATED;if(omitted||stType===statType){if(!ret){ret=[]}ret.push(stat)}}}}return ret?ret:null};Components.prototype.isRuleIgnored=function(compName,ruleName){var ret,ar;if(ar=this._ignored[compName]){ret=ar.includes(ruleName)}return!!ret};Components.prototype.isOk=function(){return this._isOk};Components.prototype.setCurFileType=function(ft){this._curFileType=ft};Components.prototype._init=function(base,urls,filePaths,jetCore){if(this._isAMD){this._processJetCorePack();return}if(base){base=base.trim();if(base.charAt(base.length-1)!=="/"){base=base+"/"}}else{base=""}this._processFilePaths(filePaths);this._processUrls(base,urls);this._processJetCorePack();this._createStyleLookup();this._processJetCore(jetCore)};Components.prototype._processFilePaths=function(filePaths){var obj,compEntry,fpath,i,j;if(!filePaths){return}this._console("\nPre-processing user-declared web component metadata...");for(i=0;i<filePaths.length;i++){compEntry=filePaths[i];var dirStack=this._nd.glob.sync(compEntry);for(j=0;j<dirStack.length;j++){fpath=dirStack[j];if(this._runOpts.isDryRun||this._runOpts.isDebug){let msg="-".repeat(70)+"\n"+(this._runOpts.isDryRun?"* ":"")+"processing component path '"+fpath+"' ...";if(this._runOpts.isDryRun){console.log(msg)}else{this._debug(msg)}}if(fpath.toLowerCase().endsWith(".zip")){obj=this._compSvcs._extractComponentJsonFromZip(fpath);if(obj.obj){this.processComponentJson(obj.obj,fpath)}else if(obj.msg){this._error("Failed to parse component.json : "+obj.msg+" - "+fpath)}else if(obj.error){this._error("Failed to unzip '"+fpath+"'")}continue}if(this._isComponentJsonPath(fpath)){if(obj=this._readComponentJson(fpath)){if(obj.type&&obj.type==="pack"){continue}this.processComponentJson(obj,this._nd.path.dirname(fpath))}continue}this._recurse(fpath)}}if(this._isDebug){this._debug("-".repeat(70))}};Components.prototype._recurse=function(fpath){var dirs,inFile,obj,i;try{dirs=this._nd.fs.readdirSync(fpath);if(this._isDebug){this._debug(` processing ${fpath} ${dirs.length} component dirs ...`)}for(i=0;i<dirs.length;i++){inFile=dirs[i];if(inFile===COMPONENT_JSON){inFile=this._nd.path.join(fpath,COMPONENT_JSON);if(this._isDebug){this._debug(" processing "+inFile+"...")}obj=this._readComponentJson(inFile);if(obj){if(!obj.type||obj.type==="composite"){this.processComponentJson(obj,fpath)}}else{return}}var curPath=this._nd.path.join(fpath,inFile);if(this._fsUtils.getFileType(curPath)==="d"){this._recurse(curPath)}}}catch(e){this._error("Component check failed - "+e);this._isOk=false}};Components.prototype._processUrls=function(base,urls){var url,i;if(!urls){return}for(i=0;i<urls.length;i++){url=urls[i];if(this._runOpts.isDryRun||this._runOpts.isDebug){let msg;msg="-".repeat(70)+"\nprocessing URL '"+url+"'";if(this._runOpts.isDryRun){console.log(msg);continue}else{this._debug(msg)}}if(_isRelativeUrl(url)){url=base+url;if(_isRelativeUrl(url)){this._error("component URL incomplete - '"+url+"'");continue}}this._processUrl(url)}};Components.prototype._processUrl=function(url){var resp,obj,rc,tempFile,tmp;try{resp=this._compSvcs.loadUrl(url);if(resp.eCode==="ETIMEDOUT"){this._error("config.componentUrls - request timed-out for '"+url+"'");this._isOk=false;return}try{if(resp.type==="json"){if(resp.body){obj=JSON.parse(resp.body);if(!this.processComponentJson(obj,url)){this._isOk=false}}else{this._error("Server responded with "+resp.statusCode+" URL: '"+url+"'")}}else if(resp.type=="zip"){rc=this._compSvcs.writeZipBufferToFile(resp.body);if(typeof rc==="boolean"&&rc){tempFile=this._compSvcs.getLastZipFilePath();obj=this._compSvcs.extractComponentJsonFromZip(tempFile);if(obj.obj){this.processComponentJson(obj.obj,url)}else if(obj.msg){this._error("Failed to parse component.json : "+obj.msg+" - "+url)}else if(obj.error){this._error("Failed to unzip '"+url+"'")}this._compSvcs.deleteZipFile(tempFile)}else{this._error("Failed to create local temp zip file from URL '"+url+"' : rc.message");this._isOk=false}}else{tmp=typeof resp.type==="string"?resp.type:"?";this._error("Server responded with unexpected data ('"+tmp+"') : '"+url+"'");this._isOk=false}}catch(e){this._error("Invalid JSON - URL '"+url+"' : "+e);this._isOk=false}}catch(e1){this._error("URL access failed "+(e1.message.includes("ENOTFOUND")?"(NOT FOUND)":"")+" - URL '"+url+"'");this._isOk=false}};Components.prototype._processJetCorePack=function(){var comps,comp;if(comps=this._ojcPack.getComponents()){for(comp in comps){this.processComponentJson(comps[comp],"oj-c")}}};Components.prototype.processComponentJson=function(obj,fromLocation,vcomp){var comp,props,events,event,eventName,compName,metaObj;var isOJC;compName=obj.pack?obj.pack+"-"+obj.name:obj.name;isOJC=obj.pack===OJ_C;if(!this._isAMD){if(this._runOpts.isDryRun){console.log(" Would have processed '"+fromLocation+"'");return}if(obj.type&&obj.type==="pack"){return this._processJetPack(obj,fromLocation)}if(!isOJC&&!vcomp){if(!this._compSvcs.validateComponentJson(obj,fromLocation)){this._isOk=false;return false}}}if(this._lookupTag(compName)){this._jafMsg("jaf-sys-dup-component",`Ignoring duplicate component '${compName}' at '${fromLocation}'`,"W");return true}this._meta[compName]=obj;(isOJC?this._jetTagLookup:vcomp?this._VCompLookup:this._tagLookup)[compName]=comp={};comp[PROP_FOLDER]=fromLocation;comp[PROP_VERSION]=obj.version;if(obj.extension&&obj.extension.audit&&obj.extension.audit.ignore){let ar;if((ar=obj.extension.audit.ignore)&&ar.length){this._ignored[compName]=[...ar]}}if(obj.hasOwnProperty(PROP_SLOTS)){comp[PROP_SLOTS]=obj[PROP_SLOTS]}if(obj.hasOwnProperty(PROP_DYNAMIC_SLOTS)){comp[PROP_DYNAMIC_SLOTS]=obj[PROP_DYNAMIC_SLOTS]}if(obj.properties){comp[PROP_PROPS]=props={};this._extractProps(props,null,obj.properties,obj.name)}if(obj.events){comp[PROP_EVENTS]=events={};for(event in obj.events){events[event]=obj.events[event];metaObj=obj.events}}if(obj.implements){comp[PROP_IMPLEMENTS]=obj.implements;this._metaLib.processImplements(compName,obj.implements)}if(obj.status){let status,i;metaObj=obj.status;for(i=0;i<metaObj.length;i++){status=metaObj[i];if(status.type===MAINTENANCE){if(!this._maintenance){this._maintenance=new Set}this._maintenance.add(compName)}else if(status.type===SUPERSEDES){if(!this._supercedes){this._supersedes=new Set}this._supersedes.add(compName)}else if(status.type===ANTIPATTERN){if(!this._antiPattern){this._antiPattern=new Set}this._antiPattern.add(compName)}}}if(obj.extension&&obj.extension.theme&&obj.extension.theme.unsupportedThemes){comp[PROP_UNSUP_THEME]=obj.extension.theme.unsupportedThemes}if(obj.hasOwnProperty(PROP_SUBCOMPONENT_TYPE)){comp[PROP_SUBCOMPONENT_TYPE]=obj[PROP_SUBCOMPONENT_TYPE]}if(obj.hasOwnProperty(PROP_DEPENDENCIES)){comp[PROP_DEPENDENCIES]=obj[PROP_DEPENDENCIES]}if(obj.type){comp[PROP_TYPE]=obj.type}if(obj.pack){comp[PROP_PACK]=obj.pack}if(obj.hasOwnProperty("required")){comp[PROP_REQUIRED]=obj.required}if(obj.status){comp[PROP_STATUS]=obj.status}if(obj.styleClasses){comp[PROP_STYLECLASSES]=this._extractStyles(obj.styleClasses)}this._count++;return true};Components.prototype._extractProps=function(propObj,propSoFar,properties,name,rdonly){var prop,thisProp,soFar,obj;for(prop in properties){soFar=(propSoFar?propSoFar+DOT:"")+prop;propObj[soFar]=obj={};thisProp=properties[prop];if(thisProp.hasOwnProperty("enumValues")){if(Array.isArray(thisProp.enumValues)){obj.enumValues=thisProp.enumValues}else{this._error(`Web component '${name}' property '${soFar}' has invalid 'enumValues' in component.json`)}}if(thisProp.hasOwnProperty("status")){obj.status=thisProp.status}if(thisProp.hasOwnProperty("type")){obj.type=thisProp.type}if(thisProp.required){obj.required=true}if(thisProp.extension&&thisProp.extension.theme&&thisProp.extension.theme.unsupportedThemes){obj[PROP_UNSUP_THEME]=thisProp.extension.theme.unsupportedThemes}if(thisProp.hasOwnProperty("translatable")){obj.translatable=true}if(typeof thisProp.readOnly==="boolean"){obj.readOnly=thisProp.readOnly}else{if(rdonly){obj.readOnly=true}}if(thisProp.hasOwnProperty("writeback")){obj.writeback=thisProp.writeback}if(thisProp.hasOwnProperty("properties")){obj.properties=true;this._extractProps(propObj,soFar,thisProp.properties,name,obj.readOnly)}}};Components.prototype._extractStyles=function(styleClasses){var so,si,obj,ret={},i,j;if(!Array.isArray(styleClasses)){return ret}for(i=0;i<styleClasses.length;i++){so=styleClasses[i];if(so.kind==="class"){ret[so.name]=this._extractStyleClass(so)}else if(so.kind==="set"&&so.styleItems&&Array.isArray(so.styleItems)){ret[so.name]=obj={kind:"set"};if(so.status){obj.status=so.status}obj.styleClasses={};for(j=0;j<so.styleItems.length;j++){si=so.styleItems[j];obj.styleClasses[si.name]=this._extractStyleClass(si)}}else if(so.kind==="template"){}}return ret};Components.prototype._extractStyleClass=function(so){var obj={};if(so.styleSelector){obj.styleSelector=so.styleSelector}if(so.status){obj.status=so.status}return obj};Components.prototype._processJetPack=function(obj,fromLocation){var deps,dep,urlKey,depUrl,msg,i;if(this._runOpts.isDryRun||this._runOpts.isDebug){msg="processing JET Pack "+obj.name+" (version: "+obj.version+") : '"+fromLocation+"'";if(this._runOpts.isDryRun){console.log("* "+msg);return}else{this._debug(msg)}}if(!fromLocation.includes("http")){this._error("JET packs loaded via config 'components' property (file based) are currently not supported");return false}i=fromLocation.indexOf(obj.name);if(i>=0){urlKey=fromLocation.substring(0,i)}else{this._error("Cannot handle Jet Pack URL format to load dependencies : "+fromLocation)}deps=obj.dependencies;if(deps){for(dep in deps){depUrl=urlKey+dep+"/versions/"+obj.dependencies[dep]+"/content/component.json";if(this._isDebug){this._debug(` processing dependency ${dep} ${obj.dependencies[dep]}`)}this._processUrls("",[depUrl])}}return false};Components.prototype._processJetCore=function(jetCorePath){var files,file,obj,i;if(!jetCorePath){return}this._console("-".repeat(70)+"\nPerforming schema analysis on JET Core components (dt) using '"+this._compSvcs.getSchemaName()+"'...");try{files=this._nd.fs.readdirSync(jetCorePath);this._console(` processing ${files.length} $jetCore components...`);for(i=0;i<files.length;i++){file=files[i];if(file.endsWith(".json")){file=this._nd.path.join(jetCorePath,file);try{obj=this._readComponentJson(file);if(obj){this._compSvcs.validateComponentJson(obj,file)}}catch(e){}}}}catch(e1){this._error("!!! $JetCore Component check failed - "+e1)}this._console(" processing "+(files?files.length+" ":"")+"$jetCore components completed");this._console("-".repeat(70))};Components.prototype._initVComponents=function(){let precompileCache,tscript;const preComp=this._tsUtils.getPreCompiler();const preCompUtils=this._tsUtils.getUtils();const auditBase=this._fsUtils.toJAFPath(this._oConfig.getBase());const projectPathInfo=preCompUtils.getKeyPathInfo(auditBase);if((tscript=this._oConfig.getTypescript())&&tscript.compile&&projectPathInfo.tsSource){this._console("Pre-processing VComponents...");if(!(precompileCache=preComp.getPrecompileCache(auditBase,projectPathInfo.tsSource,projectPathInfo.componentRootFolder))){return}if(!this._fsUtils.pathExistsSync(precompileCache)){this._debug(`VComponents: precompileCache not created - ${precompileCache}`)}else{this._getVComponentJson(precompileCache)}}};Components.prototype._getVComponentJson=function(jsonDir){var contents;if(contents=this._fsUtils.readDirSync(jsonDir)){let json;this._VFilesInspected=[];this._VTypes={};contents.forEach(file=>{if(file.isFile){json=this._fsUtils.readJsonSync(this._nd.path.join(jsonDir,file.name),false,false);if(typeof json==="string"){this._error(`Compiled metadata for x - ${json}`)}else{if(this._isDebug){this._debug(`Post compilation VComponent found : ${json.name}`)}this.processComponentJson(json,this._getVCompFolder(json.name),true)}}});this._VFilesInspected=null}};Components.prototype._getVCompFolder=function(name){var files,file,folder,ret=null,x,_self=this;const preComp=this._tsUtils.getPreCompiler();const srcFiles=preComp.getVFiles();if(srcFiles){for(file of srcFiles){if(this._VFilesInspected.includes(file)){continue}let src,VType;function _fail(errMsg){_self._warn(`Unexpected read error of '${file}'`)}if(!(src=this._fsUtils.readFileSync(file,_fail))){continue}if(!(VType=this._isVCompSrc(src,name))){continue}this._VFilesInspected.push(file);this._VTypes[name]=VType;ret=this._nd.path.dirname(file);break}}return ret};Components.prototype._isVCompSrc=function(src,name){var ret,start=0,utils=this._utils;function _extractCompName(data,x,closeDelim){let x2,comp,match=false;if((x=utils.eatWhitespace(data,x))>=0){if(data.charAt(x)==="("){if((x=utils.eatWhitespace(data,x+1))>=0){if((x2=data.indexOf(closeDelim,x))>=0){comp=data.substring(x,x2).trim();comp=comp.substring(1,comp.length-1);match=comp===name}}}}return match}while(start<src.length){let i;if((i=src.indexOf(CUSTOM_ELEMENT,start))>=0){start=i+=CUSTOM_ELEMENT.length;if(ret=_extractCompName(src,i,")")){return"class"}continue}else if((i=src.indexOf(REGISTER_CUSTOM_ELEMENT,start))>=0){start=i+=REGISTER_CUSTOM_ELEMENT.length;if(ret=_extractCompName(src,i,",")){return"func"}continue}break}return null};Components.prototype._createStyleLookup=function(){var tag,o,scl,st;for(tag in this._tagLookup){o=this._tagLookup[tag];if(scl=o.styleClasses){for(st in scl){this._styleLookup[st]=tag}}}};Components.prototype._readComponentJson=function(inFile){var obj=null;if(this._isDebug){this._debug(` loading '${inFile}'`)}obj=this._nd.jsonLoader.load(inFile,this._nd,this._error,false,this._utils);if(!obj){this._isOk=false}return obj};Components.prototype._isComponentJsonPath=function(filePath){return filePath.toLowerCase().endsWith(COMPONENT_JSON)};Components.prototype.dumpComponentNames=function(){var names,keys;this._dumpComponentNames(this._tagLookup,"--------- Declared Web Components ---------","No valid user (non-VComponent) components declared!","-------- End Declared Web Components ---------");this._dumpComponentNames(this._VCompLookup,"--------- Discovered VComponents ---------","No VComponents found!","-------- End Discovered VComponents ---------");this._dumpComponentNames(this._jetTagLookup,"--------- Declared JET OJ-C Pack Web Components ---------","No valid user JET Core Pack components declared!","-------- End Declared OJ-C Pack Web Components ---------")};Components.prototype._dumpComponentNames=function(lookup,start,none,end){var keys,meta,impls;const INFO="[info]";keys=Object.keys(lookup);if(!keys.length){this._console(`${INFO} ${none}\n`,"I");return}this._console(`${INFO} ${start}`,"I");keys.forEach(key=>{meta=lookup[key];this._console(`${INFO} ${key} (${meta.version})`,"I");impls=meta.implements&&meta.implements.length?meta.implements.join(", "):"none declared";this._console(`${INFO} Impls: ${impls}`)});this._console(`${INFO} ${end}\n`,"I")};function _isTagStatusType(statType){return type===SUPERSEDES||type===MAINTENANCE||type===DEPRECATED||type===ANTIPATTERN};function _propToKebabCase(str){return str.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/([A-Z])([A-Z])(?=[a-z])/g,"$1-$2").toLowerCase()};function _propToCamelCase(str){var parts,i;function _camelCase(str){return str.replace(/(?:^\w|[A-Z]|\b\w)/g,function(word,index){return index==0?word.toLowerCase():word.toUpperCase()}).replace(/-|\s+/g,"")};parts=str.split(DOT);for(i=0;i<parts.length;i++){parts[i]=_camelCase(parts[i])}return parts.join(DOT)};function _isRelativeUrl(url){url=url.toLowerCase();return!(url.indexOf("http://")===0||url.indexOf("https://")===0)};function _removeChevrons(tagName){if(tagName){let len=tagName.length-1;let start=tagName.charAt(0)==="<"?1:0;let end=tagName.charAt(len)===">"?len:++len;tagName=tagName.substring(start,end)}return tagName};module.exports=Components;
package/lib/DomUtils.js CHANGED
@@ -3,4 +3,4 @@
3
3
  * Licensed under The Universal Permissive License (UPL), Version 1.0
4
4
  * as shown at https://oss.oracle.com/licenses/upl/
5
5
  */
6
- const jsonParser=require("really-relaxed-json").createParser();const HtmlUtils=require("./HtmlUtils");const NodeType=require("./NodeTypes");const OJCOMPONENT="ojComponent";const COMPONENT="component";const DOT=".";const ON_DASH="on-";function DomUtils(nodeDeps,appContext,oTabs,fileIndex){this._tree=null;this._nodeDeps=nodeDeps;this._appContext=appContext;this._tabs=oTabs;this._utils=appContext.utils;this._fileIndex=fileIndex};DomUtils.prototype.getFirst=function(){return this._tree.length?this._tree[0]:null};DomUtils.prototype.getLast=function(){var node;node=this._tree.length?this._tree[this._tree.length-1]:null;while(node&&node.children&&node.children.length){node=node.children[node.children.length-1]}return node};DomUtils.prototype.getFirstElem=function(){var node=this.getFirst();while(node){if(node.type===NodeType.TAG){break};node=node.next}return node};DomUtils.prototype.getChildren=function(node){return node.children};DomUtils.prototype.getParent=function(node){return node.parent};DomUtils.prototype.getSiblings=function(node){var parent;if(parent=this.getParent(node)){return this.getChildren(parent)}else{return this._tree}};DomUtils.prototype.getNext=function(node){return node.next||null};DomUtils.prototype.getAttribs=function(node){return node.attribs||null};DomUtils.prototype.getAttribValue=function(node,name){return node.attribs?node.attribs[name]:undefined};DomUtils.prototype.getAttribRawValue=function(ruleCtx,name){var val,pos;if(ruleCtx.tagNode.attribs){if(typeof(val=ruleCtx.tagNode.attribs[name])==="string"){pos=this.getAttrPosition(ruleCtx.data,ruleCtx.tagNode,name);return _getAttrRawValue(ruleCtx.data,pos.start,name,val,ruleCtx.utils.utils)}}};DomUtils.prototype.hasAttrib=function(node,name){return!!node.attribs&&hasOwnProperty.call(node.attribs,name)};DomUtils.prototype.hasChildren=function(node){return!!node.children?.length};DomUtils.prototype.hasNext=function(node){return!!node.next};DomUtils.prototype.getName=function(node){return node.name};DomUtils.prototype.getType=function(node){return node.type};DomUtils.prototype.getElemsByName=function(name){var a=[],i,names;if(!this._tree){return a}names=typeof name==="string"?[name]:name;for(i=0;i<names.length;i++){names[i]=names[i].toLowerCase()}for(i=0;i<this._tree.length;i++){_getElemsByName2(this._tree[i],a,names)}return a};function _getElemsByName2(node,a,names){var children,i;if((node.type===NodeType.TAG||node.type===NodeType.SCRIPT)&&names.indexOf(node.name.toLowerCase())>=0){a.push(node)}if(node.children){children=node.children;for(i=0;i<children.length;i++){_getElemsByName2(children[i],a,names)}}};DomUtils.prototype.getElemById=function(id,labelId){var node,i;if(!this._tree){return null}for(i=0;i<this._tree.length;i++){node=this._tree[i];if(node.type===NodeType.TAG||_isHtmlScript(node)){node=this._getElemById2(node,id,labelId);if(node){return node}}}return null};DomUtils.prototype._getElemById2=function(node,id,labelId){var curNode,attrib,attr,attribLower,i;if((node.type===NodeType.TAG||_isHtmlScript(node))&&node.attribs){for(attrib in node.attribs){attribLower=attrib.toLowerCase();if(attribLower==="id"||labelId&&attribLower==="label-id"){if(node.attribs[attrib]===id){return node}}else if(attrib==="data-bind"){attr=this.extractAttribsFromDataBind(node.attribs[attrib]);if(attr&&attr["id"]===id){return node}}}}if(node.children){for(i=0;i<node.children.length;i++){curNode=this._getElemById2(node.children[i],id,labelId);if(curNode){return curNode}}}return null};DomUtils.prototype.getElems=function(){var a=[],i;if(!this._tree){return a}for(i=0;i<this._tree.length;i++){_getElems2(this._tree[i],a)}return a};function _getElems2(node,a){var children,i;if(node.type===NodeType.TAG||node.type===NodeType.SCRIPT){a.push(node)}if(node.children){children=node.children;for(i=0;i<children.length;i++){_getElems2(children[i],a)}}};DomUtils.prototype.getScripts=function(){var head,ch,a=[];if(head=this.getHead()){if(ch=head.children){ch.forEach(elem=>{if(elem.type===NodeType.TAG&&elem.name==="script"){a.push(elem)}})}}return a};DomUtils.prototype.getLinks=function(){var head,ch,a=[];if(head=this.getHead()){if(ch=head.children){ch.forEach(elem=>{if(elem.type===NodeType.TAG&&elem.name==="link"){a.push(elem)}})}}return a};DomUtils.prototype.getHead=function(){var elem,ch,i;if(!this._tree){return null}for(i=0;i<this._tree.length;i++){elem=this._tree[i];if(elem.type===NodeType.TAG&&elem.name==="html"){if(ch=elem.children){for(i=0;i<ch.length;i++){elem=ch[i];if(elem.type===NodeType.TAG&&elem.name==="head"){return elem}}}break}}return null};DomUtils.prototype.getBody=function(){var elem,ch,i;if(!this._tree){return null}for(i=0;i<this._tree.length;i++){elem=this._tree[i];if(elem.type===NodeType.TAG&&elem.name==="html"){if(ch=elem.children){for(i=0;i<ch.length;i++){elem=ch[i];if(elem.type===NodeType.TAG&&elem.name==="body"){return elem}}}break}}return null};DomUtils.prototype.getComponentElems=function(){var a=[],i;if(!this._tree){return a}for(i=0;i<this._tree.length;i++){this._getComponentElems2(this._tree[i],a)}return a};DomUtils.prototype._getComponentElems2=function(node,a){var children,i;if(node.type===NodeType.TAG&&this._appContext.metaLib.isWCTag(node.name)){a.push(node)}if(node.children){children=node.children;for(i=0;i<children.length;i++){this._getComponentElems2(children[i],a)}}};DomUtils.prototype.isCommonAttr=function(attrName){attrName=attrName.toLowerCase();attrName=attrName.charAt(0)===":"?attrName.substring(1):attrName;return HtmlUtils.isCommonAttr(attrName)};DomUtils.prototype.isCommonEventAttr=function(attrName){attrName=attrName.toLowerCase();attrName=attrName.charAt(0)===":"?attrName.substr(1):attrName;if(attrName.startsWith("on-oj-")){return false}if(attrName.startsWith("on-")){attrName=attrName.substring(0,2)+attrName.substring(3)}return HtmlUtils.isCommonEventAttr(attrName)};DomUtils.prototype.isCommonElem=function(elem){return HtmlUtils.isCommonElem(elem)};DomUtils.prototype.isSvgElem=function(elem){return HtmlUtils.isSvgElem(elem)};DomUtils.prototype.isHtml5ObsoleteElem=function(tag){return HtmlUtils.isHtml5ObsoleteElem(tag)};DomUtils.prototype.isHtml5ObsoleteAttr=function(tagName,attrName){return HtmlUtils.isHtml5ObsoleteAttr(tagName,attrName)};DomUtils.prototype.isSelfClosingTag=function(tag){return HtmlUtils.isSelfClosingTag(tag)};DomUtils.prototype.isNamespaceTag=function(tagName){if(this._appContext.metaLib.isJetTag(tagName)){return true}return HtmlUtils.isNamespaceTag(tagName)};DomUtils.prototype.isNamespacePrefix=function(tagPrefix){return!!HtmlUtils.isNamespacePrefix(tagPrefix)};DomUtils.prototype.isChildOfElem=function(elemName,node){return!!this.isChildOfElemNode(elemName,node)};DomUtils.prototype.isChildOfElemNode=function(elemName,node){var ret=null;while(node.parent){if(node.parent.name===elemName){ret=node.parent;break}node=node.parent}return ret};DomUtils.prototype.getDataBindComponent=function(context){var node,val,attrVal,ret=null;node=context.tagNode;if(this.getAttribs(node)){attrVal=this.getAttribValue(node,"data-bind");if(attrVal){val=this.extractComponentFromDataBind(attrVal);if(val){ret="oj."+val}}}return ret};DomUtils.prototype.getDataBindAttr=function(context){return this.getDataBindAttrsFromNode(context,context.node)};DomUtils.prototype.getDataBindAttrs=function(context){return this.getDataBindAttrsFromNode(context,context.node)};DomUtils.prototype.getDataBindAttrsFromNode=function(context,node){var attrVal,ret=null;if(this.getAttribs(node)){attrVal=this.getAttribValue(node,"data-bind");if(attrVal){ret=this.extractAttribsFromDataBind(attrVal)}}return ret};DomUtils.prototype.extractComponentFromDataBind=function(attrValue){var dataBind,componentName,x;x=attrValue.indexOf(OJCOMPONENT);if(x<0){return}componentName=null;if(attrValue.length>OJCOMPONENT.length){dataBind=attrValue.substring(x+OJCOMPONENT.length);x=dataBind.indexOf(COMPONENT);if(x>=0){dataBind=dataBind.substring(x+COMPONENT.length).trim();if(dataBind.charAt(0)===":"){x=dataBind.indexOf("oj");if(x>=0){dataBind=dataBind.substring(x);componentName=_extractComponentName(dataBind,this._utils)}}}}return componentName};function _extractComponentName(s,utils){var componentName,i,c;for(i=0;i<s.length;i++){c=s.charAt(i);if(c==="'"||c==="\""||utils.isWhitespace(c)){componentName=s.substring(0,i);break}}return componentName};DomUtils.prototype.extractAttribsFromDataBind=function(attrValue){var s,a,nextAttr,val,i,j,x,ret=null;if(attrValue.indexOf(":")<0){return ret}a=attrValue.split("attr");if(a.length<2){return ret}for(i=0;i<a.length;i++){a[i]=s=a[i].trim();if(s.charAt(0)===":"){s=s.substr(1).trim();if(s.charAt(0)==="{"){try{ret=jsonParser.stringToJson(s);ret=JSON.parse(ret)}catch(e){s=s.substring(1).trim();a=s.split(":");for(j=0;j<a.length;j++){if(nextAttr){if(!ret){ret={}}ret[nextAttr]=val=a[j].replace(/['\"]/g,"").trim();x=val.lastIndexOf("}");if(x>=0){ret[nextAttr]=val.substring(0,x).trim();break}nextAttr=null}if(j+1===a.length){break}a[j]=s=a[j].trim();s=s.replace(/['\"]/g,"").trim();if(s.length===0)continue;if(!ret){ret={}}ret[s]=val=a[++j].trim();x=val.indexOf(",");if(x>=0){ret[s]=val.substring(0,x).replace(/['\"]/g,"").trim();nextAttr=val.substring(x+1).trim();nextAttr=nextAttr.replace(/['\"]/g,"").trim();val=val.substring(0,x).replace(/['\"]/g,"").trim()}else{ret[s]=val.replace(/['\"]/g,"").trim()}x=val.lastIndexOf("}");if(x>=0){ret[s]=val.substring(0,x).trim();break}}}}break}}return ret};DomUtils.prototype.getAttribPosition=function(data,node,attrName){var startIndex=this.getAttrIndex(data,node,attrName);var endIndex=startIndex+attrName.length-1;var pos=this._utils.getRowColFromIndex(data,startIndex,"html");pos.start=startIndex;pos.end=endIndex;return pos};DomUtils.prototype.getAttrPosition=function(data,node,attrName){return this.getAttribPosition(data,node,attrName)};DomUtils.prototype.getAttribValuePosition=function(data,node,attrName){var attrPos,pos,endPos,ws,ret,good;var isDouble,isSingle,isUnquoted;attrPos=this.getAttrPosition(data,node,attrName);if(!attrPos||attrPos.start===node.startIndex){return}if((pos=this._utils.eatWhitespace(data,attrPos.end+1))>=0){if(data.charAt(pos++)==="="){if((endPos=this._utils.eatWhitespace(data,pos))>=0){isDouble=data.charAt(endPos)==="\"";isSingle=data.charAt(endPos)==="'";isUnquoted=!(isSingle||isDouble);if(isDouble){if((endPos=data.indexOf("\"",pos+1))>=0){good=true}}else if(isSingle){if((endPos=data.indexOf("'",pos+1))>=0){good=true}}else if(isUnquoted){ws=this._utils.getIndexToWhitespace(data,pos);endPos=data.indexOf(">",pos);if(ws>=0&&endPos>=0){endPos=(endPos<ws?endPos:ws)-1;good=true}}if(good){attrPos=this.getLineCol(data,pos);ret={row:attrPos.row,col:attrPos.col,start:pos,end:endPos}}}}}return ret};DomUtils.prototype.getAttrValuePosition=function(data,node,attrName){return this.getAttribValuePosition(data,node,attrName)};DomUtils.prototype.getLineCol=function(data,index){return this._fileIndex.getRowCol(data,{start:index},"html")};DomUtils.prototype.getAttribIndex=function(data,node,attrName){var attribs,index,temp,c,i,isQuote=attrName==="\""||attrName==="'";if(!(attribs=node.attribs)){this._appContext.assert("no attrs in tag "+node.name+"(expected attr '"+attrName+")");return node.startIndex}if(!attribs.hasOwnProperty(attrName)&&!attribs.hasOwnProperty(":"+attrName)){this._appContext.assert("expected attr '"+attrName+"' in tag "+node.name);return node.startIndex}index=data.indexOf(attrName,node.startIndex);while(true){index=data.indexOf(attrName,index);if(index>=0){temp=data.substring(index+attrName.length,index+100);i=this._utils.eatWhitespace(temp);if(i<0){return node.startIndex}c=temp.charAt(i);if(c==="="||c===">"||!isQuote&&this._utils.isWhitespace(temp.charAt(0))){return index}index+=i+1;continue}this._appContext.assert("expected attr '"+attrName+"' in tag "+node.name);return node.startIndex}};DomUtils.prototype.getAttrIndex=function(data,node,attrName){return this.getAttribIndex(data,node,attrName)};DomUtils.prototype.isNonFragmentJetPage=function(context){return this.hasBody(context)&&this.isJetPage(context)};DomUtils.prototype.hasBody=function(context){var i,siblings,ret=false;siblings=this.getSiblings(context.node);for(i=0;i<siblings.length;i++){if(this._hasBody2(siblings[i])){ret=true;break}}return ret};DomUtils.prototype._hasBody2=function(node){var i,children,ret=false;if(node.type===NodeType.TAG&&node.name.toLowerCase()==="body"){return true}if(node.children){children=node.children;for(i=0;i<children.length;i++){if(this._hasBody2(children[i])){ret=true;break}}}return ret};DomUtils.prototype.isJetPage=function(context){var i,siblings,ret=false;siblings=this.getSiblings(context.node);for(i=0;i<siblings.length;i++){if(this._isJetPage2(siblings[i])){ret=true;break}}return ret};DomUtils.prototype._isJetPage2=function(node){var i,children,ret=false;if(node.type===NodeType.TAG&&node.name.toLowerCase().startsWith("oj-")){return true}if(node.children){children=node.children;for(i=0;i<children.length;i++){if(this._isJetPage2(children[i])){ret=true;break}}}return ret};DomUtils.prototype.isValidJson=function(value,data){var data,ret;if(value.charAt(0)!=="{"){return true}try{data=JSON.parse(this._nodeDeps.decomment(value));ret=!!data}catch(e){if(typeof data==="string"&&e.toString().startsWith("SyntaxError")){var obj=_convertMsgToRowCol(e.message,data,this._utils);ret.msg=obj.msg;ret.line=obj.row;ret.col=obj.col;ret.position=obj.position}else{ret=e.message}}return ret};DomUtils.prototype.isAttrExprConstant=function(expr){return HtmlUtils.isAttrExprConstant(expr)};DomUtils.prototype.isExpression=function(s){var sq,ret=false;if(s&&(s=s.trim())){if((sq=s.startsWith("[["))||s.startsWith("{{")){ret=sq?s.endsWith("]]"):s.endsWith("}}")}}return ret};DomUtils.prototype.getExpression=function(s){var ret=null;if(this.isExpression(s)){ret=s.trim().substring(2,s.length-2).trim()}return ret};DomUtils.prototype.isSvgPath=function(s){return HtmlUtils.isSvgPath(s)};DomUtils.prototype.camelCase=function(str){var parts,i;function _camelCase(str){return str.replace(/(?:^\w|[A-Z]|\b\w)/g,function(word,index){return index==0?word.toLowerCase():word.toUpperCase()}).replace(/-|\s+/g,"")};parts=str.split(DOT);for(i=0;i<parts.length;i++){parts[i]=_camelCase(parts[i])}return parts.join(DOT)};DomUtils.prototype.kebabCase=function(str){return str.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/([A-Z])([A-Z])(?=[a-z])/g,"$1-$2").toLowerCase()};DomUtils.prototype.kekabCaseEvent=function(str){return ON_DASH+this.kebabCase(str)};function _isHtmlScript(node){var attribs=node.attribs;return node.type&&node.type===NodeType.SCRIPT&&attribs&&attribs.type&&attribs.type.indexOf("html")>=0};function _convertMsgToRowCol(msg,data,utils){var x,n,obj;x=msg.indexOf("position");if(x<0){return null}n=parseInt(msg.substr(x+8).trim());obj=utils.getRowColFromIndex(data,n);obj.msg=msg.substr(0,x)+"line "+obj.row+", col "+obj.col+" (position "+n+")";obj.position=n;return obj};function _getAttrRawValue(data,index,attrName,attrValue,utils){var ret=null,delim,i;i=index+attrName.length;if(data.charAt(i)==="="){i=utils.eatWhitespace(data,i+1);delim=data.substr(i,1);delim=delim==="'"||delim==="\""?delim:"\"";ret=delim+attrValue+data.charAt(i+attrValue.length+1)}else{ret=attrValue}return ret};DomUtils.prototype.setDom=function(oDom){this._tree=oDom};module.exports=DomUtils;
6
+ const jsonParser=require("really-relaxed-json").createParser();const HtmlUtils=require("./HtmlUtils");const NodeType=require("./NodeTypes");const OJCOMPONENT="ojComponent";const COMPONENT="component";const DOT=".";const ON_DASH="on-";function DomUtils(nodeDeps,appContext,oTabs,fileIndex){this._tree=null;this._nodeDeps=nodeDeps;this._appContext=appContext;this._tabs=oTabs;this._utils=appContext.utils;this._fileIndex=fileIndex};DomUtils.prototype.getFirst=function(){return this._tree.length?this._tree[0]:null};DomUtils.prototype.getLast=function(){var node;node=this._tree.length?this._tree[this._tree.length-1]:null;while(node&&node.children&&node.children.length){node=node.children[node.children.length-1]}return node};DomUtils.prototype.getFirstElem=function(){var node=this.getFirst();while(node){if(node.type===NodeType.TAG){break};node=node.next}return node};DomUtils.prototype.getChildren=function(node){return node.children};DomUtils.prototype.getParent=function(node){return node.parent};DomUtils.prototype.getSiblings=function(node){var parent;if(parent=this.getParent(node)){return this.getChildren(parent)}else{return this._tree}};DomUtils.prototype.getNext=function(node){return node.next||null};DomUtils.prototype.getAttribs=function(node){return node.attribs||null};DomUtils.prototype.getAttribValue=function(node,name){return node.attribs?node.attribs[name]:undefined};DomUtils.prototype.getAttribRawValue=function(ruleCtx,name){var val,pos;if(ruleCtx.tagNode.attribs){if(typeof(val=ruleCtx.tagNode.attribs[name])==="string"){pos=this.getAttrPosition(ruleCtx.data,ruleCtx.tagNode,name);return _getAttrRawValue(ruleCtx.data,pos.start,name,val,ruleCtx.utils.utils)}}};DomUtils.prototype.hasAttrib=function(node,name){return!!node.attribs&&hasOwnProperty.call(node.attribs,name)};DomUtils.prototype.hasChildren=function(node){return!!node.children?.length};DomUtils.prototype.hasNext=function(node){return!!node.next};DomUtils.prototype.getName=function(node){return node.name};DomUtils.prototype.getType=function(node){return node.type};DomUtils.prototype.getElemsByName=function(name){var a=[],i,names;if(!this._tree){return a}names=typeof name==="string"?[name]:name;for(i=0;i<names.length;i++){names[i]=names[i].toLowerCase()}for(i=0;i<this._tree.length;i++){_getElemsByName2(this._tree[i],a,names)}return a};function _getElemsByName2(node,a,names){var children,i;if((node.type===NodeType.TAG||node.type===NodeType.SCRIPT)&&names.indexOf(node.name.toLowerCase())>=0){a.push(node)}if(node.children){children=node.children;for(i=0;i<children.length;i++){_getElemsByName2(children[i],a,names)}}};DomUtils.prototype.getElemById=function(id,labelId){var node,i;if(!this._tree){return null}for(i=0;i<this._tree.length;i++){node=this._tree[i];if(node.type===NodeType.TAG||_isHtmlScript(node)){node=this._getElemById2(node,id,labelId);if(node){return node}}}return null};DomUtils.prototype._getElemById2=function(node,id,labelId){var curNode,attrib,attr,attribLower,i;if((node.type===NodeType.TAG||_isHtmlScript(node))&&node.attribs){for(attrib in node.attribs){attribLower=attrib.toLowerCase();if(attribLower==="id"||labelId&&attribLower==="label-id"){if(node.attribs[attrib]===id){return node}}else if(attrib==="data-bind"){attr=this.extractAttribsFromDataBind(node.attribs[attrib]);if(attr&&attr["id"]===id){return node}}}}if(node.children){for(i=0;i<node.children.length;i++){curNode=this._getElemById2(node.children[i],id,labelId);if(curNode){return curNode}}}return null};DomUtils.prototype.getElems=function(){var a=[],i;if(!this._tree){return a}for(i=0;i<this._tree.length;i++){_getElems2(this._tree[i],a)}return a};function _getElems2(node,a){var children,i;if(node.type===NodeType.TAG||node.type===NodeType.SCRIPT){a.push(node)}if(node.children){children=node.children;for(i=0;i<children.length;i++){_getElems2(children[i],a)}}};DomUtils.prototype.getScripts=function(){var head,ch,a=[];if(head=this.getHead()){if(ch=head.children){ch.forEach(elem=>{if(elem.type===NodeType.TAG&&elem.name==="script"){a.push(elem)}})}}return a};DomUtils.prototype.getLinks=function(){var head,ch,a=[];if(head=this.getHead()){if(ch=head.children){ch.forEach(elem=>{if(elem.type===NodeType.TAG&&elem.name==="link"){a.push(elem)}})}}return a};DomUtils.prototype.getHead=function(){var elem,ch,i;if(!this._tree){return null}for(i=0;i<this._tree.length;i++){elem=this._tree[i];if(elem.type===NodeType.TAG&&elem.name==="html"){if(ch=elem.children){for(i=0;i<ch.length;i++){elem=ch[i];if(elem.type===NodeType.TAG&&elem.name==="head"){return elem}}}break}}return null};DomUtils.prototype.getBody=function(){var elem,ch,i;if(!this._tree){return null}for(i=0;i<this._tree.length;i++){elem=this._tree[i];if(elem.type===NodeType.TAG&&elem.name==="html"){if(ch=elem.children){for(i=0;i<ch.length;i++){elem=ch[i];if(elem.type===NodeType.TAG&&elem.name==="body"){return elem}}}break}}return null};DomUtils.prototype.getComponentElems=function(){var a=[],i;if(!this._tree){return a}for(i=0;i<this._tree.length;i++){this._getComponentElems2(this._tree[i],a)}return a};DomUtils.prototype._getComponentElems2=function(node,a){var children,i;if(node.type===NodeType.TAG&&this._appContext.metaLib.isWCTag(node.name)){a.push(node)}if(node.children){children=node.children;for(i=0;i<children.length;i++){this._getComponentElems2(children[i],a)}}};DomUtils.prototype.isCommonAttr=function(attrName){attrName=attrName.toLowerCase();attrName=attrName.charAt(0)===":"?attrName.substring(1):attrName;return HtmlUtils.isCommonAttr(attrName)};DomUtils.prototype.isCommonEventAttr=function(attrName){attrName=attrName.toLowerCase();attrName=attrName.charAt(0)===":"?attrName.substr(1):attrName;if(attrName.startsWith("on-oj-")){return false}if(attrName.startsWith("on-")){attrName=attrName.substring(0,2)+attrName.substring(3)}return HtmlUtils.isCommonEventAttr(attrName)};DomUtils.prototype.isCommonElem=function(elem){return HtmlUtils.isCommonElem(elem)};DomUtils.prototype.isSvgElem=function(elem){return HtmlUtils.isSvgElem(elem)};DomUtils.prototype.isHtml5ObsoleteElem=function(tag){return HtmlUtils.isHtml5ObsoleteElem(tag)};DomUtils.prototype.isHtml5ObsoleteAttr=function(tagName,attrName){return HtmlUtils.isHtml5ObsoleteAttr(tagName,attrName)};DomUtils.prototype.isSelfClosingTag=function(tag){return HtmlUtils.isSelfClosingTag(tag)};DomUtils.prototype.isNamespaceTag=function(tagName){if(this._appContext.metaLib.isJetTag(tagName)){return true}return HtmlUtils.isNamespaceTag(tagName)};DomUtils.prototype.isNamespacePrefix=function(tagPrefix){return!!HtmlUtils.isNamespacePrefix(tagPrefix)};DomUtils.prototype.isChildOfElem=function(elemName,node){return!!this.isChildOfElemNode(elemName,node)};DomUtils.prototype.isChildOfElemNode=function(elemName,node){var ret=null;while(node.parent){if(node.parent.name===elemName){ret=node.parent;break}node=node.parent}return ret};DomUtils.prototype.getDataBindComponent=function(context){var node,val,attrVal,ret=null;node=context.tagNode;if(this.getAttribs(node)){attrVal=this.getAttribValue(node,"data-bind");if(attrVal){val=this.extractComponentFromDataBind(attrVal);if(val){ret="oj."+val}}}return ret};DomUtils.prototype.getDataBindAttr=function(context){return this.getDataBindAttrsFromNode(context,context.node)};DomUtils.prototype.getDataBindAttrs=function(context){return this.getDataBindAttrsFromNode(context,context.node)};DomUtils.prototype.getDataBindAttrsFromNode=function(context,node){var attrVal,ret=null;if(this.getAttribs(node)){attrVal=this.getAttribValue(node,"data-bind");if(attrVal){ret=this.extractAttribsFromDataBind(attrVal)}}return ret};DomUtils.prototype.extractComponentFromDataBind=function(attrValue){var dataBind,componentName,x;x=attrValue.indexOf(OJCOMPONENT);if(x<0){return}componentName=null;if(attrValue.length>OJCOMPONENT.length){dataBind=attrValue.substring(x+OJCOMPONENT.length);x=dataBind.indexOf(COMPONENT);if(x>=0){dataBind=dataBind.substring(x+COMPONENT.length).trim();if(dataBind.charAt(0)===":"){x=dataBind.indexOf("oj");if(x>=0){dataBind=dataBind.substring(x);componentName=_extractComponentName(dataBind,this._utils)}}}}return componentName};function _extractComponentName(s,utils){var componentName,i,c;for(i=0;i<s.length;i++){c=s.charAt(i);if(c==="'"||c==="\""||utils.isWhitespace(c)){componentName=s.substring(0,i);break}}return componentName};DomUtils.prototype.extractAttribsFromDataBind=function(attrValue){var s,a,nextAttr,val,i,j,x,ret=null;if(attrValue.indexOf(":")<0){return ret}a=attrValue.split("attr");if(a.length<2){return ret}for(i=0;i<a.length;i++){a[i]=s=a[i].trim();if(s.charAt(0)===":"){s=s.substr(1).trim();if(s.charAt(0)==="{"){try{ret=jsonParser.stringToJson(s);ret=JSON.parse(ret)}catch(e){s=s.substring(1).trim();a=s.split(":");for(j=0;j<a.length;j++){if(nextAttr){if(!ret){ret={}}ret[nextAttr]=val=a[j].replace(/['\"]/g,"").trim();x=val.lastIndexOf("}");if(x>=0){ret[nextAttr]=val.substring(0,x).trim();break}nextAttr=null}if(j+1===a.length){break}a[j]=s=a[j].trim();s=s.replace(/['\"]/g,"").trim();if(s.length===0)continue;if(!ret){ret={}}ret[s]=val=a[++j].trim();x=val.indexOf(",");if(x>=0){ret[s]=val.substring(0,x).replace(/['\"]/g,"").trim();nextAttr=val.substring(x+1).trim();nextAttr=nextAttr.replace(/['\"]/g,"").trim();val=val.substring(0,x).replace(/['\"]/g,"").trim()}else{ret[s]=val.replace(/['\"]/g,"").trim()}x=val.lastIndexOf("}");if(x>=0){ret[s]=val.substring(0,x).trim();break}}}}break}}return ret};DomUtils.prototype.getAttribPosition=function(data,node,attrName){var startIndex=this.getAttrIndex(data,node,attrName);var endIndex=startIndex+attrName.length-1;var pos=this._utils.getRowColFromIndex(data,startIndex,"html");pos.start=startIndex;pos.end=endIndex;return pos};DomUtils.prototype.getAttrPosition=function(data,node,attrName){return this.getAttribPosition(data,node,attrName)};DomUtils.prototype.getAttribValuePosition=function(data,node,attrName){var attrPos,pos,endPos,ws,ret,good;var isDouble,isSingle,isUnquoted;attrPos=this.getAttrPosition(data,node,attrName);if(!attrPos||attrPos.start===node.startIndex){return}if((pos=this._utils.eatWhitespace(data,attrPos.end+1))>=0){if(data.charAt(pos++)==="="){if((endPos=this._utils.eatWhitespace(data,pos))>=0){isDouble=data.charAt(endPos)==="\"";isSingle=data.charAt(endPos)==="'";isUnquoted=!(isSingle||isDouble);if(isDouble){if((endPos=data.indexOf("\"",pos+1))>=0){good=true}}else if(isSingle){if((endPos=data.indexOf("'",pos+1))>=0){good=true}}else if(isUnquoted){ws=this._utils.getIndexToWhitespace(data,pos);endPos=data.indexOf(">",pos);if(ws>=0&&endPos>=0){endPos=(endPos<ws?endPos:ws)-1;good=true}}if(good){attrPos=this.getLineCol(data,pos);ret={row:attrPos.row,col:attrPos.col,start:pos,end:endPos}}}}}return ret};DomUtils.prototype.getAttrValuePosition=function(data,node,attrName){return this.getAttribValuePosition(data,node,attrName)};DomUtils.prototype.getLineCol=function(data,index){return this._fileIndex.getRowCol(data,{start:index},"html")};DomUtils.prototype.getAttribIndex=function(data,node,attrName){var attribs,index,temp,c,i,isQuote=attrName==="\""||attrName==="'";if(!(attribs=node.attribs)){this._appContext.assert(`data indexing: no attrs in tag <${node.name}> (expected attr '${attrName}'`);return node.startIndex}if(!attribs.hasOwnProperty(attrName)&&!attribs.hasOwnProperty(":"+attrName)){this._appContext.assert("data indexing: "+(attrName&&attrName.length?`expected attr '${attrName}' in tag <${node.name}>`:`no attrib name specified for tag <${node.name}>`));return node.startIndex}index=data.indexOf(attrName,node.startIndex);while(true){index=data.indexOf(attrName,index);if(index>=0){temp=data.substring(index+attrName.length,index+100);i=this._utils.eatWhitespace(temp);if(i<0){return node.startIndex}c=temp.charAt(i);if(c==="="||c===">"||!isQuote&&this._utils.isWhitespace(temp.charAt(0))){return index}index+=i+1;continue}this._appContext.assert(`data indexing: expected attr '${attrName}' in tag <${node.name}>`);return node.startIndex}};DomUtils.prototype.getAttrIndex=function(data,node,attrName){return this.getAttribIndex(data,node,attrName)};DomUtils.prototype.isNonFragmentJetPage=function(context){return this.hasBody(context)&&this.isJetPage(context)};DomUtils.prototype.hasBody=function(context){var i,siblings,ret=false;siblings=this.getSiblings(context.node);for(i=0;i<siblings.length;i++){if(this._hasBody2(siblings[i])){ret=true;break}}return ret};DomUtils.prototype._hasBody2=function(node){var i,children,ret=false;if(node.type===NodeType.TAG&&node.name.toLowerCase()==="body"){return true}if(node.children){children=node.children;for(i=0;i<children.length;i++){if(this._hasBody2(children[i])){ret=true;break}}}return ret};DomUtils.prototype.isJetPage=function(context){var i,siblings,ret=false;siblings=this.getSiblings(context.node);for(i=0;i<siblings.length;i++){if(this._isJetPage2(siblings[i])){ret=true;break}}return ret};DomUtils.prototype._isJetPage2=function(node){var i,children,ret=false;if(node.type===NodeType.TAG&&node.name.toLowerCase().startsWith("oj-")){return true}if(node.children){children=node.children;for(i=0;i<children.length;i++){if(this._isJetPage2(children[i])){ret=true;break}}}return ret};DomUtils.prototype.isValidJson=function(value,data){var data,ret;if(value.charAt(0)!=="{"){return true}try{data=JSON.parse(this._nodeDeps.decomment(value));ret=!!data}catch(e){if(typeof data==="string"&&e.toString().startsWith("SyntaxError")){var obj=_convertMsgToRowCol(e.message,data,this._utils);ret.msg=obj.msg;ret.line=obj.row;ret.col=obj.col;ret.position=obj.position}else{ret=e.message}}return ret};DomUtils.prototype.isAttrExprConstant=function(expr){return HtmlUtils.isAttrExprConstant(expr)};DomUtils.prototype.isExpression=function(s){var sq,ret=false;if(s&&(s=s.trim())){if((sq=s.startsWith("[["))||s.startsWith("{{")){ret=sq?s.endsWith("]]"):s.endsWith("}}")}}return ret};DomUtils.prototype.getExpression=function(s){var ret=null;if(this.isExpression(s)){ret=s.trim().substring(2,s.length-2).trim()}return ret};DomUtils.prototype.isSvgPath=function(s){return HtmlUtils.isSvgPath(s)};DomUtils.prototype.camelCase=function(str){var parts,i;function _camelCase(str){return str.replace(/(?:^\w|[A-Z]|\b\w)/g,function(word,index){return index==0?word.toLowerCase():word.toUpperCase()}).replace(/-|\s+/g,"")};parts=str.split(DOT);for(i=0;i<parts.length;i++){parts[i]=_camelCase(parts[i])}return parts.join(DOT)};DomUtils.prototype.kebabCase=function(str){return str.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/([A-Z])([A-Z])(?=[a-z])/g,"$1-$2").toLowerCase()};DomUtils.prototype.kekabCaseEvent=function(str){return ON_DASH+this.kebabCase(str)};function _isHtmlScript(node){var attribs=node.attribs;return node.type&&node.type===NodeType.SCRIPT&&attribs&&attribs.type&&attribs.type.indexOf("html")>=0};function _convertMsgToRowCol(msg,data,utils){var x,n,obj;x=msg.indexOf("position");if(x<0){return null}n=parseInt(msg.substr(x+8).trim());obj=utils.getRowColFromIndex(data,n);obj.msg=msg.substr(0,x)+"line "+obj.row+", col "+obj.col+" (position "+n+")";obj.position=n;return obj};function _getAttrRawValue(data,index,attrName,attrValue,utils){var ret=null,delim,i;i=index+attrName.length;if(data.charAt(i)==="="){i=utils.eatWhitespace(data,i+1);delim=data.substr(i,1);delim=delim==="'"||delim==="\""?delim:"\"";ret=delim+attrValue+data.charAt(i+attrValue.length+1)}else{ret=attrValue}return ret};DomUtils.prototype.setDom=function(oDom){this._tree=oDom};module.exports=DomUtils;
package/lib/FsUtils.js CHANGED
@@ -3,4 +3,4 @@
3
3
  * Licensed under The Universal Permissive License (UPL), Version 1.0
4
4
  * as shown at https://oss.oracle.com/licenses/upl/
5
5
  */
6
- const tmpFile=require("tmp");function FSU(nd,utils){this._nd=nd;this._utils=utils};FSU.prototype.getFileType=function(path){var stats,ret;try{stats=this._nd.fs.statSync(path);if(stats.isFile()){ret="f"}else if(stats.isDirectory()){ret="d"}}catch(e){ret=e}return ret};FSU.prototype.getFileTypeSync=function(path){return this.getFileType(path)};FSU.prototype.getFileTypeWithMsg=function(path){var ret;ret=this.getFileType(path);if(ret!=="f"&&ret!=="d"){if(ret.message.startsWith("ENOENT:")){console.log("\n** File \""+path+"\" not found")}else{console("\n** File \""+path+"\" error.\n"+" "+ret.message+".\n")}ret="?"}return ret};FSU.prototype.getFileTypeWithMsgSync=function(path){return this.getFileTypeWithMsg(path)};FSU.prototype.getFileExt=function(path){var s;try{if(!this.isSymLink(path)){s=this._nd.path.extname(path)}else{let p=this._nd.fs.readlinkSync(path);if(p){s=this._nd.path.extname(p)}}if(s&&s.charAt(0)==="."){s=s.substring(1)}return s}catch(e){}return""};FSU.prototype.getFileExtSync=function(path){return this.getFileExt(path)};FSU.prototype.isSymLink=function(path){var stats;try{stats=this._nd.fs.lstatSync(path);return stats.isSymbolicLink()}catch(e){}return false};FSU.prototype.fileExists=function(filepath,dir){var stats,ret=false;try{stats=this._nd.fs.lstatSync(filepath);ret=dir?stats.isDirectory():stats.isFile()}catch(e){}return ret};FSU.prototype.fileExistsSync=function(filepath,dir){return this.fileExists(filepath,dir)};FSU.prototype.pathExistsSync=function(filepath){try{return this._nd.fs.existsSync(filepath)}catch(e){}return false};FSU.prototype.readDir=function(path){var ret=[];try{this._readDir(path,ret)}catch(e){ret=null}return ret};FSU.prototype.readDirSync=function(path){return this.readDir(path)};FSU.prototype._readDir=function(dir,ar){var files,file,filePath,stat,arDir,i;files=this._nd.fs.readdirSync(dir);for(i=0;i<files.length;i++){file=files[i];if(file[0]==="."){continue}filePath=this._nd.path.join(dir,file);stat=this._nd.fs.statSync(filePath);if(stat.isFile()){ar.push({name:file,isFile:true})}else if(stat.isDirectory()){arDir=[];ar.push({name:file,isFile:false,files:arDir});this._readDir(filePath,arDir)}}};FSU.prototype.createFolder=function(dirPath,orig){var rc;dirPath=this._nd.path.resolve(dirPath);if(!orig){orig=dirPath}try{if(!this._nd.fs.statSync(dirPath).isDirectory()){return new Error(dirPath+" exists but is not a directory")}}catch(err){if(err.code==="ENOENT"){var np=this._nd.path.dirname(dirPath);if(np===dirPath){return new Error(orig+" cannot be created")}rc=this.createFolder(np,orig);if(typeof rc!=="boolean"){return rc}this._nd.fs.mkdirSync(dirPath);if(dirPath===orig){return true}}else{return err}}return true};FSU.prototype.createFolderSync=function(dirPath){return this.createFolder(dirPath)};FSU.prototype.deleteFolder=function(filepath,deleteTarget){if(this._nd.fs.existsSync(filepath)){this._nd.fs.readdirSync(filepath).forEach(function(file){var curPath=this._nd.path.join(filepath,file);if(this._nd.fs.lstatSync(curPath).isDirectory()){this.deleteFolder(curPath,true)}else{this._nd.fs.unlinkSync(curPath)}},this);if(deleteTarget){this._nd.fs.rmdirSync(filepath)}}};FSU.prototype.deleteFolderSync=function(filepath,deleteTarget){return this.deleteFolder(filepath,deleteTarget)};FSU.prototype.getUniqueFileNameSync=function(template,targetFolder){const opts={template:template};if(targetFolder){opts.dir=targetFolder}return tmpFile.tmpNameSync(opts)};FSU.prototype.getUniqueFileName=function(template,targetFolder){return this.getUniqueFileNameSync(template,targetFolder)};FSU.prototype.findFile=function(dir,name,fncb){var ret;try{ret=this._findFile(dir,name,fncb)}catch(e){}return ret};FSU.prototype._findFile=function(dir,name,fncb){var files,file,filePath,stat,ret,i;files=this._nd.fs.readdirSync(dir);for(i=0;i<files.length;i++){file=files[i];if(!fncb||fncb(dir,file)){if(file===name){return dir}}if(file[0]==="."){continue}filePath=this._nd.path.join(dir,file);stat=this._nd.fs.statSync(filePath);if(stat.isDirectory()){ret=this._findFile(filePath,name,fncb);if(ret){return ret}}}return null};FSU.prototype.findFileSync=function(dir,name,fncb){return this.findFile(dir,name,fncb)};FSU.prototype.readFileSync=function(filePath,error){return this._readFileSync(filePath,false,error)};FSU.prototype.readFileBufSync=function(filePath,error){return this._readFileSync(filePath,true,error)};FSU.prototype._readFileSync=function(filePath,wantBuffer,error){var haveFn,doThrow,noThrow,t;t=typeof error;doThrow=t==="boolean"&&error;noThrow=t==="boolean"&&!error;haveFn=t==="function";try{return wantBuffer?this._nd.fs.readFileSync(filePath):this._nd.fs.readFileSync(filePath,"utf8")}catch(e){function _prepErr(){var s=e.message;if(s.startsWith("ENOENT")){s=`ENOENT: file not found - '${filePath}'`}return s}if(haveFn){error(_prepErr())}else if(doThrow){throw new Error(e)}else if(noThrow){return _prepErr()}}return null};FSU.prototype.readJsonSync=function(filepath,comments,error){var e,haveFn,doThrow,noThrow,t;t=typeof error;doThrow=t==="boolean"&&error;noThrow=t==="boolean"&&!error;haveFn=t==="function";var _fn=function(err){err="SYNTAX: "+err;e=err;if(haveFn){error(err)}};filepath=this.makeAbsolutePath(filepath);var o=this._nd.jsonLoader.load(filepath,this._nd,_fn,comments,this._utils);if(e){if(doThrow){throw new Error(e)}else if(noThrow){return e}return null}if(o){return o}let msg="NOFILE: "+filepath;if(doThrow){throw new Error(msg)}if(noThrow){return msg}if(haveFn){error(msg)}return null};FSU.prototype.writeJsonSync=function(obj,filepath,opts,error){var repl,ind,err;var doThrow,noThrow,haveFn,t;t=typeof error;doThrow=t==="boolean"&&error;noThrow=t==="boolean"&&!error;haveFn=t==="function";if(opts){repl=opts.replacer?opts.replacer:null;ind=opts.spaces}filepath=this.makeAbsolutePath(filepath);try{let s=JSON.stringify(obj,repl,ind);this._nd.fs.writeFileSync(filepath,s);return true}catch(e){if(doThrow){throw e}err=e}if(err){if(haveFn){error(err.message);return false}if(noThrow){return err.message}}return false};FSU.prototype.walkDirSync=function(dirPath,cb,forceFwdSlash){if(typeof cb!=="function"||!this.fileExistsSync(dirPath,true)){return}let path=this._nd.path;let fs=this._nd.fs;let _getFileType=this.getFileType.bind(this);function _walkDirSync(dirPath,cb,forceFwdSlash){var i,ftype,fpath,files,file,ret;if(files=fs.readdirSync(dirPath)){for(i=0;i<files.length;i++){file=files[i];fpath=path.join(dirPath,file);fpath=forceFwdSlash?fpath.replace(/\\/g,"/"):fpath;ftype=_getFileType(fpath);if(ftype==="f"||ftype==="d"||ftype==="l"){ret=cb(fpath,ftype);if(ret==="exit"){return false}else if(ret==="direxit"){break}if(ftype==="d"){if(!_walkDirSync(fpath,cb,forceFwdSlash)){return false}}}}}return true};_walkDirSync(dirPath,cb,forceFwdSlash)};FSU.prototype.makeAbsolutePath=function(filepath){if(!this._nd.path.isAbsolute(filepath)){filepath=this._nd.path.resolve(process.cwd(),filepath)}return filepath};module.exports=FSU;
6
+ const tmpFile=require("tmp");function FSU(nd,utils){this._nd=nd;this._utils=utils};FSU.prototype.toJAFPath=function(sourcePath){if(sourcePath){sourcePath=this._nd.path.normalize(sourcePath);if(this._utils.isWindows()){sourcePath=sourcePath.replace(/\\/g,"/")}}return sourcePath};FSU.prototype.toNativePath=function(sourcePath){if(sourcePath){sourcePath=this._nd.normalize(sourcePath);if(this._utils.isWindows()){sourcePath=sourcePath.replace(/\//g,"\\")}}return sourcePath};FSU.prototype.getFileType=function(path){var stats,ret;try{stats=this._nd.fs.statSync(path);if(stats.isFile()){ret="f"}else if(stats.isDirectory()){ret="d"}}catch(e){ret=e}return ret};FSU.prototype.getFileTypeSync=function(path){return this.getFileType(path)};FSU.prototype.getFileTypeWithMsg=function(path){var ret;ret=this.getFileType(path);if(ret!=="f"&&ret!=="d"){if(ret.message.startsWith("ENOENT:")){console.log("\n** File \""+path+"\" not found")}else{console("\n** File \""+path+"\" error.\n"+" "+ret.message+".\n")}ret="?"}return ret};FSU.prototype.getFileTypeWithMsgSync=function(path){return this.getFileTypeWithMsg(path)};FSU.prototype.getFileExt=function(path){var s;try{if(!this.isSymLink(path)){s=this._nd.path.extname(path)}else{let p=this._nd.fs.readlinkSync(path);if(p){s=this._nd.path.extname(p)}}if(s&&s.charAt(0)==="."){s=s.substring(1)}return s}catch(e){}return""};FSU.prototype.getFileExtSync=function(path){return this.getFileExt(path)};FSU.prototype.isSymLink=function(path){var stats;try{stats=this._nd.fs.lstatSync(path);return stats.isSymbolicLink()}catch(e){}return false};FSU.prototype.fileExists=function(filepath,dir){var stats,ret=false;try{stats=this._nd.fs.lstatSync(filepath);ret=dir?stats.isDirectory():stats.isFile()}catch(e){}return ret};FSU.prototype.fileExistsSync=function(filepath,dir){return this.fileExists(filepath,dir)};FSU.prototype.pathExistsSync=function(filepath){try{return this._nd.fs.existsSync(filepath)}catch(e){}return false};FSU.prototype.readDir=function(path){var ret=[];try{this._readDir(path,ret)}catch(e){ret=null}return ret};FSU.prototype.readDirSync=function(path){return this.readDir(path)};FSU.prototype._readDir=function(dir,ar){var files,file,filePath,stat,arDir,i;files=this._nd.fs.readdirSync(dir);for(i=0;i<files.length;i++){file=files[i];if(file[0]==="."){continue}filePath=this._nd.path.join(dir,file);stat=this._nd.fs.statSync(filePath);if(stat.isFile()){ar.push({name:file,isFile:true})}else if(stat.isDirectory()){arDir=[];ar.push({name:file,isFile:false,files:arDir});this._readDir(filePath,arDir)}}};FSU.prototype.createFolder=function(dirPath,orig){var rc;dirPath=this._nd.path.resolve(dirPath);if(!orig){orig=dirPath}try{if(!this._nd.fs.statSync(dirPath).isDirectory()){return new Error(dirPath+" exists but is not a directory")}}catch(err){if(err.code==="ENOENT"){var np=this._nd.path.dirname(dirPath);if(np===dirPath){return new Error(orig+" cannot be created")}rc=this.createFolder(np,orig);if(typeof rc!=="boolean"){return rc}this._nd.fs.mkdirSync(dirPath);if(dirPath===orig){return true}}else{return err}}return true};FSU.prototype.createFolderSync=function(dirPath){return this.createFolder(dirPath)};FSU.prototype.deleteFolder=function(filepath,deleteTarget){if(this._nd.fs.existsSync(filepath)){this._nd.fs.readdirSync(filepath).forEach(function(file){var curPath=this._nd.path.join(filepath,file);if(this._nd.fs.lstatSync(curPath).isDirectory()){this.deleteFolder(curPath,true)}else{this._nd.fs.unlinkSync(curPath)}},this);if(deleteTarget){this._nd.fs.rmdirSync(filepath)}}};FSU.prototype.deleteFolderSync=function(filepath,deleteTarget){return this.deleteFolder(filepath,deleteTarget)};FSU.prototype.getUniqueFileNameSync=function(template,targetFolder){const opts={template:template};if(targetFolder){opts.dir=targetFolder}return tmpFile.tmpNameSync(opts)};FSU.prototype.getUniqueFileName=function(template,targetFolder){return this.getUniqueFileNameSync(template,targetFolder)};FSU.prototype.findFile=function(dir,name,fncb){var ret;try{ret=this._findFile(dir,name,fncb)}catch(e){}return ret};FSU.prototype._findFile=function(dir,name,fncb){var files,file,filePath,stat,ret,i;files=this._nd.fs.readdirSync(dir);for(i=0;i<files.length;i++){file=files[i];if(!fncb||fncb(dir,file)){if(file===name){return dir}}if(file[0]==="."){continue}filePath=this._nd.path.join(dir,file);stat=this._nd.fs.statSync(filePath);if(stat.isDirectory()){ret=this._findFile(filePath,name,fncb);if(ret){return ret}}}return null};FSU.prototype.findFileSync=function(dir,name,fncb){return this.findFile(dir,name,fncb)};FSU.prototype.readFileSync=function(filePath,error){return this._readFileSync(filePath,false,error)};FSU.prototype.readFileBufSync=function(filePath,error){return this._readFileSync(filePath,true,error)};FSU.prototype._readFileSync=function(filePath,wantBuffer,error){var haveFn,doThrow,noThrow,t;t=typeof error;doThrow=t==="boolean"&&error;noThrow=t==="boolean"&&!error;haveFn=t==="function";try{return wantBuffer?this._nd.fs.readFileSync(filePath):this._nd.fs.readFileSync(filePath,"utf8")}catch(e){function _prepErr(){var s=e.message;if(s.startsWith("ENOENT")){s=`ENOENT: file not found - '${filePath}'`}return s}if(haveFn){error(_prepErr())}else if(doThrow){throw new Error(e)}else if(noThrow){return _prepErr()}}return null};FSU.prototype.readJsonSync=function(filepath,comments,error){var e,haveFn,doThrow,noThrow,t;t=typeof error;doThrow=t==="boolean"&&error;noThrow=t==="boolean"&&!error;haveFn=t==="function";var _fn=function(err){err="SYNTAX: "+err;e=err;if(haveFn){error(err)}};filepath=this.makeAbsolutePath(filepath);var o=this._nd.jsonLoader.load(filepath,this._nd,_fn,comments,this._utils);if(e){if(doThrow){throw new Error(e)}else if(noThrow){return e}return null}if(o){return o}let msg="NOFILE: "+filepath;if(doThrow){throw new Error(msg)}if(noThrow){return msg}if(haveFn){error(msg)}return null};FSU.prototype.writeJsonSync=function(obj,filepath,opts,error){var repl,ind,err;var doThrow,noThrow,haveFn,t;t=typeof error;doThrow=t==="boolean"&&error;noThrow=t==="boolean"&&!error;haveFn=t==="function";if(opts){repl=opts.replacer?opts.replacer:null;ind=opts.spaces}filepath=this.makeAbsolutePath(filepath);try{let s=JSON.stringify(obj,repl,ind);this._nd.fs.writeFileSync(filepath,s);return true}catch(e){if(doThrow){throw e}err=e}if(err){if(haveFn){error(err.message);return false}if(noThrow){return err.message}}return false};FSU.prototype.walkDirSync=function(dirPath,cb,forceFwdSlash){if(typeof cb!=="function"||!this.fileExistsSync(dirPath,true)){return}let path=this._nd.path;let fs=this._nd.fs;let _getFileType=this.getFileType.bind(this);function _walkDirSync(dirPath,cb,forceFwdSlash){var i,ftype,fpath,files,file,ret;if(files=fs.readdirSync(dirPath)){for(i=0;i<files.length;i++){file=files[i];fpath=path.join(dirPath,file);fpath=forceFwdSlash?fpath.replace(/\\/g,"/"):fpath;ftype=_getFileType(fpath);if(ftype==="f"||ftype==="d"||ftype==="l"){ret=cb(fpath,ftype);if(ret==="exit"){return false}else if(ret==="direxit"){break}if(ftype==="d"){if(!_walkDirSync(fpath,cb,forceFwdSlash)){return false}}}}}return true};_walkDirSync(dirPath,cb,forceFwdSlash)};FSU.prototype.makeAbsolutePath=function(filepath){if(!this._nd.path.isAbsolute(filepath)){filepath=this._nd.path.resolve(process.cwd(),filepath)}return filepath};module.exports=FSU;
package/lib/HtmlUtils.js CHANGED
@@ -3,4 +3,4 @@
3
3
  * Licensed under The Universal Permissive License (UPL), Version 1.0
4
4
  * as shown at https://oss.oracle.com/licenses/upl/
5
5
  */
6
- const COMMON_ATTRS={"accesskey":true,"class":true,"contenteditable":true,"contextmenu":true,"dir":true,"draggable":true,"dropzone":true,"hidden":true,"id":true,"lang":true,"role":true,"spellcheck":true,"style":true,"tabindex":true,"title":true,"translate":true};var COMMON_ELEMS={"a":true,"abbr":true,"address":true,"area":true,"article":true,"aside":true,"audio":true,"b":true,"base":true,"bdi":true,"bdo":true,"blockquote":true,"body":true,"br":true,"button":true,"canvas":true,"caption":true,"cite":true,"code":true,"col":true,"colgroup":true,"command":true,"datalist":true,"dd":true,"del":true,"details":true,"dfn":true,"div":true,"dl":true,"dt":true,"em":true,"embed":true,"fieldset":true,"figcaption":true,"figure":true,"footer":true,"form":true,"h1":true,"h2":true,"h3":true,"h4":true,"h5":true,"h6":true,"head":true,"header":true,"hgroup":true,"hr":true,"html":true,"i":true,"iframe":true,"img":true,"input":true,"ins":true,"kbd":true,"keygen":true,"label":true,"legend":true,"li":true,"link":true,"map":true,"main":true,"mark":true,"menu":true,"meta":true,"meter":true,"nav":true,"noscript":true,"object":true,"ol":true,"optgroup":true,"option":true,"output":true,"p":true,"param":true,"pre":true,"progress":true,"q":true,"rp":true,"rt":true,"ruby":true,"s":true,"samp":true,"script":true,"section":true,"select":true,"small":true,"source":true,"span":true,"strong":true,"style":true,"sub":true,"summary":true,"sup":true,"table":true,"tbody":true,"td":true,"textarea":true,"tfoot":true,"th":true,"thead":true,"time":true,"title":true,"tr":true,"track":true,"u":true,"ul":true,"var":true,"video":true,"wbr":true,"svg":true};var COMMON_EVENT_ATTRS={"onabort":true,"onauxclick":true,"onblur":true,"oncanplay":true,"oncanplaythrough":true,"onchange":true,"onclick":true,"oncontextmenu":true,"ondblclick":true,"ondrag":true,"ondragend":true,"ondragenter":true,"ondragleave":true,"ondragover":true,"ondragstart":true,"ondrop":true,"ondurationchange":true,"onemptied":true,"onended":true,"onerror":true,"onfocus":true,"onfocusin":true,"onfocusout":true,"onformchange":true,"onforminput":true,"oninput":true,"oninvalid":true,"onkeydown":true,"onkeypress":true,"onkeyup":true,"onload":true,"onloadeddata":true,"onloadedmetadata":true,"onloadstart":true,"onmousedown":true,"onmousemove":true,"onmouseout":true,"onmouseover":true,"onmouseup":true,"onmousewheel":true,"onpause":true,"onplay":true,"onplaying":true,"onprogress":true,"onratechange":true,"onreadystatechange":true,"onreset":true,"onscroll":true,"onseeked":true,"onseeking":true,"onselect":true,"onshow":true,"onstalled":true,"onsubmit":true,"onsuspend":true,"ontimeupdate":true,"onvolumechange":true,"onwaiting":true};const SVG_ELEMS={"animate":true,"animatemotion":true,"animatetransform":true,"circle":true,"clippath":true,"color-profile":true,"defs":true,"desc":true,"discard":true,"ellipse":true,"feblend":true,"fecolormatrix":true,"fecomponenttransfer":true,"fecomposite":true,"feconvolvematrix":true,"fediffuselighting":true,"fedisplacementmap":true,"fedistantlight":true,"fedropshadow":true,"feflood":true,"fefunca":true,"fefuncb":true,"fefuncg":true,"fefuncr":true,"fegaussianblur":true,"feimage":true,"femerge":true,"femergenode":true,"femorphology":true,"feoffset":true,"fepointlight":true,"fespecularlighting":true,"fespotLight":true,"fetile":true,"feturbulence":true,"filter":true,"foreignobject":true,"g":true,"hatch":true,"hatchpath":true,"image":true,"line":true,"lineargradient":true,"marker":true,"mask":true,"mesh":true,"meshgradient":true,"meshpatch":true,"meshrow":true,"metadata":true,"mpath":true,"path":true,"pattern":true,"polygon":true,"polyline":true,"radialgradient":true,"rect":true,"script":true,"set":true,"solidcolor":true,"stop":true,"style":true,"svg":true,"switch":true,"symbol":true,"text":true,"textpath":true,"title":true,"tspan":true,"unknown":true,"use":true,"view":true};const HTML5_OBS_TAGS={"applet":true,"acronym":true,"basefont":true,"bgsound":true,"big":true,"blink":true,"center":true,"dir":true,"font":true,"frame":true,"frameset":true,"noframes":true,"isindex":true,"keygen":true,"listing":true,"marquee":true,"menuitem":true,"multicol":true,"nextid":true,"nobr":true,"noembed":true,"plaintext":true,"rb":true,"rlc":true,"s":true,"spacer":true,"strike":true,"tt":true,"xmp":true};const HTML5_OBS_ATTRS={"a":["charset","coords","methods","name","rev","shape","urn"],"area":["nohref"],"body":["alink","background","bgcolor","bottommargin","leftmargin","link","marginheight","marginwidth","rightmargin","text","vlink"],"br":["clear"],"caption":["align"],"col":["align","char","charoff","valign","width"],"div":["align"],"dl":["compact"],"embed":["align","name","hspace","vspace"],"form":["accept"],"head":["profile"],"hr":["align","noshade","size","width"],"h1":["align"],"h2":["align"],"h3":["align"],"h4":["align"],"h5":["align"],"h6":["align"],"html":["version"],"iframe":["align","allowtransparency","frameborder","framespacing","hspace","longdesc","marginheight","marginwidth","scrolling","vspace"],"img":["align","border","hspace","longdesc","lowsrc","name","vspace"],"input":["align","border","hspace","ismap","usemap","vspace"],"legend":["align"],"li":["type"],"link":["charset","methods","rev","target","urn"],"menu":["compact","label","type"],"meta":["scheme"],"object":["align","archive","border","classid","code","codebase","codetype","declare","hspace","standby","typemustmatch","vspace"],"ol":["compact"],"option":["name"],"p":["align"],"param":["type","valuetype"],"pre":["width"],"script":["charset","event","for","language"],"style":["type"],"table":["align","background","bgcolor","border","bordercolor","cellpadding","cellspacing","datapagesize","frame","height","rules","summary","width"],"tbody":["align","background","char","charoff","valign"],"tfoot":["align","background","char","charoff","valign"],"thead":["align","background","char","charoff","valign"],"td":["abbr","align","axis","background","bgcolor","char","charoff","height","nowrap","scope","valign","width"],"th":["abbr","align","axis","background","bgcolor","char","charoff","height","nowrap","valign","width"],"tr":["align","background","bgcolor","char","charoff","height","valign"],"ul":["compact","type"]};const HTML5_OBS_ATTR_ALL_ELEM=["contextmenu","dropzone","onshow"];const SELF_CLOSING_ELEMS={"area":true,"base":true,"br":true,"embed":true,"hr":true,"iframe":true,"img":true,"input":true,"link":true,"meta":true,"param":true,"source":true,"track":true};const SVG_PATH_COMMANDS=["M","m","L","I","H","h","V","v","C","c","S","s","Q","q","T","t","A","a","Z","z"];const OJ_NAMESPACE_PREFIXES=require("./ns");const ARIA_LIST=["aria-atomic","aria-busy","aria-controls","aria-describedat","aria-describedby","aria-disabled","aria-dropeffect","aria-flowto","aria-grabbed","aria-haspopup","aria-hidden","aria-invalid","aria-label","aria-labelledby","aria-live","aria-owns","aria-relevant","aria-autocomplete","aria-checked","aria-disabled","aria-expanded","aria-haspopup","aria-hidden","aria-invalid","aria-label","aria-level","aria-multiline","aria-multiselectable","aria-orientation","aria-pressed","aria-readonly","aria-required","aria-rowcount","aria-rowindex","aria-selected","aria-sort","aria-valuemax","aria-valuemin","aria-valuenow","aria-valuetext","aria-dropeffect","aria-grabbed","aria-activedescendant","aria-flowto","aria-posinset","aria-setsize"];module.exports.isCommonAttr=function(attrName){var x;attrName=attrName.toLowerCase();attrName=attrName.charAt(0)===":"?attrName.substring(1):attrName;x=attrName.indexOf(".");if(x>=0){attrName=attrName.substring(0,x)};return COMMON_ATTRS[attrName]||attrName.startsWith("aria-")||attrName.startsWith("data-")&&attrName!=="data-oj-command"&&attrName!=="data-oj-context"};module.exports.isCommonEventAttr=function(attrName){attrName=attrName.toLowerCase();attrName=attrName.charAt(0)===":"?attrName.substring(1):attrName;if(attrName.startsWith("on-oj-")){return false}if(attrName.startsWith("on-")){attrName=attrName.substring(0,2)+attrName.substring(3)}return COMMON_EVENT_ATTRS[attrName]};module.exports.isCommonElem=function(elem){return COMMON_ELEMS[elem.toLowerCase()]};module.exports.isSvgElem=function(elem){return SVG_ELEMS[elem.toLowerCase()]};module.exports.isSvgPath=function(s){var c=s.trim().charAt(0);return SVG_PATH_COMMANDS.indexOf(c)>=0};module.exports.isSelfClosingTag=function(elem){return SELF_CLOSING_ELEMS[elem]};module.exports.isNamespacePrefix=function(prefix){return OJ_NAMESPACE_PREFIXES.has(prefix)};module.exports.isNamespaceTag=function(tag){var s=tag.replace(/[<>]/g,"");var x,ret=false;if(tag.startsWith("demo-")||tag.startsWith("my-")||tag.startsWith("ns-")){return true}while(true){x=s.lastIndexOf("-");if(x>=0){s=s.substring(0,x);if(s.lastIndexOf("-")<0&&s==="oj"){break}if(OJ_NAMESPACE_PREFIXES.has(s)){ret=true;break}}else{break}}return ret};module.exports.isHtml5ObsoleteElem=function(tag){return HTML5_OBS_TAGS[tag.toLowerCase()]};module.exports.isHtml5ObsoleteAttr=function(tagName,attrName){var depAttrs,ret=false;attrName=attrName.charAt(0)!==":"?attrName:attrName.substring(1);depAttrs=HTML5_OBS_ATTRS[tagName];if(!depAttrs){depAttrs=HTML5_OBS_ATTR_ALL_ELEM}if(depAttrs){if(depAttrs.includes(attrName)){ret=true}}return ret};module.exports.isAriaAttr=function(attrName){attrName=attrName.charAt(0)===":"?attrName.substring(1):attrName;return ARIA_LIST.includes(attrName.toLowerCase())};const EXPR_CHARS=new RegExp("[?\"'=+:/()[]{}]","g");module.exports.isEncodedLiteral=function(expr){if(expr.charAt(0)==="'"&&expr.charAt(expr.length-1)==="'"){return EXPR_CHARS.test(expr.substring(1,expr.length-1))}return false};module.exports.replaceEntities=function(s){const ENTITY_LT=/&lt;/g;const ENTITY_GT=/&amp;/g;const ENTITY_QUOT=/&quot;/g;const ENTITY_APOS=/&apos;/g;const ENTITY_AMP=/&amp;/g;const ENTITY_NBSP=/&nbsp;/g;if(s.indexOf("&")>=0){s=s.replace(ENTITY_LT,"<");s=s.replace(ENTITY_GT,"&");s=s.replace(ENTITY_QUOT,"\"");s=s.replace(ENTITY_APOS,"'");s=s.replace(ENTITY_AMP,"&");s=s.replace(ENTITY_NBSP," ")}return s};
6
+ const COMMON_ATTRS={"accesskey":true,"class":true,"contenteditable":true,"contextmenu":true,"dir":true,"draggable":true,"dropzone":true,"hidden":true,"id":true,"lang":true,"role":true,"spellcheck":true,"style":true,"tabindex":true,"title":true,"translate":true};var COMMON_ELEMS={"a":true,"abbr":true,"address":true,"area":true,"article":true,"aside":true,"audio":true,"b":true,"base":true,"bdi":true,"bdo":true,"blockquote":true,"body":true,"br":true,"button":true,"canvas":true,"caption":true,"cite":true,"code":true,"col":true,"colgroup":true,"command":true,"datalist":true,"dd":true,"del":true,"details":true,"dfn":true,"div":true,"dl":true,"dt":true,"em":true,"embed":true,"fieldset":true,"figcaption":true,"figure":true,"footer":true,"form":true,"h1":true,"h2":true,"h3":true,"h4":true,"h5":true,"h6":true,"head":true,"header":true,"hgroup":true,"hr":true,"html":true,"i":true,"iframe":true,"img":true,"input":true,"ins":true,"kbd":true,"keygen":true,"label":true,"legend":true,"li":true,"link":true,"map":true,"main":true,"mark":true,"menu":true,"meta":true,"meter":true,"nav":true,"noscript":true,"object":true,"ol":true,"optgroup":true,"option":true,"output":true,"p":true,"param":true,"pre":true,"progress":true,"q":true,"rp":true,"rt":true,"ruby":true,"s":true,"samp":true,"script":true,"section":true,"select":true,"small":true,"source":true,"span":true,"strong":true,"style":true,"sub":true,"summary":true,"sup":true,"table":true,"tbody":true,"td":true,"textarea":true,"tfoot":true,"th":true,"thead":true,"time":true,"title":true,"tr":true,"track":true,"u":true,"ul":true,"var":true,"video":true,"wbr":true,"svg":true};var COMMON_EVENT_ATTRS={"onabort":true,"onauxclick":true,"onblur":true,"oncanplay":true,"oncanplaythrough":true,"onchange":true,"onclick":true,"oncontextmenu":true,"ondblclick":true,"ondblclickcapture":true,"ondrag":true,"ondragend":true,"ondragenter":true,"ondragleave":true,"ondragover":true,"ondragstart":true,"ondrop":true,"ondurationchange":true,"onemptied":true,"onended":true,"onerror":true,"onfocus":true,"onfocusin":true,"onfocusout":true,"onformchange":true,"onforminput":true,"oninput":true,"oninvalid":true,"onkeydown":true,"onkeypress":true,"onkeyup":true,"onload":true,"onloadeddata":true,"onloadedmetadata":true,"onloadstart":true,"onmousedown":true,"onmouseenter":true,"onmouseleave":true,"onmousemove":true,"onmouseout":true,"onmouseover":true,"onmouseup":true,"onmousewheel":true,"onpause":true,"onplay":true,"onplaying":true,"onprogress":true,"onratechange":true,"onreadystatechange":true,"onreset":true,"onscroll":true,"onseeked":true,"onseeking":true,"onselect":true,"onshow":true,"onstalled":true,"onsubmit":true,"onsuspend":true,"ontimeupdate":true,"onvolumechange":true,"onwaiting":true,"onwheel":true};const SVG_ELEMS={"animate":true,"animatemotion":true,"animatetransform":true,"circle":true,"clippath":true,"color-profile":true,"defs":true,"desc":true,"discard":true,"ellipse":true,"feblend":true,"fecolormatrix":true,"fecomponenttransfer":true,"fecomposite":true,"feconvolvematrix":true,"fediffuselighting":true,"fedisplacementmap":true,"fedistantlight":true,"fedropshadow":true,"feflood":true,"fefunca":true,"fefuncb":true,"fefuncg":true,"fefuncr":true,"fegaussianblur":true,"feimage":true,"femerge":true,"femergenode":true,"femorphology":true,"feoffset":true,"fepointlight":true,"fespecularlighting":true,"fespotLight":true,"fetile":true,"feturbulence":true,"filter":true,"foreignobject":true,"g":true,"hatch":true,"hatchpath":true,"image":true,"line":true,"lineargradient":true,"marker":true,"mask":true,"mesh":true,"meshgradient":true,"meshpatch":true,"meshrow":true,"metadata":true,"mpath":true,"path":true,"pattern":true,"polygon":true,"polyline":true,"radialgradient":true,"rect":true,"script":true,"set":true,"solidcolor":true,"stop":true,"style":true,"svg":true,"switch":true,"symbol":true,"text":true,"textpath":true,"title":true,"tspan":true,"unknown":true,"use":true,"view":true};const HTML5_OBS_TAGS={"applet":true,"acronym":true,"basefont":true,"bgsound":true,"big":true,"blink":true,"center":true,"dir":true,"font":true,"frame":true,"frameset":true,"noframes":true,"isindex":true,"keygen":true,"listing":true,"marquee":true,"menuitem":true,"multicol":true,"nextid":true,"nobr":true,"noembed":true,"plaintext":true,"rb":true,"rlc":true,"s":true,"spacer":true,"strike":true,"tt":true,"xmp":true};const HTML5_OBS_ATTRS={"a":["charset","coords","methods","name","rev","shape","urn"],"area":["nohref"],"body":["alink","background","bgcolor","bottommargin","leftmargin","link","marginheight","marginwidth","rightmargin","text","vlink"],"br":["clear"],"caption":["align"],"col":["align","char","charoff","valign","width"],"div":["align"],"dl":["compact"],"embed":["align","name","hspace","vspace"],"form":["accept"],"head":["profile"],"hr":["align","noshade","size","width"],"h1":["align"],"h2":["align"],"h3":["align"],"h4":["align"],"h5":["align"],"h6":["align"],"html":["version"],"iframe":["align","allowtransparency","frameborder","framespacing","hspace","longdesc","marginheight","marginwidth","scrolling","vspace"],"img":["align","border","hspace","longdesc","lowsrc","name","vspace"],"input":["align","border","hspace","ismap","usemap","vspace"],"legend":["align"],"li":["type"],"link":["charset","methods","rev","target","urn"],"menu":["compact","label","type"],"meta":["scheme"],"object":["align","archive","border","classid","code","codebase","codetype","declare","hspace","standby","typemustmatch","vspace"],"ol":["compact"],"option":["name"],"p":["align"],"param":["type","valuetype"],"pre":["width"],"script":["charset","event","for","language"],"style":["type"],"table":["align","background","bgcolor","border","bordercolor","cellpadding","cellspacing","datapagesize","frame","height","rules","summary","width"],"tbody":["align","background","char","charoff","valign"],"tfoot":["align","background","char","charoff","valign"],"thead":["align","background","char","charoff","valign"],"td":["abbr","align","axis","background","bgcolor","char","charoff","height","nowrap","scope","valign","width"],"th":["abbr","align","axis","background","bgcolor","char","charoff","height","nowrap","valign","width"],"tr":["align","background","bgcolor","char","charoff","height","valign"],"ul":["compact","type"]};const HTML5_OBS_ATTR_ALL_ELEM=["contextmenu","dropzone","onshow"];const SELF_CLOSING_ELEMS={"area":true,"base":true,"br":true,"embed":true,"hr":true,"iframe":true,"img":true,"input":true,"link":true,"meta":true,"param":true,"source":true,"track":true};const SVG_PATH_COMMANDS=["M","m","L","I","H","h","V","v","C","c","S","s","Q","q","T","t","A","a","Z","z"];const OJ_NAMESPACE_PREFIXES=require("./ns");const ARIA_LIST=["aria-atomic","aria-busy","aria-controls","aria-describedat","aria-describedby","aria-disabled","aria-dropeffect","aria-flowto","aria-grabbed","aria-haspopup","aria-hidden","aria-invalid","aria-label","aria-labelledby","aria-live","aria-owns","aria-relevant","aria-autocomplete","aria-checked","aria-disabled","aria-expanded","aria-haspopup","aria-hidden","aria-invalid","aria-label","aria-level","aria-multiline","aria-multiselectable","aria-orientation","aria-pressed","aria-readonly","aria-required","aria-rowcount","aria-rowindex","aria-selected","aria-sort","aria-valuemax","aria-valuemin","aria-valuenow","aria-valuetext","aria-dropeffect","aria-grabbed","aria-activedescendant","aria-flowto","aria-posinset","aria-setsize"];module.exports.isCommonAttr=function(attrName){var x;attrName=attrName.toLowerCase();attrName=attrName.charAt(0)===":"?attrName.substring(1):attrName;x=attrName.indexOf(".");if(x>=0){attrName=attrName.substring(0,x)};return COMMON_ATTRS[attrName]||attrName.startsWith("aria-")||attrName.startsWith("data-")&&attrName!=="data-oj-command"&&attrName!=="data-oj-context"};module.exports.isCommonEventAttr=function(attrName){attrName=attrName.toLowerCase();attrName=attrName.charAt(0)===":"?attrName.substring(1):attrName;if(attrName.startsWith("on-oj-")){return false}if(attrName.startsWith("on-")){attrName=attrName.substring(0,2)+attrName.substring(3)}return COMMON_EVENT_ATTRS[attrName]};module.exports.isCommonElem=function(elem){return COMMON_ELEMS[elem.toLowerCase()]};module.exports.isSvgElem=function(elem){return SVG_ELEMS[elem.toLowerCase()]};module.exports.isSvgPath=function(s){var c=s.trim().charAt(0);return SVG_PATH_COMMANDS.indexOf(c)>=0};module.exports.isSelfClosingTag=function(elem){return SELF_CLOSING_ELEMS[elem]};module.exports.isNamespacePrefix=function(prefix){return OJ_NAMESPACE_PREFIXES.has(prefix)};module.exports.isNamespaceTag=function(tag){var s=tag.replace(/[<>]/g,"");var x,ret=false;if(tag.startsWith("demo-")||tag.startsWith("my-")||tag.startsWith("ns-")){return true}while(true){x=s.lastIndexOf("-");if(x>=0){s=s.substring(0,x);if(s.lastIndexOf("-")<0&&s==="oj"){break}if(OJ_NAMESPACE_PREFIXES.has(s)){ret=true;break}}else{break}}return ret};module.exports.isHtml5ObsoleteElem=function(tag){return HTML5_OBS_TAGS[tag.toLowerCase()]};module.exports.isHtml5ObsoleteAttr=function(tagName,attrName){var depAttrs,ret=false;attrName=attrName.charAt(0)!==":"?attrName:attrName.substring(1);depAttrs=HTML5_OBS_ATTRS[tagName];if(!depAttrs){depAttrs=HTML5_OBS_ATTR_ALL_ELEM}if(depAttrs){if(depAttrs.includes(attrName)){ret=true}}return ret};module.exports.isAriaAttr=function(attrName){attrName=attrName.charAt(0)===":"?attrName.substring(1):attrName;return ARIA_LIST.includes(attrName.toLowerCase())};const EXPR_CHARS=new RegExp("[?\"'=+:/()[]{}]","g");module.exports.isEncodedLiteral=function(expr){if(expr.charAt(0)==="'"&&expr.charAt(expr.length-1)==="'"){return EXPR_CHARS.test(expr.substring(1,expr.length-1))}return false};module.exports.replaceEntities=function(s){const ENTITY_LT=/&lt;/g;const ENTITY_GT=/&amp;/g;const ENTITY_QUOT=/&quot;/g;const ENTITY_APOS=/&apos;/g;const ENTITY_AMP=/&amp;/g;const ENTITY_NBSP=/&nbsp;/g;if(s.indexOf("&")>=0){s=s.replace(ENTITY_LT,"<");s=s.replace(ENTITY_GT,"&");s=s.replace(ENTITY_QUOT,"\"");s=s.replace(ENTITY_APOS,"'");s=s.replace(ENTITY_AMP,"&");s=s.replace(ENTITY_NBSP," ")}return s};
package/lib/JafLib.js CHANGED
@@ -3,4 +3,4 @@
3
3
  * Licensed under The Universal Permissive License (UPL), Version 1.0
4
4
  * as shown at https://oss.oracle.com/licenses/upl/
5
5
  */
6
- const CLI_MODE="cli";const API_MODE="api";const AMD_MODE="amd";function JafLib(nd,jfs,mctx,runMode,jafver,jv,cfg,ageLib){this._rdy=-1;this.setup(nd,jfs,mctx,runMode,jafver,jv,cfg,ageLib)};JafLib.prototype.getFileset=function(ruleCtx){if(this._nd&&ruleCtx.phase&&ruleCtx.phase==="startaudit"){return this._jfs.getFiles()}};JafLib.prototype.setFileset=function(ruleCtx,files,exclude){var rc=false;if(this._nd&&ruleCtx.phase&&ruleCtx.phase==="startaudit"){if(files&&!Array.isArray(files)||exclude&&!Array.isArray(exclude)){this._mCtx.error("Rule '"+ruleCtx.ruleName+"' attempt to call JafLib.setfiles() with non-array");this._jfs.setFiles(null,null);return false}this._jfs.setFiles(files,exclude);rc=true}return rc};JafLib.prototype.getRunMode=function(){return this._runMode};JafLib.prototype.getConfig=function(){return this._cfg};JafLib.prototype.getTsConfigObj=function(){return this._cfg.getTsConfigObj()};JafLib.prototype.isCLI=function(){return this._runMode===CLI_MODE};JafLib.prototype.isAPI=function(){return this._runMode===API_MODE};JafLib.prototype.isAMD=function(){return this._runMode===AMD_MODE};JafLib.prototype.getJetVer=function(){return this._jetver};JafLib.prototype.getJafVer=function(){return this._jafver};JafLib.prototype.getJetReleaseCount=function(){return this._ageLib.getJetReleaseCount()};JafLib.prototype.setup=function(nd,jfs,mctx,runMode,jafver,jv,cfg,ageLib){if(this._rdy===-1){this._nd=nd;this._jfs=jfs;this._mCtx=mctx;this._runMode=runMode;this._jafver=jafver;this._jetver=jv;this._cfg=cfg;this._ageLib=ageLib}};JafLib.prototype.disable=function(){this._rdy=-2};JafLib.prototype.getJafLib=function(){return{getConfig:this.getConfig.bind(this),getTsConfigObj:this.getTsConfigObj.bind(this),getRunMode:this.getRunMode.bind(this),isCLI:this.isCLI.bind(this),isAPI:this.isAPI.bind(this),isAMD:this.isAMD.bind(this),getJetVer:this.getJetVer.bind(this),getJafVer:this.getJafVer.bind(this),getJetReleaseCount:this.getJetReleaseCount.bind(this)}};JafLib.prototype.getPublic=function(){return{setFileset:this.setFileset.bind(this),getFileset:this.getFileset.bind(this)}};module.exports=JafLib;
6
+ const CLI_MODE="cli";const API_MODE="api";const AMD_MODE="amd";function JafLib(nd,jfs,mctx,runMode,jafver,jv,cfg,ageLib){this._rdy=-1;this.setup(nd,jfs,mctx,runMode,jafver,jv,cfg,ageLib)};JafLib.prototype.getFileset=function(ruleCtx){if(this._nd&&ruleCtx.phase&&ruleCtx.phase==="startaudit"){return this._jfs.getFiles()}};JafLib.prototype.setFileset=function(ruleCtx,files,exclude){var rc=false;if(this._nd&&ruleCtx.phase&&ruleCtx.phase==="startaudit"){if(files&&!Array.isArray(files)||exclude&&!Array.isArray(exclude)){this._mCtx.error("Rule '"+ruleCtx.ruleName+"' attempt to call JafLib.setfiles() with non-array");this._jfs.setFiles(null,null);return false}this._jfs.setFiles(files,exclude);rc=true}return rc};JafLib.prototype.getRunMode=function(){return this._runMode};JafLib.prototype.getConfig=function(){return this._cfg};JafLib.prototype.getTsConfigObj=function(){return this._cfg.getTsConfigObj()};JafLib.prototype.isCLI=function(){return this._runMode===CLI_MODE};JafLib.prototype.isAPI=function(){return this._runMode===API_MODE};JafLib.prototype.isAMD=function(){return this._runMode===AMD_MODE};JafLib.prototype.getJetVer=function(){return this._jetver};JafLib.prototype.getJafVer=function(){return this._jafver};JafLib.prototype.getJetReleaseCount=function(){return this.getJafReleaseCount()};JafLib.prototype.getJafReleaseCount=function(){return this._ageLib.getJafReleaseCount()};JafLib.prototype.getMajorReleaseCount=function(major){return this._ageLib.getMajorReleaseCount(major)};JafLib.prototype.setup=function(nd,jfs,mctx,runMode,jafver,jv,cfg,ageLib){if(this._rdy===-1){this._nd=nd;this._jfs=jfs;this._mCtx=mctx;this._runMode=runMode;this._jafver=jafver;this._jetver=jv;this._cfg=cfg;this._ageLib=ageLib}};JafLib.prototype.disable=function(){this._rdy=-2};JafLib.prototype.getJafLib=function(){return{getConfig:this.getConfig.bind(this),getTsConfigObj:this.getTsConfigObj.bind(this),getRunMode:this.getRunMode.bind(this),isCLI:this.isCLI.bind(this),isAPI:this.isAPI.bind(this),isAMD:this.isAMD.bind(this),getJetVer:this.getJetVer.bind(this),getJafVer:this.getJafVer.bind(this),getJetReleaseCount:this.getJetReleaseCount.bind(this),getJafReleaseCount:this.getJafReleaseCount.bind(this),getMajorReleaseCount:this.getMajorReleaseCount.bind(this)}};JafLib.prototype.getPublic=function(){return{setFileset:this.setFileset.bind(this),getFileset:this.getFileset.bind(this)}};module.exports=JafLib;