Skip to content

Fix getExportSymbolOfValueSymbolIfExported #48769

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 1 commit into from
Apr 26, 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
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4109,7 +4109,7 @@ namespace ts {
function getExportSymbolOfValueSymbolIfExported(symbol: Symbol): Symbol;
function getExportSymbolOfValueSymbolIfExported(symbol: Symbol | undefined): Symbol | undefined;
function getExportSymbolOfValueSymbolIfExported(symbol: Symbol | undefined): Symbol | undefined {
return getMergedSymbol(symbol && (symbol.flags & SymbolFlags.ExportValue) !== 0 ? symbol.exportSymbol : symbol);
return getMergedSymbol(symbol && (symbol.flags & SymbolFlags.ExportValue) !== 0 && symbol.exportSymbol || symbol);
Copy link
Member Author

Choose a reason for hiding this comment

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

The symbol passed here that had the ExportValue flag but no exportSymbol was the export= symbol for constants.js in the test case.

Copy link
Member

Choose a reason for hiding this comment

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

The export= symbol is the result of a symbol merge, afaik - is it as simple as cloneSymbol not copying this field when it should?

Copy link
Member Author

Choose a reason for hiding this comment

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

This export= symbol is not a merged symbol, no.

}

function symbolIsValue(symbol: Symbol): boolean {
Expand Down
21 changes: 21 additions & 0 deletions tests/baselines/reference/reExportJsFromTs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//// [tests/cases/conformance/salsa/reExportJsFromTs.ts] ////

//// [constants.js]
module.exports = {
str: 'x',
};

//// [constants.ts]
import * as tsConstants from "../lib/constants";
export { tsConstants };

//// [constants.js]
module.exports = {
str: 'x'
};
//// [constants.js]
"use strict";
exports.__esModule = true;
exports.tsConstants = void 0;
var tsConstants = require("../lib/constants");
exports.tsConstants = tsConstants;
18 changes: 18 additions & 0 deletions tests/baselines/reference/reExportJsFromTs.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
=== /lib/constants.js ===
module.exports = {
>module.exports : Symbol(module.exports, Decl(constants.js, 0, 0))
>module : Symbol(export=, Decl(constants.js, 0, 0))
>exports : Symbol(export=, Decl(constants.js, 0, 0))

str: 'x',
>str : Symbol(str, Decl(constants.js, 0, 18))

};

=== /src/constants.ts ===
import * as tsConstants from "../lib/constants";
>tsConstants : Symbol(tsConstants, Decl(constants.ts, 0, 6))

export { tsConstants };
>tsConstants : Symbol(tsConstants, Decl(constants.ts, 1, 8))

21 changes: 21 additions & 0 deletions tests/baselines/reference/reExportJsFromTs.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
=== /lib/constants.js ===
module.exports = {
>module.exports = { str: 'x',} : { str: string; }
>module.exports : { str: string; }
>module : { exports: { str: string; }; }
>exports : { str: string; }
>{ str: 'x',} : { str: string; }

str: 'x',
>str : string
>'x' : "x"

};

=== /src/constants.ts ===
import * as tsConstants from "../lib/constants";
>tsConstants : { str: string; }

export { tsConstants };
>tsConstants : { str: string; }

11 changes: 11 additions & 0 deletions tests/cases/conformance/salsa/reExportJsFromTs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @allowJs: true
// @outDir: out

// @Filename: /lib/constants.js
module.exports = {
str: 'x',
};

// @Filename: /src/constants.ts
import * as tsConstants from "../lib/constants";
export { tsConstants };