public void SetData(SourceContext input) { if (input != null) { this.Document = input.Document; this.StartLineNumber = input.StartLineNumber; this.StartLinePosition = input.StartLinePosition; this.StartPosition = input.StartPosition; this.EndLineNumber = input.EndLineNumber; this.EndLinePosition = input.EndLinePosition; this.EndPosition = input.EndPosition; this.Token = input.Token; this.SourceOffsetStart = input.SourceOffsetStart; this.SourceOffsetEnd = input.SourceOffsetEnd; } }
public void MarkSegment(AstNode node, int startLine, int startColumn, string name, SourceContext context) { if (node == null || string.IsNullOrEmpty(name)) { return; } // see if this is within a function object node, // AND if this segment has the same name as the function name // AND this context isn't the same as the entire function context. // this should only be true for the function NAME segment. var functionObject = node as FunctionObject; if (functionObject != null && functionObject.Binding != null && string.CompareOrdinal(name, functionObject.Binding.Name) == 0 && context != functionObject.Context) { // adjust the offsets startLine += m_lineOffset; startColumn += m_columnOffset; // it does -- so this is the segment that corresponds to the function object's name, which // for this format we want to output a separate segment for. It used to be its own Lookup // node child of the function object, so we need to create a fake node here, start a new // symbol from it, end the symbol, then write it. var fakeLookup = new LookupExpression(context) { Name = name }; var nameSymbol = JavaScriptSymbol.StartNew(fakeLookup, startLine, startColumn, GetSourceFileIndex(functionObject.Context.Document.FileContext)); // the name will never end on a different line -- it's a single unbreakable token. The length is just // the length of the name, so add that number to the column start. And the parent context is the function // name (again) nameSymbol.End(startLine, startColumn + name.Length, name); nameSymbol.WriteTo(m_writer); } }
public void MarkSegment(AstNode node, int startLine, int startColumn, string name, SourceContext 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); }