forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create the module scope as a function
Summary: Currently, we do not correctly process declarations at the top level of a module because the DeclCollector is only run on functions. This is a problem for modules, because they are defined as a scope in a dummy global function, which does not actually contain the AST for the modules. So when the DeclCollector runs, the declarations in the module scope cannot be reached. Using a function also ensures that vars declared at the top level of a module are not treated as global properties. Reviewed By: tmikov Differential Revision: D36231405 fbshipit-source-id: 20a16daa905fe84e659630dc3410d9245ecb1831
- Loading branch information
1 parent
5c7a666
commit f1462aa
Showing
3 changed files
with
44 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
// RUN: %juno %s %s | %FileCheck %s --match-full-lines | ||
|
||
function foo(){ | ||
return 42; | ||
} | ||
|
||
// CHECK-LABEL: Module: {{.*}}/module-function-decl.js | ||
// CHECK: 1 declarations | ||
// CHECK: Decl#0 'foo' ScopedFunction NotSpecial |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
// RUN: %juno %s %s | %FileCheck %s --match-full-lines | ||
|
||
var x = 5; | ||
|
||
// CHECK-LABEL: Module: {{.*}}/module-var-decl.js | ||
// CHECK: 1 declarations | ||
// CHECK: Decl#0 'x' Var NotSpecial |