Skip to content
Merged
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
24 changes: 24 additions & 0 deletions internal/checker/emitresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,30 @@ func (r *emitResolver) IsImportRequiredByAugmentation(decl *ast.ImportDeclaratio
return false
}

func (r *emitResolver) IsDefinitelyReferenceToGlobalSymbolObject(node *ast.Node) bool {
if !ast.IsPropertyAccessExpression(node) ||
!ast.IsIdentifier(node.Name()) ||
!ast.IsPropertyAccessExpression(node.Expression()) && !ast.IsIdentifier(node.Expression()) {
return false
}
if node.Expression().Kind == ast.KindIdentifier {
if node.Expression().AsIdentifier().Text != "Symbol" {
return false
}
r.checkerMu.Lock()
defer r.checkerMu.Unlock()
// Exactly `Symbol.something` and `Symbol` either does not resolve or definitely resolves to the global Symbol
return r.checker.getResolvedSymbol(node.Expression()) == r.checker.getGlobalSymbol("Symbol", ast.SymbolFlagsValue|ast.SymbolFlagsExportValue, nil /*diagnostic*/)
}
if node.Expression().Expression().Kind != ast.KindIdentifier || node.Expression().Expression().AsIdentifier().Text != "globalThis" || node.Expression().Name().Text() != "Symbol" {
return false
}
r.checkerMu.Lock()
defer r.checkerMu.Unlock()
// Exactly `globalThis.Symbol.something` and `globalThis` resolves to the global `globalThis`
return r.checker.getResolvedSymbol(node.Expression().Expression()) == r.checker.globalThisSymbol
}

func (r *emitResolver) RequiresAddingImplicitUndefined(declaration *ast.Node, symbol *ast.Symbol, enclosingDeclaration *ast.Node) bool {
if !ast.IsParseTreeNode(declaration) {
return false
Expand Down
1 change: 1 addition & 0 deletions internal/printer/emitresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type EmitResolver interface {
RequiresAddingImplicitUndefined(node *ast.Node, symbol *ast.Symbol, enclosingDeclaration *ast.Node) bool
IsDeclarationVisible(node *ast.Node) bool
IsImportRequiredByAugmentation(decl *ast.ImportDeclaration) bool
IsDefinitelyReferenceToGlobalSymbolObject(node *ast.Node) bool
IsImplementationOfOverload(node *ast.SignatureDeclaration) bool
GetEnumMemberValue(node *ast.Node) evaluator.Result
IsLateBound(node *ast.Node) bool
Expand Down
16 changes: 14 additions & 2 deletions internal/transformers/declarations/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,20 @@ func (tx *DeclarationTransformer) visitDeclarationSubtree(input *ast.Node) *ast.
}
if ast.HasDynamicName(input) {
if tx.state.isolatedDeclarations {
// !!! isolatedDeclarations support
return nil
// Classes and object literals usually elide properties with computed names that are not of a literal type
// In isolated declarations TSC needs to error on these as we don't know the type in a DTE.
if !tx.resolver.IsDefinitelyReferenceToGlobalSymbolObject(input.Name().Expression()) {
if ast.IsClassDeclaration(input.Parent) || ast.IsObjectLiteralExpression(input.Parent) {
// !!! TODO: isolatedDeclarations diagnostics
// context.addDiagnostic(createDiagnosticForNode(input, diagnostics.Computed_property_names_on_class_or_object_literals_cannot_be_inferred_with_isolatedDeclarations))
return nil
} else if (ast.IsInterfaceDeclaration(input.Parent) || ast.IsTypeLiteralNode(input.Parent)) && !ast.IsEntityNameExpression(input.Name().Expression()) {
// Type declarations just need to double-check that the input computed name is an entity name expression
// !!! TODO: isolatedDeclarations diagnostics
// context.addDiagnostic(createDiagnosticForNode(input, diagnostics.Computed_properties_must_be_number_or_string_literals_variables_or_dotted_expressions_with_isolatedDeclarations))
return nil
}
}
} else if !tx.resolver.IsLateBound(tx.EmitContext().ParseNode(input)) || !ast.IsEntityNameExpression(input.Name().AsComputedPropertyName().Expression) {
return nil
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//// [tests/cases/compiler/enumMemberInterfacePropertyDeclarationEmit.ts] ////

//// [enum.ts]
export enum WWMF{
AAR = 'AAR',
}

//// [base.ts]
import type { WWMF } from "./enum";

interface WWMFMap {
[WWMF.AAR]?: any;
}

export const wwmfMap: WWMFMap = {};


//// [enum.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WWMF = void 0;
var WWMF;
(function (WWMF) {
WWMF["AAR"] = "AAR";
})(WWMF || (exports.WWMF = WWMF = {}));
//// [base.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.wwmfMap = void 0;
exports.wwmfMap = {};


//// [enum.d.ts]
export declare enum WWMF {
AAR = "AAR"
}
//// [base.d.ts]
import type { WWMF } from "./enum";
interface WWMFMap {
[WWMF.AAR]?: any;
}
export declare const wwmfMap: WWMFMap;
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,14 @@ export declare class Cls {
get getSetOk3(): number;
set getSetOk3(value: number);
}
declare let noAnnotationStringName: string;
declare const noAnnotationLiteralName = "noAnnotationLiteralName";
export declare class C {
[x: string]: any;
[x: number]: number;
}
export interface I {
[noAnnotationStringName]: 10;
[noAnnotationLiteralName](): any;
}
export {};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this diff might be bogus. The submodule’s copy of this baseline doesn‘t include declaration emit output at all, so it must have been meddled with in some way during generation.

Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@
+ get getSetOk3(): number;
+ set getSetOk3(value: number);
+}
+declare let noAnnotationStringName: string;
+declare const noAnnotationLiteralName = "noAnnotationLiteralName";
+export declare class C {
+ [x: string]: any;
+ [x: number]: number;
+}
+export interface I {
+}
+ [noAnnotationStringName]: 10;
+ [noAnnotationLiteralName](): any;
+}
+export {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// @declaration: true
// @noTypesAndSymbols: true
// @isolatedDeclarations: true

// @Filename: enum.ts
export enum WWMF{
AAR = 'AAR',
}

// @Filename: base.ts
import type { WWMF } from "./enum";

interface WWMFMap {
[WWMF.AAR]?: any;
}

export const wwmfMap: WWMFMap = {};
Loading