tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

module-environment.js (1487B)


      1 // Test top-level module environment
      2 
      3 function testInitialEnvironment(source, expected) {
      4    let module = parseModule(source);
      5    let names = getModuleEnvironmentNames(module);
      6    assertEq(names.length, expected.length);
      7    expected.forEach(function(name) {
      8        assertEq(names.includes(name), true);
      9    });
     10 }
     11 
     12 // Non-exported bindings: only top-level functions are present in the
     13 // environment.
     14 testInitialEnvironment('', []);
     15 testInitialEnvironment('var x = 1;', []);
     16 testInitialEnvironment('let x = 1;', []);
     17 testInitialEnvironment("if (true) { let x = 1; }", []);
     18 testInitialEnvironment("if (true) { var x = 1; }", []);
     19 testInitialEnvironment('function x() {}', ['x']);
     20 testInitialEnvironment("class x { constructor() {} }", []);
     21 
     22 // Exported bindings must be present in the environment.
     23 testInitialEnvironment('export var x = 1;', ['x']);
     24 testInitialEnvironment('export let x = 1;', ['x']);
     25 testInitialEnvironment('export default function x() {};', ['x']);
     26 testInitialEnvironment('export default 1;', ['default']);
     27 testInitialEnvironment('export default function() {};', ['default']);
     28 testInitialEnvironment("export class x { constructor() {} }", ['x']);
     29 testInitialEnvironment('export default class x { constructor() {} };', ['x']);
     30 testInitialEnvironment('export default class { constructor() {} };', ['default']);
     31 
     32 // Imports: namespace imports are present.
     33 testInitialEnvironment('import { x } from "m";', []);
     34 testInitialEnvironment('import * as x from "m";', ['x']);