Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts2famix",
"version": "3.0.0",
"version": "3.1.0",
"description": "A TypeScript to JSON importer for Moose.",
"main": "dist/ts2famix-cli.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/famix_functions/EntityDictionary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class EntityDictionary {

// The +1 is because the source anchor (Pharo) is 1-based, but ts-morph is 0-based
sourceAnchor.startPos = sourceStart + 1;
sourceAnchor.endPos = sourceEnd + 1;
sourceAnchor.endPos = sourceEnd;

let fileName = node.getSourceFile().getFilePath() as string;
if (fileName.startsWith("/")) {
Expand Down Expand Up @@ -196,7 +196,7 @@ export class EntityDictionary {
}
// note: the +1 is because the source anchor is 1-based, but ts-morph is 0-based
fmxIndexFileAnchor.startPos = sourceStart + 1;
fmxIndexFileAnchor.endPos = sourceEnd + 1;
fmxIndexFileAnchor.endPos = sourceEnd;

// if (!(famixElement instanceof Famix.ImportClause || famixElement instanceof Famix.Access || famixElement instanceof Famix.Reference || famixElement instanceof Famix.Invocation || famixElement instanceof Famix.Inheritance) && !(famixElement instanceof Famix.Comment) && !(sourceElement instanceof CommentRange) && !(sourceElement instanceof Identifier) && !(sourceElement instanceof ImportSpecifier) && !(sourceElement instanceof ExpressionWithTypeArguments)) {
// initFQN(sourceElement, famixElement);
Expand Down
2 changes: 2 additions & 0 deletions src/ts2famix-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { config } from "./analyze";
const argv = yargs
.example(`ts2famix -i "path/to/project/**/*.ts" -o JSONModels/projectName.json`, 'Creates a JSON-format Famix model of typescript files.')
.example(`ts2famix -i path/to/tsconfig.json -o JSONModels/projectName.json`, 'Creates a JSON-format model of a typescript project.')
.version()
.alias('v', 'version')
.alias('i', 'input')
.nargs('i', 1)
.alias('o', 'output')
Expand Down
1 change: 0 additions & 1 deletion test/alias.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const arrayOfAliases = Array.from(setOfAliases);
const arrayOfTypes = Array.from(fmxRep._getAllEntitiesWithType("Type") as Set<Type>);
const theFirstAlias = arrayOfAliases[0];
const theFirstType = arrayOfTypes[0];
const theFile = fmxRep._getFamixFile("alias.ts");

describe('Tests for alias', () => {

Expand Down
4 changes: 2 additions & 2 deletions test/functionWithVariables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ describe('Tests for function with variables', () => {
let anchor = secondVariableComments[0]?.sourceAnchor as IndexedFileAnchor;
expect(anchor?.fileName.endsWith("functionWithVariables.ts")).toBe(true);
expect(project.getSourceFileOrThrow(anchor.fileName).getFullText().substring(
anchor.startPos - 1, anchor.endPos - 1)).toBe(`// comment 1`);
anchor.startPos - 1, anchor.endPos)).toBe(`// comment 1`);

anchor = secondVariableComments[1]?.sourceAnchor as IndexedFileAnchor;
expect(anchor?.fileName.endsWith("functionWithVariables.ts")).toBe(true);
expect(project.getSourceFileOrThrow(anchor.fileName).getFullText().substring(
anchor.startPos - 1, anchor.endPos - 1)).toBe(`// comment 3`);
anchor.startPos - 1, anchor.endPos)).toBe(`// comment 3`);

expect(secondVariableComments[0]?.container).toBe(secondVariable);
expect(secondVariableComments[1]?.container).toBe(secondVariable);
Expand Down
24 changes: 12 additions & 12 deletions test/sourceText.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ describe('Tests for source text', () => {
const sourceAnchor = theClass?.sourceAnchor as IndexedFileAnchor;
// note: the +1 is because the source anchor is 1-based, but ts-morph is 0-based
expect(sourceAnchor.startPos).toBe(19 + 1);
expect(sourceAnchor.endPos).toBe(402 + 1);
expect(sourceAnchor.endPos).toBe(402);
expect(sourceAnchor.fileName).toBe("test_src/simple.ts");
expect(project.getSourceFileOrThrow(
sourceAnchor.fileName).getFullText().substring(
sourceAnchor.startPos - 1, sourceAnchor.endPos - 1))
sourceAnchor.startPos - 1, sourceAnchor.endPos))
.toBe(
`export class A {
/**
Expand All @@ -55,11 +55,11 @@ describe('Tests for source text', () => {
const sourceAnchor = theMethod.sourceAnchor as IndexedFileAnchor;
// note: the +1 is because the source anchor is 1-based, but ts-morph is 0-based
expect(sourceAnchor.startPos).toBe(266 + 1);
expect(sourceAnchor.endPos).toBe(400 + 1);
expect(sourceAnchor.endPos).toBe(400);
expect(sourceAnchor.fileName).toBe("test_src/simple.ts");
expect(project.getSourceFileOrThrow(
sourceAnchor.fileName).getFullText().substring(
sourceAnchor.startPos - 1, sourceAnchor.endPos - 1))
sourceAnchor.startPos - 1, sourceAnchor.endPos))
.toBe(`public moveBack(numberOfSpaces: number) {
let currentSquareIndex = this.board.indexOf(this.currentPlayer.currentSquare);
}`
Expand All @@ -73,11 +73,11 @@ describe('Tests for source text', () => {
const sourceAnchor = theVariable.sourceAnchor as IndexedFileAnchor;
// note: the +1 is because the source anchor is 1-based, but ts-morph is 0-based
expect(sourceAnchor.startPos).toBe(4 + 1);
expect(sourceAnchor.endPos).toBe(17 + 1);
expect(sourceAnchor.endPos).toBe(17);
expect(sourceAnchor.fileName).toBe("test_src/simple.ts");
expect(project.getSourceFileOrThrow(
sourceAnchor.fileName).getFullText().substring(
sourceAnchor.startPos - 1, sourceAnchor.endPos - 1))
sourceAnchor.startPos - 1, sourceAnchor.endPos))
.toBe("a: number = 1");
});

Expand All @@ -87,11 +87,11 @@ describe('Tests for source text', () => {
const sourceAnchor = theVariable.sourceAnchor as IndexedFileAnchor;
// note: the +1 is because the source anchor is 1-based, but ts-morph is 0-based
expect(sourceAnchor.startPos).toBe(320 + 1);
expect(sourceAnchor.endPos).toBe(393 + 1);
expect(sourceAnchor.endPos).toBe(393);
expect(sourceAnchor.fileName).toBe("test_src/simple.ts");
expect(project.getSourceFileOrThrow(
sourceAnchor.fileName).getFullText().substring(
sourceAnchor.startPos - 1, sourceAnchor.endPos - 1))
sourceAnchor.startPos - 1, sourceAnchor.endPos))
.toBe("currentSquareIndex = this.board.indexOf(this.currentPlayer.currentSquare)");
});

Expand All @@ -106,21 +106,21 @@ describe('Tests for source text', () => {
expect(testSourceWithGraphemes.length).toBe(7);
// note: the +1 is because the source anchor is 1-based, but ts-morph is 0-based
expect(sourceAnchor.startPos).toBe(4 + 1);
expect(sourceAnchor.endPos).toBe(4 + testSourceWithGraphemes.length + 1);
expect(sourceAnchor.endPos).toBe(4 + testSourceWithGraphemes.length);
expect(sourceAnchor.fileName).toBe("test_src/a-b.ts");
const sourceFileTextWithGraphemes = splitter.splitGraphemes(project.getSourceFileOrThrow(sourceAnchor.fileName).getFullText());
expect(sourceFileTextWithGraphemes.slice(sourceAnchor.startPos - 1, sourceAnchor.endPos - 1)).toEqual(testSourceWithGraphemes);
expect(sourceFileTextWithGraphemes.slice(sourceAnchor.startPos - 1, sourceAnchor.endPos)).toEqual(testSourceWithGraphemes);
});

it("should have variable 'd' with the proper source text", () => {
const theVariable = Array.from(abFile.variables)[1];
const sourceAnchor = theVariable.sourceAnchor as IndexedFileAnchor;
// note: the +1 is because the source anchor is 1-based, but ts-morph is 0-based
expect(sourceAnchor.startPos).toBe(13 + 1);
expect(sourceAnchor.endPos).toBe(18 + 1);
expect(sourceAnchor.endPos).toBe(18);
expect(sourceAnchor.fileName).toBe("test_src/a-b.ts");
const sourceFileTextWithGraphemes = splitter.splitGraphemes(project.getSourceFileOrThrow(sourceAnchor.fileName).getFullText());
const testSourceWithGraphemes = splitter.splitGraphemes('d = 5');
expect(sourceFileTextWithGraphemes.slice(sourceAnchor.startPos - 1, sourceAnchor.endPos - 1)).toEqual(testSourceWithGraphemes); });
expect(sourceFileTextWithGraphemes.slice(sourceAnchor.startPos - 1, sourceAnchor.endPos)).toEqual(testSourceWithGraphemes); });

});
4 changes: 2 additions & 2 deletions test/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ function getIndexedFileAnchorFromComment(comment: Comment) {
}

function getCommentFromAnchor(anchor: IndexedFileAnchor, project: Project) {
return project.getSourceFileOrThrow(anchor.fileName).getFullText().substring(anchor.startPos - 1, anchor.endPos - 1);
return project.getSourceFileOrThrow(anchor.fileName).getFullText().substring(anchor.startPos - 1, anchor.endPos);
}

export function getCommentTextFromCommentViaAnchor(comment: Comment, project: Project) {
return getCommentFromAnchor(getIndexedFileAnchorFromComment(comment), project);
}

export function getTextFromAnchor(anchor: IndexedFileAnchor, project: Project) {
return project.getSourceFileOrThrow(anchor.fileName).getFullText().substring(anchor.startPos - 1, anchor.endPos - 1);
return project.getSourceFileOrThrow(anchor.fileName).getFullText().substring(anchor.startPos - 1, anchor.endPos);
}