Skip to content

Commit 7b7a0ea

Browse files
committed
Revert #35877 - fix receiver on calls of imported and exported functions
1 parent f630365 commit 7b7a0ea

File tree

175 files changed

+345
-507
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

175 files changed

+345
-507
lines changed

src/compiler/transformers/module/module.ts

+32-109
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ namespace ts {
3535
context.onEmitNode = onEmitNode;
3636
context.enableSubstitution(SyntaxKind.Identifier); // Substitutes expression identifiers with imported/exported symbols.
3737
context.enableSubstitution(SyntaxKind.BinaryExpression); // Substitutes assignments to exported symbols.
38-
context.enableSubstitution(SyntaxKind.CallExpression); // Substitutes expression identifiers with imported/exported symbols.
39-
context.enableSubstitution(SyntaxKind.TaggedTemplateExpression); // Substitutes expression identifiers with imported/exported symbols.
4038
context.enableSubstitution(SyntaxKind.PrefixUnaryExpression); // Substitutes updates to exported symbols.
4139
context.enableSubstitution(SyntaxKind.PostfixUnaryExpression); // Substitutes updates to exported symbols.
4240
context.enableSubstitution(SyntaxKind.ShorthandPropertyAssignment); // Substitutes shorthand property assignments for imported/exported symbols.
@@ -49,7 +47,6 @@ namespace ts {
4947
let currentModuleInfo: ExternalModuleInfo; // The ExternalModuleInfo for the current file.
5048
let noSubstitution: boolean[]; // Set of nodes for which substitution rules should be ignored.
5149
let needUMDDynamicImportHelper: boolean;
52-
let bindingReferenceCache: ESMap<Node, Identifier | SourceFile | ImportClause | ImportSpecifier | undefined> | undefined;
5350

5451
return chainBundle(context, transformSourceFile);
5552

@@ -1746,10 +1743,6 @@ namespace ts {
17461743
return substituteExpressionIdentifier(<Identifier>node);
17471744
case SyntaxKind.BinaryExpression:
17481745
return substituteBinaryExpression(<BinaryExpression>node);
1749-
case SyntaxKind.CallExpression:
1750-
return substituteCallExpression(<CallExpression>node);
1751-
case SyntaxKind.TaggedTemplateExpression:
1752-
return substituteTaggedTemplateExpression(<TaggedTemplateExpression>node);
17531746
case SyntaxKind.PostfixUnaryExpression:
17541747
case SyntaxKind.PrefixUnaryExpression:
17551748
return substituteUnaryExpression(<PrefixUnaryExpression | PostfixUnaryExpression>node);
@@ -1759,124 +1752,54 @@ namespace ts {
17591752
}
17601753

17611754
/**
1762-
* For an Identifier, gets the import or export binding that it references.
1763-
* @returns One of the following:
1764-
* - An `Identifier` if node references an external helpers module (i.e., `tslib`).
1765-
* - A `SourceFile` if the node references an export in the file.
1766-
* - An `ImportClause` or `ImportSpecifier` if the node references an import binding.
1767-
* - Otherwise, `undefined`.
1755+
* Substitution for an Identifier expression that may contain an imported or exported
1756+
* symbol.
1757+
*
1758+
* @param node The node to substitute.
17681759
*/
1769-
function getImportOrExportBindingReferenceWorker(node: Identifier): Identifier | SourceFile | ImportClause | ImportSpecifier | undefined {
1760+
function substituteExpressionIdentifier(node: Identifier): Expression {
17701761
if (getEmitFlags(node) & EmitFlags.HelperName) {
17711762
const externalHelpersModuleName = getExternalHelpersModuleName(currentSourceFile);
17721763
if (externalHelpersModuleName) {
1773-
return externalHelpersModuleName;
1764+
return factory.createPropertyAccessExpression(externalHelpersModuleName, node);
17741765
}
1766+
return node;
17751767
}
17761768
else if (!(isGeneratedIdentifier(node) && !(node.autoGenerateFlags & GeneratedIdentifierFlags.AllowNameSubstitution)) && !isLocalName(node)) {
17771769
const exportContainer = resolver.getReferencedExportContainer(node, isExportName(node));
1778-
if (exportContainer?.kind === SyntaxKind.SourceFile) {
1779-
return exportContainer;
1780-
}
1781-
const importDeclaration = resolver.getReferencedImportDeclaration(node);
1782-
if (importDeclaration && (isImportClause(importDeclaration) || isImportSpecifier(importDeclaration))) {
1783-
return importDeclaration;
1784-
}
1785-
}
1786-
return undefined;
1787-
}
1788-
1789-
/**
1790-
* For an Identifier, gets the import or export binding that it references.
1791-
* @param removeEntry When `false`, the result is cached to avoid recomputing the result in a later substitution.
1792-
* When `true`, any cached result for the node is removed.
1793-
* @returns One of the following:
1794-
* - An `Identifier` if node references an external helpers module (i.e., `tslib`).
1795-
* - A `SourceFile` if the node references an export in the file.
1796-
* - An `ImportClause` or `ImportSpecifier` if the node references an import binding.
1797-
* - Otherwise, `undefined`.
1798-
*/
1799-
function getImportOrExportBindingReference(node: Identifier, removeEntry: boolean): Identifier | SourceFile | ImportClause | ImportSpecifier | undefined {
1800-
let result = bindingReferenceCache?.get(node);
1801-
if (!result && !bindingReferenceCache?.has(node)) {
1802-
result = getImportOrExportBindingReferenceWorker(node);
1803-
if (!removeEntry) {
1804-
bindingReferenceCache ||= new Map();
1805-
bindingReferenceCache.set(node, result);
1806-
}
1807-
}
1808-
else if (removeEntry) {
1809-
bindingReferenceCache?.delete(node);
1810-
}
1811-
return result;
1812-
}
1813-
1814-
function substituteCallExpression(node: CallExpression) {
1815-
if (isIdentifier(node.expression) && getImportOrExportBindingReference(node.expression, /*removeEntry*/ false)) {
1816-
return isCallChain(node) ?
1817-
factory.updateCallChain(node,
1818-
setTextRange(factory.createComma(factory.createNumericLiteral(0), node.expression), node.expression),
1819-
node.questionDotToken,
1820-
/*typeArguments*/ undefined,
1821-
node.arguments) :
1822-
factory.updateCallExpression(node,
1823-
setTextRange(factory.createComma(factory.createNumericLiteral(0), node.expression), node.expression),
1824-
/*typeArguments*/ undefined,
1825-
node.arguments);
1826-
}
1827-
return node;
1828-
}
1829-
1830-
function substituteTaggedTemplateExpression(node: TaggedTemplateExpression) {
1831-
if (isIdentifier(node.tag) && getImportOrExportBindingReference(node.tag, /*removeEntry*/ false)) {
1832-
return factory.updateTaggedTemplateExpression(
1833-
node,
1834-
setTextRange(factory.createComma(factory.createNumericLiteral(0), node.tag), node.tag),
1835-
/*typeArguments*/ undefined,
1836-
node.template);
1837-
}
1838-
return node;
1839-
}
1840-
1841-
/**
1842-
* Substitution for an Identifier expression that may contain an imported or exported
1843-
* symbol.
1844-
*
1845-
* @param node The node to substitute.
1846-
*/
1847-
function substituteExpressionIdentifier(node: Identifier): Expression {
1848-
const result = getImportOrExportBindingReference(node, /*removeEntry*/ true);
1849-
switch (result?.kind) {
1850-
case SyntaxKind.Identifier: // tslib import
1851-
return factory.createPropertyAccessExpression(result, node);
1852-
case SyntaxKind.SourceFile: // top-level export
1770+
if (exportContainer && exportContainer.kind === SyntaxKind.SourceFile) {
18531771
return setTextRange(
18541772
factory.createPropertyAccessExpression(
18551773
factory.createIdentifier("exports"),
18561774
factory.cloneNode(node)
18571775
),
18581776
/*location*/ node
18591777
);
1860-
case SyntaxKind.ImportClause:
1861-
return setTextRange(
1862-
factory.createPropertyAccessExpression(
1863-
factory.getGeneratedNameForNode(result.parent),
1864-
factory.createIdentifier("default")
1865-
),
1866-
/*location*/ node
1867-
);
1868-
case SyntaxKind.ImportSpecifier:
1869-
const name = result.propertyName || result.name;
1870-
return setTextRange(
1871-
factory.createPropertyAccessExpression(
1872-
factory.getGeneratedNameForNode(result.parent?.parent?.parent || result),
1873-
factory.cloneNode(name)
1874-
),
1875-
/*location*/ node
1876-
);
1877-
default:
1878-
return node;
1778+
}
1779+
const importDeclaration = resolver.getReferencedImportDeclaration(node);
1780+
if (importDeclaration) {
1781+
if (isImportClause(importDeclaration)) {
1782+
return setTextRange(
1783+
factory.createPropertyAccessExpression(
1784+
factory.getGeneratedNameForNode(importDeclaration.parent),
1785+
factory.createIdentifier("default")
1786+
),
1787+
/*location*/ node
1788+
);
1789+
}
1790+
else if (isImportSpecifier(importDeclaration)) {
1791+
const name = importDeclaration.propertyName || importDeclaration.name;
1792+
return setTextRange(
1793+
factory.createPropertyAccessExpression(
1794+
factory.getGeneratedNameForNode(importDeclaration.parent?.parent?.parent || importDeclaration),
1795+
factory.cloneNode(name)
1796+
),
1797+
/*location*/ node
1798+
);
1799+
}
1800+
}
18791801
}
1802+
return node;
18801803
}
18811804

18821805
/**

src/testRunner/tsconfig.json

-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@
9292
"unittests/evaluation/asyncGenerator.ts",
9393
"unittests/evaluation/awaiter.ts",
9494
"unittests/evaluation/destructuring.ts",
95-
"unittests/evaluation/externalModules.ts",
9695
"unittests/evaluation/forAwaitOf.ts",
9796
"unittests/evaluation/forOf.ts",
9897
"unittests/evaluation/optionalCall.ts",

src/testRunner/unittests/evaluation/externalModules.ts

-84
This file was deleted.

src/testRunner/unittests/tsserver/projectReferenceCompileOnSave.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ exports.fn3 = fn3;`;
5555
content: `"use strict";
5656
exports.__esModule = true;${appendJsText === changeJs ? "\nexports.fn3 = void 0;" : ""}
5757
var fns_1 = require("../decls/fns");
58-
(0, fns_1.fn1)();
59-
(0, fns_1.fn2)();
58+
fns_1.fn1();
59+
fns_1.fn2();
6060
${appendJs}`
6161
}];
6262
}

tests/baselines/reference/allowJscheckJsTypeParameterNoCrash.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ exports.__esModule = true;
3030
exports.a = void 0;
3131
var func_1 = require("./func");
3232
// hover on vextend
33-
exports.a = (0, func_1.vextend)({
33+
exports.a = func_1.vextend({
3434
watch: {
3535
data1: function (val) {
3636
this.data2 = 1;

tests/baselines/reference/allowSyntheticDefaultImportsCanPaintCrossModuleDeclaration.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ exports.__esModule = true;
2323
exports.__esModule = true;
2424
exports.A = void 0;
2525
var file1_1 = require("./file1");
26-
exports.A = (0, file1_1.styled)();
26+
exports.A = file1_1.styled();
2727

2828

2929
//// [color.d.ts]

tests/baselines/reference/ambientDeclarationsPatterns.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ foo(fileText);
3737
exports.__esModule = true;
3838
///<reference path="declarations.d.ts" />
3939
var foobarbaz_1 = require("foobarbaz");
40-
(0, foobarbaz_1.foo)(foobarbaz_1.baz);
40+
foobarbaz_1.foo(foobarbaz_1.baz);
4141
var foosball_1 = require("foosball");
42-
(0, foobarbaz_1.foo)(foosball_1.foos);
42+
foobarbaz_1.foo(foosball_1.foos);
4343
// Works with relative file name
4444
var file_text_1 = require("./file!text");
45-
(0, foobarbaz_1.foo)(file_text_1["default"]);
45+
foobarbaz_1.foo(file_text_1["default"]);

tests/baselines/reference/ambientShorthand.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ exports.__esModule = true;
2020
var jquery_1 = require("jquery");
2121
var baz = require("fs");
2222
var boom = require("jquery");
23-
(0, jquery_1["default"])(jquery_1.bar, baz, boom);
23+
jquery_1["default"](jquery_1.bar, baz, boom);

tests/baselines/reference/ambientShorthand_reExport.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ exports.__esModule = true;
4949
var reExportX_1 = require("./reExportX");
5050
var $ = require("./reExportAll");
5151
// '$' is not callable, it is an object.
52-
(0, reExportX_1.x)($);
52+
reExportX_1.x($);

tests/baselines/reference/amdDeclarationEmitNoExtraDeclare.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ define("Class", ["require", "exports", "Configurable"], function (require, expor
7272
return _super !== null && _super.apply(this, arguments) || this;
7373
}
7474
return ActualClass;
75-
}((0, Configurable_1.Configurable)(HiddenClass)));
75+
}(Configurable_1.Configurable(HiddenClass)));
7676
exports.ActualClass = ActualClass;
7777
});
7878

tests/baselines/reference/anonClassDeclarationEmitIsAnon.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ var __extends = (this && this.__extends) || (function () {
9696
exports.__esModule = true;
9797
exports.TimestampedUser = exports.User = void 0;
9898
var wrapClass_1 = require("./wrapClass");
99-
exports["default"] = (0, wrapClass_1.wrapClass)(0);
99+
exports["default"] = wrapClass_1.wrapClass(0);
100100
// Simple class
101101
var User = /** @class */ (function () {
102102
function User() {
@@ -112,7 +112,7 @@ var TimestampedUser = /** @class */ (function (_super) {
112112
return _super.call(this) || this;
113113
}
114114
return TimestampedUser;
115-
}((0, wrapClass_1.Timestamped)(User)));
115+
}(wrapClass_1.Timestamped(User)));
116116
exports.TimestampedUser = TimestampedUser;
117117

118118

tests/baselines/reference/callbackTagVariadicType.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ exports.x = void 0;
2222
/** @type {Foo} */
2323
var x = function () { return 1; };
2424
exports.x = x;
25-
var res = (0, exports.x)('a', 'b');
25+
var res = exports.x('a', 'b');
2626

2727

2828
//// [callbackTagVariadicType.d.ts]

tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsx,module=commonjs).js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var Component = /** @class */ (function () {
2525
function Component() {
2626
}
2727
Component.prototype.render = function () {
28-
return (0, _a.jsx)("div", { children: null /* preserved */ }, void 0);
28+
return _a.jsx("div", { children: null /* preserved */ }, void 0);
2929
};
3030
return Component;
3131
}());

tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs).js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var Component = /** @class */ (function () {
2626
function Component() {
2727
}
2828
Component.prototype.render = function () {
29-
return (0, _a.jsxDEV)("div", { children: null /* preserved */ }, void 0, false, { fileName: _jsxFileName, lineNumber: 5, columnNumber: 15 }, this);
29+
return _a.jsxDEV("div", { children: null /* preserved */ }, void 0, false, { fileName: _jsxFileName, lineNumber: 5, columnNumber: 15 }, this);
3030
};
3131
return Component;
3232
}());

tests/baselines/reference/commonjsSafeImport.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ exports.Foo = Foo;
1919
"use strict";
2020
Object.defineProperty(exports, "__esModule", { value: true });
2121
var _10_lib_1 = require("./10_lib");
22-
(0, _10_lib_1.Foo)();
22+
_10_lib_1.Foo();
2323

2424

2525
//// [10_lib.d.ts]

0 commit comments

Comments
 (0)