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

arrow function emit emit error #11377

Closed
basarat opened this issue Oct 5, 2016 · 26 comments
Closed

arrow function emit emit error #11377

basarat opened this issue Oct 5, 2016 · 26 comments
Assignees
Labels
Bug A bug in TypeScript Domain: Transforms Relates to the public transform API Fixed A PR has been merged for this issue

Comments

@basarat
Copy link
Contributor

basarat commented Oct 5, 2016

TypeScript Version: nightly latest

Code

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "noImplicitAny": false,
        "sourceMap": false,
        "lib": [
          "es6", "dom"
        ]
    },
    "exclude": [
        "node_modules"
    ]
}
const foo = (x: string) => null;

Expected behavior:

Gives js

var foo = function (x) { return null; };

Actual behavior:

var foo = function (x: string) { return null; };
@mhegazy mhegazy added the Bug A bug in TypeScript label Oct 5, 2016
@mhegazy mhegazy added this to the TypeScript 2.1 milestone Oct 5, 2016
@mhegazy mhegazy added the Domain: Transforms Relates to the public transform API label Oct 5, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Oct 5, 2016

@rbuckton can you take a look.

@rbuckton
Copy link
Member

rbuckton commented Oct 5, 2016

@basarat Is this the entire set of repro steps? I tried this locally and cannot repro this.

@mhegazy mhegazy added the Needs More Info The issue still hasn't been fully clarified label Oct 5, 2016
@basarat
Copy link
Contributor Author

basarat commented Oct 5, 2016

Is this the entire set of repro steps?

Sadly no. Seems to be an issue one with language service compile on save, stuff like semicolons etc can be used to trigger it to come in and go out. Same code can give different output depending on how the edits were made :-/

Made a quick video : https://www.youtube.com/watch?v=N4EgtjRnZGE 🌹

@rbuckton
Copy link
Member

rbuckton commented Oct 5, 2016

Thanks, I'll take a look at it.

@rbuckton
Copy link
Member

rbuckton commented Oct 7, 2016

In the video it looks like you're using VSCode. Are you using a .vscode/tasks.json and compiling with tsc in watch mode, or are you using grunt or gulp with a plugin? So far I'm still unable to reproduce this issue.

@rbuckton
Copy link
Member

rbuckton commented Oct 7, 2016

Or rather, is this Atom?

@jesseschalken
Copy link
Contributor

@rbuckton I think it's https://github.com/alm-tools/alm

@basarat
Copy link
Contributor Author

basarat commented Oct 7, 2016

I think it's https://github.com/alm-tools/alm

Yup.

@basarat
Copy link
Contributor Author

basarat commented Oct 7, 2016

@basarat
Copy link
Contributor Author

basarat commented Oct 7, 2016

I can repro in alm with just const foo = (x: string) => null => const foo = (x) => null;

With a simple tsconfig.json

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5"
    }
}

That said I ran the same with tsc -w and it doesn't happen, does that use languageService. getEmitOutput? 🌹

@basarat
Copy link
Contributor Author

basarat commented Oct 11, 2016

Looked at the tsserver and it uses the same function as me getFileEmitOutput : https://github.com/Microsoft/TypeScript/blob/3b0515fd8b8742d1c25c70642e853a9ed4e324c7/src/server/project.ts#L227-L232 and since you haven't been able to repro in vscode (which uses tsserver) I'll look into it a bit more 🌹

@basarat
Copy link
Contributor Author

basarat commented Oct 11, 2016

Guess compileOnSave isn't supported in tsserver yet : #10838 (comment) so I can't give you repro in vscode :-/

@basarat
Copy link
Contributor Author

basarat commented Oct 11, 2016

I've attached the project:

ts-emit-error.zip

Opening it in alm is easy npm install alm -g and then alm -o in the project folder.

The repro is simply changing const foo = (x: string) => "hello"; => const foo = (x: string) => "hello" => const foo = (x: string) => "hello"; and the x:string should start appearing in the output.

I added a log to getRawOutput function in alm locally as shown:

export function getRawOutput(proj: project.Project, filePath: string): ts.EmitOutput {
    let services = proj.languageService;
    let output: ts.EmitOutput = services.getEmitOutput(filePath);
    console.log({ input: services.getNonBoundSourceFile(filePath).getFullText(), output: output.outputFiles[0].text });
    return output;
}

You can see the annotation appear and disappear in the output of services.getEmitOutput in the screenshot below as you edit the file to add a ; :

image

Please let me know if there is still more info required 🌹

@basarat
Copy link
Contributor Author

basarat commented Oct 11, 2016

PS: thanks for your great work. async / await has already prevented some hacky stuff at work ❤️ 🌹

@basarat
Copy link
Contributor Author

basarat commented Oct 11, 2016

Update: I've pushed the fix in alm : alm-tools/alm@687c238 that uses the slow but correct ts.transpile to get around the problem. So you need npm install [email protected] -g for the repro on the sample project 🌹

@frankwallis
Copy link
Contributor

I have a similar issue to this where compile on save is not producing valid es5 output, I'm using

  • Visual Studio 2015 Professional Update 3
  • Microsoft.TypeScript.MSBuild v2.1.0-beta-20161008-1

Steps to reproduce:

  1. Build entire project verify that async/await is correctly transpiled to ES5
function loadAgendaItems(meetingId, listid) {
    var _this = this;
    return function (dispatch, getState) { return __awaiter(_this, void 0, void 0, function () {
        var meetingHub, agendaItemsResponse, err_1;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    _a.trys.push([0, 2, , 3]);
                    meetingHub = hubs_1.getMeetingHubServer();
                    return [4 /*yield*/, meetingHub.getAgendaItems(meetingId)];
                case 1:
                    agendaItemsResponse = _a.sent();
                    dispatch(repository_action_creators_1.repositoryPutNormalized(agendaItemsResponse.AgendaItems, data_types_1.DataTypes.AgendaItem, { dataType: data_types_1.DataTypes.Meeting, dataKey: meetingId }));
                    return [3 /*break*/, 3];
                case 2:
                    err_1 = _a.sent();
                    dispatch(notification_action_creators_1.growlError({ message: err_1.message }));
                    return [3 /*break*/, 3];
                case 3: return [2 /*return*/];
            }
        });
    }); };
}
  1. Edit function containing async/await
export function loadAgendaItems(meetingId: number, listid: any) {
    return async (dispatch: Dispatch<GlobalState>, getState: () => GlobalState) => {
        /* I added this comment */
        try {
            const meetingHub = getMeetingHubServer();
            const agendaItemsResponse = await meetingHub.getAgendaItems(meetingId);
            dispatch(repositoryPutNormalized(agendaItemsResponse.AgendaItems, DataTypes.AgendaItem, { dataType: DataTypes.Meeting, dataKey: meetingId }));
        } catch (err) {
            dispatch(growlError({ message: err.message }));
        }
    };
}
  1. Transpiled output now contains await keyword:
function loadAgendaItems(meetingId, listid) {
    var _this = this;
    return function (dispatch, getState) { return __awaiter(_this, void 0, void 0, function () {
        return __generator(this, function (_a) {
            /* I added this comment */
            try {
                const meetingHub = hubs_1.getMeetingHubServer();
                const agendaItemsResponse = await meetingHub.getAgendaItems(meetingId);
                dispatch(repository_action_creators_1.repositoryPutNormalized(agendaItemsResponse.AgendaItems, data_types_1.DataTypes.AgendaItem, { dataType: data_types_1.DataTypes.Meeting, dataKey: meetingId }));
            }
            catch (err) {
                dispatch(notification_action_creators_1.growlError({ message: err.message }));
            }
            return [2 /*return*/];
        });
    }); };
}

Let me know if you would like any more information, thanks

@mhegazy
Copy link
Contributor

mhegazy commented Oct 14, 2016

@frankwallis what version of TS are you using for VS? compile on save is not driven from the MSBuild nugget package.

@frankwallis
Copy link
Contributor

@mhegazy I have run the VSDevMode.ps1 script (as per here) and pointed it at my global npm typescript installation (in ...AppData/Roaming/npm/node_modules/typescript/lib) which is:

$ tsc -v
Version 2.1.0-dev.20161014

I reran the VSDevMode.ps1 script today and retried the steps above, and the same issue is present. Is there a way of verifying which version the language service is actually using?

@mhegazy
Copy link
Contributor

mhegazy commented Oct 17, 2016

Is there a way of verifying which version the language service is actually using?

This is sufficient information. thank you.

@frankwallis
Copy link
Contributor

frankwallis commented Oct 21, 2016

@mhegazy - can the "Needs More Info" label be removed now?

@mhegazy mhegazy added 2.1 RC and removed Needs More Info The issue still hasn't been fully clarified labels Oct 24, 2016
@mhegazy mhegazy removed this from the TypeScript 2.1 milestone Oct 27, 2016
@mhegazy mhegazy modified the milestones: TypeScript 2.1.2, TypeScript 2.1 Oct 27, 2016
@mhegazy mhegazy removed the 2.1 RC label Oct 27, 2016
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Nov 8, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Nov 8, 2016

@basarat can you give tonight's build a try.

@mhegazy
Copy link
Contributor

mhegazy commented Nov 8, 2016

@basarat have you had a chance to try the fix?

@basarat
Copy link
Contributor Author

basarat commented Nov 9, 2016

In Mexico 🇲🇽 for a conf. Will update once I try 🌹❤️

@mhegazy
Copy link
Contributor

mhegazy commented Nov 9, 2016

thanks.

@basarat
Copy link
Contributor Author

basarat commented Nov 14, 2016

I can no longer reproduce it with the latest nightly. Thanks! 🌹

basarat pushed a commit to alm-tools/alm that referenced this issue Nov 14, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Nov 14, 2016

thanks for conforming 🌷

@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
Bug A bug in TypeScript Domain: Transforms Relates to the public transform API Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

5 participants