Skip to content

Commit c4b62ae

Browse files
committed
Fix bug when external options are changed
Add unit test
1 parent 52fc6c7 commit c4b62ae

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

compile-service-host.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ SH.getScriptFileNames = function() {
4747
}
4848
var typings = this.options.typings;
4949
if (typings) {
50-
rootFilePaths = rootFilePaths.concat(typings);
50+
_.each(typings, function(filePath) {
51+
if (! this.files[filePath]) {
52+
rootFilePaths.push(filePath);
53+
}
54+
}, this);
5155
}
5256
return rootFilePaths;
5357
};

index.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,23 @@ function lazyInit() {
5353
}
5454

5555
function TSBuild(filePaths, getFileContent, options) {
56-
validateAndConvertOptions(options);
56+
var resOptions = validateAndConvertOptions(options);
5757

5858
lazyInit();
5959

60-
if (! options)
61-
options = {compilerOptions: getConvertedDefault()};
60+
if (! resOptions)
61+
resOptions = {compilerOptions: getConvertedDefault()};
6262

63-
if (! options.compilerOptions)
64-
options.compilerOptions = getConvertedDefault();
63+
if (! resOptions.compilerOptions)
64+
resOptions.compilerOptions = getConvertedDefault();
6565

66-
this.options = options;
66+
this.options = resOptions;
6767

6868
sourceHost.setSource(getFileContent);
6969

70-
serviceHost.setFiles(filePaths, options);
70+
serviceHost.setFiles(filePaths, resOptions);
7171

72-
this.rebuildMap = getRebuildMap(filePaths, options);
72+
this.rebuildMap = getRebuildMap(filePaths, resOptions);
7373
}
7474

7575
function rebuildWithNewTypings(filePath, typings) {
@@ -183,7 +183,7 @@ function checkType(option, optionName) {
183183
}
184184

185185
function validateAndConvertOptions(options) {
186-
if (! options) return;
186+
if (! options) return null;
187187

188188
// Validate top level options.
189189
for (var option in options) {
@@ -200,11 +200,14 @@ function validateAndConvertOptions(options) {
200200
}
201201
}
202202

203+
var resOptions = _.clone(options);
203204
// Validate and convert compilerOptions.
204205
if (options.compilerOptions) {
205-
options.compilerOptions = convertCompilerOptionsOrThrow(
206+
resOptions.compilerOptions = convertCompilerOptionsOrThrow(
206207
options.compilerOptions);
207208
}
209+
210+
return resOptions;
208211
}
209212

210213
exports.validateAndConvertOptions = validateAndConvertOptions;

tests/ts.spec.js

+14
Original file line numberDiff line numberDiff line change
@@ -271,5 +271,19 @@ describe("meteor-typescript -> ", function() {
271271

272272
expect(result2.diagnostics.semanticErrors.length).toEqual(1);
273273
});
274+
275+
it("should handle ambient typings properly", function() {
276+
var foo11 = "declare module Foo { interface Test {}};";
277+
var foo12 = "var test: Foo.Test";
278+
279+
var build1 = new TSBuild(["foo11.d.ts", "foo12.ts"], function(filePath) {
280+
if (filePath === "foo11.d.ts") return foo11;
281+
if (filePath === "foo12.ts") return foo12;
282+
});
283+
284+
var result1 = build1.emit("foo12.ts");
285+
286+
expect(result1.diagnostics.semanticErrors.length).toEqual(0);
287+
});
274288
});
275289
});

0 commit comments

Comments
 (0)