From 668ea6c3bc6750d3629a6e35a0c490f5fe508f02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Mon, 26 Feb 2024 19:12:11 +0100 Subject: [PATCH] Don't escape unicode characters in import/export paths in reported errors --- src/compiler/checker.ts | 3 +-- .../unicodeInModuleSpecifierError1.errors.txt | 24 +++++++++++++++++++ .../unicodeInModuleSpecifierError1.symbols | 18 ++++++++++++++ .../unicodeInModuleSpecifierError1.types | 20 ++++++++++++++++ .../unicodeInModuleSpecifierError1.ts | 11 +++++++++ 5 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/unicodeInModuleSpecifierError1.errors.txt create mode 100644 tests/baselines/reference/unicodeInModuleSpecifierError1.symbols create mode 100644 tests/baselines/reference/unicodeInModuleSpecifierError1.types create mode 100644 tests/cases/compiler/unicodeInModuleSpecifierError1.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f9ab74b053256..371a06a785afc 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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); } return symbol; } @@ -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 const printer = enclosingDeclaration?.kind === SyntaxKind.SourceFile ? createPrinterWithRemoveCommentsNeverAsciiEscape() : createPrinterWithRemoveComments(); diff --git a/tests/baselines/reference/unicodeInModuleSpecifierError1.errors.txt b/tests/baselines/reference/unicodeInModuleSpecifierError1.errors.txt new file mode 100644 index 0000000000000..5e4cf21ed7984 --- /dev/null +++ b/tests/baselines/reference/unicodeInModuleSpecifierError1.errors.txt @@ -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. + \ No newline at end of file diff --git a/tests/baselines/reference/unicodeInModuleSpecifierError1.symbols b/tests/baselines/reference/unicodeInModuleSpecifierError1.symbols new file mode 100644 index 0000000000000..e58a6e777e5d0 --- /dev/null +++ b/tests/baselines/reference/unicodeInModuleSpecifierError1.symbols @@ -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)) + diff --git a/tests/baselines/reference/unicodeInModuleSpecifierError1.types b/tests/baselines/reference/unicodeInModuleSpecifierError1.types new file mode 100644 index 0000000000000..378d188ca5dad --- /dev/null +++ b/tests/baselines/reference/unicodeInModuleSpecifierError1.types @@ -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 + diff --git a/tests/cases/compiler/unicodeInModuleSpecifierError1.ts b/tests/cases/compiler/unicodeInModuleSpecifierError1.ts new file mode 100644 index 0000000000000..c3e928c9dd9d6 --- /dev/null +++ b/tests/cases/compiler/unicodeInModuleSpecifierError1.ts @@ -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';