| 233 | * @returns {ImportAttributes | undefined} import attributes |
| 234 | */ |
| 235 | const getImportAttributes = (node) => { |
| 236 | if (node.type === "ImportExpression") { |
| 237 | if ( |
| 238 | node.options && |
| 239 | node.options.type === "ObjectExpression" && |
| 240 | node.options.properties[0] && |
| 241 | node.options.properties[0].type === "Property" && |
| 242 | node.options.properties[0].key.type === "Identifier" && |
| 243 | (node.options.properties[0].key.name === "with" || |
| 244 | node.options.properties[0].key.name === "assert") && |
| 245 | node.options.properties[0].value.type === "ObjectExpression" && |
| 246 | node.options.properties[0].value.properties.length > 0 |
| 247 | ) { |
| 248 | const properties = |
| 249 | /** @type {Property[]} */ |
| 250 | (node.options.properties[0].value.properties); |
| 251 | const result = /** @type {ImportAttributes} */ ({}); |
| 252 | for (const property of properties) { |
| 253 | const key = |
| 254 | /** @type {string} */ |
| 255 | ( |
| 256 | property.key.type === "Identifier" |
| 257 | ? property.key.name |
| 258 | : /** @type {Literal} */ (property.key).value |
| 259 | ); |
| 260 | result[key] = |
| 261 | /** @type {string} */ |
| 262 | (/** @type {Literal} */ (property.value).value); |
| 263 | } |
| 264 | const key = |
| 265 | node.options.properties[0].key.type === "Identifier" |
| 266 | ? node.options.properties[0].key.name |
| 267 | : /** @type {Literal} */ (node.options.properties[0].key).value; |
| 268 | |
| 269 | if (key === "assert") { |
| 270 | result._isLegacyAssert = true; |
| 271 | } |
| 272 | |
| 273 | return result; |
| 274 | } |
| 275 | |
| 276 | return; |
| 277 | } |
| 278 | |
| 279 | if (node.attributes === undefined || node.attributes.length === 0) { |
| 280 | return; |
| 281 | } |
| 282 | |
| 283 | const result = /** @type {ImportAttributes} */ ({}); |
| 284 | |
| 285 | for (const attribute of node.attributes) { |
| 286 | const key = |
| 287 | /** @type {string} */ |
| 288 | ( |
| 289 | attribute.key.type === "Identifier" |
| 290 | ? attribute.key.name |
| 291 | : attribute.key.value |
| 292 | ); |