1// Copyright 2012 the V8 project authors. All rights reserved. 2// Redistribution and use in source and binary forms, with or without 3// modification, are permitted provided that the following conditions are 4// met: 5// 6// * Redistributions of source code must retain the above copyright 7// notice, this list of conditions and the following disclaimer. 8// * Redistributions in binary form must reproduce the above 9// copyright notice, this list of conditions and the following 10// disclaimer in the documentation and/or other materials provided 11// with the distribution. 12// * Neither the name of Google Inc. nor the names of its 13// contributors may be used to endorse or promote products derived 14// from this software without specific prior written permission. 15// 16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 28// Flags: --harmony-modules --harmony-scoping 29 30// Test basic module interface inference. 31 32"use strict"; 33 34print("begin.") 35 36 37export let x = print("0") 38 39export module B = A.B 40 41export module A { 42 export let x = print("1") 43 export let f = function() { return B.x } 44 export module B { 45 module BB = B 46 export BB, x 47 let x = print("2") 48 var y = print("3") 49 let Ax = A.x 50 try { A.y } catch (e) {} // throws 51 let Az = A.z // undefined 52 let Az2 = z // undefined 53 A.g() // hoisted 54 g() // hoisted 55 let ABx = A.B.x 56 let ABy = A.B.y 57 let Bx = B.x 58 let By = B.y 59 let BBx = BB.x 60 let BBy = BB.y 61 let Af = A.f 62 function f(x,y) { return x } 63 } 64 export let y = print("4") 65 export var z = print("4.1") 66 export function g() {} 67 let Ax = A.x 68 let Bx = B.x 69 let ABx = A.B.x 70 module C { 71 export let z = print("5") 72 export module D = B 73 // TODO(rossberg): turn these into proper negative test cases once we have 74 // suitable error messages. 75 // import C.z // multiple declarations 76 import x from B 77 } 78 module D { 79 // TODO(rossberg): Handle import *. 80 // import A.* // invalid forward import 81 } 82 module M {} 83 // TODO(rossberg): Handle import *. 84 // import M.* // invalid forward import 85 let Cz = C.z 86 let CDx = C.D.x 87} 88 89export module Imports { 90 module A1 { 91 export module A2 {} 92 } 93 module B { 94 // TODO(rossberg): Handle import *. 95 // import A1.* 96 // import A2.* // unbound variable A2 97 } 98} 99 100export module E { 101 export let xx = x 102 export y, B 103 let Bx = B.x 104 // TODO(rossberg): Handle import *. 105 // import A.* 106 module B = A.B 107 let y = A.y 108} 109 110export module M1 { 111 export module A2 = M2 112} 113export module M2 { 114 export module A1 = M1 115} 116 117// TODO(rossberg): turn these into proper negative test cases once we have 118// suitable error messages. 119// module W1 = W2.W 120// module W2 = { export module W = W3 } 121// module W3 = W1 // cyclic module definition 122 123// module W1 = W2.W3 124// module W2 = { 125// export module W3 = W4 126// export module W4 = W1 127// } // cyclic module definition 128 129// TODO(rossberg): Handle import *. 130//module M3B = M3.B 131//export module M3 { 132// export module B { export let x = "" } 133// module C1 = { import M3.* } 134// module C2 = { import M3.B.* } 135// module C3 = { import M3B.* } 136// module C4 = { export x import B.* } 137//// TODO(rossberg): turn these into proper negative test cases once we have 138//// suitable error messages. 139//// export module C5 = { import C5.* } // invalid forward import 140//// export module C6 = { import M3.C6.* } // invalid forward import 141//} 142 143export module External at "external.js" 144export module External1 = External 145//export module ExternalA = External.A 146export module InnerExternal { 147 export module E at "external.js" 148} 149export module External2 = InnerExternal.E 150//export let xxx = InnerExternal.E.A.x 151 152print("end.") 153