helper-module-transforms: dereference imported template tag (#10934)

* Dereference imported template tag

* apply fix for OptionalCallExpression as well
This commit is contained in:
Klaus Meinhardt 2019-12-28 22:46:20 +01:00 committed by Huáng Jùnliàng
parent e9dc74e787
commit b91720c1cc
4 changed files with 8 additions and 1 deletions

View File

@ -182,7 +182,9 @@ const rewriteReferencesVisitor = {
ref.loc = path.node.loc; ref.loc = path.node.loc;
if ( if (
path.parentPath.isCallExpression({ callee: path.node }) && (path.parentPath.isCallExpression({ callee: path.node }) ||
path.parentPath.isOptionalCallExpression({ callee: path.node }) ||
path.parentPath.isTaggedTemplateExpression({ tag: path.node })) &&
t.isMemberExpression(ref) t.isMemberExpression(ref)
) { ) {
path.replaceWith(t.sequenceExpression([t.numericLiteral(0), ref])); path.replaceWith(t.sequenceExpression([t.numericLiteral(0), ref]));

View File

@ -7,3 +7,5 @@ foo;
foo2; foo2;
foo3; foo3;
foo3(); foo3();
foo3``;
foo3?.();

View File

@ -5,3 +5,5 @@ foo4.default;
foo4.default; foo4.default;
foo4.foo3; foo4.foo3;
(0, foo4.foo3)(); (0, foo4.foo3)();
(0, foo4.foo3)``;
(0, foo4.foo3)?.();

View File

@ -2,6 +2,7 @@
"plugins": [ "plugins": [
"external-helpers", "external-helpers",
"syntax-object-rest-spread", "syntax-object-rest-spread",
"syntax-optional-chaining",
[ [
"transform-modules-commonjs", "transform-modules-commonjs",
{ "strict": true, "mjsStrictNamespace": false } { "strict": true, "mjsStrictNamespace": false }