-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix relative paths in commonjs decl emit w/property access (#40986)
```js const x = require('./foo').y ``` was incorrectly using the unmangled require path as the temp name in emit: ``` import ./foo_1 = require('./foo') import x = ./foo_1.y ``` It now uses the imported identifier: ``` import x_1 = require('./foo') import x = x_1.y ``` Discovered while fixing #37832
- Loading branch information
Showing
7 changed files
with
103 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
22 changes: 22 additions & 0 deletions
22
tests/baselines/reference/jsDeclarationsCommonjsRelativePath.js
This file contains 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,22 @@ | ||
//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsCommonjsRelativePath.ts] //// | ||
|
||
//// [thing.js] | ||
'use strict'; | ||
class Thing {} | ||
module.exports = { Thing } | ||
|
||
//// [reexport.js] | ||
'use strict'; | ||
const Thing = require('./thing').Thing | ||
module.exports = { Thing } | ||
|
||
|
||
|
||
|
||
//// [thing.d.ts] | ||
export class Thing { | ||
} | ||
//// [reexport.d.ts] | ||
import Thing_1 = require("./thing"); | ||
import Thing = Thing_1.Thing; | ||
export { Thing }; |
26 changes: 26 additions & 0 deletions
26
tests/baselines/reference/jsDeclarationsCommonjsRelativePath.symbols
This file contains 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,26 @@ | ||
=== tests/cases/conformance/jsdoc/declarations/reexport.js === | ||
'use strict'; | ||
const Thing = require('./thing').Thing | ||
>Thing : Symbol(Thing, Decl(reexport.js, 1, 5)) | ||
>require('./thing').Thing : Symbol(Thing, Decl(thing.js, 2, 18)) | ||
>require : Symbol(require) | ||
>'./thing' : Symbol("tests/cases/conformance/jsdoc/declarations/thing", Decl(thing.js, 0, 0)) | ||
>Thing : Symbol(Thing, Decl(thing.js, 2, 18)) | ||
|
||
module.exports = { Thing } | ||
>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/reexport", Decl(reexport.js, 0, 0)) | ||
>module : Symbol(export=, Decl(reexport.js, 1, 38)) | ||
>exports : Symbol(export=, Decl(reexport.js, 1, 38)) | ||
>Thing : Symbol(Thing, Decl(reexport.js, 2, 18)) | ||
|
||
=== tests/cases/conformance/jsdoc/declarations/thing.js === | ||
'use strict'; | ||
class Thing {} | ||
>Thing : Symbol(Thing, Decl(thing.js, 0, 13)) | ||
|
||
module.exports = { Thing } | ||
>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/thing", Decl(thing.js, 0, 0)) | ||
>module : Symbol(export=, Decl(thing.js, 1, 14)) | ||
>exports : Symbol(export=, Decl(thing.js, 1, 14)) | ||
>Thing : Symbol(Thing, Decl(thing.js, 2, 18)) | ||
|
35 changes: 35 additions & 0 deletions
35
tests/baselines/reference/jsDeclarationsCommonjsRelativePath.types
This file contains 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,35 @@ | ||
=== tests/cases/conformance/jsdoc/declarations/reexport.js === | ||
'use strict'; | ||
>'use strict' : "use strict" | ||
|
||
const Thing = require('./thing').Thing | ||
>Thing : typeof Thing | ||
>require('./thing').Thing : typeof Thing | ||
>require('./thing') : { Thing: typeof Thing; } | ||
>require : any | ||
>'./thing' : "./thing" | ||
>Thing : typeof Thing | ||
|
||
module.exports = { Thing } | ||
>module.exports = { Thing } : { Thing: typeof Thing; } | ||
>module.exports : { Thing: typeof Thing; } | ||
>module : { "\"tests/cases/conformance/jsdoc/declarations/reexport\"": { Thing: typeof Thing; }; } | ||
>exports : { Thing: typeof Thing; } | ||
>{ Thing } : { Thing: typeof Thing; } | ||
>Thing : typeof Thing | ||
|
||
=== tests/cases/conformance/jsdoc/declarations/thing.js === | ||
'use strict'; | ||
>'use strict' : "use strict" | ||
|
||
class Thing {} | ||
>Thing : Thing | ||
|
||
module.exports = { Thing } | ||
>module.exports = { Thing } : { Thing: typeof Thing; } | ||
>module.exports : { Thing: typeof Thing; } | ||
>module : { "\"tests/cases/conformance/jsdoc/declarations/thing\"": { Thing: typeof Thing; }; } | ||
>exports : { Thing: typeof Thing; } | ||
>{ Thing } : { Thing: typeof Thing; } | ||
>Thing : typeof Thing | ||
|
This file contains 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
This file contains 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
13 changes: 13 additions & 0 deletions
13
tests/cases/conformance/jsdoc/declarations/jsDeclarationsCommonjsRelativePath.ts
This file contains 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,13 @@ | ||
// @checkJs: true | ||
// @declaration: true | ||
// @emitDeclarationOnly: true | ||
// @module: commonjs | ||
// @Filename: thing.js | ||
'use strict'; | ||
class Thing {} | ||
module.exports = { Thing } | ||
|
||
// @Filename: reexport.js | ||
'use strict'; | ||
const Thing = require('./thing').Thing | ||
module.exports = { Thing } |