Class SemicolonResourceContentAnnotator
java.lang.Object
com.atlassian.plugin.webresource.impl.annotators.ResourceContentAnnotator
com.atlassian.plugin.webresource.impl.annotators.SemicolonResourceContentAnnotator
Prepend and append a semicolon.
If a JavaScript file follows another that doesn't end with a semicolon, when it's batched, it's possible for the semantics of the JavaScript to change. Consider the following:
// FILE ONE.js
console.log("Loading...")
// FILE TWO.js
(function () {})()
When batched, it's turned into:
console.log("Loading...")(function () {})()
(Notice that the result of `console.log` is being *executed* with `function () {}` passed in as an argument. This
means you'll get an exception like this:
TypeError: undefined is not a functionThis is a stateless implementation of the
ResourceContentAnnotator that will write a semicolon before and
after each resource.- Since:
- 3.1.1
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidafterResourceInBatch(LinkedHashSet<String> requiredResources, Resource resource, Map<String, String> params, OutputStream stream) Called after the resource content is written in batch.intbeforeResourceInBatch(LinkedHashSet<String> requiredResources, Resource resource, Map<String, String> params, OutputStream stream) Called before the resource content is written in batch.inthashCode()Produce a hash for this instance.Methods inherited from class com.atlassian.plugin.webresource.impl.annotators.ResourceContentAnnotator
afterAllResourcesInBatch, afterResource, beforeAllResourcesInBatch, beforeResource
-
Constructor Details
-
SemicolonResourceContentAnnotator
public SemicolonResourceContentAnnotator()
-
-
Method Details
-
beforeResourceInBatch
public int beforeResourceInBatch(LinkedHashSet<String> requiredResources, Resource resource, Map<String, String> params, OutputStream stream) throws IOExceptionDescription copied from class:ResourceContentAnnotatorCalled before the resource content is written in batch.- Overrides:
beforeResourceInBatchin classResourceContentAnnotator- Returns:
- amount of lines the annotator adds to the source, used for source map generation.
- Throws:
IOException- if there is a problem writing the annotation.
-
afterResourceInBatch
public void afterResourceInBatch(LinkedHashSet<String> requiredResources, Resource resource, Map<String, String> params, OutputStream stream) throws IOExceptionDescription copied from class:ResourceContentAnnotatorCalled after the resource content is written in batch.- Overrides:
afterResourceInBatchin classResourceContentAnnotator- Throws:
IOException- if there is a problem writing the annotation.
-
hashCode
public int hashCode()Description copied from class:ResourceContentAnnotatorProduce a hash for this instance. Should be stable across jvms.- Specified by:
hashCodein classResourceContentAnnotator
-