{"version":3,"file":"_accessExpressionAsString.mjs","names":[],"sources":["../../src/internal/_accessExpressionAsString.ts"],"sourcesContent":["/**\n * Write a property access on a key as source text.\n *\n * A key that is a legal ASCII identifier and not a reserved word becomes\n * `.key`, and any other key becomes `[\"key\"]` with a JSON string literal.\n *\n * @evidence contracts/common.md#principled-implementation A key that is a legal ASCII identifier and not a reserved word is written as a dot access, and every other key as a bracket access with a JSON string literal, which is a valid JavaScript string literal for any key, so the emitted access expression is correct for every property name. The reserved list is conservative for dot access, which is legal after a dot, so it can only cause an extra bracket form; the strict-mode future reserved words are not in the list.\n * @evidence contracts/common.md#clear-and-simple-design One function with two private helpers, the identifier test and the reserved set.\n * @evidence contracts/common.md#prohibited-implementation-shortcuts The decision is purely lexical and no property name is special-cased.\n * @evidence contracts/common.md#meaningful-documentation The doc states the dot and bracket forms and why bracket access is always safe.\n */\nexport const _accessExpressionAsString = (str: string): string =>\n  variable(str) ? `.${str}` : `[${JSON.stringify(str)}]`;\n\nconst variable = (str: string): boolean =>\n  reserved(str) === false && /^[a-zA-Z_$][a-zA-Z_$0-9]*$/g.test(str);\n\nconst reserved = (str: string): boolean => RESERVED.has(str);\n\nconst RESERVED: Set<string> = new Set([\n  \"break\",\n  \"case\",\n  \"catch\",\n  \"class\",\n  \"const\",\n  \"continue\",\n  \"debugger\",\n  \"default\",\n  \"delete\",\n  \"do\",\n  \"else\",\n  \"enum\",\n  \"export\",\n  \"extends\",\n  \"false\",\n  \"finally\",\n  \"for\",\n  \"function\",\n  \"if\",\n  \"import\",\n  \"in\",\n  \"instanceof\",\n  \"new\",\n  \"null\",\n  \"return\",\n  \"super\",\n  \"switch\",\n  \"this\",\n  \"throw\",\n  \"true\",\n  \"try\",\n  \"typeof\",\n  \"var\",\n  \"void\",\n  \"while\",\n  \"with\",\n]);\n"],"mappings":";;;;;;;;;;;;AAWA,MAAa,6BAA6B,QACxC,SAAS,GAAG,IAAI,IAAI,QAAQ,IAAI,KAAK,UAAU,GAAG,EAAE;AAEtD,MAAM,YAAY,QAChB,SAAS,GAAG,MAAM,SAAS,8BAA8B,KAAK,GAAG;AAEnE,MAAM,YAAY,QAAyB,SAAS,IAAI,GAAG;AAE3D,MAAM,2BAAwB,IAAI,IAAI;CACpC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}