@oracle/oraclejet-audit 18.0.1 → 18.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/jaf-amd.js +1 -1
- package/lib/HtmlUtils.js +1 -1
- package/lib/TsxUtils.js +1 -1
- package/lib/checkage.js +1 -1
- package/lib/defaults.js +1 -1
- package/lib/sublib/precomp/Precompiler.js +1 -1
- package/meta/18.0.0/jetauditmeta.js +1 -1
- package/meta/metaverlist.json +1 -1
- package/package.json +2 -2
- package/rules/jet/oj-html-alta-deprecated.js +1 -1
- package/rules/jet/oj-tsx-ojattr.js +1 -1
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,"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-current","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=/</g;const ENTITY_GT=/&/g;const ENTITY_QUOT=/"/g;const ENTITY_APOS=/'/g;const ENTITY_AMP=/&/g;const ENTITY_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-activedescendant","aria-atomic","aria-autocomplete","aria-busy","aria-checked","aria-colcount","aria-colindex","aria-colspan","aria-controls","aria-current","aria-describedby","aria-details","aria-disabled","aria-dropeffect","aria-errormessage","aria-expanded","aria-flowto","aria-grabbed","aria-haspopup","aria-hidden","aria-invalid","aria-ketshortcuts","aria-label","aria-labelledby","aria-level","aria-live","aria-modal","aria-multiline","aria-multiselectable","aria-orientation","aria-owns","aria-placeholder","aria-posinset","aria-pressed","aria-readonly","aria-relevant","aria-required","aria-roledecsription","aria-rowcount","aria-rowindex","aria-rowspan","aria-selected","aria-setsize","aria-sort","aria-valuemax","aria-valuemin","aria-valuenow","aria-valuetext"];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=/</g;const ENTITY_GT=/&/g;const ENTITY_QUOT=/"/g;const ENTITY_APOS=/'/g;const ENTITY_AMP=/&/g;const ENTITY_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/TsxUtils.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 TSX2_UTILS=require("./TsxUtils2");const HTML_UTILS=require("./HtmlUtils");const CB_END="end";const CB_NEXT_COMP="next-comp";const TSX_COMPONENT="TsxComponent";const TSX_PROPERTY="TsxProperty";const TEMPLATE="template";const OJ_DEFER="oj-defer";const OJ_BIND="oj-bind";const BODY="body";var TsxUtils=function(assert){this._fnAssert=assert;this._metaLib=null};TsxUtils.prototype.extractTsxProperties=function(ruleCtx,tsxRC,cb){this._onTsxRC(ruleCtx,tsxRC,cb)};TsxUtils.prototype.getProperty=function(tsxObj,propName){return this._extractProp(tsxObj,propName)};TsxUtils.prototype._extractProp=function(tsxObj,propName){var ret,ot;if(tsxObj&&(ot=tsxObj.type)){if(ot===TSX_PROPERTY){return tsxObj}if(ot===TSX_COMPONENT&&propName){let props,prop,i;if(props=tsxObj.properties){for(i=0;i<props.length;i++){prop=props[i];if(prop.name===propName){ret=prop;break}}}}}return ret};TsxUtils.prototype.getPropertyRawValue=function(tsxComp,name,stripDelims){var prop,ret;if(prop=this.getProperty(tsxComp,name)){ret=prop.valueRaw;if(stripDelims&&ret.charAt(0)==="\""){ret=ret.charAt(1)==="\""?ret="":ret.substring(1,ret.length-1)}}return typeof ret==="string"?ret:null};TsxUtils.prototype.getPropertyValue=function(tsxComp,propName){var tsxProp,ret,obj,i;var a=propName.split(".");var major=a[0];if(tsxProp=this.getProperty(tsxComp,major)){if(a.length===1){return tsxProp.node.value}if(!this.isPropertyPreactExpr(tsxProp)){return undefined}obj=tsxProp.node.value;for(i=1;i<a.length;i++){major=a.shift();if(!_isObject(obj)){break}if((obj=obj[major])&&_isObject(obj)){continue}break}}return ret};TsxUtils.prototype.getPropertyStringValue=function(tsxObj,propName){var tsxProp,value,ret;if(tsxProp=this._extractProp(tsxObj,propName)){value=tsxProp.node.value;if(value!==null){ret=value.type==="Literal"&&typeof value.value==="string"?value.value:null}}else{ret=null}return ret};TsxUtils.prototype.isPropertyPreactExpr=function(tsxObj,propName){var tsxProp,ret=false;if(tsxProp=this._extractProp(tsxObj,propName)){ret=tsxProp.node.value.type==="JSXExpressionContainer"}return ret};TsxUtils.prototype.isPropertyObjectExpr=function(tsxObj,propName){var tsxProp,ret=false;if(tsxProp=this._extractProp(tsxObj,propName)){if(tsxProp.node.value.type==="JSXExpressionContainer"){let expr=tsxProp.node.value.expression;ret=expr&&expr.type==="ObjectExpression"}}return ret};TsxUtils.prototype.isPropertyString=function(tsxObj,propName){var tsxProp,ret=false;if(tsxProp=this._extractProp(tsxObj,propName)){ret=tsxProp.node.value.type==="Literal"&&typeof tsxProp.node.value.value==="string"}return ret};TsxUtils.prototype.getAncestor=function(tsxComp,name){var o,ret;name=name||tsxComp.name;while(o=tsxComp.parent){if(o.name===name){ret=o;break}tsxComp=o}return ret||null};TsxUtils.prototype.getChildren=function(tsxComp){return tsxComp.children};TsxUtils.prototype.getDescendant=function(tsxComp,name){var childs,child,ret,i;while(childs=tsxComp.children){for(i=0;i<childs.length;i++){child=childs[i];if(child.name===name){ret=child;break}if(ret=this.getDescendant(child,name)){break}}break}return ret||null};TsxUtils.prototype.getDirectDescendant=function(tsxComp,name){var childs,child,ret,i;if(childs=tsxComp.children){for(i=0;i<childs.length;i++){child=childs[i];if(child.name===name){ret=child;break}}}return ret||null};TsxUtils.prototype.isExpressionObject=function(tsxObj,propName){var tsxProp,ret;if(tsxProp=this._extractProp(tsxObj,propName)){if(tsxProp.node.value.type==="JSXExpressionContainer"){let expr=tsxProp.node.value.expression;ret=expr.type==="ObjectExpression"}}return!!ret};TsxUtils.prototype.getExpressionObject=function(tsxObj,propName){var tsxProp,obj;if(tsxProp=this._extractProp(tsxObj,propName)){if(!tsxProp.node.value){return null}if(tsxProp.node.value.type!=="JSXExpressionContainer"){return null}let expr=tsxProp.node.value.expression;if(expr.type==="ObjectExpression"){let props,stack;props=expr.properties;obj={};stack=[];props.forEach(prop=>{_doProp(prop,obj,stack,this._fnAssert)})}}return obj||null};TsxUtils.prototype.toCamelCase=function(str){return TSX2_UTILS.toCamelCase(str)};TsxUtils.prototype.toKebabCase=function(str){return TSX2_UTILS.toKebabCase(str)};function _doProp(prop,obj,stack,fnAssert){let key,elems,propx,pvType;if(prop.type==="Property"&&(prop.key.type==="Identifier"||prop.key.type==="Literal")){if(prop.key.type==="Identifier"){key=prop.key.name}else{key=prop.key.value}pvType=prop.value.type;if(pvType==="Literal"){obj[key]=prop.value.value}else if(pvType==="Identifier"){obj[key]=prop.value.name}else if(pvType==="ArrayExpression"){obj[key]=[];elems=prop.value.elements;elems.forEach(elem=>{if(elem.type==="Literal"){obj[key].push(elem.value)}else if(elem.type==="ObjectExpression"){elem.properties.forEach(prop=>{stack.push(obj);obj={};propx=_doProp(prop,obj,stack,fnAssert);obj=stack.pop();obj[key].push(propx)})}})}else if(prop.value.
|
|
6
|
+
const TSX2_UTILS=require("./TsxUtils2");const HTML_UTILS=require("./HtmlUtils");const CB_END="end";const CB_NEXT_COMP="next-comp";const TSX_COMPONENT="TsxComponent";const TSX_PROPERTY="TsxProperty";const TEMPLATE="template";const OJ_DEFER="oj-defer";const OJ_BIND="oj-bind";const BODY="body";var TsxUtils=function(assert){this._fnAssert=assert;this._metaLib=null};TsxUtils.prototype.extractTsxProperties=function(ruleCtx,tsxRC,cb){this._onTsxRC(ruleCtx,tsxRC,cb)};TsxUtils.prototype.getProperty=function(tsxObj,propName){return this._extractProp(tsxObj,propName)};TsxUtils.prototype._extractProp=function(tsxObj,propName){var ret,ot;if(tsxObj&&(ot=tsxObj.type)){if(ot===TSX_PROPERTY){return tsxObj}if(ot===TSX_COMPONENT&&propName){let props,prop,i;if(props=tsxObj.properties){for(i=0;i<props.length;i++){prop=props[i];if(prop.name===propName){ret=prop;break}}}}}return ret};TsxUtils.prototype.getPropertyRawValue=function(tsxComp,name,stripDelims){var prop,ret;if(prop=this.getProperty(tsxComp,name)){ret=prop.valueRaw;if(stripDelims&&ret.charAt(0)==="\""){ret=ret.charAt(1)==="\""?ret="":ret.substring(1,ret.length-1)}}return typeof ret==="string"?ret:null};TsxUtils.prototype.getPropertyValue=function(tsxComp,propName){var tsxProp,ret,obj,i;var a=propName.split(".");var major=a[0];if(tsxProp=this.getProperty(tsxComp,major)){if(a.length===1){return tsxProp.node.value}if(!this.isPropertyPreactExpr(tsxProp)){return undefined}obj=tsxProp.node.value;for(i=1;i<a.length;i++){major=a.shift();if(!_isObject(obj)){break}if((obj=obj[major])&&_isObject(obj)){continue}break}}return ret};TsxUtils.prototype.getPropertyStringValue=function(tsxObj,propName){var tsxProp,value,ret;if(tsxProp=this._extractProp(tsxObj,propName)){value=tsxProp.node.value;if(value!==null){ret=value.type==="Literal"&&typeof value.value==="string"?value.value:null}}else{ret=null}return ret};TsxUtils.prototype.isPropertyPreactExpr=function(tsxObj,propName){var tsxProp,ret=false;if(tsxProp=this._extractProp(tsxObj,propName)){ret=tsxProp.node.value.type==="JSXExpressionContainer"}return ret};TsxUtils.prototype.isPropertyObjectExpr=function(tsxObj,propName){var tsxProp,ret=false;if(tsxProp=this._extractProp(tsxObj,propName)){if(tsxProp.node.value.type==="JSXExpressionContainer"){let expr=tsxProp.node.value.expression;ret=expr&&expr.type==="ObjectExpression"}}return ret};TsxUtils.prototype.isPropertyString=function(tsxObj,propName){var tsxProp,ret=false;if(tsxProp=this._extractProp(tsxObj,propName)){ret=tsxProp.node.value.type==="Literal"&&typeof tsxProp.node.value.value==="string"}return ret};TsxUtils.prototype.getAncestor=function(tsxComp,name){var o,ret;name=name||tsxComp.name;while(o=tsxComp.parent){if(o.name===name){ret=o;break}tsxComp=o}return ret||null};TsxUtils.prototype.getChildren=function(tsxComp){return tsxComp.children};TsxUtils.prototype.getDescendant=function(tsxComp,name){var childs,child,ret,i;while(childs=tsxComp.children){for(i=0;i<childs.length;i++){child=childs[i];if(child.name===name){ret=child;break}if(ret=this.getDescendant(child,name)){break}}break}return ret||null};TsxUtils.prototype.getDirectDescendant=function(tsxComp,name){var childs,child,ret,i;if(childs=tsxComp.children){for(i=0;i<childs.length;i++){child=childs[i];if(child.name===name){ret=child;break}}}return ret||null};TsxUtils.prototype.isExpressionObject=function(tsxObj,propName){var tsxProp,ret;if(tsxProp=this._extractProp(tsxObj,propName)){if(tsxProp.node.value.type==="JSXExpressionContainer"){let expr=tsxProp.node.value.expression;ret=expr.type==="ObjectExpression"}}return!!ret};TsxUtils.prototype.getExpressionObject=function(tsxObj,propName){var tsxProp,obj;if(tsxProp=this._extractProp(tsxObj,propName)){if(!tsxProp.node.value){return null}if(tsxProp.node.value.type!=="JSXExpressionContainer"){return null}let expr=tsxProp.node.value.expression;if(expr.type==="ObjectExpression"){let props,stack;props=expr.properties;obj={};stack=[];props.forEach(prop=>{_doProp(prop,obj,stack,this._fnAssert)})}}return obj||null};TsxUtils.prototype.toCamelCase=function(str){return TSX2_UTILS.toCamelCase(str)};TsxUtils.prototype.toKebabCase=function(str){return TSX2_UTILS.toKebabCase(str)};function _doProp(prop,obj,stack,fnAssert){let key,elems,propx,pvType;if(prop.type==="Property"&&(prop.key.type==="Identifier"||prop.key.type==="Literal")){if(prop.key.type==="Identifier"){key=prop.key.name}else{key=prop.key.value}pvType=prop.value.type;if(pvType==="Literal"){obj[key]=prop.value.value}else if(pvType==="Identifier"){obj[key]=prop.value.name}else if(pvType==="ArrayExpression"){obj[key]=[];elems=prop.value.elements;elems.forEach(elem=>{if(elem.type==="Literal"){obj[key].push(elem.value)}else if(elem.type==="ObjectExpression"){elem.properties.forEach(prop=>{stack.push(obj);obj={};propx=_doProp(prop,obj,stack,fnAssert);obj=stack.pop();obj[key].push(propx)})}})}else if(pvType==="FunctionExpression"){obj[key]=prop.value.body.body}else if(pvType==="ArrowFunctionExpression"){obj[key]=prop.value.body}else if(pvType==="ObjectExpression"){let o,p,i,objProps=prop.value.properties;stack.push(obj);obj[key]=o={};obj=o;for(i=0;i<objProps.length;i++){p=objProps[i];if(p.key.type==="Identifier"){if(p.value.type==="Literal"){o[p.key.name]=p.value.value}else if(p.value.type==="ObjectExpression"){_doProp(p,obj,stack,fnAssert);obj=stack.pop()}else if(p.value.type==="Identifier"){o[p.key.name]=p.value.name}else if(p.value.type==="ArrowFunctionExpression"){o[p.key.name]=p.value}else{fnAssert(`TsxUtils._doProp file line=${prop?.loc.start.line} ${p.value.type}`)}}}}else if(pvType==="MemberExpression"){obj[key]=prop.value}else if(pvType==="TemplateLiteral"){obj[key]=null}else if(pvType==="LogicalExpression"){obj[key]=prop.value}else if(pvType==="CallExpression"){obj[key]=prop.value}else if(pvType==="ConditionalExpression"){obj[key]=prop.value}else if(pvType==="AssignmentPattern"){fnAssert(`TsxUtils._doProp2 unhandled prop key '${key}' value type '${pvType}', file line=${prop?.loc.start.line}`);obj[key]="?"}else{fnAssert(`TsxUtils._doProp3 unhandled prop key '${key}' value type '${pvType}', file line=${prop?.loc.start.line}`);obj[key]="?"}}return obj};TsxUtils.prototype.setIssuePosition=function(issue,obj){if(obj.type===TSX_COMPONENT||obj.type===TSX_PROPERTY){let loc=obj.loc;issue.setPosition(loc.start.line,loc.start.column,obj.range[0],obj.range[1])}else{issue.setPosition(0,0,0,0)}};TsxUtils.prototype.setIssuePropValuePosition=function(issue,tsxProp){if(tsxProp.type==="TsxProperty"){let loc=tsxProp.node.value.loc;issue.setPosition(loc.start.line,loc.start.column,tsxProp.node.value.range[0],tsxProp.node.value.range[1])}else{issue.setPosition(0,0,0,0)}};TsxUtils.prototype.getRawtext=function(ruleCtx,tsxRC){return ruleCtx&&tsxRC&&tsxRC.range?ruleCtx.data.substring(tsxRC.range[0],tsxRC.range[1]):""};TsxUtils.prototype._onTsxRC=function(ruleCtx,tsxRC,cb){var comps,tsxComp,ret,i;if(!(comps=tsxRC.components)){return}for(i=0;i<comps.length;i++){tsxComp=comps[i];ret=this._checkComp(ruleCtx,tsxComp,cb);if(ret===CB_END){break}};cb(ruleCtx,null)};TsxUtils.prototype._checkComp=function(ruleCtx,tsxComp,cb){var props;if(props=tsxComp.properties){let prop,ret,i;for(i=0;i<props.length;i++){prop=props[i];ret=cb(ruleCtx,prop);if(ret===CB_END||ret===CB_NEXT_COMP){return ret}};}if(tsxComp.children){tsxComp.children.forEach(child=>{this._checkComp(ruleCtx,child,cb)})}};TsxUtils.prototype.getSlotParent=function(ruleCtx,tsxProp,slotName){var parent,isOjDefer=false,ret=null;parent=tsxProp.parent;if(!(parent=parent.parent)){return}isOjDefer=parent.name==="oj-defer";if(parent&&parent.name){if(parent.name!==BODY){if(ruleCtx.utils.metaLib.isTagSlotName(parent.name,slotName)){ret=parent}if(!ret){if(isOjDefer&&parent.name===TEMPLATE||parent.name==="oj-switcher"){ret=parent}else if(parent.name===TEMPLATE||parent.name.startsWith(OJ_BIND)||parent.name===OJ_DEFER){ret=_continueUpwards(ruleCtx,parent,slotName)}}}}return ret};TsxUtils.prototype.isChildOfElem=function(elemName,tsxComp){var ret=null;while(tsxComp.parent){if(tsxComp.parent.name===elemName){ret=tsxComp.parent;break}tsxComp=tsxComp.parent}return ret};function _continueUpwards(ruleCtx,tsxComp,slotName){var ret=null,parent,tagName;while(parent=tsxComp.parent){tagName=parent.name;if(tagName===TEMPLATE||tagName.startsWith(OJ_BIND)||tagName===OJ_DEFER){tsxComp=parent;continue}if(parent.name!==BODY){if(ruleCtx.utils.metaLib.isTagSlotName(tagName,slotName)){ret=parent}}break}return ret};function _isObject(value){return typeof value==="object"&&!Array.isArray(value)};TsxUtils.prototype.setMetaLib=function(metaLib){this._metaLib=metaLib};TsxUtils.prototype.isCommonElem=function(elem){return HTML_UTILS.isCommonElem(elem)};TsxUtils.prototype.isCommonAttr=function(attrName){return TSX2_UTILS.isCommonProp(attrName)||this.isAriaAttr(attrName)};TsxUtils.prototype.isCommonEventAttr=function(attrName){return TSX2_UTILS.isCommonEventProp(attrName)};TsxUtils.prototype.isHtml5ObsoleteElem=function(tag){return HTML_UTILS.isHtml5ObsoleteElem(tag)};TsxUtils.prototype.isAriaAttr=function(attr){return HTML_UTILS.isAriaAttr(attr)};TsxUtils.prototype.isSelfClosingTag=function(tag){return HTML_UTILS.isSelfClosingTag(tag)};TsxUtils.prototype.isSvgElem=function(elem){return HTML_UTILS.isSvgElem(elem)};module.exports=TsxUtils;
|
package/lib/checkage.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 BUILT="2025-
|
|
6
|
+
const BUILT="2025-03-20T14:20:02.194Z";const MAJOR_RELS=2;function CheckAge(burnedInJetVer,msgCtx){this._jetRels=-1;this._msgCtx=msgCtx;this._burnedInMajor=parseInt(burnedInJetVer.split(".")[0])};CheckAge.prototype.checkAge=function(){var curDate;var buildDate;var buildMonth;var monthsToNow;curDate=new Date;buildDate=BUILT==="@BUILT@"?curDate:new Date(BUILT);buildMonth=buildDate.getMonth()+1;monthsToNow=_getElapsedMonths(buildDate,curDate);if(!monthsToNow){this._jetRels=0}else{this._jetRels=_getReleases(buildMonth,monthsToNow);if(this._jetRels>MAJOR_RELS){this._emitMsg(monthsToNow)}}return this._jetRels};CheckAge.prototype.getJafReleaseCount=function(){return this._jetRels};CheckAge.prototype.getMajorReleaseCount=function(major){if(typeof major==="string"){let a=major.split(".");major=parseInt(a[0])}if(isNaN(major)){return this._jetRels}let estimatedMajor=this._burnedInMajor+this._jetRels;return estimatedMajor-major};CheckAge.prototype._emitMsg=function(old){var INDENT=" ".repeat(12);var s,h,p;if(this._jetRels){s=""+this._jetRels;if(this._jetRels===1){h="has";p=""}else{h="have";p="s"}}else{s="at least one";h="has";p=""}var s=`\nThis version of JAF is ${old} month${old===1?"":"s"} old, and there ${h} been ${s} scheduled public\n`+`${INDENT}major JET release${p}, together with JAF updates and fixes. It is strongly\n`+INDENT+"recommended that you install the latest version of JAF. [JAF-9100]\n";this._msgCtx.warn(s,"JAF-9100",true)};function _getElapsedMonths(start,end){return end.getMonth()-start.getMonth()+12*(end.getFullYear()-start.getFullYear())};function _getReleases(buildMonth,months){var toNextRel,releases=0;if(buildMonth===1){toNextRel=0}else if(buildMonth>1&&buildMonth<7){toNextRel=7-buildMonth}else if(buildMonth===7){toNextRel=0}else{toNextRel=13-buildMonth}if((releases=months-toNextRel)>=0){releases=1+Math.floor(releases/6)}else{releases=0}return releases};module.exports=CheckAge;
|
package/lib/defaults.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 defaults={JETVER:"18.0.
|
|
6
|
+
const defaults={JETVER:"18.0.3".replace(/(\d*\.\d*)(\.\d*)+$/g,"$1")+".0",THEME:"Alta",ECMAVER:14};module.exports=defaults;
|
|
@@ -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 JAF_TEMP="jaf";const WORKING_ROOT_FOLDER="ts-temp";const TSCONFIG_JSON="tsconfig.json";const VCOMP_MSG_PREFIX="VComponent Processing:";var path;const PreCompiler=function(utils,jafUtils,fsUtils,msgCtx,semVer,nd){this._utils=utils;this._jafUtils=jafUtils;this._fsUtils=fsUtils;this._semVer=semVer;this._error=msgCtx.error;this._info=msgCtx.info;this._msg=msgCtx.msg;this._debug=msgCtx.debug;this._jafMsg=msgCtx.jafMsg;this._isDebug=msgCtx.isDebug;this._isVerbose=msgCtx.isVerbose;this._isVerboseOrDebug=this._isVerbose||this._isDebug;path=nd.path;this._workingRootFolder=this._utils.toJAFPath(path.join(nd.os.tmpdir(),JAF_TEMP,WORKING_ROOT_FOLDER));this._runOnce=false;this._vfiles=null};PreCompiler.prototype.getPrecompileCache=function(auditBase,tsSource,componentRootFolder){if(!this.runOnce){this._runOnce=true;this._precompileCache=this._transformVComponents(path.join(auditBase,TSCONFIG_JSON),auditBase,tsSource,componentRootFolder)}return this._precompileCache};PreCompiler.prototype.getVFiles=function(){return this._vfiles};PreCompiler.prototype._transformVComponents=function(tsConfigPath,auditBase,sourceBase,componentBase){const normalizedTsConfigPath=this._fsUtils.toJAFPath(tsConfigPath);if(!this._fsUtils.fileExistsSync(normalizedTsConfigPath)){if(this._isVerboseOrDebug){this._info(`Skipping pre-compilation - Typescript configuration file '${tsConfigPath}' not found!`)}return}const outputFolder=this._fsUtils.getUniqueFileNameSync("_XXXXXX");const compiledOutputFolder=this._utils.toJAFPath(`${this._workingRootFolder}/js${outputFolder}`);const compiledJSONFolder=this._utils.toJAFPath(`${this._workingRootFolder}/json${outputFolder}`);const allTsConfig=this._fsUtils.readJsonSync(tsConfigPath,true,error=>this._error(`Typescript configuration file ${tsConfigPath} cannot be read, unable to process VComponents.\nError: ${error}`));if(!allTsConfig){return}if(this._isDebug){this._debug(
|
|
6
|
+
const JAF_TEMP="jaf";const WORKING_ROOT_FOLDER="ts-temp";const TSCONFIG_JSON="tsconfig.json";const VCOMP_MSG_PREFIX="VComponent Processing:";var path;const PreCompiler=function(utils,jafUtils,fsUtils,msgCtx,semVer,nd){this._utils=utils;this._jafUtils=jafUtils;this._fsUtils=fsUtils;this._semVer=semVer;this._error=msgCtx.error;this._info=msgCtx.info;this._msg=msgCtx.msg;this._debug=msgCtx.debug;this._jafMsg=msgCtx.jafMsg;this._isDebug=msgCtx.isDebug;this._isVerbose=msgCtx.isVerbose;this._isVerboseOrDebug=this._isVerbose||this._isDebug;path=nd.path;this._workingRootFolder=this._utils.toJAFPath(path.join(nd.os.tmpdir(),JAF_TEMP,WORKING_ROOT_FOLDER));this._runOnce=false;this._vfiles=null};PreCompiler.prototype.getPrecompileCache=function(auditBase,tsSource,componentRootFolder){if(!this.runOnce){this._runOnce=true;if(this._isDebug){this._debug(`getPrecompileCache ->\n auditBase=\"${auditBase}\"\n tsSource=\"${tsSource}\"\n componentRootFolder=\"${componentRootFolder}\"`)}this._precompileCache=this._transformVComponents(path.join(auditBase,TSCONFIG_JSON),auditBase,tsSource,componentRootFolder)}return this._precompileCache};PreCompiler.prototype.getVFiles=function(){return this._vfiles};PreCompiler.prototype._transformVComponents=function(tsConfigPath,auditBase,sourceBase,componentBase){const normalizedTsConfigPath=this._fsUtils.toJAFPath(tsConfigPath);if(!this._fsUtils.fileExistsSync(normalizedTsConfigPath)){if(this._isVerboseOrDebug){this._info(`Skipping pre-compilation - Typescript configuration file '${tsConfigPath}' not found!`)}return}const outputFolder=this._fsUtils.getUniqueFileNameSync("_XXXXXX");const compiledOutputFolder=this._utils.toJAFPath(`${this._workingRootFolder}/js${outputFolder}`);const compiledJSONFolder=this._utils.toJAFPath(`${this._workingRootFolder}/json${outputFolder}`);const allTsConfig=this._fsUtils.readJsonSync(tsConfigPath,true,error=>this._error(`Typescript configuration file ${tsConfigPath} cannot be read, unable to process VComponents.\nError: ${error}`));if(!allTsConfig){return}if(this._isDebug){this._debug(`\nTypeScript Config ->\n${JSON.stringify(allTsConfig,null,3)}`)}if(this._isVerboseOrDebug){this._msg(`\n${VCOMP_MSG_PREFIX} Compiling project ...`)}if(this._isDebug){this._debug(`...transforming to full paths ->\n componentBase=\"${componentBase}\"\n auditBase=\"${auditBase}\"\n sourceBase=\"${sourceBase}\"\n componentBase=\"${componentBase}\"\n`)}allTsConfig.compilerOptions.paths[`${componentBase}/*`]=[`${auditBase}/${sourceBase}/${componentBase}/*`];const sourceBaseRoot=sourceBase.includes("/")?sourceBase.split("/")[0]:sourceBase;Object.entries(allTsConfig.compilerOptions.paths).forEach(([pathKey,pathValues])=>{if(this._isDebug){this._debug(`pathKey -> ${pathKey} pathValues -> ${pathValues}`)};const remapped=pathValues.map(mappedPath=>{return this._remapPath(mappedPath,sourceBaseRoot,auditBase)});allTsConfig.compilerOptions.paths[pathKey]=remapped});if(allTsConfig.compilerOptions.hasOwnProperty("typeRoots")){allTsConfig.compilerOptions.typeRoots=allTsConfig.compilerOptions.typeRoots.map(typeroot=>this._remapPath(typeroot,sourceBaseRoot,auditBase))}else if(this._isVerboseOrDebug){this._msg(`${VCOMP_MSG_PREFIX} tsconfig 'typeRoots' property not defined ...`)}if(allTsConfig.compilerOptions.hasOwnProperty("types")){allTsConfig.compilerOptions.types=allTsConfig.compilerOptions.types.map(type=>this._remapPath(type,sourceBaseRoot,auditBase))}else if(this._isVerboseOrDebug){this._msg(`${VCOMP_MSG_PREFIX} tsconfig 'types' property not defined ...`)}allTsConfig.compilerOptions.rootDir=auditBase;allTsConfig.compilerOptions.outDir=compiledOutputFolder;if(!this._fsUtils.pathExistsSync(this._workingRootFolder)){this._fsUtils.createFolderSync(this._workingRootFolder)}else{this._fsUtils.deleteFolderSync(this._workingRootFolder,false)}if(this._isVerboseOrDebug){this._msg(`${VCOMP_MSG_PREFIX} Typescript will be compiled into '${this._workingRootFolder}'`)}let nodeJetRoot=path.join(auditBase,"node_modules","@oracle","oraclejet");if(!this._fsUtils.pathExistsSync(nodeJetRoot)){nodeJetRoot=path.normalize(path.join(auditBase,"..","..","node_modules","@oracle","oraclejet"))}let nodeJetPackage=path.join(nodeJetRoot,"package.json");let customTsc=this._utils.toJAFPath(path.join(nodeJetRoot,"dist","custom-tsc"));if(!this._fsUtils.pathExistsSync(customTsc)||!this._fsUtils.pathExistsSync(nodeJetPackage)){this._error("Unable to run VComponent pre-compilation -the required packages are not available. Run \"ojet restore\" or \"npm install\" to correct this.");return}let jetVerString;const packageJson=this._fsUtils.readJsonSync(nodeJetPackage);if(packageJson){jetVerString=packageJson.version}if(this._isVerboseOrDebug){this._msg(`${VCOMP_MSG_PREFIX} oraclejet package version -> ${jetVerString?jetVerString:"not found"}`)}let CustomTypeScriptCompiler;if(this._isVerboseOrDebug){this._msg(`${VCOMP_MSG_PREFIX} loading TypeScript compiler...`)}try{CustomTypeScriptCompiler=require(customTsc)}catch(e){this._jafMsg("jaf-ts-loader",`${VCOMP_MSG_PREFIX} failure loading TypeScript <- '${customTsc}'`)}if(!CustomTypeScriptCompiler){return}const readFrom=path.join(auditBase,sourceBase);let files=this._discoverCompilableFiles(readFrom,readFrom);if(!files||!files.length){return}files.forEach((file,x)=>{files[x]=this._utils.toJAFPath(file)});if(this._isDebug){this._displayCompilableList(files)}const buildOptions={debug:false,dtDir:compiledJSONFolder,version:"",jetVersion:"",templatePath:path.join(customTsc,"templates"),tsBuiltDir:compiledOutputFolder,typesDir:compiledOutputFolder};const compileOptionsPre12={files,compilerOptions:allTsConfig.compilerOptions,buildOptions:buildOptions};const compileOptions1201={tsconfigJson:{compilerOptions:allTsConfig.compilerOptions,files},buildOptions:buildOptions};let compileOptions;if(jetVerString){if(this._semVer.gt(jetVerString,"12.0.0")){compileOptions=compileOptions1201}else{compileOptions=compileOptionsPre12}if(this._semVer.lt(jetVerString,"16.0.0")){compileOptions.mainEntryFile="loader.d.ts"}}if(compileOptions){if(this._isDebug){this._debug(`Using TypeScript compile options ->\n${JSON.stringify(compileOptions,null,3)}\n`)}try{if(this._isVerboseOrDebug){this._msg(`${VCOMP_MSG_PREFIX} compiling ${files.length} file${files.length>1?"s":""}...`)}const{errors}=CustomTypeScriptCompiler.compile(compileOptions);if(errors.length){this._error(`${errors.length} Error${errors.length>1?"s":""} found during TypeScript pre-compilation of VComponents`);errors.forEach(error=>{if(error.hasOwnProperty("message")){this._error(error.message);this._error(error.stack)}else{this._jafMsg("jaf-ts-precompile",JSON.stringify(error))}})}else{this._msg(`${VCOMP_MSG_PREFIX} Typescript compilation of ${files.length} file${files.length!==1?"s":""} successful ...`)}if(!errors.length){this._vfiles=files}return compiledJSONFolder}catch(uncaughtFromCompile){this._error("Uncaught error during TypeScript pre-compilation of VComponents");this._error(uncaughtFromCompile.stack)}}else{this._error("Unable to run VComponent pre-compilation, cannot detect JET custom compiler version")}};PreCompiler.prototype._discoverCompilableFiles=function(root,pathPrefix){const allSources=this._fsUtils.readDirSync(root);return allSources?this._extractCompilables(allSources,"").map(sourceFile=>`${pathPrefix}/${sourceFile}`):null};PreCompiler.prototype._extractCompilables=function(sources,folder){return sources.reduce((compilables,candidate)=>{if(candidate.isFile&&(candidate.name.endsWith(".ts")||candidate.name.endsWith(".tsx"))){compilables.push(`${folder}/${candidate.name}`)}else if(candidate.files){compilables=compilables.concat(this._extractCompilables(candidate.files,`${folder}/${candidate.name}`))}return compilables},new Array)};PreCompiler.prototype._remapPath=function(definedPath,sourceFolder,auditBase){let newPath=definedPath;const segs=definedPath.split("/");if(segs[0]==="."){segs.shift()}switch(segs[0]){case"node_modules":case"jet_components":case"exchange_components":case sourceFolder:newPath=`${auditBase}${segs.join("/")}`;break}return newPath};PreCompiler.prototype._displayCompilableList=function(files){let count=0;let flist;if(files&&files.length){count=files.length;flist="\n "+files.join("\n ")}this._debug(`VComponents: discovered ${count} compilable files:${flist}`)};module.exports=PreCompiler;
|