microsoft / microsoft/TypeScript

Compiler generates jsxFactory call with incorrect namespace

Open
#29,376 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Domain: Error Messages Needs Proposal Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: 3.2.2, 3.3.0-dev.20190111

Search Terms:
jsx, jsxFactory

Code
Full solution: test.zip

namespace Templates {

    export function compile(_: string, __: { [key: string]: any }, ...___: Array<any>) {
        return {};
    }
}
// this template generated properly as call to Templates.compile
namespace SomeNS.Templates.OtherNS {
    export const Boolean = (props: {
        id: string;
        name: string;
    }) => {
        return (
            <input type="checkbox" id={props.id} name={props.name} />
        );
    }
}
// this template generated as call to non-existing SomeNS.Templates.compile
namespace SomeNS.templates {
    export const text = (value: string) => <span>{value}</span>;
}
{
    "compileOnSave": false,
    "files": [
        "root.ts"
    ],
    "compilerOptions": {
        "noEmitOnError": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "removeComments": true,
        "target": "es5",
        "strict": true,
        "noImplicitReturns": true,
        "noFallthroughCasesInSwitch": true,
        "forceConsistentCasingInFileNames": true,
        "noErrorTruncation": true,
        "allowJs": true,
        "lib": [
            "dom",
            "es5"
        ],
        "stripInternal": true,
        "declaration": false,
        "jsx": "react",
        "jsxFactory": "Templates.compile"
    }
}

Expected behavior:
Proper call to jsxFactory method generated

Actual behavior:

Generated code contains call of non-existing method (SomeNS.Templates.compile instead of Templates.compile):

"use strict";
var Templates;
(function (Templates) {
    function compile(_, __) {
        var ___ = [];
        for (var _i = 2; _i < arguments.length; _i++) {
            ___[_i - 2] = arguments[_i];
        }
        return {};
    }
    Templates.compile = compile;
})(Templates || (Templates = {}));
var SomeNS;
(function (SomeNS) {
    var templates;
    (function (templates) {
                // unknown SomeNS.Templates.compile method called
        templates.text = function (value) { return SomeNS.Templates.compile("span", null, value); };
    })(templates = SomeNS.templates || (SomeNS.templates = {}));
})(SomeNS || (SomeNS = {}));
var SomeNS;
(function (SomeNS) {
    var TestClass = (function () {
        function TestClass() {
        }
        TestClass.prototype.test = function () {
            return SomeNS.Templates.OtherNS.Boolean({
                id: 'id',
                name: 'name'
            });
        };
        return TestClass;
    }());
    SomeNS.TestClass = TestClass;
})(SomeNS || (SomeNS = {}));
var SomeNS;
(function (SomeNS) {
    var Templates;
    (function (Templates) {
        var OtherNS;
        (function (OtherNS) {
            OtherNS.Boolean = function (props) {
                // proper Templates.compile method called
                return (Templates.compile("input", { type: "checkbox", id: props.id, name: props.name }));
            };
        })(OtherNS = Templates.OtherNS || (Templates.OtherNS = {}));
    })(Templates = SomeNS.Templates || (SomeNS.Templates = {}));
})(SomeNS || (SomeNS = {}));

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the root.ts reproduction and the compiler options shown in the issue, or extract test.zip. Trace JSX factory emission when the JSX appears inside nested namespaces and compare the generated output with the expected Templates.compile call. Done means the compiler no longer qualifies the configured factory with the enclosing namespace.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.