| 1 |
// |jit-test| --enable-import-attributes |
| 2 |
|
| 3 |
// Test importEntries property |
| 4 |
|
| 5 |
function attributeEq(actual, expected) { |
| 6 |
|
| 7 |
return actual.moduleType === expected.moduleType; |
| 8 |
} |
| 9 |
|
| 10 |
function importEntryEq(a, b) { |
| 11 |
var r1 = a['moduleRequest']['specifier'] === b['moduleRequest']['specifier'] && |
| 12 |
a['importName'] === b['importName'] && |
| 13 |
a['localName'] === b['localName']; |
| 14 |
|
| 15 |
return r1 && attributeEq(a['moduleRequest'], b['moduleRequest']); |
| 16 |
} |
| 17 |
|
| 18 |
function findImportEntry(array, target) |
| 19 |
{ |
| 20 |
for (let i = 0; i < array.length; i++) { |
| 21 |
if (importEntryEq(array[i], target)) |
| 22 |
return i; |
| 23 |
} |
| 24 |
return -1; |
| 25 |
} |
| 26 |
|
| 27 |
function testImportEntries(source, expected) { |
| 28 |
var module = parseModule(source); |
| 29 |
var actual = module.importEntries.slice(0); |
| 30 |
assertEq(actual.length, expected.length); |
| 31 |
for (var i = 0; i < expected.length; i++) { |
| 32 |
let index = findImportEntry(actual, expected[i]); |
| 33 |
assertEq(index >= 0, true); |
| 34 |
actual.splice(index, 1); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
testImportEntries('', []); |
| 39 |
|
| 40 |
testImportEntries('import v from "mod";', |
| 41 |
[{moduleRequest: {specifier: 'mod', moduleType: 'js'}, importName: 'default', localName: 'v'}]); |
| 42 |
|
| 43 |
testImportEntries('import * as ns from "mod";', |
| 44 |
[{moduleRequest: {specifier: 'mod', moduleType: 'js'}, importName: null, localName: 'ns'}]); |
| 45 |
|
| 46 |
testImportEntries('import {x} from "mod";', |
| 47 |
[{moduleRequest: {specifier: 'mod', moduleType: 'js'}, importName: 'x', localName: 'x'}]); |
| 48 |
|
| 49 |
testImportEntries('import {x as v} from "mod";', |
| 50 |
[{moduleRequest: {specifier: 'mod', moduleType: 'js'}, importName: 'x', localName: 'v'}]); |
| 51 |
|
| 52 |
testImportEntries('import "mod";', |
| 53 |
[]); |
| 54 |
|
| 55 |
testImportEntries('import {x} from "a"; import {y} from "b";', |
| 56 |
[{moduleRequest: {specifier: 'a', moduleType: 'js'}, importName: 'x', localName: 'x'}, |
| 57 |
{moduleRequest: {specifier: 'b', moduleType: 'js'}, importName: 'y', localName: 'y'}]); |
| 58 |
|
| 59 |
|
| 60 |
if (getRealmConfiguration("importAttributes")) { |
| 61 |
testImportEntries('import v from "mod" with {};', |
| 62 |
[{moduleRequest: {specifier: 'mod', moduleType: 'js'}, importName: 'default', localName: 'v'}]); |
| 63 |
|
| 64 |
testImportEntries('import v from "mod" with { type: "json"};', |
| 65 |
[{moduleRequest: {specifier: 'mod', moduleType: 'json'}, importName: 'default', localName: 'v'}]); |
| 66 |
|
| 67 |
testImportEntries('import {x} from "mod" with { type: "json"};', |
| 68 |
[{moduleRequest: {specifier: 'mod', moduleType: 'json'}, importName: 'x', localName: 'x'}]); |
| 69 |
|
| 70 |
testImportEntries('import {x as v} from "mod" with { type: "json"};', |
| 71 |
[{moduleRequest: {specifier: 'mod', moduleType: 'json'}, importName: 'x', localName: 'v'}]); |
| 72 |
} |