erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame^] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 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 |
| 29 | |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame^] | 30 | // Test basic module syntax, with and without automatic semicolon insertion. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 31 | |
| 32 | module A {} |
| 33 | |
| 34 | module A1 = A |
| 35 | module A2 = A; |
| 36 | module A3 = A2 |
| 37 | |
| 38 | module B { |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame^] | 39 | export vx |
| 40 | export vy, lz, c, f |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 41 | |
| 42 | var vx |
| 43 | var vx, vy; |
| 44 | var vx = 0, vy |
| 45 | let lx, ly |
| 46 | let lz = 1 |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 47 | const c = 9 |
| 48 | function f() {} |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 49 | |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame^] | 50 | module C0 {} |
| 51 | |
| 52 | export module C { |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 53 | let x |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame^] | 54 | export module D { export let x } |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 55 | let y |
| 56 | } |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 57 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 58 | let zz = "" |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 59 | |
| 60 | export var x0 |
| 61 | export var x1, x2 = 6, x3 |
| 62 | export let y0 |
| 63 | export let y1 = 0, y2 |
| 64 | export const z0 = 0 |
| 65 | export const z1 = 2, z2 = 3 |
| 66 | export function f0() {} |
| 67 | export module M1 {} |
| 68 | export module M2 = C.D |
| 69 | export module M3 at "http://where" |
| 70 | |
| 71 | import i0 from I |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame^] | 72 | import i1, i2, i3, M from I |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 73 | import i4, i5 from "http://where" |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 74 | } |
| 75 | |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame^] | 76 | module I { |
| 77 | export let i0, i1, i2, i3; |
| 78 | export module M {} |
| 79 | } |
| 80 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 81 | module C1 = B.C; |
| 82 | module D1 = B.C.D |
| 83 | module D2 = C1.D |
| 84 | module D3 = D2 |
| 85 | |
| 86 | module E1 at "http://where" |
| 87 | module E2 at "http://where"; |
| 88 | module E3 = E1.F |
| 89 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 90 | // Check that ASI does not interfere. |
| 91 | |
yangguo@chromium.org | a7d3df9 | 2012-02-27 11:46:55 +0000 | [diff] [blame] | 92 | module X |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 93 | { |
| 94 | let x |
| 95 | } |
| 96 | |
yangguo@chromium.org | a7d3df9 | 2012-02-27 11:46:55 +0000 | [diff] [blame] | 97 | module Y |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 98 | = |
| 99 | X |
| 100 | |
yangguo@chromium.org | a7d3df9 | 2012-02-27 11:46:55 +0000 | [diff] [blame] | 101 | module Z |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 102 | at |
| 103 | "file://local" |
yangguo@chromium.org | a7d3df9 | 2012-02-27 11:46:55 +0000 | [diff] [blame] | 104 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 105 | import |
| 106 | x |
| 107 | , |
| 108 | y |
| 109 | from |
| 110 | "file://local" |
| 111 | |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame^] | 112 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 113 | module Wrap { |
| 114 | export |
| 115 | x |
| 116 | , |
| 117 | y |
| 118 | |
| 119 | export |
| 120 | var |
| 121 | v1 = 1 |
| 122 | |
| 123 | export |
| 124 | let |
| 125 | v2 = 2 |
| 126 | |
| 127 | export |
| 128 | const |
| 129 | v3 = 3 |
| 130 | |
| 131 | export |
| 132 | function |
| 133 | f |
| 134 | ( |
| 135 | ) |
| 136 | { |
| 137 | } |
| 138 | |
| 139 | export |
| 140 | module V |
| 141 | { |
| 142 | } |
| 143 | } |
| 144 | |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame^] | 145 | export A, A1, A2, A3, B, I, C1, D1, D2, D3, E1, E2, E3, X, Y, Z, Wrap, x, y, UU |
| 146 | |
| 147 | |
yangguo@chromium.org | a7d3df9 | 2012-02-27 11:46:55 +0000 | [diff] [blame] | 148 | |
| 149 | // Check that 'module' still works as an identifier. |
| 150 | |
| 151 | var module |
| 152 | module = {} |
| 153 | module["a"] = 6 |
| 154 | function module() {} |
| 155 | function f(module) { return module } |
| 156 | try {} catch (module) {} |
| 157 | |
| 158 | module |
| 159 | v = 20 |