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IAAI,IAAI,GAAW,KAAK,CAAC,CAAC,CAAC,CAAC;YAC5B,IAAI,IAAI,CAAC,WAAW,EAAE,KAAK,IAAI,EAAE;gBAC/B,2DAA2D;gBAC3D,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;aAC3B;YACD,IAAI,CAAC,KAAK,CAAC,EAAE;gBACX,sDAAsD;gBACtD,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE;oBAChC,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC;iBACnB;aACF;iBAAM;gBACL,qEAAqE;gBACrE,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;aACrD;YACD,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;SACjB;QACD,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACxB,CAAC;CACF;AApED,sCAoEC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport * as ts from 'typescript';\n\n/**\n * Helpers for validating various text string formats.\n */\nexport class SyntaxHelpers {\n /**\n * Tests whether the input string is safe to use as an ECMAScript identifier without quotes.\n *\n * @remarks\n * For example:\n *\n * ```ts\n * class X {\n * public okay: number = 1;\n * public \"not okay!\": number = 2;\n * }\n * ```\n *\n * A precise check is extremely complicated and highly dependent on the ECMAScript standard version\n * and how faithfully the interpreter implements it. To keep things simple, `isSafeUnquotedMemberIdentifier()`\n * conservatively accepts any identifier that would be valid with ECMAScript 5, and returns false otherwise.\n */\n public static isSafeUnquotedMemberIdentifier(identifier: string): boolean {\n if (identifier.length === 0) {\n return false; // cannot be empty\n }\n\n if (!ts.isIdentifierStart(identifier.charCodeAt(0), ts.ScriptTarget.ES5)) {\n return false;\n }\n\n for (let i: number = 1; i < identifier.length; i++) {\n if (!ts.isIdentifierPart(identifier.charCodeAt(i), ts.ScriptTarget.ES5)) {\n return false;\n }\n }\n\n return true;\n }\n\n /**\n * Given an arbitrary input string, return a regular TypeScript identifier name.\n *\n * @remarks\n * Example input: \"api-extractor-lib1-test\"\n * Example output: \"apiExtractorLib1Test\"\n */\n public static makeCamelCaseIdentifier(input: string): string {\n const parts: string[] = input.split(/\\W+/).filter((x) => x.length > 0);\n if (parts.length === 0) {\n return '_';\n }\n\n for (let i: number = 0; i < parts.length; ++i) {\n let part: string = parts[i];\n if (part.toUpperCase() === part) {\n // Preserve existing case unless the part is all upper-case\n part = part.toLowerCase();\n }\n if (i === 0) {\n // If the first part starts with a number, prepend \"_\"\n if (/[0-9]/.test(part.charAt(0))) {\n part = '_' + part;\n }\n } else {\n // Capitalize the first letter of each part, except for the first one\n part = part.charAt(0).toUpperCase() + part.slice(1);\n }\n parts[i] = part;\n }\n return parts.join('');\n }\n}\n"]} |