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

Function parseIdentifierName

packages/babel-parser/src/parser/expression.ts:2861–2896  ·  view source on GitHub ↗
(liberal?: boolean)

Source from the content-addressed store, hash-verified

2859 }
2860
2861 parseIdentifierName(liberal?: boolean): string {
2862 let name: string;
2863
2864 const { start, type } = this.state;
2865
2866 if (tokenIsKeywordOrIdentifier(type)) {
2867 name = this.state.value;
2868 } else {
2869 this.unexpected();
2870 }
2871
2872 const tokenIsKeyword = tokenKeywordOrIdentifierIsKeyword(type);
2873
2874 if (liberal) {
2875 // If the current token is not used as a keyword, set its type to "tt.name".
2876 // This will prevent this.next() from throwing about unexpected escapes.
2877 if (tokenIsKeyword) {
2878 this.replaceToken(tt.name);
2879 }
2880 } else {
2881 // Plugins (e.g. v8intrinsic, flow) may call parseIdentifierName()
2882 // without having started a node at this token, so record the location
2883 // data for `start` in case checkReservedWord needs to raise at it.
2884 this.setLoc(this.state.startLoc);
2885 this.checkReservedWord(
2886 name!,
2887 this.sourceToOffsetPos(start),
2888 tokenIsKeyword,
2889 false,
2890 );
2891 }
2892
2893 this.next();
2894
2895 return name!;
2896 }
2897
2898 checkReservedWord(
2899 word: string,

Callers

nothing calls this directly

Calls 5

sourceToOffsetPosMethod · 0.80
nextMethod · 0.80
checkReservedWordMethod · 0.45

Tested by

no test coverage detected