Skip to content
Merged
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
  •  
  •  
  •  
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
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.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
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 @@ -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,7 +9308,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/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/ClassDeclaration10.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ class C {
}

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

//// [ClassDeclaration13.js]
"use strict";
class C {
bar() { }
}
1 change: 1 addition & 0 deletions tests/baselines/reference/ClassDeclaration14.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ class C {
}

//// [ClassDeclaration14.js]
"use strict";
class C {
}
1 change: 1 addition & 0 deletions tests/baselines/reference/ClassDeclaration15.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class C {
}

//// [ClassDeclaration15.js]
"use strict";
class C {
constructor() { }
}
1 change: 1 addition & 0 deletions tests/baselines/reference/ClassDeclaration21.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class C {
}

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

//// [ClassDeclaration22.js]
"use strict";
class C {
"bar"() { }
}
1 change: 1 addition & 0 deletions tests/baselines/reference/ClassDeclaration26.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class C {
}

//// [ClassDeclaration26.js]
"use strict";
class C {
constructor() {
this.foo = 10;
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/ClassDeclaration9.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ class C {
}

//// [ClassDeclaration9.js]
"use strict";
class C {
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class C {
}

//// [ClassDeclarationWithInvalidConstOnPropertyDeclaration2.js]
"use strict";
class C {
constructor() {
this.x = 10;
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/ES5For-of14(target=es2015).js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ for (const v of []) {
}

//// [ES5For-of14.js]
"use strict";
for (const v of []) {
var x = v;
}
1 change: 1 addition & 0 deletions tests/baselines/reference/ES5For-of14(target=es5).js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ for (const v of []) {
}

//// [ES5For-of14.js]
"use strict";
for (var _i = 0, _a = []; _i < _a.length; _i++) {
var v = _a[_i];
var x = v;
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/ES5For-of15(target=es2015).js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ for (let v of []) {
}

//// [ES5For-of15.js]
"use strict";
for (let v of []) {
v;
for (const v of []) {
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/ES5For-of15(target=es5).js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ for (let v of []) {
}

//// [ES5For-of15.js]
"use strict";
for (var _i = 0, _a = []; _i < _a.length; _i++) {
var v = _a[_i];
v;
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/ES5For-of16(target=es2015).js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ for (let v of []) {
}

//// [ES5For-of16.js]
"use strict";
for (let v of []) {
v;
for (let v of []) {
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/ES5For-of16(target=es5).js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ for (let v of []) {
}

//// [ES5For-of16.js]
"use strict";
for (var _i = 0, _a = []; _i < _a.length; _i++) {
var v = _a[_i];
v;
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/ES5For-of18(target=es2015).js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ for (let v of []) {


//// [ES5For-of18.js]
"use strict";
for (let v of []) {
v;
}
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/ES5For-of18(target=es5).js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ for (let v of []) {


//// [ES5For-of18.js]
"use strict";
for (var _i = 0, _a = []; _i < _a.length; _i++) {
var v = _a[_i];
v;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//// [tests/cases/conformance/statements/for-ofStatements/ES5For-of19.ts] ////

=== ES5For-of19.ts ===
for (let v of []) {
>v : any
>[] : undefined[]
> : ^^^^^^^^^^^

v;
>v : any

function foo() {
>foo : () => void
> : ^^^^^^^^^^

for (const v of []) {
>v : any
>[] : undefined[]
> : ^^^^^^^^^^^

v;
>v : any
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//// [tests/cases/conformance/statements/for-ofStatements/ES5For-of19.ts] ////

//// [ES5For-of19.ts]
for (let v of []) {
v;
function foo() {
for (const v of []) {
v;
}
}
}


//// [ES5For-of19.js]
"use strict";
for (let v of []) {
v;
function foo() {
for (const v of []) {
v;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//// [tests/cases/conformance/statements/for-ofStatements/ES5For-of19.ts] ////

=== ES5For-of19.ts ===
for (let v of []) {
>v : Symbol(v, Decl(ES5For-of19.ts, 0, 8))

v;
>v : Symbol(v, Decl(ES5For-of19.ts, 0, 8))

function foo() {
>foo : Symbol(foo, Decl(ES5For-of19.ts, 1, 6))

for (const v of []) {
>v : Symbol(v, Decl(ES5For-of19.ts, 3, 18))

v;
>v : Symbol(v, Decl(ES5For-of19.ts, 3, 18))
}
}
}

Loading
Loading