Esempio n. 1
0
        private void DefineField(ResolutionVisitor resolutionVisitor, INameDeclaration nameDecl)
        {
            if (nameDecl == null)
            {
                // malformed code, for example catch w/o a variable.
                return;
            }
            var field = this[nameDecl.Name];

            if (nameDecl is ParameterDeclaration)
            {
                // function parameters are handled separately, so if this is a parameter declaration,
                // then it must be a catch variable.
                if (field == null)
                {
                    // no collision - create the catch-error field
                    field = new JSVariableField(FieldType.CatchError, nameDecl.Name);

                    this.AddField(field);
                }
                else
                {
                    // it's an error to declare anything in the catch scope with the same name as the
                    // error variable

                    ErrorSink.HandleError(JSError.DuplicateCatch, nameDecl.GetNameSpan(GlobalScope.Node.LocationResolver), resolutionVisitor._locationResolver, true);
                }
            }
            else
            {
                if (field == null)
                {
                    // could be global or local depending on the scope, so let the scope create it.
                    field = this.CreateField(nameDecl.Name);

                    // if this field is a constant, mark it now
                    var lexDeclaration = nameDecl.Parent as LexicalDeclaration;

                    this.AddField(field);
                }
                else
                {
                    // already defined!
                    // if this is a lexical declaration, then it's an error because we have two
                    // lexical declarations with the same name in the same scope.
                    if (nameDecl.Parent is LexicalDeclaration)
                    {
                        _errorSink.HandleError(
                            JSError.DuplicateLexicalDeclaration,
                            nameDecl.GetNameSpan(GlobalScope.Node.LocationResolver),
                            resolutionVisitor._locationResolver,
                            true
                            );
                    }
                }
            }

            nameDecl.VariableField = field;
        }
        private void DefineField(ResolutionVisitor resolutionVisitor, INameDeclaration nameDecl)
        {
            if (nameDecl == null) {
                // malformed code, for example catch w/o a variable.
                return;
            }
            var field = this[nameDecl.Name];
            if (nameDecl is ParameterDeclaration)
            {
                // function parameters are handled separately, so if this is a parameter declaration,
                // then it must be a catch variable. 
                if (field == null)
                {
                    // no collision - create the catch-error field
                    field = new JSVariableField(FieldType.CatchError, nameDecl.Name);

                    this.AddField(field);
                }
                else
                {
                    // it's an error to declare anything in the catch scope with the same name as the
                    // error variable
                    
                    ErrorSink.HandleError(JSError.DuplicateCatch, nameDecl.GetNameSpan(GlobalScope.Node.LocationResolver), resolutionVisitor._locationResolver, true);
                }
            }
            else
            {
                if (field == null)
                {
                    // could be global or local depending on the scope, so let the scope create it.
                    field = this.CreateField(nameDecl.Name);
                    
                    // if this field is a constant, mark it now
                    var lexDeclaration = nameDecl.Parent as LexicalDeclaration;

                    this.AddField(field);
                }
                else
                {
                    // already defined! 
                    // if this is a lexical declaration, then it's an error because we have two
                    // lexical declarations with the same name in the same scope.
                    if (nameDecl.Parent is LexicalDeclaration)
                    {
                        _errorSink.HandleError(
                            JSError.DuplicateLexicalDeclaration, 
                            nameDecl.GetNameSpan(GlobalScope.Node.LocationResolver), 
                            resolutionVisitor._locationResolver, 
                            true
                        );
                    }
                }
            }

            nameDecl.VariableField = field;
        }