@webority/tokens 0.148.0 → 0.150.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 (71) hide show
  1. package/dist/brand.d.ts +39 -25
  2. package/dist/brand.js +2 -2
  3. package/dist/build.d.ts +41 -0
  4. package/dist/build.js +5 -5
  5. package/dist/canvas/webority-phone.json +1 -1
  6. package/dist/canvas/webority-web-390.json +1 -1
  7. package/dist/canvas/webority-web.json +1 -1
  8. package/dist/check.d.ts +37 -0
  9. package/dist/check.js +3 -3
  10. package/dist/cli.d.ts +15 -96
  11. package/dist/cli.js +1 -1
  12. package/dist/emit/canvas.d.ts +8 -0
  13. package/dist/emit/canvas.js +1 -1
  14. package/dist/emit/email.d.ts +32 -0
  15. package/dist/emit/email.js +2 -2
  16. package/dist/emit/meanings.d.ts +3 -0
  17. package/dist/emit/phone.d.ts +26 -0
  18. package/dist/emit/phone.js +3 -3
  19. package/dist/emit/web.d.ts +18 -0
  20. package/dist/emit/web.js +14 -14
  21. package/dist/guards.d.ts +3 -0
  22. package/dist/guards.js +1 -0
  23. package/dist/index.d.ts +7 -7
  24. package/dist/meanings.json +1 -1
  25. package/dist/model/colour.d.ts +8 -0
  26. package/dist/model/colour.js +1 -1
  27. package/dist/model/contrast.d.ts +26 -0
  28. package/dist/model/contrast.js +1 -1
  29. package/dist/model/index.d.ts +52 -0
  30. package/dist/model/length.d.ts +21 -0
  31. package/dist/model/length.js +1 -1
  32. package/dist/model/load.d.ts +32 -0
  33. package/dist/model/load.js +1 -1
  34. package/dist/model/references.d.ts +3 -0
  35. package/dist/model/references.js +1 -1
  36. package/dist/model/resolve.d.ts +4 -0
  37. package/dist/model/resolve.js +2 -2
  38. package/dist/names.d.ts +1 -11
  39. package/dist/names.js +1 -1
  40. package/dist/outputs.d.ts +51 -102
  41. package/dist/present.d.ts +1 -0
  42. package/dist/present.js +1 -0
  43. package/dist/ramp.d.ts +8 -0
  44. package/dist/ramp.js +1 -1
  45. package/dist/upgrade/classes.d.ts +13 -0
  46. package/dist/upgrade/classes.js +2 -2
  47. package/dist/upgrade/components.d.ts +19 -0
  48. package/dist/upgrade/components.js +3 -3
  49. package/dist/upgrade/css.d.ts +28 -0
  50. package/dist/upgrade/css.js +2 -2
  51. package/dist/upgrade/index.d.ts +64 -0
  52. package/dist/upgrade/index.js +2 -2
  53. package/dist/upgrade/razorAttributes.d.ts +19 -0
  54. package/dist/upgrade/razorAttributes.js +2 -2
  55. package/dist/upgrade/razorTags.d.ts +19 -0
  56. package/dist/upgrade/razorTags.js +2 -2
  57. package/dist/upgrade/razorValueSplits.d.ts +19 -0
  58. package/dist/upgrade/razorValueSplits.js +2 -2
  59. package/dist/upgrade/source.d.ts +19 -0
  60. package/dist/upgrade/source.js +3 -3
  61. package/dist/upgrade/tagScan.d.ts +7 -0
  62. package/dist/upgrade/tagScan.js +1 -1
  63. package/dist/upgrade/themeReads.d.ts +55 -0
  64. package/dist/upgrade/themeReads.js +2 -2
  65. package/dist/upgrade/valueSplits.d.ts +23 -0
  66. package/dist/upgrade/valueSplits.js +3 -3
  67. package/dist/upgrade/wrapperValues.d.ts +71 -0
  68. package/dist/upgrade/wrapperValues.js +1 -1
  69. package/dist/webority.d.ts +1 -0
  70. package/package.json +7 -3
  71. package/renames/renames.d.ts +1 -1
@@ -0,0 +1,19 @@
1
+ import type { RazorValueSplitRule } from "../../renames/renames.d.ts";
2
+ export type RazorValueSplitHit = {
3
+ line: number;
4
+ from: string;
5
+ to: string;
6
+ };
7
+ export type RazorValueSplitFinding = {
8
+ file: string;
9
+ line: number;
10
+ path: string;
11
+ message: string;
12
+ };
13
+ export type RazorValueSplitResult = {
14
+ text: string;
15
+ hits: RazorValueSplitHit[];
16
+ findings: RazorValueSplitFinding[];
17
+ };
18
+ /** @param file repo-relative, forward slashes */
19
+ export declare function applyRazorValueSplits(source: string, file: string, rules: RazorValueSplitRule[]): RazorValueSplitResult;
@@ -1,2 +1,2 @@
1
- import{findQuoteEnd as e,tagOccurrences as t}from"./tagScan.js";import{applyEdits as n}from"./themeReads.js";import{separatorAt as r}from"./valueSplits.js";var i=new Set([`.cshtml`,`.razor`]),a=/(\s*)([^\s=/>"']+)(\s*=\s*)?/y,o=e=>{let t=/\.[^./]*$/.exec(e);return t?t[0].toLowerCase():``},s=(e,t)=>e.slice(0,t).split(`
2
- `).length;function c(t,n,r){let i=[],o=n;for(;;){a.lastIndex=o;let n=a.exec(t);if(n===null)break;let s=n.index+n[1].length,c={name:n[2],nameStart:s,nameEnd:s+n[2].length,wsStart:n.index,kind:`none`,attrEnd:s+n[2].length},l=n.index+n[0].length;if(n[3]!==void 0&&(t[l]===`"`||t[l]===`'`)){let n=e(t,l);if(n===-1)break;c.kind=`quoted`,c.value=t.slice(l+1,n),c.attrEnd=n+1}else n[3]!==void 0&&(c.kind=`bare`,c.attrEnd=l+/[^\s"'>]*/y.exec(t.slice(l))[0].length);if(c.attrEnd>r)break;i.push(c),o=c.attrEnd}return i}function l(e,a,l){if(l.length===0||!i.has(o(a)))return{text:e,hits:[],findings:[]};let u=[],d=[],f=[];for(let n of l)for(let i of n.tags)for(let{nameEnd:o,end:l}of t(e,i)){if(l===-1){f.push({file:a,line:s(e,o),path:`<${i}>`,message:`the tag could not be read (a quote in an attribute value does not pair up); set it by hand`});continue}let t=c(e,o,l),p=new Set(t.map(e=>e.name));for(let o of t){if(o.name!==n.attribute)continue;let t=s(e,o.nameStart),c=`<${i}> ${n.attribute}`,l=o.kind===`none`?`true`:o.kind===`quoted`?o.value.toLowerCase():void 0;if(l!==void 0&&!Object.hasOwn(n.values,l)&&n.keep?.includes(l))continue;if(l===void 0||!Object.hasOwn(n.values,l)){f.push({file:a,line:t,path:c,message:n.flag});continue}let m=Object.entries(n.values[l]).filter(([,e])=>e!==null),h=m.map(([e])=>e).filter(e=>e!==n.attribute&&p.has(e));if(h.length>0){f.push({file:a,line:t,path:c,message:`<${i}> already sets ${h.join(` and `)}; merge ${n.attribute} into it by hand`});continue}let g=m.map(([e,t])=>`${e}="${t}"`).join(r(e,o.nameStart));if(n.skipWritten&&g===e.slice(o.nameStart,o.attrEnd))continue;let _=m.length===0?o.wsStart:o.nameStart;u.push({start:_,end:o.attrEnd,text:g}),d.push({line:t,from:e.slice(o.nameStart,o.attrEnd),to:g.replace(/\n\s*/g,` `)})}}return d.sort((e,t)=>e.line-t.line||(e.from<t.from?-1:+(e.from>t.from))),f.sort((e,t)=>e.line-t.line||(e.path<t.path?-1:+(e.path>t.path))),{text:n(e,u,a),hits:d,findings:f}}export{l as applyRazorValueSplits};
1
+ import{present as e}from"../present.js";import{findQuoteEnd as t,tagOccurrences as n}from"./tagScan.js";import{applyEdits as r}from"./themeReads.js";import{separatorAt as i}from"./valueSplits.js";var a=new Set([`.cshtml`,`.razor`]),o=/(\s*)([^\s=/>"']+)(\s*=\s*)?/y,s=e=>{let t=/\.[^./]*$/.exec(e);return t?t[0].toLowerCase():``},c=(e,t)=>e.slice(0,t).split(`
2
+ `).length;function l(n,r,i){let a=[],s=r;for(;;){o.lastIndex=s;let r=o.exec(n);if(r===null)break;let c=e(r[2],`the attribute name`),l=r.index+e(r[1],`the whitespace before an attribute`).length,u={name:c,nameStart:l,nameEnd:l+c.length,wsStart:r.index,kind:`none`,attrEnd:l+c.length},d=r.index+r[0].length;if(r[3]!==void 0&&(n[d]===`"`||n[d]===`'`)){let e=t(n,d);if(e===-1)break;u.kind=`quoted`,u.value=n.slice(d+1,e),u.attrEnd=e+1}else if(r[3]!==void 0){u.kind=`bare`;let e=/[^\s"'>]*/y.exec(n.slice(d));if(e===null)throw Error(`webority-tokens: bare attribute value is missing.`);u.attrEnd=d+e[0].length}if(u.attrEnd>i)break;a.push(u),s=u.attrEnd}return a}function u(t,o,u){if(u.length===0||!a.has(s(o)))return{text:t,hits:[],findings:[]};let d=[],f=[],p=[];for(let r of u)for(let a of r.tags)for(let{nameEnd:s,end:u}of n(t,a)){if(u===-1){p.push({file:o,line:c(t,s),path:`<${a}>`,message:`the tag could not be read (a quote in an attribute value does not pair up); set it by hand`});continue}let n=l(t,s,u),m=new Set(n.map(e=>e.name));for(let s of n){if(s.name!==r.attribute)continue;let n=c(t,s.nameStart),l=`<${a}> ${r.attribute}`,u=s.kind===`none`?`true`:s.kind===`quoted`&&s.value!==void 0?s.value.toLowerCase():void 0;if(u!==void 0&&!Object.hasOwn(r.values,u)&&r.keep?.includes(u))continue;if(u===void 0||!Object.hasOwn(r.values,u)){p.push({file:o,line:n,path:l,message:r.flag});continue}let h=Object.entries(e(r.values[u],`the table's values for the attribute`)).filter(([,e])=>e!==null),g=h.map(([e])=>e).filter(e=>e!==r.attribute&&m.has(e));if(g.length>0){p.push({file:o,line:n,path:l,message:`<${a}> already sets ${g.join(` and `)}; merge ${r.attribute} into it by hand`});continue}let _=h.map(([e,t])=>`${e}="${t}"`).join(i(t,s.nameStart));if(r.skipWritten&&_===t.slice(s.nameStart,s.attrEnd))continue;let v=h.length===0?s.wsStart:s.nameStart;d.push({start:v,end:s.attrEnd,text:_}),f.push({line:n,from:t.slice(s.nameStart,s.attrEnd),to:_.replace(/\n\s*/g,` `)})}}return f.sort((e,t)=>e.line-t.line||(e.from<t.from?-1:+(e.from>t.from))),p.sort((e,t)=>e.line-t.line||(e.path<t.path?-1:+(e.path>t.path))),{text:r(t,d,o),hits:f,findings:p}}export{u as applyRazorValueSplits};
@@ -0,0 +1,19 @@
1
+ import type { MarkupRules, SourceRules } from "../../renames/renames.d.ts";
2
+ export type SourceHit = {
3
+ line: number;
4
+ from: string;
5
+ to: string;
6
+ };
7
+ export type SourceFinding = {
8
+ line: number;
9
+ path: string;
10
+ message: string;
11
+ };
12
+ export type SourceResult = {
13
+ text: string;
14
+ hits: SourceHit[];
15
+ findings: SourceFinding[];
16
+ };
17
+ export declare const SOURCE_EXTENSIONS: Set<string>;
18
+ export declare function applySource(text: string, file: string, rules: SourceRules | undefined): SourceResult;
19
+ export declare function applyMarkup(text: string, file: string, rules: MarkupRules | undefined): SourceResult;
@@ -1,3 +1,3 @@
1
- import e from"node:path";var t=new Set([`.js`,`.jsx`,`.mjs`,`.cjs`,`.ts`,`.tsx`,`.mts`,`.cts`]),n=new Set([`.cshtml`,`.razor`,`.html`]),r=`["'\`]`,i=`[A-Za-z_$][\\w$]*`,a=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),o=e=>[...e].sort((e,t)=>t.length-e.length).map(a).join(`|`),s=e=>{let t=[0];for(let n=0;n<e.length;n++)e[n]===`
2
- `&&t.push(n+1);return t},c=(e,t)=>{let n=0,r=e.length-1;for(;n<r;){let i=n+r+1>>1;e[i]<=t?n=i:r=i-1}return n+1},l=(e,t)=>e<t?-1:+(e>t),u=(e,t,n)=>{if(t.length===0)return e;let i=new Map(t),a=RegExp(`(${r})(${o(i.keys())})\\1`,`g`),l=s(e);return e.replace(a,(e,t,r,a)=>{let o=i.get(r);return n.push({line:c(l,a),from:r,to:o}),`${t}${o}${t}`})},d=(e,t,n)=>{let r=e;for(let e of t){let t=e.receiver===void 0?void 0:RegExp(`^(?:${e.receiver})$`),o=RegExp(`(${i})(\\?\\.|\\.)${a(e.from)}(?![\\w$])`,`g`),l=s(r);r=r.replace(o,(r,i,a,o)=>t!==void 0&&!t.test(i)?r:(n.push({line:c(l,o),from:`${i}${a}${e.from}`,to:`${i}${a}${e.to}`}),`${i}${a}${e.to}`))}return r},f=(e,t)=>RegExp(`(?:\\bfrom\\s*|\\bimport\\s*\\(?\\s*|\\brequire\\(\\s*)["']${a(t)}["']`).test(e),p=(e,t)=>{let n=e.split(`
3
- `),r=[],i=new Map;for(let a of t){if(a.importedFrom!==void 0&&(i.has(a.importedFrom)||i.set(a.importedFrom,f(e,a.importedFrom)),!i.get(a.importedFrom)))continue;let t=new RegExp(a.pattern);for(let e=0;e<n.length;e++){let i=t.exec(n[e]);i!==null&&r.push({line:e+1,path:i[0],message:a.hint})}}return r},m=e=>RegExp(`(?:\\b(?:import|export)\\s+(?:type\\s+)?(?:[\\w$]+\\s*,\\s*)?\\{([^}]*)\\}\\s*from\\s*|\\b(?:const|let|var)\\s*\\{([^}]*)\\}\\s*=\\s*require\\(\\s*)(["'])${a(e)}\\3`,`g`),h=(e,t)=>{let n=[],r=s(e);for(let i of t){let t=new Set(i.names);for(let a of e.matchAll(m(i.package))){let e=a[1]??a[2],o=a.index+a[0].indexOf(`{`)+1,s=0;for(let a of e.split(`,`)){let e=a.length-a.trimStart().length,l=a.trim().replace(/^type\s+/,``).split(/\s+as\s+|:/)[0].trim();t.has(l)&&n.push({line:c(r,o+s+e),path:l,message:i.hint}),s+=a.length+1}}}return n};function g(n,r,i){if(i===void 0||!t.has(e.extname(r).toLowerCase()))return{text:n,hits:[],findings:[]};let a=[],o=d(u(n,i.literals,a),i.members,a),s=p(o,i.flags);return s.push(...h(o,i.removedImports??[])),a.sort((e,t)=>e.line-t.line||l(e.from,t.from)),s.sort((e,t)=>e.line-t.line||l(e.path,t.path)),{text:o,hits:a,findings:s}}function _(t,r,i){if(i===void 0||!n.has(e.extname(r).toLowerCase()))return{text:t,hits:[],findings:[]};let a=[],o=u(t,i.literals,a),s=p(o,i.flags);return a.sort((e,t)=>e.line-t.line||l(e.from,t.from)),s.sort((e,t)=>e.line-t.line||l(e.path,t.path)),{text:o,hits:a,findings:s}}export{t as SOURCE_EXTENSIONS,_ as applyMarkup,g as applySource};
1
+ import{present as e}from"../present.js";import t from"node:path";var n=new Set([`.js`,`.jsx`,`.mjs`,`.cjs`,`.ts`,`.tsx`,`.mts`,`.cts`]),r=new Set([`.cshtml`,`.razor`,`.html`]),i=`["'\`]`,a=`[A-Za-z_$][\\w$]*`,o=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),s=e=>[...e].sort((e,t)=>t.length-e.length).map(o).join(`|`),c=e=>{let t=[0];for(let n=0;n<e.length;n++)e[n]===`
2
+ `&&t.push(n+1);return t},l=(t,n)=>{let r=0,i=t.length-1;for(;r<i;){let a=r+i+1>>1;e(t[a],`line start`)<=n?r=a:i=a-1}return r+1},u=(e,t)=>e<t?-1:+(e>t),d=(t,n,r)=>{if(n.length===0)return t;let a=new Map(n),o=RegExp(`(${i})(${s(a.keys())})\\1`,`g`),u=c(t);return t.replace(o,(t,n,i,o)=>{let s=e(a.get(i),`rename`);return r.push({line:l(u,o),from:i,to:s}),`${n}${s}${n}`})},f=(e,t,n)=>{let r=e;for(let e of t){let t=e.receiver===void 0?void 0:RegExp(`^(?:${e.receiver})$`),i=RegExp(`(${a})(\\?\\.|\\.)${o(e.from)}(?![\\w$])`,`g`),s=c(r);r=r.replace(i,(r,i,a,o)=>t!==void 0&&!t.test(i)?r:(n.push({line:l(s,o),from:`${i}${a}${e.from}`,to:`${i}${a}${e.to}`}),`${i}${a}${e.to}`))}return r},p=(e,t)=>RegExp(`(?:\\bfrom\\s*|\\bimport\\s*\\(?\\s*|\\brequire\\(\\s*)["']${o(t)}["']`).test(e),m=(e,t)=>{let n=e.split(`
3
+ `),r=[],i=new Map;for(let a of t){if(a.importedFrom!==void 0&&(i.has(a.importedFrom)||i.set(a.importedFrom,p(e,a.importedFrom)),!i.get(a.importedFrom)))continue;let t=new RegExp(a.pattern);for(let[e,i]of n.entries()){let n=t.exec(i);n!==null&&r.push({line:e+1,path:n[0],message:a.hint})}}return r},h=e=>RegExp(`(?:\\b(?:import|export)\\s+(?:type\\s+)?(?:[\\w$]+\\s*,\\s*)?\\{([^}]*)\\}\\s*from\\s*|\\b(?:const|let|var)\\s*\\{([^}]*)\\}\\s*=\\s*require\\(\\s*)(["'])${o(e)}\\3`,`g`),g=(t,n)=>{let r=[],i=c(t);for(let a of n){let n=new Set(a.names);for(let o of t.matchAll(h(a.package))){let t=e(o[1]??o[2],`regex group`),s=o.index+o[0].indexOf(`{`)+1,c=0;for(let o of t.split(`,`)){let t=o.length-o.trimStart().length,[u]=o.trim().replace(/^type\s+/,``).split(/\s+as\s+|:/),d=e(u,`import name`).trim();n.has(d)&&r.push({line:l(i,s+c+t),path:d,message:a.hint}),c+=o.length+1}}}return r};function _(e,r,i){if(i===void 0||!n.has(t.extname(r).toLowerCase()))return{text:e,hits:[],findings:[]};let a=[],o=f(d(e,i.literals,a),i.members,a),s=m(o,i.flags);return s.push(...g(o,i.removedImports??[])),a.sort((e,t)=>e.line-t.line||u(e.from,t.from)),s.sort((e,t)=>e.line-t.line||u(e.path,t.path)),{text:o,hits:a,findings:s}}function v(e,n,i){if(i===void 0||!r.has(t.extname(n).toLowerCase()))return{text:e,hits:[],findings:[]};let a=[],o=d(e,i.literals,a),s=m(o,i.flags);return a.sort((e,t)=>e.line-t.line||u(e.from,t.from)),s.sort((e,t)=>e.line-t.line||u(e.path,t.path)),{text:o,hits:a,findings:s}}export{n as SOURCE_EXTENSIONS,v as applyMarkup,_ as applySource};
@@ -0,0 +1,7 @@
1
+ export declare function findQuoteEnd(source: string, from: number): number;
2
+ export declare function findTagEnd(source: string, from: number): number;
3
+ export type TagOccurrence = {
4
+ nameEnd: number;
5
+ end: number;
6
+ };
7
+ export declare function tagOccurrences(source: string, tag: string): TagOccurrence[];
@@ -1 +1 @@
1
- var e=e=>/[\p{L}\p{Nd}_.]/u.test(e);function t(e,t,n){for(let r=t+1;r<e.length;r++)if(e[r]===`\\`)r++;else if(e[r]===n)return r+1;return-1}function n(e,t){for(let n=t+2;n<e.length;n++)if(e[n]===`"`){if(e[n+1]===`"`)n++;else return n+1}return-1}function r(e,r){let i=0,a=r;for(;a<e.length;){let r=e[a];if(r===`@`&&e[a+1]===`"`)a=n(e,a);else if(r===`"`||r===`'`)a=t(e,a,r);else{if(a++,r===`(`||r===`[`)i++;else if((r===`)`||r===`]`)&&(i--,i===0))return a;continue}if(a===-1)return-1}return-1}function i(t,n){let i=n+1;for(;;){for(;i<t.length&&e(t[i]);)i++;let n=t[i];if(n!==`(`&&n!==`[`)return i;if(i=r(t,i),i===-1)return-1;let a=t[i];if(a!==`.`&&a!==`(`&&a!==`[`)return i}}function a(e,t){let n=e[t],r=t+1;for(;r<e.length;){let t=e[r];if(t===`@`&&e[r+1]===`@`)r+=2;else if(t===`@`){if(r=i(e,r),r===-1)return-1}else if(t===n)return r;else r++}return-1}function o(e,t){let n=t;for(;n<e.length;){let t=e[n];if(t===`"`||t===`'`){if(n=a(e,n),n===-1)return-1}else if(t===`>`)return n;n++}return-1}function s(e,t){let n=`<${t}`,r=[];for(let t=e.indexOf(n);t!==-1;t=e.indexOf(n,t+1)){let i=t+n.length;/[\s/>]/.test(e[i]??``)&&r.push({nameEnd:i,end:o(e,i)})}return r}export{a as findQuoteEnd,o as findTagEnd,s as tagOccurrences};
1
+ var e=e=>e!==void 0&&/[\p{L}\p{Nd}_.]/u.test(e);function t(e,t,n){for(let r=t+1;r<e.length;r++)if(e[r]===`\\`)r++;else if(e[r]===n)return r+1;return-1}function n(e,t){for(let n=t+2;n<e.length;n++)if(e[n]===`"`){if(e[n+1]===`"`)n++;else return n+1}return-1}function r(e,r){let i=0,a=r;for(;a<e.length;){let r=e[a];if(r===`@`&&e[a+1]===`"`)a=n(e,a);else if(r===`"`||r===`'`)a=t(e,a,r);else{if(a++,r===`(`||r===`[`)i++;else if((r===`)`||r===`]`)&&(i--,i===0))return a;continue}if(a===-1)return-1}return-1}function i(t,n){let i=n+1;for(;;){for(;i<t.length&&e(t[i]);)i++;let n=t[i];if(n!==`(`&&n!==`[`)return i;if(i=r(t,i),i===-1)return-1;let a=t[i];if(a!==`.`&&a!==`(`&&a!==`[`)return i}}function a(e,t){let n=e[t],r=t+1;for(;r<e.length;){let t=e[r];if(t===`@`&&e[r+1]===`@`)r+=2;else if(t===`@`){if(r=i(e,r),r===-1)return-1}else if(t===n)return r;else r++}return-1}function o(e,t){let n=t;for(;n<e.length;){let t=e[n];if(t===`"`||t===`'`){if(n=a(e,n),n===-1)return-1}else if(t===`>`)return n;n++}return-1}function s(e,t){let n=`<${t}`,r=[];for(let t=e.indexOf(n);t!==-1;t=e.indexOf(n,t+1)){let i=t+n.length;/[\s/>]/.test(e[i]??``)&&r.push({nameEnd:i,end:o(e,i)})}return r}export{a as findQuoteEnd,o as findTagEnd,s as tagOccurrences};
@@ -0,0 +1,55 @@
1
+ import type { File, JSXOpeningElement, Node } from "@babel/types";
2
+ import type { RenameTable, RetiredThemeRead } from "../../renames/renames.d.ts";
3
+ type SourceLocation = NonNullable<Node["loc"]>;
4
+ export type ThemeReadHit = {
5
+ line: number;
6
+ from: string;
7
+ to: string;
8
+ };
9
+ export type ThemeReadFinding = {
10
+ file: string;
11
+ line: number;
12
+ path: string;
13
+ message: string;
14
+ };
15
+ export type Edit = {
16
+ start: number;
17
+ end: number;
18
+ text: string;
19
+ };
20
+ export type ThemeReadResult = {
21
+ text: string;
22
+ hits: ThemeReadHit[];
23
+ findings: ThemeReadFinding[];
24
+ };
25
+ export declare function spanOf(node: Node): {
26
+ start: number;
27
+ end: number;
28
+ loc: SourceLocation;
29
+ };
30
+ /**
31
+ * Calls onNode with each AST node and its ancestors (parent last).
32
+ */
33
+ export declare const visit: (value: unknown, onNode: (node: Node, ancestors: Node[]) => void, ancestors?: Node[]) => void;
34
+ /**
35
+ * Returns null for a file type the engine does not read; throws when the file does not parse.
36
+ */
37
+ export declare const parseSource: (source: string, file: string) => File | null;
38
+ export declare const skipped: (source: string, file: string, error: unknown) => ThemeReadResult;
39
+ export declare const applyEdits: (code: string, edits: Edit[], file: string) => string;
40
+ export declare function applyThemeReads(source: string, file: string, entries: readonly RetiredThemeRead[]): ThemeReadResult;
41
+ export declare const stringNode: (value: Node | null | undefined) => StringLiteralNode | undefined;
42
+ type StringLiteralNode = Extract<Node, {
43
+ type: "StringLiteral";
44
+ }>;
45
+ export declare function applyProps(source: string, file: string, rules: RenameTable["props"]): ThemeReadResult;
46
+ export declare function applyComponentProps(source: string, file: string, rules: RenameTable["componentProps"]): ThemeReadResult;
47
+ export type ImportedComponents = {
48
+ named: Map<string, string>;
49
+ namespaces: Set<string>;
50
+ };
51
+ export declare const importedComponents: (ast: File, pkg: string) => ImportedComponents;
52
+ export declare const componentOf: (name: JSXOpeningElement["name"], imports: ImportedComponents) => string | undefined;
53
+ export declare function applyPropValues(source: string, file: string, rules: RenameTable["propValues"]): ThemeReadResult;
54
+ export declare function applyPropSplits(source: string, file: string, rules: RenameTable["propSplits"]): ThemeReadResult;
55
+ export {};
@@ -1,2 +1,2 @@
1
- import e from"node:path";import{parse as t}from"@babel/parser";var n=new Set([`FunctionDeclaration`,`FunctionExpression`,`ArrowFunctionExpression`,`ObjectMethod`,`ClassMethod`]),r=new Set([`MemberExpression`,`OptionalMemberExpression`]),i=new Set([`CallExpression`,`OptionalCallExpression`]),a=new Set([`useTheme`,`getTheme`]),o=new Set([`loc`,`start`,`end`,`extra`,`comments`,`leadingComments`,`trailingComments`,`innerComments`]),s=new Map([[`.js`,[`jsx`]],[`.jsx`,[`jsx`]],[`.mjs`,[`jsx`]],[`.cjs`,[`jsx`]],[`.ts`,[`typescript`]],[`.tsx`,[`typescript`,`jsx`]]]),c=/^[A-Za-z_$][\w$]*$/,l=new Set([`lightOverrides`,`darkOverrides`]),u=`move the brand into theme/brand.tokens.json, list the app under tokens.heads.phone, run webority brand, pass brand and settings`,d=e=>typeof e==`object`&&!!e&&typeof e.type==`string`,f=(e,t,n=[])=>{if(Array.isArray(e)){for(let r of e)f(r,t,n);return}if(!d(e))return;t(e,n);let r=[...n,e];for(let[n,i]of Object.entries(e))!o.has(n)&&typeof i==`object`&&i&&f(i,t,r)},p=(n,r)=>{let i=s.get(e.extname(r).toLowerCase());return i===void 0?null:t(n,{sourceType:`module`,plugins:i})},m=(e,t,n)=>({text:e,hits:[],findings:[{file:t,line:1,path:``,message:`skipped, it does not parse (${(n instanceof Error?n.message:String(n)).split(`
2
- `)[0]})`}]}),h=(e,t,n)=>{let r=[...t].sort((e,t)=>e.start-t.start||e.end-t.end),i=0;for(let e of r){if(e.start<i)throw Error(`two edits overlap in ${n}; fix it by hand`);i=e.end}let a=e;for(let e of r.reverse())a=a.slice(0,e.start)+e.text+a.slice(e.end);return a},g=e=>e.replace(/\.$/,``).split(`.`),_=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),v=(e,t)=>e<t?-1:+(e>t),y=(e,t)=>{let n=t.at(-1);return n!==void 0&&r.has(n.type)&&n.object===e},b=(e,t)=>d(e)&&i.has(e.type)&&e.callee.type===`Identifier`&&t.has(e.callee.name),x=e=>{for(let t=e.length-1;t>=0;t--)if(n.has(e[t].type))return e[t];return e.find(e=>e.type===`Program`)},S=(e,t)=>{let n=new Map;return f(e,(e,r)=>{if(e.type!==`VariableDeclarator`||e.id.type!==`Identifier`||!b(e.init,t))return;let i=x(r);n.has(i)||n.set(i,new Set),n.get(i)?.add(e.id.name)}),n},C=(e,t,r)=>t.some(t=>(n.has(t.type)||t.type===`Program`)&&r.get(t)?.has(e)===!0),w=(e,t,n,r)=>e.type===`Identifier`?e.name===`theme`&&r.size>0||C(e.name,t,n):b(e,r),T=e=>{if(e.computed!==!0&&e.property.type===`Identifier`)return e.property.name;if(e.computed===!0&&e.property.type===`StringLiteral`)return e.property.value};function E(e,t,n){if(n.length===0)return{text:e,hits:[],findings:[]};let i;try{i=p(e,t)}catch(n){return m(e,t,n)}if(i===null)return{text:e,hits:[],findings:[]};let o=new Set;f(i,e=>{if(e.type===`ImportDeclaration`&&e.source.value.startsWith(`@webority/`))for(let t of e.specifiers){if(t.type!==`ImportSpecifier`)continue;let e=t.imported.type===`StringLiteral`?t.imported.value:t.imported.name;a.has(e)&&o.add(t.local.name)}});let s=S(i,o),d=n.filter(e=>e.kind===`path`||e.kind===`prefix`||e.kind===`gone`).sort((e,t)=>g(t.from).length-g(e.from).length),b=n.filter(e=>e.kind===`kebab`),x=[],C=[],E=[],D=new Set,O=(e,n)=>{let r=`${e}:${n}`;D.has(r)||(D.add(r),E.push({file:t,line:e,path:n,message:u}))},k=(e,n)=>{let i=[],a=e;for(;r.has(a.type);)i.unshift(a),a=a.object;if(!w(a,n,s,o))return;let l=[];for(let e of i){let t=T(e);if(t===void 0)break;l.push(t)}let u=l.length;if(u===0)return;let f=[...l];for(let e of d){let n=g(e.from),r=e.kind===`prefix`&&e.from.endsWith(`.`);if(!(u<n.length||r&&u===n.length)&&n.every((e,t)=>l[t]===e)){if(e.kind===`gone`){E.push({file:t,line:i[n.length-1].property.loc.start.line,path:n.join(`.`),message:`no longer exists; ${e.hint}`});return}if(e.kind===`path`||e.kind===`prefix`){f=[...g(e.to),...l.slice(n.length)];break}}}for(let e of b){let t=e.under.split(`.`),n=t.length;if(f.length<=n||!t.every((e,t)=>f[t]===e))continue;let r=f[n];Object.hasOwn(e.names,r)&&(f[n]=e.names[r]);for(let e=n+1;e<f.length;e++)/[A-Z]/.test(f[e])&&(f[e]=f[e].replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase())}if(_(f,l))return;let p=f.map((e,t)=>{let n=i[t]?.optional===!0;return c.test(e)?`${n?`?.`:`.`}${e}`:`${n?`?.`:``}["${e}"]`}).join(``);x.push({start:a.end,end:i[u-1].end,text:p}),C.push({line:i[0].property.loc.start.line,from:l.join(`.`),to:f.join(`.`)})};return f(i,(e,t)=>{r.has(e.type)&&!y(e,t)&&k(e,t),e.type===`JSXAttribute`&&e.name.type===`JSXIdentifier`&&l.has(e.name.name)&&O(e.loc.start.line,e.name.name),e.type===`Identifier`&&e.name===`ThemeOverrides`&&O(e.loc.start.line,e.name)}),C.sort((e,t)=>e.line-t.line||v(e.from,t.from)),E.sort((e,t)=>e.line-t.line||v(e.path,t.path)),{text:h(e,x,t),hits:C,findings:E}}var D=(e,t,n)=>{if(e.type===`JSXIdentifier`)return t.has(e.name);if(e.type===`JSXMemberExpression`){let t=e;for(;t.type===`JSXMemberExpression`;)t=t.object;return t.type===`JSXIdentifier`&&n.has(t.name)}return!1},O=e=>{if(e?.type===`StringLiteral`)return e;if(e?.type===`JSXExpressionContainer`&&e.expression.type===`StringLiteral`)return e.expression};function k(e,t,n){if(n.length===0)return{text:e,hits:[],findings:[]};let r;try{r=p(e,t)}catch(n){return m(e,t,n)}if(r===null)return{text:e,hits:[],findings:[]};let i=[],a=[];for(let t of n){let n=new Set,o=new Set;f(r,e=>{if(e.type===`ImportDeclaration`&&e.source.value===t.package)for(let t of e.specifiers)t.type===`ImportNamespaceSpecifier`?o.add(t.local.name):n.add(t.local.name)});let s=new Set(t.props);f(r,r=>{if(r.type===`JSXOpeningElement`&&D(r.name,n,o))for(let n of r.attributes){if(n.type!==`JSXAttribute`||n.name.type!==`JSXIdentifier`||!s.has(n.name.name))continue;let r=O(n.value);if(r===void 0||r.value!==t.from)continue;let o=e[r.start];i.push({start:r.start,end:r.end,text:`${o}${t.to}${o}`}),a.push({line:r.loc.start.line,from:`${n.name.name}="${t.from}"`,to:`${n.name.name}="${t.to}"`})}})}return a.sort((e,t)=>e.line-t.line||v(e.from,t.from)),{text:h(e,i,t),hits:a,findings:[]}}function A(e,t,n){if(n.length===0)return{text:e,hits:[],findings:[]};let r;try{r=p(e,t)}catch(n){return m(e,t,n)}if(r===null)return{text:e,hits:[],findings:[]};let i=[],a=[],o=[],s=new Set;for(let c of n){let n=N(r,c.package);f(r,r=>{if(r.type!==`JSXOpeningElement`)return;let l=P(r.name,n);if(c.components.includes(l))for(let n of r.attributes){if(n.type!==`JSXAttribute`||n.name.type!==`JSXIdentifier`||n.name.name!==c.prop||s.has(n.start))continue;s.add(n.start);let u=n.loc.start.line,d=`${l}.${c.prop}`;if(c.flag&&c.to===void 0&&c.values===void 0){o.push({file:t,line:u,path:d,message:c.flag});continue}if(c.to&&c.to!==c.prop&&r.attributes.some(e=>j(e,c.to))){o.push({file:t,line:u,path:d,message:`${l} already sets ${c.to}; merge ${c.prop} into it by hand`});continue}let f=n.value===null?void 0:O(n.value)?.value??null,p=c.prop,m=f,h=i.length;c.to&&c.to!==c.prop&&(i.push({start:n.name.start,end:n.name.end,text:c.to}),p=c.to);let g=O(n.value);if(c.values&&g!==void 0&&Object.hasOwn(c.values,g.value)){let t=e[g.start];m=c.values[g.value],i.push({start:g.start,end:g.end,text:`${t}${m}${t}`})}c.flag&&g===void 0&&o.push({file:t,line:u,path:d,message:c.flag}),i.length!==h&&a.push({line:u,from:M(c.prop,f),to:M(p,m)})}})}return a.sort((e,t)=>e.line-t.line||v(e.from,t.from)),o.sort((e,t)=>e.line-t.line||v(e.path,t.path)),{text:h(e,i,t),hits:a,findings:o}}var j=(e,t)=>e.type===`JSXAttribute`&&e.name.type===`JSXIdentifier`&&e.name.name===t,M=(e,t)=>t===void 0?e:t===null?`${e}={...}`:`${e}="${t}"`,N=(e,t)=>{let n=new Map,r=new Set;return f(e,e=>{if(e.type===`ImportDeclaration`&&e.source.value===t)for(let t of e.specifiers)if(t.type===`ImportSpecifier`){let e=t.imported.type===`StringLiteral`?t.imported.value:t.imported.name;n.set(t.local.name,e)}else t.type===`ImportNamespaceSpecifier`&&r.add(t.local.name)}),{named:n,namespaces:r}},P=(e,t)=>{if(e.type===`JSXIdentifier`)return t.named.get(e.name);if(e.type===`JSXMemberExpression`&&e.object.type===`JSXIdentifier`&&t.namespaces.has(e.object.name))return e.property.name};function F(e,t,n){if(n.length===0)return{text:e,hits:[],findings:[]};let r;try{r=p(e,t)}catch(n){return m(e,t,n)}if(r===null)return{text:e,hits:[],findings:[]};let i=[],a=[],o=[];for(let s of n){let n=N(r,s.package);f(r,r=>{if(r.type!==`JSXOpeningElement`)return;let c=P(r.name,n);if(s.components.includes(c))for(let n of r.attributes){if(n.type!==`JSXAttribute`||n.name.type!==`JSXIdentifier`||n.name.name!==s.prop)continue;let r=n.value,l=n.loc.start.line,u=r?.type===`JSXExpressionContainer`?r.expression:void 0,d=r===null?!0:u?.type===`BooleanLiteral`?u.value:void 0,f;if(d!==void 0)f=`${s.prop}="${d?s.true:s.false}"`;else if(O(r)!==void 0)continue;else{o.push({file:t,line:l,path:`${c}.${s.prop}`,message:`${s.prop} takes a named value such as "${s.true}" or "${s.false}" now, not a boolean; set it by hand`});continue}i.push({start:n.start,end:n.end,text:f}),a.push({line:l,from:e.slice(n.start,n.end),to:f})}})}return a.sort((e,t)=>e.line-t.line||v(e.from,t.from)),o.sort((e,t)=>e.line-t.line||v(e.path,t.path)),{text:h(e,i,t),hits:a,findings:o}}function I(e,t,n){if(n.length===0)return{text:e,hits:[],findings:[]};let r;try{r=p(e,t)}catch(n){return m(e,t,n)}if(r===null)return{text:e,hits:[],findings:[]};let i=t=>e.slice(t.start,t.end),a=new Set([`ObjectExpression`,`Identifier`,`MemberExpression`,`OptionalMemberExpression`]),o=new Set([`SequenceExpression`,`AssignmentExpression`,`ConditionalExpression`,`YieldExpression`]),s=e=>{if(e?.type===`LogicalExpression`&&e.operator===`&&`)return{test:e.left,consequent:e.right};let t=e?.alternate;if(e?.type===`ConditionalExpression`&&(t.type===`NullLiteral`||t.type===`Identifier`&&t.name===`undefined`||t.type===`BooleanLiteral`&&t.value===!1))return{test:e.test,consequent:e.consequent}},c=e=>o.has(e.test.type)?`(${i(e.test)})`:i(e.test),l=[],u=[],d=[];for(let e of n){let n=N(r,e.package);f(r,r=>{if(r.type!==`JSXOpeningElement`)return;let o=P(r.name,n);if(!e.components.includes(o))return;let f=r.attributes.some(t=>t.type===`JSXAttribute`&&t.name.type===`JSXIdentifier`&&t.name.name===e.into);for(let n of r.attributes){if(n.type!==`JSXAttribute`||n.name.type!==`JSXIdentifier`||n.name.name!==e.prop)continue;let r=n.value,p=n.loc.start.line;if(O(r)!==void 0)continue;let m=`${o}.${e.prop}`;if(f){d.push({file:t,line:p,path:m,message:`already sets ${e.into}; set ${e.prop} to "${e.on}" or "${e.off}" by hand`});continue}let h=r?.type===`JSXExpressionContainer`?r.expression:void 0,g=r===null?!0:h?.type===`BooleanLiteral`?h.value:void 0,_=s(h),v;if(g!==void 0)v=`${e.prop}="${g?e.on:e.off}"`;else if(a.has(h?.type))v=`${e.prop}="${e.on}" ${e.into}={${i(h)}}`;else if(_!==void 0&&_.consequent.type===`BooleanLiteral`&&_.consequent.value===!0)v=`${e.prop}={${c(_)} ? "${e.on}" : "${e.off}"}`;else if(_!==void 0&&a.has(_.consequent.type))v=`${e.prop}={${c(_)} ? "${e.on}" : "${e.off}"} ${e.into}={${i(_.consequent)}}`;else{d.push({file:t,line:p,path:m,message:`${e.prop} takes "${e.on}" or "${e.off}" now, and its settings object moves to ${e.into}; set both by hand`});continue}l.push({start:n.start,end:n.end,text:v}),u.push({line:p,from:i(n),to:v})}})}return u.sort((e,t)=>e.line-t.line||v(e.from,t.from)),d.sort((e,t)=>e.line-t.line||v(e.path,t.path)),{text:h(e,l,t),hits:u,findings:d}}export{A as applyComponentProps,h as applyEdits,I as applyPropSplits,F as applyPropValues,k as applyProps,E as applyThemeReads,P as componentOf,N as importedComponents,p as parseSource,m as skipped,O as stringNode,f as visit};
1
+ import{present as e}from"../present.js";import t from"node:path";import{parse as n}from"@babel/parser";function r(e){let{start:t,end:n,loc:r}=e;if(t==null||n==null||r==null)throw Error(`${e.type}: the parser left no source position`);return{start:t,end:n,loc:r}}var i=new Set([`loc`,`start`,`end`,`extra`,`comments`,`leadingComments`,`trailingComments`,`innerComments`]),a=new Map([[`.js`,[`jsx`]],[`.jsx`,[`jsx`]],[`.mjs`,[`jsx`]],[`.cjs`,[`jsx`]],[`.ts`,[`typescript`]],[`.tsx`,[`typescript`,`jsx`]]]),o=new Set([`useTheme`,`getTheme`]),s=/^[A-Za-z_$][\w$]*$/,c=new Set([`lightOverrides`,`darkOverrides`]),l=`move the brand into theme/brand.tokens.json, list the app under tokens.heads.phone, run webority brand, pass brand and settings`,u=e=>typeof e==`object`&&!!e&&`type`in e&&typeof e.type==`string`,d=e=>e.type===`FunctionDeclaration`||e.type===`FunctionExpression`||e.type===`ArrowFunctionExpression`||e.type===`ObjectMethod`||e.type===`ClassMethod`,f=e=>e.type===`MemberExpression`||e.type===`OptionalMemberExpression`,p=e=>e.type===`CallExpression`||e.type===`OptionalCallExpression`,m=(e,t,n=[])=>{if(Array.isArray(e)){for(let r of e)m(r,t,n);return}if(!u(e))return;t(e,n);let r=[...n,e];for(let[n,a]of Object.entries(e))!i.has(n)&&typeof a==`object`&&a&&m(a,t,r)},h=(e,r)=>{let i=a.get(t.extname(r).toLowerCase());return i===void 0?null:n(e,{sourceType:`module`,plugins:i})},g=(t,n,r)=>{let i=r instanceof Error?r.message:String(r);return{text:t,hits:[],findings:[{file:n,line:1,path:``,message:`skipped, it does not parse (${e(i.split(`
2
+ `)[0],`error message`)})`}]}},_=(e,t,n)=>{let r=[...t].sort((e,t)=>e.start-t.start||e.end-t.end),i=0;for(let e of r){if(e.start<i)throw Error(`two edits overlap in ${n}; fix it by hand`);i=e.end}let a=e;for(let e of r.reverse())a=a.slice(0,e.start)+e.text+a.slice(e.end);return a},v=e=>e.replace(/\.$/,``).split(`.`),y=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),b=(e,t)=>e<t?-1:+(e>t),x=(e,t)=>{let n=t.at(-1);return n!==void 0&&f(n)&&n.object===e},S=(e,t)=>u(e)&&p(e)&&e.callee.type===`Identifier`&&t.has(e.callee.name),C=e=>e.findLast(d)??e.find(e=>e.type===`Program`),w=(e,t)=>{let n=new Map;return m(e,(e,r)=>{if(e.type!==`VariableDeclarator`||e.id.type!==`Identifier`||!S(e.init,t))return;let i=C(r);n.has(i)||n.set(i,new Set),n.get(i)?.add(e.id.name)}),n},T=(e,t,n)=>t.some(t=>(d(t)||t.type===`Program`)&&n.get(t)?.has(e)===!0),E=(e,t,n,r)=>e.type===`Identifier`?e.name===`theme`&&r.size>0||T(e.name,t,n):S(e,r),D=e=>{if(e.computed!==!0&&e.property.type===`Identifier`)return e.property.name;if(e.computed===!0&&e.property.type===`StringLiteral`)return e.property.value},O=e=>e.kind!==`kebab`,k=e=>e.kind===`kebab`;function A(t,n,i){if(i.length===0)return{text:t,hits:[],findings:[]};let a;try{a=h(t,n)}catch(e){return g(t,n,e)}if(a===null)return{text:t,hits:[],findings:[]};let u=new Set;m(a,e=>{if(e.type===`ImportDeclaration`&&e.source.value.startsWith(`@webority/`))for(let t of e.specifiers){if(t.type!==`ImportSpecifier`)continue;let e=t.imported.type===`StringLiteral`?t.imported.value:t.imported.name;o.has(e)&&u.add(t.local.name)}});let d=w(a,u),p=i.filter(O).sort((e,t)=>v(t.from).length-v(e.from).length),S=i.filter(k),C=[],T=[],A=[],j=new Set,M=(e,t)=>{let r=`${e}:${t}`;j.has(r)||(j.add(r),A.push({file:n,line:e,path:t,message:l}))},N=(t,i)=>{let a=[],o=t;for(;f(o);)a.unshift(o),o=o.object;if(!E(o,i,d,u))return;let c=[];for(let e of a){let t=D(e);if(t===void 0)break;c.push(t)}let l=c.length;if(l===0)return;let m=[...c];for(let t of p){let i=v(t.from),o=t.kind===`prefix`&&t.from.endsWith(`.`);if(!(l<i.length||o&&l===i.length)&&i.every((e,t)=>c[t]===e)){if(t.kind===`gone`){A.push({file:n,line:r(e(a[i.length-1],`member`).property).loc.start.line,path:i.join(`.`),message:`no longer exists; ${t.hint}`});return}if(t.kind===`path`||t.kind===`prefix`){m=[...v(t.to),...c.slice(i.length)];break}}}for(let t of S){let n=t.under.split(`.`),r=n.length;if(m.length<=r||!n.every((e,t)=>m[t]===e))continue;let i=e(m[r],`segment`);Object.hasOwn(t.names,i)&&(m[r]=e(t.names[i],`kebab name`));for(let t=r+1;t<m.length;t++){let n=e(m[t],`segment`);/[A-Z]/.test(n)&&(m[t]=n.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase())}}if(y(m,c))return;let h=m.map((e,t)=>{let n=a[t]?.optional===!0;return s.test(e)?`${n?`?.`:`.`}${e}`:`${n?`?.`:``}["${e}"]`}).join(``);C.push({start:r(o).end,end:r(e(a[l-1],`member`)).end,text:h}),T.push({line:r(e(a[0],`member`).property).loc.start.line,from:c.join(`.`),to:m.join(`.`)})};return m(a,(e,t)=>{f(e)&&!x(e,t)&&N(e,t),e.type===`JSXAttribute`&&e.name.type===`JSXIdentifier`&&c.has(e.name.name)&&M(r(e).loc.start.line,e.name.name),e.type===`Identifier`&&e.name===`ThemeOverrides`&&M(r(e).loc.start.line,e.name)}),T.sort((e,t)=>e.line-t.line||b(e.from,t.from)),A.sort((e,t)=>e.line-t.line||b(e.path,t.path)),{text:_(t,C,n),hits:T,findings:A}}var j=(e,t,n)=>{if(e.type===`JSXIdentifier`)return t.has(e.name);if(e.type===`JSXMemberExpression`){let t=e;for(;t.type===`JSXMemberExpression`;)t=t.object;return t.type===`JSXIdentifier`&&n.has(t.name)}return!1},M=e=>{if(e?.type===`StringLiteral`)return e;if(e?.type===`JSXExpressionContainer`&&e.expression.type===`StringLiteral`)return e.expression};function N(e,t,n){if(n.length===0)return{text:e,hits:[],findings:[]};let i;try{i=h(e,t)}catch(n){return g(e,t,n)}if(i===null)return{text:e,hits:[],findings:[]};let a=[],o=[];for(let t of n){let n=new Set,s=new Set;m(i,e=>{if(e.type===`ImportDeclaration`&&e.source.value===t.package)for(let t of e.specifiers)t.type===`ImportNamespaceSpecifier`?s.add(t.local.name):n.add(t.local.name)});let c=new Set(t.props);m(i,i=>{if(i.type===`JSXOpeningElement`&&j(i.name,n,s))for(let n of i.attributes){if(n.type!==`JSXAttribute`||n.name.type!==`JSXIdentifier`||!c.has(n.name.name))continue;let i=M(n.value);if(i===void 0||i.value!==t.from)continue;let s=e[r(i).start];a.push({start:r(i).start,end:r(i).end,text:`${s}${t.to}${s}`}),o.push({line:r(i).loc.start.line,from:`${n.name.name}="${t.from}"`,to:`${n.name.name}="${t.to}"`})}})}return o.sort((e,t)=>e.line-t.line||b(e.from,t.from)),{text:_(e,a,t),hits:o,findings:[]}}function P(e,t,n){if(n.length===0)return{text:e,hits:[],findings:[]};let i;try{i=h(e,t)}catch(n){return g(e,t,n)}if(i===null)return{text:e,hits:[],findings:[]};let a=[],o=[],s=[],c=new Set;for(let l of n){let n=L(i,l.package),u=l.to;m(i,i=>{if(i.type!==`JSXOpeningElement`)return;let d=R(i.name,n);if(d!==void 0&&l.components.includes(d))for(let n of i.attributes){if(n.type!==`JSXAttribute`||n.name.type!==`JSXIdentifier`||n.name.name!==l.prop||c.has(r(n).start))continue;c.add(r(n).start);let f=r(n).loc.start.line,p=`${d}.${l.prop}`;if(l.flag&&l.to===void 0&&l.values===void 0){s.push({file:t,line:f,path:p,message:l.flag});continue}if(u&&u!==l.prop&&i.attributes.some(e=>F(e,u))){s.push({file:t,line:f,path:p,message:`${d} already sets ${u}; merge ${l.prop} into it by hand`});continue}let m=n.value===null?void 0:M(n.value)?.value??null,h=l.prop,g=m,_=a.length;l.to&&l.to!==l.prop&&(a.push({start:r(n.name).start,end:r(n.name).end,text:l.to}),h=l.to);let v=M(n.value);if(l.values&&v!==void 0&&Object.hasOwn(l.values,v.value)){let t=e[r(v).start];g=l.values[v.value],a.push({start:r(v).start,end:r(v).end,text:`${t}${g}${t}`})}l.flag&&v===void 0&&s.push({file:t,line:f,path:p,message:l.flag}),a.length!==_&&o.push({line:f,from:I(l.prop,m),to:I(h,g)})}})}return o.sort((e,t)=>e.line-t.line||b(e.from,t.from)),s.sort((e,t)=>e.line-t.line||b(e.path,t.path)),{text:_(e,a,t),hits:o,findings:s}}var F=(e,t)=>e.type===`JSXAttribute`&&e.name.type===`JSXIdentifier`&&e.name.name===t,I=(e,t)=>t===void 0?e:t===null?`${e}={...}`:`${e}="${t}"`,L=(e,t)=>{let n=new Map,r=new Set;return m(e,e=>{if(e.type===`ImportDeclaration`&&e.source.value===t)for(let t of e.specifiers)if(t.type===`ImportSpecifier`){let e=t.imported.type===`StringLiteral`?t.imported.value:t.imported.name;n.set(t.local.name,e)}else t.type===`ImportNamespaceSpecifier`&&r.add(t.local.name)}),{named:n,namespaces:r}},R=(e,t)=>{if(e.type===`JSXIdentifier`)return t.named.get(e.name);if(e.type===`JSXMemberExpression`&&e.object.type===`JSXIdentifier`&&t.namespaces.has(e.object.name))return e.property.name};function z(e,t,n){if(n.length===0)return{text:e,hits:[],findings:[]};let i;try{i=h(e,t)}catch(n){return g(e,t,n)}if(i===null)return{text:e,hits:[],findings:[]};let a=[],o=[],s=[];for(let c of n){let n=L(i,c.package);m(i,i=>{if(i.type!==`JSXOpeningElement`)return;let l=R(i.name,n);if(l!==void 0&&c.components.includes(l))for(let n of i.attributes){if(n.type!==`JSXAttribute`||n.name.type!==`JSXIdentifier`||n.name.name!==c.prop)continue;let i=n.value,u=r(n).loc.start.line,d=i?.type===`JSXExpressionContainer`?i.expression:void 0,f=i===null?!0:d?.type===`BooleanLiteral`?d.value:void 0,p;if(f!==void 0)p=`${c.prop}="${f?c.true:c.false}"`;else if(M(i)!==void 0)continue;else{s.push({file:t,line:u,path:`${l}.${c.prop}`,message:`${c.prop} takes a named value such as "${c.true}" or "${c.false}" now, not a boolean; set it by hand`});continue}a.push({start:r(n).start,end:r(n).end,text:p}),o.push({line:u,from:e.slice(r(n).start,r(n).end),to:p})}})}return o.sort((e,t)=>e.line-t.line||b(e.from,t.from)),s.sort((e,t)=>e.line-t.line||b(e.path,t.path)),{text:_(e,a,t),hits:o,findings:s}}function B(e,t,n){if(n.length===0)return{text:e,hits:[],findings:[]};let i;try{i=h(e,t)}catch(n){return g(e,t,n)}if(i===null)return{text:e,hits:[],findings:[]};let a=t=>e.slice(r(t).start,r(t).end),o=new Set([`ObjectExpression`,`Identifier`,`MemberExpression`,`OptionalMemberExpression`]),s=new Set([`SequenceExpression`,`AssignmentExpression`,`ConditionalExpression`,`YieldExpression`]),c=e=>{if(e?.type===`LogicalExpression`&&e.operator===`&&`)return{test:e.left,consequent:e.right};if(e?.type===`ConditionalExpression`&&(e.alternate.type===`NullLiteral`||e.alternate.type===`Identifier`&&e.alternate.name===`undefined`||e.alternate.type===`BooleanLiteral`&&e.alternate.value===!1))return{test:e.test,consequent:e.consequent}},l=e=>s.has(e.test.type)?`(${a(e.test)})`:a(e.test),u=[],d=[],f=[];for(let e of n){let n=L(i,e.package);m(i,i=>{if(i.type!==`JSXOpeningElement`)return;let s=R(i.name,n);if(s===void 0||!e.components.includes(s))return;let p=i.attributes.some(t=>t.type===`JSXAttribute`&&t.name.type===`JSXIdentifier`&&t.name.name===e.into);for(let n of i.attributes){if(n.type!==`JSXAttribute`||n.name.type!==`JSXIdentifier`||n.name.name!==e.prop)continue;let i=n.value,m=r(n).loc.start.line;if(M(i)!==void 0)continue;let h=`${s}.${e.prop}`;if(p){f.push({file:t,line:m,path:h,message:`already sets ${e.into}; set ${e.prop} to "${e.on}" or "${e.off}" by hand`});continue}let g=i?.type===`JSXExpressionContainer`?i.expression:void 0,_=i===null?!0:g?.type===`BooleanLiteral`?g.value:void 0,v=c(g),y;if(_!==void 0)y=`${e.prop}="${_?e.on:e.off}"`;else if(g!==void 0&&o.has(g.type))y=`${e.prop}="${e.on}" ${e.into}={${a(g)}}`;else if(v!==void 0&&v.consequent.type===`BooleanLiteral`&&v.consequent.value===!0)y=`${e.prop}={${l(v)} ? "${e.on}" : "${e.off}"}`;else if(v!==void 0&&o.has(v.consequent.type))y=`${e.prop}={${l(v)} ? "${e.on}" : "${e.off}"} ${e.into}={${a(v.consequent)}}`;else{f.push({file:t,line:m,path:h,message:`${e.prop} takes "${e.on}" or "${e.off}" now, and its settings object moves to ${e.into}; set both by hand`});continue}u.push({start:r(n).start,end:r(n).end,text:y}),d.push({line:m,from:a(n),to:y})}})}return d.sort((e,t)=>e.line-t.line||b(e.from,t.from)),f.sort((e,t)=>e.line-t.line||b(e.path,t.path)),{text:_(e,u,t),hits:d,findings:f}}export{P as applyComponentProps,_ as applyEdits,B as applyPropSplits,z as applyPropValues,N as applyProps,A as applyThemeReads,R as componentOf,L as importedComponents,h as parseSource,g as skipped,r as spanOf,M as stringNode,m as visit};
@@ -0,0 +1,23 @@
1
+ import type { ValueSplitRule } from "../../renames/renames.d.ts";
2
+ export type ValueSplitHit = {
3
+ line: number;
4
+ from: string;
5
+ to: string;
6
+ };
7
+ export type ValueSplitFinding = {
8
+ file: string;
9
+ line: number;
10
+ path: string;
11
+ message: string;
12
+ };
13
+ export type ValueSplitResult = {
14
+ text: string;
15
+ hits: ValueSplitHit[];
16
+ findings: ValueSplitFinding[];
17
+ };
18
+ /**
19
+ * What goes between two props written in place of one: a space, or, when the attribute starts its own line in a
20
+ * multi-line tag, a line break with that line's indentation, as the formatter lays it out.
21
+ */
22
+ export declare const separatorAt: (source: string, start: number) => string;
23
+ export declare function applyValueSplits(source: string, file: string, rules: ValueSplitRule[]): ValueSplitResult;
@@ -1,4 +1,4 @@
1
- import{applyEdits as e,componentOf as t,importedComponents as n,parseSource as r,skipped as i,stringNode as a,visit as o}from"./themeReads.js";var s=e=>e===null?`true`:e.type===`JSXExpressionContainer`&&e.expression.type===`BooleanLiteral`?String(e.expression.value):a(e)?.value,c=(e,t)=>typeof t==`string`?`${e}="${t}"`:`${e}={${t}}`,l=(e,t)=>{let n=e.lastIndexOf(`
1
+ import{present as e}from"../present.js";import{applyEdits as t,componentOf as n,importedComponents as r,parseSource as i,skipped as a,spanOf as o,stringNode as s,visit as c}from"./themeReads.js";var l=e=>e===null?`true`:e?.type===`JSXExpressionContainer`&&e.expression.type===`BooleanLiteral`?String(e.expression.value):s(e)?.value,u=(e,t)=>typeof t==`string`?`${e}="${t}"`:`${e}={${t}}`,d=(e,t)=>{let n=e.lastIndexOf(`
2
2
  `,t.start-1)+1,r=e.indexOf(`
3
- `,t.end),i=r===-1?e.length:r;if(e.slice(n,t.start).trim()===``&&e.slice(t.end,i).trim()===``)return{start:n,end:i===e.length?i:i+1};let a=t.start;for(;a>0&&(e[a-1]===` `||e[a-1]===` `);)a--;return{start:a,end:t.end}},u=(e,t)=>{let n=e.lastIndexOf(`
4
- `,t-1)+1,r=e.slice(n,t);return r.trim()===``&&n>0?`\n${r}`:` `};function d(a,d,f){if(f.length===0)return{text:a,hits:[],findings:[]};let p;try{p=r(a,d)}catch(e){return i(a,d,e)}if(p===null)return{text:a,hits:[],findings:[]};let m=[],h=[],g=[];for(let e of f){let r=n(p,e.package);o(p,n=>{if(n.type!==`JSXOpeningElement`)return;let i=t(n.name,r);if(!e.components.includes(i))return;let o=new Set(n.attributes.filter(e=>e.type===`JSXAttribute`&&e.name.type===`JSXIdentifier`).map(e=>e.name.name));for(let t of n.attributes){if(t.type!==`JSXAttribute`||t.name.type!==`JSXIdentifier`||t.name.name!==e.prop)continue;let n=t.loc.start.line,r=`${i}.${e.prop}`,f=s(t.value);if(f!==void 0&&!Object.hasOwn(e.values,f)&&e.keep?.includes(f))continue;if(f===void 0||!Object.hasOwn(e.values,f)){g.push({file:d,line:n,path:r,message:e.flag});continue}let p=Object.entries(e.values[f]).filter(([,e])=>e!==null),_=p.map(([e])=>e).filter(t=>t!==e.prop&&o.has(t));if(_.length>0){g.push({file:d,line:n,path:r,message:`${i} already sets ${_.join(` and `)}; merge ${e.prop} into it by hand`});continue}let v=p.map(([e,t])=>c(e,t)).join(u(a,t.start)),y=p.length===0?l(a,t):{start:t.start,end:t.end};m.push({start:y.start,end:y.end,text:v}),h.push({line:n,from:a.slice(t.start,t.end),to:v.replace(/\n\s*/g,` `)})}})}return h.sort((e,t)=>e.line-t.line||(e.from<t.from?-1:+(e.from>t.from))),g.sort((e,t)=>e.line-t.line||(e.path<t.path?-1:+(e.path>t.path))),{text:e(a,m,d),hits:h,findings:g}}export{d as applyValueSplits,u as separatorAt};
3
+ `,t.end),i=r===-1?e.length:r;if(e.slice(n,t.start).trim()===``&&e.slice(t.end,i).trim()===``)return{start:n,end:i===e.length?i:i+1};let a=t.start;for(;a>0&&(e[a-1]===` `||e[a-1]===` `);)a--;return{start:a,end:t.end}},f=(e,t)=>{let n=e.lastIndexOf(`
4
+ `,t-1)+1,r=e.slice(n,t);return r.trim()===``&&n>0?`\n${r}`:` `};function p(s,p,m){if(m.length===0)return{text:s,hits:[],findings:[]};let h;try{h=i(s,p)}catch(e){return a(s,p,e)}if(h===null)return{text:s,hits:[],findings:[]};let g=[],_=[],v=[];for(let t of m){let i=r(h,t.package);c(h,r=>{if(r.type!==`JSXOpeningElement`)return;let a=n(r.name,i);if(a===void 0||!t.components.includes(a))return;let c=new Set;for(let e of r.attributes)e.type===`JSXAttribute`&&e.name.type===`JSXIdentifier`&&c.add(e.name.name);for(let n of r.attributes){if(n.type!==`JSXAttribute`||n.name.type!==`JSXIdentifier`||n.name.name!==t.prop)continue;let r=o(n).loc.start.line,i=`${a}.${t.prop}`,m=o(n).start,h=o(n).end,y=l(n.value);if(y!==void 0&&!Object.hasOwn(t.values,y)&&t.keep?.includes(y))continue;if(y===void 0||!Object.hasOwn(t.values,y)){v.push({file:p,line:r,path:i,message:t.flag});continue}let b=Object.entries(e(t.values[y],`rule value`)).filter(([,e])=>e!==null),x=b.map(([e])=>e).filter(e=>e!==t.prop&&c.has(e));if(x.length>0){v.push({file:p,line:r,path:i,message:`${a} already sets ${x.join(` and `)}; merge ${t.prop} into it by hand`});continue}let S=b.map(([e,t])=>u(e,t)).join(f(s,m)),C=b.length===0?d(s,{start:m,end:h}):{start:m,end:h};g.push({start:C.start,end:C.end,text:S}),_.push({line:r,from:s.slice(m,h),to:S.replace(/\n\s*/g,` `)})}})}return _.sort((e,t)=>e.line-t.line||(e.from<t.from?-1:+(e.from>t.from))),v.sort((e,t)=>e.line-t.line||(e.path<t.path?-1:+(e.path>t.path))),{text:t(s,g,p),hits:_,findings:v}}export{p as applyValueSplits,f as separatorAt};
@@ -0,0 +1,71 @@
1
+ import type { ArrowFunctionExpression, Expression, File, FunctionDeclaration, FunctionExpression } from "@babel/types";
2
+ import type { RenameTable } from "../../renames/renames.d.ts";
3
+ export type WrapperFinding = {
4
+ file: string;
5
+ line: number;
6
+ path: string;
7
+ message: string;
8
+ };
9
+ /**
10
+ * One library prop with old values: `components` null means every component the package exports.
11
+ */
12
+ export type Target = {
13
+ package: string;
14
+ components: string[] | null;
15
+ prop: string;
16
+ label: (component: string) => string;
17
+ old: Map<string, string>;
18
+ };
19
+ /**
20
+ * A product component that forwards its own prop `prop` to a target's prop.
21
+ */
22
+ export type Wrapper = {
23
+ file: string;
24
+ name: string;
25
+ prop: string;
26
+ target: Target;
27
+ reaches: string;
28
+ };
29
+ type Local = {
30
+ prop: string;
31
+ fallback: Expression | undefined;
32
+ };
33
+ export type Shape = {
34
+ props: Set<string>;
35
+ rest: Set<string>;
36
+ named: Set<string>;
37
+ locals: Map<string, Local>;
38
+ };
39
+ type FunctionLike = FunctionDeclaration | FunctionExpression | ArrowFunctionExpression;
40
+ export type Definition = {
41
+ name: string;
42
+ fn: FunctionLike;
43
+ shape: Shape;
44
+ };
45
+ export type WrapperIndex = {
46
+ wrappers: Wrapper[];
47
+ packages: Set<string>;
48
+ };
49
+ /**
50
+ * The library props whose old literal values a wrapper can carry.
51
+ */
52
+ export declare function wrapperTargets(table: RenameTable): Target[];
53
+ /**
54
+ * Each function component in a file with how its first parameter is read.
55
+ */
56
+ export declare function componentDefinitions(ast: File, file: string): Definition[];
57
+ /**
58
+ * Finds every product component that forwards an old-valued library prop, directly or through other wrappers.
59
+ * `asts` holds parsed files shared between tables; null marks a file that is not parsed.
60
+ */
61
+ export declare function findWrappers(root: string, files: string[], table: RenameTable, asts?: Map<string, File | null>): WrapperIndex;
62
+ /**
63
+ * Reports old values that reach a library component through a product's own component: at each use of a wrapper,
64
+ * and in the wrapper's own default. Writes nothing, because the wrapper may not forward the new props.
65
+ */
66
+ export declare function applyWrapperValues(source: string, file: string, index: WrapperIndex): {
67
+ text: string;
68
+ hits: never[];
69
+ findings: WrapperFinding[];
70
+ };
71
+ export {};
@@ -1 +1 @@
1
- import{componentOf as e,importedComponents as t,parseSource as n,stringNode as r,visit as i}from"./themeReads.js";import{readFileSync as a}from"node:fs";import{basename as o,dirname as s,join as c}from"node:path";var l=new Set([`FunctionDeclaration`,`FunctionExpression`,`ArrowFunctionExpression`]),u=5,d=[`dependencies`,`devDependencies`,`peerDependencies`,`optionalDependencies`],f=e=>{let t=Object.entries(e).filter(([,e])=>e!==null);return t.length===0?`nothing (drop the prop)`:t.map(([e,t])=>typeof t==`string`?`${e}="${t}"`:`${e}={${t}}`).join(` `)};function p(e){let t=[];for(let n of e.valueSplits??[]){let e=new Map;for(let[t,r]of Object.entries(n.values))t!==`true`&&t!==`false`&&!n.keep?.includes(t)&&e.set(t,f(r));e.size>0&&t.push({package:n.package,components:n.components,prop:n.prop,label:e=>`${e}.${n.prop}`,old:e})}for(let n of e.componentProps??[]){if(n.values===void 0)continue;let e=n.to??n.prop,r=new Map;for(let[t,i]of Object.entries(n.values))t!==i&&r.set(t,`${e}="${i}"`);r.size>0&&t.push({package:n.package,components:n.components,prop:n.prop,label:e=>`${e}.${n.prop}`,old:r})}for(let n of e.props??[])for(let e of n.props)t.push({package:n.package,components:null,prop:e,label:t=>`${t}.${e}`,old:new Map([[n.from,`${e}="${n.to}"`]])});return t}var m=e=>e.type===`Identifier`?e.name:e.type===`StringLiteral`?e.value:void 0,h=(e,t)=>{for(let n of e.properties){if(n.type===`RestElement`){n.argument.type===`Identifier`&&t.rest.add(n.argument.name);continue}if(n.type!==`ObjectProperty`||n.computed)continue;let e=m(n.key);if(e===void 0)continue;t.named.add(e);let r=n.value;r.type===`Identifier`?t.locals.set(r.name,{prop:e,fallback:void 0}):r.type===`AssignmentPattern`&&r.left.type===`Identifier`&&t.locals.set(r.left.name,{prop:e,fallback:r.right})}},g=e=>{if(e!=null){if(l.has(e.type))return e;if(e.type===`CallExpression`)for(let t of e.arguments){let e=g(t);if(e!==void 0)return e}}},_=e=>/^[A-Z]/.test(e);function v(e,t){let n=[],r=(e,t)=>{if(t===void 0||!_(e))return;let r={props:new Set,rest:new Set,named:new Set,locals:new Map},a=t.params[0];if(a?.type===`AssignmentPattern`&&(a=a.left),a?.type===`Identifier`)r.props.add(a.name);else if(a?.type===`ObjectPattern`)h(a,r);else return;i(t.body,e=>{e.type===`VariableDeclarator`&&e.id.type===`ObjectPattern`&&e.init?.type===`Identifier`&&r.props.has(e.init.name)&&h(e.id,r)}),n.push({name:e,fn:t,shape:r})};return i(e,(e,n)=>{if(e.type===`FunctionDeclaration`&&e.id!==null)r(e.id.name,e);else if(e.type===`VariableDeclarator`&&e.id.type===`Identifier`)r(e.id.name,g(e.init));else if(e.type===`ExportDefaultDeclaration`&&n.length===1){let n=e.declaration;l.has(n.type)&&n.id===null?r(o(t).replace(/\.[^.]+$/,``),n):n.type===`CallExpression`&&r(o(t).replace(/\.[^.]+$/,``),g(n))}}),n}var y=e=>{let t=e.split(`/`);return e.startsWith(`@`)?t.slice(0,2).join(`/`):t[0]},b=e=>e.replace(/\.(?:jsx?|mjs|cjs|tsx?)$/i,``).replace(/\/index$/,``),x=(e,t)=>{let n=e.split(`/`),r=t.split(`/`),i=0;for(;i<n.length-1&&i<r.length-1&&n[i]===r[i];)i++;return i},S=(e,t,n,r)=>{let a=new Map;i(e,e=>{if(e.type!==`ImportDeclaration`)return;let t=e.source.value;for(let n of e.specifiers)if(n.type===`ImportDefaultSpecifier`)a.set(n.local.name,{specifier:t,imported:null});else if(n.type===`ImportSpecifier`){let e=n.imported.type===`StringLiteral`?n.imported.value:n.imported.name;a.set(n.local.name,{specifier:t,imported:e==="default"?null:e})}else a.set(n.local.name,{specifier:t,imported:void 0})});let l=e=>!e.startsWith(`.`)&&!e.startsWith(`/`)&&(e.startsWith(`@webority/`)||r.has(y(e)));return e=>{if(e.type!==`JSXIdentifier`)return[];let r=e.name,i=a.get(r);if(i===void 0)return n.filter(e=>e.file===t&&e.name===r);if(i.imported===void 0||l(i.specifier))return[];let u=o(b(i.specifier)),d=n.filter(e=>i.imported===null?e.name===r||o(b(e.file))===u:e.name===i.imported);if(d.length===0)return[];if(i.specifier.startsWith(`.`)){let e=c(s(t),i.specifier).split(`\\`).join(`/`),n=d.filter(t=>b(t.file)===b(e));if(n.length>0)return n}let f=Math.max(...d.map(e=>x(e.file,t))),p=d.filter(e=>x(e.file,t)===f),m=[...new Set(p.map(e=>e.file))].sort()[0];return p.filter(e=>e.file===m)}},C=(e,t,n)=>{let r=e.attributes.find(e=>e.type===`JSXAttribute`&&e.name.type===`JSXIdentifier`&&e.name.name===t);if(r!==void 0){let e=r.value?.type===`JSXExpressionContainer`?r.value.expression:void 0;return e?.type===`Identifier`?n.locals.get(e.name)?.prop:e?.type===`MemberExpression`&&!e.computed&&e.object.type===`Identifier`&&n.props.has(e.object.name)&&e.property.type===`Identifier`?e.property.name:void 0}for(let r of e.attributes){if(r.type!==`JSXSpreadAttribute`||r.argument.type!==`Identifier`)continue;let e=r.argument.name;if(n.props.has(e)||n.rest.has(e)&&!n.named.has(t))return t}};function w(r,s,l,f=new Map){let m=p(l),h=new Set;for(let e of s)if(!(o(e)!==`package.json`||e.split(`/`).includes(`node_modules`)))try{let t=JSON.parse(a(c(r,e),`utf8`));for(let e of d)for(let n of Object.keys(t[e]??{}))h.add(n)}catch(t){throw Error(`${e} could not be read as a package manifest: ${t.message}`,{cause:t})}if(m.length===0)return{wrappers:[],packages:h};let g=[];for(let e of s){if(!f.has(e))try{f.set(e,n(a(c(r,e),`utf8`),e))}catch{f.set(e,null)}let t=f.get(e);t!==null&&g.push({file:e,ast:t,definitions:v(t,e)})}let _=[],y=new Set;for(let n=0;n<u;n++){let r=[..._],a=_.length;for(let{file:a,ast:o,definitions:s}of g){if(s.length===0)continue;let c=S(o,a,r,h),l=new Map,u=e=>(l.has(e)||l.set(e,t(o,e)),l.get(e));for(let{name:t,fn:r,shape:o}of s)i(r.body,r=>{if(r.type!==`JSXOpeningElement`)return;let i=[];if(n===0)for(let t of m){let n=e(r.name,u(t.package));n!==void 0&&(t.components===null||t.components.includes(n))&&i.push({prop:t.prop,target:t,reaches:t.label(n)})}for(let e of c(r.name))(e.name!==t||e.file!==a)&&i.push({prop:e.prop,target:e.target,reaches:e.reaches});for(let e of i){let n=C(r,e.prop,o);if(n===void 0)continue;let i=`${a}\0${t}\0${n}\0${e.reaches}`;y.has(i)||(y.add(i),_.push({file:a,name:t,prop:n,target:e.target,reaches:e.reaches}))}})}if(_.length===a)break}return{wrappers:_,packages:h}}var T=(e,t)=>`"${e}" reaches ${t.reaches} through ${t.name} (${t.file}), which no longer takes it; it becomes ${t.target.old.get(e)} there, so pass the new props through ${t.name} by hand`,E=(e,t)=>`the default ${t.prop}="${e}" reaches ${t.reaches}, which no longer takes it; it becomes ${t.target.old.get(e)} there, so change the default and forward the new props by hand`;function D(e,t,a){if(a.wrappers.length===0)return{text:e,hits:[],findings:[]};let o;try{o=n(e,t)}catch{return{text:e,hits:[],findings:[]}}if(o===null)return{text:e,hits:[],findings:[]};let s=[],c=new Set,l=(e,n,r)=>{let i=`${e}\0${n}\0${r}`;c.has(i)||(c.add(i),s.push({file:t,line:e,path:n,message:r}))},u=S(o,t,a.wrappers,a.packages);i(o,e=>{if(e.type===`JSXOpeningElement`)for(let t of u(e.name))for(let n of e.attributes){if(n.type!==`JSXAttribute`||n.name.type!==`JSXIdentifier`||n.name.name!==t.prop)continue;let e=r(n.value)?.value;e!==void 0&&t.target.old.has(e)&&l(n.loc.start.line,`${t.name}.${t.prop}`,T(e,t))}});let d=a.wrappers.filter(e=>e.file===t);if(d.length>0)for(let{name:e,shape:n}of v(o,t))for(let{prop:t,fallback:r}of n.locals.values()){let n=r?.type===`StringLiteral`?r.value:void 0;if(n!==void 0)for(let i of d)i.name===e&&i.prop===t&&i.target.old.has(n)&&l(r.loc.start.line,`${e}.${t}`,E(n,i))}return s.sort((e,t)=>e.line-t.line||(e.path<t.path?-1:+(e.path>t.path))),{text:e,hits:[],findings:s}}export{D as applyWrapperValues,v as componentDefinitions,w as findWrappers,p as wrapperTargets};
1
+ import{present as e}from"../present.js";import{componentOf as t,importedComponents as n,parseSource as r,spanOf as i,stringNode as a,visit as o}from"./themeReads.js";import{readFileSync as s}from"node:fs";import{basename as c,dirname as l,join as u}from"node:path";var d=5,f=[`dependencies`,`devDependencies`,`peerDependencies`,`optionalDependencies`],p=e=>{let t=Object.entries(e).filter(([,e])=>e!==null);return t.length===0?`nothing (drop the prop)`:t.map(([e,t])=>typeof t==`string`?`${e}="${t}"`:`${e}={${t}}`).join(` `)};function m(e){let t=[];for(let n of e.valueSplits??[]){let e=new Map;for(let[t,r]of Object.entries(n.values))t!==`true`&&t!==`false`&&!n.keep?.includes(t)&&e.set(t,p(r));e.size>0&&t.push({package:n.package,components:n.components,prop:n.prop,label:e=>`${e}.${n.prop}`,old:e})}for(let n of e.componentProps??[]){if(n.values===void 0)continue;let e=n.to??n.prop,r=new Map;for(let[t,i]of Object.entries(n.values))t!==i&&r.set(t,`${e}="${i}"`);r.size>0&&t.push({package:n.package,components:n.components,prop:n.prop,label:e=>`${e}.${n.prop}`,old:r})}for(let n of e.props??[])for(let e of n.props)t.push({package:n.package,components:null,prop:e,label:t=>`${t}.${e}`,old:new Map([[n.from,`${e}="${n.to}"`]])});return t}var h=e=>e.type===`Identifier`?e.name:e.type===`StringLiteral`?e.value:void 0,g=(e,t)=>{for(let n of e.properties){if(n.type===`RestElement`){n.argument.type===`Identifier`&&t.rest.add(n.argument.name);continue}if(n.type!==`ObjectProperty`||n.computed)continue;let e=h(n.key);if(e===void 0)continue;t.named.add(e);let r=n.value;r.type===`Identifier`?t.locals.set(r.name,{prop:e,fallback:void 0}):r.type===`AssignmentPattern`&&r.left.type===`Identifier`&&t.locals.set(r.left.name,{prop:e,fallback:r.right})}},_=e=>e.type===`FunctionDeclaration`||e.type===`FunctionExpression`||e.type===`ArrowFunctionExpression`,v=e=>{if(e!=null){if(_(e))return e;if(e.type===`CallExpression`)for(let t of e.arguments){let e=v(t);if(e!==void 0)return e}}},y=e=>/^[A-Z]/.test(e);function b(e,t){let n=[],r=(e,t)=>{if(t===void 0||!y(e))return;let r={props:new Set,rest:new Set,named:new Set,locals:new Map},i=t.params[0];if(i?.type===`AssignmentPattern`&&(i=i.left),i?.type===`Identifier`)r.props.add(i.name);else if(i?.type===`ObjectPattern`)g(i,r);else return;o(t.body,e=>{e.type===`VariableDeclarator`&&e.id.type===`ObjectPattern`&&e.init?.type===`Identifier`&&r.props.has(e.init.name)&&g(e.id,r)}),n.push({name:e,fn:t,shape:r})};return o(e,(e,n)=>{if(e.type===`FunctionDeclaration`&&e.id)r(e.id.name,e);else if(e.type===`VariableDeclarator`&&e.id.type===`Identifier`)r(e.id.name,v(e.init));else if(e.type===`ExportDefaultDeclaration`&&n.at(-1)?.type===`Program`){let n=e.declaration;_(n)&&(n.type===`ArrowFunctionExpression`||n.id===null)?r(c(t).replace(/\.[^.]+$/,``),n):n.type===`CallExpression`&&r(c(t).replace(/\.[^.]+$/,``),v(n))}}),n}var x=t=>{let n=t.split(`/`);return t.startsWith(`@`)?n.slice(0,2).join(`/`):e(n[0],`package name`)},S=e=>e.replace(/\.(?:jsx?|mjs|cjs|tsx?)$/i,``).replace(/\/index$/,``),C=(e,t)=>{let n=e.split(`/`),r=t.split(`/`),i=0;for(;i<n.length-1&&i<r.length-1&&n[i]===r[i];)i++;return i},w=(e,t,n,r)=>{let i=new Map;o(e,e=>{if(e.type!==`ImportDeclaration`)return;let t=e.source.value;for(let n of e.specifiers)if(n.type===`ImportDefaultSpecifier`)i.set(n.local.name,{specifier:t,imported:null});else if(n.type===`ImportSpecifier`){let e=n.imported.type===`StringLiteral`?n.imported.value:n.imported.name;i.set(n.local.name,{specifier:t,imported:e==="default"?null:e})}else i.set(n.local.name,{specifier:t,imported:void 0})});let a=e=>!e.startsWith(`.`)&&!e.startsWith(`/`)&&(e.startsWith(`@webority/`)||r.has(x(e)));return e=>{if(e.type!==`JSXIdentifier`)return[];let r=e.name,o=i.get(r);if(o===void 0)return n.filter(e=>e.file===t&&e.name===r);if(o.imported===void 0||a(o.specifier))return[];let s=o.imported,d=c(S(o.specifier)),f=n.filter(e=>s===null?e.name===r||c(S(e.file))===d:e.name===s);if(f.length===0)return[];if(o.specifier.startsWith(`.`)){let e=u(l(t),o.specifier).split(`\\`).join(`/`),n=f.filter(t=>S(t.file)===S(e));if(n.length>0)return n}let p=Math.max(...f.map(e=>C(e.file,t))),m=f.filter(e=>C(e.file,t)===p),h=[...new Set(m.map(e=>e.file))].sort()[0];return m.filter(e=>e.file===h)}},T=(e,t,n)=>{let r=e.attributes.find(e=>e.type===`JSXAttribute`&&e.name.type===`JSXIdentifier`&&e.name.name===t);if(r!==void 0){let e=r.value?.type===`JSXExpressionContainer`?r.value.expression:void 0;return e?.type===`Identifier`?n.locals.get(e.name)?.prop:e?.type===`MemberExpression`&&!e.computed&&e.object.type===`Identifier`&&n.props.has(e.object.name)&&e.property.type===`Identifier`?e.property.name:void 0}for(let r of e.attributes){if(r.type!==`JSXSpreadAttribute`||r.argument.type!==`Identifier`)continue;let e=r.argument.name;if(n.props.has(e)||n.rest.has(e)&&!n.named.has(t))return t}};function E(i,a,l,p=new Map){let h=m(l),g=new Set;for(let e of a)if(!(c(e)!==`package.json`||e.split(`/`).includes(`node_modules`)))try{let t=JSON.parse(s(u(i,e),`utf8`));for(let e of f)for(let n of Object.keys(t[e]??{}))g.add(n)}catch(t){let n=t instanceof Error?t.message:String(t);throw Error(`${e} could not be read as a package manifest: ${n}`,{cause:t})}if(h.length===0)return{wrappers:[],packages:g};let _=[];for(let e of a){if(!p.has(e))try{p.set(e,r(s(u(i,e),`utf8`),e))}catch{p.set(e,null)}let t=p.get(e);t&&_.push({file:e,ast:t,definitions:b(t,e)})}let v=[],y=new Set;for(let r=0;r<d;r++){let i=[...v],a=v.length;for(let{file:a,ast:s,definitions:c}of _){if(c.length===0)continue;let l=w(s,a,i,g),u=new Map,d=t=>(u.has(t)||u.set(t,n(s,t)),e(u.get(t),t));for(let{name:e,fn:n,shape:i}of c)o(n.body,n=>{if(n.type!==`JSXOpeningElement`)return;let o=[];if(r===0)for(let e of h){let r=t(n.name,d(e.package));r!==void 0&&(e.components===null||e.components.includes(r))&&o.push({prop:e.prop,target:e,reaches:e.label(r)})}for(let t of l(n.name))(t.name!==e||t.file!==a)&&o.push({prop:t.prop,target:t.target,reaches:t.reaches});for(let t of o){let r=T(n,t.prop,i);if(r===void 0)continue;let o=`${a}\0${e}\0${r}\0${t.reaches}`;y.has(o)||(y.add(o),v.push({file:a,name:e,prop:r,target:t.target,reaches:t.reaches}))}})}if(v.length===a)break}return{wrappers:v,packages:g}}var D=(e,t)=>`"${e}" reaches ${t.reaches} through ${t.name} (${t.file}), which no longer takes it; it becomes ${t.target.old.get(e)} there, so pass the new props through ${t.name} by hand`,O=(e,t)=>`the default ${t.prop}="${e}" reaches ${t.reaches}, which no longer takes it; it becomes ${t.target.old.get(e)} there, so change the default and forward the new props by hand`;function k(t,n,s){if(s.wrappers.length===0)return{text:t,hits:[],findings:[]};let c;try{c=r(t,n)}catch{return{text:t,hits:[],findings:[]}}if(c===null)return{text:t,hits:[],findings:[]};let l=[],u=new Set,d=(e,t,r)=>{let i=`${e}\0${t}\0${r}`;u.has(i)||(u.add(i),l.push({file:n,line:e,path:t,message:r}))},f=w(c,n,s.wrappers,s.packages);o(c,e=>{if(e.type===`JSXOpeningElement`)for(let t of f(e.name))for(let n of e.attributes){if(n.type!==`JSXAttribute`||n.name.type!==`JSXIdentifier`||n.name.name!==t.prop)continue;let e=a(n.value)?.value;e!==void 0&&t.target.old.has(e)&&d(i(n).loc.start.line,`${t.name}.${t.prop}`,D(e,t))}});let p=s.wrappers.filter(e=>e.file===n);if(p.length>0)for(let{name:t,shape:r}of b(c,n))for(let{prop:n,fallback:a}of r.locals.values()){let r=a?.type===`StringLiteral`?a.value:void 0;if(r!==void 0)for(let o of p)o.name===t&&o.prop===n&&o.target.old.has(r)&&d(i(e(a,`fallback`)).loc.start.line,`${t}.${n}`,O(r,o))}return l.sort((e,t)=>e.line-t.line||(e.path<t.path?-1:+(e.path>t.path))),{text:t,hits:[],findings:l}}export{k as applyWrapperValues,b as componentDefinitions,E as findWrappers,m as wrapperTargets};
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webority/tokens",
3
- "version": "0.148.0",
3
+ "version": "0.150.0",
4
4
  "description": "The Webority design tokens in one W3C Design Tokens source (palette, scale, meaning and component tiers, with light and dark, web and phone, and 390 and 1440 widths), and the webority command that brands a product, upgrades it between releases and checks it against the token source.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "type": "module",
@@ -39,11 +39,15 @@
39
39
  "@babel/parser": "7.29.8"
40
40
  },
41
41
  "devDependencies": {
42
+ "@babel/types": "7.29.8",
43
+ "@types/node": "25.6.0",
42
44
  "ajv": "8.20.0",
45
+ "typescript": "^7.0.2",
43
46
  "vite": "^8.3.6"
44
47
  },
45
48
  "scripts": {
46
- "build": "vite build && node dist/webority.js brand --library --out dist",
47
- "test": "node --test \"src/**/*.test.js\""
49
+ "build": "tsc -p tsconfig.json && vite build && tsc -p tsconfig.build.json && node dist/webority.js brand --library --out dist",
50
+ "typecheck": "tsc -p tsconfig.json",
51
+ "test": "node --test \"src/**/*.test.ts\""
48
52
  }
49
53
  }
@@ -28,7 +28,7 @@ export interface PropSplitRule {
28
28
  export interface RazorAttributeRule {
29
29
  tags: string[];
30
30
  attribute: string;
31
- values: Readonly<Record<"true" | "false", string>>;
31
+ values: Readonly<Record<string, string>>;
32
32
  }
33
33
 
34
34
  /** Source code a release changed: the renames apply to the source files the upgrade reads as JavaScript or TypeScript. */