-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Don't escape unicode characters in import/export paths in reported errors #57550
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
Open
Andarist
wants to merge
3
commits into
microsoft:main
Choose a base branch
from
Andarist:fix/unicode-in-import-export
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
668ea6c
Don't escape unicode characters in import/export paths in reported er…
Andarist e112fcb
Merge remote-tracking branch 'origin/main' into fix/unicode-in-import…
Andarist 5303137
Merge remote-tracking branch 'origin/main' into fix/unicode-in-import…
Andarist File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
|
|
||
24 changes: 24 additions & 0 deletions
24
tests/baselines/reference/unicodeInModuleSpecifierError1.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
18
tests/baselines/reference/unicodeInModuleSpecifierError1.symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
20
tests/baselines/reference/unicodeInModuleSpecifierError1.types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This relies on the
printerselection insymbolToStringWorker. While the containing function also acceptsnode.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 callgetSourceFileOfNodeunconditionally here. I think it's OK for imports and exports.There was a problem hiding this comment.
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?