-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Issues with order of files in combined output #1359
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
Comments
If I get the chance, I'll try to write a formal explanation (and I'll double-check what I'm writing here), but basically the idea is that the order in which the file is built is the order in which files get resolved and parsed. This is effectively a depth-first post-order traversal of the dependency tree. If a file has already been emitted, it won't be again. As an example, let's say you have the following files: file1.ts/// <reference path="file2.ts" />
function a() {
} file2.tsfunction b() {
} Now let's say you compile with the following:
Although function b() {
}
function a() {
} Hope that helps a bit; if you're still having trouble taming the output, I'd be willing to take a look at the general structure of your project. |
This is not the first time someone has run into an issue like this. It's possible that we need to expose some way for people to inspect the order that files are resolved via a compiler flag. |
Seems like on of those things other compilers would emit in |
A verbose mode for the Visual Studio plugin would also be very useful. I'm experiencing many cases of intellisense crashing, sticky red squiggles etc with no way to reproduce or report an error. |
@NoelAbrahams, a |
@DanielRosenwasser, perhaps the language service could write errors to the windows event log? There are a few code files where I'm consistently losing intellisense after a few minutes or so. I suspect it has something to do with circular dependencies, but because of the size of the source tree, I'm not able to reproduce the problem. I'm always happiest when I'm able to repro something! |
Worth considering; pinging @mhegazy. |
We have the errors showing in popups, but we suppress them in retail :) so may be the desired behavior here is a way to switch back to debug/dev mode. |
A pop up would be more useful than an error logged to the event log, because the former is better suited to identifying the activity that actually triggered the crash. If there is a way of editing |
It happened again today and it is related to the order of the files in the .csproj file. I auto-generate files into a new folder and then include all of them into the project at once. I have figured out that I can reorder the files in the csproj file to get the correct output but this should indicate a bug in Visual Studio right? |
csproj files are not order sensitive. there are no guarantees that order will be maintained. i would use _references.ts at the root to order these files. can you auto generate _references.ts as you generate the files? |
I did previously use the _references.ts file but ran into similar issues so I gave it up, and I did generate _import.ts files that were included into the main _references.ts file. |
The language service asks the project system (in this case csproj) for a list of files to include. csproj does not have a notion of order in project files, so it will return the list of files in the order of definition in the xml, this is prone to error as any addition, removal, move, rename can change the order, and the user has no way to manage or observe it from the UI. so we added _references.ts to allow for a way to inform the language service as well as msbuild (which also uses the csproj) about order. if you are doing --out, i would stick with _references.ts; if using _references still does not enforce order, then that is a bug that we need to look into. |
But shouldn't Visual Studio be able to at least handle the simple case that you have two files, Parent.ts and Subclass.ts, and order them correctly? |
It has been one of our axioms not to change user code. so we have always refrained from reordering user code. having said that, the compiler has enough information to at least tell you it is not going to work, or help you arrange the files. Issue #21 tracks the detection and flagging of use before definition cases. I think we should be able to get this in 1.5. |
But to reiterate, if you allow Visual Studio to manage the files that go into the output, Visual Studio should also try to order them correctly, anything else doesn't make sense (just my 2 cents). I suggest you try to get a TS project to behave as closely to a C# project as possible. |
I really whish this could be fixed. Typescript intellisense does not seem to have any problem at all infering the proper order. When the compiler, which has the option "Combine into one file" does not solve this, it renders larger js files upfront unreliable ... |
I understand that the typescript compiler in itself might be bound to reference-tags and imports, but do you know if there is any way to have Visual Studio do the dependency analysis and maintain a file like _references.ts automatically for all files in a project? The overhead of having to maintain reference-tags in all files in the project in order for it to compile properly is getting a little painful. Visual Studio seems capable enough to resolve the source for the implicit references that occur in a file, wouldn't it be a relatively small investment to have it doing a dependency analysis and updating a text file as well? |
Please implement the suggest automatic dependency analysis, maintaining a _references.ts in a large project is difficult. |
This may help: https://github.com/domchen/typescript-plus . The typescript-plus compiler is an enhanced version of the original typescript compiler, which provides extra features to the original typescript compiler, such as accessors optimization, class reflection, conditional compilation and the most useful one : automatically reordering the source files by analyzing their denpendencies in code. It is basicly the same to the original compiler on usage, for a documentation of how to use the extra options please see the README. |
Looks good @domchen! Do you plan to integrate the automatic ordering work back upstream into typescript? |
@haxiomic If the typescript team accepts this feature some day, I will be happy to integrate it back to the original typescript project. Util then, I will keep updating the typescript-plus project. |
Context: Visual Studio 2013 Ultimate w/ Update 4 with TS 1.3
I've got a TS project with 500+ files that compiled fine until today when I added a few new files. Now the order of the output file is messed up, parent class gets defined after subclass. I've tried both using a "_references.ts" file and without.
Where can I learn about how the compiler arranges the files when combining into one output file? Is there a trick how to force a certain file to be placed earlier? What would cause a parent class to placed after a subclass?
Hoping for some hints.
---bjorn
The text was updated successfully, but these errors were encountered: