1

Closed

Inconsistent output from compile on build and compile on save

description

When saving some sample files using Typescript's Compile-on-save feature, the output is different to the output from the output generated by building:

Specifically, imports seem to go missing when compiled through saving.

Typescript test file:

import Greeter = module("file1");
import Shooter = module("file2");

class Hello extends Greeter {
    hello() {
        return "Hello";
    }
}

var stuff = new Hello();
console.log(stuff.greet(), stuff.hello(), "World");

var test2 = <Shooter><any> {};

console.log(test2);
console.log(test2.shoot);

JavaScript output (highlighting the lines that do not exist when saved):
var __extends = this.__extends || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    __.prototype = b.prototype;
    d.prototype = new __();
};
var Greeter = require("./file1"); // <-- This line does not exist
var Shooter = require("./file2"); // <-- This line does not exist

var Hello = (function (_super) {
    __extends(Hello, _super);
    function Hello() {
        _super.apply(this, arguments);
    }
    Hello.prototype.hello = function () {
        return "Hello";
    };
    return Hello;
})(Greeter);

var stuff = new Hello();
console.log(stuff.greet(), stuff.hello(), "World");

var test2 = {};

console.log(test2);
console.log(test2.shoot);

//@ sourceMappingURL=app.js.map

When using the 0.8 compiler, I was under the impression that imports that were only used for adding types to variables were removed from the compiled code, and imports that were used directly (through direct access or through inheritance) were not removed, however the above example seems to not follow either of those conventions.

I have attached the entire solution which was used to build the app.

Any feedback appreciated!

Griffork.

file attachments

Closed Jul 18, 2013 at 2:19 AM by danquirk
This has been fixed

comments

Griffork wrote Jul 3, 2013 at 5:23 AM

I forgot to add: This issue appears in Typescript 0.9.0 and 0.9.0.1 for me (I upgraded during the testing of this issue to see if the update had fixed it).

danquirk wrote Jul 3, 2013 at 10:10 PM

Thanks for the report. Your understanding of emit for imports is correct, compile on save must be failing to consider the full scope of the project that the file is in or something. Marked as active.