Skip to content

Commit ffd1c3a

Browse files
Deprecate alwaysStrict: false (#63089)
1 parent 01c23d6 commit ffd1c3a

File tree

2,543 files changed

+22667
-2527
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,543 files changed

+22667
-2527
lines changed

src/compiler/binder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ import {
8282
FunctionExpression,
8383
FunctionLikeDeclaration,
8484
GetAccessorDeclaration,
85+
getAlwaysStrict,
8586
getAssignedExpandoInitializer,
8687
getAssignmentDeclarationKind,
8788
getAssignmentDeclarationPropertyAccessKind,
@@ -108,7 +109,6 @@ import {
108109
getSourceFileOfNode,
109110
getSourceTextOfNodeFromSourceFile,
110111
getSpanOfTokenAtPosition,
111-
getStrictOptionValue,
112112
getSymbolNameForPrivateIdentifier,
113113
getTextOfIdentifierOrLiteral,
114114
getThisContainer,
@@ -618,7 +618,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
618618
}
619619

620620
function bindInStrictMode(file: SourceFile, opts: CompilerOptions): boolean {
621-
if (getStrictOptionValue(opts, "alwaysStrict") && !file.isDeclarationFile) {
621+
if (getAlwaysStrict(opts) && !file.isDeclarationFile) {
622622
// bind in strict mode source files with alwaysStrict option
623623
return true;
624624
}

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -987,10 +987,9 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
987987
affectsSourceFile: true,
988988
affectsEmit: true,
989989
affectsBuildInfo: true,
990-
strictFlag: true,
991990
category: Diagnostics.Type_Checking,
992991
description: Diagnostics.Ensure_use_strict_is_always_emitted,
993-
defaultValueDescription: Diagnostics.false_unless_strict_is_set,
992+
defaultValueDescription: true,
994993
},
995994

996995
// Additional Checks

src/compiler/program.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4526,6 +4526,9 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
45264526
});
45274527

45284528
checkDeprecations("6.0", "7.0", createDiagnostic, createDeprecatedDiagnostic => {
4529+
if (options.alwaysStrict === false) {
4530+
createDeprecatedDiagnostic("alwaysStrict", "false", /*useInstead*/ undefined, /*related*/ undefined);
4531+
}
45294532
if (options.target === ScriptTarget.ES5) {
45304533
createDeprecatedDiagnostic("target", "ES5");
45314534
}

src/compiler/transformers/module/module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
FunctionDeclaration,
4242
FunctionExpression,
4343
GeneratedIdentifierFlags,
44+
getAlwaysStrict,
4445
getEmitFlags,
4546
getEmitModuleKind,
4647
getEmitScriptTarget,
@@ -55,7 +56,6 @@ import {
5556
getNamespaceDeclarationNode,
5657
getNodeId,
5758
getOriginalNodeId,
58-
getStrictOptionValue,
5959
getTextOfIdentifierOrLiteral,
6060
hasJSFileExtension,
6161
hasJsonModuleEmitEnabled,
@@ -277,7 +277,7 @@ export function transformModule(context: TransformationContext): (x: SourceFile
277277
startLexicalEnvironment();
278278

279279
const statements: Statement[] = [];
280-
const ensureUseStrict = getStrictOptionValue(compilerOptions, "alwaysStrict") || isExternalModule(currentSourceFile);
280+
const ensureUseStrict = getAlwaysStrict(compilerOptions) || isExternalModule(currentSourceFile);
281281
const statementOffset = factory.copyPrologue(node.statements, statements, ensureUseStrict && !isJsonSourceFile(node), topLevelVisitor);
282282

283283
if (shouldEmitUnderscoreUnderscoreESModule()) {

src/compiler/transformers/module/system.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ import {
3333
ForOfStatement,
3434
ForStatement,
3535
FunctionDeclaration,
36+
getAlwaysStrict,
3637
getEmitFlags,
3738
getExternalHelpersModuleName,
3839
getExternalModuleNameLiteral,
3940
getLocalNameForExternalImport,
4041
getNodeId,
4142
getOriginalNode,
4243
getOriginalNodeId,
43-
getStrictOptionValue,
4444
getTextOfIdentifierOrLiteral,
4545
hasSyntacticModifier,
4646
Identifier,
@@ -357,7 +357,7 @@ export function transformSystemModule(context: TransformationContext): (x: Sourc
357357
startLexicalEnvironment();
358358

359359
// Add any prologue directives.
360-
const ensureUseStrict = getStrictOptionValue(compilerOptions, "alwaysStrict") || isExternalModule(currentSourceFile);
360+
const ensureUseStrict = getAlwaysStrict(compilerOptions) || isExternalModule(currentSourceFile);
361361
const statementOffset = factory.copyPrologue(node.statements, statements, ensureUseStrict, topLevelVisitor);
362362

363363
// var __moduleName = context_1 && context_1.id;

src/compiler/transformers/ts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {
4747
FunctionExpression,
4848
FunctionLikeDeclaration,
4949
GetAccessorDeclaration,
50+
getAlwaysStrict,
5051
getEffectiveBaseTypeNode,
5152
getEmitFlags,
5253
getEmitModuleKind,
@@ -57,7 +58,6 @@ import {
5758
getOriginalNode,
5859
getParseTreeNode,
5960
getProperties,
60-
getStrictOptionValue,
6161
getTextOfNode,
6262
hasDecorators,
6363
hasSyntacticModifier,
@@ -836,7 +836,7 @@ export function transformTypeScript(context: TransformationContext): Transformer
836836
}
837837

838838
function visitSourceFile(node: SourceFile) {
839-
const alwaysStrict = getStrictOptionValue(compilerOptions, "alwaysStrict") &&
839+
const alwaysStrict = getAlwaysStrict(compilerOptions) &&
840840
!(isExternalModule(node) && moduleKind >= ModuleKind.ES2015) &&
841841
!isJsonSourceFile(node);
842842

src/compiler/utilities.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,7 +2132,7 @@ export function isEffectiveStrictModeSourceFile(node: SourceFile, compilerOption
21322132
return false;
21332133
}
21342134
// If `alwaysStrict` is set, then treat the file as strict.
2135-
if (getStrictOptionValue(compilerOptions, "alwaysStrict")) {
2135+
if (getAlwaysStrict(compilerOptions)) {
21362136
return true;
21372137
}
21382138
// Starting with a "use strict" directive indicates the file is strict.
@@ -9212,10 +9212,11 @@ const _computedOptions = createComputedCompilerOptions({
92129212
return getStrictOptionValue(compilerOptions, "strictBuiltinIteratorReturn");
92139213
},
92149214
},
9215+
// Previously a strict-mode flag, but no longer.
92159216
alwaysStrict: {
9216-
dependencies: ["strict"],
9217+
dependencies: [],
92179218
computeValue: compilerOptions => {
9218-
return getStrictOptionValue(compilerOptions, "alwaysStrict");
9219+
return compilerOptions.alwaysStrict !== false;
92199220
},
92209221
},
92219222
useUnknownInCatchVariables: {
@@ -9263,6 +9264,8 @@ export const getAreDeclarationMapsEnabled: (compilerOptions: CompilerOptions) =>
92639264
export const getAllowJSCompilerOption: (compilerOptions: CompilerOptions) => boolean = _computedOptions.allowJs.computeValue;
92649265
/** @internal */
92659266
export const getUseDefineForClassFields: (compilerOptions: CompilerOptions) => boolean = _computedOptions.useDefineForClassFields.computeValue;
9267+
/** @internal */
9268+
export const getAlwaysStrict: (compilerOptions: CompilerOptions) => boolean = _computedOptions.alwaysStrict.computeValue;
92669269

92679270
/** @internal */
92689271
export function emitModuleKindIsNonNodeESM(moduleKind: ModuleKind): boolean {
@@ -9305,7 +9308,6 @@ export type StrictOptionName =
93059308
| "strictBindCallApply"
93069309
| "strictPropertyInitialization"
93079310
| "strictBuiltinIteratorReturn"
9308-
| "alwaysStrict"
93099311
| "useUnknownInCatchVariables";
93109312

93119313
/** @internal */

src/testRunner/unittests/tscWatch/programUpdates.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,7 @@ foo().hello`,
16001600
},
16011601
{
16021602
caption: "Set always strict false",
1603-
edit: sys => sys.writeFile(`/user/username/projects/myproject/tsconfig.json`, jsonToReadableText({ compilerOptions: { strict: true, alwaysStrict: false } })), // Avoid changing 'alwaysStrict' or must re-bind
1603+
edit: sys => sys.writeFile(`/user/username/projects/myproject/tsconfig.json`, jsonToReadableText({ compilerOptions: { strict: true, alwaysStrict: false, ignoreDeprecations: "6.0" } })), // Avoid changing 'alwaysStrict' or must re-bind
16041604
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
16051605
},
16061606
{

tests/baselines/reference/ArrowFunction4.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ var v = (a, b) => {
66
};
77

88
//// [ArrowFunction4.js]
9+
"use strict";
910
var v = (a, b) => {
1011
};

tests/baselines/reference/ClassDeclaration10.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ class C {
77
}
88

99
//// [ClassDeclaration10.js]
10+
"use strict";
1011
class C {
1112
}

0 commit comments

Comments
 (0)