js/src/jit-test/tests/modules/export-declaration.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 load(libdir + "match.js");
michael@0 2 load(libdir + "asserts.js");
michael@0 3
michael@0 4 var { Pattern, MatchError } = Match;
michael@0 5
michael@0 6 program = (elts) => Pattern({
michael@0 7 type: "Program",
michael@0 8 body: elts
michael@0 9 })
michael@0 10 exportDeclaration = (declaration, specifiers, source) => Pattern({
michael@0 11 type: "ExportDeclaration",
michael@0 12 declaration: declaration,
michael@0 13 specifiers: specifiers,
michael@0 14 source: source
michael@0 15 });
michael@0 16 exportSpecifier = (id, name) => Pattern({
michael@0 17 type: "ExportSpecifier",
michael@0 18 id: id,
michael@0 19 name: name
michael@0 20 });
michael@0 21 exportBatchSpecifier = () => Pattern({
michael@0 22 type: "ExportBatchSpecifier"
michael@0 23 });
michael@0 24 blockStatement = (body) => Pattern({
michael@0 25 type: "BlockStatement",
michael@0 26 body: body
michael@0 27 });
michael@0 28 functionDeclaration = (id, params, body) => Pattern({
michael@0 29 type: "FunctionDeclaration",
michael@0 30 id: id,
michael@0 31 params: params,
michael@0 32 defaults: [],
michael@0 33 body: body,
michael@0 34 rest: null,
michael@0 35 generator: false
michael@0 36 });
michael@0 37 variableDeclaration = (decls) => Pattern({
michael@0 38 type: "VariableDeclaration",
michael@0 39 kind: "var",
michael@0 40 declarations: decls
michael@0 41 });
michael@0 42 constDeclaration = (decls) => Pattern({
michael@0 43 type: "VariableDeclaration",
michael@0 44 kind: "const",
michael@0 45 declarations: decls
michael@0 46 });
michael@0 47 letDeclaration = (decls) => Pattern({
michael@0 48 type: "VariableDeclaration",
michael@0 49 kind: "let",
michael@0 50 declarations: decls
michael@0 51 });
michael@0 52 ident = (name) => Pattern({
michael@0 53 type: "Identifier",
michael@0 54 name: name
michael@0 55 });
michael@0 56 lit = (val) => Pattern({
michael@0 57 type: "Literal",
michael@0 58 value: val
michael@0 59 });
michael@0 60
michael@0 61 program([
michael@0 62 exportDeclaration(
michael@0 63 null,
michael@0 64 [],
michael@0 65 null
michael@0 66 )
michael@0 67 ]).assert(Reflect.parse("export {}"));
michael@0 68
michael@0 69 program([
michael@0 70 exportDeclaration(
michael@0 71 null,
michael@0 72 [
michael@0 73 exportSpecifier(
michael@0 74 ident("a"),
michael@0 75 ident("a")
michael@0 76 )
michael@0 77 ],
michael@0 78 null
michael@0 79 )
michael@0 80 ]).assert(Reflect.parse("export { a }"));
michael@0 81
michael@0 82 program([
michael@0 83 exportDeclaration(
michael@0 84 null,
michael@0 85 [
michael@0 86 exportSpecifier(
michael@0 87 ident("a"),
michael@0 88 ident("b")
michael@0 89 )
michael@0 90 ],
michael@0 91 null
michael@0 92 )
michael@0 93 ]).assert(Reflect.parse("export { a as b }"));
michael@0 94
michael@0 95 program([
michael@0 96 exportDeclaration(
michael@0 97 null,
michael@0 98 [
michael@0 99 exportSpecifier(
michael@0 100 ident("as"),
michael@0 101 ident("as")
michael@0 102 )
michael@0 103 ],
michael@0 104 null
michael@0 105 )
michael@0 106 ]).assert(Reflect.parse("export { as as as }"));
michael@0 107
michael@0 108 program([
michael@0 109 exportDeclaration(
michael@0 110 null,
michael@0 111 [
michael@0 112 exportSpecifier(
michael@0 113 ident("a"),
michael@0 114 ident("true")
michael@0 115 )
michael@0 116 ],
michael@0 117 null
michael@0 118 )
michael@0 119 ]).assert(Reflect.parse("export { a as true }"));
michael@0 120
michael@0 121 program([
michael@0 122 exportDeclaration(
michael@0 123 null,
michael@0 124 [
michael@0 125 exportSpecifier(
michael@0 126 ident("a"),
michael@0 127 ident("a")
michael@0 128 ),
michael@0 129 exportSpecifier(
michael@0 130 ident("b"),
michael@0 131 ident("b")
michael@0 132 ),
michael@0 133 ],
michael@0 134 null
michael@0 135 )
michael@0 136 ]).assert(Reflect.parse("export { a, b }"));
michael@0 137
michael@0 138 program([
michael@0 139 exportDeclaration(
michael@0 140 null,
michael@0 141 [
michael@0 142 exportSpecifier(
michael@0 143 ident("a"),
michael@0 144 ident("b")
michael@0 145 ),
michael@0 146 exportSpecifier(
michael@0 147 ident("c"),
michael@0 148 ident("d")
michael@0 149 ),
michael@0 150 ],
michael@0 151 null
michael@0 152 )
michael@0 153 ]).assert(Reflect.parse("export { a as b, c as d }"));
michael@0 154
michael@0 155 program([
michael@0 156 exportDeclaration(
michael@0 157 null,
michael@0 158 [
michael@0 159 exportBatchSpecifier()
michael@0 160 ],
michael@0 161 null
michael@0 162 )
michael@0 163 ]).assert(Reflect.parse("export *"));
michael@0 164
michael@0 165 program([
michael@0 166 exportDeclaration(
michael@0 167 null,
michael@0 168 [
michael@0 169 exportBatchSpecifier()
michael@0 170 ],
michael@0 171 lit("a")
michael@0 172 )
michael@0 173 ]).assert(Reflect.parse("export * from 'a'"));
michael@0 174
michael@0 175 program([
michael@0 176 exportDeclaration(
michael@0 177 functionDeclaration(
michael@0 178 ident("f"),
michael@0 179 [],
michael@0 180 blockStatement([])
michael@0 181 ),
michael@0 182 null,
michael@0 183 null
michael@0 184 )
michael@0 185 ]).assert(Reflect.parse("export function f() {}"));
michael@0 186
michael@0 187 program([
michael@0 188 exportDeclaration(
michael@0 189 variableDeclaration([
michael@0 190 {
michael@0 191 id: ident("a"),
michael@0 192 init: lit(1)
michael@0 193 }, {
michael@0 194 id: ident("b"),
michael@0 195 init: lit(2)
michael@0 196 }
michael@0 197 ]),
michael@0 198 null,
michael@0 199 null
michael@0 200 )
michael@0 201 ]).assert(Reflect.parse("export var a = 1, b = 2;"));
michael@0 202
michael@0 203 program([
michael@0 204 exportDeclaration(
michael@0 205 constDeclaration([
michael@0 206 {
michael@0 207 id: ident("a"),
michael@0 208 init: lit(1)
michael@0 209 }, {
michael@0 210 id: ident("b"),
michael@0 211 init: lit(2)
michael@0 212 }
michael@0 213 ]),
michael@0 214 null,
michael@0 215 null
michael@0 216 )
michael@0 217 ]).assert(Reflect.parse("export const a = 1, b = 2;"));
michael@0 218
michael@0 219 // FIXME: In scripts, top level lets are converted back to vars. Fix this when
michael@0 220 // we implement compiling scripts as modules.
michael@0 221 program([
michael@0 222 exportDeclaration(
michael@0 223 variableDeclaration([
michael@0 224 {
michael@0 225 id: ident("a"),
michael@0 226 init: lit(1)
michael@0 227 }, {
michael@0 228 id: ident("b"),
michael@0 229 init: lit(2)
michael@0 230 }
michael@0 231 ]),
michael@0 232 null,
michael@0 233 null
michael@0 234 )
michael@0 235 ]).assert(Reflect.parse("export let a = 1, b = 2;"));
michael@0 236
michael@0 237 // NOTE: binding lists are treated as if they were let declarations by esprima,
michael@0 238 // so we follow that convention.
michael@0 239 program([
michael@0 240 exportDeclaration(
michael@0 241 variableDeclaration([
michael@0 242 {
michael@0 243 id: ident("a"),
michael@0 244 init: lit(1)
michael@0 245 }, {
michael@0 246 id: ident("b"),
michael@0 247 init: lit(2)
michael@0 248 }
michael@0 249 ]),
michael@0 250 null,
michael@0 251 null
michael@0 252 )
michael@0 253 ]).assert(Reflect.parse("export a = 1, b = 2;"));
michael@0 254
michael@0 255 var loc = Reflect.parse("export { a as b } from 'c'", {
michael@0 256 loc: true
michael@0 257 }).body[0].loc;
michael@0 258
michael@0 259 assertEq(loc.start.line, 1);
michael@0 260 assertEq(loc.start.column, 0);
michael@0 261 assertEq(loc.start.line, 1);
michael@0 262 assertEq(loc.end.column, 26);
michael@0 263
michael@0 264 assertThrowsInstanceOf(function () {
michael@0 265 Reflect.parse("function f() { export a }");
michael@0 266 }, SyntaxError);
michael@0 267
michael@0 268 assertThrowsInstanceOf(function () {
michael@0 269 Reflect.parse("if (true) export a");
michael@0 270 }, SyntaxError);
michael@0 271
michael@0 272 assertThrowsInstanceOf(function() {
michael@0 273 Reflect.parse("export {");
michael@0 274 }, SyntaxError);
michael@0 275
michael@0 276 assertThrowsInstanceOf(function() {
michael@0 277 Reflect.parse("export {} from");
michael@0 278 }, SyntaxError);
michael@0 279
michael@0 280 assertThrowsInstanceOf(function() {
michael@0 281 Reflect.parse("export {,} from 'a'");
michael@0 282 }, SyntaxError);
michael@0 283
michael@0 284 assertThrowsInstanceOf(function() {
michael@0 285 Reflect.parse("export { true as a } from 'b'");
michael@0 286 }, SyntaxError);
michael@0 287
michael@0 288 assertThrowsInstanceOf(function () {
michael@0 289 Reflect.parse("export { a } from 'b' f();");
michael@0 290 }, SyntaxError);
michael@0 291
michael@0 292 assertThrowsInstanceOf(function () {
michael@0 293 Reflect.parse("export * from 'b' f();");
michael@0 294 }, SyntaxError);
michael@0 295
michael@0 296 assertThrowsInstanceOf(function() {
michael@0 297 Reflect.parse("export {}\nfrom ()");
michael@0 298 }, SyntaxError);

mercurial