Skip to content

Commit 51fb7e9

Browse files
t-mrtweswigham
authored andcommitted
Add alwaysStrict option (#16562)
* Add alwaysStrict option * Enable alwaysStrict * Fix for strict mode * keep whitespace
1 parent 22f38b7 commit 51fb7e9

File tree

7 files changed

+37
-33
lines changed

7 files changed

+37
-33
lines changed

Jakefile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, opts
286286
var startCompileTime = mark();
287287
opts = opts || {};
288288
var compilerPath = useBuiltCompiler ? builtLocalCompiler : LKGCompiler;
289-
var options = "--noImplicitAny --noImplicitThis --noEmitOnError --types "
289+
var options = "--noImplicitAny --noImplicitThis --alwaysStrict --noEmitOnError --types "
290290
if (opts.types) {
291291
options += opts.types.join(",");
292292
}

src/harness/unittests/moduleResolution.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -950,8 +950,8 @@ import b = require("./moduleB");
950950
{
951951
const f1 = { name: "/root/src/app.ts" };
952952
const f2 = { name: "/root/src/types/lib/typings/lib.d.ts" };
953-
const package = { name: "/root/src/types/lib/package.json", content: JSON.stringify({ types: "typings/lib.d.ts" }) };
954-
test(/*typesRoot*/"/root/src/types", /* typeDirective */"lib", /*primary*/ true, f1, f2, package);
953+
const packageFile = { name: "/root/src/types/lib/package.json", content: JSON.stringify({ types: "typings/lib.d.ts" }) };
954+
test(/*typesRoot*/"/root/src/types", /* typeDirective */"lib", /*primary*/ true, f1, f2, packageFile);
955955
}
956956
{
957957
const f1 = { name: "/root/src/app.ts" };
@@ -961,8 +961,8 @@ import b = require("./moduleB");
961961
{
962962
const f1 = { name: "/root/src/app.ts" };
963963
const f2 = { name: "/root/src/node_modules/lib/typings/lib.d.ts" };
964-
const package = { name: "/root/src/node_modules/lib/package.json", content: JSON.stringify({ types: "typings/lib.d.ts" }) };
965-
test(/*typesRoot*/"/root/src/types", /* typeDirective */"lib", /*primary*/ false, f1, f2, package);
964+
const packageFile = { name: "/root/src/node_modules/lib/package.json", content: JSON.stringify({ types: "typings/lib.d.ts" }) };
965+
test(/*typesRoot*/"/root/src/types", /* typeDirective */"lib", /*primary*/ false, f1, f2, packageFile);
966966
}
967967
{
968968
const f1 = { name: "/root/src/app.ts" };
@@ -972,8 +972,8 @@ import b = require("./moduleB");
972972
{
973973
const f1 = { name: "/root/src/app.ts" };
974974
const f2 = { name: "/root/src/node_modules/@types/lib/typings/lib.d.ts" };
975-
const package = { name: "/root/src/node_modules/@types/lib/package.json", content: JSON.stringify({ types: "typings/lib.d.ts" }) };
976-
test(/*typesRoot*/"/root/src/types", /* typeDirective */"lib", /*primary*/ false, f1, f2, package);
975+
const packageFile = { name: "/root/src/node_modules/@types/lib/package.json", content: JSON.stringify({ types: "typings/lib.d.ts" }) };
976+
test(/*typesRoot*/"/root/src/types", /* typeDirective */"lib", /*primary*/ false, f1, f2, packageFile);
977977
}
978978
});
979979
it("Can be resolved from secondary location", () => {
@@ -990,8 +990,8 @@ import b = require("./moduleB");
990990
{
991991
const f1 = { name: "/root/src/app.ts" };
992992
const f2 = { name: "/root/node_modules/lib/typings/lib.d.ts" };
993-
const package = { name: "/root/node_modules/lib/package.json", content: JSON.stringify({ typings: "typings/lib.d.ts" }) };
994-
test(/*typesRoot*/"/root/src/types", /* typeDirective */"lib", /*primary*/ false, f1, f2, package);
993+
const packageFile = { name: "/root/node_modules/lib/package.json", content: JSON.stringify({ typings: "typings/lib.d.ts" }) };
994+
test(/*typesRoot*/"/root/src/types", /* typeDirective */"lib", /*primary*/ false, f1, f2, packageFile);
995995
}
996996
{
997997
const f1 = { name: "/root/src/app.ts" };
@@ -1001,8 +1001,8 @@ import b = require("./moduleB");
10011001
{
10021002
const f1 = { name: "/root/src/app.ts" };
10031003
const f2 = { name: "/root/node_modules/@types/lib/typings/lib.d.ts" };
1004-
const package = { name: "/root/node_modules/@types/lib/package.json", content: JSON.stringify({ typings: "typings/lib.d.ts" }) };
1005-
test(/*typesRoot*/"/root/src/types", /* typeDirective */"lib", /*primary*/ false, f1, f2, package);
1004+
const packageFile = { name: "/root/node_modules/@types/lib/package.json", content: JSON.stringify({ typings: "typings/lib.d.ts" }) };
1005+
test(/*typesRoot*/"/root/src/types", /* typeDirective */"lib", /*primary*/ false, f1, f2, packageFile);
10061006
}
10071007
});
10081008
it("Primary resolution overrides secondary resolutions", () => {

src/harness/unittests/textChanges.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -367,20 +367,22 @@ namespace M {
367367
changeTracker.insertNodeAfter(sourceFile, findChild("M", sourceFile), createTestClass(), { prefix: newLineCharacter });
368368
});
369369
}
370-
{
371-
function findOpenBraceForConstructor(sourceFile: SourceFile) {
372-
const classDecl = <ClassDeclaration>sourceFile.statements[0];
373-
const constructorDecl = forEach(classDecl.members, m => m.kind === SyntaxKind.Constructor && (<ConstructorDeclaration>m).body && <ConstructorDeclaration>m);
374-
return constructorDecl.body.getFirstToken();
375-
}
376-
function createTestSuperCall() {
377-
const superCall = createCall(
378-
createSuper(),
370+
371+
function findOpenBraceForConstructor(sourceFile: SourceFile) {
372+
const classDecl = <ClassDeclaration>sourceFile.statements[0];
373+
const constructorDecl = forEach(classDecl.members, m => m.kind === SyntaxKind.Constructor && (<ConstructorDeclaration>m).body && <ConstructorDeclaration>m);
374+
return constructorDecl.body.getFirstToken();
375+
}
376+
function createTestSuperCall() {
377+
const superCall = createCall(
378+
createSuper(),
379379
/*typeArguments*/ undefined,
380380
/*argumentsArray*/ emptyArray
381-
);
382-
return createStatement(superCall);
383-
}
381+
);
382+
return createStatement(superCall);
383+
}
384+
385+
{
384386
const text1 = `
385387
class A {
386388
constructor() {

src/harness/unittests/typingsInstaller.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ namespace ts.projectSystem {
10661066
path: "/a/app.js",
10671067
content: ""
10681068
};
1069-
const package = {
1069+
const packageFile = {
10701070
path: "/a/package.json",
10711071
content: JSON.stringify({ dependencies: { "commander": "1.0.0" } })
10721072
};
@@ -1075,7 +1075,7 @@ namespace ts.projectSystem {
10751075
path: cachePath + "node_modules/@types/commander/index.d.ts",
10761076
content: "export let x: number"
10771077
};
1078-
const host = createServerHost([f1, package]);
1078+
const host = createServerHost([f1, packageFile]);
10791079
let seenTelemetryEvent = false;
10801080
const installer = new (class extends Installer {
10811081
constructor() {
@@ -1115,7 +1115,7 @@ namespace ts.projectSystem {
11151115
path: "/a/app.js",
11161116
content: ""
11171117
};
1118-
const package = {
1118+
const packageFile = {
11191119
path: "/a/package.json",
11201120
content: JSON.stringify({ dependencies: { "commander": "1.0.0" } })
11211121
};
@@ -1124,7 +1124,7 @@ namespace ts.projectSystem {
11241124
path: cachePath + "node_modules/@types/commander/index.d.ts",
11251125
content: "export let x: number"
11261126
};
1127-
const host = createServerHost([f1, package]);
1127+
const host = createServerHost([f1, packageFile]);
11281128
let beginEvent: server.BeginInstallTypes;
11291129
let endEvent: server.EndInstallTypes;
11301130
const installer = new (class extends Installer {
@@ -1166,12 +1166,12 @@ namespace ts.projectSystem {
11661166
path: "/a/app.js",
11671167
content: ""
11681168
};
1169-
const package = {
1169+
const packageFile = {
11701170
path: "/a/package.json",
11711171
content: JSON.stringify({ dependencies: { "commander": "1.0.0" } })
11721172
};
11731173
const cachePath = "/a/cache/";
1174-
const host = createServerHost([f1, package]);
1174+
const host = createServerHost([f1, packageFile]);
11751175
let beginEvent: server.BeginInstallTypes;
11761176
let endEvent: server.EndInstallTypes;
11771177
const installer = new (class extends Installer {

src/server/tsconfig.library.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"compilerOptions": {
33
"noImplicitAny": true,
44
"noImplicitThis": true,
5+
"alwaysStrict": true,
56
"preserveConstEnums": true,
67
"pretty": true,
78
"outFile": "../../built/local/tsserverlibrary.js",

src/services/codefixes/fixClassSuperMustPrecedeThisAccess.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ namespace ts.codefix {
1919
// figure out if the `this` access is actually inside the supercall
2020
// i.e. super(this.a), since in that case we won't suggest a fix
2121
if (superCall.expression && superCall.expression.kind === SyntaxKind.CallExpression) {
22-
const arguments = (<CallExpression>superCall.expression).arguments;
23-
for (let i = 0; i < arguments.length; i++) {
24-
if ((<PropertyAccessExpression>arguments[i]).expression === token) {
22+
const expressionArguments = (<CallExpression>superCall.expression).arguments;
23+
for (let i = 0; i < expressionArguments.length; i++) {
24+
if ((<PropertyAccessExpression>expressionArguments[i]).expression === token) {
2525
return undefined;
2626
}
2727
}
@@ -46,4 +46,4 @@ namespace ts.codefix {
4646
}
4747
}
4848
});
49-
}
49+
}

src/tsconfig-base.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"noImplicitThis": true,
77
"noUnusedLocals": true,
88
"noUnusedParameters": true,
9+
"alwaysStrict": true,
910
"pretty": true,
1011
"preserveConstEnums": true,
1112
"stripInternal": true,

0 commit comments

Comments
 (0)