Skip to content

Commit f770382

Browse files
committed
added test to confirm hoistables are only scanned a single time
1 parent 0884386 commit f770382

1 file changed

Lines changed: 84 additions & 0 deletions

File tree

scope/scope_test.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6030,6 +6030,90 @@ func TestModuleScope(t *testing.T) {
60306030
},
60316031
}
60326032

6033+
return scope, nil
6034+
},
6035+
},
6036+
{ // 172
6037+
"var a = b => b;\nvar d = a(1);",
6038+
func(m *javascript.Module) (*Scope, error) {
6039+
scope := NewScope()
6040+
fscope := scope.newArrowFunctionScope(m.ModuleListItems[0].StatementListItem.Statement.VariableStatement.VariableDeclarationList[0].Initializer.ArrowFunction)
6041+
6042+
scope.Bindings["a"] = []Binding{
6043+
{
6044+
BindingType: BindingVar,
6045+
Scope: scope,
6046+
Token: m.ModuleListItems[0].StatementListItem.Statement.VariableStatement.VariableDeclarationList[0].BindingIdentifier,
6047+
},
6048+
{
6049+
BindingType: BindingRef,
6050+
Scope: scope,
6051+
Token: javascript.UnwrapConditional(m.ModuleListItems[1].StatementListItem.Statement.VariableStatement.VariableDeclarationList[0].Initializer.ConditionalExpression).(*javascript.CallExpression).MemberExpression.PrimaryExpression.IdentifierReference,
6052+
},
6053+
}
6054+
scope.Bindings["d"] = []Binding{
6055+
{
6056+
BindingType: BindingVar,
6057+
Scope: scope,
6058+
Token: m.ModuleListItems[1].StatementListItem.Statement.VariableStatement.VariableDeclarationList[0].BindingIdentifier,
6059+
},
6060+
}
6061+
6062+
fscope.Bindings["b"] = []Binding{
6063+
{
6064+
BindingType: BindingFunctionParam,
6065+
Scope: fscope,
6066+
Token: m.ModuleListItems[0].StatementListItem.Statement.VariableStatement.VariableDeclarationList[0].Initializer.ArrowFunction.BindingIdentifier,
6067+
},
6068+
{
6069+
BindingType: BindingRef,
6070+
Scope: fscope,
6071+
Token: javascript.UnwrapConditional(m.ModuleListItems[0].StatementListItem.Statement.VariableStatement.VariableDeclarationList[0].Initializer.ArrowFunction.AssignmentExpression.ConditionalExpression).(*javascript.PrimaryExpression).IdentifierReference,
6072+
},
6073+
}
6074+
6075+
return scope, nil
6076+
},
6077+
},
6078+
{ // 173
6079+
"function b() {{var a}function a(){}a}",
6080+
func(m *javascript.Module) (*Scope, error) {
6081+
scope := NewScope()
6082+
fscope := scope.newFunctionScope(m.ModuleListItems[0].StatementListItem.Declaration.FunctionDeclaration)
6083+
lscope := fscope.newLexicalScope(m.ModuleListItems[0].StatementListItem.Declaration.FunctionDeclaration.FunctionBody.StatementList[0].Statement.BlockStatement)
6084+
fscope.newFunctionScope(m.ModuleListItems[0].StatementListItem.Declaration.FunctionDeclaration.FunctionBody.StatementList[1].Declaration.FunctionDeclaration)
6085+
scope.Bindings["b"] = []Binding{
6086+
{
6087+
BindingType: BindingHoistable,
6088+
Scope: scope,
6089+
Token: m.ModuleListItems[0].StatementListItem.Declaration.FunctionDeclaration.BindingIdentifier,
6090+
},
6091+
}
6092+
fscope.Bindings["a"] = []Binding{
6093+
{
6094+
BindingType: BindingHoistable,
6095+
Scope: fscope,
6096+
Token: m.ModuleListItems[0].StatementListItem.Declaration.FunctionDeclaration.FunctionBody.StatementList[1].Declaration.FunctionDeclaration.BindingIdentifier,
6097+
},
6098+
{
6099+
BindingType: BindingVar,
6100+
Scope: lscope,
6101+
Token: m.ModuleListItems[0].StatementListItem.Declaration.FunctionDeclaration.FunctionBody.StatementList[0].Statement.BlockStatement.StatementList[0].Statement.VariableStatement.VariableDeclarationList[0].BindingIdentifier,
6102+
},
6103+
{
6104+
BindingType: BindingRef,
6105+
Scope: fscope,
6106+
Token: javascript.UnwrapConditional(m.ModuleListItems[0].StatementListItem.Declaration.FunctionDeclaration.FunctionBody.StatementList[2].Statement.ExpressionStatement.Expressions[0].ConditionalExpression).(*javascript.PrimaryExpression).IdentifierReference,
6107+
},
6108+
}
6109+
lscope.Bindings["a"] = []Binding{
6110+
{
6111+
BindingType: BindingVar,
6112+
Scope: lscope,
6113+
Token: m.ModuleListItems[0].StatementListItem.Declaration.FunctionDeclaration.FunctionBody.StatementList[0].Statement.BlockStatement.StatementList[0].Statement.VariableStatement.VariableDeclarationList[0].BindingIdentifier,
6114+
},
6115+
}
6116+
60336117
return scope, nil
60346118
},
60356119
},

0 commit comments

Comments
 (0)