Skip to content

Commit

Permalink
Merge pull request #42 from buehler/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
buehler committed Oct 30, 2017
2 parents a5f45be + 3d30f5f commit ec573e6
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 63 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build": "npm run clean && tsc -p ./config/tsconfig.build.json",
"clean": "del-cli ./build ./coverage",
"develop": "npm run clean && tsc -p .",
"lint": "tslint -c tslint.json 'src/**/*.ts'",
"lint": "tslint -c ./tslint.json -p ./config/tsconfig.build.json 'src/**/*.ts'",
"test": "npm run lint && npm run clean && jest -c ./jest.json",
"test:watch": "npm run clean && jest -c ./jest.json --watch --no-coverage",
"typedoc": "del-cli ./docs && typedoc --ignoreCompilerErrors --out ./docs --mode file --tsconfig ./config/tsconfig.build.json ./src/",
Expand Down
26 changes: 14 additions & 12 deletions src/TypescriptParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ export class TypescriptParser {
*/
public async parseSource(source: string, scriptKind: ScriptKind = ScriptKind.TS): Promise<File> {
return await this.parseTypescript(
createSourceFile(
'inline.tsx',
source,
ScriptTarget.ES2015,
true,
scriptKind),
'/');
createSourceFile(
'inline.tsx',
source,
ScriptTarget.ES2015,
true,
scriptKind),
'/');
}

/**
Expand Down Expand Up @@ -109,11 +109,13 @@ export class TypescriptParser {
scriptKind = ScriptKind.TSX;
break;
}
return createSourceFile(o,
readFileSync(o).toString(),
ScriptTarget.ES2015,
true,
scriptKind);
return createSourceFile(
o,
readFileSync(o).toString(),
ScriptTarget.ES2015,
true,
scriptKind,
);
})
.map(o => this.parseTypescript(o, rootPath));
}
Expand Down
7 changes: 3 additions & 4 deletions src/node-parser/identifier-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const usageAllowedIfLast = [
SyntaxKind.Parameter,
SyntaxKind.PropertyDeclaration,
SyntaxKind.VariableDeclaration,
SyntaxKind.ElementAccessExpression,
SyntaxKind.BinaryExpression,
];

Expand All @@ -37,7 +36,7 @@ const usagePredicates: any = [
/**
* Predicate function to determine if the node is possible as a "usage".
* Checks for the node identifier to be the last of the identifier list.
*
*
* @param {Node} node
* @returns {boolean}
*/
Expand All @@ -57,7 +56,7 @@ function allowedIfLastIdentifier(node: Node): boolean {
/**
* Predicate function to determine if the node is possible as a "usage".
* Checks if the identifier is on the lefthand side of a property access.
*
*
* @param {Node} node
* @returns {boolean}
*/
Expand All @@ -76,7 +75,7 @@ function allowedIfPropertyAccessFirst(node: Node): boolean {

/**
* Parses an identifier into a usage of a resource if the predicates are true.
*
*
* @export
* @param {Resource} resource
* @param {Identifier} node
Expand Down
32 changes: 0 additions & 32 deletions src/run.ts

This file was deleted.

31 changes: 26 additions & 5 deletions test/TypescriptParser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,24 @@ describe('TypescriptParser', () => {
expect(usages).toContain('GenericType');
});

it('should parse a default exported element', () => {
const usages = parsed.usages;

expect(usages).toContain('defaultExportUsage');
});

it('should parse an indexer property', () => {
const usages = parsed.usages;

expect(usages).toContain('indexedUsage');
});

it('should parse an indexer property access', () => {
const usages = parsed.usages;

expect(usages).toContain('indexingUsage');
});

});

describe('TSX Usage parsing', () => {
Expand Down Expand Up @@ -754,11 +772,14 @@ describe('TypescriptParser', () => {
describe('Specific sources', () => {

it('should parse generics in functions in classes correctly', async () => {
const parsed = await parser.parseSource(`export class TestClass {
public test() {
let a = <T>() => { let b = null; };
}
}`, ScriptKind.TS);
const parsed = await parser.parseSource(
`export class TestClass {
public test() {
let a = <T>() => { let b = null; };
}
}`,
ScriptKind.TS,
);
expect(parsed).toMatchSnapshot();
});

Expand Down
16 changes: 8 additions & 8 deletions test/__snapshots__/TypescriptParser.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1518,31 +1518,31 @@ File {
"declarations": Array [
ClassDeclaration {
"accessors": Array [],
"end": 144,
"end": 160,
"isExported": true,
"methods": Array [
MethodDeclaration {
"end": 130,
"end": 142,
"isAbstract": false,
"name": "test",
"parameters": Array [],
"start": 41,
"start": 45,
"type": undefined,
"variables": Array [
VariableDeclaration {
"end": 112,
"end": 120,
"isConst": false,
"isExported": false,
"name": "a",
"start": 77,
"start": 85,
"type": undefined,
},
VariableDeclaration {
"end": 109,
"end": 117,
"isConst": false,
"isExported": false,
"name": "b",
"start": 96,
"start": 104,
"type": undefined,
},
],
Expand All @@ -1554,7 +1554,7 @@ File {
"start": 0,
},
],
"end": 144,
"end": 160,
"exports": Array [],
"filePath": "inline.tsx",
"imports": Array [],
Expand Down
6 changes: 5 additions & 1 deletion test/_workspace/typescript-parser/usagesOnly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Class {
public assignedProperty = AssignedProperty;

@FunctionDecorator()
public func(@ParamDecorator() param: TypedParam, defaultParam = DefaultParam) {
public func( @ParamDecorator() param: TypedParam, defaultParam = DefaultParam) {
}

private prv(param): ReturnValue {
Expand Down Expand Up @@ -39,3 +39,7 @@ class Class extends DefaultClass {
class Class extends GenericClass<GenericType> {

}

indexedUsage[indexingUsage];

export default defaultExportUsage;
2 changes: 2 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
]
}
],
"no-boolean-literal-compare": false,
"strict-boolean-expressions": false,
"ter-indent": [
true,
4,
Expand Down

0 comments on commit ec573e6

Please sign in to comment.