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.

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

mercurial