Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React component imports was removed. #15905

Closed
yhorbachov opened this issue May 17, 2017 · 2 comments
Closed

React component imports was removed. #15905

yhorbachov opened this issue May 17, 2017 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@yhorbachov
Copy link

TypeScript Version: 2.3.2
Version 2.3.2 removes imports of react components if you use them only in JSX(TSX).

Code

import * as React from "react";

import { TitleComponent } from './title.component.tsx';
import { BodyComponent } from './body.component.tsx';

export default function render(Router:any, routerArgs) {
  return (
    <Router {...routerArgs}>
      <div>
        <div>
          <TitleComponent />
        </div>
        <div>
          <BodyComponent />
        </div>
      </div>
    </Router>
  );
}

Compiled with 2.3.2

"use strict";
var __assign = (this && this.__assign) || Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
        s = arguments[i];
        for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
            t[p] = s[p];
    }
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
function render(Router, routerArgs) {
    return (React.createElement(Router, __assign({}, routerArgs),
        React.createElement("div", null,
            React.createElement("div", null,
                React.createElement(title_component_tsx_1.TitleComponent, null)),
            React.createElement("div", null,
                React.createElement(body_component_tsx_1.BodyComponent, null)))));
}
exports.default = render;

As you can see import was removed from compiled JS, but if i assign these components to a variable - everything works fine.

import * as React from "react";

import { TitleComponent } from './title.component.tsx';
import { BodyComponent } from './body.component.tsx';

const a = TitleComponent;
const b = BodyComponent;

export default function render(Router:any, routerArgs) {
  return (
    <Router {...routerArgs}>
      <div>
        <div>
          <TitleComponent />
        </div>
        <div>
          <BodyComponent />
        </div>
      </div>
    </Router>
  );
}

compiles into

"use strict";
var __assign = (this && this.__assign) || Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
        s = arguments[i];
        for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
            t[p] = s[p];
    }
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
var title_component_tsx_1 = require("./title.component.tsx");
var body_component_tsx_1 = require("./body.component.tsx");
var a = title_component_tsx_1.TitleComponent;
var b = body_component_tsx_1.BodyComponent;
function render(Router, routerArgs) {
    return (React.createElement(Router, __assign({}, routerArgs),
        React.createElement("div", null,
            React.createElement("div", null,
                React.createElement(title_component_tsx_1.TitleComponent, null)),
            React.createElement("div", null,
                React.createElement(body_component_tsx_1.BodyComponent, null)))));
}
exports.default = render;

Version 2.3.0 works fine even without assigning to dummy vars, so it looks like regression.

Compiled with 2.3.0

"use strict";
var __assign = (this && this.__assign) || Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
        s = arguments[i];
        for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
            t[p] = s[p];
    }
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
var title_component_tsx_1 = require("./title.component.tsx");
var body_component_tsx_1 = require("./body.component.tsx");
function render(Router, routerArgs) {
    return (React.createElement(Router, __assign({}, routerArgs),
        React.createElement("div", null,
            React.createElement("div", null,
                React.createElement(title_component_tsx_1.TitleComponent, null)),
            React.createElement("div", null,
                React.createElement(body_component_tsx_1.BodyComponent, null)))));
}
exports.default = render;

Expected behavior:
To have

var title_component_tsx_1 = require("./title.component.tsx");
var body_component_tsx_1 = require("./body.component.tsx");

Actual behavior:
Import of components was removed from compiled file.

@mhegazy
Copy link
Contributor

mhegazy commented May 17, 2017

Duplicate of #15469. should be fixed in TS 2.3 (out later this week). the fix should already be in typescript@next please give it a try and let us know if you still running into issues.

@mhegazy mhegazy closed this as completed May 17, 2017
@mhegazy mhegazy added the Duplicate An existing issue was already created label May 17, 2017
@yhorbachov
Copy link
Author

Confirm, typescript@next has no this issue.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants