| Index: chrome_linux64/resources/inspector/ScriptFormatterWorker.js
|
| ===================================================================
|
| --- chrome_linux64/resources/inspector/ScriptFormatterWorker.js (revision 273864)
|
| +++ chrome_linux64/resources/inspector/ScriptFormatterWorker.js (working copy)
|
| @@ -10,6 +10,11 @@
|
| String.prototype.lineEndings=function()
|
| {if(!this._lineEndings){this._lineEndings=this.findAll("\n");this._lineEndings.push(this.length);}
|
| return this._lineEndings;}
|
| +String.prototype.lineCount=function()
|
| +{var lineEndings=this.lineEndings();return lineEndings.length;}
|
| +String.prototype.lineAt=function(lineNumber)
|
| +{var lineEndings=this.lineEndings();var lineStart=lineNumber>0?lineEndings[lineNumber-1]+1:0;var lineEnd=lineEndings[lineNumber];var lineContent=this.substring(lineStart,lineEnd);if(lineContent.length>0&&lineContent.charAt(lineContent.length-1)==="\r")
|
| +lineContent=lineContent.substring(0,lineContent.length-1);return lineContent;}
|
| String.prototype.escapeCharacters=function(chars)
|
| {var foundChar=false;for(var i=0;i<chars.length;++i){if(this.indexOf(chars.charAt(i))!==-1){foundChar=true;break;}}
|
| if(!foundChar)
|
| @@ -17,7 +22,7 @@
|
| result+="\\";result+=this.charAt(i);}
|
| return result;}
|
| String.regexSpecialCharacters=function()
|
| -{return"^[]{}()\\.$*+?|-,";}
|
| +{return"^[]{}()\\.^$*+?|-,";}
|
| String.prototype.escapeForRegExp=function()
|
| {return this.escapeCharacters(String.regexSpecialCharacters());}
|
| String.prototype.escapeHTML=function()
|
| @@ -83,11 +88,24 @@
|
| leadZero(this.getHours())+
|
| leadZero(this.getMinutes())+
|
| leadZero(this.getSeconds());}
|
| -Object.defineProperty(Array.prototype,"remove",{value:function(value,onlyFirst)
|
| -{if(onlyFirst){var index=this.indexOf(value);if(index!==-1)
|
| -this.splice(index,1);return;}
|
| -var length=this.length;for(var i=0;i<length;++i){if(this[i]===value)
|
| -this.splice(i,1);}}});Object.defineProperty(Array.prototype,"keySet",{value:function()
|
| +Date.prototype.toConsoleTime=function()
|
| +{function leadZero2(x)
|
| +{return(x>9?"":"0")+x;}
|
| +function leadZero3(x)
|
| +{return(Array(4-x.toString().length)).join('0')+x;}
|
| +return this.getFullYear()+"-"+
|
| +leadZero2(this.getMonth()+1)+"-"+
|
| +leadZero2(this.getDate())+" "+
|
| +leadZero2(this.getHours())+":"+
|
| +leadZero2(this.getMinutes())+":"+
|
| +leadZero2(this.getSeconds())+"."+
|
| +leadZero3(this.getMilliseconds());}
|
| +Object.defineProperty(Array.prototype,"remove",{value:function(value,firstOnly)
|
| +{var index=this.indexOf(value);if(index===-1)
|
| +return;if(firstOnly){this.splice(index,1);return;}
|
| +for(var i=index+1,n=this.length;i<n;++i){if(this[i]!==value)
|
| +this[index++]=this[i];}
|
| +this.length=index;}});Object.defineProperty(Array.prototype,"keySet",{value:function()
|
| {var keys={};for(var i=0;i<this.length;++i)
|
| keys[this[i]]=true;return keys;}});Object.defineProperty(Array.prototype,"rotate",{value:function(index)
|
| {var result=[];for(var i=index;i<index+this.length;++i)
|
| @@ -119,16 +137,16 @@
|
| var low=0;var high=this.length-1;for(;;){var pivotPosition=this.partition(comparator,low,high,Math.floor((high+low)/2));if(pivotPosition===k)
|
| return this[k];else if(pivotPosition>k)
|
| high=pivotPosition-1;else
|
| -low=pivotPosition+1;}}});Object.defineProperty(Array.prototype,"lowerBound",{value:function(object,comparator)
|
| +low=pivotPosition+1;}}});Object.defineProperty(Array.prototype,"lowerBound",{value:function(object,comparator,left,right)
|
| {function defaultComparator(a,b)
|
| {return a<b?-1:(a>b?1:0);}
|
| -comparator=comparator||defaultComparator;var l=0;var r=this.length;while(l<r){var m=(l+r)>>1;if(comparator(object,this[m])>0)
|
| +comparator=comparator||defaultComparator;var l=left||0;var r=right!==undefined?right:this.length;while(l<r){var m=(l+r)>>1;if(comparator(object,this[m])>0)
|
| l=m+1;else
|
| r=m;}
|
| -return r;}});Object.defineProperty(Array.prototype,"upperBound",{value:function(object,comparator)
|
| +return r;}});Object.defineProperty(Array.prototype,"upperBound",{value:function(object,comparator,left,right)
|
| {function defaultComparator(a,b)
|
| {return a<b?-1:(a>b?1:0);}
|
| -comparator=comparator||defaultComparator;var l=0;var r=this.length;while(l<r){var m=(l+r)>>1;if(comparator(object,this[m])>=0)
|
| +comparator=comparator||defaultComparator;var l=left||0;var r=right!==undefined?right:this.length;while(l<r){var m=(l+r)>>1;if(comparator(object,this[m])>=0)
|
| l=m+1;else
|
| r=m;}
|
| return r;}});Object.defineProperty(Array.prototype,"binaryIndexOf",{value:function(value,comparator)
|
| @@ -136,10 +154,13 @@
|
| {var result=new Array(this.length);for(var i=0;i<this.length;++i)
|
| result[i]=this[i][field];return result;}});Object.defineProperty(Array.prototype,"peekLast",{value:function()
|
| {return this[this.length-1];}});(function(){function mergeOrIntersect(array1,array2,comparator,mergeNotIntersect)
|
| -{var result=[];var i=0;var j=0;while(i<array1.length||j<array2.length){if(i===array1.length){result=result.concat(array2.slice(j));j=array2.length;}else if(j===array2.length){result=result.concat(array1.slice(i));i=array1.length;}else{var compareValue=comparator(array1[i],array2[j])
|
| -if(compareValue<0){if(mergeNotIntersect)
|
| -result.push(array1[i]);++i;}else if(compareValue>0){if(mergeNotIntersect)
|
| -result.push(array2[j]);++j;}else{result.push(array1[i]);++i;++j;}}}
|
| +{var result=[];var i=0;var j=0;while(i<array1.length&&j<array2.length){var compareValue=comparator(array1[i],array2[j]);if(mergeNotIntersect||!compareValue)
|
| +result.push(compareValue<=0?array1[i]:array2[j]);if(compareValue<=0)
|
| +i++;if(compareValue>=0)
|
| +j++;}
|
| +if(mergeNotIntersect){while(i<array1.length)
|
| +result.push(array1[i++]);while(j<array2.length)
|
| +result.push(array2[j++]);}
|
| return result;}
|
| Object.defineProperty(Array.prototype,"intersectOrdered",{value:function(array,comparator)
|
| {return mergeOrIntersect(this,array,comparator,false);}});Object.defineProperty(Array.prototype,"mergeOrdered",{value:function(array,comparator)
|
| @@ -254,6 +275,15 @@
|
| return this._hasProtoKey;return Object.prototype.hasOwnProperty.call(this._map,key);},size:function()
|
| {return this._size;},clear:function()
|
| {this._map={};this._size=0;delete this._hasProtoKey;delete this._protoValue;}}
|
| +var StringSet=function()
|
| +{this._map=new StringMap();}
|
| +StringSet.prototype={put:function(value)
|
| +{this._map.put(value,true);},remove:function(value)
|
| +{return!!this._map.remove(value);},values:function()
|
| +{return this._map.keys();},contains:function(value)
|
| +{return this._map.contains(value);},size:function()
|
| +{return this._map.size();},clear:function()
|
| +{this._map.clear();}}
|
| function loadXHR(url,async,callback)
|
| {function onReadyStateChanged()
|
| {if(xhr.readyState!==XMLHttpRequest.DONE)
|
| @@ -263,20 +293,10 @@
|
| xhr.onreadystatechange=onReadyStateChanged;xhr.send(null);if(!async){if(xhr.status===200)
|
| return xhr.responseText;return null;}
|
| return null;}
|
| -function StringPool()
|
| -{this.reset();}
|
| -StringPool.prototype={intern:function(string)
|
| -{if(string==="__proto__")
|
| -return"__proto__";var result=this._strings[string];if(result===undefined){this._strings[string]=string;result=string;}
|
| -return result;},reset:function()
|
| -{this._strings=Object.create(null);},internObjectStrings:function(obj,depthLimit)
|
| -{if(typeof depthLimit!=="number")
|
| -depthLimit=100;else if(--depthLimit<0)
|
| -throw"recursion depth limit reached in StringPool.deepIntern(), perhaps attempting to traverse cyclical references?";for(var field in obj){switch(typeof obj[field]){case"string":obj[field]=this.intern(obj[field]);break;case"object":this.internObjectStrings(obj[field],depthLimit);break;}}}}
|
| var _importedScripts={};function importScript(scriptName)
|
| {if(_importedScripts[scriptName])
|
| return;var xhr=new XMLHttpRequest();_importedScripts[scriptName]=true;xhr.open("GET",scriptName,false);xhr.send(null);if(!xhr.responseText)
|
| -throw"empty response arrived for script '"+scriptName+"'";var baseUrl=location.href;baseUrl=baseUrl.substring(0,baseUrl.lastIndexOf("/"));var sourceURL=baseUrl+"/"+scriptName;eval(xhr.responseText+"\n//# sourceURL="+sourceURL);}
|
| +throw"empty response arrived for script '"+scriptName+"'";var baseUrl=location.origin+location.pathname;baseUrl=baseUrl.substring(0,baseUrl.lastIndexOf("/"));var sourceURL=baseUrl+"/"+scriptName;self.eval(xhr.responseText+"\n//# sourceURL="+sourceURL);}
|
| var loadScript=importScript;function CallbackBarrier()
|
| {this._pendingIncomingCallbacksCount=0;}
|
| CallbackBarrier.prototype={createCallback:function(userCallback)
|
| @@ -285,7 +305,9 @@
|
| this._outgoingCallback();},_incomingCallback:function(userCallback)
|
| {console.assert(this._pendingIncomingCallbacksCount>0);if(userCallback){var args=Array.prototype.slice.call(arguments,1);userCallback.apply(null,args);}
|
| if(!--this._pendingIncomingCallbacksCount&&this._outgoingCallback)
|
| -this._outgoingCallback();}};(function(window){window.CodeMirror={};(function(){"use strict";function splitLines(string){return string.split(/\r?\n|\r/);};function StringStream(string){this.pos=this.start=0;this.string=string;this.lineStart=0;}
|
| +this._outgoingCallback();}}
|
| +function suppressUnused(value)
|
| +{};(function(window){window.CodeMirror={};(function(){"use strict";function splitLines(string){return string.split(/\r?\n|\r/);};function StringStream(string){this.pos=this.start=0;this.string=string;this.lineStart=0;}
|
| StringStream.prototype={eol:function(){return this.pos>=this.string.length;},sol:function(){return this.pos==0;},peek:function(){return this.string.charAt(this.pos)||null;},next:function(){if(this.pos<this.string.length)
|
| return this.string.charAt(this.pos++);},eat:function(match){var ch=this.string.charAt(this.pos);if(typeof match=="string")var ok=ch==match;else var ok=ch&&(match.test?match.test(ch):match(ch));if(ok){++this.pos;return ch;}},eatWhile:function(match){var start=this.pos;while(this.eat(match)){}
|
| return this.pos>start;},eatSpace:function(){var start=this.pos;while(/[\s\u00a0]/.test(this.string.charAt(this.pos)))++this.pos;return this.pos>start;},skipToEnd:function(){this.pos=this.string.length;},skipTo:function(ch){var found=this.string.indexOf(ch,this.pos);if(found>-1){this.pos=found;return true;}},backUp:function(n){this.pos-=n;},column:function(){return this.start-this.lineStart;},indentation:function(){return 0;},match:function(pattern,consume,caseInsensitive){if(typeof pattern=="string"){var cased=function(str){return caseInsensitive?str.toLowerCase():str;};var substr=this.string.substr(this.pos,pattern.length);if(cased(substr)==cased(pattern)){if(consume!==false)this.pos+=pattern.length;return true;}}else{var match=this.string.slice(this.pos).match(pattern);if(match&&match.index>0)return null;if(match&&consume!==false)this.pos+=match[0].length;return match;}},current:function(){return this.string.slice(this.start,this.pos);},hideFirstChars:function(n,inner){this.lineStart+=n;try{return inner();}
|
| @@ -495,38 +517,41 @@
|
| var local=CodeMirror.copyState(state.localMode,state.localState);return{token:state.token,localMode:state.localMode,localState:local,htmlState:CodeMirror.copyState(htmlMode,state.htmlState)};},token:function(stream,state){return state.token(stream,state);},indent:function(state,textAfter){if(!state.localMode||/^\s*<\//.test(textAfter))
|
| return htmlMode.indent(state.htmlState,textAfter);else if(state.localMode.indent)
|
| return state.localMode.indent(state.localState,textAfter);else
|
| -return CodeMirror.Pass;},electricChars:"/{}:",innerMode:function(state){return{state:state.localState||state.htmlState,mode:state.localMode||htmlMode};}};},"xml","javascript","css");CodeMirror.defineMIME("text/html","htmlmixed");;WebInspector={};FormatterWorker={};WebInspector.CodeMirrorUtils={createTokenizer:function(mimeType)
|
| +return CodeMirror.Pass;},electricChars:"/{}:",innerMode:function(state){return{state:state.localState||state.htmlState,mode:state.localMode||htmlMode};}};},"xml","javascript","css");CodeMirror.defineMIME("text/html","htmlmixed");;WebInspector={};FormatterWorker={createTokenizer:function(mimeType)
|
| {var mode=CodeMirror.getMode({indentUnit:2},mimeType);var state=CodeMirror.startState(mode);function tokenize(line,callback)
|
| {var stream=new CodeMirror.StringStream(line);while(!stream.eol()){var style=mode.token(stream,state);var value=stream.current();callback(value,style,stream.start,stream.start+value.length);stream.start=stream.pos;}}
|
| -return tokenize;},convertTokenType:function(tokenType)
|
| -{if(tokenType.startsWith("js-variable")||tokenType.startsWith("js-property")||tokenType==="js-def")
|
| -return"javascript-ident";if(tokenType==="js-string-2")
|
| -return"javascript-regexp";if(tokenType==="js-number"||tokenType==="js-comment"||tokenType==="js-string"||tokenType==="js-keyword")
|
| -return"javascript-"+tokenType.substring("js-".length);if(tokenType==="css-number")
|
| -return"css-number";return null;},overrideModeWithPrefixedTokens:function(modeName,tokenPrefix)
|
| -{var oldModeName=modeName+"-old";if(CodeMirror.modes[oldModeName])
|
| -return;CodeMirror.defineMode(oldModeName,CodeMirror.modes[modeName]);CodeMirror.defineMode(modeName,modeConstructor);function modeConstructor(config,parserConfig)
|
| -{var innerConfig={};for(var i in parserConfig)
|
| -innerConfig[i]=parserConfig[i];innerConfig.name=oldModeName;var codeMirrorMode=CodeMirror.getMode(config,innerConfig);codeMirrorMode.name=modeName;codeMirrorMode.token=tokenOverride.bind(null,codeMirrorMode.token);return codeMirrorMode;}
|
| -function tokenOverride(superToken,stream,state)
|
| -{var token=superToken(stream,state);return token?tokenPrefix+token:token;}}}
|
| -WebInspector.CodeMirrorUtils.overrideModeWithPrefixedTokens("css","css-");WebInspector.CodeMirrorUtils.overrideModeWithPrefixedTokens("javascript","js-");WebInspector.CodeMirrorUtils.overrideModeWithPrefixedTokens("xml","xml-");;var FormatterParameters;var onmessage=function(event){var data=(event.data);if(!data.method)
|
| +return tokenize;}};var FormatterParameters;var onmessage=function(event){var data=(event.data);if(!data.method)
|
| return;FormatterWorker[data.method](data.params);};FormatterWorker.format=function(params)
|
| {var indentString=params.indentString||" ";var result={};if(params.mimeType==="text/html"){var formatter=new FormatterWorker.HTMLFormatter(indentString);result=formatter.format(params.content);}else if(params.mimeType==="text/css"){result.mapping={original:[0],formatted:[0]};result.content=FormatterWorker._formatCSS(params.content,result.mapping,0,0,indentString);}else{result.mapping={original:[0],formatted:[0]};result.content=FormatterWorker._formatScript(params.content,result.mapping,0,0,indentString);}
|
| postMessage(result);}
|
| FormatterWorker._chunkCount=function(totalLength,chunkSize)
|
| {if(totalLength<=chunkSize)
|
| return 1;var remainder=totalLength%chunkSize;var partialLength=totalLength-remainder;return(partialLength/chunkSize)+(remainder?1:0);}
|
| -FormatterWorker.outline=function(params)
|
| -{const chunkSize=100000;const totalLength=params.content.length;const lines=params.content.split("\n");const chunkCount=FormatterWorker._chunkCount(totalLength,chunkSize);var outlineChunk=[];var previousIdentifier=null;var previousToken=null;var previousTokenType=null;var currentChunk=1;var processedChunkCharacters=0;var addedFunction=false;var isReadingArguments=false;var argumentsText="";var currentFunction=null;var tokenizer=WebInspector.CodeMirrorUtils.createTokenizer("text/javascript");for(var i=0;i<lines.length;++i){var line=lines[i];tokenizer(line,processToken);}
|
| +FormatterWorker.javaScriptOutline=function(params)
|
| +{var chunkSize=100000;var totalLength=params.content.length;var lines=params.content.split("\n");var chunkCount=FormatterWorker._chunkCount(totalLength,chunkSize);var outlineChunk=[];var previousIdentifier=null;var previousToken=null;var previousTokenType=null;var currentChunk=1;var processedChunkCharacters=0;var addedFunction=false;var isReadingArguments=false;var argumentsText="";var currentFunction=null;var tokenizer=FormatterWorker.createTokenizer("text/javascript");for(var i=0;i<lines.length;++i){var line=lines[i];tokenizer(line,processToken);}
|
| +function isJavaScriptIdentifier(tokenType)
|
| +{if(!tokenType)
|
| +return false;return tokenType.startsWith("variable")||tokenType.startsWith("property")||tokenType==="def";}
|
| function processToken(tokenValue,tokenType,column,newColumn)
|
| -{var convertedType=tokenType?WebInspector.CodeMirrorUtils.convertTokenType(tokenType):null;if(convertedType==="javascript-ident"){previousIdentifier=tokenValue;if(tokenValue&&previousToken==="function"){currentFunction={line:i,column:column,name:tokenValue};addedFunction=true;previousIdentifier=null;}}else if(convertedType==="javascript-keyword"){if(tokenValue==="function"){if(previousIdentifier&&(previousToken==="="||previousToken===":")){currentFunction={line:i,column:column,name:previousIdentifier};addedFunction=true;previousIdentifier=null;}}}else if(tokenValue==="."&&previousTokenType==="javascript-ident")
|
| +{if(isJavaScriptIdentifier(tokenType)){previousIdentifier=tokenValue;if(tokenValue&&previousToken==="function"){currentFunction={line:i,column:column,name:tokenValue};addedFunction=true;previousIdentifier=null;}}else if(tokenType==="keyword"){if(tokenValue==="function"){if(previousIdentifier&&(previousToken==="="||previousToken===":")){currentFunction={line:i,column:column,name:previousIdentifier};addedFunction=true;previousIdentifier=null;}}}else if(tokenValue==="."&&isJavaScriptIdentifier(previousTokenType))
|
| previousIdentifier+=".";else if(tokenValue==="("&&addedFunction)
|
| isReadingArguments=true;if(isReadingArguments&&tokenValue)
|
| argumentsText+=tokenValue;if(tokenValue===")"&&isReadingArguments){addedFunction=false;isReadingArguments=false;currentFunction.arguments=argumentsText.replace(/,[\r\n\s]*/g,", ").replace(/([^,])[\r\n\s]+/g,"$1");argumentsText="";outlineChunk.push(currentFunction);}
|
| -if(tokenValue.trim().length){previousToken=tokenValue;previousTokenType=convertedType;}
|
| +if(tokenValue.trim().length){previousToken=tokenValue;previousTokenType=tokenType;}
|
| processedChunkCharacters+=newColumn-column;if(processedChunkCharacters>=chunkSize){postMessage({chunk:outlineChunk,total:chunkCount,index:currentChunk++});outlineChunk=[];processedChunkCharacters=0;}}
|
| postMessage({chunk:outlineChunk,total:chunkCount,index:chunkCount});}
|
| +FormatterWorker.CSSParserStates={Initial:"Initial",Selector:"Selector",Style:"Style",PropertyName:"PropertyName",PropertyValue:"PropertyValue",AtRule:"AtRule",};FormatterWorker.parseCSS=function(params)
|
| +{var chunkSize=100000;var lines=params.content.split("\n");var rules=[];var processedChunkCharacters=0;var state=FormatterWorker.CSSParserStates.Initial;var rule;var property;var UndefTokenType={};function processToken(tokenValue,tokenTypes,column,newColumn)
|
| +{var tokenType=tokenTypes?tokenTypes.split(" ").keySet():UndefTokenType;switch(state){case FormatterWorker.CSSParserStates.Initial:if(tokenType["qualifier"]||tokenType["builtin"]||tokenType["tag"]){rule={selectorText:tokenValue,lineNumber:lineNumber,columNumber:column,properties:[],};state=FormatterWorker.CSSParserStates.Selector;}else if(tokenType["def"]){rule={atRule:tokenValue,lineNumber:lineNumber,columNumber:column,};state=FormatterWorker.CSSParserStates.AtRule;}
|
| +break;case FormatterWorker.CSSParserStates.Selector:if(tokenValue==="{"&&tokenType===UndefTokenType){rule.selectorText=rule.selectorText.trim();state=FormatterWorker.CSSParserStates.Style;}else{rule.selectorText+=tokenValue;}
|
| +break;case FormatterWorker.CSSParserStates.AtRule:if((tokenValue===";"||tokenValue==="{")&&tokenType===UndefTokenType){rule.atRule=rule.atRule.trim();rules.push(rule);state=FormatterWorker.CSSParserStates.Initial;}else{rule.atRule+=tokenValue;}
|
| +break;case FormatterWorker.CSSParserStates.Style:if(tokenType["meta"]||tokenType["property"]){property={name:tokenValue,value:"",};state=FormatterWorker.CSSParserStates.PropertyName;}else if(tokenValue==="}"&&tokenType===UndefTokenType){rules.push(rule);state=FormatterWorker.CSSParserStates.Initial;}
|
| +break;case FormatterWorker.CSSParserStates.PropertyName:if(tokenValue===":"&&tokenType["operator"]){property.name=property.name.trim();state=FormatterWorker.CSSParserStates.PropertyValue;}else if(tokenType["property"]){property.name+=tokenValue;}
|
| +break;case FormatterWorker.CSSParserStates.PropertyValue:if(tokenValue===";"&&tokenType===UndefTokenType){property.value=property.value.trim();rule.properties.push(property);state=FormatterWorker.CSSParserStates.Style;}else if(tokenValue==="}"&&tokenType===UndefTokenType){property.value=property.value.trim();rule.properties.push(property);rules.push(rule);state=FormatterWorker.CSSParserStates.Initial;}else if(!tokenType["comment"]){property.value+=tokenValue;}
|
| +break;default:console.assert(false,"Unknown CSS parser state.");}
|
| +processedChunkCharacters+=newColumn-column;if(processedChunkCharacters>chunkSize){postMessage({chunk:rules,isLastChunk:false});rules=[];processedChunkCharacters=0;}}
|
| +var tokenizer=FormatterWorker.createTokenizer("text/css");var lineNumber;for(lineNumber=0;lineNumber<lines.length;++lineNumber){var line=lines[lineNumber];tokenizer(line,processToken);}
|
| +postMessage({chunk:rules,isLastChunk:true});}
|
| FormatterWorker._formatScript=function(content,mapping,offset,formattedOffset,indentString)
|
| {var formattedContent;try{var tokenizer=new FormatterWorker.JavaScriptTokenizer(content);var builder=new FormatterWorker.JavaScriptFormattedContentBuilder(tokenizer.content(),mapping,offset,formattedOffset,indentString);var formatter=new FormatterWorker.JavaScriptFormatter(tokenizer,builder);formatter.format();formattedContent=builder.content();}catch(e){formattedContent=content;}
|
| return formattedContent;}
|
| @@ -536,7 +561,7 @@
|
| FormatterWorker.HTMLFormatter=function(indentString)
|
| {this._indentString=indentString;}
|
| FormatterWorker.HTMLFormatter.prototype={format:function(content)
|
| -{this.line=content;this._content=content;this._formattedContent="";this._mapping={original:[0],formatted:[0]};this._position=0;var scriptOpened=false;var styleOpened=false;var tokenizer=WebInspector.CodeMirrorUtils.createTokenizer("text/html");function processToken(tokenValue,tokenType,tokenStart,tokenEnd){if(tokenType!=="xml-tag")
|
| +{this.line=content;this._content=content;this._formattedContent="";this._mapping={original:[0],formatted:[0]};this._position=0;var scriptOpened=false;var styleOpened=false;var tokenizer=FormatterWorker.createTokenizer("text/html");function processToken(tokenValue,tokenType,tokenStart,tokenEnd){if(tokenType!=="tag")
|
| return;if(tokenValue.toLowerCase()==="<script"){scriptOpened=true;}else if(scriptOpened&&tokenValue===">"){scriptOpened=false;this._scriptStarted(tokenEnd);}else if(tokenValue.toLowerCase()==="</script"){this._scriptEnded(tokenStart);}else if(tokenValue.toLowerCase()==="<style"){styleOpened=true;}else if(styleOpened&&tokenValue===">"){styleOpened=false;this._styleStarted(tokenEnd);}else if(tokenValue.toLowerCase()==="</style"){this._styleEnded(tokenStart);}}
|
| tokenizer(content,processToken.bind(this));this._formattedContent+=this._content.substring(this._position);return{content:this._formattedContent,mapping:this._mapping};},_scriptStarted:function(cursor)
|
| {this._handleSubFormatterStart(cursor);},_scriptEnded:function(cursor)
|
| @@ -752,12 +777,12 @@
|
| return token;throw"Unknown token type "+uglifyToken.type;}};FormatterWorker.CSSFormatter=function(content,builder)
|
| {this._content=content;this._builder=builder;this._lastLine=-1;this._state={};}
|
| FormatterWorker.CSSFormatter.prototype={format:function()
|
| -{this._lineEndings=this._lineEndings(this._content);var tokenize=WebInspector.CodeMirrorUtils.createTokenizer("text/css");var lines=this._content.split("\n");for(var i=0;i<lines.length;++i){var line=lines[i];tokenize(line,this._tokenCallback.bind(this,i));}
|
| +{this._lineEndings=this._lineEndings(this._content);var tokenize=FormatterWorker.createTokenizer("text/css");var lines=this._content.split("\n");for(var i=0;i<lines.length;++i){var line=lines[i];tokenize(line,this._tokenCallback.bind(this,i));}
|
| this._builder.flushNewLines(true);},_lineEndings:function(text)
|
| {var lineEndings=[];var i=text.indexOf("\n");while(i!==-1){lineEndings.push(i);i=text.indexOf("\n",i+1);}
|
| lineEndings.push(text.length);return lineEndings;},_tokenCallback:function(startLine,token,type,startColumn)
|
| {if(startLine!==this._lastLine)
|
| -this._state.eatWhitespace=true;if(/^css-property/.test(type)&&!this._state.inPropertyValue)
|
| +this._state.eatWhitespace=true;if(/^property/.test(type)&&!this._state.inPropertyValue)
|
| this._state.seenProperty=true;this._lastLine=startLine;var isWhitespace=/^\s+$/.test(token);if(isWhitespace){if(!this._state.eatWhitespace)
|
| this._builder.addSpace();return;}
|
| this._state.eatWhitespace=false;if(token==="\n")
|
| @@ -765,7 +790,7 @@
|
| this._builder.addNewLine();this._state.afterClosingBrace=false;}
|
| var startPosition=(startLine?this._lineEndings[startLine-1]:0)+startColumn;if(token==="}"){if(this._state.inPropertyValue)
|
| this._builder.addNewLine();this._builder.decreaseNestingLevel();this._state.afterClosingBrace=true;this._state.inPropertyValue=false;}else if(token===":"&&!this._state.inPropertyValue&&this._state.seenProperty){this._builder.addToken(token,startPosition,startLine,startColumn);this._builder.addSpace();this._state.eatWhitespace=true;this._state.inPropertyValue=true;this._state.seenProperty=false;return;}else if(token==="{"){this._builder.addSpace();this._builder.addToken(token,startPosition,startLine,startColumn);this._builder.addNewLine();this._builder.increaseNestingLevel();return;}
|
| -this._builder.addToken(token,startPosition,startLine,startColumn);if(type==="css-comment"&&!this._state.inPropertyValue&&!this._state.seenProperty)
|
| +this._builder.addToken(token,startPosition,startLine,startColumn);if(type==="comment"&&!this._state.inPropertyValue&&!this._state.seenProperty)
|
| this._builder.addNewLine();if(token===";"&&this._state.inPropertyValue){this._state.inPropertyValue=false;this._builder.addNewLine();}else if(token==="}"){this._builder.addNewLine();}}}
|
| FormatterWorker.CSSFormattedContentBuilder=function(content,mapping,originalOffset,formattedOffset,indentString)
|
| {this._originalContent=content;this._originalOffset=originalOffset;this._lastOriginalPosition=0;this._formattedContent=[];this._formattedContentLength=0;this._formattedOffset=formattedOffset;this._lastFormattedPosition=0;this._mapping=mapping;this._lineNumber=0;this._nestingLevel=0;this._needNewLines=0;this._atLineStart=true;this._indentString=indentString;this._cachedIndents={};}
|
|
|