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

0.4.2 compiles in an endless loop #76

Closed
AndreasPresthammer opened this issue Nov 10, 2014 · 3 comments
Closed

0.4.2 compiles in an endless loop #76

AndreasPresthammer opened this issue Nov 10, 2014 · 3 comments

Comments

@AndreasPresthammer
Copy link

0.4.1 seem to work fine, but the 0.4.2 compiles in an endless loop. It never finishes.

@k-maru
Copy link
Owner

k-maru commented Nov 10, 2014

I can not reproduce the error.
Please show the code to reproduce.

or

grunt --verbose option log

e.g. grunt typescript --verbose

@Coridyn
Copy link
Contributor

Coridyn commented Nov 12, 2014

I've just found this error too. The TypeScript compiler is writing all source files out multiple times (so for 100 input files it will write out 100 * 100 = 10,000 files).

Here is an example project showing the problem: https://github.com/Coridyn/grunt-typescript-debug

Expected output:

--host.writeFile: src/app.js
  write file: src/app.js => l:/User/projects/WidgetWorks/wiwo-playground/grunt-typescript-debug/dist/app.js
--host.writeFile: src/other-file.js
  write file: src/other-file.js => l:/User/projects/WidgetWorks/wiwo-playground/grunt-typescript-debug/dist/other-file.js
2 files created. js: 2 files, map: 0 files, declaration: 0 files

Actual output:

--host.writeFile: src/app.js
  write file: src/app.js => l:/User/projects/WidgetWorks/wiwo-playground/grunt-typescript-debug/dist/app.js
--host.writeFile: src/other-file.js
  write file: src/other-file.js => l:/User/projects/WidgetWorks/wiwo-playground/grunt-typescript-debug/dist/other-file.js
--host.writeFile: src/app.js
  write file: src/app.js => l:/User/projects/WidgetWorks/wiwo-playground/grunt-typescript-debug/dist/app.js
--host.writeFile: src/other-file.js
  write file: src/other-file.js => l:/User/projects/WidgetWorks/wiwo-playground/grunt-typescript-debug/dist/other-file.js
--host.writeFile: src/app.js
  write file: src/app.js => l:/User/projects/WidgetWorks/wiwo-playground/grunt-typescript-debug/dist/app.js
--host.writeFile: src/other-file.js
  write file: src/other-file.js => l:/User/projects/WidgetWorks/wiwo-playground/grunt-typescript-debug/dist/other-file.js
6 files created. js: 6 files, map: 0 files, declaration: 0 files (492ms)

It looks like typescript.js compile() function (https://github.com/k-maru/grunt-typescript/blob/master/tasks/typescript.js#L738) calls checker.emitFiles() for every file.

program.getSourceFiles().forEach(function (sourceFile) {
    if (!options.noLib && sourceFile.filename === defaultLibFilename) {
        return;
    }
    var emitOutput = checker.emitFiles(sourceFile);
    errors.push.apply(errors, emitOutput.errors);
});

and tsc.js emitFiles() (https://github.com/Microsoft/TypeScript/blob/v1.1.0.1/bin/tsc.js#L8496) calls emitFile() for every file as well

ts.forEach(program.getSourceFiles(), function (sourceFile) {
    if (shouldEmitToOwnFile(sourceFile)) {
        var jsFilePath = getOwnEmitOutputFilePath(sourceFile, ".js");
        emitFile(jsFilePath, sourceFile);
    }
});

@k-maru
Copy link
Owner

k-maru commented Nov 12, 2014

Thanks Coridyn.

It seems that my reading was not enough.
I has released a modified version 0.4.3

@k-maru k-maru closed this as completed Nov 12, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants