requested-modules.js (4305B)
1 // |jit-test| 2 3 // Test requestedModules property 4 5 function testRequestedModules(source, expected) { 6 var module = parseModule(source); 7 var actual = module.requestedModules; 8 assertEq(actual.length, expected.length); 9 for (var i = 0; i < actual.length; i++) { 10 assertEq(actual[i].moduleRequest.specifier, expected[i].specifier); 11 assertEq(actual[i].moduleRequest.moduleType, expected[i].moduleType); 12 if (actual[i].moduleRequest.firstUnsupportedAttributeKey != expected[i].firstUnsupportedAttributeKey) { 13 assertEq(true, false); 14 } 15 } 16 } 17 18 testRequestedModules("", []); 19 20 testRequestedModules("import a from 'foo'", [ 21 { specifier: 'foo', moduleType: 'js' } 22 ]); 23 24 testRequestedModules("import a from 'foo'; import b from 'bar'", [ 25 { specifier: 'foo', moduleType: 'js' }, 26 { specifier: 'bar', moduleType: 'js' } 27 ]); 28 29 testRequestedModules("import a from 'foo'; import b from 'foo'", [ 30 { specifier: 'foo', moduleType: 'js' } 31 ]); 32 33 testRequestedModules("import a from 'foo'; import b from 'bar'; import c from 'foo'", [ 34 { specifier: 'foo', moduleType: 'js' }, 35 { specifier: 'bar', moduleType: 'js' } 36 ]); 37 38 testRequestedModules("export {} from 'foo'", [ 39 { specifier: 'foo', moduleType: 'js' } 40 ]); 41 42 testRequestedModules("export * from 'bar'",[ 43 { specifier: 'bar', moduleType: 'js' } 44 ]); 45 46 testRequestedModules("import a from 'foo'; export {} from 'bar'; export * from 'baz'", [ 47 { specifier: 'foo', moduleType: 'js' }, 48 { specifier: 'bar', moduleType: 'js' }, 49 { specifier: 'baz', moduleType: 'js' } 50 ]); 51 52 testRequestedModules("import a from 'foo' with {}", [ 53 { specifier: 'foo', moduleType: 'js' }, 54 ]); 55 56 testRequestedModules("import a from 'foo' with { type: 'json'}", [ 57 { specifier: 'foo', moduleType: 'json' }, 58 ]); 59 60 testRequestedModules("import a from 'foo' with { unsupported: 'test'}", [ 61 { specifier: 'foo', moduleType: 'js', firstUnsupportedAttributeKey: 'unsupported'}, 62 ]); 63 64 testRequestedModules("import a from 'foo' with { unsupported: 'test', type: 'js', foo: 'bar' }", [ 65 { specifier: 'foo', moduleType: 'unknown', firstUnsupportedAttributeKey: 'unsupported' }, 66 ]); 67 68 testRequestedModules("import a from 'foo' with { type: 'js1'}; export {} from 'bar' with { type: 'js2'}; export * from 'baz' with { type: 'js3'}", [ 69 { specifier: 'foo', moduleType: 'unknown' }, 70 { specifier: 'bar', moduleType: 'unknown' }, 71 { specifier: 'baz', moduleType: 'unknown' } 72 ]); 73 74 testRequestedModules("export {} from 'foo' with { type: 'js'}", [ 75 { specifier: 'foo', moduleType: 'unknown' } 76 ]); 77 78 testRequestedModules("export * from 'bar' with { type: 'json'}",[ 79 { specifier: 'bar', moduleType: 'json' } 80 ]); 81 82 testRequestedModules("import a from 'foo'; import b from 'bar' with { type: 'json' };", [ 83 { specifier: 'foo', moduleType: 'js' }, 84 { specifier: 'bar', moduleType: 'json' }, 85 ]); 86 87 testRequestedModules("import a from 'foo'; import b from 'foo' with { type: 'json' };", [ 88 { specifier: 'foo', moduleType: 'js' }, 89 { specifier: 'foo', moduleType: 'json' }, 90 ]); 91 92 testRequestedModules("import a from 'foo'; import b from 'foo' with { type: 'js1' };", [ 93 { specifier: 'foo', moduleType: 'js' }, 94 { specifier: 'foo', moduleType: 'unknown' }, 95 ]); 96 97 testRequestedModules("import a from 'foo'; import b from 'foo' with { type: 'json' }; import c from 'foo' with { type: 'json' };", [ 98 { specifier: 'foo', moduleType: 'js' }, 99 { specifier: 'foo', moduleType: 'json' } 100 ]); 101 102 testRequestedModules("import a from 'foo'; import b from 'foo' with { type: 'json' }; import c from 'foo' with { type: 'json', foo: 'bar'};", [ 103 { specifier: 'foo', moduleType: 'js' }, 104 { specifier: 'foo', moduleType: 'json' }, 105 { specifier: 'foo', moduleType: 'json', firstUnsupportedAttributeKey: 'foo' } 106 ]); 107 108 testRequestedModules("import a from 'foo' with { type: 'json' }; import b from 'foo' with { type: 'json' };", [ 109 { specifier: 'foo', moduleType: 'json' }, 110 ]); 111 112 testRequestedModules("import b from 'bar' with { type: 'json' }; import a from 'foo';", [ 113 { specifier: 'bar', moduleType: 'json' }, 114 { specifier: 'foo', moduleType: 'js' }, 115 ]); 116 117 testRequestedModules("export {} from 'foo' with { type: 'someValueThatWillNeverBeSupported'}", [ 118 { specifier: 'foo', moduleType: 'unknown' } 119 ]);