microsoft / microsoft/TypeScript

Compiler generates jsxFactory call with incorrect namespace

Aperta
#29,376 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Domain: Error Messages Needs Proposal Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

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 = {}));

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con la riproduzione in root.ts e con le opzioni del compilatore mostrate nell’issue, oppure estrai test.zip. Traccia l’emissione della factory JSX quando il JSX compare all’interno di namespace annidati e confronta l’output generato con la chiamata attesa a Templates.compile. Il lavoro è completato quando il compilatore non qualifica più la factory configurata con il namespace contenitore.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.