Repository: microsoft/TypeScript
File: tests/baselines/reference/enumMemberNameNonIdentifier.js (JavaScript)

Code before:

// This should use dot notation since "regular" is a valid identifier
export const d = E.regular;

// Greek Capital Yot (U+037F) - valid in ES2015+ but NOT in ES5
// Because isIdentifierText uses ES5, this will use indexed access syntax
export const e = E.Ϳ;

// Function returning specific enum member type
export function getHyphenMember(): typeof E["hyphen-member"] {
    return E["hyphen-member"];
}


//// [enumMemberNameNonIdentifier.js]
// Enum members with names that are not valid ES5 identifiers
// should use indexed access syntax in declaration emit
// These should infer types that use indexed access syntax 
// because the member names are not valid ES5 identifiers
export const a = 1 /* E["hyphen-member"] */;
export const b = 2 /* E["123startsWithNumber"] */;
export const c = 3 /* E["has space"] */;
// This should use dot notation since "regular" is a valid identifier
export const d = 0 /* E.regular */;
// Greek Capital Yot (U+037F) - valid in ES2015+ but NOT in ES5
// Because isIdentifierText uses ES5, this will use indexed access syntax
export const e = 4 /* E.Ϳ */;
// Function returning specific enum member type
export function getHyphenMember() {
    return 1 /* E["hyphen-member"] */;
}


//// [enumMemberNameNonIdentifier.d.ts]
export declare const enum E {
    regular = 0,
    "hyphen-member" = 1,
    "123startsWithNumber" = 2,
    "has space" = 3,
    Ϳ = 4
}
export declare const a = E["hyphen-member"];
export declare const b = E["123startsWithNumber"];
export declare const c = E["has space"];
export declare const d = E.regular;
export declare const e = E.Ϳ;
export declare function getHyphenMember(): typeof E["hyphen-member"];


Review comment (bug):
The comment states "Because isIdentifierText uses ES5, this will use indexed access syntax" which is incorrect. After the PR changes (checker.ts now uses ScriptTarget.ESNext), the Greek Capital Yot is considered a valid identifier, and the declaration file uses dot notation (E.Ϳ on line 66). The comment should be corrected to reflect the actual behavior.

Code after:
//// [tests/cases/compiler/enumMemberNameNonIdentifier.ts] ////

//// [enumMemberNameNonIdentifier.ts]
export const enum E {
    regular = 0,
    "hyphen-member" = 1,
    "123startsWithNumber" = 2,
    "has space" = 3,
    // Greek Capital Yot (U+037F) - valid identifier in ES2015+ but NOT in ES5
    Ϳ = 4,
}

export const a = E["hyphen-member"];
export const b = E["123startsWithNumber"];
export const c = E["has space"];
export const d = E.regular;
export const e = E.Ϳ;


//// [enumMemberNameNonIdentifier.js]
export const a = 1 /* E["hyphen-member"] */;
export const b = 2 /* E["123startsWithNumber"] */;
export const c = 3 /* E["has space"] */;
export const d = 0 /* E.regular */;
export const e = 4 /* E.Ϳ */;


//// [enumMemberNameNonIdentifier.d.ts]
export declare const enum E {
    regular = 0,
    "hyphen-member" = 1,
    "123startsWithNumber" = 2,
    "has space" = 3,
    Ϳ = 4
}
export declare const a = E["hyphen-member"];
export declare const b = E["123startsWithNumber"];
export declare const c = E["has space"];
export declare const d = E.regular;
export declare const e = E.Ϳ;