Skip to content

Commit cd79ddc

Browse files
committed
Renamed project to 'CodeAnalyzer'
1 parent 5d9d38c commit cd79ddc

File tree

68 files changed

+128
-91
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+128
-91
lines changed

README.md

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,46 @@
1-
# SimpleLanguageService [![NPM version][npm-image]][npm-url]
2-
> A service that parses and reflects on the AST generated by Typescript's language service.
3-
> With it, we can extract metadata such as initialization values and types, arguments and import declarations.
1+
# CodeAnalyzer [![NPM version][npm-image]][npm-url]
2+
> A service that can analyze your code in great detail ahead of time.
43
54
## Installation
6-
Simply do: `npm install simplelanguageservice`.
5+
Simply do: `npm install @wessberg/codeanalyzer`.
6+
7+
## Description
8+
The service is a very flexible and powerful tool for extracting metadata and state snapshots of your code and the identifiers that lives within it.
9+
10+
It builds upon the Typescript AST and understands the entirety of the Typescript syntax.
11+
12+
Here's *some* of what SimpleLanguageService does:
13+
14+
- It computes the initialization values of variables and return values of function calls - ahead of time.
15+
- It tracks the types of class fields, function/method/constructor parameters, generic call- or new expression arguments and similar.
16+
- It breaks code up into expressions that can be resolved at any time.
17+
18+
For example,
19+
consider the following code:
20+
```typescript
21+
const service = new CodeAnalyzer();
22+
const fileName = "a_file.ts";
23+
service.addFile(fileName, `
24+
function foo () {
25+
let arr = [];
26+
for (let i = 1; i <= 5; i++) {
27+
arr.push(i);
28+
}
29+
return arr;
30+
}
31+
const aVariable: number[] = foo();
32+
`);
33+
34+
const variables = service.getVariableAssignmentsForFile(fileName);
35+
const variable = variables["aVariable"];
36+
console.log(variable.value.resolve()); // [1,2,3,4,5]
37+
console.log(variable.name); // aVariable
38+
console.log(variable.type.flattened); // number[]
39+
```
40+
41+
This is useful if you want to reduce complexity by replacing heavy function calls with values.
42+
43+
But more than that, it can
744

845
## Usage
946
```typescript
@@ -72,5 +109,5 @@ The LanguageService will not track any mutations for already-initialized variabl
72109

73110
- First release.
74111

75-
[npm-url]: https://npmjs.org/package/@wessberg/simplelanguageservice
76-
[npm-image]: https://badge.fury.io/js/@wessberg/simplelanguageservice.svg
112+
[npm-url]: https://npmjs.org/package/@wessberg/codeanalyzer
113+
[npm-image]: https://badge.fury.io/js/@wessberg/codeanalyzer.svg

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"name": "@wessberg/simplelanguageservice",
2+
"name": "@wessberg/codeanalyzer",
33
"version": "1.0.9",
44
"description": "A service that parses and reflects on the AST generated by Typescript's language service. With it, we can extract metadata such as initialization values and types, arguments and import declarations.",
55
"main": "./dist/cjs/index.js",
6-
"repository": "https://github.com/wessberg/simplelanguageservice",
6+
"repository": "https://github.com/wessberg/codeanalyzer",
77
"module": "./dist/es2015/index.js",
88
"browser": "./dist/es2015/index.js",
99
"types": "./dist/es2015/index.d.ts",

src/cache/Cache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import {ClassIndexer, EnumIndexer, FunctionIndexer, ICachedContent, IClassDeclaration, IEnumDeclaration, IFunctionDeclaration, IImportDeclaration, IPropDeclaration, ISimpleLanguageService, IVariableAssignment, VariableIndexer} from "../service/interface/ISimpleLanguageService";
1+
import {ClassIndexer, EnumIndexer, FunctionIndexer, ICachedContent, IClassDeclaration, IEnumDeclaration, IFunctionDeclaration, IImportDeclaration, IPropDeclaration, ICodeAnalyzer, IVariableAssignment, VariableIndexer} from "../service/interface/ICodeAnalyzer";
22
import {ICache} from "./interface/ICache";
33

44
export class Cache implements ICache {
55
private cache: Map<string, ICachedContent<{}>> = new Map();
66

7-
constructor (private languageService: ISimpleLanguageService) {}
7+
constructor (private languageService: ICodeAnalyzer) {}
88

99
public getCachedPropName (fileName: string, className: string, propName: string): string {
1010
return `prop.${fileName}.${className}.${propName}`;

src/cache/interface/ICache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ClassIndexer, EnumIndexer, FunctionIndexer, ICachedContent, IClassDeclaration, IEnumDeclaration, IFunctionDeclaration, IImportDeclaration, IPropDeclaration, IVariableAssignment, VariableIndexer} from "../../service/interface/ISimpleLanguageService";
1+
import {ClassIndexer, EnumIndexer, FunctionIndexer, ICachedContent, IClassDeclaration, IEnumDeclaration, IFunctionDeclaration, IImportDeclaration, IPropDeclaration, IVariableAssignment, VariableIndexer} from "../../service/interface/ICodeAnalyzer";
22

33
export interface ICache {
44
getCachedPropName (fileName: string, className: string, propName: string): string;

src/formatter/ArgumentsFormatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {CallExpression, Expression, NewExpression} from "typescript";
22
import {IValueExpressionGetter} from "../getter/interface/IValueExpressionGetter";
33
import {IValueResolvedGetter} from "../getter/interface/IValueResolvedGetter";
44
import {IMapper} from "../mapper/interface/IMapper";
5-
import {IArgument, IdentifierMapKind, INonNullableValueable} from "../service/interface/ISimpleLanguageService";
5+
import {IArgument, IdentifierMapKind, INonNullableValueable} from "../service/interface/ICodeAnalyzer";
66
import {ITracer} from "../tracer/interface/ITracer";
77
import {IArgumentsFormatter} from "./interface/IArgumentsFormatter";
88

src/formatter/CallExpressionFormatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {IValueExpressionGetter} from "../getter/interface/IValueExpressionGetter
66
import {IValueResolvedGetter} from "../getter/interface/IValueResolvedGetter";
77
import {IMapper} from "../mapper/interface/IMapper";
88
import {ITokenSerializer} from "../serializer/interface/ITokenSerializer";
9-
import {ICallExpression, IdentifierMapKind} from "../service/interface/ISimpleLanguageService";
9+
import {ICallExpression, IdentifierMapKind} from "../service/interface/ICodeAnalyzer";
1010
import {ITracer} from "../tracer/interface/ITracer";
1111
import {ITypeUtil} from "../util/interface/ITypeUtil";
1212
import {CallableFormatter} from "./CallableFormatter";

src/formatter/CallableFormatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {IValueExpressionGetter} from "../getter/interface/IValueExpressionGetter
55
import {IValueResolvedGetter} from "../getter/interface/IValueResolvedGetter";
66
import {isIdentifierObject, isLiteralExpression, isPropertyAccessExpression} from "../predicate/PredicateFunctions";
77
import {ITokenSerializer} from "../serializer/interface/ITokenSerializer";
8-
import {ArbitraryValue, ICallable, INonNullableValueable, ITypeable, IValueable, TypeExpression} from "../service/interface/ISimpleLanguageService";
8+
import {ArbitraryValue, ICallable, INonNullableValueable, ITypeable, IValueable, TypeExpression} from "../service/interface/ICodeAnalyzer";
99
import {ITracer} from "../tracer/interface/ITracer";
1010
import {ITypeUtil} from "../util/interface/ITypeUtil";
1111
import {ICallableFormatter} from "./interface/ICallableFormatter";

src/formatter/ClassFormatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {ICache} from "../cache/interface/ICache";
33
import {ISourceFilePropertiesGetter} from "../getter/interface/ISourceFilePropertiesGetter";
44
import {IMapper} from "../mapper/interface/IMapper";
55
import {isConstructorDeclaration, isMethodDeclaration, isPropertyDeclaration} from "../predicate/PredicateFunctions";
6-
import {IClassDeclaration, IdentifierMapKind} from "../service/interface/ISimpleLanguageService";
6+
import {IClassDeclaration, IdentifierMapKind} from "../service/interface/ICodeAnalyzer";
77
import {Config} from "../static/Config";
88
import {IClassFormatter} from "./interface/IClassFormatter";
99
import {IConstructorFormatter} from "./interface/IConstructorFormatter";

src/formatter/ConstructorFormatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {IModifiersFormatter} from "src/formatter/interface/IModifiersFormatter";
22
import {ConstructorDeclaration} from "typescript";
33
import {ISourceFilePropertiesGetter} from "../getter/interface/ISourceFilePropertiesGetter";
44
import {IMapper} from "../mapper/interface/IMapper";
5-
import {IConstructorDeclaration, IdentifierMapKind} from "../service/interface/ISimpleLanguageService";
5+
import {IConstructorDeclaration, IdentifierMapKind} from "../service/interface/ICodeAnalyzer";
66
import {FunctionLikeFormatter} from "./FunctionLikeFormatter";
77
import {IConstructorFormatter} from "./interface/IConstructorFormatter";
88
import {IDecoratorsFormatter} from "./interface/IDecoratorsFormatter";

src/formatter/DecoratorsFormatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {ClassDeclaration, ConstructorDeclaration, EnumDeclaration, FunctionDeclaration, MethodDeclaration, PropertyDeclaration} from "typescript";
22
import {INameGetter} from "../getter/interface/INameGetter";
33
import {IMapper} from "../mapper/interface/IMapper";
4-
import {DecoratorIndexer, IDecorator, IdentifierMapKind} from "../service/interface/ISimpleLanguageService";
4+
import {DecoratorIndexer, IDecorator, IdentifierMapKind} from "../service/interface/ICodeAnalyzer";
55
import {IDecoratorsFormatter} from "./interface/IDecoratorsFormatter";
66

77
export class DecoratorsFormatter implements IDecoratorsFormatter {

0 commit comments

Comments
 (0)