Skip to content
This repository has been archived by the owner on Jan 22, 2024. It is now read-only.

Upgrade Closure to v20150609 #313

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions jaggr-core/WebContent/loaderExtCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ var params = {

extraArgs = {},

featureFilter =
/**
* Default feature filter allows all features
*
* @return true if the specified feature should be included
* @return {boolean} true if the specified feature should be included
* in the list of features sent to the aggregator
*/
featureFilter = function(feature) {return true;},
function(feature) {return true;},

/**
* Array of functions that process a url, returning the new,
Expand Down Expand Up @@ -88,6 +89,7 @@ var params = {
return size;
},

addFoldedModuleName =
/**
* Adds the module specified by dep to the list of folded module names
* in oFolded.
Expand All @@ -107,7 +109,7 @@ var params = {
* plugin, then the plugin name and its ordinal are added to this
* map.
*/
addFoldedModuleName = function(dep, position, oFolded, oPrefixes) {
function(dep, position, oFolded, oPrefixes) {
var name = dep.name,
segments = name.split('/'),
len = segments.length,
Expand Down Expand Up @@ -146,6 +148,7 @@ var params = {
}
},

addModuleIdEncoded =
/**
* Adds the module specified by dep to the encoded module id list at the specified
* list position. The encoded module id list uses the mapping of module name to
Expand Down Expand Up @@ -179,7 +182,7 @@ var params = {
* the server.
* @return true if the module was added to the encoded list
*/
addModuleIdEncoded = function(dep, position, encodedIds, moduleIdMap) {
function(dep, position, encodedIds, moduleIdMap) {

var nameId = moduleIdMap[dep.name], result = false,
pluginNameId = dep.prefix ? moduleIdMap[dep.prefix] : 0;
Expand Down Expand Up @@ -266,6 +269,7 @@ var params = {
return asEnc.join('');
},

base64EncodeModuleIds =
/**
* Performs base64 encoding of the encoded module id list
*
Expand All @@ -275,7 +279,7 @@ var params = {
* the base64 encoder
* @return the URL safe base64 encoded representation of the number array
*/
base64EncodeModuleIds = function(ids, encoder, idListHash) {
function(ids, encoder, idListHash) {
// First, determine the max id. If max id is less than 64k, then we can
// use 16-bit encoding. Otherwise, we need to use 32-bit encoding.
var use32BitEncoding = false;
Expand Down Expand Up @@ -305,6 +309,7 @@ var params = {
});
},

addModulesToUrl =
/**
* Adds the list of modules specified in opt_deps to the request as
* request URL query args. For each module in the list, we will try
Expand All @@ -327,7 +332,7 @@ var params = {
* the base64 encoder to use for encoding the encoded module id
* list.
*/
addModulesToUrl = function(url, argNames, opt_deps, moduleIdMap, base64Encoder) {
function(url, argNames, opt_deps, moduleIdMap, base64Encoder) {
var oFolded = {},
oPrefixes = {},
ids = [],
Expand Down
10 changes: 10 additions & 0 deletions jaggr-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@
</Import-Package>
<Embed-Dependency>
closure-compiler,
protobuf-java,
gson,
commons-codec,
commons-io,
commons-lang3,
Expand Down Expand Up @@ -392,6 +394,14 @@
<groupId>com.google.javascript</groupId>
<artifactId>closure-compiler</artifactId>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>org.mozilla</groupId>
<artifactId>rhino</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
import com.ibm.jaggr.core.util.CompilerUtil;

import com.google.javascript.jscomp.Compiler;
import com.google.javascript.jscomp.JSSourceFile;
import com.google.javascript.jscomp.SourceFile;
import com.google.javascript.rhino.Node;

import java.io.InputStream;
import java.net.URI;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
Expand Down Expand Up @@ -77,7 +78,7 @@ public URI call() throws Exception {
InputStream in = resource.getInputStream();
Node node = null;
try {
node = compiler.parse(JSSourceFile.fromInputStream(resource.getURI().toString(), in));
node = compiler.parse(SourceFile.fromInputStream(resource.getURI().toString(), in, Charset.forName("UTF-8"))); //$NON-NLS-1$
} catch (Throwable e) {
if (log.isLoggable(Level.WARNING)) {
log.log(Level.WARNING, "Error occurred parsing " + resource.getURI().toString() + ": " + e.getMessage(), e); //$NON-NLS-1$ //$NON-NLS-2$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void processChildren(Node node) {
name.getString().equals("define")) { // name is "define" //$NON-NLS-1$
Node param = name.getNext();
if (param != null && param.getType() != Token.STRING) {
String expname = name.getProp(Node.SOURCENAME_PROP).toString();
String expname = name.getSourceFileName();
if (source != null) {
PositionLocator locator = source.locate(name.getLineno(), name.getCharno()+6);
char tok = locator.findNextJSToken(); // move cursor to the open paren
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@
import com.ibm.jaggr.core.util.RequestUtil;
import com.ibm.jaggr.core.util.StringUtil;

import com.google.common.collect.HashMultimap;
import com.google.javascript.jscomp.CheckLevel;
import com.google.javascript.jscomp.CompilationLevel;
import com.google.javascript.jscomp.Compiler;
import com.google.javascript.jscomp.CompilerOptions;
import com.google.javascript.jscomp.CustomPassExecutionTime;
import com.google.javascript.jscomp.DiagnosticGroups;
import com.google.javascript.jscomp.JSError;
import com.google.javascript.jscomp.JSSourceFile;
import com.google.javascript.jscomp.Result;
import com.google.javascript.jscomp.SourceFile;

import org.apache.commons.lang3.mutable.MutableBoolean;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -94,7 +94,7 @@
public class JavaScriptModuleBuilder implements IModuleBuilder, IExtensionInitializer, ILayerListener, IShutdownListener {
private static final Logger log = Logger.getLogger(JavaScriptModuleBuilder.class.getName());

private static final List<JSSourceFile> externs = Collections.emptyList();
private static final List<SourceFile> externs = Collections.emptyList();

/**
* Name of the request attribute containing the expanded dependencies for
Expand Down Expand Up @@ -306,15 +306,15 @@ public ModuleBuild build(
throw new NotFoundException(resource.getURI().toString());
}

List<JSSourceFile> sources = this.getJSSource(mid, resource, request, keyGens);
List<SourceFile> sources = this.getJSSource(mid, resource, request, keyGens);

JSSource source = null;
if (level == null) {
// If optimization level is none, then we need to modify the source code
// when expanding require lists and exporting module names because the
// parsed AST produced by closure does not preserve whitespace and comments.
StringBuffer code = new StringBuffer();
for (JSSourceFile sf : sources) {
for (SourceFile sf : sources) {
code.append(sf.getCode());
}
source = new JSSource(code.toString(), mid);
Expand All @@ -336,7 +336,7 @@ public ModuleBuild build(

Compiler compiler = new Compiler();
CompilerOptions compiler_options = CompilerUtil.getDefaultOptions();
compiler_options.customPasses = HashMultimap.create();
//compiler_options.setWarningLevel(DiagnosticGroups.CHECK_USELESS_CODE, CheckLevel.OFF);
if (isHasFiltering && (level != null || keyGens == null)) {
// Run has filtering compiler pass if we are doing has filtering, or if this
// is the first build for this module (keyGens == null) so that we can get
Expand All @@ -346,7 +346,7 @@ public ModuleBuild build(
keyGens == null ? hasFiltDiscoveredHasConditionals : null,
coerceUndefinedToFalse
);
compiler_options.customPasses.put(CustomPassExecutionTime.BEFORE_CHECKS, hfcp);
compiler_options.addCustomPass(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS, hfcp);
}

boolean isReqExpLogging = RequestUtil.isDependencyExpansionLogging(request);
Expand All @@ -371,7 +371,7 @@ public ModuleBuild build(
isReqExpLogging,
source);

compiler_options.customPasses.put(CustomPassExecutionTime.BEFORE_CHECKS, recp);
compiler_options.addCustomPass(CustomPassExecutionTime.BEFORE_CHECKS, recp);

// Call IRequestedModuleNames.getBaseLayerDeps() in case it throws an exception so that
// we propagate it here instead of in layerBeginEndNotifier where we can't propagate
Expand All @@ -382,7 +382,7 @@ public ModuleBuild build(
}
}
if (RequestUtil.isExportModuleName(request)) {
compiler_options.customPasses.put(
compiler_options.addCustomPass(
CustomPassExecutionTime.BEFORE_CHECKS,
new ExportModuleNameCompilerPass(source)
);
Expand Down Expand Up @@ -459,7 +459,7 @@ public ModuleBuild build(
// together with the uncompressed source.
String errorMsg = StringUtil.escapeForJavaScript(sb.toString());
StringBuffer code = new StringBuffer();
for (JSSourceFile sf : sources) {
for (SourceFile sf : sources) {
code.append(sf.getCode());
}
return new ModuleBuild(code.toString(), null, errorMsg);
Expand Down Expand Up @@ -490,11 +490,11 @@ public ModuleBuild build(
* @return the list of source files
* @throws IOException
*/
protected List<JSSourceFile> getJSSource(String mid, IResource resource, HttpServletRequest request, List<ICacheKeyGenerator> keyGens) throws IOException {
protected List<SourceFile> getJSSource(String mid, IResource resource, HttpServletRequest request, List<ICacheKeyGenerator> keyGens) throws IOException {

List<JSSourceFile> result = new LinkedList<JSSourceFile>();
List<SourceFile> result = new LinkedList<SourceFile>();
InputStream in = resource.getInputStream();
JSSourceFile sf = JSSourceFile.fromInputStream(mid, in);
SourceFile sf = SourceFile.fromInputStream(mid, in, Charset.forName("UTF-8")); //$NON-NLS-1$
sf.setOriginalPath(resource.getURI().toString());
in.close();
result.add(sf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public void processChildren(Node node, List<DependencyList> enclosingDependencie
) : null,
false);
} else if ((dependencies = NodeUtil.moduleDepsFromDefine(cursor)) != null) {
String moduleName = cursor.getFirstChild().getProp(Node.SOURCENAME_PROP).toString();
String moduleName = cursor.getFirstChild().getSourceFileName();

if (aggregator.getOptions().isDevelopmentMode() &&
aggregator.getOptions().isVerifyDeps()) {
Expand Down Expand Up @@ -311,7 +311,7 @@ private void expandRequireList(Node array, List<DependencyList> enclosingDepende
return;
}
List<String> msg = new LinkedList<String>();
String moduleName = array.getParent().getProp(Node.SOURCENAME_PROP).toString();
String moduleName = array.getParent().getSourceFileName();
if (logDebug) {
msg.add("%c" + MessageFormat.format( //$NON-NLS-1$
Messages.RequireExpansionCompilerPass_6,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ public static Node moduleDepsFromRequire(Node cursor) {
* null.
*/
public static Node moduleDepsFromConfigDeps(Node cursor, String configVarName) {
if (cursor.getType() == Token.STRING && cursor.getString().equals("deps")) { //$NON-NLS-1$
if ((cursor.getType() == Token.STRING || cursor.getType() == Token.STRING_KEY)
&& cursor.getString().equals("deps")) { //$NON-NLS-1$
// handle require.deps assignment of array literal
Node parent = cursor.getParent(),
previousSibling = parent.getChildBefore(cursor);
Expand Down Expand Up @@ -177,7 +178,7 @@ public static Node moduleDepsFromConfigDeps(Node cursor, String configVarName) {
// var require = { deps: [...] }
return cursor.getFirstChild();
} else if (parent.getType() == Token.OBJECTLIT &&
parent.getParent().getType() == Token.STRING &&
parent.getParent().getType() == Token.STRING_KEY &&
parent.getParent().getString().equals(configVarName) &&
parent.getParent().getParent().getType() == Token.OBJECTLIT &&
cursor.getFirstChild() != null &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import com.ibm.jaggr.core.impl.deps.DepUtils.ParseResult;

import com.google.javascript.jscomp.Compiler;
import com.google.javascript.jscomp.JSSourceFile;
import com.google.javascript.jscomp.SourceFile;
import com.google.javascript.rhino.Node;

import org.junit.Test;
Expand Down Expand Up @@ -123,25 +123,25 @@ public void testParseDependencies() {


Compiler compiler = new Compiler();
Node node = compiler.parse(JSSourceFile.fromCode("js1", js1));
Node node = compiler.parse(SourceFile.fromCode("js1", js1));
Collection<String> deps = DepUtils.parseDependencies(node, new HashSet<String>()).getDefineDependencies();
assertEquals(deps.toString(), "[a, b, c]");
node = compiler.parse(JSSourceFile.fromCode("js2", js2));
node = compiler.parse(SourceFile.fromCode("js2", js2));
deps = DepUtils.parseDependencies(node, new HashSet<String>()).getDefineDependencies();
assertEquals(deps.toString(), "[a, b, c]");
node = compiler.parse(JSSourceFile.fromCode("js3", js3));
node = compiler.parse(SourceFile.fromCode("js3", js3));
deps = DepUtils.parseDependencies(node, new HashSet<String>()).getDefineDependencies();
assertEquals(deps.size(), 0);
node = compiler.parse(JSSourceFile.fromCode("js4", js4));
node = compiler.parse(SourceFile.fromCode("js4", js4));
deps = DepUtils.parseDependencies(node, new HashSet<String>()).getDefineDependencies();
assertEquals(deps.toString(), "[a, b, c]");
node = compiler.parse(JSSourceFile.fromCode("js5", js5));
node = compiler.parse(SourceFile.fromCode("js5", js5));
deps = DepUtils.parseDependencies(node, new HashSet<String>()).getDefineDependencies();
assertNull(deps);
node = compiler.parse(JSSourceFile.fromCode("js6", js6));
node = compiler.parse(SourceFile.fromCode("js6", js6));
deps = DepUtils.parseDependencies(node, new HashSet<String>()).getDefineDependencies();
assertNull(deps);
node = compiler.parse(JSSourceFile.fromCode("js7", js7));
node = compiler.parse(SourceFile.fromCode("js7", js7));
// Test dependent features
Set<String> dependentFeatures = new HashSet<String>();
ParseResult parseResult = DepUtils.parseDependencies(node, dependentFeatures);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import com.google.javascript.jscomp.Compiler;
import com.google.javascript.jscomp.Compiler.CodeBuilder;
import com.google.javascript.jscomp.JSSourceFile;
import com.google.javascript.jscomp.SourceFile;
import com.google.javascript.rhino.Node;

import org.junit.Test;
Expand Down Expand Up @@ -80,7 +80,7 @@ public void testSourceUpdate() throws Exception {

private String runPass(String moduleName, String code) {
Compiler compiler = new Compiler();
Node root = compiler.parse(JSSourceFile.fromCode(moduleName, code));
Node root = compiler.parse(SourceFile.fromCode(moduleName, code));
pass.process(null, root);
CodeBuilder cb = new CodeBuilder();
compiler.toSource(cb, 0, root);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@

package com.ibm.jaggr.core.impl.modulebuilder.javascript;

import com.ibm.jaggr.core.impl.modulebuilder.javascript.HasFilteringCompilerPass;
import com.ibm.jaggr.core.util.Features;

import com.google.javascript.jscomp.Compiler;
import com.google.javascript.jscomp.Compiler.CodeBuilder;
import com.google.javascript.jscomp.JSSourceFile;
import com.google.javascript.jscomp.SourceFile;
import com.google.javascript.rhino.Node;

import org.junit.Assert;
Expand Down Expand Up @@ -193,7 +192,7 @@ public void testProcess() throws Exception {

private String runPass(HasFilteringCompilerPass pass, String code) {
Compiler compiler = new Compiler();
Node root = compiler.parse(JSSourceFile.fromCode("test", code));
Node root = compiler.parse(SourceFile.fromCode("test", code));
pass.process(null, root);
CodeBuilder cb = new CodeBuilder();
compiler.toSource(cb, 0, root);
Expand Down
Loading