MCPcopy Create free account
hub / github.com/babel/babel / parseImportAttributes

Function parseImportAttributes

packages/babel-parser/src/parser/statement.ts:3161–3209  ·  view source on GitHub ↗

* parse assert entries * * @see https://tc39.es/proposal-import-attributes/#prod-WithEntries WithEntries

()

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 7

matchMethod · 0.80
parseStringLiteralMethod · 0.80
parseIdentifierMethod · 0.80
finishNodeMethod · 0.80
hasMethod · 0.45
addMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected