Skip to content

Commit

Permalink
Merge pull request #1238 from IgniteUI/bpenkov/typescript-ast-transfo…
Browse files Browse the repository at this point in the history
…rmer

Implement an AST transformer
  • Loading branch information
Lipata authored Jun 7, 2024
2 parents 1f68a25 + 4df028f commit cddcc3a
Show file tree
Hide file tree
Showing 10 changed files with 2,082 additions and 24 deletions.
3 changes: 3 additions & 0 deletions packages/core/types/KeyValuePair.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface KeyValuePair<T> {
[key: string]: T;
}
2 changes: 2 additions & 0 deletions packages/core/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ export * from "./TemplateDependency";
export * from "./enumerations/ControlExtraConfigType";
export * from "./TemplateReplaceDelimiters";
export * from "./FileSystem";
export * from "./types-typescript";
export * from './KeyValuePair';
73 changes: 73 additions & 0 deletions packages/core/types/types-typescript.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import * as ts from 'typescript';
import { Expression, FormatCodeSettings } from 'typescript';

export interface FormattingService {
path: string;
/** Applies formatting to the file after reading it form the `fs`. */
applyFormatting(sourceFile: ts.SourceFile): string;
}

export interface FormatSettings extends FormatCodeSettings {
singleQuotes?: boolean;
}

export interface Identifier {
name: string;
alias?: string;
}

export interface ImportDeclarationMeta {
identifiers: Identifier | Identifier[];
moduleName: string;
}

export interface PropertyAssignment {
name: string;
value: Expression;
}

/**
* The type of change to apply to the source file.
*/
export enum ChangeType {
NewNode = 'new-node',
NodeUpdate = 'node-update',
}

/**
* The kind of syntax node to transform in the source file.
*/
export enum SyntaxKind {
PropertyAssignment = 'property-assignment',
ObjectLiteralExpression = 'object-literal-expression',
ArrayLiteralExpression = 'array-literal-expression',
ImportDeclaration = 'import-declaration',
Primitive = 'primitive',
Expression = 'expression',
}

/**
* A request to change the source file.
*/
export interface ChangeRequest<T extends ts.Node> {
/**
* A unique identifier for the change request. It can represent the accumulated values of a node's text or properties.
*/
id: string;
/**
* The type of change to apply to the source file.
*/
type: ChangeType;
/**
* The transformer factory to apply to the source file.
*/
transformerFactory: ts.TransformerFactory<ts.SourceFile>;
/**
* The kind of syntax node to transform in the source file.
*/
syntaxKind: SyntaxKind;
/**
* The affected node in the source file.
*/
node: T | ts.NodeArray<T>;
}
Loading

0 comments on commit cddcc3a

Please sign in to comment.