Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
js_minify.h
1 // Copyright 2010 Google Inc. All Rights Reserved.
14 
15 #ifndef PAGESPEED_KERNEL_JS_JS_MINIFY_H_
16 #define PAGESPEED_KERNEL_JS_JS_MINIFY_H_
17 
23 #include "pagespeed/kernel/js/js_tokenizer.h"
24 
25 namespace pagespeed {
26 
27 namespace js {
28 
33 enum JsWhitespace { kNoWhitespace, kSpace, kLinebreak };
34 
42  public:
45  JsMinifyingTokenizer(const JsTokenizerPatterns* patterns, StringPiece input);
46 
52  const JsTokenizerPatterns* patterns, StringPiece input,
53  net_instaweb::source_map::MappingVector* mappings);
54 
56 
58  JsKeywords::Type NextToken(StringPiece* token_out);
59 
62  bool has_error() const { return tokenizer_.has_error(); }
63 
64  private:
65  JsKeywords::Type NextTokenHelper(
66  StringPiece* token_out,
67  net_instaweb::source_map::Mapping* token_out_position);
68 
71  bool WhitespaceNeededBefore(JsKeywords::Type type, StringPiece token);
72 
73  JsTokenizer tokenizer_;
74  JsWhitespace whitespace_;
75  JsKeywords::Type prev_type_;
76  StringPiece prev_token_;
77  JsKeywords::Type next_type_;
78  StringPiece next_token_;
79  net_instaweb::source_map::MappingVector* mappings_;
80  net_instaweb::source_map::Mapping current_position_;
81  net_instaweb::source_map::Mapping next_position_;
82 
83 
84 };
85 
96 bool MinifyUtf8Js(const JsTokenizerPatterns* patterns,
97  StringPiece input, GoogleString* output);
98 
103 bool MinifyUtf8JsWithSourceMap(
104  const JsTokenizerPatterns* patterns,
105  StringPiece input, GoogleString* output,
106  net_instaweb::source_map::MappingVector* mappings);
107 
116 
118 bool MinifyJs(const StringPiece& input, GoogleString* out);
119 
121 bool GetMinifiedJsSize(const StringPiece& input, int* minimized_size);
122 
128 bool MinifyJsAndCollapseStrings(const StringPiece& input, GoogleString* output);
129 bool GetMinifiedStringCollapsedJsSize(const StringPiece& input,
130  int* minimized_size);
131 
132 }
133 
134 }
135 
136 #endif
bool has_error() const
Definition: js_minify.h:62
bool has_error() const
Definition: js_tokenizer.h:79
Definition: source_map.h:37
Type
Definition: js_keywords.h:33
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
JsKeywords::Type NextToken(StringPiece *token_out)
Gets the next token type from the input,.
Definition: js_tokenizer.h:194
Definition: js_tokenizer.h:62
JsMinifyingTokenizer(const JsTokenizerPatterns *patterns, StringPiece input)
Definition: js_minify.h:41