@webority/tokens 0.149.0 → 0.152.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.
- package/dist/brand.d.ts +39 -25
- package/dist/brand.js +2 -2
- package/dist/build.d.ts +41 -0
- package/dist/build.js +5 -5
- package/dist/canvas/webority-phone.json +12 -12
- package/dist/canvas/webority-web-390.json +35 -3
- package/dist/canvas/webority-web.json +35 -3
- package/dist/check.d.ts +37 -0
- package/dist/check.js +3 -3
- package/dist/cli.d.ts +15 -96
- package/dist/cli.js +1 -1
- package/dist/emit/canvas.d.ts +8 -0
- package/dist/emit/canvas.js +1 -1
- package/dist/emit/email.d.ts +32 -0
- package/dist/emit/email.js +2 -2
- package/dist/emit/meanings.d.ts +3 -0
- package/dist/emit/phone.d.ts +26 -0
- package/dist/emit/phone.js +3 -3
- package/dist/emit/web.d.ts +18 -0
- package/dist/emit/web.js +14 -14
- package/dist/guards.d.ts +3 -0
- package/dist/guards.js +1 -0
- package/dist/index.d.ts +7 -7
- package/dist/meanings.json +97 -1
- package/dist/model/colour.d.ts +8 -0
- package/dist/model/colour.js +1 -1
- package/dist/model/contrast.d.ts +26 -0
- package/dist/model/contrast.js +1 -1
- package/dist/model/index.d.ts +52 -0
- package/dist/model/length.d.ts +21 -0
- package/dist/model/length.js +1 -1
- package/dist/model/load.d.ts +32 -0
- package/dist/model/load.js +1 -1
- package/dist/model/references.d.ts +3 -0
- package/dist/model/references.js +1 -1
- package/dist/model/resolve.d.ts +4 -0
- package/dist/model/resolve.js +2 -2
- package/dist/names.d.ts +1 -11
- package/dist/names.js +1 -1
- package/dist/outputs.d.ts +51 -102
- package/dist/present.d.ts +1 -0
- package/dist/present.js +1 -0
- package/dist/ramp.d.ts +8 -0
- package/dist/ramp.js +1 -1
- package/dist/source/meaning.tokens.json +144 -0
- package/dist/source/palette.tokens.json +9 -9
- package/dist/source/scale.tokens.json +39 -2
- package/dist/upgrade/classes.d.ts +13 -0
- package/dist/upgrade/classes.js +2 -2
- package/dist/upgrade/components.d.ts +19 -0
- package/dist/upgrade/components.js +3 -3
- package/dist/upgrade/css.d.ts +28 -0
- package/dist/upgrade/css.js +2 -2
- package/dist/upgrade/index.d.ts +64 -0
- package/dist/upgrade/index.js +2 -2
- package/dist/upgrade/razorAttributes.d.ts +19 -0
- package/dist/upgrade/razorAttributes.js +2 -2
- package/dist/upgrade/razorTags.d.ts +19 -0
- package/dist/upgrade/razorTags.js +2 -2
- package/dist/upgrade/razorValueSplits.d.ts +19 -0
- package/dist/upgrade/razorValueSplits.js +2 -2
- package/dist/upgrade/source.d.ts +19 -0
- package/dist/upgrade/source.js +3 -3
- package/dist/upgrade/tagScan.d.ts +7 -0
- package/dist/upgrade/tagScan.js +1 -1
- package/dist/upgrade/themeReads.d.ts +55 -0
- package/dist/upgrade/themeReads.js +2 -2
- package/dist/upgrade/valueSplits.d.ts +23 -0
- package/dist/upgrade/valueSplits.js +3 -3
- package/dist/upgrade/wrapperValues.d.ts +71 -0
- package/dist/upgrade/wrapperValues.js +1 -1
- package/dist/webority.d.ts +1 -0
- package/package.json +8 -3
- package/renames/0.130.0.json +15 -0
- package/renames/0.152.0.json +30 -0
- package/renames/renames.d.ts +1 -1
package/dist/upgrade/source.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import e from"node:path";var
|
|
2
|
-
`&&t.push(n+1);return t},
|
|
3
|
-
`),r=[],i=new Map;for(let a of t){if(a.importedFrom!==void 0&&(i.has(a.importedFrom)||i.set(a.importedFrom,
|
|
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[];
|
package/dist/upgrade/tagScan.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=e
|
|
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
|
|
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
|
|
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}},
|
|
4
|
-
`,t-1)+1,r=e.slice(n,t);return r.trim()===``&&n>0?`\n${r}`:` `};function
|
|
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
|
|
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.
|
|
3
|
+
"version": "0.152.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,16 @@
|
|
|
39
39
|
"@babel/parser": "7.29.8"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
+
"@babel/types": "7.29.8",
|
|
43
|
+
"@types/node": "25.6.0",
|
|
44
|
+
"@webority/biome-config": "0.152.0",
|
|
42
45
|
"ajv": "8.20.0",
|
|
46
|
+
"typescript": "^7.0.2",
|
|
43
47
|
"vite": "^8.3.6"
|
|
44
48
|
},
|
|
45
49
|
"scripts": {
|
|
46
|
-
"build": "vite build && node dist/webority.js brand --library --out dist",
|
|
47
|
-
"
|
|
50
|
+
"build": "tsc -p tsconfig.json && vite build && tsc -p tsconfig.build.json && node dist/webority.js brand --library --out dist",
|
|
51
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
52
|
+
"test": "node --test \"src/**/*.test.ts\""
|
|
48
53
|
}
|
|
49
54
|
}
|
package/renames/0.130.0.json
CHANGED
|
@@ -558,6 +558,21 @@
|
|
|
558
558
|
"hint": "AppDropdown item or confirm() request: danger: true is now tone: \"danger\"",
|
|
559
559
|
"importedFrom": "@webority/ui-react"
|
|
560
560
|
},
|
|
561
|
+
{
|
|
562
|
+
"pattern": "\\bshow\\s*:",
|
|
563
|
+
"hint": "show is now open on AppDropdown, AppPopover, AppModal and AppTooltip: an object key, spread or props map that sets show: keeps the component closed on 0.130.0; rename the key to open",
|
|
564
|
+
"importedFrom": "@webority/ui-react"
|
|
565
|
+
},
|
|
566
|
+
{
|
|
567
|
+
"pattern": "\\bonToggle\\s*:",
|
|
568
|
+
"hint": "onToggle is now onOpenChange on AppDropdown and AppPopover: an object key, spread or props map that sets onToggle: is ignored on 0.130.0; rename the key to onOpenChange",
|
|
569
|
+
"importedFrom": "@webority/ui-react"
|
|
570
|
+
},
|
|
571
|
+
{
|
|
572
|
+
"pattern": "\\bonHide\\s*:",
|
|
573
|
+
"hint": "onHide is now onClose on AppModal: an object key, spread or props map that sets onHide: is ignored on 0.130.0; rename the key to onClose. AppTooltip has no close callback; AppDropdown and AppPopover use onOpenChange",
|
|
574
|
+
"importedFrom": "@webority/ui-react"
|
|
575
|
+
},
|
|
561
576
|
{
|
|
562
577
|
"pattern": "\\bAVATAR_ACCEPT\\b",
|
|
563
578
|
"hint": "AVATAR_ACCEPT is no longer exported from the @webority/ui-elements root in 0.130.0; import it from the module that owns it",
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "0.152.0",
|
|
3
|
+
"css": {
|
|
4
|
+
"rename": [],
|
|
5
|
+
"reads": [],
|
|
6
|
+
"choose": {},
|
|
7
|
+
"checkRole": []
|
|
8
|
+
},
|
|
9
|
+
"classes": [],
|
|
10
|
+
"themeReads": [],
|
|
11
|
+
"props": [],
|
|
12
|
+
"propValues": [],
|
|
13
|
+
"propSplits": [],
|
|
14
|
+
"razorAttributes": [],
|
|
15
|
+
"componentProps": [],
|
|
16
|
+
"valueSplits": [],
|
|
17
|
+
"components": [],
|
|
18
|
+
"razorValueSplits": [
|
|
19
|
+
{
|
|
20
|
+
"tags": ["app-button", "app-action-icon"],
|
|
21
|
+
"attribute": "confirm-danger",
|
|
22
|
+
"values": {
|
|
23
|
+
"true": { "confirm-tone": "danger" },
|
|
24
|
+
"false": {}
|
|
25
|
+
},
|
|
26
|
+
"flag": "confirm-danger is now confirm-tone=\"danger\"; set the new attribute by hand"
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
"razorTags": []
|
|
30
|
+
}
|
package/renames/renames.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export interface PropSplitRule {
|
|
|
28
28
|
export interface RazorAttributeRule {
|
|
29
29
|
tags: string[];
|
|
30
30
|
attribute: string;
|
|
31
|
-
values: Readonly<Record<
|
|
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. */
|