@eliasku/ts-transformers 0.0.9 → 0.0.10
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/index.d.ts +33 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/package.json +14 -6
- package/src/exports/tracker.ts +2 -20
- package/src/index.ts +46 -63
- package/src/utils/ast-utils.ts +2 -2
- package/src/utils/symbol-utils.ts +39 -53
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
|
|
3
|
+
interface OptimizerOptions {
|
|
4
|
+
/**
|
|
5
|
+
* An array of entry source files which will used to detect exported and internal fields.
|
|
6
|
+
* Basically it should be entry point(s) of the library/project.
|
|
7
|
+
* @example ['./src/index.ts']
|
|
8
|
+
*/
|
|
9
|
+
entrySourceFiles: string[];
|
|
10
|
+
/**
|
|
11
|
+
* Prefix of generated names for private fields
|
|
12
|
+
* @example '_private_'
|
|
13
|
+
* @example '$_' // default
|
|
14
|
+
*/
|
|
15
|
+
privatePrefix: string;
|
|
16
|
+
/**
|
|
17
|
+
* Comment which will treat a class/interface/type/property/etc and all its children as "public".
|
|
18
|
+
* Set it to empty string to disable using JSDoc comment to detecting "visibility level".
|
|
19
|
+
* @example 'public' // default
|
|
20
|
+
* @example 'external'
|
|
21
|
+
* @example ''
|
|
22
|
+
*/
|
|
23
|
+
publicJSDocTag: string;
|
|
24
|
+
/**
|
|
25
|
+
* Whether fields that were decorated should be renamed.
|
|
26
|
+
* A field is treated as "decorated" if itself or any its parent (on type level) has a decorator.
|
|
27
|
+
*/
|
|
28
|
+
ignoreDecorated: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
declare const optimizer: (program: ts.Program, options?: Partial<OptimizerOptions>) => ts.TransformerFactory<ts.SourceFile>;
|
|
32
|
+
|
|
33
|
+
export { type OptimizerOptions, optimizer };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"typescript";var t=(t,r)=>(t.flags&e.SymbolFlags.Alias&&(t=r.getAliasedSymbol(t)),t),r=(r,o)=>{if(0===(r.flags&e.SymbolFlags.Transient))return[r];const i=n(r),s=[];for(const e of i){if(!a(e)||void 0===e.name)continue;const r=o.getSymbolAtLocation(e.name);void 0!==r&&s.push(t(r,o))}return s},n=e=>{const t=[];return void 0!==e.declarations&&t.push(...e.declarations),void 0!==e.valueDeclaration&&(t.includes(e.valueDeclaration)||t.push(e.valueDeclaration)),t},o=(r,n)=>{if(void 0!==n.exports){const o=n.exports.get(e.InternalSymbolName.ExportEquals);if(void 0!==o)return[t(o,r)]}const o=r.getExportsOfModule(n);if(void 0!==n.exports){const t=n.exports.get(e.InternalSymbolName.Default);void 0!==t&&(o.includes(t)||o.push(t))}return o.map(e=>t(e,r))},i=[e.SyntaxKind.InterfaceDeclaration,e.SyntaxKind.ClassDeclaration,e.SyntaxKind.EnumDeclaration,e.SyntaxKind.TypeAliasDeclaration,e.SyntaxKind.ModuleDeclaration,e.SyntaxKind.FunctionDeclaration,e.SyntaxKind.VariableDeclaration,e.SyntaxKind.PropertySignature,e.SyntaxKind.Parameter],a=e=>-1!==i.indexOf(e.kind),s=t=>e.isMethodDeclaration(t)||e.isPropertyDeclaration(t)||e.isGetAccessor(t)||e.isSetAccessor(t),c=t=>l(t,e.SyntaxKind.PrivateKeyword),l=(t,r)=>(t=>d(e)?e.canHaveModifiers(t)&&e.getModifiers(t)||[]:t.modifiers||[])(t).some(e=>e.kind===r),p=t=>0!==(t=>d(e)?e.canHaveDecorators(t)&&e.getDecorators(t)||[]:t.decorators||[])(t).length,f=t=>e.isParameter(t)&&e.isConstructorDeclaration(t.parent)&&(l(t,e.SyntaxKind.PublicKeyword)||l(t,e.SyntaxKind.ProtectedKeyword)||l(t,e.SyntaxKind.PrivateKeyword)||l(t,e.SyntaxKind.ReadonlyKeyword)),u=e=>{if(void 0===e)return[];const t=e.getDeclarations();return void 0===t?[]:t.filter(e=>s(e)||f(e))},d=e=>"canHaveDecorators"in e,g=class{constructor(e,t){this.exportsTree=new Map,this.program=e,this.computeTreeForExports(t)}isSymbolAccessibleFromExports(e){e=this.getActualSymbol(e);for(const[,t]of this.exportsTree)if(t.has(e))return!0;return!1}computeTreeForExports(e){this.exportsTree.clear();const t=this.program.getTypeChecker();for(const r of e){const e=this.program.getSourceFile(r);if(void 0===e)throw new Error(`Cannot find source file ${r}`);const i=t.getSymbolAtLocation(e);if(void 0!==i)for(const e of o(t,i)){const t=new Set;this.exportsTree.set(e,t);for(const r of n(e))this.computeTreeForChildren(t,r,new Set)}}}computeTreeForChildren(r,o,i){if(e.isNamespaceExport(o)){const a=this.program.getTypeChecker(),s=a.getSymbolAtLocation(o.name);if(void 0!==s&&s.flags&e.SymbolFlags.Alias){const e=a.getAliasedSymbol(s),o=a.getExportsOfModule(e);if(o&&o.length>0)for(const e of o){const o=t(e,a);if(!i.has(o)){i.add(o),r.add(o);for(const e of n(o))this.computeTreeForChildren(r,e,i)}}else console.warn("[computeTreeForChildren] Could not get exports for aliased symbol")}return}if(e.isExportDeclaration(o)&&void 0!==o.exportClause&&e.isNamedExports(o.exportClause)){const a=this.program.getTypeChecker();for(const s of o.exportClause.elements){const o=a.getSymbolAtLocation(s.name);if(void 0!==o&&0!==(o.flags&e.SymbolFlags.Alias)){const s=a.getAliasedSymbol(o);if(0!==(s.flags&e.SymbolFlags.NamespaceModule)){const e=a.getExportsOfModule(s);for(const o of e){const e=t(o,a);if(!i.has(e)){i.add(e),r.add(e);for(const t of n(e))this.computeTreeForChildren(r,t,i)}}}}}}if(e.isVariableDeclaration(o)){const e=this.program.getTypeChecker().getTypeAtLocation(o).getSymbol();return void(void 0!==e&&r.add(e))}e.forEachChild(o,e=>this.computeTreeForNode(r,e,i))}computeTreeForNode(t,o,i){if(e.isVariableStatement(o))for(const e of o.declarationList.declarations)this.computeTreeForNode(t,e,i);else if(!(o.kind===e.SyntaxKind.JSDoc||e.isBlock(o)||s(o)&&c(o))){if(e.isIdentifier(o)){const e=this.getSymbol(o);if(null===e)return;if(i.has(e))return;i.add(e);for(const o of r(e,this.program.getTypeChecker())){t.add(o);for(const e of n(o))this.computeTreeForChildren(t,e,i)}}this.computeTreeForChildren(t,o,i)}}getSymbol(e){const t=this.program.getTypeChecker().getSymbolAtLocation(e);return void 0===t?null:this.getActualSymbol(t)}getActualSymbol(e){return t(e,this.program.getTypeChecker())}},m=e=>{const t=e.getStart(),r=e.getStart(void 0,!0);return e.getSourceFile().getFullText().substring(r,t).trim()},y={entrySourceFiles:[],privatePrefix:"$_",publicJSDocTag:"public",ignoreDecorated:!1},S=(t,o)=>{const i={...y,...o},d=t.getTypeChecker(),S=new g(t,i.entrySourceFiles),h=new Map,x=(e,t)=>(h.set(e,t),t);return o=>{const g=e=>{const t=e.parent,r=d.getTypeAtLocation(e);if(!r.isStringLiteral())throw new Error(`Can't get type for left expression in ${e.parent.getText()}`);const n=r.value;return M(d.getTypeAtLocation(t.right),n)?e:P(n,0,o.factory.createStringLiteral)},y=e=>K(e),b=e=>{const t=O(e);return 1===t?e:w(e,t,o.factory.createStringLiteral)},T=e=>K(e),A=e=>K(e),v=e=>K(e),F=e=>K(e),D=e=>K(e),E=e=>{const t=O(e.name);return 1===t?e:w(e.name,t,t=>o.factory.createPropertyAssignment(t,e.name))},C=t=>{if(!e.isIdentifier(t.name))return t;const r=O(t);return 1===r?t:w(t.name,r,e=>o.factory.createBindingElement(t.dotDotDotToken,e,t.name,t.initializer))},L=e=>K(e),K=e=>{const t=O(e);return 1===t?e:w(e,t,o.factory.createIdentifier)},w=(t,r,n)=>{const o=d.getSymbolAtLocation(t);if(void 0===o)throw new Error(`Cannot get symbol for node "${t.getText()}"`);const i=e.unescapeLeadingUnderscores(o.escapedName);return P(i,r,n)},P=(e,t,r)=>r(N(e)),N=e=>`${i.privatePrefix}${e}`,k=t=>(t.flags&e.SymbolFlags.Alias&&(t=d.getAliasedSymbol(t)),t),I=e=>{const t=d.getSymbolAtLocation(e);return void 0===t?null:k(t)},M=(t,o)=>{if(t.flags&e.TypeFlags.Unknown||t.flags&e.TypeFlags.Any)return!0;if(t.flags&e.TypeFlags.IndexedAccess)return M(d.getApparentType(t),o);const i=t.getSymbol(),a=d.getPropertyOfType(t,o);if(t.flags&e.TypeFlags.Object){const r=t;if(r.objectFlags&e.ObjectFlags.Tuple)return!0;if(r.objectFlags&e.ObjectFlags.Reference){const e=r.target;if(e!==r&&M(e,o))return!0}const s=void 0!==a&&0!==n(a).length;if(r.objectFlags&e.ObjectFlags.Mapped&&void 0!==i&&!s&&1===B(i))return!0}if(t.isUnionOrIntersection()){const e=t.types.some(e=>M(e,o));if(e)return e}if(void 0!==i){const t=n(i);for(const r of t)if((e.isClassDeclaration(r)||e.isInterfaceDeclaration(r))&&void 0!==r.heritageClauses){if(r.heritageClauses.some(e=>e.types.some(e=>M(d.getTypeAtLocation(e),o))))return!0}}return void 0!==a&&[a,...r(a,d)].some(e=>1===B(e))},O=t=>{if(e.isPropertyAssignment(t.parent)||e.isShorthandPropertyAssignment(t.parent)){let r=t.parent.parent,n=t.parent.parent,o=t.parent.parent.parent;for(;e.isParenthesizedExpression(o)||e.isAsExpression(o);)e.isAsExpression(o)&&(r=n,n=o),o=o.parent;const i=d.getContextualType(r);if(void 0!==i&&M(i,t.getText()))return 1}if(e.isPropertyAccessExpression(t.parent)||e.isElementAccessExpression(t.parent)){if(e.isIdentifier(t.parent.expression)){const r=d.getSymbolAtLocation(t.parent.expression);if(void 0!==r){const o=n(r);if(o.some(t=>e.isNamespaceImport(t)||e.isModuleDeclaration(t)))return 1;if(o.some(t=>e.isImportSpecifier(t))){const r=d.getTypeAtLocation(t.parent.expression);if(r){const t=r.getSymbol();if(t&&(0!==(t.flags&e.SymbolFlags.NamespaceModule)||0!==(t.flags&e.SymbolFlags.Module)))return 1}}}}const r=d.getTypeAtLocation(t.parent.expression),o=t.getText();if(M(r,o))return 1}if(e.isBindingElement(t)&&M(d.getTypeAtLocation(t.parent),t.getText()))return 1;if(e.isBindingElement(t.parent)&&M(d.getTypeAtLocation(t.parent.parent),t.getText()))return 1;if(e.isJsxAttribute(t.parent)){const e=d.getSymbolAtLocation(t.parent.parent.parent.tagName);if(void 0!==e&&void 0!==e.valueDeclaration){const r=d.getTypeOfSymbolAtLocation(e,e.valueDeclaration);if(M(r,t.getText()))return 1}}const r=I(t),o=null!==r?(e=>{const t=u(e);if(0!==t.length){const e=t[0];return f(e)?e.parent.parent:e.parent}return null})(r):null;if(null!==o&&M(d.getTypeAtLocation(o),t.getText()))return 1;const i=e.isBindingElement(t)?$(t):r;return null===i?1:B(i)},B=t=>{t=k(t);const r=h.get(t);if(void 0!==r)return r;const o=n(t);if(o.some(j))return x(t,1);if(o.some(t=>l(t,e.SyntaxKind.DeclareKeyword)))return x(t,1);if("prototype"===t.escapedName)return x(t,1);if(0!==i.publicJSDocTag.length||i.ignoreDecorated)for(const r of o){let n=r;for(;!e.isSourceFile(n);){if(0!==i.publicJSDocTag.length&&m(n).includes(`@${i.publicJSDocTag}`))return x(t,1);if(i.ignoreDecorated&&p(n))return x(t,1);if(e.isEnumDeclaration(n))return x(t,1);n=n.parent}}if(u(t).some(c))return x(t,0);if(S.isSymbolAccessibleFromExports(t))return x(t,1);for(const e of o){if(!a(e.parent)||void 0===e.parent.name)continue;const r=I(e.parent.name);if(null!==r&&1===B(r))return x(t,1)}return x(t,0)},$=t=>{if(void 0!==t.propertyName)throw new Error(`Cannot handle binding element with property name: ${t.getText()} in ${t.getSourceFile().fileName}`);if(!e.isIdentifier(t.name))return null;const r=d.getTypeAtLocation(t.parent);return r.isUnion()?null:r.getProperty(e.idText(t.name))||null},j=e=>{const r=e.getSourceFile();return r.isDeclarationFile||t.isSourceFileDefaultLibrary(r)||/[\\/]node_modules[\\/]/.test(r.fileName)},J=t=>{return!!e.isIdentifier(t)&&(r=d.getSymbolAtLocation(t),0!==u(r).length);var r},U=t=>e.visitEachChild((t=>{if(e.isShorthandPropertyAssignment(t))return E(t);if(e.isBindingElement(t)&&void 0===t.propertyName)return t.parent&&e.isObjectBindingPattern(t.parent)?C(t):t;if(t.parent&&e.isStringLiteral(t)&&e.isBinaryExpression(t.parent)&&t.parent.operatorToken.kind===e.SyntaxKind.InKeyword)return g(t);if(e.isIdentifier(t)&&t.parent){if(e.isPropertyAccessExpression(t.parent)&&t.parent.name===t)return y(t);if(s(t.parent)&&t.parent.name===t)return T(t);if(e.isEnumMember(t.parent)&&t.parent.name===t)return A(t);if(e.isPropertyAssignment(t.parent)&&t.parent.name===t)return D(t);if(e.isBindingElement(t.parent)&&t.parent.propertyName===t)return v(t);if(e.isJsxAttribute(t.parent)&&t.parent.name===t)return F(t);if(f(t.parent)&&t.parent.name===t||J(t))return L(t)}return t.parent&&e.isStringLiteral(t)&&e.isElementAccessExpression(t.parent)&&t.parent.argumentExpression===t?b(t):t})(t),U,o);return e=>U(e)}};export{S as optimizer};//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/symbol-utils.ts","../src/exports/tracker.ts","../src/utils/ast-utils.ts","../src/types.ts","../src/index.ts"],"names":["ts","getActualSymbol","expressionType"],"mappings":";AAEO,IAAM,eAAA,GAAkB,CAAC,MAAA,EAAmB,WAAA,KAA2C;AAC5F,EAAA,IAAI,MAAA,CAAO,KAAA,GAAQA,GAAA,CAAG,WAAA,CAAY,KAAA,EAAO;AACvC,IAAA,MAAA,GAAS,WAAA,CAAY,iBAAiB,MAAM,CAAA;AAAA,EAC9C;AAEA,EAAA,OAAO,MAAA;AACT,CAAA;AAEO,IAAM,oBAAA,GAAuB,CAAC,MAAA,EAAmB,WAAA,KAA6C;AAKnG,EAAA,IAAA,CAAK,MAAA,CAAO,KAAA,GAAQA,GAAA,CAAG,WAAA,CAAY,eAAe,CAAA,EAAG;AACnD,IAAA,OAAO,CAAC,MAAM,CAAA;AAAA,EAChB;AAKA,EAAA,MAAM,YAAA,GAAe,yBAA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YAAA,CAAa,OAAA,CAAQ,IAAI,CAAA,EAAG;AAClC,QAAA,OAAO,IAAA;AAAA,MACT;AAMA,MAAA,MAAM,IAAA,GAAO,WAAA,CAAY,iBAAA,CAAkB,OAAA,CAAQ,MAAiB,CAAA;AACpE,MAAA,IAAI,IAAA,CAAK,SAAQ,EAAG;AAClB,QAAA,OAAO,IAAA;AAAA,MACT;AAEA,MAAA,OAAO,KAAK,WAAA,CAAYA,GAAAA,CAAG,OAAO,OAAA,CAAQ,IAAI,CAAC,CAAA,IAAK,IAAA;AAAA,IACtD,CAAA;AAEA,IAAA,MAAM,0BAAA,GAA6B,CAAC,WAAA,KAAyC;AAC3E,MAAA,MAAM,UAAA,GAAa,YAAY,aAAA,EAAc;AAG7C,MAAA,OACE,UAAA,CAAW,qBACX,OAAA,CAAQ,0BAAA,CAA2B,UAAU,CAAA,IAC7C,wBAAA,CAAyB,IAAA,CAAK,UAAA,CAAW,QAAQ,CAAA;AAAA,IAErD,CAAA;AAEA,IAAA,MAAM,+BAAA,GAAkC,CAAC,IAAA,KAAyC;AAChF,MAAA,IAAI,CAACA,GAAAA,CAAG,YAAA,CAAa,IAAI,CAAA,EAAG;AAC1B,QAAA,OAAO,KAAA;AAAA,MACT;AAEA,MAAA,OAAO,mBAAA,CAAoB,WAAA,CAAY,mBAAA,CAAoB,IAAI,CAAC,CAAA;AAAA,IAClE,CAAA;AACA,IAAA,MAAM,wBAAA,GAA2B,CAAC,IAAA,KAChCA,GAAAA,CAAG,eAAe,aAAA,CAAc,IAAI,CAAA,EAAG,wBAAA,EAA0B,OAAO,CAAA;AAE1E,IAAA,OAAO,CAAC,UAAA,KAA8B,wBAAA,CAAyB,UAAU,CAAA;AAAA,EAC3E,CAAA;AACF","file":"index.js","sourcesContent":["import ts from \"typescript\";\n\nexport const getActualSymbol = (symbol: ts.Symbol, typeChecker: ts.TypeChecker): ts.Symbol => {\n if (symbol.flags & ts.SymbolFlags.Alias) {\n symbol = typeChecker.getAliasedSymbol(symbol);\n }\n\n return symbol;\n};\n\nexport const splitTransientSymbol = (symbol: ts.Symbol, typeChecker: ts.TypeChecker): ts.Symbol[] => {\n // actually I think we even don't need to operate/use \"Transient\" symbols anywhere\n // it's kind of aliased symbol, but just merged\n // but it's hard to refractor everything to use array of symbols instead of just symbol\n // so let's fix it for some places\n if ((symbol.flags & ts.SymbolFlags.Transient) === 0) {\n return [symbol];\n }\n\n // \"Transient\" symbol is kinda \"merged\" symbol\n // I don't really know is this way to \"split\" is correct\n // but it seems that it works for now\n const declarations = getDeclarationsForSymbol(symbol);\n const result: ts.Symbol[] = [];\n for (const declaration of declarations) {\n if (!isNodeNamedDeclaration(declaration) || declaration.name === undefined) {\n continue;\n }\n\n const sym = typeChecker.getSymbolAtLocation(declaration.name);\n if (sym === undefined) {\n continue;\n }\n\n result.push(getActualSymbol(sym, typeChecker));\n }\n\n return result;\n};\n\nexport const getDeclarationsForSymbol = (symbol: ts.Symbol): ts.Declaration[] => {\n const result: ts.Declaration[] = [];\n\n if (symbol.declarations !== undefined) {\n result.push(...symbol.declarations);\n }\n\n if (symbol.valueDeclaration !== undefined) {\n // push valueDeclaration might be already in declarations array\n // so let's check first to avoid duplication nodes\n if (!result.includes(symbol.valueDeclaration)) {\n result.push(symbol.valueDeclaration);\n }\n }\n\n return result;\n};\n\nexport const getExportsForSourceFile = (typeChecker: ts.TypeChecker, sourceFileSymbol: ts.Symbol): ts.Symbol[] => {\n if (sourceFileSymbol.exports !== undefined) {\n const commonJsExport = sourceFileSymbol.exports.get(ts.InternalSymbolName.ExportEquals);\n if (commonJsExport !== undefined) {\n return [getActualSymbol(commonJsExport, typeChecker)];\n }\n }\n\n const result: ts.Symbol[] = typeChecker.getExportsOfModule(sourceFileSymbol);\n\n if (sourceFileSymbol.exports !== undefined) {\n const defaultExportSymbol = sourceFileSymbol.exports.get(ts.InternalSymbolName.Default);\n if (defaultExportSymbol !== undefined) {\n if (!result.includes(defaultExportSymbol)) {\n // it seems that default export is always returned by getExportsOfModule\n // but let's add it to be sure add if there is no such export\n result.push(defaultExportSymbol);\n }\n }\n }\n\n return result.map((symbol: ts.Symbol) => getActualSymbol(symbol, typeChecker));\n};\n\nconst namedDeclarationKinds = [\n ts.SyntaxKind.InterfaceDeclaration,\n ts.SyntaxKind.ClassDeclaration,\n ts.SyntaxKind.EnumDeclaration,\n ts.SyntaxKind.TypeAliasDeclaration,\n ts.SyntaxKind.ModuleDeclaration,\n ts.SyntaxKind.FunctionDeclaration,\n ts.SyntaxKind.VariableDeclaration,\n ts.SyntaxKind.PropertySignature,\n ts.SyntaxKind.Parameter,\n];\n\nexport const isNodeNamedDeclaration = (node: ts.Node): node is ts.NamedDeclaration =>\n namedDeclarationKinds.indexOf(node.kind) !== -1;\n\nexport type ClassMember =\n | ts.MethodDeclaration\n | ts.PropertyDeclaration\n | ts.GetAccessorDeclaration\n | ts.SetAccessorDeclaration;\n\nexport const isClassMember = (node: ts.Node): node is ClassMember =>\n ts.isMethodDeclaration(node) || ts.isPropertyDeclaration(node) || ts.isGetAccessor(node) || ts.isSetAccessor(node);\n\nexport const getClassOfMemberSymbol = (\n nodeSymbol: ts.Symbol,\n): ts.ClassLikeDeclaration | ts.ObjectLiteralExpression | ts.TypeLiteralNode | ts.InterfaceDeclaration | null => {\n const classMembers = getClassMemberDeclarations(nodeSymbol);\n if (classMembers.length !== 0) {\n // we need any member to get class' declaration\n const classMember = classMembers[0];\n if (isConstructorParameter(classMember)) {\n return (classMember.parent as ts.ConstructorDeclaration).parent;\n }\n\n // we're sure that it is a class, not interface\n return classMember.parent as ts.ClassLikeDeclaration | ts.ObjectLiteralExpression;\n }\n\n return null;\n};\n\nexport const hasPrivateKeyword = (node: ClassMember | ts.ParameterDeclaration): boolean =>\n hasModifier(node, ts.SyntaxKind.PrivateKeyword);\n\nconst getModifiers = (node: ts.Node): readonly ts.Modifier[] => {\n if (isBreakingTypeScriptApi(ts)) {\n if (!ts.canHaveModifiers(node)) {\n return [];\n }\n\n return ts.getModifiers(node) || [];\n }\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return node.modifiers || [];\n};\n\nexport const hasModifier = (node: ts.Node, modifier: ts.SyntaxKind): boolean =>\n getModifiers(node).some((mod) => mod.kind === modifier);\n\nconst getDecorators = (node: ts.Node): readonly unknown[] => {\n if (isBreakingTypeScriptApi(ts)) {\n if (!ts.canHaveDecorators(node)) {\n return [];\n }\n\n return ts.getDecorators(node) || [];\n }\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return node.decorators || [];\n};\n\nexport const hasDecorators = (node: ts.Node): boolean => getDecorators(node).length !== 0;\n\nexport const isConstructorParameter = (node: ts.Node): node is ts.ParameterDeclaration =>\n ts.isParameter(node) &&\n ts.isConstructorDeclaration(node.parent as ts.Node) &&\n (hasModifier(node, ts.SyntaxKind.PublicKeyword) ||\n hasModifier(node, ts.SyntaxKind.ProtectedKeyword) ||\n hasModifier(node, ts.SyntaxKind.PrivateKeyword) ||\n hasModifier(node, ts.SyntaxKind.ReadonlyKeyword));\n\nconst getClassMemberDeclarations = (symbol: ts.Symbol | undefined): (ClassMember | ts.ParameterDeclaration)[] => {\n if (symbol === undefined) {\n return [];\n }\n\n const declarations = symbol.getDeclarations();\n if (declarations === undefined) {\n return [];\n }\n\n return declarations.filter((x: ts.Declaration): x is ClassMember | ts.ParameterDeclaration => {\n return isClassMember(x) || isConstructorParameter(x);\n });\n};\n\nexport const isSymbolClassMember = (symbol: ts.Symbol | undefined): boolean =>\n getClassMemberDeclarations(symbol).length !== 0;\n\nexport const isPrivateClassMember = (symbol: ts.Symbol | undefined): boolean =>\n getClassMemberDeclarations(symbol).some(hasPrivateKeyword);\n\n// decorators and modifiers-related api added in ts 4.8\ninterface BreakingTypeScriptApi {\n canHaveDecorators(node: ts.Node): boolean;\n getDecorators(node: ts.Node): readonly ts.Decorator[] | undefined;\n canHaveModifiers(node: ts.Node): boolean;\n getModifiers(node: ts.Node): readonly ts.Modifier[] | undefined;\n}\n\nconst isBreakingTypeScriptApi = (compiler: object): compiler is BreakingTypeScriptApi =>\n \"canHaveDecorators\" in compiler;\n","import ts from \"typescript\";\n\nimport {\n getActualSymbol,\n splitTransientSymbol,\n isClassMember,\n hasPrivateKeyword,\n getExportsForSourceFile,\n getDeclarationsForSymbol,\n} from \"../utils/symbol-utils\";\nimport { LOGS } from \"../config\";\n\nexport class ExportsSymbolTree {\n private readonly program: ts.Program;\n private readonly exportsTree = new Map<ts.Symbol, Set<ts.Symbol>>();\n\n constructor(program: ts.Program, entrySourceFiles: readonly string[]) {\n this.program = program;\n this.computeTreeForExports(entrySourceFiles);\n }\n\n isSymbolAccessibleFromExports(symbol: ts.Symbol): boolean {\n symbol = this.getActualSymbol(symbol);\n for (const [, set] of this.exportsTree) {\n if (set.has(symbol)) {\n return true;\n }\n }\n return false;\n }\n\n private computeTreeForExports(entrySourceFiles: readonly string[]): void {\n this.exportsTree.clear();\n\n const typeChecker = this.program.getTypeChecker();\n for (const filePath of entrySourceFiles) {\n const sourceFile = this.program.getSourceFile(filePath);\n if (sourceFile === undefined) {\n throw new Error(`Cannot find source file ${filePath}`);\n }\n\n const entrySourceFile = typeChecker.getSymbolAtLocation(sourceFile);\n if (entrySourceFile === undefined) {\n // if a source file doesn't have any export - then it doesn't have a symbol as well\n // so just skip it here\n continue;\n }\n\n if (LOGS) {\n console.log(`[ExportsSymbolTree] Processing entry file: ${filePath}`);\n }\n for (const entryExportSymbol of getExportsForSourceFile(typeChecker, entrySourceFile)) {\n if (LOGS) {\n console.log(`[ExportsSymbolTree] Export symbol: ${entryExportSymbol.escapedName}`);\n }\n const exportSymbolsSet = new Set<ts.Symbol>();\n this.exportsTree.set(entryExportSymbol, exportSymbolsSet);\n\n for (const exportDeclaration of getDeclarationsForSymbol(entryExportSymbol)) {\n if (LOGS) {\n console.log(\n `[ExportsSymbolTree] Declaration: ${ts.SyntaxKind[exportDeclaration.kind]} - ${exportDeclaration.getText()}`,\n );\n }\n this.computeTreeForChildren(exportSymbolsSet, exportDeclaration, new Set<ts.Symbol>());\n }\n }\n }\n }\n\n private computeTreeForChildren(\n targetSymbolsSet: Set<ts.Symbol>,\n node: ts.Node,\n visitedSymbols: Set<ts.Symbol>,\n ): void {\n if (LOGS) {\n console.log(`[computeTreeForChildren] Processing: ${ts.SyntaxKind[node.kind]} - ${node.getText()}`);\n }\n\n // Handle namespace exports (export * as name from './module')\n // These create an alias symbol that points to the actual module symbol\n if (ts.isNamespaceExport(node)) {\n if (LOGS) {\n console.log(`[computeTreeForChildren] Found NamespaceExport!`);\n }\n const typeChecker = this.program.getTypeChecker();\n\n // Get the symbol at the namespace export's name (e.g., \"fun1\" in \"export * as fun1 from './module'\")\n const symbol = typeChecker.getSymbolAtLocation(node.name);\n if (LOGS) {\n console.log(\n `[computeTreeForChildren] Symbol: ${symbol?.name}, isAlias: ${symbol && (symbol.flags & ts.SymbolFlags.Alias) !== 0}`,\n );\n }\n if (symbol !== undefined && symbol.flags & ts.SymbolFlags.Alias) {\n // Resolve the alias to get the actual module symbol\n const aliasedSymbol = typeChecker.getAliasedSymbol(symbol);\n if (LOGS) {\n console.log(`[computeTreeForChildren] Aliased to: ${aliasedSymbol.escapedName}`);\n }\n\n // Get all exports from the referenced module\n const moduleExports = typeChecker.getExportsOfModule(aliasedSymbol);\n if (moduleExports && moduleExports.length > 0) {\n if (LOGS) {\n console.log(`[computeTreeForChildren] Module exports: ${moduleExports.map((e) => e.name).join(\", \")}`);\n }\n for (const exportSymbol of moduleExports) {\n const actualExport = getActualSymbol(exportSymbol, typeChecker);\n if (!visitedSymbols.has(actualExport)) {\n visitedSymbols.add(actualExport);\n targetSymbolsSet.add(actualExport);\n if (LOGS) {\n console.log(`[computeTreeForChildren] Adding: ${actualExport.escapedName}`);\n }\n\n for (const exportDeclaration of getDeclarationsForSymbol(actualExport)) {\n this.computeTreeForChildren(targetSymbolsSet, exportDeclaration, visitedSymbols);\n }\n }\n }\n } else {\n console.warn(`[computeTreeForChildren] Could not get exports for aliased symbol`);\n }\n }\n return;\n }\n\n // Handle re-export of namespace imports (import * as x from './module'; export { x })\n // This pattern creates an export that references a namespace import\n if (ts.isExportDeclaration(node) && node.exportClause !== undefined && ts.isNamedExports(node.exportClause)) {\n if (LOGS) {\n console.log(`[computeTreeForChildren] Found ExportDeclaration with named exports`);\n }\n const typeChecker = this.program.getTypeChecker();\n\n for (const exportSpecifier of node.exportClause.elements) {\n if (LOGS) {\n console.log(`[computeTreeForChildren] Export specifier: ${exportSpecifier.name.text}`);\n }\n // Get the symbol for this exported name\n const exportedSymbol = typeChecker.getSymbolAtLocation(exportSpecifier.name);\n if (exportedSymbol !== undefined) {\n if (LOGS) {\n console.log(\n `[computeTreeForChildren] Symbol: ${exportedSymbol.name}, flags: ${exportedSymbol.flags}`,\n );\n }\n\n // Check if this is an alias (e.g., from a namespace import)\n if ((exportedSymbol.flags & ts.SymbolFlags.Alias) !== 0) {\n const aliasedSymbol = typeChecker.getAliasedSymbol(exportedSymbol);\n if (LOGS) {\n console.log(\n `[computeTreeForChildren] Aliased to: ${aliasedSymbol.name}, flags: ${aliasedSymbol.flags}`,\n );\n }\n\n // Check if the aliased symbol is a namespace module\n if ((aliasedSymbol.flags & ts.SymbolFlags.NamespaceModule) !== 0) {\n if (LOGS) {\n console.log(`[computeTreeForChildren] Aliased symbol is a namespace module!`);\n }\n // Get all exports from this namespace module\n const moduleExports = typeChecker.getExportsOfModule(aliasedSymbol);\n if (LOGS) {\n console.log(\n `[computeTreeForChildren] Module exports: ${moduleExports.map((e) => e.name).join(\", \")}`,\n );\n }\n for (const exportSymbol of moduleExports) {\n const actualExport = getActualSymbol(exportSymbol, typeChecker);\n if (!visitedSymbols.has(actualExport)) {\n visitedSymbols.add(actualExport);\n targetSymbolsSet.add(actualExport);\n if (LOGS) {\n console.log(`[computeTreeForChildren] Adding: ${actualExport.escapedName}`);\n }\n\n // Recursively process the export's declarations\n for (const exportDeclaration of getDeclarationsForSymbol(actualExport)) {\n this.computeTreeForChildren(targetSymbolsSet, exportDeclaration, visitedSymbols);\n }\n }\n }\n }\n }\n }\n }\n // Don't return here - continue to process children\n }\n\n // it's similar to handling ts.Block node - both Block and variable's initializer are part of _implementation_\n // and we don't care about that implementation at all - we just only need to worry it's definition\n // for functions it is arguments and return type\n // for variables - the type of a variable\n if (ts.isVariableDeclaration(node)) {\n const typeChecker = this.program.getTypeChecker();\n const variableType = typeChecker.getTypeAtLocation(node);\n const variableTypeSymbol = variableType.getSymbol();\n if (variableTypeSymbol !== undefined) {\n targetSymbolsSet.add(variableTypeSymbol);\n if (LOGS) {\n console.log(`[computeTreeForChildren] Added variable type symbol: ${variableTypeSymbol.escapedName}`);\n }\n }\n\n return;\n }\n\n ts.forEachChild(node, (childNode: ts.Node) => this.computeTreeForNode(targetSymbolsSet, childNode, visitedSymbols));\n }\n\n private computeTreeForNode(targetSymbolsSet: Set<ts.Symbol>, node: ts.Node, visitedSymbols: Set<ts.Symbol>): void {\n if (ts.isVariableStatement(node)) {\n for (const varDeclaration of node.declarationList.declarations) {\n this.computeTreeForNode(targetSymbolsSet, varDeclaration, visitedSymbols);\n }\n\n return;\n }\n\n if (node.kind === ts.SyntaxKind.JSDoc || ts.isBlock(node)) {\n return;\n }\n\n if (isClassMember(node) && hasPrivateKeyword(node)) {\n return;\n }\n\n if (ts.isIdentifier(node)) {\n const symbol = this.getSymbol(node);\n if (symbol === null) {\n return;\n }\n\n if (visitedSymbols.has(symbol)) {\n return;\n }\n\n visitedSymbols.add(symbol);\n if (LOGS) {\n console.log(`[computeTreeForNode] Processing identifier: ${node.getText()} -> ${symbol.escapedName}`);\n }\n\n for (const childSymbol of splitTransientSymbol(symbol, this.program.getTypeChecker())) {\n targetSymbolsSet.add(childSymbol);\n if (LOGS) {\n console.log(`[computeTreeForNode] Added to set: ${childSymbol.escapedName}`);\n }\n\n for (const exportDeclaration of getDeclarationsForSymbol(childSymbol)) {\n this.computeTreeForChildren(targetSymbolsSet, exportDeclaration, visitedSymbols);\n }\n }\n }\n\n this.computeTreeForChildren(targetSymbolsSet, node, visitedSymbols);\n }\n\n private getSymbol(node: ts.Node): ts.Symbol | null {\n const nodeSymbol = this.program.getTypeChecker().getSymbolAtLocation(node);\n if (nodeSymbol === undefined) {\n return null;\n }\n\n return this.getActualSymbol(nodeSymbol);\n }\n\n private getActualSymbol(symbol: ts.Symbol): ts.Symbol {\n return getActualSymbol(symbol, this.program.getTypeChecker());\n }\n}\n","import ts from \"typescript\";\n\nexport const getNodeJSDocComment = (node: ts.Node): string => {\n const start = node.getStart();\n const jsDocStart = node.getStart(undefined, true);\n return node.getSourceFile().getFullText().substring(jsDocStart, start).trim();\n};\n","export interface OptimizerOptions {\n /**\n * An array of entry source files which will used to detect exported and internal fields.\n * Basically it should be entry point(s) of the library/project.\n * @example ['./src/index.ts']\n */\n entrySourceFiles: string[];\n\n /**\n * Prefix of generated names for private fields\n * @example '_private_'\n * @example '$_' // default\n */\n privatePrefix: string;\n\n /**\n * Comment which will treat a class/interface/type/property/etc and all its children as \"public\".\n * Set it to empty string to disable using JSDoc comment to detecting \"visibility level\".\n * @example 'public' // default\n * @example 'external'\n * @example ''\n */\n publicJSDocTag: string;\n\n /**\n * Whether fields that were decorated should be renamed.\n * A field is treated as \"decorated\" if itself or any its parent (on type level) has a decorator.\n */\n ignoreDecorated: boolean;\n}\n\nexport const enum VisibilityType {\n Private = 0,\n External = 1,\n}\n\nexport const defaultOptions: OptimizerOptions = {\n entrySourceFiles: [],\n privatePrefix: \"$_\",\n publicJSDocTag: \"public\",\n ignoreDecorated: false,\n};\n","import ts from \"typescript\";\nimport { ExportsSymbolTree } from \"./exports/tracker\";\nimport {\n getDeclarationsForSymbol,\n isClassMember,\n isConstructorParameter,\n isPrivateClassMember,\n isSymbolClassMember,\n getClassOfMemberSymbol,\n hasDecorators,\n hasModifier,\n splitTransientSymbol,\n isNodeNamedDeclaration,\n} from \"./utils/symbol-utils\";\nimport { getNodeJSDocComment } from \"./utils/ast-utils\";\nimport { OptimizerOptions, defaultOptions, VisibilityType } from \"./types\";\nimport { LOGS } from \"./config\";\n\nexport type { OptimizerOptions } from \"./types\";\n\nexport const optimizer = (\n program: ts.Program,\n options?: Partial<OptimizerOptions>,\n): ts.TransformerFactory<ts.SourceFile> => {\n const fullOptions: OptimizerOptions = { ...defaultOptions, ...options };\n const typeChecker = program.getTypeChecker();\n const exportsSymbolTree = new ExportsSymbolTree(program, fullOptions.entrySourceFiles);\n\n const cache = new Map<ts.Symbol, VisibilityType>();\n\n const putToCache = (nodeSymbol: ts.Symbol, val: VisibilityType): VisibilityType => {\n cache.set(nodeSymbol, val);\n return val;\n };\n\n return (context: ts.TransformationContext) => {\n const transformNode = (node: ts.Node): ts.Node | undefined => {\n // const a = { node }\n if (ts.isShorthandPropertyAssignment(node)) {\n return handleShorthandPropertyAssignment(node);\n }\n\n // const { node } = obj;\n if (ts.isBindingElement(node) && node.propertyName === undefined) {\n if (node.parent && ts.isObjectBindingPattern(node.parent)) {\n return handleShorthandObjectBindingElement(node);\n }\n return node;\n }\n\n // is not supported:\n // const { node = default_Value } = obj;\n\n // 'node' in obj\n if (\n node.parent &&\n ts.isStringLiteral(node) &&\n ts.isBinaryExpression(node.parent) &&\n node.parent.operatorToken.kind === ts.SyntaxKind.InKeyword\n ) {\n return handleInKeyword(node);\n }\n\n if (ts.isIdentifier(node) && node.parent) {\n // obj.node\n if (ts.isPropertyAccessExpression(node.parent) && node.parent.name === node) {\n return handlePropertyAccessIdentifier(node);\n }\n\n // private node\n // public node()\n if (isClassMember(node.parent) && node.parent.name === node) {\n return handleClassMember(node);\n }\n\n // enum Enum { node }\n if (ts.isEnumMember(node.parent) && node.parent.name === node) {\n return handleEnumMember(node);\n }\n\n // const a = { node: 123 }\n if (ts.isPropertyAssignment(node.parent) && node.parent.name === node) {\n return handlePropertyAssignment(node);\n }\n\n // const { node: localName } = obj;\n if (ts.isBindingElement(node.parent) && node.parent.propertyName === node) {\n return handleBindingElement(node);\n }\n\n // <Comp node={...} />\n if (ts.isJsxAttribute(node.parent) && node.parent.name === node) {\n return handleJsxAttributeName(node);\n }\n\n // constructor(public node: string) { // <--- this\n // console.log(node); // <--- and this\n // }\n if (\n (isConstructorParameter(node.parent) && node.parent.name === node) ||\n isConstructorParameterReference(node)\n ) {\n return handleCtorParameter(node);\n }\n }\n\n // obj['fooBar']\n if (\n node.parent &&\n ts.isStringLiteral(node) &&\n ts.isElementAccessExpression(node.parent) &&\n node.parent.argumentExpression === node\n ) {\n return handleElementAccessExpression(node);\n }\n\n return node;\n };\n\n const handleInKeyword = (node: ts.StringLiteral): ts.StringLiteral => {\n const parent = node.parent as ts.BinaryExpression;\n const nodeType = typeChecker.getTypeAtLocation(node);\n if (!nodeType.isStringLiteral()) {\n throw new Error(`Can't get type for left expression in ${node.parent.getText()}`);\n }\n\n const propertyName = nodeType.value;\n if (isTypePropertyExternal(typeChecker.getTypeAtLocation(parent.right), propertyName)) {\n return node;\n }\n\n return createNewNode(propertyName, VisibilityType.Private, context.factory.createStringLiteral);\n };\n\n // obj.node\n const handlePropertyAccessIdentifier = (node: ts.Identifier): ts.Identifier => createNewIdentifier(node);\n\n // obj['fooBar']\n const handleElementAccessExpression = (node: ts.StringLiteral): ts.StringLiteral => {\n const visibilityType = getNodeVisibilityType(node);\n if (visibilityType === VisibilityType.External) {\n return node;\n }\n\n return createNewNodeFromProperty(node, visibilityType, context.factory.createStringLiteral);\n };\n\n // private node\n // public node()\n const handleClassMember = (node: ts.Identifier): ts.Identifier => createNewIdentifier(node);\n\n // enum Enum { node }\n const handleEnumMember = (node: ts.Identifier): ts.Identifier => createNewIdentifier(node);\n\n // const { node: localName } = obj;\n const handleBindingElement = (node: ts.Identifier): ts.Identifier => createNewIdentifier(node);\n\n // <Comp node={...} />\n const handleJsxAttributeName = (node: ts.Identifier): ts.Identifier => createNewIdentifier(node);\n\n // const a = { node: 123 }\n const handlePropertyAssignment = (node: ts.Identifier): ts.Identifier => createNewIdentifier(node);\n\n // const a = { node }\n const handleShorthandPropertyAssignment = (\n node: ts.ShorthandPropertyAssignment,\n ): ts.PropertyAssignment | ts.ShorthandPropertyAssignment => {\n const visibilityType = getNodeVisibilityType(node.name);\n if (visibilityType === VisibilityType.External) {\n return node;\n }\n\n return createNewNodeFromProperty(node.name, visibilityType, (newName: string) => {\n return context.factory.createPropertyAssignment(newName, node.name);\n });\n };\n\n // const { node } = obj;\n const handleShorthandObjectBindingElement = (node: ts.BindingElement): ts.BindingElement => {\n if (!ts.isIdentifier(node.name)) {\n return node;\n }\n\n const visibilityType = getNodeVisibilityType(node);\n if (visibilityType === VisibilityType.External) {\n return node;\n }\n\n return createNewNodeFromProperty(node.name, visibilityType, (newName: string) => {\n return context.factory.createBindingElement(node.dotDotDotToken, newName, node.name, node.initializer);\n });\n };\n\n // constructor(public node: string) { // <--- this\n // console.log(node); // <--- and this\n // }\n const handleCtorParameter = (node: ts.Identifier): ts.Identifier => createNewIdentifier(node);\n\n const createNewIdentifier = (oldIdentifier: ts.Identifier): ts.Identifier => {\n const visibilityType = getNodeVisibilityType(oldIdentifier);\n if (visibilityType === VisibilityType.External) {\n return oldIdentifier;\n }\n\n return createNewNodeFromProperty(oldIdentifier, visibilityType, context.factory.createIdentifier);\n };\n\n const createNewNodeFromProperty = <T extends ts.Node>(\n oldProperty: ts.PropertyName,\n type: VisibilityType,\n createNode: (newName: string) => T,\n ): T => {\n const symbol = typeChecker.getSymbolAtLocation(oldProperty);\n if (symbol === undefined) {\n throw new Error(`Cannot get symbol for node \"${oldProperty.getText()}\"`);\n }\n\n const oldPropertyName = ts.unescapeLeadingUnderscores(symbol.escapedName);\n\n return createNewNode(oldPropertyName, type, createNode);\n };\n\n const createNewNode = <T extends ts.Node>(\n oldPropertyName: string,\n type: VisibilityType,\n createNode: (newName: string) => T,\n ): T => {\n const newPropertyName = getNewName(oldPropertyName);\n return createNode(newPropertyName);\n };\n\n const getNewName = (originalName: string): string => `${fullOptions.privatePrefix}${originalName}`;\n\n const getActualSymbol = (symbol: ts.Symbol): ts.Symbol => {\n if (symbol.flags & ts.SymbolFlags.Alias) {\n symbol = typeChecker.getAliasedSymbol(symbol);\n }\n\n return symbol;\n };\n\n const getNodeSymbol = (node: ts.Expression | ts.NamedDeclaration | ts.DeclarationName): ts.Symbol | null => {\n const symbol = typeChecker.getSymbolAtLocation(node);\n if (symbol === undefined) {\n return null;\n }\n\n return getActualSymbol(symbol);\n };\n\n const isTypePropertyExternal = (type: ts.Type, typePropertyName: string): boolean => {\n // if a type is unknown or any - they should be interpret as a public ones\n if (type.flags & ts.TypeFlags.Unknown || type.flags & ts.TypeFlags.Any) {\n return true;\n }\n\n if (type.flags & ts.TypeFlags.IndexedAccess) {\n return isTypePropertyExternal(typeChecker.getApparentType(type), typePropertyName);\n }\n\n const symbol = type.getSymbol();\n const propertySymbol = typeChecker.getPropertyOfType(type, typePropertyName);\n\n if (type.flags & ts.TypeFlags.Object) {\n const objectType = type as ts.ObjectType;\n\n // treat any tuple property as \"external\"\n if (objectType.objectFlags & ts.ObjectFlags.Tuple) {\n return true;\n }\n\n if (objectType.objectFlags & ts.ObjectFlags.Reference) {\n const target = (objectType as ts.TypeReference).target;\n if (target !== objectType && isTypePropertyExternal(target, typePropertyName)) {\n return true;\n }\n }\n\n // in case when we can't get where a property come from in mapped types\n // let's check the whole type explicitly\n // thus in case of when property doesn't have a declaration let's treat any property of a mapped type as \"external\" if its parent type is external\n // e.g. Readonly<Foo>.field will look for `field` in _Foo_ type (not in Readonly<Foo>), but { [K in 'foo' | 'bar']: any } won't\n // perhaps it would be awesome to handle exactly property we have, but ¯\\_(ツ)_/¯\n const propertyHasDeclarations =\n propertySymbol !== undefined ? getDeclarationsForSymbol(propertySymbol).length !== 0 : false;\n if (\n objectType.objectFlags & ts.ObjectFlags.Mapped &&\n symbol !== undefined &&\n !propertyHasDeclarations &&\n getSymbolVisibilityType(symbol) === VisibilityType.External\n ) {\n return true;\n }\n }\n\n if (type.isUnionOrIntersection()) {\n const hasExternalSubType = type.types.some((t: ts.Type) => isTypePropertyExternal(t, typePropertyName));\n if (hasExternalSubType) {\n return hasExternalSubType;\n }\n }\n\n if (symbol !== undefined) {\n const declarations = getDeclarationsForSymbol(symbol);\n for (const declaration of declarations) {\n if (\n (ts.isClassDeclaration(declaration) || ts.isInterfaceDeclaration(declaration)) &&\n declaration.heritageClauses !== undefined\n ) {\n const hasHeritageClausesExternals = declaration.heritageClauses.some((clause: ts.HeritageClause) => {\n return clause.types.some((expr: ts.ExpressionWithTypeArguments) => {\n return isTypePropertyExternal(typeChecker.getTypeAtLocation(expr), typePropertyName);\n });\n });\n\n if (hasHeritageClausesExternals) {\n return true;\n }\n }\n }\n }\n\n if (propertySymbol === undefined) {\n return false;\n }\n\n return [propertySymbol, ...splitTransientSymbol(propertySymbol, typeChecker)].some(\n (sym: ts.Symbol) => getSymbolVisibilityType(sym) === VisibilityType.External,\n );\n };\n\n const getNodeVisibilityType = (\n node: ts.Expression | ts.Identifier | ts.StringLiteral | ts.BindingElement,\n ): VisibilityType => {\n if (ts.isPropertyAssignment(node.parent) || ts.isShorthandPropertyAssignment(node.parent)) {\n let expressionToGetTypeFrom: ts.Expression = node.parent.parent;\n let lastKnownExpression: ts.AsExpression | ts.ObjectLiteralExpression = node.parent.parent;\n let currentNode: ts.Node = node.parent.parent.parent;\n\n while (ts.isParenthesizedExpression(currentNode) || ts.isAsExpression(currentNode)) {\n if (ts.isAsExpression(currentNode)) {\n expressionToGetTypeFrom = lastKnownExpression;\n lastKnownExpression = currentNode;\n }\n\n currentNode = currentNode.parent;\n }\n\n // to get correct contextual type we need to provide the previous last expression rather than the last one\n const type = typeChecker.getContextualType(expressionToGetTypeFrom);\n if (type !== undefined && isTypePropertyExternal(type, node.getText())) {\n return VisibilityType.External;\n }\n }\n\n if (ts.isPropertyAccessExpression(node.parent) || ts.isElementAccessExpression(node.parent)) {\n if (ts.isIdentifier(node.parent.expression)) {\n const expressionSymbol = typeChecker.getSymbolAtLocation(node.parent.expression);\n if (LOGS) {\n console.log(\n `[transformer] PropertyAccess: expression=${node.parent.expression.getText()}, property=${node.getText()}`,\n );\n console.log(`[transformer] Expression symbol: ${expressionSymbol?.name}`);\n }\n if (expressionSymbol !== undefined) {\n // import * as foo from '...';\n // foo.node;\n // foo['node'];\n // or\n // namespace Foo { ... }\n // Foo.node\n // Foo['node'];\n const declarations = getDeclarationsForSymbol(expressionSymbol);\n if (LOGS) {\n console.log(`[transformer] Declarations: ${declarations.map((d) => ts.SyntaxKind[d.kind]).join(\", \")}`);\n }\n const isModuleOrStarImport = declarations.some(\n (decl: ts.Declaration) => ts.isNamespaceImport(decl) || ts.isModuleDeclaration(decl),\n );\n if (LOGS) {\n console.log(`[transformer] isModuleOrStarImport: ${isModuleOrStarImport}`);\n }\n if (isModuleOrStarImport) {\n // treat accessing to import-star or namespace as external one\n // because we can't rename them yet\n if (LOGS) {\n console.log(`[transformer] Returning External (module/star import)`);\n }\n return VisibilityType.External;\n }\n\n // import { foo } from '...';\n // where foo is a namespace re-export (export * as foo from './bar')\n // In this case, symbol for 'foo' is an alias to a module\n // Check if the symbol's type is a namespace module or regular module\n const hasImportSpecifier = declarations.some((decl) => ts.isImportSpecifier(decl));\n if (LOGS) {\n console.log(`[transformer] hasImportSpecifier: ${hasImportSpecifier}`);\n }\n if (hasImportSpecifier) {\n const expressionType = typeChecker.getTypeAtLocation(node.parent.expression);\n if (LOGS) {\n console.log(`[transformer] Expression type: ${expressionType?.flags}`);\n }\n if (expressionType) {\n const typeSymbol = expressionType.getSymbol();\n if (LOGS) {\n console.log(`[transformer] Type symbol: ${typeSymbol?.name}, flags: ${typeSymbol?.flags}`);\n }\n // Check if it's a module (NamespaceModule or regular Module)\n // NamespaceModule: 0x8000000, Module: 0x200\n const isModule =\n typeSymbol &&\n ((typeSymbol.flags & ts.SymbolFlags.NamespaceModule) !== 0 ||\n (typeSymbol.flags & ts.SymbolFlags.Module) !== 0);\n if (isModule) {\n // The expression's type is a module, so accessing its properties\n // means accessing exports from that module, which are external\n if (LOGS) {\n console.log(`[transformer] Returning External (module)`);\n }\n return VisibilityType.External;\n }\n }\n }\n }\n }\n\n const expressionType = typeChecker.getTypeAtLocation(node.parent.expression);\n const propertyText = node.getText();\n if (LOGS) {\n console.log(`[transformer] Checking isTypePropertyExternal for ${propertyText}`);\n }\n if (isTypePropertyExternal(expressionType, propertyText)) {\n if (LOGS) {\n console.log(`[transformer] Returning External (isTypePropertyExternal)`);\n }\n return VisibilityType.External;\n }\n }\n\n // shorthand binding element\n // const { node } = obj;\n if (\n ts.isBindingElement(node) &&\n isTypePropertyExternal(typeChecker.getTypeAtLocation(node.parent), node.getText())\n ) {\n return VisibilityType.External;\n }\n\n // full binding element\n // const { node: propName } = obj;\n if (\n ts.isBindingElement(node.parent) &&\n isTypePropertyExternal(typeChecker.getTypeAtLocation(node.parent.parent), node.getText())\n ) {\n return VisibilityType.External;\n }\n\n // <Comp node={...} />\n if (ts.isJsxAttribute(node.parent)) {\n const jsxTagSymbol = typeChecker.getSymbolAtLocation(node.parent.parent.parent.tagName);\n if (jsxTagSymbol !== undefined && jsxTagSymbol.valueDeclaration !== undefined) {\n const jsxPropsType = typeChecker.getTypeOfSymbolAtLocation(jsxTagSymbol, jsxTagSymbol.valueDeclaration);\n if (isTypePropertyExternal(jsxPropsType, node.getText())) {\n return VisibilityType.External;\n }\n }\n }\n\n const nodeSymbol = getNodeSymbol(node);\n const classOfMember = nodeSymbol !== null ? getClassOfMemberSymbol(nodeSymbol) : null;\n if (\n classOfMember !== null &&\n isTypePropertyExternal(typeChecker.getTypeAtLocation(classOfMember), node.getText())\n ) {\n return VisibilityType.External;\n }\n\n const symbol = ts.isBindingElement(node) ? getShorthandObjectBindingElementSymbol(node) : nodeSymbol;\n if (symbol === null) {\n return VisibilityType.External;\n }\n\n return getSymbolVisibilityType(symbol);\n };\n\n const getSymbolVisibilityType = (nodeSymbol: ts.Symbol): VisibilityType => {\n nodeSymbol = getActualSymbol(nodeSymbol);\n\n const cachedValue = cache.get(nodeSymbol);\n if (cachedValue !== undefined) {\n return cachedValue;\n }\n\n const symbolDeclarations = getDeclarationsForSymbol(nodeSymbol);\n if (symbolDeclarations.some(isDeclarationFromExternals)) {\n return putToCache(nodeSymbol, VisibilityType.External);\n }\n\n if (symbolDeclarations.some((decl: ts.Declaration) => hasModifier(decl, ts.SyntaxKind.DeclareKeyword))) {\n return putToCache(nodeSymbol, VisibilityType.External);\n }\n\n if (nodeSymbol.escapedName === \"prototype\") {\n return putToCache(nodeSymbol, VisibilityType.External);\n }\n\n if (fullOptions.publicJSDocTag.length !== 0 || fullOptions.ignoreDecorated) {\n for (const declaration of symbolDeclarations) {\n let currentNode: ts.Node = declaration;\n while (!ts.isSourceFile(currentNode)) {\n if (\n fullOptions.publicJSDocTag.length !== 0 &&\n getNodeJSDocComment(currentNode).includes(`@${fullOptions.publicJSDocTag}`)\n ) {\n return putToCache(nodeSymbol, VisibilityType.External);\n }\n\n if (fullOptions.ignoreDecorated && hasDecorators(currentNode)) {\n return putToCache(nodeSymbol, VisibilityType.External);\n }\n\n if (ts.isEnumDeclaration(currentNode)) {\n return putToCache(nodeSymbol, VisibilityType.External);\n }\n\n currentNode = currentNode.parent;\n }\n }\n }\n\n if (isPrivateClassMember(nodeSymbol)) {\n return putToCache(nodeSymbol, VisibilityType.Private);\n }\n\n if (exportsSymbolTree.isSymbolAccessibleFromExports(nodeSymbol)) {\n return putToCache(nodeSymbol, VisibilityType.External);\n }\n\n for (const declaration of symbolDeclarations) {\n if (!isNodeNamedDeclaration(declaration.parent) || declaration.parent.name === undefined) {\n continue;\n }\n\n const parentSymbol = getNodeSymbol(declaration.parent.name);\n if (parentSymbol === null) {\n continue;\n }\n\n if (getSymbolVisibilityType(parentSymbol) === VisibilityType.External) {\n return putToCache(nodeSymbol, VisibilityType.External);\n }\n }\n\n return putToCache(nodeSymbol, VisibilityType.Private);\n };\n\n const getShorthandObjectBindingElementSymbol = (element: ts.BindingElement): ts.Symbol | null => {\n if (element.propertyName !== undefined) {\n throw new Error(\n `Cannot handle binding element with property name: ${element.getText()} in ${\n element.getSourceFile().fileName\n }`,\n );\n }\n\n if (!ts.isIdentifier(element.name)) {\n return null;\n }\n\n // if no property name is set (const { a } = foo)\n // then node.propertyName is undefined and we need to find this property ourselves\n // so let's use go-to-definition algorithm from TSServer\n // see https://github.com/microsoft/TypeScript/blob/672b0e3e16ad18b422dbe0cec5a98fce49881b76/src/services/goToDefinition.ts#L58-L77\n const type = typeChecker.getTypeAtLocation(element.parent as ts.Node);\n if (type.isUnion()) {\n return null;\n }\n\n return type.getProperty(ts.idText(element.name)) || null;\n };\n\n const isDeclarationFromExternals = (declaration: ts.Declaration): boolean => {\n const sourceFile = declaration.getSourceFile();\n\n // all declarations from declaration source files are external by default\n return (\n sourceFile.isDeclarationFile ||\n program.isSourceFileDefaultLibrary(sourceFile) ||\n /[\\\\/]node_modules[\\\\/]/.test(sourceFile.fileName)\n );\n };\n\n const isConstructorParameterReference = (node: ts.Node): node is ts.Identifier => {\n if (!ts.isIdentifier(node)) {\n return false;\n }\n\n return isSymbolClassMember(typeChecker.getSymbolAtLocation(node));\n };\n const transformNodeAndChildren = (node: ts.Node): ts.Node | undefined =>\n ts.visitEachChild(transformNode(node), transformNodeAndChildren, context);\n\n return (sourceFile: ts.SourceFile) => transformNodeAndChildren(sourceFile) as ts.SourceFile;\n };\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eliasku/ts-transformers",
|
|
3
3
|
"description": "TypeScript transformer for code optimization",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.10",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"type": "module",
|
|
7
6
|
"scripts": {
|
|
7
|
+
"build": "tsup ./src/index.ts --target esnext --platform neutral --format esm --dts --sourcemap --minify terser --treeshake smallest --splitting false",
|
|
8
8
|
"test": "bun test",
|
|
9
9
|
"format": "prettier --write **/*.{ts,json,md,yml}",
|
|
10
10
|
"check": "tsc -p .",
|
|
@@ -22,12 +22,19 @@
|
|
|
22
22
|
"rollup": "latest",
|
|
23
23
|
"@rollup/plugin-typescript": "latest",
|
|
24
24
|
"tslib": "latest",
|
|
25
|
-
"esbuild": "latest"
|
|
25
|
+
"esbuild": "latest",
|
|
26
|
+
"tsup": "latest",
|
|
27
|
+
"terser": "latest"
|
|
26
28
|
},
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
+
"type": "module",
|
|
30
|
+
"module": "./dist/index.js",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
29
32
|
"exports": {
|
|
30
|
-
".":
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"import": "./dist/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./ts": "./scr/index.ts"
|
|
31
38
|
},
|
|
32
39
|
"repository": {
|
|
33
40
|
"type": "git",
|
|
@@ -47,6 +54,7 @@
|
|
|
47
54
|
"access": "public"
|
|
48
55
|
},
|
|
49
56
|
"files": [
|
|
57
|
+
"dist",
|
|
50
58
|
"src"
|
|
51
59
|
]
|
|
52
60
|
}
|
package/src/exports/tracker.ts
CHANGED
|
@@ -14,12 +14,12 @@ export class ExportsSymbolTree {
|
|
|
14
14
|
private readonly program: ts.Program;
|
|
15
15
|
private readonly exportsTree = new Map<ts.Symbol, Set<ts.Symbol>>();
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
constructor(program: ts.Program, entrySourceFiles: readonly string[]) {
|
|
18
18
|
this.program = program;
|
|
19
19
|
this.computeTreeForExports(entrySourceFiles);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
isSymbolAccessibleFromExports(symbol: ts.Symbol): boolean {
|
|
23
23
|
symbol = this.getActualSymbol(symbol);
|
|
24
24
|
for (const [, set] of this.exportsTree) {
|
|
25
25
|
if (set.has(symbol)) {
|
|
@@ -122,24 +122,6 @@ export class ExportsSymbolTree {
|
|
|
122
122
|
} else {
|
|
123
123
|
console.warn(`[computeTreeForChildren] Could not get exports for aliased symbol`);
|
|
124
124
|
}
|
|
125
|
-
if (LOGS) {
|
|
126
|
-
console.log(`[computeTreeForChildren] Module exports: ${moduleExports.map((e) => e.name).join(", ")}`);
|
|
127
|
-
}
|
|
128
|
-
for (const exportSymbol of moduleExports) {
|
|
129
|
-
const actualExport = getActualSymbol(exportSymbol, typeChecker);
|
|
130
|
-
if (!visitedSymbols.has(actualExport)) {
|
|
131
|
-
visitedSymbols.add(actualExport);
|
|
132
|
-
targetSymbolsSet.add(actualExport);
|
|
133
|
-
if (LOGS) {
|
|
134
|
-
console.log(`[computeTreeForChildren] Adding: ${actualExport.escapedName}`);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// Recursively process the export's declarations
|
|
138
|
-
for (const exportDeclaration of getDeclarationsForSymbol(actualExport)) {
|
|
139
|
-
this.computeTreeForChildren(targetSymbolsSet, exportDeclaration, visitedSymbols);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
125
|
}
|
|
144
126
|
return;
|
|
145
127
|
}
|
package/src/index.ts
CHANGED
|
@@ -28,13 +28,13 @@ export const optimizer = (
|
|
|
28
28
|
|
|
29
29
|
const cache = new Map<ts.Symbol, VisibilityType>();
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
const putToCache = (nodeSymbol: ts.Symbol, val: VisibilityType): VisibilityType => {
|
|
32
32
|
cache.set(nodeSymbol, val);
|
|
33
33
|
return val;
|
|
34
|
-
}
|
|
34
|
+
};
|
|
35
35
|
|
|
36
36
|
return (context: ts.TransformationContext) => {
|
|
37
|
-
|
|
37
|
+
const transformNode = (node: ts.Node): ts.Node | undefined => {
|
|
38
38
|
// const a = { node }
|
|
39
39
|
if (ts.isShorthandPropertyAssignment(node)) {
|
|
40
40
|
return handleShorthandPropertyAssignment(node);
|
|
@@ -115,9 +115,9 @@ export const optimizer = (
|
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
return node;
|
|
118
|
-
}
|
|
118
|
+
};
|
|
119
119
|
|
|
120
|
-
|
|
120
|
+
const handleInKeyword = (node: ts.StringLiteral): ts.StringLiteral => {
|
|
121
121
|
const parent = node.parent as ts.BinaryExpression;
|
|
122
122
|
const nodeType = typeChecker.getTypeAtLocation(node);
|
|
123
123
|
if (!nodeType.isStringLiteral()) {
|
|
@@ -130,53 +130,41 @@ export const optimizer = (
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
return createNewNode(propertyName, VisibilityType.Private, context.factory.createStringLiteral);
|
|
133
|
-
}
|
|
133
|
+
};
|
|
134
134
|
|
|
135
135
|
// obj.node
|
|
136
|
-
|
|
137
|
-
return createNewIdentifier(node);
|
|
138
|
-
}
|
|
136
|
+
const handlePropertyAccessIdentifier = (node: ts.Identifier): ts.Identifier => createNewIdentifier(node);
|
|
139
137
|
|
|
140
138
|
// obj['fooBar']
|
|
141
|
-
|
|
139
|
+
const handleElementAccessExpression = (node: ts.StringLiteral): ts.StringLiteral => {
|
|
142
140
|
const visibilityType = getNodeVisibilityType(node);
|
|
143
141
|
if (visibilityType === VisibilityType.External) {
|
|
144
142
|
return node;
|
|
145
143
|
}
|
|
146
144
|
|
|
147
145
|
return createNewNodeFromProperty(node, visibilityType, context.factory.createStringLiteral);
|
|
148
|
-
}
|
|
146
|
+
};
|
|
149
147
|
|
|
150
148
|
// private node
|
|
151
149
|
// public node()
|
|
152
|
-
|
|
153
|
-
return createNewIdentifier(node);
|
|
154
|
-
}
|
|
150
|
+
const handleClassMember = (node: ts.Identifier): ts.Identifier => createNewIdentifier(node);
|
|
155
151
|
|
|
156
152
|
// enum Enum { node }
|
|
157
|
-
|
|
158
|
-
return createNewIdentifier(node);
|
|
159
|
-
}
|
|
153
|
+
const handleEnumMember = (node: ts.Identifier): ts.Identifier => createNewIdentifier(node);
|
|
160
154
|
|
|
161
155
|
// const { node: localName } = obj;
|
|
162
|
-
|
|
163
|
-
return createNewIdentifier(node);
|
|
164
|
-
}
|
|
156
|
+
const handleBindingElement = (node: ts.Identifier): ts.Identifier => createNewIdentifier(node);
|
|
165
157
|
|
|
166
158
|
// <Comp node={...} />
|
|
167
|
-
|
|
168
|
-
return createNewIdentifier(node);
|
|
169
|
-
}
|
|
159
|
+
const handleJsxAttributeName = (node: ts.Identifier): ts.Identifier => createNewIdentifier(node);
|
|
170
160
|
|
|
171
161
|
// const a = { node: 123 }
|
|
172
|
-
|
|
173
|
-
return createNewIdentifier(node);
|
|
174
|
-
}
|
|
162
|
+
const handlePropertyAssignment = (node: ts.Identifier): ts.Identifier => createNewIdentifier(node);
|
|
175
163
|
|
|
176
164
|
// const a = { node }
|
|
177
|
-
|
|
165
|
+
const handleShorthandPropertyAssignment = (
|
|
178
166
|
node: ts.ShorthandPropertyAssignment,
|
|
179
|
-
): ts.PropertyAssignment | ts.ShorthandPropertyAssignment {
|
|
167
|
+
): ts.PropertyAssignment | ts.ShorthandPropertyAssignment => {
|
|
180
168
|
const visibilityType = getNodeVisibilityType(node.name);
|
|
181
169
|
if (visibilityType === VisibilityType.External) {
|
|
182
170
|
return node;
|
|
@@ -185,10 +173,10 @@ export const optimizer = (
|
|
|
185
173
|
return createNewNodeFromProperty(node.name, visibilityType, (newName: string) => {
|
|
186
174
|
return context.factory.createPropertyAssignment(newName, node.name);
|
|
187
175
|
});
|
|
188
|
-
}
|
|
176
|
+
};
|
|
189
177
|
|
|
190
178
|
// const { node } = obj;
|
|
191
|
-
|
|
179
|
+
const handleShorthandObjectBindingElement = (node: ts.BindingElement): ts.BindingElement => {
|
|
192
180
|
if (!ts.isIdentifier(node.name)) {
|
|
193
181
|
return node;
|
|
194
182
|
}
|
|
@@ -201,29 +189,27 @@ export const optimizer = (
|
|
|
201
189
|
return createNewNodeFromProperty(node.name, visibilityType, (newName: string) => {
|
|
202
190
|
return context.factory.createBindingElement(node.dotDotDotToken, newName, node.name, node.initializer);
|
|
203
191
|
});
|
|
204
|
-
}
|
|
192
|
+
};
|
|
205
193
|
|
|
206
194
|
// constructor(public node: string) { // <--- this
|
|
207
195
|
// console.log(node); // <--- and this
|
|
208
196
|
// }
|
|
209
|
-
|
|
210
|
-
return createNewIdentifier(node);
|
|
211
|
-
}
|
|
197
|
+
const handleCtorParameter = (node: ts.Identifier): ts.Identifier => createNewIdentifier(node);
|
|
212
198
|
|
|
213
|
-
|
|
199
|
+
const createNewIdentifier = (oldIdentifier: ts.Identifier): ts.Identifier => {
|
|
214
200
|
const visibilityType = getNodeVisibilityType(oldIdentifier);
|
|
215
201
|
if (visibilityType === VisibilityType.External) {
|
|
216
202
|
return oldIdentifier;
|
|
217
203
|
}
|
|
218
204
|
|
|
219
205
|
return createNewNodeFromProperty(oldIdentifier, visibilityType, context.factory.createIdentifier);
|
|
220
|
-
}
|
|
206
|
+
};
|
|
221
207
|
|
|
222
|
-
|
|
208
|
+
const createNewNodeFromProperty = <T extends ts.Node>(
|
|
223
209
|
oldProperty: ts.PropertyName,
|
|
224
210
|
type: VisibilityType,
|
|
225
211
|
createNode: (newName: string) => T,
|
|
226
|
-
): T {
|
|
212
|
+
): T => {
|
|
227
213
|
const symbol = typeChecker.getSymbolAtLocation(oldProperty);
|
|
228
214
|
if (symbol === undefined) {
|
|
229
215
|
throw new Error(`Cannot get symbol for node "${oldProperty.getText()}"`);
|
|
@@ -232,39 +218,37 @@ export const optimizer = (
|
|
|
232
218
|
const oldPropertyName = ts.unescapeLeadingUnderscores(symbol.escapedName);
|
|
233
219
|
|
|
234
220
|
return createNewNode(oldPropertyName, type, createNode);
|
|
235
|
-
}
|
|
221
|
+
};
|
|
236
222
|
|
|
237
|
-
|
|
223
|
+
const createNewNode = <T extends ts.Node>(
|
|
238
224
|
oldPropertyName: string,
|
|
239
225
|
type: VisibilityType,
|
|
240
226
|
createNode: (newName: string) => T,
|
|
241
|
-
): T {
|
|
227
|
+
): T => {
|
|
242
228
|
const newPropertyName = getNewName(oldPropertyName);
|
|
243
229
|
return createNode(newPropertyName);
|
|
244
|
-
}
|
|
230
|
+
};
|
|
245
231
|
|
|
246
|
-
|
|
247
|
-
return `${fullOptions.privatePrefix}${originalName}`;
|
|
248
|
-
}
|
|
232
|
+
const getNewName = (originalName: string): string => `${fullOptions.privatePrefix}${originalName}`;
|
|
249
233
|
|
|
250
|
-
|
|
234
|
+
const getActualSymbol = (symbol: ts.Symbol): ts.Symbol => {
|
|
251
235
|
if (symbol.flags & ts.SymbolFlags.Alias) {
|
|
252
236
|
symbol = typeChecker.getAliasedSymbol(symbol);
|
|
253
237
|
}
|
|
254
238
|
|
|
255
239
|
return symbol;
|
|
256
|
-
}
|
|
240
|
+
};
|
|
257
241
|
|
|
258
|
-
|
|
242
|
+
const getNodeSymbol = (node: ts.Expression | ts.NamedDeclaration | ts.DeclarationName): ts.Symbol | null => {
|
|
259
243
|
const symbol = typeChecker.getSymbolAtLocation(node);
|
|
260
244
|
if (symbol === undefined) {
|
|
261
245
|
return null;
|
|
262
246
|
}
|
|
263
247
|
|
|
264
248
|
return getActualSymbol(symbol);
|
|
265
|
-
}
|
|
249
|
+
};
|
|
266
250
|
|
|
267
|
-
|
|
251
|
+
const isTypePropertyExternal = (type: ts.Type, typePropertyName: string): boolean => {
|
|
268
252
|
// if a type is unknown or any - they should be interpret as a public ones
|
|
269
253
|
if (type.flags & ts.TypeFlags.Unknown || type.flags & ts.TypeFlags.Any) {
|
|
270
254
|
return true;
|
|
@@ -343,11 +327,11 @@ export const optimizer = (
|
|
|
343
327
|
return [propertySymbol, ...splitTransientSymbol(propertySymbol, typeChecker)].some(
|
|
344
328
|
(sym: ts.Symbol) => getSymbolVisibilityType(sym) === VisibilityType.External,
|
|
345
329
|
);
|
|
346
|
-
}
|
|
330
|
+
};
|
|
347
331
|
|
|
348
|
-
|
|
332
|
+
const getNodeVisibilityType = (
|
|
349
333
|
node: ts.Expression | ts.Identifier | ts.StringLiteral | ts.BindingElement,
|
|
350
|
-
): VisibilityType {
|
|
334
|
+
): VisibilityType => {
|
|
351
335
|
if (ts.isPropertyAssignment(node.parent) || ts.isShorthandPropertyAssignment(node.parent)) {
|
|
352
336
|
let expressionToGetTypeFrom: ts.Expression = node.parent.parent;
|
|
353
337
|
let lastKnownExpression: ts.AsExpression | ts.ObjectLiteralExpression = node.parent.parent;
|
|
@@ -499,9 +483,9 @@ export const optimizer = (
|
|
|
499
483
|
}
|
|
500
484
|
|
|
501
485
|
return getSymbolVisibilityType(symbol);
|
|
502
|
-
}
|
|
486
|
+
};
|
|
503
487
|
|
|
504
|
-
|
|
488
|
+
const getSymbolVisibilityType = (nodeSymbol: ts.Symbol): VisibilityType => {
|
|
505
489
|
nodeSymbol = getActualSymbol(nodeSymbol);
|
|
506
490
|
|
|
507
491
|
const cachedValue = cache.get(nodeSymbol);
|
|
@@ -570,9 +554,9 @@ export const optimizer = (
|
|
|
570
554
|
}
|
|
571
555
|
|
|
572
556
|
return putToCache(nodeSymbol, VisibilityType.Private);
|
|
573
|
-
}
|
|
557
|
+
};
|
|
574
558
|
|
|
575
|
-
|
|
559
|
+
const getShorthandObjectBindingElementSymbol = (element: ts.BindingElement): ts.Symbol | null => {
|
|
576
560
|
if (element.propertyName !== undefined) {
|
|
577
561
|
throw new Error(
|
|
578
562
|
`Cannot handle binding element with property name: ${element.getText()} in ${
|
|
@@ -595,9 +579,9 @@ export const optimizer = (
|
|
|
595
579
|
}
|
|
596
580
|
|
|
597
581
|
return type.getProperty(ts.idText(element.name)) || null;
|
|
598
|
-
}
|
|
582
|
+
};
|
|
599
583
|
|
|
600
|
-
|
|
584
|
+
const isDeclarationFromExternals = (declaration: ts.Declaration): boolean => {
|
|
601
585
|
const sourceFile = declaration.getSourceFile();
|
|
602
586
|
|
|
603
587
|
// all declarations from declaration source files are external by default
|
|
@@ -606,16 +590,15 @@ export const optimizer = (
|
|
|
606
590
|
program.isSourceFileDefaultLibrary(sourceFile) ||
|
|
607
591
|
/[\\/]node_modules[\\/]/.test(sourceFile.fileName)
|
|
608
592
|
);
|
|
609
|
-
}
|
|
593
|
+
};
|
|
610
594
|
|
|
611
|
-
|
|
595
|
+
const isConstructorParameterReference = (node: ts.Node): node is ts.Identifier => {
|
|
612
596
|
if (!ts.isIdentifier(node)) {
|
|
613
597
|
return false;
|
|
614
598
|
}
|
|
615
599
|
|
|
616
600
|
return isSymbolClassMember(typeChecker.getSymbolAtLocation(node));
|
|
617
|
-
}
|
|
618
|
-
|
|
601
|
+
};
|
|
619
602
|
const transformNodeAndChildren = (node: ts.Node): ts.Node | undefined =>
|
|
620
603
|
ts.visitEachChild(transformNode(node), transformNodeAndChildren, context);
|
|
621
604
|
|
package/src/utils/ast-utils.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export const getNodeJSDocComment = (node: ts.Node): string => {
|
|
4
4
|
const start = node.getStart();
|
|
5
5
|
const jsDocStart = node.getStart(undefined, true);
|
|
6
6
|
return node.getSourceFile().getFullText().substring(jsDocStart, start).trim();
|
|
7
|
-
}
|
|
7
|
+
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export const getActualSymbol = (symbol: ts.Symbol, typeChecker: ts.TypeChecker): ts.Symbol => {
|
|
4
4
|
if (symbol.flags & ts.SymbolFlags.Alias) {
|
|
5
5
|
symbol = typeChecker.getAliasedSymbol(symbol);
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
return symbol;
|
|
9
|
-
}
|
|
9
|
+
};
|
|
10
10
|
|
|
11
|
-
export
|
|
11
|
+
export const splitTransientSymbol = (symbol: ts.Symbol, typeChecker: ts.TypeChecker): ts.Symbol[] => {
|
|
12
12
|
// actually I think we even don't need to operate/use "Transient" symbols anywhere
|
|
13
13
|
// it's kind of aliased symbol, but just merged
|
|
14
14
|
// but it's hard to refractor everything to use array of symbols instead of just symbol
|
|
@@ -36,9 +36,9 @@ export function splitTransientSymbol(symbol: ts.Symbol, typeChecker: ts.TypeChec
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
return result;
|
|
39
|
-
}
|
|
39
|
+
};
|
|
40
40
|
|
|
41
|
-
export
|
|
41
|
+
export const getDeclarationsForSymbol = (symbol: ts.Symbol): ts.Declaration[] => {
|
|
42
42
|
const result: ts.Declaration[] = [];
|
|
43
43
|
|
|
44
44
|
if (symbol.declarations !== undefined) {
|
|
@@ -54,9 +54,9 @@ export function getDeclarationsForSymbol(symbol: ts.Symbol): ts.Declaration[] {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
return result;
|
|
57
|
-
}
|
|
57
|
+
};
|
|
58
58
|
|
|
59
|
-
export
|
|
59
|
+
export const getExportsForSourceFile = (typeChecker: ts.TypeChecker, sourceFileSymbol: ts.Symbol): ts.Symbol[] => {
|
|
60
60
|
if (sourceFileSymbol.exports !== undefined) {
|
|
61
61
|
const commonJsExport = sourceFileSymbol.exports.get(ts.InternalSymbolName.ExportEquals);
|
|
62
62
|
if (commonJsExport !== undefined) {
|
|
@@ -78,7 +78,7 @@ export function getExportsForSourceFile(typeChecker: ts.TypeChecker, sourceFileS
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
return result.map((symbol: ts.Symbol) => getActualSymbol(symbol, typeChecker));
|
|
81
|
-
}
|
|
81
|
+
};
|
|
82
82
|
|
|
83
83
|
const namedDeclarationKinds = [
|
|
84
84
|
ts.SyntaxKind.InterfaceDeclaration,
|
|
@@ -92,9 +92,8 @@ const namedDeclarationKinds = [
|
|
|
92
92
|
ts.SyntaxKind.Parameter,
|
|
93
93
|
];
|
|
94
94
|
|
|
95
|
-
export
|
|
96
|
-
|
|
97
|
-
}
|
|
95
|
+
export const isNodeNamedDeclaration = (node: ts.Node): node is ts.NamedDeclaration =>
|
|
96
|
+
namedDeclarationKinds.indexOf(node.kind) !== -1;
|
|
98
97
|
|
|
99
98
|
export type ClassMember =
|
|
100
99
|
| ts.MethodDeclaration
|
|
@@ -102,15 +101,12 @@ export type ClassMember =
|
|
|
102
101
|
| ts.GetAccessorDeclaration
|
|
103
102
|
| ts.SetAccessorDeclaration;
|
|
104
103
|
|
|
105
|
-
export
|
|
106
|
-
|
|
107
|
-
ts.isMethodDeclaration(node) || ts.isPropertyDeclaration(node) || ts.isGetAccessor(node) || ts.isSetAccessor(node)
|
|
108
|
-
);
|
|
109
|
-
}
|
|
104
|
+
export const isClassMember = (node: ts.Node): node is ClassMember =>
|
|
105
|
+
ts.isMethodDeclaration(node) || ts.isPropertyDeclaration(node) || ts.isGetAccessor(node) || ts.isSetAccessor(node);
|
|
110
106
|
|
|
111
|
-
export
|
|
107
|
+
export const getClassOfMemberSymbol = (
|
|
112
108
|
nodeSymbol: ts.Symbol,
|
|
113
|
-
): ts.ClassLikeDeclaration | ts.ObjectLiteralExpression | ts.TypeLiteralNode | ts.InterfaceDeclaration | null {
|
|
109
|
+
): ts.ClassLikeDeclaration | ts.ObjectLiteralExpression | ts.TypeLiteralNode | ts.InterfaceDeclaration | null => {
|
|
114
110
|
const classMembers = getClassMemberDeclarations(nodeSymbol);
|
|
115
111
|
if (classMembers.length !== 0) {
|
|
116
112
|
// we need any member to get class' declaration
|
|
@@ -124,13 +120,12 @@ export function getClassOfMemberSymbol(
|
|
|
124
120
|
}
|
|
125
121
|
|
|
126
122
|
return null;
|
|
127
|
-
}
|
|
123
|
+
};
|
|
128
124
|
|
|
129
|
-
export
|
|
130
|
-
|
|
131
|
-
}
|
|
125
|
+
export const hasPrivateKeyword = (node: ClassMember | ts.ParameterDeclaration): boolean =>
|
|
126
|
+
hasModifier(node, ts.SyntaxKind.PrivateKeyword);
|
|
132
127
|
|
|
133
|
-
|
|
128
|
+
const getModifiers = (node: ts.Node): readonly ts.Modifier[] => {
|
|
134
129
|
if (isBreakingTypeScriptApi(ts)) {
|
|
135
130
|
if (!ts.canHaveModifiers(node)) {
|
|
136
131
|
return [];
|
|
@@ -142,13 +137,12 @@ function getModifiers(node: ts.Node): readonly ts.Modifier[] {
|
|
|
142
137
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
143
138
|
// @ts-ignore
|
|
144
139
|
return node.modifiers || [];
|
|
145
|
-
}
|
|
140
|
+
};
|
|
146
141
|
|
|
147
|
-
export
|
|
148
|
-
|
|
149
|
-
}
|
|
142
|
+
export const hasModifier = (node: ts.Node, modifier: ts.SyntaxKind): boolean =>
|
|
143
|
+
getModifiers(node).some((mod) => mod.kind === modifier);
|
|
150
144
|
|
|
151
|
-
|
|
145
|
+
const getDecorators = (node: ts.Node): readonly unknown[] => {
|
|
152
146
|
if (isBreakingTypeScriptApi(ts)) {
|
|
153
147
|
if (!ts.canHaveDecorators(node)) {
|
|
154
148
|
return [];
|
|
@@ -160,24 +154,19 @@ function getDecorators(node: ts.Node): readonly unknown[] {
|
|
|
160
154
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
161
155
|
// @ts-ignore
|
|
162
156
|
return node.decorators || [];
|
|
163
|
-
}
|
|
157
|
+
};
|
|
164
158
|
|
|
165
|
-
export
|
|
166
|
-
return getDecorators(node).length !== 0;
|
|
167
|
-
}
|
|
159
|
+
export const hasDecorators = (node: ts.Node): boolean => getDecorators(node).length !== 0;
|
|
168
160
|
|
|
169
|
-
export
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
hasModifier(node, ts.SyntaxKind.ReadonlyKeyword))
|
|
177
|
-
);
|
|
178
|
-
}
|
|
161
|
+
export const isConstructorParameter = (node: ts.Node): node is ts.ParameterDeclaration =>
|
|
162
|
+
ts.isParameter(node) &&
|
|
163
|
+
ts.isConstructorDeclaration(node.parent as ts.Node) &&
|
|
164
|
+
(hasModifier(node, ts.SyntaxKind.PublicKeyword) ||
|
|
165
|
+
hasModifier(node, ts.SyntaxKind.ProtectedKeyword) ||
|
|
166
|
+
hasModifier(node, ts.SyntaxKind.PrivateKeyword) ||
|
|
167
|
+
hasModifier(node, ts.SyntaxKind.ReadonlyKeyword));
|
|
179
168
|
|
|
180
|
-
|
|
169
|
+
const getClassMemberDeclarations = (symbol: ts.Symbol | undefined): (ClassMember | ts.ParameterDeclaration)[] => {
|
|
181
170
|
if (symbol === undefined) {
|
|
182
171
|
return [];
|
|
183
172
|
}
|
|
@@ -190,15 +179,13 @@ function getClassMemberDeclarations(symbol: ts.Symbol | undefined): (ClassMember
|
|
|
190
179
|
return declarations.filter((x: ts.Declaration): x is ClassMember | ts.ParameterDeclaration => {
|
|
191
180
|
return isClassMember(x) || isConstructorParameter(x);
|
|
192
181
|
});
|
|
193
|
-
}
|
|
182
|
+
};
|
|
194
183
|
|
|
195
|
-
export
|
|
196
|
-
|
|
197
|
-
}
|
|
184
|
+
export const isSymbolClassMember = (symbol: ts.Symbol | undefined): boolean =>
|
|
185
|
+
getClassMemberDeclarations(symbol).length !== 0;
|
|
198
186
|
|
|
199
|
-
export
|
|
200
|
-
|
|
201
|
-
}
|
|
187
|
+
export const isPrivateClassMember = (symbol: ts.Symbol | undefined): boolean =>
|
|
188
|
+
getClassMemberDeclarations(symbol).some(hasPrivateKeyword);
|
|
202
189
|
|
|
203
190
|
// decorators and modifiers-related api added in ts 4.8
|
|
204
191
|
interface BreakingTypeScriptApi {
|
|
@@ -208,6 +195,5 @@ interface BreakingTypeScriptApi {
|
|
|
208
195
|
getModifiers(node: ts.Node): readonly ts.Modifier[] | undefined;
|
|
209
196
|
}
|
|
210
197
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
198
|
+
const isBreakingTypeScriptApi = (compiler: object): compiler is BreakingTypeScriptApi =>
|
|
199
|
+
"canHaveDecorators" in compiler;
|