Skip to content
Merged
  •  
  •  
  •  
38 changes: 1 addition & 37 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ import {
getContainingClass,
getEffectiveContainerForJSDocTemplateTag,
getElementOrPropertyAccessName,
getEmitScriptTarget,
getEnclosingBlockScopeContainer,
getEnclosingContainer,
getErrorSpanForNode,
Expand Down Expand Up @@ -280,7 +279,6 @@ import {
QualifiedName,
removeFileExtension,
ReturnStatement,
ScriptTarget,
SetAccessorDeclaration,
setParent,
setParentRecursive,
Expand Down Expand Up @@ -523,7 +521,6 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
/* eslint-disable no-var */
var file: SourceFile;
var options: CompilerOptions;
var languageVersion: ScriptTarget;
var parent: Node;
var container: IsContainer | EntityNameExpression;
var thisParentContainer: IsContainer | EntityNameExpression; // Container one level up
Expand Down Expand Up @@ -583,7 +580,6 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
function bindSourceFile(f: SourceFile, opts: CompilerOptions) {
file = f;
options = opts;
languageVersion = getEmitScriptTarget(options);
inStrictMode = bindInStrictMode(file, opts);
classifiableNames = new Set();
symbolCount = 0;
Expand All @@ -606,7 +602,6 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {

file = undefined!;
options = undefined!;
languageVersion = undefined!;
parent = undefined!;
container = undefined!;
thisParentContainer = undefined!;
Expand Down Expand Up @@ -2673,36 +2668,6 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
}
}

function getStrictModeBlockScopeFunctionDeclarationMessage(node: Node) {
// Provide specialized messages to help the user understand why we think they're in
// strict mode.
if (getContainingClass(node)) {
return Diagnostics.Function_declarations_are_not_allowed_inside_blocks_in_strict_mode_when_targeting_ES5_Class_definitions_are_automatically_in_strict_mode;
}

if (file.externalModuleIndicator) {
return Diagnostics.Function_declarations_are_not_allowed_inside_blocks_in_strict_mode_when_targeting_ES5_Modules_are_automatically_in_strict_mode;
}

return Diagnostics.Function_declarations_are_not_allowed_inside_blocks_in_strict_mode_when_targeting_ES5;
}

function checkStrictModeFunctionDeclaration(node: FunctionDeclaration) {
if (languageVersion < ScriptTarget.ES2015) {
// Report error if function is not top level function declaration
if (
blockScopeContainer.kind !== SyntaxKind.SourceFile &&
blockScopeContainer.kind !== SyntaxKind.ModuleDeclaration &&
!isFunctionLikeOrClassStaticBlockDeclaration(blockScopeContainer)
) {
// We check first if the name is inside class declaration or class expression; if so give explicit message
// otherwise report generic error message.
const errorSpan = getErrorSpanForNode(file, node);
file.bindDiagnostics.push(createFileDiagnostic(file, errorSpan.start, errorSpan.length, getStrictModeBlockScopeFunctionDeclarationMessage(node)));
}
}
}

function checkStrictModePostfixUnaryExpression(node: PostfixUnaryExpression) {
// Grammar checking
// The identifier eval or arguments may not appear as the LeftHandSideExpression of an
Expand Down Expand Up @@ -2731,7 +2696,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {

function checkStrictModeLabeledStatement(node: LabeledStatement) {
// Grammar checking for labeledStatement
if (inStrictMode && getEmitScriptTarget(options) >= ScriptTarget.ES2015) {
if (inStrictMode) {
if (isDeclarationStatement(node.statement) || isVariableStatement(node.statement)) {
errorOnFirstToken(node.label, Diagnostics.A_label_is_not_allowed_here);
}
Expand Down Expand Up @@ -3725,7 +3690,6 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {

checkStrictModeFunctionName(node);
if (inStrictMode) {
checkStrictModeFunctionDeclaration(node);
bindBlockScopedDeclaration(node, SymbolFlags.Function, SymbolFlags.FunctionExcludes);
}
else {
Expand Down
Loading