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

Warn when a subset of input files have "use strict" with --outFile #11464

Closed
mattmccutchen opened this issue Oct 8, 2016 · 3 comments
Closed
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@mattmccutchen
Copy link
Contributor

As per #4270, the supported way to control strict mode when not using ES6 modules is to put "use strict"; at the top of the file. However, when the --outFile option is used to concatenate the emitted code for the input files into a single output file, the strict mode of the output file ends up being controlled by the first input file; attempting to enable strict mode on some input files and not others does not work. The compiler could warn if a user tries this by mistake.

TypeScript Version: 2.0.3

Code

// a.ts
"use strict";
var a = 1;
// b.ts
var b = 2;

tsc a.ts b.ts --outFile ab.js

Expected behavior: Semantic error: "Cannot enable strict mode on a subset of input files when using --outFile" or similar.

Actual behavior: No warning and the following output:

"use strict";
var a = 1;
var b = 2;

So strict mode is enabled on both input files, or neither if the order is reversed.

@RyanCavanaugh
Copy link
Member

I think #10758 would handle your use case? It's likely some people want to only have to write "use strict" at the top file in concatenated output, so I wouldn't want to break them.

@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Oct 10, 2016
@mattmccutchen
Copy link
Contributor Author

mattmccutchen commented Oct 10, 2016

I think #10758 would handle your use case?

Indeed. Thanks for the reference; I'm not having much success finding these existing issues myself. :(

It's likely some people want to only have to write "use strict" at the top file in concatenated output, so I wouldn't want to break them.

If a user does that, then all of the other files will use strict mode for the eventual parsing and execution by the JavaScript engine, but not for the parsing by the TypeScript compiler. Do you think that's a reasonable thing for a user to want? I don't think the inconsistency is reasonable.

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature and removed Needs More Info The issue still hasn't been fully clarified labels Oct 10, 2016
@mattmccutchen
Copy link
Contributor Author

I believe that while this is still a valid suggestion in principle, it almost certainly won't be worth implementing now that --alwaysStrict is implemented (note, not yet released), so closing. Comment if you disagree.

@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
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants