|
| 1 | +// Tests for `ExportNamedDeclaration` |
| 2 | + |
| 3 | +if (typeof exports !== "undefined") { |
| 4 | + var driver = require("./driver.js"); |
| 5 | + var test = driver.test, testFail = driver.testFail; |
| 6 | +} |
| 7 | + |
| 8 | +//------------------------------------------------------------------------------ |
| 9 | +// export {x} from "source" |
| 10 | +//------------------------------------------------------------------------------ |
| 11 | + |
| 12 | +test("export {x} from \"source\"", { |
| 13 | + "type": "Program", |
| 14 | + "start": 0, |
| 15 | + "end": 24, |
| 16 | + "body": [ |
| 17 | + { |
| 18 | + "type": "ExportNamedDeclaration", |
| 19 | + "start": 0, |
| 20 | + "end": 24, |
| 21 | + "declaration": null, |
| 22 | + "specifiers": [ |
| 23 | + { |
| 24 | + "type": "ExportSpecifier", |
| 25 | + "start": 8, |
| 26 | + "end": 9, |
| 27 | + "local": { |
| 28 | + "type": "Identifier", |
| 29 | + "start": 8, |
| 30 | + "end": 9, |
| 31 | + "name": "x" |
| 32 | + }, |
| 33 | + "exported": { |
| 34 | + "type": "Identifier", |
| 35 | + "start": 8, |
| 36 | + "end": 9, |
| 37 | + "name": "x" |
| 38 | + } |
| 39 | + } |
| 40 | + ], |
| 41 | + "source": { |
| 42 | + "type": "Literal", |
| 43 | + "start": 16, |
| 44 | + "end": 24, |
| 45 | + "value": "source", |
| 46 | + "raw": "\"source\"" |
| 47 | + }, |
| 48 | + "attributes": [] |
| 49 | + } |
| 50 | + ], |
| 51 | + "sourceType": "module" |
| 52 | +}, { sourceType: "module", ecmaVersion: 16 }) |
| 53 | + |
| 54 | +test("export {x as y} from \"source\"", { |
| 55 | + "type": "Program", |
| 56 | + "start": 0, |
| 57 | + "end": 29, |
| 58 | + "body": [ |
| 59 | + { |
| 60 | + "type": "ExportNamedDeclaration", |
| 61 | + "start": 0, |
| 62 | + "end": 29, |
| 63 | + "declaration": null, |
| 64 | + "specifiers": [ |
| 65 | + { |
| 66 | + "type": "ExportSpecifier", |
| 67 | + "start": 8, |
| 68 | + "end": 14, |
| 69 | + "local": { |
| 70 | + "type": "Identifier", |
| 71 | + "start": 8, |
| 72 | + "end": 9, |
| 73 | + "name": "x" |
| 74 | + }, |
| 75 | + "exported": { |
| 76 | + "type": "Identifier", |
| 77 | + "start": 13, |
| 78 | + "end": 14, |
| 79 | + "name": "y" |
| 80 | + } |
| 81 | + } |
| 82 | + ], |
| 83 | + "source": { |
| 84 | + "type": "Literal", |
| 85 | + "start": 21, |
| 86 | + "end": 29, |
| 87 | + "value": "source", |
| 88 | + "raw": "\"source\"" |
| 89 | + }, |
| 90 | + "attributes": [] |
| 91 | + } |
| 92 | + ], |
| 93 | + "sourceType": "module" |
| 94 | +}, { sourceType: "module", ecmaVersion: 16 }) |
| 95 | + |
| 96 | +//------------------------------------------------------------------------------ |
| 97 | +// export {x} |
| 98 | +//------------------------------------------------------------------------------ |
| 99 | + |
| 100 | +test("let x; export {x};", { |
| 101 | + "type": "Program", |
| 102 | + "start": 0, |
| 103 | + "end": 18, |
| 104 | + "body": [ |
| 105 | + { |
| 106 | + "type": "VariableDeclaration", |
| 107 | + "start": 0, |
| 108 | + "end": 6, |
| 109 | + "declarations": [ |
| 110 | + { |
| 111 | + "type": "VariableDeclarator", |
| 112 | + "start": 4, |
| 113 | + "end": 5, |
| 114 | + "id": { |
| 115 | + "type": "Identifier", |
| 116 | + "start": 4, |
| 117 | + "end": 5, |
| 118 | + "name": "x" |
| 119 | + }, |
| 120 | + "init": null |
| 121 | + } |
| 122 | + ], |
| 123 | + "kind": "let" |
| 124 | + }, |
| 125 | + { |
| 126 | + "type": "ExportNamedDeclaration", |
| 127 | + "start": 7, |
| 128 | + "end": 18, |
| 129 | + "declaration": null, |
| 130 | + "specifiers": [ |
| 131 | + { |
| 132 | + "type": "ExportSpecifier", |
| 133 | + "start": 15, |
| 134 | + "end": 16, |
| 135 | + "local": { |
| 136 | + "type": "Identifier", |
| 137 | + "start": 15, |
| 138 | + "end": 16, |
| 139 | + "name": "x" |
| 140 | + }, |
| 141 | + "exported": { |
| 142 | + "type": "Identifier", |
| 143 | + "start": 15, |
| 144 | + "end": 16, |
| 145 | + "name": "x" |
| 146 | + } |
| 147 | + } |
| 148 | + ], |
| 149 | + "source": null, |
| 150 | + "attributes": [] |
| 151 | + } |
| 152 | + ], |
| 153 | + "sourceType": "module" |
| 154 | +}, { sourceType: "module", ecmaVersion: 16 }) |
| 155 | + |
| 156 | +test("let x; export {x as y};", { |
| 157 | + "type": "Program", |
| 158 | + "start": 0, |
| 159 | + "end": 23, |
| 160 | + "body": [ |
| 161 | + { |
| 162 | + "type": "VariableDeclaration", |
| 163 | + "start": 0, |
| 164 | + "end": 6, |
| 165 | + "declarations": [ |
| 166 | + { |
| 167 | + "type": "VariableDeclarator", |
| 168 | + "start": 4, |
| 169 | + "end": 5, |
| 170 | + "id": { |
| 171 | + "type": "Identifier", |
| 172 | + "start": 4, |
| 173 | + "end": 5, |
| 174 | + "name": "x" |
| 175 | + }, |
| 176 | + "init": null |
| 177 | + } |
| 178 | + ], |
| 179 | + "kind": "let" |
| 180 | + }, |
| 181 | + { |
| 182 | + "type": "ExportNamedDeclaration", |
| 183 | + "start": 7, |
| 184 | + "end": 23, |
| 185 | + "declaration": null, |
| 186 | + "specifiers": [ |
| 187 | + { |
| 188 | + "type": "ExportSpecifier", |
| 189 | + "start": 15, |
| 190 | + "end": 21, |
| 191 | + "local": { |
| 192 | + "type": "Identifier", |
| 193 | + "start": 15, |
| 194 | + "end": 16, |
| 195 | + "name": "x" |
| 196 | + }, |
| 197 | + "exported": { |
| 198 | + "type": "Identifier", |
| 199 | + "start": 20, |
| 200 | + "end": 21, |
| 201 | + "name": "y" |
| 202 | + } |
| 203 | + } |
| 204 | + ], |
| 205 | + "source": null, |
| 206 | + "attributes": [] |
| 207 | + } |
| 208 | + ], |
| 209 | + "sourceType": "module" |
| 210 | +}, {sourceType: "module", ecmaVersion: 16}) |
| 211 | + |
| 212 | +testFail("export {x} from \"source\"", "'import' and 'export' may appear only with 'sourceType: module' (1:0)", { sourceType: "script", ecmaVersion: 11 }) |
| 213 | +testFail("export {x as y} from \"source\"", "'import' and 'export' may appear only with 'sourceType: module' (1:0)", { sourceType: "script", ecmaVersion: 11 }) |
| 214 | +testFail("export {x}; let x;", "'import' and 'export' may appear only with 'sourceType: module' (1:0)", { sourceType: "script", ecmaVersion: 11 }) |
| 215 | +testFail("export {x as y}; let x;", "'import' and 'export' may appear only with 'sourceType: module' (1:0)", { sourceType: "script", ecmaVersion: 11 }) |
0 commit comments