// However, this implementation ensures Caja has a single point of truth
// regarding what constitutes a JS identifier.
// TODO(kpreid): Reevaluate whether this is worth the complexity and the
// runtime dependency on the JS parser now that there is no cajoler.
MessageQueue mq = new SimpleMessageQueue();
Parser parser = new Parser(
new JsTokenQueue(
new JsLexer(
CharProducer.Factory.fromString(
"var " + candidate + ";",
InputSource.UNKNOWN)),
InputSource.UNKNOWN),
mq);
ParseTreeNode node;
try { node = parser.parse(); } catch (ParseException e) { return false; }
if (node == null || !mq.getMessages().isEmpty()) { return false; }
Map<String, ParseTreeNode> bindings = Maps.newHashMap();
if (!QuasiBuilder.match("{ var @p; }", node, bindings)) { return false; }
if (bindings.size() != 1) { return false; }
if (bindings.get("p") == null) { return false; }