Skip to content

Compile-on-save with typescriptservices.js from LKG drops module prefixes #2061

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
NoelAbrahams opened this issue Feb 18, 2015 · 8 comments
Closed
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@NoelAbrahams
Copy link

NoelAbrahams commented Feb 18, 2015

Hi,

I'm using VS 2015 CTP 5 and wanted to try out typescriptservices.js from LKG of 12-Feb-2015.

Code like the following:

// my.d.ts
declare module foo.bar {
  class Baz { }
}

When referenced from another project

/// <reference path='my.d.ts' />
module foo.bar {
      var baz = <any>Baz.prototype;
}

is compiling into

var foo;
(function (foo) {
    var bar;
    (function (bar) {
        var baz = /*bar.*/Baz.prototype; // missing prefix
    })(bar = foo.bar || (foo.bar = {}));
})(foo || (foo  = {}));

This is only a problem when compile is triggered via save - generates the correct JavaScript when building.

Edit

This is a little bit more involved: The combine JS into output file also needs to be set. The faulty JS is generated not when the code file itself is saved, but when a sibling file in the same project is saved (which would cause the combined file to be generated).

@danquirk danquirk added the Bug A bug in TypeScript label Feb 18, 2015
@mhegazy mhegazy modified the milestones: Community, TypeScript 1.5 Feb 20, 2015
@NoelAbrahams
Copy link
Author

This bug is present in 1.5 beta. I would have thought it's critical as it produces JavaScript that fails at runtime.

@mhegazy mhegazy assigned JsonFreeman and unassigned vladima May 7, 2015
@mhegazy mhegazy modified the milestones: TypeScript 1.5.2, TypeScript 1.6 May 7, 2015
@mhegazy
Copy link
Contributor

mhegazy commented May 7, 2015

@JsonFreeman can you take a look.

@JsonFreeman
Copy link
Contributor

@NoelAbrahams do you have noEmitOnError explicitly set to false in your project? I've investigated this with @vladima, but the only way we were able to reproduce it is to set noEmitOnError to false.

@mhegazy
Copy link
Contributor

mhegazy commented May 8, 2015

I got it to repro earlier today without any changes. You just need to create a project add two files as listed above set --out, touch both files and then save the one with declare module.

@vladima
Copy link
Contributor

vladima commented May 8, 2015

@mhegazy That is very interesting. What is special in scenario with '--out' is that you''ll trigger save in one file but during emit you'll examine the entire project. Crux of the problem: initial file will be typechecked however other files -- not so nodeLinks \ symbolLinks for them will not be populated -> incorrect emit. Why it works today: see line 215 in program.ts - here we call getPreEmitDiagnostics that will query semantic diagnostics for all files and so all files will be typechecked. However this function is called only if noEmitOnError flag is set. If it is not set then emit will almost always be incorrect and we've verified that.

@mhegazy
Copy link
Contributor

mhegazy commented May 8, 2015

That makes sense.. --noEmitOnError is set in projects by default...

@JsonFreeman
Copy link
Contributor

@mhegazy This brings us back to the question, how did it repro for you if you had noEmitOnError turned on?

@JsonFreeman
Copy link
Contributor

@NoelAbrahams please try upgrading your VS with my fix, and see if it fixes your problem.

@JsonFreeman JsonFreeman added the Fixed A PR has been merged for this issue label May 8, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

5 participants