/** * Parse the directives, encode them in the AST, and remove their nodes. * * For information on ES5 directives, see section 14.1 of * ECMA-262, Edition 5. * * It would be nice if Rhino would eventually take care of this for * us, but right now their directive-processing is a one-off. */ private void parseDirectives(Node node) { // Remove all the directives, and encode them in the AST. ImmutableSet.Builder<String> directives = null; while (isDirective(node.getFirstChild())) { String directive = node.removeFirstChild().getFirstChild().getString(); if (directives == null) { directives = new ImmutableSet.Builder<>(); } directives.add(directive); } if (directives != null) { ImmutableSet<String> result = directives.build(); if (result.size() == 1 && result.contains("use strict")) { // Use a shared set. result = USE_STRICT_ONLY; } node.setDirectives(result); } }
/** * Parse the directives, encode them in the AST, and remove their nodes. * * For information on ES5 directives, see section 14.1 of * ECMA-262, Edition 5. * * It would be nice if Rhino would eventually take care of this for * us, but right now their directive-processing is a one-off. */ private void parseDirectives(Node node) { // Remove all the directives, and encode them in the AST. ImmutableSet.Builder<String> directives = null; while (isDirective(node.getFirstChild())) { String directive = node.removeFirstChild().getFirstChild().getString(); if (directives == null) { directives = new ImmutableSet.Builder<String>(); } directives.add(directive); } if (directives != null) { ImmutableSet<String> result = directives.build(); if (result.size() == 1 && result.contains("use strict")) { // Use a shared set. result = USE_STRICT_ONLY; } node.setDirectives(result); } }