Skip to content

Commit

Permalink
fix(app): drop usage of ts-simple-ast for ts-morph
Browse files Browse the repository at this point in the history
  • Loading branch information
vogloblinsky committed Jul 14, 2021
1 parent ee0d9c3 commit 7bb9a40
Show file tree
Hide file tree
Showing 27 changed files with 75 additions and 1,164 deletions.
1,139 changes: 24 additions & 1,115 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion package.json
Expand Up @@ -115,7 +115,6 @@
"semver": "^7.3.5",
"traverse": "^0.6.6",
"ts-morph": "^11.0.3",
"ts-simple-ast": "21.0.4",
"uuid": "^8.3.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/app/application.ts
Expand Up @@ -3,7 +3,7 @@ import * as LiveServer from '@compodoc/live-server';
import * as _ from 'lodash';
import * as path from 'path';

import { SyntaxKind } from 'ts-simple-ast';
import { SyntaxKind } from 'ts-morph';

const chokidar = require('chokidar');
const marked = require('marked');
Expand Down
6 changes: 3 additions & 3 deletions src/app/compiler/angular-dependencies.ts
@@ -1,7 +1,7 @@
import * as path from 'path';

import * as _ from 'lodash';
import Ast, { ts, SyntaxKind } from 'ts-simple-ast';
import { Project, ts, SyntaxKind } from 'ts-morph';

import { kindToType } from '../../utils/kind-to-type';
import { logger } from '../../utils/logger';
Expand Down Expand Up @@ -48,7 +48,7 @@ import {

const crypto = require('crypto');
const marked = require('marked');
const ast = new Ast();
const ast = new Project();

// TypeScript reference : https://github.com/Microsoft/TypeScript/blob/master/lib/typescript.d.ts

Expand Down Expand Up @@ -288,7 +288,7 @@ export class AngularDependencies extends FrameworkDependencies {
const astFile =
typeof ast.getSourceFile(initialSrcFile.fileName) !== 'undefined'
? ast.getSourceFile(initialSrcFile.fileName)
: ast.addExistingSourceFile(initialSrcFile.fileName);
: ast.addSourceFileAtPath(initialSrcFile.fileName);

const variableRoutesStatements = astFile.getVariableStatements();
let hasRoutesStatements = false;
Expand Down
18 changes: 9 additions & 9 deletions src/app/compiler/angular/code-generator.ts
@@ -1,4 +1,4 @@
import { ts, SyntaxKind } from 'ts-simple-ast';
import { ts, SyntaxKind } from 'ts-morph';

export class CodeGenerator {
public generate(node: ts.Node): string {
Expand Down Expand Up @@ -38,10 +38,10 @@ class TsKindsToText {
}

const TsKindConversion: Array<TsKindsToText> = [
new TsKindsToText(node => ['"', node.text, '"'], [
SyntaxKind.FirstLiteralToken,
SyntaxKind.Identifier
]),
new TsKindsToText(
node => ['"', node.text, '"'],
[SyntaxKind.FirstLiteralToken, SyntaxKind.Identifier]
),
new TsKindsToText(node => ['"', node.text, '"'], [SyntaxKind.StringLiteral]),
new TsKindsToText(node => [], [SyntaxKind.ArrayLiteralExpression]),
new TsKindsToText(node => ['import', ' '], [SyntaxKind.ImportKeyword]),
Expand All @@ -57,10 +57,10 @@ const TsKindConversion: Array<TsKindsToText> = [
new TsKindsToText(node => ['+'], [SyntaxKind.PlusToken]),
new TsKindsToText(node => [' => '], [SyntaxKind.EqualsGreaterThanToken]),
new TsKindsToText(node => ['('], [SyntaxKind.OpenParenToken]),
new TsKindsToText(node => ['{', ' '], [
SyntaxKind.ImportClause,
SyntaxKind.ObjectLiteralExpression
]),
new TsKindsToText(
node => ['{', ' '],
[SyntaxKind.ImportClause, SyntaxKind.ObjectLiteralExpression]
),
new TsKindsToText(node => ['{', '\n'], [SyntaxKind.Block]),
new TsKindsToText(node => ['}'], [SyntaxKind.CloseBraceToken]),
new TsKindsToText(node => [')'], [SyntaxKind.CloseParenToken]),
Expand Down
2 changes: 1 addition & 1 deletion src/app/compiler/angular/deps/controller-dep.factory.ts
@@ -1,5 +1,5 @@
import { IDep } from '../dependencies.interfaces';
import { ts } from 'ts-simple-ast';
import { ts } from 'ts-morph';

const crypto = require('crypto');

Expand Down
2 changes: 1 addition & 1 deletion src/app/compiler/angular/deps/helpers/class-helper.ts
Expand Up @@ -2,7 +2,7 @@ import * as _ from 'lodash';
import * as util from 'util';
import * as path from 'path';

import { ts, SyntaxKind } from 'ts-simple-ast';
import { ts, SyntaxKind } from 'ts-morph';

import { getNamesCompareFn, mergeTagsAndArgs, markedtags } from '../../../../../utils/utils';
import { kindToType } from '../../../../../utils/kind-to-type';
Expand Down
4 changes: 2 additions & 2 deletions src/app/compiler/angular/deps/helpers/component-helper.ts
@@ -1,4 +1,4 @@
import { ts } from 'ts-simple-ast';
import { ts } from 'ts-morph';
import { detectIndent } from '../../../../../utils';
import { ClassHelper } from './class-helper';
import { IParseDeepIdentifierResult, SymbolHelper } from './symbol-helper';
Expand Down Expand Up @@ -177,7 +177,7 @@ export class ComponentHelper {
let exampleUrlsMatches = text.match(/<example-url>(.*?)<\/example-url>/g);
let exampleUrls = undefined;
if (exampleUrlsMatches && exampleUrlsMatches.length) {
exampleUrls = exampleUrlsMatches.map(function(val) {
exampleUrls = exampleUrlsMatches.map(function (val) {
return val.replace(/<\/?example-url>/g, '');
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/compiler/angular/deps/helpers/js-doc-helper.ts
@@ -1,4 +1,4 @@
import { ts } from 'ts-simple-ast';
import { ts } from 'ts-morph';

export class JsDocHelper {
public hasJSDocInternalTag(
Expand Down
2 changes: 1 addition & 1 deletion src/app/compiler/angular/deps/helpers/module-helper.ts
@@ -1,7 +1,7 @@
import { SymbolHelper, IParseDeepIdentifierResult } from './symbol-helper';
import { ComponentCache } from './component-helper';
import { Deps } from '../../dependencies.interfaces';
import { ts } from 'ts-simple-ast';
import { ts } from 'ts-morph';

export class ModuleHelper {
constructor(
Expand Down
@@ -1,5 +1,5 @@
import { SymbolHelper } from './symbol-helper';
import { ts, SyntaxKind } from 'ts-simple-ast';
import { ts, SyntaxKind } from 'ts-morph';
import { expect } from 'chai';

describe(SymbolHelper.name, () => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/compiler/angular/deps/helpers/symbol-helper.ts
@@ -1,6 +1,6 @@
import * as _ from 'lodash';

import { ts, SyntaxKind } from 'ts-simple-ast';
import { ts, SyntaxKind } from 'ts-morph';

import { TsPrinterUtil } from '../../../../../utils/ts-printer.util';

Expand Down
2 changes: 1 addition & 1 deletion src/app/compiler/angular/deps/module-dep.factory.ts
@@ -1,4 +1,4 @@
import { ts } from 'ts-simple-ast';
import { ts } from 'ts-morph';

import { IDep } from '../dependencies.interfaces';
import { ModuleHelper } from './helpers/module-helper';
Expand Down
2 changes: 1 addition & 1 deletion src/app/compiler/framework-dependencies.ts
@@ -1,4 +1,4 @@
import { ts } from 'ts-simple-ast';
import { ts } from 'ts-morph';

import { ClassHelper } from './angular/deps/helpers/class-helper';
import { ComponentHelper } from './angular/deps/helpers/component-helper';
Expand Down
2 changes: 1 addition & 1 deletion src/app/engines/html-engine-helpers/modif-icon.helper.ts
@@ -1,6 +1,6 @@
import { IHtmlEngineHelper } from './html-engine-helper.interface';

import { ts, SyntaxKind } from 'ts-simple-ast';
import { ts, SyntaxKind } from 'ts-morph';

export class ModifIconHelper implements IHtmlEngineHelper {
public helperFunc(context: any, kind: SyntaxKind): string {
Expand Down
2 changes: 1 addition & 1 deletion src/app/engines/html-engine-helpers/modif-kind-helper.ts
@@ -1,7 +1,7 @@
import { IHtmlEngineHelper } from './html-engine-helper.interface';
import * as Handlebars from 'handlebars';

import { ts, SyntaxKind } from 'ts-simple-ast';
import { ts, SyntaxKind } from 'ts-morph';

export class ModifKindHelper implements IHtmlEngineHelper {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/index-cli.ts
@@ -1,7 +1,7 @@
import * as fs from 'fs-extra';
import * as path from 'path';

import { ts } from 'ts-simple-ast';
import { ts } from 'ts-morph';

import { Application } from './app/application';
import Configuration from './app/configuration';
Expand Down
2 changes: 1 addition & 1 deletion src/utils/get-module-with-providers.ts
@@ -1,4 +1,4 @@
import { ts } from 'ts-simple-ast';
import { ts } from 'ts-morph';

export function getModuleWithProviders(node: ts.VariableStatement) {
let result;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/has-spread-element-in-array.ts
@@ -1,4 +1,4 @@
import { SyntaxKind } from 'ts-simple-ast';
import { SyntaxKind } from 'ts-morph';

export function hasSpreadElementInArray(arr): boolean {
let result = false;
Expand Down
18 changes: 9 additions & 9 deletions src/utils/imports.util.ts
@@ -1,8 +1,8 @@
import * as path from 'path';

import Ast, { ts, PropertyDeclaration, SyntaxKind } from 'ts-simple-ast';
import { Project, ts, PropertyDeclaration, SyntaxKind } from 'ts-morph';

const ast = new Ast();
const ast = new Project();

export class ImportsUtil {
private static instance: ImportsUtil;
Expand Down Expand Up @@ -109,7 +109,7 @@ export class ImportsUtil {
const file =
typeof ast.getSourceFile(sourceFile.fileName) !== 'undefined'
? ast.getSourceFile(sourceFile.fileName)
: ast.addExistingSourceFileIfExists(sourceFile.fileName); // tslint:disable-line
: ast.addSourceFileAtPathIfExists(sourceFile.fileName); // tslint:disable-line
const imports = file.getImportDeclarations();

/**
Expand Down Expand Up @@ -166,7 +166,7 @@ export class ImportsUtil {
const sourceFileImport =
typeof ast.getSourceFile(importPath) !== 'undefined'
? ast.getSourceFile(importPath)
: ast.addExistingSourceFileIfExists(importPath); // tslint:disable-line
: ast.addSourceFileAtPathIfExists(importPath); // tslint:disable-line

if (sourceFileImport) {
let variableName = foundWithAlias ? aliasOriginalName : metadataVariableName;
Expand All @@ -193,7 +193,7 @@ export class ImportsUtil {
sourceFileExportedReferencePath
) !== 'undefined'
? ast.getSourceFile(sourceFileExportedReferencePath)
: ast.addExistingSourceFileIfExists(
: ast.addSourceFileAtPathIfExists(
sourceFileExportedReferencePath
);

Expand Down Expand Up @@ -242,7 +242,7 @@ export class ImportsUtil {
const file =
typeof ast.getSourceFile(sourceFile.fileName) !== 'undefined'
? ast.getSourceFile(sourceFile.fileName)
: ast.addExistingSourceFile(sourceFile.fileName); // tslint:disable-line
: ast.addSourceFileAtPath(sourceFile.fileName); // tslint:disable-line
const imports = file.getImportDeclarations();
let searchedImport,
aliasOriginalName = '',
Expand Down Expand Up @@ -300,7 +300,7 @@ export class ImportsUtil {
const file =
typeof ast.getSourceFile(sourceFilePath) !== 'undefined'
? ast.getSourceFile(sourceFilePath)
: ast.addExistingSourceFile(sourceFilePath); // tslint:disable-line
: ast.addSourceFileAtPath(sourceFilePath); // tslint:disable-line
const imports = file.getImportDeclarations();

/**
Expand Down Expand Up @@ -358,7 +358,7 @@ export class ImportsUtil {
const file =
typeof ast.getSourceFile(sourceFile.fileName) !== 'undefined'
? ast.getSourceFile(sourceFile.fileName)
: ast.addExistingSourceFile(sourceFile.fileName); // tslint:disable-line
: ast.addSourceFileAtPath(sourceFile.fileName); // tslint:disable-line
const imports = file.getImportDeclarations();

/**
Expand Down Expand Up @@ -402,7 +402,7 @@ export class ImportsUtil {
const sourceFileImport =
typeof ast.getSourceFile(importPath) !== 'undefined'
? ast.getSourceFile(importPath)
: ast.addExistingSourceFile(importPath); // tslint:disable-line
: ast.addSourceFileAtPath(importPath); // tslint:disable-line
if (sourceFileImport) {
fileToSearchIn = sourceFileImport;
let variableName = foundWithAlias ? aliasOriginalName : metadataVariableName;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/is-module-with-providers.ts
@@ -1,4 +1,4 @@
import { ts } from 'ts-simple-ast';
import { ts } from 'ts-morph';

export function isModuleWithProviders(node: ts.VariableStatement): boolean {
let result = false;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/jsdoc-parser.util.ts
@@ -1,5 +1,5 @@
import * as _ from 'lodash';
import { ts, SyntaxKind } from 'ts-simple-ast';
import { ts, SyntaxKind } from 'ts-morph';

import * as _ts from './ts-internal';

Expand Down
2 changes: 1 addition & 1 deletion src/utils/kind-to-type.ts
@@ -1,4 +1,4 @@
import { SyntaxKind } from 'ts-simple-ast';
import { SyntaxKind } from 'ts-morph';

export function kindToType(kind: number): string {
let _type = '';
Expand Down
2 changes: 1 addition & 1 deletion src/utils/object-literal-expression.util.ts
@@ -1,4 +1,4 @@
import { SyntaxKind } from 'ts-simple-ast';
import { SyntaxKind } from 'ts-morph';

export function StringifyObjectLiteralExpression(ole) {
let returnedString = '{';
Expand Down
6 changes: 3 additions & 3 deletions src/utils/router-parser.util.ts
Expand Up @@ -2,7 +2,7 @@ import * as Handlebars from 'handlebars';
import * as JSON5 from 'json5';
import * as _ from 'lodash';
import * as path from 'path';
import Ast, { ts, SourceFile, SyntaxKind, TypeGuards } from 'ts-simple-ast';
import { Project, ts, SourceFile, SyntaxKind, TypeGuards } from 'ts-morph';

import FileEngine from '../app/engines/file.engine';
import { RoutingGraphNode } from '../app/nodes/routing-graph-node';
Expand All @@ -12,7 +12,7 @@ import { logger } from './logger';

const traverse = require('traverse');

const ast = new Ast();
const ast = new Project();

export class RouterParserUtil {
private routes: any[] = [];
Expand Down Expand Up @@ -591,7 +591,7 @@ export class RouterParserUtil {
const sourceFileImport =
typeof ast.getSourceFile(importPath) !== 'undefined'
? ast.getSourceFile(importPath)
: ast.addExistingSourceFile(importPath);
: ast.addSourceFileAtPath(importPath);
if (sourceFileImport) {
let variableName = foundWithAlias
? aliasOriginalName
Expand Down
2 changes: 1 addition & 1 deletion src/utils/ts-printer.util.ts
@@ -1,4 +1,4 @@
import { ts } from 'ts-simple-ast';
import { ts } from 'ts-morph';

export class TsPrinterUtil {
private printer: ts.Printer;
Expand Down
9 changes: 6 additions & 3 deletions src/utils/utils.ts
@@ -1,7 +1,7 @@
import * as fs from 'fs-extra';
import * as _ from 'lodash';
import * as path from 'path';
import { ts } from 'ts-simple-ast';
import { ts } from 'ts-morph';

import { LinkParser } from './link-parser';

Expand Down Expand Up @@ -177,7 +177,7 @@ export function isIgnore(member): boolean {
// https://tc39.github.io/ecma262/#sec-array.prototype.includes
if (!Array.prototype.includes) {
Object.defineProperty(Array.prototype, 'includes', {
value: function(searchElement, fromIndex) {
value: function (searchElement, fromIndex) {
if (this == null) {
throw new TypeError('"this" is null or not defined');
}
Expand Down Expand Up @@ -319,7 +319,10 @@ export function detectIndent(str, count): string {
}

// TODO: use spread operator when targeting Node.js 6
const indent = Math.min.apply(Math, match.map(x => x.length)); // eslint-disable-line
const indent = Math.min.apply(
Math,
match.map(x => x.length)
); // eslint-disable-line
const re = new RegExp(`^[ \\t]{${indent}}`, 'gm');

return indent > 0 ? stripedString.replace(re, '') : stripedString;
Expand Down

0 comments on commit 7bb9a40

Please sign in to comment.