Skip to content

1.8: -m system --outFile foo.js should recognize files without exports as modules #6313

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
vivainio opened this issue Jan 1, 2016 · 1 comment
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript

Comments

@vivainio
Copy link

vivainio commented Jan 1, 2016

Background: I come from tsify, which treats files as modules even if you don't export anything from them, if the file is imported from elsewhere in the project.

I am trying to use the new bundling feature implemented in #5090.

I am doing this:

tsc -m system -t es5 --outFile dev/js/main.js .\App\app.ts

We have .ts files that don't have any exports; module system is used to impose execution order. E.g.

import './a';
import './b';

if a.ts or b.ts doesn't have any exports, System.register() wrapper is not generated for them. Instead, they are dumped to top level of main.js, and are executed immediately when script is loaded.

Proposed solution: promote all files that are imported somewhere to modules, regardless of whether they have exports or not. This is feasible for --outFile, since the compiler has global knowledge of everything that ends up in the emitted output file.

@mhegazy
Copy link
Contributor

mhegazy commented Jan 4, 2016

We can not do that safely as this would break single file compilation scenarios. consider cases where you are transpiling in the browser, the compiler only looks at one file at a time. deciding if a file is external module or not should only depend on the file and not on the global state. otherwise we get inconsistent output.
what tsify does is to pass --isolatedModules; doing so on the command line would give an error (which is ignored in the case of tsify) but will emit the expected code, not sure if that helps you though.

@mhegazy mhegazy added Suggestion An idea for TypeScript Declined The issue was declined as something which matches the TypeScript vision labels Jan 4, 2016
@mhegazy mhegazy closed this as completed Jan 8, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants