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

Function parseIdentifierName

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

sourceToOffsetPosMethod · 0.80
nextMethod · 0.80
checkReservedWordMethod · 0.45

Tested by

no test coverage detected