Page Speed Optimization Libraries
1.13.35.1
|
#include "javascript_code_block.h"
Public Member Functions | |
JavascriptCodeBlock (const StringPiece &original_code, JavascriptRewriteConfig *config, const StringPiece &message_id, MessageHandler *handler) | |
bool | Rewrite () |
bool | successfully_rewritten () const |
StringPiece | rewritten_code () const |
const source_map::MappingVector & | SourceMappings () const |
void | AppendSourceMapUrl (StringPiece url) |
StringPiece | ComputeJavascriptLibrary () const |
void | SwapRewrittenString (GoogleString *other) |
const GoogleString & | message_id () const |
Get message id passed in at creation time, for external diagnostics. | |
Static Public Member Functions | |
static bool | UnsafeToRename (const StringPiece &script) |
static void | ToJsStringLiteral (const StringPiece &original, GoogleString *escaped) |
static GoogleString | JsUrlHash (const GoogleString &url, Hasher *hasher) |
Static Public Attributes | |
static const char | kIntrospectionComment [] |
Object representing a block of Javascript code that might be a candidate for rewriting.
For now, we're content just being able to pull data in and parse it at all.
void net_instaweb::JavascriptCodeBlock::AppendSourceMapUrl | ( | StringPiece | url | ) |
Annotate rewritten_code() with a source map URL.
Call this after Rewrite() and before rewritten_code() if you want to append a comment to the minified JS indicating the URL for the source map. Note: Source map URL may not be appended if url is unsanitary, but this probably shouldn't happen in practice.
StringPiece net_instaweb::JavascriptCodeBlock::ComputeJavascriptLibrary | ( | ) | const |
Is the current block a JS library that can be redirected to a canonical URL? If so, return that canonical URL (storage owned by the underlying config object passed in at construction), otherwise return an empty StringPiece.
PRECONDITION: Rewrite() must have been called first.
|
inlinestatic |
Generates a hash of a URL escaped to be safe to use in a Javascript identifier, so that variable names can be safely created that won't collide with other local Javascript.
Hashes may contain '-', which isn't valid in a JavaScript name, so replace every '-' with '$'.
bool net_instaweb::JavascriptCodeBlock::Rewrite | ( | ) |
Attempt to rewrite the file. Returns true if we should use the rewritten version. Must be called before successfully_rewritten(), rewritten_code() and ComputeJavascriptLibrary().
|
inline |
PRECONDITION: Rewrite() must have been called first and successfully_rewritten() must be true.
|
inline |
Returns the contents of a source map from original to rewritten. PRECONDITION: Rewrite() must have been called first and successfully_rewritten() must be true.
|
inline |
Should we use the rewritten version? PRECONDITION: Rewrite() must have been called first.
void net_instaweb::JavascriptCodeBlock::SwapRewrittenString | ( | GoogleString * | other | ) |
Swaps rewritten_code_ into *other. Afterward the JavascriptCodeBlock will be cleared and unusable. PRECONDITION: Rewrite() must have been called first and successfully_rewritten() must be true.
|
inlinestatic |
Converts a regular string to what can be used in Javascript directly. Note that output also contains starting and ending quotes, to facilitate embedding.
add quotes
|
static |
Determines whether the javascript is brittle and will likely break if we alter its URL.
|
static |
If debug_filter and AvoidRenamingIntrospectiveJavascript option are turned on, this comment will be injected right after the introspective Javascript context for debugging.