Skip to content
Closed
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 @@ -618,7 +618,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
5 changes: 2 additions & 3 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
showInSimplifiedHelpView: true,
category: Diagnostics.Type_Checking,
description: Diagnostics.Enable_all_strict_type_checking_options,
defaultValueDescription: false,
defaultValueDescription: true,
},
{
name: "noImplicitAny",
Expand Down 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.target === ScriptTarget.ES5) {
createDeprecatedDiagnostic("target", "ES5");
}
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
12 changes: 7 additions & 5 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 @@ -9212,10 +9212,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 @@ -9263,6 +9264,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 @@ -9305,12 +9308,11 @@ export type StrictOptionName =
| "strictBindCallApply"
| "strictPropertyInitialization"
| "strictBuiltinIteratorReturn"
| "alwaysStrict"
| "useUnknownInCatchVariables";

/** @internal */
export function getStrictOptionValue(compilerOptions: CompilerOptions, flag: StrictOptionName): boolean {
return compilerOptions[flag] === undefined ? !!compilerOptions.strict : !!compilerOptions[flag];
return compilerOptions[flag] === undefined ? (compilerOptions.strict !== false) : !!compilerOptions[flag];
}

/** @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";
class Cell {
}
class Ship {
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/2dArrays.types
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ class Board {
ships: Ship[] = [];
>ships : Ship[]
> : ^^^^^^
>[] : undefined[]
> : ^^^^^^^^^^^
>[] : never[]
> : ^^^^^^^

cells: Cell[] = [];
>cells : Cell[]
> : ^^^^^^
>[] : undefined[]
> : ^^^^^^^^^^^
>[] : never[]
> : ^^^^^^^

private allShipsSunk() {
>allShipsSunk : () => boolean
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) {
class Point {
Expand All @@ -34,6 +35,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 = (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 = (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 = (x) => { };
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts(5,5): error TS2564: Property 'id' has no initializer and is not definitely assigned in the constructor.
ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts(6,5): error TS2564: Property 'value' has no initializer and is not definitely assigned in the constructor.
ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts(10,19): error TS2304: Cannot find name 'T'.
ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts(15,5): error TS2564: Property 'id' has no initializer and is not definitely assigned in the constructor.
ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts(16,5): error TS2564: Property 'value' has no initializer and is not definitely assigned in the constructor.
ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts(20,12): error TS2304: Cannot find name 'T'.
ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts(22,23): error TS2304: Cannot find name 'T'.
ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts(23,9): error TS2564: Property 'id' has no initializer and is not definitely assigned in the constructor.
ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts(24,9): error TS2564: Property 'value' has no initializer and is not definitely assigned in the constructor.
ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts(30,5): error TS2564: Property 'id' has no initializer and is not definitely assigned in the constructor.
ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts(31,5): error TS2564: Property 'value' has no initializer and is not definitely assigned in the constructor.
ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts(35,26): error TS2304: Cannot find name 'T'.
ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts(40,5): error TS2564: Property 'id' has no initializer and is not definitely assigned in the constructor.
ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts(41,5): error TS2564: Property 'value' has no initializer and is not definitely assigned in the constructor.
ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts(46,15): error TS2304: Cannot find name 'T'.


==== ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts (5 errors) ====
==== ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts (15 errors) ====
// all expected to be errors

class clodule1<T>{

id: string;
~~
!!! error TS2564: Property 'id' has no initializer and is not definitely assigned in the constructor.
value: T;
~~~~~
!!! error TS2564: Property 'value' has no initializer and is not definitely assigned in the constructor.
}

namespace clodule1 {
Expand All @@ -23,7 +37,11 @@ ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts(46,15): err
class clodule2<T>{

id: string;
~~
!!! error TS2564: Property 'id' has no initializer and is not definitely assigned in the constructor.
value: T;
~~~~~
!!! error TS2564: Property 'value' has no initializer and is not definitely assigned in the constructor.
}

namespace clodule2 {
Expand All @@ -35,14 +53,22 @@ ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts(46,15): err
~
!!! error TS2304: Cannot find name 'T'.
id: string;
~~
!!! error TS2564: Property 'id' has no initializer and is not definitely assigned in the constructor.
value: U;
~~~~~
!!! error TS2564: Property 'value' has no initializer and is not definitely assigned in the constructor.
}
}

class clodule3<T>{

id: string;
~~
!!! error TS2564: Property 'id' has no initializer and is not definitely assigned in the constructor.
value: T;
~~~~~
!!! error TS2564: Property 'value' has no initializer and is not definitely assigned in the constructor.
}

namespace clodule3 {
Expand All @@ -54,7 +80,11 @@ ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts(46,15): err
class clodule4<T>{

id: string;
~~
!!! error TS2564: Property 'id' has no initializer and is not definitely assigned in the constructor.
value: T;
~~~~~
!!! error TS2564: Property 'value' has no initializer and is not definitely assigned in the constructor.
}

namespace clodule4 {
Expand Down
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
class clodule1 {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
ClassAndModuleThatMergeWithModulesExportedGenericFunctionAndGenericClassStaticFunctionOfTheSameName.ts(2,5): error TS2564: Property 'id' has no initializer and is not definitely assigned in the constructor.
ClassAndModuleThatMergeWithModulesExportedGenericFunctionAndGenericClassStaticFunctionOfTheSameName.ts(3,5): error TS2564: Property 'value' has no initializer and is not definitely assigned in the constructor.
ClassAndModuleThatMergeWithModulesExportedGenericFunctionAndGenericClassStaticFunctionOfTheSameName.ts(5,12): error TS2300: Duplicate identifier 'fn'.
ClassAndModuleThatMergeWithModulesExportedGenericFunctionAndGenericClassStaticFunctionOfTheSameName.ts(10,21): error TS2300: Duplicate identifier 'fn'.


==== ClassAndModuleThatMergeWithModulesExportedGenericFunctionAndGenericClassStaticFunctionOfTheSameName.ts (2 errors) ====
==== ClassAndModuleThatMergeWithModulesExportedGenericFunctionAndGenericClassStaticFunctionOfTheSameName.ts (4 errors) ====
class clodule<T> {
id: string;
~~
!!! error TS2564: Property 'id' has no initializer and is not definitely assigned in the constructor.
value: T;
~~~~~
!!! error TS2564: Property 'value' has no initializer and is not definitely assigned in the constructor.

static fn<U>(id: U) { }
~~
Expand Down
Loading
Loading