@@ -70,7 +70,6 @@ type Binder struct {
7070 seenThisKeyword bool
7171 hasExplicitReturn bool
7272 hasFlowEffects bool
73- inStrictMode bool
7473 inAssignmentPattern bool
7574 seenParseError bool
7675 symbolCount int
@@ -83,10 +82,6 @@ type Binder struct {
8382 expandoAssignments []ExpandoAssignmentInfo
8483}
8584
86- func (b * Binder ) options () core.SourceFileAffectingCompilerOptions {
87- return b .file .ParseOptions ().CompilerOptions
88- }
89-
9085type ActiveLabel struct {
9186 next * ActiveLabel
9287 breakTarget * ast.FlowLabel
@@ -128,7 +123,6 @@ func bindSourceFile(file *ast.SourceFile) {
128123 b := getBinder ()
129124 defer putBinder (b )
130125 b .file = file
131- b .inStrictMode = b .options ().BindInStrictMode && ! file .IsDeclarationFile || ast .IsExternalModule (file )
132126 b .unreachableFlow = b .newFlowNode (ast .FlowFlagsUnreachable )
133127 b .bind (file .AsNode ())
134128 b .bindDeferredExpandoAssignments ()
@@ -590,7 +584,6 @@ func (b *Binder) bind(node *ast.Node) bool {
590584 if node == nil {
591585 return false
592586 }
593- saveInStrictMode := b .inStrictMode
594587 // Even though in the AST the jsdoc @typedef node belongs to the current node,
595588 // its symbol might be in the same scope with the current node's symbol. Consider:
596589 //
@@ -692,7 +685,6 @@ func (b *Binder) bind(node *ast.Node) bool {
692685 case ast .KindFunctionExpression , ast .KindArrowFunction :
693686 b .bindFunctionExpression (node )
694687 case ast .KindClassExpression , ast .KindClassDeclaration :
695- b .inStrictMode = true
696688 b .bindClassLikeDeclaration (node )
697689 case ast .KindInterfaceDeclaration :
698690 b .bindBlockScopedDeclaration (node , ast .SymbolFlagsInterface , ast .SymbolFlagsInterfaceExcludes )
@@ -723,14 +715,7 @@ func (b *Binder) bind(node *ast.Node) bool {
723715 case ast .KindExportAssignment , ast .KindJSExportAssignment :
724716 b .bindExportAssignment (node )
725717 case ast .KindSourceFile :
726- b .updateStrictModeStatementList (node .StatementList ())
727718 b .bindSourceFileIfExternalModule ()
728- case ast .KindBlock :
729- if ast .IsFunctionLikeOrClassStaticBlockDeclaration (node .Parent ) {
730- b .updateStrictModeStatementList (node .StatementList ())
731- }
732- case ast .KindModuleBlock :
733- b .updateStrictModeStatementList (node .StatementList ())
734719 case ast .KindJsxAttributes :
735720 b .bindJsxAttributes (node )
736721 case ast .KindJsxAttribute :
@@ -760,7 +745,6 @@ func (b *Binder) bind(node *ast.Node) bool {
760745 node .Flags |= ast .NodeFlagsThisNodeOrAnySubNodesHasError
761746 b .seenParseError = true
762747 }
763- b .inStrictMode = saveInStrictMode
764748 return false
765749}
766750
@@ -1151,9 +1135,7 @@ func (b *Binder) bindEnumDeclaration(node *ast.Node) {
11511135}
11521136
11531137func (b * Binder ) bindVariableDeclarationOrBindingElement (node * ast.Node ) {
1154- if b .inStrictMode {
1155- b .checkStrictModeEvalOrArguments (node , node .Name ())
1156- }
1138+ b .checkStrictModeEvalOrArguments (node , node .Name ())
11571139 if name := node .Name (); name != nil && ! ast .IsBindingPattern (name ) {
11581140 switch {
11591141 case ast .IsVariableDeclarationInitializedToRequire (node ):
@@ -1179,7 +1161,7 @@ func (b *Binder) bindVariableDeclarationOrBindingElement(node *ast.Node) {
11791161
11801162func (b * Binder ) bindParameter (node * ast.Node ) {
11811163 decl := node .AsParameterDeclaration ()
1182- if b . inStrictMode && node .Flags & ast .NodeFlagsAmbient == 0 {
1164+ if node .Flags & ast .NodeFlagsAmbient == 0 {
11831165 // It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a
11841166 // strict mode FunctionLikeDeclaration or FunctionExpression(13.1)
11851167 b .checkStrictModeEvalOrArguments (node , decl .Name ())
@@ -1201,11 +1183,7 @@ func (b *Binder) bindParameter(node *ast.Node) {
12011183
12021184func (b * Binder ) bindFunctionDeclaration (node * ast.Node ) {
12031185 b .checkStrictModeFunctionName (node )
1204- if b .inStrictMode {
1205- b .bindBlockScopedDeclaration (node , ast .SymbolFlagsFunction , ast .SymbolFlagsFunctionExcludes )
1206- } else {
1207- b .declareSymbolAndAddToSymbolTable (node , ast .SymbolFlagsFunction , ast .SymbolFlagsFunctionExcludes )
1208- }
1186+ b .bindBlockScopedDeclaration (node , ast .SymbolFlagsFunction , ast .SymbolFlagsFunctionExcludes )
12091187}
12101188
12111189func (b * Binder ) getInferTypeContainer (node * ast.Node ) * ast.Node {
@@ -1298,7 +1276,7 @@ func (b *Binder) checkContextualIdentifier(node *ast.Node) {
12981276 if originalKeywordKind == ast .KindIdentifier {
12991277 return
13001278 }
1301- if b . inStrictMode && originalKeywordKind >= ast .KindFirstFutureReservedWord && originalKeywordKind <= ast .KindLastFutureReservedWord {
1279+ if originalKeywordKind >= ast .KindFirstFutureReservedWord && originalKeywordKind <= ast .KindLastFutureReservedWord {
13021280 b .errorOnNode (node , b .getStrictModeIdentifierMessage (node ), scanner .DeclarationNameToString (node ))
13031281 } else if originalKeywordKind == ast .KindAwaitKeyword {
13041282 if ast .IsExternalModule (b .file ) && ast .IsInTopLevelContext (node ) {
@@ -1333,15 +1311,6 @@ func (b *Binder) getStrictModeIdentifierMessage(node *ast.Node) *diagnostics.Mes
13331311 return diagnostics .Identifier_expected_0_is_a_reserved_word_in_strict_mode
13341312}
13351313
1336- func (b * Binder ) updateStrictModeStatementList (statements * ast.NodeList ) {
1337- if ! b .inStrictMode {
1338- useStrictDirective := FindUseStrictPrologue (b .file , statements .Nodes )
1339- if useStrictDirective != nil {
1340- b .inStrictMode = true
1341- }
1342- }
1343- }
1344-
13451314// Should be called only on prologue directives (ast.IsPrologueDirective(node) should be true)
13461315func isUseStrictPrologueDirective (sourceFile * ast.SourceFile , node * ast.Node ) bool {
13471316 nodeText := scanner .GetSourceTextOfNodeFromSourceFile (sourceFile , node .Expression (), false /*includeTrivia*/ )
@@ -1365,7 +1334,7 @@ func FindUseStrictPrologue(sourceFile *ast.SourceFile, statements []*ast.Node) *
13651334}
13661335
13671336func (b * Binder ) checkStrictModeFunctionName (node * ast.Node ) {
1368- if b . inStrictMode && node .Flags & ast .NodeFlagsAmbient == 0 {
1337+ if node .Flags & ast .NodeFlagsAmbient == 0 {
13691338 // It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a strict mode FunctionDeclaration or FunctionExpression (13.1))
13701339 b .checkStrictModeEvalOrArguments (node , node .Name ())
13711340 }
@@ -1384,7 +1353,7 @@ func (b *Binder) getStrictModeBlockScopeFunctionDeclarationMessage(node *ast.Nod
13841353
13851354func (b * Binder ) checkStrictModeBinaryExpression (node * ast.Node ) {
13861355 expr := node .AsBinaryExpression ()
1387- if b . inStrictMode && ast .IsLeftHandSideExpression (expr .Left ) && ast .IsAssignmentOperator (expr .OperatorToken .Kind ) {
1356+ if ast .IsLeftHandSideExpression (expr .Left ) && ast .IsAssignmentOperator (expr .OperatorToken .Kind ) {
13881357 // ECMA 262 (Annex C) The identifier eval or arguments may not appear as the LeftHandSideExpression of an
13891358 // Assignment operator(11.13) or of a PostfixExpression(11.3)
13901359 b .checkStrictModeEvalOrArguments (node , expr .Left )
@@ -1395,15 +1364,15 @@ func (b *Binder) checkStrictModeCatchClause(node *ast.Node) {
13951364 // It is a SyntaxError if a TryStatement with a Catch occurs within strict code and the Identifier of the
13961365 // Catch production is eval or arguments
13971366 clause := node .AsCatchClause ()
1398- if b . inStrictMode && clause .VariableDeclaration != nil {
1367+ if clause .VariableDeclaration != nil {
13991368 b .checkStrictModeEvalOrArguments (node , clause .VariableDeclaration .AsVariableDeclaration ().Name ())
14001369 }
14011370}
14021371
14031372func (b * Binder ) checkStrictModeDeleteExpression (node * ast.Node ) {
14041373 // Grammar checking
14051374 expr := node .AsDeleteExpression ()
1406- if b . inStrictMode && expr .Expression .Kind == ast .KindIdentifier {
1375+ if expr .Expression .Kind == ast .KindIdentifier {
14071376 // When a delete operator occurs within strict mode code, a SyntaxError is thrown if its
14081377 // UnaryExpression is a direct reference to a variable, function argument, or function name
14091378 b .errorOnNode (expr .Expression , diagnostics .X_delete_cannot_be_called_on_an_identifier_in_strict_mode )
@@ -1415,35 +1384,27 @@ func (b *Binder) checkStrictModePostfixUnaryExpression(node *ast.Node) {
14151384 // The identifier eval or arguments may not appear as the LeftHandSideExpression of an
14161385 // Assignment operator(11.13) or of a PostfixExpression(11.3) or as the UnaryExpression
14171386 // operated upon by a Prefix Increment(11.4.4) or a Prefix Decrement(11.4.5) operator.
1418- if b .inStrictMode {
1419- b .checkStrictModeEvalOrArguments (node , node .AsPostfixUnaryExpression ().Operand )
1420- }
1387+ b .checkStrictModeEvalOrArguments (node , node .AsPostfixUnaryExpression ().Operand )
14211388}
14221389
14231390func (b * Binder ) checkStrictModePrefixUnaryExpression (node * ast.Node ) {
14241391 // Grammar checking
1425- if b .inStrictMode {
1426- expr := node .AsPrefixUnaryExpression ()
1427- if expr .Operator == ast .KindPlusPlusToken || expr .Operator == ast .KindMinusMinusToken {
1428- b .checkStrictModeEvalOrArguments (node , expr .Operand )
1429- }
1392+ expr := node .AsPrefixUnaryExpression ()
1393+ if expr .Operator == ast .KindPlusPlusToken || expr .Operator == ast .KindMinusMinusToken {
1394+ b .checkStrictModeEvalOrArguments (node , expr .Operand )
14301395 }
14311396}
14321397
14331398func (b * Binder ) checkStrictModeWithStatement (node * ast.Node ) {
14341399 // Grammar checking for withStatement
1435- if b .inStrictMode {
1436- b .errorOnFirstToken (node , diagnostics .X_with_statements_are_not_allowed_in_strict_mode )
1437- }
1400+ b .errorOnFirstToken (node , diagnostics .X_with_statements_are_not_allowed_in_strict_mode )
14381401}
14391402
14401403func (b * Binder ) checkStrictModeLabeledStatement (node * ast.Node ) {
14411404 // Grammar checking for labeledStatement
1442- if b .inStrictMode {
1443- data := node .AsLabeledStatement ()
1444- if ast .IsDeclarationStatement (data .Statement ) || ast .IsVariableStatement (data .Statement ) {
1445- b .errorOnFirstToken (data .Label , diagnostics .A_label_is_not_allowed_here )
1446- }
1405+ data := node .AsLabeledStatement ()
1406+ if ast .IsDeclarationStatement (data .Statement ) || ast .IsVariableStatement (data .Statement ) {
1407+ b .errorOnFirstToken (data .Label , diagnostics .A_label_is_not_allowed_here )
14471408 }
14481409}
14491410
0 commit comments