| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * @constructor | 32 * @constructor |
| 33 * @param {string} content | 33 * @param {string} content |
| 34 * @param {!FormatterWorker.JavaScriptFormattedContentBuilder} builder | 34 * @param {!FormatterWorker.JavaScriptFormattedContentBuilder} builder |
| 35 */ | 35 */ |
| 36 FormatterWorker.JavaScriptFormatter = function(content, builder) | 36 FormatterWorker.JavaScriptFormatter = function(content, builder) |
| 37 { | 37 { |
| 38 this._content = content; | 38 this._content = content; |
| 39 this._builder = builder; | 39 this._builder = builder; |
| 40 this._tokenizer = new FormatterWorker.AcornTokenizer(this._content); | 40 this._tokenizer = new WebInspector.AcornTokenizer(this._content); |
| 41 } | 41 } |
| 42 | 42 |
| 43 FormatterWorker.JavaScriptFormatter.prototype = { | 43 FormatterWorker.JavaScriptFormatter.prototype = { |
| 44 format: function() | 44 format: function() |
| 45 { | 45 { |
| 46 var ast = acorn.parse(this._content, { ranges: false, ecmaVersion: 6 }); | 46 var ast = acorn.parse(this._content, { ranges: false, ecmaVersion: 6 }); |
| 47 var walker = new WebInspector.ESTreeWalker(this._beforeVisit.bind(this),
this._afterVisit.bind(this)); | 47 var walker = new WebInspector.ESTreeWalker(this._beforeVisit.bind(this),
this._afterVisit.bind(this)); |
| 48 walker.walk(ast); | 48 walker.walk(ast); |
| 49 }, | 49 }, |
| 50 | 50 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 return false; | 111 return false; |
| 112 }, | 112 }, |
| 113 | 113 |
| 114 /** | 114 /** |
| 115 * @param {!ESTree.Node} node | 115 * @param {!ESTree.Node} node |
| 116 * @param {!Acorn.TokenOrComment} token | 116 * @param {!Acorn.TokenOrComment} token |
| 117 * @return {string} | 117 * @return {string} |
| 118 */ | 118 */ |
| 119 _formatToken: function(node, token) | 119 _formatToken: function(node, token) |
| 120 { | 120 { |
| 121 var AT = FormatterWorker.AcornTokenizer; | 121 var AT = WebInspector.AcornTokenizer; |
| 122 if (AT.lineComment(token)) | 122 if (AT.lineComment(token)) |
| 123 return "tn"; | 123 return "tn"; |
| 124 if (AT.blockComment(token)) | 124 if (AT.blockComment(token)) |
| 125 return "t"; | 125 return "t"; |
| 126 if (node.type === "ContinueStatement" || node.type === "BreakStatement")
{ | 126 if (node.type === "ContinueStatement" || node.type === "BreakStatement")
{ |
| 127 return node.label && AT.keyword(token) ? "ts" : "t"; | 127 return node.label && AT.keyword(token) ? "ts" : "t"; |
| 128 } else if (node.type === "Identifier") { | 128 } else if (node.type === "Identifier") { |
| 129 return "t"; | 129 return "t"; |
| 130 } else if (node.type === "ReturnStatement") { | 130 } else if (node.type === "ReturnStatement") { |
| 131 if (AT.punctuator(token, ";")) | 131 if (AT.punctuator(token, ";")) |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 _addMappingIfNeeded: function(originalPosition) | 418 _addMappingIfNeeded: function(originalPosition) |
| 419 { | 419 { |
| 420 if (originalPosition - this._lastOriginalPosition === this._formattedCon
tentLength - this._lastFormattedPosition) | 420 if (originalPosition - this._lastOriginalPosition === this._formattedCon
tentLength - this._lastFormattedPosition) |
| 421 return; | 421 return; |
| 422 this._mapping.original.push(this._originalOffset + originalPosition); | 422 this._mapping.original.push(this._originalOffset + originalPosition); |
| 423 this._lastOriginalPosition = originalPosition; | 423 this._lastOriginalPosition = originalPosition; |
| 424 this._mapping.formatted.push(this._formattedOffset + this._formattedCont
entLength); | 424 this._mapping.formatted.push(this._formattedOffset + this._formattedCont
entLength); |
| 425 this._lastFormattedPosition = this._formattedContentLength; | 425 this._lastFormattedPosition = this._formattedContentLength; |
| 426 } | 426 } |
| 427 } | 427 } |
| OLD | NEW |