Skip to content

Commit ec573e6

Browse files
authored
Merge pull request #42 from buehler/develop
Release
2 parents a5f45be + 3d30f5f commit ec573e6

File tree

8 files changed

+59
-63
lines changed

8 files changed

+59
-63
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"build": "npm run clean && tsc -p ./config/tsconfig.build.json",
99
"clean": "del-cli ./build ./coverage",
1010
"develop": "npm run clean && tsc -p .",
11-
"lint": "tslint -c tslint.json 'src/**/*.ts'",
11+
"lint": "tslint -c ./tslint.json -p ./config/tsconfig.build.json 'src/**/*.ts'",
1212
"test": "npm run lint && npm run clean && jest -c ./jest.json",
1313
"test:watch": "npm run clean && jest -c ./jest.json --watch --no-coverage",
1414
"typedoc": "del-cli ./docs && typedoc --ignoreCompilerErrors --out ./docs --mode file --tsconfig ./config/tsconfig.build.json ./src/",

src/TypescriptParser.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ export class TypescriptParser {
5656
*/
5757
public async parseSource(source: string, scriptKind: ScriptKind = ScriptKind.TS): Promise<File> {
5858
return await this.parseTypescript(
59-
createSourceFile(
60-
'inline.tsx',
61-
source,
62-
ScriptTarget.ES2015,
63-
true,
64-
scriptKind),
65-
'/');
59+
createSourceFile(
60+
'inline.tsx',
61+
source,
62+
ScriptTarget.ES2015,
63+
true,
64+
scriptKind),
65+
'/');
6666
}
6767

6868
/**
@@ -109,11 +109,13 @@ export class TypescriptParser {
109109
scriptKind = ScriptKind.TSX;
110110
break;
111111
}
112-
return createSourceFile(o,
113-
readFileSync(o).toString(),
114-
ScriptTarget.ES2015,
115-
true,
116-
scriptKind);
112+
return createSourceFile(
113+
o,
114+
readFileSync(o).toString(),
115+
ScriptTarget.ES2015,
116+
true,
117+
scriptKind,
118+
);
117119
})
118120
.map(o => this.parseTypescript(o, rootPath));
119121
}

src/node-parser/identifier-parser.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const usageAllowedIfLast = [
2424
SyntaxKind.Parameter,
2525
SyntaxKind.PropertyDeclaration,
2626
SyntaxKind.VariableDeclaration,
27-
SyntaxKind.ElementAccessExpression,
2827
SyntaxKind.BinaryExpression,
2928
];
3029

@@ -37,7 +36,7 @@ const usagePredicates: any = [
3736
/**
3837
* Predicate function to determine if the node is possible as a "usage".
3938
* Checks for the node identifier to be the last of the identifier list.
40-
*
39+
*
4140
* @param {Node} node
4241
* @returns {boolean}
4342
*/
@@ -57,7 +56,7 @@ function allowedIfLastIdentifier(node: Node): boolean {
5756
/**
5857
* Predicate function to determine if the node is possible as a "usage".
5958
* Checks if the identifier is on the lefthand side of a property access.
60-
*
59+
*
6160
* @param {Node} node
6261
* @returns {boolean}
6362
*/
@@ -76,7 +75,7 @@ function allowedIfPropertyAccessFirst(node: Node): boolean {
7675

7776
/**
7877
* Parses an identifier into a usage of a resource if the predicates are true.
79-
*
78+
*
8079
* @export
8180
* @param {Resource} resource
8281
* @param {Identifier} node

src/run.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

test/TypescriptParser.spec.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,24 @@ describe('TypescriptParser', () => {
573573
expect(usages).toContain('GenericType');
574574
});
575575

576+
it('should parse a default exported element', () => {
577+
const usages = parsed.usages;
578+
579+
expect(usages).toContain('defaultExportUsage');
580+
});
581+
582+
it('should parse an indexer property', () => {
583+
const usages = parsed.usages;
584+
585+
expect(usages).toContain('indexedUsage');
586+
});
587+
588+
it('should parse an indexer property access', () => {
589+
const usages = parsed.usages;
590+
591+
expect(usages).toContain('indexingUsage');
592+
});
593+
576594
});
577595

578596
describe('TSX Usage parsing', () => {
@@ -754,11 +772,14 @@ describe('TypescriptParser', () => {
754772
describe('Specific sources', () => {
755773

756774
it('should parse generics in functions in classes correctly', async () => {
757-
const parsed = await parser.parseSource(`export class TestClass {
758-
public test() {
759-
let a = <T>() => { let b = null; };
760-
}
761-
}`, ScriptKind.TS);
775+
const parsed = await parser.parseSource(
776+
`export class TestClass {
777+
public test() {
778+
let a = <T>() => { let b = null; };
779+
}
780+
}`,
781+
ScriptKind.TS,
782+
);
762783
expect(parsed).toMatchSnapshot();
763784
});
764785

test/__snapshots__/TypescriptParser.spec.ts.snap

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,31 +1518,31 @@ File {
15181518
"declarations": Array [
15191519
ClassDeclaration {
15201520
"accessors": Array [],
1521-
"end": 144,
1521+
"end": 160,
15221522
"isExported": true,
15231523
"methods": Array [
15241524
MethodDeclaration {
1525-
"end": 130,
1525+
"end": 142,
15261526
"isAbstract": false,
15271527
"name": "test",
15281528
"parameters": Array [],
1529-
"start": 41,
1529+
"start": 45,
15301530
"type": undefined,
15311531
"variables": Array [
15321532
VariableDeclaration {
1533-
"end": 112,
1533+
"end": 120,
15341534
"isConst": false,
15351535
"isExported": false,
15361536
"name": "a",
1537-
"start": 77,
1537+
"start": 85,
15381538
"type": undefined,
15391539
},
15401540
VariableDeclaration {
1541-
"end": 109,
1541+
"end": 117,
15421542
"isConst": false,
15431543
"isExported": false,
15441544
"name": "b",
1545-
"start": 96,
1545+
"start": 104,
15461546
"type": undefined,
15471547
},
15481548
],
@@ -1554,7 +1554,7 @@ File {
15541554
"start": 0,
15551555
},
15561556
],
1557-
"end": 144,
1557+
"end": 160,
15581558
"exports": Array [],
15591559
"filePath": "inline.tsx",
15601560
"imports": Array [],

test/_workspace/typescript-parser/usagesOnly.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Class {
88
public assignedProperty = AssignedProperty;
99

1010
@FunctionDecorator()
11-
public func(@ParamDecorator() param: TypedParam, defaultParam = DefaultParam) {
11+
public func( @ParamDecorator() param: TypedParam, defaultParam = DefaultParam) {
1212
}
1313

1414
private prv(param): ReturnValue {
@@ -39,3 +39,7 @@ class Class extends DefaultClass {
3939
class Class extends GenericClass<GenericType> {
4040

4141
}
42+
43+
indexedUsage[indexingUsage];
44+
45+
export default defaultExportUsage;

tslint.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
]
2828
}
2929
],
30+
"no-boolean-literal-compare": false,
31+
"strict-boolean-expressions": false,
3032
"ter-indent": [
3133
true,
3234
4,

0 commit comments

Comments
 (0)