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 10 matching lines...) Expand all Loading... |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 function FormattedContentBuilder(content, mapping, originalOffset, formattedOffs
et, indentString) | 31 function JavaScriptFormattedContentBuilder(content, mapping, originalOffset, for
mattedOffset, indentString) |
32 { | 32 { |
33 this._originalContent = content; | 33 this._originalContent = content; |
34 this._originalOffset = originalOffset; | 34 this._originalOffset = originalOffset; |
35 this._lastOriginalPosition = 0; | 35 this._lastOriginalPosition = 0; |
36 | 36 |
37 this._formattedContent = []; | 37 this._formattedContent = []; |
38 this._formattedContentLength = 0; | 38 this._formattedContentLength = 0; |
39 this._formattedOffset = formattedOffset; | 39 this._formattedOffset = formattedOffset; |
40 this._lastFormattedPosition = 0; | 40 this._lastFormattedPosition = 0; |
41 | 41 |
42 this._mapping = mapping; | 42 this._mapping = mapping; |
43 | 43 |
44 this._lineNumber = 0; | 44 this._lineNumber = 0; |
45 this._nestingLevel = 0; | 45 this._nestingLevel = 0; |
46 this._indentString = indentString; | 46 this._indentString = indentString; |
47 this._cachedIndents = {}; | 47 this._cachedIndents = {}; |
48 } | 48 } |
49 | 49 |
50 FormattedContentBuilder.prototype = { | 50 JavaScriptFormattedContentBuilder.prototype = { |
51 addToken: function(token) | 51 addToken: function(token) |
52 { | 52 { |
53 for (var i = 0; i < token.comments_before.length; ++i) | 53 for (var i = 0; i < token.comments_before.length; ++i) |
54 this._addComment(token.comments_before[i]); | 54 this._addComment(token.comments_before[i]); |
55 | 55 |
56 while (this._lineNumber < token.line) { | 56 while (this._lineNumber < token.line) { |
57 this._addText("\n"); | 57 this._addText("\n"); |
58 this._addIndent(); | 58 this._addIndent(); |
59 this._needNewLine = false; | 59 this._needNewLine = false; |
60 this._lineNumber += 1; | 60 this._lineNumber += 1; |
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
906 this._builder.addSpace(); | 906 this._builder.addSpace(); |
907 | 907 |
908 this._expect(Tokens.LBRACE); | 908 this._expect(Tokens.LBRACE); |
909 this._builder.addNewLine(); | 909 this._builder.addNewLine(); |
910 this._builder.increaseNestingLevel(); | 910 this._builder.increaseNestingLevel(); |
911 this._parseSourceElements(Tokens.RBRACE); | 911 this._parseSourceElements(Tokens.RBRACE); |
912 this._builder.decreaseNestingLevel(); | 912 this._builder.decreaseNestingLevel(); |
913 this._expect(Tokens.RBRACE); | 913 this._expect(Tokens.RBRACE); |
914 } | 914 } |
915 } | 915 } |
OLD | NEW |