Skip to content

Commit

Permalink
Do not prepend options.name to non-relative imports. (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritzingerp committed Jan 17, 2017
1 parent a6412ae commit 7c84d63
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
3 changes: 0 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,6 @@ export default function generate(options: Options): Promise<void> {
if (moduleId.charAt(0) === '.') {
return filenameToMid(pathUtil.join(pathUtil.dirname(sourceModuleId), moduleId));
}
else if (!isDeclaredExternalModule) {
return options.name ? (options.name + '/' + moduleId) : (moduleId);
}
}
/* For some reason, SourceFile.externalModuleIndicator is missing from 1.6+, so having
* to use a sledgehammer on the nut */
Expand Down
5 changes: 5 additions & 0 deletions tests/support/foo-resolve-module-id/NonRelative.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class NonRelative {
public sayHello(s: string): string {
return `Hello $name`;
}
}
5 changes: 5 additions & 0 deletions tests/support/foo-resolve-module-id/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { FooImplExportDeclaration } from './FooImplExportDeclaration';
export { ReExport } from './ReExport';
import { ClassInJavaScript } from 'SomethingInJavaScript';
import { NonRelative } from 'NonRelative';

export function fooImplExportAssignment(): FooImplExportAssignment {
return new FooImplExportAssignment();
Expand All @@ -13,4 +14,8 @@ export function fooImplExportDeclaration(): FooImplExportDeclaration {

export function classInJavaScript(): ClassInJavaScript {
return new ClassInJavaScript();
}

export function nonRelative(): NonRelative {
return new NonRelative();
}
3 changes: 2 additions & 1 deletion tests/support/foo-resolve-module-id/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"./FooInterfaceExportAssignment.ts",
"./FooInterfaceExportDeclaration.ts",
"./ExternalModuleDeclaration.d.ts",
"./ReExport.ts"
"./ReExport.ts",
"./NonRelative.ts"
]
}
3 changes: 3 additions & 0 deletions tests/unit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ registerSuite({
// replaced external module declaration import
assert.include(contents, `import { ClassInJavaScript } from 'ReplacedSomethingInJavaScript';`);

// non relative module import, should not be changed
assert.include(contents, `import { NonRelative } from 'NonRelative';`);

// class imports should not be replaced, also assert on them
assert.include(contents, `import FooImplExportAssignment = require('foo/FooImplExportAssignment');`);
assert.include(contents, `import { FooImplExportDeclaration } from 'foo/FooImplExportDeclaration';`);
Expand Down

0 comments on commit 7c84d63

Please sign in to comment.