Sign In

@zeronejs/ast

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zeronejs/ast - npm Package Compare versions

Comparing version
1.0.0-beta.2
to
1.0.0-beta.3
+2
src/ts/common/type.interpret.d.ts
import * as ts from 'typescript';
export declare function getTypeReferences(type: ts.TypeNode, arr?: Set<string>): string[];
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTypeReferences = void 0;
const ts = __importStar(require("typescript"));
function getTypeReferences(type, arr = new Set()) {
if (ts.isTypeReferenceNode(type)) {
let typeName = '';
if (ts.isIdentifier(type.typeName)) {
typeName = ts.unescapeLeadingUnderscores(type.typeName.escapedText);
}
arr.add(typeName);
}
else if (ts.isUnionTypeNode(type) || ts.isIntersectionTypeNode(type)) {
for (const itemType of type.types) {
getTypeReferences(itemType, arr);
}
}
else if (ts.isArrayTypeNode(type)) {
getTypeReferences(type.elementType, arr);
}
else if (ts.isTypeLiteralNode(type)) {
for (const item of type.members) {
if (ts.isPropertySignature(item) && item.type) {
getTypeReferences(item.type, arr);
}
}
}
else if (ts.isTupleTypeNode(type)) {
for (const itemType of type.elements) {
getTypeReferences(itemType, arr);
}
}
else {
// Common types do not need to be processed
}
return [...arr];
}
exports.getTypeReferences = getTypeReferences;
import { InterpretCore } from './interpret.core';
export interface SourceFileInterfaces {
name: string;
}
export declare class InterfaceInterpret {
private readonly interpretCore;
constructor(interpretCore: InterpretCore);
interpret(): SourceFileInterfaces[];
}
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.InterfaceInterpret = void 0;
const ts = __importStar(require("typescript"));
const interpret_core_1 = require("./interpret.core");
class InterfaceInterpret {
constructor(interpretCore) {
this.interpretCore = interpretCore;
}
interpret() {
const interfaceDeclarations = this.interpretCore.getDeclarationsItem(interpret_core_1.DeclarationType.interfaceDeclarations);
return interfaceDeclarations.map((interfaceDeclaration) => {
const item = {
name: ts.unescapeLeadingUnderscores(interfaceDeclaration.name.escapedText),
};
return item;
});
}
}
exports.InterfaceInterpret = InterfaceInterpret;
import { InterpretCore } from './interpret.core';
export interface SourceFileTypeAlias {
name: string;
}
export declare class TypeAliasInterpret {
private readonly interpretCore;
constructor(interpretCore: InterpretCore);
interpret(): SourceFileTypeAlias[];
}
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TypeAliasInterpret = void 0;
const ts = __importStar(require("typescript"));
const interpret_core_1 = require("./interpret.core");
class TypeAliasInterpret {
constructor(interpretCore) {
this.interpretCore = interpretCore;
}
interpret() {
const typeAliasDeclarations = this.interpretCore.getDeclarationsItem(interpret_core_1.DeclarationType.typeAliasDeclarations);
return typeAliasDeclarations.map((typeAliasDeclaration) => {
const typeAliasItem = {
name: ts.unescapeLeadingUnderscores(typeAliasDeclaration.name.escapedText),
};
return typeAliasItem;
});
}
}
exports.TypeAliasInterpret = TypeAliasInterpret;
+3
-0

@@ -13,2 +13,5 @@ "use strict";

exports.UserEntity = exports.Gender = void 0;
test('this test will not run', () => {
expect('A').toBe('A');
});
const typeorm_1 = require("typeorm");

@@ -15,0 +18,0 @@ const tes2 = {

+20
-9
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -9,10 +18,12 @@ const interpret_core_1 = require("../../src/ts/interpret.core");

const variables_interpret_1 = require("../../src/ts/variables.interpret");
const handle = () => {
const interpretCore = new interpret_core_1.InterpretCore((0, path_1.join)(__dirname, 'test.entity.ts'));
const classes = new classes_interpret_1.ClassesInterpret(interpretCore).interpret();
const inports = new imports_interpret_1.ImportsInterpret(interpretCore).interpret();
const variables = new variables_interpret_1.VariablesInterpret(interpretCore).interpret();
const enums = new enums_interpret_1.EnumsInterpret(interpretCore).interpret();
debugger;
};
handle();
const test_entity_1 = require("./test.entity");
describe('@zeronejs/ast => ts InterpretCore', () => {
it('entity 文件读取', () => __awaiter(void 0, void 0, void 0, function* () {
const interpretCore = new interpret_core_1.InterpretCore((0, path_1.join)(__dirname, 'test.entity.ts'));
const classes = new classes_interpret_1.ClassesInterpret(interpretCore).interpret();
const inports = new imports_interpret_1.ImportsInterpret(interpretCore).interpret();
const variables = new variables_interpret_1.VariablesInterpret(interpretCore).interpret();
const enums = new enums_interpret_1.EnumsInterpret(interpretCore).interpret();
expect(classes[0].name).toBe(test_entity_1.UserEntity.name);
}));
});
{
"name": "@zeronejs/ast",
"version": "1.0.0-beta.2",
"version": "1.0.0-beta.3",
"description": "Zerone Abstract Syntax Tree",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -7,2 +7,3 @@ import { DecoratorDoc } from './common/decorator.interpret';

documentation: string;
properties: ClassPropertyDeclarationDoc[];
}

@@ -16,2 +17,3 @@ export interface ClassPropertyDeclarationDoc {

value: string;
typeReferences: string[];
};

@@ -18,0 +20,0 @@ }

@@ -25,2 +25,3 @@ "use strict";

const decorator_interpret_1 = require("./common/decorator.interpret");
const type_interpret_1 = require("./common/type.interpret");
const interpret_core_1 = require("./interpret.core");

@@ -40,2 +41,3 @@ class ClassesInterpret {

documentation: '',
properties: [],
};

@@ -50,3 +52,2 @@ if (classDeclaration.name) {

// const properties = classDeclaration.members.filter((it) => ts.isPropertyDeclaration(it));
const properties = [];
classDeclaration.members.map((member) => {

@@ -63,8 +64,12 @@ var _a, _b;

value: (_b = (_a = member.type) === null || _a === void 0 ? void 0 : _a.getText(this.interpretCore.sourceFile)) !== null && _b !== void 0 ? _b : 'any',
typeReferences: [],
},
};
if (member.type) {
property.type.typeReferences = (0, type_interpret_1.getTypeReferences)(member.type);
}
if (symbol) {
property.documentation = ts.displayPartsToString(symbol.getDocumentationComment(checker));
}
properties.push(property);
fileClasses.properties.push(property);
}

@@ -71,0 +76,0 @@ });

@@ -28,3 +28,3 @@ "use strict";

if (ts.isObjectLiteralExpression(element)) {
const newObj = { name: '', value: null };
const newObj = {};
(0, object_interpret_1.generateObjectDoc)(sourceFile, element, newObj);

@@ -31,0 +31,0 @@ return newObj;

@@ -42,3 +42,3 @@ "use strict";

if (ts.isObjectLiteralExpression(arg)) {
const newObj = { name: '', value: null };
const newObj = {};
(0, object_interpret_1.generateObjectDoc)(sourceFile, arg, newObj);

@@ -45,0 +45,0 @@ return newObj;

export * from './array.interpret';
export * from './decorator.interpret';
export * from './object.interpret';
export * from './type.interpret';

@@ -16,1 +16,2 @@ "use strict";

__exportStar(require("./object.interpret"), exports);
__exportStar(require("./type.interpret"), exports);
import * as ts from 'typescript';
export interface ObjectLiteralExpressionDoc {
name: string;
value: any;
}
export declare function generateObjectDoc(sourceFile: ts.SourceFile, object: ts.ObjectLiteralExpression, obj: ObjectLiteralExpressionDoc): void;
export declare function generateObjectDoc(sourceFile: ts.SourceFile, object: ts.ObjectLiteralExpression, obj: any): void;

@@ -28,13 +28,15 @@ "use strict";

if (ts.isPropertyAssignment(propertie)) {
let key = '';
if (ts.isIdentifier(propertie.name)) {
obj.name = ts.unescapeLeadingUnderscores(propertie.name.escapedText);
key = ts.unescapeLeadingUnderscores(propertie.name.escapedText);
}
else {
obj.name = propertie.name.getText(sourceFile);
key = propertie.name.getText(sourceFile);
}
if (ts.isObjectLiteralExpression(propertie.initializer)) {
generateObjectDoc(sourceFile, propertie.initializer, obj.value);
obj[key] = {};
generateObjectDoc(sourceFile, propertie.initializer, obj[key]);
}
else if (ts.isArrayLiteralExpression(propertie.initializer)) {
obj.value = (0, array_interpret_1.generateArrayDoc)(sourceFile, propertie.initializer);
obj[key] = (0, array_interpret_1.generateArrayDoc)(sourceFile, propertie.initializer);
}

@@ -45,3 +47,3 @@ // else if (ts.isStringLiteral(propertie.initializer)) {

else {
obj.value = propertie.initializer.getText(sourceFile);
obj[key] = propertie.initializer.getText(sourceFile);
}

@@ -48,0 +50,0 @@ }

@@ -42,3 +42,3 @@ "use strict";

if (ts.isObjectLiteralExpression(member.initializer)) {
const newObj = { name: '', value: null };
const newObj = {};
(0, object_interpret_1.generateObjectDoc)(this.interpretCore.sourceFile, member.initializer, newObj);

@@ -45,0 +45,0 @@ enumMember.value = newObj;

@@ -6,1 +6,4 @@ export * from './classes.interpret';

export * from './interpret.core';
export * from './typeAlias.interpret';
export * from './interface.interpret';
export * from './common';

@@ -19,1 +19,4 @@ "use strict";

__exportStar(require("./interpret.core"), exports);
__exportStar(require("./typeAlias.interpret"), exports);
__exportStar(require("./interface.interpret"), exports);
__exportStar(require("./common"), exports);

@@ -7,2 +7,4 @@ import * as ts from 'typescript';

getDeclarationsItem(declarationType: DeclarationType.importDeclaration): ts.ImportDeclaration[];
getDeclarationsItem(declarationType: DeclarationType.interfaceDeclarations): ts.InterfaceDeclaration[];
getDeclarationsItem(declarationType: DeclarationType.typeAliasDeclarations): ts.TypeAliasDeclaration[];
getDeclarationsItem(declarationType: DeclarationType.enumDeclarations): ts.EnumDeclaration[];

@@ -17,3 +19,5 @@ getDeclarationsItem(declarationType: DeclarationType.variableStatements): ts.VariableStatement[];

enumDeclarations = 2,
classDeclarations = 3
classDeclarations = 3,
interfaceDeclarations = 4,
typeAliasDeclarations = 5
}

@@ -67,2 +67,14 @@ "use strict";

break;
// interface
case DeclarationType.interfaceDeclarations:
if (ts.isInterfaceDeclaration(statement)) {
return statement;
}
break;
// interface
case DeclarationType.typeAliasDeclarations:
if (ts.isTypeAliasDeclaration(statement)) {
return statement;
}
break;
// 类

@@ -95,2 +107,4 @@ case DeclarationType.classDeclarations:

DeclarationType[DeclarationType["classDeclarations"] = 3] = "classDeclarations";
DeclarationType[DeclarationType["interfaceDeclarations"] = 4] = "interfaceDeclarations";
DeclarationType[DeclarationType["typeAliasDeclarations"] = 5] = "typeAliasDeclarations";
})(DeclarationType = exports.DeclarationType || (exports.DeclarationType = {}));

@@ -47,3 +47,3 @@ "use strict";

if (ts.isObjectLiteralExpression(declaration.initializer)) {
const newObj = { name: '', value: null };
const newObj = {};
(0, object_interpret_1.generateObjectDoc)(this.interpretCore.sourceFile, declaration.initializer, newObj);

@@ -50,0 +50,0 @@ variable.value = newObj;