Skip to content

Commit 2d77419

Browse files
ajafffrbuckton
authored andcommitted
fix receiver of imported and exported functions
fixes: #35420
1 parent f462576 commit 2d77419

File tree

93 files changed

+746
-718
lines changed

Some content is hidden

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

93 files changed

+746
-718
lines changed

src/compiler/transformers/module/module.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ namespace ts {
3434
context.onEmitNode = onEmitNode;
3535
context.enableSubstitution(SyntaxKind.Identifier); // Substitutes expression identifiers with imported/exported symbols.
3636
context.enableSubstitution(SyntaxKind.BinaryExpression); // Substitutes assignments to exported symbols.
37+
context.enableSubstitution(SyntaxKind.CallExpression); // Substitutes expression identifiers with imported/exported symbols.
38+
context.enableSubstitution(SyntaxKind.TaggedTemplateExpression); // Substitutes expression identifiers with imported/exported symbols.
3739
context.enableSubstitution(SyntaxKind.PrefixUnaryExpression); // Substitutes updates to exported symbols.
3840
context.enableSubstitution(SyntaxKind.PostfixUnaryExpression); // Substitutes updates to exported symbols.
3941
context.enableSubstitution(SyntaxKind.ShorthandPropertyAssignment); // Substitutes shorthand property assignments for imported/exported symbols.
@@ -1742,6 +1744,10 @@ namespace ts {
17421744
return substituteExpressionIdentifier(<Identifier>node);
17431745
case SyntaxKind.BinaryExpression:
17441746
return substituteBinaryExpression(<BinaryExpression>node);
1747+
case SyntaxKind.CallExpression:
1748+
return substituteCallExpression(<CallExpression>node);
1749+
case SyntaxKind.TaggedTemplateExpression:
1750+
return substituteTaggedTemplateExpression(<TaggedTemplateExpression>node);
17451751
case SyntaxKind.PostfixUnaryExpression:
17461752
case SyntaxKind.PrefixUnaryExpression:
17471753
return substituteUnaryExpression(<PrefixUnaryExpression | PostfixUnaryExpression>node);
@@ -1750,6 +1756,28 @@ namespace ts {
17501756
return node;
17511757
}
17521758

1759+
function substituteCallExpression(node: CallExpression) {
1760+
if (!isIdentifier(node.expression)) {
1761+
return node;
1762+
}
1763+
const newExpression = substituteExpressionIdentifier(node.expression);
1764+
if (newExpression !== node.expression) {
1765+
return updateCall(node, setTextRange(createBinary(createNumericLiteral("0"), SyntaxKind.CommaToken, newExpression), node.expression), /*typeArguments*/ undefined, node.arguments);
1766+
}
1767+
return node;
1768+
}
1769+
1770+
function substituteTaggedTemplateExpression(node: TaggedTemplateExpression) {
1771+
if (!isIdentifier(node.tag)) {
1772+
return node;
1773+
}
1774+
const newTag = substituteExpressionIdentifier(node.tag);
1775+
if (newTag !== node.tag) {
1776+
return updateTaggedTemplate(node, setTextRange(createBinary(createNumericLiteral("0"), SyntaxKind.CommaToken, newTag), node.tag), /*typeArguments*/ undefined, node.template);
1777+
}
1778+
return node;
1779+
}
1780+
17531781
/**
17541782
* Substitution for an Identifier expression that may contain an imported or exported
17551783
* symbol.

src/testRunner/unittests/tsserver/projectReferenceCompileOnSave.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ exports.fn3 = fn3;`;
238238
content: `"use strict";
239239
exports.__esModule = true;${appendJsText === changeJs ? "\nexports.fn3 = void 0;" : ""}
240240
var fns_1 = require("../decls/fns");
241-
fns_1.fn1();
242-
fns_1.fn2();
241+
(0, fns_1.fn1)();
242+
(0, fns_1.fn2)();
243243
${appendJs}`
244244
}]
245245
};

tests/baselines/reference/allowJscheckJsTypeParameterNoCrash.js

Lines changed: 1 addition & 1 deletion
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 = func_1.vextend({
33+
exports.a = (0, func_1.vextend)({
3434
watch: {
3535
data1: function (val) {
3636
this.data2 = 1;

tests/baselines/reference/allowSyntheticDefaultImportsCanPaintCrossModuleDeclaration.js

Lines changed: 1 addition & 1 deletion
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 = file1_1.styled();
26+
exports.A = (0, file1_1.styled)();
2727

2828

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

tests/baselines/reference/ambientDeclarationsPatterns.js

Lines changed: 3 additions & 3 deletions
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-
foobarbaz_1.foo(foobarbaz_1.baz);
40+
(0, foobarbaz_1.foo)(foobarbaz_1.baz);
4141
var foosball_1 = require("foosball");
42-
foobarbaz_1.foo(foosball_1.foos);
42+
(0, foobarbaz_1.foo)(foosball_1.foos);
4343
// Works with relative file name
4444
var file_text_1 = require("./file!text");
45-
foobarbaz_1.foo(file_text_1["default"]);
45+
(0, foobarbaz_1.foo)(file_text_1["default"]);

tests/baselines/reference/ambientShorthand.js

Lines changed: 1 addition & 1 deletion
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-
jquery_1["default"](jquery_1.bar, baz, boom);
23+
(0, jquery_1["default"])(jquery_1.bar, baz, boom);

tests/baselines/reference/ambientShorthand_reExport.js

Lines changed: 1 addition & 1 deletion
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-
reExportX_1.x($);
52+
(0, reExportX_1.x)($);

tests/baselines/reference/amdDeclarationEmitNoExtraDeclare.js

Lines changed: 1 addition & 1 deletion
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-
}(Configurable_1.Configurable(HiddenClass)));
75+
}((0, Configurable_1.Configurable)(HiddenClass)));
7676
exports.ActualClass = ActualClass;
7777
});
7878

tests/baselines/reference/anonClassDeclarationEmitIsAnon.js

Lines changed: 2 additions & 2 deletions
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"] = wrapClass_1.wrapClass(0);
99+
exports["default"] = (0, 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-
}(wrapClass_1.Timestamped(User)));
115+
}((0, wrapClass_1.Timestamped)(User)));
116116
exports.TimestampedUser = TimestampedUser;
117117

118118

tests/baselines/reference/commonjsSafeImport.js

Lines changed: 1 addition & 1 deletion
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-
_10_lib_1.Foo();
22+
(0, _10_lib_1.Foo)();
2323

2424

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

0 commit comments

Comments
 (0)