id int32 0 165k | repo stringlengths 7 58 | path stringlengths 12 218 | func_name stringlengths 3 140 | original_string stringlengths 73 34.1k | language stringclasses 1 value | code stringlengths 73 34.1k | code_tokens list | docstring stringlengths 3 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 105 339 |
|---|---|---|---|---|---|---|---|---|---|---|---|
24,800 | google/closure-compiler | src/com/google/javascript/jscomp/JSModuleGraph.java | JSModuleGraph.getModulesByName | Map<String, JSModule> getModulesByName() {
Map<String, JSModule> result = new HashMap<>();
for (JSModule m : modules) {
result.put(m.getName(), m);
}
return result;
} | java | Map<String, JSModule> getModulesByName() {
Map<String, JSModule> result = new HashMap<>();
for (JSModule m : modules) {
result.put(m.getName(), m);
}
return result;
} | [
"Map",
"<",
"String",
",",
"JSModule",
">",
"getModulesByName",
"(",
")",
"{",
"Map",
"<",
"String",
",",
"JSModule",
">",
"result",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"for",
"(",
"JSModule",
"m",
":",
"modules",
")",
"{",
"result",
".",
"put",
"(",
"m",
".",
"getName",
"(",
")",
",",
"m",
")",
";",
"}",
"return",
"result",
";",
"}"
] | Gets all modules indexed by name. | [
"Gets",
"all",
"modules",
"indexed",
"by",
"name",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/JSModuleGraph.java#L277-L283 |
24,801 | google/closure-compiler | src/com/google/javascript/jscomp/JSModuleGraph.java | JSModuleGraph.dependsOn | public boolean dependsOn(JSModule src, JSModule m) {
return src != m && selfPlusTransitiveDeps[src.getIndex()].get(m.getIndex());
} | java | public boolean dependsOn(JSModule src, JSModule m) {
return src != m && selfPlusTransitiveDeps[src.getIndex()].get(m.getIndex());
} | [
"public",
"boolean",
"dependsOn",
"(",
"JSModule",
"src",
",",
"JSModule",
"m",
")",
"{",
"return",
"src",
"!=",
"m",
"&&",
"selfPlusTransitiveDeps",
"[",
"src",
".",
"getIndex",
"(",
")",
"]",
".",
"get",
"(",
"m",
".",
"getIndex",
"(",
")",
")",
";",
"}"
] | Determines whether this module depends on a given module. Note that a
module never depends on itself, as that dependency would be cyclic. | [
"Determines",
"whether",
"this",
"module",
"depends",
"on",
"a",
"given",
"module",
".",
"Note",
"that",
"a",
"module",
"never",
"depends",
"on",
"itself",
"as",
"that",
"dependency",
"would",
"be",
"cyclic",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/JSModuleGraph.java#L339-L341 |
24,802 | google/closure-compiler | src/com/google/javascript/jscomp/JSModuleGraph.java | JSModuleGraph.getSmallestCoveringSubtree | public JSModule getSmallestCoveringSubtree(JSModule parentTree, BitSet dependentModules) {
checkState(!dependentModules.isEmpty());
// Candidate modules are those that all of the given dependent modules depend on, including
// themselves. The dependent module with the smallest index might be our answer, if all
// the other modules depend on it.
int minDependentModuleIndex = modules.length;
final BitSet candidates = new BitSet(modules.length);
candidates.set(0, modules.length, true);
for (int dependentIndex = dependentModules.nextSetBit(0);
dependentIndex >= 0;
dependentIndex = dependentModules.nextSetBit(dependentIndex + 1)) {
minDependentModuleIndex = Math.min(minDependentModuleIndex, dependentIndex);
candidates.and(selfPlusTransitiveDeps[dependentIndex]);
}
checkState(
!candidates.isEmpty(), "No common dependency found for %s", dependentModules);
// All candidates must have an index <= the smallest dependent module index.
// Work backwards through the candidates starting with the dependent module with the smallest
// index. For each candidate, we'll remove all of the modules it depends on from consideration,
// since they must all have larger subtrees than the one we're considering.
int parentTreeIndex = parentTree.getIndex();
// default to parent tree if we don't find anything better
int bestCandidateIndex = parentTreeIndex;
for (int candidateIndex = candidates.previousSetBit(minDependentModuleIndex);
candidateIndex >= 0;
candidateIndex = candidates.previousSetBit(candidateIndex - 1)) {
BitSet candidatePlusTransitiveDeps = selfPlusTransitiveDeps[candidateIndex];
if (candidatePlusTransitiveDeps.get(parentTreeIndex)) {
// candidate is a subtree of parentTree
candidates.andNot(candidatePlusTransitiveDeps);
if (subtreeSize[candidateIndex] < subtreeSize[bestCandidateIndex]) {
bestCandidateIndex = candidateIndex;
}
} // eliminate candidates that are not a subtree of parentTree
}
return modules[bestCandidateIndex];
} | java | public JSModule getSmallestCoveringSubtree(JSModule parentTree, BitSet dependentModules) {
checkState(!dependentModules.isEmpty());
// Candidate modules are those that all of the given dependent modules depend on, including
// themselves. The dependent module with the smallest index might be our answer, if all
// the other modules depend on it.
int minDependentModuleIndex = modules.length;
final BitSet candidates = new BitSet(modules.length);
candidates.set(0, modules.length, true);
for (int dependentIndex = dependentModules.nextSetBit(0);
dependentIndex >= 0;
dependentIndex = dependentModules.nextSetBit(dependentIndex + 1)) {
minDependentModuleIndex = Math.min(minDependentModuleIndex, dependentIndex);
candidates.and(selfPlusTransitiveDeps[dependentIndex]);
}
checkState(
!candidates.isEmpty(), "No common dependency found for %s", dependentModules);
// All candidates must have an index <= the smallest dependent module index.
// Work backwards through the candidates starting with the dependent module with the smallest
// index. For each candidate, we'll remove all of the modules it depends on from consideration,
// since they must all have larger subtrees than the one we're considering.
int parentTreeIndex = parentTree.getIndex();
// default to parent tree if we don't find anything better
int bestCandidateIndex = parentTreeIndex;
for (int candidateIndex = candidates.previousSetBit(minDependentModuleIndex);
candidateIndex >= 0;
candidateIndex = candidates.previousSetBit(candidateIndex - 1)) {
BitSet candidatePlusTransitiveDeps = selfPlusTransitiveDeps[candidateIndex];
if (candidatePlusTransitiveDeps.get(parentTreeIndex)) {
// candidate is a subtree of parentTree
candidates.andNot(candidatePlusTransitiveDeps);
if (subtreeSize[candidateIndex] < subtreeSize[bestCandidateIndex]) {
bestCandidateIndex = candidateIndex;
}
} // eliminate candidates that are not a subtree of parentTree
}
return modules[bestCandidateIndex];
} | [
"public",
"JSModule",
"getSmallestCoveringSubtree",
"(",
"JSModule",
"parentTree",
",",
"BitSet",
"dependentModules",
")",
"{",
"checkState",
"(",
"!",
"dependentModules",
".",
"isEmpty",
"(",
")",
")",
";",
"// Candidate modules are those that all of the given dependent modules depend on, including",
"// themselves. The dependent module with the smallest index might be our answer, if all",
"// the other modules depend on it.",
"int",
"minDependentModuleIndex",
"=",
"modules",
".",
"length",
";",
"final",
"BitSet",
"candidates",
"=",
"new",
"BitSet",
"(",
"modules",
".",
"length",
")",
";",
"candidates",
".",
"set",
"(",
"0",
",",
"modules",
".",
"length",
",",
"true",
")",
";",
"for",
"(",
"int",
"dependentIndex",
"=",
"dependentModules",
".",
"nextSetBit",
"(",
"0",
")",
";",
"dependentIndex",
">=",
"0",
";",
"dependentIndex",
"=",
"dependentModules",
".",
"nextSetBit",
"(",
"dependentIndex",
"+",
"1",
")",
")",
"{",
"minDependentModuleIndex",
"=",
"Math",
".",
"min",
"(",
"minDependentModuleIndex",
",",
"dependentIndex",
")",
";",
"candidates",
".",
"and",
"(",
"selfPlusTransitiveDeps",
"[",
"dependentIndex",
"]",
")",
";",
"}",
"checkState",
"(",
"!",
"candidates",
".",
"isEmpty",
"(",
")",
",",
"\"No common dependency found for %s\"",
",",
"dependentModules",
")",
";",
"// All candidates must have an index <= the smallest dependent module index.",
"// Work backwards through the candidates starting with the dependent module with the smallest",
"// index. For each candidate, we'll remove all of the modules it depends on from consideration,",
"// since they must all have larger subtrees than the one we're considering.",
"int",
"parentTreeIndex",
"=",
"parentTree",
".",
"getIndex",
"(",
")",
";",
"// default to parent tree if we don't find anything better",
"int",
"bestCandidateIndex",
"=",
"parentTreeIndex",
";",
"for",
"(",
"int",
"candidateIndex",
"=",
"candidates",
".",
"previousSetBit",
"(",
"minDependentModuleIndex",
")",
";",
"candidateIndex",
">=",
"0",
";",
"candidateIndex",
"=",
"candidates",
".",
"previousSetBit",
"(",
"candidateIndex",
"-",
"1",
")",
")",
"{",
"BitSet",
"candidatePlusTransitiveDeps",
"=",
"selfPlusTransitiveDeps",
"[",
"candidateIndex",
"]",
";",
"if",
"(",
"candidatePlusTransitiveDeps",
".",
"get",
"(",
"parentTreeIndex",
")",
")",
"{",
"// candidate is a subtree of parentTree",
"candidates",
".",
"andNot",
"(",
"candidatePlusTransitiveDeps",
")",
";",
"if",
"(",
"subtreeSize",
"[",
"candidateIndex",
"]",
"<",
"subtreeSize",
"[",
"bestCandidateIndex",
"]",
")",
"{",
"bestCandidateIndex",
"=",
"candidateIndex",
";",
"}",
"}",
"// eliminate candidates that are not a subtree of parentTree",
"}",
"return",
"modules",
"[",
"bestCandidateIndex",
"]",
";",
"}"
] | Finds the module with the fewest transitive dependents on which all of the given modules depend
and that is a subtree of the given parent module tree.
<p>If no such subtree can be found, the parent module is returned.
<p>If multiple candidates have the same number of dependents, the module farthest down in the
total ordering of modules will be chosen.
@param parentTree module on which the result must depend
@param dependentModules indices of modules to consider
@return A module on which all of the argument modules depend | [
"Finds",
"the",
"module",
"with",
"the",
"fewest",
"transitive",
"dependents",
"on",
"which",
"all",
"of",
"the",
"given",
"modules",
"depend",
"and",
"that",
"is",
"a",
"subtree",
"of",
"the",
"given",
"parent",
"module",
"tree",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/JSModuleGraph.java#L356-L395 |
24,803 | google/closure-compiler | src/com/google/javascript/jscomp/JSModuleGraph.java | JSModuleGraph.getDeepestCommonDependency | JSModule getDeepestCommonDependency(JSModule m1, JSModule m2) {
int m1Depth = m1.getDepth();
int m2Depth = m2.getDepth();
// According our definition of depth, the result must have a strictly
// smaller depth than either m1 or m2.
for (int depth = Math.min(m1Depth, m2Depth) - 1; depth >= 0; depth--) {
List<JSModule> modulesAtDepth = modulesByDepth.get(depth);
// Look at the modules at this depth in reverse order, so that we use the
// original ordering of the modules to break ties (later meaning deeper).
for (int i = modulesAtDepth.size() - 1; i >= 0; i--) {
JSModule m = modulesAtDepth.get(i);
if (dependsOn(m1, m) && dependsOn(m2, m)) {
return m;
}
}
}
return null;
} | java | JSModule getDeepestCommonDependency(JSModule m1, JSModule m2) {
int m1Depth = m1.getDepth();
int m2Depth = m2.getDepth();
// According our definition of depth, the result must have a strictly
// smaller depth than either m1 or m2.
for (int depth = Math.min(m1Depth, m2Depth) - 1; depth >= 0; depth--) {
List<JSModule> modulesAtDepth = modulesByDepth.get(depth);
// Look at the modules at this depth in reverse order, so that we use the
// original ordering of the modules to break ties (later meaning deeper).
for (int i = modulesAtDepth.size() - 1; i >= 0; i--) {
JSModule m = modulesAtDepth.get(i);
if (dependsOn(m1, m) && dependsOn(m2, m)) {
return m;
}
}
}
return null;
} | [
"JSModule",
"getDeepestCommonDependency",
"(",
"JSModule",
"m1",
",",
"JSModule",
"m2",
")",
"{",
"int",
"m1Depth",
"=",
"m1",
".",
"getDepth",
"(",
")",
";",
"int",
"m2Depth",
"=",
"m2",
".",
"getDepth",
"(",
")",
";",
"// According our definition of depth, the result must have a strictly",
"// smaller depth than either m1 or m2.",
"for",
"(",
"int",
"depth",
"=",
"Math",
".",
"min",
"(",
"m1Depth",
",",
"m2Depth",
")",
"-",
"1",
";",
"depth",
">=",
"0",
";",
"depth",
"--",
")",
"{",
"List",
"<",
"JSModule",
">",
"modulesAtDepth",
"=",
"modulesByDepth",
".",
"get",
"(",
"depth",
")",
";",
"// Look at the modules at this depth in reverse order, so that we use the",
"// original ordering of the modules to break ties (later meaning deeper).",
"for",
"(",
"int",
"i",
"=",
"modulesAtDepth",
".",
"size",
"(",
")",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"JSModule",
"m",
"=",
"modulesAtDepth",
".",
"get",
"(",
"i",
")",
";",
"if",
"(",
"dependsOn",
"(",
"m1",
",",
"m",
")",
"&&",
"dependsOn",
"(",
"m2",
",",
"m",
")",
")",
"{",
"return",
"m",
";",
"}",
"}",
"}",
"return",
"null",
";",
"}"
] | Finds the deepest common dependency of two modules, not including the two
modules themselves.
@param m1 A module in this graph
@param m2 A module in this graph
@return The deepest common dep of {@code m1} and {@code m2}, or null if
they have no common dependencies | [
"Finds",
"the",
"deepest",
"common",
"dependency",
"of",
"two",
"modules",
"not",
"including",
"the",
"two",
"modules",
"themselves",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/JSModuleGraph.java#L406-L423 |
24,804 | google/closure-compiler | src/com/google/javascript/jscomp/JSModuleGraph.java | JSModuleGraph.getDeepestCommonDependencyInclusive | public JSModule getDeepestCommonDependencyInclusive(
JSModule m1, JSModule m2) {
if (m2 == m1 || dependsOn(m2, m1)) {
return m1;
} else if (dependsOn(m1, m2)) {
return m2;
}
return getDeepestCommonDependency(m1, m2);
} | java | public JSModule getDeepestCommonDependencyInclusive(
JSModule m1, JSModule m2) {
if (m2 == m1 || dependsOn(m2, m1)) {
return m1;
} else if (dependsOn(m1, m2)) {
return m2;
}
return getDeepestCommonDependency(m1, m2);
} | [
"public",
"JSModule",
"getDeepestCommonDependencyInclusive",
"(",
"JSModule",
"m1",
",",
"JSModule",
"m2",
")",
"{",
"if",
"(",
"m2",
"==",
"m1",
"||",
"dependsOn",
"(",
"m2",
",",
"m1",
")",
")",
"{",
"return",
"m1",
";",
"}",
"else",
"if",
"(",
"dependsOn",
"(",
"m1",
",",
"m2",
")",
")",
"{",
"return",
"m2",
";",
"}",
"return",
"getDeepestCommonDependency",
"(",
"m1",
",",
"m2",
")",
";",
"}"
] | Finds the deepest common dependency of two modules, including the
modules themselves.
@param m1 A module in this graph
@param m2 A module in this graph
@return The deepest common dep of {@code m1} and {@code m2}, or null if
they have no common dependencies | [
"Finds",
"the",
"deepest",
"common",
"dependency",
"of",
"two",
"modules",
"including",
"the",
"modules",
"themselves",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/JSModuleGraph.java#L434-L443 |
24,805 | google/closure-compiler | src/com/google/javascript/jscomp/JSModuleGraph.java | JSModuleGraph.getDeepestCommonDependencyInclusive | public JSModule getDeepestCommonDependencyInclusive(
Collection<JSModule> modules) {
Iterator<JSModule> iter = modules.iterator();
JSModule dep = iter.next();
while (iter.hasNext()) {
dep = getDeepestCommonDependencyInclusive(dep, iter.next());
}
return dep;
} | java | public JSModule getDeepestCommonDependencyInclusive(
Collection<JSModule> modules) {
Iterator<JSModule> iter = modules.iterator();
JSModule dep = iter.next();
while (iter.hasNext()) {
dep = getDeepestCommonDependencyInclusive(dep, iter.next());
}
return dep;
} | [
"public",
"JSModule",
"getDeepestCommonDependencyInclusive",
"(",
"Collection",
"<",
"JSModule",
">",
"modules",
")",
"{",
"Iterator",
"<",
"JSModule",
">",
"iter",
"=",
"modules",
".",
"iterator",
"(",
")",
";",
"JSModule",
"dep",
"=",
"iter",
".",
"next",
"(",
")",
";",
"while",
"(",
"iter",
".",
"hasNext",
"(",
")",
")",
"{",
"dep",
"=",
"getDeepestCommonDependencyInclusive",
"(",
"dep",
",",
"iter",
".",
"next",
"(",
")",
")",
";",
"}",
"return",
"dep",
";",
"}"
] | Returns the deepest common dependency of the given modules. | [
"Returns",
"the",
"deepest",
"common",
"dependency",
"of",
"the",
"given",
"modules",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/JSModuleGraph.java#L446-L454 |
24,806 | google/closure-compiler | src/com/google/javascript/jscomp/JSModuleGraph.java | JSModuleGraph.getTransitiveDeps | private Set<JSModule> getTransitiveDeps(JSModule m) {
Set<JSModule> deps = dependencyMap.computeIfAbsent(m, JSModule::getAllDependencies);
return deps;
} | java | private Set<JSModule> getTransitiveDeps(JSModule m) {
Set<JSModule> deps = dependencyMap.computeIfAbsent(m, JSModule::getAllDependencies);
return deps;
} | [
"private",
"Set",
"<",
"JSModule",
">",
"getTransitiveDeps",
"(",
"JSModule",
"m",
")",
"{",
"Set",
"<",
"JSModule",
">",
"deps",
"=",
"dependencyMap",
".",
"computeIfAbsent",
"(",
"m",
",",
"JSModule",
"::",
"getAllDependencies",
")",
";",
"return",
"deps",
";",
"}"
] | Returns the transitive dependencies of the module. | [
"Returns",
"the",
"transitive",
"dependencies",
"of",
"the",
"module",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/JSModuleGraph.java#L470-L473 |
24,807 | google/closure-compiler | src/com/google/javascript/jscomp/JSModuleGraph.java | JSModuleGraph.getDepthFirstDependenciesOf | private List<CompilerInput> getDepthFirstDependenciesOf(
CompilerInput rootInput,
Set<CompilerInput> unreachedInputs,
Map<String, CompilerInput> inputsByProvide) {
List<CompilerInput> orderedInputs = new ArrayList<>();
if (!unreachedInputs.remove(rootInput)) {
return orderedInputs;
}
for (String importedNamespace : rootInput.getRequiredSymbols()) {
CompilerInput dependency = null;
if (inputsByProvide.containsKey(importedNamespace)
&& unreachedInputs.contains(inputsByProvide.get(importedNamespace))) {
dependency = inputsByProvide.get(importedNamespace);
}
if (dependency != null) {
orderedInputs.addAll(
getDepthFirstDependenciesOf(dependency, unreachedInputs, inputsByProvide));
}
}
orderedInputs.add(rootInput);
return orderedInputs;
} | java | private List<CompilerInput> getDepthFirstDependenciesOf(
CompilerInput rootInput,
Set<CompilerInput> unreachedInputs,
Map<String, CompilerInput> inputsByProvide) {
List<CompilerInput> orderedInputs = new ArrayList<>();
if (!unreachedInputs.remove(rootInput)) {
return orderedInputs;
}
for (String importedNamespace : rootInput.getRequiredSymbols()) {
CompilerInput dependency = null;
if (inputsByProvide.containsKey(importedNamespace)
&& unreachedInputs.contains(inputsByProvide.get(importedNamespace))) {
dependency = inputsByProvide.get(importedNamespace);
}
if (dependency != null) {
orderedInputs.addAll(
getDepthFirstDependenciesOf(dependency, unreachedInputs, inputsByProvide));
}
}
orderedInputs.add(rootInput);
return orderedInputs;
} | [
"private",
"List",
"<",
"CompilerInput",
">",
"getDepthFirstDependenciesOf",
"(",
"CompilerInput",
"rootInput",
",",
"Set",
"<",
"CompilerInput",
">",
"unreachedInputs",
",",
"Map",
"<",
"String",
",",
"CompilerInput",
">",
"inputsByProvide",
")",
"{",
"List",
"<",
"CompilerInput",
">",
"orderedInputs",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"if",
"(",
"!",
"unreachedInputs",
".",
"remove",
"(",
"rootInput",
")",
")",
"{",
"return",
"orderedInputs",
";",
"}",
"for",
"(",
"String",
"importedNamespace",
":",
"rootInput",
".",
"getRequiredSymbols",
"(",
")",
")",
"{",
"CompilerInput",
"dependency",
"=",
"null",
";",
"if",
"(",
"inputsByProvide",
".",
"containsKey",
"(",
"importedNamespace",
")",
"&&",
"unreachedInputs",
".",
"contains",
"(",
"inputsByProvide",
".",
"get",
"(",
"importedNamespace",
")",
")",
")",
"{",
"dependency",
"=",
"inputsByProvide",
".",
"get",
"(",
"importedNamespace",
")",
";",
"}",
"if",
"(",
"dependency",
"!=",
"null",
")",
"{",
"orderedInputs",
".",
"addAll",
"(",
"getDepthFirstDependenciesOf",
"(",
"dependency",
",",
"unreachedInputs",
",",
"inputsByProvide",
")",
")",
";",
"}",
"}",
"orderedInputs",
".",
"add",
"(",
"rootInput",
")",
";",
"return",
"orderedInputs",
";",
"}"
] | Given an input and set of unprocessed inputs, return the input and it's strong dependencies by
performing a recursive, depth-first traversal. | [
"Given",
"an",
"input",
"and",
"set",
"of",
"unprocessed",
"inputs",
"return",
"the",
"input",
"and",
"it",
"s",
"strong",
"dependencies",
"by",
"performing",
"a",
"recursive",
"depth",
"-",
"first",
"traversal",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/JSModuleGraph.java#L644-L668 |
24,808 | google/closure-compiler | src/com/google/javascript/jscomp/MustBeReachingVariableDef.java | MustBeReachingVariableDef.computeDependence | private void computeDependence(final Definition def, Node rValue) {
NodeTraversal.traverse(
compiler,
rValue,
new AbstractCfgNodeTraversalCallback() {
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
if (n.isName()) {
Var dep = allVarsInFn.get(n.getString());
if (dep == null) {
def.unknownDependencies = true;
} else {
def.depends.add(dep);
}
}
}
});
} | java | private void computeDependence(final Definition def, Node rValue) {
NodeTraversal.traverse(
compiler,
rValue,
new AbstractCfgNodeTraversalCallback() {
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
if (n.isName()) {
Var dep = allVarsInFn.get(n.getString());
if (dep == null) {
def.unknownDependencies = true;
} else {
def.depends.add(dep);
}
}
}
});
} | [
"private",
"void",
"computeDependence",
"(",
"final",
"Definition",
"def",
",",
"Node",
"rValue",
")",
"{",
"NodeTraversal",
".",
"traverse",
"(",
"compiler",
",",
"rValue",
",",
"new",
"AbstractCfgNodeTraversalCallback",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"visit",
"(",
"NodeTraversal",
"t",
",",
"Node",
"n",
",",
"Node",
"parent",
")",
"{",
"if",
"(",
"n",
".",
"isName",
"(",
")",
")",
"{",
"Var",
"dep",
"=",
"allVarsInFn",
".",
"get",
"(",
"n",
".",
"getString",
"(",
")",
")",
";",
"if",
"(",
"dep",
"==",
"null",
")",
"{",
"def",
".",
"unknownDependencies",
"=",
"true",
";",
"}",
"else",
"{",
"def",
".",
"depends",
".",
"add",
"(",
"dep",
")",
";",
"}",
"}",
"}",
"}",
")",
";",
"}"
] | Computes all the local variables that rValue reads from and store that
in the def's depends set. | [
"Computes",
"all",
"the",
"local",
"variables",
"that",
"rValue",
"reads",
"from",
"and",
"store",
"that",
"in",
"the",
"def",
"s",
"depends",
"set",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/MustBeReachingVariableDef.java#L442-L459 |
24,809 | google/closure-compiler | src/com/google/javascript/jscomp/MustBeReachingVariableDef.java | MustBeReachingVariableDef.getDef | Definition getDef(String name, Node useNode) {
checkArgument(getCfg().hasNode(useNode));
GraphNode<Node, Branch> n = getCfg().getNode(useNode);
FlowState<MustDef> state = n.getAnnotation();
return state.getIn().reachingDef.get(allVarsInFn.get(name));
} | java | Definition getDef(String name, Node useNode) {
checkArgument(getCfg().hasNode(useNode));
GraphNode<Node, Branch> n = getCfg().getNode(useNode);
FlowState<MustDef> state = n.getAnnotation();
return state.getIn().reachingDef.get(allVarsInFn.get(name));
} | [
"Definition",
"getDef",
"(",
"String",
"name",
",",
"Node",
"useNode",
")",
"{",
"checkArgument",
"(",
"getCfg",
"(",
")",
".",
"hasNode",
"(",
"useNode",
")",
")",
";",
"GraphNode",
"<",
"Node",
",",
"Branch",
">",
"n",
"=",
"getCfg",
"(",
")",
".",
"getNode",
"(",
"useNode",
")",
";",
"FlowState",
"<",
"MustDef",
">",
"state",
"=",
"n",
".",
"getAnnotation",
"(",
")",
";",
"return",
"state",
".",
"getIn",
"(",
")",
".",
"reachingDef",
".",
"get",
"(",
"allVarsInFn",
".",
"get",
"(",
"name",
")",
")",
";",
"}"
] | Gets the must reaching definition of a given node.
@param name name of the variable. It can only be names of local variable
that are not function parameters, escaped variables or variables
declared in catch.
@param useNode the location of the use where the definition reaches. | [
"Gets",
"the",
"must",
"reaching",
"definition",
"of",
"a",
"given",
"node",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/MustBeReachingVariableDef.java#L469-L474 |
24,810 | google/closure-compiler | src/com/google/javascript/jscomp/deps/ClosureBundler.java | ClosureBundler.appendTo | public void appendTo(
Appendable out,
DependencyInfo info,
File content, Charset contentCharset) throws IOException {
appendTo(out, info, Files.asCharSource(content, contentCharset));
} | java | public void appendTo(
Appendable out,
DependencyInfo info,
File content, Charset contentCharset) throws IOException {
appendTo(out, info, Files.asCharSource(content, contentCharset));
} | [
"public",
"void",
"appendTo",
"(",
"Appendable",
"out",
",",
"DependencyInfo",
"info",
",",
"File",
"content",
",",
"Charset",
"contentCharset",
")",
"throws",
"IOException",
"{",
"appendTo",
"(",
"out",
",",
"info",
",",
"Files",
".",
"asCharSource",
"(",
"content",
",",
"contentCharset",
")",
")",
";",
"}"
] | Append the contents of the file to the supplied appendable. | [
"Append",
"the",
"contents",
"of",
"the",
"file",
"to",
"the",
"supplied",
"appendable",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/deps/ClosureBundler.java#L129-L134 |
24,811 | google/closure-compiler | src/com/google/javascript/jscomp/deps/ClosureBundler.java | ClosureBundler.appendTo | public void appendTo(
Appendable out,
DependencyInfo info,
CharSource content) throws IOException {
if (info.isModule()) {
mode.appendGoogModule(transpile(content.read()), out, sourceUrl);
} else if ("es6".equals(info.getLoadFlags().get("module")) && transpiler == Transpiler.NULL) {
// TODO(johnplaisted): Make the default transpiler the ES_MODULE_TO_CJS_TRANSPILER. Currently
// some code is passing in unicode identifiers in non-ES6 modules the compiler fails to parse.
// Once this compiler bug is fixed we can always transpile.
mode.appendTraditional(transpileEs6Module(content.read()), out, sourceUrl);
} else {
mode.appendTraditional(transpile(content.read()), out, sourceUrl);
}
} | java | public void appendTo(
Appendable out,
DependencyInfo info,
CharSource content) throws IOException {
if (info.isModule()) {
mode.appendGoogModule(transpile(content.read()), out, sourceUrl);
} else if ("es6".equals(info.getLoadFlags().get("module")) && transpiler == Transpiler.NULL) {
// TODO(johnplaisted): Make the default transpiler the ES_MODULE_TO_CJS_TRANSPILER. Currently
// some code is passing in unicode identifiers in non-ES6 modules the compiler fails to parse.
// Once this compiler bug is fixed we can always transpile.
mode.appendTraditional(transpileEs6Module(content.read()), out, sourceUrl);
} else {
mode.appendTraditional(transpile(content.read()), out, sourceUrl);
}
} | [
"public",
"void",
"appendTo",
"(",
"Appendable",
"out",
",",
"DependencyInfo",
"info",
",",
"CharSource",
"content",
")",
"throws",
"IOException",
"{",
"if",
"(",
"info",
".",
"isModule",
"(",
")",
")",
"{",
"mode",
".",
"appendGoogModule",
"(",
"transpile",
"(",
"content",
".",
"read",
"(",
")",
")",
",",
"out",
",",
"sourceUrl",
")",
";",
"}",
"else",
"if",
"(",
"\"es6\"",
".",
"equals",
"(",
"info",
".",
"getLoadFlags",
"(",
")",
".",
"get",
"(",
"\"module\"",
")",
")",
"&&",
"transpiler",
"==",
"Transpiler",
".",
"NULL",
")",
"{",
"// TODO(johnplaisted): Make the default transpiler the ES_MODULE_TO_CJS_TRANSPILER. Currently",
"// some code is passing in unicode identifiers in non-ES6 modules the compiler fails to parse.",
"// Once this compiler bug is fixed we can always transpile.",
"mode",
".",
"appendTraditional",
"(",
"transpileEs6Module",
"(",
"content",
".",
"read",
"(",
")",
")",
",",
"out",
",",
"sourceUrl",
")",
";",
"}",
"else",
"{",
"mode",
".",
"appendTraditional",
"(",
"transpile",
"(",
"content",
".",
"read",
"(",
")",
")",
",",
"out",
",",
"sourceUrl",
")",
";",
"}",
"}"
] | Append the contents of the CharSource to the supplied appendable. | [
"Append",
"the",
"contents",
"of",
"the",
"CharSource",
"to",
"the",
"supplied",
"appendable",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/deps/ClosureBundler.java#L137-L151 |
24,812 | google/closure-compiler | src/com/google/javascript/jscomp/PolymerBehaviorExtractor.java | PolymerBehaviorExtractor.resolveBehaviorName | @Nullable
private ResolveBehaviorNameResult resolveBehaviorName(Node nameNode) {
String name = getQualifiedNameThroughCast(nameNode);
if (name == null) {
return null;
}
Name globalName = globalNames.getSlot(name);
if (globalName == null) {
return null;
}
boolean isGlobalDeclaration = true;
// Use any set as a backup declaration, even if it's local.
Ref declarationRef = globalName.getDeclaration();
if (declarationRef == null) {
for (Ref ref : globalName.getRefs()) {
if (ref.isSet()) {
isGlobalDeclaration = false;
declarationRef = ref;
break;
}
}
}
if (declarationRef == null) {
return null;
}
Node declarationNode = declarationRef.getNode();
if (declarationNode == null) {
return null;
}
Node rValue = NodeUtil.getRValueOfLValue(declarationNode);
if (rValue == null) {
return null;
}
if (rValue.isQualifiedName()) {
// Another identifier; recurse.
return resolveBehaviorName(rValue);
}
JSDocInfo behaviorInfo = NodeUtil.getBestJSDocInfo(declarationNode);
if (behaviorInfo == null || !behaviorInfo.isPolymerBehavior()) {
compiler.report(
JSError.make(declarationNode, PolymerPassErrors.POLYMER_UNANNOTATED_BEHAVIOR));
}
return new ResolveBehaviorNameResult(rValue, isGlobalDeclaration);
} | java | @Nullable
private ResolveBehaviorNameResult resolveBehaviorName(Node nameNode) {
String name = getQualifiedNameThroughCast(nameNode);
if (name == null) {
return null;
}
Name globalName = globalNames.getSlot(name);
if (globalName == null) {
return null;
}
boolean isGlobalDeclaration = true;
// Use any set as a backup declaration, even if it's local.
Ref declarationRef = globalName.getDeclaration();
if (declarationRef == null) {
for (Ref ref : globalName.getRefs()) {
if (ref.isSet()) {
isGlobalDeclaration = false;
declarationRef = ref;
break;
}
}
}
if (declarationRef == null) {
return null;
}
Node declarationNode = declarationRef.getNode();
if (declarationNode == null) {
return null;
}
Node rValue = NodeUtil.getRValueOfLValue(declarationNode);
if (rValue == null) {
return null;
}
if (rValue.isQualifiedName()) {
// Another identifier; recurse.
return resolveBehaviorName(rValue);
}
JSDocInfo behaviorInfo = NodeUtil.getBestJSDocInfo(declarationNode);
if (behaviorInfo == null || !behaviorInfo.isPolymerBehavior()) {
compiler.report(
JSError.make(declarationNode, PolymerPassErrors.POLYMER_UNANNOTATED_BEHAVIOR));
}
return new ResolveBehaviorNameResult(rValue, isGlobalDeclaration);
} | [
"@",
"Nullable",
"private",
"ResolveBehaviorNameResult",
"resolveBehaviorName",
"(",
"Node",
"nameNode",
")",
"{",
"String",
"name",
"=",
"getQualifiedNameThroughCast",
"(",
"nameNode",
")",
";",
"if",
"(",
"name",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"Name",
"globalName",
"=",
"globalNames",
".",
"getSlot",
"(",
"name",
")",
";",
"if",
"(",
"globalName",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"boolean",
"isGlobalDeclaration",
"=",
"true",
";",
"// Use any set as a backup declaration, even if it's local.",
"Ref",
"declarationRef",
"=",
"globalName",
".",
"getDeclaration",
"(",
")",
";",
"if",
"(",
"declarationRef",
"==",
"null",
")",
"{",
"for",
"(",
"Ref",
"ref",
":",
"globalName",
".",
"getRefs",
"(",
")",
")",
"{",
"if",
"(",
"ref",
".",
"isSet",
"(",
")",
")",
"{",
"isGlobalDeclaration",
"=",
"false",
";",
"declarationRef",
"=",
"ref",
";",
"break",
";",
"}",
"}",
"}",
"if",
"(",
"declarationRef",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"Node",
"declarationNode",
"=",
"declarationRef",
".",
"getNode",
"(",
")",
";",
"if",
"(",
"declarationNode",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"Node",
"rValue",
"=",
"NodeUtil",
".",
"getRValueOfLValue",
"(",
"declarationNode",
")",
";",
"if",
"(",
"rValue",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"rValue",
".",
"isQualifiedName",
"(",
")",
")",
"{",
"// Another identifier; recurse.",
"return",
"resolveBehaviorName",
"(",
"rValue",
")",
";",
"}",
"JSDocInfo",
"behaviorInfo",
"=",
"NodeUtil",
".",
"getBestJSDocInfo",
"(",
"declarationNode",
")",
";",
"if",
"(",
"behaviorInfo",
"==",
"null",
"||",
"!",
"behaviorInfo",
".",
"isPolymerBehavior",
"(",
")",
")",
"{",
"compiler",
".",
"report",
"(",
"JSError",
".",
"make",
"(",
"declarationNode",
",",
"PolymerPassErrors",
".",
"POLYMER_UNANNOTATED_BEHAVIOR",
")",
")",
";",
"}",
"return",
"new",
"ResolveBehaviorNameResult",
"(",
"rValue",
",",
"isGlobalDeclaration",
")",
";",
"}"
] | Resolve an identifier, which is presumed to refer to a Polymer Behavior declaration, using the
global namespace. Recurses to resolve assignment chains of any length.
@param nameNode The NAME, GETPROP, or CAST node containing the identifier.
@return The behavior declaration node, or null if it couldn't be resolved. | [
"Resolve",
"an",
"identifier",
"which",
"is",
"presumed",
"to",
"refer",
"to",
"a",
"Polymer",
"Behavior",
"declaration",
"using",
"the",
"global",
"namespace",
".",
"Recurses",
"to",
"resolve",
"assignment",
"chains",
"of",
"any",
"length",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/PolymerBehaviorExtractor.java#L143-L192 |
24,813 | google/closure-compiler | src/com/google/javascript/jscomp/CheckConformance.java | CheckConformance.initRules | private static ImmutableList<Rule> initRules(
AbstractCompiler compiler, ImmutableList<ConformanceConfig> configs) {
ImmutableList.Builder<Rule> builder = ImmutableList.builder();
List<Requirement> requirements = mergeRequirements(compiler, configs);
for (Requirement requirement : requirements) {
Rule rule = initRule(compiler, requirement);
if (rule != null) {
builder.add(rule);
}
}
return builder.build();
} | java | private static ImmutableList<Rule> initRules(
AbstractCompiler compiler, ImmutableList<ConformanceConfig> configs) {
ImmutableList.Builder<Rule> builder = ImmutableList.builder();
List<Requirement> requirements = mergeRequirements(compiler, configs);
for (Requirement requirement : requirements) {
Rule rule = initRule(compiler, requirement);
if (rule != null) {
builder.add(rule);
}
}
return builder.build();
} | [
"private",
"static",
"ImmutableList",
"<",
"Rule",
">",
"initRules",
"(",
"AbstractCompiler",
"compiler",
",",
"ImmutableList",
"<",
"ConformanceConfig",
">",
"configs",
")",
"{",
"ImmutableList",
".",
"Builder",
"<",
"Rule",
">",
"builder",
"=",
"ImmutableList",
".",
"builder",
"(",
")",
";",
"List",
"<",
"Requirement",
">",
"requirements",
"=",
"mergeRequirements",
"(",
"compiler",
",",
"configs",
")",
";",
"for",
"(",
"Requirement",
"requirement",
":",
"requirements",
")",
"{",
"Rule",
"rule",
"=",
"initRule",
"(",
"compiler",
",",
"requirement",
")",
";",
"if",
"(",
"rule",
"!=",
"null",
")",
"{",
"builder",
".",
"add",
"(",
"rule",
")",
";",
"}",
"}",
"return",
"builder",
".",
"build",
"(",
")",
";",
"}"
] | Build the data structures need by this pass from the provided
configurations. | [
"Build",
"the",
"data",
"structures",
"need",
"by",
"this",
"pass",
"from",
"the",
"provided",
"configurations",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/CheckConformance.java#L106-L117 |
24,814 | google/closure-compiler | src/com/google/javascript/jscomp/CheckConformance.java | CheckConformance.mergeRequirements | static List<Requirement> mergeRequirements(AbstractCompiler compiler,
List<ConformanceConfig> configs) {
List<Requirement.Builder> builders = new ArrayList<>();
Map<String, Requirement.Builder> extendable = new HashMap<>();
for (ConformanceConfig config : configs) {
for (Requirement requirement : config.getRequirementList()) {
Requirement.Builder builder = requirement.toBuilder();
if (requirement.hasRuleId()) {
if (requirement.getRuleId().isEmpty()) {
reportInvalidRequirement(compiler, requirement, "empty rule_id");
continue;
}
if (extendable.containsKey(requirement.getRuleId())) {
reportInvalidRequirement(compiler, requirement,
"two requirements with the same rule_id: " + requirement.getRuleId());
continue;
}
extendable.put(requirement.getRuleId(), builder);
}
if (!requirement.hasExtends()) {
builders.add(builder);
}
}
}
for (ConformanceConfig config : configs) {
for (Requirement requirement : config.getRequirementList()) {
if (requirement.hasExtends()) {
Requirement.Builder existing = extendable.get(requirement.getExtends());
if (existing == null) {
reportInvalidRequirement(compiler, requirement,
"no requirement with rule_id: " + requirement.getExtends());
continue;
}
for (Descriptors.FieldDescriptor field : requirement.getAllFields().keySet()) {
if (!EXTENDABLE_FIELDS.contains(field.getName())) {
reportInvalidRequirement(compiler, requirement,
"extending rules allow only " + EXTENDABLE_FIELDS);
}
}
existing.addAllWhitelist(requirement.getWhitelistList());
existing.addAllWhitelistRegexp(requirement.getWhitelistRegexpList());
existing.addAllOnlyApplyTo(requirement.getOnlyApplyToList());
existing.addAllOnlyApplyToRegexp(requirement.getOnlyApplyToRegexpList());
existing.addAllWhitelistEntry(requirement.getWhitelistEntryList());
}
}
}
List<Requirement> requirements = new ArrayList<>(builders.size());
for (Requirement.Builder builder : builders) {
removeDuplicates(builder);
requirements.add(builder.build());
}
return requirements;
} | java | static List<Requirement> mergeRequirements(AbstractCompiler compiler,
List<ConformanceConfig> configs) {
List<Requirement.Builder> builders = new ArrayList<>();
Map<String, Requirement.Builder> extendable = new HashMap<>();
for (ConformanceConfig config : configs) {
for (Requirement requirement : config.getRequirementList()) {
Requirement.Builder builder = requirement.toBuilder();
if (requirement.hasRuleId()) {
if (requirement.getRuleId().isEmpty()) {
reportInvalidRequirement(compiler, requirement, "empty rule_id");
continue;
}
if (extendable.containsKey(requirement.getRuleId())) {
reportInvalidRequirement(compiler, requirement,
"two requirements with the same rule_id: " + requirement.getRuleId());
continue;
}
extendable.put(requirement.getRuleId(), builder);
}
if (!requirement.hasExtends()) {
builders.add(builder);
}
}
}
for (ConformanceConfig config : configs) {
for (Requirement requirement : config.getRequirementList()) {
if (requirement.hasExtends()) {
Requirement.Builder existing = extendable.get(requirement.getExtends());
if (existing == null) {
reportInvalidRequirement(compiler, requirement,
"no requirement with rule_id: " + requirement.getExtends());
continue;
}
for (Descriptors.FieldDescriptor field : requirement.getAllFields().keySet()) {
if (!EXTENDABLE_FIELDS.contains(field.getName())) {
reportInvalidRequirement(compiler, requirement,
"extending rules allow only " + EXTENDABLE_FIELDS);
}
}
existing.addAllWhitelist(requirement.getWhitelistList());
existing.addAllWhitelistRegexp(requirement.getWhitelistRegexpList());
existing.addAllOnlyApplyTo(requirement.getOnlyApplyToList());
existing.addAllOnlyApplyToRegexp(requirement.getOnlyApplyToRegexpList());
existing.addAllWhitelistEntry(requirement.getWhitelistEntryList());
}
}
}
List<Requirement> requirements = new ArrayList<>(builders.size());
for (Requirement.Builder builder : builders) {
removeDuplicates(builder);
requirements.add(builder.build());
}
return requirements;
} | [
"static",
"List",
"<",
"Requirement",
">",
"mergeRequirements",
"(",
"AbstractCompiler",
"compiler",
",",
"List",
"<",
"ConformanceConfig",
">",
"configs",
")",
"{",
"List",
"<",
"Requirement",
".",
"Builder",
">",
"builders",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"Map",
"<",
"String",
",",
"Requirement",
".",
"Builder",
">",
"extendable",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"for",
"(",
"ConformanceConfig",
"config",
":",
"configs",
")",
"{",
"for",
"(",
"Requirement",
"requirement",
":",
"config",
".",
"getRequirementList",
"(",
")",
")",
"{",
"Requirement",
".",
"Builder",
"builder",
"=",
"requirement",
".",
"toBuilder",
"(",
")",
";",
"if",
"(",
"requirement",
".",
"hasRuleId",
"(",
")",
")",
"{",
"if",
"(",
"requirement",
".",
"getRuleId",
"(",
")",
".",
"isEmpty",
"(",
")",
")",
"{",
"reportInvalidRequirement",
"(",
"compiler",
",",
"requirement",
",",
"\"empty rule_id\"",
")",
";",
"continue",
";",
"}",
"if",
"(",
"extendable",
".",
"containsKey",
"(",
"requirement",
".",
"getRuleId",
"(",
")",
")",
")",
"{",
"reportInvalidRequirement",
"(",
"compiler",
",",
"requirement",
",",
"\"two requirements with the same rule_id: \"",
"+",
"requirement",
".",
"getRuleId",
"(",
")",
")",
";",
"continue",
";",
"}",
"extendable",
".",
"put",
"(",
"requirement",
".",
"getRuleId",
"(",
")",
",",
"builder",
")",
";",
"}",
"if",
"(",
"!",
"requirement",
".",
"hasExtends",
"(",
")",
")",
"{",
"builders",
".",
"add",
"(",
"builder",
")",
";",
"}",
"}",
"}",
"for",
"(",
"ConformanceConfig",
"config",
":",
"configs",
")",
"{",
"for",
"(",
"Requirement",
"requirement",
":",
"config",
".",
"getRequirementList",
"(",
")",
")",
"{",
"if",
"(",
"requirement",
".",
"hasExtends",
"(",
")",
")",
"{",
"Requirement",
".",
"Builder",
"existing",
"=",
"extendable",
".",
"get",
"(",
"requirement",
".",
"getExtends",
"(",
")",
")",
";",
"if",
"(",
"existing",
"==",
"null",
")",
"{",
"reportInvalidRequirement",
"(",
"compiler",
",",
"requirement",
",",
"\"no requirement with rule_id: \"",
"+",
"requirement",
".",
"getExtends",
"(",
")",
")",
";",
"continue",
";",
"}",
"for",
"(",
"Descriptors",
".",
"FieldDescriptor",
"field",
":",
"requirement",
".",
"getAllFields",
"(",
")",
".",
"keySet",
"(",
")",
")",
"{",
"if",
"(",
"!",
"EXTENDABLE_FIELDS",
".",
"contains",
"(",
"field",
".",
"getName",
"(",
")",
")",
")",
"{",
"reportInvalidRequirement",
"(",
"compiler",
",",
"requirement",
",",
"\"extending rules allow only \"",
"+",
"EXTENDABLE_FIELDS",
")",
";",
"}",
"}",
"existing",
".",
"addAllWhitelist",
"(",
"requirement",
".",
"getWhitelistList",
"(",
")",
")",
";",
"existing",
".",
"addAllWhitelistRegexp",
"(",
"requirement",
".",
"getWhitelistRegexpList",
"(",
")",
")",
";",
"existing",
".",
"addAllOnlyApplyTo",
"(",
"requirement",
".",
"getOnlyApplyToList",
"(",
")",
")",
";",
"existing",
".",
"addAllOnlyApplyToRegexp",
"(",
"requirement",
".",
"getOnlyApplyToRegexpList",
"(",
")",
")",
";",
"existing",
".",
"addAllWhitelistEntry",
"(",
"requirement",
".",
"getWhitelistEntryList",
"(",
")",
")",
";",
"}",
"}",
"}",
"List",
"<",
"Requirement",
">",
"requirements",
"=",
"new",
"ArrayList",
"<>",
"(",
"builders",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"Requirement",
".",
"Builder",
"builder",
":",
"builders",
")",
"{",
"removeDuplicates",
"(",
"builder",
")",
";",
"requirements",
".",
"add",
"(",
"builder",
".",
"build",
"(",
")",
")",
";",
"}",
"return",
"requirements",
";",
"}"
] | Gets requirements from all configs. Merges whitelists of requirements with 'extends' equal to
'rule_id' of other rule. | [
"Gets",
"requirements",
"from",
"all",
"configs",
".",
"Merges",
"whitelists",
"of",
"requirements",
"with",
"extends",
"equal",
"to",
"rule_id",
"of",
"other",
"rule",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/CheckConformance.java#L127-L182 |
24,815 | google/closure-compiler | src/com/google/javascript/jscomp/deps/JsFileParser.java | JsFileParser.parseFile | public DependencyInfo parseFile(String filePath, String closureRelativePath,
String fileContents) {
return parseReader(filePath, closureRelativePath, new StringReader(fileContents));
} | java | public DependencyInfo parseFile(String filePath, String closureRelativePath,
String fileContents) {
return parseReader(filePath, closureRelativePath, new StringReader(fileContents));
} | [
"public",
"DependencyInfo",
"parseFile",
"(",
"String",
"filePath",
",",
"String",
"closureRelativePath",
",",
"String",
"fileContents",
")",
"{",
"return",
"parseReader",
"(",
"filePath",
",",
"closureRelativePath",
",",
"new",
"StringReader",
"(",
"fileContents",
")",
")",
";",
"}"
] | Parses the given file and returns the dependency information that it
contained.
@param filePath Path to the file to parse.
@param closureRelativePath Path of the file relative to closure.
@param fileContents The contents to parse.
@return A DependencyInfo containing all provides/requires found in the
file. | [
"Parses",
"the",
"given",
"file",
"and",
"returns",
"the",
"dependency",
"information",
"that",
"it",
"contained",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/deps/JsFileParser.java#L180-L183 |
24,816 | google/closure-compiler | src/com/google/javascript/jscomp/deps/JsFileParser.java | JsFileParser.parseLine | @Override
protected boolean parseLine(String line) throws ParseException {
boolean lineHasProvidesOrRequires = false;
if (line.startsWith(BUNDLED_GOOG_MODULE_START)) {
seenLoadModule = true;
}
// Quick check that will catch most cases. This is a performance win for teams with a lot of JS.
if (line.contains("provide")
|| line.contains("require")
|| line.contains("module")
|| line.contains("addDependency")
|| line.contains("declareModuleId")) {
// Iterate over the provides/requires.
googMatcher.reset(line);
while (googMatcher.find()) {
lineHasProvidesOrRequires = true;
if (includeGoogBase && !fileHasProvidesOrRequires) {
fileHasProvidesOrRequires = true;
requires.add(Require.BASE);
}
// See if it's a require or provide.
String methodName = googMatcher.group("func");
char firstChar = methodName.charAt(0);
boolean isDeclareModuleNamespace = firstChar == 'd';
boolean isModule = !isDeclareModuleNamespace && firstChar == 'm';
boolean isProvide = firstChar == 'p';
boolean providesNamespace = isProvide || isModule || isDeclareModuleNamespace;
boolean isRequire = firstChar == 'r';
if (isModule && !seenLoadModule) {
providesNamespace = setModuleType(ModuleType.GOOG_MODULE);
}
if (isProvide) {
providesNamespace = setModuleType(ModuleType.GOOG_PROVIDE);
}
if (providesNamespace || isRequire) {
// Parse the param.
String arg = parseJsString(googMatcher.group("args"));
// Add the dependency.
if (isRequire) {
if ("requireType".equals(methodName)) {
typeRequires.add(arg);
} else if (!"goog".equals(arg)) {
// goog is always implicit.
Require require = Require.googRequireSymbol(arg);
requires.add(require);
}
} else {
provides.add(arg);
}
}
}
}
if (line.startsWith("import") || line.startsWith("export")) {
es6Matcher.reset(line);
while (es6Matcher.find()) {
setModuleType(ModuleType.ES6_MODULE);
lineHasProvidesOrRequires = true;
String arg = es6Matcher.group(1);
if (arg != null) {
if (arg.startsWith("goog:")) {
// cut off the "goog:" prefix
requires.add(Require.googRequireSymbol(arg.substring(5)));
} else {
ModuleLoader.ModulePath path =
file.resolveJsModule(arg, filePath, lineNum, es6Matcher.start());
if (path == null) {
path = file.resolveModuleAsPath(arg);
}
requires.add(Require.es6Import(path.toModuleName(), arg));
}
}
}
// This check is only relevant for modules that don't import anything.
if (moduleType != ModuleType.ES6_MODULE && ES6_EXPORT_PATTERN.matcher(line).lookingAt()) {
setModuleType(ModuleType.ES6_MODULE);
}
}
return !shortcutMode || lineHasProvidesOrRequires
|| CharMatcher.whitespace().matchesAllOf(line)
|| !line.contains(";")
|| line.contains("goog.setTestOnly")
|| line.contains("goog.module.declareLegacyNamespace");
} | java | @Override
protected boolean parseLine(String line) throws ParseException {
boolean lineHasProvidesOrRequires = false;
if (line.startsWith(BUNDLED_GOOG_MODULE_START)) {
seenLoadModule = true;
}
// Quick check that will catch most cases. This is a performance win for teams with a lot of JS.
if (line.contains("provide")
|| line.contains("require")
|| line.contains("module")
|| line.contains("addDependency")
|| line.contains("declareModuleId")) {
// Iterate over the provides/requires.
googMatcher.reset(line);
while (googMatcher.find()) {
lineHasProvidesOrRequires = true;
if (includeGoogBase && !fileHasProvidesOrRequires) {
fileHasProvidesOrRequires = true;
requires.add(Require.BASE);
}
// See if it's a require or provide.
String methodName = googMatcher.group("func");
char firstChar = methodName.charAt(0);
boolean isDeclareModuleNamespace = firstChar == 'd';
boolean isModule = !isDeclareModuleNamespace && firstChar == 'm';
boolean isProvide = firstChar == 'p';
boolean providesNamespace = isProvide || isModule || isDeclareModuleNamespace;
boolean isRequire = firstChar == 'r';
if (isModule && !seenLoadModule) {
providesNamespace = setModuleType(ModuleType.GOOG_MODULE);
}
if (isProvide) {
providesNamespace = setModuleType(ModuleType.GOOG_PROVIDE);
}
if (providesNamespace || isRequire) {
// Parse the param.
String arg = parseJsString(googMatcher.group("args"));
// Add the dependency.
if (isRequire) {
if ("requireType".equals(methodName)) {
typeRequires.add(arg);
} else if (!"goog".equals(arg)) {
// goog is always implicit.
Require require = Require.googRequireSymbol(arg);
requires.add(require);
}
} else {
provides.add(arg);
}
}
}
}
if (line.startsWith("import") || line.startsWith("export")) {
es6Matcher.reset(line);
while (es6Matcher.find()) {
setModuleType(ModuleType.ES6_MODULE);
lineHasProvidesOrRequires = true;
String arg = es6Matcher.group(1);
if (arg != null) {
if (arg.startsWith("goog:")) {
// cut off the "goog:" prefix
requires.add(Require.googRequireSymbol(arg.substring(5)));
} else {
ModuleLoader.ModulePath path =
file.resolveJsModule(arg, filePath, lineNum, es6Matcher.start());
if (path == null) {
path = file.resolveModuleAsPath(arg);
}
requires.add(Require.es6Import(path.toModuleName(), arg));
}
}
}
// This check is only relevant for modules that don't import anything.
if (moduleType != ModuleType.ES6_MODULE && ES6_EXPORT_PATTERN.matcher(line).lookingAt()) {
setModuleType(ModuleType.ES6_MODULE);
}
}
return !shortcutMode || lineHasProvidesOrRequires
|| CharMatcher.whitespace().matchesAllOf(line)
|| !line.contains(";")
|| line.contains("goog.setTestOnly")
|| line.contains("goog.module.declareLegacyNamespace");
} | [
"@",
"Override",
"protected",
"boolean",
"parseLine",
"(",
"String",
"line",
")",
"throws",
"ParseException",
"{",
"boolean",
"lineHasProvidesOrRequires",
"=",
"false",
";",
"if",
"(",
"line",
".",
"startsWith",
"(",
"BUNDLED_GOOG_MODULE_START",
")",
")",
"{",
"seenLoadModule",
"=",
"true",
";",
"}",
"// Quick check that will catch most cases. This is a performance win for teams with a lot of JS.",
"if",
"(",
"line",
".",
"contains",
"(",
"\"provide\"",
")",
"||",
"line",
".",
"contains",
"(",
"\"require\"",
")",
"||",
"line",
".",
"contains",
"(",
"\"module\"",
")",
"||",
"line",
".",
"contains",
"(",
"\"addDependency\"",
")",
"||",
"line",
".",
"contains",
"(",
"\"declareModuleId\"",
")",
")",
"{",
"// Iterate over the provides/requires.",
"googMatcher",
".",
"reset",
"(",
"line",
")",
";",
"while",
"(",
"googMatcher",
".",
"find",
"(",
")",
")",
"{",
"lineHasProvidesOrRequires",
"=",
"true",
";",
"if",
"(",
"includeGoogBase",
"&&",
"!",
"fileHasProvidesOrRequires",
")",
"{",
"fileHasProvidesOrRequires",
"=",
"true",
";",
"requires",
".",
"add",
"(",
"Require",
".",
"BASE",
")",
";",
"}",
"// See if it's a require or provide.",
"String",
"methodName",
"=",
"googMatcher",
".",
"group",
"(",
"\"func\"",
")",
";",
"char",
"firstChar",
"=",
"methodName",
".",
"charAt",
"(",
"0",
")",
";",
"boolean",
"isDeclareModuleNamespace",
"=",
"firstChar",
"==",
"'",
"'",
";",
"boolean",
"isModule",
"=",
"!",
"isDeclareModuleNamespace",
"&&",
"firstChar",
"==",
"'",
"'",
";",
"boolean",
"isProvide",
"=",
"firstChar",
"==",
"'",
"'",
";",
"boolean",
"providesNamespace",
"=",
"isProvide",
"||",
"isModule",
"||",
"isDeclareModuleNamespace",
";",
"boolean",
"isRequire",
"=",
"firstChar",
"==",
"'",
"'",
";",
"if",
"(",
"isModule",
"&&",
"!",
"seenLoadModule",
")",
"{",
"providesNamespace",
"=",
"setModuleType",
"(",
"ModuleType",
".",
"GOOG_MODULE",
")",
";",
"}",
"if",
"(",
"isProvide",
")",
"{",
"providesNamespace",
"=",
"setModuleType",
"(",
"ModuleType",
".",
"GOOG_PROVIDE",
")",
";",
"}",
"if",
"(",
"providesNamespace",
"||",
"isRequire",
")",
"{",
"// Parse the param.",
"String",
"arg",
"=",
"parseJsString",
"(",
"googMatcher",
".",
"group",
"(",
"\"args\"",
")",
")",
";",
"// Add the dependency.",
"if",
"(",
"isRequire",
")",
"{",
"if",
"(",
"\"requireType\"",
".",
"equals",
"(",
"methodName",
")",
")",
"{",
"typeRequires",
".",
"add",
"(",
"arg",
")",
";",
"}",
"else",
"if",
"(",
"!",
"\"goog\"",
".",
"equals",
"(",
"arg",
")",
")",
"{",
"// goog is always implicit.",
"Require",
"require",
"=",
"Require",
".",
"googRequireSymbol",
"(",
"arg",
")",
";",
"requires",
".",
"add",
"(",
"require",
")",
";",
"}",
"}",
"else",
"{",
"provides",
".",
"add",
"(",
"arg",
")",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"line",
".",
"startsWith",
"(",
"\"import\"",
")",
"||",
"line",
".",
"startsWith",
"(",
"\"export\"",
")",
")",
"{",
"es6Matcher",
".",
"reset",
"(",
"line",
")",
";",
"while",
"(",
"es6Matcher",
".",
"find",
"(",
")",
")",
"{",
"setModuleType",
"(",
"ModuleType",
".",
"ES6_MODULE",
")",
";",
"lineHasProvidesOrRequires",
"=",
"true",
";",
"String",
"arg",
"=",
"es6Matcher",
".",
"group",
"(",
"1",
")",
";",
"if",
"(",
"arg",
"!=",
"null",
")",
"{",
"if",
"(",
"arg",
".",
"startsWith",
"(",
"\"goog:\"",
")",
")",
"{",
"// cut off the \"goog:\" prefix",
"requires",
".",
"add",
"(",
"Require",
".",
"googRequireSymbol",
"(",
"arg",
".",
"substring",
"(",
"5",
")",
")",
")",
";",
"}",
"else",
"{",
"ModuleLoader",
".",
"ModulePath",
"path",
"=",
"file",
".",
"resolveJsModule",
"(",
"arg",
",",
"filePath",
",",
"lineNum",
",",
"es6Matcher",
".",
"start",
"(",
")",
")",
";",
"if",
"(",
"path",
"==",
"null",
")",
"{",
"path",
"=",
"file",
".",
"resolveModuleAsPath",
"(",
"arg",
")",
";",
"}",
"requires",
".",
"add",
"(",
"Require",
".",
"es6Import",
"(",
"path",
".",
"toModuleName",
"(",
")",
",",
"arg",
")",
")",
";",
"}",
"}",
"}",
"// This check is only relevant for modules that don't import anything.",
"if",
"(",
"moduleType",
"!=",
"ModuleType",
".",
"ES6_MODULE",
"&&",
"ES6_EXPORT_PATTERN",
".",
"matcher",
"(",
"line",
")",
".",
"lookingAt",
"(",
")",
")",
"{",
"setModuleType",
"(",
"ModuleType",
".",
"ES6_MODULE",
")",
";",
"}",
"}",
"return",
"!",
"shortcutMode",
"||",
"lineHasProvidesOrRequires",
"||",
"CharMatcher",
".",
"whitespace",
"(",
")",
".",
"matchesAllOf",
"(",
"line",
")",
"||",
"!",
"line",
".",
"contains",
"(",
"\";\"",
")",
"||",
"line",
".",
"contains",
"(",
"\"goog.setTestOnly\"",
")",
"||",
"line",
".",
"contains",
"(",
"\"goog.module.declareLegacyNamespace\"",
")",
";",
"}"
] | Parses a line of JavaScript, extracting goog.provide and goog.require information. | [
"Parses",
"a",
"line",
"of",
"JavaScript",
"extracting",
"goog",
".",
"provide",
"and",
"goog",
".",
"require",
"information",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/deps/JsFileParser.java#L283-L376 |
24,817 | google/closure-compiler | src/com/google/javascript/jscomp/RuntimeTypeCheck.java | RuntimeTypeCheck.paramNamesOf | private static ImmutableList<Node> paramNamesOf(Node paramList) {
checkArgument(paramList.isParamList(), paramList);
ImmutableList.Builder<Node> builder = ImmutableList.builder();
paramNamesOf(paramList, builder);
return builder.build();
} | java | private static ImmutableList<Node> paramNamesOf(Node paramList) {
checkArgument(paramList.isParamList(), paramList);
ImmutableList.Builder<Node> builder = ImmutableList.builder();
paramNamesOf(paramList, builder);
return builder.build();
} | [
"private",
"static",
"ImmutableList",
"<",
"Node",
">",
"paramNamesOf",
"(",
"Node",
"paramList",
")",
"{",
"checkArgument",
"(",
"paramList",
".",
"isParamList",
"(",
")",
",",
"paramList",
")",
";",
"ImmutableList",
".",
"Builder",
"<",
"Node",
">",
"builder",
"=",
"ImmutableList",
".",
"builder",
"(",
")",
";",
"paramNamesOf",
"(",
"paramList",
",",
"builder",
")",
";",
"return",
"builder",
".",
"build",
"(",
")",
";",
"}"
] | Returns the NAME parameter nodes of a FUNCTION.
<p>This lookup abstracts over the other legal node types in a PARAM_LIST. It includes only
those nodes that declare bindings within the function body. | [
"Returns",
"the",
"NAME",
"parameter",
"nodes",
"of",
"a",
"FUNCTION",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/RuntimeTypeCheck.java#L429-L435 |
24,818 | google/closure-compiler | src/com/google/javascript/jscomp/RuntimeTypeCheck.java | RuntimeTypeCheck.paramNamesOf | private static void paramNamesOf(Node node, ImmutableList.Builder<Node> names) {
switch (node.getToken()) {
case NAME:
names.add(node);
break;
case REST:
case DEFAULT_VALUE:
paramNamesOf(node.getFirstChild(), names);
break;
case PARAM_LIST:
case ARRAY_PATTERN:
for (Node child = node.getFirstChild(); child != null; child = child.getNext()) {
paramNamesOf(child, names);
}
break;
case OBJECT_PATTERN:
for (Node child = node.getFirstChild(); child != null; child = child.getNext()) {
checkArgument(child.isStringKey() || child.isComputedProp(), child);
paramNamesOf(child.getLastChild(), names);
}
break;
default:
checkArgument(false, node);
break;
}
} | java | private static void paramNamesOf(Node node, ImmutableList.Builder<Node> names) {
switch (node.getToken()) {
case NAME:
names.add(node);
break;
case REST:
case DEFAULT_VALUE:
paramNamesOf(node.getFirstChild(), names);
break;
case PARAM_LIST:
case ARRAY_PATTERN:
for (Node child = node.getFirstChild(); child != null; child = child.getNext()) {
paramNamesOf(child, names);
}
break;
case OBJECT_PATTERN:
for (Node child = node.getFirstChild(); child != null; child = child.getNext()) {
checkArgument(child.isStringKey() || child.isComputedProp(), child);
paramNamesOf(child.getLastChild(), names);
}
break;
default:
checkArgument(false, node);
break;
}
} | [
"private",
"static",
"void",
"paramNamesOf",
"(",
"Node",
"node",
",",
"ImmutableList",
".",
"Builder",
"<",
"Node",
">",
"names",
")",
"{",
"switch",
"(",
"node",
".",
"getToken",
"(",
")",
")",
"{",
"case",
"NAME",
":",
"names",
".",
"add",
"(",
"node",
")",
";",
"break",
";",
"case",
"REST",
":",
"case",
"DEFAULT_VALUE",
":",
"paramNamesOf",
"(",
"node",
".",
"getFirstChild",
"(",
")",
",",
"names",
")",
";",
"break",
";",
"case",
"PARAM_LIST",
":",
"case",
"ARRAY_PATTERN",
":",
"for",
"(",
"Node",
"child",
"=",
"node",
".",
"getFirstChild",
"(",
")",
";",
"child",
"!=",
"null",
";",
"child",
"=",
"child",
".",
"getNext",
"(",
")",
")",
"{",
"paramNamesOf",
"(",
"child",
",",
"names",
")",
";",
"}",
"break",
";",
"case",
"OBJECT_PATTERN",
":",
"for",
"(",
"Node",
"child",
"=",
"node",
".",
"getFirstChild",
"(",
")",
";",
"child",
"!=",
"null",
";",
"child",
"=",
"child",
".",
"getNext",
"(",
")",
")",
"{",
"checkArgument",
"(",
"child",
".",
"isStringKey",
"(",
")",
"||",
"child",
".",
"isComputedProp",
"(",
")",
",",
"child",
")",
";",
"paramNamesOf",
"(",
"child",
".",
"getLastChild",
"(",
")",
",",
"names",
")",
";",
"}",
"break",
";",
"default",
":",
"checkArgument",
"(",
"false",
",",
"node",
")",
";",
"break",
";",
"}",
"}"
] | Recursively collects the NAME parameter nodes of a FUNCTION.
<p>This lookup abstracts over the other legal node types in a PARAM_LIST. It includes only
those nodes that declare bindings within the function body. | [
"Recursively",
"collects",
"the",
"NAME",
"parameter",
"nodes",
"of",
"a",
"FUNCTION",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/RuntimeTypeCheck.java#L443-L472 |
24,819 | google/closure-compiler | src/com/google/javascript/jscomp/CompilerOptions.java | CompilerOptions.setIdGenerators | public void setIdGenerators(Set<String> idGenerators) {
RenamingMap gen = new UniqueRenamingToken();
ImmutableMap.Builder<String, RenamingMap> builder = ImmutableMap.builder();
for (String name : idGenerators) {
builder.put(name, gen);
}
this.idGenerators = builder.build();
} | java | public void setIdGenerators(Set<String> idGenerators) {
RenamingMap gen = new UniqueRenamingToken();
ImmutableMap.Builder<String, RenamingMap> builder = ImmutableMap.builder();
for (String name : idGenerators) {
builder.put(name, gen);
}
this.idGenerators = builder.build();
} | [
"public",
"void",
"setIdGenerators",
"(",
"Set",
"<",
"String",
">",
"idGenerators",
")",
"{",
"RenamingMap",
"gen",
"=",
"new",
"UniqueRenamingToken",
"(",
")",
";",
"ImmutableMap",
".",
"Builder",
"<",
"String",
",",
"RenamingMap",
">",
"builder",
"=",
"ImmutableMap",
".",
"builder",
"(",
")",
";",
"for",
"(",
"String",
"name",
":",
"idGenerators",
")",
"{",
"builder",
".",
"put",
"(",
"name",
",",
"gen",
")",
";",
"}",
"this",
".",
"idGenerators",
"=",
"builder",
".",
"build",
"(",
")",
";",
"}"
] | Sets the id generators to replace. | [
"Sets",
"the",
"id",
"generators",
"to",
"replace",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/CompilerOptions.java#L1549-L1556 |
24,820 | google/closure-compiler | src/com/google/javascript/jscomp/CompilerOptions.java | CompilerOptions.setInlineVariables | public void setInlineVariables(Reach reach) {
switch (reach) {
case ALL:
this.inlineVariables = true;
this.inlineLocalVariables = true;
break;
case LOCAL_ONLY:
this.inlineVariables = false;
this.inlineLocalVariables = true;
break;
case NONE:
this.inlineVariables = false;
this.inlineLocalVariables = false;
break;
default:
throw new IllegalStateException("unexpected");
}
} | java | public void setInlineVariables(Reach reach) {
switch (reach) {
case ALL:
this.inlineVariables = true;
this.inlineLocalVariables = true;
break;
case LOCAL_ONLY:
this.inlineVariables = false;
this.inlineLocalVariables = true;
break;
case NONE:
this.inlineVariables = false;
this.inlineLocalVariables = false;
break;
default:
throw new IllegalStateException("unexpected");
}
} | [
"public",
"void",
"setInlineVariables",
"(",
"Reach",
"reach",
")",
"{",
"switch",
"(",
"reach",
")",
"{",
"case",
"ALL",
":",
"this",
".",
"inlineVariables",
"=",
"true",
";",
"this",
".",
"inlineLocalVariables",
"=",
"true",
";",
"break",
";",
"case",
"LOCAL_ONLY",
":",
"this",
".",
"inlineVariables",
"=",
"false",
";",
"this",
".",
"inlineLocalVariables",
"=",
"true",
";",
"break",
";",
"case",
"NONE",
":",
"this",
".",
"inlineVariables",
"=",
"false",
";",
"this",
".",
"inlineLocalVariables",
"=",
"false",
";",
"break",
";",
"default",
":",
"throw",
"new",
"IllegalStateException",
"(",
"\"unexpected\"",
")",
";",
"}",
"}"
] | Set the variable inlining policy for the compiler. | [
"Set",
"the",
"variable",
"inlining",
"policy",
"for",
"the",
"compiler",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/CompilerOptions.java#L1615-L1632 |
24,821 | google/closure-compiler | src/com/google/javascript/jscomp/CompilerOptions.java | CompilerOptions.setRemoveUnusedVariables | public void setRemoveUnusedVariables(Reach reach) {
switch (reach) {
case ALL:
this.removeUnusedVars = true;
this.removeUnusedLocalVars = true;
break;
case LOCAL_ONLY:
this.removeUnusedVars = false;
this.removeUnusedLocalVars = true;
break;
case NONE:
this.removeUnusedVars = false;
this.removeUnusedLocalVars = false;
break;
default:
throw new IllegalStateException("unexpected");
}
} | java | public void setRemoveUnusedVariables(Reach reach) {
switch (reach) {
case ALL:
this.removeUnusedVars = true;
this.removeUnusedLocalVars = true;
break;
case LOCAL_ONLY:
this.removeUnusedVars = false;
this.removeUnusedLocalVars = true;
break;
case NONE:
this.removeUnusedVars = false;
this.removeUnusedLocalVars = false;
break;
default:
throw new IllegalStateException("unexpected");
}
} | [
"public",
"void",
"setRemoveUnusedVariables",
"(",
"Reach",
"reach",
")",
"{",
"switch",
"(",
"reach",
")",
"{",
"case",
"ALL",
":",
"this",
".",
"removeUnusedVars",
"=",
"true",
";",
"this",
".",
"removeUnusedLocalVars",
"=",
"true",
";",
"break",
";",
"case",
"LOCAL_ONLY",
":",
"this",
".",
"removeUnusedVars",
"=",
"false",
";",
"this",
".",
"removeUnusedLocalVars",
"=",
"true",
";",
"break",
";",
"case",
"NONE",
":",
"this",
".",
"removeUnusedVars",
"=",
"false",
";",
"this",
".",
"removeUnusedLocalVars",
"=",
"false",
";",
"break",
";",
"default",
":",
"throw",
"new",
"IllegalStateException",
"(",
"\"unexpected\"",
")",
";",
"}",
"}"
] | Set the variable removal policy for the compiler. | [
"Set",
"the",
"variable",
"removal",
"policy",
"for",
"the",
"compiler",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/CompilerOptions.java#L1648-L1665 |
24,822 | google/closure-compiler | src/com/google/javascript/jscomp/CompilerOptions.java | CompilerOptions.setReplaceStringsConfiguration | public void setReplaceStringsConfiguration(
String placeholderToken, List<String> functionDescriptors) {
this.replaceStringsPlaceholderToken = placeholderToken;
this.replaceStringsFunctionDescriptions =
new ArrayList<>(functionDescriptors);
} | java | public void setReplaceStringsConfiguration(
String placeholderToken, List<String> functionDescriptors) {
this.replaceStringsPlaceholderToken = placeholderToken;
this.replaceStringsFunctionDescriptions =
new ArrayList<>(functionDescriptors);
} | [
"public",
"void",
"setReplaceStringsConfiguration",
"(",
"String",
"placeholderToken",
",",
"List",
"<",
"String",
">",
"functionDescriptors",
")",
"{",
"this",
".",
"replaceStringsPlaceholderToken",
"=",
"placeholderToken",
";",
"this",
".",
"replaceStringsFunctionDescriptions",
"=",
"new",
"ArrayList",
"<>",
"(",
"functionDescriptors",
")",
";",
"}"
] | Sets the functions whose debug strings to replace. | [
"Sets",
"the",
"functions",
"whose",
"debug",
"strings",
"to",
"replace",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/CompilerOptions.java#L1670-L1675 |
24,823 | google/closure-compiler | src/com/google/javascript/jscomp/CompilerOptions.java | CompilerOptions.setLanguage | public void setLanguage(LanguageMode language) {
checkState(language != LanguageMode.NO_TRANSPILE);
checkState(language != LanguageMode.UNSUPPORTED);
this.setLanguageIn(language);
this.setLanguageOut(language);
} | java | public void setLanguage(LanguageMode language) {
checkState(language != LanguageMode.NO_TRANSPILE);
checkState(language != LanguageMode.UNSUPPORTED);
this.setLanguageIn(language);
this.setLanguageOut(language);
} | [
"public",
"void",
"setLanguage",
"(",
"LanguageMode",
"language",
")",
"{",
"checkState",
"(",
"language",
"!=",
"LanguageMode",
".",
"NO_TRANSPILE",
")",
";",
"checkState",
"(",
"language",
"!=",
"LanguageMode",
".",
"UNSUPPORTED",
")",
";",
"this",
".",
"setLanguageIn",
"(",
"language",
")",
";",
"this",
".",
"setLanguageOut",
"(",
"language",
")",
";",
"}"
] | Sets ECMAScript version to use. | [
"Sets",
"ECMAScript",
"version",
"to",
"use",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/CompilerOptions.java#L1822-L1827 |
24,824 | google/closure-compiler | src/com/google/javascript/jscomp/CompilerOptions.java | CompilerOptions.setLanguageOut | public void setLanguageOut(LanguageMode languageOut) {
checkState(languageOut != LanguageMode.UNSUPPORTED);
if (languageOut == LanguageMode.NO_TRANSPILE) {
languageOutIsDefaultStrict = Optional.absent();
outputFeatureSet = Optional.absent();
} else {
languageOut = languageOut == LanguageMode.STABLE ? LanguageMode.STABLE_OUT : languageOut;
languageOutIsDefaultStrict = Optional.of(languageOut.isDefaultStrict());
setOutputFeatureSet(languageOut.toFeatureSet());
}
} | java | public void setLanguageOut(LanguageMode languageOut) {
checkState(languageOut != LanguageMode.UNSUPPORTED);
if (languageOut == LanguageMode.NO_TRANSPILE) {
languageOutIsDefaultStrict = Optional.absent();
outputFeatureSet = Optional.absent();
} else {
languageOut = languageOut == LanguageMode.STABLE ? LanguageMode.STABLE_OUT : languageOut;
languageOutIsDefaultStrict = Optional.of(languageOut.isDefaultStrict());
setOutputFeatureSet(languageOut.toFeatureSet());
}
} | [
"public",
"void",
"setLanguageOut",
"(",
"LanguageMode",
"languageOut",
")",
"{",
"checkState",
"(",
"languageOut",
"!=",
"LanguageMode",
".",
"UNSUPPORTED",
")",
";",
"if",
"(",
"languageOut",
"==",
"LanguageMode",
".",
"NO_TRANSPILE",
")",
"{",
"languageOutIsDefaultStrict",
"=",
"Optional",
".",
"absent",
"(",
")",
";",
"outputFeatureSet",
"=",
"Optional",
".",
"absent",
"(",
")",
";",
"}",
"else",
"{",
"languageOut",
"=",
"languageOut",
"==",
"LanguageMode",
".",
"STABLE",
"?",
"LanguageMode",
".",
"STABLE_OUT",
":",
"languageOut",
";",
"languageOutIsDefaultStrict",
"=",
"Optional",
".",
"of",
"(",
"languageOut",
".",
"isDefaultStrict",
"(",
")",
")",
";",
"setOutputFeatureSet",
"(",
"languageOut",
".",
"toFeatureSet",
"(",
")",
")",
";",
"}",
"}"
] | Sets ECMAScript version to use for the output.
<p>If you are not transpiling from one version to another, use #setLanguage instead.
<p>If you you need something more fine grained (e.g. "ES2017 without modules") use
#setOutputFeatureSet. | [
"Sets",
"ECMAScript",
"version",
"to",
"use",
"for",
"the",
"output",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/CompilerOptions.java#L1862-L1872 |
24,825 | google/closure-compiler | src/com/google/javascript/jscomp/CompilerOptions.java | CompilerOptions.setConformanceConfigs | @GwtIncompatible("Conformance")
public void setConformanceConfigs(List<ConformanceConfig> configs) {
this.conformanceConfigs =
ImmutableList.<ConformanceConfig>builder()
.add(ResourceLoader.loadGlobalConformance(CompilerOptions.class))
.addAll(configs)
.build();
} | java | @GwtIncompatible("Conformance")
public void setConformanceConfigs(List<ConformanceConfig> configs) {
this.conformanceConfigs =
ImmutableList.<ConformanceConfig>builder()
.add(ResourceLoader.loadGlobalConformance(CompilerOptions.class))
.addAll(configs)
.build();
} | [
"@",
"GwtIncompatible",
"(",
"\"Conformance\"",
")",
"public",
"void",
"setConformanceConfigs",
"(",
"List",
"<",
"ConformanceConfig",
">",
"configs",
")",
"{",
"this",
".",
"conformanceConfigs",
"=",
"ImmutableList",
".",
"<",
"ConformanceConfig",
">",
"builder",
"(",
")",
".",
"add",
"(",
"ResourceLoader",
".",
"loadGlobalConformance",
"(",
"CompilerOptions",
".",
"class",
")",
")",
".",
"addAll",
"(",
"configs",
")",
".",
"build",
"(",
")",
";",
"}"
] | Both enable and configure conformance checks, if non-null. | [
"Both",
"enable",
"and",
"configure",
"conformance",
"checks",
"if",
"non",
"-",
"null",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/CompilerOptions.java#L2749-L2756 |
24,826 | google/closure-compiler | src/com/google/javascript/jscomp/CompilerOptions.java | CompilerOptions.serialize | @GwtIncompatible("ObjectOutputStream")
public void serialize(OutputStream objectOutputStream) throws IOException {
new java.io.ObjectOutputStream(objectOutputStream).writeObject(this);
} | java | @GwtIncompatible("ObjectOutputStream")
public void serialize(OutputStream objectOutputStream) throws IOException {
new java.io.ObjectOutputStream(objectOutputStream).writeObject(this);
} | [
"@",
"GwtIncompatible",
"(",
"\"ObjectOutputStream\"",
")",
"public",
"void",
"serialize",
"(",
"OutputStream",
"objectOutputStream",
")",
"throws",
"IOException",
"{",
"new",
"java",
".",
"io",
".",
"ObjectOutputStream",
"(",
"objectOutputStream",
")",
".",
"writeObject",
"(",
"this",
")",
";",
"}"
] | Serializes compiler options to a stream. | [
"Serializes",
"compiler",
"options",
"to",
"a",
"stream",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/CompilerOptions.java#L2818-L2821 |
24,827 | google/closure-compiler | src/com/google/javascript/jscomp/CompilerOptions.java | CompilerOptions.deserialize | @GwtIncompatible("ObjectInputStream")
public static CompilerOptions deserialize(InputStream objectInputStream)
throws IOException, ClassNotFoundException {
return (CompilerOptions) new java.io.ObjectInputStream(objectInputStream).readObject();
} | java | @GwtIncompatible("ObjectInputStream")
public static CompilerOptions deserialize(InputStream objectInputStream)
throws IOException, ClassNotFoundException {
return (CompilerOptions) new java.io.ObjectInputStream(objectInputStream).readObject();
} | [
"@",
"GwtIncompatible",
"(",
"\"ObjectInputStream\"",
")",
"public",
"static",
"CompilerOptions",
"deserialize",
"(",
"InputStream",
"objectInputStream",
")",
"throws",
"IOException",
",",
"ClassNotFoundException",
"{",
"return",
"(",
"CompilerOptions",
")",
"new",
"java",
".",
"io",
".",
"ObjectInputStream",
"(",
"objectInputStream",
")",
".",
"readObject",
"(",
")",
";",
"}"
] | Deserializes compiler options from a stream. | [
"Deserializes",
"compiler",
"options",
"from",
"a",
"stream",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/CompilerOptions.java#L2824-L2828 |
24,828 | google/closure-compiler | src/com/google/javascript/jscomp/J2clConstantHoisterPass.java | J2clConstantHoisterPass.isHoistableFunction | private static boolean isHoistableFunction(NodeTraversal t, Node node) {
// TODO(michaelthomas): This could be improved slightly by not assuming that any variable in the
// outer scope is used in the function.
return node.isFunction() && t.getScope().getVarCount() == 0;
} | java | private static boolean isHoistableFunction(NodeTraversal t, Node node) {
// TODO(michaelthomas): This could be improved slightly by not assuming that any variable in the
// outer scope is used in the function.
return node.isFunction() && t.getScope().getVarCount() == 0;
} | [
"private",
"static",
"boolean",
"isHoistableFunction",
"(",
"NodeTraversal",
"t",
",",
"Node",
"node",
")",
"{",
"// TODO(michaelthomas): This could be improved slightly by not assuming that any variable in the",
"// outer scope is used in the function.",
"return",
"node",
".",
"isFunction",
"(",
")",
"&&",
"t",
".",
"getScope",
"(",
")",
".",
"getVarCount",
"(",
")",
"==",
"0",
";",
"}"
] | Returns whether the specified rValue is a function which does not receive any variables from
its containing scope, and is thus 'hoistable'. | [
"Returns",
"whether",
"the",
"specified",
"rValue",
"is",
"a",
"function",
"which",
"does",
"not",
"receive",
"any",
"variables",
"from",
"its",
"containing",
"scope",
"and",
"is",
"thus",
"hoistable",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/J2clConstantHoisterPass.java#L73-L77 |
24,829 | google/closure-compiler | src/com/google/javascript/jscomp/CreateSyntheticBlocks.java | CreateSyntheticBlocks.moveSiblingExclusive | private void moveSiblingExclusive(Node dest, Node start, Node end) {
checkNotNull(start);
checkNotNull(end);
while (start.getNext() != end) {
Node child = start.getNext().detach();
dest.addChildToBack(child);
}
} | java | private void moveSiblingExclusive(Node dest, Node start, Node end) {
checkNotNull(start);
checkNotNull(end);
while (start.getNext() != end) {
Node child = start.getNext().detach();
dest.addChildToBack(child);
}
} | [
"private",
"void",
"moveSiblingExclusive",
"(",
"Node",
"dest",
",",
"Node",
"start",
",",
"Node",
"end",
")",
"{",
"checkNotNull",
"(",
"start",
")",
";",
"checkNotNull",
"(",
"end",
")",
";",
"while",
"(",
"start",
".",
"getNext",
"(",
")",
"!=",
"end",
")",
"{",
"Node",
"child",
"=",
"start",
".",
"getNext",
"(",
")",
".",
"detach",
"(",
")",
";",
"dest",
".",
"addChildToBack",
"(",
"child",
")",
";",
"}",
"}"
] | Move the Nodes between start and end from the source block to the
destination block. If start is null, move the first child of the block.
If end is null, move the last child of the block. | [
"Move",
"the",
"Nodes",
"between",
"start",
"and",
"end",
"from",
"the",
"source",
"block",
"to",
"the",
"destination",
"block",
".",
"If",
"start",
"is",
"null",
"move",
"the",
"first",
"child",
"of",
"the",
"block",
".",
"If",
"end",
"is",
"null",
"move",
"the",
"last",
"child",
"of",
"the",
"block",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/CreateSyntheticBlocks.java#L133-L140 |
24,830 | google/closure-compiler | src/com/google/javascript/jscomp/Es6RewriteModules.java | Es6RewriteModules.isEs6ModuleRoot | public static boolean isEs6ModuleRoot(Node scriptNode) {
checkArgument(scriptNode.isScript(), scriptNode);
if (scriptNode.getBooleanProp(Node.GOOG_MODULE)) {
return false;
}
return scriptNode.hasChildren() && scriptNode.getFirstChild().isModuleBody();
} | java | public static boolean isEs6ModuleRoot(Node scriptNode) {
checkArgument(scriptNode.isScript(), scriptNode);
if (scriptNode.getBooleanProp(Node.GOOG_MODULE)) {
return false;
}
return scriptNode.hasChildren() && scriptNode.getFirstChild().isModuleBody();
} | [
"public",
"static",
"boolean",
"isEs6ModuleRoot",
"(",
"Node",
"scriptNode",
")",
"{",
"checkArgument",
"(",
"scriptNode",
".",
"isScript",
"(",
")",
",",
"scriptNode",
")",
";",
"if",
"(",
"scriptNode",
".",
"getBooleanProp",
"(",
"Node",
".",
"GOOG_MODULE",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"scriptNode",
".",
"hasChildren",
"(",
")",
"&&",
"scriptNode",
".",
"getFirstChild",
"(",
")",
".",
"isModuleBody",
"(",
")",
";",
"}"
] | Return whether or not the given script node represents an ES6 module file. | [
"Return",
"whether",
"or",
"not",
"the",
"given",
"script",
"node",
"represents",
"an",
"ES6",
"module",
"file",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Es6RewriteModules.java#L150-L156 |
24,831 | google/closure-compiler | src/com/google/javascript/jscomp/Es6RewriteModules.java | Es6RewriteModules.processFile | private void processFile(Node root) {
checkArgument(isEs6ModuleRoot(root), root);
clearState();
root.putBooleanProp(Node.TRANSPILED, true);
NodeTraversal.traverse(compiler, root, this);
} | java | private void processFile(Node root) {
checkArgument(isEs6ModuleRoot(root), root);
clearState();
root.putBooleanProp(Node.TRANSPILED, true);
NodeTraversal.traverse(compiler, root, this);
} | [
"private",
"void",
"processFile",
"(",
"Node",
"root",
")",
"{",
"checkArgument",
"(",
"isEs6ModuleRoot",
"(",
"root",
")",
",",
"root",
")",
";",
"clearState",
"(",
")",
";",
"root",
".",
"putBooleanProp",
"(",
"Node",
".",
"TRANSPILED",
",",
"true",
")",
";",
"NodeTraversal",
".",
"traverse",
"(",
"compiler",
",",
"root",
",",
"this",
")",
";",
"}"
] | Rewrite a single ES6 module file to a global script version. | [
"Rewrite",
"a",
"single",
"ES6",
"module",
"file",
"to",
"a",
"global",
"script",
"version",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Es6RewriteModules.java#L182-L187 |
24,832 | google/closure-compiler | src/com/google/javascript/jscomp/Es6RewriteModules.java | Es6RewriteModules.getFallbackMetadataForNamespace | private ModuleMetadata getFallbackMetadataForNamespace(String namespace) {
// Assume a provide'd file to be consistent with goog.module rewriting.
ModuleMetadata.Builder builder =
ModuleMetadata.builder()
.moduleType(ModuleMetadataMap.ModuleType.GOOG_PROVIDE)
.usesClosure(true)
.isTestOnly(false);
builder.googNamespacesBuilder().add(namespace);
return builder.build();
} | java | private ModuleMetadata getFallbackMetadataForNamespace(String namespace) {
// Assume a provide'd file to be consistent with goog.module rewriting.
ModuleMetadata.Builder builder =
ModuleMetadata.builder()
.moduleType(ModuleMetadataMap.ModuleType.GOOG_PROVIDE)
.usesClosure(true)
.isTestOnly(false);
builder.googNamespacesBuilder().add(namespace);
return builder.build();
} | [
"private",
"ModuleMetadata",
"getFallbackMetadataForNamespace",
"(",
"String",
"namespace",
")",
"{",
"// Assume a provide'd file to be consistent with goog.module rewriting.",
"ModuleMetadata",
".",
"Builder",
"builder",
"=",
"ModuleMetadata",
".",
"builder",
"(",
")",
".",
"moduleType",
"(",
"ModuleMetadataMap",
".",
"ModuleType",
".",
"GOOG_PROVIDE",
")",
".",
"usesClosure",
"(",
"true",
")",
".",
"isTestOnly",
"(",
"false",
")",
";",
"builder",
".",
"googNamespacesBuilder",
"(",
")",
".",
"add",
"(",
"namespace",
")",
";",
"return",
"builder",
".",
"build",
"(",
")",
";",
"}"
] | Gets some made-up metadata for the given Closure namespace.
<p>This is used when the namespace is not part of the input so that this pass can be fault
tolerant and still rewrite to something. Some tools don't care about rewriting correctly and
just want the type information of this module (e.g. clutz). | [
"Gets",
"some",
"made",
"-",
"up",
"metadata",
"for",
"the",
"given",
"Closure",
"namespace",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Es6RewriteModules.java#L746-L755 |
24,833 | google/closure-compiler | src/com/google/javascript/jscomp/DotFormatter.java | DotFormatter.toDot | static String toDot(Node n, ControlFlowGraph<Node> inCFG)
throws IOException {
StringBuilder builder = new StringBuilder();
new DotFormatter(n, inCFG, builder, false);
return builder.toString();
} | java | static String toDot(Node n, ControlFlowGraph<Node> inCFG)
throws IOException {
StringBuilder builder = new StringBuilder();
new DotFormatter(n, inCFG, builder, false);
return builder.toString();
} | [
"static",
"String",
"toDot",
"(",
"Node",
"n",
",",
"ControlFlowGraph",
"<",
"Node",
">",
"inCFG",
")",
"throws",
"IOException",
"{",
"StringBuilder",
"builder",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"new",
"DotFormatter",
"(",
"n",
",",
"inCFG",
",",
"builder",
",",
"false",
")",
";",
"return",
"builder",
".",
"toString",
"(",
")",
";",
"}"
] | Converts an AST to dot representation.
@param n the root of the AST described in the dot formatted string
@param inCFG Control Flow Graph.
@return the dot representation of the AST | [
"Converts",
"an",
"AST",
"to",
"dot",
"representation",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/DotFormatter.java#L93-L98 |
24,834 | google/closure-compiler | src/com/google/javascript/jscomp/DotFormatter.java | DotFormatter.toDot | public static String toDot(GraphvizGraph graph) {
StringBuilder builder = new StringBuilder();
builder.append(graph.isDirected() ? "digraph" : "graph");
builder.append(INDENT);
builder.append(graph.getName());
builder.append(" {\n");
builder.append(INDENT);
builder.append("node [color=lightblue2, style=filled];\n");
final String edgeSymbol = graph.isDirected() ? ARROW : LINE;
List<GraphvizNode> nodes = graph.getGraphvizNodes();
String[] nodeNames = new String[nodes.size()];
for (int i = 0; i < nodeNames.length; i++) {
GraphvizNode gNode = nodes.get(i);
nodeNames[i] =
gNode.getId()
+ " [label=\""
+ gNode.getLabel()
+ "\" color=\""
+ gNode.getColor()
+ "\"]";
}
// We sort the nodes so we get a deterministic output every time regardless
// of the implementation of the graph data structure.
Arrays.sort(nodeNames);
for (String nodeName : nodeNames) {
builder.append(INDENT);
builder.append(nodeName);
builder.append(";\n");
}
List<GraphvizEdge> edges = graph.getGraphvizEdges();
String[] edgeNames = new String[edges.size()];
for (int i = 0; i < edgeNames.length; i++) {
GraphvizEdge edge = edges.get(i);
edgeNames[i] = edge.getNode1Id() + edgeSymbol + edge.getNode2Id();
}
// Again, we sort the edges as well.
Arrays.sort(edgeNames);
for (String edgeName : edgeNames) {
builder.append(INDENT);
builder.append(edgeName);
builder.append(";\n");
}
builder.append("}\n");
return builder.toString();
} | java | public static String toDot(GraphvizGraph graph) {
StringBuilder builder = new StringBuilder();
builder.append(graph.isDirected() ? "digraph" : "graph");
builder.append(INDENT);
builder.append(graph.getName());
builder.append(" {\n");
builder.append(INDENT);
builder.append("node [color=lightblue2, style=filled];\n");
final String edgeSymbol = graph.isDirected() ? ARROW : LINE;
List<GraphvizNode> nodes = graph.getGraphvizNodes();
String[] nodeNames = new String[nodes.size()];
for (int i = 0; i < nodeNames.length; i++) {
GraphvizNode gNode = nodes.get(i);
nodeNames[i] =
gNode.getId()
+ " [label=\""
+ gNode.getLabel()
+ "\" color=\""
+ gNode.getColor()
+ "\"]";
}
// We sort the nodes so we get a deterministic output every time regardless
// of the implementation of the graph data structure.
Arrays.sort(nodeNames);
for (String nodeName : nodeNames) {
builder.append(INDENT);
builder.append(nodeName);
builder.append(";\n");
}
List<GraphvizEdge> edges = graph.getGraphvizEdges();
String[] edgeNames = new String[edges.size()];
for (int i = 0; i < edgeNames.length; i++) {
GraphvizEdge edge = edges.get(i);
edgeNames[i] = edge.getNode1Id() + edgeSymbol + edge.getNode2Id();
}
// Again, we sort the edges as well.
Arrays.sort(edgeNames);
for (String edgeName : edgeNames) {
builder.append(INDENT);
builder.append(edgeName);
builder.append(";\n");
}
builder.append("}\n");
return builder.toString();
} | [
"public",
"static",
"String",
"toDot",
"(",
"GraphvizGraph",
"graph",
")",
"{",
"StringBuilder",
"builder",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"builder",
".",
"append",
"(",
"graph",
".",
"isDirected",
"(",
")",
"?",
"\"digraph\"",
":",
"\"graph\"",
")",
";",
"builder",
".",
"append",
"(",
"INDENT",
")",
";",
"builder",
".",
"append",
"(",
"graph",
".",
"getName",
"(",
")",
")",
";",
"builder",
".",
"append",
"(",
"\" {\\n\"",
")",
";",
"builder",
".",
"append",
"(",
"INDENT",
")",
";",
"builder",
".",
"append",
"(",
"\"node [color=lightblue2, style=filled];\\n\"",
")",
";",
"final",
"String",
"edgeSymbol",
"=",
"graph",
".",
"isDirected",
"(",
")",
"?",
"ARROW",
":",
"LINE",
";",
"List",
"<",
"GraphvizNode",
">",
"nodes",
"=",
"graph",
".",
"getGraphvizNodes",
"(",
")",
";",
"String",
"[",
"]",
"nodeNames",
"=",
"new",
"String",
"[",
"nodes",
".",
"size",
"(",
")",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"nodeNames",
".",
"length",
";",
"i",
"++",
")",
"{",
"GraphvizNode",
"gNode",
"=",
"nodes",
".",
"get",
"(",
"i",
")",
";",
"nodeNames",
"[",
"i",
"]",
"=",
"gNode",
".",
"getId",
"(",
")",
"+",
"\" [label=\\\"\"",
"+",
"gNode",
".",
"getLabel",
"(",
")",
"+",
"\"\\\" color=\\\"\"",
"+",
"gNode",
".",
"getColor",
"(",
")",
"+",
"\"\\\"]\"",
";",
"}",
"// We sort the nodes so we get a deterministic output every time regardless",
"// of the implementation of the graph data structure.",
"Arrays",
".",
"sort",
"(",
"nodeNames",
")",
";",
"for",
"(",
"String",
"nodeName",
":",
"nodeNames",
")",
"{",
"builder",
".",
"append",
"(",
"INDENT",
")",
";",
"builder",
".",
"append",
"(",
"nodeName",
")",
";",
"builder",
".",
"append",
"(",
"\";\\n\"",
")",
";",
"}",
"List",
"<",
"GraphvizEdge",
">",
"edges",
"=",
"graph",
".",
"getGraphvizEdges",
"(",
")",
";",
"String",
"[",
"]",
"edgeNames",
"=",
"new",
"String",
"[",
"edges",
".",
"size",
"(",
")",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"edgeNames",
".",
"length",
";",
"i",
"++",
")",
"{",
"GraphvizEdge",
"edge",
"=",
"edges",
".",
"get",
"(",
"i",
")",
";",
"edgeNames",
"[",
"i",
"]",
"=",
"edge",
".",
"getNode1Id",
"(",
")",
"+",
"edgeSymbol",
"+",
"edge",
".",
"getNode2Id",
"(",
")",
";",
"}",
"// Again, we sort the edges as well.",
"Arrays",
".",
"sort",
"(",
"edgeNames",
")",
";",
"for",
"(",
"String",
"edgeName",
":",
"edgeNames",
")",
"{",
"builder",
".",
"append",
"(",
"INDENT",
")",
";",
"builder",
".",
"append",
"(",
"edgeName",
")",
";",
"builder",
".",
"append",
"(",
"\";\\n\"",
")",
";",
"}",
"builder",
".",
"append",
"(",
"\"}\\n\"",
")",
";",
"return",
"builder",
".",
"toString",
"(",
")",
";",
"}"
] | Outputs a string in DOT format that presents the graph.
@param graph Input graph.
@return A string in Dot format that presents the graph. | [
"Outputs",
"a",
"string",
"in",
"DOT",
"format",
"that",
"presents",
"the",
"graph",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/DotFormatter.java#L106-L162 |
24,835 | google/closure-compiler | src/com/google/javascript/jscomp/DotFormatter.java | DotFormatter.appendDot | static void appendDot(Node n, ControlFlowGraph<Node> inCFG,
Appendable builder) throws IOException {
new DotFormatter(n, inCFG, builder, false);
} | java | static void appendDot(Node n, ControlFlowGraph<Node> inCFG,
Appendable builder) throws IOException {
new DotFormatter(n, inCFG, builder, false);
} | [
"static",
"void",
"appendDot",
"(",
"Node",
"n",
",",
"ControlFlowGraph",
"<",
"Node",
">",
"inCFG",
",",
"Appendable",
"builder",
")",
"throws",
"IOException",
"{",
"new",
"DotFormatter",
"(",
"n",
",",
"inCFG",
",",
"builder",
",",
"false",
")",
";",
"}"
] | Converts an AST to dot representation and appends it to the given buffer.
@param n the root of the AST described in the dot formatted string
@param inCFG Control Flow Graph.
@param builder A place to dump the graph. | [
"Converts",
"an",
"AST",
"to",
"dot",
"representation",
"and",
"appends",
"it",
"to",
"the",
"given",
"buffer",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/DotFormatter.java#L170-L173 |
24,836 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseFunctionDeclaration | private ParseTree parseFunctionDeclaration() {
SourcePosition start = getTreeStartLocation();
eat(Keywords.FUNCTION.type);
boolean isGenerator = eatOpt(TokenType.STAR) != null;
FunctionDeclarationTree.Builder builder =
FunctionDeclarationTree.builder(FunctionDeclarationTree.Kind.DECLARATION).setName(eatId());
parseFunctionTail(builder, isGenerator ? FunctionFlavor.GENERATOR : FunctionFlavor.NORMAL);
return builder.build(getTreeLocation(start));
} | java | private ParseTree parseFunctionDeclaration() {
SourcePosition start = getTreeStartLocation();
eat(Keywords.FUNCTION.type);
boolean isGenerator = eatOpt(TokenType.STAR) != null;
FunctionDeclarationTree.Builder builder =
FunctionDeclarationTree.builder(FunctionDeclarationTree.Kind.DECLARATION).setName(eatId());
parseFunctionTail(builder, isGenerator ? FunctionFlavor.GENERATOR : FunctionFlavor.NORMAL);
return builder.build(getTreeLocation(start));
} | [
"private",
"ParseTree",
"parseFunctionDeclaration",
"(",
")",
"{",
"SourcePosition",
"start",
"=",
"getTreeStartLocation",
"(",
")",
";",
"eat",
"(",
"Keywords",
".",
"FUNCTION",
".",
"type",
")",
";",
"boolean",
"isGenerator",
"=",
"eatOpt",
"(",
"TokenType",
".",
"STAR",
")",
"!=",
"null",
";",
"FunctionDeclarationTree",
".",
"Builder",
"builder",
"=",
"FunctionDeclarationTree",
".",
"builder",
"(",
"FunctionDeclarationTree",
".",
"Kind",
".",
"DECLARATION",
")",
".",
"setName",
"(",
"eatId",
"(",
")",
")",
";",
"parseFunctionTail",
"(",
"builder",
",",
"isGenerator",
"?",
"FunctionFlavor",
".",
"GENERATOR",
":",
"FunctionFlavor",
".",
"NORMAL",
")",
";",
"return",
"builder",
".",
"build",
"(",
"getTreeLocation",
"(",
"start",
")",
")",
";",
"}"
] | 13 Function Definition | [
"13",
"Function",
"Definition"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L1256-L1265 |
24,837 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseVariableStatement | private VariableStatementTree parseVariableStatement() {
SourcePosition start = getTreeStartLocation();
VariableDeclarationListTree declarations = parseVariableDeclarationList();
eatPossibleImplicitSemiColon();
return new VariableStatementTree(getTreeLocation(start), declarations);
} | java | private VariableStatementTree parseVariableStatement() {
SourcePosition start = getTreeStartLocation();
VariableDeclarationListTree declarations = parseVariableDeclarationList();
eatPossibleImplicitSemiColon();
return new VariableStatementTree(getTreeLocation(start), declarations);
} | [
"private",
"VariableStatementTree",
"parseVariableStatement",
"(",
")",
"{",
"SourcePosition",
"start",
"=",
"getTreeStartLocation",
"(",
")",
";",
"VariableDeclarationListTree",
"declarations",
"=",
"parseVariableDeclarationList",
"(",
")",
";",
"eatPossibleImplicitSemiColon",
"(",
")",
";",
"return",
"new",
"VariableStatementTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"declarations",
")",
";",
"}"
] | 12.2 Variable Statement | [
"12",
".",
"2",
"Variable",
"Statement"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L1764-L1769 |
24,838 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseEmptyStatement | private EmptyStatementTree parseEmptyStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.SEMI_COLON);
return new EmptyStatementTree(getTreeLocation(start));
} | java | private EmptyStatementTree parseEmptyStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.SEMI_COLON);
return new EmptyStatementTree(getTreeLocation(start));
} | [
"private",
"EmptyStatementTree",
"parseEmptyStatement",
"(",
")",
"{",
"SourcePosition",
"start",
"=",
"getTreeStartLocation",
"(",
")",
";",
"eat",
"(",
"TokenType",
".",
"SEMI_COLON",
")",
";",
"return",
"new",
"EmptyStatementTree",
"(",
"getTreeLocation",
"(",
"start",
")",
")",
";",
"}"
] | 12.3 Empty Statement | [
"12",
".",
"3",
"Empty",
"Statement"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L1851-L1855 |
24,839 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseExpressionStatement | private ExpressionStatementTree parseExpressionStatement() {
SourcePosition start = getTreeStartLocation();
ParseTree expression = parseExpression();
eatPossibleImplicitSemiColon();
return new ExpressionStatementTree(getTreeLocation(start), expression);
} | java | private ExpressionStatementTree parseExpressionStatement() {
SourcePosition start = getTreeStartLocation();
ParseTree expression = parseExpression();
eatPossibleImplicitSemiColon();
return new ExpressionStatementTree(getTreeLocation(start), expression);
} | [
"private",
"ExpressionStatementTree",
"parseExpressionStatement",
"(",
")",
"{",
"SourcePosition",
"start",
"=",
"getTreeStartLocation",
"(",
")",
";",
"ParseTree",
"expression",
"=",
"parseExpression",
"(",
")",
";",
"eatPossibleImplicitSemiColon",
"(",
")",
";",
"return",
"new",
"ExpressionStatementTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"expression",
")",
";",
"}"
] | 12.4 Expression Statement | [
"12",
".",
"4",
"Expression",
"Statement"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L1858-L1863 |
24,840 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseIfStatement | private IfStatementTree parseIfStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.IF);
eat(TokenType.OPEN_PAREN);
ParseTree condition = parseExpression();
eat(TokenType.CLOSE_PAREN);
ParseTree ifClause = parseStatement();
ParseTree elseClause = null;
if (peek(TokenType.ELSE)) {
eat(TokenType.ELSE);
elseClause = parseStatement();
}
return new IfStatementTree(getTreeLocation(start), condition, ifClause, elseClause);
} | java | private IfStatementTree parseIfStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.IF);
eat(TokenType.OPEN_PAREN);
ParseTree condition = parseExpression();
eat(TokenType.CLOSE_PAREN);
ParseTree ifClause = parseStatement();
ParseTree elseClause = null;
if (peek(TokenType.ELSE)) {
eat(TokenType.ELSE);
elseClause = parseStatement();
}
return new IfStatementTree(getTreeLocation(start), condition, ifClause, elseClause);
} | [
"private",
"IfStatementTree",
"parseIfStatement",
"(",
")",
"{",
"SourcePosition",
"start",
"=",
"getTreeStartLocation",
"(",
")",
";",
"eat",
"(",
"TokenType",
".",
"IF",
")",
";",
"eat",
"(",
"TokenType",
".",
"OPEN_PAREN",
")",
";",
"ParseTree",
"condition",
"=",
"parseExpression",
"(",
")",
";",
"eat",
"(",
"TokenType",
".",
"CLOSE_PAREN",
")",
";",
"ParseTree",
"ifClause",
"=",
"parseStatement",
"(",
")",
";",
"ParseTree",
"elseClause",
"=",
"null",
";",
"if",
"(",
"peek",
"(",
"TokenType",
".",
"ELSE",
")",
")",
"{",
"eat",
"(",
"TokenType",
".",
"ELSE",
")",
";",
"elseClause",
"=",
"parseStatement",
"(",
")",
";",
"}",
"return",
"new",
"IfStatementTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"condition",
",",
"ifClause",
",",
"elseClause",
")",
";",
"}"
] | 12.5 If Statement | [
"12",
".",
"5",
"If",
"Statement"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L1866-L1879 |
24,841 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseDoWhileStatement | private ParseTree parseDoWhileStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.DO);
ParseTree body = parseStatement();
eat(TokenType.WHILE);
eat(TokenType.OPEN_PAREN);
ParseTree condition = parseExpression();
eat(TokenType.CLOSE_PAREN);
// The semicolon after the "do-while" is optional.
if (peek(TokenType.SEMI_COLON)) {
eat(TokenType.SEMI_COLON);
}
return new DoWhileStatementTree(getTreeLocation(start), body, condition);
} | java | private ParseTree parseDoWhileStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.DO);
ParseTree body = parseStatement();
eat(TokenType.WHILE);
eat(TokenType.OPEN_PAREN);
ParseTree condition = parseExpression();
eat(TokenType.CLOSE_PAREN);
// The semicolon after the "do-while" is optional.
if (peek(TokenType.SEMI_COLON)) {
eat(TokenType.SEMI_COLON);
}
return new DoWhileStatementTree(getTreeLocation(start), body, condition);
} | [
"private",
"ParseTree",
"parseDoWhileStatement",
"(",
")",
"{",
"SourcePosition",
"start",
"=",
"getTreeStartLocation",
"(",
")",
";",
"eat",
"(",
"TokenType",
".",
"DO",
")",
";",
"ParseTree",
"body",
"=",
"parseStatement",
"(",
")",
";",
"eat",
"(",
"TokenType",
".",
"WHILE",
")",
";",
"eat",
"(",
"TokenType",
".",
"OPEN_PAREN",
")",
";",
"ParseTree",
"condition",
"=",
"parseExpression",
"(",
")",
";",
"eat",
"(",
"TokenType",
".",
"CLOSE_PAREN",
")",
";",
"// The semicolon after the \"do-while\" is optional.",
"if",
"(",
"peek",
"(",
"TokenType",
".",
"SEMI_COLON",
")",
")",
"{",
"eat",
"(",
"TokenType",
".",
"SEMI_COLON",
")",
";",
"}",
"return",
"new",
"DoWhileStatementTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"body",
",",
"condition",
")",
";",
"}"
] | 12.6.1 The do-while Statement | [
"12",
".",
"6",
".",
"1",
"The",
"do",
"-",
"while",
"Statement"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L1884-L1897 |
24,842 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseWhileStatement | private ParseTree parseWhileStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.WHILE);
eat(TokenType.OPEN_PAREN);
ParseTree condition = parseExpression();
eat(TokenType.CLOSE_PAREN);
ParseTree body = parseStatement();
return new WhileStatementTree(getTreeLocation(start), condition, body);
} | java | private ParseTree parseWhileStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.WHILE);
eat(TokenType.OPEN_PAREN);
ParseTree condition = parseExpression();
eat(TokenType.CLOSE_PAREN);
ParseTree body = parseStatement();
return new WhileStatementTree(getTreeLocation(start), condition, body);
} | [
"private",
"ParseTree",
"parseWhileStatement",
"(",
")",
"{",
"SourcePosition",
"start",
"=",
"getTreeStartLocation",
"(",
")",
";",
"eat",
"(",
"TokenType",
".",
"WHILE",
")",
";",
"eat",
"(",
"TokenType",
".",
"OPEN_PAREN",
")",
";",
"ParseTree",
"condition",
"=",
"parseExpression",
"(",
")",
";",
"eat",
"(",
"TokenType",
".",
"CLOSE_PAREN",
")",
";",
"ParseTree",
"body",
"=",
"parseStatement",
"(",
")",
";",
"return",
"new",
"WhileStatementTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"condition",
",",
"body",
")",
";",
"}"
] | 12.6.2 The while Statement | [
"12",
".",
"6",
".",
"2",
"The",
"while",
"Statement"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L1900-L1908 |
24,843 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseForStatement | private ParseTree parseForStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.FOR);
boolean awaited = peekPredefinedString(AWAIT);
if (awaited) {
eatPredefinedString(AWAIT);
}
eat(TokenType.OPEN_PAREN);
if (peekVariableDeclarationList()) {
VariableDeclarationListTree variables = parseVariableDeclarationListNoIn();
if (peek(TokenType.IN)) {
if (awaited) {
reportError("for-await-of is the only allowed asynchronous iteration");
}
// for-in: only one declaration allowed
if (variables.declarations.size() > 1) {
reportError("for-in statement may not have more than one variable declaration");
}
VariableDeclarationTree declaration = variables.declarations.get(0);
if (declaration.initializer != null) {
// An initializer is allowed here in ES5 and below, but not in ES6.
// Warn about it, to encourage people to eliminate it from their code.
// http://esdiscuss.org/topic/initializer-expression-on-for-in-syntax-subject
if (config.atLeast6) {
reportError("for-in statement may not have initializer");
} else {
errorReporter.reportWarning(declaration.location.start,
"for-in statement should not have initializer");
}
}
return parseForInStatement(start, variables);
} else if (peekPredefinedString(PredefinedName.OF)) {
// for-of: only one declaration allowed
if (variables.declarations.size() > 1) {
if (awaited) {
reportError("for-await-of statement may not have more than one variable declaration");
} else {
reportError("for-of statement may not have more than one variable declaration");
}
}
// for-of: initializer is illegal
VariableDeclarationTree declaration = variables.declarations.get(0);
if (declaration.initializer != null) {
if (awaited) {
reportError("for-await-of statement may not have initializer");
} else {
reportError("for-of statement may not have initializer");
}
}
if (awaited) {
return parseForAwaitOfStatement(start, variables);
} else {
return parseForOfStatement(start, variables);
}
} else {
// "Vanilla" for statement: const/destructuring must have initializer
checkVanillaForInitializers(variables);
return parseForStatement(start, variables);
}
}
if (peek(TokenType.SEMI_COLON)) {
return parseForStatement(start, null);
}
ParseTree initializer = parseExpressionNoIn();
if (peek(TokenType.IN) || peek(TokenType.EQUAL) || peekPredefinedString(PredefinedName.OF)) {
initializer = transformLeftHandSideExpression(initializer);
if (!initializer.isValidAssignmentTarget()) {
reportError("invalid assignment target");
}
}
if (peek(TokenType.IN) || peekPredefinedString(PredefinedName.OF)) {
if (initializer.type != ParseTreeType.BINARY_OPERATOR
&& initializer.type != ParseTreeType.COMMA_EXPRESSION) {
if (peek(TokenType.IN)) {
return parseForInStatement(start, initializer);
} else {
// for {await}? ( _ of _ )
if (awaited) {
return parseForAwaitOfStatement(start, initializer);
} else {
return parseForOfStatement(start, initializer);
}
}
}
}
return parseForStatement(start, initializer);
} | java | private ParseTree parseForStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.FOR);
boolean awaited = peekPredefinedString(AWAIT);
if (awaited) {
eatPredefinedString(AWAIT);
}
eat(TokenType.OPEN_PAREN);
if (peekVariableDeclarationList()) {
VariableDeclarationListTree variables = parseVariableDeclarationListNoIn();
if (peek(TokenType.IN)) {
if (awaited) {
reportError("for-await-of is the only allowed asynchronous iteration");
}
// for-in: only one declaration allowed
if (variables.declarations.size() > 1) {
reportError("for-in statement may not have more than one variable declaration");
}
VariableDeclarationTree declaration = variables.declarations.get(0);
if (declaration.initializer != null) {
// An initializer is allowed here in ES5 and below, but not in ES6.
// Warn about it, to encourage people to eliminate it from their code.
// http://esdiscuss.org/topic/initializer-expression-on-for-in-syntax-subject
if (config.atLeast6) {
reportError("for-in statement may not have initializer");
} else {
errorReporter.reportWarning(declaration.location.start,
"for-in statement should not have initializer");
}
}
return parseForInStatement(start, variables);
} else if (peekPredefinedString(PredefinedName.OF)) {
// for-of: only one declaration allowed
if (variables.declarations.size() > 1) {
if (awaited) {
reportError("for-await-of statement may not have more than one variable declaration");
} else {
reportError("for-of statement may not have more than one variable declaration");
}
}
// for-of: initializer is illegal
VariableDeclarationTree declaration = variables.declarations.get(0);
if (declaration.initializer != null) {
if (awaited) {
reportError("for-await-of statement may not have initializer");
} else {
reportError("for-of statement may not have initializer");
}
}
if (awaited) {
return parseForAwaitOfStatement(start, variables);
} else {
return parseForOfStatement(start, variables);
}
} else {
// "Vanilla" for statement: const/destructuring must have initializer
checkVanillaForInitializers(variables);
return parseForStatement(start, variables);
}
}
if (peek(TokenType.SEMI_COLON)) {
return parseForStatement(start, null);
}
ParseTree initializer = parseExpressionNoIn();
if (peek(TokenType.IN) || peek(TokenType.EQUAL) || peekPredefinedString(PredefinedName.OF)) {
initializer = transformLeftHandSideExpression(initializer);
if (!initializer.isValidAssignmentTarget()) {
reportError("invalid assignment target");
}
}
if (peek(TokenType.IN) || peekPredefinedString(PredefinedName.OF)) {
if (initializer.type != ParseTreeType.BINARY_OPERATOR
&& initializer.type != ParseTreeType.COMMA_EXPRESSION) {
if (peek(TokenType.IN)) {
return parseForInStatement(start, initializer);
} else {
// for {await}? ( _ of _ )
if (awaited) {
return parseForAwaitOfStatement(start, initializer);
} else {
return parseForOfStatement(start, initializer);
}
}
}
}
return parseForStatement(start, initializer);
} | [
"private",
"ParseTree",
"parseForStatement",
"(",
")",
"{",
"SourcePosition",
"start",
"=",
"getTreeStartLocation",
"(",
")",
";",
"eat",
"(",
"TokenType",
".",
"FOR",
")",
";",
"boolean",
"awaited",
"=",
"peekPredefinedString",
"(",
"AWAIT",
")",
";",
"if",
"(",
"awaited",
")",
"{",
"eatPredefinedString",
"(",
"AWAIT",
")",
";",
"}",
"eat",
"(",
"TokenType",
".",
"OPEN_PAREN",
")",
";",
"if",
"(",
"peekVariableDeclarationList",
"(",
")",
")",
"{",
"VariableDeclarationListTree",
"variables",
"=",
"parseVariableDeclarationListNoIn",
"(",
")",
";",
"if",
"(",
"peek",
"(",
"TokenType",
".",
"IN",
")",
")",
"{",
"if",
"(",
"awaited",
")",
"{",
"reportError",
"(",
"\"for-await-of is the only allowed asynchronous iteration\"",
")",
";",
"}",
"// for-in: only one declaration allowed",
"if",
"(",
"variables",
".",
"declarations",
".",
"size",
"(",
")",
">",
"1",
")",
"{",
"reportError",
"(",
"\"for-in statement may not have more than one variable declaration\"",
")",
";",
"}",
"VariableDeclarationTree",
"declaration",
"=",
"variables",
".",
"declarations",
".",
"get",
"(",
"0",
")",
";",
"if",
"(",
"declaration",
".",
"initializer",
"!=",
"null",
")",
"{",
"// An initializer is allowed here in ES5 and below, but not in ES6.",
"// Warn about it, to encourage people to eliminate it from their code.",
"// http://esdiscuss.org/topic/initializer-expression-on-for-in-syntax-subject",
"if",
"(",
"config",
".",
"atLeast6",
")",
"{",
"reportError",
"(",
"\"for-in statement may not have initializer\"",
")",
";",
"}",
"else",
"{",
"errorReporter",
".",
"reportWarning",
"(",
"declaration",
".",
"location",
".",
"start",
",",
"\"for-in statement should not have initializer\"",
")",
";",
"}",
"}",
"return",
"parseForInStatement",
"(",
"start",
",",
"variables",
")",
";",
"}",
"else",
"if",
"(",
"peekPredefinedString",
"(",
"PredefinedName",
".",
"OF",
")",
")",
"{",
"// for-of: only one declaration allowed",
"if",
"(",
"variables",
".",
"declarations",
".",
"size",
"(",
")",
">",
"1",
")",
"{",
"if",
"(",
"awaited",
")",
"{",
"reportError",
"(",
"\"for-await-of statement may not have more than one variable declaration\"",
")",
";",
"}",
"else",
"{",
"reportError",
"(",
"\"for-of statement may not have more than one variable declaration\"",
")",
";",
"}",
"}",
"// for-of: initializer is illegal",
"VariableDeclarationTree",
"declaration",
"=",
"variables",
".",
"declarations",
".",
"get",
"(",
"0",
")",
";",
"if",
"(",
"declaration",
".",
"initializer",
"!=",
"null",
")",
"{",
"if",
"(",
"awaited",
")",
"{",
"reportError",
"(",
"\"for-await-of statement may not have initializer\"",
")",
";",
"}",
"else",
"{",
"reportError",
"(",
"\"for-of statement may not have initializer\"",
")",
";",
"}",
"}",
"if",
"(",
"awaited",
")",
"{",
"return",
"parseForAwaitOfStatement",
"(",
"start",
",",
"variables",
")",
";",
"}",
"else",
"{",
"return",
"parseForOfStatement",
"(",
"start",
",",
"variables",
")",
";",
"}",
"}",
"else",
"{",
"// \"Vanilla\" for statement: const/destructuring must have initializer",
"checkVanillaForInitializers",
"(",
"variables",
")",
";",
"return",
"parseForStatement",
"(",
"start",
",",
"variables",
")",
";",
"}",
"}",
"if",
"(",
"peek",
"(",
"TokenType",
".",
"SEMI_COLON",
")",
")",
"{",
"return",
"parseForStatement",
"(",
"start",
",",
"null",
")",
";",
"}",
"ParseTree",
"initializer",
"=",
"parseExpressionNoIn",
"(",
")",
";",
"if",
"(",
"peek",
"(",
"TokenType",
".",
"IN",
")",
"||",
"peek",
"(",
"TokenType",
".",
"EQUAL",
")",
"||",
"peekPredefinedString",
"(",
"PredefinedName",
".",
"OF",
")",
")",
"{",
"initializer",
"=",
"transformLeftHandSideExpression",
"(",
"initializer",
")",
";",
"if",
"(",
"!",
"initializer",
".",
"isValidAssignmentTarget",
"(",
")",
")",
"{",
"reportError",
"(",
"\"invalid assignment target\"",
")",
";",
"}",
"}",
"if",
"(",
"peek",
"(",
"TokenType",
".",
"IN",
")",
"||",
"peekPredefinedString",
"(",
"PredefinedName",
".",
"OF",
")",
")",
"{",
"if",
"(",
"initializer",
".",
"type",
"!=",
"ParseTreeType",
".",
"BINARY_OPERATOR",
"&&",
"initializer",
".",
"type",
"!=",
"ParseTreeType",
".",
"COMMA_EXPRESSION",
")",
"{",
"if",
"(",
"peek",
"(",
"TokenType",
".",
"IN",
")",
")",
"{",
"return",
"parseForInStatement",
"(",
"start",
",",
"initializer",
")",
";",
"}",
"else",
"{",
"// for {await}? ( _ of _ )",
"if",
"(",
"awaited",
")",
"{",
"return",
"parseForAwaitOfStatement",
"(",
"start",
",",
"initializer",
")",
";",
"}",
"else",
"{",
"return",
"parseForOfStatement",
"(",
"start",
",",
"initializer",
")",
";",
"}",
"}",
"}",
"}",
"return",
"parseForStatement",
"(",
"start",
",",
"initializer",
")",
";",
"}"
] | The for-await-of Statement | [
"The",
"for",
"-",
"await",
"-",
"of",
"Statement"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L1914-L2006 |
24,844 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.checkVanillaForInitializers | private void checkVanillaForInitializers(VariableDeclarationListTree variables) {
for (VariableDeclarationTree declaration : variables.declarations) {
if (declaration.initializer == null) {
maybeReportNoInitializer(variables.declarationType, declaration.lvalue);
}
}
} | java | private void checkVanillaForInitializers(VariableDeclarationListTree variables) {
for (VariableDeclarationTree declaration : variables.declarations) {
if (declaration.initializer == null) {
maybeReportNoInitializer(variables.declarationType, declaration.lvalue);
}
}
} | [
"private",
"void",
"checkVanillaForInitializers",
"(",
"VariableDeclarationListTree",
"variables",
")",
"{",
"for",
"(",
"VariableDeclarationTree",
"declaration",
":",
"variables",
".",
"declarations",
")",
"{",
"if",
"(",
"declaration",
".",
"initializer",
"==",
"null",
")",
"{",
"maybeReportNoInitializer",
"(",
"variables",
".",
"declarationType",
",",
"declaration",
".",
"lvalue",
")",
";",
"}",
"}",
"}"
] | Checks variable declarations in for statements. | [
"Checks",
"variable",
"declarations",
"in",
"for",
"statements",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L2029-L2035 |
24,845 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.maybeReportNoInitializer | private void maybeReportNoInitializer(TokenType token, ParseTree lvalue) {
if (token == TokenType.CONST) {
reportError("const variables must have an initializer");
} else if (lvalue.isPattern()) {
reportError("destructuring must have an initializer");
}
} | java | private void maybeReportNoInitializer(TokenType token, ParseTree lvalue) {
if (token == TokenType.CONST) {
reportError("const variables must have an initializer");
} else if (lvalue.isPattern()) {
reportError("destructuring must have an initializer");
}
} | [
"private",
"void",
"maybeReportNoInitializer",
"(",
"TokenType",
"token",
",",
"ParseTree",
"lvalue",
")",
"{",
"if",
"(",
"token",
"==",
"TokenType",
".",
"CONST",
")",
"{",
"reportError",
"(",
"\"const variables must have an initializer\"",
")",
";",
"}",
"else",
"if",
"(",
"lvalue",
".",
"isPattern",
"(",
")",
")",
"{",
"reportError",
"(",
"\"destructuring must have an initializer\"",
")",
";",
"}",
"}"
] | Reports if declaration requires an initializer, assuming initializer is absent. | [
"Reports",
"if",
"declaration",
"requires",
"an",
"initializer",
"assuming",
"initializer",
"is",
"absent",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L2038-L2044 |
24,846 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseForStatement | private ParseTree parseForStatement(SourcePosition start, ParseTree initializer) {
if (initializer == null) {
initializer = new NullTree(getTreeLocation(getTreeStartLocation()));
}
eat(TokenType.SEMI_COLON);
ParseTree condition;
if (!peek(TokenType.SEMI_COLON)) {
condition = parseExpression();
} else {
condition = new NullTree(getTreeLocation(getTreeStartLocation()));
}
eat(TokenType.SEMI_COLON);
ParseTree increment;
if (!peek(TokenType.CLOSE_PAREN)) {
increment = parseExpression();
} else {
increment = new NullTree(getTreeLocation(getTreeStartLocation()));
}
eat(TokenType.CLOSE_PAREN);
ParseTree body = parseStatement();
return new ForStatementTree(getTreeLocation(start), initializer, condition, increment, body);
} | java | private ParseTree parseForStatement(SourcePosition start, ParseTree initializer) {
if (initializer == null) {
initializer = new NullTree(getTreeLocation(getTreeStartLocation()));
}
eat(TokenType.SEMI_COLON);
ParseTree condition;
if (!peek(TokenType.SEMI_COLON)) {
condition = parseExpression();
} else {
condition = new NullTree(getTreeLocation(getTreeStartLocation()));
}
eat(TokenType.SEMI_COLON);
ParseTree increment;
if (!peek(TokenType.CLOSE_PAREN)) {
increment = parseExpression();
} else {
increment = new NullTree(getTreeLocation(getTreeStartLocation()));
}
eat(TokenType.CLOSE_PAREN);
ParseTree body = parseStatement();
return new ForStatementTree(getTreeLocation(start), initializer, condition, increment, body);
} | [
"private",
"ParseTree",
"parseForStatement",
"(",
"SourcePosition",
"start",
",",
"ParseTree",
"initializer",
")",
"{",
"if",
"(",
"initializer",
"==",
"null",
")",
"{",
"initializer",
"=",
"new",
"NullTree",
"(",
"getTreeLocation",
"(",
"getTreeStartLocation",
"(",
")",
")",
")",
";",
"}",
"eat",
"(",
"TokenType",
".",
"SEMI_COLON",
")",
";",
"ParseTree",
"condition",
";",
"if",
"(",
"!",
"peek",
"(",
"TokenType",
".",
"SEMI_COLON",
")",
")",
"{",
"condition",
"=",
"parseExpression",
"(",
")",
";",
"}",
"else",
"{",
"condition",
"=",
"new",
"NullTree",
"(",
"getTreeLocation",
"(",
"getTreeStartLocation",
"(",
")",
")",
")",
";",
"}",
"eat",
"(",
"TokenType",
".",
"SEMI_COLON",
")",
";",
"ParseTree",
"increment",
";",
"if",
"(",
"!",
"peek",
"(",
"TokenType",
".",
"CLOSE_PAREN",
")",
")",
"{",
"increment",
"=",
"parseExpression",
"(",
")",
";",
"}",
"else",
"{",
"increment",
"=",
"new",
"NullTree",
"(",
"getTreeLocation",
"(",
"getTreeStartLocation",
"(",
")",
")",
")",
";",
"}",
"eat",
"(",
"TokenType",
".",
"CLOSE_PAREN",
")",
";",
"ParseTree",
"body",
"=",
"parseStatement",
"(",
")",
";",
"return",
"new",
"ForStatementTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"initializer",
",",
"condition",
",",
"increment",
",",
"body",
")",
";",
"}"
] | 12.6.3 The for Statement | [
"12",
".",
"6",
".",
"3",
"The",
"for",
"Statement"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L2058-L2081 |
24,847 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseForInStatement | private ParseTree parseForInStatement(SourcePosition start, ParseTree initializer) {
eat(TokenType.IN);
ParseTree collection = parseExpression();
eat(TokenType.CLOSE_PAREN);
ParseTree body = parseStatement();
return new ForInStatementTree(getTreeLocation(start), initializer, collection, body);
} | java | private ParseTree parseForInStatement(SourcePosition start, ParseTree initializer) {
eat(TokenType.IN);
ParseTree collection = parseExpression();
eat(TokenType.CLOSE_PAREN);
ParseTree body = parseStatement();
return new ForInStatementTree(getTreeLocation(start), initializer, collection, body);
} | [
"private",
"ParseTree",
"parseForInStatement",
"(",
"SourcePosition",
"start",
",",
"ParseTree",
"initializer",
")",
"{",
"eat",
"(",
"TokenType",
".",
"IN",
")",
";",
"ParseTree",
"collection",
"=",
"parseExpression",
"(",
")",
";",
"eat",
"(",
"TokenType",
".",
"CLOSE_PAREN",
")",
";",
"ParseTree",
"body",
"=",
"parseStatement",
"(",
")",
";",
"return",
"new",
"ForInStatementTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"initializer",
",",
"collection",
",",
"body",
")",
";",
"}"
] | 12.6.4 The for-in Statement | [
"12",
".",
"6",
".",
"4",
"The",
"for",
"-",
"in",
"Statement"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L2084-L2090 |
24,848 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseContinueStatement | private ParseTree parseContinueStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.CONTINUE);
IdentifierToken name = null;
if (!peekImplicitSemiColon()) {
name = eatIdOpt();
}
eatPossibleImplicitSemiColon();
return new ContinueStatementTree(getTreeLocation(start), name);
} | java | private ParseTree parseContinueStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.CONTINUE);
IdentifierToken name = null;
if (!peekImplicitSemiColon()) {
name = eatIdOpt();
}
eatPossibleImplicitSemiColon();
return new ContinueStatementTree(getTreeLocation(start), name);
} | [
"private",
"ParseTree",
"parseContinueStatement",
"(",
")",
"{",
"SourcePosition",
"start",
"=",
"getTreeStartLocation",
"(",
")",
";",
"eat",
"(",
"TokenType",
".",
"CONTINUE",
")",
";",
"IdentifierToken",
"name",
"=",
"null",
";",
"if",
"(",
"!",
"peekImplicitSemiColon",
"(",
")",
")",
"{",
"name",
"=",
"eatIdOpt",
"(",
")",
";",
"}",
"eatPossibleImplicitSemiColon",
"(",
")",
";",
"return",
"new",
"ContinueStatementTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"name",
")",
";",
"}"
] | 12.7 The continue Statement | [
"12",
".",
"7",
"The",
"continue",
"Statement"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L2093-L2102 |
24,849 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseBreakStatement | private ParseTree parseBreakStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.BREAK);
IdentifierToken name = null;
if (!peekImplicitSemiColon()) {
name = eatIdOpt();
}
eatPossibleImplicitSemiColon();
return new BreakStatementTree(getTreeLocation(start), name);
} | java | private ParseTree parseBreakStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.BREAK);
IdentifierToken name = null;
if (!peekImplicitSemiColon()) {
name = eatIdOpt();
}
eatPossibleImplicitSemiColon();
return new BreakStatementTree(getTreeLocation(start), name);
} | [
"private",
"ParseTree",
"parseBreakStatement",
"(",
")",
"{",
"SourcePosition",
"start",
"=",
"getTreeStartLocation",
"(",
")",
";",
"eat",
"(",
"TokenType",
".",
"BREAK",
")",
";",
"IdentifierToken",
"name",
"=",
"null",
";",
"if",
"(",
"!",
"peekImplicitSemiColon",
"(",
")",
")",
"{",
"name",
"=",
"eatIdOpt",
"(",
")",
";",
"}",
"eatPossibleImplicitSemiColon",
"(",
")",
";",
"return",
"new",
"BreakStatementTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"name",
")",
";",
"}"
] | 12.8 The break Statement | [
"12",
".",
"8",
"The",
"break",
"Statement"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L2105-L2114 |
24,850 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseReturnStatement | private ParseTree parseReturnStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.RETURN);
ParseTree expression = null;
if (!peekImplicitSemiColon()) {
expression = parseExpression();
}
eatPossibleImplicitSemiColon();
return new ReturnStatementTree(getTreeLocation(start), expression);
} | java | private ParseTree parseReturnStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.RETURN);
ParseTree expression = null;
if (!peekImplicitSemiColon()) {
expression = parseExpression();
}
eatPossibleImplicitSemiColon();
return new ReturnStatementTree(getTreeLocation(start), expression);
} | [
"private",
"ParseTree",
"parseReturnStatement",
"(",
")",
"{",
"SourcePosition",
"start",
"=",
"getTreeStartLocation",
"(",
")",
";",
"eat",
"(",
"TokenType",
".",
"RETURN",
")",
";",
"ParseTree",
"expression",
"=",
"null",
";",
"if",
"(",
"!",
"peekImplicitSemiColon",
"(",
")",
")",
"{",
"expression",
"=",
"parseExpression",
"(",
")",
";",
"}",
"eatPossibleImplicitSemiColon",
"(",
")",
";",
"return",
"new",
"ReturnStatementTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"expression",
")",
";",
"}"
] | 12.9 The return Statement | [
"12",
".",
"9",
"The",
"return",
"Statement"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L2117-L2126 |
24,851 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseWithStatement | private ParseTree parseWithStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.WITH);
eat(TokenType.OPEN_PAREN);
ParseTree expression = parseExpression();
eat(TokenType.CLOSE_PAREN);
ParseTree body = parseStatement();
return new WithStatementTree(getTreeLocation(start), expression, body);
} | java | private ParseTree parseWithStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.WITH);
eat(TokenType.OPEN_PAREN);
ParseTree expression = parseExpression();
eat(TokenType.CLOSE_PAREN);
ParseTree body = parseStatement();
return new WithStatementTree(getTreeLocation(start), expression, body);
} | [
"private",
"ParseTree",
"parseWithStatement",
"(",
")",
"{",
"SourcePosition",
"start",
"=",
"getTreeStartLocation",
"(",
")",
";",
"eat",
"(",
"TokenType",
".",
"WITH",
")",
";",
"eat",
"(",
"TokenType",
".",
"OPEN_PAREN",
")",
";",
"ParseTree",
"expression",
"=",
"parseExpression",
"(",
")",
";",
"eat",
"(",
"TokenType",
".",
"CLOSE_PAREN",
")",
";",
"ParseTree",
"body",
"=",
"parseStatement",
"(",
")",
";",
"return",
"new",
"WithStatementTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"expression",
",",
"body",
")",
";",
"}"
] | 12.10 The with Statement | [
"12",
".",
"10",
"The",
"with",
"Statement"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L2129-L2137 |
24,852 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseSwitchStatement | private ParseTree parseSwitchStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.SWITCH);
eat(TokenType.OPEN_PAREN);
ParseTree expression = parseExpression();
eat(TokenType.CLOSE_PAREN);
eat(TokenType.OPEN_CURLY);
ImmutableList<ParseTree> caseClauses = parseCaseClauses();
eat(TokenType.CLOSE_CURLY);
return new SwitchStatementTree(getTreeLocation(start), expression, caseClauses);
} | java | private ParseTree parseSwitchStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.SWITCH);
eat(TokenType.OPEN_PAREN);
ParseTree expression = parseExpression();
eat(TokenType.CLOSE_PAREN);
eat(TokenType.OPEN_CURLY);
ImmutableList<ParseTree> caseClauses = parseCaseClauses();
eat(TokenType.CLOSE_CURLY);
return new SwitchStatementTree(getTreeLocation(start), expression, caseClauses);
} | [
"private",
"ParseTree",
"parseSwitchStatement",
"(",
")",
"{",
"SourcePosition",
"start",
"=",
"getTreeStartLocation",
"(",
")",
";",
"eat",
"(",
"TokenType",
".",
"SWITCH",
")",
";",
"eat",
"(",
"TokenType",
".",
"OPEN_PAREN",
")",
";",
"ParseTree",
"expression",
"=",
"parseExpression",
"(",
")",
";",
"eat",
"(",
"TokenType",
".",
"CLOSE_PAREN",
")",
";",
"eat",
"(",
"TokenType",
".",
"OPEN_CURLY",
")",
";",
"ImmutableList",
"<",
"ParseTree",
">",
"caseClauses",
"=",
"parseCaseClauses",
"(",
")",
";",
"eat",
"(",
"TokenType",
".",
"CLOSE_CURLY",
")",
";",
"return",
"new",
"SwitchStatementTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"expression",
",",
"caseClauses",
")",
";",
"}"
] | 12.11 The switch Statement | [
"12",
".",
"11",
"The",
"switch",
"Statement"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L2140-L2150 |
24,853 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseLabelledStatement | private ParseTree parseLabelledStatement() {
SourcePosition start = getTreeStartLocation();
IdentifierToken name = eatId();
eat(TokenType.COLON);
return new LabelledStatementTree(getTreeLocation(start), name, parseStatement());
} | java | private ParseTree parseLabelledStatement() {
SourcePosition start = getTreeStartLocation();
IdentifierToken name = eatId();
eat(TokenType.COLON);
return new LabelledStatementTree(getTreeLocation(start), name, parseStatement());
} | [
"private",
"ParseTree",
"parseLabelledStatement",
"(",
")",
"{",
"SourcePosition",
"start",
"=",
"getTreeStartLocation",
"(",
")",
";",
"IdentifierToken",
"name",
"=",
"eatId",
"(",
")",
";",
"eat",
"(",
"TokenType",
".",
"COLON",
")",
";",
"return",
"new",
"LabelledStatementTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"name",
",",
"parseStatement",
"(",
")",
")",
";",
"}"
] | 12.12 Labelled Statement | [
"12",
".",
"12",
"Labelled",
"Statement"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L2187-L2192 |
24,854 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseThrowStatement | private ParseTree parseThrowStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.THROW);
ParseTree value = null;
if (peekImplicitSemiColon()) {
reportError("semicolon/newline not allowed after 'throw'");
} else {
value = parseExpression();
}
eatPossibleImplicitSemiColon();
return new ThrowStatementTree(getTreeLocation(start), value);
} | java | private ParseTree parseThrowStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.THROW);
ParseTree value = null;
if (peekImplicitSemiColon()) {
reportError("semicolon/newline not allowed after 'throw'");
} else {
value = parseExpression();
}
eatPossibleImplicitSemiColon();
return new ThrowStatementTree(getTreeLocation(start), value);
} | [
"private",
"ParseTree",
"parseThrowStatement",
"(",
")",
"{",
"SourcePosition",
"start",
"=",
"getTreeStartLocation",
"(",
")",
";",
"eat",
"(",
"TokenType",
".",
"THROW",
")",
";",
"ParseTree",
"value",
"=",
"null",
";",
"if",
"(",
"peekImplicitSemiColon",
"(",
")",
")",
"{",
"reportError",
"(",
"\"semicolon/newline not allowed after 'throw'\"",
")",
";",
"}",
"else",
"{",
"value",
"=",
"parseExpression",
"(",
")",
";",
"}",
"eatPossibleImplicitSemiColon",
"(",
")",
";",
"return",
"new",
"ThrowStatementTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"value",
")",
";",
"}"
] | 12.13 Throw Statement | [
"12",
".",
"13",
"Throw",
"Statement"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L2200-L2211 |
24,855 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseTryStatement | private ParseTree parseTryStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.TRY);
ParseTree body = parseBlock();
ParseTree catchBlock = null;
if (peek(TokenType.CATCH)) {
catchBlock = parseCatch();
}
ParseTree finallyBlock = null;
if (peek(TokenType.FINALLY)) {
finallyBlock = parseFinallyBlock();
}
if (catchBlock == null && finallyBlock == null) {
reportError("'catch' or 'finally' expected.");
}
return new TryStatementTree(getTreeLocation(start), body, catchBlock, finallyBlock);
} | java | private ParseTree parseTryStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.TRY);
ParseTree body = parseBlock();
ParseTree catchBlock = null;
if (peek(TokenType.CATCH)) {
catchBlock = parseCatch();
}
ParseTree finallyBlock = null;
if (peek(TokenType.FINALLY)) {
finallyBlock = parseFinallyBlock();
}
if (catchBlock == null && finallyBlock == null) {
reportError("'catch' or 'finally' expected.");
}
return new TryStatementTree(getTreeLocation(start), body, catchBlock, finallyBlock);
} | [
"private",
"ParseTree",
"parseTryStatement",
"(",
")",
"{",
"SourcePosition",
"start",
"=",
"getTreeStartLocation",
"(",
")",
";",
"eat",
"(",
"TokenType",
".",
"TRY",
")",
";",
"ParseTree",
"body",
"=",
"parseBlock",
"(",
")",
";",
"ParseTree",
"catchBlock",
"=",
"null",
";",
"if",
"(",
"peek",
"(",
"TokenType",
".",
"CATCH",
")",
")",
"{",
"catchBlock",
"=",
"parseCatch",
"(",
")",
";",
"}",
"ParseTree",
"finallyBlock",
"=",
"null",
";",
"if",
"(",
"peek",
"(",
"TokenType",
".",
"FINALLY",
")",
")",
"{",
"finallyBlock",
"=",
"parseFinallyBlock",
"(",
")",
";",
"}",
"if",
"(",
"catchBlock",
"==",
"null",
"&&",
"finallyBlock",
"==",
"null",
")",
"{",
"reportError",
"(",
"\"'catch' or 'finally' expected.\"",
")",
";",
"}",
"return",
"new",
"TryStatementTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"body",
",",
"catchBlock",
",",
"finallyBlock",
")",
";",
"}"
] | 12.14 Try Statement | [
"12",
".",
"14",
"Try",
"Statement"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L2214-L2230 |
24,856 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseDebuggerStatement | private ParseTree parseDebuggerStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.DEBUGGER);
eatPossibleImplicitSemiColon();
return new DebuggerStatementTree(getTreeLocation(start));
} | java | private ParseTree parseDebuggerStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.DEBUGGER);
eatPossibleImplicitSemiColon();
return new DebuggerStatementTree(getTreeLocation(start));
} | [
"private",
"ParseTree",
"parseDebuggerStatement",
"(",
")",
"{",
"SourcePosition",
"start",
"=",
"getTreeStartLocation",
"(",
")",
";",
"eat",
"(",
"TokenType",
".",
"DEBUGGER",
")",
";",
"eatPossibleImplicitSemiColon",
"(",
")",
";",
"return",
"new",
"DebuggerStatementTree",
"(",
"getTreeLocation",
"(",
"start",
")",
")",
";",
"}"
] | 12.15 The Debugger Statement | [
"12",
".",
"15",
"The",
"Debugger",
"Statement"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L2264-L2270 |
24,857 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parsePrimaryExpression | private ParseTree parsePrimaryExpression() {
switch (peekType()) {
case CLASS:
return parseClassExpression();
case SUPER:
return parseSuperExpression();
case THIS:
return parseThisExpression();
case IMPORT:
return parseDynamicImportExpression();
case IDENTIFIER:
case TYPE:
case DECLARE:
case MODULE:
case NAMESPACE:
return parseIdentifierExpression();
case NUMBER:
case STRING:
case TRUE:
case FALSE:
case NULL:
return parseLiteralExpression();
case NO_SUBSTITUTION_TEMPLATE:
case TEMPLATE_HEAD:
return parseTemplateLiteral(null);
case OPEN_SQUARE:
return parseArrayInitializer();
case OPEN_CURLY:
return parseObjectLiteral();
case OPEN_PAREN:
return parseCoverParenthesizedExpressionAndArrowParameterList();
case SLASH:
case SLASH_EQUAL:
return parseRegularExpressionLiteral();
default:
return parseMissingPrimaryExpression();
}
} | java | private ParseTree parsePrimaryExpression() {
switch (peekType()) {
case CLASS:
return parseClassExpression();
case SUPER:
return parseSuperExpression();
case THIS:
return parseThisExpression();
case IMPORT:
return parseDynamicImportExpression();
case IDENTIFIER:
case TYPE:
case DECLARE:
case MODULE:
case NAMESPACE:
return parseIdentifierExpression();
case NUMBER:
case STRING:
case TRUE:
case FALSE:
case NULL:
return parseLiteralExpression();
case NO_SUBSTITUTION_TEMPLATE:
case TEMPLATE_HEAD:
return parseTemplateLiteral(null);
case OPEN_SQUARE:
return parseArrayInitializer();
case OPEN_CURLY:
return parseObjectLiteral();
case OPEN_PAREN:
return parseCoverParenthesizedExpressionAndArrowParameterList();
case SLASH:
case SLASH_EQUAL:
return parseRegularExpressionLiteral();
default:
return parseMissingPrimaryExpression();
}
} | [
"private",
"ParseTree",
"parsePrimaryExpression",
"(",
")",
"{",
"switch",
"(",
"peekType",
"(",
")",
")",
"{",
"case",
"CLASS",
":",
"return",
"parseClassExpression",
"(",
")",
";",
"case",
"SUPER",
":",
"return",
"parseSuperExpression",
"(",
")",
";",
"case",
"THIS",
":",
"return",
"parseThisExpression",
"(",
")",
";",
"case",
"IMPORT",
":",
"return",
"parseDynamicImportExpression",
"(",
")",
";",
"case",
"IDENTIFIER",
":",
"case",
"TYPE",
":",
"case",
"DECLARE",
":",
"case",
"MODULE",
":",
"case",
"NAMESPACE",
":",
"return",
"parseIdentifierExpression",
"(",
")",
";",
"case",
"NUMBER",
":",
"case",
"STRING",
":",
"case",
"TRUE",
":",
"case",
"FALSE",
":",
"case",
"NULL",
":",
"return",
"parseLiteralExpression",
"(",
")",
";",
"case",
"NO_SUBSTITUTION_TEMPLATE",
":",
"case",
"TEMPLATE_HEAD",
":",
"return",
"parseTemplateLiteral",
"(",
"null",
")",
";",
"case",
"OPEN_SQUARE",
":",
"return",
"parseArrayInitializer",
"(",
")",
";",
"case",
"OPEN_CURLY",
":",
"return",
"parseObjectLiteral",
"(",
")",
";",
"case",
"OPEN_PAREN",
":",
"return",
"parseCoverParenthesizedExpressionAndArrowParameterList",
"(",
")",
";",
"case",
"SLASH",
":",
"case",
"SLASH_EQUAL",
":",
"return",
"parseRegularExpressionLiteral",
"(",
")",
";",
"default",
":",
"return",
"parseMissingPrimaryExpression",
"(",
")",
";",
"}",
"}"
] | 11.1 Primary Expressions | [
"11",
".",
"1",
"Primary",
"Expressions"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L2273-L2310 |
24,858 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseArrayLiteral | private ParseTree parseArrayLiteral() {
// ArrayLiteral :
// [ Elisionopt ]
// [ ElementList ]
// [ ElementList , Elisionopt ]
//
// ElementList :
// Elisionopt AssignmentOrSpreadExpression
// ElementList , Elisionopt AssignmentOrSpreadExpression
//
// Elision :
// ,
// Elision ,
SourcePosition start = getTreeStartLocation();
ImmutableList.Builder<ParseTree> elements = ImmutableList.builder();
eat(TokenType.OPEN_SQUARE);
Token trailingCommaToken = null;
while (peek(TokenType.COMMA) || peek(TokenType.SPREAD) || peekAssignmentExpression()) {
trailingCommaToken = null;
if (peek(TokenType.COMMA)) {
elements.add(new NullTree(getTreeLocation(getTreeStartLocation())));
} else {
if (peek(TokenType.SPREAD)) {
recordFeatureUsed(Feature.SPREAD_EXPRESSIONS);
elements.add(parseSpreadExpression());
} else {
elements.add(parseAssignmentExpression());
}
}
if (!peek(TokenType.CLOSE_SQUARE)) {
trailingCommaToken = eat(TokenType.COMMA);
}
}
eat(TokenType.CLOSE_SQUARE);
maybeReportTrailingComma(trailingCommaToken);
return new ArrayLiteralExpressionTree(
getTreeLocation(start), elements.build());
} | java | private ParseTree parseArrayLiteral() {
// ArrayLiteral :
// [ Elisionopt ]
// [ ElementList ]
// [ ElementList , Elisionopt ]
//
// ElementList :
// Elisionopt AssignmentOrSpreadExpression
// ElementList , Elisionopt AssignmentOrSpreadExpression
//
// Elision :
// ,
// Elision ,
SourcePosition start = getTreeStartLocation();
ImmutableList.Builder<ParseTree> elements = ImmutableList.builder();
eat(TokenType.OPEN_SQUARE);
Token trailingCommaToken = null;
while (peek(TokenType.COMMA) || peek(TokenType.SPREAD) || peekAssignmentExpression()) {
trailingCommaToken = null;
if (peek(TokenType.COMMA)) {
elements.add(new NullTree(getTreeLocation(getTreeStartLocation())));
} else {
if (peek(TokenType.SPREAD)) {
recordFeatureUsed(Feature.SPREAD_EXPRESSIONS);
elements.add(parseSpreadExpression());
} else {
elements.add(parseAssignmentExpression());
}
}
if (!peek(TokenType.CLOSE_SQUARE)) {
trailingCommaToken = eat(TokenType.COMMA);
}
}
eat(TokenType.CLOSE_SQUARE);
maybeReportTrailingComma(trailingCommaToken);
return new ArrayLiteralExpressionTree(
getTreeLocation(start), elements.build());
} | [
"private",
"ParseTree",
"parseArrayLiteral",
"(",
")",
"{",
"// ArrayLiteral :",
"// [ Elisionopt ]",
"// [ ElementList ]",
"// [ ElementList , Elisionopt ]",
"//",
"// ElementList :",
"// Elisionopt AssignmentOrSpreadExpression",
"// ElementList , Elisionopt AssignmentOrSpreadExpression",
"//",
"// Elision :",
"// ,",
"// Elision ,",
"SourcePosition",
"start",
"=",
"getTreeStartLocation",
"(",
")",
";",
"ImmutableList",
".",
"Builder",
"<",
"ParseTree",
">",
"elements",
"=",
"ImmutableList",
".",
"builder",
"(",
")",
";",
"eat",
"(",
"TokenType",
".",
"OPEN_SQUARE",
")",
";",
"Token",
"trailingCommaToken",
"=",
"null",
";",
"while",
"(",
"peek",
"(",
"TokenType",
".",
"COMMA",
")",
"||",
"peek",
"(",
"TokenType",
".",
"SPREAD",
")",
"||",
"peekAssignmentExpression",
"(",
")",
")",
"{",
"trailingCommaToken",
"=",
"null",
";",
"if",
"(",
"peek",
"(",
"TokenType",
".",
"COMMA",
")",
")",
"{",
"elements",
".",
"add",
"(",
"new",
"NullTree",
"(",
"getTreeLocation",
"(",
"getTreeStartLocation",
"(",
")",
")",
")",
")",
";",
"}",
"else",
"{",
"if",
"(",
"peek",
"(",
"TokenType",
".",
"SPREAD",
")",
")",
"{",
"recordFeatureUsed",
"(",
"Feature",
".",
"SPREAD_EXPRESSIONS",
")",
";",
"elements",
".",
"add",
"(",
"parseSpreadExpression",
"(",
")",
")",
";",
"}",
"else",
"{",
"elements",
".",
"add",
"(",
"parseAssignmentExpression",
"(",
")",
")",
";",
"}",
"}",
"if",
"(",
"!",
"peek",
"(",
"TokenType",
".",
"CLOSE_SQUARE",
")",
")",
"{",
"trailingCommaToken",
"=",
"eat",
"(",
"TokenType",
".",
"COMMA",
")",
";",
"}",
"}",
"eat",
"(",
"TokenType",
".",
"CLOSE_SQUARE",
")",
";",
"maybeReportTrailingComma",
"(",
"trailingCommaToken",
")",
";",
"return",
"new",
"ArrayLiteralExpressionTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"elements",
".",
"build",
"(",
")",
")",
";",
"}"
] | 11.1.4 Array Literal Expression | [
"11",
".",
"1",
".",
"4",
"Array",
"Literal",
"Expression"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L2494-L2535 |
24,859 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseObjectLiteral | private ParseTree parseObjectLiteral() {
SourcePosition start = getTreeStartLocation();
ImmutableList.Builder<ParseTree> result = ImmutableList.builder();
eat(TokenType.OPEN_CURLY);
Token commaToken = null;
while (peek(TokenType.SPREAD)
|| peekPropertyNameOrComputedProp(0)
|| peek(TokenType.STAR)
|| peekAccessibilityModifier()) {
commaToken = null;
result.add(parsePropertyAssignment());
commaToken = eatOpt(TokenType.COMMA);
if (commaToken == null) {
break;
}
}
eat(TokenType.CLOSE_CURLY);
maybeReportTrailingComma(commaToken);
return new ObjectLiteralExpressionTree(getTreeLocation(start), result.build());
} | java | private ParseTree parseObjectLiteral() {
SourcePosition start = getTreeStartLocation();
ImmutableList.Builder<ParseTree> result = ImmutableList.builder();
eat(TokenType.OPEN_CURLY);
Token commaToken = null;
while (peek(TokenType.SPREAD)
|| peekPropertyNameOrComputedProp(0)
|| peek(TokenType.STAR)
|| peekAccessibilityModifier()) {
commaToken = null;
result.add(parsePropertyAssignment());
commaToken = eatOpt(TokenType.COMMA);
if (commaToken == null) {
break;
}
}
eat(TokenType.CLOSE_CURLY);
maybeReportTrailingComma(commaToken);
return new ObjectLiteralExpressionTree(getTreeLocation(start), result.build());
} | [
"private",
"ParseTree",
"parseObjectLiteral",
"(",
")",
"{",
"SourcePosition",
"start",
"=",
"getTreeStartLocation",
"(",
")",
";",
"ImmutableList",
".",
"Builder",
"<",
"ParseTree",
">",
"result",
"=",
"ImmutableList",
".",
"builder",
"(",
")",
";",
"eat",
"(",
"TokenType",
".",
"OPEN_CURLY",
")",
";",
"Token",
"commaToken",
"=",
"null",
";",
"while",
"(",
"peek",
"(",
"TokenType",
".",
"SPREAD",
")",
"||",
"peekPropertyNameOrComputedProp",
"(",
"0",
")",
"||",
"peek",
"(",
"TokenType",
".",
"STAR",
")",
"||",
"peekAccessibilityModifier",
"(",
")",
")",
"{",
"commaToken",
"=",
"null",
";",
"result",
".",
"add",
"(",
"parsePropertyAssignment",
"(",
")",
")",
";",
"commaToken",
"=",
"eatOpt",
"(",
"TokenType",
".",
"COMMA",
")",
";",
"if",
"(",
"commaToken",
"==",
"null",
")",
"{",
"break",
";",
"}",
"}",
"eat",
"(",
"TokenType",
".",
"CLOSE_CURLY",
")",
";",
"maybeReportTrailingComma",
"(",
"commaToken",
")",
";",
"return",
"new",
"ObjectLiteralExpressionTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"result",
".",
"build",
"(",
")",
")",
";",
"}"
] | 11.1.4 Object Literal Expression | [
"11",
".",
"1",
".",
"4",
"Object",
"Literal",
"Expression"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L2538-L2560 |
24,860 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.transformLeftHandSideExpression | private ParseTree transformLeftHandSideExpression(ParseTree tree) {
switch (tree.type) {
case ARRAY_LITERAL_EXPRESSION:
case OBJECT_LITERAL_EXPRESSION:
resetScanner(tree);
// If we fail to parse as an LeftHandSidePattern then
// parseLeftHandSidePattern will take care reporting errors.
return parseLeftHandSidePattern();
default:
return tree;
}
} | java | private ParseTree transformLeftHandSideExpression(ParseTree tree) {
switch (tree.type) {
case ARRAY_LITERAL_EXPRESSION:
case OBJECT_LITERAL_EXPRESSION:
resetScanner(tree);
// If we fail to parse as an LeftHandSidePattern then
// parseLeftHandSidePattern will take care reporting errors.
return parseLeftHandSidePattern();
default:
return tree;
}
} | [
"private",
"ParseTree",
"transformLeftHandSideExpression",
"(",
"ParseTree",
"tree",
")",
"{",
"switch",
"(",
"tree",
".",
"type",
")",
"{",
"case",
"ARRAY_LITERAL_EXPRESSION",
":",
"case",
"OBJECT_LITERAL_EXPRESSION",
":",
"resetScanner",
"(",
"tree",
")",
";",
"// If we fail to parse as an LeftHandSidePattern then",
"// parseLeftHandSidePattern will take care reporting errors.",
"return",
"parseLeftHandSidePattern",
"(",
")",
";",
"default",
":",
"return",
"tree",
";",
"}",
"}"
] | Transforms a LeftHandSideExpression into a LeftHandSidePattern if possible.
This returns the transformed tree if it parses as a LeftHandSidePattern,
otherwise it returns the original tree. | [
"Transforms",
"a",
"LeftHandSideExpression",
"into",
"a",
"LeftHandSidePattern",
"if",
"possible",
".",
"This",
"returns",
"the",
"transformed",
"tree",
"if",
"it",
"parses",
"as",
"a",
"LeftHandSidePattern",
"otherwise",
"it",
"returns",
"the",
"original",
"tree",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L3143-L3154 |
24,861 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseConditional | private ParseTree parseConditional(Expression expressionIn) {
SourcePosition start = getTreeStartLocation();
ParseTree condition = parseLogicalOR(expressionIn);
if (peek(TokenType.QUESTION)) {
eat(TokenType.QUESTION);
ParseTree left = parseAssignment(expressionIn);
eat(TokenType.COLON);
ParseTree right = parseAssignment(expressionIn);
return new ConditionalExpressionTree(
getTreeLocation(start), condition, left, right);
}
return condition;
} | java | private ParseTree parseConditional(Expression expressionIn) {
SourcePosition start = getTreeStartLocation();
ParseTree condition = parseLogicalOR(expressionIn);
if (peek(TokenType.QUESTION)) {
eat(TokenType.QUESTION);
ParseTree left = parseAssignment(expressionIn);
eat(TokenType.COLON);
ParseTree right = parseAssignment(expressionIn);
return new ConditionalExpressionTree(
getTreeLocation(start), condition, left, right);
}
return condition;
} | [
"private",
"ParseTree",
"parseConditional",
"(",
"Expression",
"expressionIn",
")",
"{",
"SourcePosition",
"start",
"=",
"getTreeStartLocation",
"(",
")",
";",
"ParseTree",
"condition",
"=",
"parseLogicalOR",
"(",
"expressionIn",
")",
";",
"if",
"(",
"peek",
"(",
"TokenType",
".",
"QUESTION",
")",
")",
"{",
"eat",
"(",
"TokenType",
".",
"QUESTION",
")",
";",
"ParseTree",
"left",
"=",
"parseAssignment",
"(",
"expressionIn",
")",
";",
"eat",
"(",
"TokenType",
".",
"COLON",
")",
";",
"ParseTree",
"right",
"=",
"parseAssignment",
"(",
"expressionIn",
")",
";",
"return",
"new",
"ConditionalExpressionTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"condition",
",",
"left",
",",
"right",
")",
";",
"}",
"return",
"condition",
";",
"}"
] | 11.12 Conditional Expression | [
"11",
".",
"12",
"Conditional",
"Expression"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L3221-L3233 |
24,862 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseLogicalOR | private ParseTree parseLogicalOR(Expression expressionIn) {
SourcePosition start = getTreeStartLocation();
ParseTree left = parseLogicalAND(expressionIn);
while (peek(TokenType.OR)) {
Token operator = eat(TokenType.OR);
ParseTree right = parseLogicalAND(expressionIn);
left = new BinaryOperatorTree(getTreeLocation(start), left, operator, right);
}
return left;
} | java | private ParseTree parseLogicalOR(Expression expressionIn) {
SourcePosition start = getTreeStartLocation();
ParseTree left = parseLogicalAND(expressionIn);
while (peek(TokenType.OR)) {
Token operator = eat(TokenType.OR);
ParseTree right = parseLogicalAND(expressionIn);
left = new BinaryOperatorTree(getTreeLocation(start), left, operator, right);
}
return left;
} | [
"private",
"ParseTree",
"parseLogicalOR",
"(",
"Expression",
"expressionIn",
")",
"{",
"SourcePosition",
"start",
"=",
"getTreeStartLocation",
"(",
")",
";",
"ParseTree",
"left",
"=",
"parseLogicalAND",
"(",
"expressionIn",
")",
";",
"while",
"(",
"peek",
"(",
"TokenType",
".",
"OR",
")",
")",
"{",
"Token",
"operator",
"=",
"eat",
"(",
"TokenType",
".",
"OR",
")",
";",
"ParseTree",
"right",
"=",
"parseLogicalAND",
"(",
"expressionIn",
")",
";",
"left",
"=",
"new",
"BinaryOperatorTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"left",
",",
"operator",
",",
"right",
")",
";",
"}",
"return",
"left",
";",
"}"
] | 11.11 Logical OR | [
"11",
".",
"11",
"Logical",
"OR"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L3236-L3245 |
24,863 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseEquality | private ParseTree parseEquality(Expression expressionIn) {
SourcePosition start = getTreeStartLocation();
ParseTree left = parseRelational(expressionIn);
while (peekEqualityOperator()) {
Token operator = nextToken();
ParseTree right = parseRelational(expressionIn);
left = new BinaryOperatorTree(getTreeLocation(start), left, operator, right);
}
return left;
} | java | private ParseTree parseEquality(Expression expressionIn) {
SourcePosition start = getTreeStartLocation();
ParseTree left = parseRelational(expressionIn);
while (peekEqualityOperator()) {
Token operator = nextToken();
ParseTree right = parseRelational(expressionIn);
left = new BinaryOperatorTree(getTreeLocation(start), left, operator, right);
}
return left;
} | [
"private",
"ParseTree",
"parseEquality",
"(",
"Expression",
"expressionIn",
")",
"{",
"SourcePosition",
"start",
"=",
"getTreeStartLocation",
"(",
")",
";",
"ParseTree",
"left",
"=",
"parseRelational",
"(",
"expressionIn",
")",
";",
"while",
"(",
"peekEqualityOperator",
"(",
")",
")",
"{",
"Token",
"operator",
"=",
"nextToken",
"(",
")",
";",
"ParseTree",
"right",
"=",
"parseRelational",
"(",
"expressionIn",
")",
";",
"left",
"=",
"new",
"BinaryOperatorTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"left",
",",
"operator",
",",
"right",
")",
";",
"}",
"return",
"left",
";",
"}"
] | 11.9 Equality Expression | [
"11",
".",
"9",
"Equality",
"Expression"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L3296-L3305 |
24,864 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseRelational | private ParseTree parseRelational(Expression expressionIn) {
SourcePosition start = getTreeStartLocation();
ParseTree left = parseShiftExpression();
while (peekRelationalOperator(expressionIn)) {
Token operator = nextToken();
ParseTree right = parseShiftExpression();
left = new BinaryOperatorTree(getTreeLocation(start), left, operator, right);
}
return left;
} | java | private ParseTree parseRelational(Expression expressionIn) {
SourcePosition start = getTreeStartLocation();
ParseTree left = parseShiftExpression();
while (peekRelationalOperator(expressionIn)) {
Token operator = nextToken();
ParseTree right = parseShiftExpression();
left = new BinaryOperatorTree(getTreeLocation(start), left, operator, right);
}
return left;
} | [
"private",
"ParseTree",
"parseRelational",
"(",
"Expression",
"expressionIn",
")",
"{",
"SourcePosition",
"start",
"=",
"getTreeStartLocation",
"(",
")",
";",
"ParseTree",
"left",
"=",
"parseShiftExpression",
"(",
")",
";",
"while",
"(",
"peekRelationalOperator",
"(",
"expressionIn",
")",
")",
"{",
"Token",
"operator",
"=",
"nextToken",
"(",
")",
";",
"ParseTree",
"right",
"=",
"parseShiftExpression",
"(",
")",
";",
"left",
"=",
"new",
"BinaryOperatorTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"left",
",",
"operator",
",",
"right",
")",
";",
"}",
"return",
"left",
";",
"}"
] | 11.8 Relational | [
"11",
".",
"8",
"Relational"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L3320-L3329 |
24,865 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseShiftExpression | private ParseTree parseShiftExpression() {
SourcePosition start = getTreeStartLocation();
ParseTree left = parseAdditiveExpression();
while (peekShiftOperator()) {
Token operator = nextToken();
ParseTree right = parseAdditiveExpression();
left = new BinaryOperatorTree(getTreeLocation(start), left, operator, right);
}
return left;
} | java | private ParseTree parseShiftExpression() {
SourcePosition start = getTreeStartLocation();
ParseTree left = parseAdditiveExpression();
while (peekShiftOperator()) {
Token operator = nextToken();
ParseTree right = parseAdditiveExpression();
left = new BinaryOperatorTree(getTreeLocation(start), left, operator, right);
}
return left;
} | [
"private",
"ParseTree",
"parseShiftExpression",
"(",
")",
"{",
"SourcePosition",
"start",
"=",
"getTreeStartLocation",
"(",
")",
";",
"ParseTree",
"left",
"=",
"parseAdditiveExpression",
"(",
")",
";",
"while",
"(",
"peekShiftOperator",
"(",
")",
")",
"{",
"Token",
"operator",
"=",
"nextToken",
"(",
")",
";",
"ParseTree",
"right",
"=",
"parseAdditiveExpression",
"(",
")",
";",
"left",
"=",
"new",
"BinaryOperatorTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"left",
",",
"operator",
",",
"right",
")",
";",
"}",
"return",
"left",
";",
"}"
] | 11.7 Shift Expression | [
"11",
".",
"7",
"Shift",
"Expression"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L3347-L3356 |
24,866 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseAdditiveExpression | private ParseTree parseAdditiveExpression() {
SourcePosition start = getTreeStartLocation();
ParseTree left = parseMultiplicativeExpression();
while (peekAdditiveOperator()) {
Token operator = nextToken();
ParseTree right = parseMultiplicativeExpression();
left = new BinaryOperatorTree(getTreeLocation(start), left, operator, right);
}
return left;
} | java | private ParseTree parseAdditiveExpression() {
SourcePosition start = getTreeStartLocation();
ParseTree left = parseMultiplicativeExpression();
while (peekAdditiveOperator()) {
Token operator = nextToken();
ParseTree right = parseMultiplicativeExpression();
left = new BinaryOperatorTree(getTreeLocation(start), left, operator, right);
}
return left;
} | [
"private",
"ParseTree",
"parseAdditiveExpression",
"(",
")",
"{",
"SourcePosition",
"start",
"=",
"getTreeStartLocation",
"(",
")",
";",
"ParseTree",
"left",
"=",
"parseMultiplicativeExpression",
"(",
")",
";",
"while",
"(",
"peekAdditiveOperator",
"(",
")",
")",
"{",
"Token",
"operator",
"=",
"nextToken",
"(",
")",
";",
"ParseTree",
"right",
"=",
"parseMultiplicativeExpression",
"(",
")",
";",
"left",
"=",
"new",
"BinaryOperatorTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"left",
",",
"operator",
",",
"right",
")",
";",
"}",
"return",
"left",
";",
"}"
] | 11.6 Additive Expression | [
"11",
".",
"6",
"Additive",
"Expression"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L3370-L3379 |
24,867 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseMultiplicativeExpression | private ParseTree parseMultiplicativeExpression() {
SourcePosition start = getTreeStartLocation();
ParseTree left = parseExponentiationExpression();
while (peekMultiplicativeOperator()) {
Token operator = nextToken();
ParseTree right = parseExponentiationExpression();
left = new BinaryOperatorTree(getTreeLocation(start), left, operator, right);
}
return left;
} | java | private ParseTree parseMultiplicativeExpression() {
SourcePosition start = getTreeStartLocation();
ParseTree left = parseExponentiationExpression();
while (peekMultiplicativeOperator()) {
Token operator = nextToken();
ParseTree right = parseExponentiationExpression();
left = new BinaryOperatorTree(getTreeLocation(start), left, operator, right);
}
return left;
} | [
"private",
"ParseTree",
"parseMultiplicativeExpression",
"(",
")",
"{",
"SourcePosition",
"start",
"=",
"getTreeStartLocation",
"(",
")",
";",
"ParseTree",
"left",
"=",
"parseExponentiationExpression",
"(",
")",
";",
"while",
"(",
"peekMultiplicativeOperator",
"(",
")",
")",
"{",
"Token",
"operator",
"=",
"nextToken",
"(",
")",
";",
"ParseTree",
"right",
"=",
"parseExponentiationExpression",
"(",
")",
";",
"left",
"=",
"new",
"BinaryOperatorTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"left",
",",
"operator",
",",
"right",
")",
";",
"}",
"return",
"left",
";",
"}"
] | 11.5 Multiplicative Expression | [
"11",
".",
"5",
"Multiplicative",
"Expression"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L3392-L3401 |
24,868 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseUnaryExpression | private ParseTree parseUnaryExpression() {
SourcePosition start = getTreeStartLocation();
if (peekUnaryOperator()) {
Token operator = nextToken();
ParseTree operand = parseUnaryExpression();
return new UnaryExpressionTree(getTreeLocation(start), operator, operand);
} else if (peekAwaitExpression()) {
return parseAwaitExpression();
} else {
return parseUpdateExpression();
}
} | java | private ParseTree parseUnaryExpression() {
SourcePosition start = getTreeStartLocation();
if (peekUnaryOperator()) {
Token operator = nextToken();
ParseTree operand = parseUnaryExpression();
return new UnaryExpressionTree(getTreeLocation(start), operator, operand);
} else if (peekAwaitExpression()) {
return parseAwaitExpression();
} else {
return parseUpdateExpression();
}
} | [
"private",
"ParseTree",
"parseUnaryExpression",
"(",
")",
"{",
"SourcePosition",
"start",
"=",
"getTreeStartLocation",
"(",
")",
";",
"if",
"(",
"peekUnaryOperator",
"(",
")",
")",
"{",
"Token",
"operator",
"=",
"nextToken",
"(",
")",
";",
"ParseTree",
"operand",
"=",
"parseUnaryExpression",
"(",
")",
";",
"return",
"new",
"UnaryExpressionTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"operator",
",",
"operand",
")",
";",
"}",
"else",
"if",
"(",
"peekAwaitExpression",
"(",
")",
")",
"{",
"return",
"parseAwaitExpression",
"(",
")",
";",
"}",
"else",
"{",
"return",
"parseUpdateExpression",
"(",
")",
";",
"}",
"}"
] | 11.4 Unary Operator | [
"11",
".",
"4",
"Unary",
"Operator"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L3437-L3448 |
24,869 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseLeftHandSideExpression | @SuppressWarnings("incomplete-switch")
private ParseTree parseLeftHandSideExpression() {
SourcePosition start = getTreeStartLocation();
ParseTree operand = parseNewExpression();
// this test is equivalent to is member expression
if (!(operand instanceof NewExpressionTree)
|| ((NewExpressionTree) operand).arguments != null) {
// The Call expression productions
while (peekCallSuffix()) {
switch (peekType()) {
case OPEN_PAREN:
ArgumentListTree arguments = parseArguments();
operand = new CallExpressionTree(getTreeLocation(start), operand, arguments);
break;
case OPEN_SQUARE:
eat(TokenType.OPEN_SQUARE);
ParseTree member = parseExpression();
eat(TokenType.CLOSE_SQUARE);
operand = new MemberLookupExpressionTree(getTreeLocation(start), operand, member);
break;
case PERIOD:
eat(TokenType.PERIOD);
IdentifierToken id = eatIdOrKeywordAsId();
operand = new MemberExpressionTree(getTreeLocation(start), operand, id);
break;
case NO_SUBSTITUTION_TEMPLATE:
case TEMPLATE_HEAD:
operand = parseTemplateLiteral(operand);
break;
default:
throw new AssertionError("unexpected case: " + peekType());
}
}
}
return operand;
} | java | @SuppressWarnings("incomplete-switch")
private ParseTree parseLeftHandSideExpression() {
SourcePosition start = getTreeStartLocation();
ParseTree operand = parseNewExpression();
// this test is equivalent to is member expression
if (!(operand instanceof NewExpressionTree)
|| ((NewExpressionTree) operand).arguments != null) {
// The Call expression productions
while (peekCallSuffix()) {
switch (peekType()) {
case OPEN_PAREN:
ArgumentListTree arguments = parseArguments();
operand = new CallExpressionTree(getTreeLocation(start), operand, arguments);
break;
case OPEN_SQUARE:
eat(TokenType.OPEN_SQUARE);
ParseTree member = parseExpression();
eat(TokenType.CLOSE_SQUARE);
operand = new MemberLookupExpressionTree(getTreeLocation(start), operand, member);
break;
case PERIOD:
eat(TokenType.PERIOD);
IdentifierToken id = eatIdOrKeywordAsId();
operand = new MemberExpressionTree(getTreeLocation(start), operand, id);
break;
case NO_SUBSTITUTION_TEMPLATE:
case TEMPLATE_HEAD:
operand = parseTemplateLiteral(operand);
break;
default:
throw new AssertionError("unexpected case: " + peekType());
}
}
}
return operand;
} | [
"@",
"SuppressWarnings",
"(",
"\"incomplete-switch\"",
")",
"private",
"ParseTree",
"parseLeftHandSideExpression",
"(",
")",
"{",
"SourcePosition",
"start",
"=",
"getTreeStartLocation",
"(",
")",
";",
"ParseTree",
"operand",
"=",
"parseNewExpression",
"(",
")",
";",
"// this test is equivalent to is member expression",
"if",
"(",
"!",
"(",
"operand",
"instanceof",
"NewExpressionTree",
")",
"||",
"(",
"(",
"NewExpressionTree",
")",
"operand",
")",
".",
"arguments",
"!=",
"null",
")",
"{",
"// The Call expression productions",
"while",
"(",
"peekCallSuffix",
"(",
")",
")",
"{",
"switch",
"(",
"peekType",
"(",
")",
")",
"{",
"case",
"OPEN_PAREN",
":",
"ArgumentListTree",
"arguments",
"=",
"parseArguments",
"(",
")",
";",
"operand",
"=",
"new",
"CallExpressionTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"operand",
",",
"arguments",
")",
";",
"break",
";",
"case",
"OPEN_SQUARE",
":",
"eat",
"(",
"TokenType",
".",
"OPEN_SQUARE",
")",
";",
"ParseTree",
"member",
"=",
"parseExpression",
"(",
")",
";",
"eat",
"(",
"TokenType",
".",
"CLOSE_SQUARE",
")",
";",
"operand",
"=",
"new",
"MemberLookupExpressionTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"operand",
",",
"member",
")",
";",
"break",
";",
"case",
"PERIOD",
":",
"eat",
"(",
"TokenType",
".",
"PERIOD",
")",
";",
"IdentifierToken",
"id",
"=",
"eatIdOrKeywordAsId",
"(",
")",
";",
"operand",
"=",
"new",
"MemberExpressionTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"operand",
",",
"id",
")",
";",
"break",
";",
"case",
"NO_SUBSTITUTION_TEMPLATE",
":",
"case",
"TEMPLATE_HEAD",
":",
"operand",
"=",
"parseTemplateLiteral",
"(",
"operand",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"AssertionError",
"(",
"\"unexpected case: \"",
"+",
"peekType",
"(",
")",
")",
";",
"}",
"}",
"}",
"return",
"operand",
";",
"}"
] | Also inlines the call expression productions | [
"Also",
"inlines",
"the",
"call",
"expression",
"productions"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L3516-L3553 |
24,870 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parseMemberExpressionNoNew | private ParseTree parseMemberExpressionNoNew() {
SourcePosition start = getTreeStartLocation();
ParseTree operand;
if (peekAsyncFunctionStart()) {
operand = parseAsyncFunctionExpression();
} else if (peekFunction()) {
operand = parseFunctionExpression();
} else {
operand = parsePrimaryExpression();
}
while (peekMemberExpressionSuffix()) {
switch (peekType()) {
case OPEN_SQUARE:
eat(TokenType.OPEN_SQUARE);
ParseTree member = parseExpression();
eat(TokenType.CLOSE_SQUARE);
operand = new MemberLookupExpressionTree(
getTreeLocation(start), operand, member);
break;
case PERIOD:
eat(TokenType.PERIOD);
IdentifierToken id = eatIdOrKeywordAsId();
operand = new MemberExpressionTree(getTreeLocation(start), operand, id);
break;
case NO_SUBSTITUTION_TEMPLATE:
case TEMPLATE_HEAD:
operand = parseTemplateLiteral(operand);
break;
default:
throw new RuntimeException("unreachable");
}
}
return operand;
} | java | private ParseTree parseMemberExpressionNoNew() {
SourcePosition start = getTreeStartLocation();
ParseTree operand;
if (peekAsyncFunctionStart()) {
operand = parseAsyncFunctionExpression();
} else if (peekFunction()) {
operand = parseFunctionExpression();
} else {
operand = parsePrimaryExpression();
}
while (peekMemberExpressionSuffix()) {
switch (peekType()) {
case OPEN_SQUARE:
eat(TokenType.OPEN_SQUARE);
ParseTree member = parseExpression();
eat(TokenType.CLOSE_SQUARE);
operand = new MemberLookupExpressionTree(
getTreeLocation(start), operand, member);
break;
case PERIOD:
eat(TokenType.PERIOD);
IdentifierToken id = eatIdOrKeywordAsId();
operand = new MemberExpressionTree(getTreeLocation(start), operand, id);
break;
case NO_SUBSTITUTION_TEMPLATE:
case TEMPLATE_HEAD:
operand = parseTemplateLiteral(operand);
break;
default:
throw new RuntimeException("unreachable");
}
}
return operand;
} | [
"private",
"ParseTree",
"parseMemberExpressionNoNew",
"(",
")",
"{",
"SourcePosition",
"start",
"=",
"getTreeStartLocation",
"(",
")",
";",
"ParseTree",
"operand",
";",
"if",
"(",
"peekAsyncFunctionStart",
"(",
")",
")",
"{",
"operand",
"=",
"parseAsyncFunctionExpression",
"(",
")",
";",
"}",
"else",
"if",
"(",
"peekFunction",
"(",
")",
")",
"{",
"operand",
"=",
"parseFunctionExpression",
"(",
")",
";",
"}",
"else",
"{",
"operand",
"=",
"parsePrimaryExpression",
"(",
")",
";",
"}",
"while",
"(",
"peekMemberExpressionSuffix",
"(",
")",
")",
"{",
"switch",
"(",
"peekType",
"(",
")",
")",
"{",
"case",
"OPEN_SQUARE",
":",
"eat",
"(",
"TokenType",
".",
"OPEN_SQUARE",
")",
";",
"ParseTree",
"member",
"=",
"parseExpression",
"(",
")",
";",
"eat",
"(",
"TokenType",
".",
"CLOSE_SQUARE",
")",
";",
"operand",
"=",
"new",
"MemberLookupExpressionTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"operand",
",",
"member",
")",
";",
"break",
";",
"case",
"PERIOD",
":",
"eat",
"(",
"TokenType",
".",
"PERIOD",
")",
";",
"IdentifierToken",
"id",
"=",
"eatIdOrKeywordAsId",
"(",
")",
";",
"operand",
"=",
"new",
"MemberExpressionTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"operand",
",",
"id",
")",
";",
"break",
";",
"case",
"NO_SUBSTITUTION_TEMPLATE",
":",
"case",
"TEMPLATE_HEAD",
":",
"operand",
"=",
"parseTemplateLiteral",
"(",
"operand",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"RuntimeException",
"(",
"\"unreachable\"",
")",
";",
"}",
"}",
"return",
"operand",
";",
"}"
] | 11.2 Member Expression without the new production | [
"11",
".",
"2",
"Member",
"Expression",
"without",
"the",
"new",
"production"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L3566-L3599 |
24,871 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.parsePatternAssignmentTarget | private ParseTree parsePatternAssignmentTarget(PatternKind patternKind) {
SourcePosition start = getTreeStartLocation();
ParseTree assignmentTarget;
assignmentTarget = parsePatternAssignmentTargetNoDefault(patternKind);
if (peek(TokenType.EQUAL)) {
eat(TokenType.EQUAL);
ParseTree defaultValue = parseAssignmentExpression();
assignmentTarget =
new DefaultParameterTree(getTreeLocation(start), assignmentTarget, defaultValue);
}
return assignmentTarget;
} | java | private ParseTree parsePatternAssignmentTarget(PatternKind patternKind) {
SourcePosition start = getTreeStartLocation();
ParseTree assignmentTarget;
assignmentTarget = parsePatternAssignmentTargetNoDefault(patternKind);
if (peek(TokenType.EQUAL)) {
eat(TokenType.EQUAL);
ParseTree defaultValue = parseAssignmentExpression();
assignmentTarget =
new DefaultParameterTree(getTreeLocation(start), assignmentTarget, defaultValue);
}
return assignmentTarget;
} | [
"private",
"ParseTree",
"parsePatternAssignmentTarget",
"(",
"PatternKind",
"patternKind",
")",
"{",
"SourcePosition",
"start",
"=",
"getTreeStartLocation",
"(",
")",
";",
"ParseTree",
"assignmentTarget",
";",
"assignmentTarget",
"=",
"parsePatternAssignmentTargetNoDefault",
"(",
"patternKind",
")",
";",
"if",
"(",
"peek",
"(",
"TokenType",
".",
"EQUAL",
")",
")",
"{",
"eat",
"(",
"TokenType",
".",
"EQUAL",
")",
";",
"ParseTree",
"defaultValue",
"=",
"parseAssignmentExpression",
"(",
")",
";",
"assignmentTarget",
"=",
"new",
"DefaultParameterTree",
"(",
"getTreeLocation",
"(",
"start",
")",
",",
"assignmentTarget",
",",
"defaultValue",
")",
";",
"}",
"return",
"assignmentTarget",
";",
"}"
] | A PatternAssignmentTarget is the location where the assigned value gets stored, including an
optional default value.
<dl>
<dt> Spec AssignmentElement === PatternAssignmentTarget(PatternKind.ANY)
<dd> Valid in an assignment that is not a formal parameter list or variable declaration.
Sub-patterns and arbitrary left hand side expressions are allowed.
<dt> Spec BindingElement === PatternAssignmentElement(PatternKind.INITIALIZER)
<dd> Valid in a formal parameter list or variable declaration statement.
Only sub-patterns and identifiers are allowed.
</dl>
Examples:
<pre>
<code>
[a, {foo: b = 'default'}] = someArray; // valid
[x.a, {foo: x.b = 'default'}] = someArray; // valid
let [a, {foo: b = 'default'}] = someArray; // valid
let [x.a, {foo: x.b = 'default'}] = someArray; // invalid
function f([a, {foo: b = 'default'}]) {...} // valid
function f([x.a, {foo: x.b = 'default'}]) {...} // invalid
</code>
</pre> | [
"A",
"PatternAssignmentTarget",
"is",
"the",
"location",
"where",
"the",
"assigned",
"value",
"gets",
"stored",
"including",
"an",
"optional",
"default",
"value",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L3850-L3862 |
24,872 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.eatId | private IdentifierToken eatId() {
if (peekId()) {
return eatIdOrKeywordAsId();
} else {
reportExpectedError(peekToken(), TokenType.IDENTIFIER);
if (peekIdOrKeyword()) {
return eatIdOrKeywordAsId();
} else {
return null;
}
}
} | java | private IdentifierToken eatId() {
if (peekId()) {
return eatIdOrKeywordAsId();
} else {
reportExpectedError(peekToken(), TokenType.IDENTIFIER);
if (peekIdOrKeyword()) {
return eatIdOrKeywordAsId();
} else {
return null;
}
}
} | [
"private",
"IdentifierToken",
"eatId",
"(",
")",
"{",
"if",
"(",
"peekId",
"(",
")",
")",
"{",
"return",
"eatIdOrKeywordAsId",
"(",
")",
";",
"}",
"else",
"{",
"reportExpectedError",
"(",
"peekToken",
"(",
")",
",",
"TokenType",
".",
"IDENTIFIER",
")",
";",
"if",
"(",
"peekIdOrKeyword",
"(",
")",
")",
"{",
"return",
"eatIdOrKeywordAsId",
"(",
")",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}",
"}"
] | Consumes an identifier token that is not a reserved word.
@see "http://www.ecma-international.org/ecma-262/5.1/#sec-7.6" | [
"Consumes",
"an",
"identifier",
"token",
"that",
"is",
"not",
"a",
"reserved",
"word",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L4042-L4053 |
24,873 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.eatIdOrKeywordAsId | private IdentifierToken eatIdOrKeywordAsId() {
Token token = nextToken();
if (token.type == TokenType.IDENTIFIER) {
return (IdentifierToken) token;
} else if (Keywords.isKeyword(token.type)) {
return new IdentifierToken(
token.location, Keywords.get(token.type).toString());
} else {
reportExpectedError(token, TokenType.IDENTIFIER);
}
return null;
} | java | private IdentifierToken eatIdOrKeywordAsId() {
Token token = nextToken();
if (token.type == TokenType.IDENTIFIER) {
return (IdentifierToken) token;
} else if (Keywords.isKeyword(token.type)) {
return new IdentifierToken(
token.location, Keywords.get(token.type).toString());
} else {
reportExpectedError(token, TokenType.IDENTIFIER);
}
return null;
} | [
"private",
"IdentifierToken",
"eatIdOrKeywordAsId",
"(",
")",
"{",
"Token",
"token",
"=",
"nextToken",
"(",
")",
";",
"if",
"(",
"token",
".",
"type",
"==",
"TokenType",
".",
"IDENTIFIER",
")",
"{",
"return",
"(",
"IdentifierToken",
")",
"token",
";",
"}",
"else",
"if",
"(",
"Keywords",
".",
"isKeyword",
"(",
"token",
".",
"type",
")",
")",
"{",
"return",
"new",
"IdentifierToken",
"(",
"token",
".",
"location",
",",
"Keywords",
".",
"get",
"(",
"token",
".",
"type",
")",
".",
"toString",
"(",
")",
")",
";",
"}",
"else",
"{",
"reportExpectedError",
"(",
"token",
",",
"TokenType",
".",
"IDENTIFIER",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Consumes an identifier token that may be a reserved word, i.e.
an IdentifierName, not necessarily an Identifier.
@see "http://www.ecma-international.org/ecma-262/5.1/#sec-7.6" | [
"Consumes",
"an",
"identifier",
"token",
"that",
"may",
"be",
"a",
"reserved",
"word",
"i",
".",
"e",
".",
"an",
"IdentifierName",
"not",
"necessarily",
"an",
"Identifier",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L4072-L4083 |
24,874 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.eat | private Token eat(TokenType expectedTokenType) {
Token token = nextToken();
if (token.type != expectedTokenType) {
reportExpectedError(token, expectedTokenType);
return null;
}
return token;
} | java | private Token eat(TokenType expectedTokenType) {
Token token = nextToken();
if (token.type != expectedTokenType) {
reportExpectedError(token, expectedTokenType);
return null;
}
return token;
} | [
"private",
"Token",
"eat",
"(",
"TokenType",
"expectedTokenType",
")",
"{",
"Token",
"token",
"=",
"nextToken",
"(",
")",
";",
"if",
"(",
"token",
".",
"type",
"!=",
"expectedTokenType",
")",
"{",
"reportExpectedError",
"(",
"token",
",",
"expectedTokenType",
")",
";",
"return",
"null",
";",
"}",
"return",
"token",
";",
"}"
] | Consumes the next token. If the consumed token is not of the expected type then
report an error and return null. Otherwise return the consumed token.
@param expectedTokenType
@return The consumed token, or null if the next token is not of the expected type. | [
"Consumes",
"the",
"next",
"token",
".",
"If",
"the",
"consumed",
"token",
"is",
"not",
"of",
"the",
"expected",
"type",
"then",
"report",
"an",
"error",
"and",
"return",
"null",
".",
"Otherwise",
"return",
"the",
"consumed",
"token",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L4092-L4099 |
24,875 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.nextToken | private Token nextToken() {
Token token = scanner.nextToken();
lastSourcePosition = token.location.end;
return token;
} | java | private Token nextToken() {
Token token = scanner.nextToken();
lastSourcePosition = token.location.end;
return token;
} | [
"private",
"Token",
"nextToken",
"(",
")",
"{",
"Token",
"token",
"=",
"scanner",
".",
"nextToken",
"(",
")",
";",
"lastSourcePosition",
"=",
"token",
".",
"location",
".",
"end",
";",
"return",
"token",
";",
"}"
] | Consumes the next token and returns it. Will return a never ending stream of
TokenType.END_OF_FILE at the end of the file so callers don't have to check for EOF
explicitly.
<p>Tokenizing is contextual. nextToken() will never return a regular expression literal. | [
"Consumes",
"the",
"next",
"token",
"and",
"returns",
"it",
".",
"Will",
"return",
"a",
"never",
"ending",
"stream",
"of",
"TokenType",
".",
"END_OF_FILE",
"at",
"the",
"end",
"of",
"the",
"file",
"so",
"callers",
"don",
"t",
"have",
"to",
"check",
"for",
"EOF",
"explicitly",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L4139-L4143 |
24,876 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.nextRegularExpressionLiteralToken | private LiteralToken nextRegularExpressionLiteralToken() {
LiteralToken token = scanner.nextRegularExpressionLiteralToken();
lastSourcePosition = token.location.end;
return token;
} | java | private LiteralToken nextRegularExpressionLiteralToken() {
LiteralToken token = scanner.nextRegularExpressionLiteralToken();
lastSourcePosition = token.location.end;
return token;
} | [
"private",
"LiteralToken",
"nextRegularExpressionLiteralToken",
"(",
")",
"{",
"LiteralToken",
"token",
"=",
"scanner",
".",
"nextRegularExpressionLiteralToken",
"(",
")",
";",
"lastSourcePosition",
"=",
"token",
".",
"location",
".",
"end",
";",
"return",
"token",
";",
"}"
] | Consumes a regular expression literal token and returns it. | [
"Consumes",
"a",
"regular",
"expression",
"literal",
"token",
"and",
"returns",
"it",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L4148-L4152 |
24,877 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.nextTemplateLiteralToken | private TemplateLiteralToken nextTemplateLiteralToken() {
TemplateLiteralToken token = scanner.nextTemplateLiteralToken();
lastSourcePosition = token.location.end;
return token;
} | java | private TemplateLiteralToken nextTemplateLiteralToken() {
TemplateLiteralToken token = scanner.nextTemplateLiteralToken();
lastSourcePosition = token.location.end;
return token;
} | [
"private",
"TemplateLiteralToken",
"nextTemplateLiteralToken",
"(",
")",
"{",
"TemplateLiteralToken",
"token",
"=",
"scanner",
".",
"nextTemplateLiteralToken",
"(",
")",
";",
"lastSourcePosition",
"=",
"token",
".",
"location",
".",
"end",
";",
"return",
"token",
";",
"}"
] | Consumes a template literal token and returns it. | [
"Consumes",
"a",
"template",
"literal",
"token",
"and",
"returns",
"it",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L4155-L4159 |
24,878 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Parser.java | Parser.createLookaheadParser | @Deprecated
private Parser createLookaheadParser() {
return new Parser(
config,
new LookaheadErrorReporter(),
this.scanner.getFile(),
this.scanner.getOffset(),
inGeneratorContext());
} | java | @Deprecated
private Parser createLookaheadParser() {
return new Parser(
config,
new LookaheadErrorReporter(),
this.scanner.getFile(),
this.scanner.getOffset(),
inGeneratorContext());
} | [
"@",
"Deprecated",
"private",
"Parser",
"createLookaheadParser",
"(",
")",
"{",
"return",
"new",
"Parser",
"(",
"config",
",",
"new",
"LookaheadErrorReporter",
"(",
")",
",",
"this",
".",
"scanner",
".",
"getFile",
"(",
")",
",",
"this",
".",
"scanner",
".",
"getOffset",
"(",
")",
",",
"inGeneratorContext",
"(",
")",
")",
";",
"}"
] | Forks the parser at the current point and returns a new
parser for speculative parsing.
@deprecated Creating a lookahead parser often leads to exponential parse times
(see issues #1049, #1115, and #1148 on github) so avoid using this if possible. | [
"Forks",
"the",
"parser",
"at",
"the",
"current",
"point",
"and",
"returns",
"a",
"new",
"parser",
"for",
"speculative",
"parsing",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Parser.java#L4211-L4219 |
24,879 | google/closure-compiler | src/com/google/javascript/jscomp/type/SemanticReverseAbstractInterpreter.java | SemanticReverseAbstractInterpreter.maybeRestrictName | @CheckReturnValue
private FlowScope maybeRestrictName(
FlowScope blindScope, Node node, JSType originalType, JSType restrictedType) {
if (restrictedType != null && restrictedType != originalType) {
return declareNameInScope(blindScope, node, restrictedType);
}
return blindScope;
} | java | @CheckReturnValue
private FlowScope maybeRestrictName(
FlowScope blindScope, Node node, JSType originalType, JSType restrictedType) {
if (restrictedType != null && restrictedType != originalType) {
return declareNameInScope(blindScope, node, restrictedType);
}
return blindScope;
} | [
"@",
"CheckReturnValue",
"private",
"FlowScope",
"maybeRestrictName",
"(",
"FlowScope",
"blindScope",
",",
"Node",
"node",
",",
"JSType",
"originalType",
",",
"JSType",
"restrictedType",
")",
"{",
"if",
"(",
"restrictedType",
"!=",
"null",
"&&",
"restrictedType",
"!=",
"originalType",
")",
"{",
"return",
"declareNameInScope",
"(",
"blindScope",
",",
"node",
",",
"restrictedType",
")",
";",
"}",
"return",
"blindScope",
";",
"}"
] | If the restrictedType differs from the originalType, then we should branch the current flow
scope and create a new flow scope with the name declared with the new type.
<p>We try not to create spurious child flow scopes as this makes type inference slower.
<p>We also do not want spurious slots around in type inference, because we use these as a
signal for "checked unknown" types. A "checked unknown" type is a symbol that the programmer
has already checked and verified that it's defined, even if we don't know what it is.
<p>It is OK to pass non-name nodes into this method, as long as you pass in {@code null} for a
restricted type. | [
"If",
"the",
"restrictedType",
"differs",
"from",
"the",
"originalType",
"then",
"we",
"should",
"branch",
"the",
"current",
"flow",
"scope",
"and",
"create",
"a",
"new",
"flow",
"scope",
"with",
"the",
"name",
"declared",
"with",
"the",
"new",
"type",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/type/SemanticReverseAbstractInterpreter.java#L401-L408 |
24,880 | google/closure-compiler | src/com/google/javascript/jscomp/type/SemanticReverseAbstractInterpreter.java | SemanticReverseAbstractInterpreter.caseIn | @CheckReturnValue
private FlowScope caseIn(Node object, String propertyName, FlowScope blindScope) {
JSType jsType = object.getJSType();
jsType = this.getRestrictedWithoutNull(jsType);
jsType = this.getRestrictedWithoutUndefined(jsType);
boolean hasProperty = false;
ObjectType objectType = ObjectType.cast(jsType);
if (objectType != null) {
hasProperty = objectType.hasProperty(propertyName);
}
if (!hasProperty) {
String qualifiedName = object.getQualifiedName();
if (qualifiedName != null) {
String propertyQualifiedName = qualifiedName + "." + propertyName;
if (blindScope.getSlot(propertyQualifiedName) == null) {
JSType unknownType = typeRegistry.getNativeType(JSTypeNative.UNKNOWN_TYPE);
return blindScope.inferQualifiedSlot(
object, propertyQualifiedName, unknownType, unknownType, false);
}
}
}
return blindScope;
} | java | @CheckReturnValue
private FlowScope caseIn(Node object, String propertyName, FlowScope blindScope) {
JSType jsType = object.getJSType();
jsType = this.getRestrictedWithoutNull(jsType);
jsType = this.getRestrictedWithoutUndefined(jsType);
boolean hasProperty = false;
ObjectType objectType = ObjectType.cast(jsType);
if (objectType != null) {
hasProperty = objectType.hasProperty(propertyName);
}
if (!hasProperty) {
String qualifiedName = object.getQualifiedName();
if (qualifiedName != null) {
String propertyQualifiedName = qualifiedName + "." + propertyName;
if (blindScope.getSlot(propertyQualifiedName) == null) {
JSType unknownType = typeRegistry.getNativeType(JSTypeNative.UNKNOWN_TYPE);
return blindScope.inferQualifiedSlot(
object, propertyQualifiedName, unknownType, unknownType, false);
}
}
}
return blindScope;
} | [
"@",
"CheckReturnValue",
"private",
"FlowScope",
"caseIn",
"(",
"Node",
"object",
",",
"String",
"propertyName",
",",
"FlowScope",
"blindScope",
")",
"{",
"JSType",
"jsType",
"=",
"object",
".",
"getJSType",
"(",
")",
";",
"jsType",
"=",
"this",
".",
"getRestrictedWithoutNull",
"(",
"jsType",
")",
";",
"jsType",
"=",
"this",
".",
"getRestrictedWithoutUndefined",
"(",
"jsType",
")",
";",
"boolean",
"hasProperty",
"=",
"false",
";",
"ObjectType",
"objectType",
"=",
"ObjectType",
".",
"cast",
"(",
"jsType",
")",
";",
"if",
"(",
"objectType",
"!=",
"null",
")",
"{",
"hasProperty",
"=",
"objectType",
".",
"hasProperty",
"(",
"propertyName",
")",
";",
"}",
"if",
"(",
"!",
"hasProperty",
")",
"{",
"String",
"qualifiedName",
"=",
"object",
".",
"getQualifiedName",
"(",
")",
";",
"if",
"(",
"qualifiedName",
"!=",
"null",
")",
"{",
"String",
"propertyQualifiedName",
"=",
"qualifiedName",
"+",
"\".\"",
"+",
"propertyName",
";",
"if",
"(",
"blindScope",
".",
"getSlot",
"(",
"propertyQualifiedName",
")",
"==",
"null",
")",
"{",
"JSType",
"unknownType",
"=",
"typeRegistry",
".",
"getNativeType",
"(",
"JSTypeNative",
".",
"UNKNOWN_TYPE",
")",
";",
"return",
"blindScope",
".",
"inferQualifiedSlot",
"(",
"object",
",",
"propertyQualifiedName",
",",
"unknownType",
",",
"unknownType",
",",
"false",
")",
";",
"}",
"}",
"}",
"return",
"blindScope",
";",
"}"
] | Given 'property in object', ensures that the object has the property in the informed scope by
defining it as a qualified name if the object type lacks the property and it's not in the blind
scope.
@param object The node of the right-side of the in.
@param propertyName The string of the left-side of the in. | [
"Given",
"property",
"in",
"object",
"ensures",
"that",
"the",
"object",
"has",
"the",
"property",
"in",
"the",
"informed",
"scope",
"by",
"defining",
"it",
"as",
"a",
"qualified",
"name",
"if",
"the",
"object",
"type",
"lacks",
"the",
"property",
"and",
"it",
"s",
"not",
"in",
"the",
"blind",
"scope",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/type/SemanticReverseAbstractInterpreter.java#L486-L509 |
24,881 | google/closure-compiler | src/com/google/javascript/jscomp/type/SemanticReverseAbstractInterpreter.java | SemanticReverseAbstractInterpreter.unwrap | private static FlowScope unwrap(FlowScope scope) {
while (scope instanceof RefinementTrackingFlowScope) {
scope = ((RefinementTrackingFlowScope) scope).delegate;
}
return scope;
} | java | private static FlowScope unwrap(FlowScope scope) {
while (scope instanceof RefinementTrackingFlowScope) {
scope = ((RefinementTrackingFlowScope) scope).delegate;
}
return scope;
} | [
"private",
"static",
"FlowScope",
"unwrap",
"(",
"FlowScope",
"scope",
")",
"{",
"while",
"(",
"scope",
"instanceof",
"RefinementTrackingFlowScope",
")",
"{",
"scope",
"=",
"(",
"(",
"RefinementTrackingFlowScope",
")",
"scope",
")",
".",
"delegate",
";",
"}",
"return",
"scope",
";",
"}"
] | Unwraps any RefinementTrackingFlowScopes. | [
"Unwraps",
"any",
"RefinementTrackingFlowScopes",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/type/SemanticReverseAbstractInterpreter.java#L612-L617 |
24,882 | google/closure-compiler | src/com/google/javascript/jscomp/FunctionRewriter.java | FunctionRewriter.parseHelperCode | public Node parseHelperCode(Reducer reducer) {
Node root =
compiler.parseSyntheticCode(reducer.getClass() + ":helper", reducer.getHelperSource());
return (root != null) ? root.removeFirstChild() : null;
} | java | public Node parseHelperCode(Reducer reducer) {
Node root =
compiler.parseSyntheticCode(reducer.getClass() + ":helper", reducer.getHelperSource());
return (root != null) ? root.removeFirstChild() : null;
} | [
"public",
"Node",
"parseHelperCode",
"(",
"Reducer",
"reducer",
")",
"{",
"Node",
"root",
"=",
"compiler",
".",
"parseSyntheticCode",
"(",
"reducer",
".",
"getClass",
"(",
")",
"+",
"\":helper\"",
",",
"reducer",
".",
"getHelperSource",
"(",
")",
")",
";",
"return",
"(",
"root",
"!=",
"null",
")",
"?",
"root",
".",
"removeFirstChild",
"(",
")",
":",
"null",
";",
"}"
] | Parse helper code needed by a reducer.
@return Helper code root. If parse fails, return null. | [
"Parse",
"helper",
"code",
"needed",
"by",
"a",
"reducer",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/FunctionRewriter.java#L115-L119 |
24,883 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/Config.java | Config.buildAnnotations | private static ImmutableMap<String, Annotation> buildAnnotations(Iterable<String> whitelist) {
ImmutableMap.Builder<String, Annotation> annotationsBuilder = ImmutableMap.builder();
annotationsBuilder.putAll(Annotation.recognizedAnnotations);
for (String unrecognizedAnnotation : whitelist) {
if (!unrecognizedAnnotation.isEmpty()
&& !Annotation.recognizedAnnotations.containsKey(unrecognizedAnnotation)) {
annotationsBuilder.put(unrecognizedAnnotation, Annotation.NOT_IMPLEMENTED);
}
}
return annotationsBuilder.build();
} | java | private static ImmutableMap<String, Annotation> buildAnnotations(Iterable<String> whitelist) {
ImmutableMap.Builder<String, Annotation> annotationsBuilder = ImmutableMap.builder();
annotationsBuilder.putAll(Annotation.recognizedAnnotations);
for (String unrecognizedAnnotation : whitelist) {
if (!unrecognizedAnnotation.isEmpty()
&& !Annotation.recognizedAnnotations.containsKey(unrecognizedAnnotation)) {
annotationsBuilder.put(unrecognizedAnnotation, Annotation.NOT_IMPLEMENTED);
}
}
return annotationsBuilder.build();
} | [
"private",
"static",
"ImmutableMap",
"<",
"String",
",",
"Annotation",
">",
"buildAnnotations",
"(",
"Iterable",
"<",
"String",
">",
"whitelist",
")",
"{",
"ImmutableMap",
".",
"Builder",
"<",
"String",
",",
"Annotation",
">",
"annotationsBuilder",
"=",
"ImmutableMap",
".",
"builder",
"(",
")",
";",
"annotationsBuilder",
".",
"putAll",
"(",
"Annotation",
".",
"recognizedAnnotations",
")",
";",
"for",
"(",
"String",
"unrecognizedAnnotation",
":",
"whitelist",
")",
"{",
"if",
"(",
"!",
"unrecognizedAnnotation",
".",
"isEmpty",
"(",
")",
"&&",
"!",
"Annotation",
".",
"recognizedAnnotations",
".",
"containsKey",
"(",
"unrecognizedAnnotation",
")",
")",
"{",
"annotationsBuilder",
".",
"put",
"(",
"unrecognizedAnnotation",
",",
"Annotation",
".",
"NOT_IMPLEMENTED",
")",
";",
"}",
"}",
"return",
"annotationsBuilder",
".",
"build",
"(",
")",
";",
"}"
] | Create the annotation names from the user-specified annotation whitelist. | [
"Create",
"the",
"annotation",
"names",
"from",
"the",
"user",
"-",
"specified",
"annotation",
"whitelist",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/Config.java#L189-L199 |
24,884 | google/closure-compiler | src/com/google/javascript/jscomp/ReferenceCollectingCallback.java | ReferenceCollectingCallback.processScope | void processScope(Scope scope) {
boolean shouldAddToBlockStack = !scope.isHoistScope();
this.narrowScope = scope;
if (shouldAddToBlockStack) {
blockStack.add(new BasicBlock(null, scope.getRootNode()));
}
(new NodeTraversal(compiler, this, scopeCreator)).traverseAtScope(scope);
if (shouldAddToBlockStack) {
pop(blockStack);
}
this.narrowScope = null;
} | java | void processScope(Scope scope) {
boolean shouldAddToBlockStack = !scope.isHoistScope();
this.narrowScope = scope;
if (shouldAddToBlockStack) {
blockStack.add(new BasicBlock(null, scope.getRootNode()));
}
(new NodeTraversal(compiler, this, scopeCreator)).traverseAtScope(scope);
if (shouldAddToBlockStack) {
pop(blockStack);
}
this.narrowScope = null;
} | [
"void",
"processScope",
"(",
"Scope",
"scope",
")",
"{",
"boolean",
"shouldAddToBlockStack",
"=",
"!",
"scope",
".",
"isHoistScope",
"(",
")",
";",
"this",
".",
"narrowScope",
"=",
"scope",
";",
"if",
"(",
"shouldAddToBlockStack",
")",
"{",
"blockStack",
".",
"add",
"(",
"new",
"BasicBlock",
"(",
"null",
",",
"scope",
".",
"getRootNode",
"(",
")",
")",
")",
";",
"}",
"(",
"new",
"NodeTraversal",
"(",
"compiler",
",",
"this",
",",
"scopeCreator",
")",
")",
".",
"traverseAtScope",
"(",
"scope",
")",
";",
"if",
"(",
"shouldAddToBlockStack",
")",
"{",
"pop",
"(",
"blockStack",
")",
";",
"}",
"this",
".",
"narrowScope",
"=",
"null",
";",
"}"
] | Targets reference collection to a particular scope. | [
"Targets",
"reference",
"collection",
"to",
"a",
"particular",
"scope",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ReferenceCollectingCallback.java#L124-L135 |
24,885 | google/closure-compiler | src/com/google/javascript/jscomp/ReferenceCollectingCallback.java | ReferenceCollectingCallback.shouldTraverse | @Override
public boolean shouldTraverse(NodeTraversal nodeTraversal, Node n, Node parent) {
// We automatically traverse a hoisted function body when that function
// is first referenced, so that the reference lists are in the right order.
//
// TODO(nicksantos): Maybe generalize this to a continuation mechanism
// like in RemoveUnusedCode.
if (NodeUtil.isHoistedFunctionDeclaration(n)) {
Node nameNode = n.getFirstChild();
Var functionVar = nodeTraversal.getScope().getVar(nameNode.getString());
checkNotNull(functionVar);
if (finishedFunctionTraverse.contains(functionVar)) {
return false;
}
startedFunctionTraverse.add(functionVar);
}
// If node is a new basic block, put on basic block stack
if (isBlockBoundary(n, parent)) {
blockStack.add(new BasicBlock(peek(blockStack), n));
}
// Add the second x before the first one in "let [x] = x;". VariableReferenceCheck
// relies on reference order to give a warning.
if ((n.isDefaultValue() || n.isDestructuringLhs()) && n.hasTwoChildren()) {
Scope scope = nodeTraversal.getScope();
nodeTraversal.traverseInnerNode(n.getSecondChild(), n, scope);
nodeTraversal.traverseInnerNode(n.getFirstChild(), n, scope);
return false;
}
return true;
} | java | @Override
public boolean shouldTraverse(NodeTraversal nodeTraversal, Node n, Node parent) {
// We automatically traverse a hoisted function body when that function
// is first referenced, so that the reference lists are in the right order.
//
// TODO(nicksantos): Maybe generalize this to a continuation mechanism
// like in RemoveUnusedCode.
if (NodeUtil.isHoistedFunctionDeclaration(n)) {
Node nameNode = n.getFirstChild();
Var functionVar = nodeTraversal.getScope().getVar(nameNode.getString());
checkNotNull(functionVar);
if (finishedFunctionTraverse.contains(functionVar)) {
return false;
}
startedFunctionTraverse.add(functionVar);
}
// If node is a new basic block, put on basic block stack
if (isBlockBoundary(n, parent)) {
blockStack.add(new BasicBlock(peek(blockStack), n));
}
// Add the second x before the first one in "let [x] = x;". VariableReferenceCheck
// relies on reference order to give a warning.
if ((n.isDefaultValue() || n.isDestructuringLhs()) && n.hasTwoChildren()) {
Scope scope = nodeTraversal.getScope();
nodeTraversal.traverseInnerNode(n.getSecondChild(), n, scope);
nodeTraversal.traverseInnerNode(n.getFirstChild(), n, scope);
return false;
}
return true;
} | [
"@",
"Override",
"public",
"boolean",
"shouldTraverse",
"(",
"NodeTraversal",
"nodeTraversal",
",",
"Node",
"n",
",",
"Node",
"parent",
")",
"{",
"// We automatically traverse a hoisted function body when that function",
"// is first referenced, so that the reference lists are in the right order.",
"//",
"// TODO(nicksantos): Maybe generalize this to a continuation mechanism",
"// like in RemoveUnusedCode.",
"if",
"(",
"NodeUtil",
".",
"isHoistedFunctionDeclaration",
"(",
"n",
")",
")",
"{",
"Node",
"nameNode",
"=",
"n",
".",
"getFirstChild",
"(",
")",
";",
"Var",
"functionVar",
"=",
"nodeTraversal",
".",
"getScope",
"(",
")",
".",
"getVar",
"(",
"nameNode",
".",
"getString",
"(",
")",
")",
";",
"checkNotNull",
"(",
"functionVar",
")",
";",
"if",
"(",
"finishedFunctionTraverse",
".",
"contains",
"(",
"functionVar",
")",
")",
"{",
"return",
"false",
";",
"}",
"startedFunctionTraverse",
".",
"add",
"(",
"functionVar",
")",
";",
"}",
"// If node is a new basic block, put on basic block stack",
"if",
"(",
"isBlockBoundary",
"(",
"n",
",",
"parent",
")",
")",
"{",
"blockStack",
".",
"add",
"(",
"new",
"BasicBlock",
"(",
"peek",
"(",
"blockStack",
")",
",",
"n",
")",
")",
";",
"}",
"// Add the second x before the first one in \"let [x] = x;\". VariableReferenceCheck",
"// relies on reference order to give a warning.",
"if",
"(",
"(",
"n",
".",
"isDefaultValue",
"(",
")",
"||",
"n",
".",
"isDestructuringLhs",
"(",
")",
")",
"&&",
"n",
".",
"hasTwoChildren",
"(",
")",
")",
"{",
"Scope",
"scope",
"=",
"nodeTraversal",
".",
"getScope",
"(",
")",
";",
"nodeTraversal",
".",
"traverseInnerNode",
"(",
"n",
".",
"getSecondChild",
"(",
")",
",",
"n",
",",
"scope",
")",
";",
"nodeTraversal",
".",
"traverseInnerNode",
"(",
"n",
".",
"getFirstChild",
"(",
")",
",",
"n",
",",
"scope",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Updates block stack. | [
"Updates",
"block",
"stack",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ReferenceCollectingCallback.java#L270-L301 |
24,886 | google/closure-compiler | src/com/google/javascript/rhino/SourcePosition.java | SourcePosition.setPositionInformation | public void setPositionInformation(int startLineno, int startCharno,
int endLineno, int endCharno) {
if (startLineno > endLineno) {
throw new IllegalStateException(
"Recorded bad position information\n"
+ "start-line: " + startLineno + "\n"
+ "end-line: " + endLineno);
} else if (startLineno == endLineno && startCharno >= endCharno) {
throw new IllegalStateException(
"Recorded bad position information\n"
+ "line: " + startLineno + "\n"
+ "start-char: " + startCharno + "\n"
+ "end-char: " + endCharno);
}
this.startLineno = startLineno;
this.startCharno = startCharno;
this.endLineno = endLineno;
this.endCharno = endCharno;
} | java | public void setPositionInformation(int startLineno, int startCharno,
int endLineno, int endCharno) {
if (startLineno > endLineno) {
throw new IllegalStateException(
"Recorded bad position information\n"
+ "start-line: " + startLineno + "\n"
+ "end-line: " + endLineno);
} else if (startLineno == endLineno && startCharno >= endCharno) {
throw new IllegalStateException(
"Recorded bad position information\n"
+ "line: " + startLineno + "\n"
+ "start-char: " + startCharno + "\n"
+ "end-char: " + endCharno);
}
this.startLineno = startLineno;
this.startCharno = startCharno;
this.endLineno = endLineno;
this.endCharno = endCharno;
} | [
"public",
"void",
"setPositionInformation",
"(",
"int",
"startLineno",
",",
"int",
"startCharno",
",",
"int",
"endLineno",
",",
"int",
"endCharno",
")",
"{",
"if",
"(",
"startLineno",
">",
"endLineno",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Recorded bad position information\\n\"",
"+",
"\"start-line: \"",
"+",
"startLineno",
"+",
"\"\\n\"",
"+",
"\"end-line: \"",
"+",
"endLineno",
")",
";",
"}",
"else",
"if",
"(",
"startLineno",
"==",
"endLineno",
"&&",
"startCharno",
">=",
"endCharno",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Recorded bad position information\\n\"",
"+",
"\"line: \"",
"+",
"startLineno",
"+",
"\"\\n\"",
"+",
"\"start-char: \"",
"+",
"startCharno",
"+",
"\"\\n\"",
"+",
"\"end-char: \"",
"+",
"endCharno",
")",
";",
"}",
"this",
".",
"startLineno",
"=",
"startLineno",
";",
"this",
".",
"startCharno",
"=",
"startCharno",
";",
"this",
".",
"endLineno",
"=",
"endLineno",
";",
"this",
".",
"endCharno",
"=",
"endCharno",
";",
"}"
] | Sets the position information contained in this source position. | [
"Sets",
"the",
"position",
"information",
"contained",
"in",
"this",
"source",
"position",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/SourcePosition.java#L83-L102 |
24,887 | google/closure-compiler | src/com/google/javascript/jscomp/deps/PathUtil.java | PathUtil.removeExtraneousSlashes | static String removeExtraneousSlashes(String s) {
int lastNonSlash = NON_SLASH_MATCHER.lastIndexIn(s);
if (lastNonSlash != -1) {
s = s.substring(0, lastNonSlash + 1);
}
return SLASH_MATCHER.collapseFrom(s, '/');
} | java | static String removeExtraneousSlashes(String s) {
int lastNonSlash = NON_SLASH_MATCHER.lastIndexIn(s);
if (lastNonSlash != -1) {
s = s.substring(0, lastNonSlash + 1);
}
return SLASH_MATCHER.collapseFrom(s, '/');
} | [
"static",
"String",
"removeExtraneousSlashes",
"(",
"String",
"s",
")",
"{",
"int",
"lastNonSlash",
"=",
"NON_SLASH_MATCHER",
".",
"lastIndexIn",
"(",
"s",
")",
";",
"if",
"(",
"lastNonSlash",
"!=",
"-",
"1",
")",
"{",
"s",
"=",
"s",
".",
"substring",
"(",
"0",
",",
"lastNonSlash",
"+",
"1",
")",
";",
"}",
"return",
"SLASH_MATCHER",
".",
"collapseFrom",
"(",
"s",
",",
"'",
"'",
")",
";",
"}"
] | Removes extra slashes from a path. Leading slash is preserved, trailing
slash is stripped, and any runs of more than one slash in the middle is
replaced by a single slash. | [
"Removes",
"extra",
"slashes",
"from",
"a",
"path",
".",
"Leading",
"slash",
"is",
"preserved",
"trailing",
"slash",
"is",
"stripped",
"and",
"any",
"runs",
"of",
"more",
"than",
"one",
"slash",
"in",
"the",
"middle",
"is",
"replaced",
"by",
"a",
"single",
"slash",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/deps/PathUtil.java#L99-L106 |
24,888 | google/closure-compiler | src/com/google/javascript/jscomp/deps/PathUtil.java | PathUtil.makeAbsolute | public static String makeAbsolute(String path, String rootPath) {
if (!isAbsolute(path)) {
path = rootPath + "/" + path;
}
return collapseDots(path);
} | java | public static String makeAbsolute(String path, String rootPath) {
if (!isAbsolute(path)) {
path = rootPath + "/" + path;
}
return collapseDots(path);
} | [
"public",
"static",
"String",
"makeAbsolute",
"(",
"String",
"path",
",",
"String",
"rootPath",
")",
"{",
"if",
"(",
"!",
"isAbsolute",
"(",
"path",
")",
")",
"{",
"path",
"=",
"rootPath",
"+",
"\"/\"",
"+",
"path",
";",
"}",
"return",
"collapseDots",
"(",
"path",
")",
";",
"}"
] | Converts the given path into an absolute one. This prepends the given
rootPath and removes all .'s from the path. If an absolute path is given,
it will not be prefixed.
<p>Unlike File.getAbsolutePath(), this function does remove .'s from the
path and unlike File.getCanonicalPath(), this function does not resolve
symlinks and does not use filesystem calls.</p>
@param rootPath The path to prefix to path if path is not already absolute.
@param path The path to make absolute.
@return The path made absolute. | [
"Converts",
"the",
"given",
"path",
"into",
"an",
"absolute",
"one",
".",
"This",
"prepends",
"the",
"given",
"rootPath",
"and",
"removes",
"all",
".",
"s",
"from",
"the",
"path",
".",
"If",
"an",
"absolute",
"path",
"is",
"given",
"it",
"will",
"not",
"be",
"prefixed",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/deps/PathUtil.java#L138-L143 |
24,889 | google/closure-compiler | src/com/google/javascript/jscomp/deps/PathUtil.java | PathUtil.makeRelative | public static String makeRelative(String basePath, String targetPath) {
// Ensure the paths are both absolute or both relative.
if (isAbsolute(basePath) !=
isAbsolute(targetPath)) {
throw new IllegalArgumentException(
"Paths must both be relative or both absolute.\n" +
" basePath: " + basePath + "\n" +
" targetPath: " + targetPath);
}
basePath = collapseDots(basePath);
targetPath = collapseDots(targetPath);
String[] baseFragments = basePath.split("/");
String[] targetFragments = targetPath.split("/");
int i = -1;
do {
i += 1;
if (i == baseFragments.length && i == targetFragments.length) {
// Eg) base: /java/com/google
// target: /java/com/google
// result: . <-- . is better than "" since "" + "/path" = "/path"
return ".";
} else if (i == baseFragments.length) {
// Eg) base: /java/com/google
// target: /java/com/google/c/ui
// result: c/ui
return Joiner.on("/").join(
Lists.newArrayList(
Arrays.asList(targetFragments).listIterator(i)));
} else if (i == targetFragments.length) {
// Eg) base: /java/com/google/c/ui
// target: /java/com/google
// result: ../..
return Strings.repeat("../", baseFragments.length - i - 1) + "..";
}
} while (baseFragments[i].equals(targetFragments[i]));
// Eg) base: /java/com/google/c
// target: /java/com/google/common/base
// result: ../common/base
return Strings.repeat("../", baseFragments.length - i) +
Joiner.on("/").join(
Lists.newArrayList(Arrays.asList(targetFragments).listIterator(i)));
} | java | public static String makeRelative(String basePath, String targetPath) {
// Ensure the paths are both absolute or both relative.
if (isAbsolute(basePath) !=
isAbsolute(targetPath)) {
throw new IllegalArgumentException(
"Paths must both be relative or both absolute.\n" +
" basePath: " + basePath + "\n" +
" targetPath: " + targetPath);
}
basePath = collapseDots(basePath);
targetPath = collapseDots(targetPath);
String[] baseFragments = basePath.split("/");
String[] targetFragments = targetPath.split("/");
int i = -1;
do {
i += 1;
if (i == baseFragments.length && i == targetFragments.length) {
// Eg) base: /java/com/google
// target: /java/com/google
// result: . <-- . is better than "" since "" + "/path" = "/path"
return ".";
} else if (i == baseFragments.length) {
// Eg) base: /java/com/google
// target: /java/com/google/c/ui
// result: c/ui
return Joiner.on("/").join(
Lists.newArrayList(
Arrays.asList(targetFragments).listIterator(i)));
} else if (i == targetFragments.length) {
// Eg) base: /java/com/google/c/ui
// target: /java/com/google
// result: ../..
return Strings.repeat("../", baseFragments.length - i - 1) + "..";
}
} while (baseFragments[i].equals(targetFragments[i]));
// Eg) base: /java/com/google/c
// target: /java/com/google/common/base
// result: ../common/base
return Strings.repeat("../", baseFragments.length - i) +
Joiner.on("/").join(
Lists.newArrayList(Arrays.asList(targetFragments).listIterator(i)));
} | [
"public",
"static",
"String",
"makeRelative",
"(",
"String",
"basePath",
",",
"String",
"targetPath",
")",
"{",
"// Ensure the paths are both absolute or both relative.",
"if",
"(",
"isAbsolute",
"(",
"basePath",
")",
"!=",
"isAbsolute",
"(",
"targetPath",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Paths must both be relative or both absolute.\\n\"",
"+",
"\" basePath: \"",
"+",
"basePath",
"+",
"\"\\n\"",
"+",
"\" targetPath: \"",
"+",
"targetPath",
")",
";",
"}",
"basePath",
"=",
"collapseDots",
"(",
"basePath",
")",
";",
"targetPath",
"=",
"collapseDots",
"(",
"targetPath",
")",
";",
"String",
"[",
"]",
"baseFragments",
"=",
"basePath",
".",
"split",
"(",
"\"/\"",
")",
";",
"String",
"[",
"]",
"targetFragments",
"=",
"targetPath",
".",
"split",
"(",
"\"/\"",
")",
";",
"int",
"i",
"=",
"-",
"1",
";",
"do",
"{",
"i",
"+=",
"1",
";",
"if",
"(",
"i",
"==",
"baseFragments",
".",
"length",
"&&",
"i",
"==",
"targetFragments",
".",
"length",
")",
"{",
"// Eg) base: /java/com/google",
"// target: /java/com/google",
"// result: . <-- . is better than \"\" since \"\" + \"/path\" = \"/path\"",
"return",
"\".\"",
";",
"}",
"else",
"if",
"(",
"i",
"==",
"baseFragments",
".",
"length",
")",
"{",
"// Eg) base: /java/com/google",
"// target: /java/com/google/c/ui",
"// result: c/ui",
"return",
"Joiner",
".",
"on",
"(",
"\"/\"",
")",
".",
"join",
"(",
"Lists",
".",
"newArrayList",
"(",
"Arrays",
".",
"asList",
"(",
"targetFragments",
")",
".",
"listIterator",
"(",
"i",
")",
")",
")",
";",
"}",
"else",
"if",
"(",
"i",
"==",
"targetFragments",
".",
"length",
")",
"{",
"// Eg) base: /java/com/google/c/ui",
"// target: /java/com/google",
"// result: ../..",
"return",
"Strings",
".",
"repeat",
"(",
"\"../\"",
",",
"baseFragments",
".",
"length",
"-",
"i",
"-",
"1",
")",
"+",
"\"..\"",
";",
"}",
"}",
"while",
"(",
"baseFragments",
"[",
"i",
"]",
".",
"equals",
"(",
"targetFragments",
"[",
"i",
"]",
")",
")",
";",
"// Eg) base: /java/com/google/c",
"// target: /java/com/google/common/base",
"// result: ../common/base",
"return",
"Strings",
".",
"repeat",
"(",
"\"../\"",
",",
"baseFragments",
".",
"length",
"-",
"i",
")",
"+",
"Joiner",
".",
"on",
"(",
"\"/\"",
")",
".",
"join",
"(",
"Lists",
".",
"newArrayList",
"(",
"Arrays",
".",
"asList",
"(",
"targetFragments",
")",
".",
"listIterator",
"(",
"i",
")",
")",
")",
";",
"}"
] | Returns targetPath relative to basePath.
<p>basePath and targetPath must either both be relative, or both be
absolute paths.</p>
<p>This function is different from makeRelative
in that it is able to add in ../ components and collapse existing ones as well.</p>
Examples:
base="some/relative/path" target="some/relative/path/foo" return="foo"
base="some/relative/path" target="some/relative" return=".."
base="some/relative/path" target="foo/bar" return="../../../foo/bar"
base="/some/abs/path" target="/foo/bar" return="../../../foo/bar"
@param basePath The path to make targetPath relative to.
@param targetPath The path to make relative.
@return A path relative to targetPath. The returned value will never start
with a slash. | [
"Returns",
"targetPath",
"relative",
"to",
"basePath",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/deps/PathUtil.java#L165-L210 |
24,890 | google/closure-compiler | src/com/google/javascript/jscomp/DataFlowAnalysis.java | DataFlowAnalysis.initialize | protected void initialize() {
// TODO(user): Calling clear doesn't deallocate the memory in a
// LinkedHashSet. Consider creating a new work set if we plan to repeatedly
// call analyze.
orderedWorkSet.clear();
for (DiGraphNode<N, Branch> node : cfg.getDirectedGraphNodes()) {
node.setAnnotation(new FlowState<>(createInitialEstimateLattice(),
createInitialEstimateLattice()));
if (node != cfg.getImplicitReturn()) {
orderedWorkSet.add(node);
}
}
} | java | protected void initialize() {
// TODO(user): Calling clear doesn't deallocate the memory in a
// LinkedHashSet. Consider creating a new work set if we plan to repeatedly
// call analyze.
orderedWorkSet.clear();
for (DiGraphNode<N, Branch> node : cfg.getDirectedGraphNodes()) {
node.setAnnotation(new FlowState<>(createInitialEstimateLattice(),
createInitialEstimateLattice()));
if (node != cfg.getImplicitReturn()) {
orderedWorkSet.add(node);
}
}
} | [
"protected",
"void",
"initialize",
"(",
")",
"{",
"// TODO(user): Calling clear doesn't deallocate the memory in a",
"// LinkedHashSet. Consider creating a new work set if we plan to repeatedly",
"// call analyze.",
"orderedWorkSet",
".",
"clear",
"(",
")",
";",
"for",
"(",
"DiGraphNode",
"<",
"N",
",",
"Branch",
">",
"node",
":",
"cfg",
".",
"getDirectedGraphNodes",
"(",
")",
")",
"{",
"node",
".",
"setAnnotation",
"(",
"new",
"FlowState",
"<>",
"(",
"createInitialEstimateLattice",
"(",
")",
",",
"createInitialEstimateLattice",
"(",
")",
")",
")",
";",
"if",
"(",
"node",
"!=",
"cfg",
".",
"getImplicitReturn",
"(",
")",
")",
"{",
"orderedWorkSet",
".",
"add",
"(",
"node",
")",
";",
"}",
"}",
"}"
] | Initializes the work list and the control flow graph. | [
"Initializes",
"the",
"work",
"list",
"and",
"the",
"control",
"flow",
"graph",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/DataFlowAnalysis.java#L241-L253 |
24,891 | google/closure-compiler | src/com/google/javascript/jscomp/DataFlowAnalysis.java | DataFlowAnalysis.flow | protected boolean flow(DiGraphNode<N, Branch> node) {
FlowState<L> state = node.getAnnotation();
if (isForward()) {
L outBefore = state.out;
state.out = flowThrough(node.getValue(), state.in);
return !outBefore.equals(state.out);
} else {
L inBefore = state.in;
state.in = flowThrough(node.getValue(), state.out);
return !inBefore.equals(state.in);
}
} | java | protected boolean flow(DiGraphNode<N, Branch> node) {
FlowState<L> state = node.getAnnotation();
if (isForward()) {
L outBefore = state.out;
state.out = flowThrough(node.getValue(), state.in);
return !outBefore.equals(state.out);
} else {
L inBefore = state.in;
state.in = flowThrough(node.getValue(), state.out);
return !inBefore.equals(state.in);
}
} | [
"protected",
"boolean",
"flow",
"(",
"DiGraphNode",
"<",
"N",
",",
"Branch",
">",
"node",
")",
"{",
"FlowState",
"<",
"L",
">",
"state",
"=",
"node",
".",
"getAnnotation",
"(",
")",
";",
"if",
"(",
"isForward",
"(",
")",
")",
"{",
"L",
"outBefore",
"=",
"state",
".",
"out",
";",
"state",
".",
"out",
"=",
"flowThrough",
"(",
"node",
".",
"getValue",
"(",
")",
",",
"state",
".",
"in",
")",
";",
"return",
"!",
"outBefore",
".",
"equals",
"(",
"state",
".",
"out",
")",
";",
"}",
"else",
"{",
"L",
"inBefore",
"=",
"state",
".",
"in",
";",
"state",
".",
"in",
"=",
"flowThrough",
"(",
"node",
".",
"getValue",
"(",
")",
",",
"state",
".",
"out",
")",
";",
"return",
"!",
"inBefore",
".",
"equals",
"(",
"state",
".",
"in",
")",
";",
"}",
"}"
] | Performs a single flow through a node.
@return {@code true} if the flow state differs from the previous state. | [
"Performs",
"a",
"single",
"flow",
"through",
"a",
"node",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/DataFlowAnalysis.java#L260-L271 |
24,892 | google/closure-compiler | src/com/google/javascript/jscomp/ReplaceStrings.java | ReplaceStrings.getResult | List<Result> getResult() {
return ImmutableList.copyOf(Iterables.filter(results.values(), USED_RESULTS));
} | java | List<Result> getResult() {
return ImmutableList.copyOf(Iterables.filter(results.values(), USED_RESULTS));
} | [
"List",
"<",
"Result",
">",
"getResult",
"(",
")",
"{",
"return",
"ImmutableList",
".",
"copyOf",
"(",
"Iterables",
".",
"filter",
"(",
"results",
".",
"values",
"(",
")",
",",
"USED_RESULTS",
")",
")",
";",
"}"
] | Get the list of all replacements performed. | [
"Get",
"the",
"list",
"of",
"all",
"replacements",
"performed",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ReplaceStrings.java#L172-L174 |
24,893 | google/closure-compiler | src/com/google/javascript/jscomp/ReplaceStrings.java | ReplaceStrings.getStringMap | VariableMap getStringMap() {
ImmutableMap.Builder<String, String> map = ImmutableMap.builder();
for (Result result : Iterables.filter(results.values(), USED_RESULTS)) {
map.put(result.replacement, result.original);
}
VariableMap stringMap = new VariableMap(map.build());
return stringMap;
} | java | VariableMap getStringMap() {
ImmutableMap.Builder<String, String> map = ImmutableMap.builder();
for (Result result : Iterables.filter(results.values(), USED_RESULTS)) {
map.put(result.replacement, result.original);
}
VariableMap stringMap = new VariableMap(map.build());
return stringMap;
} | [
"VariableMap",
"getStringMap",
"(",
")",
"{",
"ImmutableMap",
".",
"Builder",
"<",
"String",
",",
"String",
">",
"map",
"=",
"ImmutableMap",
".",
"builder",
"(",
")",
";",
"for",
"(",
"Result",
"result",
":",
"Iterables",
".",
"filter",
"(",
"results",
".",
"values",
"(",
")",
",",
"USED_RESULTS",
")",
")",
"{",
"map",
".",
"put",
"(",
"result",
".",
"replacement",
",",
"result",
".",
"original",
")",
";",
"}",
"VariableMap",
"stringMap",
"=",
"new",
"VariableMap",
"(",
"map",
".",
"build",
"(",
")",
")",
";",
"return",
"stringMap",
";",
"}"
] | Get the list of replaces as a VariableMap | [
"Get",
"the",
"list",
"of",
"replaces",
"as",
"a",
"VariableMap"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ReplaceStrings.java#L177-L185 |
24,894 | google/closure-compiler | src/com/google/javascript/jscomp/ReplaceStrings.java | ReplaceStrings.doSubstitutions | private void doSubstitutions(NodeTraversal t, Config config, Node n) {
if (n.isTaggedTemplateLit()) {
// This is currently not supported, since tagged template literals have a different calling
// convention than ordinary functions, so it's unclear which arguments are expected to be
// replaced. Specifically, there are no direct string arguments, and for arbitrary tag
// functions it's not clear that it's safe to inline any constant placeholders.
compiler.report(JSError.make(n, STRING_REPLACEMENT_TAGGED_TEMPLATE));
return;
}
checkState(n.isNew() || n.isCall());
if (!config.isReplaceAll()) {
// Note: the first child is the function, but the parameter id is 1 based.
for (int parameter : config.parameters) {
Node arg = n.getChildAtIndex(parameter);
if (arg != null) {
replaceExpression(t, arg, n);
}
}
} else {
// Replace all parameters.
Node firstParam = n.getSecondChild();
for (Node arg = firstParam; arg != null; arg = arg.getNext()) {
arg = replaceExpression(t, arg, n);
}
}
} | java | private void doSubstitutions(NodeTraversal t, Config config, Node n) {
if (n.isTaggedTemplateLit()) {
// This is currently not supported, since tagged template literals have a different calling
// convention than ordinary functions, so it's unclear which arguments are expected to be
// replaced. Specifically, there are no direct string arguments, and for arbitrary tag
// functions it's not clear that it's safe to inline any constant placeholders.
compiler.report(JSError.make(n, STRING_REPLACEMENT_TAGGED_TEMPLATE));
return;
}
checkState(n.isNew() || n.isCall());
if (!config.isReplaceAll()) {
// Note: the first child is the function, but the parameter id is 1 based.
for (int parameter : config.parameters) {
Node arg = n.getChildAtIndex(parameter);
if (arg != null) {
replaceExpression(t, arg, n);
}
}
} else {
// Replace all parameters.
Node firstParam = n.getSecondChild();
for (Node arg = firstParam; arg != null; arg = arg.getNext()) {
arg = replaceExpression(t, arg, n);
}
}
} | [
"private",
"void",
"doSubstitutions",
"(",
"NodeTraversal",
"t",
",",
"Config",
"config",
",",
"Node",
"n",
")",
"{",
"if",
"(",
"n",
".",
"isTaggedTemplateLit",
"(",
")",
")",
"{",
"// This is currently not supported, since tagged template literals have a different calling",
"// convention than ordinary functions, so it's unclear which arguments are expected to be",
"// replaced. Specifically, there are no direct string arguments, and for arbitrary tag",
"// functions it's not clear that it's safe to inline any constant placeholders.",
"compiler",
".",
"report",
"(",
"JSError",
".",
"make",
"(",
"n",
",",
"STRING_REPLACEMENT_TAGGED_TEMPLATE",
")",
")",
";",
"return",
";",
"}",
"checkState",
"(",
"n",
".",
"isNew",
"(",
")",
"||",
"n",
".",
"isCall",
"(",
")",
")",
";",
"if",
"(",
"!",
"config",
".",
"isReplaceAll",
"(",
")",
")",
"{",
"// Note: the first child is the function, but the parameter id is 1 based.",
"for",
"(",
"int",
"parameter",
":",
"config",
".",
"parameters",
")",
"{",
"Node",
"arg",
"=",
"n",
".",
"getChildAtIndex",
"(",
"parameter",
")",
";",
"if",
"(",
"arg",
"!=",
"null",
")",
"{",
"replaceExpression",
"(",
"t",
",",
"arg",
",",
"n",
")",
";",
"}",
"}",
"}",
"else",
"{",
"// Replace all parameters.",
"Node",
"firstParam",
"=",
"n",
".",
"getSecondChild",
"(",
")",
";",
"for",
"(",
"Node",
"arg",
"=",
"firstParam",
";",
"arg",
"!=",
"null",
";",
"arg",
"=",
"arg",
".",
"getNext",
"(",
")",
")",
"{",
"arg",
"=",
"replaceExpression",
"(",
"t",
",",
"arg",
",",
"n",
")",
";",
"}",
"}",
"}"
] | Replace the parameters specified in the config, if possible. | [
"Replace",
"the",
"parameters",
"specified",
"in",
"the",
"config",
"if",
"possible",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ReplaceStrings.java#L280-L306 |
24,895 | google/closure-compiler | src/com/google/javascript/jscomp/ReplaceStrings.java | ReplaceStrings.replaceExpression | private Node replaceExpression(NodeTraversal t, Node expr, Node parent) {
Node replacement;
String key = null;
String replacementString;
switch (expr.getToken()) {
case STRING:
key = expr.getString();
replacementString = getReplacement(key);
replacement = IR.string(replacementString);
break;
case TEMPLATELIT:
case ADD:
case NAME:
StringBuilder keyBuilder = new StringBuilder();
Node keyNode = IR.string("");
replacement = buildReplacement(t, expr, keyNode, keyBuilder);
key = keyBuilder.toString();
if (key.equals(placeholderToken)) {
// There is no static text in expr - only a placeholder - so just return expr directly.
// In this case, replacement is just the string join ('`' + expr), which is not useful.
return expr;
}
replacementString = getReplacement(key);
keyNode.setString(replacementString);
break;
default:
// This may be a function call or a variable reference. We don't
// replace these.
return expr;
}
checkNotNull(key);
checkNotNull(replacementString);
recordReplacement(key);
replacement.useSourceInfoIfMissingFromForTree(expr);
parent.replaceChild(expr, replacement);
t.reportCodeChange();
return replacement;
} | java | private Node replaceExpression(NodeTraversal t, Node expr, Node parent) {
Node replacement;
String key = null;
String replacementString;
switch (expr.getToken()) {
case STRING:
key = expr.getString();
replacementString = getReplacement(key);
replacement = IR.string(replacementString);
break;
case TEMPLATELIT:
case ADD:
case NAME:
StringBuilder keyBuilder = new StringBuilder();
Node keyNode = IR.string("");
replacement = buildReplacement(t, expr, keyNode, keyBuilder);
key = keyBuilder.toString();
if (key.equals(placeholderToken)) {
// There is no static text in expr - only a placeholder - so just return expr directly.
// In this case, replacement is just the string join ('`' + expr), which is not useful.
return expr;
}
replacementString = getReplacement(key);
keyNode.setString(replacementString);
break;
default:
// This may be a function call or a variable reference. We don't
// replace these.
return expr;
}
checkNotNull(key);
checkNotNull(replacementString);
recordReplacement(key);
replacement.useSourceInfoIfMissingFromForTree(expr);
parent.replaceChild(expr, replacement);
t.reportCodeChange();
return replacement;
} | [
"private",
"Node",
"replaceExpression",
"(",
"NodeTraversal",
"t",
",",
"Node",
"expr",
",",
"Node",
"parent",
")",
"{",
"Node",
"replacement",
";",
"String",
"key",
"=",
"null",
";",
"String",
"replacementString",
";",
"switch",
"(",
"expr",
".",
"getToken",
"(",
")",
")",
"{",
"case",
"STRING",
":",
"key",
"=",
"expr",
".",
"getString",
"(",
")",
";",
"replacementString",
"=",
"getReplacement",
"(",
"key",
")",
";",
"replacement",
"=",
"IR",
".",
"string",
"(",
"replacementString",
")",
";",
"break",
";",
"case",
"TEMPLATELIT",
":",
"case",
"ADD",
":",
"case",
"NAME",
":",
"StringBuilder",
"keyBuilder",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"Node",
"keyNode",
"=",
"IR",
".",
"string",
"(",
"\"\"",
")",
";",
"replacement",
"=",
"buildReplacement",
"(",
"t",
",",
"expr",
",",
"keyNode",
",",
"keyBuilder",
")",
";",
"key",
"=",
"keyBuilder",
".",
"toString",
"(",
")",
";",
"if",
"(",
"key",
".",
"equals",
"(",
"placeholderToken",
")",
")",
"{",
"// There is no static text in expr - only a placeholder - so just return expr directly.",
"// In this case, replacement is just the string join ('`' + expr), which is not useful.",
"return",
"expr",
";",
"}",
"replacementString",
"=",
"getReplacement",
"(",
"key",
")",
";",
"keyNode",
".",
"setString",
"(",
"replacementString",
")",
";",
"break",
";",
"default",
":",
"// This may be a function call or a variable reference. We don't",
"// replace these.",
"return",
"expr",
";",
"}",
"checkNotNull",
"(",
"key",
")",
";",
"checkNotNull",
"(",
"replacementString",
")",
";",
"recordReplacement",
"(",
"key",
")",
";",
"replacement",
".",
"useSourceInfoIfMissingFromForTree",
"(",
"expr",
")",
";",
"parent",
".",
"replaceChild",
"(",
"expr",
",",
"replacement",
")",
";",
"t",
".",
"reportCodeChange",
"(",
")",
";",
"return",
"replacement",
";",
"}"
] | Replaces a string expression with a short encoded string expression.
@param t The traversal
@param expr The expression node
@param parent The expression node's parent
@return The replacement node (or the original expression if no replacement is made) | [
"Replaces",
"a",
"string",
"expression",
"with",
"a",
"short",
"encoded",
"string",
"expression",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ReplaceStrings.java#L316-L355 |
24,896 | google/closure-compiler | src/com/google/javascript/jscomp/ReplaceStrings.java | ReplaceStrings.getReplacement | private String getReplacement(String key) {
Result result = results.get(key);
if (result != null) {
return result.replacement;
}
String replacement = nameGenerator.generateNextName();
result = new Result(key, replacement);
results.put(key, result);
return replacement;
} | java | private String getReplacement(String key) {
Result result = results.get(key);
if (result != null) {
return result.replacement;
}
String replacement = nameGenerator.generateNextName();
result = new Result(key, replacement);
results.put(key, result);
return replacement;
} | [
"private",
"String",
"getReplacement",
"(",
"String",
"key",
")",
"{",
"Result",
"result",
"=",
"results",
".",
"get",
"(",
"key",
")",
";",
"if",
"(",
"result",
"!=",
"null",
")",
"{",
"return",
"result",
".",
"replacement",
";",
"}",
"String",
"replacement",
"=",
"nameGenerator",
".",
"generateNextName",
"(",
")",
";",
"result",
"=",
"new",
"Result",
"(",
"key",
",",
"replacement",
")",
";",
"results",
".",
"put",
"(",
"key",
",",
"result",
")",
";",
"return",
"replacement",
";",
"}"
] | Get a replacement string for the provide key text. | [
"Get",
"a",
"replacement",
"string",
"for",
"the",
"provide",
"key",
"text",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ReplaceStrings.java#L358-L368 |
24,897 | google/closure-compiler | src/com/google/javascript/jscomp/ReplaceStrings.java | ReplaceStrings.recordReplacement | private void recordReplacement(String key) {
Result result = results.get(key);
checkState(result != null);
result.didReplacement = true;
} | java | private void recordReplacement(String key) {
Result result = results.get(key);
checkState(result != null);
result.didReplacement = true;
} | [
"private",
"void",
"recordReplacement",
"(",
"String",
"key",
")",
"{",
"Result",
"result",
"=",
"results",
".",
"get",
"(",
"key",
")",
";",
"checkState",
"(",
"result",
"!=",
"null",
")",
";",
"result",
".",
"didReplacement",
"=",
"true",
";",
"}"
] | Record the location the replacement was made. | [
"Record",
"the",
"location",
"the",
"replacement",
"was",
"made",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ReplaceStrings.java#L371-L376 |
24,898 | google/closure-compiler | src/com/google/javascript/jscomp/ReplaceStrings.java | ReplaceStrings.getMethodFromDeclarationName | private static String getMethodFromDeclarationName(String fullDeclarationName) {
String[] parts = fullDeclarationName.split("\\.prototype\\.");
checkState(parts.length == 1 || parts.length == 2);
if (parts.length == 2) {
return parts[1];
}
return null;
} | java | private static String getMethodFromDeclarationName(String fullDeclarationName) {
String[] parts = fullDeclarationName.split("\\.prototype\\.");
checkState(parts.length == 1 || parts.length == 2);
if (parts.length == 2) {
return parts[1];
}
return null;
} | [
"private",
"static",
"String",
"getMethodFromDeclarationName",
"(",
"String",
"fullDeclarationName",
")",
"{",
"String",
"[",
"]",
"parts",
"=",
"fullDeclarationName",
".",
"split",
"(",
"\"\\\\.prototype\\\\.\"",
")",
";",
"checkState",
"(",
"parts",
".",
"length",
"==",
"1",
"||",
"parts",
".",
"length",
"==",
"2",
")",
";",
"if",
"(",
"parts",
".",
"length",
"==",
"2",
")",
"{",
"return",
"parts",
"[",
"1",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | From a provide name extract the method name. | [
"From",
"a",
"provide",
"name",
"extract",
"the",
"method",
"name",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ReplaceStrings.java#L439-L446 |
24,899 | google/closure-compiler | src/com/google/javascript/jscomp/ReplaceStrings.java | ReplaceStrings.getClassFromDeclarationName | private static String getClassFromDeclarationName(String fullDeclarationName) {
String[] parts = fullDeclarationName.split("\\.prototype\\.");
checkState(parts.length == 1 || parts.length == 2);
if (parts.length == 2) {
return parts[0];
}
return null;
} | java | private static String getClassFromDeclarationName(String fullDeclarationName) {
String[] parts = fullDeclarationName.split("\\.prototype\\.");
checkState(parts.length == 1 || parts.length == 2);
if (parts.length == 2) {
return parts[0];
}
return null;
} | [
"private",
"static",
"String",
"getClassFromDeclarationName",
"(",
"String",
"fullDeclarationName",
")",
"{",
"String",
"[",
"]",
"parts",
"=",
"fullDeclarationName",
".",
"split",
"(",
"\"\\\\.prototype\\\\.\"",
")",
";",
"checkState",
"(",
"parts",
".",
"length",
"==",
"1",
"||",
"parts",
".",
"length",
"==",
"2",
")",
";",
"if",
"(",
"parts",
".",
"length",
"==",
"2",
")",
"{",
"return",
"parts",
"[",
"0",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | From a provide name extract the class name. | [
"From",
"a",
"provide",
"name",
"extract",
"the",
"class",
"name",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ReplaceStrings.java#L449-L456 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.