* parse assert entries * * @see https://tc39.es/proposal-import-attributes/#prod-WithEntries WithEntries
()
| 3163 | * @see {@link https://tc39.es/proposal-import-attributes/#prod-WithEntries WithEntries} |
| 3164 | */ |
| 3165 | parseImportAttributes(): N.ImportAttribute[] { |
| 3166 | this.expect(tt.braceL); |
| 3167 | |
| 3168 | const attrs = []; |
| 3169 | const attrNames = new Set(); |
| 3170 | |
| 3171 | do { |
| 3172 | if (this.match(tt.braceR)) { |
| 3173 | break; |
| 3174 | } |
| 3175 | |
| 3176 | const node = this.startNode<N.ImportAttribute>(); |
| 3177 | |
| 3178 | // parse AssertionKey : IdentifierName, StringLiteral |
| 3179 | const keyName = this.state.value; |
| 3180 | // check if we already have an entry for an attribute |
| 3181 | // if a duplicate entry is found, throw an error |
| 3182 | // for now this logic will come into play only when someone declares `type` twice |
| 3183 | if (attrNames.has(keyName)) { |
| 3184 | this.raise( |
| 3185 | Errors.ModuleAttributesWithDuplicateKeys, |
| 3186 | this.state.startLoc, |
| 3187 | { |
| 3188 | key: keyName, |
| 3189 | }, |
| 3190 | ); |
| 3191 | } |
| 3192 | attrNames.add(keyName); |
| 3193 | if (this.match(tt.string)) { |
| 3194 | node.key = this.parseStringLiteral(keyName); |
| 3195 | } else { |
| 3196 | node.key = this.parseIdentifier(true); |
| 3197 | } |
| 3198 | this.expect(tt.colon); |
| 3199 | |
| 3200 | if (!this.match(tt.string)) { |
| 3201 | throw this.raise( |
| 3202 | Errors.ModuleAttributeInvalidValue, |
| 3203 | this.state.startLoc, |
| 3204 | ); |
| 3205 | } |
| 3206 | node.value = this.parseStringLiteral(this.state.value); |
| 3207 | attrs.push(this.finishNode(node, "ImportAttribute")); |
| 3208 | } while (this.eat(tt.comma)); |
| 3209 | |
| 3210 | this.expect(tt.braceR); |
| 3211 | |
| 3212 | return attrs; |
| 3213 | } |
| 3214 | |
| 3215 | maybeParseImportAttributes( |
| 3216 | node: Undone< |
nothing calls this directly
no test coverage detected