Skip to content

Generate correct scipSymbol for namespace imports #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 28, 2022
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
4 changes: 3 additions & 1 deletion snapshots/input/syntax/src/import.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as namespace from './namespace'
import { Class } from './class'
import { Enum } from './enum'
import { newFunction } from './function'
Expand All @@ -8,7 +9,8 @@ export function useEverything(): string {
new Class('a').classProperty +
renamedInterface().methodSignature('a') +
Enum[Enum.A] +
newFunction()
newFunction() +
namespace.a.value
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
declare namespace a {
export declare namespace a {
function hello(): string
interface Interface {
hello: string
}
var i: Interface
export const value = 1
}
11 changes: 9 additions & 2 deletions snapshots/output/syntax/src/import.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Class } from './class'
import * as namespace from './namespace'
// definition syntax 1.0.0 src/`import.ts`/
//documentation ```ts\nmodule "import.ts"\n```
// ^^^^^^^^^ reference syntax 1.0.0 src/`namespace.ts`/
// ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`namespace.ts`/
import { Class } from './class'
// ^^^^^ reference syntax 1.0.0 src/`class.ts`/Class#
// ^^^^^^^^^ reference syntax 1.0.0 src/`class.ts`/
import { Enum } from './enum'
Expand Down Expand Up @@ -28,8 +31,12 @@
// ^^^^ reference syntax 1.0.0 src/`enum.ts`/Enum#
// ^^^^ reference syntax 1.0.0 src/`enum.ts`/Enum#
// ^ reference syntax 1.0.0 src/`enum.ts`/Enum#A.
newFunction()
newFunction() +
// ^^^^^^^^^^^ reference syntax 1.0.0 src/`function.ts`/newFunction().
namespace.a.value
// ^^^^^^^^^ reference syntax 1.0.0 src/`namespace.ts`/
// ^ reference syntax 1.0.0 src/`namespace.ts`/a/
// ^^^^^ reference syntax 1.0.0 src/`namespace.ts`/a/value.
)
}

Expand Down
21 changes: 0 additions & 21 deletions snapshots/output/syntax/src/namespace.d.ts

This file was deleted.

24 changes: 24 additions & 0 deletions snapshots/output/syntax/src/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export declare namespace a {
// definition syntax 1.0.0 src/`namespace.ts`/
//documentation ```ts\nmodule "namespace.ts"\n```
// ^ definition syntax 1.0.0 src/`namespace.ts`/a/
// documentation ```ts\na: typeof a\n```
function hello(): string
// ^^^^^ definition syntax 1.0.0 src/`namespace.ts`/a/hello().
// documentation ```ts\nfunction hello(): string\n```
interface Interface {
// ^^^^^^^^^ definition syntax 1.0.0 src/`namespace.ts`/a/Interface#
// documentation ```ts\ninterface Interface\n```
hello: string
// ^^^^^ definition syntax 1.0.0 src/`namespace.ts`/a/Interface#hello.
// documentation ```ts\n(property) hello: string\n```
}
var i: Interface
// ^ definition syntax 1.0.0 src/`namespace.ts`/a/i.
// documentation ```ts\nvar i: Interface\n```
// ^^^^^^^^^ reference syntax 1.0.0 src/`namespace.ts`/a/Interface#
export const value = 1
// ^^^^^ definition syntax 1.0.0 src/`namespace.ts`/a/value.
// documentation ```ts\nvar value: 1\n```
}

6 changes: 5 additions & 1 deletion src/FileIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,11 @@ export class FileIndexer {
return this.cached(node, this.scipSymbol(node.parent))
}

if (ts.isImportSpecifier(node) || ts.isImportClause(node)) {
if (
ts.isImportSpecifier(node) ||
ts.isImportClause(node) ||
ts.isNamespaceImport(node)
) {
const tpe = this.checker.getTypeAtLocation(node)
for (const declaration of tpe.symbol?.declarations || []) {
return this.scipSymbol(declaration)
Expand Down