Skip to content

Commit 2ca02b2

Browse files
authored
Merge pull request #38 from buehler/develop
2 parents 2aaeb73 + d97ed4e commit 2ca02b2

File tree

12 files changed

+83
-10
lines changed

12 files changed

+83
-10
lines changed

.appveyor.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: "{build} - {branch}"
2+
skip_tags: true
3+
4+
environment:
5+
matrix:
6+
- nodejs_version: "8"
7+
- nodejs_version: "7"
8+
- nodejs_version: "6"
9+
10+
install:
11+
- ps: Install-Product node $env:nodejs_version
12+
- npm install
13+
14+
test_script:
15+
- npm test
16+
17+
build: off

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ This package is a TypeScript and ECMAScript parser. It uses the underlying types
44
a more or less human readable AST out of .js or .ts files.
55

66
[![Build Status](https://travis-ci.org/buehler/node-typescript-parser.svg)](https://travis-ci.org/buehler/node-typescript-parser)
7+
[![Build Status Windows](https://ci.appveyor.com/api/projects/status/j06bqjc4tkdt7sej?svg=true)](https://ci.appveyor.com/project/buehler/node-typescript-parser)
78
[![npm](https://img.shields.io/npm/v/typescript-parser.svg?maxAge=3600)](https://www.npmjs.com/package/typescript-parser)
89
[![Coverage status](https://img.shields.io/coveralls/buehler/node-typescript-parser.svg?maxAge=3600)](https://coveralls.io/github/buehler/node-typescript-parser)
910
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@
4747
"dependencies": {
4848
"lodash": "^4.17.4",
4949
"tslib": "^1.7.1",
50-
"typescript": "2.4.2"
50+
"typescript": "^2.5.3"
5151
}
5252
}

src/DeclarationIndex.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Namespace } from './resources/Namespace';
1212
import { Resource } from './resources/Resource';
1313
import { isExportableDeclaration } from './type-guards/TypescriptHeroGuards';
1414
import { TypescriptParser } from './TypescriptParser';
15-
import { normalizeFilename, normalizePathUri } from './utilities/PathHelpers';
15+
import { normalizeFilename, normalizePathUri, toPosix } from './utilities/PathHelpers';
1616

1717
/**
1818
* Returns the name of the node folder. Is used as the library name for indexing.
@@ -118,7 +118,7 @@ export class DeclarationIndex {
118118
*/
119119
public get declarationInfos(): DeclarationInfo[] {
120120
return Object
121-
.keys(this.index)
121+
.keys(this.index!)
122122
.sort()
123123
.reduce((all, key) => all.concat(this.index![key]), <DeclarationInfo[]>[]);
124124
}
@@ -308,7 +308,7 @@ export class DeclarationIndex {
308308
break;
309309
}
310310
if (ex instanceof AllExport || ex instanceof NamedExport) {
311-
const exported = '/' + relative(this.rootPath, normalize(join(resource.parsedPath.dir, ex.from)));
311+
const exported = '/' + toPosix(relative(this.rootPath, normalize(join(resource.parsedPath.dir, ex.from))));
312312
exportsResource = exported === resourcePath;
313313
}
314314
}

src/utilities/PathHelpers.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,16 @@ export function normalizePathUri(uri: string): string {
2525
* @returns {string}
2626
*/
2727
export function normalizeFilename(filepath: string): string {
28-
return filepath.replace(/([.]d)?[.](t|j)sx?$/g, '');
28+
return toPosix(filepath.replace(/([.]d)?[.](t|j)sx?$/g, ''));
29+
}
30+
31+
/**
32+
* On Windows, replaces all backslash delimeters with forward slashes.
33+
* On other OSes, returns the path unmodified.
34+
*/
35+
export function toPosix(path: string): string {
36+
if (platform() === 'win32') {
37+
return path.replace(/\\/g, '/');
38+
}
39+
return path;
2940
}

test/TypescriptParser.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('TypescriptParser', () => {
5151
});
5252

5353
it('should parse imports', () => {
54-
expect(parsed.imports).toHaveLength(9);
54+
expect(parsed.imports).toHaveLength(12);
5555
expect(parsed.imports).toMatchSnapshot();
5656
});
5757

test/__snapshots__/TypescriptParser.spec.ts.snap

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,36 @@ Array [
10121012
],
10131013
"start": 400,
10141014
},
1015+
NamedImport {
1016+
"defaultAlias": "__DefaultAlias",
1017+
"end": 540,
1018+
"libraryName": "namedImport",
1019+
"specifiers": Array [
1020+
SymbolSpecifier {
1021+
"alias": "__Specifier1",
1022+
"specifier": "Specifier1",
1023+
},
1024+
],
1025+
"start": 456,
1026+
},
1027+
NamedImport {
1028+
"defaultAlias": "__DefaultAlias",
1029+
"end": 614,
1030+
"libraryName": "namedImport",
1031+
"specifiers": Array [
1032+
SymbolSpecifier {
1033+
"alias": "__Specifier1",
1034+
"specifier": "Specifier1",
1035+
},
1036+
],
1037+
"start": 541,
1038+
},
1039+
NamespaceImport {
1040+
"alias": "__namespaceImport",
1041+
"end": 662,
1042+
"libraryName": "namespace",
1043+
"start": 615,
1044+
},
10151045
]
10161046
`;
10171047

test/_workspace/typescript-parser/importsOnly.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ import {
1010
import Foobar from 'aFile';
1111
import { default as DefaultAlias, Specifier1 } from 'namedImport';
1212
import DefaultAlias, { Specifier1 } from 'namedImport';
13+
import { default as __DefaultAlias, Specifier1 as __Specifier1 } from 'namedImport';
14+
import __DefaultAlias, { Specifier1 as __Specifier1 } from 'namedImport';
15+
import * as __namespaceImport from 'namespace';

test/declaration-index/DeclarationIndex.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import mockFs = require('mock-fs');
2-
import { join, resolve } from 'path';
2+
import { join, resolve } from '../testUtilities';
33

44
import { DeclarationIndex } from '../../src/DeclarationIndex';
55
import { ClassDeclaration } from '../../src/declarations';

test/declaration-index/specific-cases/body-parser/DeclarationIndex.body-parser.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { join, resolve } from 'path';
1+
import { join, resolve } from '../../../testUtilities';
22

33
import { DeclarationIndex } from '../../../../src/DeclarationIndex';
44
import { TypescriptParser } from '../../../../src/TypescriptParser';

test/declaration-index/specific-cases/reindex-with-global-module/DeclarationIndex.reindex-with-global-module-export.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FileChanges } from '../../../../src';
2-
import { join, resolve } from 'path';
2+
import { join, resolve } from '../../../testUtilities';
33

44
import { DeclarationIndex } from '../../../../src/DeclarationIndex';
55
import { TypescriptParser } from '../../../../src/TypescriptParser';

test/testUtilities.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1-
import { resolve } from 'path';
1+
import * as Path from 'path';
2+
import { toPosix } from '../src/utilities/PathHelpers';
23

34
export function getWorkspaceFile(pathFromWorkspace: string): string {
45
return resolve(__dirname, '_workspace', pathFromWorkspace);
56
}
67

8+
// Like path.resolve, but always replaces backslashes with forward slashes on Windows.
9+
export function resolve(...paths: string[]): string {
10+
return toPosix(Path.resolve(...paths));
11+
}
12+
13+
// Like path.join, but always replaces backslashes with forward slashes on Windows.
14+
export function join(...paths: string[]): string {
15+
return toPosix(Path.join(...paths));
16+
}
17+
718
export const rootPath = resolve(__dirname, '_workspace');

0 commit comments

Comments
 (0)