@oracle/oraclejet-audit 15.1.8 → 16.0.0

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 (150) 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/AstNodeTypes.js +1 -1
  38. package/lib/Components.js +1 -1
  39. package/lib/DomUtils.js +1 -1
  40. package/lib/FsUtils.js +1 -1
  41. package/lib/HtmlUtils.js +1 -1
  42. package/lib/JafLib.js +1 -1
  43. package/lib/MetaLib.js +1 -1
  44. package/lib/OjCPack.js +1 -1
  45. package/lib/Registry.js +1 -1
  46. package/lib/RulePack.js +1 -1
  47. package/lib/RuleSet.js +1 -1
  48. package/lib/Rules.js +1 -1
  49. package/lib/Stats.js +1 -1
  50. package/lib/Ts.js +1 -1
  51. package/lib/TsUtils.js +6 -0
  52. package/lib/TsxUtils.js +1 -1
  53. package/lib/TsxUtils2.js +1 -1
  54. package/lib/Utils.js +1 -1
  55. package/lib/checkage.js +1 -1
  56. package/lib/defaults.js +1 -1
  57. package/lib/jsx.js +1 -1
  58. package/lib/migrator.js +1 -1
  59. package/lib/scaffold.js +1 -1
  60. package/lib/sublib/precomp/ComponentFinder.js +6 -0
  61. package/lib/sublib/precomp/Precompiler.js +6 -0
  62. package/lib/sublib/precomp/TsxUtils.js +6 -0
  63. package/lib/sublib/precomp/Utils.js +6 -0
  64. package/meta/15.0.0/jetauditmeta.js +1 -1
  65. package/meta/15.1.0/jetauditmeta.js +1 -1
  66. package/meta/16.0.0/jetauditmeta.js +9 -0
  67. package/meta/metaverlist.json +1 -1
  68. package/package.json +10 -7
  69. package/profiles/best-practice.json +1 -0
  70. package/rulepacks/csp/csp-json-unsafe-expr.js +1 -1
  71. package/rulepacks/jetwc/jetwc-bootstrap.js +1 -1
  72. package/rulepacks/jetwc/jetwc-require-paths.js +1 -1
  73. package/rulepacks/jetwc/jetwc-schema.js +1 -1
  74. package/rulepacks/jetwc/jetwc-well-formed-description.js +6 -0
  75. package/rulepacks/jetwc/msgid.json +1 -1
  76. package/rulepacks/jetwc/rules.json +1 -1
  77. package/rulepacks/jetwc-lib/jetwcutils-componentAuditUtils.js +1 -1
  78. package/rulepacks/jetwc-lib/jetwcutils-componentFinder.js +1 -1
  79. package/rulepacks/jetwc-lib/jetwcutils-tsxUtils.js +1 -1
  80. package/rulepacks/jetwco/jetwco-bootstrap.js +1 -1
  81. package/rulepacks/jetwco/jetwco-cacc-methodParamTypes.js +1 -1
  82. package/rulepacks/jetwco/jetwco-cacc-methodReturnType.js +1 -1
  83. package/rulepacks/jetwco/jetwco-description-standards.js +1 -1
  84. package/rulepacks/jetwco/jetwco-license-info.js +1 -1
  85. package/rulepacks/jetwco/jetwco-validate-applied-audits.js +6 -0
  86. package/rulepacks/jetwco/msgid.json +1 -1
  87. package/rulepacks/jetwco/rules.json +1 -1
  88. package/rulepacks/ojc/msgid.json +1 -1
  89. package/rulepacks/ojc/ojc-html-button-defslot.js +6 -0
  90. package/rulepacks/ojc/ojc-tsx-button-defslot.js +6 -0
  91. package/rulepacks/ojc/rules.json +1 -1
  92. package/rules/jaf/jaf-css-diagnose.js +1 -1
  93. package/rules/jaf/jaf-js-diagnose.js +1 -1
  94. package/rules/jaf/jaf-sys-dup-component.js +6 -0
  95. package/rules/jaf/jaf-sys-rule-opt.js +6 -0
  96. package/rules/jaf/jaf-ts-precompile.js +6 -0
  97. package/rules/jaf/msgid.json +1 -1
  98. package/rules/jaf/rules.json +1 -1
  99. package/rules/jet/helpers/has-slot-name.js +1 -1
  100. package/rules/jet/msgid.json +1 -1
  101. package/rules/jet/oj-cca-compjson-bp-jetver.js +1 -1
  102. package/rules/jet/oj-html-alta-deprecated.js +1 -1
  103. package/rules/jet/oj-html-attr-expr-writeback.js +6 -0
  104. package/rules/jet/oj-html-binding-as-slot-child.js +6 -0
  105. package/rules/jet/oj-html-event-focus-blur.js +6 -0
  106. package/rules/jet/oj-html-form-bindif.js +1 -1
  107. package/rules/jet/oj-html-ojattr-deprecated.js +1 -1
  108. package/rules/jet/oj-html-ojattr-enum-deprecated.js +1 -1
  109. package/rules/jet/oj-html-ojattr.js +1 -1
  110. package/rules/jet/oj-html-ojtag-deprecated.js +1 -1
  111. package/rules/jet/oj-html-ojtag-nonglobattr-prefix.js +1 -1
  112. package/rules/jet/oj-html-prop-anti-pattern.js +6 -0
  113. package/rules/jet/oj-html-slot-default.js +6 -0
  114. package/rules/jet/oj-html-slot-deprecated.js +1 -1
  115. package/rules/jet/oj-html-slot-name.js +1 -1
  116. package/rules/jet/oj-html-slot-pref-content.js +1 -1
  117. package/rules/jet/oj-html-style-deprecated.js +1 -1
  118. package/rules/jet/oj-html-treeview-actionable-content.js +6 -0
  119. package/rules/jet/oj-html-wctag-anti-pattern.js +6 -0
  120. package/rules/jet/oj-html-wctag-maintenance.js +1 -1
  121. package/rules/jet/oj-html-wctag-supersedes.js +1 -1
  122. package/rules/jet/oj-js-ojcomp-exist.js +1 -1
  123. package/rules/jet/oj-ts-ojcomp-exist.js +1 -1
  124. package/rules/jet/oj-tsx-aria-ojselector-labelledby.js +1 -1
  125. package/rules/jet/oj-tsx-aria-prop.js +1 -1
  126. package/rules/jet/oj-tsx-event.js +6 -0
  127. package/rules/jet/oj-tsx-ojattr-deprecated.js +1 -1
  128. package/rules/jet/oj-tsx-ojattr-enum-deprecated.js +1 -1
  129. package/rules/jet/oj-tsx-ojattr-value.js +1 -1
  130. package/rules/jet/oj-tsx-ojattr.js +1 -1
  131. package/rules/jet/oj-tsx-ojtag-deprecated.js +1 -1
  132. package/rules/jet/oj-tsx-pageopts-type.js +1 -1
  133. package/rules/jet/oj-tsx-picker-attrs.js +1 -1
  134. package/rules/jet/oj-tsx-popup-sibling.js +6 -0
  135. package/rules/jet/oj-tsx-prop-anti-pattern.js +6 -0
  136. package/rules/jet/oj-tsx-rating-gauge-size.js +1 -1
  137. package/rules/jet/oj-tsx-rating-gauge-track-resize.js +1 -1
  138. package/rules/jet/oj-tsx-slot-deprecated.js +1 -1
  139. package/rules/jet/oj-tsx-slot-pref-content.js +1 -1
  140. package/rules/jet/oj-tsx-treeview-actionable-content.js +6 -0
  141. package/rules/jet/oj-tsx-unsup-theme.js +1 -1
  142. package/rules/jet/oj-tsx-wctag-anti-pattern.js +6 -0
  143. package/rules/jet/oj-tsx-wctag-maintenance.js +1 -1
  144. package/rules/jet/rules.json +1 -1
  145. package/schema/component-schema.json +1 -1
  146. package/src/JafCore.js +1 -1
  147. package/types/index.d.ts +1 -0
  148. package/rulepacks/jetwc-lib/jetwcutils-preCompiler.js +0 -6
  149. package/rules/jet/oj-html-combo-converter.js +0 -6
  150. package/rules/jet/oj-tsx-combo-converter.js +0 -6
@@ -0,0 +1,37 @@
1
+ {
2
+ "legacyTag": "oj-selector",
3
+ "corePackTag": "oj-c-selector",
4
+ "migrateImports": {
5
+ "from": "ojs/ojselector",
6
+ "to": [
7
+ "oj-c/selector",
8
+ "oj-c/selector-all"
9
+ ]
10
+ },
11
+ "migrateTagByAttribute": [
12
+ {
13
+ "fromTag": "oj-selector",
14
+ "toTag": "oj-c-selector",
15
+ "attribute": "selection-mode",
16
+ "attributeValue": "singular"
17
+ },
18
+ {
19
+ "fromTag": "oj-selector",
20
+ "toTag": "oj-c-selector",
21
+ "attribute": "selection-mode",
22
+ "attributeValue": "multiple"
23
+ },
24
+ {
25
+ "fromTag": "oj-selector",
26
+ "toTag": "oj-c-selector-all",
27
+ "attribute": "selection-mode",
28
+ "attributeValue": "all"
29
+ },
30
+ {
31
+ "fromTag": "oj-selector",
32
+ "toTag": "oj-c-selector",
33
+ "attribute": "",
34
+ "attributeValue": ""
35
+ }
36
+ ]
37
+ }
@@ -6,6 +6,12 @@
6
6
  "to": ["oj-c/meter-bar", "oj-c/meter-circle", "oj-c/rating-gauge"]
7
7
  },
8
8
  "migrateTagByAttribute": [
9
+ {
10
+ "fromTag": "oj-status-meter-gauge",
11
+ "toTag": "oj-c-meter-circle",
12
+ "attribute": "orientation",
13
+ "attributeValue": "circular"
14
+ },
9
15
  {
10
16
  "fromTag": "oj-status-meter-gauge",
11
17
  "toTag": "oj-c-meter-bar",
@@ -20,9 +26,9 @@
20
26
  },
21
27
  {
22
28
  "fromTag": "oj-status-meter-gauge",
23
- "toTag": "oj-c-meter-circle",
24
- "attribute": "orientation",
25
- "attributeValue": "circular"
29
+ "toTag": "oj-c-meter-bar",
30
+ "attribute": "",
31
+ "attributeValue": ""
26
32
  }
27
33
  ],
28
34
  "migrateAttributes": [
@@ -74,12 +80,6 @@
74
80
  "toAttribute": "thresholds.accessibleLabel",
75
81
  "toValue": ""
76
82
  },
77
- {
78
- "fromAttribute": "",
79
- "fromValue": "",
80
- "toAttribute": "orientation",
81
- "toValue": "horizontal"
82
- },
83
83
  {
84
84
  "fromAttribute": "threshold-display",
85
85
  "fromValue": "currentOnly",
@@ -91,6 +91,18 @@
91
91
  "fromValue": "onIndicator",
92
92
  "toAttribute": "threshold-display",
93
93
  "toValue": "indicator"
94
+ },
95
+ {
96
+ "fromAttribute": "thresholdDisplay",
97
+ "fromValue": "currentOnly",
98
+ "toAttribute": "thresholdDisplay",
99
+ "toValue": "plotArea"
100
+ },
101
+ {
102
+ "fromAttribute": "thresholdDisplay",
103
+ "fromValue": "onIndicator",
104
+ "toAttribute": "thresholdDisplay",
105
+ "toValue": "indicator"
94
106
  }
95
107
  ],
96
108
  "NOT COMPLETE YET. NEED TO ADD MORE": {
@@ -0,0 +1,8 @@
1
+ {
2
+ "legacyTag": "oj-tag-cloud",
3
+ "corePackTag": "oj-c-tag-cloud",
4
+ "migrateImports": {
5
+ "from": "ojs/ojtagcloud",
6
+ "to": "oj-c/tag-cloud"
7
+ }
8
+ }
@@ -30,9 +30,15 @@
30
30
  "toValue": ""
31
31
  },
32
32
  {
33
- "fromAttribute": "labeledge",
33
+ "fromAttribute": "label-edge",
34
34
  "fromValue": "provided",
35
- "toAttribute": "labeledge",
35
+ "toAttribute": "",
36
+ "toValue": ""
37
+ },
38
+ {
39
+ "fromAttribute": "labelEdge",
40
+ "fromValue": "provided",
41
+ "toAttribute": "",
36
42
  "toValue": ""
37
43
  }
38
44
  ],
@@ -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 estree=require("@typescript-eslint/typescript-estree");const traverse=require("ast-traverse");const logging=require("../utilities/logging");function _checkFileUpdate(){if(!global.fileIsUpdated){global.fileIsUpdated=true;global.migrationMetrics.files+=1;logging.logFilePath(global.filePath);return true}return false}function _generateAST(code){return estree.parse(code,{comment:true,filePath:global.filePath,jsx:true,loc:true,range:true})}function _commentJSXNode(text,locObj){let dataArray=text.split("\n");let{start,end}=locObj;let startString=dataArray[start.line-1];dataArray[start.line-1]=[startString.slice(0,start.column)," {/* ",startString.slice(start.column)].join("");let endString=dataArray[end.line-1];if(start.line===end.line){end.column+=5}dataArray[end.line-1]=[endString.slice(0,end.column)," */} ",endString.slice(end.column)].join("");text=dataArray.join("\n");return text}function _getText(text,locObj){let specificText;const dataArray=text.split("\n");const{start,end}=locObj;if(start.line===end.line){specificText=dataArray[start.line-1].substring(start.column,end.column);return specificText}else{dataArray[start.line-1]=dataArray[start.line-1].substring(start.column);const textByLines=dataArray.slice(start.line-1,end.line).map(s=>s.trim());specificText=textByLines.join("\n");return specificText}}function _updateText(text,locObj,replaceString){let replaceArray=replaceString.split("");let dataArray=text.split("\n");let{start,end}=locObj;if(start.line!=end.line){let firtLineArray=dataArray[locObj.start.line-1].split("");dataArray[locObj.start.line-1]=firtLineArray.splice(0,start.column).concat(...replaceArray).join("");for(let i=locObj.end.line-2;i>start.line-1;i--){dataArray[i]=""}let lastLineArray=dataArray[end.line-1].split("");dataArray[end.line-1]=lastLineArray.splice(end.column,end.column).join("")}else{let updateLineArray=dataArray[locObj.start.line-1].split("");updateLineArray.splice(locObj.start.column,locObj.end.column-locObj.start.column,...replaceArray);dataArray[locObj.start.line-1]=updateLineArray.join("")}text=dataArray.join("\n");return text}function _appendText(text,locObj,appendString){let appendArray=appendString.split("");let dataArray=text.split("\n");let updateLineArray=dataArray[locObj.end.line-1].split("");updateLineArray.splice(locObj.end.column+1,0,...appendArray);dataArray[locObj.end.line-1]=updateLineArray.join("");text=dataArray.join("\n");return text}function _getLabelFromASTDOMNode(astnode,code){let label="";for(let currentNode of astnode.children){if(currentNode.type=="JSXText"){if(/\S/.test(currentNode.value)){label=currentNode.value.trim()}}else if(currentNode.type=="JSXExpressionContainer"){if(currentNode.expression&&currentNode.expression.type!="JSXEmptyExpression"){expression=_getText(code,currentNode.loc);label={expression:expression}}}else if(currentNode.type=="JSXElement"&&currentNode.openingElement.name.name.toUpperCase()=="OJ-BIND-TEXT"){currentNode.openingElement.attributes.forEach(attr=>{if(attr.name.name=="value")label=attr.value.value})}else if(currentNode.children){label=_getLabelFromASTDOMNode(currentNode,code)}}return label}function _getLabelFromLegacyButton(astnode,slotName,code){for(let child of astnode.children){switch(child.type){case"JSXText":if(/\S/.test(child.value)){return{label:child.value.trim(),cnode:child}}break;case"JSXExpressionContainer":if(child.expression&&child.expression.type!="JSXEmptyExpression"){expression=_getText(code,child.loc);return{label:{expression:expression},cnode:child}}break;case"JSXElement":let slotValue;switch(child.openingElement.name.name.toUpperCase()){case"SPAN":case"DIV":child.openingElement.attributes.forEach(attr=>{if(attr.name.name=="slot"&&(attr.value.value===slotName||!attr.value.value.length))slotValue=true});if(!child.openingElement.attributes.map(att=>att.name.name).includes("slot")){slotValue=true}if(slotValue){let label=_getLabelFromASTDOMNode(child,code);return{label:label,cnode:child}}break}break}}}function _hasAttributesToIgnore(component,ignoreRuleData){if(ignoreRuleData&&component.attributes.length){for(let obj of ignoreRuleData){for(let i=0;i<component.attributes.length;i++){let attribute=component.attributes[i];if(obj.attribute&&obj.attribute===attribute.name.name){_checkFileUpdate();logging.logIgnoreComponent(component.name.name,obj.attribute);return true}let arr=Object.keys(obj);let key=arr[0];if(attribute.name.name===key&&attribute.value.value===obj[key]){_checkFileUpdate();logging.logIgnoreComponent(component.name.name,key,obj[key]);return true}}}}return false}function _hasExpressionAttributes(component,code,isPre=false){const excludedAttributes=global.configData.excludeAttributeExpressions[component.name.name];if(global.jaf.options.dryRunMode&&isPre){component.attributes.forEach(attribute=>{if(attribute.value&&attribute.value.type==="JSXExpressionContainer"){const expression=_getText(code,attribute.value.loc);if(_checkFileUpdate()){logging.logAttributeExpression(component.name.name,attribute.name.name,expression)}}})}if(excludedAttributes&&excludedAttributes.length){for(let exAtt of excludedAttributes){for(let i=0;i<component.attributes.length;i++){const attribute=component.attributes[i];if(exAtt===attribute.name.name&&attribute.value.type==="JSXExpressionContainer"){const expression=_getText(code,attribute.value.loc);if(isPre){_checkFileUpdate();logging.logExcludeAttributeExpression(component.name.name,exAtt,expression)}return true}}}}return false}function commentSlotContent(code,data,ignoreRuleData,componentName){let ast=_generateAST(code);traverse(ast,{pre:function(node){if(node.type=="JSXElement"&&node.openingElement.name.name===componentName&&(!_hasAttributesToIgnore(node.openingElement,ignoreRuleData)||global.configData.forceMigration.includes(componentName))&&!_hasExpressionAttributes(node.openingElement,code,true)){node.children.forEach(child=>{if(child.openingElement&&child.openingElement.attributes){child.openingElement.attributes.forEach(attribute=>{if(attribute.name.name=="slot"&&attribute.value.value==data.slot){code=_commentJSXNode(code,child.loc);_checkFileUpdate();logging.logCommentSlotContent(componentName,data.slot)}})}})}}});return code}function slotContentToAttribute(code,data,ignoreRuleData,componentName){if(data.attribute||data.slotName){let isUpdated=false;let ast=_generateAST(code);traverse(ast,{pre:function(node){if(!isUpdated&&node.type=="JSXElement"&&node.openingElement.name.name===componentName&&(!_hasAttributesToIgnore(node.openingElement,ignoreRuleData)||global.configData.forceMigration.includes(componentName))&&!_hasExpressionAttributes(node.openingElement,code,true)&&!node.openingElement.attributes.map(att=>att.name.name).includes(data.attribute)){let obj={line:node.openingElement.loc.end.line,column:node.openingElement.loc.end.column-1};const legacyButtonLabel=_getLabelFromLegacyButton(node,data.slotName,code);if(legacyButtonLabel){const{label,cnode}=legacyButtonLabel;if(label){code=_commentJSXNode(code,cnode.loc);code=_updateText(code,{start:obj,end:obj},` ${data.attribute}=${label.expression?`${label.expression}`:`"${label}"`}`);_checkFileUpdate()}logging.logSlotContentToAttribute(componentName,data.attribute,label.expression?label.expression:label);code=slotContentToAttribute(code,data,ignoreRuleData,componentName)}}},post:function(node){if(!isUpdated&&node.type=="JSXElement"&&node.openingElement.name.name===componentName&&(!_hasAttributesToIgnore(node.openingElement,ignoreRuleData)||global.configData.forceMigration.includes(componentName))&&!_hasExpressionAttributes(node.openingElement,code)&&!node.openingElement.attributes.map(att=>att.name.name).includes(data.attribute)){isUpdated=true}}})}return code}function classNameToAttribute(code,data){for(let obj of data){let isUpdated=false;let ast=_generateAST(code);traverse(ast,{pre:function(node){if(!isUpdated&&node.type=="JSXAttribute"&&node.name.name=="class"&&node.value?.value?.includes(obj.className)){if(obj.attribute){classNames=node.value.value.split(" ");index=classNames.indexOf(obj.className);classNames.splice(index,1);if(classNames.length===0){code=_updateText(code,node.loc,obj.attribute+"="+"\""+obj.attributeValue+"\"")}else{code=_updateText(code,node.loc,`class="${classNames.join(" ")}"`);node.loc.end.column-=obj.className.length+2;code=_appendText(code,node.loc,`\n${obj.attribute}="${obj.attributeValue}"`)}_checkFileUpdate();logging.logClassNameToAttribute(obj.className,obj.attribute,obj.attributeValue);code=classNameToAttribute(code,data)}}},post:function(node){if(!isUpdated&&node.type=="JSXAttribute"&&node.name.name=="class"&&node.value?.value?.includes(obj.className)){isUpdated=true}}})}return code}function handleSpecialCase(code,data){let obj;let regex;if(data[1]){obj=data[1];regex=new RegExp(obj.fromString.split(" ").join("\\s*"),"igm");code=code.replace(regex,obj.toString)}obj=data[0];regex=new RegExp(obj.fromString.split(" ").join("\\s*"),"igm");code=code.replace(regex,obj.toString);return code}function migrateTag(code,legacyComponentName,coreComponentName,ignoreRuleData){let isUpdated=false;let ast=_generateAST(code);traverse(ast,{pre:function(node){if(!isUpdated&&node.type=="JSXElement"&&node.openingElement.name.name===legacyComponentName&&(!_hasAttributesToIgnore(node.openingElement,ignoreRuleData)||global.configData.forceMigration.includes(legacyComponentName))&&!_hasExpressionAttributes(node.openingElement,code,true)){code=_updateText(code,node.openingElement.name.loc,coreComponentName);_checkFileUpdate();logging.logTagMigration(legacyComponentName,coreComponentName);global.migrationMetrics.components+=1;if(node.closingElement&&node.closingElement.name.name===legacyComponentName){if(node.openingElement.name.loc.start.line===node.closingElement.name.loc.start.line){const lengthDif=coreComponentName.length-node.closingElement.name.name.length;node.closingElement.name.loc.start.column+=lengthDif;node.closingElement.name.loc.end.column+=lengthDif}code=_updateText(code,node.closingElement.name.loc,coreComponentName)}code=migrateTag(code,legacyComponentName,coreComponentName,ignoreRuleData)}},post:function(node){if(!isUpdated&&node.type=="JSXElement"&&node.openingElement.name.name===legacyComponentName&&(!_hasAttributesToIgnore(node.openingElement,ignoreRuleData)||global.configData.forceMigration.includes(legacyComponentName))&&!_hasExpressionAttributes(node.openingElement,code)){isUpdated=true}}});return code}function migrateTagByAttribute(code,data,ignoreRuleData){for(const tagSet in data){let isUpdated=false;let ast=_generateAST(code);traverse(ast,{pre:function(node){tag=data[tagSet];if(!isUpdated&&node.type=="JSXElement"&&node.openingElement.name.name===tag.fromTag&&(!_hasAttributesToIgnore(node.openingElement,ignoreRuleData)||global.configData.forceMigration.includes(componentName))&&!_hasExpressionAttributes(node.openingElement,code,true)){node.openingElement.attributes.forEach(attribute=>{if(attribute.name.name===tag.attribute&&attribute.value.value===tag.attributeValue){code=_updateText(code,node.openingElement.name.loc,tag.toTag);_checkFileUpdate();logging.logTagMigration(tag.fromTag,tag.toTag);global.migrationMetrics.components+=1;if(node.closingElement&&node.closingElement.name.name===tag.fromTag){if(node.openingElement.name.loc.start.line===node.closingElement.name.loc.start.line){const lengthDif=tag.toTag.length-node.closingElement.name.name.length;node.closingElement.name.loc.start.column+=lengthDif;node.closingElement.name.loc.end.column+=lengthDif}code=_updateText(code,node.closingElement.name.loc,tag.toTag)}code=migrateTagByAttribute(code,data,ignoreRuleData)}})}},post:function(node){if(!isUpdated&&node.type=="JSXElement"&&node.openingElement.name.name===tag.fromTag&&(!_hasAttributesToIgnore(node.openingElement,ignoreRuleData)||global.configData.forceMigration.includes(componentName))&&!_hasExpressionAttributes(node.openingElement,code)){isUpdated=true}}})}return code}function migrateImports(code,importData,ruleSetToIgnore){if(importData){if(Array.isArray(importData.to)&&importData.to.some(s=>code.includes(s))||code.includes(importData.to)){if(Array.isArray(importData.to)){for(let i=0;i<importData.to.length;i++){if(new RegExp(`\nimport ('|")${importData.to[i]}('|")*`).test(code)){return code}}}else if(new RegExp(`\nimport ('|")${importData.to}('|")*`).test(code)){return code}}if(ruleSetToIgnore&&ruleSetToIgnore.length>0){if(Array.isArray(importData.to)&&importData.to.length>0){importData.to.forEach(toVal=>{let isUpdated=false;let ast=_generateAST(code);traverse(ast,{pre:function(node){if(!isUpdated&&node.type=="ImportDeclaration"&&node.source.value===importData.from&&!node.specifiers.length){code=_appendText(code,node.loc,`\nimport "${toVal}";`);_checkFileUpdate();logging.logImportAppend(importData.from,toVal);code=migrateImports(code,importData,ruleSetToIgnore)}},post:function(node){if(!isUpdated&&node.type=="ImportDeclaration"&&node.source.value===importData.from&&!node.specifiers.length){isUpdated=true}}})})}else{let isUpdated=false;let ast=_generateAST(code);traverse(ast,{pre:function(node){if(!isUpdated&&node.type=="ImportDeclaration"&&node.source.value===importData.from&&!node.specifiers.length){code=_appendText(code,node.loc,`\nimport "${importData.to}";`);_checkFileUpdate();logging.logImportAppend(importData.from,importData.to);code=migrateImports(code,importData,ruleSetToIgnore)}},post:function(node){if(!isUpdated&&node.type=="ImportDeclaration"&&node.source.value===importData.from&&!node.specifiers.length){isUpdated=true}}})}}else{if(Array.isArray(importData.to)&&importData.to.length>0){let isUpdated=false;let ast=_generateAST(code);traverse(ast,{pre:function(node){if(!isUpdated&&node.type=="ImportDeclaration"&&node.source.value===importData.from&&!node.specifiers.length){code=_updateText(code,node.loc,`import "${importData.to[0]}";`);_checkFileUpdate();logging.logImportUpdate(importData.from,importData.to);for(let i=1;i<importData.to.length;i++){node.loc.end.column=node.loc.end.column+`"${importData.to[i-1]}"`.length;code=_appendText(code,node.loc,`\nimport "${importData.to[i]}";`);_checkFileUpdate();logging.logImportAppend(importData.from,importData.to[i]);code=migrateImports(code,importData,ruleSetToIgnore)}}},post:function(node){if(!isUpdated&&node.type=="ImportDeclaration"&&node.source.value===importData.from&&!node.specifiers.length){isUpdated=true}}})}else{let ast=_generateAST(code);traverse(ast,{pre:function(node){if(node.type=="ImportDeclaration"&&!node.specifiers.length&&node.source.value===importData.from){code=_updateText(code,node.loc,`import "${importData.to}";`);_checkFileUpdate();logging.logImportUpdate(importData.from,importData.to);code=migrateImports(code,importData,ruleSetToIgnore)}}})}}return code}}function migrateAttributes(code,data,ignoreRuleData,componentName){if(data&&data.length>0){for(const attributeSet in data){let isUpdated=false;let ast=_generateAST(code);traverse(ast,{pre:function(node){if(!isUpdated&&node.type==="JSXElement"&&node.openingElement.name.name===componentName&&(!_hasAttributesToIgnore(node.openingElement,ignoreRuleData)||global.configData.forceMigration.includes(componentName))){let component=node.openingElement;let attObj=data[attributeSet];let hasDepAttribute=true;if(attObj.depAttribute){hasDepAttribute=component.attributes.map(att=>att.name.name).includes(attObj.depAttribute)}const hasToAttribute=component.attributes.map(att=>att.name.name).includes(attObj.toAttribute);component.attributes.forEach(attribute=>{const hasFromAttribute=attObj.fromValue?attribute.name.name===attObj.fromAttribute&&attribute.value.value===attObj.fromValue:attribute.name.name===attObj.fromAttribute;if(hasDepAttribute&&hasFromAttribute&&attObj.toAttribute){if(attObj.toValue){code=_updateText(code,attribute.loc,` ${attObj.toAttribute}="${attObj.toValue}" `);_checkFileUpdate();logging.logAttributeMigration(attObj.fromAttribute,attObj.fromValue,attObj.toAttribute,attObj.toValue)}else{const attValue=attribute.value.value||{expression:_getText(code,attribute.value.loc)};code=_updateText(code,attribute.loc,` ${attObj.toAttribute}=${attValue.expression||`"${attValue}"`} `);_checkFileUpdate();logging.logAttributeMigration(attObj.fromAttribute,attValue.expression||attValue,attObj.toAttribute,attValue.expression||attValue)}code=migrateAttributes(code,data,ignoreRuleData,componentName)}else if(hasDepAttribute&&hasFromAttribute&&!attObj.toAttribute){code=_updateText(code,attribute.loc,"");_checkFileUpdate();logging.logAttributeDeprecation(attObj.fromAttribute,attObj.fromValue);code=migrateAttributes(code,data,ignoreRuleData,componentName)}});if(hasDepAttribute&&!attObj.fromAttribute&&attObj.toAttribute&&!hasToAttribute){code=_appendText(code,node.openingElement.name.loc,` ${attObj.toAttribute}="${attObj.toValue}" `);_checkFileUpdate();logging.logAttributeAddition(attObj.toAttribute,attObj.toValue);code=migrateAttributes(code,data,ignoreRuleData,componentName)}}},post:function(node){if(!isUpdated&&node.type==="JSXElement"&&node.openingElement.name.name===componentName&&(!_hasAttributesToIgnore(node.openingElement,ignoreRuleData)||global.configData.forceMigration.includes(componentName))){isUpdated=true}}})}return code}}exports.commentSlotContent=commentSlotContent;exports.slotContentToAttribute=slotContentToAttribute;exports.classNameToAttribute=classNameToAttribute;exports.handleSpecialCase=handleSpecialCase;exports.migrateImports=migrateImports;exports.migrateTag=migrateTag;exports.migrateTagByAttribute=migrateTagByAttribute;exports.migrateAttributes=migrateAttributes;
6
+ const traverse=require("ast-traverse");const logging=require("../utilities/logging");const generate=require("@babel/generator").default;const{parse}=require("@babel/parser");const self=require("./astUtils");function _checkFileUpdate(){if(!global.fileIsUpdated){global.fileIsUpdated=true;global.migrationMetrics.files+=1;logging.logFilePath(global.filePath);return true}return false}function generateAST(code){try{return parse(code,{sourceType:"unambiguous",plugins:global.plugins})}catch(e){if(e instanceof SyntaxError){logging.logFilePath(global.filePath,true);logging.logMessage(`\tCouldn't migrate file because there's jsx/tsx code in js/ts`);global.errorInFile=true}}}function generateCode(ast){return generate(ast,{retainLines:false}).code}function _generateSpecCode(ast){return generateCode(ast).replace(/^\s*$(?:\r\n?|\n)/gm,"")}function _appendAttribute(name,value,tag){let node;if(!value.expression){node={type:"StringLiteral",value:`${value}`}}else{let expAst=generateAST(`${value.expression}`).program.body[0].body[0].expression;node={type:"JSXExpressionContainer",expression:expAst}}const attrNode={type:"JSXAttribute",name:{type:"JSXIdentifier",name:`${name}`},value:node};tag.attributes.push(attrNode);return true}function appendImport(value,line,ast){const importNode={type:"JSXText",value:`import "${value}";\n`};ast.program.body.splice(line,0,importNode)}function _appendImportToRequire(toImport,node,parent){let importNode={type:"StringLiteral",value:`${toImport}`};if(parent){parent.elements.push(importNode)}else{node.expression.arguments.push(importNode)}}function _hasImportInRequire(args,fromImport){for(let arg of args){if(arg.type==="ArrayExpression"){obj=_hasImportInRequire(arg.elements,fromImport);if(obj&&!obj.parent){obj.parent=arg}return obj}else if(arg.type==="StringLiteral"&&arg.value===fromImport){return{child:arg}}}return false}function _findChild(node,childTag){for(let child of node.children){if(child.type==="JSXElement"&&child.openingElement.name.name===childTag){return child}else if(child.children){return _findChild(child,childTag)}}return false}function _hasImport(body,importVal,newImports){for(let node of body){if(node.type==="ImportDeclaration"&&node.source.value===importVal||node.type==="JSXText"&&node.value.includes(importVal)){return true}}for(let obj of newImports){if(obj.name===importVal){return true}}return false}function _commentJSX(node,label){if(node.type==="JSXElement"){return`{ /* ${_generateSpecCode(node)} */ }`}return`${label.expression?`{ /* ${label.expression} */ }`:`{ /* ${label} */ }`}`}function _getText(text,locObj){let specificText;const dataArray=text.split("\n");const{start,end}=locObj;if(start.line===end.line){specificText=dataArray[start.line-1].substring(start.column,end.column);return specificText}else{dataArray[start.line-1]=dataArray[start.line-1].substring(start.column);const textByLines=dataArray.slice(start.line-1,end.line).map(s=>s.trim());specificText=textByLines.join("\n");return specificText}}function _getLabelFromASTDOMNode(astnode,code){let label="";for(let currentNode of astnode.children){if(currentNode.type=="JSXText"){if(/\S/.test(currentNode.value)){label=currentNode.value.trim()}}else if(currentNode.type=="JSXExpressionContainer"){if(currentNode.expression&&currentNode.expression.type!="JSXEmptyExpression"){expression=_getText(code,currentNode.loc);label={expression:expression}}}else if(currentNode.type=="JSXElement"&&currentNode.openingElement.name.name.toUpperCase()=="OJ-BIND-TEXT"){currentNode.openingElement.attributes.forEach(attr=>{if(attr.name.name=="value")label=attr.value.value})}else if(currentNode.children){label=_getLabelFromASTDOMNode(currentNode,code)}}return label}function _getLabelFromLegacyComponent(astnode,slotName,code){for(let child of astnode.children){switch(child.type){case"JSXText":if(/\S/.test(child.value)){return{label:child.value.trim(),cnode:child}}break;case"JSXExpressionContainer":if(child.expression&&child.expression.type!="JSXEmptyExpression"){expression=_getText(code,child.loc);return{label:{expression:expression},cnode:child}}break;case"JSXElement":let slotValue;switch(child.openingElement.name.name.toUpperCase()){case"SPAN":case"DIV":child.openingElement.attributes.forEach(attr=>{if(attr.name.name=="slot"&&(attr.value.value===slotName||!attr.value.value.length))slotValue=true});if(!child.openingElement.attributes.map(att=>att.name.name).includes("slot")){slotValue=true}if(slotValue){let label=_getLabelFromASTDOMNode(child,code);return{label:label,cnode:child}}break}break}}}function hasAttributesToIgnore(node,ignoreRuleData){if(node.openingElement){let component=node.openingElement;if(ignoreRuleData){for(let obj of ignoreRuleData){let arr=Object.keys(obj);let key=arr[0];if(!obj.descendant&&component.attributes.length){for(let i=0;i<component.attributes.length;i++){let attribute=component.attributes[i];if(obj.attribute&&obj.attribute===attribute.name.name){if(obj.allowedValues&&!obj.allowedValues.includes(attribute.value.value)||obj.prohibitedValues&&obj.prohibitedValues.includes(attribute.value.value)||!obj.allowedValues&&!obj.prohibitedValues){_checkFileUpdate();logging.logIgnoreComponent(component.name.name,obj.attribute);return true}}if(attribute.name.name===key&&attribute.value.value===obj[key]){_checkFileUpdate();logging.logIgnoreComponent(component.name.name,key,obj[key]);return true}}}if(node.children&&!obj.attribute){for(let j=0;j<node.children.length;j++){let child=node.children[j];if(child.type==="JSXElement"){if(obj.descendant&&child.openingElement.name.name===obj.descendant){_checkFileUpdate();logging.logIgnoreComponent(component.name.name,obj.descendant);return true}if(child.attributes&&hasAttributesToIgnore(child,ignoreRuleData)){_checkFileUpdate();logging.logIgnoreComponent(component.name.name,key,obj[key]);return true}}}}}return false}return false}}function hasExpressionAttributes(component,componentName,code,importantAttributes=null,isPre=false){const excludedAttributes=global.configData.excludeAttributeExpressions[componentName];if(global.jaf.options.dryRunMode&&importantAttributes){component.attributes.forEach(attribute=>{if(importantAttributes.includes(attribute.name.name)&&attribute.value&&attribute.value.type==="JSXExpressionContainer"){const expression=_getText(code,attribute.value.loc);if(_checkFileUpdate()){logging.logAttributeExpression(component.name.name,attribute.name.name,expression)}}})}if(excludedAttributes&&excludedAttributes.length){for(let exAtt of excludedAttributes){for(let i=0;i<component.attributes.length;i++){const attribute=component.attributes[i];if(exAtt===attribute.name.name&&attribute.value.type==="JSXExpressionContainer"){const expression=attribute.value.loc?_getText(code,attribute.value.loc):_generateSpecCode(attribute.value);_checkFileUpdate();logging.logExcludeAttributeExpression(component.name.name,exAtt,expression);return true}}}}return false}function commentSlotContent(node,data){node.children.forEach(child=>{if(child.openingElement&&child.openingElement.attributes){child.openingElement.attributes.forEach(attribute=>{if(attribute.name.name=="slot"&&attribute.value.value==data.slot){let value=_commentJSX(child);index=node.children.indexOf(child);node.children[index]=generateAST(_generateSpecCode({type:"JSXText",value:`${value}`}));_checkFileUpdate();logging.logCommentSlotContent(node.openingElement.name.name,data.slot)}})}});return node}function slotContentToAttribute(node,data,code){if(!node.openingElement.attributes.map(att=>att.name.name).includes(data.attribute)){const component=node.openingElement;const legacyButtonLabel=_getLabelFromLegacyComponent(node,data.slotName,code);if(legacyButtonLabel){let{label,cnode}=legacyButtonLabel;if(label){cnode.value=_commentJSX(cnode,label);cnode.type="JSXText";_appendAttribute(data.attribute,label,component);_checkFileUpdate();logging.logSlotContentToAttribute(node.openingElement.name.name,data.attribute,label.expression?label.expression:label)}}return node}}function classNameToAttribute(node,data){for(let obj of data){for(let attr of node.openingElement.attributes){if(attr.name.name=="class"&&attr.value?.value?.includes(obj.className)){if(obj.attribute){classNames=attr.value.value.split(" ");index=classNames.indexOf(obj.className);classNames.splice(index,1);if(classNames.length===0){attr.name.name=`${obj.attribute}`;attr.value.value=`${obj.attributeValue}`}else{attr.value.value=`${classNames.join(" ")}`;_appendAttribute(obj.attribute,obj.attributeValue,node.openingElement)}_checkFileUpdate();logging.logClassNameToAttribute(obj.className,obj.attribute,obj.attributeValue)}break}}}return node}function handleSpecialCase(code,data){let obj;let regex;if(data[1]){obj=data[1];regex=new RegExp(obj.fromString.split(" ").join("\\s*"),"igm");code=code.replace(regex,obj.toString)}obj=data[0];regex=new RegExp(obj.fromString.split(" ").join("\\s*"),"igm");code=code.replace(regex,obj.toString);return code}function migrateTag(node,legacyComponentName,coreComponentName,isChild){node.openingElement.name.name=coreComponentName;_checkFileUpdate();logging.logTagMigration(legacyComponentName,coreComponentName,isChild);global.migrationMetrics.components+=1;if(node.closingElement&&node.closingElement.name.name===legacyComponentName){node.closingElement.name.name=coreComponentName}return node}function migrateTagByAttribute(node,data,isChild){for(const tagSet of data){if(tagSet.attribute){for(let attribute of node.openingElement.attributes){if(attribute.name.name===tagSet.attribute&&attribute.value.value===tagSet.attributeValue){node.openingElement.name.name=tagSet.toTag;_checkFileUpdate();logging.logTagMigration(tagSet.fromTag,tagSet.toTag);global.migrationMetrics.components+=1;if(node.closingElement&&node.closingElement.name.name===tagSet.fromTag){node.closingElement.name.name=tagSet.toTag}return node}}}else{node.openingElement.name.name=tagSet.toTag;_checkFileUpdate();logging.logTagMigration(tagSet.fromTag,tagSet.toTag,isChild);global.migrationMetrics.components+=1;if(node.closingElement&&node.closingElement.name.name===tagSet.fromTag){node.closingElement.name.name=tagSet.toTag}return node}}return node}function migrateImports(ast,importData,code,ruleSetToIgnore,corePackTag){let newImports=[];if(ruleSetToIgnore&&ruleSetToIgnore.length>0){if(Array.isArray(importData.to)&&importData.to.length>0&&!importData.to.some(s=>_hasImport(ast.program.body,s,newImports))){traverse(ast,{pre:function(node){if(node.type=="ImportDeclaration"&&node.source.value===importData.from&&!node.specifiers.length){for(let i=0;i<importData.to.length;i++){if(!_hasImport(ast.program.body,importData.to[i],newImports)){newImports.push({name:importData.to[i],line:node.loc.start.line});_checkFileUpdate();logging.logImportAppend(importData.from,importData.to[i])}}}else if(node.type=="ExpressionStatement"&&node.expression.callee&&node.expression.callee.name=="require"){let fromImportLoc=_hasImportInRequire(node.expression.arguments,importData.from);if(fromImportLoc){let parent=fromImportLoc.parent?fromImportLoc.parent:false;for(let i=0;i<importData.to.length;i++){if(!_hasImportInRequire(node.expression.arguments,importData.to[i])){_appendImportToRequire(importData.to[i],node,parent);_checkFileUpdate();logging.logImportAppend(importData.from,importData.to[i])}}}}}})}else if(!Array.isArray(importData.to)&&!_hasImport(ast.program.body,importData.to,newImports)){traverse(ast,{pre:function(node){if(node.type=="ImportDeclaration"&&node.source.value===importData.from&&!node.specifiers.length&&!_hasImport(ast.program.body,importData.to,newImports)){newImports.push({name:importData.to,line:node.loc.start.line});_checkFileUpdate();logging.logImportAppend(importData.from,importData.to)}else if(node.type=="ExpressionStatement"&&node.expression.callee&&node.expression.callee.name=="require"){let fromImportLoc=_hasImportInRequire(node.expression.arguments,importData.from);if(fromImportLoc&&!_hasImportInRequire(node.expression.arguments,importData.to)){let parent=fromImportLoc.parent?fromImportLoc.parent:false;_appendImportToRequire(importData.to,node,parent);_checkFileUpdate();logging.logImportAppend(importData.from,importData.to)}}}})}}else{if(Array.isArray(importData.to)&&importData.to.length>0&&!importData.to.some(s=>_hasImport(ast.program.body,s,newImports))){traverse(ast,{pre:function(node){if(node.type=="ImportDeclaration"&&node.source.value===importData.from&&!node.specifiers.length){if(!_hasImport(ast.program.body,importData.to[0],newImports)){node.source.value=importData.to[0];_checkFileUpdate();logging.logImportUpdate(importData.from,importData.to[0])}for(let i=1;i<importData.to.length;i++){if(!_hasImport(ast.program.body,importData.to[i],newImports)){newImports.push({name:importData.to[i],line:node.loc.start.line});_checkFileUpdate();logging.logImportAppend(importData.from,importData.to[i])}}}else if(node.type=="ExpressionStatement"&&node.expression.callee&&node.expression.callee.name=="require"){let fromImportLoc=_hasImportInRequire(node.expression.arguments,importData.from);if(fromImportLoc){let parent=fromImportLoc.parent?fromImportLoc.parent:false;if(!_hasImportInRequire(node.expression.arguments,importData.to[0])){fromImportLoc.child.value=importData.to[0];_checkFileUpdate();logging.logImportUpdate(importData.from,importData.to[0])}for(let i=1;i<importData.to.length;i++){if(!_hasImportInRequire(node.expression.arguments,importData.to[i])){_appendImportToRequire(importData.to[i],node,parent);_checkFileUpdate();logging.logImportAppend(importData.from,importData.to[i])}}}}}})}else if(!Array.isArray(importData.to)&&!_hasImport(ast.program.body,importData.to,newImports)){traverse(ast,{pre:function(node){if(node.type=="ImportDeclaration"&&!node.specifiers.length&&node.source.value===importData.from&&!_hasImport(ast.program.body,importData.to,newImports)){node.source.value=importData.to;_checkFileUpdate();logging.logImportUpdate(importData.from,importData.to)}else if(node.type=="ExpressionStatement"&&node.expression.callee&&node.expression.callee.name=="require"&&!_hasImportInRequire(node.expression.arguments,importData.to)){let fromImportLoc=_hasImportInRequire(node.expression.arguments,importData.from);if(fromImportLoc){fromImportLoc.child.value=importData.to;_checkFileUpdate();logging.logImportUpdate(importData.from,importData.to)}}}})}}if(code.includes(corePackTag)&&(Array.isArray(importData.to)&&!importData.to.some(s=>_hasImport(ast.program.body,s,newImports))||!Array.isArray(importData.to)&&!_hasImport(ast.program.body,importData.to,newImports))){if(Array.isArray(importData.to)){importData.to.forEach(toImport=>{newImports.push({name:toImport,line:0});_checkFileUpdate();logging.logMissingImport(corePackTag,toImport)})}else{newImports.push({name:importData.to,line:0});_checkFileUpdate();logging.logMissingImport(corePackTag,importData.to)}}return newImports}function migrateAttributes(node,data,code){if(data&&data.length>0){for(const attributeSet in data){let fromChildInTag=true;let component=node.openingElement;let attObj=data[attributeSet];if(attObj.fromChild){fromChildInTag=false;if(node.children){let child=_findChild(node,attObj.fromChild);if(node.children&&child){fromChildInTag=true;component=child.openingElement}}}if(fromChildInTag){let hasDepAttribute=true;if(attObj.depAttribute){hasDepAttribute=component.attributes.map(att=>att.name.name).includes(attObj.depAttribute)}const hasToAttribute=component.attributes.map(att=>att.name.name).includes(attObj.toAttribute);component.attributes.forEach(attribute=>{const hasFromAttribute=attObj.fromValue?attribute.name.name===attObj.fromAttribute&&attribute.value.value===attObj.fromValue:attribute.name.name===attObj.fromAttribute;if(hasDepAttribute&&hasFromAttribute&&attObj.toAttribute){if(attObj.toValue){attribute.name.name=attObj.toAttribute;attribute.value.value=attObj.toValue;_checkFileUpdate();logging.logAttributeMigration(attObj.fromAttribute,attObj.fromValue,attObj.toAttribute,attObj.toValue)}else{const attValue=attribute.value.value||{expression:_getText(code,attribute.value.loc)};if(attObj.fromValue){attribute.name.name=attObj.toAttribute;attribute.value.value="";_checkFileUpdate();logging.logAttributeMigration(attObj.fromAttribute,attValue.expression||attValue,attObj.toAttribute,attObj.toValue)}else{attribute.name.name=attObj.toAttribute;attribute.value.value=attValue.expression||attValue;_checkFileUpdate();logging.logAttributeMigration(attObj.fromAttribute,attValue.expression||attValue,attObj.toAttribute,attValue.expression||attValue)}}}else if(hasDepAttribute&&hasFromAttribute&&!attObj.toAttribute){index=component.attributes.indexOf(attribute);component.attributes.splice(index,1);_checkFileUpdate();logging.logAttributeDeprecation(attObj.fromAttribute,attObj.fromValue)}if(attObj.fromChild&&hasFromAttribute){index=component.attributes.indexOf(attribute);_appendAttribute(attribute.name.name,attribute.value.value,node.openingElement);component.attributes.splice(index,1);logging.logAttributeTransfer(component.name.name,node.openingElement.name.name,attribute.name.name,attribute.value.value)}});if(hasDepAttribute&&!attObj.fromAttribute&&attObj.toAttribute&&!hasToAttribute){_appendAttribute(attObj.toAttribute,attObj.toValue,component);_checkFileUpdate();logging.logAttributeAddition(attObj.toAttribute,attObj.toValue)}}}return node}}function migrateChildren(node,data,code,ast,newImports=[]){for(let metaName of data){let componentMetadata=require("../metadata/"+metaName+".json");if(node.children){for(let child of node.children){if(child.type==="JSXElement"&&child.openingElement.name.name===componentMetadata.legacyTag){if(componentMetadata["migrateTagByAttribute"]){migrateTagByAttribute(child,componentMetadata["migrateTagByAttribute"],true)}else{migrateTag(child,componentMetadata.legacyTag,componentMetadata.corePackTag,true)}for(let key in componentMetadata){if(typeof self[key]=="function"&&key!="migrateTagByAttribute"&&key!="migrateImports"){if(key==="migrateChildren"){newImports=newImports.concat(self[key](child,componentMetadata[key],code,ast,newImports))}else{self[key](child,componentMetadata[key],code)}}}code=generateCode(ast);if(componentMetadata["migrateImports"]){newImports=newImports.concat(migrateImports(ast,componentMetadata["migrateImports"],code,componentMetadata.ruleSetToIgnore,componentMetadata.corePackTag))}}else{newImports=migrateChildren(child,data,code,ast,newImports)}}}}return newImports}exports.generateAST=generateAST;exports.generateCode=generateCode;exports.hasAttributesToIgnore=hasAttributesToIgnore;exports.hasExpressionAttributes=hasExpressionAttributes;exports.appendImport=appendImport;exports.commentSlotContent=commentSlotContent;exports.slotContentToAttribute=slotContentToAttribute;exports.classNameToAttribute=classNameToAttribute;exports.handleSpecialCase=handleSpecialCase;exports.migrateImports=migrateImports;exports.migrateTag=migrateTag;exports.migrateTagByAttribute=migrateTagByAttribute;exports.migrateAttributes=migrateAttributes;exports.migrateChildren=migrateChildren;
@@ -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";var fs=require("fs");const utils=require("./htmlUtils");const astUtils=require("./astUtils");function migrateHTML(filePath,componentMetadata){let text=fs.readFileSync(filePath,{encoding:"utf8",flag:"r"});const COMPONENT_NAME=componentMetadata.legacyTag;for(let key in componentMetadata){if(typeof utils[key]=="function"&&key!=="migrateTagByAttribute"){text=utils[key](text,COMPONENT_NAME,componentMetadata[key],componentMetadata.ruleSetToIgnore)}}if(componentMetadata["migrateTagByAttribute"]){text=utils["migrateTagByAttribute"](text,componentMetadata.legacyTag,componentMetadata["migrateTagByAttribute"],componentMetadata.ruleSetToIgnore)}else{text=utils["migrateTag"](text,componentMetadata.legacyTag,componentMetadata.corePackTag,componentMetadata.ruleSetToIgnore)}if(!global.jaf.options.dryRunMode&&global.fileIsUpdated){fs.writeFileSync(filePath,text,err=>{if(err){console.error(err)}})}}function migrateTSX(filePath,componentMetadata){let code=fs.readFileSync(filePath,{encoding:"utf8",flag:"r"});const COMPONENT_NAME=componentMetadata.legacyTag;for(let key in componentMetadata){if(typeof astUtils[key]=="function"&&key!=="migrateTagByAttribute"){code=astUtils[key](code,componentMetadata[key],componentMetadata.ruleSetToIgnore,COMPONENT_NAME)}}if(componentMetadata["migrateTagByAttribute"]){code=astUtils["migrateTagByAttribute"](code,componentMetadata["migrateTagByAttribute"],componentMetadata.ruleSetToIgnore)}else{code=astUtils["migrateTag"](code,componentMetadata.legacyTag,componentMetadata.corePackTag,componentMetadata.ruleSetToIgnore)}const importToData=componentMetadata.migrateImports.to;if(code.includes(componentMetadata.corePackTag)&&(Array.isArray(importToData)&&!importToData.some(s=>code.includes(s))||!code.includes(importToData))){if(Array.isArray(importToData)){importToData.forEach(toImport=>{code=`import "${toImport}";\n`+code})}else{code=`import "${importToData}";\n`+code}}if(!global.jaf.options.dryRunMode&&global.fileIsUpdated){fs.writeFileSync(filePath,code,err=>{if(err){console.error(err)}})}}exports.migrateHTML=migrateHTML;exports.migrateTSX=migrateTSX;
6
+ "use strict";const{DomUtils}=require("htmlparser2");const utils=require("./htmlUtils");const astUtils=require("./astUtils");const traverse=require("ast-traverse");const render=require("dom-serializer").default;function _inManifestData(tag){for(let obj of global.manifestData){if(obj.componentName===tag){return obj}}return false}function migrateHTML(code){let dom=utils.getDom(code);let components=DomUtils.findAll(elem=>_inManifestData(elem.name),dom.children);for(let component of components){let componentInfo=_inManifestData(component.name);let componentMetadata=require("../metadata/"+componentInfo.metadata+".json");let componentName=componentMetadata.legacyTag;if((global.configData.forceMigration.includes(componentName)||!utils.hasAttributesToIgnore(component,componentMetadata.ruleSetToIgnore))&&!utils.hasExpressionAttributes(component,componentMetadata.importantAttributes)){if(componentMetadata["migrateTagByAttribute"]){utils["migrateTagByAttribute"](component,componentMetadata["migrateTagByAttribute"])}else{utils["migrateTag"](component,componentMetadata.legacyTag,componentMetadata.corePackTag)}for(let key in componentMetadata){if(typeof utils[key]=="function"&&key!=="migrateTagByAttribute"&&key!=="migrateImports"){utils[key](component,componentMetadata[key])}}}}return render(dom,{decodeEntities:false})}function migrateTSX(code){let ast=astUtils.generateAST(code);let childImports=[];if(!errorInFile){traverse(ast,{pre:function(node){if(node.type==="JSXElement"){let componentInfo=_inManifestData(node.openingElement.name.name);if(componentInfo){let componentName=componentInfo.componentName;let componentMetadata=require("../metadata/"+componentInfo.metadata+".json");let copyNode=JSON.parse(JSON.stringify(node));if((global.configData.forceMigration.includes(componentName)||!astUtils.hasAttributesToIgnore(node,componentMetadata.ruleSetToIgnore))&&!astUtils.hasExpressionAttributes(node.openingElement,componentMetadata.legacyTag,code,componentMetadata.importantAttributes)){if(componentMetadata["migrateTagByAttribute"]){astUtils["migrateTagByAttribute"](node,componentMetadata["migrateTagByAttribute"])}else{astUtils["migrateTag"](node,componentMetadata.legacyTag,componentMetadata.corePackTag)}for(let key in componentMetadata){if(typeof astUtils[key]=="function"&&key!="migrateTagByAttribute"&&key!="migrateImports"){if(key==="migrateChildren"){childImports=astUtils[key](node,componentMetadata[key],code,ast)}else{astUtils[key](node,componentMetadata[key],code)}}}if(astUtils.hasExpressionAttributes(node.openingElement,componentMetadata.legacyTag,code,componentMetadata.importantAttributes)){node.openingElement=copyNode.openingElement;node.closingElement=copyNode.closingElement;node.children=copyNode.children}}}}}});code=astUtils.generateCode(ast);for(let obj of global.manifestData){let newImports=[];let componentMetadata=require("../metadata/"+obj.metadata+".json");let importData=componentMetadata.migrateImports;newImports=astUtils.migrateImports(ast,importData,code,componentMetadata.ruleSetToIgnore,componentMetadata.corePackTag);for(let i of newImports){astUtils.appendImport(i.name,i.line,ast)}}if(childImports){for(let i of childImports){astUtils.appendImport(i.name,i.line,ast)}}return astUtils.generateCode(ast)}}exports.migrateHTML=migrateHTML;exports.migrateTSX=migrateTSX;
@@ -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 path=require("path");const fs=require("fs");const fileSets={};function getConfigData(sourcePath){try{if(!fs.existsSync(sourcePath)){return}if(sourcePath.toLowerCase().includes("migrationconfig.json")){let text=fs.readFileSync(sourcePath,{encoding:"utf8",flag:"r"});return JSON.parse(text)}}catch(error){console.log("Error: "+error.stack);process.exit(0)}}function scanForFiles(startPath){let{excludeFolders,fileTypes,excludeFiles}=global.configData;const regex=new RegExp(`.(${fileTypes.map(i=>"."+i).join("|")})$`,"i");try{if(!fs.existsSync(startPath)){return}let files=fs.readdirSync(startPath);for(let i=0;i<files.length;i++){let filename=path.join(startPath,files[i]);let stat=fs.lstatSync(filename);if(stat.isDirectory()){if(!excludeFolders.includes(filename)){scanForFiles(filename)}}else{if(!excludeFiles.includes(filename)){let info=regex.exec(filename);if(info&&info["index"]){if(fileSets[info[1]]){fileSets[info[1]].push(filename)}else{fileSets[info[1]]=[filename]}}}}}return fileSets}catch(error){console.log("Error: "+error.stack);process.exit(0)}}exports.scanForFiles=scanForFiles;exports.getConfigData=getConfigData;
6
+ const path=require("path");const fs=require("fs");const fileSets={};function getConfigData(sourcePath){try{if(!fs.existsSync(sourcePath)){return}let text=fs.readFileSync(sourcePath,{encoding:"utf8",flag:"r"});return JSON.parse(text)}catch(error){console.log("Error: "+error.stack);process.exit(0)}}function scanForFiles(startPath){let{excludeFolders,fileTypes,excludeFiles,includeFiles,includeFolders}=global.configData;const regex=new RegExp(`.(${fileTypes.map(i=>"."+i).join("|")})$`,"i");try{if(!fs.existsSync(startPath)){return}let files=fs.readdirSync(startPath);for(let i=0;i<files.length;i++){let filepath=path.join(startPath,files[i]);let stat=fs.lstatSync(filepath);let filename=filepath.split("/").pop();if(stat.isDirectory()){if(includeFolders.length&&(includeFolders.includes(filepath)||includeFolders.includes(filename))||!includeFolders.length&&!excludeFolders.includes(filepath)&&!excludeFolders.includes(filename)){scanForFiles(filepath)}}else{if(!excludeFiles.length&&includeFiles.includes(filepath)||!includeFiles.length&&!excludeFiles.includes(filepath)){let info=regex.exec(filepath);if(info&&info["index"]){if(fileSets[info[1]]){fileSets[info[1]].push(filepath)}else{fileSets[info[1]]=[filepath]}}}}}return fileSets}catch(error){console.log("Error: "+error.stack);process.exit(0)}}exports.scanForFiles=scanForFiles;exports.getConfigData=getConfigData;
@@ -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{parseDocument,DomUtils}=require("htmlparser2");const render=require("dom-serializer").default;const logging=require("../utilities/logging");function _checkFileUpdate(){if(!global.fileIsUpdated){global.fileIsUpdated=true;global.migrationMetrics.files+=1;logging.logFilePath(global.filePath);return true}return false}function _getLabelFromDOMNode(node,slotName){let label;let cnode;if(node&&node.children&&!!node.children.length){for(let child of node.children){if(child.type&&child.type=="text"){if(/\S/.test(child.data)){label=child.data.trim();cnode=_getDom("<!-- "+render(child,{decodeEntities:false})+" -->");DomUtils.replaceElement(child,cnode);break}}else if(child.type&&child.type=="tag"&&child.name.toUpperCase()=="OJ-BIND-TEXT"&&(!slotName&&!child.attribs.slot||slotName&&child.attribs.slot===slotName)){label=child.attribs.value;cnode=_getDom("<!-- "+render(child,{decodeEntities:false})+" -->");DomUtils.replaceElement(child,cnode);break}else if(child.children&&!!child.children.length){label=_getLabelFromDOMNode(child,slotName)}}}return label}function _getDom(text=""){return parseDocument(text,{withStartIndices:true,withEndIndices:true})}function _filterComponentsByIgnoreRule(components,ignoreRuleData){let obj;components=components.filter(component=>{for(let i=0;i<ignoreRuleData.length;i++){obj=ignoreRuleData[i];let arr=Object.keys(obj);let key=arr[0];if(obj[key].includes(component.attribs[key])){_checkFileUpdate();logging.logIgnoreComponent(component.name,key,obj[key]);return false}else{for(let child of component.children){if(child.attribs&&obj[key].includes(child.attribs[key])){_checkFileUpdate();logging.logIgnoreComponent(child.name,key,obj[key]);return false}}}}return true});return components}function _filterComponentsAttributeExpressions(components,componentName){const excludedAttributes=global.configData.excludeAttributeExpressions[componentName];const regex=new RegExp(`((\\{\\{)|(\\[\\[)).*((\\}\\})|(\\]\\]))`);components=components.filter(component=>{if(global.jaf.options.dryRunMode){for(const attribute in component.attribs){if(regex.test(component.attribs[attribute])){if(_checkFileUpdate()){logging.logAttributeExpression(component.name,attribute,component.attribs[attribute])}}}}if(excludedAttributes&&excludedAttributes.length){for(let i=0;i<excludedAttributes.length;i++){if(component.attribs[`:${excludedAttributes[i]}`]){excludedAttributes[i]=`:${excludedAttributes[i]}`}if(regex.test(component.attribs[excludedAttributes[i]])){_checkFileUpdate();logging.logExcludeAttributeExpression(componentName,excludedAttributes[i],component.attribs[excludedAttributes[i]]);return false}}}return true});return components}function commentSlotContent(text,componentName,data,ignoreRuleData){let slotValue=data.slot;const dom=_getDom(text);let components=DomUtils.getElementsByTagName(componentName,dom);if(ignoreRuleData&&!global.configData.forceMigration.includes(componentName))components=_filterComponentsByIgnoreRule(components,ignoreRuleData);components=_filterComponentsAttributeExpressions(components,componentName);components.forEach(component=>{component.children.forEach(child=>{if(child.name&&child.attribs.slot==slotValue){let cnode=_getDom("<!-- "+render(child,{decodeEntities:false})+" -->");DomUtils.replaceElement(child,cnode);_checkFileUpdate();logging.logCommentSlotContent(component.name,slotValue,child.name)}})});return render(dom,{decodeEntities:false})}function slotContentToAttribute(text,componentName,data,ignoreRuleData){const dom=_getDom(text);let components=DomUtils.getElementsByTagName(componentName,dom);if(ignoreRuleData&&!global.configData.forceMigration.includes(componentName))components=_filterComponentsByIgnoreRule(components,ignoreRuleData);components=_filterComponentsAttributeExpressions(components,componentName);components.forEach(component=>{if(!Object.keys(component.attribs).includes(data.attribute)){component.attribs[data.attribute]=_getLabelFromDOMNode(component,data.slotName);if(!component.attribs[data.attribute]){delete component.attribs[data.attribute]}_checkFileUpdate();logging.logSlotContentToAttribute(component.name,data.attribute,component.attribs[data.attribute])}});return render(dom,{decodeEntities:false})}function migrateTag(text,legacyComponentName,coreComponentName,ignoreRuleData){if(!coreComponentName)return text;const dom=_getDom(text);let components=DomUtils.getElementsByTagName(legacyComponentName,dom);if(ignoreRuleData&&!global.configData.forceMigration.includes(legacyComponentName))components=_filterComponentsByIgnoreRule(components,ignoreRuleData);components=_filterComponentsAttributeExpressions(components,legacyComponentName);components.forEach(component=>{component.name=coreComponentName;_checkFileUpdate();logging.logTagMigration(legacyComponentName,coreComponentName);global.migrationMetrics.components+=1});return render(dom,{decodeEntities:false})}function migrateTagByAttribute(text,componentName,data,ignoreRuleData){const dom=_getDom(text);let components=DomUtils.getElementsByTagName(componentName,dom);if(ignoreRuleData&&!global.configData.forceMigration.includes(componentName))components=_filterComponentsByIgnoreRule(components,ignoreRuleData);components=_filterComponentsAttributeExpressions(components,componentName);components.forEach(component=>{for(const tagSet in data){tag=data[tagSet];hasAttAndVal=tag.attributeValue===DomUtils.getAttributeValue(component,tag.attribute);if(hasAttAndVal){component.name=tag.toTag;_checkFileUpdate();logging.logTagMigration(componentName,tag.toTag);global.migrationMetrics.components+=1}}});return render(dom,{decodeEntities:false})}function classNameToAttribute(text,componentName,data,ignoreRuleData){const dom=_getDom(text);let components=DomUtils.getElementsByTagName(componentName,dom);let classNames;let index;if(ignoreRuleData&&!global.configData.forceMigration.includes(componentName))components=_filterComponentsByIgnoreRule(components,ignoreRuleData);components=_filterComponentsAttributeExpressions(components,componentName);data.forEach(obj=>{let from=obj.className;let to=obj.attributeValue;let attribute=obj.attribute;components.forEach(component=>{if(component.attribs.class){classNames=component.attribs.class.split(" ");index=classNames.indexOf(from);if(index!=-1&&attribute){classNames.splice(index,1);if(classNames.length==0)delete component.attribs.class;else component.attribs.class=classNames.join(" ");component.attribs[attribute]=to;_checkFileUpdate();logging.logClassNameToAttribute(from,attribute,to)}}})});return render(dom,{decodeEntities:false})}function migrateAttributes(text,componentName,data,ignoreRuleData){const dom=_getDom(text);let components=DomUtils.getElementsByTagName(componentName,dom);let obj;if(ignoreRuleData&&!global.configData.forceMigration.includes(componentName))components=_filterComponentsByIgnoreRule(components,ignoreRuleData);components=_filterComponentsAttributeExpressions(components,componentName);for(const attributeName in data){obj=data[attributeName];components.forEach(component=>{let hasDepAttribute=true;if(obj.depAttribute){hasDepAttribute=DomUtils.hasAttrib(component,obj.depAttribute)}const hasFromAttribute=obj.fromValue?obj.fromValue===DomUtils.getAttributeValue(component,obj.fromAttribute):DomUtils.hasAttrib(component,obj.fromAttribute);const hasToAttribute=DomUtils.hasAttrib(component,obj.toAttribute);if(hasDepAttribute&&hasFromAttribute&&obj.toAttribute){if(obj.toValue){component.attribs[obj.toAttribute]=obj.toValue;_checkFileUpdate();logging.logAttributeMigration(obj.fromAttribute,obj.fromValue,obj.toAttribute,obj.toValue)}else{component.attribs[obj.toAttribute]=component.attribs[obj.fromAttribute];_checkFileUpdate();logging.logAttributeMigration(obj.fromAttribute,component.attribs[obj.fromAttribute],obj.toAttribute,component.attribs[obj.fromAttribute])}delete component.attribs[obj.fromAttribute]}else if(hasDepAttribute&&hasFromAttribute&&!obj.toAttribute){delete component.attribs[obj.fromAttribute];_checkFileUpdate();logging.logAttributeDeprecation(obj.fromAttribute,obj.fromValue)}else if(hasDepAttribute&&!obj.fromAttribute&&obj.toAttribute&&!hasToAttribute){component.attribs[obj.toAttribute]=obj.toValue;_checkFileUpdate();logging.logAttributeAddition(obj.toAttribute,obj.toValue)}})}return render(dom,{decodeEntities:false})}function handleSpecialCase(code,componentName,data){let obj;let regex;if(data[1]){obj=data[1];regex=new RegExp(obj.fromString.split(" ").join("\\s*"),"igm");code=code.replace(regex,obj.toString)}obj=data[0];regex=new RegExp(obj.fromString.split(" ").join("\\s*"),"igm");code=code.replace(regex,obj.toString);return code}exports.slotContentToAttribute=slotContentToAttribute;exports.commentSlotContent=commentSlotContent;exports.migrateTag=migrateTag;exports.classNameToAttribute=classNameToAttribute;exports.handleSpecialCase=handleSpecialCase;exports.migrateAttributes=migrateAttributes;exports.migrateTagByAttribute=migrateTagByAttribute;
6
+ const{parseDocument,DomUtils}=require("htmlparser2");const render=require("dom-serializer").default;const logging=require("../utilities/logging");const self=require("./htmlUtils");function _checkFileUpdate(){if(!global.fileIsUpdated){global.fileIsUpdated=true;global.migrationMetrics.files+=1;logging.logFilePath(global.filePath);return true}return false}function _getLabelFromDOMNode(node,slotName){let label;let cnode;if(node&&node.children&&!!node.children.length){for(let child of node.children){if(child.type&&child.type=="text"){if(/\S/.test(child.data)){label=child.data.trim();cnode=getDom("<!-- "+render(child,{decodeEntities:false})+" -->");DomUtils.replaceElement(child,cnode);break}}else if(child.type&&child.type=="tag"&&child.name.toUpperCase()=="OJ-BIND-TEXT"&&(!slotName&&!child.attribs.slot||slotName&&child.attribs.slot===slotName)){label=child.attribs.value;cnode=getDom("<!-- "+render(child,{decodeEntities:false})+" -->");DomUtils.replaceElement(child,cnode);break}else if(child.children&&!!child.children.length){label=_getLabelFromDOMNode(child,slotName)}}}return label}function _findChild(component,childTag){for(let child of component.children){if(child.name===childTag){return child}else if(child.children){return _findChild(child,childTag)}}return false}function getDom(text=""){return parseDocument(text,{withStartIndices:true,withEndIndices:true})}function hasAttributesToIgnore(component,ignoreRuleData){if(ignoreRuleData){for(let i=0;i<ignoreRuleData.length;i++){obj=ignoreRuleData[i];let arr=Object.keys(obj);let key=arr[0];if(!obj.descendant&&component.attribs){if(obj.attribute&&component.attribs[obj.attribute]){if(obj.allowedValues&&!obj.allowedValues.includes(component.attribs[obj.attribute])||obj.prohibitedValues&&obj.prohibitedValues.includes(attribute.value.value)||!obj.allowedValues&&!obj.prohibitedValues){_checkFileUpdate();logging.logIgnoreComponent(component.name,obj.attribute);return true}}else if(component.attribs[key]&&component.attribs[key]===obj[key]){_checkFileUpdate();logging.logIgnoreComponent(component.name,key,obj[key]);return true}}if(component.children&&!obj.attribute){for(let j=0;j<component.children.length;j++){const child=component.children[j];if(child.type==="tag"){if(obj.descendant&&child.name===obj.descendant){_checkFileUpdate();logging.logIgnoreComponent(component.name,obj.descendant);return true}if(hasAttributesToIgnore(child,ignoreRuleData)){_checkFileUpdate();logging.logIgnoreComponent(component.name,key,obj[key]);return true}}}}}return false}return false}function hasExpressionAttributes(component,importantAttributes){const excludedAttributes=global.configData.excludeAttributeExpressions[component.name];const regex=new RegExp(`((\\{\\{)|(\\[\\[)).*((\\}\\})|(\\]\\]))`);if(global.jaf.options.dryRunMode&&importantAttributes){for(let attribute of importantAttributes){if(component.attribs[`:${attribute}`]){attribute=`:${attribute}`}if(regex.test(component.attribs[attribute])){if(_checkFileUpdate()){logging.logAttributeExpression(component.name,attribute,component.attribs[attribute])}}}}if(excludedAttributes&&excludedAttributes.length){for(let i=0;i<excludedAttributes.length;i++){if(component.attribs[`:${excludedAttributes[i]}`]){excludedAttributes[i]=`:${excludedAttributes[i]}`}if(regex.test(component.attribs[excludedAttributes[i]])){_checkFileUpdate();logging.logExcludeAttributeExpression(component.name,excludedAttributes[i],component.attribs[excludedAttributes[i]]);return true}}}return false}function commentSlotContent(component,data){let slotValue=data.slot;component.children.forEach(child=>{if(child.name&&child.attribs.slot==slotValue){let cnode=getDom("<!-- "+render(child,{decodeEntities:false})+" -->");DomUtils.replaceElement(child,cnode);_checkFileUpdate();logging.logCommentSlotContent(component.name,slotValue,child.name)}})}function slotContentToAttribute(component,data){if(!Object.keys(component.attribs).includes(data.attribute)){component.attribs[data.attribute]=_getLabelFromDOMNode(component,data.slotName);if(!component.attribs[data.attribute]){delete component.attribs[data.attribute]}else{_checkFileUpdate();logging.logSlotContentToAttribute(component.name,data.attribute,component.attribs[data.attribute])}}}function migrateTag(component,legacyComponentName,coreComponentName,isChild){component.name=coreComponentName;_checkFileUpdate();logging.logTagMigration(legacyComponentName,coreComponentName,isChild);global.migrationMetrics.components+=1}function migrateTagByAttribute(component,data,isChild){for(const tagSet in data){tag=data[tagSet];if(tag.attribute){hasAttAndVal=tag.attributeValue===DomUtils.getAttributeValue(component,tag.attribute);if(hasAttAndVal){component.name=tag.toTag;_checkFileUpdate();logging.logTagMigration(tag.fromTag,tag.toTag,isChild);global.migrationMetrics.components+=1;break}}else{component.name=tag.toTag;_checkFileUpdate();logging.logTagMigration(tag.fromTag,tag.toTag);global.migrationMetrics.components+=1}}}function classNameToAttribute(component,data){data.forEach(obj=>{let from=obj.className;let to=obj.attributeValue;let attribute=obj.attribute;if(component.attribs.class){classNames=component.attribs.class.split(" ");index=classNames.indexOf(from);if(index!=-1&&attribute){classNames.splice(index,1);if(classNames.length==0)delete component.attribs.class;else component.attribs.class=classNames.join(" ");component.attribs[attribute]=to;_checkFileUpdate();logging.logClassNameToAttribute(from,attribute,to)}}})}function migrateAttributes(component,data){let parent;for(const attributeName in data){let fromChildInTag=true;let obj=data[attributeName];if(obj.fromChild){fromChildInTag=false;child=_findChild(component,obj.fromChild);if(component.children&&child){fromChildInTag=true;parent=component;component=child}}if(fromChildInTag){let hasDepAttribute=true;if(obj.depAttribute){hasDepAttribute=DomUtils.hasAttrib(component,obj.depAttribute)}const hasFromAttribute=obj.fromValue?obj.fromValue===DomUtils.getAttributeValue(component,obj.fromAttribute):DomUtils.hasAttrib(component,obj.fromAttribute);const hasToAttribute=DomUtils.hasAttrib(component,obj.toAttribute);if(hasDepAttribute&&hasFromAttribute&&obj.toAttribute){if(obj.toValue){component.attribs[obj.toAttribute]=obj.toValue;_checkFileUpdate();logging.logAttributeMigration(obj.fromAttribute,obj.fromValue,obj.toAttribute,obj.toValue)}else{let fromValue=obj.fromValue?obj.fromValue:component.attribs[obj.fromAttribute];if(obj.fromValue){component.attribs[obj.toAttribute]=""}else{component.attribs[obj.toAttribute]=component.attribs[obj.fromAttribute]}_checkFileUpdate();logging.logAttributeMigration(obj.fromAttribute,fromValue,obj.toAttribute,component.attribs[obj.toAttribute])}if(obj.fromAttribute!==obj.toAttribute){delete component.attribs[obj.fromAttribute]}}else if(hasDepAttribute&&hasFromAttribute&&!obj.toAttribute){delete component.attribs[obj.fromAttribute];_checkFileUpdate();logging.logAttributeDeprecation(obj.fromAttribute,obj.fromValue)}else if(hasDepAttribute&&!obj.fromAttribute&&obj.toAttribute&&!hasToAttribute){component.attribs[obj.toAttribute]=obj.toValue;_checkFileUpdate();logging.logAttributeAddition(obj.toAttribute,obj.toValue)}if(obj.fromChild&&hasFromAttribute&&parent){let value=component.attribs[obj.toAttribute];parent.attribs[obj.toAttribute]=value;delete component.attribs[obj.toAttribute];logging.logAttributeTransfer(component.name,parent.name,obj.toAttribute,value)}}}}function handleSpecialCase(code,componentName,data){let obj;let regex;if(data[1]){obj=data[1];regex=new RegExp(obj.fromString.split(" ").join("\\s*"),"igm");code=code.replace(regex,obj.toString)}obj=data[0];regex=new RegExp(obj.fromString.split(" ").join("\\s*"),"igm");code=code.replace(regex,obj.toString);return code}function migrateChildren(component,data){for(let metaName of data){let componentMetadata=require("../metadata/"+metaName+".json");if(component.children){for(let child of component.children){if(child.name===componentMetadata.legacyTag){if(componentMetadata["migrateTagByAttribute"]){migrateTagByAttribute(child,componentMetadata["migrateTagByAttribute"],true)}else{migrateTag(child,componentMetadata.legacyTag,componentMetadata.corePackTag,true)}for(let key in componentMetadata){if(typeof self[key]=="function"&&key!="migrateTagByAttribute"&&key!="migrateImports"){self[key](child,componentMetadata[key])}}}else{migrateChildren(child,data)}}}}}exports.getDom=getDom;exports.hasAttributesToIgnore=hasAttributesToIgnore;exports.hasExpressionAttributes=hasExpressionAttributes;exports.slotContentToAttribute=slotContentToAttribute;exports.commentSlotContent=commentSlotContent;exports.migrateTag=migrateTag;exports.classNameToAttribute=classNameToAttribute;exports.handleSpecialCase=handleSpecialCase;exports.migrateAttributes=migrateAttributes;exports.migrateTagByAttribute=migrateTagByAttribute;exports.migrateChildren=migrateChildren;
@@ -1,4 +1,9 @@
1
1
  [
2
+ {
3
+ "componentName": "oj-action-card",
4
+ "metadata": "actionCardMetadata",
5
+ "migrationApiLink": "https://jet.oraclecorp.com/trunk/jsdocs/oj.ojActionCard.html#migration-section"
6
+ },
2
7
  {
3
8
  "componentName": "oj-button",
4
9
  "metadata": "buttonMetadata",
@@ -14,16 +19,31 @@
14
19
  "metadata": "collapsibleMetadata",
15
20
  "migrationApiLink": "https://jet.oraclecorp.com/trunk/jsdocs/oj.ojCollapsible.html#migration-section"
16
21
  },
22
+ {
23
+ "componentName": "oj-drawer-popup",
24
+ "metadata": "drawerPopupMetadata",
25
+ "migrationApiLink": "https://jet.oraclecorp.com/trunk/jsdocs/oj.ojDrawerPopup.html#migration-section"
26
+ },
17
27
  {
18
28
  "componentName": "oj-messages",
19
29
  "metadata": "messagesMetadata",
20
30
  "migrationApiLink": "https://jet.oraclecorp.com/trunk/jsdocs/oj.ojMessages.html#migration-section"
21
31
  },
32
+ {
33
+ "componentName": "oj-message-banner",
34
+ "metadata": "messageBannerMetadata",
35
+ "migrationApiLink": "https://jet.oraclecorp.com/trunk/jsdocs/oj.ojMessageBanner.html#migration-section"
36
+ },
22
37
  {
23
38
  "componentName": "oj-file-picker",
24
39
  "metadata": "filePickerMetadata",
25
40
  "migrationApiLink": "https://jet.oraclecorp.com/trunk/jsdocs/oj.ojFilePicker.html#migration-section"
26
41
  },
42
+ {
43
+ "componentName": "oj-highlight-text",
44
+ "metadata": "highlightTextMetadata",
45
+ "migrationApiLink": "https://jet.oraclecorp.com/trunk/jsdocs/oj.ojHighlightText.html#migration-section"
46
+ },
27
47
  {
28
48
  "componentName": "oj-list-item-layout",
29
49
  "metadata": "listItemLayoutMetadata",
@@ -79,6 +99,11 @@
79
99
  "metadata": "selectManyMetadata",
80
100
  "migrationApiLink": "https://jet.oraclecorp.com/trunk/jsdocs/oj.ojSelectMany.html#migration-section"
81
101
  },
102
+ {
103
+ "componentName": "oj-selector",
104
+ "metadata": "selectorMetadata",
105
+ "migrationApiLink": "https://jet.oraclecorp.com/trunk/jsdocs/oj.ojSelector.html#migration-section"
106
+ },
82
107
  {
83
108
  "componentName": "oj-status-meter-gauge",
84
109
  "metadata": "statusMeterGaugeMetadata",
@@ -88,15 +113,5 @@
88
113
  "componentName": "oj-legend",
89
114
  "metadata": "legendMetadata",
90
115
  "migrationApiLink": "https://jet.oraclecorp.com/trunk/jsdocs/oj.ojLegend.html#migration-section"
91
- },
92
- {
93
- "componentName": "oj-legend-item",
94
- "metadata": "legendItemMetadata",
95
- "migrationApiLink": "https://jet.oraclecorp.com/trunk/jsdocs/oj.ojLegend.html#migration-section"
96
- },
97
- {
98
- "componentName": "oj-legend-section",
99
- "metadata": "legendSectionMetadata",
100
- "migrationApiLink": "https://jet.oraclecorp.com/trunk/jsdocs/oj.ojLegend.html#migration-section"
101
116
  }
102
117
  ]
@@ -16,6 +16,9 @@
16
16
  "fileTypes": ["ts", "js", "tsx", "html", "jsx", "json", "css"],
17
17
  "excludeFiles": [],
18
18
  "excludeComponents": [],
19
+ "includeFiles": [],
20
+ "includeFolders": [],
21
+ "includeComponents": [],
19
22
  "forceMigration": [],
20
23
  "excludeAttributeExpressions": {}
21
24
  }
@@ -102,18 +102,32 @@
102
102
  "toValue": "attributeValue"
103
103
  }
104
104
  ],
105
+ "migrateChildren": [
106
+ {"description": "Migrates the children of the component"}
107
+ "metadataFile1",
108
+ "metadataFile2"
109
+ ],
105
110
  "ruleSetToIgnore": [
106
111
  {
107
112
  "description": "Defines the rule set that can contain a slot or attribute that will cause functionally breaking change and will be ignored as part of the migration
108
113
  slot : Migration will be skipped if the specified slot exists in the legacy code : string
109
- attribute : Migration will be skipped if the specified attribute exists in the legacy code : string",
114
+ attribute : Migration will be skipped if the specified attribute exists in the legacy code : string
115
+ allowedValues: Migration will be skipped if the value of the attribute is not in the allowed array : array
116
+ prohibitedValues: Migration will be skipped if the value of the attribute is in the prohibited array : array",
110
117
  "slotName": ""
111
118
  },
112
119
  {
113
120
  "description": "Defines the rule set that can contain a slot or attribute that will cause functionally breaking change and will be ignored as part of the migration
114
121
  slot : Migration will be skipped if the specified slot exists in the legacy code : string
115
- attribute : Migration will be skipped if the specified attribute exists in the legacy code : string",
116
- "attribute": ""
122
+ attribute : Migration will be skipped if the specified attribute exists in the legacy code : string
123
+ allowedValues: Migration will be skipped if the value of the attribute is not in the allowed array : array
124
+ prohibitedValues: Migration will be skipped if the value of the attribute is in the prohibited array : array",
125
+ "attribute": "",
126
+ "allowedValues": [],
127
+ "prohibitedValues": []
117
128
  }
118
- ]
129
+ ],
130
+ "description": "Defines potential attributes a component may have that could cause problems if assigned expressions as values.
131
+ Attributes listed here will be logged in dry run mode when encountered with expressions as values.",
132
+ "importantAttributes":[]
119
133
  }
@@ -1,17 +1,29 @@
1
1
  {
2
2
  "description": "migrationConfig.json can be used by the USER to fine tune the operations and behavior of the Migration Framework
3
- excludeFolder : The Array contains folder names that the migration framework will skip. The full path for the file name should be provided.
3
+ excludeFolders : The Array contains folder names that the migration framework will skip. The full path for the folder name should be provided.
4
4
  excludeFiles : The Array contains file names that the migration framework will skip. The full path for the file name should be provided.
5
5
  excludeComponents : The Array contains Legacy component tags that the migration framework will skip migration
6
+ includeFiles : The Array contains file names that the migration framework will only process for migration. The full path for the file name should be provided.
7
+ includeFolders : The Array contains folder names that the migration framework will only process for migration. The full path for the folder name should be provided.
8
+ includeComponents : The Array contains Legacy component tags that the migration framework will only process for migration
6
9
  forceMigration : The Array contains Legacy component tags for which the IgnoreRuleSet will be ignored and tag will be migrated to core pack
7
- excludeAttributeExpressions : The object contains component specific attributes that should not be migrated if contains a expression as value",
10
+ excludeAttributeExpressions : The object contains component specific attributes that should not be migrated if contains a expression as value
11
+ baseMigrationDir : The root directory the migrator will be ran from. The migrator runs from the calling directory if not specified. Relative or absolute paths can be used.
12
+ logFileName : The name for the log file generated during migration. The default name will be used if not specified.
13
+ logFilePath : The output location for the log file generated during migration. The calling directory will be used by default if not specified.",
8
14
  "excludeFolders": [],
9
15
  "excludeFiles": [],
10
16
  "excludeComponents": [],
17
+ "includeFiles": [],
18
+ "includeFolders": [],
19
+ "includeComponents": [],
11
20
  "forceMigration": [],
12
21
  "excludeAttributeExpressions" :
13
22
  {
14
23
  "legacyTag1": ["attributes"],
15
24
  "legacyTag2": ["attributes"]
16
- }
25
+ },
26
+ "baseMigrationDir": "",
27
+ "logFileName": "",
28
+ "logFilePath": ""
17
29
  }
@@ -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
- function consoleLog(text){global.jaf.log.console(text)}function logMessage(text){global.jaf.log.msg(text)}function logFilePath(filepath){global.jaf.log.msg(`\nMigrating in: ${filepath}`)}function logImportUpdate(from,to){global.jaf.log.msg(`\tImport: Updated from "${from}" to "${to}"`)}function logImportAppend(from,to){global.jaf.log.msg(`\tImport: Appended "${to}" to "${from}"`)}function logTagMigration(from,to){global.jaf.log.msg(`\tTag migrated from "${from}" to "${to}"`)}function logClassNameToAttribute(className,attribute,value){global.jaf.log.msg(`\tClass name of "${className}" migrated to "${attribute}" attribute with value of "${value}"`)}function logAttributeMigration(fromAtt,fromVal,toAtt,toVal){global.jaf.log.msg(`\tAttribute migrated from "${fromAtt}" with a value of "${fromVal}" to "${toAtt}" with a value of "${toVal}"`)}function logAttributeDeprecation(from,fromVal){global.jaf.log.msg(`\tAttribute deprecated, removed "${from}" ${fromVal?`with a value of "${fromVal}"`:""}`)}function logAttributeAddition(toAtt,toVal){global.jaf.log.msg(`\tAttribute added, "${toAtt}" with a value of "${toVal}"`)}function logIgnoreComponent(component,attribute,value){global.jaf.log.msg(`\tRule to ignore: "${component}" filtered out due to attribute "${attribute}" ${value?`with value of "${value}"`:""}`)}function logCommentSlotContent(component,value,child){global.jaf.log.msg(`\tCommented out ${component}`);global.jaf.log.msg(`\t\t${child?`has ${child}`:""} with "slot" attribute having value of "${value}"`)}function logSlotContentToAttribute(component,attribute,value){value?global.jaf.log.msg(`\tSlot migrated: "${component}" added attribute "${attribute}" with value of "${value}"`):global.jaf.log.msg(`\tSlot migration ignored: "${component}" did not add attribute "${attribute}" due to value of "${value}"`)}function logAttributeExpression(component,attribute,value){global.jaf.log.msg(`\tAttribute expression: "${component}" has attribute "${attribute}" with value as expression of "${value}"`)}function logExcludeAttributeExpression(component,attribute,value){global.jaf.log.msg(`\tMigration skipped: "${component}" has attribute "${attribute}" with value as expression of "${value}"`)}exports.consoleLog=consoleLog;exports.logMessage=logMessage;exports.logFilePath=logFilePath;exports.logImportUpdate=logImportUpdate;exports.logImportAppend=logImportAppend;exports.logTagMigration=logTagMigration;exports.logClassNameToAttribute=logClassNameToAttribute;exports.logAttributeMigration=logAttributeMigration;exports.logAttributeDeprecation=logAttributeDeprecation;exports.logAttributeAddition=logAttributeAddition;exports.logIgnoreComponent=logIgnoreComponent;exports.logCommentSlotContent=logCommentSlotContent;exports.logSlotContentToAttribute=logSlotContentToAttribute;exports.logAttributeExpression=logAttributeExpression;exports.logExcludeAttributeExpression=logExcludeAttributeExpression;
6
+ function consoleLog(text){global.jaf.log.console(text)}function logMessage(text){global.jaf.log.msg(text)}function logFilePath(filepath,err){if(err){global.jaf.log.msg(`\nFile in: ${filepath}`)}else{global.jaf.log.msg(`\nMigrating in: ${filepath}`)}}function logImportUpdate(from,to){global.jaf.log.msg(`\tImport: Updated from "${from}" to "${to}"`)}function logImportAppend(from,to){global.jaf.log.msg(`\tImport: Appended "${to}" to "${from}"`)}function logMissingImport(component,to){global.jaf.log.msg(`\tImport: Added "${to}" for "${component}" to top of file due to missing import`)}function logTagMigration(from,to,isChild){isChild?global.jaf.log.msg(`\t\tChild tag migrated from "${from}" to "${to}"`):global.jaf.log.msg(`\tTag migrated from "${from}" to "${to}"`)}function logClassNameToAttribute(className,attribute,value){global.jaf.log.msg(`\t\tClass name of "${className}" migrated to "${attribute}" attribute with value of "${value}"`)}function logAttributeMigration(fromAtt,fromVal,toAtt,toVal){toVal?global.jaf.log.msg(`\t\tAttribute migrated from "${fromAtt}" with a value of "${fromVal}" to "${toAtt}" with a value of "${toVal}"`):global.jaf.log.msg(`\t\tAttribute migrated from "${fromAtt}" with a value of "${fromVal}" to "${toAtt}" with no value`)}function logAttributeDeprecation(from,fromVal){global.jaf.log.msg(`\t\tAttribute deprecated, removed "${from}" ${fromVal?`with a value of "${fromVal}"`:""}`)}function logAttributeAddition(toAtt,toVal){global.jaf.log.msg(`\t\tAttribute added, "${toAtt}" with a value of "${toVal}"`)}function logAttributeTransfer(fromTag,toTag,att,val){global.jaf.log.msg(`\t\tAttribute "${att}" with value "${val}" transfered from "${fromTag}" to "${toTag}"`)}function logIgnoreComponent(component,attribute,value){global.jaf.log.msg(`\tRule to ignore: "${component}" filtered out due to attribute "${attribute}" ${value?`with value of "${value}"`:""}`)}function logCommentSlotContent(component,value,child){global.jaf.log.msg(`\t\tCommented out ${component}`);global.jaf.log.msg(`\t\t\t${child?`has ${child}`:""} with "slot" attribute having value of "${value}"`)}function logSlotContentToAttribute(component,attribute,value){value?global.jaf.log.msg(`\t\tSlot migrated: "${component}" added attribute "${attribute}" with value of "${value}"`):global.jaf.log.msg(`\t\tSlot migration ignored: "${component}" did not add attribute "${attribute}" due to value of "${value}"`)}function logAttributeExpression(component,attribute,value){global.jaf.log.msg(`\t\tAttribute expression: "${component}" has attribute "${attribute}" with value as expression of "${value}"`)}function logExcludeAttributeExpression(component,attribute,value){global.jaf.log.msg(`\t\tMigration skipped: "${component}" has attribute "${attribute}" with value as expression of "${value}"`)}function logIncludeExcludeIssue(type){const text=`\nMigration attempt exited. The migration config file used has values for both include${type} and exclude${type}. Please use only one or the other.`;global.jaf.log.msg(text);consoleLog(text)}exports.consoleLog=consoleLog;exports.logMessage=logMessage;exports.logFilePath=logFilePath;exports.logImportUpdate=logImportUpdate;exports.logImportAppend=logImportAppend;exports.logMissingImport=logMissingImport;exports.logTagMigration=logTagMigration;exports.logClassNameToAttribute=logClassNameToAttribute;exports.logAttributeMigration=logAttributeMigration;exports.logAttributeDeprecation=logAttributeDeprecation;exports.logAttributeAddition=logAttributeAddition;exports.logAttributeTransfer=logAttributeTransfer;exports.logIgnoreComponent=logIgnoreComponent;exports.logCommentSlotContent=logCommentSlotContent;exports.logSlotContentToAttribute=logSlotContentToAttribute;exports.logAttributeExpression=logAttributeExpression;exports.logExcludeAttributeExpression=logExcludeAttributeExpression;exports.logIncludeExcludeIssue=logIncludeExcludeIssue;