Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6774,7 +6774,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return parentName;
}
const memberName = symbolName(type.symbol);
if (isIdentifierText(memberName, ScriptTarget.ES5)) {
if (isIdentifierText(memberName, ScriptTarget.ESNext)) {
return appendReferenceToType(
parentName as TypeReferenceNode | ImportTypeNode,
factory.createTypeReferenceNode(memberName, /*typeArguments*/ undefined),
Expand Down Expand Up @@ -46772,7 +46772,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
*/
function checkClassNameCollisionWithObject(name: Identifier): void {
if (
languageVersion >= ScriptTarget.ES5 && name.escapedText === "Object"
name.escapedText === "Object"
&& host.getEmitModuleFormatOfFile(getSourceFileOfNode(name)) < ModuleKind.ES2015
) {
error(name, Diagnostics.Class_name_cannot_be_Object_when_targeting_ES5_and_above_with_module_0, ModuleKind[moduleKind]); // https://github.com/Microsoft/TypeScript/issues/17494
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2625,7 +2625,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
}

const preferNewLine = node.multiLine ? ListFormat.PreferNewLine : ListFormat.None;
const allowTrailingComma = currentSourceFile && currentSourceFile.languageVersion >= ScriptTarget.ES5 && !isJsonSourceFile(currentSourceFile) ? ListFormat.AllowTrailingComma : ListFormat.None;
const allowTrailingComma = currentSourceFile && !isJsonSourceFile(currentSourceFile) ? ListFormat.AllowTrailingComma : ListFormat.None;
emitList(node, node.properties, ListFormat.ObjectLiteralExpressionProperties | allowTrailingComma | preferNewLine);

if (indentedFlag) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ export function transformTypeScript(context: TransformationContext): Transformer

function visitClassDeclaration(node: ClassDeclaration): VisitResult<Statement> {
const facts = getClassFacts(node);
const promoteToIIFE = languageVersion <= ScriptTarget.ES5 &&
const promoteToIIFE = languageVersion < ScriptTarget.ES2015 &&
!!(facts & ClassFacts.MayNeedImmediatelyInvokedFunctionExpression);

if (
Expand Down
40 changes: 40 additions & 0 deletions tests/baselines/reference/enumMemberNameNonIdentifier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//// [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.Ϳ;
50 changes: 50 additions & 0 deletions tests/baselines/reference/enumMemberNameNonIdentifier.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//// [tests/cases/compiler/enumMemberNameNonIdentifier.ts] ////

=== enumMemberNameNonIdentifier.ts ===
export const enum E {
>E : Symbol(E, Decl(enumMemberNameNonIdentifier.ts, 0, 0))

regular = 0,
>regular : Symbol(E.regular, Decl(enumMemberNameNonIdentifier.ts, 0, 21))

"hyphen-member" = 1,
>"hyphen-member" : Symbol(E["hyphen-member"], Decl(enumMemberNameNonIdentifier.ts, 1, 16))

"123startsWithNumber" = 2,
>"123startsWithNumber" : Symbol(E["123startsWithNumber"], Decl(enumMemberNameNonIdentifier.ts, 2, 24))

"has space" = 3,
>"has space" : Symbol(E["has space"], Decl(enumMemberNameNonIdentifier.ts, 3, 30))

// Greek Capital Yot (U+037F) - valid identifier in ES2015+ but NOT in ES5
Ϳ = 4,
>Ϳ : Symbol(E.Ϳ, Decl(enumMemberNameNonIdentifier.ts, 4, 20))
}

export const a = E["hyphen-member"];
>a : Symbol(a, Decl(enumMemberNameNonIdentifier.ts, 9, 12))
>E : Symbol(E, Decl(enumMemberNameNonIdentifier.ts, 0, 0))
>"hyphen-member" : Symbol(E["hyphen-member"], Decl(enumMemberNameNonIdentifier.ts, 1, 16))

export const b = E["123startsWithNumber"];
>b : Symbol(b, Decl(enumMemberNameNonIdentifier.ts, 10, 12))
>E : Symbol(E, Decl(enumMemberNameNonIdentifier.ts, 0, 0))
>"123startsWithNumber" : Symbol(E["123startsWithNumber"], Decl(enumMemberNameNonIdentifier.ts, 2, 24))

export const c = E["has space"];
>c : Symbol(c, Decl(enumMemberNameNonIdentifier.ts, 11, 12))
>E : Symbol(E, Decl(enumMemberNameNonIdentifier.ts, 0, 0))
>"has space" : Symbol(E["has space"], Decl(enumMemberNameNonIdentifier.ts, 3, 30))

export const d = E.regular;
>d : Symbol(d, Decl(enumMemberNameNonIdentifier.ts, 12, 12))
>E.regular : Symbol(E.regular, Decl(enumMemberNameNonIdentifier.ts, 0, 21))
>E : Symbol(E, Decl(enumMemberNameNonIdentifier.ts, 0, 0))
>regular : Symbol(E.regular, Decl(enumMemberNameNonIdentifier.ts, 0, 21))

export const e = E.Ϳ;
>e : Symbol(e, Decl(enumMemberNameNonIdentifier.ts, 13, 12))
>E.Ϳ : Symbol(E.Ϳ, Decl(enumMemberNameNonIdentifier.ts, 4, 20))
>E : Symbol(E, Decl(enumMemberNameNonIdentifier.ts, 0, 0))
>Ϳ : Symbol(E.Ϳ, Decl(enumMemberNameNonIdentifier.ts, 4, 20))

89 changes: 89 additions & 0 deletions tests/baselines/reference/enumMemberNameNonIdentifier.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//// [tests/cases/compiler/enumMemberNameNonIdentifier.ts] ////

=== enumMemberNameNonIdentifier.ts ===
export const enum E {
>E : E
> : ^

regular = 0,
>regular : E.regular
> : ^^^^^^^^^
>0 : 0
> : ^

"hyphen-member" = 1,
>"hyphen-member" : (typeof E)["hyphen-member"]
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>1 : 1
> : ^

"123startsWithNumber" = 2,
>"123startsWithNumber" : (typeof E)["123startsWithNumber"]
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>2 : 2
> : ^

"has space" = 3,
>"has space" : (typeof E)["has space"]
> : ^^^^^^^^^^^^^^^^^^^^^^^
>3 : 3
> : ^

// Greek Capital Yot (U+037F) - valid identifier in ES2015+ but NOT in ES5
Ϳ = 4,
>Ϳ : E.Ϳ
> : ^^^
>4 : 4
> : ^
}

export const a = E["hyphen-member"];
>a : (typeof E)["hyphen-member"]
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>E["hyphen-member"] : (typeof E)["hyphen-member"]
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>E : typeof E
> : ^^^^^^^^
>"hyphen-member" : "hyphen-member"
> : ^^^^^^^^^^^^^^^

export const b = E["123startsWithNumber"];
>b : (typeof E)["123startsWithNumber"]
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>E["123startsWithNumber"] : (typeof E)["123startsWithNumber"]
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>E : typeof E
> : ^^^^^^^^
>"123startsWithNumber" : "123startsWithNumber"
> : ^^^^^^^^^^^^^^^^^^^^^

export const c = E["has space"];
>c : (typeof E)["has space"]
> : ^^^^^^^^^^^^^^^^^^^^^^^
>E["has space"] : (typeof E)["has space"]
> : ^^^^^^^^^^^^^^^^^^^^^^^
>E : typeof E
> : ^^^^^^^^
>"has space" : "has space"
> : ^^^^^^^^^^^

export const d = E.regular;
>d : E.regular
> : ^^^^^^^^^
>E.regular : E.regular
> : ^^^^^^^^^
>E : typeof E
> : ^^^^^^^^
>regular : E.regular
> : ^^^^^^^^^

export const e = E.Ϳ;
>e : E.Ϳ
> : ^^^
>E.Ϳ : E.Ϳ
> : ^^^
>E : typeof E
> : ^^^^^^^^
>Ϳ : E.Ϳ
> : ^^^

16 changes: 16 additions & 0 deletions tests/cases/compiler/enumMemberNameNonIdentifier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @declaration: true

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.Ϳ;