js/src/jit-test/tests/modules/import-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 importDeclaration = (specifiers, source) => Pattern({
michael@0 11 type: "ImportDeclaration",
michael@0 12 specifiers: specifiers,
michael@0 13 source: source
michael@0 14 });
michael@0 15 importSpecifier = (id, name) => Pattern({
michael@0 16 type: "ImportSpecifier",
michael@0 17 id: id,
michael@0 18 name: name
michael@0 19 });
michael@0 20 ident = (name) => Pattern({
michael@0 21 type: "Identifier",
michael@0 22 name: name
michael@0 23 })
michael@0 24 lit = (val) => Pattern({
michael@0 25 type: "Literal",
michael@0 26 value: val
michael@0 27 })
michael@0 28
michael@0 29 program([
michael@0 30 importDeclaration(
michael@0 31 [
michael@0 32 importSpecifier(
michael@0 33 ident("default"),
michael@0 34 ident("a")
michael@0 35 )
michael@0 36 ],
michael@0 37 lit("b")
michael@0 38 )
michael@0 39 ]).assert(Reflect.parse("import a from 'b'"));
michael@0 40
michael@0 41 program([
michael@0 42 importDeclaration(
michael@0 43 [],
michael@0 44 lit("a")
michael@0 45 )
michael@0 46 ]).assert(Reflect.parse("import {} from 'a'"));
michael@0 47
michael@0 48 program([
michael@0 49 importDeclaration(
michael@0 50 [
michael@0 51 importSpecifier(
michael@0 52 ident("a"),
michael@0 53 ident("a")
michael@0 54 )
michael@0 55 ],
michael@0 56 lit("b")
michael@0 57 )
michael@0 58 ]).assert(Reflect.parse("import { a } from 'b'"));
michael@0 59
michael@0 60 program([
michael@0 61 importDeclaration(
michael@0 62 [
michael@0 63 importSpecifier(
michael@0 64 ident("a"),
michael@0 65 ident("a")
michael@0 66 )
michael@0 67 ],
michael@0 68 lit("b")
michael@0 69 )
michael@0 70 ]).assert(Reflect.parse("import { a, } from 'b'"));
michael@0 71
michael@0 72 program([
michael@0 73 importDeclaration(
michael@0 74 [
michael@0 75 importSpecifier(
michael@0 76 ident("a"),
michael@0 77 ident("b")
michael@0 78 )
michael@0 79 ],
michael@0 80 lit("c")
michael@0 81 )
michael@0 82 ]).assert(Reflect.parse("import { a as b } from 'c'"));
michael@0 83
michael@0 84 program([
michael@0 85 importDeclaration(
michael@0 86 [
michael@0 87 importSpecifier(
michael@0 88 ident("as"),
michael@0 89 ident("as")
michael@0 90 )
michael@0 91 ],
michael@0 92 lit("a")
michael@0 93 )
michael@0 94 ]).assert(Reflect.parse("import { as as as } from 'a'"));
michael@0 95
michael@0 96 program([
michael@0 97 importDeclaration(
michael@0 98 [
michael@0 99 importSpecifier(
michael@0 100 ident("true"),
michael@0 101 ident("a")
michael@0 102 )
michael@0 103 ],
michael@0 104 lit("b")
michael@0 105 )
michael@0 106 ]).assert(Reflect.parse("import { true as a } from 'b'"));
michael@0 107
michael@0 108 program([
michael@0 109 importDeclaration(
michael@0 110 [
michael@0 111 importSpecifier(
michael@0 112 ident("a"),
michael@0 113 ident("a")
michael@0 114 ),
michael@0 115 importSpecifier(
michael@0 116 ident("b"),
michael@0 117 ident("b")
michael@0 118 ),
michael@0 119 ],
michael@0 120 lit("c")
michael@0 121 )
michael@0 122 ]).assert(Reflect.parse("import { a, b } from 'c'"));
michael@0 123
michael@0 124 program([
michael@0 125 importDeclaration(
michael@0 126 [
michael@0 127 importSpecifier(
michael@0 128 ident("a"),
michael@0 129 ident("b")
michael@0 130 ),
michael@0 131 importSpecifier(
michael@0 132 ident("c"),
michael@0 133 ident("d")
michael@0 134 ),
michael@0 135 ],
michael@0 136 lit("e")
michael@0 137 )
michael@0 138 ]).assert(Reflect.parse("import { a as b, c as d } from 'e'"));
michael@0 139
michael@0 140 program([
michael@0 141 importDeclaration(
michael@0 142 [],
michael@0 143 lit("a")
michael@0 144 )
michael@0 145 ]).assert(Reflect.parse("import 'a'"));
michael@0 146
michael@0 147 var loc = Reflect.parse("import { a as b } from 'c'", {
michael@0 148 loc: true
michael@0 149 }).body[0].loc;
michael@0 150
michael@0 151 assertEq(loc.start.line, 1);
michael@0 152 assertEq(loc.start.column, 0);
michael@0 153 assertEq(loc.start.line, 1);
michael@0 154 assertEq(loc.end.column, 26);
michael@0 155
michael@0 156 assertThrowsInstanceOf(function () {
michael@0 157 Reflect.parse("function f() { import a from 'b' }");
michael@0 158 }, SyntaxError);
michael@0 159
michael@0 160 assertThrowsInstanceOf(function () {
michael@0 161 Reflect.parse("if (true) import a from 'b'");
michael@0 162 }, SyntaxError);
michael@0 163
michael@0 164 assertThrowsInstanceOf(function() {
michael@0 165 Reflect.parse("import {");
michael@0 166 }, SyntaxError);
michael@0 167
michael@0 168 assertThrowsInstanceOf(function() {
michael@0 169 Reflect.parse("import {}");
michael@0 170 }, SyntaxError);
michael@0 171
michael@0 172 assertThrowsInstanceOf(function() {
michael@0 173 Reflect.parse("import {} from");
michael@0 174 }, SyntaxError);
michael@0 175
michael@0 176 assertThrowsInstanceOf(function() {
michael@0 177 Reflect.parse("import {,} from 'a'");
michael@0 178 }, SyntaxError);
michael@0 179
michael@0 180 assertThrowsInstanceOf(function() {
michael@0 181 Reflect.parse("import { a as true } from 'b'");
michael@0 182 }, SyntaxError);
michael@0 183
michael@0 184 assertThrowsInstanceOf(function() {
michael@0 185 Reflect.parse("import { true } from 'a'");
michael@0 186 }, SyntaxError);

mercurial