示例#1
0
        public void MarkSegment(AstNode node, int startLine, int startColumn, string name, Context context)
        {
            if (startLine == int.MaxValue)
            {
                throw new ArgumentOutOfRangeException("startLine");
            }

            // add the offsets
            startLine   += m_lineOffset;
            startColumn += m_columnOffset;

            // if we have a name, try adding it to the hash set of names. If it already exists, the call to Add
            // will return false. If it doesn't already exist, Add will return true and we'll append it to the list
            // of names. That way we have a nice list of names ordered by their first occurrence in the minified file.
            if (!string.IsNullOrEmpty(name) && m_names.Add(name))
            {
                m_nameList.Add(name);
            }

            // if this is a newline, the startline will be bigger than the largest line we've had so far
            m_maxMinifiedLine = Math.Max(m_maxMinifiedLine, startLine);

            // save the file context in our list of files
            if (context != null && context.Document != null && context.Document.FileContext != null)
            {
                // if this is the first instance of this file...
                if (m_sourceFiles.Add(context.Document.FileContext))
                {
                    // ...add it to the list, so we end up with a list of unique files
                    // sorted by their first occurence in the minified file.
                    m_sourceFileList.Add(MakeRelative(context.Document.FileContext, m_mapPath));
                }
            }

            // create the segment object and add it to the list.
            // the destination line/col numbers are zero-based. The format expects line to be 1-based and col 0-based.
            // the context line is one-based; col is zero-based. The format expects both to be zero-based.
            var segment = CreateSegment(
                startLine + 1,
                startColumn,
                context == null || context.StartLineNumber < 1 ? -1 : context.StartLineNumber - 1,
                context == null || context.StartColumn < 0 ? -1 : context.StartColumn,
                context.IfNotNull(c => MakeRelative(c.Document.FileContext, m_mapPath)),
                name);

            m_segments.Add(segment);
        }