Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
3 changes: 1 addition & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4324,7 +4324,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) :
symbolFromModule || symbolFromVariable;
if (!symbol) {
errorNoModuleMemberSymbol(moduleSymbol, targetSymbol, node, name);
errorNoModuleMemberSymbol(moduleSymbol, targetSymbol, getSourceFileOfNode(node), name);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This relies on the printer selection in symbolToStringWorker. While the containing function also accepts node.kind === SyntaxKind.VariableDeclaration, such a node doesn't reach this line in any test case so I'm currently not 100% sure if I can just call getSourceFileOfNode unconditionally here. I think it's OK for imports and exports.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Misrepresenting the location that we’re going to scope a symbol reference from sounds like a bad idea—the original fix in #39463 that you’re building on here feels a little too magically indirect to begin with to me. Is there any way you see to make the printer escaping behavior more directly dependent on whether a module specifier is being printed?

}
return symbol;
}
Expand Down Expand Up @@ -6375,7 +6375,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {

function symbolToStringWorker(writer: EmitTextWriter) {
const entity = builder(symbol, meaning!, enclosingDeclaration, nodeFlags)!; // TODO: GH#18217
// add neverAsciiEscape for GH#39027
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's now not only about this issue - I'm not sure if this comment has a lot of value here. If you think otherwise, I can bring it back.

const printer = enclosingDeclaration?.kind === SyntaxKind.SourceFile
? createPrinterWithRemoveCommentsNeverAsciiEscape()
: createPrinterWithRemoveComments();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
main.ts(1,10): error TS2305: Module '"./🦁.ts"' has no exported member 'bar'.
main.ts(1,15): error TS2459: Module '"./🦁.ts"' declares 'baz' locally, but it is not exported.
main.ts(2,10): error TS2305: Module '"./🦁.ts"' has no exported member 'bar'.
main.ts(2,15): error TS2459: Module '"./🦁.ts"' declares 'baz' locally, but it is not exported.


==== 🦁.ts (0 errors) ====
export const foo = "bar";
const baz = "baz";

==== main.ts (4 errors) ====
import { bar, baz } from './🦁.ts';
~~~
!!! error TS2305: Module '"./🦁.ts"' has no exported member 'bar'.
~~~
!!! error TS2459: Module '"./🦁.ts"' declares 'baz' locally, but it is not exported.
!!! related TS2728 🦁.ts:2:7: 'baz' is declared here.
export { bar, baz } from './🦁.ts';
~~~
!!! error TS2305: Module '"./🦁.ts"' has no exported member 'bar'.
~~~
!!! error TS2459: Module '"./🦁.ts"' declares 'baz' locally, but it is not exported.
!!! related TS2728 🦁.ts:2:7: 'baz' is declared here.

18 changes: 18 additions & 0 deletions tests/baselines/reference/unicodeInModuleSpecifierError1.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//// [tests/cases/compiler/unicodeInModuleSpecifierError1.ts] ////

=== 🦁.ts ===
export const foo = "bar";
>foo : Symbol(foo, Decl(🦁.ts, 0, 12))

const baz = "baz";
>baz : Symbol(baz, Decl(🦁.ts, 1, 5))

=== main.ts ===
import { bar, baz } from './🦁.ts';
>bar : Symbol(bar, Decl(main.ts, 0, 8))
>baz : Symbol(baz, Decl(main.ts, 0, 13))

export { bar, baz } from './🦁.ts';
>bar : Symbol(bar, Decl(main.ts, 1, 8))
>baz : Symbol(baz, Decl(main.ts, 1, 13))

20 changes: 20 additions & 0 deletions tests/baselines/reference/unicodeInModuleSpecifierError1.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//// [tests/cases/compiler/unicodeInModuleSpecifierError1.ts] ////

=== 🦁.ts ===
export const foo = "bar";
>foo : "bar"
>"bar" : "bar"

const baz = "baz";
>baz : "baz"
>"baz" : "baz"

=== main.ts ===
import { bar, baz } from './🦁.ts';
>bar : any
>baz : any

export { bar, baz } from './🦁.ts';
>bar : any
>baz : any

11 changes: 11 additions & 0 deletions tests/cases/compiler/unicodeInModuleSpecifierError1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @module: commonjs
// @allowImportingTsExtensions: true
// @noEmit: true

// @Filename: 🦁.ts
export const foo = "bar";
const baz = "baz";

// @Filename: main.ts
import { bar, baz } from './🦁.ts';
export { bar, baz } from './🦁.ts';