Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
4 changes: 2 additions & 2 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import {
FunctionExpression,
FunctionLikeDeclaration,
GetAccessorDeclaration,
getAlwaysStrict,
getAssignedExpandoInitializer,
getAssignmentDeclarationKind,
getAssignmentDeclarationPropertyAccessKind,
Expand All @@ -108,7 +109,6 @@ import {
getSourceFileOfNode,
getSourceTextOfNodeFromSourceFile,
getSpanOfTokenAtPosition,
getStrictOptionValue,
getSymbolNameForPrivateIdentifier,
getTextOfIdentifierOrLiteral,
getThisContainer,
Expand Down Expand Up @@ -617,7 +617,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
}

function bindInStrictMode(file: SourceFile, opts: CompilerOptions): boolean {
if (getStrictOptionValue(opts, "alwaysStrict") && !file.isDeclarationFile) {
if (getAlwaysStrict(opts) && !file.isDeclarationFile) {
// bind in strict mode source files with alwaysStrict option
return true;
}
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -987,10 +987,9 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
affectsSourceFile: true,
affectsEmit: true,
affectsBuildInfo: true,
strictFlag: true,
category: Diagnostics.Type_Checking,
description: Diagnostics.Ensure_use_strict_is_always_emitted,
defaultValueDescription: Diagnostics.false_unless_strict_is_set,
defaultValueDescription: true,
},

// Additional Checks
Expand Down
3 changes: 3 additions & 0 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4526,6 +4526,9 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
});

checkDeprecations("6.0", "7.0", createDiagnostic, createDeprecatedDiagnostic => {
if (options.alwaysStrict === false) {
createDeprecatedDiagnostic("alwaysStrict", "false", /*useInstead*/ undefined, /*related*/ undefined);
}
if (options.moduleResolution === ModuleResolutionKind.Node10) {
createDeprecatedDiagnostic("moduleResolution", "node10", /*useInstead*/ undefined, Diagnostics.Visit_https_Colon_Slash_Slashaka_ms_Slashts6_for_migration_information);
}
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/transformers/module/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
FunctionDeclaration,
FunctionExpression,
GeneratedIdentifierFlags,
getAlwaysStrict,
getEmitFlags,
getEmitModuleKind,
getEmitScriptTarget,
Expand All @@ -55,7 +56,6 @@ import {
getNamespaceDeclarationNode,
getNodeId,
getOriginalNodeId,
getStrictOptionValue,
getTextOfIdentifierOrLiteral,
hasJSFileExtension,
hasJsonModuleEmitEnabled,
Expand Down Expand Up @@ -277,7 +277,7 @@ export function transformModule(context: TransformationContext): (x: SourceFile
startLexicalEnvironment();

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

if (shouldEmitUnderscoreUnderscoreESModule()) {
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/transformers/module/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ import {
ForOfStatement,
ForStatement,
FunctionDeclaration,
getAlwaysStrict,
getEmitFlags,
getExternalHelpersModuleName,
getExternalModuleNameLiteral,
getLocalNameForExternalImport,
getNodeId,
getOriginalNode,
getOriginalNodeId,
getStrictOptionValue,
getTextOfIdentifierOrLiteral,
hasSyntacticModifier,
Identifier,
Expand Down Expand Up @@ -357,7 +357,7 @@ export function transformSystemModule(context: TransformationContext): (x: Sourc
startLexicalEnvironment();

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

// var __moduleName = context_1 && context_1.id;
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/transformers/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
FunctionExpression,
FunctionLikeDeclaration,
GetAccessorDeclaration,
getAlwaysStrict,
getEffectiveBaseTypeNode,
getEmitFlags,
getEmitModuleKind,
Expand All @@ -57,7 +58,6 @@ import {
getOriginalNode,
getParseTreeNode,
getProperties,
getStrictOptionValue,
getTextOfNode,
hasDecorators,
hasSyntacticModifier,
Expand Down Expand Up @@ -836,7 +836,7 @@ export function transformTypeScript(context: TransformationContext): Transformer
}

function visitSourceFile(node: SourceFile) {
const alwaysStrict = getStrictOptionValue(compilerOptions, "alwaysStrict") &&
const alwaysStrict = getAlwaysStrict(compilerOptions) &&
!(isExternalModule(node) && moduleKind >= ModuleKind.ES2015) &&
!isJsonSourceFile(node);

Expand Down
10 changes: 6 additions & 4 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2132,7 +2132,7 @@ export function isEffectiveStrictModeSourceFile(node: SourceFile, compilerOption
return false;
}
// If `alwaysStrict` is set, then treat the file as strict.
if (getStrictOptionValue(compilerOptions, "alwaysStrict")) {
if (getAlwaysStrict(compilerOptions)) {
return true;
}
// Starting with a "use strict" directive indicates the file is strict.
Expand Down Expand Up @@ -9203,10 +9203,11 @@ const _computedOptions = createComputedCompilerOptions({
return getStrictOptionValue(compilerOptions, "strictBuiltinIteratorReturn");
},
},
// Previously a strict-mode flag, but no longer.
alwaysStrict: {
dependencies: ["strict"],
dependencies: [],
computeValue: compilerOptions => {
return getStrictOptionValue(compilerOptions, "alwaysStrict");
return compilerOptions.alwaysStrict !== false;
},
},
useUnknownInCatchVariables: {
Expand Down Expand Up @@ -9254,6 +9255,8 @@ export const getAreDeclarationMapsEnabled: (compilerOptions: CompilerOptions) =>
export const getAllowJSCompilerOption: (compilerOptions: CompilerOptions) => boolean = _computedOptions.allowJs.computeValue;
/** @internal */
export const getUseDefineForClassFields: (compilerOptions: CompilerOptions) => boolean = _computedOptions.useDefineForClassFields.computeValue;
/** @internal */
export const getAlwaysStrict: (compilerOptions: CompilerOptions) => boolean = _computedOptions.alwaysStrict.computeValue;

/** @internal */
export function emitModuleKindIsNonNodeESM(moduleKind: ModuleKind): boolean {
Expand Down Expand Up @@ -9296,7 +9299,6 @@ export type StrictOptionName =
| "strictBindCallApply"
| "strictPropertyInitialization"
| "strictBuiltinIteratorReturn"
| "alwaysStrict"
| "useUnknownInCatchVariables";

/** @internal */
Expand Down
2 changes: 1 addition & 1 deletion src/testRunner/unittests/tscWatch/programUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1600,7 +1600,7 @@ foo().hello`,
},
{
caption: "Set always strict false",
edit: sys => sys.writeFile(`/user/username/projects/myproject/tsconfig.json`, jsonToReadableText({ compilerOptions: { strict: true, alwaysStrict: false } })), // Avoid changing 'alwaysStrict' or must re-bind
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
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
{
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/2dArrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Board {
}

//// [2dArrays.js]
"use strict";
var Cell = /** @class */ (function () {
function Cell() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var cl = Point();
var cl = Point.Origin;

//// [test.js]
"use strict";
var cl;
var cl = Point();
var cl = Point.Origin;
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var p = new A.Point(0, 0); // unexpected error here, bug 840000


//// [test.js]
"use strict";
var p;
var p = A.Point.Origin;
var p = new A.Point(0, 0); // unexpected error here, bug 840000
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var p = A.Point.Origin;
var p = new A.Point(0, 0); // unexpected error here, bug 840000

//// [classPoint.js]
"use strict";
var A;
(function (A) {
var Point = /** @class */ (function () {
Expand All @@ -35,6 +36,7 @@ var A;
A.Point = Point;
})(A || (A = {}));
//// [test.js]
"use strict";
var p;
var p = A.Point.Origin;
var p = new A.Point(0, 0); // unexpected error here, bug 840000
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ var cl = Point();
var cl = Point.Origin;

//// [function.js]
"use strict";
function Point() {
return { x: 0, y: 0 };
}
//// [test.js]
"use strict";
var cl;
var cl = Point();
var cl = Point.Origin;
1 change: 1 addition & 0 deletions tests/baselines/reference/ArrowFunction1.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ var v = (a: ) => {
};

//// [ArrowFunction1.js]
"use strict";
var v = function (a) {
};
1 change: 1 addition & 0 deletions tests/baselines/reference/ArrowFunction3.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var v = (a): => {
};

//// [ArrowFunction3.js]
"use strict";
var v = (a);
{
}
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/ArrowFunction4.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ var v = (a, b) => {
};

//// [ArrowFunction4.js]
"use strict";
var v = function (a, b) {
};
1 change: 1 addition & 0 deletions tests/baselines/reference/ArrowFunctionExpression1.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
var v = (public x: string) => { };

//// [ArrowFunctionExpression1.js]
"use strict";
var v = function (x) { };
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ namespace clodule4 {


//// [ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.js]
"use strict";
// all expected to be errors
var clodule1 = /** @class */ (function () {
function clodule1() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace clodule {


//// [ClassAndModuleThatMergeWithModulesExportedGenericFunctionAndGenericClassStaticFunctionOfTheSameName.js]
"use strict";
var clodule = /** @class */ (function () {
function clodule() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace clodule {


//// [ClassAndModuleThatMergeWithModulesExportedGenericFunctionAndNonGenericClassStaticFunctionOfTheSameName.js]
"use strict";
var clodule = /** @class */ (function () {
function clodule() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace clodule {


//// [ClassAndModuleThatMergeWithModulesExportedStaticFunctionUsingClassPrivateStatics.js]
"use strict";
var clodule = /** @class */ (function () {
function clodule() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace A {
}

//// [ClassAndModuleThatMergeWithStaticFunctionAndExportedFunctionThatShareAName.js]
"use strict";
var Point = /** @class */ (function () {
function Point(x, y) {
this.x = x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace A {
}

//// [ClassAndModuleThatMergeWithStaticFunctionAndNonExportedFunctionThatShareAName.js]
"use strict";
var Point = /** @class */ (function () {
function Point(x, y) {
this.x = x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace A {
}

//// [ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName.js]
"use strict";
var Point = /** @class */ (function () {
function Point(x, y) {
this.x = x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace A {
}

//// [ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName.js]
"use strict";
var Point = /** @class */ (function () {
function Point(x, y) {
this.x = x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@


//// [ClassAndModuleThatMergeWithStringIndexerAndExportedFunctionWithTypeIncompatibleWithIndexer.js]
"use strict";
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var a: { id: string };


//// [class.js]
"use strict";
var X;
(function (X) {
var Y;
Expand All @@ -56,6 +57,7 @@ var X;
})(Y = X.Y || (X.Y = {}));
})(X || (X = {}));
//// [module.js]
"use strict";
var X;
(function (X) {
var Y;
Expand All @@ -67,10 +69,12 @@ var X;
})(Y = X.Y || (X.Y = {}));
})(X || (X = {}));
//// [test.js]
"use strict";
//var cl: { x: number; y: number; }
var cl = new X.Y.Point(1, 1);
var cl = X.Y.Point.Origin; // error not expected here same as bug 83996 ?
//// [simple.js]
"use strict";
var A = /** @class */ (function () {
function A() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var a: { id: string };


//// [class.js]
"use strict";
var X;
(function (X) {
var Y;
Expand All @@ -55,6 +56,7 @@ var X;
})(Y = X.Y || (X.Y = {}));
})(X || (X = {}));
//// [module.js]
"use strict";
var X;
(function (X) {
var Y;
Expand All @@ -66,10 +68,12 @@ var X;
})(Y = X.Y || (X.Y = {}));
})(X || (X = {}));
//// [test.js]
"use strict";
//var cl: { x: number; y: number; }
var cl = new X.Y.Point(1, 1);
var cl = X.Y.Point.Origin; // error not expected here same as bug 83996 ?
//// [simple.js]
"use strict";
class A {
}
(function (A) {
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/ClassDeclaration10.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class C {
}

//// [ClassDeclaration10.js]
"use strict";
var C = /** @class */ (function () {
function C() {
}
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/ClassDeclaration11.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class C {
}

//// [ClassDeclaration11.js]
"use strict";
var C = /** @class */ (function () {
function C() {
}
Expand Down
Loading