@jqassistant/ts-lce
Version:
Tool to extract language concepts from a TypeScript codebase and export them to a JSON file.
222 lines (221 loc) • 6.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.valueConceptIds = exports.LCEValueComplex = exports.LCEValueClass = exports.LCEValueFunction = exports.LCEValueCall = exports.LCEValueArray = exports.LCEValueObjectProperty = exports.LCEValueObject = exports.LCEValueMember = exports.LCEValueDeclared = exports.LCEValueLiteral = exports.LCEValueNull = exports.LCEValue = void 0;
const concept_1 = require("../concept");
const type_concept_1 = require("./type.concept");
const context_1 = require("../context");
/** Base class for all values. */
class LCEValue extends concept_1.LCEConcept {
valueType;
type;
static conceptId = "value";
/**
* @param type type of the value
*/
constructor(valueType, type) {
super();
this.valueType = valueType;
this.type = type;
}
}
exports.LCEValue = LCEValue;
/**
* Represents a null value (`undefined` or `null`)
*/
class LCEValueNull extends LCEValue {
kind;
static conceptId = "null-value";
static valueTypeId = "null";
/**
* @param kind indicates whether value is `undefined` or `null`
*/
constructor(kind) {
super(LCEValueNull.valueTypeId, new type_concept_1.LCETypePrimitive(kind));
this.kind = kind;
}
}
exports.LCEValueNull = LCEValueNull;
/**
* Represents a literal value (e.g. `42`, `true` or `"str"`)
*/
class LCEValueLiteral extends LCEValue {
value;
static conceptId = "literal-value";
static valueTypeId = "literal";
/**
* @param value the value of the literal
*/
constructor(value) {
super(LCEValueLiteral.valueTypeId, typeof value === "object" ? new type_concept_1.LCETypeDeclared(new context_1.FQN("RegExp"), []) : new type_concept_1.LCETypePrimitive(typeof value));
this.value = value;
}
}
exports.LCEValueLiteral = LCEValueLiteral;
/**
* Represents a declared variable/function/class used as a value (e.g. `myVariable` or `myFunction`)
*/
class LCEValueDeclared extends LCEValue {
fqn;
static conceptId = "declared-value";
static valueTypeId = "declared";
/**
* @param fqn fully qualified name of the referenced variable/function/class (only global Fqn is used)
*/
constructor(type, fqn) {
super(LCEValueDeclared.valueTypeId, type);
this.fqn = fqn;
}
}
exports.LCEValueDeclared = LCEValueDeclared;
/**
* Represents a member expression (e.g. `myObj.x`)
*/
class LCEValueMember extends LCEValue {
parent;
member;
static conceptId = "member-value";
static valueTypeId = "member";
/**
* @param parent parent value of which a member is accessed
* @param member member value which is accessed
*/
constructor(type, parent, member) {
super(LCEValueMember.valueTypeId, type);
this.parent = parent;
this.member = member;
}
}
exports.LCEValueMember = LCEValueMember;
/**
* Represents a object expression (e.g. `{a: 3, b: "str"}`)
*/
class LCEValueObject extends LCEValue {
members;
static conceptId = "object-value";
static valueTypeId = "object";
/**
* @param members map of the object member's names to their respective values
*/
constructor(type, members) {
super(LCEValueObject.valueTypeId, type);
this.members = members;
}
}
exports.LCEValueObject = LCEValueObject;
/**
* Represents a single property of an object expression (e.g. `a: 3` in `{a: 3, b: "str"}`)
* Only used as an intermediate concept within the traversal process
*/
class LCEValueObjectProperty extends LCEValue {
name;
value;
static conceptId = "object-value-property";
static valueTypeId = "object-property";
/**
* @param name name of the property
* @param value value of the property
*/
constructor(name, value) {
super(LCEValueObjectProperty.valueTypeId, value.type);
this.name = name;
this.value = value;
}
}
exports.LCEValueObjectProperty = LCEValueObjectProperty;
/**
* Represents a array expression (e.g. `[1, 2, 3]`)
*/
class LCEValueArray extends LCEValue {
items;
static conceptId = "array-value";
static valueTypeId = "array";
/**
* @param items item values of the array
*/
constructor(type, items) {
super(LCEValueArray.valueTypeId, type);
this.items = items;
}
}
exports.LCEValueArray = LCEValueArray;
/**
* Represents a call expression (e.g. `myArr.concat([4, 5])`)
*/
class LCEValueCall extends LCEValue {
callee;
args;
typeArgs;
static conceptId = "call-value";
static valueTypeId = "call";
/**
* @param type return type of the call
* @param callee value that is called (e.g. `myArr.concat`)
* @param args values of the arguments
* @param typeArgs type arguments specified for call
*/
constructor(type, callee, args, typeArgs) {
super(LCEValueCall.valueTypeId, type);
this.callee = callee;
this.args = args;
this.typeArgs = typeArgs;
}
}
exports.LCEValueCall = LCEValueCall;
/**
* Represents a function expression (e.g. `function(x: string) { return x.trim(); }`)
*/
class LCEValueFunction extends LCEValue {
arrowFunction;
static conceptId = "function-value";
static valueTypeId = "function";
/**
* @param type return type of the function
* @param arrowFunction indicates whether the function is an arrow function
*/
constructor(type, arrowFunction) {
super(LCEValueFunction.valueTypeId, type);
this.arrowFunction = arrowFunction;
}
}
exports.LCEValueFunction = LCEValueFunction;
/**
* Represents a class expression (e.g. `class A {}`)
*/
class LCEValueClass extends LCEValue {
static conceptId = "class-value";
static valueTypeId = "class";
constructor() {
super(LCEValueClass.valueTypeId, type_concept_1.LCETypeNotIdentified.CLASS_EXPRESSION);
}
}
exports.LCEValueClass = LCEValueClass;
/**
* Represents an expression that could not be resolved with other value types
*/
class LCEValueComplex extends LCEValue {
expression;
static conceptId = "complex-value";
static valueTypeId = "complex";
/**
* @param expression string representation of the value's expression
*/
constructor(expression) {
super(LCEValueComplex.valueTypeId, type_concept_1.LCETypeNotIdentified.COMPLEX_VALUE);
this.expression = expression;
}
}
exports.LCEValueComplex = LCEValueComplex;
exports.valueConceptIds = [
LCEValue.conceptId,
LCEValueNull.conceptId,
LCEValueLiteral.conceptId,
LCEValueDeclared.conceptId,
LCEValueMember.conceptId,
LCEValueObject.conceptId,
LCEValueObjectProperty.conceptId,
LCEValueArray.conceptId,
LCEValueCall.conceptId,
LCEValueFunction.conceptId,
LCEValueClass.conceptId,
LCEValueComplex.conceptId,
];