Skip to content

import statements are transpiled even if output is set to ES6 #5110

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

Closed
tomitrescak opened this issue Oct 5, 2015 · 18 comments
Closed

import statements are transpiled even if output is set to ES6 #5110

tomitrescak opened this issue Oct 5, 2015 · 18 comments
Labels
Needs More Info The issue still hasn't been fully clarified

Comments

@tomitrescak
Copy link

Hi

Up until latest update my es6 imports were left the way they was when transpilig to es6.
From the latest update now they are transpiled to the module representation.

For example:

import TabControl from "../../components/tabs/tab_control";

is transpiled to

var tab_control_1 = require("../../components/tabs/tab_control");

The worst part is, that it breaks the TSX transpilation as for example

  <TabControl tabs={this.state.tabs}>
            {
              this.props.validations.map((validation: BoardValidation, index: number) => {
                return <BoardValidationView key={index} />
              })
            }
</TabControl>

is transpiled to:

<tab_control_1.default tabs={this.state.tabs}>
            {this.props.validations.map((validation, index) => {
            return <BoardValidationView key={index} />;
        })}
          </TabControl>

Note how the closing tag is not transpiled.

This is probably bug in transpilation, but can the transpilation of import statements be disabled? Up until today all was working well ... now none of my TS project runs ;((

For completeness, here is my tsconfig

{
    "compilerOptions": {
        "target": "es6",
        "declaration": false,
        "noImplicitAny": true,
        "removeComments": false,
        "noLib": false,
        "preserveConstEnums": true,
        "noEmitHelpers": true,
        "suppressImplicitAnyIndexErrors": true,
        "watch": true,
        "outDir": "../dist",
        "jsx": "preserve"
    },
...
}
@sandersn
Copy link
Member

sandersn commented Oct 5, 2015

What version did the latest update give you? I tried the following code with 1.6.2:

import TabControl from "tab_control";
let t = new TabControl();

With a file named tab_control.ts:

class TabControl {
    // nothing here
}
export default TabControl;

And using your tsconfig, I got the below output:

import TabControl from "tab_control";
let t = new TabControl();

@mhegazy mhegazy added the Needs More Info The issue still hasn't been fully clarified label Oct 5, 2015
@weswigham weswigham changed the title import statements are transpired even if output is set to ES6 import statements are transpiled even if output is set to ES6 Oct 5, 2015
@basarat
Copy link
Contributor

basarat commented Oct 6, 2015

What version did the latest update give you?

The version from master two days ago.

Tracked from atom-typescript package.json to this version

The bug was not in this version : git tag and not in 1.6 either (which is even older).

@mhegazy
Copy link
Contributor

mhegazy commented Oct 6, 2015

@basarat do you have a reproduction of this issue that you can share?

@basarat
Copy link
Contributor

basarat commented Oct 6, 2015

Original issue report TypeStrong/atom-typescript#643 But I'll test more ... see below:

do you have a reproduction of this issue that you can share?

Quick test with [email protected] yielded valid results :

image

I'll investigate further the next time I upgrade and comment. Sorry about a possibly invalid issue 🌹

@basarat
Copy link
Contributor

basarat commented Oct 6, 2015

@tomitrescak can you share a sample ... Would save me some time as another user had the same issue 🌹

@tomitrescak
Copy link
Author

Dears, unfortunatelly it only happened in that given version of Atom Typescript.
I tried to replicate in console but no luck. Am glad that someone else experience the same issue so that I'm not crazey ... ;)

screen shot 2015-10-06 at 20 03 22

@DeusProx
Copy link

Hello I got the same problem.
I'm using tsc 1.6.2 in terminal which is compiling fine but using atom-typescript 7.6.3 with the following tscconfig doesn't compile correctly to es6 (require instead of import):

{
    "version": "1.6.2",
    "compileOnSave": true,
    "compilerOptions": {
        "target": "es6",
        "declaration": false,
        "noImplicitAny": false,
        "removeComments": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "noLib": false,
        "outDir": "build"
    },
    "filesGlob": [       ...many.....    ],
    "files": [  ....many.....   ],
    "exclude": []
}

Previously it worked with an older version of atom-typescript on my laptop. On my pc i'm still using 7.4.3 and everything works fine.

I also tried ntypescript(1.8.0) and it also transpiled correctly.

@basarat
Copy link
Contributor

basarat commented Oct 30, 2015

Note: @Chocoloper tried with the command line (same version of ntypescript) and it works fine :-/

@Chocoloper can you share some simple files for my testing

@DeusProx
Copy link

I made a small example. Take a look at the readme too see which versions I used and what the output was:
http://plnkr.co/edit/3ASb6cjkKf2CUJwhpp3p

basarat added a commit to TypeStrong/atom-typescript-examples that referenced this issue Oct 30, 2015
@basarat
Copy link
Contributor

basarat commented Oct 30, 2015

@Chocoloper Cheers. I have a repro

image

I suspect its because of a recent change where ES6 module compilation and ES6 general compilation were split (I think I saw an issue or PR regarding this but search is failing me).

In any case the sample project : https://github.com/TypeStrong/atom-typescript-examples/tree/master/bugs/643 if save in atom-ts a.js comes out with require instead of import from (since target is es6)

@basarat
Copy link
Contributor

basarat commented Oct 30, 2015

I've double checked that we are passing the right options to the language service:

image

2 is ES6:

    enum ScriptTarget {
        ES3 = 0,
        ES5 = 1,
        ES6 = 2,
        ES2015 = 2,
        Latest = 2,
    }

@weswigham
Copy link
Member

I see module is set to 1, though - and that would be commonjs.

basarat added a commit to TypeStrong/atom-typescript that referenced this issue Oct 30, 2015
@basarat
Copy link
Contributor

basarat commented Oct 30, 2015

I suspect its because of a recent change where ES6 module compilation and ES6 general compilation were split (I think I saw an issue or PR regarding this but search is failing me).

Found it : #4811

I see module is set to 1, though - and that would be commonjs.

@weswigham thanks for spotting that 🌹 I'll fix it.

@Chocoloper Use "module": "es6", as a quick workaround : https://github.com/TypeStrong/atom-typescript/releases/tag/v7.7.0

{
    "transpiler": "typescript",
    "compileOnSave": true,
    "compilerOptions": {
        "target": "es6",
        "module": "es6",
        "declaration": false,
        "noImplicitAny": false,
        "removeComments": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "noLib": false,
        "outDir": "build"
    }
}

@basarat
Copy link
Contributor

basarat commented Oct 30, 2015

From @tomitrescak's original comment

The worst part is, that it breaks the TSX transpilation as for example

would still be a bug if one does want to target ES6 but transpile modules to commonjs (perhaps others also) 🌹

@weswigham
Copy link
Member

I think that bug is specific to the JSXClosingTag, by the looks of it. The rest of the example is correct for commonjs emit. Possibly a kind of regression of what #4096 fixed?

@mhegazy
Copy link
Contributor

mhegazy commented Nov 13, 2015

@basarat is this still an issue?

@basarat
Copy link
Contributor

basarat commented Nov 13, 2015

@mhegazy nope, thanks! 🌹

@mhegazy
Copy link
Contributor

mhegazy commented Nov 13, 2015

thanks!

@mhegazy mhegazy closed this as completed Nov 13, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

6 participants