001 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
002 // for details. All rights reserved. Use of this source code is governed by a
003 // BSD-style license that can be found in the LICENSE file.
004
005 package com.google.dart.compiler.backend.js.ast;
006
007 import com.google.dart.compiler.backend.js.JsReservedIdentifiers;
008 import org.jetbrains.annotations.NotNull;
009
010 /**
011 * The root scope is the parent of every scope. All identifiers in this scope
012 * are not obfuscatable. This scope is prefilled with reserved global
013 * JavaScript symbols.
014 */
015 public final class JsRootScope extends JsScope {
016 private final JsProgram program;
017
018 public JsRootScope(JsProgram program) {
019 super("Root");
020 this.program = program;
021 }
022
023 @Override
024 public JsProgram getProgram() {
025 return program;
026 }
027
028 @Override
029 protected JsName findOwnName(@NotNull String ident) {
030 JsName name = super.findOwnName(ident);
031 if (name == null) {
032 if (JsReservedIdentifiers.reservedGlobalSymbols.contains(ident)) {
033 /*
034 * Lazily add JsNames for reserved identifiers. Since a JsName for a reserved global symbol
035 * must report a legitimate enclosing scope, we can't simply have a shared set of symbol
036 * names.
037 */
038 name = doCreateName(ident);
039 }
040 }
041 return name;
042 }
043 }