Skip to content

Commit 6327013

Browse files
committed
Detach alwaysStrict from strict
1 parent 9144da6 commit 6327013

10,742 files changed

Lines changed: 40303 additions & 26989 deletions

File tree

Some content is hidden

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

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,
@@ -617,7 +617,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
617617
}
618618

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

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/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.
@@ -9203,10 +9203,11 @@ const _computedOptions = createComputedCompilerOptions({
92039203
return getStrictOptionValue(compilerOptions, "strictBuiltinIteratorReturn");
92049204
},
92059205
},
9206+
// Previously a strict-mode flag, but no longer.
92069207
alwaysStrict: {
9207-
dependencies: ["strict"],
9208+
dependencies: [],
92089209
computeValue: compilerOptions => {
9209-
return getStrictOptionValue(compilerOptions, "alwaysStrict");
9210+
return compilerOptions.alwaysStrict !== false;
92109211
},
92119212
},
92129213
useUnknownInCatchVariables: {
@@ -9254,6 +9255,8 @@ export const getAreDeclarationMapsEnabled: (compilerOptions: CompilerOptions) =>
92549255
export const getAllowJSCompilerOption: (compilerOptions: CompilerOptions) => boolean = _computedOptions.allowJs.computeValue;
92559256
/** @internal */
92569257
export const getUseDefineForClassFields: (compilerOptions: CompilerOptions) => boolean = _computedOptions.useDefineForClassFields.computeValue;
9258+
/** @internal */
9259+
export const getAlwaysStrict: (compilerOptions: CompilerOptions) => boolean = _computedOptions.alwaysStrict.computeValue;
92579260

92589261
/** @internal */
92599262
export function emitModuleKindIsNonNodeESM(moduleKind: ModuleKind): boolean {
@@ -9296,7 +9299,6 @@ export type StrictOptionName =
92969299
| "strictBindCallApply"
92979300
| "strictPropertyInitialization"
92989301
| "strictBuiltinIteratorReturn"
9299-
| "alwaysStrict"
93009302
| "useUnknownInCatchVariables";
93019303

93029304
/** @internal */

tests/baselines/reference/2dArrays.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Board {
1818
}
1919

2020
//// [2dArrays.js]
21+
"use strict";
2122
var Cell = /** @class */ (function () {
2223
function Cell() {
2324
}

tests/baselines/reference/AmbientModuleAndAmbientFunctionWithTheSameNameAndCommonRoot.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var cl = Point();
1414
var cl = Point.Origin;
1515

1616
//// [test.js]
17+
"use strict";
1718
var cl;
1819
var cl = Point();
1920
var cl = Point.Origin;

tests/baselines/reference/AmbientModuleAndAmbientWithSameNameAndCommonRoot.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var p = new A.Point(0, 0); // unexpected error here, bug 840000
2626

2727

2828
//// [test.js]
29+
"use strict";
2930
var p;
3031
var p = A.Point.Origin;
3132
var p = new A.Point(0, 0); // unexpected error here, bug 840000

tests/baselines/reference/AmbientModuleAndNonAmbientClassWithSameNameAndCommonRoot.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var p = A.Point.Origin;
2323
var p = new A.Point(0, 0); // unexpected error here, bug 840000
2424

2525
//// [classPoint.js]
26+
"use strict";
2627
var A;
2728
(function (A) {
2829
var Point = /** @class */ (function () {
@@ -35,6 +36,7 @@ var A;
3536
A.Point = Point;
3637
})(A || (A = {}));
3738
//// [test.js]
39+
"use strict";
3840
var p;
3941
var p = A.Point.Origin;
4042
var p = new A.Point(0, 0); // unexpected error here, bug 840000

0 commit comments

Comments
 (0)