mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Address code review feedback - revert declarations.ts changes and clean up test
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
This commit is contained in:
parent
64358a26e1
commit
bef82cbfc4
@ -103,8 +103,7 @@ import {
|
||||
isExpandoPropertyDeclaration,
|
||||
isExportAssignment,
|
||||
isExportDeclaration,
|
||||
isExpressionWithTypeArguments,
|
||||
isExpression,
|
||||
isExpressionWithTypeArguments,
|
||||
isExternalModule,
|
||||
isExternalModuleAugmentation,
|
||||
isExternalModuleIndicator,
|
||||
@ -129,9 +128,8 @@ import {
|
||||
isObjectLiteralExpression,
|
||||
isOmittedExpression,
|
||||
isParameter,
|
||||
isPrimitiveLiteralValue,
|
||||
isPrivateIdentifier,
|
||||
isPropertyAccessExpression,
|
||||
isPrimitiveLiteralValue,
|
||||
isPrivateIdentifier,
|
||||
isSemicolonClassElement,
|
||||
isSetAccessorDeclaration,
|
||||
isSourceFile,
|
||||
@ -202,8 +200,8 @@ import {
|
||||
TransformationContext,
|
||||
Transformer,
|
||||
transformNodes,
|
||||
tryCast,
|
||||
TypeAliasDeclaration,
|
||||
tryCast,
|
||||
TypeAliasDeclaration,
|
||||
TypeNode,
|
||||
TypeParameterDeclaration,
|
||||
TypeReferenceNode,
|
||||
@ -656,21 +654,21 @@ export function transformDeclarations(context: TransformationContext): Transform
|
||||
return newParam;
|
||||
}
|
||||
|
||||
function shouldPrintWithInitializer(node: Node): node is CanHaveLiteralInitializer & { initializer: Expression; } {
|
||||
return canHaveLiteralInitializer(node)
|
||||
&& !!node.initializer
|
||||
&& resolver.isLiteralConstDeclaration(getParseTreeNode(node) as CanHaveLiteralInitializer); // TODO: Make safea
|
||||
function shouldPrintWithInitializer(node: Node): node is CanHaveLiteralInitializer & { initializer: Expression; } {
|
||||
return canHaveLiteralInitializer(node)
|
||||
&& !!node.initializer
|
||||
&& resolver.isLiteralConstDeclaration(getParseTreeNode(node) as CanHaveLiteralInitializer); // TODO: Make safea
|
||||
}
|
||||
|
||||
function ensureNoInitializer(node: CanHaveLiteralInitializer) {
|
||||
if (shouldPrintWithInitializer(node)) {
|
||||
const unwrappedInitializer = unwrapParenthesizedExpression(node.initializer);
|
||||
if (!isPrimitiveLiteralValue(unwrappedInitializer)) {
|
||||
reportInferenceFallback(node);
|
||||
}
|
||||
return resolver.createLiteralConstValue(getParseTreeNode(node, canHaveLiteralInitializer)!, symbolTracker);
|
||||
}
|
||||
return undefined;
|
||||
function ensureNoInitializer(node: CanHaveLiteralInitializer) {
|
||||
if (shouldPrintWithInitializer(node)) {
|
||||
const unwrappedInitializer = unwrapParenthesizedExpression(node.initializer);
|
||||
if (!isPrimitiveLiteralValue(unwrappedInitializer)) {
|
||||
reportInferenceFallback(node);
|
||||
}
|
||||
return resolver.createLiteralConstValue(getParseTreeNode(node, canHaveLiteralInitializer)!, symbolTracker);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
function ensureType(node: VariableDeclaration | ParameterDeclaration | BindingElement | PropertyDeclaration | PropertySignature | ExportAssignment | SignatureDeclaration, ignorePrivate?: boolean): TypeNode | undefined {
|
||||
if (!ignorePrivate && hasEffectiveModifier(node, ModifierFlags.Private)) {
|
||||
@ -1051,12 +1049,12 @@ export function transformDeclarations(context: TransformationContext): Transform
|
||||
const oldWithinObjectLiteralType = suppressNewDiagnosticContexts;
|
||||
let shouldEnterSuppressNewDiagnosticsContextContext = (input.kind === SyntaxKind.TypeLiteral || input.kind === SyntaxKind.MappedType) && input.parent.kind !== SyntaxKind.TypeAliasDeclaration;
|
||||
|
||||
// Emit methods which are private as properties with no type information
|
||||
if (isMethodDeclaration(input) || isMethodSignature(input)) {
|
||||
if (hasEffectiveModifier(input, ModifierFlags.Private)) {
|
||||
if (input.symbol && input.symbol.declarations && input.symbol.declarations[0] !== input) return; // Elide all but the first overload
|
||||
return cleanup(factory.createPropertyDeclaration(ensureModifiers(input), input.name, /*questionOrExclamationToken*/ undefined, /*type*/ undefined, /*initializer*/ undefined));
|
||||
}
|
||||
// Emit methods which are private as properties with no type information
|
||||
if (isMethodDeclaration(input) || isMethodSignature(input)) {
|
||||
if (hasEffectiveModifier(input, ModifierFlags.Private)) {
|
||||
if (input.symbol && input.symbol.declarations && input.symbol.declarations[0] !== input) return; // Elide all but the first overload
|
||||
return cleanup(factory.createPropertyDeclaration(ensureModifiers(input), input.name, /*questionOrExclamationToken*/ undefined, /*type*/ undefined, /*initializer*/ undefined));
|
||||
}
|
||||
}
|
||||
|
||||
if (canProduceDiagnostic && !suppressNewDiagnosticContexts) {
|
||||
|
||||
@ -19,14 +19,7 @@ namespace MyEnum {
|
||||
export const value2 = MyEnum.Second;
|
||||
}
|
||||
|
||||
// String enum
|
||||
enum StringEnum {
|
||||
Option1 = "option1",
|
||||
Option2 = "option2"
|
||||
}
|
||||
namespace StringEnum {
|
||||
export const selected = StringEnum.Option1;
|
||||
}
|
||||
|
||||
|
||||
//// [enumNamespaceConstantsDeclaration.js]
|
||||
// Test for constant declarations inside namespace merged with enum
|
||||
@ -47,15 +40,6 @@ var MyEnum;
|
||||
MyEnum.value1 = MyEnum.First;
|
||||
MyEnum.value2 = MyEnum.Second;
|
||||
})(MyEnum || (MyEnum = {}));
|
||||
// String enum
|
||||
var StringEnum;
|
||||
(function (StringEnum) {
|
||||
StringEnum["Option1"] = "option1";
|
||||
StringEnum["Option2"] = "option2";
|
||||
})(StringEnum || (StringEnum = {}));
|
||||
(function (StringEnum) {
|
||||
StringEnum.selected = StringEnum.Option1;
|
||||
})(StringEnum || (StringEnum = {}));
|
||||
|
||||
|
||||
//// [enumNamespaceConstantsDeclaration.d.ts]
|
||||
@ -73,25 +57,3 @@ declare namespace MyEnum {
|
||||
const value1 = MyEnum.First;
|
||||
const value2 = MyEnum.Second;
|
||||
}
|
||||
declare enum StringEnum {
|
||||
Option1 = "option1",
|
||||
Option2 = "option2"
|
||||
}
|
||||
declare namespace StringEnum {
|
||||
const selected: any;
|
||||
}
|
||||
|
||||
|
||||
!!!! File enumNamespaceConstantsDeclaration.d.ts differs from original emit in noCheck emit
|
||||
//// [enumNamespaceConstantsDeclaration.d.ts]
|
||||
===================================================================
|
||||
--- Expected The full check baseline
|
||||
+++ Actual with noCheck set
|
||||
@@ -16,6 +16,6 @@
|
||||
Option1 = "option1",
|
||||
Option2 = "option2"
|
||||
}
|
||||
declare namespace StringEnum {
|
||||
- const selected: any;
|
||||
+ const selected = StringEnum.Option1;
|
||||
}
|
||||
|
||||
@ -44,22 +44,4 @@ namespace MyEnum {
|
||||
>Second : Symbol(Second, Decl(enumNamespaceConstantsDeclaration.ts, 10, 14))
|
||||
}
|
||||
|
||||
// String enum
|
||||
enum StringEnum {
|
||||
>StringEnum : Symbol(StringEnum, Decl(enumNamespaceConstantsDeclaration.ts, 16, 1), Decl(enumNamespaceConstantsDeclaration.ts, 22, 1))
|
||||
|
||||
Option1 = "option1",
|
||||
>Option1 : Symbol(StringEnum.Option1, Decl(enumNamespaceConstantsDeclaration.ts, 19, 17))
|
||||
|
||||
Option2 = "option2"
|
||||
>Option2 : Symbol(StringEnum.Option2, Decl(enumNamespaceConstantsDeclaration.ts, 20, 24))
|
||||
}
|
||||
namespace StringEnum {
|
||||
>StringEnum : Symbol(StringEnum, Decl(enumNamespaceConstantsDeclaration.ts, 16, 1), Decl(enumNamespaceConstantsDeclaration.ts, 22, 1))
|
||||
|
||||
export const selected = StringEnum.Option1;
|
||||
>selected : Symbol(selected, Decl(enumNamespaceConstantsDeclaration.ts, 24, 16))
|
||||
>StringEnum.Option1 : Symbol(Option1, Decl(enumNamespaceConstantsDeclaration.ts, 19, 17))
|
||||
>StringEnum : Symbol(StringEnum, Decl(enumNamespaceConstantsDeclaration.ts, 16, 1), Decl(enumNamespaceConstantsDeclaration.ts, 22, 1))
|
||||
>Option1 : Symbol(Option1, Decl(enumNamespaceConstantsDeclaration.ts, 19, 17))
|
||||
}
|
||||
|
||||
@ -67,33 +67,4 @@ namespace MyEnum {
|
||||
> : ^^^^^^^^^^^^^
|
||||
}
|
||||
|
||||
// String enum
|
||||
enum StringEnum {
|
||||
>StringEnum : StringEnum
|
||||
> : ^^^^^^^^^^
|
||||
|
||||
Option1 = "option1",
|
||||
>Option1 : StringEnum.Option1
|
||||
> : ^^^^^^^^^^^^^^^^^^
|
||||
>"option1" : "option1"
|
||||
> : ^^^^^^^^^
|
||||
|
||||
Option2 = "option2"
|
||||
>Option2 : StringEnum.Option2
|
||||
> : ^^^^^^^^^^^^^^^^^^
|
||||
>"option2" : "option2"
|
||||
> : ^^^^^^^^^
|
||||
}
|
||||
namespace StringEnum {
|
||||
>StringEnum : typeof StringEnum
|
||||
> : ^^^^^^^^^^^^^^^^^
|
||||
|
||||
export const selected = StringEnum.Option1;
|
||||
>selected : any
|
||||
>StringEnum.Option1 : StringEnum.Option1
|
||||
> : ^^^^^^^^^^^^^^^^^^
|
||||
>StringEnum : typeof StringEnum
|
||||
> : ^^^^^^^^^^^^^^^^^
|
||||
>Option1 : StringEnum.Option1
|
||||
> : ^^^^^^^^^^^^^^^^^^
|
||||
}
|
||||
|
||||
@ -1,21 +0,0 @@
|
||||
declare enum Foo {
|
||||
bar = 0
|
||||
}
|
||||
declare namespace Foo {
|
||||
const baz = bar;
|
||||
}
|
||||
declare enum MyEnum {
|
||||
First = 1,
|
||||
Second = 2
|
||||
}
|
||||
declare namespace MyEnum {
|
||||
const value1 = First;
|
||||
const value2 = Second;
|
||||
}
|
||||
declare enum StringEnum {
|
||||
Option1 = "option1",
|
||||
Option2 = "option2"
|
||||
}
|
||||
declare namespace StringEnum {
|
||||
const selected: any;
|
||||
}
|
||||
@ -18,11 +18,3 @@ namespace MyEnum {
|
||||
export const value2 = MyEnum.Second;
|
||||
}
|
||||
|
||||
// String enum
|
||||
enum StringEnum {
|
||||
Option1 = "option1",
|
||||
Option2 = "option2"
|
||||
}
|
||||
namespace StringEnum {
|
||||
export const selected = StringEnum.Option1;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user