@yahoo/uds 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- "use strict";var l=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var m=(n,e)=>{for(var i in e)l(n,i,{get:e[i],enumerable:!0})},E=(n,e,i,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of x(e))!g.call(n,r)&&r!==i&&l(n,r,{get:()=>e[r],enumerable:!(s=u(e,r))||s.enumerable});return n};var F=n=>E(l({},"__esModule",{value:!0}),n);var C={};m(C,{findReferencesAsJsxElements:()=>J,getJsxElement:()=>D,getJsxElements:()=>f,getReactFunctionDeclaration:()=>d,getUsedPropsInReference:()=>A,isForwardRefExpression:()=>a,isJsxComponent:()=>c});module.exports=F(C);var t=require("ts-morph");function a(n){if(t.Node.isCallExpression(n)){let e=n.getExpression();if(t.Node.isIdentifier(e)&&e.getText()==="forwardRef"||t.Node.isPropertyAccessExpression(e)&&e.getText()==="React.forwardRef")return!0}return!1}function c(n){let e;return t.Node.isVariableDeclaration(n)||t.Node.isFunctionDeclaration(n)||t.Node.isClassDeclaration(n)?e=n.getName():(t.Node.isFunctionExpression(n)||t.Node.isArrowFunction(n))&&(e=n.getFirstAncestorByKind(t.SyntaxKind.VariableDeclaration)?.getName()),e?/[A-Z]/.test(e.charAt(0)):!1}function d(n){if(c(n)){if(t.Node.isFunctionDeclaration(n))return n;if(t.Node.isVariableDeclaration(n)){let e=n.getInitializer();if(e){if(a(e)){let[i]=e.getArguments();if(t.Node.isFunctionDeclaration(i)||t.Node.isFunctionExpression(i)||t.Node.isArrowFunction(i))return i}else if(t.Node.isFunctionDeclaration(e)||t.Node.isFunctionExpression(e)||t.Node.isArrowFunction(e))return e}}}return null}function D(n,e){return f(n).find(i=>i.getFirstDescendantByKindOrThrow(t.SyntaxKind.Identifier).getText()===e)}function f(n){return n.getDescendants().filter(e=>t.Node.isJsxElement(e)||t.Node.isJsxSelfClosingElement(e))}function J(n){let e=[];for(let i of n.findReferencesAsNodes()){let s=i.getFirstAncestor(r=>t.Node.isJsxOpeningElement(r)||t.Node.isJsxSelfClosingElement(r));s&&e.push(s)}return e}var A=n=>n.getAttributes().map(s=>{if(t.Node.isJsxAttribute(s))return[s.getNameNode().getText()];if(t.Node.isJsxSpreadAttribute(s)){let r=s.getExpression().getChildren(),o=r.length===0?s.getExpression():r.pop();return!o||o?.getText()==="props"?[]:o.getType().getProperties().map(p=>p.getName()).flat()}return[]}).flat();0&&(module.exports={findReferencesAsJsxElements,getJsxElement,getJsxElements,getReactFunctionDeclaration,getUsedPropsInReference,isForwardRefExpression,isJsxComponent});
1
+ "use strict";var f=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var J=(t,e)=>{for(var i in e)f(t,i,{get:e[i],enumerable:!0})},C=(t,e,i,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of D(e))!F.call(t,r)&&r!==i&&f(t,r,{get:()=>e[r],enumerable:!(s=E(e,r))||s.enumerable});return t};var A=t=>C(f({},"__esModule",{value:!0}),t);var h={};J(h,{findReferencesAsJsxElements:()=>S,getJsxElement:()=>O,getJsxElements:()=>d,getParentSpreadOrParamIdentifier:()=>m,getReactFunctionDeclaration:()=>p,getUsedPropsInReference:()=>b,isForwardRefExpression:()=>u,isJsxComponent:()=>x});module.exports=A(h);var n=require("ts-morph");function u(t){if(n.Node.isCallExpression(t)){let e=t.getExpression();if(n.Node.isIdentifier(e)&&e.getText()==="forwardRef"||n.Node.isPropertyAccessExpression(e)&&e.getText()==="React.forwardRef")return!0}return!1}function x(t){let e;return n.Node.isVariableDeclaration(t)||n.Node.isFunctionDeclaration(t)||n.Node.isClassDeclaration(t)?e=t.getName():(n.Node.isFunctionExpression(t)||n.Node.isArrowFunction(t))&&(e=t.getFirstAncestorByKind(n.SyntaxKind.VariableDeclaration)?.getName()),e?/[A-Z]/.test(e.charAt(0)):!1}function p(t){if(x(t)){if(n.Node.isFunctionDeclaration(t))return t;if(n.Node.isVariableDeclaration(t)){let e=t.getInitializer();if(e){if(u(e)){let[i]=e.getArguments();if(n.Node.isFunctionDeclaration(i)||n.Node.isFunctionExpression(i)||n.Node.isArrowFunction(i))return i}else if(n.Node.isFunctionDeclaration(e)||n.Node.isFunctionExpression(e)||n.Node.isArrowFunction(e))return e}}}return null}function O(t,e){return d(t).find(i=>i.getFirstDescendantByKindOrThrow(n.SyntaxKind.Identifier).getText()===e)}function d(t){return t.getDescendants().filter(e=>n.Node.isJsxElement(e)||n.Node.isJsxSelfClosingElement(e))}function S(t){let e=[];for(let i of t.findReferencesAsNodes()){let s=i.getFirstAncestor(r=>n.Node.isJsxOpeningElement(r)||n.Node.isJsxSelfClosingElement(r));s&&e.push(s)}return e}var m=t=>{let i=t.getParentWhile(r=>!p(r)).getParent();if(!i)return;let s=p(i);if(s){let r=s.getParameters();for(let o=0;o<r.length;o++){let a=r[o],c=a.getChildrenOfKind(n.SyntaxKind.ObjectBindingPattern)[0],l=a.getChildrenOfKind(n.SyntaxKind.Identifier)[0];if(c){let g=c.getFirstDescendantByKind(n.SyntaxKind.DotDotDotToken);if(g!==void 0)return g?.getParent()?.getFirstChildByKindOrThrow(n.SyntaxKind.Identifier).getText()}else if(l)return l.getText()}}},b=t=>t.getAttributes().map(s=>{if(n.Node.isJsxAttribute(s))return[s.getNameNode().getText()];if(n.Node.isJsxSpreadAttribute(s)){let r=m(t),o=s.getExpression().getChildren(),a=o.length===0?s.getExpression():o.pop();return!a||a?.getText()===r?[]:a.getType().getProperties().map(l=>l.getName()).flat()}return[]}).flat();0&&(module.exports={findReferencesAsJsxElements,getJsxElement,getJsxElements,getParentSpreadOrParamIdentifier,getReactFunctionDeclaration,getUsedPropsInReference,isForwardRefExpression,isJsxComponent});
@@ -17,9 +17,15 @@ declare function getJsxElements(node: Node): (JsxElement | JsxSelfClosingElement
17
17
  * Note, this currently does not account for cases where the component is used as a prop or is renamed.
18
18
  */
19
19
  declare function findReferencesAsJsxElements(identifer: Identifier): (JsxOpeningElement | JsxSelfClosingElement)[];
20
+ /**
21
+ * Given a Jsx Reference, this function finds the parent of that reference,
22
+ * looks at the props, and returns the name used either for spread operator rest or
23
+ * the prop name if there's no spread operator
24
+ */
25
+ declare const getParentSpreadOrParamIdentifier: (reference: JsxOpeningElement | JsxSelfClosingElement) => string | undefined;
20
26
  /**
21
27
  * Get used props on a reference.
22
28
  */
23
29
  declare const getUsedPropsInReference: (reference: JsxOpeningElement | JsxSelfClosingElement) => string[];
24
30
 
25
- export { findReferencesAsJsxElements, getJsxElement, getJsxElements, getReactFunctionDeclaration, getUsedPropsInReference, isForwardRefExpression, isJsxComponent };
31
+ export { findReferencesAsJsxElements, getJsxElement, getJsxElements, getParentSpreadOrParamIdentifier, getReactFunctionDeclaration, getUsedPropsInReference, isForwardRefExpression, isJsxComponent };
@@ -17,9 +17,15 @@ declare function getJsxElements(node: Node): (JsxElement | JsxSelfClosingElement
17
17
  * Note, this currently does not account for cases where the component is used as a prop or is renamed.
18
18
  */
19
19
  declare function findReferencesAsJsxElements(identifer: Identifier): (JsxOpeningElement | JsxSelfClosingElement)[];
20
+ /**
21
+ * Given a Jsx Reference, this function finds the parent of that reference,
22
+ * looks at the props, and returns the name used either for spread operator rest or
23
+ * the prop name if there's no spread operator
24
+ */
25
+ declare const getParentSpreadOrParamIdentifier: (reference: JsxOpeningElement | JsxSelfClosingElement) => string | undefined;
20
26
  /**
21
27
  * Get used props on a reference.
22
28
  */
23
29
  declare const getUsedPropsInReference: (reference: JsxOpeningElement | JsxSelfClosingElement) => string[];
24
30
 
25
- export { findReferencesAsJsxElements, getJsxElement, getJsxElements, getReactFunctionDeclaration, getUsedPropsInReference, isForwardRefExpression, isJsxComponent };
31
+ export { findReferencesAsJsxElements, getJsxElement, getJsxElements, getParentSpreadOrParamIdentifier, getReactFunctionDeclaration, getUsedPropsInReference, isForwardRefExpression, isJsxComponent };
@@ -1 +1 @@
1
- import{Node as t,SyntaxKind as l}from"ts-morph";function c(n){if(t.isCallExpression(n)){let e=n.getExpression();if(t.isIdentifier(e)&&e.getText()==="forwardRef"||t.isPropertyAccessExpression(e)&&e.getText()==="React.forwardRef")return!0}return!1}function f(n){let e;return t.isVariableDeclaration(n)||t.isFunctionDeclaration(n)||t.isClassDeclaration(n)?e=n.getName():(t.isFunctionExpression(n)||t.isArrowFunction(n))&&(e=n.getFirstAncestorByKind(l.VariableDeclaration)?.getName()),e?/[A-Z]/.test(e.charAt(0)):!1}function g(n){if(f(n)){if(t.isFunctionDeclaration(n))return n;if(t.isVariableDeclaration(n)){let e=n.getInitializer();if(e){if(c(e)){let[i]=e.getArguments();if(t.isFunctionDeclaration(i)||t.isFunctionExpression(i)||t.isArrowFunction(i))return i}else if(t.isFunctionDeclaration(e)||t.isFunctionExpression(e)||t.isArrowFunction(e))return e}}}return null}function m(n,e){return p(n).find(i=>i.getFirstDescendantByKindOrThrow(l.Identifier).getText()===e)}function p(n){return n.getDescendants().filter(e=>t.isJsxElement(e)||t.isJsxSelfClosingElement(e))}function E(n){let e=[];for(let i of n.findReferencesAsNodes()){let s=i.getFirstAncestor(r=>t.isJsxOpeningElement(r)||t.isJsxSelfClosingElement(r));s&&e.push(s)}return e}var F=n=>n.getAttributes().map(s=>{if(t.isJsxAttribute(s))return[s.getNameNode().getText()];if(t.isJsxSpreadAttribute(s)){let r=s.getExpression().getChildren(),o=r.length===0?s.getExpression():r.pop();return!o||o?.getText()==="props"?[]:o.getType().getProperties().map(a=>a.getName()).flat()}return[]}).flat();export{E as findReferencesAsJsxElements,m as getJsxElement,p as getJsxElements,g as getReactFunctionDeclaration,F as getUsedPropsInReference,c as isForwardRefExpression,f as isJsxComponent};
1
+ import{Node as n,SyntaxKind as l}from"ts-morph";function u(e){if(n.isCallExpression(e)){let t=e.getExpression();if(n.isIdentifier(t)&&t.getText()==="forwardRef"||n.isPropertyAccessExpression(t)&&t.getText()==="React.forwardRef")return!0}return!1}function x(e){let t;return n.isVariableDeclaration(e)||n.isFunctionDeclaration(e)||n.isClassDeclaration(e)?t=e.getName():(n.isFunctionExpression(e)||n.isArrowFunction(e))&&(t=e.getFirstAncestorByKind(l.VariableDeclaration)?.getName()),t?/[A-Z]/.test(t.charAt(0)):!1}function g(e){if(x(e)){if(n.isFunctionDeclaration(e))return e;if(n.isVariableDeclaration(e)){let t=e.getInitializer();if(t){if(u(t)){let[i]=t.getArguments();if(n.isFunctionDeclaration(i)||n.isFunctionExpression(i)||n.isArrowFunction(i))return i}else if(n.isFunctionDeclaration(t)||n.isFunctionExpression(t)||n.isArrowFunction(t))return t}}}return null}function J(e,t){return d(e).find(i=>i.getFirstDescendantByKindOrThrow(l.Identifier).getText()===t)}function d(e){return e.getDescendants().filter(t=>n.isJsxElement(t)||n.isJsxSelfClosingElement(t))}function C(e){let t=[];for(let i of e.findReferencesAsNodes()){let r=i.getFirstAncestor(s=>n.isJsxOpeningElement(s)||n.isJsxSelfClosingElement(s));r&&t.push(r)}return t}var m=e=>{let i=e.getParentWhile(s=>!g(s)).getParent();if(!i)return;let r=g(i);if(r){let s=r.getParameters();for(let o=0;o<s.length;o++){let a=s[o],f=a.getChildrenOfKind(l.ObjectBindingPattern)[0],c=a.getChildrenOfKind(l.Identifier)[0];if(f){let p=f.getFirstDescendantByKind(l.DotDotDotToken);if(p!==void 0)return p?.getParent()?.getFirstChildByKindOrThrow(l.Identifier).getText()}else if(c)return c.getText()}}},A=e=>e.getAttributes().map(r=>{if(n.isJsxAttribute(r))return[r.getNameNode().getText()];if(n.isJsxSpreadAttribute(r)){let s=m(e),o=r.getExpression().getChildren(),a=o.length===0?r.getExpression():o.pop();return!a||a?.getText()===s?[]:a.getType().getProperties().map(c=>c.getName()).flat()}return[]}).flat();export{C as findReferencesAsJsxElements,J as getJsxElement,d as getJsxElements,m as getParentSpreadOrParamIdentifier,g as getReactFunctionDeclaration,A as getUsedPropsInReference,u as isForwardRefExpression,x as isJsxComponent};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@yahoo/uds",
3
3
  "description": "Yahoo Universal System",
4
- "version": "0.4.5",
4
+ "version": "0.4.6",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "uds": "./cli/uds-cli"