From 2920f8280452f38f2478c30976f6a5fa0c55ab96 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 13 Oct 2016 16:54:09 -0700 Subject: [PATCH] Add error reporting for using `--noImplicitUseStrict` with `--options.alwaysStrict` --- src/compiler/program.ts | 4 +++ .../reference/alwaysStrictModule2.errors.txt | 22 ++++++++++++ .../reference/alwaysStrictModule2.js | 34 +++++++++++++++++++ ...alwaysStrictNoImplicitUseStrict.errors.txt | 2 ++ tests/cases/compiler/alwaysStrictModule2.ts | 16 +++++++++ 5 files changed, 78 insertions(+) create mode 100644 tests/baselines/reference/alwaysStrictModule2.errors.txt create mode 100644 tests/baselines/reference/alwaysStrictModule2.js create mode 100644 tests/cases/compiler/alwaysStrictModule2.ts diff --git a/src/compiler/program.ts b/src/compiler/program.ts index a52ffc85452..9404be2127e 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1473,6 +1473,10 @@ namespace ts { programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "lib", "noLib")); } + if (options.noImplicitUseStrict && options.alwaysStrict) { + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noImplicitUseStrict", "alwaysStrict")); + } + const languageVersion = options.target || ScriptTarget.ES3; const outFile = options.outFile || options.out; diff --git a/tests/baselines/reference/alwaysStrictModule2.errors.txt b/tests/baselines/reference/alwaysStrictModule2.errors.txt new file mode 100644 index 00000000000..3980d24abfc --- /dev/null +++ b/tests/baselines/reference/alwaysStrictModule2.errors.txt @@ -0,0 +1,22 @@ +tests/cases/compiler/a.ts(4,13): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/compiler/b.ts(3,13): error TS1100: Invalid use of 'arguments' in strict mode. + + +==== tests/cases/compiler/a.ts (1 errors) ==== + + module M { + export function f() { + var arguments = []; + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. + } + } + +==== tests/cases/compiler/b.ts (1 errors) ==== + module M { + export function f2() { + var arguments = []; + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/alwaysStrictModule2.js b/tests/baselines/reference/alwaysStrictModule2.js new file mode 100644 index 00000000000..54f179ff10b --- /dev/null +++ b/tests/baselines/reference/alwaysStrictModule2.js @@ -0,0 +1,34 @@ +//// [tests/cases/compiler/alwaysStrictModule2.ts] //// + +//// [a.ts] + +module M { + export function f() { + var arguments = []; + } +} + +//// [b.ts] +module M { + export function f2() { + var arguments = []; + } +} + +//// [out.js] +"use strict"; +var M; +(function (M) { + function f() { + var arguments = []; + } + M.f = f; +})(M || (M = {})); +"use strict"; +var M; +(function (M) { + function f2() { + var arguments = []; + } + M.f2 = f2; +})(M || (M = {})); diff --git a/tests/baselines/reference/alwaysStrictNoImplicitUseStrict.errors.txt b/tests/baselines/reference/alwaysStrictNoImplicitUseStrict.errors.txt index d677ec9b4cb..8df1d76e546 100644 --- a/tests/baselines/reference/alwaysStrictNoImplicitUseStrict.errors.txt +++ b/tests/baselines/reference/alwaysStrictNoImplicitUseStrict.errors.txt @@ -1,6 +1,8 @@ +error TS5053: Option 'noImplicitUseStrict' cannot be specified with option 'alwaysStrict'. tests/cases/compiler/alwaysStrictNoImplicitUseStrict.ts(4,13): error TS1100: Invalid use of 'arguments' in strict mode. +!!! error TS5053: Option 'noImplicitUseStrict' cannot be specified with option 'alwaysStrict'. ==== tests/cases/compiler/alwaysStrictNoImplicitUseStrict.ts (1 errors) ==== module M { diff --git a/tests/cases/compiler/alwaysStrictModule2.ts b/tests/cases/compiler/alwaysStrictModule2.ts new file mode 100644 index 00000000000..6afecb0e770 --- /dev/null +++ b/tests/cases/compiler/alwaysStrictModule2.ts @@ -0,0 +1,16 @@ +// @alwaysStrict: true +// @outFile: out.js + +// @fileName: a.ts +module M { + export function f() { + var arguments = []; + } +} + +// @fileName: b.ts +module M { + export function f2() { + var arguments = []; + } +} \ No newline at end of file